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.

252045 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 static_cast <uint32> (nextInt()) / (float) 0xffffffff;
  869. }
  870. double Random::nextDouble() throw()
  871. {
  872. return static_cast <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. const String SystemStats::getJUCEVersion() throw()
  1098. {
  1099. return "JUCE v" + String (JUCE_MAJOR_VERSION)
  1100. + "." + String (JUCE_MINOR_VERSION)
  1101. + "." + String (JUCE_BUILDNUMBER);
  1102. }
  1103. const StringArray SystemStats::getMACAddressStrings()
  1104. {
  1105. int64 macAddresses [16];
  1106. const int numAddresses = getMACAddresses (macAddresses, numElementsInArray (macAddresses), false);
  1107. StringArray s;
  1108. for (int i = 0; i < numAddresses; ++i)
  1109. {
  1110. s.add (String::toHexString (0xff & (int) (macAddresses [i] >> 40)).paddedLeft ('0', 2)
  1111. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 32)).paddedLeft ('0', 2)
  1112. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 24)).paddedLeft ('0', 2)
  1113. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 16)).paddedLeft ('0', 2)
  1114. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 8)).paddedLeft ('0', 2)
  1115. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 0)).paddedLeft ('0', 2));
  1116. }
  1117. return s;
  1118. }
  1119. static bool juceInitialisedNonGUI = false;
  1120. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1121. {
  1122. if (! juceInitialisedNonGUI)
  1123. {
  1124. #if JUCE_MAC || JUCE_IPHONE
  1125. const ScopedAutoReleasePool pool;
  1126. #endif
  1127. #ifdef JUCE_DEBUG
  1128. {
  1129. // Some simple test code to keep an eye on things and make sure these functions
  1130. // work ok on all platforms. Let me know if any of these assertions fail!
  1131. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1132. char a1[7];
  1133. jassert (numElementsInArray(a1) == 7);
  1134. int a2[3];
  1135. jassert (numElementsInArray(a2) == 3);
  1136. int n = 1;
  1137. Atomic::increment (n);
  1138. jassert (Atomic::incrementAndReturn (n) == 3);
  1139. Atomic::decrement (n);
  1140. jassert (Atomic::decrementAndReturn (n) == 1);
  1141. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1142. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1143. // Some quick stream tests..
  1144. int randomInt = Random::getSystemRandom().nextInt();
  1145. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1146. double randomDouble = Random::getSystemRandom().nextDouble();
  1147. String randomString;
  1148. for (int i = 50; --i >= 0;)
  1149. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1150. MemoryOutputStream mo;
  1151. mo.writeInt (randomInt);
  1152. mo.writeIntBigEndian (randomInt);
  1153. mo.writeCompressedInt (randomInt);
  1154. mo.writeString (randomString);
  1155. mo.writeInt64 (randomInt64);
  1156. mo.writeInt64BigEndian (randomInt64);
  1157. mo.writeDouble (randomDouble);
  1158. mo.writeDoubleBigEndian (randomDouble);
  1159. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1160. jassert (mi.readInt() == randomInt);
  1161. jassert (mi.readIntBigEndian() == randomInt);
  1162. jassert (mi.readCompressedInt() == randomInt);
  1163. jassert (mi.readString() == randomString);
  1164. jassert (mi.readInt64() == randomInt64);
  1165. jassert (mi.readInt64BigEndian() == randomInt64);
  1166. jassert (mi.readDouble() == randomDouble);
  1167. jassert (mi.readDoubleBigEndian() == randomDouble);
  1168. }
  1169. #endif
  1170. // Now the real initialisation..
  1171. juceInitialisedNonGUI = true;
  1172. DBG (SystemStats::getJUCEVersion());
  1173. SystemStats::initialiseStats();
  1174. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1175. }
  1176. }
  1177. #if JUCE_WINDOWS
  1178. // This is imported from the sockets code..
  1179. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1180. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1181. #endif
  1182. #if JUCE_DEBUG
  1183. extern void juce_CheckForDanglingStreams();
  1184. #endif
  1185. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1186. {
  1187. if (juceInitialisedNonGUI)
  1188. {
  1189. #if JUCE_MAC || JUCE_IPHONE
  1190. const ScopedAutoReleasePool pool;
  1191. #endif
  1192. #if JUCE_WINDOWS
  1193. // need to shut down sockets if they were used..
  1194. if (juce_CloseWin32SocketLib != 0)
  1195. (*juce_CloseWin32SocketLib)();
  1196. #endif
  1197. LocalisedStrings::setCurrentMappings (0);
  1198. Thread::stopAllThreads (3000);
  1199. #if JUCE_DEBUG
  1200. juce_CheckForDanglingStreams();
  1201. #endif
  1202. juceInitialisedNonGUI = false;
  1203. }
  1204. }
  1205. #ifdef JUCE_DLL
  1206. void* juce_Malloc (const int size)
  1207. {
  1208. return malloc (size);
  1209. }
  1210. void* juce_Calloc (const int size)
  1211. {
  1212. return calloc (1, size);
  1213. }
  1214. void* juce_Realloc (void* const block, const int size)
  1215. {
  1216. return realloc (block, size);
  1217. }
  1218. void juce_Free (void* const block)
  1219. {
  1220. free (block);
  1221. }
  1222. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1223. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1224. {
  1225. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1226. }
  1227. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1228. {
  1229. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1230. }
  1231. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1232. {
  1233. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1234. }
  1235. void juce_DebugFree (void* const block)
  1236. {
  1237. _free_dbg (block, _NORMAL_BLOCK);
  1238. }
  1239. #endif
  1240. #endif
  1241. END_JUCE_NAMESPACE
  1242. /*** End of inlined file: juce_SystemStats.cpp ***/
  1243. /*** Start of inlined file: juce_Time.cpp ***/
  1244. #ifdef _MSC_VER
  1245. #pragma warning (disable: 4514)
  1246. #pragma warning (push)
  1247. #endif
  1248. #ifndef JUCE_WINDOWS
  1249. #include <sys/time.h>
  1250. #else
  1251. #include <ctime>
  1252. #endif
  1253. #include <sys/timeb.h>
  1254. BEGIN_JUCE_NAMESPACE
  1255. #ifdef _MSC_VER
  1256. #pragma warning (pop)
  1257. #ifdef _INC_TIME_INL
  1258. #define USE_NEW_SECURE_TIME_FNS
  1259. #endif
  1260. #endif
  1261. static void millisToLocal (const int64 millis, struct tm& result) throw()
  1262. {
  1263. const int64 seconds = millis / 1000;
  1264. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1265. {
  1266. // use extended maths for dates beyond 1970 to 2037..
  1267. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1268. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1269. const int days = (int) (jdm / literal64bit (86400));
  1270. const int a = 32044 + days;
  1271. const int b = (4 * a + 3) / 146097;
  1272. const int c = a - (b * 146097) / 4;
  1273. const int d = (4 * c + 3) / 1461;
  1274. const int e = c - (d * 1461) / 4;
  1275. const int m = (5 * e + 2) / 153;
  1276. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1277. result.tm_mon = m + 2 - 12 * (m / 10);
  1278. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1279. result.tm_wday = (days + 1) % 7;
  1280. result.tm_yday = -1;
  1281. int t = (int) (jdm % literal64bit (86400));
  1282. result.tm_hour = t / 3600;
  1283. t %= 3600;
  1284. result.tm_min = t / 60;
  1285. result.tm_sec = t % 60;
  1286. result.tm_isdst = -1;
  1287. }
  1288. else
  1289. {
  1290. time_t now = (time_t) (seconds);
  1291. #if JUCE_WINDOWS
  1292. #ifdef USE_NEW_SECURE_TIME_FNS
  1293. if (now >= 0 && now <= 0x793406fff)
  1294. localtime_s (&result, &now);
  1295. else
  1296. zeromem (&result, sizeof (result));
  1297. #else
  1298. result = *localtime (&now);
  1299. #endif
  1300. #else
  1301. // more thread-safe
  1302. localtime_r (&now, &result);
  1303. #endif
  1304. }
  1305. }
  1306. Time::Time() throw()
  1307. : millisSinceEpoch (0)
  1308. {
  1309. }
  1310. Time::Time (const Time& other) throw()
  1311. : millisSinceEpoch (other.millisSinceEpoch)
  1312. {
  1313. }
  1314. Time::Time (const int64 ms) throw()
  1315. : millisSinceEpoch (ms)
  1316. {
  1317. }
  1318. Time::Time (const int year,
  1319. const int month,
  1320. const int day,
  1321. const int hours,
  1322. const int minutes,
  1323. const int seconds,
  1324. const int milliseconds,
  1325. const bool useLocalTime) throw()
  1326. {
  1327. jassert (year > 100); // year must be a 4-digit version
  1328. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1329. {
  1330. // use extended maths for dates beyond 1970 to 2037..
  1331. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1332. : 0;
  1333. const int a = (13 - month) / 12;
  1334. const int y = year + 4800 - a;
  1335. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1336. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1337. - 32045;
  1338. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1339. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1340. + milliseconds;
  1341. }
  1342. else
  1343. {
  1344. struct tm t;
  1345. t.tm_year = year - 1900;
  1346. t.tm_mon = month;
  1347. t.tm_mday = day;
  1348. t.tm_hour = hours;
  1349. t.tm_min = minutes;
  1350. t.tm_sec = seconds;
  1351. t.tm_isdst = -1;
  1352. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1353. if (millisSinceEpoch < 0)
  1354. millisSinceEpoch = 0;
  1355. else
  1356. millisSinceEpoch += milliseconds;
  1357. }
  1358. }
  1359. Time::~Time() throw()
  1360. {
  1361. }
  1362. Time& Time::operator= (const Time& other) throw()
  1363. {
  1364. millisSinceEpoch = other.millisSinceEpoch;
  1365. return *this;
  1366. }
  1367. int64 Time::currentTimeMillis() throw()
  1368. {
  1369. static uint32 lastCounterResult = 0xffffffff;
  1370. static int64 correction = 0;
  1371. const uint32 now = getMillisecondCounter();
  1372. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1373. if (now < lastCounterResult)
  1374. {
  1375. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1376. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1377. {
  1378. // get the time once using normal library calls, and store the difference needed to
  1379. // turn the millisecond counter into a real time.
  1380. #if JUCE_WINDOWS
  1381. struct _timeb t;
  1382. #ifdef USE_NEW_SECURE_TIME_FNS
  1383. _ftime_s (&t);
  1384. #else
  1385. _ftime (&t);
  1386. #endif
  1387. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1388. #else
  1389. struct timeval tv;
  1390. struct timezone tz;
  1391. gettimeofday (&tv, &tz);
  1392. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1393. #endif
  1394. }
  1395. }
  1396. lastCounterResult = now;
  1397. return correction + now;
  1398. }
  1399. uint32 juce_millisecondsSinceStartup() throw();
  1400. static uint32 lastMSCounterValue = 0;
  1401. uint32 Time::getMillisecondCounter() throw()
  1402. {
  1403. const uint32 now = juce_millisecondsSinceStartup();
  1404. if (now < lastMSCounterValue)
  1405. {
  1406. // in multi-threaded apps this might be called concurrently, so
  1407. // make sure that our last counter value only increases and doesn't
  1408. // go backwards..
  1409. if (now < lastMSCounterValue - 1000)
  1410. lastMSCounterValue = now;
  1411. }
  1412. else
  1413. {
  1414. lastMSCounterValue = now;
  1415. }
  1416. return now;
  1417. }
  1418. uint32 Time::getApproximateMillisecondCounter() throw()
  1419. {
  1420. jassert (lastMSCounterValue != 0);
  1421. return lastMSCounterValue;
  1422. }
  1423. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1424. {
  1425. for (;;)
  1426. {
  1427. const uint32 now = getMillisecondCounter();
  1428. if (now >= targetTime)
  1429. break;
  1430. const int toWait = targetTime - now;
  1431. if (toWait > 2)
  1432. {
  1433. Thread::sleep (jmin (20, toWait >> 1));
  1434. }
  1435. else
  1436. {
  1437. // xxx should consider using mutex_pause on the mac as it apparently
  1438. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1439. for (int i = 10; --i >= 0;)
  1440. Thread::yield();
  1441. }
  1442. }
  1443. }
  1444. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1445. {
  1446. return ticks / (double) getHighResolutionTicksPerSecond();
  1447. }
  1448. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1449. {
  1450. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1451. }
  1452. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1453. {
  1454. return Time (currentTimeMillis());
  1455. }
  1456. const String Time::toString (const bool includeDate,
  1457. const bool includeTime,
  1458. const bool includeSeconds,
  1459. const bool use24HourClock) const throw()
  1460. {
  1461. String result;
  1462. if (includeDate)
  1463. {
  1464. result << getDayOfMonth() << ' '
  1465. << getMonthName (true) << ' '
  1466. << getYear();
  1467. if (includeTime)
  1468. result << ' ';
  1469. }
  1470. if (includeTime)
  1471. {
  1472. const int mins = getMinutes();
  1473. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  1474. << (mins < 10 ? ":0" : ":") << mins;
  1475. if (includeSeconds)
  1476. {
  1477. const int secs = getSeconds();
  1478. result << (secs < 10 ? ":0" : ":") << secs;
  1479. }
  1480. if (! use24HourClock)
  1481. result << (isAfternoon() ? "pm" : "am");
  1482. }
  1483. return result.trimEnd();
  1484. }
  1485. const String Time::formatted (const tchar* const format) const throw()
  1486. {
  1487. String buffer;
  1488. int bufferSize = 128;
  1489. buffer.preallocateStorage (bufferSize);
  1490. struct tm t;
  1491. millisToLocal (millisSinceEpoch, t);
  1492. while (CharacterFunctions::ftime ((tchar*) (const tchar*) buffer, bufferSize, format, &t) <= 0)
  1493. {
  1494. bufferSize += 128;
  1495. buffer.preallocateStorage (bufferSize);
  1496. }
  1497. return buffer;
  1498. }
  1499. int Time::getYear() const throw()
  1500. {
  1501. struct tm t;
  1502. millisToLocal (millisSinceEpoch, t);
  1503. return t.tm_year + 1900;
  1504. }
  1505. int Time::getMonth() const throw()
  1506. {
  1507. struct tm t;
  1508. millisToLocal (millisSinceEpoch, t);
  1509. return t.tm_mon;
  1510. }
  1511. int Time::getDayOfMonth() const throw()
  1512. {
  1513. struct tm t;
  1514. millisToLocal (millisSinceEpoch, t);
  1515. return t.tm_mday;
  1516. }
  1517. int Time::getDayOfWeek() const throw()
  1518. {
  1519. struct tm t;
  1520. millisToLocal (millisSinceEpoch, t);
  1521. return t.tm_wday;
  1522. }
  1523. int Time::getHours() const throw()
  1524. {
  1525. struct tm t;
  1526. millisToLocal (millisSinceEpoch, t);
  1527. return t.tm_hour;
  1528. }
  1529. int Time::getHoursInAmPmFormat() const throw()
  1530. {
  1531. const int hours = getHours();
  1532. if (hours == 0)
  1533. return 12;
  1534. else if (hours <= 12)
  1535. return hours;
  1536. else
  1537. return hours - 12;
  1538. }
  1539. bool Time::isAfternoon() const throw()
  1540. {
  1541. return getHours() >= 12;
  1542. }
  1543. static int extendedModulo (const int64 value, const int modulo) throw()
  1544. {
  1545. return (int) (value >= 0 ? (value % modulo)
  1546. : (value - ((value / modulo) + 1) * modulo));
  1547. }
  1548. int Time::getMinutes() const throw()
  1549. {
  1550. struct tm t;
  1551. millisToLocal (millisSinceEpoch, t);
  1552. return t.tm_min;
  1553. }
  1554. int Time::getSeconds() const throw()
  1555. {
  1556. return extendedModulo (millisSinceEpoch / 1000, 60);
  1557. }
  1558. int Time::getMilliseconds() const throw()
  1559. {
  1560. return extendedModulo (millisSinceEpoch, 1000);
  1561. }
  1562. bool Time::isDaylightSavingTime() const throw()
  1563. {
  1564. struct tm t;
  1565. millisToLocal (millisSinceEpoch, t);
  1566. return t.tm_isdst != 0;
  1567. }
  1568. const String Time::getTimeZone() const throw()
  1569. {
  1570. String zone[2];
  1571. #if JUCE_WINDOWS
  1572. _tzset();
  1573. #ifdef USE_NEW_SECURE_TIME_FNS
  1574. {
  1575. char name [128];
  1576. size_t length;
  1577. for (int i = 0; i < 2; ++i)
  1578. {
  1579. zeromem (name, sizeof (name));
  1580. _get_tzname (&length, name, 127, i);
  1581. zone[i] = name;
  1582. }
  1583. }
  1584. #else
  1585. const char** const zonePtr = (const char**) _tzname;
  1586. zone[0] = zonePtr[0];
  1587. zone[1] = zonePtr[1];
  1588. #endif
  1589. #else
  1590. tzset();
  1591. const char** const zonePtr = (const char**) tzname;
  1592. zone[0] = zonePtr[0];
  1593. zone[1] = zonePtr[1];
  1594. #endif
  1595. if (isDaylightSavingTime())
  1596. {
  1597. zone[0] = zone[1];
  1598. if (zone[0].length() > 3
  1599. && zone[0].containsIgnoreCase (T("daylight"))
  1600. && zone[0].contains (T("GMT")))
  1601. zone[0] = "BST";
  1602. }
  1603. return zone[0].substring (0, 3);
  1604. }
  1605. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1606. {
  1607. return getMonthName (getMonth(), threeLetterVersion);
  1608. }
  1609. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1610. {
  1611. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1612. }
  1613. const String Time::getMonthName (int monthNumber,
  1614. const bool threeLetterVersion) throw()
  1615. {
  1616. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1617. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1618. monthNumber %= 12;
  1619. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1620. : longMonthNames [monthNumber]);
  1621. }
  1622. const String Time::getWeekdayName (int day,
  1623. const bool threeLetterVersion) throw()
  1624. {
  1625. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1626. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1627. day %= 7;
  1628. return TRANS (threeLetterVersion ? shortDayNames [day]
  1629. : longDayNames [day]);
  1630. }
  1631. END_JUCE_NAMESPACE
  1632. /*** End of inlined file: juce_Time.cpp ***/
  1633. /*** Start of inlined file: juce_BitArray.cpp ***/
  1634. BEGIN_JUCE_NAMESPACE
  1635. BitArray::BitArray() throw()
  1636. : numValues (4),
  1637. highestBit (-1),
  1638. negative (false)
  1639. {
  1640. values.calloc (numValues + 1);
  1641. }
  1642. BitArray::BitArray (const int value) throw()
  1643. : numValues (4),
  1644. highestBit (31),
  1645. negative (value < 0)
  1646. {
  1647. values.calloc (numValues + 1);
  1648. values[0] = abs (value);
  1649. highestBit = getHighestBit();
  1650. }
  1651. BitArray::BitArray (int64 value) throw()
  1652. : numValues (4),
  1653. highestBit (63),
  1654. negative (value < 0)
  1655. {
  1656. values.calloc (numValues + 1);
  1657. if (value < 0)
  1658. value = -value;
  1659. values[0] = (unsigned int) value;
  1660. values[1] = (unsigned int) (value >> 32);
  1661. highestBit = getHighestBit();
  1662. }
  1663. BitArray::BitArray (const unsigned int value) throw()
  1664. : numValues (4),
  1665. highestBit (31),
  1666. negative (false)
  1667. {
  1668. values.calloc (numValues + 1);
  1669. values[0] = value;
  1670. highestBit = getHighestBit();
  1671. }
  1672. BitArray::BitArray (const BitArray& other) throw()
  1673. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1674. highestBit (other.getHighestBit()),
  1675. negative (other.negative)
  1676. {
  1677. values.malloc (numValues + 1);
  1678. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1679. }
  1680. BitArray::~BitArray() throw()
  1681. {
  1682. }
  1683. BitArray& BitArray::operator= (const BitArray& other) throw()
  1684. {
  1685. if (this != &other)
  1686. {
  1687. highestBit = other.getHighestBit();
  1688. numValues = jmax (4, (highestBit >> 5) + 1);
  1689. negative = other.negative;
  1690. values.malloc (numValues + 1);
  1691. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1692. }
  1693. return *this;
  1694. }
  1695. // result == 0 = the same
  1696. // result < 0 = this number is smaller
  1697. // result > 0 = this number is bigger
  1698. int BitArray::compare (const BitArray& other) const throw()
  1699. {
  1700. if (isNegative() == other.isNegative())
  1701. {
  1702. const int absComp = compareAbsolute (other);
  1703. return isNegative() ? -absComp : absComp;
  1704. }
  1705. else
  1706. {
  1707. return isNegative() ? -1 : 1;
  1708. }
  1709. }
  1710. int BitArray::compareAbsolute (const BitArray& other) const throw()
  1711. {
  1712. const int h1 = getHighestBit();
  1713. const int h2 = other.getHighestBit();
  1714. if (h1 > h2)
  1715. return 1;
  1716. else if (h1 < h2)
  1717. return -1;
  1718. for (int i = (h1 >> 5) + 1; --i >= 0;)
  1719. if (values[i] != other.values[i])
  1720. return (values[i] > other.values[i]) ? 1 : -1;
  1721. return 0;
  1722. }
  1723. bool BitArray::operator== (const BitArray& other) const throw()
  1724. {
  1725. return compare (other) == 0;
  1726. }
  1727. bool BitArray::operator!= (const BitArray& other) const throw()
  1728. {
  1729. return compare (other) != 0;
  1730. }
  1731. bool BitArray::operator[] (const int bit) const throw()
  1732. {
  1733. return bit >= 0 && bit <= highestBit
  1734. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1735. }
  1736. bool BitArray::isEmpty() const throw()
  1737. {
  1738. return getHighestBit() < 0;
  1739. }
  1740. void BitArray::clear() throw()
  1741. {
  1742. if (numValues > 16)
  1743. {
  1744. numValues = 4;
  1745. values.calloc (numValues + 1);
  1746. }
  1747. else
  1748. {
  1749. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1750. }
  1751. highestBit = -1;
  1752. negative = false;
  1753. }
  1754. void BitArray::setBit (const int bit) throw()
  1755. {
  1756. if (bit >= 0)
  1757. {
  1758. if (bit > highestBit)
  1759. {
  1760. ensureSize (bit >> 5);
  1761. highestBit = bit;
  1762. }
  1763. values [bit >> 5] |= (1 << (bit & 31));
  1764. }
  1765. }
  1766. void BitArray::setBit (const int bit,
  1767. const bool shouldBeSet) throw()
  1768. {
  1769. if (shouldBeSet)
  1770. setBit (bit);
  1771. else
  1772. clearBit (bit);
  1773. }
  1774. void BitArray::clearBit (const int bit) throw()
  1775. {
  1776. if (bit >= 0 && bit <= highestBit)
  1777. values [bit >> 5] &= ~(1 << (bit & 31));
  1778. }
  1779. void BitArray::setRange (int startBit,
  1780. int numBits,
  1781. const bool shouldBeSet) throw()
  1782. {
  1783. while (--numBits >= 0)
  1784. setBit (startBit++, shouldBeSet);
  1785. }
  1786. void BitArray::insertBit (const int bit,
  1787. const bool shouldBeSet) throw()
  1788. {
  1789. if (bit >= 0)
  1790. shiftBits (1, bit);
  1791. setBit (bit, shouldBeSet);
  1792. }
  1793. void BitArray::andWith (const BitArray& other) throw()
  1794. {
  1795. // this operation will only work with the absolute values
  1796. jassert (isNegative() == other.isNegative());
  1797. int n = numValues;
  1798. while (n > other.numValues)
  1799. values[--n] = 0;
  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::orWith (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::xorWith (const BitArray& other) throw()
  1821. {
  1822. if (other.highestBit < 0)
  1823. return;
  1824. // this operation will only work with the absolute values
  1825. jassert (isNegative() == other.isNegative());
  1826. ensureSize (other.highestBit >> 5);
  1827. int n = (other.highestBit >> 5) + 1;
  1828. while (--n >= 0)
  1829. values[n] ^= other.values[n];
  1830. if (other.highestBit > highestBit)
  1831. highestBit = other.highestBit;
  1832. highestBit = getHighestBit();
  1833. }
  1834. void BitArray::add (const BitArray& other) throw()
  1835. {
  1836. if (other.isNegative())
  1837. {
  1838. BitArray o (other);
  1839. o.negate();
  1840. subtract (o);
  1841. return;
  1842. }
  1843. if (isNegative())
  1844. {
  1845. if (compareAbsolute (other) < 0)
  1846. {
  1847. BitArray temp (*this);
  1848. temp.negate();
  1849. *this = other;
  1850. subtract (temp);
  1851. }
  1852. else
  1853. {
  1854. negate();
  1855. subtract (other);
  1856. negate();
  1857. }
  1858. return;
  1859. }
  1860. if (other.highestBit > highestBit)
  1861. highestBit = other.highestBit;
  1862. ++highestBit;
  1863. const int numInts = (highestBit >> 5) + 1;
  1864. ensureSize (numInts);
  1865. int64 remainder = 0;
  1866. for (int i = 0; i <= numInts; ++i)
  1867. {
  1868. if (i < numValues)
  1869. remainder += values[i];
  1870. if (i < other.numValues)
  1871. remainder += other.values[i];
  1872. values[i] = (unsigned int) remainder;
  1873. remainder >>= 32;
  1874. }
  1875. jassert (remainder == 0);
  1876. highestBit = getHighestBit();
  1877. }
  1878. void BitArray::subtract (const BitArray& other) throw()
  1879. {
  1880. if (other.isNegative())
  1881. {
  1882. BitArray o (other);
  1883. o.negate();
  1884. add (o);
  1885. return;
  1886. }
  1887. if (! isNegative())
  1888. {
  1889. if (compareAbsolute (other) < 0)
  1890. {
  1891. BitArray temp (*this);
  1892. *this = other;
  1893. subtract (temp);
  1894. negate();
  1895. return;
  1896. }
  1897. }
  1898. else
  1899. {
  1900. negate();
  1901. add (other);
  1902. negate();
  1903. return;
  1904. }
  1905. const int numInts = (highestBit >> 5) + 1;
  1906. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1907. int64 amountToSubtract = 0;
  1908. for (int i = 0; i <= numInts; ++i)
  1909. {
  1910. if (i <= maxOtherInts)
  1911. amountToSubtract += (int64)other.values[i];
  1912. if (values[i] >= amountToSubtract)
  1913. {
  1914. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1915. amountToSubtract = 0;
  1916. }
  1917. else
  1918. {
  1919. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1920. values[i] = (unsigned int) n;
  1921. amountToSubtract = 1;
  1922. }
  1923. }
  1924. }
  1925. void BitArray::multiplyBy (const BitArray& other) throw()
  1926. {
  1927. BitArray total;
  1928. highestBit = getHighestBit();
  1929. const bool wasNegative = isNegative();
  1930. setNegative (false);
  1931. for (int i = 0; i <= highestBit; ++i)
  1932. {
  1933. if (operator[](i))
  1934. {
  1935. BitArray n (other);
  1936. n.setNegative (false);
  1937. n.shiftBits (i);
  1938. total.add (n);
  1939. }
  1940. }
  1941. *this = total;
  1942. negative = wasNegative ^ other.isNegative();
  1943. }
  1944. void BitArray::divideBy (const BitArray& divisor, BitArray& remainder) throw()
  1945. {
  1946. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1947. const int divHB = divisor.getHighestBit();
  1948. const int ourHB = getHighestBit();
  1949. if (divHB < 0 || ourHB < 0)
  1950. {
  1951. // division by zero
  1952. remainder.clear();
  1953. clear();
  1954. }
  1955. else
  1956. {
  1957. remainder = *this;
  1958. remainder.setNegative (false);
  1959. const bool wasNegative = isNegative();
  1960. clear();
  1961. BitArray temp (divisor);
  1962. temp.setNegative (false);
  1963. int leftShift = ourHB - divHB;
  1964. temp.shiftBits (leftShift);
  1965. while (leftShift >= 0)
  1966. {
  1967. if (remainder.compareAbsolute (temp) >= 0)
  1968. {
  1969. remainder.subtract (temp);
  1970. setBit (leftShift);
  1971. }
  1972. if (--leftShift >= 0)
  1973. temp.shiftBits (-1);
  1974. }
  1975. negative = wasNegative ^ divisor.isNegative();
  1976. remainder.setNegative (wasNegative);
  1977. }
  1978. }
  1979. void BitArray::modulo (const BitArray& divisor) throw()
  1980. {
  1981. BitArray remainder;
  1982. divideBy (divisor, remainder);
  1983. *this = remainder;
  1984. }
  1985. static const BitArray simpleGCD (BitArray* m, BitArray* n) throw()
  1986. {
  1987. while (! m->isEmpty())
  1988. {
  1989. if (n->compareAbsolute (*m) > 0)
  1990. swapVariables (m, n);
  1991. m->subtract (*n);
  1992. }
  1993. return *n;
  1994. }
  1995. const BitArray BitArray::findGreatestCommonDivisor (BitArray n) const throw()
  1996. {
  1997. BitArray m (*this);
  1998. while (! n.isEmpty())
  1999. {
  2000. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  2001. return simpleGCD (&m, &n);
  2002. BitArray temp1 (m), temp2;
  2003. temp1.divideBy (n, temp2);
  2004. m = n;
  2005. n = temp2;
  2006. }
  2007. return m;
  2008. }
  2009. void BitArray::exponentModulo (const BitArray& exponent,
  2010. const BitArray& modulus) throw()
  2011. {
  2012. BitArray exp (exponent);
  2013. exp.modulo (modulus);
  2014. BitArray value (*this);
  2015. value.modulo (modulus);
  2016. clear();
  2017. setBit (0);
  2018. while (! exp.isEmpty())
  2019. {
  2020. if (exp [0])
  2021. {
  2022. multiplyBy (value);
  2023. this->modulo (modulus);
  2024. }
  2025. value.multiplyBy (value);
  2026. value.modulo (modulus);
  2027. exp.shiftBits (-1);
  2028. }
  2029. }
  2030. void BitArray::inverseModulo (const BitArray& modulus) throw()
  2031. {
  2032. const BitArray one (1);
  2033. if (modulus == one || modulus.isNegative())
  2034. {
  2035. clear();
  2036. return;
  2037. }
  2038. if (isNegative() || compareAbsolute (modulus) >= 0)
  2039. this->modulo (modulus);
  2040. if (*this == one)
  2041. return;
  2042. if (! (*this)[0])
  2043. {
  2044. // not invertible
  2045. clear();
  2046. return;
  2047. }
  2048. BitArray a1 (modulus);
  2049. BitArray a2 (*this);
  2050. BitArray b1 (modulus);
  2051. BitArray b2 (1);
  2052. while (a2 != one)
  2053. {
  2054. BitArray temp1, temp2, multiplier (a1);
  2055. multiplier.divideBy (a2, temp1);
  2056. temp1 = a2;
  2057. temp1.multiplyBy (multiplier);
  2058. temp2 = a1;
  2059. temp2.subtract (temp1);
  2060. a1 = a2;
  2061. a2 = temp2;
  2062. temp1 = b2;
  2063. temp1.multiplyBy (multiplier);
  2064. temp2 = b1;
  2065. temp2.subtract (temp1);
  2066. b1 = b2;
  2067. b2 = temp2;
  2068. }
  2069. while (b2.isNegative())
  2070. b2.add (modulus);
  2071. b2.modulo (modulus);
  2072. *this = b2;
  2073. }
  2074. void BitArray::shiftBits (int bits, const int startBit) throw()
  2075. {
  2076. if (highestBit < 0)
  2077. return;
  2078. if (startBit > 0)
  2079. {
  2080. if (bits < 0)
  2081. {
  2082. // right shift
  2083. for (int i = startBit; i <= highestBit; ++i)
  2084. setBit (i, operator[] (i - bits));
  2085. highestBit = getHighestBit();
  2086. }
  2087. else if (bits > 0)
  2088. {
  2089. // left shift
  2090. for (int i = highestBit + 1; --i >= startBit;)
  2091. setBit (i + bits, operator[] (i));
  2092. while (--bits >= 0)
  2093. clearBit (bits + startBit);
  2094. }
  2095. }
  2096. else
  2097. {
  2098. if (bits < 0)
  2099. {
  2100. // right shift
  2101. bits = -bits;
  2102. if (bits > highestBit)
  2103. {
  2104. clear();
  2105. }
  2106. else
  2107. {
  2108. const int wordsToMove = bits >> 5;
  2109. int top = 1 + (highestBit >> 5) - wordsToMove;
  2110. highestBit -= bits;
  2111. if (wordsToMove > 0)
  2112. {
  2113. int i;
  2114. for (i = 0; i < top; ++i)
  2115. values [i] = values [i + wordsToMove];
  2116. for (i = 0; i < wordsToMove; ++i)
  2117. values [top + i] = 0;
  2118. bits &= 31;
  2119. }
  2120. if (bits != 0)
  2121. {
  2122. const int invBits = 32 - bits;
  2123. --top;
  2124. for (int i = 0; i < top; ++i)
  2125. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2126. values[top] = (values[top] >> bits);
  2127. }
  2128. highestBit = getHighestBit();
  2129. }
  2130. }
  2131. else if (bits > 0)
  2132. {
  2133. // left shift
  2134. ensureSize (((highestBit + bits) >> 5) + 1);
  2135. const int wordsToMove = bits >> 5;
  2136. int top = 1 + (highestBit >> 5);
  2137. highestBit += bits;
  2138. if (wordsToMove > 0)
  2139. {
  2140. int i;
  2141. for (i = top; --i >= 0;)
  2142. values [i + wordsToMove] = values [i];
  2143. for (i = 0; i < wordsToMove; ++i)
  2144. values [i] = 0;
  2145. bits &= 31;
  2146. }
  2147. if (bits != 0)
  2148. {
  2149. const int invBits = 32 - bits;
  2150. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2151. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2152. values [wordsToMove] = values [wordsToMove] << bits;
  2153. }
  2154. highestBit = getHighestBit();
  2155. }
  2156. }
  2157. }
  2158. const BitArray BitArray::getBitRange (int startBit, int numBits) const throw()
  2159. {
  2160. BitArray r;
  2161. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  2162. r.ensureSize (numBits >> 5);
  2163. r.highestBit = numBits;
  2164. int i = 0;
  2165. while (numBits > 0)
  2166. {
  2167. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  2168. numBits -= 32;
  2169. startBit += 32;
  2170. }
  2171. r.highestBit = r.getHighestBit();
  2172. return r;
  2173. }
  2174. int BitArray::getBitRangeAsInt (const int startBit, int numBits) const throw()
  2175. {
  2176. if (numBits > 32)
  2177. {
  2178. jassertfalse // use getBitRange() if you need more than 32 bits..
  2179. numBits = 32;
  2180. }
  2181. numBits = jmin (numBits, highestBit + 1 - startBit);
  2182. if (numBits <= 0)
  2183. return 0;
  2184. const int pos = startBit >> 5;
  2185. const int offset = startBit & 31;
  2186. const int endSpace = 32 - numBits;
  2187. uint32 n = ((uint32) values [pos]) >> offset;
  2188. if (offset > endSpace)
  2189. n |= ((uint32) values [pos + 1]) << (32 - offset);
  2190. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  2191. }
  2192. void BitArray::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet) throw()
  2193. {
  2194. if (numBits > 32)
  2195. {
  2196. jassertfalse
  2197. numBits = 32;
  2198. }
  2199. for (int i = 0; i < numBits; ++i)
  2200. {
  2201. setBit (startBit + i, (valueToSet & 1) != 0);
  2202. valueToSet >>= 1;
  2203. }
  2204. }
  2205. bool BitArray::isNegative() const throw()
  2206. {
  2207. return negative && ! isEmpty();
  2208. }
  2209. void BitArray::setNegative (const bool neg) throw()
  2210. {
  2211. negative = neg;
  2212. }
  2213. void BitArray::negate() throw()
  2214. {
  2215. negative = (! negative) && ! isEmpty();
  2216. }
  2217. int BitArray::countNumberOfSetBits() const throw()
  2218. {
  2219. int total = 0;
  2220. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  2221. {
  2222. unsigned int n = values[i];
  2223. if (n == 0xffffffff)
  2224. {
  2225. total += 32;
  2226. }
  2227. else
  2228. {
  2229. while (n != 0)
  2230. {
  2231. total += (n & 1);
  2232. n >>= 1;
  2233. }
  2234. }
  2235. }
  2236. return total;
  2237. }
  2238. int BitArray::getHighestBit() const throw()
  2239. {
  2240. for (int i = highestBit + 1; --i >= 0;)
  2241. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2242. return i;
  2243. return -1;
  2244. }
  2245. int BitArray::findNextSetBit (int i) const throw()
  2246. {
  2247. for (; i <= highestBit; ++i)
  2248. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2249. return i;
  2250. return -1;
  2251. }
  2252. int BitArray::findNextClearBit (int i) const throw()
  2253. {
  2254. for (; i <= highestBit; ++i)
  2255. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  2256. break;
  2257. return i;
  2258. }
  2259. void BitArray::ensureSize (const int numVals) throw()
  2260. {
  2261. if (numVals + 2 >= numValues)
  2262. {
  2263. int oldSize = numValues;
  2264. numValues = ((numVals + 2) * 3) / 2;
  2265. values.realloc (numValues + 1);
  2266. while (oldSize < numValues)
  2267. values [oldSize++] = 0;
  2268. }
  2269. }
  2270. const String BitArray::toString (const int base, const int minimumNumCharacters) const throw()
  2271. {
  2272. String s;
  2273. BitArray v (*this);
  2274. if (base == 2 || base == 8 || base == 16)
  2275. {
  2276. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2277. static const tchar* const hexDigits = T("0123456789abcdef");
  2278. for (;;)
  2279. {
  2280. const int remainder = v.getBitRangeAsInt (0, bits);
  2281. v.shiftBits (-bits);
  2282. if (remainder == 0 && v.isEmpty())
  2283. break;
  2284. s = String::charToString (hexDigits [remainder]) + s;
  2285. }
  2286. }
  2287. else if (base == 10)
  2288. {
  2289. const BitArray ten (10);
  2290. BitArray remainder;
  2291. for (;;)
  2292. {
  2293. v.divideBy (ten, remainder);
  2294. if (remainder.isEmpty() && v.isEmpty())
  2295. break;
  2296. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2297. }
  2298. }
  2299. else
  2300. {
  2301. jassertfalse // can't do the specified base
  2302. return String::empty;
  2303. }
  2304. s = s.paddedLeft ('0', minimumNumCharacters);
  2305. return isNegative() ? T("-") + s : s;
  2306. }
  2307. void BitArray::parseString (const String& text,
  2308. const int base) throw()
  2309. {
  2310. clear();
  2311. const tchar* t = (const tchar*) text;
  2312. if (base == 2 || base == 8 || base == 16)
  2313. {
  2314. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2315. for (;;)
  2316. {
  2317. const tchar c = *t++;
  2318. const int digit = CharacterFunctions::getHexDigitValue (c);
  2319. if (((unsigned int) digit) < (unsigned int) base)
  2320. {
  2321. shiftBits (bits);
  2322. add (digit);
  2323. }
  2324. else if (c == 0)
  2325. {
  2326. break;
  2327. }
  2328. }
  2329. }
  2330. else if (base == 10)
  2331. {
  2332. const BitArray ten ((unsigned int) 10);
  2333. for (;;)
  2334. {
  2335. const tchar c = *t++;
  2336. if (c >= T('0') && c <= T('9'))
  2337. {
  2338. multiplyBy (ten);
  2339. add ((int) (c - T('0')));
  2340. }
  2341. else if (c == 0)
  2342. {
  2343. break;
  2344. }
  2345. }
  2346. }
  2347. setNegative (text.trimStart().startsWithChar (T('-')));
  2348. }
  2349. const MemoryBlock BitArray::toMemoryBlock() const throw()
  2350. {
  2351. const int numBytes = (getHighestBit() + 8) >> 3;
  2352. MemoryBlock mb ((size_t) numBytes);
  2353. for (int i = 0; i < numBytes; ++i)
  2354. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2355. return mb;
  2356. }
  2357. void BitArray::loadFromMemoryBlock (const MemoryBlock& data) throw()
  2358. {
  2359. clear();
  2360. for (int i = (int) data.getSize(); --i >= 0;)
  2361. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2362. }
  2363. END_JUCE_NAMESPACE
  2364. /*** End of inlined file: juce_BitArray.cpp ***/
  2365. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2366. BEGIN_JUCE_NAMESPACE
  2367. MemoryBlock::MemoryBlock() throw()
  2368. : size (0)
  2369. {
  2370. }
  2371. MemoryBlock::MemoryBlock (const size_t initialSize,
  2372. const bool initialiseToZero) throw()
  2373. {
  2374. if (initialSize > 0)
  2375. {
  2376. size = initialSize;
  2377. data.allocate (initialSize, initialiseToZero);
  2378. }
  2379. else
  2380. {
  2381. size = 0;
  2382. }
  2383. }
  2384. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2385. : size (other.size)
  2386. {
  2387. if (size > 0)
  2388. {
  2389. jassert (other.data != 0);
  2390. data.malloc (size);
  2391. memcpy (data, other.data, size);
  2392. }
  2393. }
  2394. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2395. const size_t sizeInBytes) throw()
  2396. : size (jmax ((size_t) 0, sizeInBytes))
  2397. {
  2398. jassert (sizeInBytes >= 0);
  2399. if (size > 0)
  2400. {
  2401. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2402. data.malloc (size);
  2403. if (dataToInitialiseFrom != 0)
  2404. memcpy (data, dataToInitialiseFrom, size);
  2405. }
  2406. }
  2407. MemoryBlock::~MemoryBlock() throw()
  2408. {
  2409. jassert (size >= 0); // should never happen
  2410. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2411. }
  2412. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2413. {
  2414. if (this != &other)
  2415. {
  2416. setSize (other.size, false);
  2417. memcpy (data, other.data, size);
  2418. }
  2419. return *this;
  2420. }
  2421. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2422. {
  2423. return matches (other.data, other.size);
  2424. }
  2425. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2426. {
  2427. return ! operator== (other);
  2428. }
  2429. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2430. {
  2431. return size == dataSize
  2432. && memcmp (data, dataToCompare, size) == 0;
  2433. }
  2434. // this will resize the block to this size
  2435. void MemoryBlock::setSize (const size_t newSize,
  2436. const bool initialiseToZero) throw()
  2437. {
  2438. if (size != newSize)
  2439. {
  2440. if (newSize <= 0)
  2441. {
  2442. data.free();
  2443. size = 0;
  2444. }
  2445. else
  2446. {
  2447. if (data != 0)
  2448. {
  2449. data.realloc (newSize);
  2450. if (initialiseToZero && (newSize > size))
  2451. zeromem (data + size, newSize - size);
  2452. }
  2453. else
  2454. {
  2455. data.allocate (newSize, initialiseToZero);
  2456. }
  2457. size = newSize;
  2458. }
  2459. }
  2460. }
  2461. void MemoryBlock::ensureSize (const size_t minimumSize,
  2462. const bool initialiseToZero) throw()
  2463. {
  2464. if (size < minimumSize)
  2465. setSize (minimumSize, initialiseToZero);
  2466. }
  2467. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2468. {
  2469. swapVariables (size, other.size);
  2470. data.swapWith (other.data);
  2471. }
  2472. void MemoryBlock::fillWith (const uint8 value) throw()
  2473. {
  2474. memset (data, (int) value, size);
  2475. }
  2476. void MemoryBlock::append (const void* const srcData,
  2477. const size_t numBytes) throw()
  2478. {
  2479. if (numBytes > 0)
  2480. {
  2481. const size_t oldSize = size;
  2482. setSize (size + numBytes);
  2483. memcpy (data + oldSize, srcData, numBytes);
  2484. }
  2485. }
  2486. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2487. {
  2488. const char* d = static_cast<const char*> (src);
  2489. if (offset < 0)
  2490. {
  2491. d -= offset;
  2492. num -= offset;
  2493. offset = 0;
  2494. }
  2495. if (offset + num > size)
  2496. num = size - offset;
  2497. if (num > 0)
  2498. memcpy (data + offset, d, num);
  2499. }
  2500. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2501. {
  2502. char* d = static_cast<char*> (dst);
  2503. if (offset < 0)
  2504. {
  2505. zeromem (d, -offset);
  2506. d -= offset;
  2507. num += offset;
  2508. offset = 0;
  2509. }
  2510. if (offset + num > size)
  2511. {
  2512. const size_t newNum = size - offset;
  2513. zeromem (d + newNum, num - newNum);
  2514. num = newNum;
  2515. }
  2516. if (num > 0)
  2517. memcpy (d, data + offset, num);
  2518. }
  2519. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2520. {
  2521. if (startByte < 0)
  2522. {
  2523. numBytesToRemove += startByte;
  2524. startByte = 0;
  2525. }
  2526. if (startByte + numBytesToRemove >= size)
  2527. {
  2528. setSize (startByte);
  2529. }
  2530. else if (numBytesToRemove > 0)
  2531. {
  2532. memmove (data + startByte,
  2533. data + startByte + numBytesToRemove,
  2534. size - (startByte + numBytesToRemove));
  2535. setSize (size - numBytesToRemove);
  2536. }
  2537. }
  2538. const String MemoryBlock::toString() const throw()
  2539. {
  2540. return String ((const char*) data, size);
  2541. }
  2542. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2543. {
  2544. int res = 0;
  2545. size_t byte = bitRangeStart >> 3;
  2546. int offsetInByte = (int) bitRangeStart & 7;
  2547. size_t bitsSoFar = 0;
  2548. while (numBits > 0 && (size_t) byte < size)
  2549. {
  2550. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2551. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2552. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2553. bitsSoFar += bitsThisTime;
  2554. numBits -= bitsThisTime;
  2555. ++byte;
  2556. offsetInByte = 0;
  2557. }
  2558. return res;
  2559. }
  2560. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2561. {
  2562. size_t byte = bitRangeStart >> 3;
  2563. int offsetInByte = (int) bitRangeStart & 7;
  2564. unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2565. while (numBits > 0 && (size_t) byte < size)
  2566. {
  2567. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2568. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte);
  2569. const unsigned int tempBits = bitsToSet << offsetInByte;
  2570. data[byte] = (char) ((data[byte] & tempMask) | tempBits);
  2571. ++byte;
  2572. numBits -= bitsThisTime;
  2573. bitsToSet >>= bitsThisTime;
  2574. mask >>= bitsThisTime;
  2575. offsetInByte = 0;
  2576. }
  2577. }
  2578. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2579. {
  2580. ensureSize (hex.length() >> 1);
  2581. char* dest = data;
  2582. int i = 0;
  2583. for (;;)
  2584. {
  2585. int byte = 0;
  2586. for (int loop = 2; --loop >= 0;)
  2587. {
  2588. byte <<= 4;
  2589. for (;;)
  2590. {
  2591. const juce_wchar c = hex [i++];
  2592. if (c >= T('0') && c <= T('9'))
  2593. {
  2594. byte |= c - T('0');
  2595. break;
  2596. }
  2597. else if (c >= T('a') && c <= T('z'))
  2598. {
  2599. byte |= c - (T('a') - 10);
  2600. break;
  2601. }
  2602. else if (c >= T('A') && c <= T('Z'))
  2603. {
  2604. byte |= c - (T('A') - 10);
  2605. break;
  2606. }
  2607. else if (c == 0)
  2608. {
  2609. setSize (static_cast <size_t> (dest - data));
  2610. return;
  2611. }
  2612. }
  2613. }
  2614. *dest++ = (char) byte;
  2615. }
  2616. }
  2617. static const char* const encodingTable
  2618. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2619. const String MemoryBlock::toBase64Encoding() const throw()
  2620. {
  2621. const size_t numChars = ((size << 3) + 5) / 6;
  2622. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2623. const int initialLen = destString.length();
  2624. destString.preallocateStorage (initialLen + 2 + numChars);
  2625. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2626. *d++ = T('.');
  2627. for (size_t i = 0; i < numChars; ++i)
  2628. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2629. *d++ = 0;
  2630. return destString;
  2631. }
  2632. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2633. {
  2634. const int startPos = s.indexOfChar (T('.')) + 1;
  2635. if (startPos <= 0)
  2636. return false;
  2637. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2638. setSize (numBytesNeeded, true);
  2639. const int numChars = s.length() - startPos;
  2640. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2641. int pos = 0;
  2642. for (int i = 0; i < numChars; ++i)
  2643. {
  2644. const char c = (char) srcChars[i];
  2645. for (int j = 0; j < 64; ++j)
  2646. {
  2647. if (encodingTable[j] == c)
  2648. {
  2649. setBitRange (pos, 6, j);
  2650. pos += 6;
  2651. break;
  2652. }
  2653. }
  2654. }
  2655. return true;
  2656. }
  2657. END_JUCE_NAMESPACE
  2658. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2659. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2660. BEGIN_JUCE_NAMESPACE
  2661. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2662. : properties (ignoreCaseOfKeyNames),
  2663. fallbackProperties (0),
  2664. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2665. {
  2666. }
  2667. PropertySet::PropertySet (const PropertySet& other) throw()
  2668. : properties (other.properties),
  2669. fallbackProperties (other.fallbackProperties),
  2670. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2671. {
  2672. }
  2673. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2674. {
  2675. properties = other.properties;
  2676. fallbackProperties = other.fallbackProperties;
  2677. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2678. propertyChanged();
  2679. return *this;
  2680. }
  2681. PropertySet::~PropertySet()
  2682. {
  2683. }
  2684. void PropertySet::clear()
  2685. {
  2686. const ScopedLock sl (lock);
  2687. if (properties.size() > 0)
  2688. {
  2689. properties.clear();
  2690. propertyChanged();
  2691. }
  2692. }
  2693. const String PropertySet::getValue (const String& keyName,
  2694. const String& defaultValue) const throw()
  2695. {
  2696. const ScopedLock sl (lock);
  2697. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2698. if (index >= 0)
  2699. return properties.getAllValues() [index];
  2700. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2701. : defaultValue;
  2702. }
  2703. int PropertySet::getIntValue (const String& keyName,
  2704. const int defaultValue) const throw()
  2705. {
  2706. const ScopedLock sl (lock);
  2707. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2708. if (index >= 0)
  2709. return properties.getAllValues() [index].getIntValue();
  2710. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2711. : defaultValue;
  2712. }
  2713. double PropertySet::getDoubleValue (const String& keyName,
  2714. const double defaultValue) const throw()
  2715. {
  2716. const ScopedLock sl (lock);
  2717. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2718. if (index >= 0)
  2719. return properties.getAllValues()[index].getDoubleValue();
  2720. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2721. : defaultValue;
  2722. }
  2723. bool PropertySet::getBoolValue (const String& keyName,
  2724. const bool defaultValue) const throw()
  2725. {
  2726. const ScopedLock sl (lock);
  2727. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2728. if (index >= 0)
  2729. return properties.getAllValues() [index].getIntValue() != 0;
  2730. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2731. : defaultValue;
  2732. }
  2733. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2734. {
  2735. XmlDocument doc (getValue (keyName));
  2736. return doc.getDocumentElement();
  2737. }
  2738. void PropertySet::setValue (const String& keyName,
  2739. const String& value) throw()
  2740. {
  2741. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2742. if (keyName.isNotEmpty())
  2743. {
  2744. const ScopedLock sl (lock);
  2745. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2746. if (index < 0 || properties.getAllValues() [index] != value)
  2747. {
  2748. properties.set (keyName, value);
  2749. propertyChanged();
  2750. }
  2751. }
  2752. }
  2753. void PropertySet::removeValue (const String& keyName) throw()
  2754. {
  2755. if (keyName.isNotEmpty())
  2756. {
  2757. const ScopedLock sl (lock);
  2758. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2759. if (index >= 0)
  2760. {
  2761. properties.remove (keyName);
  2762. propertyChanged();
  2763. }
  2764. }
  2765. }
  2766. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2767. {
  2768. setValue (keyName, String (value));
  2769. }
  2770. void PropertySet::setValue (const String& keyName, const int value) throw()
  2771. {
  2772. setValue (keyName, String (value));
  2773. }
  2774. void PropertySet::setValue (const String& keyName, const double value) throw()
  2775. {
  2776. setValue (keyName, String (value));
  2777. }
  2778. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2779. {
  2780. setValue (keyName, String ((value) ? T("1") : T("0")));
  2781. }
  2782. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2783. {
  2784. setValue (keyName, (xml == 0) ? String::empty
  2785. : xml->createDocument (String::empty, true));
  2786. }
  2787. bool PropertySet::containsKey (const String& keyName) const throw()
  2788. {
  2789. const ScopedLock sl (lock);
  2790. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2791. }
  2792. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2793. {
  2794. const ScopedLock sl (lock);
  2795. fallbackProperties = fallbackProperties_;
  2796. }
  2797. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2798. {
  2799. const ScopedLock sl (lock);
  2800. XmlElement* const xml = new XmlElement (nodeName);
  2801. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2802. {
  2803. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2804. e->setAttribute (T("name"), properties.getAllKeys()[i]);
  2805. e->setAttribute (T("val"), properties.getAllValues()[i]);
  2806. }
  2807. return xml;
  2808. }
  2809. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2810. {
  2811. const ScopedLock sl (lock);
  2812. clear();
  2813. forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
  2814. {
  2815. if (e->hasAttribute (T("name"))
  2816. && e->hasAttribute (T("val")))
  2817. {
  2818. properties.set (e->getStringAttribute (T("name")),
  2819. e->getStringAttribute (T("val")));
  2820. }
  2821. }
  2822. if (properties.size() > 0)
  2823. propertyChanged();
  2824. }
  2825. void PropertySet::propertyChanged()
  2826. {
  2827. }
  2828. END_JUCE_NAMESPACE
  2829. /*** End of inlined file: juce_PropertySet.cpp ***/
  2830. /*** Start of inlined file: juce_Variant.cpp ***/
  2831. BEGIN_JUCE_NAMESPACE
  2832. var::var() throw()
  2833. : type (voidType)
  2834. {
  2835. value.doubleValue = 0;
  2836. }
  2837. var::~var() throw()
  2838. {
  2839. if (type == stringType)
  2840. delete value.stringValue;
  2841. else if (type == objectType && value.objectValue != 0)
  2842. value.objectValue->decReferenceCount();
  2843. }
  2844. const var var::null;
  2845. var::var (const var& valueToCopy)
  2846. : type (valueToCopy.type),
  2847. value (valueToCopy.value)
  2848. {
  2849. if (type == stringType)
  2850. value.stringValue = new String (*(value.stringValue));
  2851. else if (type == objectType && value.objectValue != 0)
  2852. value.objectValue->incReferenceCount();
  2853. }
  2854. var::var (const int value_) throw()
  2855. : type (intType)
  2856. {
  2857. value.intValue = value_;
  2858. }
  2859. var::var (const bool value_) throw()
  2860. : type (boolType)
  2861. {
  2862. value.boolValue = value_;
  2863. }
  2864. var::var (const double value_) throw()
  2865. : type (doubleType)
  2866. {
  2867. value.doubleValue = value_;
  2868. }
  2869. var::var (const String& value_)
  2870. : type (stringType)
  2871. {
  2872. value.stringValue = new String (value_);
  2873. }
  2874. var::var (const char* const value_)
  2875. : type (stringType)
  2876. {
  2877. value.stringValue = new String (value_);
  2878. }
  2879. var::var (const juce_wchar* const value_)
  2880. : type (stringType)
  2881. {
  2882. value.stringValue = new String (value_);
  2883. }
  2884. var::var (DynamicObject* const object)
  2885. : type (objectType)
  2886. {
  2887. value.objectValue = object;
  2888. if (object != 0)
  2889. object->incReferenceCount();
  2890. }
  2891. var::var (MethodFunction method_) throw()
  2892. : type (methodType)
  2893. {
  2894. value.methodValue = method_;
  2895. }
  2896. void var::swapWith (var& other) throw()
  2897. {
  2898. swapVariables (type, other.type);
  2899. swapVariables (value, other.value);
  2900. }
  2901. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2902. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2903. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2904. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2905. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2906. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2907. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2908. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2909. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2910. var::operator int() const
  2911. {
  2912. switch (type)
  2913. {
  2914. case voidType: break;
  2915. case intType: return value.intValue;
  2916. case boolType: return value.boolValue ? 1 : 0;
  2917. case doubleType: return static_cast <int> (value.doubleValue);
  2918. case stringType: return value.stringValue->getIntValue();
  2919. case objectType: break;
  2920. default: jassertfalse; break;
  2921. }
  2922. return 0;
  2923. }
  2924. var::operator bool() const
  2925. {
  2926. switch (type)
  2927. {
  2928. case voidType: break;
  2929. case intType: return value.intValue != 0;
  2930. case boolType: return value.boolValue;
  2931. case doubleType: return value.doubleValue != 0;
  2932. case stringType: return value.stringValue->getIntValue() != 0
  2933. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2934. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2935. case objectType: return value.objectValue != 0;
  2936. default: jassertfalse; break;
  2937. }
  2938. return false;
  2939. }
  2940. var::operator float() const
  2941. {
  2942. return (float) operator double();
  2943. }
  2944. var::operator double() const
  2945. {
  2946. switch (type)
  2947. {
  2948. case voidType: break;
  2949. case intType: return value.intValue;
  2950. case boolType: return value.boolValue ? 1.0 : 0.0;
  2951. case doubleType: return value.doubleValue;
  2952. case stringType: return value.stringValue->getDoubleValue();
  2953. case objectType: break;
  2954. default: jassertfalse; break;
  2955. }
  2956. return 0.0;
  2957. }
  2958. const String var::toString() const
  2959. {
  2960. switch (type)
  2961. {
  2962. case voidType: return String::empty;
  2963. case intType: return String (value.intValue);
  2964. case boolType: return value.boolValue ? T("1") : T("0");
  2965. case doubleType: return String (value.doubleValue);
  2966. case stringType: return *(value.stringValue);
  2967. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  2968. case methodType: return "Method";
  2969. default: jassertfalse; break;
  2970. }
  2971. return String::empty;
  2972. }
  2973. var::operator const String() const
  2974. {
  2975. return toString();
  2976. }
  2977. DynamicObject* var::getObject() const
  2978. {
  2979. return type == objectType ? value.objectValue : 0;
  2980. }
  2981. bool var::equals (const var& other) const throw()
  2982. {
  2983. switch (type)
  2984. {
  2985. case voidType: return other.isVoid();
  2986. case intType: return value.intValue == static_cast <int> (other);
  2987. case boolType: return value.boolValue == static_cast <bool> (other);
  2988. case doubleType: return value.doubleValue == static_cast <double> (other);
  2989. case stringType: return (*(value.stringValue)) == other.toString();
  2990. case objectType: return value.objectValue == other.getObject();
  2991. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  2992. default: jassertfalse; break;
  2993. }
  2994. return false;
  2995. }
  2996. bool operator== (const var& v1, const var& v2) throw() { return v1.equals (v2); }
  2997. bool operator!= (const var& v1, const var& v2) throw() { return ! v1.equals (v2); }
  2998. bool operator== (const var& v1, const String& v2) throw() { return v1.toString() == v2; }
  2999. bool operator!= (const var& v1, const String& v2) throw() { return v1.toString() != v2; }
  3000. void var::writeToStream (OutputStream& output) const
  3001. {
  3002. switch (type)
  3003. {
  3004. case voidType: output.writeCompressedInt (0); break;
  3005. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  3006. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  3007. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  3008. case stringType:
  3009. {
  3010. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  3011. output.writeCompressedInt (len + 1);
  3012. output.writeByte (5);
  3013. HeapBlock<char> temp (len);
  3014. value.stringValue->copyToUTF8 (temp, len);
  3015. output.write (temp, len);
  3016. break;
  3017. }
  3018. case objectType:
  3019. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3020. default: jassertfalse; break; // Is this a corrupted object?
  3021. }
  3022. }
  3023. const var var::readFromStream (InputStream& input)
  3024. {
  3025. const int numBytes = input.readCompressedInt();
  3026. if (numBytes > 0)
  3027. {
  3028. switch (input.readByte())
  3029. {
  3030. case 1: return var (input.readInt());
  3031. case 2: return var (true);
  3032. case 3: return var (false);
  3033. case 4: return var (input.readDouble());
  3034. case 5:
  3035. {
  3036. MemoryBlock mb;
  3037. input.readIntoMemoryBlock (mb, numBytes - 1);
  3038. return var (String::fromUTF8 ((const char*) mb.getData(), (int) mb.getSize()));
  3039. }
  3040. default: input.skipNextBytes (numBytes - 1); break;
  3041. }
  3042. }
  3043. return var::null;
  3044. }
  3045. const var var::operator[] (const var::identifier& propertyName) const
  3046. {
  3047. if (type == objectType && value.objectValue != 0)
  3048. return value.objectValue->getProperty (propertyName);
  3049. return var::null;
  3050. }
  3051. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3052. {
  3053. if (type == objectType && value.objectValue != 0)
  3054. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3055. return var::null;
  3056. }
  3057. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3058. {
  3059. if (isMethod())
  3060. {
  3061. DynamicObject* const target = targetObject.getObject();
  3062. if (target != 0)
  3063. return (target->*(value.methodValue)) (arguments, numArguments);
  3064. }
  3065. return var::null;
  3066. }
  3067. const var var::call (const var::identifier& method) const
  3068. {
  3069. return invoke (method, 0, 0);
  3070. }
  3071. const var var::call (const var::identifier& method, const var& arg1) const
  3072. {
  3073. return invoke (method, &arg1, 1);
  3074. }
  3075. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3076. {
  3077. var args[] = { arg1, arg2 };
  3078. return invoke (method, args, 2);
  3079. }
  3080. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3081. {
  3082. var args[] = { arg1, arg2, arg3 };
  3083. return invoke (method, args, 3);
  3084. }
  3085. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3086. {
  3087. var args[] = { arg1, arg2, arg3, arg4 };
  3088. return invoke (method, args, 4);
  3089. }
  3090. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3091. {
  3092. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3093. return invoke (method, args, 5);
  3094. }
  3095. var::identifier::identifier() throw()
  3096. : hashCode (0)
  3097. {
  3098. }
  3099. var::identifier::identifier (const String& name_)
  3100. : name (name_),
  3101. hashCode (name_.hashCode())
  3102. {
  3103. /* An identifier string must be suitable for use as a script variable or XML
  3104. attribute, so it can only contain this limited set of characters.. */
  3105. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3106. }
  3107. var::identifier::identifier (const char* const name_)
  3108. : name (name_),
  3109. hashCode (name.hashCode())
  3110. {
  3111. /* An identifier string must be suitable for use as a script variable or XML
  3112. attribute, so it can only contain this limited set of characters.. */
  3113. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3114. }
  3115. var::identifier::~identifier()
  3116. {
  3117. }
  3118. END_JUCE_NAMESPACE
  3119. /*** End of inlined file: juce_Variant.cpp ***/
  3120. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3121. BEGIN_JUCE_NAMESPACE
  3122. NamedValueSet::NamedValue::NamedValue() throw()
  3123. {
  3124. }
  3125. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3126. : name (name_), value (value_)
  3127. {
  3128. }
  3129. NamedValueSet::NamedValueSet() throw()
  3130. {
  3131. }
  3132. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3133. : values (other.values)
  3134. {
  3135. }
  3136. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3137. {
  3138. values = other.values;
  3139. return *this;
  3140. }
  3141. NamedValueSet::~NamedValueSet()
  3142. {
  3143. }
  3144. int NamedValueSet::size() const throw()
  3145. {
  3146. return values.size();
  3147. }
  3148. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3149. {
  3150. for (int i = values.size(); --i >= 0;)
  3151. {
  3152. const NamedValue& v = values.getReference(i);
  3153. if (v.name == name)
  3154. return v.value;
  3155. }
  3156. return var::null;
  3157. }
  3158. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3159. {
  3160. const var* v = getItem (name);
  3161. return v != 0 ? *v : defaultReturnValue;
  3162. }
  3163. var* NamedValueSet::getItem (const var::identifier& name) const
  3164. {
  3165. for (int i = values.size(); --i >= 0;)
  3166. {
  3167. NamedValue& v = values.getReference(i);
  3168. if (v.name == name)
  3169. return &(v.value);
  3170. }
  3171. return 0;
  3172. }
  3173. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3174. {
  3175. for (int i = values.size(); --i >= 0;)
  3176. {
  3177. NamedValue& v = values.getReference(i);
  3178. if (v.name == name)
  3179. {
  3180. if (v.value == newValue)
  3181. return false;
  3182. v.value = newValue;
  3183. return true;
  3184. }
  3185. }
  3186. values.add (NamedValue (name, newValue));
  3187. return true;
  3188. }
  3189. bool NamedValueSet::contains (const var::identifier& name) const
  3190. {
  3191. return getItem (name) != 0;
  3192. }
  3193. bool NamedValueSet::remove (const var::identifier& name)
  3194. {
  3195. for (int i = values.size(); --i >= 0;)
  3196. {
  3197. if (values.getReference(i).name == name)
  3198. {
  3199. values.remove (i);
  3200. return true;
  3201. }
  3202. }
  3203. return false;
  3204. }
  3205. const var::identifier NamedValueSet::getName (int index) const
  3206. {
  3207. jassert (((unsigned int) index) < (unsigned int) values.size());
  3208. return values [index].name;
  3209. }
  3210. void NamedValueSet::clear()
  3211. {
  3212. values.clear();
  3213. }
  3214. END_JUCE_NAMESPACE
  3215. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3216. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3217. BEGIN_JUCE_NAMESPACE
  3218. DynamicObject::DynamicObject()
  3219. {
  3220. }
  3221. DynamicObject::~DynamicObject()
  3222. {
  3223. }
  3224. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3225. {
  3226. var* const v = properties.getItem (propertyName);
  3227. return v != 0 && ! v->isMethod();
  3228. }
  3229. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3230. {
  3231. return properties [propertyName];
  3232. }
  3233. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3234. {
  3235. properties.set (propertyName, newValue);
  3236. }
  3237. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3238. {
  3239. properties.remove (propertyName);
  3240. }
  3241. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3242. {
  3243. return getProperty (methodName).isMethod();
  3244. }
  3245. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3246. const var* parameters,
  3247. int numParameters)
  3248. {
  3249. return properties [methodName].invoke (var (this), parameters, numParameters);
  3250. }
  3251. void DynamicObject::setMethod (const var::identifier& name,
  3252. var::MethodFunction methodFunction)
  3253. {
  3254. properties.set (name, var (methodFunction));
  3255. }
  3256. void DynamicObject::clear()
  3257. {
  3258. properties.clear();
  3259. }
  3260. END_JUCE_NAMESPACE
  3261. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3262. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3263. BEGIN_JUCE_NAMESPACE
  3264. static const uint32 initialPValues [18] =
  3265. {
  3266. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
  3267. 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3268. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
  3269. 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3270. 0x9216d5d9, 0x8979fb1b
  3271. };
  3272. static const uint32 initialSValues [4 * 256] =
  3273. {
  3274. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
  3275. 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3276. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
  3277. 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3278. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
  3279. 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3280. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
  3281. 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3282. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
  3283. 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3284. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
  3285. 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3286. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
  3287. 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3288. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
  3289. 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3290. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
  3291. 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3292. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
  3293. 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3294. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
  3295. 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3296. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
  3297. 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3298. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
  3299. 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3300. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
  3301. 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3302. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
  3303. 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3304. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
  3305. 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3306. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
  3307. 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3308. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
  3309. 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3310. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
  3311. 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3312. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
  3313. 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3314. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
  3315. 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3316. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
  3317. 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3318. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
  3319. 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3320. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
  3321. 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3322. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
  3323. 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3324. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
  3325. 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3326. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
  3327. 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3328. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
  3329. 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3330. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
  3331. 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3332. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
  3333. 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3334. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
  3335. 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3336. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
  3337. 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3338. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
  3339. 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3340. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
  3341. 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3342. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
  3343. 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3344. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
  3345. 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3346. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
  3347. 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3348. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
  3349. 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3350. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
  3351. 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3352. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
  3353. 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3354. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
  3355. 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3356. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
  3357. 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3358. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
  3359. 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3360. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
  3361. 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3362. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
  3363. 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3364. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
  3365. 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3366. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
  3367. 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3368. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
  3369. 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3370. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
  3371. 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3372. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
  3373. 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3374. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
  3375. 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3376. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
  3377. 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3378. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
  3379. 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3380. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
  3381. 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3382. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
  3383. 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3384. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
  3385. 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3386. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
  3387. 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3388. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
  3389. 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3390. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
  3391. 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3392. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
  3393. 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3394. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
  3395. 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3396. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
  3397. 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3398. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
  3399. 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3400. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
  3401. 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3402. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
  3403. 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3404. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
  3405. 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3406. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
  3407. 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3408. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
  3409. 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3410. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
  3411. 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3412. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
  3413. 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3414. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
  3415. 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3416. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
  3417. 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3418. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
  3419. 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3420. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
  3421. 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3422. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
  3423. 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3424. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
  3425. 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3426. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
  3427. 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3428. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
  3429. 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3430. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
  3431. 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3432. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
  3433. 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3434. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
  3435. 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3436. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
  3437. 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3438. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
  3439. 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3440. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
  3441. 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3442. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
  3443. 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3444. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
  3445. 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3446. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
  3447. 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3448. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
  3449. 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3450. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
  3451. 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3452. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
  3453. 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3454. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
  3455. 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3456. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
  3457. 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3458. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
  3459. 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3460. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
  3461. 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3462. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
  3463. 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3464. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
  3465. 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3466. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
  3467. 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3468. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
  3469. 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3470. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
  3471. 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3472. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
  3473. 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3474. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
  3475. 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3476. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
  3477. 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3478. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
  3479. 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3480. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
  3481. 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3482. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
  3483. 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3484. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
  3485. 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3486. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
  3487. 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3488. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
  3489. 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3490. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
  3491. 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3492. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
  3493. 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3494. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
  3495. 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3496. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
  3497. 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3498. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
  3499. 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3500. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
  3501. 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3502. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
  3503. 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3504. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
  3505. 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3506. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
  3507. 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3508. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
  3509. 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3510. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
  3511. 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3512. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
  3513. 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3514. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
  3515. 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3516. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
  3517. 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3518. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
  3519. 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3520. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
  3521. 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3522. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
  3523. 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3524. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
  3525. 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3526. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
  3527. 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3528. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
  3529. 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3530. };
  3531. BlowFish::BlowFish (const uint8* keyData, int keyBytes)
  3532. {
  3533. memcpy (p, initialPValues, sizeof (p));
  3534. int i, j;
  3535. for (i = 4; --i >= 0;)
  3536. {
  3537. s[i].malloc (256);
  3538. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3539. }
  3540. j = 0;
  3541. for (i = 0; i < 18; ++i)
  3542. {
  3543. uint32 d = 0;
  3544. for (int k = 0; k < 4; ++k)
  3545. {
  3546. d = (d << 8) | keyData[j];
  3547. if (++j >= keyBytes)
  3548. j = 0;
  3549. }
  3550. p[i] = initialPValues[i] ^ d;
  3551. }
  3552. uint32 l = 0, r = 0;
  3553. for (i = 0; i < 18; i += 2)
  3554. {
  3555. encrypt (l, r);
  3556. p[i] = l;
  3557. p[i + 1] = r;
  3558. }
  3559. for (i = 0; i < 4; ++i)
  3560. {
  3561. for (j = 0; j < 256; j += 2)
  3562. {
  3563. encrypt (l, r);
  3564. s[i][j] = l;
  3565. s[i][j + 1] = r;
  3566. }
  3567. }
  3568. }
  3569. BlowFish::BlowFish (const BlowFish& other)
  3570. {
  3571. for (int i = 4; --i >= 0;)
  3572. s[i].malloc (256);
  3573. operator= (other);
  3574. }
  3575. BlowFish& BlowFish::operator= (const BlowFish& other)
  3576. {
  3577. memcpy (p, other.p, sizeof (p));
  3578. for (int i = 4; --i >= 0;)
  3579. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3580. return *this;
  3581. }
  3582. BlowFish::~BlowFish()
  3583. {
  3584. }
  3585. uint32 BlowFish::F (uint32 x) const
  3586. {
  3587. uint16 a, b, c, d;
  3588. uint32 y;
  3589. d = (uint16) (x & 0xff);
  3590. x >>= 8;
  3591. c = (uint16) (x & 0xff);
  3592. x >>= 8;
  3593. b = (uint16) (x & 0xff);
  3594. x >>= 8;
  3595. a = (uint16) (x & 0xff);
  3596. y = s[0][a] + s[1][b];
  3597. y = y ^ s[2][c];
  3598. y = y + s[3][d];
  3599. return y;
  3600. }
  3601. void BlowFish::encrypt (uint32& data1,
  3602. uint32& data2) const
  3603. {
  3604. uint32 l = data1;
  3605. uint32 r = data2;
  3606. for (int i = 0; i < 16; ++i)
  3607. {
  3608. l = l ^ p[i];
  3609. r = F (l) ^ r;
  3610. const uint32 temp = l;
  3611. l = r;
  3612. r = temp;
  3613. }
  3614. const uint32 temp = l;
  3615. l = r;
  3616. r = temp;
  3617. r = r ^ p[16];
  3618. l = l ^ p[17];
  3619. data1 = l;
  3620. data2 = r;
  3621. }
  3622. void BlowFish::decrypt (uint32& data1,
  3623. uint32& data2) const
  3624. {
  3625. uint32 l = data1;
  3626. uint32 r = data2;
  3627. for (int i = 17; i > 1; --i)
  3628. {
  3629. l =l ^ p[i];
  3630. r = F (l) ^ r;
  3631. const uint32 temp = l;
  3632. l = r;
  3633. r = temp;
  3634. }
  3635. const uint32 temp = l;
  3636. l = r;
  3637. r = temp;
  3638. r = r ^ p[1];
  3639. l = l ^ p[0];
  3640. data1 = l;
  3641. data2 = r;
  3642. }
  3643. END_JUCE_NAMESPACE
  3644. /*** End of inlined file: juce_BlowFish.cpp ***/
  3645. /*** Start of inlined file: juce_MD5.cpp ***/
  3646. BEGIN_JUCE_NAMESPACE
  3647. MD5::MD5()
  3648. {
  3649. zerostruct (result);
  3650. }
  3651. MD5::MD5 (const MD5& other)
  3652. {
  3653. memcpy (result, other.result, sizeof (result));
  3654. }
  3655. MD5& MD5::operator= (const MD5& other)
  3656. {
  3657. memcpy (result, other.result, sizeof (result));
  3658. return *this;
  3659. }
  3660. MD5::MD5 (const MemoryBlock& data)
  3661. {
  3662. ProcessContext context;
  3663. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3664. context.finish (result);
  3665. }
  3666. MD5::MD5 (const char* data, const size_t numBytes)
  3667. {
  3668. ProcessContext context;
  3669. context.processBlock ((const uint8*) data, numBytes);
  3670. context.finish (result);
  3671. }
  3672. MD5::MD5 (const String& text)
  3673. {
  3674. ProcessContext context;
  3675. const int len = text.length();
  3676. const juce_wchar* const t = text;
  3677. for (int i = 0; i < len; ++i)
  3678. {
  3679. // force the string into integer-sized unicode characters, to try to make it
  3680. // get the same results on all platforms + compilers.
  3681. uint32 unicodeChar = (uint32) t[i];
  3682. ByteOrder::swapIfBigEndian (unicodeChar);
  3683. context.processBlock ((const uint8*) &unicodeChar,
  3684. sizeof (unicodeChar));
  3685. }
  3686. context.finish (result);
  3687. }
  3688. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3689. {
  3690. ProcessContext context;
  3691. if (numBytesToRead < 0)
  3692. numBytesToRead = std::numeric_limits<int64>::max();
  3693. while (numBytesToRead > 0)
  3694. {
  3695. char tempBuffer [512];
  3696. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3697. if (bytesRead <= 0)
  3698. break;
  3699. numBytesToRead -= bytesRead;
  3700. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3701. }
  3702. context.finish (result);
  3703. }
  3704. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3705. {
  3706. processStream (input, numBytesToRead);
  3707. }
  3708. MD5::MD5 (const File& file)
  3709. {
  3710. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3711. if (fin != 0)
  3712. processStream (*fin, -1);
  3713. else
  3714. zerostruct (result);
  3715. }
  3716. MD5::~MD5()
  3717. {
  3718. }
  3719. namespace MD5Functions
  3720. {
  3721. static void encode (uint8* const output, const uint32* const input, const int numBytes) throw()
  3722. {
  3723. uint32* const o = (uint32*) output;
  3724. for (int i = 0; i < (numBytes >> 2); ++i)
  3725. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3726. }
  3727. static void decode (uint32* const output, const uint8* const input, const int numBytes) throw()
  3728. {
  3729. for (int i = 0; i < (numBytes >> 2); ++i)
  3730. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3731. }
  3732. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3733. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3734. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3735. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3736. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3737. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3738. {
  3739. a += F (b, c, d) + x + ac;
  3740. a = rotateLeft (a, s) + b;
  3741. }
  3742. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3743. {
  3744. a += G (b, c, d) + x + ac;
  3745. a = rotateLeft (a, s) + b;
  3746. }
  3747. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3748. {
  3749. a += H (b, c, d) + x + ac;
  3750. a = rotateLeft (a, s) + b;
  3751. }
  3752. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3753. {
  3754. a += I (b, c, d) + x + ac;
  3755. a = rotateLeft (a, s) + b;
  3756. }
  3757. }
  3758. MD5::ProcessContext::ProcessContext()
  3759. {
  3760. state[0] = 0x67452301;
  3761. state[1] = 0xefcdab89;
  3762. state[2] = 0x98badcfe;
  3763. state[3] = 0x10325476;
  3764. count[0] = 0;
  3765. count[1] = 0;
  3766. }
  3767. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3768. {
  3769. int bufferPos = ((count[0] >> 3) & 0x3F);
  3770. count[0] += (uint32) (dataSize << 3);
  3771. if (count[0] < ((uint32) dataSize << 3))
  3772. count[1]++;
  3773. count[1] += (uint32) (dataSize >> 29);
  3774. const size_t spaceLeft = 64 - bufferPos;
  3775. size_t i = 0;
  3776. if (dataSize >= spaceLeft)
  3777. {
  3778. memcpy (buffer + bufferPos, data, spaceLeft);
  3779. transform (buffer);
  3780. i = spaceLeft;
  3781. while (i + 64 <= dataSize)
  3782. {
  3783. transform (data + i);
  3784. i += 64;
  3785. }
  3786. bufferPos = 0;
  3787. }
  3788. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3789. }
  3790. void MD5::ProcessContext::finish (uint8* const result)
  3791. {
  3792. unsigned char encodedLength[8];
  3793. MD5Functions::encode (encodedLength, count, 8);
  3794. // Pad out to 56 mod 64.
  3795. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3796. const int paddingLength = (index < 56) ? (56 - index)
  3797. : (120 - index);
  3798. uint8 paddingBuffer [64];
  3799. zeromem (paddingBuffer, paddingLength);
  3800. paddingBuffer [0] = 0x80;
  3801. processBlock (paddingBuffer, paddingLength);
  3802. processBlock (encodedLength, 8);
  3803. MD5Functions::encode (result, state, 16);
  3804. zerostruct (buffer);
  3805. }
  3806. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3807. {
  3808. using namespace MD5Functions;
  3809. uint32 a = state[0];
  3810. uint32 b = state[1];
  3811. uint32 c = state[2];
  3812. uint32 d = state[3];
  3813. uint32 x[16];
  3814. decode (x, bufferToTransform, 64);
  3815. enum Constants
  3816. {
  3817. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3818. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3819. };
  3820. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3821. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3822. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3823. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3824. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3825. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3826. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3827. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3828. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3829. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3830. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3831. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3832. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3833. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3834. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3835. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3836. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3837. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3838. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3839. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3840. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3841. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3842. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3843. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3844. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3845. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3846. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3847. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3848. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3849. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3850. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3851. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3852. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3853. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3854. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3855. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3856. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3857. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3858. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3859. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3860. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3861. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3862. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3863. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3864. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3865. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3866. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3867. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3868. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3869. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3870. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3871. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3872. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3873. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3874. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3875. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3876. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3877. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3878. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3879. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3880. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3881. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3882. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3883. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3884. state[0] += a;
  3885. state[1] += b;
  3886. state[2] += c;
  3887. state[3] += d;
  3888. zerostruct (x);
  3889. }
  3890. const MemoryBlock MD5::getRawChecksumData() const
  3891. {
  3892. return MemoryBlock (result, sizeof (result));
  3893. }
  3894. const String MD5::toHexString() const
  3895. {
  3896. return String::toHexString (result, sizeof (result), 0);
  3897. }
  3898. bool MD5::operator== (const MD5& other) const
  3899. {
  3900. return memcmp (result, other.result, sizeof (result)) == 0;
  3901. }
  3902. bool MD5::operator!= (const MD5& other) const
  3903. {
  3904. return ! operator== (other);
  3905. }
  3906. END_JUCE_NAMESPACE
  3907. /*** End of inlined file: juce_MD5.cpp ***/
  3908. /*** Start of inlined file: juce_Primes.cpp ***/
  3909. BEGIN_JUCE_NAMESPACE
  3910. namespace PrimesHelpers
  3911. {
  3912. static void createSmallSieve (const int numBits, BitArray& result) throw()
  3913. {
  3914. result.setBit (numBits);
  3915. result.clearBit (numBits); // to enlarge the array
  3916. result.setBit (0);
  3917. int n = 2;
  3918. do
  3919. {
  3920. for (int i = n + n; i < numBits; i += n)
  3921. result.setBit (i);
  3922. n = result.findNextClearBit (n + 1);
  3923. }
  3924. while (n <= (numBits >> 1));
  3925. }
  3926. static void bigSieve (const BitArray& base,
  3927. const int numBits,
  3928. BitArray& result,
  3929. const BitArray& smallSieve,
  3930. const int smallSieveSize) throw()
  3931. {
  3932. jassert (! base[0]); // must be even!
  3933. result.setBit (numBits);
  3934. result.clearBit (numBits); // to enlarge the array
  3935. int index = smallSieve.findNextClearBit (0);
  3936. do
  3937. {
  3938. const int prime = (index << 1) + 1;
  3939. BitArray r (base);
  3940. BitArray remainder;
  3941. r.divideBy (prime, remainder);
  3942. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3943. if (r.isEmpty())
  3944. i += prime;
  3945. if ((i & 1) == 0)
  3946. i += prime;
  3947. i = (i - 1) >> 1;
  3948. while (i < numBits)
  3949. {
  3950. result.setBit (i);
  3951. i += prime;
  3952. }
  3953. index = smallSieve.findNextClearBit (index + 1);
  3954. }
  3955. while (index < smallSieveSize);
  3956. }
  3957. static bool findCandidate (const BitArray& base,
  3958. const BitArray& sieve,
  3959. const int numBits,
  3960. BitArray& result,
  3961. const int certainty) throw()
  3962. {
  3963. for (int i = 0; i < numBits; ++i)
  3964. {
  3965. if (! sieve[i])
  3966. {
  3967. result = base;
  3968. result.add (BitArray ((unsigned int) ((i << 1) + 1)));
  3969. if (Primes::isProbablyPrime (result, certainty))
  3970. return true;
  3971. }
  3972. }
  3973. return false;
  3974. }
  3975. }
  3976. const BitArray Primes::createProbablePrime (const int bitLength,
  3977. const int certainty,
  3978. const int* randomSeeds,
  3979. int numRandomSeeds) throw()
  3980. {
  3981. using namespace PrimesHelpers;
  3982. int defaultSeeds [16];
  3983. if (numRandomSeeds <= 0)
  3984. {
  3985. randomSeeds = defaultSeeds;
  3986. numRandomSeeds = numElementsInArray (defaultSeeds);
  3987. Random r (0);
  3988. for (int j = 10; --j >= 0;)
  3989. {
  3990. r.setSeedRandomly();
  3991. for (int i = numRandomSeeds; --i >= 0;)
  3992. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3993. }
  3994. }
  3995. BitArray smallSieve;
  3996. const int smallSieveSize = 15000;
  3997. createSmallSieve (smallSieveSize, smallSieve);
  3998. BitArray p;
  3999. for (int i = numRandomSeeds; --i >= 0;)
  4000. {
  4001. BitArray p2;
  4002. Random r (randomSeeds[i]);
  4003. r.fillBitsRandomly (p2, 0, bitLength);
  4004. p.xorWith (p2);
  4005. }
  4006. p.setBit (bitLength - 1);
  4007. p.clearBit (0);
  4008. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  4009. while (p.getHighestBit() < bitLength)
  4010. {
  4011. p.add (2 * searchLen);
  4012. BitArray sieve;
  4013. bigSieve (p, searchLen, sieve,
  4014. smallSieve, smallSieveSize);
  4015. BitArray candidate;
  4016. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  4017. return candidate;
  4018. }
  4019. jassertfalse
  4020. return BitArray();
  4021. }
  4022. static bool passesMillerRabin (const BitArray& n, int iterations) throw()
  4023. {
  4024. using namespace PrimesHelpers;
  4025. const BitArray one (1);
  4026. const BitArray two (2);
  4027. BitArray nMinusOne (n);
  4028. nMinusOne.subtract (one);
  4029. BitArray d (nMinusOne);
  4030. const int s = d.findNextSetBit (0);
  4031. d.shiftBits (-s);
  4032. BitArray smallPrimes;
  4033. int numBitsInSmallPrimes = 0;
  4034. for (;;)
  4035. {
  4036. numBitsInSmallPrimes += 256;
  4037. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  4038. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  4039. if (numPrimesFound > iterations + 1)
  4040. break;
  4041. }
  4042. int smallPrime = 2;
  4043. while (--iterations >= 0)
  4044. {
  4045. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  4046. BitArray r (smallPrime);
  4047. //r.createRandomNumber (nMinusOne);
  4048. r.exponentModulo (d, n);
  4049. if (! (r == one || r == nMinusOne))
  4050. {
  4051. for (int j = 0; j < s; ++j)
  4052. {
  4053. r.exponentModulo (two, n);
  4054. if (r == nMinusOne)
  4055. break;
  4056. }
  4057. if (r != nMinusOne)
  4058. return false;
  4059. }
  4060. }
  4061. return true;
  4062. }
  4063. bool Primes::isProbablyPrime (const BitArray& number,
  4064. const int certainty) throw()
  4065. {
  4066. if (! number[0])
  4067. return false;
  4068. if (number.getHighestBit() <= 10)
  4069. {
  4070. const int num = number.getBitRangeAsInt (0, 10);
  4071. for (int i = num / 2; --i > 1;)
  4072. if (num % i == 0)
  4073. return false;
  4074. return true;
  4075. }
  4076. else
  4077. {
  4078. const BitArray screen (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23);
  4079. if (number.findGreatestCommonDivisor (screen) != BitArray (1))
  4080. return false;
  4081. return passesMillerRabin (number, certainty);
  4082. }
  4083. }
  4084. END_JUCE_NAMESPACE
  4085. /*** End of inlined file: juce_Primes.cpp ***/
  4086. /*** Start of inlined file: juce_RSAKey.cpp ***/
  4087. BEGIN_JUCE_NAMESPACE
  4088. RSAKey::RSAKey() throw()
  4089. {
  4090. }
  4091. RSAKey::RSAKey (const String& s) throw()
  4092. {
  4093. if (s.containsChar (T(',')))
  4094. {
  4095. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  4096. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  4097. }
  4098. else
  4099. {
  4100. // the string needs to be two hex numbers, comma-separated..
  4101. jassertfalse;
  4102. }
  4103. }
  4104. RSAKey::~RSAKey() throw()
  4105. {
  4106. }
  4107. const String RSAKey::toString() const throw()
  4108. {
  4109. return part1.toString (16) + T(",") + part2.toString (16);
  4110. }
  4111. bool RSAKey::applyToValue (BitArray& value) const throw()
  4112. {
  4113. if (part1.isEmpty() || part2.isEmpty()
  4114. || value.compare (0) <= 0)
  4115. {
  4116. jassertfalse // using an uninitialised key
  4117. value.clear();
  4118. return false;
  4119. }
  4120. BitArray result;
  4121. while (! value.isEmpty())
  4122. {
  4123. result.multiplyBy (part2);
  4124. BitArray remainder;
  4125. value.divideBy (part2, remainder);
  4126. remainder.exponentModulo (part1, part2);
  4127. result.add (remainder);
  4128. }
  4129. value = result;
  4130. return true;
  4131. }
  4132. static const BitArray findBestCommonDivisor (const BitArray& p,
  4133. const BitArray& q) throw()
  4134. {
  4135. const BitArray one (1);
  4136. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  4137. // are fast to divide + multiply
  4138. for (int i = 2; i <= 65536; i *= 2)
  4139. {
  4140. const BitArray e (1 + i);
  4141. if (e.findGreatestCommonDivisor (p) == one
  4142. && e.findGreatestCommonDivisor (q) == one)
  4143. {
  4144. return e;
  4145. }
  4146. }
  4147. BitArray e (4);
  4148. while (! (e.findGreatestCommonDivisor (p) == one
  4149. && e.findGreatestCommonDivisor (q) == one))
  4150. {
  4151. e.add (one);
  4152. }
  4153. return e;
  4154. }
  4155. void RSAKey::createKeyPair (RSAKey& publicKey,
  4156. RSAKey& privateKey,
  4157. const int numBits,
  4158. const int* randomSeeds,
  4159. const int numRandomSeeds) throw()
  4160. {
  4161. jassert (numBits > 16); // not much point using less than this..
  4162. BitArray p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4163. BitArray q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4164. BitArray n (p);
  4165. n.multiplyBy (q); // n = pq
  4166. const BitArray one (1);
  4167. p.subtract (one);
  4168. q.subtract (one);
  4169. BitArray m (p);
  4170. m.multiplyBy (q); // m = (p - 1)(q - 1)
  4171. const BitArray e (findBestCommonDivisor (p, q));
  4172. BitArray d (e);
  4173. d.inverseModulo (m);
  4174. publicKey.part1 = e;
  4175. publicKey.part2 = n;
  4176. privateKey.part1 = d;
  4177. privateKey.part2 = n;
  4178. }
  4179. END_JUCE_NAMESPACE
  4180. /*** End of inlined file: juce_RSAKey.cpp ***/
  4181. /*** Start of inlined file: juce_InputStream.cpp ***/
  4182. BEGIN_JUCE_NAMESPACE
  4183. char InputStream::readByte()
  4184. {
  4185. char temp = 0;
  4186. read (&temp, 1);
  4187. return temp;
  4188. }
  4189. bool InputStream::readBool()
  4190. {
  4191. return readByte() != 0;
  4192. }
  4193. short InputStream::readShort()
  4194. {
  4195. char temp [2];
  4196. if (read (temp, 2) == 2)
  4197. return (short) ByteOrder::littleEndianShort (temp);
  4198. else
  4199. return 0;
  4200. }
  4201. short InputStream::readShortBigEndian()
  4202. {
  4203. char temp [2];
  4204. if (read (temp, 2) == 2)
  4205. return (short) ByteOrder::bigEndianShort (temp);
  4206. else
  4207. return 0;
  4208. }
  4209. int InputStream::readInt()
  4210. {
  4211. char temp [4];
  4212. if (read (temp, 4) == 4)
  4213. return (int) ByteOrder::littleEndianInt (temp);
  4214. else
  4215. return 0;
  4216. }
  4217. int InputStream::readIntBigEndian()
  4218. {
  4219. char temp [4];
  4220. if (read (temp, 4) == 4)
  4221. return (int) ByteOrder::bigEndianInt (temp);
  4222. else
  4223. return 0;
  4224. }
  4225. int InputStream::readCompressedInt()
  4226. {
  4227. const unsigned char sizeByte = readByte();
  4228. if (sizeByte == 0)
  4229. return 0;
  4230. const int numBytes = (sizeByte & 0x7f);
  4231. if (numBytes > 4)
  4232. {
  4233. jassertfalse // trying to read corrupt data - this method must only be used
  4234. // to read data that was written by OutputStream::writeCompressedInt()
  4235. return 0;
  4236. }
  4237. char bytes[4] = { 0, 0, 0, 0 };
  4238. if (read (bytes, numBytes) != numBytes)
  4239. return 0;
  4240. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4241. return (sizeByte >> 7) ? -num : num;
  4242. }
  4243. int64 InputStream::readInt64()
  4244. {
  4245. char temp [8];
  4246. if (read (temp, 8) == 8)
  4247. return (int64) ByteOrder::swapIfBigEndian (*(uint64*) temp);
  4248. else
  4249. return 0;
  4250. }
  4251. int64 InputStream::readInt64BigEndian()
  4252. {
  4253. char temp [8];
  4254. if (read (temp, 8) == 8)
  4255. return (int64) ByteOrder::swapIfLittleEndian (*(uint64*) temp);
  4256. else
  4257. return 0;
  4258. }
  4259. float InputStream::readFloat()
  4260. {
  4261. union { int asInt; float asFloat; } n;
  4262. n.asInt = readInt();
  4263. return n.asFloat;
  4264. }
  4265. float InputStream::readFloatBigEndian()
  4266. {
  4267. union { int asInt; float asFloat; } n;
  4268. n.asInt = readIntBigEndian();
  4269. return n.asFloat;
  4270. }
  4271. double InputStream::readDouble()
  4272. {
  4273. union { int64 asInt; double asDouble; } n;
  4274. n.asInt = readInt64();
  4275. return n.asDouble;
  4276. }
  4277. double InputStream::readDoubleBigEndian()
  4278. {
  4279. union { int64 asInt; double asDouble; } n;
  4280. n.asInt = readInt64BigEndian();
  4281. return n.asDouble;
  4282. }
  4283. const String InputStream::readString()
  4284. {
  4285. MemoryBlock buffer (256);
  4286. char* data = (char*) buffer.getData();
  4287. size_t i = 0;
  4288. while ((data[i] = readByte()) != 0)
  4289. {
  4290. if (++i >= buffer.getSize())
  4291. {
  4292. buffer.setSize (buffer.getSize() + 512);
  4293. data = (char*) buffer.getData();
  4294. }
  4295. }
  4296. return String::fromUTF8 (data, (int) i);
  4297. }
  4298. const String InputStream::readNextLine()
  4299. {
  4300. MemoryBlock buffer (256);
  4301. char* data = (char*) buffer.getData();
  4302. size_t i = 0;
  4303. while ((data[i] = readByte()) != 0)
  4304. {
  4305. if (data[i] == '\n')
  4306. break;
  4307. if (data[i] == '\r')
  4308. {
  4309. const int64 lastPos = getPosition();
  4310. if (readByte() != '\n')
  4311. setPosition (lastPos);
  4312. break;
  4313. }
  4314. if (++i >= buffer.getSize())
  4315. {
  4316. buffer.setSize (buffer.getSize() + 512);
  4317. data = (char*) buffer.getData();
  4318. }
  4319. }
  4320. return String::fromUTF8 (data, (int) i);
  4321. }
  4322. int InputStream::readIntoMemoryBlock (MemoryBlock& block,
  4323. int numBytes)
  4324. {
  4325. const int64 totalLength = getTotalLength();
  4326. if (totalLength >= 0)
  4327. {
  4328. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4329. totalLength - getPosition());
  4330. if (numBytes < 0)
  4331. numBytes = totalBytesRemaining;
  4332. else if (numBytes > 0)
  4333. numBytes = jmin (numBytes, totalBytesRemaining);
  4334. else
  4335. return 0;
  4336. }
  4337. const size_t originalBlockSize = block.getSize();
  4338. int totalBytesRead = 0;
  4339. if (numBytes > 0)
  4340. {
  4341. // know how many bytes we want, so we can resize the block first..
  4342. block.setSize (originalBlockSize + numBytes, false);
  4343. totalBytesRead = read (((char*) block.getData()) + originalBlockSize, numBytes);
  4344. }
  4345. else
  4346. {
  4347. // read until end of stram..
  4348. const int chunkSize = 32768;
  4349. for (;;)
  4350. {
  4351. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4352. const int bytesJustIn = read (((char*) block.getData())
  4353. + originalBlockSize
  4354. + totalBytesRead,
  4355. chunkSize);
  4356. if (bytesJustIn == 0)
  4357. break;
  4358. totalBytesRead += bytesJustIn;
  4359. }
  4360. }
  4361. // trim off any excess left at the end
  4362. block.setSize (originalBlockSize + totalBytesRead, false);
  4363. return totalBytesRead;
  4364. }
  4365. const String InputStream::readEntireStreamAsString()
  4366. {
  4367. MemoryBlock mb;
  4368. const int size = readIntoMemoryBlock (mb);
  4369. return String::createStringFromData ((const char*) mb.getData(), size);
  4370. }
  4371. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4372. {
  4373. if (numBytesToSkip > 0)
  4374. {
  4375. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4376. HeapBlock <char> temp (skipBufferSize);
  4377. while (numBytesToSkip > 0 && ! isExhausted())
  4378. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4379. }
  4380. }
  4381. END_JUCE_NAMESPACE
  4382. /*** End of inlined file: juce_InputStream.cpp ***/
  4383. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4384. BEGIN_JUCE_NAMESPACE
  4385. #if JUCE_DEBUG
  4386. static CriticalSection activeStreamLock;
  4387. static VoidArray activeStreams;
  4388. void juce_CheckForDanglingStreams()
  4389. {
  4390. /*
  4391. It's always a bad idea to leak any object, but if you're leaking output
  4392. streams, then there's a good chance that you're failing to flush a file
  4393. to disk properly, which could result in corrupted data and other similar
  4394. nastiness..
  4395. */
  4396. jassert (activeStreams.size() == 0);
  4397. };
  4398. #endif
  4399. OutputStream::OutputStream()
  4400. {
  4401. #if JUCE_DEBUG
  4402. const ScopedLock sl (activeStreamLock);
  4403. activeStreams.add (this);
  4404. #endif
  4405. }
  4406. OutputStream::~OutputStream()
  4407. {
  4408. #if JUCE_DEBUG
  4409. const ScopedLock sl (activeStreamLock);
  4410. activeStreams.removeValue (this);
  4411. #endif
  4412. }
  4413. void OutputStream::writeBool (bool b)
  4414. {
  4415. writeByte ((b) ? (char) 1
  4416. : (char) 0);
  4417. }
  4418. void OutputStream::writeByte (char byte)
  4419. {
  4420. write (&byte, 1);
  4421. }
  4422. void OutputStream::writeShort (short value)
  4423. {
  4424. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4425. write (&v, 2);
  4426. }
  4427. void OutputStream::writeShortBigEndian (short value)
  4428. {
  4429. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4430. write (&v, 2);
  4431. }
  4432. void OutputStream::writeInt (int value)
  4433. {
  4434. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4435. write (&v, 4);
  4436. }
  4437. void OutputStream::writeIntBigEndian (int value)
  4438. {
  4439. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4440. write (&v, 4);
  4441. }
  4442. void OutputStream::writeCompressedInt (int value)
  4443. {
  4444. unsigned int un = (value < 0) ? (unsigned int) -value
  4445. : (unsigned int) value;
  4446. uint8 data[5];
  4447. int num = 0;
  4448. while (un > 0)
  4449. {
  4450. data[++num] = (uint8) un;
  4451. un >>= 8;
  4452. }
  4453. data[0] = (uint8) num;
  4454. if (value < 0)
  4455. data[0] |= 0x80;
  4456. write (data, num + 1);
  4457. }
  4458. void OutputStream::writeInt64 (int64 value)
  4459. {
  4460. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4461. write (&v, 8);
  4462. }
  4463. void OutputStream::writeInt64BigEndian (int64 value)
  4464. {
  4465. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4466. write (&v, 8);
  4467. }
  4468. void OutputStream::writeFloat (float value)
  4469. {
  4470. union { int asInt; float asFloat; } n;
  4471. n.asFloat = value;
  4472. writeInt (n.asInt);
  4473. }
  4474. void OutputStream::writeFloatBigEndian (float value)
  4475. {
  4476. union { int asInt; float asFloat; } n;
  4477. n.asFloat = value;
  4478. writeIntBigEndian (n.asInt);
  4479. }
  4480. void OutputStream::writeDouble (double value)
  4481. {
  4482. union { int64 asInt; double asDouble; } n;
  4483. n.asDouble = value;
  4484. writeInt64 (n.asInt);
  4485. }
  4486. void OutputStream::writeDoubleBigEndian (double value)
  4487. {
  4488. union { int64 asInt; double asDouble; } n;
  4489. n.asDouble = value;
  4490. writeInt64BigEndian (n.asInt);
  4491. }
  4492. void OutputStream::writeString (const String& text)
  4493. {
  4494. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4495. // if lots of large, persistent strings were to be written to streams).
  4496. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4497. HeapBlock<char> temp (numBytes);
  4498. text.copyToUTF8 (temp, numBytes);
  4499. write (temp, numBytes);
  4500. }
  4501. void OutputStream::writeText (const String& text, const bool asUnicode,
  4502. const bool writeUnicodeHeaderBytes)
  4503. {
  4504. if (asUnicode)
  4505. {
  4506. if (writeUnicodeHeaderBytes)
  4507. write ("\x0ff\x0fe", 2);
  4508. const juce_wchar* src = (const juce_wchar*) text;
  4509. bool lastCharWasReturn = false;
  4510. while (*src != 0)
  4511. {
  4512. if (*src == L'\n' && ! lastCharWasReturn)
  4513. writeShort ((short) L'\r');
  4514. lastCharWasReturn = (*src == L'\r');
  4515. writeShort ((short) *src++);
  4516. }
  4517. }
  4518. else
  4519. {
  4520. const char* src = text.toUTF8();
  4521. const char* t = src;
  4522. for (;;)
  4523. {
  4524. if (*t == '\n')
  4525. {
  4526. if (t > src)
  4527. write (src, (int) (t - src));
  4528. write ("\r\n", 2);
  4529. src = t + 1;
  4530. }
  4531. else if (*t == '\r')
  4532. {
  4533. if (t[1] == '\n')
  4534. ++t;
  4535. }
  4536. else if (*t == 0)
  4537. {
  4538. if (t > src)
  4539. write (src, (int) (t - src));
  4540. break;
  4541. }
  4542. ++t;
  4543. }
  4544. }
  4545. }
  4546. int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite)
  4547. {
  4548. if (numBytesToWrite < 0)
  4549. numBytesToWrite = 0x7fffffff;
  4550. int numWritten = 0;
  4551. while (numBytesToWrite > 0 && ! source.isExhausted())
  4552. {
  4553. char buffer [8192];
  4554. const int num = (int) source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4555. if (num == 0)
  4556. break;
  4557. write (buffer, num);
  4558. numBytesToWrite -= num;
  4559. numWritten += num;
  4560. }
  4561. return numWritten;
  4562. }
  4563. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const int number)
  4564. {
  4565. return stream << String (number);
  4566. }
  4567. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const double number)
  4568. {
  4569. return stream << String (number);
  4570. }
  4571. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char character)
  4572. {
  4573. stream.writeByte (character);
  4574. return stream;
  4575. }
  4576. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const text)
  4577. {
  4578. stream.write (text, (int) strlen (text));
  4579. return stream;
  4580. }
  4581. END_JUCE_NAMESPACE
  4582. /*** End of inlined file: juce_OutputStream.cpp ***/
  4583. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4584. BEGIN_JUCE_NAMESPACE
  4585. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4586. bool* isDirectory, bool* isHidden, int64* fileSize,
  4587. Time* modTime, Time* creationTime, bool* isReadOnly);
  4588. bool juce_findFileNext (void* handle, String& resultFile,
  4589. bool* isDirectory, bool* isHidden, int64* fileSize,
  4590. Time* modTime, Time* creationTime, bool* isReadOnly);
  4591. void juce_findFileClose (void* handle);
  4592. DirectoryIterator::DirectoryIterator (const File& directory,
  4593. bool isRecursive,
  4594. const String& wc,
  4595. const int whatToLookFor_)
  4596. : wildCard (wc),
  4597. index (-1),
  4598. whatToLookFor (whatToLookFor_)
  4599. {
  4600. // you have to specify the type of files you're looking for!
  4601. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4602. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4603. String path (directory.getFullPathName());
  4604. if (! path.endsWithChar (File::separator))
  4605. path += File::separator;
  4606. String filename;
  4607. bool isDirectory, isHidden;
  4608. void* const handle = juce_findFileStart (path,
  4609. isRecursive ? T("*") : wc,
  4610. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4611. if (handle != 0)
  4612. {
  4613. do
  4614. {
  4615. if (! filename.containsOnly (T(".")))
  4616. {
  4617. bool addToList = false;
  4618. if (isDirectory)
  4619. {
  4620. if (isRecursive
  4621. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4622. || ! isHidden))
  4623. {
  4624. dirsFound.add (File (path + filename, 0));
  4625. }
  4626. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4627. }
  4628. else
  4629. {
  4630. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4631. }
  4632. // if it's recursive, we're not relying on the OS iterator
  4633. // to do the wildcard match, so do it now..
  4634. if (isRecursive && addToList)
  4635. addToList = filename.matchesWildcard (wc, true);
  4636. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4637. addToList = ! isHidden;
  4638. if (addToList)
  4639. filesFound.add (File (path + filename, 0));
  4640. }
  4641. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4642. juce_findFileClose (handle);
  4643. }
  4644. }
  4645. DirectoryIterator::~DirectoryIterator()
  4646. {
  4647. }
  4648. bool DirectoryIterator::next()
  4649. {
  4650. if (subIterator != 0)
  4651. {
  4652. if (subIterator->next())
  4653. return true;
  4654. subIterator = 0;
  4655. }
  4656. if (index >= filesFound.size() + dirsFound.size() - 1)
  4657. return false;
  4658. ++index;
  4659. if (index >= filesFound.size())
  4660. {
  4661. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4662. true, wildCard, whatToLookFor);
  4663. return next();
  4664. }
  4665. return true;
  4666. }
  4667. const File DirectoryIterator::getFile() const
  4668. {
  4669. if (subIterator != 0)
  4670. return subIterator->getFile();
  4671. return filesFound [index];
  4672. }
  4673. float DirectoryIterator::getEstimatedProgress() const
  4674. {
  4675. if (filesFound.size() + dirsFound.size() == 0)
  4676. {
  4677. return 0.0f;
  4678. }
  4679. else
  4680. {
  4681. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4682. : (float) index;
  4683. return detailedIndex / (filesFound.size() + dirsFound.size());
  4684. }
  4685. }
  4686. END_JUCE_NAMESPACE
  4687. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4688. /*** Start of inlined file: juce_File.cpp ***/
  4689. #ifdef _MSC_VER
  4690. #pragma warning (disable: 4514)
  4691. #pragma warning (push)
  4692. #endif
  4693. #if ! JUCE_WINDOWS
  4694. #include <pwd.h>
  4695. #endif
  4696. BEGIN_JUCE_NAMESPACE
  4697. #ifdef _MSC_VER
  4698. #pragma warning (pop)
  4699. #endif
  4700. void* juce_fileOpen (const String& path, bool forWriting);
  4701. void juce_fileClose (void* handle);
  4702. int juce_fileWrite (void* handle, const void* buffer, int size);
  4703. int64 juce_fileGetPosition (void* handle);
  4704. int64 juce_fileSetPosition (void* handle, int64 pos);
  4705. void juce_fileFlush (void* handle);
  4706. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4707. bool juce_isDirectory (const String& fileName);
  4708. int64 juce_getFileSize (const String& fileName);
  4709. bool juce_canWriteToFile (const String& fileName);
  4710. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4711. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4712. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4713. bool juce_deleteFile (const String& fileName);
  4714. bool juce_copyFile (const String& source, const String& dest);
  4715. bool juce_moveFile (const String& source, const String& dest);
  4716. // this must also create all paths involved in the directory.
  4717. void juce_createDirectory (const String& fileName);
  4718. bool juce_launchFile (const String& fileName, const String& parameters);
  4719. const StringArray juce_getFileSystemRoots();
  4720. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4721. // starts a directory search operation with a wildcard, returning a handle for
  4722. // use in calls to juce_findFileNext.
  4723. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4724. // the other pointers, if non-null, are set based on the properties of the file.
  4725. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4726. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4727. Time* creationTime, bool* isReadOnly);
  4728. // returns false when no more files are found
  4729. bool juce_findFileNext (void* handle, String& resultFile,
  4730. bool* isDirectory, bool* isHidden, int64* fileSize,
  4731. Time* modTime, Time* creationTime, bool* isReadOnly);
  4732. void juce_findFileClose (void* handle);
  4733. static const String juce_addTrailingSeparator (const String& path)
  4734. {
  4735. return path.endsWithChar (File::separator) ? path
  4736. : path + File::separator;
  4737. }
  4738. static const String parseAbsolutePath (String path)
  4739. {
  4740. if (path.isEmpty())
  4741. return String::empty;
  4742. #if JUCE_WINDOWS
  4743. // Windows..
  4744. path = path.replaceCharacter (T('/'), T('\\'));
  4745. if (path.startsWithChar (File::separator))
  4746. {
  4747. if (path[1] != File::separator)
  4748. {
  4749. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4750. If you're trying to parse a string that may be either a relative path or an absolute path,
  4751. you MUST provide a context against which the partial path can be evaluated - you can do
  4752. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4753. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4754. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4755. */
  4756. jassertfalse
  4757. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4758. }
  4759. }
  4760. else if (path.indexOfChar (T(':')) < 0)
  4761. {
  4762. if (path.isEmpty())
  4763. return String::empty;
  4764. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4765. If you're trying to parse a string that may be either a relative path or an absolute path,
  4766. you MUST provide a context against which the partial path can be evaluated - you can do
  4767. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4768. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4769. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4770. */
  4771. jassertfalse
  4772. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4773. }
  4774. #else
  4775. // Mac or Linux..
  4776. path = path.replaceCharacter (T('\\'), T('/'));
  4777. if (path.startsWithChar (T('~')))
  4778. {
  4779. const char* homeDir = 0;
  4780. if (path[1] == File::separator || path[1] == 0)
  4781. {
  4782. // expand a name of the form "~/abc"
  4783. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4784. + path.substring (1);
  4785. }
  4786. else
  4787. {
  4788. // expand a name of type "~dave/abc"
  4789. const String userName (path.substring (1).upToFirstOccurrenceOf (T("/"), false, false));
  4790. struct passwd* const pw = getpwnam (userName.toUTF8());
  4791. if (pw != 0)
  4792. {
  4793. String home (homeDir);
  4794. if (home.endsWithChar (File::separator))
  4795. home [home.length() - 1] = 0;
  4796. path = String (pw->pw_dir)
  4797. + path.substring (userName.length());
  4798. }
  4799. }
  4800. }
  4801. else if (! path.startsWithChar (File::separator))
  4802. {
  4803. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4804. If you're trying to parse a string that may be either a relative path or an absolute path,
  4805. you MUST provide a context against which the partial path can be evaluated - you can do
  4806. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4807. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4808. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4809. */
  4810. jassert (path.startsWith (T("./"))); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4811. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4812. }
  4813. #endif
  4814. int len = path.length();
  4815. while (--len > 0 && path [len] == File::separator)
  4816. path [len] = 0;
  4817. return path;
  4818. }
  4819. const File File::nonexistent;
  4820. File::File (const String& fullPathName)
  4821. : fullPath (parseAbsolutePath (fullPathName))
  4822. {
  4823. }
  4824. File::File (const String& path, int)
  4825. : fullPath (path)
  4826. {
  4827. }
  4828. const File File::createFileWithoutCheckingPath (const String& path)
  4829. {
  4830. return File (path, 0);
  4831. }
  4832. File::File (const File& other)
  4833. : fullPath (other.fullPath)
  4834. {
  4835. }
  4836. File& File::operator= (const String& newPath)
  4837. {
  4838. fullPath = parseAbsolutePath (newPath);
  4839. return *this;
  4840. }
  4841. File& File::operator= (const File& other)
  4842. {
  4843. fullPath = other.fullPath;
  4844. return *this;
  4845. }
  4846. #if JUCE_LINUX
  4847. #define NAMES_ARE_CASE_SENSITIVE 1
  4848. #endif
  4849. bool File::areFileNamesCaseSensitive()
  4850. {
  4851. #if NAMES_ARE_CASE_SENSITIVE
  4852. return true;
  4853. #else
  4854. return false;
  4855. #endif
  4856. }
  4857. bool File::operator== (const File& other) const
  4858. {
  4859. // case-insensitive on Windows, but not on linux.
  4860. #if NAMES_ARE_CASE_SENSITIVE
  4861. return fullPath == other.fullPath;
  4862. #else
  4863. return fullPath.equalsIgnoreCase (other.fullPath);
  4864. #endif
  4865. }
  4866. bool File::operator!= (const File& other) const
  4867. {
  4868. return ! operator== (other);
  4869. }
  4870. bool File::exists() const
  4871. {
  4872. return juce_fileExists (fullPath, false);
  4873. }
  4874. bool File::existsAsFile() const
  4875. {
  4876. return juce_fileExists (fullPath, true);
  4877. }
  4878. bool File::isDirectory() const
  4879. {
  4880. return juce_isDirectory (fullPath);
  4881. }
  4882. bool File::hasWriteAccess() const
  4883. {
  4884. if (exists())
  4885. return juce_canWriteToFile (fullPath);
  4886. #if ! JUCE_WINDOWS
  4887. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4888. return getParentDirectory().hasWriteAccess();
  4889. else
  4890. return false;
  4891. #else
  4892. // on windows, it seems that even read-only directories can still be written into,
  4893. // so checking the parent directory's permissions would return the wrong result..
  4894. else
  4895. return true;
  4896. #endif
  4897. }
  4898. bool File::setReadOnly (const bool shouldBeReadOnly,
  4899. const bool applyRecursively) const
  4900. {
  4901. bool worked = true;
  4902. if (applyRecursively && isDirectory())
  4903. {
  4904. Array <File> subFiles;
  4905. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4906. for (int i = subFiles.size(); --i >= 0;)
  4907. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4908. }
  4909. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4910. }
  4911. bool File::deleteFile() const
  4912. {
  4913. return (! exists())
  4914. || juce_deleteFile (fullPath);
  4915. }
  4916. bool File::deleteRecursively() const
  4917. {
  4918. bool worked = true;
  4919. if (isDirectory())
  4920. {
  4921. Array<File> subFiles;
  4922. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4923. for (int i = subFiles.size(); --i >= 0;)
  4924. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4925. }
  4926. return deleteFile() && worked;
  4927. }
  4928. bool File::moveFileTo (const File& newFile) const
  4929. {
  4930. if (newFile.fullPath == fullPath)
  4931. return true;
  4932. #if ! NAMES_ARE_CASE_SENSITIVE
  4933. if (*this != newFile)
  4934. #endif
  4935. if (! newFile.deleteFile())
  4936. return false;
  4937. return juce_moveFile (fullPath, newFile.fullPath);
  4938. }
  4939. bool File::copyFileTo (const File& newFile) const
  4940. {
  4941. if (*this == newFile)
  4942. return true;
  4943. if (! newFile.deleteFile())
  4944. return false;
  4945. return juce_copyFile (fullPath, newFile.fullPath);
  4946. }
  4947. bool File::copyDirectoryTo (const File& newDirectory) const
  4948. {
  4949. if (isDirectory() && newDirectory.createDirectory())
  4950. {
  4951. Array<File> subFiles;
  4952. findChildFiles (subFiles, File::findFiles, false);
  4953. int i;
  4954. for (i = 0; i < subFiles.size(); ++i)
  4955. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4956. return false;
  4957. subFiles.clear();
  4958. findChildFiles (subFiles, File::findDirectories, false);
  4959. for (i = 0; i < subFiles.size(); ++i)
  4960. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4961. return false;
  4962. return true;
  4963. }
  4964. return false;
  4965. }
  4966. const String File::getPathUpToLastSlash() const
  4967. {
  4968. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4969. if (lastSlash > 0)
  4970. return fullPath.substring (0, lastSlash);
  4971. else if (lastSlash == 0)
  4972. return separatorString;
  4973. else
  4974. return fullPath;
  4975. }
  4976. const File File::getParentDirectory() const
  4977. {
  4978. return File (getPathUpToLastSlash());
  4979. }
  4980. const String File::getFileName() const
  4981. {
  4982. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4983. }
  4984. int File::hashCode() const
  4985. {
  4986. return fullPath.hashCode();
  4987. }
  4988. int64 File::hashCode64() const
  4989. {
  4990. return fullPath.hashCode64();
  4991. }
  4992. const String File::getFileNameWithoutExtension() const
  4993. {
  4994. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4995. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  4996. if (lastDot > lastSlash)
  4997. return fullPath.substring (lastSlash, lastDot);
  4998. else
  4999. return fullPath.substring (lastSlash);
  5000. }
  5001. bool File::isAChildOf (const File& potentialParent) const
  5002. {
  5003. if (potentialParent == File::nonexistent)
  5004. return false;
  5005. const String ourPath (getPathUpToLastSlash());
  5006. #if NAMES_ARE_CASE_SENSITIVE
  5007. if (potentialParent.fullPath == ourPath)
  5008. #else
  5009. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  5010. #endif
  5011. {
  5012. return true;
  5013. }
  5014. else if (potentialParent.fullPath.length() >= ourPath.length())
  5015. {
  5016. return false;
  5017. }
  5018. else
  5019. {
  5020. return getParentDirectory().isAChildOf (potentialParent);
  5021. }
  5022. }
  5023. bool File::isAbsolutePath (const String& path)
  5024. {
  5025. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  5026. #if JUCE_WINDOWS
  5027. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  5028. #else
  5029. || path.startsWithChar (T('~'));
  5030. #endif
  5031. }
  5032. const File File::getChildFile (String relativePath) const
  5033. {
  5034. if (isAbsolutePath (relativePath))
  5035. {
  5036. // the path is really absolute..
  5037. return File (relativePath);
  5038. }
  5039. else
  5040. {
  5041. // it's relative, so remove any ../ or ./ bits at the start.
  5042. String path (fullPath);
  5043. if (relativePath[0] == T('.'))
  5044. {
  5045. #if JUCE_WINDOWS
  5046. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  5047. #else
  5048. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  5049. #endif
  5050. while (relativePath[0] == T('.'))
  5051. {
  5052. if (relativePath[1] == T('.'))
  5053. {
  5054. if (relativePath [2] == 0 || relativePath[2] == separator)
  5055. {
  5056. const int lastSlash = path.lastIndexOfChar (separator);
  5057. if (lastSlash >= 0)
  5058. path = path.substring (0, lastSlash);
  5059. relativePath = relativePath.substring (3);
  5060. }
  5061. else
  5062. {
  5063. break;
  5064. }
  5065. }
  5066. else if (relativePath[1] == separator)
  5067. {
  5068. relativePath = relativePath.substring (2);
  5069. }
  5070. else
  5071. {
  5072. break;
  5073. }
  5074. }
  5075. }
  5076. return File (juce_addTrailingSeparator (path) + relativePath);
  5077. }
  5078. }
  5079. const File File::getSiblingFile (const String& fileName) const
  5080. {
  5081. return getParentDirectory().getChildFile (fileName);
  5082. }
  5083. int64 File::getSize() const
  5084. {
  5085. return juce_getFileSize (fullPath);
  5086. }
  5087. const String File::descriptionOfSizeInBytes (const int64 bytes)
  5088. {
  5089. if (bytes == 1)
  5090. {
  5091. return "1 byte";
  5092. }
  5093. else if (bytes < 1024)
  5094. {
  5095. return String ((int) bytes) + " bytes";
  5096. }
  5097. else if (bytes < 1024 * 1024)
  5098. {
  5099. return String (bytes / 1024.0, 1) + " KB";
  5100. }
  5101. else if (bytes < 1024 * 1024 * 1024)
  5102. {
  5103. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  5104. }
  5105. else
  5106. {
  5107. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  5108. }
  5109. }
  5110. bool File::create() const
  5111. {
  5112. if (! exists())
  5113. {
  5114. const File parentDir (getParentDirectory());
  5115. if (parentDir == *this || ! parentDir.createDirectory())
  5116. return false;
  5117. void* const fh = juce_fileOpen (fullPath, true);
  5118. if (fh == 0)
  5119. return false;
  5120. juce_fileClose (fh);
  5121. }
  5122. return true;
  5123. }
  5124. bool File::createDirectory() const
  5125. {
  5126. if (! isDirectory())
  5127. {
  5128. const File parentDir (getParentDirectory());
  5129. if (parentDir == *this || ! parentDir.createDirectory())
  5130. return false;
  5131. String dir (fullPath);
  5132. while (dir.endsWithChar (separator))
  5133. dir [dir.length() - 1] = 0;
  5134. juce_createDirectory (dir);
  5135. return isDirectory();
  5136. }
  5137. return true;
  5138. }
  5139. const Time File::getCreationTime() const
  5140. {
  5141. int64 m, a, c;
  5142. juce_getFileTimes (fullPath, m, a, c);
  5143. return Time (c);
  5144. }
  5145. bool File::setCreationTime (const Time& t) const
  5146. {
  5147. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  5148. }
  5149. const Time File::getLastModificationTime() const
  5150. {
  5151. int64 m, a, c;
  5152. juce_getFileTimes (fullPath, m, a, c);
  5153. return Time (m);
  5154. }
  5155. bool File::setLastModificationTime (const Time& t) const
  5156. {
  5157. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  5158. }
  5159. const Time File::getLastAccessTime() const
  5160. {
  5161. int64 m, a, c;
  5162. juce_getFileTimes (fullPath, m, a, c);
  5163. return Time (a);
  5164. }
  5165. bool File::setLastAccessTime (const Time& t) const
  5166. {
  5167. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5168. }
  5169. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5170. {
  5171. if (! existsAsFile())
  5172. return false;
  5173. FileInputStream in (*this);
  5174. return getSize() == in.readIntoMemoryBlock (destBlock);
  5175. }
  5176. const String File::loadFileAsString() const
  5177. {
  5178. if (! existsAsFile())
  5179. return String::empty;
  5180. FileInputStream in (*this);
  5181. return in.readEntireStreamAsString();
  5182. }
  5183. static inline bool fileTypeMatches (const int whatToLookFor,
  5184. const bool isDir,
  5185. const bool isHidden)
  5186. {
  5187. return (whatToLookFor & (isDir ? File::findDirectories
  5188. : File::findFiles)) != 0
  5189. && ((! isHidden)
  5190. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5191. }
  5192. int File::findChildFiles (Array<File>& results,
  5193. const int whatToLookFor,
  5194. const bool searchRecursively,
  5195. const String& wildCardPattern) const
  5196. {
  5197. // you have to specify the type of files you're looking for!
  5198. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5199. int total = 0;
  5200. // find child files or directories in this directory first..
  5201. if (isDirectory())
  5202. {
  5203. const String path (juce_addTrailingSeparator (fullPath));
  5204. String filename;
  5205. bool itemIsDirectory, itemIsHidden;
  5206. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5207. &itemIsDirectory, &itemIsHidden,
  5208. 0, 0, 0, 0);
  5209. if (handle != 0)
  5210. {
  5211. do
  5212. {
  5213. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5214. && ! filename.containsOnly (T(".")))
  5215. {
  5216. results.add (File (path + filename, 0));
  5217. ++total;
  5218. }
  5219. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5220. juce_findFileClose (handle);
  5221. }
  5222. }
  5223. else
  5224. {
  5225. // trying to search for files inside a non-directory?
  5226. //jassertfalse
  5227. }
  5228. // and recurse down if required.
  5229. if (searchRecursively)
  5230. {
  5231. Array<File> subDirectories;
  5232. findChildFiles (subDirectories, File::findDirectories, false);
  5233. for (int i = 0; i < subDirectories.size(); ++i)
  5234. {
  5235. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5236. true, wildCardPattern);
  5237. }
  5238. }
  5239. return total;
  5240. }
  5241. int File::getNumberOfChildFiles (const int whatToLookFor,
  5242. const String& wildCardPattern) const
  5243. {
  5244. // you have to specify the type of files you're looking for!
  5245. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5246. int count = 0;
  5247. if (isDirectory())
  5248. {
  5249. String filename;
  5250. bool itemIsDirectory, itemIsHidden;
  5251. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5252. &itemIsDirectory, &itemIsHidden,
  5253. 0, 0, 0, 0);
  5254. if (handle != 0)
  5255. {
  5256. do
  5257. {
  5258. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5259. && ! filename.containsOnly (T(".")))
  5260. {
  5261. ++count;
  5262. }
  5263. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5264. juce_findFileClose (handle);
  5265. }
  5266. }
  5267. else
  5268. {
  5269. // trying to search for files inside a non-directory?
  5270. jassertfalse
  5271. }
  5272. return count;
  5273. }
  5274. bool File::containsSubDirectories() const
  5275. {
  5276. bool result = false;
  5277. if (isDirectory())
  5278. {
  5279. String filename;
  5280. bool itemIsDirectory, itemIsHidden;
  5281. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5282. T("*"), filename,
  5283. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5284. if (handle != 0)
  5285. {
  5286. do
  5287. {
  5288. if (itemIsDirectory)
  5289. {
  5290. result = true;
  5291. break;
  5292. }
  5293. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5294. juce_findFileClose (handle);
  5295. }
  5296. }
  5297. return result;
  5298. }
  5299. const File File::getNonexistentChildFile (const String& prefix_,
  5300. const String& suffix,
  5301. bool putNumbersInBrackets) const
  5302. {
  5303. File f (getChildFile (prefix_ + suffix));
  5304. if (f.exists())
  5305. {
  5306. int num = 2;
  5307. String prefix (prefix_);
  5308. // remove any bracketed numbers that may already be on the end..
  5309. if (prefix.trim().endsWithChar (T(')')))
  5310. {
  5311. putNumbersInBrackets = true;
  5312. const int openBracks = prefix.lastIndexOfChar (T('('));
  5313. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5314. if (openBracks > 0
  5315. && closeBracks > openBracks
  5316. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5317. {
  5318. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5319. prefix = prefix.substring (0, openBracks);
  5320. }
  5321. }
  5322. // also use brackets if it ends in a digit.
  5323. putNumbersInBrackets = putNumbersInBrackets
  5324. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5325. do
  5326. {
  5327. if (putNumbersInBrackets)
  5328. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5329. else
  5330. f = getChildFile (prefix + String (num++) + suffix);
  5331. } while (f.exists());
  5332. }
  5333. return f;
  5334. }
  5335. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5336. {
  5337. if (exists())
  5338. {
  5339. return getParentDirectory()
  5340. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5341. getFileExtension(),
  5342. putNumbersInBrackets);
  5343. }
  5344. else
  5345. {
  5346. return *this;
  5347. }
  5348. }
  5349. const String File::getFileExtension() const
  5350. {
  5351. String ext;
  5352. if (! isDirectory())
  5353. {
  5354. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5355. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5356. ext = fullPath.substring (indexOfDot);
  5357. }
  5358. return ext;
  5359. }
  5360. bool File::hasFileExtension (const String& possibleSuffix) const
  5361. {
  5362. if (possibleSuffix.isEmpty())
  5363. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5364. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5365. if (semicolon >= 0)
  5366. {
  5367. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5368. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5369. }
  5370. else
  5371. {
  5372. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5373. {
  5374. if (possibleSuffix.startsWithChar (T('.')))
  5375. return true;
  5376. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5377. if (dotPos >= 0)
  5378. return fullPath [dotPos] == T('.');
  5379. }
  5380. }
  5381. return false;
  5382. }
  5383. const File File::withFileExtension (const String& newExtension) const
  5384. {
  5385. if (fullPath.isEmpty())
  5386. return File::nonexistent;
  5387. String filePart (getFileName());
  5388. int i = filePart.lastIndexOfChar (T('.'));
  5389. if (i < 0)
  5390. i = filePart.length();
  5391. String newExt (newExtension);
  5392. if (newExt.isNotEmpty() && ! newExt.startsWithChar (T('.')))
  5393. newExt = T(".") + newExt;
  5394. return getSiblingFile (filePart.substring (0, i) + newExt);
  5395. }
  5396. bool File::startAsProcess (const String& parameters) const
  5397. {
  5398. return exists()
  5399. && juce_launchFile (fullPath, parameters);
  5400. }
  5401. FileInputStream* File::createInputStream() const
  5402. {
  5403. if (existsAsFile())
  5404. return new FileInputStream (*this);
  5405. else
  5406. return 0;
  5407. }
  5408. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5409. {
  5410. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5411. if (out->failedToOpen())
  5412. return 0;
  5413. return out.release();
  5414. }
  5415. bool File::appendData (const void* const dataToAppend,
  5416. const int numberOfBytes) const
  5417. {
  5418. if (numberOfBytes > 0)
  5419. {
  5420. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5421. if (out == 0)
  5422. return false;
  5423. out->write (dataToAppend, numberOfBytes);
  5424. }
  5425. return true;
  5426. }
  5427. bool File::replaceWithData (const void* const dataToWrite,
  5428. const int numberOfBytes) const
  5429. {
  5430. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5431. if (numberOfBytes <= 0)
  5432. return deleteFile();
  5433. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5434. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5435. return tempFile.overwriteTargetFileWithTemporary();
  5436. }
  5437. bool File::appendText (const String& text,
  5438. const bool asUnicode,
  5439. const bool writeUnicodeHeaderBytes) const
  5440. {
  5441. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5442. if (out != 0)
  5443. {
  5444. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5445. return true;
  5446. }
  5447. return false;
  5448. }
  5449. bool File::replaceWithText (const String& textToWrite,
  5450. const bool asUnicode,
  5451. const bool writeUnicodeHeaderBytes) const
  5452. {
  5453. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5454. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5455. return tempFile.overwriteTargetFileWithTemporary();
  5456. }
  5457. const String File::createLegalPathName (const String& original)
  5458. {
  5459. String s (original);
  5460. String start;
  5461. if (s[1] == T(':'))
  5462. {
  5463. start = s.substring (0, 2);
  5464. s = s.substring (2);
  5465. }
  5466. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5467. .substring (0, 1024);
  5468. }
  5469. const String File::createLegalFileName (const String& original)
  5470. {
  5471. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5472. const int maxLength = 128; // only the length of the filename, not the whole path
  5473. const int len = s.length();
  5474. if (len > maxLength)
  5475. {
  5476. const int lastDot = s.lastIndexOfChar (T('.'));
  5477. if (lastDot > jmax (0, len - 12))
  5478. {
  5479. s = s.substring (0, maxLength - (len - lastDot))
  5480. + s.substring (lastDot);
  5481. }
  5482. else
  5483. {
  5484. s = s.substring (0, maxLength);
  5485. }
  5486. }
  5487. return s;
  5488. }
  5489. const String File::getRelativePathFrom (const File& dir) const
  5490. {
  5491. String thisPath (fullPath);
  5492. {
  5493. int len = thisPath.length();
  5494. while (--len >= 0 && thisPath [len] == File::separator)
  5495. thisPath [len] = 0;
  5496. }
  5497. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5498. : dir.fullPath));
  5499. const int len = jmin (thisPath.length(), dirPath.length());
  5500. int commonBitLength = 0;
  5501. for (int i = 0; i < len; ++i)
  5502. {
  5503. #if NAMES_ARE_CASE_SENSITIVE
  5504. if (thisPath[i] != dirPath[i])
  5505. #else
  5506. if (CharacterFunctions::toLowerCase (thisPath[i])
  5507. != CharacterFunctions::toLowerCase (dirPath[i]))
  5508. #endif
  5509. {
  5510. break;
  5511. }
  5512. ++commonBitLength;
  5513. }
  5514. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5515. --commonBitLength;
  5516. // if the only common bit is the root, then just return the full path..
  5517. if (commonBitLength <= 0
  5518. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5519. return fullPath;
  5520. thisPath = thisPath.substring (commonBitLength);
  5521. dirPath = dirPath.substring (commonBitLength);
  5522. while (dirPath.isNotEmpty())
  5523. {
  5524. #if JUCE_WINDOWS
  5525. thisPath = T("..\\") + thisPath;
  5526. #else
  5527. thisPath = T("../") + thisPath;
  5528. #endif
  5529. const int sep = dirPath.indexOfChar (separator);
  5530. if (sep >= 0)
  5531. dirPath = dirPath.substring (sep + 1);
  5532. else
  5533. dirPath = String::empty;
  5534. }
  5535. return thisPath;
  5536. }
  5537. void File::findFileSystemRoots (Array<File>& destArray)
  5538. {
  5539. const StringArray roots (juce_getFileSystemRoots());
  5540. for (int i = 0; i < roots.size(); ++i)
  5541. destArray.add (File (roots[i]));
  5542. }
  5543. const String File::getVolumeLabel() const
  5544. {
  5545. int serialNum;
  5546. return juce_getVolumeLabel (fullPath, serialNum);
  5547. }
  5548. int File::getVolumeSerialNumber() const
  5549. {
  5550. int serialNum;
  5551. juce_getVolumeLabel (fullPath, serialNum);
  5552. return serialNum;
  5553. }
  5554. const File File::createTempFile (const String& fileNameEnding)
  5555. {
  5556. const File tempFile (getSpecialLocation (tempDirectory)
  5557. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5558. .withFileExtension (fileNameEnding));
  5559. if (tempFile.exists())
  5560. return createTempFile (fileNameEnding);
  5561. else
  5562. return tempFile;
  5563. }
  5564. END_JUCE_NAMESPACE
  5565. /*** End of inlined file: juce_File.cpp ***/
  5566. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5567. BEGIN_JUCE_NAMESPACE
  5568. void* juce_fileOpen (const String& path, bool forWriting);
  5569. void juce_fileClose (void* handle);
  5570. int juce_fileRead (void* handle, void* buffer, int size);
  5571. int64 juce_fileSetPosition (void* handle, int64 pos);
  5572. FileInputStream::FileInputStream (const File& f)
  5573. : file (f),
  5574. currentPosition (0),
  5575. needToSeek (true)
  5576. {
  5577. totalSize = f.getSize();
  5578. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5579. }
  5580. FileInputStream::~FileInputStream()
  5581. {
  5582. juce_fileClose (fileHandle);
  5583. }
  5584. int64 FileInputStream::getTotalLength()
  5585. {
  5586. return totalSize;
  5587. }
  5588. int FileInputStream::read (void* buffer, int bytesToRead)
  5589. {
  5590. int num = 0;
  5591. if (needToSeek)
  5592. {
  5593. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5594. return 0;
  5595. needToSeek = false;
  5596. }
  5597. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5598. currentPosition += num;
  5599. return num;
  5600. }
  5601. bool FileInputStream::isExhausted()
  5602. {
  5603. return currentPosition >= totalSize;
  5604. }
  5605. int64 FileInputStream::getPosition()
  5606. {
  5607. return currentPosition;
  5608. }
  5609. bool FileInputStream::setPosition (int64 pos)
  5610. {
  5611. pos = jlimit ((int64) 0, totalSize, pos);
  5612. needToSeek |= (currentPosition != pos);
  5613. currentPosition = pos;
  5614. return true;
  5615. }
  5616. END_JUCE_NAMESPACE
  5617. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5618. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5619. BEGIN_JUCE_NAMESPACE
  5620. void* juce_fileOpen (const String& path, bool forWriting);
  5621. void juce_fileClose (void* handle);
  5622. int juce_fileWrite (void* handle, const void* buffer, int size);
  5623. void juce_fileFlush (void* handle);
  5624. int64 juce_fileGetPosition (void* handle);
  5625. int64 juce_fileSetPosition (void* handle, int64 pos);
  5626. FileOutputStream::FileOutputStream (const File& f,
  5627. const int bufferSize_)
  5628. : file (f),
  5629. bufferSize (bufferSize_),
  5630. bytesInBuffer (0)
  5631. {
  5632. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5633. if (fileHandle != 0)
  5634. {
  5635. currentPosition = juce_fileGetPosition (fileHandle);
  5636. if (currentPosition < 0)
  5637. {
  5638. jassertfalse
  5639. juce_fileClose (fileHandle);
  5640. fileHandle = 0;
  5641. }
  5642. }
  5643. buffer.malloc (jmax (bufferSize_, 16));
  5644. }
  5645. FileOutputStream::~FileOutputStream()
  5646. {
  5647. flush();
  5648. juce_fileClose (fileHandle);
  5649. }
  5650. int64 FileOutputStream::getPosition()
  5651. {
  5652. return currentPosition;
  5653. }
  5654. bool FileOutputStream::setPosition (int64 newPosition)
  5655. {
  5656. if (newPosition != currentPosition)
  5657. {
  5658. flush();
  5659. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5660. }
  5661. return newPosition == currentPosition;
  5662. }
  5663. void FileOutputStream::flush()
  5664. {
  5665. if (bytesInBuffer > 0)
  5666. {
  5667. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5668. bytesInBuffer = 0;
  5669. }
  5670. juce_fileFlush (fileHandle);
  5671. }
  5672. bool FileOutputStream::write (const void* const src, const int numBytes)
  5673. {
  5674. if (bytesInBuffer + numBytes < bufferSize)
  5675. {
  5676. memcpy (buffer + bytesInBuffer, src, numBytes);
  5677. bytesInBuffer += numBytes;
  5678. currentPosition += numBytes;
  5679. }
  5680. else
  5681. {
  5682. if (bytesInBuffer > 0)
  5683. {
  5684. // flush the reservoir
  5685. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5686. bytesInBuffer = 0;
  5687. if (! wroteOk)
  5688. return false;
  5689. }
  5690. if (numBytes < bufferSize)
  5691. {
  5692. memcpy (buffer + bytesInBuffer, src, numBytes);
  5693. bytesInBuffer += numBytes;
  5694. currentPosition += numBytes;
  5695. }
  5696. else
  5697. {
  5698. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5699. currentPosition += bytesWritten;
  5700. return bytesWritten == numBytes;
  5701. }
  5702. }
  5703. return true;
  5704. }
  5705. END_JUCE_NAMESPACE
  5706. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5707. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5708. BEGIN_JUCE_NAMESPACE
  5709. FileSearchPath::FileSearchPath()
  5710. {
  5711. }
  5712. FileSearchPath::FileSearchPath (const String& path)
  5713. {
  5714. init (path);
  5715. }
  5716. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5717. : directories (other.directories)
  5718. {
  5719. }
  5720. FileSearchPath::~FileSearchPath()
  5721. {
  5722. }
  5723. FileSearchPath& FileSearchPath::operator= (const String& path)
  5724. {
  5725. init (path);
  5726. return *this;
  5727. }
  5728. void FileSearchPath::init (const String& path)
  5729. {
  5730. directories.clear();
  5731. directories.addTokens (path, T(";"), T("\""));
  5732. directories.trim();
  5733. directories.removeEmptyStrings();
  5734. for (int i = directories.size(); --i >= 0;)
  5735. directories.set (i, directories[i].unquoted());
  5736. }
  5737. int FileSearchPath::getNumPaths() const
  5738. {
  5739. return directories.size();
  5740. }
  5741. const File FileSearchPath::operator[] (const int index) const
  5742. {
  5743. return File (directories [index]);
  5744. }
  5745. const String FileSearchPath::toString() const
  5746. {
  5747. StringArray directories2 (directories);
  5748. for (int i = directories2.size(); --i >= 0;)
  5749. if (directories2[i].containsChar (T(';')))
  5750. directories2.set (i, directories2[i].quoted());
  5751. return directories2.joinIntoString (T(";"));
  5752. }
  5753. void FileSearchPath::add (const File& dir, const int insertIndex)
  5754. {
  5755. directories.insert (insertIndex, dir.getFullPathName());
  5756. }
  5757. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5758. {
  5759. for (int i = 0; i < directories.size(); ++i)
  5760. if (File (directories[i]) == dir)
  5761. return;
  5762. add (dir);
  5763. }
  5764. void FileSearchPath::remove (const int index)
  5765. {
  5766. directories.remove (index);
  5767. }
  5768. void FileSearchPath::addPath (const FileSearchPath& other)
  5769. {
  5770. for (int i = 0; i < other.getNumPaths(); ++i)
  5771. addIfNotAlreadyThere (other[i]);
  5772. }
  5773. void FileSearchPath::removeRedundantPaths()
  5774. {
  5775. for (int i = directories.size(); --i >= 0;)
  5776. {
  5777. const File d1 (directories[i]);
  5778. for (int j = directories.size(); --j >= 0;)
  5779. {
  5780. const File d2 (directories[j]);
  5781. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5782. {
  5783. directories.remove (i);
  5784. break;
  5785. }
  5786. }
  5787. }
  5788. }
  5789. void FileSearchPath::removeNonExistentPaths()
  5790. {
  5791. for (int i = directories.size(); --i >= 0;)
  5792. if (! File (directories[i]).isDirectory())
  5793. directories.remove (i);
  5794. }
  5795. int FileSearchPath::findChildFiles (Array<File>& results,
  5796. const int whatToLookFor,
  5797. const bool searchRecursively,
  5798. const String& wildCardPattern) const
  5799. {
  5800. int total = 0;
  5801. for (int i = 0; i < directories.size(); ++i)
  5802. total += operator[] (i).findChildFiles (results,
  5803. whatToLookFor,
  5804. searchRecursively,
  5805. wildCardPattern);
  5806. return total;
  5807. }
  5808. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5809. const bool checkRecursively) const
  5810. {
  5811. for (int i = directories.size(); --i >= 0;)
  5812. {
  5813. const File d (directories[i]);
  5814. if (checkRecursively)
  5815. {
  5816. if (fileToCheck.isAChildOf (d))
  5817. return true;
  5818. }
  5819. else
  5820. {
  5821. if (fileToCheck.getParentDirectory() == d)
  5822. return true;
  5823. }
  5824. }
  5825. return false;
  5826. }
  5827. END_JUCE_NAMESPACE
  5828. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5829. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5830. BEGIN_JUCE_NAMESPACE
  5831. NamedPipe::NamedPipe()
  5832. : internal (0)
  5833. {
  5834. }
  5835. NamedPipe::~NamedPipe()
  5836. {
  5837. close();
  5838. }
  5839. bool NamedPipe::openExisting (const String& pipeName)
  5840. {
  5841. currentPipeName = pipeName;
  5842. return openInternal (pipeName, false);
  5843. }
  5844. bool NamedPipe::createNewPipe (const String& pipeName)
  5845. {
  5846. currentPipeName = pipeName;
  5847. return openInternal (pipeName, true);
  5848. }
  5849. bool NamedPipe::isOpen() const
  5850. {
  5851. return internal != 0;
  5852. }
  5853. const String NamedPipe::getName() const
  5854. {
  5855. return currentPipeName;
  5856. }
  5857. // other methods for this class are implemented in the platform-specific files
  5858. END_JUCE_NAMESPACE
  5859. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5860. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5861. BEGIN_JUCE_NAMESPACE
  5862. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5863. {
  5864. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5865. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5866. suffix,
  5867. optionFlags);
  5868. }
  5869. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5870. : targetFile (targetFile_)
  5871. {
  5872. // If you use this constructor, you need to give it a valid target file!
  5873. jassert (targetFile != File::nonexistent);
  5874. createTempFile (targetFile.getParentDirectory(),
  5875. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5876. targetFile.getFileExtension(),
  5877. optionFlags);
  5878. }
  5879. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5880. const String& suffix, const int optionFlags)
  5881. {
  5882. if ((optionFlags & useHiddenFile) != 0)
  5883. name = T(".") + name;
  5884. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5885. }
  5886. TemporaryFile::~TemporaryFile()
  5887. {
  5888. // Have a few attempts at deleting the file before giving up..
  5889. for (int i = 5; --i >= 0;)
  5890. {
  5891. if (temporaryFile.deleteFile())
  5892. return;
  5893. Thread::sleep (50);
  5894. }
  5895. // Failed to delete our temporary file! Check that you've deleted all the
  5896. // file output streams that were using it!
  5897. jassertfalse;
  5898. }
  5899. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5900. {
  5901. // This method only works if you created this object with the constructor
  5902. // that takes a target file!
  5903. jassert (targetFile != File::nonexistent);
  5904. if (temporaryFile.exists())
  5905. {
  5906. // Have a few attempts at overwriting the file before giving up..
  5907. for (int i = 5; --i >= 0;)
  5908. {
  5909. if (temporaryFile.moveFileTo (targetFile))
  5910. return true;
  5911. Thread::sleep (100);
  5912. }
  5913. // Failed to overwrite the new file! Make sure you've not left any
  5914. // file streams hanging around when you call this method!
  5915. jassertfalse
  5916. }
  5917. else
  5918. {
  5919. // There's no temporary file to use. If your write failed, you should
  5920. // probably check, and not bother calling this method.
  5921. jassertfalse
  5922. }
  5923. return false;
  5924. }
  5925. END_JUCE_NAMESPACE
  5926. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5927. /*** Start of inlined file: juce_Socket.cpp ***/
  5928. #if JUCE_WINDOWS
  5929. #include <winsock2.h>
  5930. #ifdef _MSC_VER
  5931. #pragma warning (disable : 4127 4389 4018)
  5932. #endif
  5933. #else
  5934. #if JUCE_LINUX
  5935. #include <sys/types.h>
  5936. #include <sys/socket.h>
  5937. #include <sys/errno.h>
  5938. #include <unistd.h>
  5939. #include <netinet/in.h>
  5940. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5941. #include <CoreServices/CoreServices.h>
  5942. #endif
  5943. #include <fcntl.h>
  5944. #include <netdb.h>
  5945. #include <arpa/inet.h>
  5946. #include <netinet/tcp.h>
  5947. #endif
  5948. BEGIN_JUCE_NAMESPACE
  5949. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5950. typedef socklen_t juce_socklen_t;
  5951. #else
  5952. typedef int juce_socklen_t;
  5953. #endif
  5954. #if JUCE_WINDOWS
  5955. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5956. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5957. static void initWin32Sockets()
  5958. {
  5959. static CriticalSection lock;
  5960. const ScopedLock sl (lock);
  5961. if (juce_CloseWin32SocketLib == 0)
  5962. {
  5963. WSADATA wsaData;
  5964. const WORD wVersionRequested = MAKEWORD (1, 1);
  5965. WSAStartup (wVersionRequested, &wsaData);
  5966. juce_CloseWin32SocketLib = &WSACleanup;
  5967. }
  5968. }
  5969. #endif
  5970. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5971. {
  5972. const int sndBufSize = 65536;
  5973. const int rcvBufSize = 65536;
  5974. const int one = 1;
  5975. return handle > 0
  5976. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5977. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5978. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5979. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5980. }
  5981. static bool bindSocketToPort (const int handle, const int port) throw()
  5982. {
  5983. if (handle <= 0 || port <= 0)
  5984. return false;
  5985. struct sockaddr_in servTmpAddr;
  5986. zerostruct (servTmpAddr);
  5987. servTmpAddr.sin_family = PF_INET;
  5988. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5989. servTmpAddr.sin_port = htons ((uint16) port);
  5990. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5991. }
  5992. static int readSocket (const int handle,
  5993. void* const destBuffer, const int maxBytesToRead,
  5994. bool volatile& connected,
  5995. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5996. {
  5997. int bytesRead = 0;
  5998. while (bytesRead < maxBytesToRead)
  5999. {
  6000. int bytesThisTime;
  6001. #if JUCE_WINDOWS
  6002. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  6003. #else
  6004. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  6005. && errno == EINTR
  6006. && connected)
  6007. {
  6008. }
  6009. #endif
  6010. if (bytesThisTime <= 0 || ! connected)
  6011. {
  6012. if (bytesRead == 0)
  6013. bytesRead = -1;
  6014. break;
  6015. }
  6016. bytesRead += bytesThisTime;
  6017. if (! blockUntilSpecifiedAmountHasArrived)
  6018. break;
  6019. }
  6020. return bytesRead;
  6021. }
  6022. static int waitForReadiness (const int handle, const bool forReading,
  6023. const int timeoutMsecs) throw()
  6024. {
  6025. struct timeval timeout;
  6026. struct timeval* timeoutp;
  6027. if (timeoutMsecs >= 0)
  6028. {
  6029. timeout.tv_sec = timeoutMsecs / 1000;
  6030. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  6031. timeoutp = &timeout;
  6032. }
  6033. else
  6034. {
  6035. timeoutp = 0;
  6036. }
  6037. fd_set rset, wset;
  6038. FD_ZERO (&rset);
  6039. FD_SET (handle, &rset);
  6040. FD_ZERO (&wset);
  6041. FD_SET (handle, &wset);
  6042. fd_set* const prset = forReading ? &rset : 0;
  6043. fd_set* const pwset = forReading ? 0 : &wset;
  6044. #if JUCE_WINDOWS
  6045. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  6046. return -1;
  6047. #else
  6048. {
  6049. int result;
  6050. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  6051. && errno == EINTR)
  6052. {
  6053. }
  6054. if (result < 0)
  6055. return -1;
  6056. }
  6057. #endif
  6058. {
  6059. int opt;
  6060. juce_socklen_t len = sizeof (opt);
  6061. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  6062. || opt != 0)
  6063. return -1;
  6064. }
  6065. if ((forReading && FD_ISSET (handle, &rset))
  6066. || ((! forReading) && FD_ISSET (handle, &wset)))
  6067. return 1;
  6068. return 0;
  6069. }
  6070. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  6071. {
  6072. #if JUCE_WINDOWS
  6073. u_long nonBlocking = shouldBlock ? 0 : 1;
  6074. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  6075. return false;
  6076. #else
  6077. int socketFlags = fcntl (handle, F_GETFL, 0);
  6078. if (socketFlags == -1)
  6079. return false;
  6080. if (shouldBlock)
  6081. socketFlags &= ~O_NONBLOCK;
  6082. else
  6083. socketFlags |= O_NONBLOCK;
  6084. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  6085. return false;
  6086. #endif
  6087. return true;
  6088. }
  6089. static bool connectSocket (int volatile& handle,
  6090. const bool isDatagram,
  6091. void** serverAddress,
  6092. const String& hostName,
  6093. const int portNumber,
  6094. const int timeOutMillisecs) throw()
  6095. {
  6096. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  6097. if (hostEnt == 0)
  6098. return false;
  6099. struct in_addr targetAddress;
  6100. memcpy (&targetAddress.s_addr,
  6101. *(hostEnt->h_addr_list),
  6102. sizeof (targetAddress.s_addr));
  6103. struct sockaddr_in servTmpAddr;
  6104. zerostruct (servTmpAddr);
  6105. servTmpAddr.sin_family = PF_INET;
  6106. servTmpAddr.sin_addr = targetAddress;
  6107. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6108. if (handle < 0)
  6109. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  6110. if (handle < 0)
  6111. return false;
  6112. if (isDatagram)
  6113. {
  6114. *serverAddress = new struct sockaddr_in();
  6115. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  6116. return true;
  6117. }
  6118. setSocketBlockingState (handle, false);
  6119. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  6120. if (result < 0)
  6121. {
  6122. #if JUCE_WINDOWS
  6123. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  6124. #else
  6125. if (errno == EINPROGRESS)
  6126. #endif
  6127. {
  6128. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  6129. {
  6130. setSocketBlockingState (handle, true);
  6131. return false;
  6132. }
  6133. }
  6134. }
  6135. setSocketBlockingState (handle, true);
  6136. resetSocketOptions (handle, false, false);
  6137. return true;
  6138. }
  6139. StreamingSocket::StreamingSocket()
  6140. : portNumber (0),
  6141. handle (-1),
  6142. connected (false),
  6143. isListener (false)
  6144. {
  6145. #if JUCE_WINDOWS
  6146. initWin32Sockets();
  6147. #endif
  6148. }
  6149. StreamingSocket::StreamingSocket (const String& hostName_,
  6150. const int portNumber_,
  6151. const int handle_)
  6152. : hostName (hostName_),
  6153. portNumber (portNumber_),
  6154. handle (handle_),
  6155. connected (true),
  6156. isListener (false)
  6157. {
  6158. #if JUCE_WINDOWS
  6159. initWin32Sockets();
  6160. #endif
  6161. resetSocketOptions (handle_, false, false);
  6162. }
  6163. StreamingSocket::~StreamingSocket()
  6164. {
  6165. close();
  6166. }
  6167. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6168. {
  6169. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6170. : -1;
  6171. }
  6172. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6173. {
  6174. if (isListener || ! connected)
  6175. return -1;
  6176. #if JUCE_WINDOWS
  6177. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6178. #else
  6179. int result;
  6180. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6181. && errno == EINTR)
  6182. {
  6183. }
  6184. return result;
  6185. #endif
  6186. }
  6187. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6188. const int timeoutMsecs) const
  6189. {
  6190. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6191. : -1;
  6192. }
  6193. bool StreamingSocket::bindToPort (const int port)
  6194. {
  6195. return bindSocketToPort (handle, port);
  6196. }
  6197. bool StreamingSocket::connect (const String& remoteHostName,
  6198. const int remotePortNumber,
  6199. const int timeOutMillisecs)
  6200. {
  6201. if (isListener)
  6202. {
  6203. jassertfalse // a listener socket can't connect to another one!
  6204. return false;
  6205. }
  6206. if (connected)
  6207. close();
  6208. hostName = remoteHostName;
  6209. portNumber = remotePortNumber;
  6210. isListener = false;
  6211. connected = connectSocket (handle, false, 0, remoteHostName,
  6212. remotePortNumber, timeOutMillisecs);
  6213. if (! (connected && resetSocketOptions (handle, false, false)))
  6214. {
  6215. close();
  6216. return false;
  6217. }
  6218. return true;
  6219. }
  6220. void StreamingSocket::close()
  6221. {
  6222. #if JUCE_WINDOWS
  6223. closesocket (handle);
  6224. connected = false;
  6225. #else
  6226. if (connected)
  6227. {
  6228. connected = false;
  6229. if (isListener)
  6230. {
  6231. // need to do this to interrupt the accept() function..
  6232. StreamingSocket temp;
  6233. temp.connect ("localhost", portNumber, 1000);
  6234. }
  6235. }
  6236. ::close (handle);
  6237. #endif
  6238. hostName = String::empty;
  6239. portNumber = 0;
  6240. handle = -1;
  6241. isListener = false;
  6242. }
  6243. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6244. {
  6245. if (connected)
  6246. close();
  6247. hostName = "listener";
  6248. portNumber = newPortNumber;
  6249. isListener = true;
  6250. struct sockaddr_in servTmpAddr;
  6251. zerostruct (servTmpAddr);
  6252. servTmpAddr.sin_family = PF_INET;
  6253. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6254. if (localHostName.isNotEmpty())
  6255. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6256. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6257. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6258. if (handle < 0)
  6259. return false;
  6260. const int reuse = 1;
  6261. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6262. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6263. || listen (handle, SOMAXCONN) < 0)
  6264. {
  6265. close();
  6266. return false;
  6267. }
  6268. connected = true;
  6269. return true;
  6270. }
  6271. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6272. {
  6273. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6274. // prepare this socket as a listener.
  6275. if (connected && isListener)
  6276. {
  6277. struct sockaddr address;
  6278. juce_socklen_t len = sizeof (sockaddr);
  6279. const int newSocket = (int) accept (handle, &address, &len);
  6280. if (newSocket >= 0 && connected)
  6281. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6282. portNumber, newSocket);
  6283. }
  6284. return 0;
  6285. }
  6286. bool StreamingSocket::isLocal() const throw()
  6287. {
  6288. return hostName == T("127.0.0.1");
  6289. }
  6290. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6291. : portNumber (0),
  6292. handle (-1),
  6293. connected (true),
  6294. allowBroadcast (allowBroadcast_),
  6295. serverAddress (0)
  6296. {
  6297. #if JUCE_WINDOWS
  6298. initWin32Sockets();
  6299. #endif
  6300. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6301. bindToPort (localPortNumber);
  6302. }
  6303. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6304. const int handle_, const int localPortNumber)
  6305. : hostName (hostName_),
  6306. portNumber (portNumber_),
  6307. handle (handle_),
  6308. connected (true),
  6309. allowBroadcast (false),
  6310. serverAddress (0)
  6311. {
  6312. #if JUCE_WINDOWS
  6313. initWin32Sockets();
  6314. #endif
  6315. resetSocketOptions (handle_, true, allowBroadcast);
  6316. bindToPort (localPortNumber);
  6317. }
  6318. DatagramSocket::~DatagramSocket()
  6319. {
  6320. close();
  6321. delete ((struct sockaddr_in*) serverAddress);
  6322. serverAddress = 0;
  6323. }
  6324. void DatagramSocket::close()
  6325. {
  6326. #if JUCE_WINDOWS
  6327. closesocket (handle);
  6328. connected = false;
  6329. #else
  6330. connected = false;
  6331. ::close (handle);
  6332. #endif
  6333. hostName = String::empty;
  6334. portNumber = 0;
  6335. handle = -1;
  6336. }
  6337. bool DatagramSocket::bindToPort (const int port)
  6338. {
  6339. return bindSocketToPort (handle, port);
  6340. }
  6341. bool DatagramSocket::connect (const String& remoteHostName,
  6342. const int remotePortNumber,
  6343. const int timeOutMillisecs)
  6344. {
  6345. if (connected)
  6346. close();
  6347. hostName = remoteHostName;
  6348. portNumber = remotePortNumber;
  6349. connected = connectSocket (handle, true, &serverAddress,
  6350. remoteHostName, remotePortNumber,
  6351. timeOutMillisecs);
  6352. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6353. {
  6354. close();
  6355. return false;
  6356. }
  6357. return true;
  6358. }
  6359. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6360. {
  6361. struct sockaddr address;
  6362. juce_socklen_t len = sizeof (sockaddr);
  6363. while (waitUntilReady (true, -1) == 1)
  6364. {
  6365. char buf[1];
  6366. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6367. {
  6368. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6369. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6370. -1, -1);
  6371. }
  6372. }
  6373. return 0;
  6374. }
  6375. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6376. const int timeoutMsecs) const
  6377. {
  6378. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6379. : -1;
  6380. }
  6381. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6382. {
  6383. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6384. : -1;
  6385. }
  6386. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6387. {
  6388. // You need to call connect() first to set the server address..
  6389. jassert (serverAddress != 0 && connected);
  6390. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6391. numBytesToWrite, 0,
  6392. (const struct sockaddr*) serverAddress,
  6393. sizeof (struct sockaddr_in))
  6394. : -1;
  6395. }
  6396. bool DatagramSocket::isLocal() const throw()
  6397. {
  6398. return hostName == T("127.0.0.1");
  6399. }
  6400. END_JUCE_NAMESPACE
  6401. /*** End of inlined file: juce_Socket.cpp ***/
  6402. /*** Start of inlined file: juce_URL.cpp ***/
  6403. BEGIN_JUCE_NAMESPACE
  6404. URL::URL()
  6405. {
  6406. }
  6407. URL::URL (const String& url_)
  6408. : url (url_)
  6409. {
  6410. int i = url.indexOfChar (T('?'));
  6411. if (i >= 0)
  6412. {
  6413. do
  6414. {
  6415. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6416. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6417. if (equalsPos > i + 1)
  6418. {
  6419. if (nextAmp < 0)
  6420. {
  6421. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6422. removeEscapeChars (url.substring (equalsPos + 1)));
  6423. }
  6424. else if (nextAmp > 0 && equalsPos < nextAmp)
  6425. {
  6426. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6427. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6428. }
  6429. }
  6430. i = nextAmp;
  6431. }
  6432. while (i >= 0);
  6433. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6434. }
  6435. }
  6436. URL::URL (const URL& other)
  6437. : url (other.url),
  6438. postData (other.postData),
  6439. parameters (other.parameters),
  6440. filesToUpload (other.filesToUpload),
  6441. mimeTypes (other.mimeTypes)
  6442. {
  6443. }
  6444. URL& URL::operator= (const URL& other)
  6445. {
  6446. url = other.url;
  6447. postData = other.postData;
  6448. parameters = other.parameters;
  6449. filesToUpload = other.filesToUpload;
  6450. mimeTypes = other.mimeTypes;
  6451. return *this;
  6452. }
  6453. URL::~URL()
  6454. {
  6455. }
  6456. static const String getMangledParameters (const StringPairArray& parameters)
  6457. {
  6458. String p;
  6459. for (int i = 0; i < parameters.size(); ++i)
  6460. {
  6461. if (i > 0)
  6462. p += T("&");
  6463. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6464. << T("=")
  6465. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6466. }
  6467. return p;
  6468. }
  6469. const String URL::toString (const bool includeGetParameters) const
  6470. {
  6471. if (includeGetParameters && parameters.size() > 0)
  6472. return url + T("?") + getMangledParameters (parameters);
  6473. else
  6474. return url;
  6475. }
  6476. bool URL::isWellFormed() const
  6477. {
  6478. //xxx TODO
  6479. return url.isNotEmpty();
  6480. }
  6481. static int findStartOfDomain (const String& url)
  6482. {
  6483. int i = 0;
  6484. while (CharacterFunctions::isLetterOrDigit (url[i])
  6485. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6486. ++i;
  6487. return url[i] == T(':') ? i + 1 : 0;
  6488. }
  6489. const String URL::getDomain() const
  6490. {
  6491. int start = findStartOfDomain (url);
  6492. while (url[start] == T('/'))
  6493. ++start;
  6494. const int end1 = url.indexOfChar (start, T('/'));
  6495. const int end2 = url.indexOfChar (start, T(':'));
  6496. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6497. : jmin (end1, end2);
  6498. return url.substring (start, end);
  6499. }
  6500. const String URL::getSubPath() const
  6501. {
  6502. int start = findStartOfDomain (url);
  6503. while (url[start] == T('/'))
  6504. ++start;
  6505. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6506. return startOfPath <= 0 ? String::empty
  6507. : url.substring (startOfPath);
  6508. }
  6509. const String URL::getScheme() const
  6510. {
  6511. return url.substring (0, findStartOfDomain (url) - 1);
  6512. }
  6513. const URL URL::withNewSubPath (const String& newPath) const
  6514. {
  6515. int start = findStartOfDomain (url);
  6516. while (url[start] == T('/'))
  6517. ++start;
  6518. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6519. URL u (*this);
  6520. if (startOfPath > 0)
  6521. u.url = url.substring (0, startOfPath);
  6522. if (! u.url.endsWithChar (T('/')))
  6523. u.url << '/';
  6524. if (newPath.startsWithChar (T('/')))
  6525. u.url << newPath.substring (1);
  6526. else
  6527. u.url << newPath;
  6528. return u;
  6529. }
  6530. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6531. {
  6532. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6533. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6534. return true;
  6535. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6536. || possibleURL.containsChar (T('@'))
  6537. || possibleURL.endsWithChar (T('.'))
  6538. || (! possibleURL.containsChar (T('.'))))
  6539. return false;
  6540. if (possibleURL.startsWithIgnoreCase (T("www."))
  6541. && possibleURL.substring (5).containsChar (T('.')))
  6542. return true;
  6543. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6544. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6545. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6546. return true;
  6547. return false;
  6548. }
  6549. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6550. {
  6551. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6552. return atSign > 0
  6553. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6554. && (! possibleEmailAddress.endsWithChar (T('.')));
  6555. }
  6556. void* juce_openInternetFile (const String& url,
  6557. const String& headers,
  6558. const MemoryBlock& optionalPostData,
  6559. const bool isPost,
  6560. URL::OpenStreamProgressCallback* callback,
  6561. void* callbackContext,
  6562. int timeOutMs);
  6563. void juce_closeInternetFile (void* handle);
  6564. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6565. int juce_seekInInternetFile (void* handle, int newPosition);
  6566. int64 juce_getInternetFileContentLength (void* handle);
  6567. class WebInputStream : public InputStream
  6568. {
  6569. public:
  6570. WebInputStream (const URL& url,
  6571. const bool isPost_,
  6572. URL::OpenStreamProgressCallback* const progressCallback_,
  6573. void* const progressCallbackContext_,
  6574. const String& extraHeaders,
  6575. int timeOutMs_)
  6576. : position (0),
  6577. finished (false),
  6578. isPost (isPost_),
  6579. progressCallback (progressCallback_),
  6580. progressCallbackContext (progressCallbackContext_),
  6581. timeOutMs (timeOutMs_)
  6582. {
  6583. server = url.toString (! isPost);
  6584. if (isPost_)
  6585. createHeadersAndPostData (url);
  6586. headers += extraHeaders;
  6587. if (! headers.endsWithChar (T('\n')))
  6588. headers << "\r\n";
  6589. handle = juce_openInternetFile (server, headers, postData, isPost,
  6590. progressCallback_, progressCallbackContext_,
  6591. timeOutMs);
  6592. }
  6593. ~WebInputStream()
  6594. {
  6595. juce_closeInternetFile (handle);
  6596. }
  6597. bool isError() const
  6598. {
  6599. return handle == 0;
  6600. }
  6601. int64 getTotalLength()
  6602. {
  6603. return juce_getInternetFileContentLength (handle);
  6604. }
  6605. bool isExhausted()
  6606. {
  6607. return finished;
  6608. }
  6609. int read (void* dest, int bytes)
  6610. {
  6611. if (finished || isError())
  6612. {
  6613. return 0;
  6614. }
  6615. else
  6616. {
  6617. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6618. position += bytesRead;
  6619. if (bytesRead == 0)
  6620. finished = true;
  6621. return bytesRead;
  6622. }
  6623. }
  6624. int64 getPosition()
  6625. {
  6626. return position;
  6627. }
  6628. bool setPosition (int64 wantedPos)
  6629. {
  6630. if (wantedPos != position)
  6631. {
  6632. finished = false;
  6633. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6634. if (actualPos == wantedPos)
  6635. {
  6636. position = wantedPos;
  6637. }
  6638. else
  6639. {
  6640. if (wantedPos < position)
  6641. {
  6642. juce_closeInternetFile (handle);
  6643. position = 0;
  6644. finished = false;
  6645. handle = juce_openInternetFile (server, headers, postData, isPost,
  6646. progressCallback, progressCallbackContext,
  6647. timeOutMs);
  6648. }
  6649. skipNextBytes (wantedPos - position);
  6650. }
  6651. }
  6652. return true;
  6653. }
  6654. juce_UseDebuggingNewOperator
  6655. private:
  6656. String server, headers;
  6657. MemoryBlock postData;
  6658. int64 position;
  6659. bool finished;
  6660. const bool isPost;
  6661. void* handle;
  6662. URL::OpenStreamProgressCallback* const progressCallback;
  6663. void* const progressCallbackContext;
  6664. const int timeOutMs;
  6665. void createHeadersAndPostData (const URL& url)
  6666. {
  6667. if (url.getFilesToUpload().size() > 0)
  6668. {
  6669. // need to upload some files, so do it as multi-part...
  6670. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6671. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6672. appendUTF8ToPostData ("--" + boundary);
  6673. int i;
  6674. for (i = 0; i < url.getParameters().size(); ++i)
  6675. {
  6676. String s;
  6677. s << "\r\nContent-Disposition: form-data; name=\""
  6678. << url.getParameters().getAllKeys() [i]
  6679. << "\"\r\n\r\n"
  6680. << url.getParameters().getAllValues() [i]
  6681. << "\r\n--"
  6682. << boundary;
  6683. appendUTF8ToPostData (s);
  6684. }
  6685. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6686. {
  6687. const File f (url.getFilesToUpload().getAllValues() [i]);
  6688. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6689. String s;
  6690. s << "\r\nContent-Disposition: form-data; name=\""
  6691. << paramName
  6692. << "\"; filename=\""
  6693. << f.getFileName()
  6694. << "\"\r\n";
  6695. const String mimeType (url.getMimeTypesOfUploadFiles()
  6696. .getValue (paramName, String::empty));
  6697. if (mimeType.isNotEmpty())
  6698. s << "Content-Type: " << mimeType << "\r\n";
  6699. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6700. appendUTF8ToPostData (s);
  6701. f.loadFileAsData (postData);
  6702. s = "\r\n--" + boundary;
  6703. appendUTF8ToPostData (s);
  6704. }
  6705. appendUTF8ToPostData ("--\r\n");
  6706. }
  6707. else
  6708. {
  6709. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6710. appendUTF8ToPostData (url.getPostData());
  6711. // just a short text attachment, so use simple url encoding..
  6712. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6713. + String ((unsigned int) postData.getSize())
  6714. + "\r\n";
  6715. }
  6716. }
  6717. void appendUTF8ToPostData (const String& text)
  6718. {
  6719. postData.append (text.toUTF8(),
  6720. (int) strlen (text.toUTF8()));
  6721. }
  6722. WebInputStream (const WebInputStream&);
  6723. WebInputStream& operator= (const WebInputStream&);
  6724. };
  6725. InputStream* URL::createInputStream (const bool usePostCommand,
  6726. OpenStreamProgressCallback* const progressCallback,
  6727. void* const progressCallbackContext,
  6728. const String& extraHeaders,
  6729. const int timeOutMs) const
  6730. {
  6731. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6732. progressCallback, progressCallbackContext,
  6733. extraHeaders,
  6734. timeOutMs));
  6735. return wi->isError() ? 0 : wi.release();
  6736. }
  6737. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6738. const bool usePostCommand) const
  6739. {
  6740. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6741. if (in != 0)
  6742. {
  6743. in->readIntoMemoryBlock (destData, -1);
  6744. return true;
  6745. }
  6746. return false;
  6747. }
  6748. const String URL::readEntireTextStream (const bool usePostCommand) const
  6749. {
  6750. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6751. if (in != 0)
  6752. return in->readEntireStreamAsString();
  6753. return String::empty;
  6754. }
  6755. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6756. {
  6757. XmlDocument doc (readEntireTextStream (usePostCommand));
  6758. return doc.getDocumentElement();
  6759. }
  6760. const URL URL::withParameter (const String& parameterName,
  6761. const String& parameterValue) const
  6762. {
  6763. URL u (*this);
  6764. u.parameters.set (parameterName, parameterValue);
  6765. return u;
  6766. }
  6767. const URL URL::withFileToUpload (const String& parameterName,
  6768. const File& fileToUpload,
  6769. const String& mimeType) const
  6770. {
  6771. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6772. URL u (*this);
  6773. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6774. u.mimeTypes.set (parameterName, mimeType);
  6775. return u;
  6776. }
  6777. const URL URL::withPOSTData (const String& postData_) const
  6778. {
  6779. URL u (*this);
  6780. u.postData = postData_;
  6781. return u;
  6782. }
  6783. const StringPairArray& URL::getParameters() const
  6784. {
  6785. return parameters;
  6786. }
  6787. const StringPairArray& URL::getFilesToUpload() const
  6788. {
  6789. return filesToUpload;
  6790. }
  6791. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6792. {
  6793. return mimeTypes;
  6794. }
  6795. const String URL::removeEscapeChars (const String& s)
  6796. {
  6797. const int len = s.length();
  6798. HeapBlock <char> resultUTF8 (len * 4);
  6799. char* r = resultUTF8;
  6800. for (int i = 0; i < len; ++i)
  6801. {
  6802. char c = (char) s[i];
  6803. if (c == 0)
  6804. break;
  6805. if (c == '+')
  6806. {
  6807. c = ' ';
  6808. }
  6809. else if (c == '%')
  6810. {
  6811. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6812. i += 2;
  6813. }
  6814. *r++ = c;
  6815. }
  6816. return String::fromUTF8 (resultUTF8);
  6817. }
  6818. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6819. {
  6820. String result;
  6821. result.preallocateStorage (s.length() + 8);
  6822. const char* utf8 = s.toUTF8();
  6823. const char* legalChars = isParameter ? "_-.*!'()"
  6824. : "_-$.*!'(),";
  6825. while (*utf8 != 0)
  6826. {
  6827. const char c = *utf8++;
  6828. if (CharacterFunctions::isLetterOrDigit (c)
  6829. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6830. {
  6831. result << c;
  6832. }
  6833. else
  6834. {
  6835. const int v = (int) (uint8) c;
  6836. if (v < 0x10)
  6837. result << T("%0");
  6838. else
  6839. result << T('%');
  6840. result << String::toHexString (v);
  6841. }
  6842. }
  6843. return result;
  6844. }
  6845. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6846. bool URL::launchInDefaultBrowser() const
  6847. {
  6848. String u (toString (true));
  6849. if (u.contains (T("@")) && ! u.contains (T(":")))
  6850. u = "mailto:" + u;
  6851. return juce_launchFile (u, String::empty);
  6852. }
  6853. END_JUCE_NAMESPACE
  6854. /*** End of inlined file: juce_URL.cpp ***/
  6855. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6856. BEGIN_JUCE_NAMESPACE
  6857. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6858. const int bufferSize_,
  6859. const bool deleteSourceWhenDestroyed)
  6860. : source (source_),
  6861. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6862. bufferSize (jmax (256, bufferSize_)),
  6863. position (source_->getPosition()),
  6864. lastReadPos (0),
  6865. bufferOverlap (128)
  6866. {
  6867. const int sourceSize = (int) source_->getTotalLength();
  6868. if (sourceSize >= 0)
  6869. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6870. bufferStart = position;
  6871. buffer.malloc (bufferSize);
  6872. }
  6873. BufferedInputStream::~BufferedInputStream()
  6874. {
  6875. }
  6876. int64 BufferedInputStream::getTotalLength()
  6877. {
  6878. return source->getTotalLength();
  6879. }
  6880. int64 BufferedInputStream::getPosition()
  6881. {
  6882. return position;
  6883. }
  6884. bool BufferedInputStream::setPosition (int64 newPosition)
  6885. {
  6886. position = jmax ((int64) 0, newPosition);
  6887. return true;
  6888. }
  6889. bool BufferedInputStream::isExhausted()
  6890. {
  6891. return (position >= lastReadPos)
  6892. && source->isExhausted();
  6893. }
  6894. void BufferedInputStream::ensureBuffered()
  6895. {
  6896. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6897. if (position < bufferStart || position >= bufferEndOverlap)
  6898. {
  6899. int bytesRead;
  6900. if (position < lastReadPos
  6901. && position >= bufferEndOverlap
  6902. && position >= bufferStart)
  6903. {
  6904. const int bytesToKeep = (int) (lastReadPos - position);
  6905. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6906. bufferStart = position;
  6907. bytesRead = source->read (buffer + bytesToKeep,
  6908. bufferSize - bytesToKeep);
  6909. lastReadPos += bytesRead;
  6910. bytesRead += bytesToKeep;
  6911. }
  6912. else
  6913. {
  6914. bufferStart = position;
  6915. source->setPosition (bufferStart);
  6916. bytesRead = source->read (buffer, bufferSize);
  6917. lastReadPos = bufferStart + bytesRead;
  6918. }
  6919. while (bytesRead < bufferSize)
  6920. buffer [bytesRead++] = 0;
  6921. }
  6922. }
  6923. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6924. {
  6925. if (position >= bufferStart
  6926. && position + maxBytesToRead <= lastReadPos)
  6927. {
  6928. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6929. position += maxBytesToRead;
  6930. return maxBytesToRead;
  6931. }
  6932. else
  6933. {
  6934. if (position < bufferStart || position >= lastReadPos)
  6935. ensureBuffered();
  6936. int bytesRead = 0;
  6937. while (maxBytesToRead > 0)
  6938. {
  6939. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6940. if (bytesAvailable > 0)
  6941. {
  6942. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6943. maxBytesToRead -= bytesAvailable;
  6944. bytesRead += bytesAvailable;
  6945. position += bytesAvailable;
  6946. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6947. }
  6948. const int64 oldLastReadPos = lastReadPos;
  6949. ensureBuffered();
  6950. if (oldLastReadPos == lastReadPos)
  6951. break; // if ensureBuffered() failed to read any more data, bail out
  6952. if (isExhausted())
  6953. break;
  6954. }
  6955. return bytesRead;
  6956. }
  6957. }
  6958. const String BufferedInputStream::readString()
  6959. {
  6960. if (position >= bufferStart
  6961. && position < lastReadPos)
  6962. {
  6963. const int maxChars = (int) (lastReadPos - position);
  6964. const char* const src = buffer + (int) (position - bufferStart);
  6965. for (int i = 0; i < maxChars; ++i)
  6966. {
  6967. if (src[i] == 0)
  6968. {
  6969. position += i + 1;
  6970. return String::fromUTF8 (src, i);
  6971. }
  6972. }
  6973. }
  6974. return InputStream::readString();
  6975. }
  6976. END_JUCE_NAMESPACE
  6977. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6978. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6979. BEGIN_JUCE_NAMESPACE
  6980. FileInputSource::FileInputSource (const File& file_)
  6981. : file (file_)
  6982. {
  6983. }
  6984. FileInputSource::~FileInputSource()
  6985. {
  6986. }
  6987. InputStream* FileInputSource::createInputStream()
  6988. {
  6989. return file.createInputStream();
  6990. }
  6991. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6992. {
  6993. return file.getSiblingFile (relatedItemPath).createInputStream();
  6994. }
  6995. int64 FileInputSource::hashCode() const
  6996. {
  6997. return file.hashCode();
  6998. }
  6999. END_JUCE_NAMESPACE
  7000. /*** End of inlined file: juce_FileInputSource.cpp ***/
  7001. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  7002. BEGIN_JUCE_NAMESPACE
  7003. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  7004. const size_t sourceDataSize,
  7005. const bool keepInternalCopy)
  7006. : data (static_cast <const char*> (sourceData)),
  7007. dataSize (sourceDataSize),
  7008. position (0)
  7009. {
  7010. if (keepInternalCopy)
  7011. {
  7012. internalCopy.append (data, sourceDataSize);
  7013. data = static_cast <const char*> (internalCopy.getData());
  7014. }
  7015. }
  7016. MemoryInputStream::MemoryInputStream (const MemoryBlock& sourceData,
  7017. const bool keepInternalCopy)
  7018. : data (static_cast <const char*> (sourceData.getData())),
  7019. dataSize (sourceData.getSize()),
  7020. position (0)
  7021. {
  7022. if (keepInternalCopy)
  7023. {
  7024. internalCopy = sourceData;
  7025. data = static_cast <const char*> (internalCopy.getData());
  7026. }
  7027. }
  7028. MemoryInputStream::~MemoryInputStream()
  7029. {
  7030. }
  7031. int64 MemoryInputStream::getTotalLength()
  7032. {
  7033. return dataSize;
  7034. }
  7035. int MemoryInputStream::read (void* const buffer, const int howMany)
  7036. {
  7037. jassert (howMany >= 0);
  7038. const int num = jmin (howMany, (int) (dataSize - position));
  7039. memcpy (buffer, data + position, num);
  7040. position += num;
  7041. return (int) num;
  7042. }
  7043. bool MemoryInputStream::isExhausted()
  7044. {
  7045. return (position >= dataSize);
  7046. }
  7047. bool MemoryInputStream::setPosition (const int64 pos)
  7048. {
  7049. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  7050. return true;
  7051. }
  7052. int64 MemoryInputStream::getPosition()
  7053. {
  7054. return position;
  7055. }
  7056. END_JUCE_NAMESPACE
  7057. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  7058. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  7059. BEGIN_JUCE_NAMESPACE
  7060. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  7061. const size_t blockSizeToIncreaseBy,
  7062. MemoryBlock* const memoryBlockToWriteTo)
  7063. : data (memoryBlockToWriteTo),
  7064. position (0),
  7065. size (0),
  7066. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  7067. {
  7068. if (data == 0)
  7069. dataToDelete = data = new MemoryBlock (initialSize);
  7070. else
  7071. data->setSize (initialSize, false);
  7072. }
  7073. MemoryOutputStream::~MemoryOutputStream()
  7074. {
  7075. flush();
  7076. }
  7077. void MemoryOutputStream::flush()
  7078. {
  7079. if (dataToDelete == 0)
  7080. data->setSize (size, false);
  7081. }
  7082. void MemoryOutputStream::reset() throw()
  7083. {
  7084. position = 0;
  7085. size = 0;
  7086. }
  7087. bool MemoryOutputStream::write (const void* const buffer, int howMany)
  7088. {
  7089. if (howMany > 0)
  7090. {
  7091. size_t storageNeeded = position + howMany;
  7092. if (storageNeeded >= data->getSize())
  7093. {
  7094. // if we need more space, increase the block by at least 10%..
  7095. storageNeeded += jmax (blockSize, storageNeeded / 10);
  7096. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  7097. data->ensureSize (storageNeeded);
  7098. }
  7099. data->copyFrom (buffer, (int) position, howMany);
  7100. position += howMany;
  7101. size = jmax (size, position);
  7102. }
  7103. return true;
  7104. }
  7105. const char* MemoryOutputStream::getData() const throw()
  7106. {
  7107. char* const d = static_cast <char*> (data->getData());
  7108. if (data->getSize() > size)
  7109. d [size] = 0;
  7110. return d;
  7111. }
  7112. size_t MemoryOutputStream::getDataSize() const throw()
  7113. {
  7114. return size;
  7115. }
  7116. int64 MemoryOutputStream::getPosition()
  7117. {
  7118. return position;
  7119. }
  7120. bool MemoryOutputStream::setPosition (int64 newPosition)
  7121. {
  7122. if (newPosition <= (int64) size)
  7123. {
  7124. // ok to seek backwards
  7125. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  7126. return true;
  7127. }
  7128. else
  7129. {
  7130. // trying to make it bigger isn't a good thing to do..
  7131. return false;
  7132. }
  7133. }
  7134. END_JUCE_NAMESPACE
  7135. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  7136. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  7137. BEGIN_JUCE_NAMESPACE
  7138. SubregionStream::SubregionStream (InputStream* const sourceStream,
  7139. const int64 startPositionInSourceStream_,
  7140. const int64 lengthOfSourceStream_,
  7141. const bool deleteSourceWhenDestroyed) throw()
  7142. : source (sourceStream),
  7143. startPositionInSourceStream (startPositionInSourceStream_),
  7144. lengthOfSourceStream (lengthOfSourceStream_)
  7145. {
  7146. if (deleteSourceWhenDestroyed)
  7147. sourceToDelete = source;
  7148. setPosition (0);
  7149. }
  7150. SubregionStream::~SubregionStream() throw()
  7151. {
  7152. }
  7153. int64 SubregionStream::getTotalLength()
  7154. {
  7155. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  7156. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  7157. : srcLen;
  7158. }
  7159. int64 SubregionStream::getPosition()
  7160. {
  7161. return source->getPosition() - startPositionInSourceStream;
  7162. }
  7163. bool SubregionStream::setPosition (int64 newPosition)
  7164. {
  7165. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7166. }
  7167. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7168. {
  7169. if (lengthOfSourceStream < 0)
  7170. {
  7171. return source->read (destBuffer, maxBytesToRead);
  7172. }
  7173. else
  7174. {
  7175. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7176. if (maxBytesToRead <= 0)
  7177. return 0;
  7178. return source->read (destBuffer, maxBytesToRead);
  7179. }
  7180. }
  7181. bool SubregionStream::isExhausted()
  7182. {
  7183. if (lengthOfSourceStream >= 0)
  7184. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7185. else
  7186. return source->isExhausted();
  7187. }
  7188. END_JUCE_NAMESPACE
  7189. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7190. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7191. BEGIN_JUCE_NAMESPACE
  7192. PerformanceCounter::PerformanceCounter (const String& name_,
  7193. int runsPerPrintout,
  7194. const File& loggingFile)
  7195. : name (name_),
  7196. numRuns (0),
  7197. runsPerPrint (runsPerPrintout),
  7198. totalTime (0),
  7199. outputFile (loggingFile)
  7200. {
  7201. if (outputFile != File::nonexistent)
  7202. {
  7203. String s ("**** Counter for \"");
  7204. s << name_ << "\" started at: "
  7205. << Time::getCurrentTime().toString (true, true)
  7206. << "\r\n";
  7207. outputFile.appendText (s, false, false);
  7208. }
  7209. }
  7210. PerformanceCounter::~PerformanceCounter()
  7211. {
  7212. printStatistics();
  7213. }
  7214. void PerformanceCounter::start()
  7215. {
  7216. started = Time::getHighResolutionTicks();
  7217. }
  7218. void PerformanceCounter::stop()
  7219. {
  7220. const int64 now = Time::getHighResolutionTicks();
  7221. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7222. if (++numRuns == runsPerPrint)
  7223. printStatistics();
  7224. }
  7225. void PerformanceCounter::printStatistics()
  7226. {
  7227. if (numRuns > 0)
  7228. {
  7229. String s ("Performance count for \"");
  7230. s << name << "\" - average over " << numRuns << " run(s) = ";
  7231. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7232. if (micros > 10000)
  7233. s << (micros/1000) << " millisecs";
  7234. else
  7235. s << micros << " microsecs";
  7236. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7237. Logger::outputDebugString (s);
  7238. s << "\r\n";
  7239. if (outputFile != File::nonexistent)
  7240. outputFile.appendText (s, false, false);
  7241. numRuns = 0;
  7242. totalTime = 0;
  7243. }
  7244. }
  7245. END_JUCE_NAMESPACE
  7246. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7247. /*** Start of inlined file: juce_Uuid.cpp ***/
  7248. BEGIN_JUCE_NAMESPACE
  7249. Uuid::Uuid()
  7250. {
  7251. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7252. // to make it very very unlikely that two UUIDs will ever be the same..
  7253. static int64 macAddresses[2];
  7254. static bool hasCheckedMacAddresses = false;
  7255. if (! hasCheckedMacAddresses)
  7256. {
  7257. hasCheckedMacAddresses = true;
  7258. SystemStats::getMACAddresses (macAddresses, 2);
  7259. }
  7260. value.asInt64[0] = macAddresses[0];
  7261. value.asInt64[1] = macAddresses[1];
  7262. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7263. // whose seed will carry over between calls to this method.
  7264. Random r (macAddresses[0] ^ macAddresses[1]
  7265. ^ Random::getSystemRandom().nextInt64());
  7266. for (int i = 4; --i >= 0;)
  7267. {
  7268. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7269. value.asInt[i] ^= r.nextInt();
  7270. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7271. }
  7272. }
  7273. Uuid::~Uuid() throw()
  7274. {
  7275. }
  7276. Uuid::Uuid (const Uuid& other)
  7277. : value (other.value)
  7278. {
  7279. }
  7280. Uuid& Uuid::operator= (const Uuid& other)
  7281. {
  7282. value = other.value;
  7283. return *this;
  7284. }
  7285. bool Uuid::operator== (const Uuid& other) const
  7286. {
  7287. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7288. }
  7289. bool Uuid::operator!= (const Uuid& other) const
  7290. {
  7291. return ! operator== (other);
  7292. }
  7293. bool Uuid::isNull() const throw()
  7294. {
  7295. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7296. }
  7297. const String Uuid::toString() const
  7298. {
  7299. return String::toHexString (value.asBytes, 16, 0);
  7300. }
  7301. Uuid::Uuid (const String& uuidString)
  7302. {
  7303. operator= (uuidString);
  7304. }
  7305. Uuid& Uuid::operator= (const String& uuidString)
  7306. {
  7307. int destIndex = 0;
  7308. int i = 0;
  7309. for (;;)
  7310. {
  7311. int byte = 0;
  7312. for (int loop = 2; --loop >= 0;)
  7313. {
  7314. byte <<= 4;
  7315. for (;;)
  7316. {
  7317. const tchar c = uuidString [i++];
  7318. if (c >= T('0') && c <= T('9'))
  7319. {
  7320. byte |= c - T('0');
  7321. break;
  7322. }
  7323. else if (c >= T('a') && c <= T('z'))
  7324. {
  7325. byte |= c - (T('a') - 10);
  7326. break;
  7327. }
  7328. else if (c >= T('A') && c <= T('Z'))
  7329. {
  7330. byte |= c - (T('A') - 10);
  7331. break;
  7332. }
  7333. else if (c == 0)
  7334. {
  7335. while (destIndex < 16)
  7336. value.asBytes [destIndex++] = 0;
  7337. return *this;
  7338. }
  7339. }
  7340. }
  7341. value.asBytes [destIndex++] = (uint8) byte;
  7342. }
  7343. }
  7344. Uuid::Uuid (const uint8* const rawData)
  7345. {
  7346. operator= (rawData);
  7347. }
  7348. Uuid& Uuid::operator= (const uint8* const rawData)
  7349. {
  7350. if (rawData != 0)
  7351. memcpy (value.asBytes, rawData, 16);
  7352. else
  7353. zeromem (value.asBytes, 16);
  7354. return *this;
  7355. }
  7356. END_JUCE_NAMESPACE
  7357. /*** End of inlined file: juce_Uuid.cpp ***/
  7358. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7359. BEGIN_JUCE_NAMESPACE
  7360. class ZipFile::ZipEntryInfo
  7361. {
  7362. public:
  7363. ZipFile::ZipEntry entry;
  7364. int streamOffset;
  7365. int compressedSize;
  7366. bool compressed;
  7367. };
  7368. class ZipFile::ZipInputStream : public InputStream
  7369. {
  7370. public:
  7371. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7372. : file (file_),
  7373. zipEntryInfo (zei),
  7374. pos (0),
  7375. headerSize (0),
  7376. inputStream (0)
  7377. {
  7378. inputStream = file_.inputStream;
  7379. if (file_.inputSource != 0)
  7380. {
  7381. inputStream = file.inputSource->createInputStream();
  7382. }
  7383. else
  7384. {
  7385. #ifdef JUCE_DEBUG
  7386. file_.numOpenStreams++;
  7387. #endif
  7388. }
  7389. char buffer [30];
  7390. if (inputStream != 0
  7391. && inputStream->setPosition (zei.streamOffset)
  7392. && inputStream->read (buffer, 30) == 30
  7393. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7394. {
  7395. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7396. + ByteOrder::littleEndianShort (buffer + 28);
  7397. }
  7398. }
  7399. ~ZipInputStream() throw()
  7400. {
  7401. #ifdef JUCE_DEBUG
  7402. if (inputStream != 0 && inputStream == file.inputStream)
  7403. file.numOpenStreams--;
  7404. #endif
  7405. if (inputStream != file.inputStream)
  7406. delete inputStream;
  7407. }
  7408. int64 getTotalLength() throw()
  7409. {
  7410. return zipEntryInfo.compressedSize;
  7411. }
  7412. int read (void* buffer, int howMany) throw()
  7413. {
  7414. if (headerSize <= 0)
  7415. return 0;
  7416. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7417. if (inputStream == 0)
  7418. return 0;
  7419. int num;
  7420. if (inputStream == file.inputStream)
  7421. {
  7422. const ScopedLock sl (file.lock);
  7423. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7424. num = inputStream->read (buffer, howMany);
  7425. }
  7426. else
  7427. {
  7428. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7429. num = inputStream->read (buffer, howMany);
  7430. }
  7431. pos += num;
  7432. return num;
  7433. }
  7434. bool isExhausted() throw()
  7435. {
  7436. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7437. }
  7438. int64 getPosition() throw()
  7439. {
  7440. return pos;
  7441. }
  7442. bool setPosition (int64 newPos) throw()
  7443. {
  7444. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7445. return true;
  7446. }
  7447. private:
  7448. ZipFile& file;
  7449. ZipEntryInfo zipEntryInfo;
  7450. int64 pos;
  7451. int headerSize;
  7452. InputStream* inputStream;
  7453. ZipInputStream (const ZipInputStream&);
  7454. ZipInputStream& operator= (const ZipInputStream&);
  7455. };
  7456. ZipFile::ZipFile (InputStream* const source_,
  7457. const bool deleteStreamWhenDestroyed) throw()
  7458. : inputStream (source_)
  7459. #ifdef JUCE_DEBUG
  7460. , numOpenStreams (0)
  7461. #endif
  7462. {
  7463. if (deleteStreamWhenDestroyed)
  7464. streamToDelete = inputStream;
  7465. init();
  7466. }
  7467. ZipFile::ZipFile (const File& file)
  7468. : inputStream (0)
  7469. #ifdef JUCE_DEBUG
  7470. , numOpenStreams (0)
  7471. #endif
  7472. {
  7473. inputSource = new FileInputSource (file);
  7474. init();
  7475. }
  7476. ZipFile::ZipFile (InputSource* const inputSource_)
  7477. : inputStream (0),
  7478. inputSource (inputSource_)
  7479. #ifdef JUCE_DEBUG
  7480. , numOpenStreams (0)
  7481. #endif
  7482. {
  7483. init();
  7484. }
  7485. ZipFile::~ZipFile() throw()
  7486. {
  7487. #ifdef JUCE_DEBUG
  7488. entries.clear();
  7489. // If you hit this assertion, it means you've created a stream to read
  7490. // one of the items in the zipfile, but you've forgotten to delete that
  7491. // stream object before deleting the file.. Streams can't be kept open
  7492. // after the file is deleted because they need to share the input
  7493. // stream that the file uses to read itself.
  7494. jassert (numOpenStreams == 0);
  7495. #endif
  7496. }
  7497. int ZipFile::getNumEntries() const throw()
  7498. {
  7499. return entries.size();
  7500. }
  7501. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7502. {
  7503. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7504. return (zei != 0) ? &(zei->entry)
  7505. : 0;
  7506. }
  7507. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7508. {
  7509. for (int i = 0; i < entries.size(); ++i)
  7510. if (entries.getUnchecked (i)->entry.filename == fileName)
  7511. return i;
  7512. return -1;
  7513. }
  7514. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7515. {
  7516. return getEntry (getIndexOfFileName (fileName));
  7517. }
  7518. InputStream* ZipFile::createStreamForEntry (const int index)
  7519. {
  7520. ZipEntryInfo* const zei = entries[index];
  7521. InputStream* stream = 0;
  7522. if (zei != 0)
  7523. {
  7524. stream = new ZipInputStream (*this, *zei);
  7525. if (zei->compressed)
  7526. {
  7527. stream = new GZIPDecompressorInputStream (stream, true, true,
  7528. zei->entry.uncompressedSize);
  7529. // (much faster to unzip in big blocks using a buffer..)
  7530. stream = new BufferedInputStream (stream, 32768, true);
  7531. }
  7532. }
  7533. return stream;
  7534. }
  7535. class ZipFile::ZipFilenameComparator
  7536. {
  7537. public:
  7538. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7539. {
  7540. return first->entry.filename.compare (second->entry.filename);
  7541. }
  7542. };
  7543. void ZipFile::sortEntriesByFilename()
  7544. {
  7545. ZipFilenameComparator sorter;
  7546. entries.sort (sorter);
  7547. }
  7548. void ZipFile::init()
  7549. {
  7550. ScopedPointer <InputStream> toDelete;
  7551. InputStream* in = inputStream;
  7552. if (inputSource != 0)
  7553. {
  7554. in = inputSource->createInputStream();
  7555. toDelete = in;
  7556. }
  7557. if (in != 0)
  7558. {
  7559. int numEntries = 0;
  7560. int pos = findEndOfZipEntryTable (in, numEntries);
  7561. if (pos >= 0 && pos < in->getTotalLength())
  7562. {
  7563. const int size = (int) (in->getTotalLength() - pos);
  7564. in->setPosition (pos);
  7565. MemoryBlock headerData;
  7566. if (in->readIntoMemoryBlock (headerData, size) == size)
  7567. {
  7568. pos = 0;
  7569. for (int i = 0; i < numEntries; ++i)
  7570. {
  7571. if (pos + 46 > size)
  7572. break;
  7573. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7574. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7575. if (pos + 46 + fileNameLen > size)
  7576. break;
  7577. ZipEntryInfo* const zei = new ZipEntryInfo();
  7578. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7579. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7580. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7581. const int year = 1980 + (date >> 9);
  7582. const int month = ((date >> 5) & 15) - 1;
  7583. const int day = date & 31;
  7584. const int hours = time >> 11;
  7585. const int minutes = (time >> 5) & 63;
  7586. const int seconds = (time & 31) << 1;
  7587. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7588. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7589. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7590. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7591. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7592. entries.add (zei);
  7593. pos += 46 + fileNameLen
  7594. + ByteOrder::littleEndianShort (buffer + 30)
  7595. + ByteOrder::littleEndianShort (buffer + 32);
  7596. }
  7597. }
  7598. }
  7599. }
  7600. }
  7601. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7602. {
  7603. BufferedInputStream in (input, 8192, false);
  7604. in.setPosition (in.getTotalLength());
  7605. int64 pos = in.getPosition();
  7606. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7607. char buffer [32];
  7608. zeromem (buffer, sizeof (buffer));
  7609. while (pos > lowestPos)
  7610. {
  7611. in.setPosition (pos - 22);
  7612. pos = in.getPosition();
  7613. memcpy (buffer + 22, buffer, 4);
  7614. if (in.read (buffer, 22) != 22)
  7615. return 0;
  7616. for (int i = 0; i < 22; ++i)
  7617. {
  7618. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7619. {
  7620. in.setPosition (pos + i);
  7621. in.read (buffer, 22);
  7622. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7623. return ByteOrder::littleEndianInt (buffer + 16);
  7624. }
  7625. }
  7626. }
  7627. return 0;
  7628. }
  7629. void ZipFile::uncompressTo (const File& targetDirectory,
  7630. const bool shouldOverwriteFiles)
  7631. {
  7632. for (int i = 0; i < entries.size(); ++i)
  7633. {
  7634. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7635. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7636. if (zei.filename.endsWithChar (T('/')))
  7637. {
  7638. targetFile.createDirectory(); // (entry is a directory, not a file)
  7639. }
  7640. else
  7641. {
  7642. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7643. if (in != 0)
  7644. {
  7645. if (shouldOverwriteFiles)
  7646. targetFile.deleteFile();
  7647. if ((! targetFile.exists())
  7648. && targetFile.getParentDirectory().createDirectory())
  7649. {
  7650. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7651. if (out != 0)
  7652. {
  7653. out->writeFromInputStream (*in, -1);
  7654. out = 0;
  7655. targetFile.setCreationTime (zei.fileTime);
  7656. targetFile.setLastModificationTime (zei.fileTime);
  7657. targetFile.setLastAccessTime (zei.fileTime);
  7658. }
  7659. }
  7660. }
  7661. }
  7662. }
  7663. }
  7664. END_JUCE_NAMESPACE
  7665. /*** End of inlined file: juce_ZipFile.cpp ***/
  7666. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7667. #ifdef _MSC_VER
  7668. #pragma warning (disable: 4514 4996)
  7669. #pragma warning (push)
  7670. #endif
  7671. #include <cwctype>
  7672. #include <cctype>
  7673. #include <ctime>
  7674. #ifdef _MSC_VER
  7675. #pragma warning (pop)
  7676. #endif
  7677. BEGIN_JUCE_NAMESPACE
  7678. int CharacterFunctions::length (const char* const s) throw()
  7679. {
  7680. return (int) strlen (s);
  7681. }
  7682. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7683. {
  7684. return (int) wcslen (s);
  7685. }
  7686. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7687. {
  7688. strncpy (dest, src, maxChars);
  7689. }
  7690. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7691. {
  7692. wcsncpy (dest, src, maxChars);
  7693. }
  7694. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7695. {
  7696. mbstowcs (dest, src, maxChars);
  7697. }
  7698. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7699. {
  7700. wcstombs (dest, src, maxChars);
  7701. }
  7702. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7703. {
  7704. return (int) wcstombs (0, src, 0);
  7705. }
  7706. void CharacterFunctions::append (char* dest, const char* src) throw()
  7707. {
  7708. strcat (dest, src);
  7709. }
  7710. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7711. {
  7712. wcscat (dest, src);
  7713. }
  7714. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7715. {
  7716. return strcmp (s1, s2);
  7717. }
  7718. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7719. {
  7720. jassert (s1 != 0 && s2 != 0);
  7721. return wcscmp (s1, s2);
  7722. }
  7723. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7724. {
  7725. jassert (s1 != 0 && s2 != 0);
  7726. return strncmp (s1, s2, maxChars);
  7727. }
  7728. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7729. {
  7730. jassert (s1 != 0 && s2 != 0);
  7731. return wcsncmp (s1, s2, maxChars);
  7732. }
  7733. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7734. {
  7735. jassert (s1 != 0 && s2 != 0);
  7736. for (;;)
  7737. {
  7738. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7739. if (diff != 0)
  7740. return diff;
  7741. else if (*s1 == 0)
  7742. break;
  7743. ++s1;
  7744. ++s2;
  7745. }
  7746. return 0;
  7747. }
  7748. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7749. {
  7750. return -compare (s2, s1);
  7751. }
  7752. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7753. {
  7754. jassert (s1 != 0 && s2 != 0);
  7755. #if JUCE_WIN32
  7756. return stricmp (s1, s2);
  7757. #else
  7758. return strcasecmp (s1, s2);
  7759. #endif
  7760. }
  7761. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7762. {
  7763. jassert (s1 != 0 && s2 != 0);
  7764. #if JUCE_WIN32
  7765. return _wcsicmp (s1, s2);
  7766. #else
  7767. for (;;)
  7768. {
  7769. if (*s1 != *s2)
  7770. {
  7771. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7772. if (diff != 0)
  7773. return diff < 0 ? -1 : 1;
  7774. }
  7775. else if (*s1 == 0)
  7776. break;
  7777. ++s1;
  7778. ++s2;
  7779. }
  7780. return 0;
  7781. #endif
  7782. }
  7783. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7784. {
  7785. jassert (s1 != 0 && s2 != 0);
  7786. #if JUCE_WIN32
  7787. return strnicmp (s1, s2, maxChars);
  7788. #else
  7789. return strncasecmp (s1, s2, maxChars);
  7790. #endif
  7791. }
  7792. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7793. {
  7794. jassert (s1 != 0 && s2 != 0);
  7795. #if JUCE_WIN32
  7796. return _wcsnicmp (s1, s2, maxChars);
  7797. #else
  7798. while (--maxChars >= 0)
  7799. {
  7800. if (*s1 != *s2)
  7801. {
  7802. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7803. if (diff != 0)
  7804. return diff < 0 ? -1 : 1;
  7805. }
  7806. else if (*s1 == 0)
  7807. break;
  7808. ++s1;
  7809. ++s2;
  7810. }
  7811. return 0;
  7812. #endif
  7813. }
  7814. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7815. {
  7816. return strstr (haystack, needle);
  7817. }
  7818. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7819. {
  7820. return wcsstr (haystack, needle);
  7821. }
  7822. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7823. {
  7824. if (haystack != 0)
  7825. {
  7826. int i = 0;
  7827. if (ignoreCase)
  7828. {
  7829. const char n1 = toLowerCase (needle);
  7830. const char n2 = toUpperCase (needle);
  7831. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7832. {
  7833. while (haystack[i] != 0)
  7834. {
  7835. if (haystack[i] == n1 || haystack[i] == n2)
  7836. return i;
  7837. ++i;
  7838. }
  7839. return -1;
  7840. }
  7841. jassert (n1 == needle);
  7842. }
  7843. while (haystack[i] != 0)
  7844. {
  7845. if (haystack[i] == needle)
  7846. return i;
  7847. ++i;
  7848. }
  7849. }
  7850. return -1;
  7851. }
  7852. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7853. {
  7854. if (haystack != 0)
  7855. {
  7856. int i = 0;
  7857. if (ignoreCase)
  7858. {
  7859. const juce_wchar n1 = toLowerCase (needle);
  7860. const juce_wchar n2 = toUpperCase (needle);
  7861. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7862. {
  7863. while (haystack[i] != 0)
  7864. {
  7865. if (haystack[i] == n1 || haystack[i] == n2)
  7866. return i;
  7867. ++i;
  7868. }
  7869. return -1;
  7870. }
  7871. jassert (n1 == needle);
  7872. }
  7873. while (haystack[i] != 0)
  7874. {
  7875. if (haystack[i] == needle)
  7876. return i;
  7877. ++i;
  7878. }
  7879. }
  7880. return -1;
  7881. }
  7882. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7883. {
  7884. jassert (haystack != 0);
  7885. int i = 0;
  7886. while (haystack[i] != 0)
  7887. {
  7888. if (haystack[i] == needle)
  7889. return i;
  7890. ++i;
  7891. }
  7892. return -1;
  7893. }
  7894. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7895. {
  7896. jassert (haystack != 0);
  7897. int i = 0;
  7898. while (haystack[i] != 0)
  7899. {
  7900. if (haystack[i] == needle)
  7901. return i;
  7902. ++i;
  7903. }
  7904. return -1;
  7905. }
  7906. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7907. {
  7908. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7909. }
  7910. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7911. {
  7912. if (allowedChars == 0)
  7913. return 0;
  7914. int i = 0;
  7915. for (;;)
  7916. {
  7917. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7918. break;
  7919. ++i;
  7920. }
  7921. return i;
  7922. }
  7923. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7924. {
  7925. return (int) strftime (dest, maxChars, format, tm);
  7926. }
  7927. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7928. {
  7929. return (int) wcsftime (dest, maxChars, format, tm);
  7930. }
  7931. int CharacterFunctions::getIntValue (const char* const s) throw()
  7932. {
  7933. return atoi (s);
  7934. }
  7935. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7936. {
  7937. #if JUCE_WIN32
  7938. return _wtoi (s);
  7939. #else
  7940. int v = 0;
  7941. while (isWhitespace (*s))
  7942. ++s;
  7943. const bool isNeg = *s == T('-');
  7944. if (isNeg)
  7945. ++s;
  7946. for (;;)
  7947. {
  7948. const wchar_t c = *s++;
  7949. if (c >= T('0') && c <= T('9'))
  7950. v = v * 10 + (int) (c - T('0'));
  7951. else
  7952. break;
  7953. }
  7954. return isNeg ? -v : v;
  7955. #endif
  7956. }
  7957. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7958. {
  7959. #if JUCE_LINUX
  7960. return atoll (s);
  7961. #elif defined (JUCE_WIN32)
  7962. return _atoi64 (s);
  7963. #else
  7964. int64 v = 0;
  7965. while (isWhitespace (*s))
  7966. ++s;
  7967. const bool isNeg = *s == T('-');
  7968. if (isNeg)
  7969. ++s;
  7970. for (;;)
  7971. {
  7972. const char c = *s++;
  7973. if (c >= '0' && c <= '9')
  7974. v = v * 10 + (int64) (c - '0');
  7975. else
  7976. break;
  7977. }
  7978. return isNeg ? -v : v;
  7979. #endif
  7980. }
  7981. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7982. {
  7983. #if JUCE_WIN32
  7984. return _wtoi64 (s);
  7985. #else
  7986. int64 v = 0;
  7987. while (isWhitespace (*s))
  7988. ++s;
  7989. const bool isNeg = *s == T('-');
  7990. if (isNeg)
  7991. ++s;
  7992. for (;;)
  7993. {
  7994. const juce_wchar c = *s++;
  7995. if (c >= T('0') && c <= T('9'))
  7996. v = v * 10 + (int64) (c - T('0'));
  7997. else
  7998. break;
  7999. }
  8000. return isNeg ? -v : v;
  8001. #endif
  8002. }
  8003. static double juce_mulexp10 (const double value, int exponent) throw()
  8004. {
  8005. if (exponent == 0)
  8006. return value;
  8007. if (value == 0)
  8008. return 0;
  8009. const bool negative = (exponent < 0);
  8010. if (negative)
  8011. exponent = -exponent;
  8012. double result = 1.0, power = 10.0;
  8013. for (int bit = 1; exponent != 0; bit <<= 1)
  8014. {
  8015. if ((exponent & bit) != 0)
  8016. {
  8017. exponent ^= bit;
  8018. result *= power;
  8019. if (exponent == 0)
  8020. break;
  8021. }
  8022. power *= power;
  8023. }
  8024. return negative ? (value / result) : (value * result);
  8025. }
  8026. template <class CharType>
  8027. double juce_atof (const CharType* const original) throw()
  8028. {
  8029. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  8030. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  8031. int exponent = 0, decPointIndex = 0, digit = 0;
  8032. int lastDigit = 0, numSignificantDigits = 0;
  8033. bool isNegative = false, digitsFound = false;
  8034. const int maxSignificantDigits = 15 + 2;
  8035. const CharType* s = original;
  8036. while (CharacterFunctions::isWhitespace (*s))
  8037. ++s;
  8038. switch (*s)
  8039. {
  8040. case '-': isNegative = true; // fall-through..
  8041. case '+': ++s;
  8042. }
  8043. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  8044. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  8045. for (;;)
  8046. {
  8047. if (CharacterFunctions::isDigit (*s))
  8048. {
  8049. lastDigit = digit;
  8050. digit = *s++ - '0';
  8051. digitsFound = true;
  8052. if (decPointIndex != 0)
  8053. exponentAdjustment[1]++;
  8054. if (numSignificantDigits == 0 && digit == 0)
  8055. continue;
  8056. if (++numSignificantDigits > maxSignificantDigits)
  8057. {
  8058. if (digit > 5)
  8059. ++accumulator [decPointIndex];
  8060. else if (digit == 5 && (lastDigit & 1) != 0)
  8061. ++accumulator [decPointIndex];
  8062. if (decPointIndex > 0)
  8063. exponentAdjustment[1]--;
  8064. else
  8065. exponentAdjustment[0]++;
  8066. while (CharacterFunctions::isDigit (*s))
  8067. {
  8068. ++s;
  8069. if (decPointIndex == 0)
  8070. exponentAdjustment[0]++;
  8071. }
  8072. }
  8073. else
  8074. {
  8075. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  8076. if (accumulator [decPointIndex] > maxAccumulatorValue)
  8077. {
  8078. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  8079. + accumulator [decPointIndex];
  8080. accumulator [decPointIndex] = 0;
  8081. exponentAccumulator [decPointIndex] = 0;
  8082. }
  8083. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  8084. exponentAccumulator [decPointIndex]++;
  8085. }
  8086. }
  8087. else if (decPointIndex == 0 && *s == '.')
  8088. {
  8089. ++s;
  8090. decPointIndex = 1;
  8091. if (numSignificantDigits > maxSignificantDigits)
  8092. {
  8093. while (CharacterFunctions::isDigit (*s))
  8094. ++s;
  8095. break;
  8096. }
  8097. }
  8098. else
  8099. {
  8100. break;
  8101. }
  8102. }
  8103. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  8104. if (decPointIndex != 0)
  8105. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  8106. if ((*s == 'e' || *s == 'E') && digitsFound)
  8107. {
  8108. bool negativeExponent = false;
  8109. switch (*++s)
  8110. {
  8111. case '-': negativeExponent = true; // fall-through..
  8112. case '+': ++s;
  8113. }
  8114. while (CharacterFunctions::isDigit (*s))
  8115. exponent = (exponent * 10) + (*s++ - '0');
  8116. if (negativeExponent)
  8117. exponent = -exponent;
  8118. }
  8119. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  8120. if (decPointIndex != 0)
  8121. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  8122. return isNegative ? -r : r;
  8123. }
  8124. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  8125. {
  8126. return juce_atof <char> (s);
  8127. }
  8128. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  8129. {
  8130. return juce_atof <juce_wchar> (s);
  8131. }
  8132. char CharacterFunctions::toUpperCase (const char character) throw()
  8133. {
  8134. return (char) toupper (character);
  8135. }
  8136. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  8137. {
  8138. return towupper (character);
  8139. }
  8140. void CharacterFunctions::toUpperCase (char* s) throw()
  8141. {
  8142. #if JUCE_WIN32
  8143. strupr (s);
  8144. #else
  8145. while (*s != 0)
  8146. {
  8147. *s = toUpperCase (*s);
  8148. ++s;
  8149. }
  8150. #endif
  8151. }
  8152. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  8153. {
  8154. #if JUCE_WIN32
  8155. _wcsupr (s);
  8156. #else
  8157. while (*s != 0)
  8158. {
  8159. *s = toUpperCase (*s);
  8160. ++s;
  8161. }
  8162. #endif
  8163. }
  8164. bool CharacterFunctions::isUpperCase (const char character) throw()
  8165. {
  8166. return isupper (character) != 0;
  8167. }
  8168. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8169. {
  8170. #if JUCE_WIN32
  8171. return iswupper (character) != 0;
  8172. #else
  8173. return toLowerCase (character) != character;
  8174. #endif
  8175. }
  8176. char CharacterFunctions::toLowerCase (const char character) throw()
  8177. {
  8178. return (char) tolower (character);
  8179. }
  8180. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8181. {
  8182. return towlower (character);
  8183. }
  8184. void CharacterFunctions::toLowerCase (char* s) throw()
  8185. {
  8186. #if JUCE_WIN32
  8187. strlwr (s);
  8188. #else
  8189. while (*s != 0)
  8190. {
  8191. *s = toLowerCase (*s);
  8192. ++s;
  8193. }
  8194. #endif
  8195. }
  8196. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8197. {
  8198. #if JUCE_WIN32
  8199. _wcslwr (s);
  8200. #else
  8201. while (*s != 0)
  8202. {
  8203. *s = toLowerCase (*s);
  8204. ++s;
  8205. }
  8206. #endif
  8207. }
  8208. bool CharacterFunctions::isLowerCase (const char character) throw()
  8209. {
  8210. return islower (character) != 0;
  8211. }
  8212. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8213. {
  8214. #if JUCE_WIN32
  8215. return iswlower (character) != 0;
  8216. #else
  8217. return toUpperCase (character) != character;
  8218. #endif
  8219. }
  8220. bool CharacterFunctions::isWhitespace (const char character) throw()
  8221. {
  8222. return character == T(' ') || (character <= 13 && character >= 9);
  8223. }
  8224. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8225. {
  8226. return iswspace (character) != 0;
  8227. }
  8228. bool CharacterFunctions::isDigit (const char character) throw()
  8229. {
  8230. return (character >= '0' && character <= '9');
  8231. }
  8232. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8233. {
  8234. return iswdigit (character) != 0;
  8235. }
  8236. bool CharacterFunctions::isLetter (const char character) throw()
  8237. {
  8238. return (character >= 'a' && character <= 'z')
  8239. || (character >= 'A' && character <= 'Z');
  8240. }
  8241. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8242. {
  8243. return iswalpha (character) != 0;
  8244. }
  8245. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8246. {
  8247. return (character >= 'a' && character <= 'z')
  8248. || (character >= 'A' && character <= 'Z')
  8249. || (character >= '0' && character <= '9');
  8250. }
  8251. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8252. {
  8253. return iswalnum (character) != 0;
  8254. }
  8255. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  8256. {
  8257. if (digit >= '0' && digit <= '9')
  8258. return digit - '0';
  8259. else if (digit >= 'a' && digit <= 'f')
  8260. return digit - ('a' - 10);
  8261. else if (digit >= 'A' && digit <= 'F')
  8262. return digit - ('A' - 10);
  8263. return -1;
  8264. }
  8265. END_JUCE_NAMESPACE
  8266. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8267. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8268. BEGIN_JUCE_NAMESPACE
  8269. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8270. {
  8271. loadFromText (fileContents);
  8272. }
  8273. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8274. {
  8275. loadFromText (fileToLoad.loadFileAsString());
  8276. }
  8277. LocalisedStrings::~LocalisedStrings()
  8278. {
  8279. }
  8280. const String LocalisedStrings::translate (const String& text) const
  8281. {
  8282. return translations.getValue (text, text);
  8283. }
  8284. static int findCloseQuote (const String& text, int startPos)
  8285. {
  8286. tchar lastChar = 0;
  8287. for (;;)
  8288. {
  8289. const tchar c = text [startPos];
  8290. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8291. break;
  8292. lastChar = c;
  8293. ++startPos;
  8294. }
  8295. return startPos;
  8296. }
  8297. static const String unescapeString (const String& s)
  8298. {
  8299. return s.replace (T("\\\""), T("\""))
  8300. .replace (T("\\\'"), T("\'"))
  8301. .replace (T("\\t"), T("\t"))
  8302. .replace (T("\\r"), T("\r"))
  8303. .replace (T("\\n"), T("\n"));
  8304. }
  8305. void LocalisedStrings::loadFromText (const String& fileContents)
  8306. {
  8307. StringArray lines;
  8308. lines.addLines (fileContents);
  8309. for (int i = 0; i < lines.size(); ++i)
  8310. {
  8311. String line (lines[i].trim());
  8312. if (line.startsWithChar (T('"')))
  8313. {
  8314. int closeQuote = findCloseQuote (line, 1);
  8315. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8316. if (originalText.isNotEmpty())
  8317. {
  8318. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8319. closeQuote = findCloseQuote (line, openingQuote + 1);
  8320. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8321. if (newText.isNotEmpty())
  8322. translations.set (originalText, newText);
  8323. }
  8324. }
  8325. else if (line.startsWithIgnoreCase (T("language:")))
  8326. {
  8327. languageName = line.substring (9).trim();
  8328. }
  8329. else if (line.startsWithIgnoreCase (T("countries:")))
  8330. {
  8331. countryCodes.addTokens (line.substring (10).trim(), true);
  8332. countryCodes.trim();
  8333. countryCodes.removeEmptyStrings();
  8334. }
  8335. }
  8336. }
  8337. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8338. {
  8339. translations.setIgnoresCase (shouldIgnoreCase);
  8340. }
  8341. static CriticalSection currentMappingsLock;
  8342. static LocalisedStrings* currentMappings = 0;
  8343. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8344. {
  8345. const ScopedLock sl (currentMappingsLock);
  8346. delete currentMappings;
  8347. currentMappings = newTranslations;
  8348. }
  8349. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8350. {
  8351. return currentMappings;
  8352. }
  8353. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8354. {
  8355. const ScopedLock sl (currentMappingsLock);
  8356. if (currentMappings != 0)
  8357. return currentMappings->translate (text);
  8358. return text;
  8359. }
  8360. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8361. {
  8362. return translateWithCurrentMappings (String (text));
  8363. }
  8364. END_JUCE_NAMESPACE
  8365. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8366. /*** Start of inlined file: juce_String.cpp ***/
  8367. #ifdef _MSC_VER
  8368. #pragma warning (disable: 4514)
  8369. #pragma warning (push)
  8370. #endif
  8371. #include <locale>
  8372. #if JUCE_MSVC
  8373. #include <float.h>
  8374. #endif
  8375. BEGIN_JUCE_NAMESPACE
  8376. #ifdef _MSC_VER
  8377. #pragma warning (pop)
  8378. #endif
  8379. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  8380. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  8381. #endif
  8382. class StringHolder
  8383. {
  8384. public:
  8385. static juce_wchar* create (const size_t numChars)
  8386. {
  8387. StringHolder* const s = reinterpret_cast <StringHolder*> (juce_malloc (sizeof (StringHolder) + numChars * sizeof (juce_wchar)));
  8388. s->refCount = 0;
  8389. s->allocatedNumChars = numChars;
  8390. return &(s->text[0]);
  8391. }
  8392. static inline juce_wchar* getEmpty() throw()
  8393. {
  8394. return &(empty.text[0]);
  8395. }
  8396. static void retain (juce_wchar* const text) throw()
  8397. {
  8398. Atomic::increment (bufferFromText (text)->refCount);
  8399. }
  8400. static inline void release (StringHolder* const b) throw()
  8401. {
  8402. if (Atomic::decrementAndReturn (b->refCount) == -1 && b != &empty)
  8403. juce_free (b);
  8404. }
  8405. static void release (juce_wchar* const text) throw()
  8406. {
  8407. release (bufferFromText (text));
  8408. }
  8409. static juce_wchar* makeUnique (juce_wchar* const text)
  8410. {
  8411. StringHolder* const b = bufferFromText (text);
  8412. if (b->refCount <= 0)
  8413. return text;
  8414. juce_wchar* const newText = create (b->allocatedNumChars);
  8415. memcpy (newText, text, (b->allocatedNumChars + 1) * sizeof (juce_wchar));
  8416. release (b);
  8417. return newText;
  8418. }
  8419. static juce_wchar* makeUniqueWithSize (juce_wchar* const text, size_t numChars)
  8420. {
  8421. StringHolder* const b = bufferFromText (text);
  8422. if (b->refCount <= 0 && b->allocatedNumChars >= numChars)
  8423. return text;
  8424. juce_wchar* const newText = create (jmax (b->allocatedNumChars, numChars));
  8425. memcpy (newText, text, (b->allocatedNumChars + 1) * sizeof (juce_wchar));
  8426. release (b);
  8427. return newText;
  8428. }
  8429. static size_t getAllocatedNumChars (juce_wchar* const text) throw()
  8430. {
  8431. return bufferFromText (text)->allocatedNumChars;
  8432. }
  8433. int refCount;
  8434. size_t allocatedNumChars;
  8435. juce_wchar text[1];
  8436. static StringHolder empty;
  8437. private:
  8438. static inline StringHolder* bufferFromText (juce_wchar* const text) throw()
  8439. {
  8440. return reinterpret_cast <StringHolder*> (reinterpret_cast <char*> (text) - offsetof (StringHolder, StringHolder::text));
  8441. }
  8442. };
  8443. StringHolder StringHolder::empty = { 0x3fffffff, 0, { 0 } };
  8444. const String String::empty;
  8445. void String::createInternal (const juce_wchar* const t, const size_t numChars)
  8446. {
  8447. jassert (t[numChars] == 0); // must have a null terminator
  8448. text = StringHolder::create (numChars);
  8449. memcpy (text, t, (numChars + 1) * sizeof (juce_wchar));
  8450. }
  8451. void String::appendInternal (const juce_wchar* const newText, const int numExtraChars)
  8452. {
  8453. if (numExtraChars > 0)
  8454. {
  8455. const int oldLen = length();
  8456. const int newTotalLen = oldLen + numExtraChars;
  8457. text = StringHolder::makeUniqueWithSize (text, newTotalLen);
  8458. memcpy (text + oldLen, newText, numExtraChars * sizeof (juce_wchar));
  8459. text [newTotalLen] = 0;
  8460. }
  8461. }
  8462. void String::dupeInternalIfMultiplyReferenced()
  8463. {
  8464. text = StringHolder::makeUnique (text);
  8465. }
  8466. void String::preallocateStorage (const size_t numChars)
  8467. {
  8468. text = StringHolder::makeUniqueWithSize (text, numChars);
  8469. }
  8470. String::String() throw()
  8471. : text (StringHolder::getEmpty())
  8472. {
  8473. }
  8474. String::~String() throw()
  8475. {
  8476. StringHolder::release (text);
  8477. }
  8478. String::String (const String& other) throw()
  8479. : text (other.text)
  8480. {
  8481. StringHolder::retain (text);
  8482. }
  8483. void String::swapWith (String& other) throw()
  8484. {
  8485. swapVariables (text, other.text);
  8486. }
  8487. String& String::operator= (const String& other) throw()
  8488. {
  8489. juce_wchar* const newText = other.text;
  8490. StringHolder::retain (newText);
  8491. StringHolder::release (static_cast <juce_wchar*> (Atomic::swapPointers ((void* volatile*) &text, newText)));
  8492. return *this;
  8493. }
  8494. String::String (const size_t numChars, const int /*dummyVariable*/)
  8495. : text (StringHolder::create (numChars))
  8496. {
  8497. }
  8498. String::String (const char* const t)
  8499. {
  8500. if (t != 0 && *t != 0)
  8501. {
  8502. const int len = CharacterFunctions::length (t);
  8503. text = StringHolder::create (len);
  8504. CharacterFunctions::copy (text, t, len + 1);
  8505. }
  8506. else
  8507. {
  8508. text = StringHolder::getEmpty();
  8509. }
  8510. }
  8511. String::String (const juce_wchar* const t)
  8512. {
  8513. if (t != 0 && *t != 0)
  8514. {
  8515. const int len = CharacterFunctions::length (t);
  8516. text = StringHolder::create (len);
  8517. memcpy (text, t, (len + 1) * sizeof (juce_wchar));
  8518. }
  8519. else
  8520. {
  8521. text = StringHolder::getEmpty();
  8522. }
  8523. }
  8524. String::String (const char* const t, const size_t maxChars)
  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. text = StringHolder::create (i);
  8533. CharacterFunctions::copy (text, t, i);
  8534. text[i] = 0;
  8535. }
  8536. else
  8537. {
  8538. text = StringHolder::getEmpty();
  8539. }
  8540. }
  8541. String::String (const juce_wchar* const t, const size_t maxChars)
  8542. {
  8543. int i;
  8544. for (i = 0; (size_t) i < maxChars; ++i)
  8545. if (t[i] == 0)
  8546. break;
  8547. if (i > 0)
  8548. {
  8549. text = StringHolder::create (i);
  8550. memcpy (text, t, i * sizeof (juce_wchar));
  8551. text[i] = 0;
  8552. }
  8553. else
  8554. {
  8555. text = StringHolder::getEmpty();
  8556. }
  8557. }
  8558. const String String::charToString (const juce_wchar character)
  8559. {
  8560. juce_wchar temp[] = { character, 0 };
  8561. return String (temp);
  8562. }
  8563. namespace NumberToStringConverters
  8564. {
  8565. // pass in a pointer to the END of a buffer..
  8566. static juce_wchar* int64ToString (juce_wchar* t, const int64 n) throw()
  8567. {
  8568. *--t = 0;
  8569. int64 v = (n >= 0) ? n : -n;
  8570. do
  8571. {
  8572. *--t = (juce_wchar) (T('0') + (int) (v % 10));
  8573. v /= 10;
  8574. } while (v > 0);
  8575. if (n < 0)
  8576. *--t = T('-');
  8577. return t;
  8578. }
  8579. static juce_wchar* uint64ToString (juce_wchar* t, int64 v) throw()
  8580. {
  8581. *--t = 0;
  8582. do
  8583. {
  8584. *--t = (juce_wchar) (T('0') + (int) (v % 10));
  8585. v /= 10;
  8586. } while (v > 0);
  8587. return t;
  8588. }
  8589. static juce_wchar* intToString (juce_wchar* t, const int n) throw()
  8590. {
  8591. if (n == (int) 0x80000000) // (would cause an overflow)
  8592. return int64ToString (t, n);
  8593. *--t = 0;
  8594. int v = abs (n);
  8595. do
  8596. {
  8597. *--t = (juce_wchar) (T('0') + (v % 10));
  8598. v /= 10;
  8599. } while (v > 0);
  8600. if (n < 0)
  8601. *--t = T('-');
  8602. return t;
  8603. }
  8604. static juce_wchar* uintToString (juce_wchar* t, unsigned int v) throw()
  8605. {
  8606. *--t = 0;
  8607. do
  8608. {
  8609. *--t = (juce_wchar) (T('0') + (v % 10));
  8610. v /= 10;
  8611. } while (v > 0);
  8612. return t;
  8613. }
  8614. static juce_wchar getDecimalPoint()
  8615. {
  8616. static juce_wchar dp = std::use_facet <std::numpunct <wchar_t> > (std::locale()).decimal_point();
  8617. return dp;
  8618. }
  8619. static juce_wchar* doubleToString (juce_wchar* buffer, int numChars, double n, int numDecPlaces, size_t& len) throw()
  8620. {
  8621. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8622. {
  8623. juce_wchar* const end = buffer + numChars;
  8624. juce_wchar* t = end;
  8625. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8626. *--t = (juce_wchar) 0;
  8627. while (numDecPlaces >= 0 || v > 0)
  8628. {
  8629. if (numDecPlaces == 0)
  8630. *--t = getDecimalPoint();
  8631. *--t = (juce_wchar) (T('0') + (v % 10));
  8632. v /= 10;
  8633. --numDecPlaces;
  8634. }
  8635. if (n < 0)
  8636. *--t = T('-');
  8637. len = end - t - 1;
  8638. return t;
  8639. }
  8640. else
  8641. {
  8642. #if JUCE_WIN32
  8643. #if _MSC_VER <= 1200
  8644. len = _snwprintf (buffer, numChars, L"%.9g", n);
  8645. #else
  8646. len = _snwprintf_s (buffer, numChars, _TRUNCATE, L"%.9g", n);
  8647. #endif
  8648. #else
  8649. len = swprintf (buffer, numChars, L"%.9g", n);
  8650. #endif
  8651. return buffer;
  8652. }
  8653. }
  8654. }
  8655. String::String (const int number)
  8656. {
  8657. juce_wchar buffer [16];
  8658. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8659. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8660. createInternal (start, end - start - 1);
  8661. }
  8662. String::String (const unsigned int number)
  8663. {
  8664. juce_wchar buffer [16];
  8665. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8666. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8667. createInternal (start, end - start - 1);
  8668. }
  8669. String::String (const short number)
  8670. {
  8671. juce_wchar buffer [16];
  8672. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8673. juce_wchar* const start = NumberToStringConverters::intToString (end, (int) number);
  8674. createInternal (start, end - start - 1);
  8675. }
  8676. String::String (const unsigned short number)
  8677. {
  8678. juce_wchar buffer [16];
  8679. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8680. juce_wchar* const start = NumberToStringConverters::uintToString (end, (unsigned int) number);
  8681. createInternal (start, end - start - 1);
  8682. }
  8683. String::String (const int64 number)
  8684. {
  8685. juce_wchar buffer [32];
  8686. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8687. juce_wchar* const start = NumberToStringConverters::int64ToString (end, number);
  8688. createInternal (start, end - start - 1);
  8689. }
  8690. String::String (const uint64 number)
  8691. {
  8692. juce_wchar buffer [32];
  8693. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8694. juce_wchar* const start = NumberToStringConverters::uint64ToString (end, number);
  8695. createInternal (start, end - start - 1);
  8696. }
  8697. String::String (const float number, const int numberOfDecimalPlaces)
  8698. {
  8699. juce_wchar buffer [48];
  8700. size_t len;
  8701. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), (double) number, numberOfDecimalPlaces, len);
  8702. createInternal (start, len);
  8703. }
  8704. String::String (const double number, const int numberOfDecimalPlaces)
  8705. {
  8706. juce_wchar buffer [48];
  8707. size_t len;
  8708. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), number, numberOfDecimalPlaces, len);
  8709. createInternal (start, len);
  8710. }
  8711. int String::length() const throw()
  8712. {
  8713. return CharacterFunctions::length (text);
  8714. }
  8715. int String::hashCode() const throw()
  8716. {
  8717. const juce_wchar* t = text;
  8718. int result = 0;
  8719. while (*t != (juce_wchar) 0)
  8720. result = 31 * result + *t++;
  8721. return result;
  8722. }
  8723. int64 String::hashCode64() const throw()
  8724. {
  8725. const juce_wchar* t = text;
  8726. int64 result = 0;
  8727. while (*t != (juce_wchar) 0)
  8728. result = 101 * result + *t++;
  8729. return result;
  8730. }
  8731. bool JUCE_CALLTYPE operator== (const String& string1, const String& string2) throw()
  8732. {
  8733. return string1.compare (string2) == 0;
  8734. }
  8735. bool JUCE_CALLTYPE operator== (const String& string1, const char* string2) throw()
  8736. {
  8737. return string1.compare (string2) == 0;
  8738. }
  8739. bool JUCE_CALLTYPE operator== (const String& string1, const juce_wchar* string2) throw()
  8740. {
  8741. return string1.compare (string2) == 0;
  8742. }
  8743. bool JUCE_CALLTYPE operator!= (const String& string1, const String& string2) throw()
  8744. {
  8745. return string1.compare (string2) != 0;
  8746. }
  8747. bool JUCE_CALLTYPE operator!= (const String& string1, const char* string2) throw()
  8748. {
  8749. return string1.compare (string2) != 0;
  8750. }
  8751. bool JUCE_CALLTYPE operator!= (const String& string1, const juce_wchar* string2) throw()
  8752. {
  8753. return string1.compare (string2) != 0;
  8754. }
  8755. bool JUCE_CALLTYPE operator> (const String& string1, const String& string2) throw()
  8756. {
  8757. return string1.compare (string2) > 0;
  8758. }
  8759. bool JUCE_CALLTYPE operator< (const String& string1, const String& string2) throw()
  8760. {
  8761. return string1.compare (string2) < 0;
  8762. }
  8763. bool JUCE_CALLTYPE operator>= (const String& string1, const String& string2) throw()
  8764. {
  8765. return string1.compare (string2) >= 0;
  8766. }
  8767. bool JUCE_CALLTYPE operator<= (const String& string1, const String& string2) throw()
  8768. {
  8769. return string1.compare (string2) <= 0;
  8770. }
  8771. bool String::equalsIgnoreCase (const juce_wchar* t) const throw()
  8772. {
  8773. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8774. : isEmpty();
  8775. }
  8776. bool String::equalsIgnoreCase (const String& other) const throw()
  8777. {
  8778. return text == other.text
  8779. || CharacterFunctions::compareIgnoreCase (text, other.text) == 0;
  8780. }
  8781. int String::compare (const String& other) const throw()
  8782. {
  8783. return (text == other.text) ? 0 : CharacterFunctions::compare (text, other.text);
  8784. }
  8785. int String::compare (const char* other) const throw()
  8786. {
  8787. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8788. }
  8789. int String::compare (const juce_wchar* other) const throw()
  8790. {
  8791. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8792. }
  8793. int String::compareIgnoreCase (const String& other) const throw()
  8794. {
  8795. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text, other.text);
  8796. }
  8797. int String::compareLexicographically (const String& other) const throw()
  8798. {
  8799. const juce_wchar* s1 = text;
  8800. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8801. ++s1;
  8802. const juce_wchar* s2 = other.text;
  8803. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8804. ++s2;
  8805. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8806. }
  8807. String& String::operator+= (const juce_wchar* const t)
  8808. {
  8809. if (t != 0)
  8810. appendInternal (t, CharacterFunctions::length (t));
  8811. return *this;
  8812. }
  8813. String& String::operator+= (const String& other)
  8814. {
  8815. if (isEmpty())
  8816. operator= (other);
  8817. else
  8818. appendInternal (other.text, other.length());
  8819. return *this;
  8820. }
  8821. String& String::operator+= (const char ch)
  8822. {
  8823. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8824. return operator+= ((const juce_wchar*) asString);
  8825. }
  8826. String& String::operator+= (const juce_wchar ch)
  8827. {
  8828. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8829. return operator+= ((const juce_wchar*) asString);
  8830. }
  8831. String& String::operator+= (const int number)
  8832. {
  8833. juce_wchar buffer [16];
  8834. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8835. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8836. appendInternal (start, (int) (end - start));
  8837. return *this;
  8838. }
  8839. String& String::operator+= (const unsigned int number)
  8840. {
  8841. juce_wchar buffer [16];
  8842. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8843. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8844. appendInternal (start, (int) (end - start));
  8845. return *this;
  8846. }
  8847. void String::append (const juce_wchar* const other, const int howMany)
  8848. {
  8849. if (howMany > 0)
  8850. {
  8851. int i;
  8852. for (i = 0; i < howMany; ++i)
  8853. if (other[i] == 0)
  8854. break;
  8855. appendInternal (other, i);
  8856. }
  8857. }
  8858. const String JUCE_CALLTYPE operator+ (const char* const string1, const String& string2)
  8859. {
  8860. String s (string1);
  8861. return s += string2;
  8862. }
  8863. const String JUCE_CALLTYPE operator+ (const juce_wchar* const string1, const String& string2)
  8864. {
  8865. String s (string1);
  8866. return s += string2;
  8867. }
  8868. const String JUCE_CALLTYPE operator+ (const char string1, const String& string2)
  8869. {
  8870. return String::charToString (string1) + string2;
  8871. }
  8872. const String JUCE_CALLTYPE operator+ (const juce_wchar string1, const String& string2)
  8873. {
  8874. return String::charToString (string1) + string2;
  8875. }
  8876. const String JUCE_CALLTYPE operator+ (String string1, const String& string2)
  8877. {
  8878. return string1 += string2;
  8879. }
  8880. const String JUCE_CALLTYPE operator+ (String string1, const char* const string2)
  8881. {
  8882. return string1 += string2;
  8883. }
  8884. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar* const string2)
  8885. {
  8886. return string1 += string2;
  8887. }
  8888. const String JUCE_CALLTYPE operator+ (String string1, const char string2)
  8889. {
  8890. return string1 += string2;
  8891. }
  8892. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar string2)
  8893. {
  8894. return string1 += string2;
  8895. }
  8896. String& JUCE_CALLTYPE operator<< (String& string1, const char characterToAppend)
  8897. {
  8898. return string1 += characterToAppend;
  8899. }
  8900. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar characterToAppend)
  8901. {
  8902. return string1 += characterToAppend;
  8903. }
  8904. String& JUCE_CALLTYPE operator<< (String& string1, const char* const string2)
  8905. {
  8906. return string1 += string2;
  8907. }
  8908. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar* const string2)
  8909. {
  8910. return string1 += string2;
  8911. }
  8912. String& JUCE_CALLTYPE operator<< (String& string1, const String& string2)
  8913. {
  8914. return string1 += string2;
  8915. }
  8916. String& JUCE_CALLTYPE operator<< (String& string1, const short number)
  8917. {
  8918. return string1 += (int) number;
  8919. }
  8920. String& JUCE_CALLTYPE operator<< (String& string1, const int number)
  8921. {
  8922. return string1 += number;
  8923. }
  8924. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned int number)
  8925. {
  8926. return string1 += number;
  8927. }
  8928. String& JUCE_CALLTYPE operator<< (String& string1, const long number)
  8929. {
  8930. return string1 += (int) number;
  8931. }
  8932. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned long number)
  8933. {
  8934. return string1 += (unsigned int) number;
  8935. }
  8936. String& JUCE_CALLTYPE operator<< (String& string1, const float number)
  8937. {
  8938. return string1 += String (number);
  8939. }
  8940. String& JUCE_CALLTYPE operator<< (String& string1, const double number)
  8941. {
  8942. return string1 += String (number);
  8943. }
  8944. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text)
  8945. {
  8946. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8947. // if lots of large, persistent strings were to be written to streams).
  8948. const int numBytes = text.getNumBytesAsUTF8();
  8949. HeapBlock<char> temp (numBytes + 1);
  8950. text.copyToUTF8 (temp, numBytes + 1);
  8951. stream.write (temp, numBytes);
  8952. return stream;
  8953. }
  8954. int String::indexOfChar (const juce_wchar character) const throw()
  8955. {
  8956. const juce_wchar* t = text;
  8957. for (;;)
  8958. {
  8959. if (*t == character)
  8960. return (int) (t - text);
  8961. if (*t++ == 0)
  8962. return -1;
  8963. }
  8964. }
  8965. int String::lastIndexOfChar (const juce_wchar character) const throw()
  8966. {
  8967. for (int i = length(); --i >= 0;)
  8968. if (text[i] == character)
  8969. return i;
  8970. return -1;
  8971. }
  8972. int String::indexOf (const juce_wchar* const t) const throw()
  8973. {
  8974. const juce_wchar* const r = CharacterFunctions::find (text, t);
  8975. return (r == 0) ? -1
  8976. : (int) (r - text);
  8977. }
  8978. int String::indexOfChar (const int startIndex,
  8979. const juce_wchar character) const throw()
  8980. {
  8981. if (startIndex >= 0 && startIndex >= length())
  8982. return -1;
  8983. const juce_wchar* t = text + jmax (0, startIndex);
  8984. for (;;)
  8985. {
  8986. if (*t == character)
  8987. return (int) (t - text);
  8988. if (*t++ == 0)
  8989. return -1;
  8990. }
  8991. }
  8992. int String::indexOfAnyOf (const juce_wchar* const charactersToLookFor,
  8993. const int startIndex,
  8994. const bool ignoreCase) const throw()
  8995. {
  8996. if (charactersToLookFor == 0
  8997. || (startIndex >= 0 && startIndex >= length()))
  8998. return -1;
  8999. const juce_wchar* t = text + jmax (0, startIndex);
  9000. while (*t != 0)
  9001. {
  9002. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  9003. return (int) (t - text);
  9004. ++t;
  9005. }
  9006. return -1;
  9007. }
  9008. int String::indexOf (const int startIndex,
  9009. const juce_wchar* const other) const throw()
  9010. {
  9011. if (other == 0 || startIndex >= length())
  9012. return -1;
  9013. const juce_wchar* const found = CharacterFunctions::find (text + jmax (0, startIndex), other);
  9014. return (found == 0) ? -1
  9015. : (int) (found - text);
  9016. }
  9017. int String::indexOfIgnoreCase (const juce_wchar* const other) const throw()
  9018. {
  9019. if (other != 0 && *other != 0)
  9020. {
  9021. const int len = CharacterFunctions::length (other);
  9022. const int end = length() - len;
  9023. for (int i = 0; i <= end; ++i)
  9024. if (CharacterFunctions::compareIgnoreCase (text + i, other, len) == 0)
  9025. return i;
  9026. }
  9027. return -1;
  9028. }
  9029. int String::indexOfIgnoreCase (const int startIndex,
  9030. const juce_wchar* const other) const throw()
  9031. {
  9032. if (other != 0 && *other != 0)
  9033. {
  9034. const int len = CharacterFunctions::length (other);
  9035. const int end = length() - len;
  9036. for (int i = jmax (0, startIndex); i <= end; ++i)
  9037. if (CharacterFunctions::compareIgnoreCase (text + i, other, len) == 0)
  9038. return i;
  9039. }
  9040. return -1;
  9041. }
  9042. int String::lastIndexOf (const juce_wchar* const other) const throw()
  9043. {
  9044. if (other != 0 && *other != 0)
  9045. {
  9046. const int len = CharacterFunctions::length (other);
  9047. int i = length() - len;
  9048. if (i >= 0)
  9049. {
  9050. const juce_wchar* n = text + i;
  9051. while (i >= 0)
  9052. {
  9053. if (CharacterFunctions::compare (n--, other, len) == 0)
  9054. return i;
  9055. --i;
  9056. }
  9057. }
  9058. }
  9059. return -1;
  9060. }
  9061. int String::lastIndexOfIgnoreCase (const juce_wchar* const other) const throw()
  9062. {
  9063. if (other != 0 && *other != 0)
  9064. {
  9065. const int len = CharacterFunctions::length (other);
  9066. int i = length() - len;
  9067. if (i >= 0)
  9068. {
  9069. const juce_wchar* n = text + i;
  9070. while (i >= 0)
  9071. {
  9072. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  9073. return i;
  9074. --i;
  9075. }
  9076. }
  9077. }
  9078. return -1;
  9079. }
  9080. int String::lastIndexOfAnyOf (const juce_wchar* const charactersToLookFor,
  9081. const bool ignoreCase) const throw()
  9082. {
  9083. for (int i = length(); --i >= 0;)
  9084. if (CharacterFunctions::indexOfChar (charactersToLookFor, text[i], ignoreCase) >= 0)
  9085. return i;
  9086. return -1;
  9087. }
  9088. bool String::contains (const juce_wchar* const other) const throw()
  9089. {
  9090. return indexOf (other) >= 0;
  9091. }
  9092. bool String::containsChar (const juce_wchar character) const throw()
  9093. {
  9094. return indexOfChar (character) >= 0;
  9095. }
  9096. bool String::containsIgnoreCase (const juce_wchar* const t) const throw()
  9097. {
  9098. return indexOfIgnoreCase (t) >= 0;
  9099. }
  9100. int String::indexOfWholeWord (const juce_wchar* const word) const throw()
  9101. {
  9102. if (word != 0 && *word != 0)
  9103. {
  9104. const int wordLen = CharacterFunctions::length (word);
  9105. const int end = length() - wordLen;
  9106. const juce_wchar* t = text;
  9107. for (int i = 0; i <= end; ++i)
  9108. {
  9109. if (CharacterFunctions::compare (t, word, wordLen) == 0
  9110. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9111. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9112. {
  9113. return i;
  9114. }
  9115. ++t;
  9116. }
  9117. }
  9118. return -1;
  9119. }
  9120. int String::indexOfWholeWordIgnoreCase (const juce_wchar* const word) const throw()
  9121. {
  9122. if (word != 0 && *word != 0)
  9123. {
  9124. const int wordLen = CharacterFunctions::length (word);
  9125. const int end = length() - wordLen;
  9126. const juce_wchar* t = text;
  9127. for (int i = 0; i <= end; ++i)
  9128. {
  9129. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  9130. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9131. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9132. {
  9133. return i;
  9134. }
  9135. ++t;
  9136. }
  9137. }
  9138. return -1;
  9139. }
  9140. bool String::containsWholeWord (const juce_wchar* const wordToLookFor) const throw()
  9141. {
  9142. return indexOfWholeWord (wordToLookFor) >= 0;
  9143. }
  9144. bool String::containsWholeWordIgnoreCase (const juce_wchar* const wordToLookFor) const throw()
  9145. {
  9146. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9147. }
  9148. static int indexOfMatch (const juce_wchar* const wildcard,
  9149. const juce_wchar* const test,
  9150. const bool ignoreCase) throw()
  9151. {
  9152. int start = 0;
  9153. while (test [start] != 0)
  9154. {
  9155. int i = 0;
  9156. for (;;)
  9157. {
  9158. const juce_wchar wc = wildcard [i];
  9159. const juce_wchar c = test [i + start];
  9160. if (wc == c
  9161. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9162. || (wc == T('?') && c != 0))
  9163. {
  9164. if (wc == 0)
  9165. return start;
  9166. ++i;
  9167. }
  9168. else
  9169. {
  9170. if (wc == T('*') && (wildcard [i + 1] == 0
  9171. || indexOfMatch (wildcard + i + 1,
  9172. test + start + i,
  9173. ignoreCase) >= 0))
  9174. {
  9175. return start;
  9176. }
  9177. break;
  9178. }
  9179. }
  9180. ++start;
  9181. }
  9182. return -1;
  9183. }
  9184. bool String::matchesWildcard (const juce_wchar* wildcard, const bool ignoreCase) const throw()
  9185. {
  9186. int i = 0;
  9187. for (;;)
  9188. {
  9189. const juce_wchar wc = wildcard [i];
  9190. const juce_wchar c = text [i];
  9191. if (wc == c
  9192. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9193. || (wc == T('?') && c != 0))
  9194. {
  9195. if (wc == 0)
  9196. return true;
  9197. ++i;
  9198. }
  9199. else
  9200. {
  9201. return wc == T('*') && (wildcard [i + 1] == 0
  9202. || indexOfMatch (wildcard + i + 1,
  9203. text + i,
  9204. ignoreCase) >= 0);
  9205. }
  9206. }
  9207. }
  9208. const String String::repeatedString (const juce_wchar* const stringToRepeat, int numberOfTimesToRepeat)
  9209. {
  9210. const int len = CharacterFunctions::length (stringToRepeat);
  9211. String result ((size_t) (len * numberOfTimesToRepeat + 1), (int) 0);
  9212. juce_wchar* n = result.text;
  9213. n[0] = 0;
  9214. while (--numberOfTimesToRepeat >= 0)
  9215. {
  9216. CharacterFunctions::append (n, stringToRepeat);
  9217. n += len;
  9218. }
  9219. return result;
  9220. }
  9221. const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const
  9222. {
  9223. jassert (padCharacter != 0);
  9224. const int len = length();
  9225. if (len >= minimumLength || padCharacter == 0)
  9226. return *this;
  9227. String result ((size_t) minimumLength + 1, (int) 0);
  9228. juce_wchar* n = result.text;
  9229. minimumLength -= len;
  9230. while (--minimumLength >= 0)
  9231. *n++ = padCharacter;
  9232. *n = 0;
  9233. CharacterFunctions::append (n, text);
  9234. return result;
  9235. }
  9236. const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const
  9237. {
  9238. jassert (padCharacter != 0);
  9239. const int paddingNeeded = minimumLength - length();
  9240. if (paddingNeeded <= 0 || padCharacter == 0)
  9241. return *this;
  9242. return *this + String::empty.paddedLeft (padCharacter, paddingNeeded);
  9243. }
  9244. const String String::replaceSection (int index, int numCharsToReplace,
  9245. const juce_wchar* const stringToInsert) const
  9246. {
  9247. if (index < 0)
  9248. {
  9249. // a negative index to replace from?
  9250. jassertfalse
  9251. index = 0;
  9252. }
  9253. if (numCharsToReplace < 0)
  9254. {
  9255. // replacing a negative number of characters?
  9256. numCharsToReplace = 0;
  9257. jassertfalse;
  9258. }
  9259. const int len = length();
  9260. if (index + numCharsToReplace > len)
  9261. {
  9262. if (index > len)
  9263. {
  9264. // replacing beyond the end of the string?
  9265. index = len;
  9266. jassertfalse
  9267. }
  9268. numCharsToReplace = len - index;
  9269. }
  9270. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9271. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9272. if (newTotalLen <= 0)
  9273. return String::empty;
  9274. String result ((size_t) newTotalLen, (int) 0);
  9275. memcpy (result.text, text, index * sizeof (juce_wchar));
  9276. if (newStringLen > 0)
  9277. memcpy (result.text + index,
  9278. stringToInsert,
  9279. newStringLen * sizeof (juce_wchar));
  9280. const int endStringLen = newTotalLen - (index + newStringLen);
  9281. if (endStringLen > 0)
  9282. memcpy (result.text + (index + newStringLen),
  9283. text + (index + numCharsToReplace),
  9284. endStringLen * sizeof (juce_wchar));
  9285. result.text [newTotalLen] = 0;
  9286. return result;
  9287. }
  9288. const String String::replace (const juce_wchar* const stringToReplace,
  9289. const juce_wchar* const stringToInsert,
  9290. const bool ignoreCase) const
  9291. {
  9292. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9293. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9294. int i = 0;
  9295. String result (*this);
  9296. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9297. : result.indexOf (i, stringToReplace))) >= 0)
  9298. {
  9299. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9300. i += stringToInsertLen;
  9301. }
  9302. return result;
  9303. }
  9304. const String String::replaceCharacter (const juce_wchar charToReplace, const juce_wchar charToInsert) const
  9305. {
  9306. const int index = indexOfChar (charToReplace);
  9307. if (index < 0)
  9308. return *this;
  9309. String result (*this);
  9310. result.dupeInternalIfMultiplyReferenced();
  9311. juce_wchar* t = result.text + index;
  9312. while (*t != 0)
  9313. {
  9314. if (*t == charToReplace)
  9315. *t = charToInsert;
  9316. ++t;
  9317. }
  9318. return result;
  9319. }
  9320. const String String::replaceCharacters (const String& charactersToReplace,
  9321. const juce_wchar* const charactersToInsertInstead) const
  9322. {
  9323. String result (*this);
  9324. result.dupeInternalIfMultiplyReferenced();
  9325. juce_wchar* t = result.text;
  9326. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9327. // the two strings passed in are supposed to be the same length!
  9328. jassert (len2 == charactersToReplace.length());
  9329. while (*t != 0)
  9330. {
  9331. const int index = charactersToReplace.indexOfChar (*t);
  9332. if (((unsigned int) index) < (unsigned int) len2)
  9333. *t = charactersToInsertInstead [index];
  9334. ++t;
  9335. }
  9336. return result;
  9337. }
  9338. bool String::startsWith (const juce_wchar* const other) const throw()
  9339. {
  9340. return other != 0
  9341. && CharacterFunctions::compare (text, other, CharacterFunctions::length (other)) == 0;
  9342. }
  9343. bool String::startsWithIgnoreCase (const juce_wchar* const other) const throw()
  9344. {
  9345. return other != 0
  9346. && CharacterFunctions::compareIgnoreCase (text, other, CharacterFunctions::length (other)) == 0;
  9347. }
  9348. bool String::startsWithChar (const juce_wchar character) const throw()
  9349. {
  9350. jassert (character != 0); // strings can't contain a null character!
  9351. return text[0] == character;
  9352. }
  9353. bool String::endsWithChar (const juce_wchar character) const throw()
  9354. {
  9355. jassert (character != 0); // strings can't contain a null character!
  9356. return text[0] != 0
  9357. && text [length() - 1] == character;
  9358. }
  9359. bool String::endsWith (const juce_wchar* const other) const throw()
  9360. {
  9361. if (other == 0)
  9362. return false;
  9363. const int thisLen = length();
  9364. const int otherLen = CharacterFunctions::length (other);
  9365. return thisLen >= otherLen
  9366. && CharacterFunctions::compare (text + thisLen - otherLen, other) == 0;
  9367. }
  9368. bool String::endsWithIgnoreCase (const juce_wchar* const other) const throw()
  9369. {
  9370. if (other == 0)
  9371. return false;
  9372. const int thisLen = length();
  9373. const int otherLen = CharacterFunctions::length (other);
  9374. return thisLen >= otherLen
  9375. && CharacterFunctions::compareIgnoreCase (text + thisLen - otherLen, other) == 0;
  9376. }
  9377. const String String::toUpperCase() const
  9378. {
  9379. String result (*this);
  9380. result.dupeInternalIfMultiplyReferenced();
  9381. CharacterFunctions::toUpperCase (result.text);
  9382. return result;
  9383. }
  9384. const String String::toLowerCase() const
  9385. {
  9386. String result (*this);
  9387. result.dupeInternalIfMultiplyReferenced();
  9388. CharacterFunctions::toLowerCase (result.text);
  9389. return result;
  9390. }
  9391. juce_wchar& String::operator[] (const int index)
  9392. {
  9393. jassert (((unsigned int) index) <= (unsigned int) length());
  9394. dupeInternalIfMultiplyReferenced();
  9395. return text [index];
  9396. }
  9397. juce_wchar String::getLastCharacter() const throw()
  9398. {
  9399. return isEmpty() ? juce_wchar() : text [length() - 1];
  9400. }
  9401. const String String::substring (int start, int end) const
  9402. {
  9403. if (start < 0)
  9404. start = 0;
  9405. else if (end <= start)
  9406. return empty;
  9407. int len = 0;
  9408. const juce_wchar* const t = text;
  9409. while (len <= end && t [len] != 0)
  9410. ++len;
  9411. if (end >= len)
  9412. {
  9413. if (start == 0)
  9414. return *this;
  9415. end = len;
  9416. }
  9417. return String (text + start, end - start);
  9418. }
  9419. const String String::substring (const int start) const
  9420. {
  9421. if (start <= 0)
  9422. return *this;
  9423. const int len = length();
  9424. if (start >= len)
  9425. return empty;
  9426. else
  9427. return String (text + start, len - start);
  9428. }
  9429. const String String::dropLastCharacters (const int numberToDrop) const
  9430. {
  9431. return String (text, jmax (0, length() - numberToDrop));
  9432. }
  9433. const String String::getLastCharacters (const int numCharacters) const
  9434. {
  9435. return String (text + jmax (0, length() - jmax (0, numCharacters)));
  9436. }
  9437. const String String::fromFirstOccurrenceOf (const juce_wchar* const sub,
  9438. const bool includeSubString,
  9439. const bool ignoreCase) const
  9440. {
  9441. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9442. : indexOf (sub);
  9443. if (i < 0)
  9444. return empty;
  9445. else
  9446. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9447. }
  9448. const String String::fromLastOccurrenceOf (const juce_wchar* const sub,
  9449. const bool includeSubString,
  9450. const bool ignoreCase) const
  9451. {
  9452. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9453. : lastIndexOf (sub);
  9454. if (i < 0)
  9455. return *this;
  9456. else
  9457. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9458. }
  9459. const String String::upToFirstOccurrenceOf (const juce_wchar* const sub,
  9460. const bool includeSubString,
  9461. const bool ignoreCase) const
  9462. {
  9463. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9464. : indexOf (sub);
  9465. if (i < 0)
  9466. return *this;
  9467. else
  9468. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9469. }
  9470. const String String::upToLastOccurrenceOf (const juce_wchar* const sub,
  9471. const bool includeSubString,
  9472. const bool ignoreCase) const
  9473. {
  9474. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9475. : lastIndexOf (sub);
  9476. if (i < 0)
  9477. return *this;
  9478. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9479. }
  9480. bool String::isQuotedString() const
  9481. {
  9482. const String trimmed (trimStart());
  9483. return trimmed[0] == T('"')
  9484. || trimmed[0] == T('\'');
  9485. }
  9486. const String String::unquoted() const
  9487. {
  9488. String s (*this);
  9489. if (s[0] == T('"') || s[0] == T('\''))
  9490. s = s.substring (1);
  9491. const int lastCharIndex = s.length() - 1;
  9492. if (lastCharIndex >= 0
  9493. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9494. s [lastCharIndex] = 0;
  9495. return s;
  9496. }
  9497. const String String::quoted (const juce_wchar quoteCharacter) const
  9498. {
  9499. if (isEmpty())
  9500. return charToString (quoteCharacter) + quoteCharacter;
  9501. String t (*this);
  9502. if (! t.startsWithChar (quoteCharacter))
  9503. t = charToString (quoteCharacter) + t;
  9504. if (! t.endsWithChar (quoteCharacter))
  9505. t += quoteCharacter;
  9506. return t;
  9507. }
  9508. const String String::trim() const
  9509. {
  9510. if (isEmpty())
  9511. return empty;
  9512. int start = 0;
  9513. while (CharacterFunctions::isWhitespace (text [start]))
  9514. ++start;
  9515. const int len = length();
  9516. int end = len - 1;
  9517. while ((end >= start) && CharacterFunctions::isWhitespace (text [end]))
  9518. --end;
  9519. ++end;
  9520. if (end <= start)
  9521. return empty;
  9522. else if (start > 0 || end < len)
  9523. return String (text + start, end - start);
  9524. else
  9525. return *this;
  9526. }
  9527. const String String::trimStart() const
  9528. {
  9529. if (isEmpty())
  9530. return empty;
  9531. const juce_wchar* t = text;
  9532. while (CharacterFunctions::isWhitespace (*t))
  9533. ++t;
  9534. if (t == text)
  9535. return *this;
  9536. else
  9537. return String (t);
  9538. }
  9539. const String String::trimEnd() const
  9540. {
  9541. if (isEmpty())
  9542. return empty;
  9543. const juce_wchar* endT = text + (length() - 1);
  9544. while ((endT >= text) && CharacterFunctions::isWhitespace (*endT))
  9545. --endT;
  9546. return String (text, (int) (++endT - text));
  9547. }
  9548. const String String::trimCharactersAtStart (const juce_wchar* charactersToTrim) const
  9549. {
  9550. jassert (charactersToTrim != 0);
  9551. if (isEmpty())
  9552. return empty;
  9553. const juce_wchar* t = text;
  9554. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9555. ++t;
  9556. if (t == text)
  9557. return *this;
  9558. else
  9559. return String (t);
  9560. }
  9561. const String String::trimCharactersAtEnd (const juce_wchar* charactersToTrim) const
  9562. {
  9563. jassert (charactersToTrim != 0);
  9564. if (isEmpty())
  9565. return empty;
  9566. const juce_wchar* endT = text + (length() - 1);
  9567. while ((endT >= text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9568. --endT;
  9569. return String (text, (int) (++endT - text));
  9570. }
  9571. const String String::retainCharacters (const juce_wchar* const charactersToRetain) const
  9572. {
  9573. jassert (charactersToRetain != 0);
  9574. if (isEmpty())
  9575. return empty;
  9576. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9577. juce_wchar* dst = result.text;
  9578. const juce_wchar* src = text;
  9579. while (*src != 0)
  9580. {
  9581. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9582. *dst++ = *src;
  9583. ++src;
  9584. }
  9585. *dst = 0;
  9586. return result;
  9587. }
  9588. const String String::removeCharacters (const juce_wchar* const charactersToRemove) const
  9589. {
  9590. jassert (charactersToRemove != 0);
  9591. if (isEmpty())
  9592. return empty;
  9593. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9594. juce_wchar* dst = result.text;
  9595. const juce_wchar* src = text;
  9596. while (*src != 0)
  9597. {
  9598. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9599. *dst++ = *src;
  9600. ++src;
  9601. }
  9602. *dst = 0;
  9603. return result;
  9604. }
  9605. const String String::initialSectionContainingOnly (const juce_wchar* const permittedCharacters) const
  9606. {
  9607. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text, permittedCharacters));
  9608. }
  9609. const String String::initialSectionNotContaining (const juce_wchar* const charactersToStopAt) const
  9610. {
  9611. jassert (charactersToStopAt != 0);
  9612. const juce_wchar* const t = text;
  9613. int i = 0;
  9614. while (t[i] != 0)
  9615. {
  9616. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9617. return String (text, i);
  9618. ++i;
  9619. }
  9620. return empty;
  9621. }
  9622. bool String::containsOnly (const juce_wchar* const chars) const throw()
  9623. {
  9624. jassert (chars != 0);
  9625. const juce_wchar* t = text;
  9626. while (*t != 0)
  9627. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9628. return false;
  9629. return true;
  9630. }
  9631. bool String::containsAnyOf (const juce_wchar* const chars) const throw()
  9632. {
  9633. jassert (chars != 0);
  9634. const juce_wchar* t = text;
  9635. while (*t != 0)
  9636. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9637. return true;
  9638. return false;
  9639. }
  9640. bool String::containsNonWhitespaceChars() const throw()
  9641. {
  9642. const juce_wchar* t = text;
  9643. while (*t != 0)
  9644. if (! CharacterFunctions::isWhitespace (*t++))
  9645. return true;
  9646. return false;
  9647. }
  9648. int String::getIntValue() const throw()
  9649. {
  9650. return CharacterFunctions::getIntValue (text);
  9651. }
  9652. int String::getTrailingIntValue() const throw()
  9653. {
  9654. int n = 0;
  9655. int mult = 1;
  9656. const juce_wchar* t = text + length();
  9657. while (--t >= text)
  9658. {
  9659. const juce_wchar c = *t;
  9660. if (! CharacterFunctions::isDigit (c))
  9661. {
  9662. if (c == T('-'))
  9663. n = -n;
  9664. break;
  9665. }
  9666. n += mult * (c - T('0'));
  9667. mult *= 10;
  9668. }
  9669. return n;
  9670. }
  9671. int64 String::getLargeIntValue() const throw()
  9672. {
  9673. return CharacterFunctions::getInt64Value (text);
  9674. }
  9675. float String::getFloatValue() const throw()
  9676. {
  9677. return (float) CharacterFunctions::getDoubleValue (text);
  9678. }
  9679. double String::getDoubleValue() const throw()
  9680. {
  9681. return CharacterFunctions::getDoubleValue (text);
  9682. }
  9683. static const juce_wchar* const hexDigits = T("0123456789abcdef");
  9684. const String String::toHexString (const int number)
  9685. {
  9686. juce_wchar buffer[32];
  9687. juce_wchar* const end = buffer + 32;
  9688. juce_wchar* t = end;
  9689. *--t = 0;
  9690. unsigned int v = (unsigned int) number;
  9691. do
  9692. {
  9693. *--t = hexDigits [v & 15];
  9694. v >>= 4;
  9695. } while (v != 0);
  9696. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9697. }
  9698. const String String::toHexString (const int64 number)
  9699. {
  9700. juce_wchar buffer[32];
  9701. juce_wchar* const end = buffer + 32;
  9702. juce_wchar* t = end;
  9703. *--t = 0;
  9704. uint64 v = (uint64) number;
  9705. do
  9706. {
  9707. *--t = hexDigits [(int) (v & 15)];
  9708. v >>= 4;
  9709. } while (v != 0);
  9710. return String (t, (int) (((char*) end) - (char*) t));
  9711. }
  9712. const String String::toHexString (const short number)
  9713. {
  9714. return toHexString ((int) (unsigned short) number);
  9715. }
  9716. const String String::toHexString (const unsigned char* data,
  9717. const int size,
  9718. const int groupSize)
  9719. {
  9720. if (size <= 0)
  9721. return empty;
  9722. int numChars = (size * 2) + 2;
  9723. if (groupSize > 0)
  9724. numChars += size / groupSize;
  9725. String s ((size_t) numChars, (int) 0);
  9726. juce_wchar* d = s.text;
  9727. for (int i = 0; i < size; ++i)
  9728. {
  9729. *d++ = hexDigits [(*data) >> 4];
  9730. *d++ = hexDigits [(*data) & 0xf];
  9731. ++data;
  9732. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9733. *d++ = T(' ');
  9734. }
  9735. *d = 0;
  9736. return s;
  9737. }
  9738. int String::getHexValue32() const throw()
  9739. {
  9740. int result = 0;
  9741. const juce_wchar* c = text;
  9742. for (;;)
  9743. {
  9744. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9745. if (hexValue >= 0)
  9746. result = (result << 4) | hexValue;
  9747. else if (*c == 0)
  9748. break;
  9749. ++c;
  9750. }
  9751. return result;
  9752. }
  9753. int64 String::getHexValue64() const throw()
  9754. {
  9755. int64 result = 0;
  9756. const juce_wchar* c = text;
  9757. for (;;)
  9758. {
  9759. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9760. if (hexValue >= 0)
  9761. result = (result << 4) | hexValue;
  9762. else if (*c == 0)
  9763. break;
  9764. ++c;
  9765. }
  9766. return result;
  9767. }
  9768. const String String::createStringFromData (const void* const data_, const int size)
  9769. {
  9770. const char* const data = (const char*) data_;
  9771. if (size <= 0 || data == 0)
  9772. {
  9773. return empty;
  9774. }
  9775. else if (size < 2)
  9776. {
  9777. return charToString (data[0]);
  9778. }
  9779. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9780. || (data[0] == (char)-1 && data[1] == (char)-2))
  9781. {
  9782. // assume it's 16-bit unicode
  9783. const bool bigEndian = (data[0] == (char)-2);
  9784. const int numChars = size / 2 - 1;
  9785. String result;
  9786. result.preallocateStorage (numChars + 2);
  9787. const uint16* const src = (const uint16*) (data + 2);
  9788. juce_wchar* const dst = const_cast <juce_wchar*> ((const juce_wchar*) result);
  9789. if (bigEndian)
  9790. {
  9791. for (int i = 0; i < numChars; ++i)
  9792. dst[i] = (juce_wchar) ByteOrder::swapIfLittleEndian (src[i]);
  9793. }
  9794. else
  9795. {
  9796. for (int i = 0; i < numChars; ++i)
  9797. dst[i] = (juce_wchar) ByteOrder::swapIfBigEndian (src[i]);
  9798. }
  9799. dst [numChars] = 0;
  9800. return result;
  9801. }
  9802. else
  9803. {
  9804. return String::fromUTF8 (data, size);
  9805. }
  9806. }
  9807. const char* String::toUTF8() const
  9808. {
  9809. if (isEmpty())
  9810. {
  9811. return reinterpret_cast <const char*> (text);
  9812. }
  9813. else
  9814. {
  9815. const int currentLen = length() + 1;
  9816. const int utf8BytesNeeded = getNumBytesAsUTF8();
  9817. String* const mutableThis = const_cast <String*> (this);
  9818. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, currentLen + 1 + utf8BytesNeeded / sizeof (juce_wchar));
  9819. char* const otherCopy = (char*) (text + currentLen);
  9820. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9821. return otherCopy;
  9822. }
  9823. }
  9824. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9825. {
  9826. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9827. int num = 0, index = 0;
  9828. for (;;)
  9829. {
  9830. const uint32 c = (uint32) text [index++];
  9831. if (c >= 0x80)
  9832. {
  9833. int numExtraBytes = 1;
  9834. if (c >= 0x800)
  9835. {
  9836. ++numExtraBytes;
  9837. if (c >= 0x10000)
  9838. {
  9839. ++numExtraBytes;
  9840. if (c >= 0x200000)
  9841. {
  9842. ++numExtraBytes;
  9843. if (c >= 0x4000000)
  9844. ++numExtraBytes;
  9845. }
  9846. }
  9847. }
  9848. if (buffer != 0)
  9849. {
  9850. if (num + numExtraBytes >= maxBufferSizeBytes)
  9851. {
  9852. buffer [num++] = 0;
  9853. break;
  9854. }
  9855. else
  9856. {
  9857. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9858. while (--numExtraBytes >= 0)
  9859. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9860. }
  9861. }
  9862. else
  9863. {
  9864. num += numExtraBytes + 1;
  9865. }
  9866. }
  9867. else
  9868. {
  9869. if (buffer != 0)
  9870. {
  9871. if (num + 1 >= maxBufferSizeBytes)
  9872. {
  9873. buffer [num++] = 0;
  9874. break;
  9875. }
  9876. buffer [num] = (uint8) c;
  9877. }
  9878. ++num;
  9879. }
  9880. if (c == 0)
  9881. break;
  9882. }
  9883. return num;
  9884. }
  9885. int String::getNumBytesAsUTF8() const throw()
  9886. {
  9887. int num = 0;
  9888. const juce_wchar* t = text;
  9889. for (;;)
  9890. {
  9891. const uint32 c = (uint32) *t;
  9892. if (c >= 0x80)
  9893. {
  9894. ++num;
  9895. if (c >= 0x800)
  9896. {
  9897. ++num;
  9898. if (c >= 0x10000)
  9899. {
  9900. ++num;
  9901. if (c >= 0x200000)
  9902. {
  9903. ++num;
  9904. if (c >= 0x4000000)
  9905. ++num;
  9906. }
  9907. }
  9908. }
  9909. }
  9910. else if (c == 0)
  9911. break;
  9912. ++num;
  9913. ++t;
  9914. }
  9915. return num;
  9916. }
  9917. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9918. {
  9919. if (buffer == 0)
  9920. return empty;
  9921. if (bufferSizeBytes < 0)
  9922. bufferSizeBytes = std::numeric_limits<int>::max();
  9923. size_t numBytes;
  9924. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9925. if (buffer [numBytes] == 0)
  9926. break;
  9927. String result ((size_t) numBytes + 1, (int) 0);
  9928. juce_wchar* dest = result.text;
  9929. size_t i = 0;
  9930. while (i < numBytes)
  9931. {
  9932. const char c = buffer [i++];
  9933. if (c < 0)
  9934. {
  9935. unsigned int mask = 0x7f;
  9936. int bit = 0x40;
  9937. int numExtraValues = 0;
  9938. while (bit != 0 && (c & bit) != 0)
  9939. {
  9940. bit >>= 1;
  9941. mask >>= 1;
  9942. ++numExtraValues;
  9943. }
  9944. int n = (mask & (unsigned char) c);
  9945. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9946. {
  9947. const char nextByte = buffer[i];
  9948. if ((nextByte & 0xc0) != 0x80)
  9949. break;
  9950. n <<= 6;
  9951. n |= (nextByte & 0x3f);
  9952. ++i;
  9953. }
  9954. *dest++ = (juce_wchar) n;
  9955. }
  9956. else
  9957. {
  9958. *dest++ = (juce_wchar) c;
  9959. }
  9960. }
  9961. *dest = 0;
  9962. return result;
  9963. }
  9964. const char* String::toCString() const
  9965. {
  9966. if (isEmpty())
  9967. {
  9968. return reinterpret_cast <const char*> (text);
  9969. }
  9970. else
  9971. {
  9972. int len = length();
  9973. String* const mutableThis = const_cast <String*> (this);
  9974. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, (len + 1) * 2);
  9975. char* otherCopy = (char*) (text + len + 1);
  9976. CharacterFunctions::copy (otherCopy, text, len);
  9977. otherCopy [len] = 0;
  9978. return otherCopy;
  9979. }
  9980. }
  9981. #ifdef _MSC_VER
  9982. #pragma warning (disable: 4514 4996)
  9983. #pragma warning (push)
  9984. #endif
  9985. int String::getNumBytesAsCString() const throw()
  9986. {
  9987. return (int) wcstombs (0, text, 0);
  9988. }
  9989. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  9990. {
  9991. const int numBytes = (int) wcstombs (destBuffer, text, maxBufferSizeBytes);
  9992. if (destBuffer != 0 && numBytes >= 0)
  9993. destBuffer [numBytes] = 0;
  9994. return numBytes;
  9995. }
  9996. #ifdef _MSC_VER
  9997. #pragma warning (pop)
  9998. #endif
  9999. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  10000. {
  10001. const int len = jmin (maxCharsToCopy, length());
  10002. memcpy (destBuffer, text, len * sizeof (juce_wchar));
  10003. destBuffer [len] = 0;
  10004. }
  10005. String::Concatenator::Concatenator (String& stringToAppendTo)
  10006. : result (stringToAppendTo),
  10007. nextIndex (stringToAppendTo.length())
  10008. {
  10009. }
  10010. String::Concatenator::~Concatenator()
  10011. {
  10012. }
  10013. void String::Concatenator::append (const String& s)
  10014. {
  10015. const int len = s.length();
  10016. if (len > 0)
  10017. {
  10018. result.preallocateStorage (nextIndex + len);
  10019. s.copyToUnicode (((juce_wchar*) result) + nextIndex, len);
  10020. nextIndex += len;
  10021. }
  10022. }
  10023. END_JUCE_NAMESPACE
  10024. /*** End of inlined file: juce_String.cpp ***/
  10025. /*** Start of inlined file: juce_StringArray.cpp ***/
  10026. BEGIN_JUCE_NAMESPACE
  10027. StringArray::StringArray() throw()
  10028. {
  10029. }
  10030. StringArray::StringArray (const StringArray& other)
  10031. : strings (other.strings)
  10032. {
  10033. }
  10034. StringArray::StringArray (const juce_wchar** const initialStrings,
  10035. const int numberOfStrings)
  10036. {
  10037. for (int i = 0; i < numberOfStrings; ++i)
  10038. add (initialStrings [i]);
  10039. }
  10040. StringArray::StringArray (const char** const initialStrings,
  10041. const int numberOfStrings)
  10042. {
  10043. for (int i = 0; i < numberOfStrings; ++i)
  10044. add (initialStrings [i]);
  10045. }
  10046. StringArray::StringArray (const juce_wchar** const initialStrings)
  10047. {
  10048. int i = 0;
  10049. while (initialStrings[i] != 0)
  10050. add (initialStrings [i++]);
  10051. }
  10052. StringArray::StringArray (const char** const initialStrings)
  10053. {
  10054. int i = 0;
  10055. while (initialStrings[i] != 0)
  10056. add (initialStrings [i++]);
  10057. }
  10058. StringArray& StringArray::operator= (const StringArray& other)
  10059. {
  10060. strings = other.strings;
  10061. return *this;
  10062. }
  10063. StringArray::~StringArray()
  10064. {
  10065. }
  10066. bool StringArray::operator== (const StringArray& other) const
  10067. {
  10068. if (other.size() != size())
  10069. return false;
  10070. for (int i = size(); --i >= 0;)
  10071. if (other.strings.getReference(i) != strings.getReference(i))
  10072. return false;
  10073. return true;
  10074. }
  10075. bool StringArray::operator!= (const StringArray& other) const
  10076. {
  10077. return ! operator== (other);
  10078. }
  10079. void StringArray::clear()
  10080. {
  10081. strings.clear();
  10082. }
  10083. const String& StringArray::operator[] (const int index) const throw()
  10084. {
  10085. if (((unsigned int) index) < (unsigned int) strings.size())
  10086. return strings.getReference (index);
  10087. return String::empty;
  10088. }
  10089. void StringArray::add (const String& newString)
  10090. {
  10091. strings.add (newString);
  10092. }
  10093. void StringArray::insert (const int index, const String& newString)
  10094. {
  10095. strings.insert (index, newString);
  10096. }
  10097. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  10098. {
  10099. if (! contains (newString, ignoreCase))
  10100. add (newString);
  10101. }
  10102. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  10103. {
  10104. if (startIndex < 0)
  10105. {
  10106. jassertfalse
  10107. startIndex = 0;
  10108. }
  10109. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10110. numElementsToAdd = otherArray.size() - startIndex;
  10111. while (--numElementsToAdd >= 0)
  10112. strings.add (otherArray.strings.getReference (startIndex++));
  10113. }
  10114. void StringArray::set (const int index, const String& newString)
  10115. {
  10116. strings.set (index, newString);
  10117. }
  10118. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10119. {
  10120. if (ignoreCase)
  10121. {
  10122. for (int i = size(); --i >= 0;)
  10123. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10124. return true;
  10125. }
  10126. else
  10127. {
  10128. for (int i = size(); --i >= 0;)
  10129. if (stringToLookFor == strings.getReference(i))
  10130. return true;
  10131. }
  10132. return false;
  10133. }
  10134. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10135. {
  10136. if (i < 0)
  10137. i = 0;
  10138. const int numElements = size();
  10139. if (ignoreCase)
  10140. {
  10141. while (i < numElements)
  10142. {
  10143. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10144. return i;
  10145. ++i;
  10146. }
  10147. }
  10148. else
  10149. {
  10150. while (i < numElements)
  10151. {
  10152. if (stringToLookFor == strings.getReference (i))
  10153. return i;
  10154. ++i;
  10155. }
  10156. }
  10157. return -1;
  10158. }
  10159. void StringArray::remove (const int index)
  10160. {
  10161. strings.remove (index);
  10162. }
  10163. void StringArray::removeString (const String& stringToRemove,
  10164. const bool ignoreCase)
  10165. {
  10166. if (ignoreCase)
  10167. {
  10168. for (int i = size(); --i >= 0;)
  10169. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10170. strings.remove (i);
  10171. }
  10172. else
  10173. {
  10174. for (int i = size(); --i >= 0;)
  10175. if (stringToRemove == strings.getReference (i))
  10176. strings.remove (i);
  10177. }
  10178. }
  10179. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10180. {
  10181. if (removeWhitespaceStrings)
  10182. {
  10183. for (int i = size(); --i >= 0;)
  10184. if (! strings.getReference(i).containsNonWhitespaceChars())
  10185. strings.remove (i);
  10186. }
  10187. else
  10188. {
  10189. for (int i = size(); --i >= 0;)
  10190. if (strings.getReference(i).isEmpty())
  10191. strings.remove (i);
  10192. }
  10193. }
  10194. void StringArray::trim()
  10195. {
  10196. for (int i = size(); --i >= 0;)
  10197. {
  10198. String& s = strings.getReference(i);
  10199. s = s.trim();
  10200. }
  10201. }
  10202. class InternalStringArrayComparator_CaseSensitive
  10203. {
  10204. public:
  10205. static int compareElements (String& first, String& second) { return first.compare (second); }
  10206. };
  10207. class InternalStringArrayComparator_CaseInsensitive
  10208. {
  10209. public:
  10210. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10211. };
  10212. void StringArray::sort (const bool ignoreCase)
  10213. {
  10214. if (ignoreCase)
  10215. {
  10216. InternalStringArrayComparator_CaseInsensitive comp;
  10217. strings.sort (comp);
  10218. }
  10219. else
  10220. {
  10221. InternalStringArrayComparator_CaseSensitive comp;
  10222. strings.sort (comp);
  10223. }
  10224. }
  10225. void StringArray::move (const int currentIndex, int newIndex) throw()
  10226. {
  10227. strings.move (currentIndex, newIndex);
  10228. }
  10229. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10230. {
  10231. const int last = (numberToJoin < 0) ? size()
  10232. : jmin (size(), start + numberToJoin);
  10233. if (start < 0)
  10234. start = 0;
  10235. if (start >= last)
  10236. return String::empty;
  10237. if (start == last - 1)
  10238. return strings.getReference (start);
  10239. const int separatorLen = separator.length();
  10240. int charsNeeded = separatorLen * (last - start - 1);
  10241. for (int i = start; i < last; ++i)
  10242. charsNeeded += strings.getReference(i).length();
  10243. String result;
  10244. result.preallocateStorage (charsNeeded);
  10245. juce_wchar* dest = (juce_wchar*) result;
  10246. while (start < last)
  10247. {
  10248. const String& s = strings.getReference (start);
  10249. const int len = s.length();
  10250. if (len > 0)
  10251. {
  10252. s.copyToUnicode (dest, len);
  10253. dest += len;
  10254. }
  10255. if (++start < last && separatorLen > 0)
  10256. {
  10257. separator.copyToUnicode (dest, separatorLen);
  10258. dest += separatorLen;
  10259. }
  10260. }
  10261. *dest = 0;
  10262. return result;
  10263. }
  10264. int StringArray::addTokens (const String& text, const bool preserveQuotedStrings)
  10265. {
  10266. return addTokens (text, T(" \n\r\t"), preserveQuotedStrings ? T("\"") : 0);
  10267. }
  10268. int StringArray::addTokens (const String& text, const String& breakCharacters, const String& quoteCharacters)
  10269. {
  10270. int num = 0;
  10271. if (text.isNotEmpty())
  10272. {
  10273. bool insideQuotes = false;
  10274. juce_wchar currentQuoteChar = 0;
  10275. int i = 0;
  10276. int tokenStart = 0;
  10277. for (;;)
  10278. {
  10279. const juce_wchar c = text[i];
  10280. bool isBreak = (c == 0);
  10281. if (! (insideQuotes || isBreak))
  10282. {
  10283. const juce_wchar* b = breakCharacters;
  10284. while (*b != 0)
  10285. {
  10286. if (*b++ == c)
  10287. {
  10288. isBreak = true;
  10289. break;
  10290. }
  10291. }
  10292. }
  10293. if (! isBreak)
  10294. {
  10295. bool isQuote = false;
  10296. const juce_wchar* q = quoteCharacters;
  10297. while (*q != 0)
  10298. {
  10299. if (*q++ == c)
  10300. {
  10301. isQuote = true;
  10302. break;
  10303. }
  10304. }
  10305. if (isQuote)
  10306. {
  10307. if (insideQuotes)
  10308. {
  10309. // only break out of quotes-mode if we find a matching quote to the
  10310. // one that we opened with..
  10311. if (currentQuoteChar == c)
  10312. insideQuotes = false;
  10313. }
  10314. else
  10315. {
  10316. insideQuotes = true;
  10317. currentQuoteChar = c;
  10318. }
  10319. }
  10320. }
  10321. else
  10322. {
  10323. add (String (static_cast <const juce_wchar*> (text) + tokenStart, i - tokenStart));
  10324. ++num;
  10325. tokenStart = i + 1;
  10326. }
  10327. if (c == 0)
  10328. break;
  10329. ++i;
  10330. }
  10331. }
  10332. return num;
  10333. }
  10334. int StringArray::addLines (const String& sourceText)
  10335. {
  10336. int numLines = 0;
  10337. const juce_wchar* text = sourceText;
  10338. while (*text != 0)
  10339. {
  10340. const juce_wchar* const startOfLine = text;
  10341. while (*text != 0)
  10342. {
  10343. if (*text == T('\r'))
  10344. {
  10345. ++text;
  10346. if (*text == T('\n'))
  10347. ++text;
  10348. break;
  10349. }
  10350. if (*text == T('\n'))
  10351. {
  10352. ++text;
  10353. break;
  10354. }
  10355. ++text;
  10356. }
  10357. const juce_wchar* endOfLine = text;
  10358. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10359. --endOfLine;
  10360. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10361. --endOfLine;
  10362. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10363. ++numLines;
  10364. }
  10365. return numLines;
  10366. }
  10367. void StringArray::removeDuplicates (const bool ignoreCase)
  10368. {
  10369. for (int i = 0; i < size() - 1; ++i)
  10370. {
  10371. const String s (strings.getReference(i));
  10372. int nextIndex = i + 1;
  10373. for (;;)
  10374. {
  10375. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10376. if (nextIndex < 0)
  10377. break;
  10378. strings.remove (nextIndex);
  10379. }
  10380. }
  10381. }
  10382. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10383. const bool appendNumberToFirstInstance,
  10384. const tchar* const preNumberString,
  10385. const tchar* const postNumberString)
  10386. {
  10387. for (int i = 0; i < size() - 1; ++i)
  10388. {
  10389. String& s = strings.getReference(i);
  10390. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10391. if (nextIndex >= 0)
  10392. {
  10393. const String original (s);
  10394. int number = 0;
  10395. if (appendNumberToFirstInstance)
  10396. s = original + preNumberString + String (++number) + postNumberString;
  10397. else
  10398. ++number;
  10399. while (nextIndex >= 0)
  10400. {
  10401. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10402. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10403. }
  10404. }
  10405. }
  10406. }
  10407. void StringArray::minimiseStorageOverheads()
  10408. {
  10409. strings.minimiseStorageOverheads();
  10410. }
  10411. END_JUCE_NAMESPACE
  10412. /*** End of inlined file: juce_StringArray.cpp ***/
  10413. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10414. BEGIN_JUCE_NAMESPACE
  10415. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  10416. : ignoreCase (ignoreCase_)
  10417. {
  10418. }
  10419. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  10420. : keys (other.keys),
  10421. values (other.values),
  10422. ignoreCase (other.ignoreCase)
  10423. {
  10424. }
  10425. StringPairArray::~StringPairArray() throw()
  10426. {
  10427. }
  10428. StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  10429. {
  10430. keys = other.keys;
  10431. values = other.values;
  10432. return *this;
  10433. }
  10434. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  10435. {
  10436. for (int i = keys.size(); --i >= 0;)
  10437. if (other [keys[i]] != values[i])
  10438. return false;
  10439. return true;
  10440. }
  10441. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  10442. {
  10443. return ! operator== (other);
  10444. }
  10445. const String& StringPairArray::operator[] (const String& key) const throw()
  10446. {
  10447. return values [keys.indexOf (key, ignoreCase)];
  10448. }
  10449. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10450. {
  10451. const int i = keys.indexOf (key, ignoreCase);
  10452. if (i >= 0)
  10453. return values[i];
  10454. return defaultReturnValue;
  10455. }
  10456. void StringPairArray::set (const String& key,
  10457. const String& value) throw()
  10458. {
  10459. const int i = keys.indexOf (key, ignoreCase);
  10460. if (i >= 0)
  10461. {
  10462. values.set (i, value);
  10463. }
  10464. else
  10465. {
  10466. keys.add (key);
  10467. values.add (value);
  10468. }
  10469. }
  10470. void StringPairArray::addArray (const StringPairArray& other)
  10471. {
  10472. for (int i = 0; i < other.size(); ++i)
  10473. set (other.keys[i], other.values[i]);
  10474. }
  10475. void StringPairArray::clear() throw()
  10476. {
  10477. keys.clear();
  10478. values.clear();
  10479. }
  10480. void StringPairArray::remove (const String& key) throw()
  10481. {
  10482. remove (keys.indexOf (key, ignoreCase));
  10483. }
  10484. void StringPairArray::remove (const int index) throw()
  10485. {
  10486. keys.remove (index);
  10487. values.remove (index);
  10488. }
  10489. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  10490. {
  10491. ignoreCase = shouldIgnoreCase;
  10492. }
  10493. const String StringPairArray::getDescription() const
  10494. {
  10495. String s;
  10496. for (int i = 0; i < keys.size(); ++i)
  10497. {
  10498. s << keys[i] << T(" = ") << values[i];
  10499. if (i < keys.size())
  10500. s << T(", ");
  10501. }
  10502. return s;
  10503. }
  10504. void StringPairArray::minimiseStorageOverheads() throw()
  10505. {
  10506. keys.minimiseStorageOverheads();
  10507. values.minimiseStorageOverheads();
  10508. }
  10509. END_JUCE_NAMESPACE
  10510. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10511. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10512. BEGIN_JUCE_NAMESPACE
  10513. XmlDocument::XmlDocument (const String& documentText) throw()
  10514. : originalText (documentText),
  10515. ignoreEmptyTextElements (true)
  10516. {
  10517. }
  10518. XmlDocument::XmlDocument (const File& file)
  10519. {
  10520. inputSource = new FileInputSource (file);
  10521. }
  10522. XmlDocument::~XmlDocument() throw()
  10523. {
  10524. }
  10525. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10526. {
  10527. inputSource = newSource;
  10528. }
  10529. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10530. {
  10531. ignoreEmptyTextElements = shouldBeIgnored;
  10532. }
  10533. bool XmlDocument::isXmlIdentifierCharSlow (const juce_wchar c) throw()
  10534. {
  10535. return CharacterFunctions::isLetterOrDigit (c)
  10536. || c == T('_')
  10537. || c == T('-')
  10538. || c == T(':')
  10539. || c == T('.');
  10540. }
  10541. inline bool XmlDocument::isXmlIdentifierChar (const juce_wchar c) const throw()
  10542. {
  10543. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10544. : isXmlIdentifierCharSlow (c);
  10545. }
  10546. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10547. {
  10548. String textToParse (originalText);
  10549. if (textToParse.isEmpty() && inputSource != 0)
  10550. {
  10551. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10552. if (in != 0)
  10553. {
  10554. MemoryBlock data;
  10555. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10556. if (data.getSize() >= 2
  10557. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10558. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10559. {
  10560. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10561. }
  10562. else
  10563. {
  10564. textToParse = String::fromUTF8 ((const char*) data.getData(), (int) data.getSize());
  10565. }
  10566. if (! onlyReadOuterDocumentElement)
  10567. originalText = textToParse;
  10568. }
  10569. }
  10570. input = textToParse;
  10571. lastError = String::empty;
  10572. errorOccurred = false;
  10573. outOfData = false;
  10574. needToLoadDTD = true;
  10575. for (int i = 0; i < 128; ++i)
  10576. identifierLookupTable[i] = isXmlIdentifierCharSlow ((juce_wchar) i);
  10577. if (textToParse.isEmpty())
  10578. {
  10579. lastError = "not enough input";
  10580. }
  10581. else
  10582. {
  10583. skipHeader();
  10584. if (input != 0)
  10585. {
  10586. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10587. if (! errorOccurred)
  10588. return result.release();
  10589. }
  10590. else
  10591. {
  10592. lastError = "incorrect xml header";
  10593. }
  10594. }
  10595. return 0;
  10596. }
  10597. const String& XmlDocument::getLastParseError() const throw()
  10598. {
  10599. return lastError;
  10600. }
  10601. void XmlDocument::setLastError (const String& desc, const bool carryOn) throw()
  10602. {
  10603. lastError = desc;
  10604. errorOccurred = ! carryOn;
  10605. }
  10606. const String XmlDocument::getFileContents (const String& filename) const
  10607. {
  10608. if (inputSource != 0)
  10609. {
  10610. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10611. if (in != 0)
  10612. return in->readEntireStreamAsString();
  10613. }
  10614. return String::empty;
  10615. }
  10616. juce_wchar XmlDocument::readNextChar() throw()
  10617. {
  10618. if (*input != 0)
  10619. {
  10620. return *input++;
  10621. }
  10622. else
  10623. {
  10624. outOfData = true;
  10625. return 0;
  10626. }
  10627. }
  10628. int XmlDocument::findNextTokenLength() throw()
  10629. {
  10630. int len = 0;
  10631. juce_wchar c = *input;
  10632. while (isXmlIdentifierChar (c))
  10633. c = input [++len];
  10634. return len;
  10635. }
  10636. void XmlDocument::skipHeader() throw()
  10637. {
  10638. const juce_wchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10639. if (found != 0)
  10640. {
  10641. input = found;
  10642. input = CharacterFunctions::find (input, T("?>"));
  10643. if (input == 0)
  10644. return;
  10645. input += 2;
  10646. }
  10647. skipNextWhiteSpace();
  10648. const juce_wchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10649. if (docType == 0)
  10650. return;
  10651. input = docType + 9;
  10652. int n = 1;
  10653. while (n > 0)
  10654. {
  10655. const juce_wchar c = readNextChar();
  10656. if (outOfData)
  10657. return;
  10658. if (c == T('<'))
  10659. ++n;
  10660. else if (c == T('>'))
  10661. --n;
  10662. }
  10663. docType += 9;
  10664. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10665. }
  10666. void XmlDocument::skipNextWhiteSpace() throw()
  10667. {
  10668. for (;;)
  10669. {
  10670. juce_wchar c = *input;
  10671. while (CharacterFunctions::isWhitespace (c))
  10672. c = *++input;
  10673. if (c == 0)
  10674. {
  10675. outOfData = true;
  10676. break;
  10677. }
  10678. else if (c == T('<'))
  10679. {
  10680. if (input[1] == T('!')
  10681. && input[2] == T('-')
  10682. && input[3] == T('-'))
  10683. {
  10684. const juce_wchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10685. if (closeComment == 0)
  10686. {
  10687. outOfData = true;
  10688. break;
  10689. }
  10690. input = closeComment + 3;
  10691. continue;
  10692. }
  10693. else if (input[1] == T('?'))
  10694. {
  10695. const juce_wchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10696. if (closeBracket == 0)
  10697. {
  10698. outOfData = true;
  10699. break;
  10700. }
  10701. input = closeBracket + 2;
  10702. continue;
  10703. }
  10704. }
  10705. break;
  10706. }
  10707. }
  10708. void XmlDocument::readQuotedString (String& result) throw()
  10709. {
  10710. const juce_wchar quote = readNextChar();
  10711. while (! outOfData)
  10712. {
  10713. const juce_wchar c = readNextChar();
  10714. if (c == quote)
  10715. break;
  10716. if (c == T('&'))
  10717. {
  10718. --input;
  10719. readEntity (result);
  10720. }
  10721. else
  10722. {
  10723. --input;
  10724. const juce_wchar* const start = input;
  10725. for (;;)
  10726. {
  10727. const juce_wchar character = *input;
  10728. if (character == quote)
  10729. {
  10730. result.append (start, (int) (input - start));
  10731. ++input;
  10732. return;
  10733. }
  10734. else if (character == T('&'))
  10735. {
  10736. result.append (start, (int) (input - start));
  10737. break;
  10738. }
  10739. else if (character == 0)
  10740. {
  10741. outOfData = true;
  10742. setLastError ("unmatched quotes", false);
  10743. break;
  10744. }
  10745. ++input;
  10746. }
  10747. }
  10748. }
  10749. }
  10750. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw()
  10751. {
  10752. XmlElement* node = 0;
  10753. skipNextWhiteSpace();
  10754. if (outOfData)
  10755. return 0;
  10756. input = CharacterFunctions::find (input, T("<"));
  10757. if (input != 0)
  10758. {
  10759. ++input;
  10760. int tagLen = findNextTokenLength();
  10761. if (tagLen == 0)
  10762. {
  10763. // no tag name - but allow for a gap after the '<' before giving an error
  10764. skipNextWhiteSpace();
  10765. tagLen = findNextTokenLength();
  10766. if (tagLen == 0)
  10767. {
  10768. setLastError ("tag name missing", false);
  10769. return node;
  10770. }
  10771. }
  10772. node = new XmlElement (String (input, tagLen));
  10773. input += tagLen;
  10774. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10775. // look for attributes
  10776. for (;;)
  10777. {
  10778. skipNextWhiteSpace();
  10779. const juce_wchar c = *input;
  10780. // empty tag..
  10781. if (c == T('/') && input[1] == T('>'))
  10782. {
  10783. input += 2;
  10784. break;
  10785. }
  10786. // parse the guts of the element..
  10787. if (c == T('>'))
  10788. {
  10789. ++input;
  10790. skipNextWhiteSpace();
  10791. if (alsoParseSubElements)
  10792. readChildElements (node);
  10793. break;
  10794. }
  10795. // get an attribute..
  10796. if (isXmlIdentifierChar (c))
  10797. {
  10798. const int attNameLen = findNextTokenLength();
  10799. if (attNameLen > 0)
  10800. {
  10801. const juce_wchar* attNameStart = input;
  10802. input += attNameLen;
  10803. skipNextWhiteSpace();
  10804. if (readNextChar() == T('='))
  10805. {
  10806. skipNextWhiteSpace();
  10807. const juce_wchar nextChar = *input;
  10808. if (nextChar == T('"') || nextChar == T('\''))
  10809. {
  10810. XmlElement::XmlAttributeNode* const newAtt
  10811. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10812. String::empty);
  10813. readQuotedString (newAtt->value);
  10814. if (lastAttribute == 0)
  10815. node->attributes = newAtt;
  10816. else
  10817. lastAttribute->next = newAtt;
  10818. lastAttribute = newAtt;
  10819. continue;
  10820. }
  10821. }
  10822. }
  10823. }
  10824. else
  10825. {
  10826. if (! outOfData)
  10827. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10828. }
  10829. break;
  10830. }
  10831. }
  10832. return node;
  10833. }
  10834. void XmlDocument::readChildElements (XmlElement* parent) throw()
  10835. {
  10836. XmlElement* lastChildNode = 0;
  10837. for (;;)
  10838. {
  10839. skipNextWhiteSpace();
  10840. if (outOfData)
  10841. {
  10842. setLastError ("unmatched tags", false);
  10843. break;
  10844. }
  10845. if (*input == T('<'))
  10846. {
  10847. if (input[1] == T('/'))
  10848. {
  10849. // our close tag..
  10850. input = CharacterFunctions::find (input, T(">"));
  10851. ++input;
  10852. break;
  10853. }
  10854. else if (input[1] == T('!')
  10855. && input[2] == T('[')
  10856. && input[3] == T('C')
  10857. && input[4] == T('D')
  10858. && input[5] == T('A')
  10859. && input[6] == T('T')
  10860. && input[7] == T('A')
  10861. && input[8] == T('['))
  10862. {
  10863. input += 9;
  10864. const juce_wchar* const inputStart = input;
  10865. int len = 0;
  10866. for (;;)
  10867. {
  10868. if (*input == 0)
  10869. {
  10870. setLastError ("unterminated CDATA section", false);
  10871. outOfData = true;
  10872. break;
  10873. }
  10874. else if (input[0] == T(']')
  10875. && input[1] == T(']')
  10876. && input[2] == T('>'))
  10877. {
  10878. input += 3;
  10879. break;
  10880. }
  10881. ++input;
  10882. ++len;
  10883. }
  10884. XmlElement* const e = new XmlElement ((int) 0);
  10885. e->setText (String (inputStart, len));
  10886. if (lastChildNode != 0)
  10887. lastChildNode->nextElement = e;
  10888. else
  10889. parent->addChildElement (e);
  10890. lastChildNode = e;
  10891. }
  10892. else
  10893. {
  10894. // this is some other element, so parse and add it..
  10895. XmlElement* const n = readNextElement (true);
  10896. if (n != 0)
  10897. {
  10898. if (lastChildNode == 0)
  10899. parent->addChildElement (n);
  10900. else
  10901. lastChildNode->nextElement = n;
  10902. lastChildNode = n;
  10903. }
  10904. else
  10905. {
  10906. return;
  10907. }
  10908. }
  10909. }
  10910. else
  10911. {
  10912. // read character block..
  10913. XmlElement* const e = new XmlElement ((int)0);
  10914. if (lastChildNode != 0)
  10915. lastChildNode->nextElement = e;
  10916. else
  10917. parent->addChildElement (e);
  10918. lastChildNode = e;
  10919. String textElementContent;
  10920. for (;;)
  10921. {
  10922. const juce_wchar c = *input;
  10923. if (c == T('<'))
  10924. break;
  10925. if (c == 0)
  10926. {
  10927. setLastError ("unmatched tags", false);
  10928. outOfData = true;
  10929. return;
  10930. }
  10931. if (c == T('&'))
  10932. {
  10933. String entity;
  10934. readEntity (entity);
  10935. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  10936. {
  10937. const juce_wchar* const oldInput = input;
  10938. const bool oldOutOfData = outOfData;
  10939. input = entity;
  10940. outOfData = false;
  10941. for (;;)
  10942. {
  10943. XmlElement* const n = readNextElement (true);
  10944. if (n == 0)
  10945. break;
  10946. if (lastChildNode == 0)
  10947. parent->addChildElement (n);
  10948. else
  10949. lastChildNode->nextElement = n;
  10950. lastChildNode = n;
  10951. }
  10952. input = oldInput;
  10953. outOfData = oldOutOfData;
  10954. }
  10955. else
  10956. {
  10957. textElementContent += entity;
  10958. }
  10959. }
  10960. else
  10961. {
  10962. const juce_wchar* start = input;
  10963. int len = 0;
  10964. for (;;)
  10965. {
  10966. const juce_wchar nextChar = *input;
  10967. if (nextChar == T('<') || nextChar == T('&'))
  10968. {
  10969. break;
  10970. }
  10971. else if (nextChar == 0)
  10972. {
  10973. setLastError ("unmatched tags", false);
  10974. outOfData = true;
  10975. return;
  10976. }
  10977. ++input;
  10978. ++len;
  10979. }
  10980. textElementContent.append (start, len);
  10981. }
  10982. }
  10983. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  10984. : textElementContent.isNotEmpty())
  10985. e->setText (textElementContent);
  10986. }
  10987. }
  10988. }
  10989. void XmlDocument::readEntity (String& result) throw()
  10990. {
  10991. // skip over the ampersand
  10992. ++input;
  10993. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  10994. {
  10995. input += 4;
  10996. result += T("&");
  10997. }
  10998. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  10999. {
  11000. input += 5;
  11001. result += T("\"");
  11002. }
  11003. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  11004. {
  11005. input += 5;
  11006. result += T("\'");
  11007. }
  11008. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  11009. {
  11010. input += 3;
  11011. result += T("<");
  11012. }
  11013. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  11014. {
  11015. input += 3;
  11016. result += T(">");
  11017. }
  11018. else if (*input == T('#'))
  11019. {
  11020. int charCode = 0;
  11021. ++input;
  11022. if (*input == T('x') || *input == T('X'))
  11023. {
  11024. ++input;
  11025. int numChars = 0;
  11026. while (input[0] != T(';'))
  11027. {
  11028. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  11029. if (hexValue < 0 || ++numChars > 8)
  11030. {
  11031. setLastError ("illegal escape sequence", true);
  11032. break;
  11033. }
  11034. charCode = (charCode << 4) | hexValue;
  11035. ++input;
  11036. }
  11037. ++input;
  11038. }
  11039. else if (input[0] >= T('0') && input[0] <= T('9'))
  11040. {
  11041. int numChars = 0;
  11042. while (input[0] != T(';'))
  11043. {
  11044. if (++numChars > 12)
  11045. {
  11046. setLastError ("illegal escape sequence", true);
  11047. break;
  11048. }
  11049. charCode = charCode * 10 + (input[0] - T('0'));
  11050. ++input;
  11051. }
  11052. ++input;
  11053. }
  11054. else
  11055. {
  11056. setLastError ("illegal escape sequence", true);
  11057. result += T("&");
  11058. return;
  11059. }
  11060. result << (juce_wchar) charCode;
  11061. }
  11062. else
  11063. {
  11064. const juce_wchar* const entityNameStart = input;
  11065. const juce_wchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  11066. if (closingSemiColon == 0)
  11067. {
  11068. outOfData = true;
  11069. result += T("&");
  11070. }
  11071. else
  11072. {
  11073. input = closingSemiColon + 1;
  11074. result += expandExternalEntity (String (entityNameStart,
  11075. (int) (closingSemiColon - entityNameStart)));
  11076. }
  11077. }
  11078. }
  11079. const String XmlDocument::expandEntity (const String& ent)
  11080. {
  11081. if (ent.equalsIgnoreCase (T("amp")))
  11082. {
  11083. return T("&");
  11084. }
  11085. else if (ent.equalsIgnoreCase (T("quot")))
  11086. {
  11087. return T("\"");
  11088. }
  11089. else if (ent.equalsIgnoreCase (T("apos")))
  11090. {
  11091. return T("\'");
  11092. }
  11093. else if (ent.equalsIgnoreCase (T("lt")))
  11094. {
  11095. return T("<");
  11096. }
  11097. else if (ent.equalsIgnoreCase (T("gt")))
  11098. {
  11099. return T(">");
  11100. }
  11101. else if (ent[0] == T('#'))
  11102. {
  11103. if (ent[1] == T('x') || ent[1] == T('X'))
  11104. {
  11105. return String::charToString (static_cast <juce_wchar> (ent.substring (2).getHexValue32()));
  11106. }
  11107. else if (ent[1] >= T('0') && ent[1] <= T('9'))
  11108. {
  11109. return String::charToString (static_cast <juce_wchar> (ent.substring (1).getIntValue()));
  11110. }
  11111. setLastError ("illegal escape sequence", false);
  11112. return T("&");
  11113. }
  11114. else
  11115. {
  11116. return expandExternalEntity (ent);
  11117. }
  11118. }
  11119. const String XmlDocument::expandExternalEntity (const String& entity)
  11120. {
  11121. if (needToLoadDTD)
  11122. {
  11123. if (dtdText.isNotEmpty())
  11124. {
  11125. while (dtdText.endsWithChar (T('>')))
  11126. dtdText = dtdText.dropLastCharacters (1);
  11127. tokenisedDTD.addTokens (dtdText, true);
  11128. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  11129. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  11130. {
  11131. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  11132. tokenisedDTD.clear();
  11133. tokenisedDTD.addTokens (getFileContents (fn), true);
  11134. }
  11135. else
  11136. {
  11137. tokenisedDTD.clear();
  11138. const int openBracket = dtdText.indexOfChar (T('['));
  11139. if (openBracket > 0)
  11140. {
  11141. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  11142. if (closeBracket > openBracket)
  11143. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  11144. closeBracket), true);
  11145. }
  11146. }
  11147. for (int i = tokenisedDTD.size(); --i >= 0;)
  11148. {
  11149. if (tokenisedDTD[i].startsWithChar (T('%'))
  11150. && tokenisedDTD[i].endsWithChar (T(';')))
  11151. {
  11152. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11153. StringArray newToks;
  11154. newToks.addTokens (parsed, true);
  11155. tokenisedDTD.remove (i);
  11156. for (int j = newToks.size(); --j >= 0;)
  11157. tokenisedDTD.insert (i, newToks[j]);
  11158. }
  11159. }
  11160. }
  11161. needToLoadDTD = false;
  11162. }
  11163. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11164. {
  11165. if (tokenisedDTD[i] == entity)
  11166. {
  11167. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11168. {
  11169. String ent (tokenisedDTD [i + 1]);
  11170. while (ent.endsWithChar (T('>')))
  11171. ent = ent.dropLastCharacters (1);
  11172. ent = ent.trim().unquoted();
  11173. // check for sub-entities..
  11174. int ampersand = ent.indexOfChar (T('&'));
  11175. while (ampersand >= 0)
  11176. {
  11177. const int semiColon = ent.indexOf (i + 1, T(";"));
  11178. if (semiColon < 0)
  11179. {
  11180. setLastError ("entity without terminating semi-colon", false);
  11181. break;
  11182. }
  11183. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11184. ent = ent.substring (0, ampersand)
  11185. + resolved
  11186. + ent.substring (semiColon + 1);
  11187. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11188. }
  11189. return ent;
  11190. }
  11191. }
  11192. }
  11193. setLastError ("unknown entity", true);
  11194. return entity;
  11195. }
  11196. const String XmlDocument::getParameterEntity (const String& entity)
  11197. {
  11198. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11199. {
  11200. if (tokenisedDTD[i] == entity)
  11201. {
  11202. if (tokenisedDTD [i - 1] == T("%")
  11203. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11204. {
  11205. String ent (tokenisedDTD [i + 1]);
  11206. while (ent.endsWithChar (T('>')))
  11207. ent = ent.dropLastCharacters (1);
  11208. if (ent.equalsIgnoreCase (T("system")))
  11209. {
  11210. String filename (tokenisedDTD [i + 2]);
  11211. while (filename.endsWithChar (T('>')))
  11212. filename = filename.dropLastCharacters (1);
  11213. return getFileContents (filename);
  11214. }
  11215. else
  11216. {
  11217. return ent.trim().unquoted();
  11218. }
  11219. }
  11220. }
  11221. }
  11222. return entity;
  11223. }
  11224. END_JUCE_NAMESPACE
  11225. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11226. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11227. BEGIN_JUCE_NAMESPACE
  11228. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11229. : name (other.name),
  11230. value (other.value),
  11231. next (0)
  11232. {
  11233. }
  11234. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_,
  11235. const String& value_) throw()
  11236. : name (name_),
  11237. value (value_),
  11238. next (0)
  11239. {
  11240. }
  11241. XmlElement::XmlElement (const String& tagName_) throw()
  11242. : tagName (tagName_),
  11243. firstChildElement (0),
  11244. nextElement (0),
  11245. attributes (0)
  11246. {
  11247. // the tag name mustn't be empty, or it'll look like a text element!
  11248. jassert (tagName_.containsNonWhitespaceChars())
  11249. // The tag can't contain spaces or other characters that would create invalid XML!
  11250. jassert (! tagName_.containsAnyOf (T(" <>/&")));
  11251. }
  11252. XmlElement::XmlElement (int /*dummy*/) throw()
  11253. : firstChildElement (0),
  11254. nextElement (0),
  11255. attributes (0)
  11256. {
  11257. }
  11258. XmlElement::XmlElement (const XmlElement& other) throw()
  11259. : tagName (other.tagName),
  11260. firstChildElement (0),
  11261. nextElement (0),
  11262. attributes (0)
  11263. {
  11264. copyChildrenAndAttributesFrom (other);
  11265. }
  11266. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11267. {
  11268. if (this != &other)
  11269. {
  11270. removeAllAttributes();
  11271. deleteAllChildElements();
  11272. tagName = other.tagName;
  11273. copyChildrenAndAttributesFrom (other);
  11274. }
  11275. return *this;
  11276. }
  11277. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11278. {
  11279. XmlElement* child = other.firstChildElement;
  11280. XmlElement* lastChild = 0;
  11281. while (child != 0)
  11282. {
  11283. XmlElement* const copiedChild = new XmlElement (*child);
  11284. if (lastChild != 0)
  11285. lastChild->nextElement = copiedChild;
  11286. else
  11287. firstChildElement = copiedChild;
  11288. lastChild = copiedChild;
  11289. child = child->nextElement;
  11290. }
  11291. const XmlAttributeNode* att = other.attributes;
  11292. XmlAttributeNode* lastAtt = 0;
  11293. while (att != 0)
  11294. {
  11295. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11296. if (lastAtt != 0)
  11297. lastAtt->next = newAtt;
  11298. else
  11299. attributes = newAtt;
  11300. lastAtt = newAtt;
  11301. att = att->next;
  11302. }
  11303. }
  11304. XmlElement::~XmlElement() throw()
  11305. {
  11306. XmlElement* child = firstChildElement;
  11307. while (child != 0)
  11308. {
  11309. XmlElement* const nextChild = child->nextElement;
  11310. delete child;
  11311. child = nextChild;
  11312. }
  11313. XmlAttributeNode* att = attributes;
  11314. while (att != 0)
  11315. {
  11316. XmlAttributeNode* const nextAtt = att->next;
  11317. delete att;
  11318. att = nextAtt;
  11319. }
  11320. }
  11321. namespace XmlOutputFunctions
  11322. {
  11323. static bool isLegalXmlChar (const uint32 c) throw()
  11324. {
  11325. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  11326. return c < sizeof (legalChars) * 8
  11327. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  11328. }
  11329. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  11330. {
  11331. const juce_wchar* t = (const juce_wchar*) text;
  11332. for (;;)
  11333. {
  11334. const juce_wchar character = *t++;
  11335. if (character == 0)
  11336. {
  11337. break;
  11338. }
  11339. else if (isLegalXmlChar ((uint32) character))
  11340. {
  11341. outputStream << (char) character;
  11342. }
  11343. else
  11344. {
  11345. switch (character)
  11346. {
  11347. case '&': outputStream << "&amp;"; break;
  11348. case '"': outputStream << "&quot;"; break;
  11349. case '>': outputStream << "&gt;"; break;
  11350. case '<': outputStream << "&lt;"; break;
  11351. case '\n':
  11352. if (changeNewLines)
  11353. outputStream << "&#10;";
  11354. else
  11355. outputStream << (char) character;
  11356. break;
  11357. case '\r':
  11358. if (changeNewLines)
  11359. outputStream << "&#13;";
  11360. else
  11361. outputStream << (char) character;
  11362. break;
  11363. default:
  11364. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  11365. break;
  11366. }
  11367. }
  11368. }
  11369. }
  11370. static void writeSpaces (OutputStream& out, int numSpaces) throw()
  11371. {
  11372. if (numSpaces > 0)
  11373. {
  11374. const char* const blanks = " ";
  11375. const int blankSize = (int) sizeof (blanks) - 1;
  11376. while (numSpaces > blankSize)
  11377. {
  11378. out.write (blanks, blankSize);
  11379. numSpaces -= blankSize;
  11380. }
  11381. out.write (blanks, numSpaces);
  11382. }
  11383. }
  11384. }
  11385. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11386. const int indentationLevel,
  11387. const int lineWrapLength) const throw()
  11388. {
  11389. using namespace XmlOutputFunctions;
  11390. writeSpaces (outputStream, indentationLevel);
  11391. if (! isTextElement())
  11392. {
  11393. outputStream.writeByte ('<');
  11394. outputStream << tagName;
  11395. const int attIndent = indentationLevel + tagName.length() + 1;
  11396. int lineLen = 0;
  11397. const XmlAttributeNode* att = attributes;
  11398. while (att != 0)
  11399. {
  11400. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11401. {
  11402. outputStream.write ("\r\n", 2);
  11403. writeSpaces (outputStream, attIndent);
  11404. lineLen = 0;
  11405. }
  11406. const int64 startPos = outputStream.getPosition();
  11407. outputStream.writeByte (' ');
  11408. outputStream << att->name;
  11409. outputStream.write ("=\"", 2);
  11410. escapeIllegalXmlChars (outputStream, att->value, true);
  11411. outputStream.writeByte ('"');
  11412. lineLen += (int) (outputStream.getPosition() - startPos);
  11413. att = att->next;
  11414. }
  11415. if (firstChildElement != 0)
  11416. {
  11417. XmlElement* child = firstChildElement;
  11418. if (child->nextElement == 0 && child->isTextElement())
  11419. {
  11420. outputStream.writeByte ('>');
  11421. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11422. }
  11423. else
  11424. {
  11425. if (indentationLevel >= 0)
  11426. outputStream.write (">\r\n", 3);
  11427. else
  11428. outputStream.writeByte ('>');
  11429. bool lastWasTextNode = false;
  11430. while (child != 0)
  11431. {
  11432. if (child->isTextElement())
  11433. {
  11434. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11435. writeSpaces (outputStream, indentationLevel + 2);
  11436. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11437. lastWasTextNode = true;
  11438. }
  11439. else
  11440. {
  11441. if (indentationLevel >= 0)
  11442. {
  11443. if (lastWasTextNode)
  11444. outputStream.write ("\r\n", 2);
  11445. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11446. }
  11447. else
  11448. {
  11449. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11450. }
  11451. lastWasTextNode = false;
  11452. }
  11453. child = child->nextElement;
  11454. }
  11455. if (indentationLevel >= 0)
  11456. {
  11457. if (lastWasTextNode)
  11458. outputStream.write ("\r\n", 2);
  11459. writeSpaces (outputStream, indentationLevel);
  11460. }
  11461. }
  11462. outputStream.write ("</", 2);
  11463. outputStream << tagName;
  11464. if (indentationLevel >= 0)
  11465. outputStream.write (">\r\n", 3);
  11466. else
  11467. outputStream.writeByte ('>');
  11468. }
  11469. else
  11470. {
  11471. if (indentationLevel >= 0)
  11472. outputStream.write ("/>\r\n", 4);
  11473. else
  11474. outputStream.write ("/>", 2);
  11475. }
  11476. }
  11477. else
  11478. {
  11479. if (indentationLevel >= 0)
  11480. writeSpaces (outputStream, indentationLevel + 2);
  11481. escapeIllegalXmlChars (outputStream, getText(), false);
  11482. }
  11483. }
  11484. const String XmlElement::createDocument (const String& dtdToUse,
  11485. const bool allOnOneLine,
  11486. const bool includeXmlHeader,
  11487. const String& encodingType,
  11488. const int lineWrapLength) const throw()
  11489. {
  11490. MemoryOutputStream mem (2048, 4096);
  11491. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11492. return String (mem.getData(), mem.getDataSize());
  11493. }
  11494. void XmlElement::writeToStream (OutputStream& output,
  11495. const String& dtdToUse,
  11496. const bool allOnOneLine,
  11497. const bool includeXmlHeader,
  11498. const String& encodingType,
  11499. const int lineWrapLength) const throw()
  11500. {
  11501. if (includeXmlHeader)
  11502. {
  11503. output << "<?xml version=\"1.0\" encoding=\"" << encodingType;
  11504. if (allOnOneLine)
  11505. output << "\"?> ";
  11506. else
  11507. output << "\"?>\r\n\r\n";
  11508. }
  11509. if (dtdToUse.isNotEmpty())
  11510. {
  11511. output << dtdToUse;
  11512. if (allOnOneLine)
  11513. output << " ";
  11514. else
  11515. output << "\r\n";
  11516. }
  11517. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11518. }
  11519. bool XmlElement::writeToFile (const File& file,
  11520. const String& dtdToUse,
  11521. const String& encodingType,
  11522. const int lineWrapLength) const throw()
  11523. {
  11524. if (file.hasWriteAccess())
  11525. {
  11526. TemporaryFile tempFile (file);
  11527. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11528. if (out != 0)
  11529. {
  11530. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11531. out = 0;
  11532. return tempFile.overwriteTargetFileWithTemporary();
  11533. }
  11534. }
  11535. return false;
  11536. }
  11537. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11538. {
  11539. #ifdef JUCE_DEBUG
  11540. // if debugging, check that the case is actually the same, because
  11541. // valid xml is case-sensitive, and although this lets it pass, it's
  11542. // better not to..
  11543. if (tagName.equalsIgnoreCase (tagNameWanted))
  11544. {
  11545. jassert (tagName == tagNameWanted);
  11546. return true;
  11547. }
  11548. else
  11549. {
  11550. return false;
  11551. }
  11552. #else
  11553. return tagName.equalsIgnoreCase (tagNameWanted);
  11554. #endif
  11555. }
  11556. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11557. {
  11558. XmlElement* e = nextElement;
  11559. while (e != 0 && ! e->hasTagName (requiredTagName))
  11560. e = e->nextElement;
  11561. return e;
  11562. }
  11563. int XmlElement::getNumAttributes() const throw()
  11564. {
  11565. const XmlAttributeNode* att = attributes;
  11566. int count = 0;
  11567. while (att != 0)
  11568. {
  11569. att = att->next;
  11570. ++count;
  11571. }
  11572. return count;
  11573. }
  11574. const String& XmlElement::getAttributeName (const int index) const throw()
  11575. {
  11576. const XmlAttributeNode* att = attributes;
  11577. int count = 0;
  11578. while (att != 0)
  11579. {
  11580. if (count == index)
  11581. return att->name;
  11582. att = att->next;
  11583. ++count;
  11584. }
  11585. return String::empty;
  11586. }
  11587. const String& XmlElement::getAttributeValue (const int index) const throw()
  11588. {
  11589. const XmlAttributeNode* att = attributes;
  11590. int count = 0;
  11591. while (att != 0)
  11592. {
  11593. if (count == index)
  11594. return att->value;
  11595. att = att->next;
  11596. ++count;
  11597. }
  11598. return String::empty;
  11599. }
  11600. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11601. {
  11602. const XmlAttributeNode* att = attributes;
  11603. while (att != 0)
  11604. {
  11605. if (att->name.equalsIgnoreCase (attributeName))
  11606. return true;
  11607. att = att->next;
  11608. }
  11609. return false;
  11610. }
  11611. const String XmlElement::getStringAttribute (const String& attributeName,
  11612. const String& defaultReturnValue) const throw()
  11613. {
  11614. const XmlAttributeNode* att = attributes;
  11615. while (att != 0)
  11616. {
  11617. if (att->name.equalsIgnoreCase (attributeName))
  11618. return att->value;
  11619. att = att->next;
  11620. }
  11621. return defaultReturnValue;
  11622. }
  11623. int XmlElement::getIntAttribute (const String& attributeName,
  11624. const int defaultReturnValue) const throw()
  11625. {
  11626. const XmlAttributeNode* att = attributes;
  11627. while (att != 0)
  11628. {
  11629. if (att->name.equalsIgnoreCase (attributeName))
  11630. return att->value.getIntValue();
  11631. att = att->next;
  11632. }
  11633. return defaultReturnValue;
  11634. }
  11635. double XmlElement::getDoubleAttribute (const String& attributeName,
  11636. const double defaultReturnValue) const throw()
  11637. {
  11638. const XmlAttributeNode* att = attributes;
  11639. while (att != 0)
  11640. {
  11641. if (att->name.equalsIgnoreCase (attributeName))
  11642. return att->value.getDoubleValue();
  11643. att = att->next;
  11644. }
  11645. return defaultReturnValue;
  11646. }
  11647. bool XmlElement::getBoolAttribute (const String& attributeName,
  11648. const bool defaultReturnValue) const throw()
  11649. {
  11650. const XmlAttributeNode* att = attributes;
  11651. while (att != 0)
  11652. {
  11653. if (att->name.equalsIgnoreCase (attributeName))
  11654. {
  11655. juce_wchar firstChar = att->value[0];
  11656. if (CharacterFunctions::isWhitespace (firstChar))
  11657. firstChar = att->value.trimStart() [0];
  11658. return firstChar == T('1')
  11659. || firstChar == T('t')
  11660. || firstChar == T('y')
  11661. || firstChar == T('T')
  11662. || firstChar == T('Y');
  11663. }
  11664. att = att->next;
  11665. }
  11666. return defaultReturnValue;
  11667. }
  11668. bool XmlElement::compareAttribute (const String& attributeName,
  11669. const String& stringToCompareAgainst,
  11670. const bool ignoreCase) const throw()
  11671. {
  11672. const XmlAttributeNode* att = attributes;
  11673. while (att != 0)
  11674. {
  11675. if (att->name.equalsIgnoreCase (attributeName))
  11676. {
  11677. if (ignoreCase)
  11678. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11679. else
  11680. return att->value == stringToCompareAgainst;
  11681. }
  11682. att = att->next;
  11683. }
  11684. return false;
  11685. }
  11686. void XmlElement::setAttribute (const String& attributeName,
  11687. const String& value) throw()
  11688. {
  11689. #ifdef JUCE_DEBUG
  11690. // check the identifier being passed in is legal..
  11691. const juce_wchar* t = attributeName;
  11692. while (*t != 0)
  11693. {
  11694. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11695. || *t == T('_')
  11696. || *t == T('-')
  11697. || *t == T(':'));
  11698. ++t;
  11699. }
  11700. #endif
  11701. if (attributes == 0)
  11702. {
  11703. attributes = new XmlAttributeNode (attributeName, value);
  11704. }
  11705. else
  11706. {
  11707. XmlAttributeNode* att = attributes;
  11708. for (;;)
  11709. {
  11710. if (att->name.equalsIgnoreCase (attributeName))
  11711. {
  11712. att->value = value;
  11713. break;
  11714. }
  11715. else if (att->next == 0)
  11716. {
  11717. att->next = new XmlAttributeNode (attributeName, value);
  11718. break;
  11719. }
  11720. att = att->next;
  11721. }
  11722. }
  11723. }
  11724. void XmlElement::setAttribute (const String& attributeName,
  11725. const int number) throw()
  11726. {
  11727. setAttribute (attributeName, String (number));
  11728. }
  11729. void XmlElement::setAttribute (const String& attributeName,
  11730. const double number) throw()
  11731. {
  11732. setAttribute (attributeName, String (number));
  11733. }
  11734. void XmlElement::removeAttribute (const String& attributeName) throw()
  11735. {
  11736. XmlAttributeNode* att = attributes;
  11737. XmlAttributeNode* lastAtt = 0;
  11738. while (att != 0)
  11739. {
  11740. if (att->name.equalsIgnoreCase (attributeName))
  11741. {
  11742. if (lastAtt == 0)
  11743. attributes = att->next;
  11744. else
  11745. lastAtt->next = att->next;
  11746. delete att;
  11747. break;
  11748. }
  11749. lastAtt = att;
  11750. att = att->next;
  11751. }
  11752. }
  11753. void XmlElement::removeAllAttributes() throw()
  11754. {
  11755. while (attributes != 0)
  11756. {
  11757. XmlAttributeNode* const nextAtt = attributes->next;
  11758. delete attributes;
  11759. attributes = nextAtt;
  11760. }
  11761. }
  11762. int XmlElement::getNumChildElements() const throw()
  11763. {
  11764. int count = 0;
  11765. const XmlElement* child = firstChildElement;
  11766. while (child != 0)
  11767. {
  11768. ++count;
  11769. child = child->nextElement;
  11770. }
  11771. return count;
  11772. }
  11773. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11774. {
  11775. int count = 0;
  11776. XmlElement* child = firstChildElement;
  11777. while (child != 0 && count < index)
  11778. {
  11779. child = child->nextElement;
  11780. ++count;
  11781. }
  11782. return child;
  11783. }
  11784. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11785. {
  11786. XmlElement* child = firstChildElement;
  11787. while (child != 0)
  11788. {
  11789. if (child->hasTagName (childName))
  11790. break;
  11791. child = child->nextElement;
  11792. }
  11793. return child;
  11794. }
  11795. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11796. {
  11797. if (newNode != 0)
  11798. {
  11799. if (firstChildElement == 0)
  11800. {
  11801. firstChildElement = newNode;
  11802. }
  11803. else
  11804. {
  11805. XmlElement* child = firstChildElement;
  11806. while (child->nextElement != 0)
  11807. child = child->nextElement;
  11808. child->nextElement = newNode;
  11809. // if this is non-zero, then something's probably
  11810. // gone wrong..
  11811. jassert (newNode->nextElement == 0);
  11812. }
  11813. }
  11814. }
  11815. void XmlElement::insertChildElement (XmlElement* const newNode,
  11816. int indexToInsertAt) throw()
  11817. {
  11818. if (newNode != 0)
  11819. {
  11820. removeChildElement (newNode, false);
  11821. if (indexToInsertAt == 0)
  11822. {
  11823. newNode->nextElement = firstChildElement;
  11824. firstChildElement = newNode;
  11825. }
  11826. else
  11827. {
  11828. if (firstChildElement == 0)
  11829. {
  11830. firstChildElement = newNode;
  11831. }
  11832. else
  11833. {
  11834. if (indexToInsertAt < 0)
  11835. indexToInsertAt = std::numeric_limits<int>::max();
  11836. XmlElement* child = firstChildElement;
  11837. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11838. child = child->nextElement;
  11839. newNode->nextElement = child->nextElement;
  11840. child->nextElement = newNode;
  11841. }
  11842. }
  11843. }
  11844. }
  11845. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11846. {
  11847. XmlElement* const newElement = new XmlElement (tagName);
  11848. addChildElement (newElement);
  11849. return newElement;
  11850. }
  11851. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11852. XmlElement* const newNode) throw()
  11853. {
  11854. if (newNode != 0)
  11855. {
  11856. XmlElement* child = firstChildElement;
  11857. XmlElement* previousNode = 0;
  11858. while (child != 0)
  11859. {
  11860. if (child == currentChildElement)
  11861. {
  11862. if (child != newNode)
  11863. {
  11864. if (previousNode == 0)
  11865. firstChildElement = newNode;
  11866. else
  11867. previousNode->nextElement = newNode;
  11868. newNode->nextElement = child->nextElement;
  11869. delete child;
  11870. }
  11871. return true;
  11872. }
  11873. previousNode = child;
  11874. child = child->nextElement;
  11875. }
  11876. }
  11877. return false;
  11878. }
  11879. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11880. const bool shouldDeleteTheChild) throw()
  11881. {
  11882. if (childToRemove != 0)
  11883. {
  11884. if (firstChildElement == childToRemove)
  11885. {
  11886. firstChildElement = childToRemove->nextElement;
  11887. childToRemove->nextElement = 0;
  11888. }
  11889. else
  11890. {
  11891. XmlElement* child = firstChildElement;
  11892. XmlElement* last = 0;
  11893. while (child != 0)
  11894. {
  11895. if (child == childToRemove)
  11896. {
  11897. if (last == 0)
  11898. firstChildElement = child->nextElement;
  11899. else
  11900. last->nextElement = child->nextElement;
  11901. childToRemove->nextElement = 0;
  11902. break;
  11903. }
  11904. last = child;
  11905. child = child->nextElement;
  11906. }
  11907. }
  11908. if (shouldDeleteTheChild)
  11909. delete childToRemove;
  11910. }
  11911. }
  11912. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11913. const bool ignoreOrderOfAttributes) const throw()
  11914. {
  11915. if (this != other)
  11916. {
  11917. if (other == 0 || tagName != other->tagName)
  11918. {
  11919. return false;
  11920. }
  11921. if (ignoreOrderOfAttributes)
  11922. {
  11923. int totalAtts = 0;
  11924. const XmlAttributeNode* att = attributes;
  11925. while (att != 0)
  11926. {
  11927. if (! other->compareAttribute (att->name, att->value))
  11928. return false;
  11929. att = att->next;
  11930. ++totalAtts;
  11931. }
  11932. if (totalAtts != other->getNumAttributes())
  11933. return false;
  11934. }
  11935. else
  11936. {
  11937. const XmlAttributeNode* thisAtt = attributes;
  11938. const XmlAttributeNode* otherAtt = other->attributes;
  11939. for (;;)
  11940. {
  11941. if (thisAtt == 0 || otherAtt == 0)
  11942. {
  11943. if (thisAtt == otherAtt) // both 0, so it's a match
  11944. break;
  11945. return false;
  11946. }
  11947. if (thisAtt->name != otherAtt->name
  11948. || thisAtt->value != otherAtt->value)
  11949. {
  11950. return false;
  11951. }
  11952. thisAtt = thisAtt->next;
  11953. otherAtt = otherAtt->next;
  11954. }
  11955. }
  11956. const XmlElement* thisChild = firstChildElement;
  11957. const XmlElement* otherChild = other->firstChildElement;
  11958. for (;;)
  11959. {
  11960. if (thisChild == 0 || otherChild == 0)
  11961. {
  11962. if (thisChild == otherChild) // both 0, so it's a match
  11963. break;
  11964. return false;
  11965. }
  11966. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  11967. return false;
  11968. thisChild = thisChild->nextElement;
  11969. otherChild = otherChild->nextElement;
  11970. }
  11971. }
  11972. return true;
  11973. }
  11974. void XmlElement::deleteAllChildElements() throw()
  11975. {
  11976. while (firstChildElement != 0)
  11977. {
  11978. XmlElement* const nextChild = firstChildElement->nextElement;
  11979. delete firstChildElement;
  11980. firstChildElement = nextChild;
  11981. }
  11982. }
  11983. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  11984. {
  11985. XmlElement* child = firstChildElement;
  11986. while (child != 0)
  11987. {
  11988. if (child->hasTagName (name))
  11989. {
  11990. XmlElement* const nextChild = child->nextElement;
  11991. removeChildElement (child, true);
  11992. child = nextChild;
  11993. }
  11994. else
  11995. {
  11996. child = child->nextElement;
  11997. }
  11998. }
  11999. }
  12000. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  12001. {
  12002. const XmlElement* child = firstChildElement;
  12003. while (child != 0)
  12004. {
  12005. if (child == possibleChild)
  12006. return true;
  12007. child = child->nextElement;
  12008. }
  12009. return false;
  12010. }
  12011. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  12012. {
  12013. if (this == elementToLookFor || elementToLookFor == 0)
  12014. return 0;
  12015. XmlElement* child = firstChildElement;
  12016. while (child != 0)
  12017. {
  12018. if (elementToLookFor == child)
  12019. return this;
  12020. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  12021. if (found != 0)
  12022. return found;
  12023. child = child->nextElement;
  12024. }
  12025. return 0;
  12026. }
  12027. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  12028. {
  12029. XmlElement* e = firstChildElement;
  12030. while (e != 0)
  12031. {
  12032. *elems++ = e;
  12033. e = e->nextElement;
  12034. }
  12035. }
  12036. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  12037. {
  12038. XmlElement* e = firstChildElement = elems[0];
  12039. for (int i = 1; i < num; ++i)
  12040. {
  12041. e->nextElement = elems[i];
  12042. e = e->nextElement;
  12043. }
  12044. e->nextElement = 0;
  12045. }
  12046. bool XmlElement::isTextElement() const throw()
  12047. {
  12048. return tagName.isEmpty();
  12049. }
  12050. static const juce_wchar* const juce_xmltextContentAttributeName = T("text");
  12051. const String XmlElement::getText() const throw()
  12052. {
  12053. jassert (isTextElement()); // you're trying to get the text from an element that
  12054. // isn't actually a text element.. If this contains text sub-nodes, you
  12055. // probably want to use getAllSubText instead.
  12056. return getStringAttribute (juce_xmltextContentAttributeName);
  12057. }
  12058. void XmlElement::setText (const String& newText) throw()
  12059. {
  12060. if (isTextElement())
  12061. {
  12062. setAttribute (juce_xmltextContentAttributeName, newText);
  12063. }
  12064. else
  12065. {
  12066. jassertfalse // you can only change the text in a text element, not a normal one.
  12067. }
  12068. }
  12069. const String XmlElement::getAllSubText() const throw()
  12070. {
  12071. String result;
  12072. String::Concatenator concatenator (result);
  12073. const XmlElement* child = firstChildElement;
  12074. while (child != 0)
  12075. {
  12076. if (child->isTextElement())
  12077. concatenator.append (child->getText());
  12078. child = child->nextElement;
  12079. }
  12080. return result;
  12081. }
  12082. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  12083. const String& defaultReturnValue) const throw()
  12084. {
  12085. const XmlElement* const child = getChildByName (childTagName);
  12086. if (child != 0)
  12087. return child->getAllSubText();
  12088. return defaultReturnValue;
  12089. }
  12090. XmlElement* XmlElement::createTextElement (const String& text) throw()
  12091. {
  12092. XmlElement* const e = new XmlElement ((int) 0);
  12093. e->setAttribute (juce_xmltextContentAttributeName, text);
  12094. return e;
  12095. }
  12096. void XmlElement::addTextElement (const String& text) throw()
  12097. {
  12098. addChildElement (createTextElement (text));
  12099. }
  12100. void XmlElement::deleteAllTextElements() throw()
  12101. {
  12102. XmlElement* child = firstChildElement;
  12103. while (child != 0)
  12104. {
  12105. XmlElement* const next = child->nextElement;
  12106. if (child->isTextElement())
  12107. removeChildElement (child, true);
  12108. child = next;
  12109. }
  12110. }
  12111. END_JUCE_NAMESPACE
  12112. /*** End of inlined file: juce_XmlElement.cpp ***/
  12113. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  12114. BEGIN_JUCE_NAMESPACE
  12115. ReadWriteLock::ReadWriteLock() throw()
  12116. : numWaitingWriters (0),
  12117. numWriters (0),
  12118. writerThreadId (0)
  12119. {
  12120. }
  12121. ReadWriteLock::~ReadWriteLock() throw()
  12122. {
  12123. jassert (readerThreads.size() == 0);
  12124. jassert (numWriters == 0);
  12125. }
  12126. void ReadWriteLock::enterRead() const throw()
  12127. {
  12128. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12129. const ScopedLock sl (accessLock);
  12130. for (;;)
  12131. {
  12132. jassert (readerThreads.size() % 2 == 0);
  12133. int i;
  12134. for (i = 0; i < readerThreads.size(); i += 2)
  12135. if (readerThreads.getUnchecked(i) == threadId)
  12136. break;
  12137. if (i < readerThreads.size()
  12138. || numWriters + numWaitingWriters == 0
  12139. || (threadId == writerThreadId && numWriters > 0))
  12140. {
  12141. if (i < readerThreads.size())
  12142. {
  12143. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  12144. }
  12145. else
  12146. {
  12147. readerThreads.add (threadId);
  12148. readerThreads.add ((Thread::ThreadID) 1);
  12149. }
  12150. return;
  12151. }
  12152. const ScopedUnlock ul (accessLock);
  12153. waitEvent.wait (100);
  12154. }
  12155. }
  12156. void ReadWriteLock::exitRead() const throw()
  12157. {
  12158. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12159. const ScopedLock sl (accessLock);
  12160. for (int i = 0; i < readerThreads.size(); i += 2)
  12161. {
  12162. if (readerThreads.getUnchecked(i) == threadId)
  12163. {
  12164. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12165. if (newCount == 0)
  12166. {
  12167. readerThreads.removeRange (i, 2);
  12168. waitEvent.signal();
  12169. }
  12170. else
  12171. {
  12172. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12173. }
  12174. return;
  12175. }
  12176. }
  12177. jassertfalse // unlocking a lock that wasn't locked..
  12178. }
  12179. void ReadWriteLock::enterWrite() const throw()
  12180. {
  12181. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12182. const ScopedLock sl (accessLock);
  12183. for (;;)
  12184. {
  12185. if (readerThreads.size() + numWriters == 0
  12186. || threadId == writerThreadId
  12187. || (readerThreads.size() == 2
  12188. && readerThreads.getUnchecked(0) == threadId))
  12189. {
  12190. writerThreadId = threadId;
  12191. ++numWriters;
  12192. break;
  12193. }
  12194. ++numWaitingWriters;
  12195. accessLock.exit();
  12196. waitEvent.wait (100);
  12197. accessLock.enter();
  12198. --numWaitingWriters;
  12199. }
  12200. }
  12201. bool ReadWriteLock::tryEnterWrite() const throw()
  12202. {
  12203. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12204. const ScopedLock sl (accessLock);
  12205. if (readerThreads.size() + numWriters == 0
  12206. || threadId == writerThreadId
  12207. || (readerThreads.size() == 2
  12208. && readerThreads.getUnchecked(0) == threadId))
  12209. {
  12210. writerThreadId = threadId;
  12211. ++numWriters;
  12212. return true;
  12213. }
  12214. return false;
  12215. }
  12216. void ReadWriteLock::exitWrite() const throw()
  12217. {
  12218. const ScopedLock sl (accessLock);
  12219. // check this thread actually had the lock..
  12220. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12221. if (--numWriters == 0)
  12222. {
  12223. writerThreadId = 0;
  12224. waitEvent.signal();
  12225. }
  12226. }
  12227. END_JUCE_NAMESPACE
  12228. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12229. /*** Start of inlined file: juce_Thread.cpp ***/
  12230. BEGIN_JUCE_NAMESPACE
  12231. // these functions are implemented in the platform-specific code.
  12232. void* juce_createThread (void* userData);
  12233. void juce_killThread (void* handle);
  12234. bool juce_setThreadPriority (void* handle, int priority);
  12235. void juce_setCurrentThreadName (const String& name);
  12236. #if JUCE_WIN32
  12237. void juce_CloseThreadHandle (void* handle);
  12238. #endif
  12239. void Thread::threadEntryPoint (Thread* const thread)
  12240. {
  12241. {
  12242. const ScopedLock sl (runningThreadsLock);
  12243. runningThreads.add (thread);
  12244. }
  12245. JUCE_TRY
  12246. {
  12247. thread->threadId_ = Thread::getCurrentThreadId();
  12248. if (thread->threadName_.isNotEmpty())
  12249. juce_setCurrentThreadName (thread->threadName_);
  12250. if (thread->startSuspensionEvent_.wait (10000))
  12251. {
  12252. if (thread->affinityMask_ != 0)
  12253. setCurrentThreadAffinityMask (thread->affinityMask_);
  12254. thread->run();
  12255. }
  12256. }
  12257. JUCE_CATCH_ALL_ASSERT
  12258. {
  12259. const ScopedLock sl (runningThreadsLock);
  12260. jassert (runningThreads.contains (thread));
  12261. runningThreads.removeValue (thread);
  12262. }
  12263. #if JUCE_WIN32
  12264. juce_CloseThreadHandle (thread->threadHandle_);
  12265. #endif
  12266. thread->threadHandle_ = 0;
  12267. thread->threadId_ = 0;
  12268. }
  12269. // used to wrap the incoming call from the platform-specific code
  12270. void JUCE_API juce_threadEntryPoint (void* userData)
  12271. {
  12272. Thread::threadEntryPoint ((Thread*) userData);
  12273. }
  12274. Thread::Thread (const String& threadName)
  12275. : threadName_ (threadName),
  12276. threadHandle_ (0),
  12277. threadPriority_ (5),
  12278. threadId_ (0),
  12279. affinityMask_ (0),
  12280. threadShouldExit_ (false)
  12281. {
  12282. }
  12283. Thread::~Thread()
  12284. {
  12285. stopThread (100);
  12286. }
  12287. void Thread::startThread()
  12288. {
  12289. const ScopedLock sl (startStopLock);
  12290. threadShouldExit_ = false;
  12291. if (threadHandle_ == 0)
  12292. {
  12293. threadHandle_ = juce_createThread ((void*) this);
  12294. juce_setThreadPriority (threadHandle_, threadPriority_);
  12295. startSuspensionEvent_.signal();
  12296. }
  12297. }
  12298. void Thread::startThread (const int priority)
  12299. {
  12300. const ScopedLock sl (startStopLock);
  12301. if (threadHandle_ == 0)
  12302. {
  12303. threadPriority_ = priority;
  12304. startThread();
  12305. }
  12306. else
  12307. {
  12308. setPriority (priority);
  12309. }
  12310. }
  12311. bool Thread::isThreadRunning() const
  12312. {
  12313. return threadHandle_ != 0;
  12314. }
  12315. void Thread::signalThreadShouldExit()
  12316. {
  12317. threadShouldExit_ = true;
  12318. }
  12319. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12320. {
  12321. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12322. jassert (getThreadId() != getCurrentThreadId());
  12323. const int sleepMsPerIteration = 5;
  12324. int count = timeOutMilliseconds / sleepMsPerIteration;
  12325. while (isThreadRunning())
  12326. {
  12327. if (timeOutMilliseconds > 0 && --count < 0)
  12328. return false;
  12329. sleep (sleepMsPerIteration);
  12330. }
  12331. return true;
  12332. }
  12333. void Thread::stopThread (const int timeOutMilliseconds)
  12334. {
  12335. // agh! You can't stop the thread that's calling this method! How on earth
  12336. // would that work??
  12337. jassert (getCurrentThreadId() != getThreadId());
  12338. const ScopedLock sl (startStopLock);
  12339. if (isThreadRunning())
  12340. {
  12341. signalThreadShouldExit();
  12342. notify();
  12343. if (timeOutMilliseconds != 0)
  12344. waitForThreadToExit (timeOutMilliseconds);
  12345. if (isThreadRunning())
  12346. {
  12347. // very bad karma if this point is reached, as
  12348. // there are bound to be locks and events left in
  12349. // silly states when a thread is killed by force..
  12350. jassertfalse
  12351. Logger::writeToLog ("!! killing thread by force !!");
  12352. juce_killThread (threadHandle_);
  12353. threadHandle_ = 0;
  12354. threadId_ = 0;
  12355. const ScopedLock sl2 (runningThreadsLock);
  12356. runningThreads.removeValue (this);
  12357. }
  12358. }
  12359. }
  12360. bool Thread::setPriority (const int priority)
  12361. {
  12362. const ScopedLock sl (startStopLock);
  12363. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12364. if (worked)
  12365. threadPriority_ = priority;
  12366. return worked;
  12367. }
  12368. bool Thread::setCurrentThreadPriority (const int priority)
  12369. {
  12370. return juce_setThreadPriority (0, priority);
  12371. }
  12372. void Thread::setAffinityMask (const uint32 affinityMask)
  12373. {
  12374. affinityMask_ = affinityMask;
  12375. }
  12376. bool Thread::wait (const int timeOutMilliseconds) const
  12377. {
  12378. return defaultEvent_.wait (timeOutMilliseconds);
  12379. }
  12380. void Thread::notify() const
  12381. {
  12382. defaultEvent_.signal();
  12383. }
  12384. int Thread::getNumRunningThreads()
  12385. {
  12386. return runningThreads.size();
  12387. }
  12388. Thread* Thread::getCurrentThread()
  12389. {
  12390. const ThreadID thisId = getCurrentThreadId();
  12391. const ScopedLock sl (runningThreadsLock);
  12392. for (int i = runningThreads.size(); --i >= 0;)
  12393. {
  12394. Thread* const t = runningThreads.getUnchecked(i);
  12395. if (t->threadId_ == thisId)
  12396. return t;
  12397. }
  12398. return 0;
  12399. }
  12400. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12401. {
  12402. {
  12403. const ScopedLock sl (runningThreadsLock);
  12404. for (int i = runningThreads.size(); --i >= 0;)
  12405. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12406. }
  12407. for (;;)
  12408. {
  12409. Thread* firstThread;
  12410. {
  12411. const ScopedLock sl (runningThreadsLock);
  12412. firstThread = runningThreads.getFirst();
  12413. }
  12414. if (firstThread == 0)
  12415. break;
  12416. firstThread->stopThread (timeOutMilliseconds);
  12417. }
  12418. }
  12419. Array<Thread*> Thread::runningThreads;
  12420. CriticalSection Thread::runningThreadsLock;
  12421. END_JUCE_NAMESPACE
  12422. /*** End of inlined file: juce_Thread.cpp ***/
  12423. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12424. BEGIN_JUCE_NAMESPACE
  12425. ThreadPoolJob::ThreadPoolJob (const String& name)
  12426. : jobName (name),
  12427. pool (0),
  12428. shouldStop (false),
  12429. isActive (false),
  12430. shouldBeDeleted (false)
  12431. {
  12432. }
  12433. ThreadPoolJob::~ThreadPoolJob()
  12434. {
  12435. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12436. // to remove it first!
  12437. jassert (pool == 0 || ! pool->contains (this));
  12438. }
  12439. const String ThreadPoolJob::getJobName() const
  12440. {
  12441. return jobName;
  12442. }
  12443. void ThreadPoolJob::setJobName (const String& newName)
  12444. {
  12445. jobName = newName;
  12446. }
  12447. void ThreadPoolJob::signalJobShouldExit()
  12448. {
  12449. shouldStop = true;
  12450. }
  12451. class ThreadPool::ThreadPoolThread : public Thread
  12452. {
  12453. public:
  12454. ThreadPoolThread (ThreadPool& pool_)
  12455. : Thread (T("Pool")),
  12456. pool (pool_),
  12457. busy (false)
  12458. {
  12459. }
  12460. ~ThreadPoolThread()
  12461. {
  12462. }
  12463. void run()
  12464. {
  12465. while (! threadShouldExit())
  12466. {
  12467. if (! pool.runNextJob())
  12468. wait (500);
  12469. }
  12470. }
  12471. private:
  12472. ThreadPool& pool;
  12473. bool volatile busy;
  12474. ThreadPoolThread (const ThreadPoolThread&);
  12475. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12476. };
  12477. ThreadPool::ThreadPool (const int numThreads,
  12478. const bool startThreadsOnlyWhenNeeded,
  12479. const int stopThreadsWhenNotUsedTimeoutMs)
  12480. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12481. priority (5)
  12482. {
  12483. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12484. for (int i = jmax (1, numThreads); --i >= 0;)
  12485. threads.add (new ThreadPoolThread (*this));
  12486. if (! startThreadsOnlyWhenNeeded)
  12487. for (int i = threads.size(); --i >= 0;)
  12488. threads.getUnchecked(i)->startThread (priority);
  12489. }
  12490. ThreadPool::~ThreadPool()
  12491. {
  12492. removeAllJobs (true, 4000);
  12493. int i;
  12494. for (i = threads.size(); --i >= 0;)
  12495. threads.getUnchecked(i)->signalThreadShouldExit();
  12496. for (i = threads.size(); --i >= 0;)
  12497. threads.getUnchecked(i)->stopThread (500);
  12498. }
  12499. void ThreadPool::addJob (ThreadPoolJob* const job)
  12500. {
  12501. jassert (job != 0);
  12502. jassert (job->pool == 0);
  12503. if (job->pool == 0)
  12504. {
  12505. job->pool = this;
  12506. job->shouldStop = false;
  12507. job->isActive = false;
  12508. {
  12509. const ScopedLock sl (lock);
  12510. jobs.add (job);
  12511. int numRunning = 0;
  12512. for (int i = threads.size(); --i >= 0;)
  12513. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12514. ++numRunning;
  12515. if (numRunning < threads.size())
  12516. {
  12517. bool startedOne = false;
  12518. int n = 1000;
  12519. while (--n >= 0 && ! startedOne)
  12520. {
  12521. for (int i = threads.size(); --i >= 0;)
  12522. {
  12523. if (! threads.getUnchecked(i)->isThreadRunning())
  12524. {
  12525. threads.getUnchecked(i)->startThread (priority);
  12526. startedOne = true;
  12527. break;
  12528. }
  12529. }
  12530. if (! startedOne)
  12531. Thread::sleep (2);
  12532. }
  12533. }
  12534. }
  12535. for (int i = threads.size(); --i >= 0;)
  12536. threads.getUnchecked(i)->notify();
  12537. }
  12538. }
  12539. int ThreadPool::getNumJobs() const
  12540. {
  12541. return jobs.size();
  12542. }
  12543. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12544. {
  12545. const ScopedLock sl (lock);
  12546. return (ThreadPoolJob*) jobs [index];
  12547. }
  12548. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12549. {
  12550. const ScopedLock sl (lock);
  12551. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12552. }
  12553. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12554. {
  12555. const ScopedLock sl (lock);
  12556. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12557. }
  12558. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12559. const int timeOutMs) const
  12560. {
  12561. if (job != 0)
  12562. {
  12563. const uint32 start = Time::getMillisecondCounter();
  12564. while (contains (job))
  12565. {
  12566. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12567. return false;
  12568. jobFinishedSignal.wait (2);
  12569. }
  12570. }
  12571. return true;
  12572. }
  12573. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12574. const bool interruptIfRunning,
  12575. const int timeOutMs)
  12576. {
  12577. bool dontWait = true;
  12578. if (job != 0)
  12579. {
  12580. const ScopedLock sl (lock);
  12581. if (jobs.contains (job))
  12582. {
  12583. if (job->isActive)
  12584. {
  12585. if (interruptIfRunning)
  12586. job->signalJobShouldExit();
  12587. dontWait = false;
  12588. }
  12589. else
  12590. {
  12591. jobs.removeValue (job);
  12592. }
  12593. }
  12594. }
  12595. return dontWait || waitForJobToFinish (job, timeOutMs);
  12596. }
  12597. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12598. const int timeOutMs,
  12599. const bool deleteInactiveJobs,
  12600. ThreadPool::JobSelector* selectedJobsToRemove)
  12601. {
  12602. Array <ThreadPoolJob*> jobsToWaitFor;
  12603. {
  12604. const ScopedLock sl (lock);
  12605. for (int i = jobs.size(); --i >= 0;)
  12606. {
  12607. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12608. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12609. {
  12610. if (job->isActive)
  12611. {
  12612. jobsToWaitFor.add (job);
  12613. if (interruptRunningJobs)
  12614. job->signalJobShouldExit();
  12615. }
  12616. else
  12617. {
  12618. jobs.remove (i);
  12619. if (deleteInactiveJobs)
  12620. delete job;
  12621. }
  12622. }
  12623. }
  12624. }
  12625. const uint32 start = Time::getMillisecondCounter();
  12626. for (;;)
  12627. {
  12628. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12629. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12630. jobsToWaitFor.remove (i);
  12631. if (jobsToWaitFor.size() == 0)
  12632. break;
  12633. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12634. return false;
  12635. jobFinishedSignal.wait (20);
  12636. }
  12637. return true;
  12638. }
  12639. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12640. {
  12641. StringArray s;
  12642. const ScopedLock sl (lock);
  12643. for (int i = 0; i < jobs.size(); ++i)
  12644. {
  12645. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12646. if (job->isActive || ! onlyReturnActiveJobs)
  12647. s.add (job->getJobName());
  12648. }
  12649. return s;
  12650. }
  12651. bool ThreadPool::setThreadPriorities (const int newPriority)
  12652. {
  12653. bool ok = true;
  12654. if (priority != newPriority)
  12655. {
  12656. priority = newPriority;
  12657. for (int i = threads.size(); --i >= 0;)
  12658. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12659. ok = false;
  12660. }
  12661. return ok;
  12662. }
  12663. bool ThreadPool::runNextJob()
  12664. {
  12665. ThreadPoolJob* job = 0;
  12666. {
  12667. const ScopedLock sl (lock);
  12668. for (int i = 0; i < jobs.size(); ++i)
  12669. {
  12670. job = jobs[i];
  12671. if (job != 0 && ! (job->isActive || job->shouldStop))
  12672. break;
  12673. job = 0;
  12674. }
  12675. if (job != 0)
  12676. job->isActive = true;
  12677. }
  12678. if (job != 0)
  12679. {
  12680. JUCE_TRY
  12681. {
  12682. ThreadPoolJob::JobStatus result = job->runJob();
  12683. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12684. const ScopedLock sl (lock);
  12685. if (jobs.contains (job))
  12686. {
  12687. job->isActive = false;
  12688. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12689. {
  12690. job->pool = 0;
  12691. job->shouldStop = true;
  12692. jobs.removeValue (job);
  12693. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12694. delete job;
  12695. jobFinishedSignal.signal();
  12696. }
  12697. else
  12698. {
  12699. // move the job to the end of the queue if it wants another go
  12700. jobs.move (jobs.indexOf (job), -1);
  12701. }
  12702. }
  12703. }
  12704. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12705. catch (...)
  12706. {
  12707. const ScopedLock sl (lock);
  12708. jobs.removeValue (job);
  12709. }
  12710. #endif
  12711. }
  12712. else
  12713. {
  12714. if (threadStopTimeout > 0
  12715. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12716. {
  12717. const ScopedLock sl (lock);
  12718. if (jobs.size() == 0)
  12719. for (int i = threads.size(); --i >= 0;)
  12720. threads.getUnchecked(i)->signalThreadShouldExit();
  12721. }
  12722. else
  12723. {
  12724. return false;
  12725. }
  12726. }
  12727. return true;
  12728. }
  12729. END_JUCE_NAMESPACE
  12730. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12731. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12732. BEGIN_JUCE_NAMESPACE
  12733. TimeSliceThread::TimeSliceThread (const String& threadName)
  12734. : Thread (threadName),
  12735. index (0),
  12736. clientBeingCalled (0),
  12737. clientsChanged (false)
  12738. {
  12739. }
  12740. TimeSliceThread::~TimeSliceThread()
  12741. {
  12742. stopThread (2000);
  12743. }
  12744. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12745. {
  12746. const ScopedLock sl (listLock);
  12747. clients.addIfNotAlreadyThere (client);
  12748. clientsChanged = true;
  12749. notify();
  12750. }
  12751. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12752. {
  12753. const ScopedLock sl1 (listLock);
  12754. clientsChanged = true;
  12755. // if there's a chance we're in the middle of calling this client, we need to
  12756. // also lock the outer lock..
  12757. if (clientBeingCalled == client)
  12758. {
  12759. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12760. const ScopedLock sl2 (callbackLock);
  12761. const ScopedLock sl3 (listLock);
  12762. clients.removeValue (client);
  12763. }
  12764. else
  12765. {
  12766. clients.removeValue (client);
  12767. }
  12768. }
  12769. int TimeSliceThread::getNumClients() const
  12770. {
  12771. return clients.size();
  12772. }
  12773. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12774. {
  12775. const ScopedLock sl (listLock);
  12776. return clients [i];
  12777. }
  12778. void TimeSliceThread::run()
  12779. {
  12780. int numCallsSinceBusy = 0;
  12781. while (! threadShouldExit())
  12782. {
  12783. int timeToWait = 500;
  12784. {
  12785. const ScopedLock sl (callbackLock);
  12786. {
  12787. const ScopedLock sl2 (listLock);
  12788. if (clients.size() > 0)
  12789. {
  12790. index = (index + 1) % clients.size();
  12791. clientBeingCalled = clients [index];
  12792. }
  12793. else
  12794. {
  12795. index = 0;
  12796. clientBeingCalled = 0;
  12797. }
  12798. if (clientsChanged)
  12799. {
  12800. clientsChanged = false;
  12801. numCallsSinceBusy = 0;
  12802. }
  12803. }
  12804. if (clientBeingCalled != 0)
  12805. {
  12806. if (clientBeingCalled->useTimeSlice())
  12807. numCallsSinceBusy = 0;
  12808. else
  12809. ++numCallsSinceBusy;
  12810. if (numCallsSinceBusy >= clients.size())
  12811. timeToWait = 500;
  12812. else if (index == 0)
  12813. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12814. else
  12815. timeToWait = 0;
  12816. }
  12817. }
  12818. if (timeToWait > 0)
  12819. wait (timeToWait);
  12820. }
  12821. }
  12822. END_JUCE_NAMESPACE
  12823. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12824. #endif
  12825. #if JUCE_BUILD_MISC
  12826. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12827. BEGIN_JUCE_NAMESPACE
  12828. class ValueTreeSetPropertyAction : public UndoableAction
  12829. {
  12830. public:
  12831. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12832. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12833. : target (target_), name (name_), newValue (newValue_),
  12834. isAddingNewProperty (isAddingNewProperty_),
  12835. isDeletingProperty (isDeletingProperty_)
  12836. {
  12837. if (! isAddingNewProperty)
  12838. oldValue = target_->getProperty (name_);
  12839. }
  12840. ~ValueTreeSetPropertyAction() {}
  12841. bool perform()
  12842. {
  12843. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12844. if (isDeletingProperty)
  12845. target->removeProperty (name, 0);
  12846. else
  12847. target->setProperty (name, newValue, 0);
  12848. return true;
  12849. }
  12850. bool undo()
  12851. {
  12852. if (isAddingNewProperty)
  12853. target->removeProperty (name, 0);
  12854. else
  12855. target->setProperty (name, oldValue, 0);
  12856. return true;
  12857. }
  12858. int getSizeInUnits()
  12859. {
  12860. return (int) sizeof (*this); //xxx should be more accurate
  12861. }
  12862. private:
  12863. const ValueTree::SharedObjectPtr target;
  12864. const var::identifier name;
  12865. const var newValue;
  12866. var oldValue;
  12867. const bool isAddingNewProperty, isDeletingProperty;
  12868. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12869. ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12870. };
  12871. class ValueTreeChildChangeAction : public UndoableAction
  12872. {
  12873. public:
  12874. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12875. const ValueTree::SharedObjectPtr& newChild_)
  12876. : target (target_),
  12877. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12878. childIndex (childIndex_),
  12879. isDeleting (newChild_ == 0)
  12880. {
  12881. jassert (child != 0);
  12882. }
  12883. ~ValueTreeChildChangeAction() {}
  12884. bool perform()
  12885. {
  12886. if (isDeleting)
  12887. target->removeChild (childIndex, 0);
  12888. else
  12889. target->addChild (child, childIndex, 0);
  12890. return true;
  12891. }
  12892. bool undo()
  12893. {
  12894. if (isDeleting)
  12895. target->addChild (child, childIndex, 0);
  12896. else
  12897. target->removeChild (childIndex, 0);
  12898. return true;
  12899. }
  12900. int getSizeInUnits()
  12901. {
  12902. return (int) sizeof (*this); //xxx should be more accurate
  12903. }
  12904. private:
  12905. const ValueTree::SharedObjectPtr target, child;
  12906. const int childIndex;
  12907. const bool isDeleting;
  12908. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12909. ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12910. };
  12911. ValueTree::SharedObject::SharedObject (const String& type_)
  12912. : type (type_), parent (0)
  12913. {
  12914. }
  12915. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12916. : type (other.type), properties (other.properties), parent (0)
  12917. {
  12918. for (int i = 0; i < other.children.size(); ++i)
  12919. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12920. }
  12921. ValueTree::SharedObject::~SharedObject()
  12922. {
  12923. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12924. for (int i = children.size(); --i >= 0;)
  12925. {
  12926. const SharedObjectPtr c (children.getUnchecked(i));
  12927. c->parent = 0;
  12928. children.remove (i);
  12929. c->sendParentChangeMessage();
  12930. }
  12931. }
  12932. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12933. {
  12934. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12935. {
  12936. ValueTree* const v = valueTreesWithListeners[i];
  12937. if (v != 0)
  12938. v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property);
  12939. }
  12940. }
  12941. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12942. {
  12943. ValueTree tree (this);
  12944. ValueTree::SharedObject* t = this;
  12945. while (t != 0)
  12946. {
  12947. t->sendPropertyChangeMessage (tree, property);
  12948. t = t->parent;
  12949. }
  12950. }
  12951. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  12952. {
  12953. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12954. {
  12955. ValueTree* const v = valueTreesWithListeners[i];
  12956. if (v != 0)
  12957. v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree);
  12958. }
  12959. }
  12960. void ValueTree::SharedObject::sendChildChangeMessage()
  12961. {
  12962. ValueTree tree (this);
  12963. ValueTree::SharedObject* t = this;
  12964. while (t != 0)
  12965. {
  12966. t->sendChildChangeMessage (tree);
  12967. t = t->parent;
  12968. }
  12969. }
  12970. void ValueTree::SharedObject::sendParentChangeMessage()
  12971. {
  12972. ValueTree tree (this);
  12973. int i;
  12974. for (i = children.size(); --i >= 0;)
  12975. {
  12976. SharedObject* const t = children[i];
  12977. if (t != 0)
  12978. t->sendParentChangeMessage();
  12979. }
  12980. for (i = valueTreesWithListeners.size(); --i >= 0;)
  12981. {
  12982. ValueTree* const v = valueTreesWithListeners[i];
  12983. if (v != 0)
  12984. v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree);
  12985. }
  12986. }
  12987. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  12988. {
  12989. return properties [name];
  12990. }
  12991. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12992. {
  12993. if (undoManager == 0)
  12994. {
  12995. if (properties.set (name, newValue))
  12996. sendPropertyChangeMessage (name);
  12997. }
  12998. else
  12999. {
  13000. var* const existingValue = properties.getItem (name);
  13001. if (existingValue != 0)
  13002. {
  13003. if (*existingValue != newValue)
  13004. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  13005. }
  13006. else
  13007. {
  13008. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  13009. }
  13010. }
  13011. }
  13012. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  13013. {
  13014. return properties.contains (name);
  13015. }
  13016. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13017. {
  13018. if (undoManager == 0)
  13019. {
  13020. if (properties.remove (name))
  13021. sendPropertyChangeMessage (name);
  13022. }
  13023. else
  13024. {
  13025. if (properties.contains (name))
  13026. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  13027. }
  13028. }
  13029. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  13030. {
  13031. if (undoManager == 0)
  13032. {
  13033. while (properties.size() > 0)
  13034. {
  13035. const var::identifier name (properties.getName (properties.size() - 1));
  13036. properties.remove (name);
  13037. sendPropertyChangeMessage (name);
  13038. }
  13039. }
  13040. else
  13041. {
  13042. for (int i = properties.size(); --i >= 0;)
  13043. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  13044. }
  13045. }
  13046. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  13047. {
  13048. for (int i = 0; i < children.size(); ++i)
  13049. if (children.getUnchecked(i)->type == typeToMatch)
  13050. return (SharedObject*) children.getUnchecked(i);
  13051. return (SharedObject*) 0;
  13052. }
  13053. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13054. {
  13055. for (int i = 0; i < children.size(); ++i)
  13056. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  13057. return (SharedObject*) children.getUnchecked(i);
  13058. return (SharedObject*) 0;
  13059. }
  13060. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  13061. {
  13062. const SharedObject* p = parent;
  13063. while (p != 0)
  13064. {
  13065. if (p == possibleParent)
  13066. return true;
  13067. p = p->parent;
  13068. }
  13069. return false;
  13070. }
  13071. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  13072. {
  13073. if (child != 0 && child->parent != this)
  13074. {
  13075. if (child != this && ! isAChildOf (child))
  13076. {
  13077. // You should always make sure that a child is removed from its previous parent before
  13078. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  13079. // undomanager should be used when removing it from its current parent..
  13080. jassert (child->parent == 0);
  13081. if (child->parent != 0)
  13082. {
  13083. jassert (child->parent->children.indexOf (child) >= 0);
  13084. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  13085. }
  13086. if (undoManager == 0)
  13087. {
  13088. children.insert (index, child);
  13089. child->parent = this;
  13090. sendChildChangeMessage();
  13091. child->sendParentChangeMessage();
  13092. }
  13093. else
  13094. {
  13095. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  13096. }
  13097. }
  13098. else
  13099. {
  13100. // You're attempting to create a recursive loop! A node
  13101. // can't be a child of one of its own children!
  13102. jassertfalse
  13103. }
  13104. }
  13105. }
  13106. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  13107. {
  13108. const SharedObjectPtr child (children [childIndex]);
  13109. if (child != 0)
  13110. {
  13111. if (undoManager == 0)
  13112. {
  13113. children.remove (childIndex);
  13114. child->parent = 0;
  13115. sendChildChangeMessage();
  13116. child->sendParentChangeMessage();
  13117. }
  13118. else
  13119. {
  13120. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  13121. }
  13122. }
  13123. }
  13124. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  13125. {
  13126. while (children.size() > 0)
  13127. removeChild (children.size() - 1, undoManager);
  13128. }
  13129. ValueTree::ValueTree (const String& type_)
  13130. : object (new ValueTree::SharedObject (type_))
  13131. {
  13132. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  13133. }
  13134. ValueTree::ValueTree (SharedObject* const object_)
  13135. : object (object_)
  13136. {
  13137. }
  13138. ValueTree::ValueTree (const ValueTree& other)
  13139. : object (other.object)
  13140. {
  13141. }
  13142. ValueTree& ValueTree::operator= (const ValueTree& other)
  13143. {
  13144. if (listeners.size() > 0)
  13145. {
  13146. if (object != 0)
  13147. object->valueTreesWithListeners.removeValue (this);
  13148. if (other.object != 0)
  13149. other.object->valueTreesWithListeners.add (this);
  13150. }
  13151. object = other.object;
  13152. return *this;
  13153. }
  13154. ValueTree::~ValueTree()
  13155. {
  13156. if (listeners.size() > 0 && object != 0)
  13157. object->valueTreesWithListeners.removeValue (this);
  13158. }
  13159. bool ValueTree::operator== (const ValueTree& other) const
  13160. {
  13161. return object == other.object;
  13162. }
  13163. bool ValueTree::operator!= (const ValueTree& other) const
  13164. {
  13165. return object != other.object;
  13166. }
  13167. ValueTree ValueTree::createCopy() const
  13168. {
  13169. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13170. }
  13171. bool ValueTree::hasType (const String& typeName) const
  13172. {
  13173. return object != 0 && object->type == typeName;
  13174. }
  13175. const String ValueTree::getType() const
  13176. {
  13177. return object != 0 ? object->type : String::empty;
  13178. }
  13179. ValueTree ValueTree::getParent() const
  13180. {
  13181. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13182. }
  13183. const var& ValueTree::operator[] (const var::identifier& name) const
  13184. {
  13185. return object == 0 ? var::null : object->getProperty (name);
  13186. }
  13187. const var& ValueTree::getProperty (const var::identifier& name) const
  13188. {
  13189. return object == 0 ? var::null : object->getProperty (name);
  13190. }
  13191. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13192. {
  13193. jassert (name.name.isNotEmpty());
  13194. if (object != 0 && name.name.isNotEmpty())
  13195. object->setProperty (name, newValue, undoManager);
  13196. }
  13197. bool ValueTree::hasProperty (const var::identifier& name) const
  13198. {
  13199. return object != 0 && object->hasProperty (name);
  13200. }
  13201. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13202. {
  13203. if (object != 0)
  13204. object->removeProperty (name, undoManager);
  13205. }
  13206. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13207. {
  13208. if (object != 0)
  13209. object->removeAllProperties (undoManager);
  13210. }
  13211. int ValueTree::getNumProperties() const
  13212. {
  13213. return object == 0 ? 0 : object->properties.size();
  13214. }
  13215. const var::identifier ValueTree::getPropertyName (int index) const
  13216. {
  13217. return (object == 0) ? var::identifier()
  13218. : object->properties.getName (index);
  13219. }
  13220. class ValueTreePropertyValueSource : public Value::ValueSource,
  13221. public ValueTree::Listener
  13222. {
  13223. public:
  13224. ValueTreePropertyValueSource (const ValueTree& tree_,
  13225. const var::identifier& property_,
  13226. UndoManager* const undoManager_)
  13227. : tree (tree_),
  13228. property (property_),
  13229. undoManager (undoManager_)
  13230. {
  13231. tree.addListener (this);
  13232. }
  13233. ~ValueTreePropertyValueSource()
  13234. {
  13235. tree.removeListener (this);
  13236. }
  13237. const var getValue() const
  13238. {
  13239. return tree [property];
  13240. }
  13241. void setValue (const var& newValue)
  13242. {
  13243. tree.setProperty (property, newValue, undoManager);
  13244. }
  13245. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13246. {
  13247. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13248. sendChangeMessage (false);
  13249. }
  13250. void valueTreeChildrenChanged (ValueTree&) {}
  13251. void valueTreeParentChanged (ValueTree&) {}
  13252. private:
  13253. ValueTree tree;
  13254. const var::identifier property;
  13255. UndoManager* const undoManager;
  13256. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13257. };
  13258. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13259. {
  13260. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13261. }
  13262. int ValueTree::getNumChildren() const
  13263. {
  13264. return object == 0 ? 0 : object->children.size();
  13265. }
  13266. ValueTree ValueTree::getChild (int index) const
  13267. {
  13268. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13269. }
  13270. ValueTree ValueTree::getChildWithName (const String& type) const
  13271. {
  13272. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13273. }
  13274. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13275. {
  13276. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13277. }
  13278. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13279. {
  13280. return object != 0 && object->isAChildOf (possibleParent.object);
  13281. }
  13282. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13283. {
  13284. if (object != 0)
  13285. object->addChild (child.object, index, undoManager);
  13286. }
  13287. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13288. {
  13289. if (object != 0)
  13290. object->removeChild (childIndex, undoManager);
  13291. }
  13292. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13293. {
  13294. if (object != 0)
  13295. object->removeChild (object->children.indexOf (child.object), undoManager);
  13296. }
  13297. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13298. {
  13299. if (object != 0)
  13300. object->removeAllChildren (undoManager);
  13301. }
  13302. void ValueTree::addListener (Listener* listener)
  13303. {
  13304. if (listener != 0)
  13305. {
  13306. if (listeners.size() == 0 && object != 0)
  13307. object->valueTreesWithListeners.add (this);
  13308. listeners.add (listener);
  13309. }
  13310. }
  13311. void ValueTree::removeListener (Listener* listener)
  13312. {
  13313. listeners.remove (listener);
  13314. if (listeners.size() == 0 && object != 0)
  13315. object->valueTreesWithListeners.removeValue (this);
  13316. }
  13317. XmlElement* ValueTree::SharedObject::createXml() const
  13318. {
  13319. XmlElement* xml = new XmlElement (type);
  13320. int i;
  13321. for (i = 0; i < properties.size(); ++i)
  13322. {
  13323. var::identifier name (properties.getName(i));
  13324. const var& v = properties [name];
  13325. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13326. xml->setAttribute (name.name, v.toString());
  13327. }
  13328. for (i = 0; i < children.size(); ++i)
  13329. xml->addChildElement (children.getUnchecked(i)->createXml());
  13330. return xml;
  13331. }
  13332. XmlElement* ValueTree::createXml() const
  13333. {
  13334. return object != 0 ? object->createXml() : 0;
  13335. }
  13336. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13337. {
  13338. ValueTree v (xml.getTagName());
  13339. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13340. for (int i = 0; i < numAtts; ++i)
  13341. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13342. forEachXmlChildElement (xml, e)
  13343. {
  13344. v.addChild (fromXml (*e), -1, 0);
  13345. }
  13346. return v;
  13347. }
  13348. void ValueTree::writeToStream (OutputStream& output)
  13349. {
  13350. output.writeString (getType());
  13351. const int numProps = getNumProperties();
  13352. output.writeCompressedInt (numProps);
  13353. int i;
  13354. for (i = 0; i < numProps; ++i)
  13355. {
  13356. const var::identifier name (getPropertyName(i));
  13357. output.writeString (name.name);
  13358. getProperty(name).writeToStream (output);
  13359. }
  13360. const int numChildren = getNumChildren();
  13361. output.writeCompressedInt (numChildren);
  13362. for (i = 0; i < numChildren; ++i)
  13363. getChild (i).writeToStream (output);
  13364. }
  13365. ValueTree ValueTree::readFromStream (InputStream& input)
  13366. {
  13367. String type (input.readString());
  13368. if (type.isEmpty())
  13369. return ValueTree ((SharedObject*) 0);
  13370. ValueTree v (type);
  13371. const int numProps = input.readCompressedInt();
  13372. if (numProps < 0)
  13373. {
  13374. jassertfalse // trying to read corrupted data!
  13375. return v;
  13376. }
  13377. int i;
  13378. for (i = 0; i < numProps; ++i)
  13379. {
  13380. const String name (input.readString());
  13381. jassert (name.isNotEmpty());
  13382. const var value (var::readFromStream (input));
  13383. v.setProperty (name, value, 0);
  13384. }
  13385. const int numChildren = input.readCompressedInt();
  13386. for (i = 0; i < numChildren; ++i)
  13387. v.addChild (readFromStream (input), -1, 0);
  13388. return v;
  13389. }
  13390. END_JUCE_NAMESPACE
  13391. /*** End of inlined file: juce_ValueTree.cpp ***/
  13392. /*** Start of inlined file: juce_Value.cpp ***/
  13393. BEGIN_JUCE_NAMESPACE
  13394. Value::ValueSource::ValueSource()
  13395. {
  13396. }
  13397. Value::ValueSource::~ValueSource()
  13398. {
  13399. }
  13400. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13401. {
  13402. if (synchronous)
  13403. {
  13404. for (int i = valuesWithListeners.size(); --i >= 0;)
  13405. {
  13406. Value* const v = valuesWithListeners[i];
  13407. if (v != 0)
  13408. v->callListeners();
  13409. }
  13410. }
  13411. else
  13412. {
  13413. triggerAsyncUpdate();
  13414. }
  13415. }
  13416. void Value::ValueSource::handleAsyncUpdate()
  13417. {
  13418. sendChangeMessage (true);
  13419. }
  13420. class SimpleValueSource : public Value::ValueSource
  13421. {
  13422. public:
  13423. SimpleValueSource()
  13424. {
  13425. }
  13426. SimpleValueSource (const var& initialValue)
  13427. : value (initialValue)
  13428. {
  13429. }
  13430. ~SimpleValueSource()
  13431. {
  13432. }
  13433. const var getValue() const
  13434. {
  13435. return value;
  13436. }
  13437. void setValue (const var& newValue)
  13438. {
  13439. if (newValue != value)
  13440. {
  13441. value = newValue;
  13442. sendChangeMessage (false);
  13443. }
  13444. }
  13445. private:
  13446. var value;
  13447. SimpleValueSource (const SimpleValueSource&);
  13448. SimpleValueSource& operator= (const SimpleValueSource&);
  13449. };
  13450. Value::Value()
  13451. : value (new SimpleValueSource())
  13452. {
  13453. }
  13454. Value::Value (ValueSource* const value_)
  13455. : value (value_)
  13456. {
  13457. jassert (value_ != 0);
  13458. }
  13459. Value::Value (const var& initialValue)
  13460. : value (new SimpleValueSource (initialValue))
  13461. {
  13462. }
  13463. Value::Value (const Value& other)
  13464. : value (other.value)
  13465. {
  13466. }
  13467. Value& Value::operator= (const Value& other)
  13468. {
  13469. value = other.value;
  13470. return *this;
  13471. }
  13472. Value::~Value()
  13473. {
  13474. if (listeners.size() > 0)
  13475. value->valuesWithListeners.removeValue (this);
  13476. }
  13477. const var Value::getValue() const
  13478. {
  13479. return value->getValue();
  13480. }
  13481. void Value::setValue (const var& newValue)
  13482. {
  13483. value->setValue (newValue);
  13484. }
  13485. const String Value::toString() const
  13486. {
  13487. return value->getValue().toString();
  13488. }
  13489. Value& Value::operator= (const var& newValue)
  13490. {
  13491. value->setValue (newValue);
  13492. return *this;
  13493. }
  13494. void Value::referTo (const Value& valueToReferTo)
  13495. {
  13496. if (valueToReferTo.value != value)
  13497. {
  13498. if (listeners.size() > 0)
  13499. {
  13500. value->valuesWithListeners.removeValue (this);
  13501. valueToReferTo.value->valuesWithListeners.add (this);
  13502. }
  13503. value = valueToReferTo.value;
  13504. callListeners();
  13505. }
  13506. }
  13507. bool Value::refersToSameSourceAs (const Value& other) const
  13508. {
  13509. return value == other.value;
  13510. }
  13511. bool Value::operator== (const Value& other) const
  13512. {
  13513. return value == other.value || value->getValue() == other.getValue();
  13514. }
  13515. bool Value::operator!= (const Value& other) const
  13516. {
  13517. return value != other.value && value->getValue() != other.getValue();
  13518. }
  13519. void Value::addListener (Listener* const listener)
  13520. {
  13521. if (listener != 0)
  13522. {
  13523. if (listeners.size() == 0)
  13524. value->valuesWithListeners.add (this);
  13525. listeners.add (listener);
  13526. }
  13527. }
  13528. void Value::removeListener (Listener* const listener)
  13529. {
  13530. listeners.remove (listener);
  13531. if (listeners.size() == 0)
  13532. value->valuesWithListeners.removeValue (this);
  13533. }
  13534. void Value::callListeners()
  13535. {
  13536. Value v (*this); // (create a copy in case this gets deleted by a callback)
  13537. listeners.call (&Listener::valueChanged, v);
  13538. }
  13539. END_JUCE_NAMESPACE
  13540. /*** End of inlined file: juce_Value.cpp ***/
  13541. /*** Start of inlined file: juce_Application.cpp ***/
  13542. #if JUCE_MSVC
  13543. #pragma warning (push)
  13544. #pragma warning (disable: 4245 4514 4100)
  13545. #include <crtdbg.h>
  13546. #pragma warning (pop)
  13547. #endif
  13548. BEGIN_JUCE_NAMESPACE
  13549. void juce_setCurrentThreadName (const String& name);
  13550. static JUCEApplication* appInstance = 0;
  13551. JUCEApplication::JUCEApplication()
  13552. : appReturnValue (0),
  13553. stillInitialising (true)
  13554. {
  13555. }
  13556. JUCEApplication::~JUCEApplication()
  13557. {
  13558. if (appLock != 0)
  13559. {
  13560. appLock->exit();
  13561. appLock = 0;
  13562. }
  13563. }
  13564. JUCEApplication* JUCEApplication::getInstance() throw()
  13565. {
  13566. return appInstance;
  13567. }
  13568. bool JUCEApplication::isInitialising() const throw()
  13569. {
  13570. return stillInitialising;
  13571. }
  13572. const String JUCEApplication::getApplicationVersion()
  13573. {
  13574. return String::empty;
  13575. }
  13576. bool JUCEApplication::moreThanOneInstanceAllowed()
  13577. {
  13578. return true;
  13579. }
  13580. void JUCEApplication::anotherInstanceStarted (const String&)
  13581. {
  13582. }
  13583. void JUCEApplication::systemRequestedQuit()
  13584. {
  13585. quit();
  13586. }
  13587. void JUCEApplication::quit()
  13588. {
  13589. MessageManager::getInstance()->stopDispatchLoop();
  13590. }
  13591. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13592. {
  13593. appReturnValue = newReturnValue;
  13594. }
  13595. void JUCEApplication::unhandledException (const std::exception*,
  13596. const String&,
  13597. const int)
  13598. {
  13599. jassertfalse
  13600. }
  13601. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13602. const char* const sourceFile,
  13603. const int lineNumber)
  13604. {
  13605. if (appInstance != 0)
  13606. appInstance->unhandledException (e, sourceFile, lineNumber);
  13607. }
  13608. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13609. {
  13610. return 0;
  13611. }
  13612. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13613. {
  13614. commands.add (StandardApplicationCommandIDs::quit);
  13615. }
  13616. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13617. {
  13618. if (commandID == StandardApplicationCommandIDs::quit)
  13619. {
  13620. result.setInfo (TRANS("Quit"),
  13621. TRANS("Quits the application"),
  13622. "Application",
  13623. 0);
  13624. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13625. }
  13626. }
  13627. bool JUCEApplication::perform (const InvocationInfo& info)
  13628. {
  13629. if (info.commandID == StandardApplicationCommandIDs::quit)
  13630. {
  13631. systemRequestedQuit();
  13632. return true;
  13633. }
  13634. return false;
  13635. }
  13636. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13637. {
  13638. if (! app->initialiseApp (commandLine))
  13639. return 0;
  13640. // now loop until a quit message is received..
  13641. JUCE_TRY
  13642. {
  13643. MessageManager::getInstance()->runDispatchLoop();
  13644. }
  13645. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13646. catch (const std::exception& e)
  13647. {
  13648. app->unhandledException (&e, __FILE__, __LINE__);
  13649. }
  13650. catch (...)
  13651. {
  13652. app->unhandledException (0, __FILE__, __LINE__);
  13653. }
  13654. #endif
  13655. return shutdownAppAndClearUp();
  13656. }
  13657. bool JUCEApplication::initialiseApp (String& commandLine)
  13658. {
  13659. jassert (appInstance == 0);
  13660. appInstance = this;
  13661. commandLineParameters = commandLine.trim();
  13662. commandLine = String::empty;
  13663. initialiseJuce_GUI();
  13664. #if ! JUCE_IPHONE
  13665. jassert (appLock == 0); // initialiseApp must only be called once!
  13666. if (! moreThanOneInstanceAllowed())
  13667. {
  13668. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13669. if (! appLock->enter(0))
  13670. {
  13671. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13672. delete appInstance;
  13673. appInstance = 0;
  13674. DBG ("Another instance is running - quitting...");
  13675. return false;
  13676. }
  13677. }
  13678. #endif
  13679. // let the app do its setting-up..
  13680. initialise (commandLineParameters);
  13681. // register for broadcast new app messages
  13682. MessageManager::getInstance()->registerBroadcastListener (this);
  13683. stillInitialising = false;
  13684. return true;
  13685. }
  13686. int JUCEApplication::shutdownAppAndClearUp()
  13687. {
  13688. jassert (appInstance != 0);
  13689. ScopedPointer<JUCEApplication> app (appInstance);
  13690. int returnValue = 0;
  13691. MessageManager::getInstance()->deregisterBroadcastListener ((JUCEApplication*) app);
  13692. static bool reentrancyCheck = false;
  13693. if (! reentrancyCheck)
  13694. {
  13695. reentrancyCheck = true;
  13696. JUCE_TRY
  13697. {
  13698. // give the app a chance to clean up..
  13699. app->shutdown();
  13700. }
  13701. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13702. catch (const std::exception& e)
  13703. {
  13704. app->unhandledException (&e, __FILE__, __LINE__);
  13705. }
  13706. catch (...)
  13707. {
  13708. app->unhandledException (0, __FILE__, __LINE__);
  13709. }
  13710. #endif
  13711. JUCE_TRY
  13712. {
  13713. shutdownJuce_GUI();
  13714. returnValue = app->getApplicationReturnValue();
  13715. appInstance = 0;
  13716. app = 0;
  13717. }
  13718. JUCE_CATCH_ALL_ASSERT
  13719. reentrancyCheck = false;
  13720. }
  13721. return returnValue;
  13722. }
  13723. #if JUCE_IPHONE
  13724. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13725. #endif
  13726. #if ! JUCE_WINDOWS
  13727. extern const char* juce_Argv0;
  13728. #endif
  13729. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13730. {
  13731. #if ! JUCE_WINDOWS
  13732. juce_Argv0 = argv[0];
  13733. #endif
  13734. #if JUCE_IPHONE
  13735. const ScopedAutoReleasePool pool;
  13736. return juce_IPhoneMain (argc, argv, newApp);
  13737. #else
  13738. #if JUCE_MAC
  13739. const ScopedAutoReleasePool pool;
  13740. #endif
  13741. String cmd;
  13742. for (int i = 1; i < argc; ++i)
  13743. cmd << argv[i] << ' ';
  13744. return JUCEApplication::main (cmd, newApp);
  13745. #endif
  13746. }
  13747. void JUCEApplication::actionListenerCallback (const String& message)
  13748. {
  13749. if (message.startsWith (getApplicationName() + "/"))
  13750. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13751. }
  13752. static bool juceInitialisedGUI = false;
  13753. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13754. {
  13755. if (! juceInitialisedGUI)
  13756. {
  13757. #if JUCE_MAC || JUCE_IPHONE
  13758. const ScopedAutoReleasePool pool;
  13759. #endif
  13760. juceInitialisedGUI = true;
  13761. initialiseJuce_NonGUI();
  13762. MessageManager::getInstance();
  13763. LookAndFeel::setDefaultLookAndFeel (0);
  13764. juce_setCurrentThreadName ("Juce Message Thread");
  13765. #if JUCE_WINDOWS && JUCE_DEBUG
  13766. // This section is just for catching people who mess up their project settings and
  13767. // turn RTTI off..
  13768. try
  13769. {
  13770. TextButton tb (String::empty);
  13771. Component* c = &tb;
  13772. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13773. c = dynamic_cast <Button*> (c);
  13774. }
  13775. catch (...)
  13776. {
  13777. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13778. // got as far as this catch statement, then why haven't you got exception catching
  13779. // turned on in the debugger???
  13780. jassertfalse
  13781. }
  13782. #endif
  13783. }
  13784. }
  13785. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13786. {
  13787. if (juceInitialisedGUI)
  13788. {
  13789. #if JUCE_MAC
  13790. const ScopedAutoReleasePool pool;
  13791. #endif
  13792. {
  13793. DeletedAtShutdown::deleteAll();
  13794. LookAndFeel::clearDefaultLookAndFeel();
  13795. }
  13796. delete MessageManager::getInstance();
  13797. shutdownJuce_NonGUI();
  13798. juceInitialisedGUI = false;
  13799. }
  13800. }
  13801. END_JUCE_NAMESPACE
  13802. /*** End of inlined file: juce_Application.cpp ***/
  13803. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13804. BEGIN_JUCE_NAMESPACE
  13805. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13806. : commandID (commandID_),
  13807. flags (0)
  13808. {
  13809. }
  13810. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13811. const String& description_,
  13812. const String& categoryName_,
  13813. const int flags_) throw()
  13814. {
  13815. shortName = shortName_;
  13816. description = description_;
  13817. categoryName = categoryName_;
  13818. flags = flags_;
  13819. }
  13820. void ApplicationCommandInfo::setActive (const bool b) throw()
  13821. {
  13822. if (b)
  13823. flags &= ~isDisabled;
  13824. else
  13825. flags |= isDisabled;
  13826. }
  13827. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13828. {
  13829. if (b)
  13830. flags |= isTicked;
  13831. else
  13832. flags &= ~isTicked;
  13833. }
  13834. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13835. {
  13836. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13837. }
  13838. END_JUCE_NAMESPACE
  13839. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13840. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13841. BEGIN_JUCE_NAMESPACE
  13842. ApplicationCommandManager::ApplicationCommandManager()
  13843. : firstTarget (0)
  13844. {
  13845. keyMappings = new KeyPressMappingSet (this);
  13846. Desktop::getInstance().addFocusChangeListener (this);
  13847. }
  13848. ApplicationCommandManager::~ApplicationCommandManager()
  13849. {
  13850. Desktop::getInstance().removeFocusChangeListener (this);
  13851. keyMappings = 0;
  13852. }
  13853. void ApplicationCommandManager::clearCommands()
  13854. {
  13855. commands.clear();
  13856. keyMappings->clearAllKeyPresses();
  13857. triggerAsyncUpdate();
  13858. }
  13859. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13860. {
  13861. // zero isn't a valid command ID!
  13862. jassert (newCommand.commandID != 0);
  13863. // the name isn't optional!
  13864. jassert (newCommand.shortName.isNotEmpty());
  13865. if (getCommandForID (newCommand.commandID) == 0)
  13866. {
  13867. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13868. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13869. commands.add (newInfo);
  13870. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13871. triggerAsyncUpdate();
  13872. }
  13873. else
  13874. {
  13875. // trying to re-register the same command with different parameters?
  13876. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13877. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13878. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13879. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13880. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13881. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13882. }
  13883. }
  13884. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13885. {
  13886. if (target != 0)
  13887. {
  13888. Array <CommandID> commandIDs;
  13889. target->getAllCommands (commandIDs);
  13890. for (int i = 0; i < commandIDs.size(); ++i)
  13891. {
  13892. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13893. target->getCommandInfo (info.commandID, info);
  13894. registerCommand (info);
  13895. }
  13896. }
  13897. }
  13898. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13899. {
  13900. for (int i = commands.size(); --i >= 0;)
  13901. {
  13902. if (commands.getUnchecked (i)->commandID == commandID)
  13903. {
  13904. commands.remove (i);
  13905. triggerAsyncUpdate();
  13906. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  13907. for (int j = keys.size(); --j >= 0;)
  13908. keyMappings->removeKeyPress (keys.getReference (j));
  13909. }
  13910. }
  13911. }
  13912. void ApplicationCommandManager::commandStatusChanged()
  13913. {
  13914. triggerAsyncUpdate();
  13915. }
  13916. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  13917. {
  13918. for (int i = commands.size(); --i >= 0;)
  13919. if (commands.getUnchecked(i)->commandID == commandID)
  13920. return commands.getUnchecked(i);
  13921. return 0;
  13922. }
  13923. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  13924. {
  13925. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13926. return (ci != 0) ? ci->shortName : String::empty;
  13927. }
  13928. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  13929. {
  13930. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13931. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  13932. : String::empty;
  13933. }
  13934. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  13935. {
  13936. StringArray s;
  13937. for (int i = 0; i < commands.size(); ++i)
  13938. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  13939. return s;
  13940. }
  13941. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  13942. {
  13943. Array <CommandID> results;
  13944. for (int i = 0; i < commands.size(); ++i)
  13945. if (commands.getUnchecked(i)->categoryName == categoryName)
  13946. results.add (commands.getUnchecked(i)->commandID);
  13947. return results;
  13948. }
  13949. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13950. {
  13951. ApplicationCommandTarget::InvocationInfo info (commandID);
  13952. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13953. return invoke (info, asynchronously);
  13954. }
  13955. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  13956. {
  13957. // This call isn't thread-safe for use from a non-UI thread without locking the message
  13958. // manager first..
  13959. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  13960. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  13961. if (target == 0)
  13962. return false;
  13963. ApplicationCommandInfo commandInfo (0);
  13964. target->getCommandInfo (info_.commandID, commandInfo);
  13965. ApplicationCommandTarget::InvocationInfo info (info_);
  13966. info.commandFlags = commandInfo.flags;
  13967. sendListenerInvokeCallback (info);
  13968. const bool ok = target->invoke (info, asynchronously);
  13969. commandStatusChanged();
  13970. return ok;
  13971. }
  13972. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  13973. {
  13974. return firstTarget != 0 ? firstTarget
  13975. : findDefaultComponentTarget();
  13976. }
  13977. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  13978. {
  13979. firstTarget = newTarget;
  13980. }
  13981. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  13982. ApplicationCommandInfo& upToDateInfo)
  13983. {
  13984. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  13985. if (target == 0)
  13986. target = JUCEApplication::getInstance();
  13987. if (target != 0)
  13988. target = target->getTargetForCommand (commandID);
  13989. if (target != 0)
  13990. target->getCommandInfo (commandID, upToDateInfo);
  13991. return target;
  13992. }
  13993. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  13994. {
  13995. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  13996. if (target == 0 && c != 0)
  13997. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13998. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13999. return target;
  14000. }
  14001. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  14002. {
  14003. Component* c = Component::getCurrentlyFocusedComponent();
  14004. if (c == 0)
  14005. {
  14006. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  14007. if (activeWindow != 0)
  14008. {
  14009. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  14010. if (c == 0)
  14011. c = activeWindow;
  14012. }
  14013. }
  14014. if (c == 0 && Process::isForegroundProcess())
  14015. {
  14016. // getting a bit desperate now - try all desktop comps..
  14017. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  14018. {
  14019. ApplicationCommandTarget* const target
  14020. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  14021. ->getPeer()->getLastFocusedSubcomponent());
  14022. if (target != 0)
  14023. return target;
  14024. }
  14025. }
  14026. if (c != 0)
  14027. {
  14028. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  14029. // if we're focused on a ResizableWindow, chances are that it's the content
  14030. // component that really should get the event. And if not, the event will
  14031. // still be passed up to the top level window anyway, so let's send it to the
  14032. // content comp.
  14033. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  14034. c = resizableWindow->getContentComponent();
  14035. ApplicationCommandTarget* const target = findTargetForComponent (c);
  14036. if (target != 0)
  14037. return target;
  14038. }
  14039. return JUCEApplication::getInstance();
  14040. }
  14041. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  14042. {
  14043. listeners.add (listener);
  14044. }
  14045. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  14046. {
  14047. listeners.remove (listener);
  14048. }
  14049. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
  14050. {
  14051. listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
  14052. }
  14053. void ApplicationCommandManager::handleAsyncUpdate()
  14054. {
  14055. listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
  14056. }
  14057. void ApplicationCommandManager::globalFocusChanged (Component*)
  14058. {
  14059. commandStatusChanged();
  14060. }
  14061. END_JUCE_NAMESPACE
  14062. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  14063. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14064. BEGIN_JUCE_NAMESPACE
  14065. ApplicationCommandTarget::ApplicationCommandTarget()
  14066. {
  14067. }
  14068. ApplicationCommandTarget::~ApplicationCommandTarget()
  14069. {
  14070. messageInvoker = 0;
  14071. }
  14072. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  14073. {
  14074. if (isCommandActive (info.commandID))
  14075. {
  14076. if (async)
  14077. {
  14078. if (messageInvoker == 0)
  14079. messageInvoker = new CommandTargetMessageInvoker (this);
  14080. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  14081. return true;
  14082. }
  14083. else
  14084. {
  14085. const bool success = perform (info);
  14086. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  14087. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  14088. // returns the command's info.
  14089. return success;
  14090. }
  14091. }
  14092. return false;
  14093. }
  14094. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  14095. {
  14096. Component* c = dynamic_cast <Component*> (this);
  14097. if (c != 0)
  14098. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14099. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14100. return 0;
  14101. }
  14102. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  14103. {
  14104. ApplicationCommandTarget* target = this;
  14105. int depth = 0;
  14106. while (target != 0)
  14107. {
  14108. Array <CommandID> commandIDs;
  14109. target->getAllCommands (commandIDs);
  14110. if (commandIDs.contains (commandID))
  14111. return target;
  14112. target = target->getNextCommandTarget();
  14113. ++depth;
  14114. jassert (depth < 100); // could be a recursive command chain??
  14115. jassert (target != this); // definitely a recursive command chain!
  14116. if (depth > 100 || target == this)
  14117. break;
  14118. }
  14119. if (target == 0)
  14120. {
  14121. target = JUCEApplication::getInstance();
  14122. if (target != 0)
  14123. {
  14124. Array <CommandID> commandIDs;
  14125. target->getAllCommands (commandIDs);
  14126. if (commandIDs.contains (commandID))
  14127. return target;
  14128. }
  14129. }
  14130. return 0;
  14131. }
  14132. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  14133. {
  14134. ApplicationCommandInfo info (commandID);
  14135. info.flags = ApplicationCommandInfo::isDisabled;
  14136. getCommandInfo (commandID, info);
  14137. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  14138. }
  14139. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  14140. {
  14141. ApplicationCommandTarget* target = this;
  14142. int depth = 0;
  14143. while (target != 0)
  14144. {
  14145. if (target->tryToInvoke (info, async))
  14146. return true;
  14147. target = target->getNextCommandTarget();
  14148. ++depth;
  14149. jassert (depth < 100); // could be a recursive command chain??
  14150. jassert (target != this); // definitely a recursive command chain!
  14151. if (depth > 100 || target == this)
  14152. break;
  14153. }
  14154. if (target == 0)
  14155. {
  14156. target = JUCEApplication::getInstance();
  14157. if (target != 0)
  14158. return target->tryToInvoke (info, async);
  14159. }
  14160. return false;
  14161. }
  14162. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14163. {
  14164. ApplicationCommandTarget::InvocationInfo info (commandID);
  14165. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14166. return invoke (info, asynchronously);
  14167. }
  14168. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14169. : commandID (commandID_),
  14170. commandFlags (0),
  14171. invocationMethod (direct),
  14172. originatingComponent (0),
  14173. isKeyDown (false),
  14174. millisecsSinceKeyPressed (0)
  14175. {
  14176. }
  14177. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14178. : owner (owner_)
  14179. {
  14180. }
  14181. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14182. {
  14183. }
  14184. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14185. {
  14186. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14187. owner->tryToInvoke (*info, false);
  14188. }
  14189. END_JUCE_NAMESPACE
  14190. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14191. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14192. BEGIN_JUCE_NAMESPACE
  14193. juce_ImplementSingleton (ApplicationProperties)
  14194. ApplicationProperties::ApplicationProperties() throw()
  14195. : msBeforeSaving (3000),
  14196. options (PropertiesFile::storeAsBinary),
  14197. commonSettingsAreReadOnly (0)
  14198. {
  14199. }
  14200. ApplicationProperties::~ApplicationProperties()
  14201. {
  14202. closeFiles();
  14203. clearSingletonInstance();
  14204. }
  14205. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14206. const String& fileNameSuffix,
  14207. const String& folderName_,
  14208. const int millisecondsBeforeSaving,
  14209. const int propertiesFileOptions) throw()
  14210. {
  14211. appName = applicationName;
  14212. fileSuffix = fileNameSuffix;
  14213. folderName = folderName_;
  14214. msBeforeSaving = millisecondsBeforeSaving;
  14215. options = propertiesFileOptions;
  14216. }
  14217. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14218. const bool testCommonSettings,
  14219. const bool showWarningDialogOnFailure)
  14220. {
  14221. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14222. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14223. if (! (userOk && commonOk))
  14224. {
  14225. if (showWarningDialogOnFailure)
  14226. {
  14227. String filenames;
  14228. if (userProps != 0 && ! userOk)
  14229. filenames << '\n' << userProps->getFile().getFullPathName();
  14230. if (commonProps != 0 && ! commonOk)
  14231. filenames << '\n' << commonProps->getFile().getFullPathName();
  14232. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14233. appName + TRANS(" - Unable to save settings"),
  14234. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14235. + appName + TRANS(" needs to be able to write to the following files:\n")
  14236. + filenames
  14237. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14238. }
  14239. return false;
  14240. }
  14241. return true;
  14242. }
  14243. void ApplicationProperties::openFiles() throw()
  14244. {
  14245. // You need to call setStorageParameters() before trying to get hold of the
  14246. // properties!
  14247. jassert (appName.isNotEmpty());
  14248. if (appName.isNotEmpty())
  14249. {
  14250. if (userProps == 0)
  14251. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14252. false, msBeforeSaving, options);
  14253. if (commonProps == 0)
  14254. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14255. true, msBeforeSaving, options);
  14256. userProps->setFallbackPropertySet (commonProps);
  14257. }
  14258. }
  14259. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14260. {
  14261. if (userProps == 0)
  14262. openFiles();
  14263. return userProps;
  14264. }
  14265. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14266. {
  14267. if (commonProps == 0)
  14268. openFiles();
  14269. if (returnUserPropsIfReadOnly)
  14270. {
  14271. if (commonSettingsAreReadOnly == 0)
  14272. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14273. if (commonSettingsAreReadOnly > 0)
  14274. return userProps;
  14275. }
  14276. return commonProps;
  14277. }
  14278. bool ApplicationProperties::saveIfNeeded()
  14279. {
  14280. return (userProps == 0 || userProps->saveIfNeeded())
  14281. && (commonProps == 0 || commonProps->saveIfNeeded());
  14282. }
  14283. void ApplicationProperties::closeFiles()
  14284. {
  14285. userProps = 0;
  14286. commonProps = 0;
  14287. }
  14288. END_JUCE_NAMESPACE
  14289. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14290. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14291. BEGIN_JUCE_NAMESPACE
  14292. static VoidArray objectsToDelete;
  14293. static CriticalSection lock;
  14294. DeletedAtShutdown::DeletedAtShutdown()
  14295. {
  14296. const ScopedLock sl (lock);
  14297. objectsToDelete.add (this);
  14298. }
  14299. DeletedAtShutdown::~DeletedAtShutdown()
  14300. {
  14301. const ScopedLock sl (lock);
  14302. objectsToDelete.removeValue (this);
  14303. }
  14304. void DeletedAtShutdown::deleteAll()
  14305. {
  14306. // make a local copy of the array, so it can't get into a loop if something
  14307. // creates another DeletedAtShutdown object during its destructor.
  14308. VoidArray localCopy;
  14309. {
  14310. const ScopedLock sl (lock);
  14311. localCopy = objectsToDelete;
  14312. }
  14313. for (int i = localCopy.size(); --i >= 0;)
  14314. {
  14315. JUCE_TRY
  14316. {
  14317. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14318. // double-check that it's not already been deleted during another object's destructor.
  14319. {
  14320. const ScopedLock sl (lock);
  14321. if (! objectsToDelete.contains (deletee))
  14322. deletee = 0;
  14323. }
  14324. delete deletee;
  14325. }
  14326. JUCE_CATCH_EXCEPTION
  14327. }
  14328. // if no objects got re-created during shutdown, this should have been emptied by their
  14329. // destructors
  14330. jassert (objectsToDelete.size() == 0);
  14331. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14332. }
  14333. END_JUCE_NAMESPACE
  14334. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14335. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14336. BEGIN_JUCE_NAMESPACE
  14337. static const int propFileMagicNumber = ((int) ByteOrder::littleEndianInt ("PROP"));
  14338. static const int propFileMagicNumberCompressed = ((int) ByteOrder::littleEndianInt ("CPRP"));
  14339. static const tchar* const propertyFileXmlTag = T("PROPERTIES");
  14340. static const tchar* const propertyTagName = T("VALUE");
  14341. PropertiesFile::PropertiesFile (const File& f,
  14342. const int millisecondsBeforeSaving,
  14343. const int options_)
  14344. : PropertySet (ignoreCaseOfKeyNames),
  14345. file (f),
  14346. timerInterval (millisecondsBeforeSaving),
  14347. options (options_),
  14348. needsWriting (false)
  14349. {
  14350. // You need to correctly specify just one storage format for the file
  14351. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14352. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14353. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14354. ScopedPointer <InputStream> fileStream (f.createInputStream());
  14355. if (fileStream != 0)
  14356. {
  14357. int magicNumber = fileStream->readInt();
  14358. if (magicNumber == propFileMagicNumberCompressed)
  14359. {
  14360. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true),
  14361. true);
  14362. magicNumber = propFileMagicNumber;
  14363. }
  14364. if (magicNumber == propFileMagicNumber)
  14365. {
  14366. BufferedInputStream in (fileStream.release(), 2048, true);
  14367. int numValues = in.readInt();
  14368. while (--numValues >= 0 && ! in.isExhausted())
  14369. {
  14370. const String key (in.readString());
  14371. const String value (in.readString());
  14372. jassert (key.isNotEmpty());
  14373. if (key.isNotEmpty())
  14374. getAllProperties().set (key, value);
  14375. }
  14376. }
  14377. else
  14378. {
  14379. // Not a binary props file - let's see if it's XML..
  14380. fileStream = 0;
  14381. XmlDocument parser (f);
  14382. ScopedPointer <XmlElement> doc (parser.getDocumentElement (true));
  14383. if (doc != 0 && doc->hasTagName (propertyFileXmlTag))
  14384. {
  14385. doc = parser.getDocumentElement();
  14386. if (doc != 0)
  14387. {
  14388. forEachXmlChildElementWithTagName (*doc, e, propertyTagName)
  14389. {
  14390. const String name (e->getStringAttribute (T("name")));
  14391. if (name.isNotEmpty())
  14392. {
  14393. getAllProperties().set (name,
  14394. e->getFirstChildElement() != 0
  14395. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14396. : e->getStringAttribute (T("val")));
  14397. }
  14398. }
  14399. }
  14400. else
  14401. {
  14402. // must be a pretty broken XML file we're trying to parse here!
  14403. jassertfalse
  14404. }
  14405. }
  14406. }
  14407. }
  14408. }
  14409. PropertiesFile::~PropertiesFile()
  14410. {
  14411. saveIfNeeded();
  14412. }
  14413. bool PropertiesFile::saveIfNeeded()
  14414. {
  14415. const ScopedLock sl (getLock());
  14416. return (! needsWriting) || save();
  14417. }
  14418. bool PropertiesFile::needsToBeSaved() const
  14419. {
  14420. const ScopedLock sl (getLock());
  14421. return needsWriting;
  14422. }
  14423. bool PropertiesFile::save()
  14424. {
  14425. const ScopedLock sl (getLock());
  14426. stopTimer();
  14427. if (file == File::nonexistent
  14428. || file.isDirectory()
  14429. || ! file.getParentDirectory().createDirectory())
  14430. return false;
  14431. if ((options & storeAsXML) != 0)
  14432. {
  14433. XmlElement doc (propertyFileXmlTag);
  14434. for (int i = 0; i < getAllProperties().size(); ++i)
  14435. {
  14436. XmlElement* const e = doc.createNewChildElement (propertyTagName);
  14437. e->setAttribute (T("name"), getAllProperties().getAllKeys() [i]);
  14438. // if the value seems to contain xml, store it as such..
  14439. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14440. XmlElement* const childElement = xmlContent.getDocumentElement();
  14441. if (childElement != 0)
  14442. e->addChildElement (childElement);
  14443. else
  14444. e->setAttribute (T("val"), getAllProperties().getAllValues() [i]);
  14445. }
  14446. return doc.writeToFile (file, String::empty);
  14447. }
  14448. else
  14449. {
  14450. TemporaryFile tempFile (file);
  14451. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14452. if (out != 0)
  14453. {
  14454. if ((options & storeAsCompressedBinary) != 0)
  14455. {
  14456. out->writeInt (propFileMagicNumberCompressed);
  14457. out->flush();
  14458. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14459. }
  14460. else
  14461. {
  14462. // have you set up the storage option flags correctly?
  14463. jassert ((options & storeAsBinary) != 0);
  14464. out->writeInt (propFileMagicNumber);
  14465. }
  14466. const int numProperties = getAllProperties().size();
  14467. out->writeInt (numProperties);
  14468. for (int i = 0; i < numProperties; ++i)
  14469. {
  14470. out->writeString (getAllProperties().getAllKeys() [i]);
  14471. out->writeString (getAllProperties().getAllValues() [i]);
  14472. }
  14473. out = 0;
  14474. if (tempFile.overwriteTargetFileWithTemporary())
  14475. {
  14476. needsWriting = false;
  14477. return true;
  14478. }
  14479. }
  14480. }
  14481. return false;
  14482. }
  14483. void PropertiesFile::timerCallback()
  14484. {
  14485. saveIfNeeded();
  14486. }
  14487. void PropertiesFile::propertyChanged()
  14488. {
  14489. sendChangeMessage (this);
  14490. needsWriting = true;
  14491. if (timerInterval > 0)
  14492. startTimer (timerInterval);
  14493. else if (timerInterval == 0)
  14494. saveIfNeeded();
  14495. }
  14496. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14497. const String& fileNameSuffix,
  14498. const String& folderName,
  14499. const bool commonToAllUsers)
  14500. {
  14501. // mustn't have illegal characters in this name..
  14502. jassert (applicationName == File::createLegalFileName (applicationName));
  14503. #if JUCE_MAC || JUCE_IPHONE
  14504. File dir (commonToAllUsers ? "/Library/Preferences"
  14505. : "~/Library/Preferences");
  14506. if (folderName.isNotEmpty())
  14507. dir = dir.getChildFile (folderName);
  14508. #endif
  14509. #ifdef JUCE_LINUX
  14510. const File dir ((commonToAllUsers ? T("/var/") : T("~/"))
  14511. + (folderName.isNotEmpty() ? folderName
  14512. : (T(".") + applicationName)));
  14513. #endif
  14514. #if JUCE_WIN32
  14515. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14516. : File::userApplicationDataDirectory));
  14517. if (dir == File::nonexistent)
  14518. return File::nonexistent;
  14519. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14520. : applicationName);
  14521. #endif
  14522. return dir.getChildFile (applicationName)
  14523. .withFileExtension (fileNameSuffix);
  14524. }
  14525. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14526. const String& fileNameSuffix,
  14527. const String& folderName,
  14528. const bool commonToAllUsers,
  14529. const int millisecondsBeforeSaving,
  14530. const int propertiesFileOptions)
  14531. {
  14532. const File file (getDefaultAppSettingsFile (applicationName,
  14533. fileNameSuffix,
  14534. folderName,
  14535. commonToAllUsers));
  14536. jassert (file != File::nonexistent);
  14537. if (file == File::nonexistent)
  14538. return 0;
  14539. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14540. }
  14541. END_JUCE_NAMESPACE
  14542. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14543. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14544. BEGIN_JUCE_NAMESPACE
  14545. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14546. const String& fileWildcard_,
  14547. const String& openFileDialogTitle_,
  14548. const String& saveFileDialogTitle_)
  14549. : changedSinceSave (false),
  14550. fileExtension (fileExtension_),
  14551. fileWildcard (fileWildcard_),
  14552. openFileDialogTitle (openFileDialogTitle_),
  14553. saveFileDialogTitle (saveFileDialogTitle_)
  14554. {
  14555. }
  14556. FileBasedDocument::~FileBasedDocument()
  14557. {
  14558. }
  14559. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14560. {
  14561. changedSinceSave = hasChanged;
  14562. }
  14563. void FileBasedDocument::changed()
  14564. {
  14565. changedSinceSave = true;
  14566. sendChangeMessage (this);
  14567. }
  14568. void FileBasedDocument::setFile (const File& newFile)
  14569. {
  14570. if (documentFile != newFile)
  14571. {
  14572. documentFile = newFile;
  14573. changedSinceSave = true;
  14574. }
  14575. }
  14576. bool FileBasedDocument::loadFrom (const File& newFile,
  14577. const bool showMessageOnFailure)
  14578. {
  14579. MouseCursor::showWaitCursor();
  14580. const File oldFile (documentFile);
  14581. documentFile = newFile;
  14582. String error;
  14583. if (newFile.existsAsFile())
  14584. {
  14585. error = loadDocument (newFile);
  14586. if (error.isEmpty())
  14587. {
  14588. setChangedFlag (false);
  14589. MouseCursor::hideWaitCursor();
  14590. setLastDocumentOpened (newFile);
  14591. return true;
  14592. }
  14593. }
  14594. else
  14595. {
  14596. error = "The file doesn't exist";
  14597. }
  14598. documentFile = oldFile;
  14599. MouseCursor::hideWaitCursor();
  14600. if (showMessageOnFailure)
  14601. {
  14602. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14603. TRANS("Failed to open file..."),
  14604. TRANS("There was an error while trying to load the file:\n\n")
  14605. + newFile.getFullPathName()
  14606. + T("\n\n")
  14607. + error);
  14608. }
  14609. return false;
  14610. }
  14611. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14612. {
  14613. FileChooser fc (openFileDialogTitle,
  14614. getLastDocumentOpened(),
  14615. fileWildcard);
  14616. if (fc.browseForFileToOpen())
  14617. return loadFrom (fc.getResult(), showMessageOnFailure);
  14618. return false;
  14619. }
  14620. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14621. const bool showMessageOnFailure)
  14622. {
  14623. return saveAs (documentFile,
  14624. false,
  14625. askUserForFileIfNotSpecified,
  14626. showMessageOnFailure);
  14627. }
  14628. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14629. const bool warnAboutOverwritingExistingFiles,
  14630. const bool askUserForFileIfNotSpecified,
  14631. const bool showMessageOnFailure)
  14632. {
  14633. if (newFile == File::nonexistent)
  14634. {
  14635. if (askUserForFileIfNotSpecified)
  14636. {
  14637. return saveAsInteractive (true);
  14638. }
  14639. else
  14640. {
  14641. // can't save to an unspecified file
  14642. jassertfalse
  14643. return failedToWriteToFile;
  14644. }
  14645. }
  14646. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14647. {
  14648. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14649. TRANS("File already exists"),
  14650. TRANS("There's already a file called:\n\n")
  14651. + newFile.getFullPathName()
  14652. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14653. TRANS("overwrite"),
  14654. TRANS("cancel")))
  14655. {
  14656. return userCancelledSave;
  14657. }
  14658. }
  14659. MouseCursor::showWaitCursor();
  14660. const File oldFile (documentFile);
  14661. documentFile = newFile;
  14662. String error (saveDocument (newFile));
  14663. if (error.isEmpty())
  14664. {
  14665. setChangedFlag (false);
  14666. MouseCursor::hideWaitCursor();
  14667. return savedOk;
  14668. }
  14669. documentFile = oldFile;
  14670. MouseCursor::hideWaitCursor();
  14671. if (showMessageOnFailure)
  14672. {
  14673. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14674. TRANS("Error writing to file..."),
  14675. TRANS("An error occurred while trying to save \"")
  14676. + getDocumentTitle()
  14677. + TRANS("\" to the file:\n\n")
  14678. + newFile.getFullPathName()
  14679. + T("\n\n")
  14680. + error);
  14681. }
  14682. return failedToWriteToFile;
  14683. }
  14684. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14685. {
  14686. if (! hasChangedSinceSaved())
  14687. return savedOk;
  14688. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14689. TRANS("Closing document..."),
  14690. TRANS("Do you want to save the changes to \"")
  14691. + getDocumentTitle() + T("\"?"),
  14692. TRANS("save"),
  14693. TRANS("discard changes"),
  14694. TRANS("cancel"));
  14695. if (r == 1)
  14696. {
  14697. // save changes
  14698. return save (true, true);
  14699. }
  14700. else if (r == 2)
  14701. {
  14702. // discard changes
  14703. return savedOk;
  14704. }
  14705. return userCancelledSave;
  14706. }
  14707. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14708. {
  14709. File f;
  14710. if (documentFile.existsAsFile())
  14711. f = documentFile;
  14712. else
  14713. f = getLastDocumentOpened();
  14714. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14715. if (legalFilename.isEmpty())
  14716. legalFilename = "unnamed";
  14717. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14718. f = f.getSiblingFile (legalFilename);
  14719. else
  14720. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14721. f = f.withFileExtension (fileExtension)
  14722. .getNonexistentSibling (true);
  14723. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14724. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14725. {
  14726. setLastDocumentOpened (fc.getResult());
  14727. File chosen (fc.getResult());
  14728. if (chosen.getFileExtension().isEmpty())
  14729. {
  14730. chosen = chosen.withFileExtension (fileExtension);
  14731. if (chosen.exists())
  14732. {
  14733. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14734. TRANS("File already exists"),
  14735. TRANS("There's already a file called:\n\n")
  14736. + chosen.getFullPathName()
  14737. + T("\n\nAre you sure you want to overwrite it?"),
  14738. TRANS("overwrite"),
  14739. TRANS("cancel")))
  14740. {
  14741. return userCancelledSave;
  14742. }
  14743. }
  14744. }
  14745. return saveAs (chosen, false, false, true);
  14746. }
  14747. return userCancelledSave;
  14748. }
  14749. END_JUCE_NAMESPACE
  14750. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14751. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14752. BEGIN_JUCE_NAMESPACE
  14753. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14754. : maxNumberOfItems (10)
  14755. {
  14756. }
  14757. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14758. {
  14759. }
  14760. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14761. {
  14762. maxNumberOfItems = jmax (1, newMaxNumber);
  14763. while (getNumFiles() > maxNumberOfItems)
  14764. files.remove (getNumFiles() - 1);
  14765. }
  14766. int RecentlyOpenedFilesList::getNumFiles() const
  14767. {
  14768. return files.size();
  14769. }
  14770. const File RecentlyOpenedFilesList::getFile (const int index) const
  14771. {
  14772. return File (files [index]);
  14773. }
  14774. void RecentlyOpenedFilesList::clear()
  14775. {
  14776. files.clear();
  14777. }
  14778. void RecentlyOpenedFilesList::addFile (const File& file)
  14779. {
  14780. const String path (file.getFullPathName());
  14781. files.removeString (path, true);
  14782. files.insert (0, path);
  14783. setMaxNumberOfItems (maxNumberOfItems);
  14784. }
  14785. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14786. {
  14787. for (int i = getNumFiles(); --i >= 0;)
  14788. if (! getFile(i).exists())
  14789. files.remove (i);
  14790. }
  14791. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14792. const int baseItemId,
  14793. const bool showFullPaths,
  14794. const bool dontAddNonExistentFiles,
  14795. const File** filesToAvoid)
  14796. {
  14797. int num = 0;
  14798. for (int i = 0; i < getNumFiles(); ++i)
  14799. {
  14800. const File f (getFile(i));
  14801. if ((! dontAddNonExistentFiles) || f.exists())
  14802. {
  14803. bool needsAvoiding = false;
  14804. if (filesToAvoid != 0)
  14805. {
  14806. const File** avoid = filesToAvoid;
  14807. while (*avoid != 0)
  14808. {
  14809. if (f == **avoid)
  14810. {
  14811. needsAvoiding = true;
  14812. break;
  14813. }
  14814. ++avoid;
  14815. }
  14816. }
  14817. if (! needsAvoiding)
  14818. {
  14819. menuToAddTo.addItem (baseItemId + i,
  14820. showFullPaths ? f.getFullPathName()
  14821. : f.getFileName());
  14822. ++num;
  14823. }
  14824. }
  14825. }
  14826. return num;
  14827. }
  14828. const String RecentlyOpenedFilesList::toString() const
  14829. {
  14830. return files.joinIntoString (T("\n"));
  14831. }
  14832. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14833. {
  14834. clear();
  14835. files.addLines (stringifiedVersion);
  14836. setMaxNumberOfItems (maxNumberOfItems);
  14837. }
  14838. END_JUCE_NAMESPACE
  14839. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14840. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14841. BEGIN_JUCE_NAMESPACE
  14842. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14843. const int minimumTransactions)
  14844. : totalUnitsStored (0),
  14845. nextIndex (0),
  14846. newTransaction (true),
  14847. reentrancyCheck (false)
  14848. {
  14849. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14850. minimumTransactions);
  14851. }
  14852. UndoManager::~UndoManager()
  14853. {
  14854. clearUndoHistory();
  14855. }
  14856. void UndoManager::clearUndoHistory()
  14857. {
  14858. transactions.clear();
  14859. transactionNames.clear();
  14860. totalUnitsStored = 0;
  14861. nextIndex = 0;
  14862. sendChangeMessage (this);
  14863. }
  14864. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14865. {
  14866. return totalUnitsStored;
  14867. }
  14868. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14869. const int minimumTransactions)
  14870. {
  14871. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14872. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14873. }
  14874. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14875. {
  14876. if (command != 0)
  14877. {
  14878. if (actionName.isNotEmpty())
  14879. currentTransactionName = actionName;
  14880. if (reentrancyCheck)
  14881. {
  14882. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14883. // undo() methods, or else these actions won't actually get done.
  14884. return false;
  14885. }
  14886. else
  14887. {
  14888. bool success = false;
  14889. JUCE_TRY
  14890. {
  14891. success = command->perform();
  14892. }
  14893. JUCE_CATCH_EXCEPTION
  14894. jassert (success);
  14895. if (success)
  14896. {
  14897. if (nextIndex > 0 && ! newTransaction)
  14898. {
  14899. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14900. jassert (commandSet != 0);
  14901. if (commandSet == 0)
  14902. return false;
  14903. commandSet->add (command);
  14904. }
  14905. else
  14906. {
  14907. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  14908. commandSet->add (command);
  14909. transactions.insert (nextIndex, commandSet);
  14910. transactionNames.insert (nextIndex, currentTransactionName);
  14911. ++nextIndex;
  14912. }
  14913. totalUnitsStored += command->getSizeInUnits();
  14914. newTransaction = false;
  14915. }
  14916. while (nextIndex < transactions.size())
  14917. {
  14918. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  14919. for (int i = lastSet->size(); --i >= 0;)
  14920. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  14921. transactions.removeLast();
  14922. transactionNames.remove (transactionNames.size() - 1);
  14923. }
  14924. while (nextIndex > 0
  14925. && totalUnitsStored > maxNumUnitsToKeep
  14926. && transactions.size() > minimumTransactionsToKeep)
  14927. {
  14928. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  14929. for (int i = firstSet->size(); --i >= 0;)
  14930. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  14931. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  14932. transactions.remove (0);
  14933. transactionNames.remove (0);
  14934. --nextIndex;
  14935. }
  14936. sendChangeMessage (this);
  14937. return success;
  14938. }
  14939. }
  14940. return false;
  14941. }
  14942. void UndoManager::beginNewTransaction (const String& actionName)
  14943. {
  14944. newTransaction = true;
  14945. currentTransactionName = actionName;
  14946. }
  14947. void UndoManager::setCurrentTransactionName (const String& newName)
  14948. {
  14949. currentTransactionName = newName;
  14950. }
  14951. bool UndoManager::canUndo() const
  14952. {
  14953. return nextIndex > 0;
  14954. }
  14955. bool UndoManager::canRedo() const
  14956. {
  14957. return nextIndex < transactions.size();
  14958. }
  14959. const String UndoManager::getUndoDescription() const
  14960. {
  14961. return transactionNames [nextIndex - 1];
  14962. }
  14963. const String UndoManager::getRedoDescription() const
  14964. {
  14965. return transactionNames [nextIndex];
  14966. }
  14967. bool UndoManager::undo()
  14968. {
  14969. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14970. if (commandSet == 0)
  14971. return false;
  14972. reentrancyCheck = true;
  14973. bool failed = false;
  14974. for (int i = commandSet->size(); --i >= 0;)
  14975. {
  14976. if (! commandSet->getUnchecked(i)->undo())
  14977. {
  14978. jassertfalse
  14979. failed = true;
  14980. break;
  14981. }
  14982. }
  14983. reentrancyCheck = false;
  14984. if (failed)
  14985. {
  14986. clearUndoHistory();
  14987. }
  14988. else
  14989. {
  14990. --nextIndex;
  14991. }
  14992. beginNewTransaction();
  14993. sendChangeMessage (this);
  14994. return true;
  14995. }
  14996. bool UndoManager::redo()
  14997. {
  14998. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  14999. if (commandSet == 0)
  15000. return false;
  15001. reentrancyCheck = true;
  15002. bool failed = false;
  15003. for (int i = 0; i < commandSet->size(); ++i)
  15004. {
  15005. if (! commandSet->getUnchecked(i)->perform())
  15006. {
  15007. jassertfalse
  15008. failed = true;
  15009. break;
  15010. }
  15011. }
  15012. reentrancyCheck = false;
  15013. if (failed)
  15014. {
  15015. clearUndoHistory();
  15016. }
  15017. else
  15018. {
  15019. ++nextIndex;
  15020. }
  15021. beginNewTransaction();
  15022. sendChangeMessage (this);
  15023. return true;
  15024. }
  15025. bool UndoManager::undoCurrentTransactionOnly()
  15026. {
  15027. return newTransaction ? false
  15028. : undo();
  15029. }
  15030. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  15031. {
  15032. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15033. if (commandSet != 0 && ! newTransaction)
  15034. {
  15035. for (int i = 0; i < commandSet->size(); ++i)
  15036. actionsFound.add (commandSet->getUnchecked(i));
  15037. }
  15038. }
  15039. int UndoManager::getNumActionsInCurrentTransaction() const
  15040. {
  15041. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15042. if (commandSet != 0 && ! newTransaction)
  15043. return commandSet->size();
  15044. return 0;
  15045. }
  15046. END_JUCE_NAMESPACE
  15047. /*** End of inlined file: juce_UndoManager.cpp ***/
  15048. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  15049. BEGIN_JUCE_NAMESPACE
  15050. static const char* const aiffFormatName = "AIFF file";
  15051. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  15052. class AiffAudioFormatReader : public AudioFormatReader
  15053. {
  15054. public:
  15055. int bytesPerFrame;
  15056. int64 dataChunkStart;
  15057. bool littleEndian;
  15058. AiffAudioFormatReader (InputStream* in)
  15059. : AudioFormatReader (in, TRANS (aiffFormatName))
  15060. {
  15061. if (input->readInt() == chunkName ("FORM"))
  15062. {
  15063. const int len = input->readIntBigEndian();
  15064. const int64 end = input->getPosition() + len;
  15065. const int nextType = input->readInt();
  15066. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  15067. {
  15068. bool hasGotVer = false;
  15069. bool hasGotData = false;
  15070. bool hasGotType = false;
  15071. while (input->getPosition() < end)
  15072. {
  15073. const int type = input->readInt();
  15074. const uint32 length = (uint32) input->readIntBigEndian();
  15075. const int64 chunkEnd = input->getPosition() + length;
  15076. if (type == chunkName ("FVER"))
  15077. {
  15078. hasGotVer = true;
  15079. const int ver = input->readIntBigEndian();
  15080. if (ver != 0 && ver != (int)0xa2805140)
  15081. break;
  15082. }
  15083. else if (type == chunkName ("COMM"))
  15084. {
  15085. hasGotType = true;
  15086. numChannels = (unsigned int)input->readShortBigEndian();
  15087. lengthInSamples = input->readIntBigEndian();
  15088. bitsPerSample = input->readShortBigEndian();
  15089. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  15090. unsigned char sampleRateBytes[10];
  15091. input->read (sampleRateBytes, 10);
  15092. const int byte0 = sampleRateBytes[0];
  15093. if ((byte0 & 0x80) != 0
  15094. || byte0 <= 0x3F || byte0 > 0x40
  15095. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  15096. break;
  15097. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  15098. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  15099. sampleRate = (int) sampRate;
  15100. if (length <= 18)
  15101. {
  15102. // some types don't have a chunk large enough to include a compression
  15103. // type, so assume it's just big-endian pcm
  15104. littleEndian = false;
  15105. }
  15106. else
  15107. {
  15108. const int compType = input->readInt();
  15109. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15110. {
  15111. littleEndian = false;
  15112. }
  15113. else if (compType == chunkName ("sowt"))
  15114. {
  15115. littleEndian = true;
  15116. }
  15117. else
  15118. {
  15119. sampleRate = 0;
  15120. break;
  15121. }
  15122. }
  15123. }
  15124. else if (type == chunkName ("SSND"))
  15125. {
  15126. hasGotData = true;
  15127. const int offset = input->readIntBigEndian();
  15128. dataChunkStart = input->getPosition() + 4 + offset;
  15129. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15130. }
  15131. else if ((hasGotVer && hasGotData && hasGotType)
  15132. || chunkEnd < input->getPosition()
  15133. || input->isExhausted())
  15134. {
  15135. break;
  15136. }
  15137. input->setPosition (chunkEnd);
  15138. }
  15139. }
  15140. }
  15141. }
  15142. ~AiffAudioFormatReader()
  15143. {
  15144. }
  15145. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15146. int64 startSampleInFile, int numSamples)
  15147. {
  15148. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15149. if (samplesAvailable < numSamples)
  15150. {
  15151. for (int i = numDestChannels; --i >= 0;)
  15152. if (destSamples[i] != 0)
  15153. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15154. numSamples = (int) samplesAvailable;
  15155. }
  15156. if (numSamples <= 0)
  15157. return true;
  15158. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15159. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15160. char tempBuffer [tempBufSize];
  15161. while (numSamples > 0)
  15162. {
  15163. int* left = destSamples[0];
  15164. if (left != 0)
  15165. left += startOffsetInDestBuffer;
  15166. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15167. if (right != 0)
  15168. right += startOffsetInDestBuffer;
  15169. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15170. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15171. if (bytesRead < numThisTime * bytesPerFrame)
  15172. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15173. if (bitsPerSample == 16)
  15174. {
  15175. if (littleEndian)
  15176. {
  15177. const short* src = (const short*) tempBuffer;
  15178. if (numChannels > 1)
  15179. {
  15180. if (left == 0)
  15181. {
  15182. for (int i = numThisTime; --i >= 0;)
  15183. {
  15184. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15185. ++src;
  15186. }
  15187. }
  15188. else if (right == 0)
  15189. {
  15190. for (int i = numThisTime; --i >= 0;)
  15191. {
  15192. ++src;
  15193. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15194. }
  15195. }
  15196. else
  15197. {
  15198. for (int i = numThisTime; --i >= 0;)
  15199. {
  15200. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15201. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15202. }
  15203. }
  15204. }
  15205. else
  15206. {
  15207. for (int i = numThisTime; --i >= 0;)
  15208. {
  15209. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15210. }
  15211. }
  15212. }
  15213. else
  15214. {
  15215. const char* src = (const char*) tempBuffer;
  15216. if (numChannels > 1)
  15217. {
  15218. if (left == 0)
  15219. {
  15220. for (int i = numThisTime; --i >= 0;)
  15221. {
  15222. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15223. src += 4;
  15224. }
  15225. }
  15226. else if (right == 0)
  15227. {
  15228. for (int i = numThisTime; --i >= 0;)
  15229. {
  15230. src += 2;
  15231. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15232. src += 2;
  15233. }
  15234. }
  15235. else
  15236. {
  15237. for (int i = numThisTime; --i >= 0;)
  15238. {
  15239. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15240. src += 2;
  15241. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15242. src += 2;
  15243. }
  15244. }
  15245. }
  15246. else
  15247. {
  15248. for (int i = numThisTime; --i >= 0;)
  15249. {
  15250. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15251. src += 2;
  15252. }
  15253. }
  15254. }
  15255. }
  15256. else if (bitsPerSample == 24)
  15257. {
  15258. const char* src = (const char*)tempBuffer;
  15259. if (littleEndian)
  15260. {
  15261. if (numChannels > 1)
  15262. {
  15263. if (left == 0)
  15264. {
  15265. for (int i = numThisTime; --i >= 0;)
  15266. {
  15267. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15268. src += 6;
  15269. }
  15270. }
  15271. else if (right == 0)
  15272. {
  15273. for (int i = numThisTime; --i >= 0;)
  15274. {
  15275. src += 3;
  15276. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15277. src += 3;
  15278. }
  15279. }
  15280. else
  15281. {
  15282. for (int i = numThisTime; --i >= 0;)
  15283. {
  15284. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15285. src += 3;
  15286. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15287. src += 3;
  15288. }
  15289. }
  15290. }
  15291. else
  15292. {
  15293. for (int i = numThisTime; --i >= 0;)
  15294. {
  15295. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15296. src += 3;
  15297. }
  15298. }
  15299. }
  15300. else
  15301. {
  15302. if (numChannels > 1)
  15303. {
  15304. if (left == 0)
  15305. {
  15306. for (int i = numThisTime; --i >= 0;)
  15307. {
  15308. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15309. src += 6;
  15310. }
  15311. }
  15312. else if (right == 0)
  15313. {
  15314. for (int i = numThisTime; --i >= 0;)
  15315. {
  15316. src += 3;
  15317. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15318. src += 3;
  15319. }
  15320. }
  15321. else
  15322. {
  15323. for (int i = numThisTime; --i >= 0;)
  15324. {
  15325. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15326. src += 3;
  15327. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15328. src += 3;
  15329. }
  15330. }
  15331. }
  15332. else
  15333. {
  15334. for (int i = numThisTime; --i >= 0;)
  15335. {
  15336. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15337. src += 3;
  15338. }
  15339. }
  15340. }
  15341. }
  15342. else if (bitsPerSample == 32)
  15343. {
  15344. const unsigned int* src = (const unsigned int*) tempBuffer;
  15345. unsigned int* l = (unsigned int*) left;
  15346. unsigned int* r = (unsigned int*) right;
  15347. if (littleEndian)
  15348. {
  15349. if (numChannels > 1)
  15350. {
  15351. if (l == 0)
  15352. {
  15353. for (int i = numThisTime; --i >= 0;)
  15354. {
  15355. ++src;
  15356. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15357. }
  15358. }
  15359. else if (r == 0)
  15360. {
  15361. for (int i = numThisTime; --i >= 0;)
  15362. {
  15363. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15364. ++src;
  15365. }
  15366. }
  15367. else
  15368. {
  15369. for (int i = numThisTime; --i >= 0;)
  15370. {
  15371. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15372. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15373. }
  15374. }
  15375. }
  15376. else
  15377. {
  15378. for (int i = numThisTime; --i >= 0;)
  15379. {
  15380. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15381. }
  15382. }
  15383. }
  15384. else
  15385. {
  15386. if (numChannels > 1)
  15387. {
  15388. if (l == 0)
  15389. {
  15390. for (int i = numThisTime; --i >= 0;)
  15391. {
  15392. ++src;
  15393. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15394. }
  15395. }
  15396. else if (r == 0)
  15397. {
  15398. for (int i = numThisTime; --i >= 0;)
  15399. {
  15400. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15401. ++src;
  15402. }
  15403. }
  15404. else
  15405. {
  15406. for (int i = numThisTime; --i >= 0;)
  15407. {
  15408. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15409. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15410. }
  15411. }
  15412. }
  15413. else
  15414. {
  15415. for (int i = numThisTime; --i >= 0;)
  15416. {
  15417. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15418. }
  15419. }
  15420. }
  15421. left = (int*) l;
  15422. right = (int*) r;
  15423. }
  15424. else if (bitsPerSample == 8)
  15425. {
  15426. const char* src = (const char*) tempBuffer;
  15427. if (numChannels > 1)
  15428. {
  15429. if (left == 0)
  15430. {
  15431. for (int i = numThisTime; --i >= 0;)
  15432. {
  15433. *right++ = ((int) *src++) << 24;
  15434. ++src;
  15435. }
  15436. }
  15437. else if (right == 0)
  15438. {
  15439. for (int i = numThisTime; --i >= 0;)
  15440. {
  15441. ++src;
  15442. *left++ = ((int) *src++) << 24;
  15443. }
  15444. }
  15445. else
  15446. {
  15447. for (int i = numThisTime; --i >= 0;)
  15448. {
  15449. *left++ = ((int) *src++) << 24;
  15450. *right++ = ((int) *src++) << 24;
  15451. }
  15452. }
  15453. }
  15454. else
  15455. {
  15456. for (int i = numThisTime; --i >= 0;)
  15457. {
  15458. *left++ = ((int) *src++) << 24;
  15459. }
  15460. }
  15461. }
  15462. startOffsetInDestBuffer += numThisTime;
  15463. numSamples -= numThisTime;
  15464. }
  15465. if (numSamples > 0)
  15466. {
  15467. for (int i = numDestChannels; --i >= 0;)
  15468. if (destSamples[i] != 0)
  15469. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15470. sizeof (int) * numSamples);
  15471. }
  15472. return true;
  15473. }
  15474. juce_UseDebuggingNewOperator
  15475. private:
  15476. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15477. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15478. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15479. };
  15480. class AiffAudioFormatWriter : public AudioFormatWriter
  15481. {
  15482. MemoryBlock tempBlock;
  15483. uint32 lengthInSamples, bytesWritten;
  15484. int64 headerPosition;
  15485. bool writeFailed;
  15486. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15487. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15488. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15489. void writeHeader()
  15490. {
  15491. const bool couldSeekOk = output->setPosition (headerPosition);
  15492. (void) couldSeekOk;
  15493. // if this fails, you've given it an output stream that can't seek! It needs
  15494. // to be able to seek back to write the header
  15495. jassert (couldSeekOk);
  15496. const int headerLen = 54;
  15497. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15498. audioBytes += (audioBytes & 1);
  15499. output->writeInt (chunkName ("FORM"));
  15500. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15501. output->writeInt (chunkName ("AIFF"));
  15502. output->writeInt (chunkName ("COMM"));
  15503. output->writeIntBigEndian (18);
  15504. output->writeShortBigEndian ((short) numChannels);
  15505. output->writeIntBigEndian (lengthInSamples);
  15506. output->writeShortBigEndian ((short) bitsPerSample);
  15507. uint8 sampleRateBytes[10];
  15508. zeromem (sampleRateBytes, 10);
  15509. if (sampleRate <= 1)
  15510. {
  15511. sampleRateBytes[0] = 0x3f;
  15512. sampleRateBytes[1] = 0xff;
  15513. sampleRateBytes[2] = 0x80;
  15514. }
  15515. else
  15516. {
  15517. int mask = 0x40000000;
  15518. sampleRateBytes[0] = 0x40;
  15519. if (sampleRate >= mask)
  15520. {
  15521. jassertfalse
  15522. sampleRateBytes[1] = 0x1d;
  15523. }
  15524. else
  15525. {
  15526. int n = (int) sampleRate;
  15527. int i;
  15528. for (i = 0; i <= 32 ; ++i)
  15529. {
  15530. if ((n & mask) != 0)
  15531. break;
  15532. mask >>= 1;
  15533. }
  15534. n = n << (i + 1);
  15535. sampleRateBytes[1] = (uint8) (29 - i);
  15536. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15537. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15538. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15539. sampleRateBytes[5] = (uint8) (n & 0xff);
  15540. }
  15541. }
  15542. output->write (sampleRateBytes, 10);
  15543. output->writeInt (chunkName ("SSND"));
  15544. output->writeIntBigEndian (audioBytes + 8);
  15545. output->writeInt (0);
  15546. output->writeInt (0);
  15547. jassert (output->getPosition() == headerLen);
  15548. }
  15549. public:
  15550. AiffAudioFormatWriter (OutputStream* out,
  15551. const double sampleRate_,
  15552. const unsigned int chans,
  15553. const int bits)
  15554. : AudioFormatWriter (out,
  15555. TRANS (aiffFormatName),
  15556. sampleRate_,
  15557. chans,
  15558. bits),
  15559. lengthInSamples (0),
  15560. bytesWritten (0),
  15561. writeFailed (false)
  15562. {
  15563. headerPosition = out->getPosition();
  15564. writeHeader();
  15565. }
  15566. ~AiffAudioFormatWriter()
  15567. {
  15568. if ((bytesWritten & 1) != 0)
  15569. output->writeByte (0);
  15570. writeHeader();
  15571. }
  15572. bool write (const int** data, int numSamples)
  15573. {
  15574. if (writeFailed)
  15575. return false;
  15576. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15577. tempBlock.ensureSize (bytes, false);
  15578. char* buffer = (char*) tempBlock.getData();
  15579. const int* left = data[0];
  15580. const int* right = data[1];
  15581. if (right == 0)
  15582. right = left;
  15583. if (bitsPerSample == 16)
  15584. {
  15585. short* b = (short*) buffer;
  15586. if (numChannels > 1)
  15587. {
  15588. for (int i = numSamples; --i >= 0;)
  15589. {
  15590. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15591. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15592. }
  15593. }
  15594. else
  15595. {
  15596. for (int i = numSamples; --i >= 0;)
  15597. {
  15598. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15599. }
  15600. }
  15601. }
  15602. else if (bitsPerSample == 24)
  15603. {
  15604. char* b = (char*) buffer;
  15605. if (numChannels > 1)
  15606. {
  15607. for (int i = numSamples; --i >= 0;)
  15608. {
  15609. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15610. b += 3;
  15611. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15612. b += 3;
  15613. }
  15614. }
  15615. else
  15616. {
  15617. for (int i = numSamples; --i >= 0;)
  15618. {
  15619. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15620. b += 3;
  15621. }
  15622. }
  15623. }
  15624. else if (bitsPerSample == 32)
  15625. {
  15626. uint32* b = (uint32*) buffer;
  15627. if (numChannels > 1)
  15628. {
  15629. for (int i = numSamples; --i >= 0;)
  15630. {
  15631. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15632. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15633. }
  15634. }
  15635. else
  15636. {
  15637. for (int i = numSamples; --i >= 0;)
  15638. {
  15639. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15640. }
  15641. }
  15642. }
  15643. else if (bitsPerSample == 8)
  15644. {
  15645. char* b = (char*) buffer;
  15646. if (numChannels > 1)
  15647. {
  15648. for (int i = numSamples; --i >= 0;)
  15649. {
  15650. *b++ = (char) (*left++ >> 24);
  15651. *b++ = (char) (*right++ >> 24);
  15652. }
  15653. }
  15654. else
  15655. {
  15656. for (int i = numSamples; --i >= 0;)
  15657. {
  15658. *b++ = (char) (*left++ >> 24);
  15659. }
  15660. }
  15661. }
  15662. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15663. || ! output->write (buffer, bytes))
  15664. {
  15665. // failed to write to disk, so let's try writing the header.
  15666. // If it's just run out of disk space, then if it does manage
  15667. // to write the header, we'll still have a useable file..
  15668. writeHeader();
  15669. writeFailed = true;
  15670. return false;
  15671. }
  15672. else
  15673. {
  15674. bytesWritten += bytes;
  15675. lengthInSamples += numSamples;
  15676. return true;
  15677. }
  15678. }
  15679. juce_UseDebuggingNewOperator
  15680. };
  15681. AiffAudioFormat::AiffAudioFormat()
  15682. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15683. {
  15684. }
  15685. AiffAudioFormat::~AiffAudioFormat()
  15686. {
  15687. }
  15688. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15689. {
  15690. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15691. return Array <int> (rates);
  15692. }
  15693. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15694. {
  15695. const int depths[] = { 8, 16, 24, 0 };
  15696. return Array <int> (depths);
  15697. }
  15698. bool AiffAudioFormat::canDoStereo()
  15699. {
  15700. return true;
  15701. }
  15702. bool AiffAudioFormat::canDoMono()
  15703. {
  15704. return true;
  15705. }
  15706. #if JUCE_MAC
  15707. bool AiffAudioFormat::canHandleFile (const File& f)
  15708. {
  15709. if (AudioFormat::canHandleFile (f))
  15710. return true;
  15711. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15712. return type == 'AIFF' || type == 'AIFC'
  15713. || type == 'aiff' || type == 'aifc';
  15714. }
  15715. #endif
  15716. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15717. const bool deleteStreamIfOpeningFails)
  15718. {
  15719. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15720. if (w->sampleRate != 0)
  15721. return w.release();
  15722. if (! deleteStreamIfOpeningFails)
  15723. w->input = 0;
  15724. return 0;
  15725. }
  15726. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15727. double sampleRate,
  15728. unsigned int chans,
  15729. int bitsPerSample,
  15730. const StringPairArray& /*metadataValues*/,
  15731. int /*qualityOptionIndex*/)
  15732. {
  15733. if (getPossibleBitDepths().contains (bitsPerSample))
  15734. {
  15735. return new AiffAudioFormatWriter (out,
  15736. sampleRate,
  15737. chans,
  15738. bitsPerSample);
  15739. }
  15740. return 0;
  15741. }
  15742. END_JUCE_NAMESPACE
  15743. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15744. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15745. BEGIN_JUCE_NAMESPACE
  15746. #if JUCE_MAC && JUCE_USE_CDREADER
  15747. // Mac version doesn't need any native code because it's all done with files..
  15748. // Windows + Linux versions are in the platform-dependent code sections.
  15749. static void findCDs (Array<File>& cds)
  15750. {
  15751. File volumes ("/Volumes");
  15752. volumes.findChildFiles (cds, File::findDirectories, false);
  15753. for (int i = cds.size(); --i >= 0;)
  15754. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15755. cds.remove (i);
  15756. }
  15757. const StringArray AudioCDReader::getAvailableCDNames()
  15758. {
  15759. Array<File> cds;
  15760. findCDs (cds);
  15761. StringArray names;
  15762. for (int i = 0; i < cds.size(); ++i)
  15763. names.add (cds.getReference(i).getFileName());
  15764. return names;
  15765. }
  15766. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15767. {
  15768. Array<File> cds;
  15769. findCDs (cds);
  15770. if (cds[index] != File::nonexistent)
  15771. return new AudioCDReader (cds[index]);
  15772. else
  15773. return 0;
  15774. }
  15775. AudioCDReader::AudioCDReader (const File& volume)
  15776. : AudioFormatReader (0, "CD Audio"),
  15777. volumeDir (volume),
  15778. currentReaderTrack (-1),
  15779. reader (0)
  15780. {
  15781. sampleRate = 44100.0;
  15782. bitsPerSample = 16;
  15783. numChannels = 2;
  15784. usesFloatingPointData = false;
  15785. refreshTrackLengths();
  15786. }
  15787. AudioCDReader::~AudioCDReader()
  15788. {
  15789. }
  15790. static int getTrackNumber (const File& file)
  15791. {
  15792. return file.getFileName()
  15793. .initialSectionContainingOnly (T("0123456789"))
  15794. .getIntValue();
  15795. }
  15796. int AudioCDReader::compareElements (const File& first, const File& second)
  15797. {
  15798. const int firstTrack = getTrackNumber (first);
  15799. const int secondTrack = getTrackNumber (second);
  15800. jassert (firstTrack > 0 && secondTrack > 0);
  15801. return firstTrack - secondTrack;
  15802. }
  15803. void AudioCDReader::refreshTrackLengths()
  15804. {
  15805. tracks.clear();
  15806. trackStartSamples.clear();
  15807. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15808. tracks.sort (*this);
  15809. AiffAudioFormat format;
  15810. int sample = 0;
  15811. for (int i = 0; i < tracks.size(); ++i)
  15812. {
  15813. trackStartSamples.add (sample);
  15814. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15815. if (in != 0)
  15816. {
  15817. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15818. if (r != 0)
  15819. sample += (int) r->lengthInSamples;
  15820. }
  15821. }
  15822. trackStartSamples.add (sample);
  15823. lengthInSamples = sample;
  15824. }
  15825. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15826. int64 startSampleInFile, int numSamples)
  15827. {
  15828. while (numSamples > 0)
  15829. {
  15830. int track = -1;
  15831. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15832. {
  15833. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15834. {
  15835. track = i;
  15836. break;
  15837. }
  15838. }
  15839. if (track < 0)
  15840. return false;
  15841. if (track != currentReaderTrack)
  15842. {
  15843. reader = 0;
  15844. FileInputStream* const in = tracks [track].createInputStream();
  15845. if (in != 0)
  15846. {
  15847. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15848. AiffAudioFormat format;
  15849. reader = format.createReaderFor (bin, true);
  15850. if (reader == 0)
  15851. currentReaderTrack = -1;
  15852. else
  15853. currentReaderTrack = track;
  15854. }
  15855. }
  15856. if (reader == 0)
  15857. return false;
  15858. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15859. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15860. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15861. numSamples -= numAvailable;
  15862. startSampleInFile += numAvailable;
  15863. }
  15864. return true;
  15865. }
  15866. bool AudioCDReader::isCDStillPresent() const
  15867. {
  15868. return volumeDir.exists();
  15869. }
  15870. int AudioCDReader::getNumTracks() const
  15871. {
  15872. return tracks.size();
  15873. }
  15874. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15875. {
  15876. return trackStartSamples [trackNum];
  15877. }
  15878. bool AudioCDReader::isTrackAudio (int trackNum) const
  15879. {
  15880. return tracks [trackNum] != File::nonexistent;
  15881. }
  15882. void AudioCDReader::enableIndexScanning (bool b)
  15883. {
  15884. // any way to do this on a Mac??
  15885. }
  15886. int AudioCDReader::getLastIndex() const
  15887. {
  15888. return 0;
  15889. }
  15890. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15891. {
  15892. return Array <int>();
  15893. }
  15894. int AudioCDReader::getCDDBId()
  15895. {
  15896. return 0; //xxx
  15897. }
  15898. #endif
  15899. END_JUCE_NAMESPACE
  15900. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15901. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15902. BEGIN_JUCE_NAMESPACE
  15903. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15904. const String& formatName_)
  15905. : sampleRate (0),
  15906. bitsPerSample (0),
  15907. lengthInSamples (0),
  15908. numChannels (0),
  15909. usesFloatingPointData (false),
  15910. input (in),
  15911. formatName (formatName_)
  15912. {
  15913. }
  15914. AudioFormatReader::~AudioFormatReader()
  15915. {
  15916. delete input;
  15917. }
  15918. bool AudioFormatReader::read (int** destSamples,
  15919. int numDestChannels,
  15920. int64 startSampleInSource,
  15921. int numSamplesToRead,
  15922. const bool fillLeftoverChannelsWithCopies)
  15923. {
  15924. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  15925. int startOffsetInDestBuffer = 0;
  15926. if (startSampleInSource < 0)
  15927. {
  15928. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  15929. for (int i = numDestChannels; --i >= 0;)
  15930. if (destSamples[i] != 0)
  15931. zeromem (destSamples[i], sizeof (int) * silence);
  15932. startOffsetInDestBuffer += silence;
  15933. numSamplesToRead -= silence;
  15934. startSampleInSource = 0;
  15935. }
  15936. if (numSamplesToRead <= 0)
  15937. return true;
  15938. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  15939. startSampleInSource, numSamplesToRead))
  15940. return false;
  15941. if (numDestChannels > (int) numChannels)
  15942. {
  15943. if (fillLeftoverChannelsWithCopies)
  15944. {
  15945. int* lastFullChannel = destSamples[0];
  15946. for (int i = numDestChannels; --i > 0;)
  15947. {
  15948. if (destSamples[i] != 0)
  15949. {
  15950. lastFullChannel = destSamples[i];
  15951. break;
  15952. }
  15953. }
  15954. if (lastFullChannel != 0)
  15955. for (int i = numChannels; i < numDestChannels; ++i)
  15956. if (destSamples[i] != 0)
  15957. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  15958. }
  15959. else
  15960. {
  15961. for (int i = numChannels; i < numDestChannels; ++i)
  15962. if (destSamples[i] != 0)
  15963. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  15964. }
  15965. }
  15966. return true;
  15967. }
  15968. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  15969. {
  15970. float mn = buffer[0];
  15971. float mx = mn;
  15972. for (int i = 1; i < num; ++i)
  15973. {
  15974. const float s = buffer[i];
  15975. if (s > mx) mx = s;
  15976. if (s < mn) mn = s;
  15977. }
  15978. maxVal = mx;
  15979. minVal = mn;
  15980. }
  15981. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  15982. int64 numSamples,
  15983. float& lowestLeft, float& highestLeft,
  15984. float& lowestRight, float& highestRight)
  15985. {
  15986. if (numSamples <= 0)
  15987. {
  15988. lowestLeft = 0;
  15989. lowestRight = 0;
  15990. highestLeft = 0;
  15991. highestRight = 0;
  15992. return;
  15993. }
  15994. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  15995. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15996. int* tempBuffer[3];
  15997. tempBuffer[0] = (int*) tempSpace.getData();
  15998. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15999. tempBuffer[2] = 0;
  16000. if (usesFloatingPointData)
  16001. {
  16002. float lmin = 1.0e6f;
  16003. float lmax = -lmin;
  16004. float rmin = lmin;
  16005. float rmax = lmax;
  16006. while (numSamples > 0)
  16007. {
  16008. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16009. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16010. numSamples -= numToDo;
  16011. startSampleInFile += numToDo;
  16012. float bufmin, bufmax;
  16013. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  16014. lmin = jmin (lmin, bufmin);
  16015. lmax = jmax (lmax, bufmax);
  16016. if (numChannels > 1)
  16017. {
  16018. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  16019. rmin = jmin (rmin, bufmin);
  16020. rmax = jmax (rmax, bufmax);
  16021. }
  16022. }
  16023. if (numChannels <= 1)
  16024. {
  16025. rmax = lmax;
  16026. rmin = lmin;
  16027. }
  16028. lowestLeft = lmin;
  16029. highestLeft = lmax;
  16030. lowestRight = rmin;
  16031. highestRight = rmax;
  16032. }
  16033. else
  16034. {
  16035. int lmax = std::numeric_limits<int>::min();
  16036. int lmin = std::numeric_limits<int>::max();
  16037. int rmax = std::numeric_limits<int>::min();
  16038. int rmin = std::numeric_limits<int>::max();
  16039. while (numSamples > 0)
  16040. {
  16041. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16042. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16043. numSamples -= numToDo;
  16044. startSampleInFile += numToDo;
  16045. for (int j = numChannels; --j >= 0;)
  16046. {
  16047. int bufMax = std::numeric_limits<int>::min();
  16048. int bufMin = std::numeric_limits<int>::max();
  16049. const int* const b = tempBuffer[j];
  16050. for (int i = 0; i < numToDo; ++i)
  16051. {
  16052. const int samp = b[i];
  16053. if (samp < bufMin)
  16054. bufMin = samp;
  16055. if (samp > bufMax)
  16056. bufMax = samp;
  16057. }
  16058. if (j == 0)
  16059. {
  16060. lmax = jmax (lmax, bufMax);
  16061. lmin = jmin (lmin, bufMin);
  16062. }
  16063. else
  16064. {
  16065. rmax = jmax (rmax, bufMax);
  16066. rmin = jmin (rmin, bufMin);
  16067. }
  16068. }
  16069. }
  16070. if (numChannels <= 1)
  16071. {
  16072. rmax = lmax;
  16073. rmin = lmin;
  16074. }
  16075. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  16076. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  16077. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  16078. highestRight = rmax / (float) std::numeric_limits<int>::max();
  16079. }
  16080. }
  16081. int64 AudioFormatReader::searchForLevel (int64 startSample,
  16082. int64 numSamplesToSearch,
  16083. const double magnitudeRangeMinimum,
  16084. const double magnitudeRangeMaximum,
  16085. const int minimumConsecutiveSamples)
  16086. {
  16087. if (numSamplesToSearch == 0)
  16088. return -1;
  16089. const int bufferSize = 4096;
  16090. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16091. int* tempBuffer[3];
  16092. tempBuffer[0] = (int*) tempSpace.getData();
  16093. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16094. tempBuffer[2] = 0;
  16095. int consecutive = 0;
  16096. int64 firstMatchPos = -1;
  16097. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  16098. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  16099. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  16100. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16101. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16102. while (numSamplesToSearch != 0)
  16103. {
  16104. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16105. int64 bufferStart = startSample;
  16106. if (numSamplesToSearch < 0)
  16107. bufferStart -= numThisTime;
  16108. if (bufferStart >= (int) lengthInSamples)
  16109. break;
  16110. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16111. int num = numThisTime;
  16112. while (--num >= 0)
  16113. {
  16114. if (numSamplesToSearch < 0)
  16115. --startSample;
  16116. bool matches = false;
  16117. const int index = (int) (startSample - bufferStart);
  16118. if (usesFloatingPointData)
  16119. {
  16120. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16121. if (sample1 >= magnitudeRangeMinimum
  16122. && sample1 <= magnitudeRangeMaximum)
  16123. {
  16124. matches = true;
  16125. }
  16126. else if (numChannels > 1)
  16127. {
  16128. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16129. matches = (sample2 >= magnitudeRangeMinimum
  16130. && sample2 <= magnitudeRangeMaximum);
  16131. }
  16132. }
  16133. else
  16134. {
  16135. const int sample1 = abs (tempBuffer[0] [index]);
  16136. if (sample1 >= intMagnitudeRangeMinimum
  16137. && sample1 <= intMagnitudeRangeMaximum)
  16138. {
  16139. matches = true;
  16140. }
  16141. else if (numChannels > 1)
  16142. {
  16143. const int sample2 = abs (tempBuffer[1][index]);
  16144. matches = (sample2 >= intMagnitudeRangeMinimum
  16145. && sample2 <= intMagnitudeRangeMaximum);
  16146. }
  16147. }
  16148. if (matches)
  16149. {
  16150. if (firstMatchPos < 0)
  16151. firstMatchPos = startSample;
  16152. if (++consecutive >= minimumConsecutiveSamples)
  16153. {
  16154. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16155. return -1;
  16156. return firstMatchPos;
  16157. }
  16158. }
  16159. else
  16160. {
  16161. consecutive = 0;
  16162. firstMatchPos = -1;
  16163. }
  16164. if (numSamplesToSearch > 0)
  16165. ++startSample;
  16166. }
  16167. if (numSamplesToSearch > 0)
  16168. numSamplesToSearch -= numThisTime;
  16169. else
  16170. numSamplesToSearch += numThisTime;
  16171. }
  16172. return -1;
  16173. }
  16174. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16175. const String& formatName_,
  16176. const double rate,
  16177. const unsigned int numChannels_,
  16178. const unsigned int bitsPerSample_)
  16179. : sampleRate (rate),
  16180. numChannels (numChannels_),
  16181. bitsPerSample (bitsPerSample_),
  16182. usesFloatingPointData (false),
  16183. output (out),
  16184. formatName (formatName_)
  16185. {
  16186. }
  16187. AudioFormatWriter::~AudioFormatWriter()
  16188. {
  16189. delete output;
  16190. }
  16191. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16192. int64 startSample,
  16193. int64 numSamplesToRead)
  16194. {
  16195. const int bufferSize = 16384;
  16196. const int maxChans = 128;
  16197. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16198. int* buffers [maxChans];
  16199. for (int i = maxChans; --i >= 0;)
  16200. buffers[i] = 0;
  16201. if (numSamplesToRead < 0)
  16202. numSamplesToRead = reader.lengthInSamples;
  16203. while (numSamplesToRead > 0)
  16204. {
  16205. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16206. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16207. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16208. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16209. return false;
  16210. if (reader.usesFloatingPointData != isFloatingPoint())
  16211. {
  16212. int** bufferChan = buffers;
  16213. while (*bufferChan != 0)
  16214. {
  16215. int* b = *bufferChan++;
  16216. if (isFloatingPoint())
  16217. {
  16218. // int -> float
  16219. const double factor = 1.0 / std::numeric_limits<int>::max();
  16220. for (int i = 0; i < numToDo; ++i)
  16221. ((float*) b)[i] = (float) (factor * b[i]);
  16222. }
  16223. else
  16224. {
  16225. // float -> int
  16226. for (int i = 0; i < numToDo; ++i)
  16227. {
  16228. const double samp = *(const float*) b;
  16229. if (samp <= -1.0)
  16230. *b++ = std::numeric_limits<int>::min();
  16231. else if (samp >= 1.0)
  16232. *b++ = std::numeric_limits<int>::max();
  16233. else
  16234. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16235. }
  16236. }
  16237. }
  16238. }
  16239. if (! write ((const int**) buffers, numToDo))
  16240. return false;
  16241. numSamplesToRead -= numToDo;
  16242. startSample += numToDo;
  16243. }
  16244. return true;
  16245. }
  16246. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16247. int numSamplesToRead,
  16248. const int samplesPerBlock)
  16249. {
  16250. const int maxChans = 128;
  16251. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16252. int* buffers [maxChans];
  16253. while (numSamplesToRead > 0)
  16254. {
  16255. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16256. AudioSourceChannelInfo info;
  16257. info.buffer = &tempBuffer;
  16258. info.startSample = 0;
  16259. info.numSamples = numToDo;
  16260. info.clearActiveBufferRegion();
  16261. source.getNextAudioBlock (info);
  16262. int i;
  16263. for (i = maxChans; --i >= 0;)
  16264. buffers[i] = 0;
  16265. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16266. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16267. if (! isFloatingPoint())
  16268. {
  16269. int** bufferChan = buffers;
  16270. while (*bufferChan != 0)
  16271. {
  16272. int* b = *bufferChan++;
  16273. // float -> int
  16274. for (int j = numToDo; --j >= 0;)
  16275. {
  16276. const double samp = *(const float*) b;
  16277. if (samp <= -1.0)
  16278. *b++ = std::numeric_limits<int>::min();
  16279. else if (samp >= 1.0)
  16280. *b++ = std::numeric_limits<int>::max();
  16281. else
  16282. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16283. }
  16284. }
  16285. }
  16286. if (! write ((const int**) buffers, numToDo))
  16287. return false;
  16288. numSamplesToRead -= numToDo;
  16289. }
  16290. return true;
  16291. }
  16292. AudioFormat::AudioFormat (const String& name,
  16293. const tchar** const extensions)
  16294. : formatName (name),
  16295. fileExtensions (extensions)
  16296. {
  16297. }
  16298. AudioFormat::~AudioFormat()
  16299. {
  16300. }
  16301. const String& AudioFormat::getFormatName() const
  16302. {
  16303. return formatName;
  16304. }
  16305. const StringArray& AudioFormat::getFileExtensions() const
  16306. {
  16307. return fileExtensions;
  16308. }
  16309. bool AudioFormat::canHandleFile (const File& f)
  16310. {
  16311. for (int i = 0; i < fileExtensions.size(); ++i)
  16312. if (f.hasFileExtension (fileExtensions[i]))
  16313. return true;
  16314. return false;
  16315. }
  16316. bool AudioFormat::isCompressed()
  16317. {
  16318. return false;
  16319. }
  16320. const StringArray AudioFormat::getQualityOptions()
  16321. {
  16322. return StringArray();
  16323. }
  16324. END_JUCE_NAMESPACE
  16325. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16326. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16327. BEGIN_JUCE_NAMESPACE
  16328. AudioFormatManager::AudioFormatManager()
  16329. : defaultFormatIndex (0)
  16330. {
  16331. }
  16332. AudioFormatManager::~AudioFormatManager()
  16333. {
  16334. clearFormats();
  16335. clearSingletonInstance();
  16336. }
  16337. juce_ImplementSingleton (AudioFormatManager);
  16338. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16339. const bool makeThisTheDefaultFormat)
  16340. {
  16341. jassert (newFormat != 0);
  16342. if (newFormat != 0)
  16343. {
  16344. #ifdef JUCE_DEBUG
  16345. for (int i = getNumKnownFormats(); --i >= 0;)
  16346. {
  16347. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16348. {
  16349. jassertfalse // trying to add the same format twice!
  16350. }
  16351. }
  16352. #endif
  16353. if (makeThisTheDefaultFormat)
  16354. defaultFormatIndex = knownFormats.size();
  16355. knownFormats.add (newFormat);
  16356. }
  16357. }
  16358. void AudioFormatManager::registerBasicFormats()
  16359. {
  16360. #if JUCE_MAC
  16361. registerFormat (new AiffAudioFormat(), true);
  16362. registerFormat (new WavAudioFormat(), false);
  16363. #else
  16364. registerFormat (new WavAudioFormat(), true);
  16365. registerFormat (new AiffAudioFormat(), false);
  16366. #endif
  16367. #if JUCE_USE_FLAC
  16368. registerFormat (new FlacAudioFormat(), false);
  16369. #endif
  16370. #if JUCE_USE_OGGVORBIS
  16371. registerFormat (new OggVorbisAudioFormat(), false);
  16372. #endif
  16373. }
  16374. void AudioFormatManager::clearFormats()
  16375. {
  16376. for (int i = getNumKnownFormats(); --i >= 0;)
  16377. delete getKnownFormat(i);
  16378. knownFormats.clear();
  16379. defaultFormatIndex = 0;
  16380. }
  16381. int AudioFormatManager::getNumKnownFormats() const
  16382. {
  16383. return knownFormats.size();
  16384. }
  16385. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16386. {
  16387. return (AudioFormat*) knownFormats [index];
  16388. }
  16389. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16390. {
  16391. return getKnownFormat (defaultFormatIndex);
  16392. }
  16393. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16394. {
  16395. String e (fileExtension);
  16396. if (! e.startsWithChar (T('.')))
  16397. e = T(".") + e;
  16398. for (int i = 0; i < getNumKnownFormats(); ++i)
  16399. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16400. return getKnownFormat(i);
  16401. return 0;
  16402. }
  16403. const String AudioFormatManager::getWildcardForAllFormats() const
  16404. {
  16405. StringArray allExtensions;
  16406. int i;
  16407. for (i = 0; i < getNumKnownFormats(); ++i)
  16408. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16409. allExtensions.trim();
  16410. allExtensions.removeEmptyStrings();
  16411. String s;
  16412. for (i = 0; i < allExtensions.size(); ++i)
  16413. {
  16414. s << T('*');
  16415. if (! allExtensions[i].startsWithChar (T('.')))
  16416. s << T('.');
  16417. s << allExtensions[i];
  16418. if (i < allExtensions.size() - 1)
  16419. s << T(';');
  16420. }
  16421. return s;
  16422. }
  16423. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16424. {
  16425. // you need to actually register some formats before the manager can
  16426. // use them to open a file!
  16427. jassert (knownFormats.size() > 0);
  16428. for (int i = 0; i < getNumKnownFormats(); ++i)
  16429. {
  16430. AudioFormat* const af = getKnownFormat(i);
  16431. if (af->canHandleFile (file))
  16432. {
  16433. InputStream* const in = file.createInputStream();
  16434. if (in != 0)
  16435. {
  16436. AudioFormatReader* const r = af->createReaderFor (in, true);
  16437. if (r != 0)
  16438. return r;
  16439. }
  16440. }
  16441. }
  16442. return 0;
  16443. }
  16444. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16445. {
  16446. // you need to actually register some formats before the manager can
  16447. // use them to open a file!
  16448. jassert (knownFormats.size() > 0);
  16449. ScopedPointer <InputStream> in (audioFileStream);
  16450. if (in != 0)
  16451. {
  16452. const int64 originalStreamPos = in->getPosition();
  16453. for (int i = 0; i < getNumKnownFormats(); ++i)
  16454. {
  16455. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16456. if (r != 0)
  16457. {
  16458. in.release();
  16459. return r;
  16460. }
  16461. in->setPosition (originalStreamPos);
  16462. // the stream that is passed-in must be capable of being repositioned so
  16463. // that all the formats can have a go at opening it.
  16464. jassert (in->getPosition() == originalStreamPos);
  16465. }
  16466. }
  16467. return 0;
  16468. }
  16469. END_JUCE_NAMESPACE
  16470. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16471. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16472. BEGIN_JUCE_NAMESPACE
  16473. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16474. const int64 startSample_,
  16475. const int64 length_,
  16476. const bool deleteSourceWhenDeleted_)
  16477. : AudioFormatReader (0, source_->getFormatName()),
  16478. source (source_),
  16479. startSample (startSample_),
  16480. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16481. {
  16482. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16483. sampleRate = source->sampleRate;
  16484. bitsPerSample = source->bitsPerSample;
  16485. lengthInSamples = length;
  16486. numChannels = source->numChannels;
  16487. usesFloatingPointData = source->usesFloatingPointData;
  16488. }
  16489. AudioSubsectionReader::~AudioSubsectionReader()
  16490. {
  16491. if (deleteSourceWhenDeleted)
  16492. delete source;
  16493. }
  16494. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16495. int64 startSampleInFile, int numSamples)
  16496. {
  16497. if (startSampleInFile + numSamples > length)
  16498. {
  16499. for (int i = numDestChannels; --i >= 0;)
  16500. if (destSamples[i] != 0)
  16501. zeromem (destSamples[i], sizeof (int) * numSamples);
  16502. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16503. if (numSamples <= 0)
  16504. return true;
  16505. }
  16506. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16507. startSampleInFile + startSample, numSamples);
  16508. }
  16509. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16510. int64 numSamples,
  16511. float& lowestLeft,
  16512. float& highestLeft,
  16513. float& lowestRight,
  16514. float& highestRight)
  16515. {
  16516. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16517. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16518. source->readMaxLevels (startSampleInFile + startSample,
  16519. numSamples,
  16520. lowestLeft,
  16521. highestLeft,
  16522. lowestRight,
  16523. highestRight);
  16524. }
  16525. END_JUCE_NAMESPACE
  16526. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16527. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16528. BEGIN_JUCE_NAMESPACE
  16529. const int timeBeforeDeletingReader = 2000;
  16530. struct AudioThumbnailDataFormat
  16531. {
  16532. char thumbnailMagic[4];
  16533. int samplesPerThumbSample;
  16534. int64 totalSamples; // source samples
  16535. int64 numFinishedSamples; // source samples
  16536. int numThumbnailSamples;
  16537. int numChannels;
  16538. int sampleRate;
  16539. char future[16];
  16540. char data[1];
  16541. void swapEndiannessIfNeeded() throw()
  16542. {
  16543. #if JUCE_BIG_ENDIAN
  16544. flip (samplesPerThumbSample);
  16545. flip (totalSamples);
  16546. flip (numFinishedSamples);
  16547. flip (numThumbnailSamples);
  16548. flip (numChannels);
  16549. flip (sampleRate);
  16550. #endif
  16551. }
  16552. private:
  16553. #if JUCE_BIG_ENDIAN
  16554. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16555. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16556. #endif
  16557. };
  16558. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16559. AudioFormatManager& formatManagerToUse_,
  16560. AudioThumbnailCache& cacheToUse)
  16561. : formatManagerToUse (formatManagerToUse_),
  16562. cache (cacheToUse),
  16563. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16564. {
  16565. clear();
  16566. }
  16567. AudioThumbnail::~AudioThumbnail()
  16568. {
  16569. cache.removeThumbnail (this);
  16570. const ScopedLock sl (readerLock);
  16571. reader = 0;
  16572. }
  16573. void AudioThumbnail::setSource (InputSource* const newSource)
  16574. {
  16575. cache.removeThumbnail (this);
  16576. timerCallback(); // stops the timer and deletes the reader
  16577. source = newSource;
  16578. clear();
  16579. if (newSource != 0
  16580. && ! (cache.loadThumb (*this, newSource->hashCode())
  16581. && isFullyLoaded()))
  16582. {
  16583. {
  16584. const ScopedLock sl (readerLock);
  16585. reader = createReader();
  16586. }
  16587. if (reader != 0)
  16588. {
  16589. initialiseFromAudioFile (*reader);
  16590. cache.addThumbnail (this);
  16591. }
  16592. }
  16593. sendChangeMessage (this);
  16594. }
  16595. bool AudioThumbnail::useTimeSlice()
  16596. {
  16597. const ScopedLock sl (readerLock);
  16598. if (isFullyLoaded())
  16599. {
  16600. if (reader != 0)
  16601. startTimer (timeBeforeDeletingReader);
  16602. cache.removeThumbnail (this);
  16603. return false;
  16604. }
  16605. if (reader == 0)
  16606. reader = createReader();
  16607. if (reader != 0)
  16608. {
  16609. readNextBlockFromAudioFile (*reader);
  16610. stopTimer();
  16611. sendChangeMessage (this);
  16612. const bool justFinished = isFullyLoaded();
  16613. if (justFinished)
  16614. cache.storeThumb (*this, source->hashCode());
  16615. return ! justFinished;
  16616. }
  16617. return false;
  16618. }
  16619. AudioFormatReader* AudioThumbnail::createReader() const
  16620. {
  16621. if (source != 0)
  16622. {
  16623. InputStream* const audioFileStream = source->createInputStream();
  16624. if (audioFileStream != 0)
  16625. return formatManagerToUse.createReaderFor (audioFileStream);
  16626. }
  16627. return 0;
  16628. }
  16629. void AudioThumbnail::timerCallback()
  16630. {
  16631. stopTimer();
  16632. const ScopedLock sl (readerLock);
  16633. reader = 0;
  16634. }
  16635. void AudioThumbnail::clear()
  16636. {
  16637. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16638. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16639. d->thumbnailMagic[0] = 'j';
  16640. d->thumbnailMagic[1] = 'a';
  16641. d->thumbnailMagic[2] = 't';
  16642. d->thumbnailMagic[3] = 'm';
  16643. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16644. d->totalSamples = 0;
  16645. d->numFinishedSamples = 0;
  16646. d->numThumbnailSamples = 0;
  16647. d->numChannels = 0;
  16648. d->sampleRate = 0;
  16649. numSamplesCached = 0;
  16650. cacheNeedsRefilling = true;
  16651. }
  16652. void AudioThumbnail::loadFrom (InputStream& input)
  16653. {
  16654. const ScopedLock sl (readerLock);
  16655. data.setSize (0);
  16656. input.readIntoMemoryBlock (data);
  16657. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16658. d->swapEndiannessIfNeeded();
  16659. if (! (d->thumbnailMagic[0] == 'j'
  16660. && d->thumbnailMagic[1] == 'a'
  16661. && d->thumbnailMagic[2] == 't'
  16662. && d->thumbnailMagic[3] == 'm'))
  16663. {
  16664. clear();
  16665. }
  16666. numSamplesCached = 0;
  16667. cacheNeedsRefilling = true;
  16668. }
  16669. void AudioThumbnail::saveTo (OutputStream& output) const
  16670. {
  16671. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16672. d->swapEndiannessIfNeeded();
  16673. output.write (data.getData(), (int) data.getSize());
  16674. d->swapEndiannessIfNeeded();
  16675. }
  16676. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16677. {
  16678. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16679. d->totalSamples = fileReader.lengthInSamples;
  16680. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16681. d->numFinishedSamples = 0;
  16682. d->sampleRate = roundToInt (fileReader.sampleRate);
  16683. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16684. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16685. d = (AudioThumbnailDataFormat*) data.getData();
  16686. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16687. return d->totalSamples > 0;
  16688. }
  16689. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16690. {
  16691. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16692. if (d->numFinishedSamples < d->totalSamples)
  16693. {
  16694. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16695. generateSection (fileReader,
  16696. d->numFinishedSamples,
  16697. numToDo);
  16698. d->numFinishedSamples += numToDo;
  16699. }
  16700. cacheNeedsRefilling = true;
  16701. return (d->numFinishedSamples < d->totalSamples);
  16702. }
  16703. int AudioThumbnail::getNumChannels() const throw()
  16704. {
  16705. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16706. jassert (d != 0);
  16707. return d->numChannels;
  16708. }
  16709. double AudioThumbnail::getTotalLength() const throw()
  16710. {
  16711. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16712. jassert (d != 0);
  16713. if (d->sampleRate > 0)
  16714. return d->totalSamples / (double)d->sampleRate;
  16715. else
  16716. return 0.0;
  16717. }
  16718. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16719. int64 startSample,
  16720. int numSamples)
  16721. {
  16722. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16723. jassert (d != 0);
  16724. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16725. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16726. char* l = getChannelData (0);
  16727. char* r = getChannelData (1);
  16728. for (int i = firstDataPos; i < lastDataPos; ++i)
  16729. {
  16730. const int sourceStart = i * d->samplesPerThumbSample;
  16731. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16732. float lowestLeft, highestLeft, lowestRight, highestRight;
  16733. fileReader.readMaxLevels (sourceStart,
  16734. sourceEnd - sourceStart,
  16735. lowestLeft,
  16736. highestLeft,
  16737. lowestRight,
  16738. highestRight);
  16739. int n = i * 2;
  16740. if (r != 0)
  16741. {
  16742. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16743. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16744. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16745. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16746. }
  16747. else
  16748. {
  16749. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16750. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16751. }
  16752. }
  16753. }
  16754. char* AudioThumbnail::getChannelData (int channel) const
  16755. {
  16756. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16757. jassert (d != 0);
  16758. if (channel >= 0 && channel < d->numChannels)
  16759. return d->data + (channel * 2 * d->numThumbnailSamples);
  16760. return 0;
  16761. }
  16762. bool AudioThumbnail::isFullyLoaded() const throw()
  16763. {
  16764. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16765. jassert (d != 0);
  16766. return d->numFinishedSamples >= d->totalSamples;
  16767. }
  16768. void AudioThumbnail::refillCache (const int numSamples,
  16769. double startTime,
  16770. const double timePerPixel)
  16771. {
  16772. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16773. jassert (d != 0);
  16774. if (numSamples <= 0
  16775. || timePerPixel <= 0.0
  16776. || d->sampleRate <= 0)
  16777. {
  16778. numSamplesCached = 0;
  16779. cacheNeedsRefilling = true;
  16780. return;
  16781. }
  16782. if (numSamples == numSamplesCached
  16783. && numChannelsCached == d->numChannels
  16784. && startTime == cachedStart
  16785. && timePerPixel == cachedTimePerPixel
  16786. && ! cacheNeedsRefilling)
  16787. {
  16788. return;
  16789. }
  16790. numSamplesCached = numSamples;
  16791. numChannelsCached = d->numChannels;
  16792. cachedStart = startTime;
  16793. cachedTimePerPixel = timePerPixel;
  16794. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16795. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16796. const ScopedLock sl (readerLock);
  16797. cacheNeedsRefilling = false;
  16798. if (needExtraDetail && reader == 0)
  16799. reader = createReader();
  16800. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16801. {
  16802. startTimer (timeBeforeDeletingReader);
  16803. char* cacheData = (char*) cachedLevels.getData();
  16804. int sample = roundToInt (startTime * d->sampleRate);
  16805. for (int i = numSamples; --i >= 0;)
  16806. {
  16807. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16808. if (sample >= 0)
  16809. {
  16810. if (sample >= reader->lengthInSamples)
  16811. break;
  16812. float lmin, lmax, rmin, rmax;
  16813. reader->readMaxLevels (sample,
  16814. jmax (1, nextSample - sample),
  16815. lmin, lmax, rmin, rmax);
  16816. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16817. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16818. if (numChannelsCached > 1)
  16819. {
  16820. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16821. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16822. }
  16823. cacheData += 2 * numChannelsCached;
  16824. }
  16825. startTime += timePerPixel;
  16826. sample = nextSample;
  16827. }
  16828. }
  16829. else
  16830. {
  16831. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16832. {
  16833. char* const channelData = getChannelData (channelNum);
  16834. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  16835. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16836. startTime = cachedStart;
  16837. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16838. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16839. for (int i = numSamples; --i >= 0;)
  16840. {
  16841. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16842. if (sample >= 0 && channelData != 0)
  16843. {
  16844. char mx = -128;
  16845. char mn = 127;
  16846. while (sample <= nextSample)
  16847. {
  16848. if (sample >= numFinished)
  16849. break;
  16850. const int n = sample << 1;
  16851. const char sampMin = channelData [n];
  16852. const char sampMax = channelData [n + 1];
  16853. if (sampMin < mn)
  16854. mn = sampMin;
  16855. if (sampMax > mx)
  16856. mx = sampMax;
  16857. ++sample;
  16858. }
  16859. if (mn <= mx)
  16860. {
  16861. cacheData[0] = mn;
  16862. cacheData[1] = mx;
  16863. }
  16864. else
  16865. {
  16866. cacheData[0] = 1;
  16867. cacheData[1] = 0;
  16868. }
  16869. }
  16870. else
  16871. {
  16872. cacheData[0] = 1;
  16873. cacheData[1] = 0;
  16874. }
  16875. cacheData += numChannelsCached * 2;
  16876. startTime += timePerPixel;
  16877. sample = nextSample;
  16878. }
  16879. }
  16880. }
  16881. }
  16882. void AudioThumbnail::drawChannel (Graphics& g,
  16883. int x, int y, int w, int h,
  16884. double startTime,
  16885. double endTime,
  16886. int channelNum,
  16887. const float verticalZoomFactor)
  16888. {
  16889. refillCache (w, startTime, (endTime - startTime) / w);
  16890. if (numSamplesCached >= w
  16891. && channelNum >= 0
  16892. && channelNum < numChannelsCached)
  16893. {
  16894. const float topY = (float) y;
  16895. const float bottomY = topY + h;
  16896. const float midY = topY + h * 0.5f;
  16897. const float vscale = verticalZoomFactor * h / 256.0f;
  16898. const Rectangle<int> clip (g.getClipBounds());
  16899. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16900. w -= skipLeft;
  16901. x += skipLeft;
  16902. const char* cacheData = ((const char*) cachedLevels.getData())
  16903. + (channelNum << 1)
  16904. + skipLeft * (numChannelsCached << 1);
  16905. while (--w >= 0)
  16906. {
  16907. const char mn = cacheData[0];
  16908. const char mx = cacheData[1];
  16909. cacheData += numChannelsCached << 1;
  16910. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  16911. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  16912. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  16913. ++x;
  16914. if (x >= clip.getRight())
  16915. break;
  16916. }
  16917. }
  16918. }
  16919. END_JUCE_NAMESPACE
  16920. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  16921. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  16922. BEGIN_JUCE_NAMESPACE
  16923. struct ThumbnailCacheEntry
  16924. {
  16925. int64 hash;
  16926. uint32 lastUsed;
  16927. MemoryBlock data;
  16928. juce_UseDebuggingNewOperator
  16929. };
  16930. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  16931. : TimeSliceThread (T("thumb cache")),
  16932. maxNumThumbsToStore (maxNumThumbsToStore_)
  16933. {
  16934. startThread (2);
  16935. }
  16936. AudioThumbnailCache::~AudioThumbnailCache()
  16937. {
  16938. }
  16939. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  16940. {
  16941. for (int i = thumbs.size(); --i >= 0;)
  16942. {
  16943. if (thumbs[i]->hash == hashCode)
  16944. {
  16945. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  16946. thumbs[i]->data.getSize(),
  16947. false);
  16948. thumb.loadFrom (in);
  16949. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  16950. return true;
  16951. }
  16952. }
  16953. return false;
  16954. }
  16955. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  16956. const int64 hashCode)
  16957. {
  16958. MemoryOutputStream out;
  16959. thumb.saveTo (out);
  16960. ThumbnailCacheEntry* te = 0;
  16961. for (int i = thumbs.size(); --i >= 0;)
  16962. {
  16963. if (thumbs[i]->hash == hashCode)
  16964. {
  16965. te = thumbs[i];
  16966. break;
  16967. }
  16968. }
  16969. if (te == 0)
  16970. {
  16971. te = new ThumbnailCacheEntry();
  16972. te->hash = hashCode;
  16973. if (thumbs.size() < maxNumThumbsToStore)
  16974. {
  16975. thumbs.add (te);
  16976. }
  16977. else
  16978. {
  16979. int oldest = 0;
  16980. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  16981. int i;
  16982. for (i = thumbs.size(); --i >= 0;)
  16983. if (thumbs[i]->lastUsed < oldestTime)
  16984. oldest = i;
  16985. thumbs.set (i, te);
  16986. }
  16987. }
  16988. te->lastUsed = Time::getMillisecondCounter();
  16989. te->data.setSize (0);
  16990. te->data.append (out.getData(), out.getDataSize());
  16991. }
  16992. void AudioThumbnailCache::clear()
  16993. {
  16994. thumbs.clear();
  16995. }
  16996. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  16997. {
  16998. addTimeSliceClient (thumb);
  16999. }
  17000. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  17001. {
  17002. removeTimeSliceClient (thumb);
  17003. }
  17004. END_JUCE_NAMESPACE
  17005. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  17006. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17007. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  17008. #if ! JUCE_WINDOWS
  17009. #include <QuickTime/Movies.h>
  17010. #include <QuickTime/QTML.h>
  17011. #include <QuickTime/QuickTimeComponents.h>
  17012. #include <QuickTime/MediaHandlers.h>
  17013. #include <QuickTime/ImageCodec.h>
  17014. #else
  17015. #if JUCE_MSVC
  17016. #pragma warning (push)
  17017. #pragma warning (disable : 4100)
  17018. #endif
  17019. #include <Movies.h>
  17020. #include <QTML.h>
  17021. #include <QuickTimeComponents.h>
  17022. #include <MediaHandlers.h>
  17023. #include <ImageCodec.h>
  17024. #if JUCE_MSVC
  17025. #pragma warning (pop)
  17026. #endif
  17027. #endif
  17028. BEGIN_JUCE_NAMESPACE
  17029. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  17030. static const char* const quickTimeFormatName = "QuickTime file";
  17031. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  17032. class QTAudioReader : public AudioFormatReader
  17033. {
  17034. public:
  17035. QTAudioReader (InputStream* const input_, const int trackNum_)
  17036. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  17037. ok (false),
  17038. movie (0),
  17039. trackNum (trackNum_),
  17040. lastSampleRead (0),
  17041. lastThreadId (0),
  17042. extractor (0),
  17043. dataHandle (0)
  17044. {
  17045. bufferList.calloc (256, 1);
  17046. #ifdef WIN32
  17047. if (InitializeQTML (0) != noErr)
  17048. return;
  17049. #endif
  17050. if (EnterMovies() != noErr)
  17051. return;
  17052. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  17053. if (! opened)
  17054. return;
  17055. {
  17056. const int numTracks = GetMovieTrackCount (movie);
  17057. int trackCount = 0;
  17058. for (int i = 1; i <= numTracks; ++i)
  17059. {
  17060. track = GetMovieIndTrack (movie, i);
  17061. media = GetTrackMedia (track);
  17062. OSType mediaType;
  17063. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  17064. if (mediaType == SoundMediaType
  17065. && trackCount++ == trackNum_)
  17066. {
  17067. ok = true;
  17068. break;
  17069. }
  17070. }
  17071. }
  17072. if (! ok)
  17073. return;
  17074. ok = false;
  17075. lengthInSamples = GetMediaDecodeDuration (media);
  17076. usesFloatingPointData = false;
  17077. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  17078. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  17079. / GetMediaTimeScale (media);
  17080. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  17081. unsigned long output_layout_size;
  17082. err = MovieAudioExtractionGetPropertyInfo (extractor,
  17083. kQTPropertyClass_MovieAudioExtraction_Audio,
  17084. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17085. 0, &output_layout_size, 0);
  17086. if (err != noErr)
  17087. return;
  17088. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  17089. qt_audio_channel_layout.calloc (output_layout_size, 1);
  17090. err = MovieAudioExtractionGetProperty (extractor,
  17091. kQTPropertyClass_MovieAudioExtraction_Audio,
  17092. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17093. output_layout_size, qt_audio_channel_layout, 0);
  17094. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  17095. err = MovieAudioExtractionSetProperty (extractor,
  17096. kQTPropertyClass_MovieAudioExtraction_Audio,
  17097. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17098. output_layout_size,
  17099. qt_audio_channel_layout);
  17100. err = MovieAudioExtractionGetProperty (extractor,
  17101. kQTPropertyClass_MovieAudioExtraction_Audio,
  17102. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17103. sizeof (inputStreamDesc),
  17104. &inputStreamDesc, 0);
  17105. if (err != noErr)
  17106. return;
  17107. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17108. | kAudioFormatFlagIsPacked
  17109. | kAudioFormatFlagsNativeEndian;
  17110. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17111. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17112. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17113. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17114. err = MovieAudioExtractionSetProperty (extractor,
  17115. kQTPropertyClass_MovieAudioExtraction_Audio,
  17116. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17117. sizeof (inputStreamDesc),
  17118. &inputStreamDesc);
  17119. if (err != noErr)
  17120. return;
  17121. Boolean allChannelsDiscrete = false;
  17122. err = MovieAudioExtractionSetProperty (extractor,
  17123. kQTPropertyClass_MovieAudioExtraction_Movie,
  17124. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17125. sizeof (allChannelsDiscrete),
  17126. &allChannelsDiscrete);
  17127. if (err != noErr)
  17128. return;
  17129. bufferList->mNumberBuffers = 1;
  17130. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17131. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17132. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17133. sampleRate = inputStreamDesc.mSampleRate;
  17134. bitsPerSample = 16;
  17135. numChannels = inputStreamDesc.mChannelsPerFrame;
  17136. detachThread();
  17137. ok = true;
  17138. }
  17139. ~QTAudioReader()
  17140. {
  17141. if (dataHandle != 0)
  17142. DisposeHandle (dataHandle);
  17143. if (extractor != 0)
  17144. {
  17145. MovieAudioExtractionEnd (extractor);
  17146. extractor = 0;
  17147. }
  17148. checkThreadIsAttached();
  17149. DisposeMovie (movie);
  17150. juce_free (bufferList->mBuffers[0].mData);
  17151. #if JUCE_MAC
  17152. ExitMoviesOnThread ();
  17153. #endif
  17154. }
  17155. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17156. int64 startSampleInFile, int numSamples)
  17157. {
  17158. checkThreadIsAttached();
  17159. while (numSamples > 0)
  17160. {
  17161. if (! loadFrame ((int) startSampleInFile))
  17162. return false;
  17163. const int numToDo = jmin (numSamples, samplesPerFrame);
  17164. for (int j = numDestChannels; --j >= 0;)
  17165. {
  17166. if (destSamples[j] != 0)
  17167. {
  17168. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17169. for (int i = 0; i < numToDo; ++i)
  17170. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17171. }
  17172. }
  17173. startOffsetInDestBuffer += numToDo;
  17174. startSampleInFile += numToDo;
  17175. numSamples -= numToDo;
  17176. }
  17177. detachThread();
  17178. return true;
  17179. }
  17180. bool loadFrame (const int sampleNum)
  17181. {
  17182. if (lastSampleRead != sampleNum)
  17183. {
  17184. TimeRecord time;
  17185. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17186. time.base = 0;
  17187. time.value.hi = 0;
  17188. time.value.lo = (UInt32) sampleNum;
  17189. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17190. kQTPropertyClass_MovieAudioExtraction_Movie,
  17191. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17192. sizeof (time), &time);
  17193. if (err != noErr)
  17194. return false;
  17195. }
  17196. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17197. UInt32 outFlags = 0;
  17198. UInt32 actualNumSamples = samplesPerFrame;
  17199. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17200. bufferList, &outFlags);
  17201. lastSampleRead = sampleNum + samplesPerFrame;
  17202. return err == noErr;
  17203. }
  17204. juce_UseDebuggingNewOperator
  17205. bool ok;
  17206. private:
  17207. Movie movie;
  17208. Media media;
  17209. Track track;
  17210. const int trackNum;
  17211. double trackUnitsPerFrame;
  17212. int samplesPerFrame;
  17213. int lastSampleRead;
  17214. Thread::ThreadID lastThreadId;
  17215. MovieAudioExtractionRef extractor;
  17216. AudioStreamBasicDescription inputStreamDesc;
  17217. HeapBlock <AudioBufferList> bufferList;
  17218. Handle dataHandle;
  17219. void checkThreadIsAttached()
  17220. {
  17221. #if JUCE_MAC
  17222. if (Thread::getCurrentThreadId() != lastThreadId)
  17223. EnterMoviesOnThread (0);
  17224. AttachMovieToCurrentThread (movie);
  17225. #endif
  17226. }
  17227. void detachThread()
  17228. {
  17229. #if JUCE_MAC
  17230. DetachMovieFromCurrentThread (movie);
  17231. #endif
  17232. }
  17233. QTAudioReader (const QTAudioReader&);
  17234. QTAudioReader& operator= (const QTAudioReader&);
  17235. };
  17236. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17237. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17238. {
  17239. }
  17240. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17241. {
  17242. }
  17243. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17244. {
  17245. return Array<int>();
  17246. }
  17247. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17248. {
  17249. return Array<int>();
  17250. }
  17251. bool QuickTimeAudioFormat::canDoStereo()
  17252. {
  17253. return true;
  17254. }
  17255. bool QuickTimeAudioFormat::canDoMono()
  17256. {
  17257. return true;
  17258. }
  17259. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17260. const bool deleteStreamIfOpeningFails)
  17261. {
  17262. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17263. if (r->ok)
  17264. return r.release();
  17265. if (! deleteStreamIfOpeningFails)
  17266. r->input = 0;
  17267. return 0;
  17268. }
  17269. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17270. double /*sampleRateToUse*/,
  17271. unsigned int /*numberOfChannels*/,
  17272. int /*bitsPerSample*/,
  17273. const StringPairArray& /*metadataValues*/,
  17274. int /*qualityOptionIndex*/)
  17275. {
  17276. jassertfalse // not yet implemented!
  17277. return 0;
  17278. }
  17279. END_JUCE_NAMESPACE
  17280. #endif
  17281. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17282. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17283. BEGIN_JUCE_NAMESPACE
  17284. static const char* const wavFormatName = "WAV file";
  17285. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17286. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17287. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17288. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17289. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17290. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17291. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17292. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17293. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17294. const String& originator,
  17295. const String& originatorRef,
  17296. const Time& date,
  17297. const int64 timeReferenceSamples,
  17298. const String& codingHistory)
  17299. {
  17300. StringPairArray m;
  17301. m.set (bwavDescription, description);
  17302. m.set (bwavOriginator, originator);
  17303. m.set (bwavOriginatorRef, originatorRef);
  17304. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17305. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17306. m.set (bwavTimeReference, String (timeReferenceSamples));
  17307. m.set (bwavCodingHistory, codingHistory);
  17308. return m;
  17309. }
  17310. #if JUCE_MSVC
  17311. #pragma pack (push, 1)
  17312. #define PACKED
  17313. #elif JUCE_GCC
  17314. #define PACKED __attribute__((packed))
  17315. #else
  17316. #define PACKED
  17317. #endif
  17318. struct BWAVChunk
  17319. {
  17320. char description [256];
  17321. char originator [32];
  17322. char originatorRef [32];
  17323. char originationDate [10];
  17324. char originationTime [8];
  17325. uint32 timeRefLow;
  17326. uint32 timeRefHigh;
  17327. uint16 version;
  17328. uint8 umid[64];
  17329. uint8 reserved[190];
  17330. char codingHistory[1];
  17331. void copyTo (StringPairArray& values) const
  17332. {
  17333. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17334. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17335. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17336. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17337. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17338. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17339. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17340. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17341. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17342. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17343. }
  17344. static MemoryBlock createFrom (const StringPairArray& values)
  17345. {
  17346. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17347. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17348. data.fillWith (0);
  17349. BWAVChunk* b = (BWAVChunk*) data.getData();
  17350. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17351. // as they get called in the right order..
  17352. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17353. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17354. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17355. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17356. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17357. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17358. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17359. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17360. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17361. if (b->description[0] != 0
  17362. || b->originator[0] != 0
  17363. || b->originationDate[0] != 0
  17364. || b->originationTime[0] != 0
  17365. || b->codingHistory[0] != 0
  17366. || time != 0)
  17367. {
  17368. return data;
  17369. }
  17370. return MemoryBlock();
  17371. }
  17372. } PACKED;
  17373. struct SMPLChunk
  17374. {
  17375. struct SampleLoop
  17376. {
  17377. uint32 identifier;
  17378. uint32 type;
  17379. uint32 start;
  17380. uint32 end;
  17381. uint32 fraction;
  17382. uint32 playCount;
  17383. } PACKED;
  17384. uint32 manufacturer;
  17385. uint32 product;
  17386. uint32 samplePeriod;
  17387. uint32 midiUnityNote;
  17388. uint32 midiPitchFraction;
  17389. uint32 smpteFormat;
  17390. uint32 smpteOffset;
  17391. uint32 numSampleLoops;
  17392. uint32 samplerData;
  17393. SampleLoop loops[1];
  17394. void copyTo (StringPairArray& values, const int totalSize) const
  17395. {
  17396. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17397. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17398. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17399. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17400. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17401. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17402. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17403. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17404. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17405. for (uint32 i = 0; i < numSampleLoops; ++i)
  17406. {
  17407. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17408. break;
  17409. const String prefix ("Loop" + String(i));
  17410. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17411. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17412. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17413. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17414. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17415. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17416. }
  17417. }
  17418. static MemoryBlock createFrom (const StringPairArray& values)
  17419. {
  17420. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17421. if (numLoops <= 0)
  17422. return MemoryBlock();
  17423. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17424. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17425. data.fillWith (0);
  17426. SMPLChunk* s = (SMPLChunk*) data.getData();
  17427. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17428. // as they get called in the right order..
  17429. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17430. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17431. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17432. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17433. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17434. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17435. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17436. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17437. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17438. for (int i = 0; i < numLoops; ++i)
  17439. {
  17440. const String prefix ("Loop" + String(i));
  17441. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17442. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17443. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17444. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17445. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17446. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17447. }
  17448. return data;
  17449. }
  17450. } PACKED;
  17451. struct ExtensibleWavSubFormat
  17452. {
  17453. uint32 data1;
  17454. uint16 data2;
  17455. uint16 data3;
  17456. uint8 data4[8];
  17457. } PACKED;
  17458. #if JUCE_MSVC
  17459. #pragma pack (pop)
  17460. #endif
  17461. #undef PACKED
  17462. class WavAudioFormatReader : public AudioFormatReader
  17463. {
  17464. int bytesPerFrame;
  17465. int64 dataChunkStart, dataLength;
  17466. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17467. WavAudioFormatReader (const WavAudioFormatReader&);
  17468. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17469. public:
  17470. int64 bwavChunkStart, bwavSize;
  17471. WavAudioFormatReader (InputStream* const in)
  17472. : AudioFormatReader (in, TRANS (wavFormatName)),
  17473. dataLength (0),
  17474. bwavChunkStart (0),
  17475. bwavSize (0)
  17476. {
  17477. if (input->readInt() == chunkName ("RIFF"))
  17478. {
  17479. const uint32 len = (uint32) input->readInt();
  17480. const int64 end = input->getPosition() + len;
  17481. bool hasGotType = false;
  17482. bool hasGotData = false;
  17483. if (input->readInt() == chunkName ("WAVE"))
  17484. {
  17485. while (input->getPosition() < end
  17486. && ! input->isExhausted())
  17487. {
  17488. const int chunkType = input->readInt();
  17489. uint32 length = (uint32) input->readInt();
  17490. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17491. if (chunkType == chunkName ("fmt "))
  17492. {
  17493. // read the format chunk
  17494. const unsigned short format = input->readShort();
  17495. const short numChans = input->readShort();
  17496. sampleRate = input->readInt();
  17497. const int bytesPerSec = input->readInt();
  17498. numChannels = numChans;
  17499. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17500. bitsPerSample = 8 * bytesPerFrame / numChans;
  17501. if (format == 3)
  17502. {
  17503. usesFloatingPointData = true;
  17504. }
  17505. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17506. {
  17507. if (length < 40) // too short
  17508. {
  17509. bytesPerFrame = 0;
  17510. }
  17511. else
  17512. {
  17513. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17514. ExtensibleWavSubFormat subFormat;
  17515. subFormat.data1 = input->readInt();
  17516. subFormat.data2 = input->readShort();
  17517. subFormat.data3 = input->readShort();
  17518. input->read (subFormat.data4, sizeof (subFormat.data4));
  17519. const ExtensibleWavSubFormat pcmFormat
  17520. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17521. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17522. {
  17523. const ExtensibleWavSubFormat ambisonicFormat
  17524. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17525. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17526. bytesPerFrame = 0;
  17527. }
  17528. }
  17529. }
  17530. else if (format != 1)
  17531. {
  17532. bytesPerFrame = 0;
  17533. }
  17534. hasGotType = true;
  17535. }
  17536. else if (chunkType == chunkName ("data"))
  17537. {
  17538. // get the data chunk's position
  17539. dataLength = length;
  17540. dataChunkStart = input->getPosition();
  17541. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17542. hasGotData = true;
  17543. }
  17544. else if (chunkType == chunkName ("bext"))
  17545. {
  17546. bwavChunkStart = input->getPosition();
  17547. bwavSize = length;
  17548. // Broadcast-wav extension chunk..
  17549. HeapBlock <BWAVChunk> bwav;
  17550. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17551. input->read (bwav, length);
  17552. bwav->copyTo (metadataValues);
  17553. }
  17554. else if (chunkType == chunkName ("smpl"))
  17555. {
  17556. HeapBlock <SMPLChunk> smpl;
  17557. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17558. input->read (smpl, length);
  17559. smpl->copyTo (metadataValues, length);
  17560. }
  17561. else if (chunkEnd <= input->getPosition())
  17562. {
  17563. break;
  17564. }
  17565. input->setPosition (chunkEnd);
  17566. }
  17567. }
  17568. }
  17569. }
  17570. ~WavAudioFormatReader()
  17571. {
  17572. }
  17573. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17574. int64 startSampleInFile, int numSamples)
  17575. {
  17576. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17577. if (samplesAvailable < numSamples)
  17578. {
  17579. for (int i = numDestChannels; --i >= 0;)
  17580. if (destSamples[i] != 0)
  17581. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17582. numSamples = (int) samplesAvailable;
  17583. }
  17584. if (numSamples <= 0)
  17585. return true;
  17586. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17587. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17588. char tempBuffer [tempBufSize];
  17589. while (numSamples > 0)
  17590. {
  17591. int* left = destSamples[0];
  17592. if (left != 0)
  17593. left += startOffsetInDestBuffer;
  17594. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17595. if (right != 0)
  17596. right += startOffsetInDestBuffer;
  17597. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17598. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17599. if (bytesRead < numThisTime * bytesPerFrame)
  17600. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17601. if (bitsPerSample == 16)
  17602. {
  17603. const short* src = (const short*) tempBuffer;
  17604. if (numChannels > 1)
  17605. {
  17606. if (left == 0)
  17607. {
  17608. for (int i = numThisTime; --i >= 0;)
  17609. {
  17610. ++src;
  17611. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17612. }
  17613. }
  17614. else if (right == 0)
  17615. {
  17616. for (int i = numThisTime; --i >= 0;)
  17617. {
  17618. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17619. ++src;
  17620. }
  17621. }
  17622. else
  17623. {
  17624. for (int i = numThisTime; --i >= 0;)
  17625. {
  17626. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17627. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17628. }
  17629. }
  17630. }
  17631. else
  17632. {
  17633. for (int i = numThisTime; --i >= 0;)
  17634. {
  17635. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17636. }
  17637. }
  17638. }
  17639. else if (bitsPerSample == 24)
  17640. {
  17641. const char* src = (const char*) tempBuffer;
  17642. if (numChannels > 1)
  17643. {
  17644. if (left == 0)
  17645. {
  17646. for (int i = numThisTime; --i >= 0;)
  17647. {
  17648. src += 3;
  17649. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17650. src += 3;
  17651. }
  17652. }
  17653. else if (right == 0)
  17654. {
  17655. for (int i = numThisTime; --i >= 0;)
  17656. {
  17657. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17658. src += 6;
  17659. }
  17660. }
  17661. else
  17662. {
  17663. for (int i = 0; i < numThisTime; ++i)
  17664. {
  17665. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17666. src += 3;
  17667. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17668. src += 3;
  17669. }
  17670. }
  17671. }
  17672. else
  17673. {
  17674. for (int i = 0; i < numThisTime; ++i)
  17675. {
  17676. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17677. src += 3;
  17678. }
  17679. }
  17680. }
  17681. else if (bitsPerSample == 32)
  17682. {
  17683. const unsigned int* src = (const unsigned int*) tempBuffer;
  17684. unsigned int* l = (unsigned int*) left;
  17685. unsigned int* r = (unsigned int*) right;
  17686. if (numChannels > 1)
  17687. {
  17688. if (l == 0)
  17689. {
  17690. for (int i = numThisTime; --i >= 0;)
  17691. {
  17692. ++src;
  17693. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17694. }
  17695. }
  17696. else if (r == 0)
  17697. {
  17698. for (int i = numThisTime; --i >= 0;)
  17699. {
  17700. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17701. ++src;
  17702. }
  17703. }
  17704. else
  17705. {
  17706. for (int i = numThisTime; --i >= 0;)
  17707. {
  17708. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17709. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17710. }
  17711. }
  17712. }
  17713. else
  17714. {
  17715. for (int i = numThisTime; --i >= 0;)
  17716. {
  17717. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17718. }
  17719. }
  17720. left = (int*)l;
  17721. right = (int*)r;
  17722. }
  17723. else if (bitsPerSample == 8)
  17724. {
  17725. const unsigned char* src = (const unsigned char*) tempBuffer;
  17726. if (numChannels > 1)
  17727. {
  17728. if (left == 0)
  17729. {
  17730. for (int i = numThisTime; --i >= 0;)
  17731. {
  17732. ++src;
  17733. *right++ = ((int) *src++ - 128) << 24;
  17734. }
  17735. }
  17736. else if (right == 0)
  17737. {
  17738. for (int i = numThisTime; --i >= 0;)
  17739. {
  17740. *left++ = ((int) *src++ - 128) << 24;
  17741. ++src;
  17742. }
  17743. }
  17744. else
  17745. {
  17746. for (int i = numThisTime; --i >= 0;)
  17747. {
  17748. *left++ = ((int) *src++ - 128) << 24;
  17749. *right++ = ((int) *src++ - 128) << 24;
  17750. }
  17751. }
  17752. }
  17753. else
  17754. {
  17755. for (int i = numThisTime; --i >= 0;)
  17756. {
  17757. *left++ = ((int)*src++ - 128) << 24;
  17758. }
  17759. }
  17760. }
  17761. startOffsetInDestBuffer += numThisTime;
  17762. numSamples -= numThisTime;
  17763. }
  17764. if (numSamples > 0)
  17765. {
  17766. for (int i = numDestChannels; --i >= 0;)
  17767. if (destSamples[i] != 0)
  17768. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17769. sizeof (int) * numSamples);
  17770. }
  17771. return true;
  17772. }
  17773. juce_UseDebuggingNewOperator
  17774. };
  17775. class WavAudioFormatWriter : public AudioFormatWriter
  17776. {
  17777. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17778. uint32 lengthInSamples, bytesWritten;
  17779. int64 headerPosition;
  17780. bool writeFailed;
  17781. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17782. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17783. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17784. void writeHeader()
  17785. {
  17786. const bool seekedOk = output->setPosition (headerPosition);
  17787. (void) seekedOk;
  17788. // if this fails, you've given it an output stream that can't seek! It needs
  17789. // to be able to seek back to write the header
  17790. jassert (seekedOk);
  17791. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17792. output->writeInt (chunkName ("RIFF"));
  17793. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17794. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17795. output->writeInt (chunkName ("WAVE"));
  17796. output->writeInt (chunkName ("fmt "));
  17797. output->writeInt (16);
  17798. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17799. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17800. output->writeShort ((short) numChannels);
  17801. output->writeInt ((int) sampleRate);
  17802. output->writeInt (bytesPerFrame * (int) sampleRate);
  17803. output->writeShort ((short) bytesPerFrame);
  17804. output->writeShort ((short) bitsPerSample);
  17805. if (bwavChunk.getSize() > 0)
  17806. {
  17807. output->writeInt (chunkName ("bext"));
  17808. output->writeInt ((int) bwavChunk.getSize());
  17809. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17810. }
  17811. if (smplChunk.getSize() > 0)
  17812. {
  17813. output->writeInt (chunkName ("smpl"));
  17814. output->writeInt ((int) smplChunk.getSize());
  17815. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17816. }
  17817. output->writeInt (chunkName ("data"));
  17818. output->writeInt (lengthInSamples * bytesPerFrame);
  17819. usesFloatingPointData = (bitsPerSample == 32);
  17820. }
  17821. public:
  17822. WavAudioFormatWriter (OutputStream* const out,
  17823. const double sampleRate_,
  17824. const unsigned int numChannels_,
  17825. const int bits,
  17826. const StringPairArray& metadataValues)
  17827. : AudioFormatWriter (out,
  17828. TRANS (wavFormatName),
  17829. sampleRate_,
  17830. numChannels_,
  17831. bits),
  17832. lengthInSamples (0),
  17833. bytesWritten (0),
  17834. writeFailed (false)
  17835. {
  17836. if (metadataValues.size() > 0)
  17837. {
  17838. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17839. smplChunk = SMPLChunk::createFrom (metadataValues);
  17840. }
  17841. headerPosition = out->getPosition();
  17842. writeHeader();
  17843. }
  17844. ~WavAudioFormatWriter()
  17845. {
  17846. writeHeader();
  17847. }
  17848. bool write (const int** data, int numSamples)
  17849. {
  17850. if (writeFailed)
  17851. return false;
  17852. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17853. tempBlock.ensureSize (bytes, false);
  17854. char* buffer = (char*) tempBlock.getData();
  17855. const int* left = data[0];
  17856. const int* right = data[1];
  17857. if (right == 0)
  17858. right = left;
  17859. if (bitsPerSample == 16)
  17860. {
  17861. short* b = (short*) buffer;
  17862. if (numChannels > 1)
  17863. {
  17864. for (int i = numSamples; --i >= 0;)
  17865. {
  17866. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17867. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17868. }
  17869. }
  17870. else
  17871. {
  17872. for (int i = numSamples; --i >= 0;)
  17873. {
  17874. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17875. }
  17876. }
  17877. }
  17878. else if (bitsPerSample == 24)
  17879. {
  17880. char* b = (char*) buffer;
  17881. if (numChannels > 1)
  17882. {
  17883. for (int i = numSamples; --i >= 0;)
  17884. {
  17885. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17886. b += 3;
  17887. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17888. b += 3;
  17889. }
  17890. }
  17891. else
  17892. {
  17893. for (int i = numSamples; --i >= 0;)
  17894. {
  17895. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17896. b += 3;
  17897. }
  17898. }
  17899. }
  17900. else if (bitsPerSample == 32)
  17901. {
  17902. unsigned int* b = (unsigned int*) buffer;
  17903. if (numChannels > 1)
  17904. {
  17905. for (int i = numSamples; --i >= 0;)
  17906. {
  17907. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17908. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17909. }
  17910. }
  17911. else
  17912. {
  17913. for (int i = numSamples; --i >= 0;)
  17914. {
  17915. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17916. }
  17917. }
  17918. }
  17919. else if (bitsPerSample == 8)
  17920. {
  17921. unsigned char* b = (unsigned char*) buffer;
  17922. if (numChannels > 1)
  17923. {
  17924. for (int i = numSamples; --i >= 0;)
  17925. {
  17926. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17927. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17928. }
  17929. }
  17930. else
  17931. {
  17932. for (int i = numSamples; --i >= 0;)
  17933. {
  17934. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17935. }
  17936. }
  17937. }
  17938. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17939. || ! output->write (buffer, bytes))
  17940. {
  17941. // failed to write to disk, so let's try writing the header.
  17942. // If it's just run out of disk space, then if it does manage
  17943. // to write the header, we'll still have a useable file..
  17944. writeHeader();
  17945. writeFailed = true;
  17946. return false;
  17947. }
  17948. else
  17949. {
  17950. bytesWritten += bytes;
  17951. lengthInSamples += numSamples;
  17952. return true;
  17953. }
  17954. }
  17955. juce_UseDebuggingNewOperator
  17956. };
  17957. WavAudioFormat::WavAudioFormat()
  17958. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  17959. {
  17960. }
  17961. WavAudioFormat::~WavAudioFormat()
  17962. {
  17963. }
  17964. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17965. {
  17966. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17967. return Array <int> (rates);
  17968. }
  17969. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17970. {
  17971. const int depths[] = { 8, 16, 24, 32, 0 };
  17972. return Array <int> (depths);
  17973. }
  17974. bool WavAudioFormat::canDoStereo()
  17975. {
  17976. return true;
  17977. }
  17978. bool WavAudioFormat::canDoMono()
  17979. {
  17980. return true;
  17981. }
  17982. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  17983. const bool deleteStreamIfOpeningFails)
  17984. {
  17985. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  17986. if (r->sampleRate != 0)
  17987. return r.release();
  17988. if (! deleteStreamIfOpeningFails)
  17989. r->input = 0;
  17990. return 0;
  17991. }
  17992. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  17993. double sampleRate,
  17994. unsigned int numChannels,
  17995. int bitsPerSample,
  17996. const StringPairArray& metadataValues,
  17997. int /*qualityOptionIndex*/)
  17998. {
  17999. if (getPossibleBitDepths().contains (bitsPerSample))
  18000. {
  18001. return new WavAudioFormatWriter (out,
  18002. sampleRate,
  18003. numChannels,
  18004. bitsPerSample,
  18005. metadataValues);
  18006. }
  18007. return 0;
  18008. }
  18009. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  18010. {
  18011. TemporaryFile tempFile (file);
  18012. WavAudioFormat wav;
  18013. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  18014. if (reader != 0)
  18015. {
  18016. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  18017. if (outStream != 0)
  18018. {
  18019. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  18020. reader->numChannels, reader->bitsPerSample,
  18021. metadata, 0));
  18022. if (writer != 0)
  18023. {
  18024. outStream.release();
  18025. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  18026. writer = 0;
  18027. reader = 0;
  18028. return ok && tempFile.overwriteTargetFileWithTemporary();
  18029. }
  18030. }
  18031. }
  18032. return false;
  18033. }
  18034. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  18035. {
  18036. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  18037. if (reader != 0)
  18038. {
  18039. const int64 bwavPos = reader->bwavChunkStart;
  18040. const int64 bwavSize = reader->bwavSize;
  18041. reader = 0;
  18042. if (bwavSize > 0)
  18043. {
  18044. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  18045. if (chunk.getSize() <= (size_t) bwavSize)
  18046. {
  18047. // the new one will fit in the space available, so write it directly..
  18048. const int64 oldSize = wavFile.getSize();
  18049. {
  18050. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  18051. out->setPosition (bwavPos);
  18052. out->write (chunk.getData(), (int) chunk.getSize());
  18053. out->setPosition (oldSize);
  18054. }
  18055. jassert (wavFile.getSize() == oldSize);
  18056. return true;
  18057. }
  18058. }
  18059. }
  18060. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  18061. }
  18062. END_JUCE_NAMESPACE
  18063. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  18064. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18065. BEGIN_JUCE_NAMESPACE
  18066. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  18067. const bool deleteReaderWhenThisIsDeleted)
  18068. : reader (reader_),
  18069. deleteReader (deleteReaderWhenThisIsDeleted),
  18070. nextPlayPos (0),
  18071. looping (false)
  18072. {
  18073. jassert (reader != 0);
  18074. }
  18075. AudioFormatReaderSource::~AudioFormatReaderSource()
  18076. {
  18077. releaseResources();
  18078. if (deleteReader)
  18079. delete reader;
  18080. }
  18081. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  18082. {
  18083. nextPlayPos = newPosition;
  18084. }
  18085. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  18086. {
  18087. looping = shouldLoop;
  18088. }
  18089. int AudioFormatReaderSource::getNextReadPosition() const
  18090. {
  18091. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18092. : nextPlayPos;
  18093. }
  18094. int AudioFormatReaderSource::getTotalLength() const
  18095. {
  18096. return (int) reader->lengthInSamples;
  18097. }
  18098. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18099. double /*sampleRate*/)
  18100. {
  18101. }
  18102. void AudioFormatReaderSource::releaseResources()
  18103. {
  18104. }
  18105. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18106. {
  18107. if (info.numSamples > 0)
  18108. {
  18109. const int start = nextPlayPos;
  18110. if (looping)
  18111. {
  18112. const int newStart = start % (int) reader->lengthInSamples;
  18113. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18114. if (newEnd > newStart)
  18115. {
  18116. info.buffer->readFromAudioReader (reader,
  18117. info.startSample,
  18118. newEnd - newStart,
  18119. newStart,
  18120. true, true);
  18121. }
  18122. else
  18123. {
  18124. const int endSamps = (int) reader->lengthInSamples - newStart;
  18125. info.buffer->readFromAudioReader (reader,
  18126. info.startSample,
  18127. endSamps,
  18128. newStart,
  18129. true, true);
  18130. info.buffer->readFromAudioReader (reader,
  18131. info.startSample + endSamps,
  18132. newEnd,
  18133. 0,
  18134. true, true);
  18135. }
  18136. nextPlayPos = newEnd;
  18137. }
  18138. else
  18139. {
  18140. info.buffer->readFromAudioReader (reader,
  18141. info.startSample,
  18142. info.numSamples,
  18143. start,
  18144. true, true);
  18145. nextPlayPos += info.numSamples;
  18146. }
  18147. }
  18148. }
  18149. END_JUCE_NAMESPACE
  18150. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18151. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18152. BEGIN_JUCE_NAMESPACE
  18153. AudioSourcePlayer::AudioSourcePlayer()
  18154. : source (0),
  18155. sampleRate (0),
  18156. bufferSize (0),
  18157. tempBuffer (2, 8),
  18158. lastGain (1.0f),
  18159. gain (1.0f)
  18160. {
  18161. }
  18162. AudioSourcePlayer::~AudioSourcePlayer()
  18163. {
  18164. setSource (0);
  18165. }
  18166. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18167. {
  18168. if (source != newSource)
  18169. {
  18170. AudioSource* const oldSource = source;
  18171. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18172. newSource->prepareToPlay (bufferSize, sampleRate);
  18173. {
  18174. const ScopedLock sl (readLock);
  18175. source = newSource;
  18176. }
  18177. if (oldSource != 0)
  18178. oldSource->releaseResources();
  18179. }
  18180. }
  18181. void AudioSourcePlayer::setGain (const float newGain) throw()
  18182. {
  18183. gain = newGain;
  18184. }
  18185. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18186. int totalNumInputChannels,
  18187. float** outputChannelData,
  18188. int totalNumOutputChannels,
  18189. int numSamples)
  18190. {
  18191. // these should have been prepared by audioDeviceAboutToStart()...
  18192. jassert (sampleRate > 0 && bufferSize > 0);
  18193. const ScopedLock sl (readLock);
  18194. if (source != 0)
  18195. {
  18196. AudioSourceChannelInfo info;
  18197. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18198. // messy stuff needed to compact the channels down into an array
  18199. // of non-zero pointers..
  18200. for (i = 0; i < totalNumInputChannels; ++i)
  18201. {
  18202. if (inputChannelData[i] != 0)
  18203. {
  18204. inputChans [numInputs++] = inputChannelData[i];
  18205. if (numInputs >= numElementsInArray (inputChans))
  18206. break;
  18207. }
  18208. }
  18209. for (i = 0; i < totalNumOutputChannels; ++i)
  18210. {
  18211. if (outputChannelData[i] != 0)
  18212. {
  18213. outputChans [numOutputs++] = outputChannelData[i];
  18214. if (numOutputs >= numElementsInArray (outputChans))
  18215. break;
  18216. }
  18217. }
  18218. if (numInputs > numOutputs)
  18219. {
  18220. // if there aren't enough output channels for the number of
  18221. // inputs, we need to create some temporary extra ones (can't
  18222. // use the input data in case it gets written to)
  18223. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18224. false, false, true);
  18225. for (i = 0; i < numOutputs; ++i)
  18226. {
  18227. channels[numActiveChans] = outputChans[i];
  18228. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18229. ++numActiveChans;
  18230. }
  18231. for (i = numOutputs; i < numInputs; ++i)
  18232. {
  18233. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18234. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18235. ++numActiveChans;
  18236. }
  18237. }
  18238. else
  18239. {
  18240. for (i = 0; i < numInputs; ++i)
  18241. {
  18242. channels[numActiveChans] = outputChans[i];
  18243. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18244. ++numActiveChans;
  18245. }
  18246. for (i = numInputs; i < numOutputs; ++i)
  18247. {
  18248. channels[numActiveChans] = outputChans[i];
  18249. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18250. ++numActiveChans;
  18251. }
  18252. }
  18253. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18254. info.buffer = &buffer;
  18255. info.startSample = 0;
  18256. info.numSamples = numSamples;
  18257. source->getNextAudioBlock (info);
  18258. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18259. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18260. lastGain = gain;
  18261. }
  18262. else
  18263. {
  18264. for (int i = 0; i < totalNumOutputChannels; ++i)
  18265. if (outputChannelData[i] != 0)
  18266. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18267. }
  18268. }
  18269. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18270. {
  18271. sampleRate = device->getCurrentSampleRate();
  18272. bufferSize = device->getCurrentBufferSizeSamples();
  18273. zeromem (channels, sizeof (channels));
  18274. if (source != 0)
  18275. source->prepareToPlay (bufferSize, sampleRate);
  18276. }
  18277. void AudioSourcePlayer::audioDeviceStopped()
  18278. {
  18279. if (source != 0)
  18280. source->releaseResources();
  18281. sampleRate = 0.0;
  18282. bufferSize = 0;
  18283. tempBuffer.setSize (2, 8);
  18284. }
  18285. END_JUCE_NAMESPACE
  18286. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18287. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18288. BEGIN_JUCE_NAMESPACE
  18289. AudioTransportSource::AudioTransportSource()
  18290. : source (0),
  18291. resamplerSource (0),
  18292. bufferingSource (0),
  18293. positionableSource (0),
  18294. masterSource (0),
  18295. gain (1.0f),
  18296. lastGain (1.0f),
  18297. playing (false),
  18298. stopped (true),
  18299. sampleRate (44100.0),
  18300. sourceSampleRate (0.0),
  18301. blockSize (128),
  18302. readAheadBufferSize (0),
  18303. isPrepared (false),
  18304. inputStreamEOF (false)
  18305. {
  18306. }
  18307. AudioTransportSource::~AudioTransportSource()
  18308. {
  18309. setSource (0);
  18310. releaseResources();
  18311. }
  18312. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18313. int readAheadBufferSize_,
  18314. double sourceSampleRateToCorrectFor)
  18315. {
  18316. if (source == newSource)
  18317. {
  18318. if (source == 0)
  18319. return;
  18320. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18321. }
  18322. readAheadBufferSize = readAheadBufferSize_;
  18323. sourceSampleRate = sourceSampleRateToCorrectFor;
  18324. ResamplingAudioSource* newResamplerSource = 0;
  18325. BufferingAudioSource* newBufferingSource = 0;
  18326. PositionableAudioSource* newPositionableSource = 0;
  18327. AudioSource* newMasterSource = 0;
  18328. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18329. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18330. AudioSource* oldMasterSource = masterSource;
  18331. if (newSource != 0)
  18332. {
  18333. newPositionableSource = newSource;
  18334. if (readAheadBufferSize_ > 0)
  18335. newPositionableSource = newBufferingSource
  18336. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18337. newPositionableSource->setNextReadPosition (0);
  18338. if (sourceSampleRateToCorrectFor != 0)
  18339. newMasterSource = newResamplerSource
  18340. = new ResamplingAudioSource (newPositionableSource, false);
  18341. else
  18342. newMasterSource = newPositionableSource;
  18343. if (isPrepared)
  18344. {
  18345. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18346. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18347. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18348. }
  18349. }
  18350. {
  18351. const ScopedLock sl (callbackLock);
  18352. source = newSource;
  18353. resamplerSource = newResamplerSource;
  18354. bufferingSource = newBufferingSource;
  18355. masterSource = newMasterSource;
  18356. positionableSource = newPositionableSource;
  18357. playing = false;
  18358. }
  18359. if (oldMasterSource != 0)
  18360. oldMasterSource->releaseResources();
  18361. }
  18362. void AudioTransportSource::start()
  18363. {
  18364. if ((! playing) && masterSource != 0)
  18365. {
  18366. {
  18367. const ScopedLock sl (callbackLock);
  18368. playing = true;
  18369. stopped = false;
  18370. inputStreamEOF = false;
  18371. }
  18372. sendChangeMessage (this);
  18373. }
  18374. }
  18375. void AudioTransportSource::stop()
  18376. {
  18377. if (playing)
  18378. {
  18379. {
  18380. const ScopedLock sl (callbackLock);
  18381. playing = false;
  18382. }
  18383. int n = 500;
  18384. while (--n >= 0 && ! stopped)
  18385. Thread::sleep (2);
  18386. sendChangeMessage (this);
  18387. }
  18388. }
  18389. void AudioTransportSource::setPosition (double newPosition)
  18390. {
  18391. if (sampleRate > 0.0)
  18392. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18393. }
  18394. double AudioTransportSource::getCurrentPosition() const
  18395. {
  18396. if (sampleRate > 0.0)
  18397. return getNextReadPosition() / sampleRate;
  18398. else
  18399. return 0.0;
  18400. }
  18401. void AudioTransportSource::setNextReadPosition (int newPosition)
  18402. {
  18403. if (positionableSource != 0)
  18404. {
  18405. if (sampleRate > 0 && sourceSampleRate > 0)
  18406. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18407. positionableSource->setNextReadPosition (newPosition);
  18408. }
  18409. }
  18410. int AudioTransportSource::getNextReadPosition() const
  18411. {
  18412. if (positionableSource != 0)
  18413. {
  18414. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18415. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18416. }
  18417. return 0;
  18418. }
  18419. int AudioTransportSource::getTotalLength() const
  18420. {
  18421. const ScopedLock sl (callbackLock);
  18422. if (positionableSource != 0)
  18423. {
  18424. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18425. return roundToInt (positionableSource->getTotalLength() * ratio);
  18426. }
  18427. return 0;
  18428. }
  18429. bool AudioTransportSource::isLooping() const
  18430. {
  18431. const ScopedLock sl (callbackLock);
  18432. return positionableSource != 0
  18433. && positionableSource->isLooping();
  18434. }
  18435. void AudioTransportSource::setGain (const float newGain) throw()
  18436. {
  18437. gain = newGain;
  18438. }
  18439. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18440. double sampleRate_)
  18441. {
  18442. const ScopedLock sl (callbackLock);
  18443. sampleRate = sampleRate_;
  18444. blockSize = samplesPerBlockExpected;
  18445. if (masterSource != 0)
  18446. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18447. if (resamplerSource != 0 && sourceSampleRate != 0)
  18448. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18449. isPrepared = true;
  18450. }
  18451. void AudioTransportSource::releaseResources()
  18452. {
  18453. const ScopedLock sl (callbackLock);
  18454. if (masterSource != 0)
  18455. masterSource->releaseResources();
  18456. isPrepared = false;
  18457. }
  18458. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18459. {
  18460. const ScopedLock sl (callbackLock);
  18461. inputStreamEOF = false;
  18462. if (masterSource != 0 && ! stopped)
  18463. {
  18464. masterSource->getNextAudioBlock (info);
  18465. if (! playing)
  18466. {
  18467. // just stopped playing, so fade out the last block..
  18468. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18469. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18470. if (info.numSamples > 256)
  18471. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18472. }
  18473. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18474. && ! positionableSource->isLooping())
  18475. {
  18476. playing = false;
  18477. inputStreamEOF = true;
  18478. sendChangeMessage (this);
  18479. }
  18480. stopped = ! playing;
  18481. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18482. {
  18483. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18484. lastGain, gain);
  18485. }
  18486. }
  18487. else
  18488. {
  18489. info.clearActiveBufferRegion();
  18490. stopped = true;
  18491. }
  18492. lastGain = gain;
  18493. }
  18494. END_JUCE_NAMESPACE
  18495. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18496. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18497. BEGIN_JUCE_NAMESPACE
  18498. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18499. public Thread,
  18500. private Timer
  18501. {
  18502. public:
  18503. SharedBufferingAudioSourceThread()
  18504. : Thread ("Audio Buffer")
  18505. {
  18506. }
  18507. ~SharedBufferingAudioSourceThread()
  18508. {
  18509. stopThread (10000);
  18510. clearSingletonInstance();
  18511. }
  18512. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18513. void addSource (BufferingAudioSource* source)
  18514. {
  18515. const ScopedLock sl (lock);
  18516. if (! sources.contains ((void*) source))
  18517. {
  18518. sources.add ((void*) source);
  18519. startThread();
  18520. stopTimer();
  18521. }
  18522. notify();
  18523. }
  18524. void removeSource (BufferingAudioSource* source)
  18525. {
  18526. const ScopedLock sl (lock);
  18527. sources.removeValue ((void*) source);
  18528. if (sources.size() == 0)
  18529. startTimer (5000);
  18530. }
  18531. private:
  18532. VoidArray sources;
  18533. CriticalSection lock;
  18534. void run()
  18535. {
  18536. while (! threadShouldExit())
  18537. {
  18538. bool busy = false;
  18539. for (int i = sources.size(); --i >= 0;)
  18540. {
  18541. if (threadShouldExit())
  18542. return;
  18543. const ScopedLock sl (lock);
  18544. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18545. if (b != 0 && b->readNextBufferChunk())
  18546. busy = true;
  18547. }
  18548. if (! busy)
  18549. wait (500);
  18550. }
  18551. }
  18552. void timerCallback()
  18553. {
  18554. stopTimer();
  18555. if (sources.size() == 0)
  18556. deleteInstance();
  18557. }
  18558. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18559. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18560. };
  18561. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18562. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18563. const bool deleteSourceWhenDeleted_,
  18564. int numberOfSamplesToBuffer_)
  18565. : source (source_),
  18566. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18567. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18568. buffer (2, 0),
  18569. bufferValidStart (0),
  18570. bufferValidEnd (0),
  18571. nextPlayPos (0),
  18572. wasSourceLooping (false)
  18573. {
  18574. jassert (source_ != 0);
  18575. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18576. // not using a larger buffer..
  18577. }
  18578. BufferingAudioSource::~BufferingAudioSource()
  18579. {
  18580. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18581. if (thread != 0)
  18582. thread->removeSource (this);
  18583. if (deleteSourceWhenDeleted)
  18584. delete source;
  18585. }
  18586. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18587. {
  18588. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18589. sampleRate = sampleRate_;
  18590. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18591. buffer.clear();
  18592. bufferValidStart = 0;
  18593. bufferValidEnd = 0;
  18594. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18595. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18596. buffer.getNumSamples() / 2))
  18597. {
  18598. SharedBufferingAudioSourceThread::getInstance()->notify();
  18599. Thread::sleep (5);
  18600. }
  18601. }
  18602. void BufferingAudioSource::releaseResources()
  18603. {
  18604. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18605. if (thread != 0)
  18606. thread->removeSource (this);
  18607. buffer.setSize (2, 0);
  18608. source->releaseResources();
  18609. }
  18610. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18611. {
  18612. const ScopedLock sl (bufferStartPosLock);
  18613. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18614. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18615. if (validStart == validEnd)
  18616. {
  18617. // total cache miss
  18618. info.clearActiveBufferRegion();
  18619. }
  18620. else
  18621. {
  18622. if (validStart > 0)
  18623. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18624. if (validEnd < info.numSamples)
  18625. info.buffer->clear (info.startSample + validEnd,
  18626. info.numSamples - validEnd); // partial cache miss at end
  18627. if (validStart < validEnd)
  18628. {
  18629. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18630. {
  18631. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18632. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18633. if (startBufferIndex < endBufferIndex)
  18634. {
  18635. info.buffer->copyFrom (chan, info.startSample + validStart,
  18636. buffer,
  18637. chan, startBufferIndex,
  18638. validEnd - validStart);
  18639. }
  18640. else
  18641. {
  18642. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18643. info.buffer->copyFrom (chan, info.startSample + validStart,
  18644. buffer,
  18645. chan, startBufferIndex,
  18646. initialSize);
  18647. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18648. buffer,
  18649. chan, 0,
  18650. (validEnd - validStart) - initialSize);
  18651. }
  18652. }
  18653. }
  18654. nextPlayPos += info.numSamples;
  18655. if (source->isLooping() && nextPlayPos > 0)
  18656. nextPlayPos %= source->getTotalLength();
  18657. }
  18658. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18659. if (thread != 0)
  18660. thread->notify();
  18661. }
  18662. int BufferingAudioSource::getNextReadPosition() const
  18663. {
  18664. return (source->isLooping() && nextPlayPos > 0)
  18665. ? nextPlayPos % source->getTotalLength()
  18666. : nextPlayPos;
  18667. }
  18668. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18669. {
  18670. const ScopedLock sl (bufferStartPosLock);
  18671. nextPlayPos = newPosition;
  18672. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18673. if (thread != 0)
  18674. thread->notify();
  18675. }
  18676. bool BufferingAudioSource::readNextBufferChunk()
  18677. {
  18678. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18679. {
  18680. const ScopedLock sl (bufferStartPosLock);
  18681. if (wasSourceLooping != isLooping())
  18682. {
  18683. wasSourceLooping = isLooping();
  18684. bufferValidStart = 0;
  18685. bufferValidEnd = 0;
  18686. }
  18687. newBVS = jmax (0, nextPlayPos);
  18688. newBVE = newBVS + buffer.getNumSamples() - 4;
  18689. sectionToReadStart = 0;
  18690. sectionToReadEnd = 0;
  18691. const int maxChunkSize = 2048;
  18692. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18693. {
  18694. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18695. sectionToReadStart = newBVS;
  18696. sectionToReadEnd = newBVE;
  18697. bufferValidStart = 0;
  18698. bufferValidEnd = 0;
  18699. }
  18700. else if (abs (newBVS - bufferValidStart) > 512
  18701. || abs (newBVE - bufferValidEnd) > 512)
  18702. {
  18703. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18704. sectionToReadStart = bufferValidEnd;
  18705. sectionToReadEnd = newBVE;
  18706. bufferValidStart = newBVS;
  18707. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18708. }
  18709. }
  18710. if (sectionToReadStart != sectionToReadEnd)
  18711. {
  18712. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18713. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18714. if (bufferIndexStart < bufferIndexEnd)
  18715. {
  18716. readBufferSection (sectionToReadStart,
  18717. sectionToReadEnd - sectionToReadStart,
  18718. bufferIndexStart);
  18719. }
  18720. else
  18721. {
  18722. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18723. readBufferSection (sectionToReadStart,
  18724. initialSize,
  18725. bufferIndexStart);
  18726. readBufferSection (sectionToReadStart + initialSize,
  18727. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18728. 0);
  18729. }
  18730. const ScopedLock sl2 (bufferStartPosLock);
  18731. bufferValidStart = newBVS;
  18732. bufferValidEnd = newBVE;
  18733. return true;
  18734. }
  18735. else
  18736. {
  18737. return false;
  18738. }
  18739. }
  18740. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18741. {
  18742. if (source->getNextReadPosition() != start)
  18743. source->setNextReadPosition (start);
  18744. AudioSourceChannelInfo info;
  18745. info.buffer = &buffer;
  18746. info.startSample = bufferOffset;
  18747. info.numSamples = length;
  18748. source->getNextAudioBlock (info);
  18749. }
  18750. END_JUCE_NAMESPACE
  18751. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18752. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18753. BEGIN_JUCE_NAMESPACE
  18754. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18755. const bool deleteSourceWhenDeleted_)
  18756. : requiredNumberOfChannels (2),
  18757. source (source_),
  18758. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18759. buffer (2, 16)
  18760. {
  18761. remappedInfo.buffer = &buffer;
  18762. remappedInfo.startSample = 0;
  18763. }
  18764. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18765. {
  18766. if (deleteSourceWhenDeleted)
  18767. delete source;
  18768. }
  18769. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18770. {
  18771. const ScopedLock sl (lock);
  18772. requiredNumberOfChannels = requiredNumberOfChannels_;
  18773. }
  18774. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18775. {
  18776. const ScopedLock sl (lock);
  18777. remappedInputs.clear();
  18778. remappedOutputs.clear();
  18779. }
  18780. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18781. {
  18782. const ScopedLock sl (lock);
  18783. while (remappedInputs.size() < destIndex)
  18784. remappedInputs.add (-1);
  18785. remappedInputs.set (destIndex, sourceIndex);
  18786. }
  18787. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18788. {
  18789. const ScopedLock sl (lock);
  18790. while (remappedOutputs.size() < sourceIndex)
  18791. remappedOutputs.add (-1);
  18792. remappedOutputs.set (sourceIndex, destIndex);
  18793. }
  18794. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18795. {
  18796. const ScopedLock sl (lock);
  18797. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18798. return remappedInputs.getUnchecked (inputChannelIndex);
  18799. return -1;
  18800. }
  18801. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18802. {
  18803. const ScopedLock sl (lock);
  18804. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18805. return remappedOutputs .getUnchecked (outputChannelIndex);
  18806. return -1;
  18807. }
  18808. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18809. {
  18810. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18811. }
  18812. void ChannelRemappingAudioSource::releaseResources()
  18813. {
  18814. source->releaseResources();
  18815. }
  18816. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18817. {
  18818. const ScopedLock sl (lock);
  18819. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18820. const int numChans = bufferToFill.buffer->getNumChannels();
  18821. int i;
  18822. for (i = 0; i < buffer.getNumChannels(); ++i)
  18823. {
  18824. const int remappedChan = getRemappedInputChannel (i);
  18825. if (remappedChan >= 0 && remappedChan < numChans)
  18826. {
  18827. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18828. remappedChan,
  18829. bufferToFill.startSample,
  18830. bufferToFill.numSamples);
  18831. }
  18832. else
  18833. {
  18834. buffer.clear (i, 0, bufferToFill.numSamples);
  18835. }
  18836. }
  18837. remappedInfo.numSamples = bufferToFill.numSamples;
  18838. source->getNextAudioBlock (remappedInfo);
  18839. bufferToFill.clearActiveBufferRegion();
  18840. for (i = 0; i < requiredNumberOfChannels; ++i)
  18841. {
  18842. const int remappedChan = getRemappedOutputChannel (i);
  18843. if (remappedChan >= 0 && remappedChan < numChans)
  18844. {
  18845. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18846. buffer, i, 0, bufferToFill.numSamples);
  18847. }
  18848. }
  18849. }
  18850. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18851. {
  18852. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18853. String ins, outs;
  18854. int i;
  18855. const ScopedLock sl (lock);
  18856. for (i = 0; i < remappedInputs.size(); ++i)
  18857. ins << remappedInputs.getUnchecked(i) << T(' ');
  18858. for (i = 0; i < remappedOutputs.size(); ++i)
  18859. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18860. e->setAttribute (T("inputs"), ins.trimEnd());
  18861. e->setAttribute (T("outputs"), outs.trimEnd());
  18862. return e;
  18863. }
  18864. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18865. {
  18866. if (e.hasTagName (T("MAPPINGS")))
  18867. {
  18868. const ScopedLock sl (lock);
  18869. clearAllMappings();
  18870. StringArray ins, outs;
  18871. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  18872. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  18873. int i;
  18874. for (i = 0; i < ins.size(); ++i)
  18875. remappedInputs.add (ins[i].getIntValue());
  18876. for (i = 0; i < outs.size(); ++i)
  18877. remappedOutputs.add (outs[i].getIntValue());
  18878. }
  18879. }
  18880. END_JUCE_NAMESPACE
  18881. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18882. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18883. BEGIN_JUCE_NAMESPACE
  18884. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18885. const bool deleteInputWhenDeleted_)
  18886. : input (inputSource),
  18887. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18888. {
  18889. jassert (inputSource != 0);
  18890. for (int i = 2; --i >= 0;)
  18891. iirFilters.add (new IIRFilter());
  18892. }
  18893. IIRFilterAudioSource::~IIRFilterAudioSource()
  18894. {
  18895. if (deleteInputWhenDeleted)
  18896. delete input;
  18897. }
  18898. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18899. {
  18900. for (int i = iirFilters.size(); --i >= 0;)
  18901. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18902. }
  18903. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18904. {
  18905. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18906. for (int i = iirFilters.size(); --i >= 0;)
  18907. iirFilters.getUnchecked(i)->reset();
  18908. }
  18909. void IIRFilterAudioSource::releaseResources()
  18910. {
  18911. input->releaseResources();
  18912. }
  18913. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18914. {
  18915. input->getNextAudioBlock (bufferToFill);
  18916. const int numChannels = bufferToFill.buffer->getNumChannels();
  18917. while (numChannels > iirFilters.size())
  18918. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18919. for (int i = 0; i < numChannels; ++i)
  18920. iirFilters.getUnchecked(i)
  18921. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18922. bufferToFill.numSamples);
  18923. }
  18924. END_JUCE_NAMESPACE
  18925. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18926. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  18927. BEGIN_JUCE_NAMESPACE
  18928. MixerAudioSource::MixerAudioSource()
  18929. : tempBuffer (2, 0),
  18930. currentSampleRate (0.0),
  18931. bufferSizeExpected (0)
  18932. {
  18933. }
  18934. MixerAudioSource::~MixerAudioSource()
  18935. {
  18936. removeAllInputs();
  18937. }
  18938. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18939. {
  18940. if (input != 0 && ! inputs.contains (input))
  18941. {
  18942. double localRate;
  18943. int localBufferSize;
  18944. {
  18945. const ScopedLock sl (lock);
  18946. localRate = currentSampleRate;
  18947. localBufferSize = bufferSizeExpected;
  18948. }
  18949. if (localRate != 0.0)
  18950. input->prepareToPlay (localBufferSize, localRate);
  18951. const ScopedLock sl (lock);
  18952. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18953. inputs.add (input);
  18954. }
  18955. }
  18956. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18957. {
  18958. if (input != 0)
  18959. {
  18960. int index;
  18961. {
  18962. const ScopedLock sl (lock);
  18963. index = inputs.indexOf ((void*) input);
  18964. if (index >= 0)
  18965. {
  18966. inputsToDelete.shiftBits (index, 1);
  18967. inputs.remove (index);
  18968. }
  18969. }
  18970. if (index >= 0)
  18971. {
  18972. input->releaseResources();
  18973. if (deleteInput)
  18974. delete input;
  18975. }
  18976. }
  18977. }
  18978. void MixerAudioSource::removeAllInputs()
  18979. {
  18980. VoidArray inputsCopy;
  18981. BitArray inputsToDeleteCopy;
  18982. {
  18983. const ScopedLock sl (lock);
  18984. inputsCopy = inputs;
  18985. inputsToDeleteCopy = inputsToDelete;
  18986. }
  18987. for (int i = inputsCopy.size(); --i >= 0;)
  18988. if (inputsToDeleteCopy[i])
  18989. delete (AudioSource*) inputsCopy[i];
  18990. }
  18991. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18992. {
  18993. tempBuffer.setSize (2, samplesPerBlockExpected);
  18994. const ScopedLock sl (lock);
  18995. currentSampleRate = sampleRate;
  18996. bufferSizeExpected = samplesPerBlockExpected;
  18997. for (int i = inputs.size(); --i >= 0;)
  18998. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  18999. sampleRate);
  19000. }
  19001. void MixerAudioSource::releaseResources()
  19002. {
  19003. const ScopedLock sl (lock);
  19004. for (int i = inputs.size(); --i >= 0;)
  19005. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  19006. tempBuffer.setSize (2, 0);
  19007. currentSampleRate = 0;
  19008. bufferSizeExpected = 0;
  19009. }
  19010. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19011. {
  19012. const ScopedLock sl (lock);
  19013. if (inputs.size() > 0)
  19014. {
  19015. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  19016. if (inputs.size() > 1)
  19017. {
  19018. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  19019. info.buffer->getNumSamples());
  19020. AudioSourceChannelInfo info2;
  19021. info2.buffer = &tempBuffer;
  19022. info2.numSamples = info.numSamples;
  19023. info2.startSample = 0;
  19024. for (int i = 1; i < inputs.size(); ++i)
  19025. {
  19026. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  19027. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  19028. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  19029. }
  19030. }
  19031. }
  19032. else
  19033. {
  19034. info.clearActiveBufferRegion();
  19035. }
  19036. }
  19037. END_JUCE_NAMESPACE
  19038. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  19039. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  19040. BEGIN_JUCE_NAMESPACE
  19041. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  19042. const bool deleteInputWhenDeleted_)
  19043. : input (inputSource),
  19044. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  19045. ratio (1.0),
  19046. lastRatio (1.0),
  19047. buffer (2, 0),
  19048. sampsInBuffer (0)
  19049. {
  19050. jassert (input != 0);
  19051. }
  19052. ResamplingAudioSource::~ResamplingAudioSource()
  19053. {
  19054. if (deleteInputWhenDeleted)
  19055. delete input;
  19056. }
  19057. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  19058. {
  19059. jassert (samplesInPerOutputSample > 0);
  19060. const ScopedLock sl (ratioLock);
  19061. ratio = jmax (0.0, samplesInPerOutputSample);
  19062. }
  19063. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  19064. double sampleRate)
  19065. {
  19066. const ScopedLock sl (ratioLock);
  19067. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19068. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  19069. buffer.clear();
  19070. sampsInBuffer = 0;
  19071. bufferPos = 0;
  19072. subSampleOffset = 0.0;
  19073. createLowPass (ratio);
  19074. resetFilters();
  19075. }
  19076. void ResamplingAudioSource::releaseResources()
  19077. {
  19078. input->releaseResources();
  19079. buffer.setSize (2, 0);
  19080. }
  19081. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19082. {
  19083. const ScopedLock sl (ratioLock);
  19084. if (lastRatio != ratio)
  19085. {
  19086. createLowPass (ratio);
  19087. lastRatio = ratio;
  19088. }
  19089. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19090. int bufferSize = buffer.getNumSamples();
  19091. if (bufferSize < sampsNeeded + 8)
  19092. {
  19093. bufferPos %= bufferSize;
  19094. bufferSize = sampsNeeded + 32;
  19095. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19096. }
  19097. bufferPos %= bufferSize;
  19098. int endOfBufferPos = bufferPos + sampsInBuffer;
  19099. while (sampsNeeded > sampsInBuffer)
  19100. {
  19101. endOfBufferPos %= bufferSize;
  19102. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19103. bufferSize - endOfBufferPos);
  19104. AudioSourceChannelInfo readInfo;
  19105. readInfo.buffer = &buffer;
  19106. readInfo.numSamples = numToDo;
  19107. readInfo.startSample = endOfBufferPos;
  19108. input->getNextAudioBlock (readInfo);
  19109. if (ratio > 1.0001)
  19110. {
  19111. // for down-sampling, pre-apply the filter..
  19112. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19113. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19114. }
  19115. sampsInBuffer += numToDo;
  19116. endOfBufferPos += numToDo;
  19117. }
  19118. float* dl = info.buffer->getSampleData (0, info.startSample);
  19119. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19120. const float* const bl = buffer.getSampleData (0, 0);
  19121. const float* const br = buffer.getSampleData (1, 0);
  19122. int nextPos = (bufferPos + 1) % bufferSize;
  19123. for (int m = info.numSamples; --m >= 0;)
  19124. {
  19125. const float alpha = (float) subSampleOffset;
  19126. const float invAlpha = 1.0f - alpha;
  19127. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19128. if (dr != 0)
  19129. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19130. subSampleOffset += ratio;
  19131. jassert (sampsInBuffer > 0);
  19132. while (subSampleOffset >= 1.0)
  19133. {
  19134. if (++bufferPos >= bufferSize)
  19135. bufferPos = 0;
  19136. --sampsInBuffer;
  19137. nextPos = (bufferPos + 1) % bufferSize;
  19138. subSampleOffset -= 1.0;
  19139. }
  19140. }
  19141. if (ratio < 0.9999)
  19142. {
  19143. // for up-sampling, apply the filter after transposing..
  19144. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19145. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19146. }
  19147. else if (ratio <= 1.0001)
  19148. {
  19149. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19150. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19151. {
  19152. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19153. FilterState& fs = filterStates[i];
  19154. if (info.numSamples > 1)
  19155. {
  19156. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19157. }
  19158. else
  19159. {
  19160. fs.y2 = fs.y1;
  19161. fs.x2 = fs.x1;
  19162. }
  19163. fs.y1 = fs.x1 = *endOfBuffer;
  19164. }
  19165. }
  19166. jassert (sampsInBuffer >= 0);
  19167. }
  19168. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19169. {
  19170. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19171. : 0.5 * frequencyRatio;
  19172. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19173. const double nSquared = n * n;
  19174. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19175. setFilterCoefficients (c1,
  19176. c1 * 2.0f,
  19177. c1,
  19178. 1.0,
  19179. c1 * 2.0 * (1.0 - nSquared),
  19180. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19181. }
  19182. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19183. {
  19184. const double a = 1.0 / c4;
  19185. c1 *= a;
  19186. c2 *= a;
  19187. c3 *= a;
  19188. c5 *= a;
  19189. c6 *= a;
  19190. coefficients[0] = c1;
  19191. coefficients[1] = c2;
  19192. coefficients[2] = c3;
  19193. coefficients[3] = c4;
  19194. coefficients[4] = c5;
  19195. coefficients[5] = c6;
  19196. }
  19197. void ResamplingAudioSource::resetFilters()
  19198. {
  19199. zeromem (filterStates, sizeof (filterStates));
  19200. }
  19201. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19202. {
  19203. while (--num >= 0)
  19204. {
  19205. const double in = *samples;
  19206. double out = coefficients[0] * in
  19207. + coefficients[1] * fs.x1
  19208. + coefficients[2] * fs.x2
  19209. - coefficients[4] * fs.y1
  19210. - coefficients[5] * fs.y2;
  19211. #if JUCE_INTEL
  19212. if (! (out < -1.0e-8 || out > 1.0e-8))
  19213. out = 0;
  19214. #endif
  19215. fs.x2 = fs.x1;
  19216. fs.x1 = in;
  19217. fs.y2 = fs.y1;
  19218. fs.y1 = out;
  19219. *samples++ = (float) out;
  19220. }
  19221. }
  19222. END_JUCE_NAMESPACE
  19223. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19224. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19225. BEGIN_JUCE_NAMESPACE
  19226. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19227. : frequency (1000.0),
  19228. sampleRate (44100.0),
  19229. currentPhase (0.0),
  19230. phasePerSample (0.0),
  19231. amplitude (0.5f)
  19232. {
  19233. }
  19234. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19235. {
  19236. }
  19237. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19238. {
  19239. amplitude = newAmplitude;
  19240. }
  19241. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19242. {
  19243. frequency = newFrequencyHz;
  19244. phasePerSample = 0.0;
  19245. }
  19246. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19247. double sampleRate_)
  19248. {
  19249. currentPhase = 0.0;
  19250. phasePerSample = 0.0;
  19251. sampleRate = sampleRate_;
  19252. }
  19253. void ToneGeneratorAudioSource::releaseResources()
  19254. {
  19255. }
  19256. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19257. {
  19258. if (phasePerSample == 0.0)
  19259. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19260. for (int i = 0; i < info.numSamples; ++i)
  19261. {
  19262. const float sample = amplitude * (float) sin (currentPhase);
  19263. currentPhase += phasePerSample;
  19264. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19265. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19266. }
  19267. }
  19268. END_JUCE_NAMESPACE
  19269. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19270. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19271. BEGIN_JUCE_NAMESPACE
  19272. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19273. : sampleRate (0),
  19274. bufferSize (0),
  19275. useDefaultInputChannels (true),
  19276. useDefaultOutputChannels (true)
  19277. {
  19278. }
  19279. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19280. {
  19281. return outputDeviceName == other.outputDeviceName
  19282. && inputDeviceName == other.inputDeviceName
  19283. && sampleRate == other.sampleRate
  19284. && bufferSize == other.bufferSize
  19285. && inputChannels == other.inputChannels
  19286. && useDefaultInputChannels == other.useDefaultInputChannels
  19287. && outputChannels == other.outputChannels
  19288. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19289. }
  19290. AudioDeviceManager::AudioDeviceManager()
  19291. : currentAudioDevice (0),
  19292. numInputChansNeeded (0),
  19293. numOutputChansNeeded (2),
  19294. listNeedsScanning (true),
  19295. useInputNames (false),
  19296. inputLevelMeasurementEnabledCount (0),
  19297. inputLevel (0),
  19298. tempBuffer (2, 2),
  19299. defaultMidiOutput (0),
  19300. cpuUsageMs (0),
  19301. timeToCpuScale (0)
  19302. {
  19303. callbackHandler.owner = this;
  19304. }
  19305. AudioDeviceManager::~AudioDeviceManager()
  19306. {
  19307. currentAudioDevice = 0;
  19308. defaultMidiOutput = 0;
  19309. }
  19310. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19311. {
  19312. if (availableDeviceTypes.size() == 0)
  19313. {
  19314. createAudioDeviceTypes (availableDeviceTypes);
  19315. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19316. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19317. if (availableDeviceTypes.size() > 0)
  19318. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19319. }
  19320. }
  19321. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19322. {
  19323. scanDevicesIfNeeded();
  19324. return availableDeviceTypes;
  19325. }
  19326. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19327. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19328. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19329. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19330. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19331. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19332. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19333. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19334. {
  19335. #if JUCE_WINDOWS
  19336. #if JUCE_WASAPI
  19337. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19338. list.add (juce_createAudioIODeviceType_WASAPI());
  19339. #endif
  19340. #if JUCE_DIRECTSOUND
  19341. list.add (juce_createAudioIODeviceType_DirectSound());
  19342. #endif
  19343. #if JUCE_ASIO
  19344. list.add (juce_createAudioIODeviceType_ASIO());
  19345. #endif
  19346. #endif
  19347. #if JUCE_MAC
  19348. list.add (juce_createAudioIODeviceType_CoreAudio());
  19349. #endif
  19350. #if JUCE_IPHONE
  19351. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19352. #endif
  19353. #if JUCE_LINUX && JUCE_ALSA
  19354. list.add (juce_createAudioIODeviceType_ALSA());
  19355. #endif
  19356. #if JUCE_LINUX && JUCE_JACK
  19357. list.add (juce_createAudioIODeviceType_JACK());
  19358. #endif
  19359. }
  19360. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19361. const int numOutputChannelsNeeded,
  19362. const XmlElement* const e,
  19363. const bool selectDefaultDeviceOnFailure,
  19364. const String& preferredDefaultDeviceName,
  19365. const AudioDeviceSetup* preferredSetupOptions)
  19366. {
  19367. scanDevicesIfNeeded();
  19368. numInputChansNeeded = numInputChannelsNeeded;
  19369. numOutputChansNeeded = numOutputChannelsNeeded;
  19370. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19371. {
  19372. lastExplicitSettings = new XmlElement (*e);
  19373. String error;
  19374. AudioDeviceSetup setup;
  19375. if (preferredSetupOptions != 0)
  19376. setup = *preferredSetupOptions;
  19377. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19378. {
  19379. setup.inputDeviceName = setup.outputDeviceName
  19380. = e->getStringAttribute (T("audioDeviceName"));
  19381. }
  19382. else
  19383. {
  19384. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19385. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19386. }
  19387. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19388. if (currentDeviceType.isEmpty())
  19389. {
  19390. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19391. if (type != 0)
  19392. currentDeviceType = type->getTypeName();
  19393. else if (availableDeviceTypes.size() > 0)
  19394. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19395. }
  19396. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19397. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19398. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19399. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19400. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19401. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19402. error = setAudioDeviceSetup (setup, true);
  19403. midiInsFromXml.clear();
  19404. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19405. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19406. const StringArray allMidiIns (MidiInput::getDevices());
  19407. for (int i = allMidiIns.size(); --i >= 0;)
  19408. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19409. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19410. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19411. false, preferredDefaultDeviceName);
  19412. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19413. return error;
  19414. }
  19415. else
  19416. {
  19417. AudioDeviceSetup setup;
  19418. if (preferredSetupOptions != 0)
  19419. {
  19420. setup = *preferredSetupOptions;
  19421. }
  19422. else if (preferredDefaultDeviceName.isNotEmpty())
  19423. {
  19424. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19425. {
  19426. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19427. StringArray outs (type->getDeviceNames (false));
  19428. int i;
  19429. for (i = 0; i < outs.size(); ++i)
  19430. {
  19431. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19432. {
  19433. setup.outputDeviceName = outs[i];
  19434. break;
  19435. }
  19436. }
  19437. StringArray ins (type->getDeviceNames (true));
  19438. for (i = 0; i < ins.size(); ++i)
  19439. {
  19440. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19441. {
  19442. setup.inputDeviceName = ins[i];
  19443. break;
  19444. }
  19445. }
  19446. }
  19447. }
  19448. insertDefaultDeviceNames (setup);
  19449. return setAudioDeviceSetup (setup, false);
  19450. }
  19451. }
  19452. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19453. {
  19454. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19455. if (type != 0)
  19456. {
  19457. if (setup.outputDeviceName.isEmpty())
  19458. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19459. if (setup.inputDeviceName.isEmpty())
  19460. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19461. }
  19462. }
  19463. XmlElement* AudioDeviceManager::createStateXml() const
  19464. {
  19465. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19466. }
  19467. void AudioDeviceManager::scanDevicesIfNeeded()
  19468. {
  19469. if (listNeedsScanning)
  19470. {
  19471. listNeedsScanning = false;
  19472. createDeviceTypesIfNeeded();
  19473. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19474. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19475. }
  19476. }
  19477. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19478. {
  19479. scanDevicesIfNeeded();
  19480. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19481. {
  19482. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19483. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19484. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19485. {
  19486. return type;
  19487. }
  19488. }
  19489. return 0;
  19490. }
  19491. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19492. {
  19493. setup = currentSetup;
  19494. }
  19495. void AudioDeviceManager::deleteCurrentDevice()
  19496. {
  19497. currentAudioDevice = 0;
  19498. currentSetup.inputDeviceName = String::empty;
  19499. currentSetup.outputDeviceName = String::empty;
  19500. }
  19501. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19502. const bool treatAsChosenDevice)
  19503. {
  19504. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19505. {
  19506. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19507. && currentDeviceType != type)
  19508. {
  19509. currentDeviceType = type;
  19510. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19511. insertDefaultDeviceNames (s);
  19512. setAudioDeviceSetup (s, treatAsChosenDevice);
  19513. sendChangeMessage (this);
  19514. break;
  19515. }
  19516. }
  19517. }
  19518. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19519. {
  19520. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19521. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19522. return availableDeviceTypes[i];
  19523. return availableDeviceTypes[0];
  19524. }
  19525. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19526. const bool treatAsChosenDevice)
  19527. {
  19528. jassert (&newSetup != &currentSetup); // this will have no effect
  19529. if (newSetup == currentSetup && currentAudioDevice != 0)
  19530. return String::empty;
  19531. if (! (newSetup == currentSetup))
  19532. sendChangeMessage (this);
  19533. stopDevice();
  19534. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19535. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19536. String error;
  19537. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19538. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19539. {
  19540. deleteCurrentDevice();
  19541. if (treatAsChosenDevice)
  19542. updateXml();
  19543. return String::empty;
  19544. }
  19545. if (currentSetup.inputDeviceName != newInputDeviceName
  19546. || currentSetup.outputDeviceName != newOutputDeviceName
  19547. || currentAudioDevice == 0)
  19548. {
  19549. deleteCurrentDevice();
  19550. scanDevicesIfNeeded();
  19551. if (newOutputDeviceName.isNotEmpty()
  19552. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19553. {
  19554. return "No such device: " + newOutputDeviceName;
  19555. }
  19556. if (newInputDeviceName.isNotEmpty()
  19557. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19558. {
  19559. return "No such device: " + newInputDeviceName;
  19560. }
  19561. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19562. if (currentAudioDevice == 0)
  19563. 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!";
  19564. else
  19565. error = currentAudioDevice->getLastError();
  19566. if (error.isNotEmpty())
  19567. {
  19568. deleteCurrentDevice();
  19569. return error;
  19570. }
  19571. if (newSetup.useDefaultInputChannels)
  19572. {
  19573. inputChannels.clear();
  19574. inputChannels.setRange (0, numInputChansNeeded, true);
  19575. }
  19576. if (newSetup.useDefaultOutputChannels)
  19577. {
  19578. outputChannels.clear();
  19579. outputChannels.setRange (0, numOutputChansNeeded, true);
  19580. }
  19581. if (newInputDeviceName.isEmpty())
  19582. inputChannels.clear();
  19583. if (newOutputDeviceName.isEmpty())
  19584. outputChannels.clear();
  19585. }
  19586. if (! newSetup.useDefaultInputChannels)
  19587. inputChannels = newSetup.inputChannels;
  19588. if (! newSetup.useDefaultOutputChannels)
  19589. outputChannels = newSetup.outputChannels;
  19590. currentSetup = newSetup;
  19591. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19592. error = currentAudioDevice->open (inputChannels,
  19593. outputChannels,
  19594. currentSetup.sampleRate,
  19595. currentSetup.bufferSize);
  19596. if (error.isEmpty())
  19597. {
  19598. currentDeviceType = currentAudioDevice->getTypeName();
  19599. currentAudioDevice->start (&callbackHandler);
  19600. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19601. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19602. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19603. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19604. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19605. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19606. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19607. if (treatAsChosenDevice)
  19608. updateXml();
  19609. }
  19610. else
  19611. {
  19612. deleteCurrentDevice();
  19613. }
  19614. return error;
  19615. }
  19616. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19617. {
  19618. jassert (currentAudioDevice != 0);
  19619. if (rate > 0)
  19620. {
  19621. bool ok = false;
  19622. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19623. {
  19624. const double sr = currentAudioDevice->getSampleRate (i);
  19625. if (sr == rate)
  19626. ok = true;
  19627. }
  19628. if (! ok)
  19629. rate = 0;
  19630. }
  19631. if (rate == 0)
  19632. {
  19633. double lowestAbove44 = 0.0;
  19634. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19635. {
  19636. const double sr = currentAudioDevice->getSampleRate (i);
  19637. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19638. lowestAbove44 = sr;
  19639. }
  19640. if (lowestAbove44 == 0.0)
  19641. rate = currentAudioDevice->getSampleRate (0);
  19642. else
  19643. rate = lowestAbove44;
  19644. }
  19645. return rate;
  19646. }
  19647. void AudioDeviceManager::stopDevice()
  19648. {
  19649. if (currentAudioDevice != 0)
  19650. currentAudioDevice->stop();
  19651. testSound = 0;
  19652. }
  19653. void AudioDeviceManager::closeAudioDevice()
  19654. {
  19655. stopDevice();
  19656. currentAudioDevice = 0;
  19657. }
  19658. void AudioDeviceManager::restartLastAudioDevice()
  19659. {
  19660. if (currentAudioDevice == 0)
  19661. {
  19662. if (currentSetup.inputDeviceName.isEmpty()
  19663. && currentSetup.outputDeviceName.isEmpty())
  19664. {
  19665. // This method will only reload the last device that was running
  19666. // before closeAudioDevice() was called - you need to actually open
  19667. // one first, with setAudioDevice().
  19668. jassertfalse
  19669. return;
  19670. }
  19671. AudioDeviceSetup s (currentSetup);
  19672. setAudioDeviceSetup (s, false);
  19673. }
  19674. }
  19675. void AudioDeviceManager::updateXml()
  19676. {
  19677. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19678. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19679. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19680. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19681. if (currentAudioDevice != 0)
  19682. {
  19683. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19684. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19685. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19686. if (! currentSetup.useDefaultInputChannels)
  19687. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19688. if (! currentSetup.useDefaultOutputChannels)
  19689. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19690. }
  19691. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19692. {
  19693. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19694. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19695. }
  19696. if (midiInsFromXml.size() > 0)
  19697. {
  19698. // Add any midi devices that have been enabled before, but which aren't currently
  19699. // open because the device has been disconnected.
  19700. const StringArray availableMidiDevices (MidiInput::getDevices());
  19701. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19702. {
  19703. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19704. {
  19705. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19706. m->setAttribute ("name", midiInsFromXml[i]);
  19707. }
  19708. }
  19709. }
  19710. if (defaultMidiOutputName.isNotEmpty())
  19711. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19712. }
  19713. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19714. {
  19715. {
  19716. const ScopedLock sl (audioCallbackLock);
  19717. if (callbacks.contains (newCallback))
  19718. return;
  19719. }
  19720. if (currentAudioDevice != 0 && newCallback != 0)
  19721. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19722. const ScopedLock sl (audioCallbackLock);
  19723. callbacks.add (newCallback);
  19724. }
  19725. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19726. {
  19727. if (callback != 0)
  19728. {
  19729. bool needsDeinitialising = currentAudioDevice != 0;
  19730. {
  19731. const ScopedLock sl (audioCallbackLock);
  19732. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19733. callbacks.removeValue (callback);
  19734. }
  19735. if (needsDeinitialising)
  19736. callback->audioDeviceStopped();
  19737. }
  19738. }
  19739. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19740. int numInputChannels,
  19741. float** outputChannelData,
  19742. int numOutputChannels,
  19743. int numSamples)
  19744. {
  19745. const ScopedLock sl (audioCallbackLock);
  19746. if (inputLevelMeasurementEnabledCount > 0)
  19747. {
  19748. for (int j = 0; j < numSamples; ++j)
  19749. {
  19750. float s = 0;
  19751. for (int i = 0; i < numInputChannels; ++i)
  19752. s += fabsf (inputChannelData[i][j]);
  19753. s /= numInputChannels;
  19754. const double decayFactor = 0.99992;
  19755. if (s > inputLevel)
  19756. inputLevel = s;
  19757. else if (inputLevel > 0.001f)
  19758. inputLevel *= decayFactor;
  19759. else
  19760. inputLevel = 0;
  19761. }
  19762. }
  19763. if (callbacks.size() > 0)
  19764. {
  19765. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19766. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19767. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19768. outputChannelData, numOutputChannels, numSamples);
  19769. float** const tempChans = tempBuffer.getArrayOfChannels();
  19770. for (int i = callbacks.size(); --i > 0;)
  19771. {
  19772. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19773. tempChans, numOutputChannels, numSamples);
  19774. for (int chan = 0; chan < numOutputChannels; ++chan)
  19775. {
  19776. const float* const src = tempChans [chan];
  19777. float* const dst = outputChannelData [chan];
  19778. if (src != 0 && dst != 0)
  19779. for (int j = 0; j < numSamples; ++j)
  19780. dst[j] += src[j];
  19781. }
  19782. }
  19783. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19784. const double filterAmount = 0.2;
  19785. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19786. }
  19787. else
  19788. {
  19789. for (int i = 0; i < numOutputChannels; ++i)
  19790. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19791. }
  19792. if (testSound != 0)
  19793. {
  19794. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19795. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19796. for (int i = 0; i < numOutputChannels; ++i)
  19797. for (int j = 0; j < numSamps; ++j)
  19798. outputChannelData [i][j] += src[j];
  19799. testSoundPosition += numSamps;
  19800. if (testSoundPosition >= testSound->getNumSamples())
  19801. testSound = 0;
  19802. }
  19803. }
  19804. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19805. {
  19806. cpuUsageMs = 0;
  19807. const double sampleRate = device->getCurrentSampleRate();
  19808. const int blockSize = device->getCurrentBufferSizeSamples();
  19809. if (sampleRate > 0.0 && blockSize > 0)
  19810. {
  19811. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19812. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19813. }
  19814. {
  19815. const ScopedLock sl (audioCallbackLock);
  19816. for (int i = callbacks.size(); --i >= 0;)
  19817. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19818. }
  19819. sendChangeMessage (this);
  19820. }
  19821. void AudioDeviceManager::audioDeviceStoppedInt()
  19822. {
  19823. cpuUsageMs = 0;
  19824. timeToCpuScale = 0;
  19825. sendChangeMessage (this);
  19826. const ScopedLock sl (audioCallbackLock);
  19827. for (int i = callbacks.size(); --i >= 0;)
  19828. callbacks.getUnchecked(i)->audioDeviceStopped();
  19829. }
  19830. double AudioDeviceManager::getCpuUsage() const
  19831. {
  19832. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19833. }
  19834. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19835. const bool enabled)
  19836. {
  19837. if (enabled != isMidiInputEnabled (name))
  19838. {
  19839. if (enabled)
  19840. {
  19841. const int index = MidiInput::getDevices().indexOf (name);
  19842. if (index >= 0)
  19843. {
  19844. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19845. if (min != 0)
  19846. {
  19847. enabledMidiInputs.add (min);
  19848. min->start();
  19849. }
  19850. }
  19851. }
  19852. else
  19853. {
  19854. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19855. if (enabledMidiInputs[i]->getName() == name)
  19856. enabledMidiInputs.remove (i);
  19857. }
  19858. updateXml();
  19859. sendChangeMessage (this);
  19860. }
  19861. }
  19862. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19863. {
  19864. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19865. if (enabledMidiInputs[i]->getName() == name)
  19866. return true;
  19867. return false;
  19868. }
  19869. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19870. MidiInputCallback* callback)
  19871. {
  19872. removeMidiInputCallback (name, callback);
  19873. if (name.isEmpty())
  19874. {
  19875. midiCallbacks.add (callback);
  19876. midiCallbackDevices.add (0);
  19877. }
  19878. else
  19879. {
  19880. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19881. {
  19882. if (enabledMidiInputs[i]->getName() == name)
  19883. {
  19884. const ScopedLock sl (midiCallbackLock);
  19885. midiCallbacks.add (callback);
  19886. midiCallbackDevices.add (enabledMidiInputs[i]);
  19887. break;
  19888. }
  19889. }
  19890. }
  19891. }
  19892. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19893. MidiInputCallback* /*callback*/)
  19894. {
  19895. const ScopedLock sl (midiCallbackLock);
  19896. for (int i = midiCallbacks.size(); --i >= 0;)
  19897. {
  19898. String devName;
  19899. if (midiCallbackDevices.getUnchecked(i) != 0)
  19900. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19901. if (devName == name)
  19902. {
  19903. midiCallbacks.remove (i);
  19904. midiCallbackDevices.remove (i);
  19905. }
  19906. }
  19907. }
  19908. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19909. const MidiMessage& message)
  19910. {
  19911. if (! message.isActiveSense())
  19912. {
  19913. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19914. const ScopedLock sl (midiCallbackLock);
  19915. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19916. {
  19917. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19918. if (md == source || (md == 0 && isDefaultSource))
  19919. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19920. }
  19921. }
  19922. }
  19923. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19924. {
  19925. if (defaultMidiOutputName != deviceName)
  19926. {
  19927. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19928. {
  19929. const ScopedLock sl (audioCallbackLock);
  19930. oldCallbacks = callbacks;
  19931. callbacks.clear();
  19932. }
  19933. if (currentAudioDevice != 0)
  19934. for (int i = oldCallbacks.size(); --i >= 0;)
  19935. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19936. defaultMidiOutput = 0;
  19937. defaultMidiOutputName = deviceName;
  19938. if (deviceName.isNotEmpty())
  19939. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19940. if (currentAudioDevice != 0)
  19941. for (int i = oldCallbacks.size(); --i >= 0;)
  19942. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19943. {
  19944. const ScopedLock sl (audioCallbackLock);
  19945. callbacks = oldCallbacks;
  19946. }
  19947. updateXml();
  19948. sendChangeMessage (this);
  19949. }
  19950. }
  19951. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19952. int numInputChannels,
  19953. float** outputChannelData,
  19954. int numOutputChannels,
  19955. int numSamples)
  19956. {
  19957. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19958. }
  19959. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19960. {
  19961. owner->audioDeviceAboutToStartInt (device);
  19962. }
  19963. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19964. {
  19965. owner->audioDeviceStoppedInt();
  19966. }
  19967. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19968. {
  19969. owner->handleIncomingMidiMessageInt (source, message);
  19970. }
  19971. void AudioDeviceManager::playTestSound()
  19972. {
  19973. { // cunningly nested to swap, unlock and delete in that order.
  19974. ScopedPointer <AudioSampleBuffer> oldSound;
  19975. {
  19976. const ScopedLock sl (audioCallbackLock);
  19977. oldSound = testSound;
  19978. }
  19979. }
  19980. testSoundPosition = 0;
  19981. if (currentAudioDevice != 0)
  19982. {
  19983. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  19984. const int soundLength = (int) sampleRate;
  19985. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  19986. float* samples = newSound->getSampleData (0);
  19987. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  19988. const float amplitude = 0.5f;
  19989. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19990. for (int i = 0; i < soundLength; ++i)
  19991. samples[i] = amplitude * (float) sin (i * phasePerSample);
  19992. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  19993. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  19994. const ScopedLock sl (audioCallbackLock);
  19995. testSound = newSound;
  19996. }
  19997. }
  19998. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  19999. {
  20000. const ScopedLock sl (audioCallbackLock);
  20001. if (enableMeasurement)
  20002. ++inputLevelMeasurementEnabledCount;
  20003. else
  20004. --inputLevelMeasurementEnabledCount;
  20005. inputLevel = 0;
  20006. }
  20007. double AudioDeviceManager::getCurrentInputLevel() const
  20008. {
  20009. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  20010. return inputLevel;
  20011. }
  20012. END_JUCE_NAMESPACE
  20013. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  20014. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  20015. BEGIN_JUCE_NAMESPACE
  20016. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  20017. : name (deviceName),
  20018. typeName (typeName_)
  20019. {
  20020. }
  20021. AudioIODevice::~AudioIODevice()
  20022. {
  20023. }
  20024. bool AudioIODevice::hasControlPanel() const
  20025. {
  20026. return false;
  20027. }
  20028. bool AudioIODevice::showControlPanel()
  20029. {
  20030. jassertfalse // this should only be called for devices which return true from
  20031. // their hasControlPanel() method.
  20032. return false;
  20033. }
  20034. END_JUCE_NAMESPACE
  20035. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  20036. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  20037. BEGIN_JUCE_NAMESPACE
  20038. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  20039. : typeName (name)
  20040. {
  20041. }
  20042. AudioIODeviceType::~AudioIODeviceType()
  20043. {
  20044. }
  20045. END_JUCE_NAMESPACE
  20046. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  20047. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  20048. BEGIN_JUCE_NAMESPACE
  20049. MidiOutput::MidiOutput()
  20050. : Thread ("midi out"),
  20051. internal (0),
  20052. firstMessage (0)
  20053. {
  20054. }
  20055. MidiOutput::PendingMessage::PendingMessage (const uint8* const data, const int len,
  20056. const double sampleNumber)
  20057. : message (data, len, sampleNumber)
  20058. {
  20059. }
  20060. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  20061. const double millisecondCounterToStartAt,
  20062. double samplesPerSecondForBuffer)
  20063. {
  20064. // You've got to call startBackgroundThread() for this to actually work..
  20065. jassert (isThreadRunning());
  20066. // this needs to be a value in the future - RTFM for this method!
  20067. jassert (millisecondCounterToStartAt > 0);
  20068. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  20069. MidiBuffer::Iterator i (buffer);
  20070. const uint8* data;
  20071. int len, time;
  20072. while (i.getNextEvent (data, len, time))
  20073. {
  20074. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  20075. PendingMessage* const m
  20076. = new PendingMessage (data, len, eventTime);
  20077. const ScopedLock sl (lock);
  20078. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  20079. {
  20080. m->next = firstMessage;
  20081. firstMessage = m;
  20082. }
  20083. else
  20084. {
  20085. PendingMessage* mm = firstMessage;
  20086. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  20087. mm = mm->next;
  20088. m->next = mm->next;
  20089. mm->next = m;
  20090. }
  20091. }
  20092. notify();
  20093. }
  20094. void MidiOutput::clearAllPendingMessages()
  20095. {
  20096. const ScopedLock sl (lock);
  20097. while (firstMessage != 0)
  20098. {
  20099. PendingMessage* const m = firstMessage;
  20100. firstMessage = firstMessage->next;
  20101. delete m;
  20102. }
  20103. }
  20104. void MidiOutput::startBackgroundThread()
  20105. {
  20106. startThread (9);
  20107. }
  20108. void MidiOutput::stopBackgroundThread()
  20109. {
  20110. stopThread (5000);
  20111. }
  20112. void MidiOutput::run()
  20113. {
  20114. while (! threadShouldExit())
  20115. {
  20116. uint32 now = Time::getMillisecondCounter();
  20117. uint32 eventTime = 0;
  20118. uint32 timeToWait = 500;
  20119. PendingMessage* message;
  20120. {
  20121. const ScopedLock sl (lock);
  20122. message = firstMessage;
  20123. if (message != 0)
  20124. {
  20125. eventTime = roundToInt (message->message.getTimeStamp());
  20126. if (eventTime > now + 20)
  20127. {
  20128. timeToWait = eventTime - (now + 20);
  20129. message = 0;
  20130. }
  20131. else
  20132. {
  20133. firstMessage = message->next;
  20134. }
  20135. }
  20136. }
  20137. if (message != 0)
  20138. {
  20139. if (eventTime > now)
  20140. {
  20141. Time::waitForMillisecondCounter (eventTime);
  20142. if (threadShouldExit())
  20143. break;
  20144. }
  20145. if (eventTime > now - 200)
  20146. sendMessageNow (message->message);
  20147. delete message;
  20148. }
  20149. else
  20150. {
  20151. jassert (timeToWait < 1000 * 30);
  20152. wait (timeToWait);
  20153. }
  20154. }
  20155. clearAllPendingMessages();
  20156. }
  20157. END_JUCE_NAMESPACE
  20158. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20159. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20160. BEGIN_JUCE_NAMESPACE
  20161. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20162. {
  20163. const double maxVal = (double) 0x7fff;
  20164. char* intData = (char*) dest;
  20165. if (dest != (void*) source || destBytesPerSample <= 4)
  20166. {
  20167. for (int i = 0; i < numSamples; ++i)
  20168. {
  20169. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20170. intData += destBytesPerSample;
  20171. }
  20172. }
  20173. else
  20174. {
  20175. intData += destBytesPerSample * numSamples;
  20176. for (int i = numSamples; --i >= 0;)
  20177. {
  20178. intData -= destBytesPerSample;
  20179. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20180. }
  20181. }
  20182. }
  20183. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20184. {
  20185. const double maxVal = (double) 0x7fff;
  20186. char* intData = (char*) dest;
  20187. if (dest != (void*) source || destBytesPerSample <= 4)
  20188. {
  20189. for (int i = 0; i < numSamples; ++i)
  20190. {
  20191. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20192. intData += destBytesPerSample;
  20193. }
  20194. }
  20195. else
  20196. {
  20197. intData += destBytesPerSample * numSamples;
  20198. for (int i = numSamples; --i >= 0;)
  20199. {
  20200. intData -= destBytesPerSample;
  20201. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20202. }
  20203. }
  20204. }
  20205. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20206. {
  20207. const double maxVal = (double) 0x7fffff;
  20208. char* intData = (char*) dest;
  20209. if (dest != (void*) source || destBytesPerSample <= 4)
  20210. {
  20211. for (int i = 0; i < numSamples; ++i)
  20212. {
  20213. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20214. intData += destBytesPerSample;
  20215. }
  20216. }
  20217. else
  20218. {
  20219. intData += destBytesPerSample * numSamples;
  20220. for (int i = numSamples; --i >= 0;)
  20221. {
  20222. intData -= destBytesPerSample;
  20223. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20224. }
  20225. }
  20226. }
  20227. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20228. {
  20229. const double maxVal = (double) 0x7fffff;
  20230. char* intData = (char*) dest;
  20231. if (dest != (void*) source || destBytesPerSample <= 4)
  20232. {
  20233. for (int i = 0; i < numSamples; ++i)
  20234. {
  20235. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20236. intData += destBytesPerSample;
  20237. }
  20238. }
  20239. else
  20240. {
  20241. intData += destBytesPerSample * numSamples;
  20242. for (int i = numSamples; --i >= 0;)
  20243. {
  20244. intData -= destBytesPerSample;
  20245. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20246. }
  20247. }
  20248. }
  20249. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20250. {
  20251. const double maxVal = (double) 0x7fffffff;
  20252. char* intData = (char*) dest;
  20253. if (dest != (void*) source || destBytesPerSample <= 4)
  20254. {
  20255. for (int i = 0; i < numSamples; ++i)
  20256. {
  20257. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20258. intData += destBytesPerSample;
  20259. }
  20260. }
  20261. else
  20262. {
  20263. intData += destBytesPerSample * numSamples;
  20264. for (int i = numSamples; --i >= 0;)
  20265. {
  20266. intData -= destBytesPerSample;
  20267. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20268. }
  20269. }
  20270. }
  20271. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20272. {
  20273. const double maxVal = (double) 0x7fffffff;
  20274. char* intData = (char*) dest;
  20275. if (dest != (void*) source || destBytesPerSample <= 4)
  20276. {
  20277. for (int i = 0; i < numSamples; ++i)
  20278. {
  20279. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20280. intData += destBytesPerSample;
  20281. }
  20282. }
  20283. else
  20284. {
  20285. intData += destBytesPerSample * numSamples;
  20286. for (int i = numSamples; --i >= 0;)
  20287. {
  20288. intData -= destBytesPerSample;
  20289. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20290. }
  20291. }
  20292. }
  20293. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20294. {
  20295. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20296. char* d = (char*) dest;
  20297. for (int i = 0; i < numSamples; ++i)
  20298. {
  20299. *(float*) d = source[i];
  20300. #if JUCE_BIG_ENDIAN
  20301. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20302. #endif
  20303. d += destBytesPerSample;
  20304. }
  20305. }
  20306. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20307. {
  20308. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20309. char* d = (char*) dest;
  20310. for (int i = 0; i < numSamples; ++i)
  20311. {
  20312. *(float*) d = source[i];
  20313. #if JUCE_LITTLE_ENDIAN
  20314. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20315. #endif
  20316. d += destBytesPerSample;
  20317. }
  20318. }
  20319. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20320. {
  20321. const float scale = 1.0f / 0x7fff;
  20322. const char* intData = (const char*) source;
  20323. if (source != (void*) dest || srcBytesPerSample >= 4)
  20324. {
  20325. for (int i = 0; i < numSamples; ++i)
  20326. {
  20327. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20328. intData += srcBytesPerSample;
  20329. }
  20330. }
  20331. else
  20332. {
  20333. intData += srcBytesPerSample * numSamples;
  20334. for (int i = numSamples; --i >= 0;)
  20335. {
  20336. intData -= srcBytesPerSample;
  20337. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20338. }
  20339. }
  20340. }
  20341. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20342. {
  20343. const float scale = 1.0f / 0x7fff;
  20344. const char* intData = (const char*) source;
  20345. if (source != (void*) dest || srcBytesPerSample >= 4)
  20346. {
  20347. for (int i = 0; i < numSamples; ++i)
  20348. {
  20349. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20350. intData += srcBytesPerSample;
  20351. }
  20352. }
  20353. else
  20354. {
  20355. intData += srcBytesPerSample * numSamples;
  20356. for (int i = numSamples; --i >= 0;)
  20357. {
  20358. intData -= srcBytesPerSample;
  20359. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20360. }
  20361. }
  20362. }
  20363. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20364. {
  20365. const float scale = 1.0f / 0x7fffff;
  20366. const char* intData = (const char*) source;
  20367. if (source != (void*) dest || srcBytesPerSample >= 4)
  20368. {
  20369. for (int i = 0; i < numSamples; ++i)
  20370. {
  20371. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20372. intData += srcBytesPerSample;
  20373. }
  20374. }
  20375. else
  20376. {
  20377. intData += srcBytesPerSample * numSamples;
  20378. for (int i = numSamples; --i >= 0;)
  20379. {
  20380. intData -= srcBytesPerSample;
  20381. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20382. }
  20383. }
  20384. }
  20385. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20386. {
  20387. const float scale = 1.0f / 0x7fffff;
  20388. const char* intData = (const char*) source;
  20389. if (source != (void*) dest || srcBytesPerSample >= 4)
  20390. {
  20391. for (int i = 0; i < numSamples; ++i)
  20392. {
  20393. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20394. intData += srcBytesPerSample;
  20395. }
  20396. }
  20397. else
  20398. {
  20399. intData += srcBytesPerSample * numSamples;
  20400. for (int i = numSamples; --i >= 0;)
  20401. {
  20402. intData -= srcBytesPerSample;
  20403. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20404. }
  20405. }
  20406. }
  20407. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20408. {
  20409. const float scale = 1.0f / 0x7fffffff;
  20410. const char* intData = (const char*) source;
  20411. if (source != (void*) dest || srcBytesPerSample >= 4)
  20412. {
  20413. for (int i = 0; i < numSamples; ++i)
  20414. {
  20415. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20416. intData += srcBytesPerSample;
  20417. }
  20418. }
  20419. else
  20420. {
  20421. intData += srcBytesPerSample * numSamples;
  20422. for (int i = numSamples; --i >= 0;)
  20423. {
  20424. intData -= srcBytesPerSample;
  20425. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20426. }
  20427. }
  20428. }
  20429. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20430. {
  20431. const float scale = 1.0f / 0x7fffffff;
  20432. const char* intData = (const char*) source;
  20433. if (source != (void*) dest || srcBytesPerSample >= 4)
  20434. {
  20435. for (int i = 0; i < numSamples; ++i)
  20436. {
  20437. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20438. intData += srcBytesPerSample;
  20439. }
  20440. }
  20441. else
  20442. {
  20443. intData += srcBytesPerSample * numSamples;
  20444. for (int i = numSamples; --i >= 0;)
  20445. {
  20446. intData -= srcBytesPerSample;
  20447. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20448. }
  20449. }
  20450. }
  20451. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20452. {
  20453. const char* s = (const char*) source;
  20454. for (int i = 0; i < numSamples; ++i)
  20455. {
  20456. dest[i] = *(float*)s;
  20457. #if JUCE_BIG_ENDIAN
  20458. uint32* const d = (uint32*) (dest + i);
  20459. *d = ByteOrder::swap (*d);
  20460. #endif
  20461. s += srcBytesPerSample;
  20462. }
  20463. }
  20464. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20465. {
  20466. const char* s = (const char*) source;
  20467. for (int i = 0; i < numSamples; ++i)
  20468. {
  20469. dest[i] = *(float*)s;
  20470. #if JUCE_LITTLE_ENDIAN
  20471. uint32* const d = (uint32*) (dest + i);
  20472. *d = ByteOrder::swap (*d);
  20473. #endif
  20474. s += srcBytesPerSample;
  20475. }
  20476. }
  20477. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20478. const float* const source,
  20479. void* const dest,
  20480. const int numSamples)
  20481. {
  20482. switch (destFormat)
  20483. {
  20484. case int16LE:
  20485. convertFloatToInt16LE (source, dest, numSamples);
  20486. break;
  20487. case int16BE:
  20488. convertFloatToInt16BE (source, dest, numSamples);
  20489. break;
  20490. case int24LE:
  20491. convertFloatToInt24LE (source, dest, numSamples);
  20492. break;
  20493. case int24BE:
  20494. convertFloatToInt24BE (source, dest, numSamples);
  20495. break;
  20496. case int32LE:
  20497. convertFloatToInt32LE (source, dest, numSamples);
  20498. break;
  20499. case int32BE:
  20500. convertFloatToInt32BE (source, dest, numSamples);
  20501. break;
  20502. case float32LE:
  20503. convertFloatToFloat32LE (source, dest, numSamples);
  20504. break;
  20505. case float32BE:
  20506. convertFloatToFloat32BE (source, dest, numSamples);
  20507. break;
  20508. default:
  20509. jassertfalse
  20510. break;
  20511. }
  20512. }
  20513. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20514. const void* const source,
  20515. float* const dest,
  20516. const int numSamples)
  20517. {
  20518. switch (sourceFormat)
  20519. {
  20520. case int16LE:
  20521. convertInt16LEToFloat (source, dest, numSamples);
  20522. break;
  20523. case int16BE:
  20524. convertInt16BEToFloat (source, dest, numSamples);
  20525. break;
  20526. case int24LE:
  20527. convertInt24LEToFloat (source, dest, numSamples);
  20528. break;
  20529. case int24BE:
  20530. convertInt24BEToFloat (source, dest, numSamples);
  20531. break;
  20532. case int32LE:
  20533. convertInt32LEToFloat (source, dest, numSamples);
  20534. break;
  20535. case int32BE:
  20536. convertInt32BEToFloat (source, dest, numSamples);
  20537. break;
  20538. case float32LE:
  20539. convertFloat32LEToFloat (source, dest, numSamples);
  20540. break;
  20541. case float32BE:
  20542. convertFloat32BEToFloat (source, dest, numSamples);
  20543. break;
  20544. default:
  20545. jassertfalse
  20546. break;
  20547. }
  20548. }
  20549. void AudioDataConverters::interleaveSamples (const float** const source,
  20550. float* const dest,
  20551. const int numSamples,
  20552. const int numChannels)
  20553. {
  20554. for (int chan = 0; chan < numChannels; ++chan)
  20555. {
  20556. int i = chan;
  20557. const float* src = source [chan];
  20558. for (int j = 0; j < numSamples; ++j)
  20559. {
  20560. dest [i] = src [j];
  20561. i += numChannels;
  20562. }
  20563. }
  20564. }
  20565. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20566. float** const dest,
  20567. const int numSamples,
  20568. const int numChannels)
  20569. {
  20570. for (int chan = 0; chan < numChannels; ++chan)
  20571. {
  20572. int i = chan;
  20573. float* dst = dest [chan];
  20574. for (int j = 0; j < numSamples; ++j)
  20575. {
  20576. dst [j] = source [i];
  20577. i += numChannels;
  20578. }
  20579. }
  20580. }
  20581. END_JUCE_NAMESPACE
  20582. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20583. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20584. BEGIN_JUCE_NAMESPACE
  20585. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20586. const int numSamples) throw()
  20587. : numChannels (numChannels_),
  20588. size (numSamples)
  20589. {
  20590. jassert (numSamples >= 0);
  20591. jassert (numChannels_ > 0);
  20592. allocateData();
  20593. }
  20594. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20595. : numChannels (other.numChannels),
  20596. size (other.size)
  20597. {
  20598. allocateData();
  20599. const size_t numBytes = size * sizeof (float);
  20600. for (int i = 0; i < numChannels; ++i)
  20601. memcpy (channels[i], other.channels[i], numBytes);
  20602. }
  20603. void AudioSampleBuffer::allocateData()
  20604. {
  20605. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20606. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20607. allocatedData.malloc (allocatedBytes);
  20608. channels = reinterpret_cast <float**> (allocatedData.getData());
  20609. float* chan = (float*) (allocatedData + channelListSize);
  20610. for (int i = 0; i < numChannels; ++i)
  20611. {
  20612. channels[i] = chan;
  20613. chan += size;
  20614. }
  20615. channels [numChannels] = 0;
  20616. }
  20617. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20618. const int numChannels_,
  20619. const int numSamples) throw()
  20620. : numChannels (numChannels_),
  20621. size (numSamples),
  20622. allocatedBytes (0)
  20623. {
  20624. jassert (numChannels_ > 0);
  20625. allocateChannels (dataToReferTo);
  20626. }
  20627. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20628. const int newNumChannels,
  20629. const int newNumSamples) throw()
  20630. {
  20631. jassert (newNumChannels > 0);
  20632. allocatedBytes = 0;
  20633. allocatedData.free();
  20634. numChannels = newNumChannels;
  20635. size = newNumSamples;
  20636. allocateChannels (dataToReferTo);
  20637. }
  20638. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20639. {
  20640. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20641. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20642. {
  20643. channels = static_cast <float**> (preallocatedChannelSpace);
  20644. }
  20645. else
  20646. {
  20647. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20648. channels = reinterpret_cast <float**> (allocatedData.getData());
  20649. }
  20650. for (int i = 0; i < numChannels; ++i)
  20651. {
  20652. // you have to pass in the same number of valid pointers as numChannels
  20653. jassert (dataToReferTo[i] != 0);
  20654. channels[i] = dataToReferTo[i];
  20655. }
  20656. channels [numChannels] = 0;
  20657. }
  20658. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20659. {
  20660. if (this != &other)
  20661. {
  20662. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20663. const size_t numBytes = size * sizeof (float);
  20664. for (int i = 0; i < numChannels; ++i)
  20665. memcpy (channels[i], other.channels[i], numBytes);
  20666. }
  20667. return *this;
  20668. }
  20669. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20670. {
  20671. }
  20672. void AudioSampleBuffer::setSize (const int newNumChannels,
  20673. const int newNumSamples,
  20674. const bool keepExistingContent,
  20675. const bool clearExtraSpace,
  20676. const bool avoidReallocating) throw()
  20677. {
  20678. jassert (newNumChannels > 0);
  20679. if (newNumSamples != size || newNumChannels != numChannels)
  20680. {
  20681. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20682. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20683. if (keepExistingContent)
  20684. {
  20685. HeapBlock <char> newData;
  20686. newData.allocate (newTotalBytes, clearExtraSpace);
  20687. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20688. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20689. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20690. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20691. for (int i = 0; i < numChansToCopy; ++i)
  20692. {
  20693. memcpy (newChan, channels[i], numBytesToCopy);
  20694. newChannels[i] = newChan;
  20695. newChan += newNumSamples;
  20696. }
  20697. allocatedData.swapWith (newData);
  20698. allocatedBytes = (int) newTotalBytes;
  20699. channels = newChannels;
  20700. }
  20701. else
  20702. {
  20703. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20704. {
  20705. if (clearExtraSpace)
  20706. zeromem (allocatedData, newTotalBytes);
  20707. }
  20708. else
  20709. {
  20710. allocatedBytes = newTotalBytes;
  20711. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20712. channels = reinterpret_cast <float**> (allocatedData.getData());
  20713. }
  20714. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20715. for (int i = 0; i < newNumChannels; ++i)
  20716. {
  20717. channels[i] = chan;
  20718. chan += newNumSamples;
  20719. }
  20720. }
  20721. channels [newNumChannels] = 0;
  20722. size = newNumSamples;
  20723. numChannels = newNumChannels;
  20724. }
  20725. }
  20726. void AudioSampleBuffer::clear() throw()
  20727. {
  20728. for (int i = 0; i < numChannels; ++i)
  20729. zeromem (channels[i], size * sizeof (float));
  20730. }
  20731. void AudioSampleBuffer::clear (const int startSample,
  20732. const int numSamples) throw()
  20733. {
  20734. jassert (startSample >= 0 && startSample + numSamples <= size);
  20735. for (int i = 0; i < numChannels; ++i)
  20736. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20737. }
  20738. void AudioSampleBuffer::clear (const int channel,
  20739. const int startSample,
  20740. const int numSamples) throw()
  20741. {
  20742. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20743. jassert (startSample >= 0 && startSample + numSamples <= size);
  20744. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20745. }
  20746. void AudioSampleBuffer::applyGain (const int channel,
  20747. const int startSample,
  20748. int numSamples,
  20749. const float gain) throw()
  20750. {
  20751. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20752. jassert (startSample >= 0 && startSample + numSamples <= size);
  20753. if (gain != 1.0f)
  20754. {
  20755. float* d = channels [channel] + startSample;
  20756. if (gain == 0.0f)
  20757. {
  20758. zeromem (d, sizeof (float) * numSamples);
  20759. }
  20760. else
  20761. {
  20762. while (--numSamples >= 0)
  20763. *d++ *= gain;
  20764. }
  20765. }
  20766. }
  20767. void AudioSampleBuffer::applyGainRamp (const int channel,
  20768. const int startSample,
  20769. int numSamples,
  20770. float startGain,
  20771. float endGain) throw()
  20772. {
  20773. if (startGain == endGain)
  20774. {
  20775. applyGain (channel, startSample, numSamples, startGain);
  20776. }
  20777. else
  20778. {
  20779. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20780. jassert (startSample >= 0 && startSample + numSamples <= size);
  20781. const float increment = (endGain - startGain) / numSamples;
  20782. float* d = channels [channel] + startSample;
  20783. while (--numSamples >= 0)
  20784. {
  20785. *d++ *= startGain;
  20786. startGain += increment;
  20787. }
  20788. }
  20789. }
  20790. void AudioSampleBuffer::applyGain (const int startSample,
  20791. const int numSamples,
  20792. const float gain) throw()
  20793. {
  20794. for (int i = 0; i < numChannels; ++i)
  20795. applyGain (i, startSample, numSamples, gain);
  20796. }
  20797. void AudioSampleBuffer::addFrom (const int destChannel,
  20798. const int destStartSample,
  20799. const AudioSampleBuffer& source,
  20800. const int sourceChannel,
  20801. const int sourceStartSample,
  20802. int numSamples,
  20803. const float gain) throw()
  20804. {
  20805. jassert (&source != this || sourceChannel != destChannel);
  20806. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20807. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20808. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20809. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20810. if (gain != 0.0f && numSamples > 0)
  20811. {
  20812. float* d = channels [destChannel] + destStartSample;
  20813. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20814. if (gain != 1.0f)
  20815. {
  20816. while (--numSamples >= 0)
  20817. *d++ += gain * *s++;
  20818. }
  20819. else
  20820. {
  20821. while (--numSamples >= 0)
  20822. *d++ += *s++;
  20823. }
  20824. }
  20825. }
  20826. void AudioSampleBuffer::addFrom (const int destChannel,
  20827. const int destStartSample,
  20828. const float* source,
  20829. int numSamples,
  20830. const float gain) throw()
  20831. {
  20832. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20833. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20834. jassert (source != 0);
  20835. if (gain != 0.0f && numSamples > 0)
  20836. {
  20837. float* d = channels [destChannel] + destStartSample;
  20838. if (gain != 1.0f)
  20839. {
  20840. while (--numSamples >= 0)
  20841. *d++ += gain * *source++;
  20842. }
  20843. else
  20844. {
  20845. while (--numSamples >= 0)
  20846. *d++ += *source++;
  20847. }
  20848. }
  20849. }
  20850. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20851. const int destStartSample,
  20852. const float* source,
  20853. int numSamples,
  20854. float startGain,
  20855. const float endGain) throw()
  20856. {
  20857. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20858. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20859. jassert (source != 0);
  20860. if (startGain == endGain)
  20861. {
  20862. addFrom (destChannel,
  20863. destStartSample,
  20864. source,
  20865. numSamples,
  20866. startGain);
  20867. }
  20868. else
  20869. {
  20870. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20871. {
  20872. const float increment = (endGain - startGain) / numSamples;
  20873. float* d = channels [destChannel] + destStartSample;
  20874. while (--numSamples >= 0)
  20875. {
  20876. *d++ += startGain * *source++;
  20877. startGain += increment;
  20878. }
  20879. }
  20880. }
  20881. }
  20882. void AudioSampleBuffer::copyFrom (const int destChannel,
  20883. const int destStartSample,
  20884. const AudioSampleBuffer& source,
  20885. const int sourceChannel,
  20886. const int sourceStartSample,
  20887. int numSamples) throw()
  20888. {
  20889. jassert (&source != this || sourceChannel != destChannel);
  20890. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20891. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20892. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20893. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20894. if (numSamples > 0)
  20895. {
  20896. memcpy (channels [destChannel] + destStartSample,
  20897. source.channels [sourceChannel] + sourceStartSample,
  20898. sizeof (float) * numSamples);
  20899. }
  20900. }
  20901. void AudioSampleBuffer::copyFrom (const int destChannel,
  20902. const int destStartSample,
  20903. const float* source,
  20904. int numSamples) throw()
  20905. {
  20906. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20907. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20908. jassert (source != 0);
  20909. if (numSamples > 0)
  20910. {
  20911. memcpy (channels [destChannel] + destStartSample,
  20912. source,
  20913. sizeof (float) * numSamples);
  20914. }
  20915. }
  20916. void AudioSampleBuffer::copyFrom (const int destChannel,
  20917. const int destStartSample,
  20918. const float* source,
  20919. int numSamples,
  20920. const float gain) throw()
  20921. {
  20922. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20923. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20924. jassert (source != 0);
  20925. if (numSamples > 0)
  20926. {
  20927. float* d = channels [destChannel] + destStartSample;
  20928. if (gain != 1.0f)
  20929. {
  20930. if (gain == 0)
  20931. {
  20932. zeromem (d, sizeof (float) * numSamples);
  20933. }
  20934. else
  20935. {
  20936. while (--numSamples >= 0)
  20937. *d++ = gain * *source++;
  20938. }
  20939. }
  20940. else
  20941. {
  20942. memcpy (d, source, sizeof (float) * numSamples);
  20943. }
  20944. }
  20945. }
  20946. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20947. const int destStartSample,
  20948. const float* source,
  20949. int numSamples,
  20950. float startGain,
  20951. float endGain) throw()
  20952. {
  20953. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20954. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20955. jassert (source != 0);
  20956. if (startGain == endGain)
  20957. {
  20958. copyFrom (destChannel,
  20959. destStartSample,
  20960. source,
  20961. numSamples,
  20962. startGain);
  20963. }
  20964. else
  20965. {
  20966. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20967. {
  20968. const float increment = (endGain - startGain) / numSamples;
  20969. float* d = channels [destChannel] + destStartSample;
  20970. while (--numSamples >= 0)
  20971. {
  20972. *d++ = startGain * *source++;
  20973. startGain += increment;
  20974. }
  20975. }
  20976. }
  20977. }
  20978. void AudioSampleBuffer::findMinMax (const int channel,
  20979. const int startSample,
  20980. int numSamples,
  20981. float& minVal,
  20982. float& maxVal) const throw()
  20983. {
  20984. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20985. jassert (startSample >= 0 && startSample + numSamples <= size);
  20986. if (numSamples <= 0)
  20987. {
  20988. minVal = 0.0f;
  20989. maxVal = 0.0f;
  20990. }
  20991. else
  20992. {
  20993. const float* d = channels [channel] + startSample;
  20994. float mn = *d++;
  20995. float mx = mn;
  20996. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  20997. {
  20998. const float samp = *d++;
  20999. if (samp > mx)
  21000. mx = samp;
  21001. if (samp < mn)
  21002. mn = samp;
  21003. }
  21004. maxVal = mx;
  21005. minVal = mn;
  21006. }
  21007. }
  21008. float AudioSampleBuffer::getMagnitude (const int channel,
  21009. const int startSample,
  21010. const int numSamples) const throw()
  21011. {
  21012. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21013. jassert (startSample >= 0 && startSample + numSamples <= size);
  21014. float mn, mx;
  21015. findMinMax (channel, startSample, numSamples, mn, mx);
  21016. return jmax (mn, -mn, mx, -mx);
  21017. }
  21018. float AudioSampleBuffer::getMagnitude (const int startSample,
  21019. const int numSamples) const throw()
  21020. {
  21021. float mag = 0.0f;
  21022. for (int i = 0; i < numChannels; ++i)
  21023. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  21024. return mag;
  21025. }
  21026. float AudioSampleBuffer::getRMSLevel (const int channel,
  21027. const int startSample,
  21028. const int numSamples) const throw()
  21029. {
  21030. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21031. jassert (startSample >= 0 && startSample + numSamples <= size);
  21032. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  21033. return 0.0f;
  21034. const float* const data = channels [channel] + startSample;
  21035. double sum = 0.0;
  21036. for (int i = 0; i < numSamples; ++i)
  21037. {
  21038. const float sample = data [i];
  21039. sum += sample * sample;
  21040. }
  21041. return (float) sqrt (sum / numSamples);
  21042. }
  21043. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  21044. const int startSample,
  21045. const int numSamples,
  21046. const int readerStartSample,
  21047. const bool useLeftChan,
  21048. const bool useRightChan) throw()
  21049. {
  21050. jassert (reader != 0);
  21051. jassert (startSample >= 0 && startSample + numSamples <= size);
  21052. if (numSamples > 0)
  21053. {
  21054. int* chans[3];
  21055. if (useLeftChan == useRightChan)
  21056. {
  21057. chans[0] = (int*) getSampleData (0, startSample);
  21058. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  21059. }
  21060. else if (useLeftChan || (reader->numChannels == 1))
  21061. {
  21062. chans[0] = (int*) getSampleData (0, startSample);
  21063. chans[1] = 0;
  21064. }
  21065. else if (useRightChan)
  21066. {
  21067. chans[0] = 0;
  21068. chans[1] = (int*) getSampleData (0, startSample);
  21069. }
  21070. chans[2] = 0;
  21071. reader->read (chans, 2, readerStartSample, numSamples, true);
  21072. if (! reader->usesFloatingPointData)
  21073. {
  21074. for (int j = 0; j < 2; ++j)
  21075. {
  21076. float* const d = (float*) (chans[j]);
  21077. if (d != 0)
  21078. {
  21079. const float multiplier = 1.0f / 0x7fffffff;
  21080. for (int i = 0; i < numSamples; ++i)
  21081. d[i] = *(int*)(d + i) * multiplier;
  21082. }
  21083. }
  21084. }
  21085. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  21086. {
  21087. // if this is a stereo buffer and the source was mono, dupe the first channel..
  21088. memcpy (getSampleData (1, startSample),
  21089. getSampleData (0, startSample),
  21090. sizeof (float) * numSamples);
  21091. }
  21092. }
  21093. }
  21094. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21095. const int startSample,
  21096. const int numSamples) const throw()
  21097. {
  21098. jassert (startSample >= 0 && startSample + numSamples <= size);
  21099. if (numSamples > 0)
  21100. {
  21101. int* chans [3];
  21102. if (writer->isFloatingPoint())
  21103. {
  21104. chans[0] = (int*) getSampleData (0, startSample);
  21105. if (numChannels > 1)
  21106. chans[1] = (int*) getSampleData (1, startSample);
  21107. else
  21108. chans[1] = 0;
  21109. chans[2] = 0;
  21110. writer->write ((const int**) chans, numSamples);
  21111. }
  21112. else
  21113. {
  21114. HeapBlock <int> tempBuffer (numSamples * 2);
  21115. chans[0] = tempBuffer;
  21116. if (numChannels > 1)
  21117. chans[1] = chans[0] + numSamples;
  21118. else
  21119. chans[1] = 0;
  21120. chans[2] = 0;
  21121. for (int j = 0; j < 2; ++j)
  21122. {
  21123. int* const dest = chans[j];
  21124. if (dest != 0)
  21125. {
  21126. const float* const src = channels [j] + startSample;
  21127. for (int i = 0; i < numSamples; ++i)
  21128. {
  21129. const double samp = src[i];
  21130. if (samp <= -1.0)
  21131. dest[i] = std::numeric_limits<int>::min();
  21132. else if (samp >= 1.0)
  21133. dest[i] = std::numeric_limits<int>::max();
  21134. else
  21135. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21136. }
  21137. }
  21138. }
  21139. writer->write ((const int**) chans, numSamples);
  21140. }
  21141. }
  21142. }
  21143. END_JUCE_NAMESPACE
  21144. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21145. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21146. BEGIN_JUCE_NAMESPACE
  21147. IIRFilter::IIRFilter() throw()
  21148. : active (false)
  21149. {
  21150. reset();
  21151. }
  21152. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21153. : active (other.active)
  21154. {
  21155. const ScopedLock sl (other.processLock);
  21156. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21157. reset();
  21158. }
  21159. IIRFilter::~IIRFilter() throw()
  21160. {
  21161. }
  21162. void IIRFilter::reset() throw()
  21163. {
  21164. const ScopedLock sl (processLock);
  21165. x1 = 0;
  21166. x2 = 0;
  21167. y1 = 0;
  21168. y2 = 0;
  21169. }
  21170. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21171. {
  21172. float out = coefficients[0] * in
  21173. + coefficients[1] * x1
  21174. + coefficients[2] * x2
  21175. - coefficients[4] * y1
  21176. - coefficients[5] * y2;
  21177. #if JUCE_INTEL
  21178. if (! (out < -1.0e-8 || out > 1.0e-8))
  21179. out = 0;
  21180. #endif
  21181. x2 = x1;
  21182. x1 = in;
  21183. y2 = y1;
  21184. y1 = out;
  21185. return out;
  21186. }
  21187. void IIRFilter::processSamples (float* const samples,
  21188. const int numSamples) throw()
  21189. {
  21190. const ScopedLock sl (processLock);
  21191. if (active)
  21192. {
  21193. for (int i = 0; i < numSamples; ++i)
  21194. {
  21195. const float in = samples[i];
  21196. float out = coefficients[0] * in
  21197. + coefficients[1] * x1
  21198. + coefficients[2] * x2
  21199. - coefficients[4] * y1
  21200. - coefficients[5] * y2;
  21201. #if JUCE_INTEL
  21202. if (! (out < -1.0e-8 || out > 1.0e-8))
  21203. out = 0;
  21204. #endif
  21205. x2 = x1;
  21206. x1 = in;
  21207. y2 = y1;
  21208. y1 = out;
  21209. samples[i] = out;
  21210. }
  21211. }
  21212. }
  21213. void IIRFilter::makeLowPass (const double sampleRate,
  21214. const double frequency) throw()
  21215. {
  21216. jassert (sampleRate > 0);
  21217. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21218. const double nSquared = n * n;
  21219. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21220. setCoefficients (c1,
  21221. c1 * 2.0f,
  21222. c1,
  21223. 1.0,
  21224. c1 * 2.0 * (1.0 - nSquared),
  21225. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21226. }
  21227. void IIRFilter::makeHighPass (const double sampleRate,
  21228. const double frequency) throw()
  21229. {
  21230. const double n = tan (double_Pi * frequency / sampleRate);
  21231. const double nSquared = n * n;
  21232. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21233. setCoefficients (c1,
  21234. c1 * -2.0f,
  21235. c1,
  21236. 1.0,
  21237. c1 * 2.0 * (nSquared - 1.0),
  21238. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21239. }
  21240. void IIRFilter::makeLowShelf (const double sampleRate,
  21241. const double cutOffFrequency,
  21242. const double Q,
  21243. const float gainFactor) throw()
  21244. {
  21245. jassert (sampleRate > 0);
  21246. jassert (Q > 0);
  21247. const double A = jmax (0.0f, gainFactor);
  21248. const double aminus1 = A - 1.0;
  21249. const double aplus1 = A + 1.0;
  21250. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21251. const double coso = cos (omega);
  21252. const double beta = sin (omega) * sqrt (A) / Q;
  21253. const double aminus1TimesCoso = aminus1 * coso;
  21254. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21255. A * 2.0 * (aminus1 - aplus1 * coso),
  21256. A * (aplus1 - aminus1TimesCoso - beta),
  21257. aplus1 + aminus1TimesCoso + beta,
  21258. -2.0 * (aminus1 + aplus1 * coso),
  21259. aplus1 + aminus1TimesCoso - beta);
  21260. }
  21261. void IIRFilter::makeHighShelf (const double sampleRate,
  21262. const double cutOffFrequency,
  21263. const double Q,
  21264. const float gainFactor) throw()
  21265. {
  21266. jassert (sampleRate > 0);
  21267. jassert (Q > 0);
  21268. const double A = jmax (0.0f, gainFactor);
  21269. const double aminus1 = A - 1.0;
  21270. const double aplus1 = A + 1.0;
  21271. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21272. const double coso = cos (omega);
  21273. const double beta = sin (omega) * sqrt (A) / Q;
  21274. const double aminus1TimesCoso = aminus1 * coso;
  21275. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21276. A * -2.0 * (aminus1 + aplus1 * coso),
  21277. A * (aplus1 + aminus1TimesCoso - beta),
  21278. aplus1 - aminus1TimesCoso + beta,
  21279. 2.0 * (aminus1 - aplus1 * coso),
  21280. aplus1 - aminus1TimesCoso - beta);
  21281. }
  21282. void IIRFilter::makeBandPass (const double sampleRate,
  21283. const double centreFrequency,
  21284. const double Q,
  21285. const float gainFactor) throw()
  21286. {
  21287. jassert (sampleRate > 0);
  21288. jassert (Q > 0);
  21289. const double A = jmax (0.0f, gainFactor);
  21290. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21291. const double alpha = 0.5 * sin (omega) / Q;
  21292. const double c2 = -2.0 * cos (omega);
  21293. const double alphaTimesA = alpha * A;
  21294. const double alphaOverA = alpha / A;
  21295. setCoefficients (1.0 + alphaTimesA,
  21296. c2,
  21297. 1.0 - alphaTimesA,
  21298. 1.0 + alphaOverA,
  21299. c2,
  21300. 1.0 - alphaOverA);
  21301. }
  21302. void IIRFilter::makeInactive() throw()
  21303. {
  21304. const ScopedLock sl (processLock);
  21305. active = false;
  21306. }
  21307. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21308. {
  21309. const ScopedLock sl (processLock);
  21310. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21311. active = other.active;
  21312. }
  21313. void IIRFilter::setCoefficients (double c1,
  21314. double c2,
  21315. double c3,
  21316. double c4,
  21317. double c5,
  21318. double c6) throw()
  21319. {
  21320. const double a = 1.0 / c4;
  21321. c1 *= a;
  21322. c2 *= a;
  21323. c3 *= a;
  21324. c5 *= a;
  21325. c6 *= a;
  21326. const ScopedLock sl (processLock);
  21327. coefficients[0] = (float) c1;
  21328. coefficients[1] = (float) c2;
  21329. coefficients[2] = (float) c3;
  21330. coefficients[3] = (float) c4;
  21331. coefficients[4] = (float) c5;
  21332. coefficients[5] = (float) c6;
  21333. active = true;
  21334. }
  21335. END_JUCE_NAMESPACE
  21336. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21337. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21338. BEGIN_JUCE_NAMESPACE
  21339. MidiBuffer::MidiBuffer() throw()
  21340. : bytesUsed (0)
  21341. {
  21342. }
  21343. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21344. : bytesUsed (0)
  21345. {
  21346. addEvent (message, 0);
  21347. }
  21348. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21349. : data (other.data),
  21350. bytesUsed (other.bytesUsed)
  21351. {
  21352. }
  21353. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21354. {
  21355. bytesUsed = other.bytesUsed;
  21356. data = other.data;
  21357. return *this;
  21358. }
  21359. void MidiBuffer::swap (MidiBuffer& other)
  21360. {
  21361. data.swapWith (other.data);
  21362. swapVariables <int> (bytesUsed, other.bytesUsed);
  21363. }
  21364. MidiBuffer::~MidiBuffer() throw()
  21365. {
  21366. }
  21367. void MidiBuffer::clear() throw()
  21368. {
  21369. bytesUsed = 0;
  21370. }
  21371. void MidiBuffer::clear (const int startSample,
  21372. const int numSamples) throw()
  21373. {
  21374. uint8* const start = findEventAfter (getData(), startSample - 1);
  21375. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21376. if (end > start)
  21377. {
  21378. const size_t bytesToMove = (size_t) (bytesUsed - (end - getData()));
  21379. if (bytesToMove > 0)
  21380. memmove (start, end, bytesToMove);
  21381. bytesUsed -= (int) (end - start);
  21382. }
  21383. }
  21384. void MidiBuffer::addEvent (const MidiMessage& m,
  21385. const int sampleNumber) throw()
  21386. {
  21387. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21388. }
  21389. static int findActualEventLength (const uint8* const data,
  21390. const int maxBytes) throw()
  21391. {
  21392. unsigned int byte = (unsigned int) *data;
  21393. int size = 0;
  21394. if (byte == 0xf0 || byte == 0xf7)
  21395. {
  21396. const uint8* d = data + 1;
  21397. while (d < data + maxBytes)
  21398. if (*d++ == 0xf7)
  21399. break;
  21400. size = (int) (d - data);
  21401. }
  21402. else if (byte == 0xff)
  21403. {
  21404. int n;
  21405. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21406. size = jmin (maxBytes, n + 2 + bytesLeft);
  21407. }
  21408. else if (byte >= 0x80)
  21409. {
  21410. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21411. }
  21412. return size;
  21413. }
  21414. void MidiBuffer::addEvent (const uint8* const newData,
  21415. const int maxBytes,
  21416. const int sampleNumber) throw()
  21417. {
  21418. const int numBytes = findActualEventLength (newData, maxBytes);
  21419. if (numBytes > 0)
  21420. {
  21421. int spaceNeeded = bytesUsed + numBytes + 6;
  21422. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21423. uint8* d = findEventAfter (getData(), sampleNumber);
  21424. const size_t bytesToMove = (size_t) (bytesUsed - (d - getData()));
  21425. if (bytesToMove > 0)
  21426. memmove (d + numBytes + 6,
  21427. d,
  21428. bytesToMove);
  21429. *(int*) d = sampleNumber;
  21430. d += 4;
  21431. *(uint16*) d = (uint16) numBytes;
  21432. d += 2;
  21433. memcpy (d, newData, numBytes);
  21434. bytesUsed += numBytes + 6;
  21435. }
  21436. }
  21437. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21438. const int startSample,
  21439. const int numSamples,
  21440. const int sampleDeltaToAdd) throw()
  21441. {
  21442. Iterator i (otherBuffer);
  21443. i.setNextSamplePosition (startSample);
  21444. const uint8* eventData;
  21445. int eventSize, position;
  21446. while (i.getNextEvent (eventData, eventSize, position)
  21447. && (position < startSample + numSamples || numSamples < 0))
  21448. {
  21449. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21450. }
  21451. }
  21452. bool MidiBuffer::isEmpty() const throw()
  21453. {
  21454. return bytesUsed == 0;
  21455. }
  21456. int MidiBuffer::getNumEvents() const throw()
  21457. {
  21458. int n = 0;
  21459. const uint8* d = getData();
  21460. const uint8* const end = d + bytesUsed;
  21461. while (d < end)
  21462. {
  21463. d += 4;
  21464. d += 2 + *(const uint16*) d;
  21465. ++n;
  21466. }
  21467. return n;
  21468. }
  21469. int MidiBuffer::getFirstEventTime() const throw()
  21470. {
  21471. return (bytesUsed > 0) ? *reinterpret_cast <const int*> (data.getData()) : 0;
  21472. }
  21473. int MidiBuffer::getLastEventTime() const throw()
  21474. {
  21475. if (bytesUsed == 0)
  21476. return 0;
  21477. const uint8* d = getData();
  21478. const uint8* const endData = d + bytesUsed;
  21479. for (;;)
  21480. {
  21481. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21482. if (nextOne >= endData)
  21483. return *(const int*) d;
  21484. d = nextOne;
  21485. }
  21486. }
  21487. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21488. {
  21489. const uint8* const endData = getData() + bytesUsed;
  21490. while (d < endData && *(int*) d <= samplePosition)
  21491. {
  21492. d += 4;
  21493. d += 2 + *(uint16*) d;
  21494. }
  21495. return d;
  21496. }
  21497. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21498. : buffer (buffer_),
  21499. data (buffer_.getData())
  21500. {
  21501. }
  21502. MidiBuffer::Iterator::~Iterator() throw()
  21503. {
  21504. }
  21505. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21506. {
  21507. data = buffer.getData();
  21508. const uint8* dataEnd = data + buffer.bytesUsed;
  21509. while (data < dataEnd && *reinterpret_cast<const int*> (data) < samplePosition)
  21510. {
  21511. data += 4;
  21512. data += 2 + *(uint16*) data;
  21513. }
  21514. }
  21515. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21516. int& numBytes,
  21517. int& samplePosition) throw()
  21518. {
  21519. if (data >= buffer.getData() + buffer.bytesUsed)
  21520. return false;
  21521. samplePosition = *(int*) data;
  21522. data += 4;
  21523. numBytes = *(uint16*) data;
  21524. data += 2;
  21525. midiData = data;
  21526. data += numBytes;
  21527. return true;
  21528. }
  21529. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21530. int& samplePosition) throw()
  21531. {
  21532. if (data >= buffer.getData() + buffer.bytesUsed)
  21533. return false;
  21534. samplePosition = *reinterpret_cast <const int*> (data);
  21535. data += 4;
  21536. const int numBytes = *reinterpret_cast <const uint16*> (data);
  21537. data += 2;
  21538. result = MidiMessage (data, numBytes, samplePosition);
  21539. data += numBytes;
  21540. return true;
  21541. }
  21542. END_JUCE_NAMESPACE
  21543. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21544. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21545. BEGIN_JUCE_NAMESPACE
  21546. namespace MidiFileHelpers
  21547. {
  21548. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21549. {
  21550. unsigned int buffer = v & 0x7F;
  21551. while ((v >>= 7) != 0)
  21552. {
  21553. buffer <<= 8;
  21554. buffer |= ((v & 0x7F) | 0x80);
  21555. }
  21556. for (;;)
  21557. {
  21558. out.writeByte ((char) buffer);
  21559. if (buffer & 0x80)
  21560. buffer >>= 8;
  21561. else
  21562. break;
  21563. }
  21564. }
  21565. static bool parseMidiHeader (const char* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21566. {
  21567. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21568. data += 4;
  21569. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21570. {
  21571. bool ok = false;
  21572. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21573. {
  21574. for (int i = 0; i < 8; ++i)
  21575. {
  21576. ch = ByteOrder::bigEndianInt (data);
  21577. data += 4;
  21578. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21579. {
  21580. ok = true;
  21581. break;
  21582. }
  21583. }
  21584. }
  21585. if (! ok)
  21586. return false;
  21587. }
  21588. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21589. data += 4;
  21590. fileType = (short) ByteOrder::bigEndianShort (data);
  21591. data += 2;
  21592. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21593. data += 2;
  21594. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21595. data += 2;
  21596. bytesRemaining -= 6;
  21597. data += bytesRemaining;
  21598. return true;
  21599. }
  21600. static double convertTicksToSeconds (const double time,
  21601. const MidiMessageSequence& tempoEvents,
  21602. const int timeFormat)
  21603. {
  21604. if (timeFormat > 0)
  21605. {
  21606. int numer = 4, denom = 4;
  21607. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21608. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21609. double secsPerTick = 0.5 * tickLen;
  21610. const int numEvents = tempoEvents.getNumEvents();
  21611. for (int i = 0; i < numEvents; ++i)
  21612. {
  21613. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21614. if (time <= m.getTimeStamp())
  21615. break;
  21616. if (timeFormat > 0)
  21617. {
  21618. correctedTempoTime = correctedTempoTime
  21619. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21620. }
  21621. else
  21622. {
  21623. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21624. }
  21625. tempoTime = m.getTimeStamp();
  21626. if (m.isTempoMetaEvent())
  21627. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21628. else if (m.isTimeSignatureMetaEvent())
  21629. m.getTimeSignatureInfo (numer, denom);
  21630. while (i + 1 < numEvents)
  21631. {
  21632. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21633. if (m2.getTimeStamp() == tempoTime)
  21634. {
  21635. ++i;
  21636. if (m2.isTempoMetaEvent())
  21637. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21638. else if (m2.isTimeSignatureMetaEvent())
  21639. m2.getTimeSignatureInfo (numer, denom);
  21640. }
  21641. else
  21642. {
  21643. break;
  21644. }
  21645. }
  21646. }
  21647. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21648. }
  21649. else
  21650. {
  21651. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21652. }
  21653. }
  21654. }
  21655. MidiFile::MidiFile() throw()
  21656. : timeFormat ((short) (unsigned short) 0xe728)
  21657. {
  21658. }
  21659. MidiFile::~MidiFile() throw()
  21660. {
  21661. clear();
  21662. }
  21663. void MidiFile::clear() throw()
  21664. {
  21665. tracks.clear();
  21666. }
  21667. int MidiFile::getNumTracks() const throw()
  21668. {
  21669. return tracks.size();
  21670. }
  21671. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21672. {
  21673. return tracks [index];
  21674. }
  21675. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21676. {
  21677. tracks.add (new MidiMessageSequence (trackSequence));
  21678. }
  21679. short MidiFile::getTimeFormat() const throw()
  21680. {
  21681. return timeFormat;
  21682. }
  21683. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21684. {
  21685. timeFormat = (short)ticks;
  21686. }
  21687. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21688. const int subframeResolution) throw()
  21689. {
  21690. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21691. }
  21692. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21693. {
  21694. for (int i = tracks.size(); --i >= 0;)
  21695. {
  21696. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21697. for (int j = 0; j < numEvents; ++j)
  21698. {
  21699. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21700. if (m.isTempoMetaEvent())
  21701. tempoChangeEvents.addEvent (m);
  21702. }
  21703. }
  21704. }
  21705. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21706. {
  21707. for (int i = tracks.size(); --i >= 0;)
  21708. {
  21709. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21710. for (int j = 0; j < numEvents; ++j)
  21711. {
  21712. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21713. if (m.isTimeSignatureMetaEvent())
  21714. timeSigEvents.addEvent (m);
  21715. }
  21716. }
  21717. }
  21718. double MidiFile::getLastTimestamp() const
  21719. {
  21720. double t = 0.0;
  21721. for (int i = tracks.size(); --i >= 0;)
  21722. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21723. return t;
  21724. }
  21725. bool MidiFile::readFrom (InputStream& sourceStream)
  21726. {
  21727. clear();
  21728. MemoryBlock data;
  21729. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21730. // (put a sanity-check on the file size, as midi files are generally small)
  21731. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21732. {
  21733. size_t size = data.getSize();
  21734. const char* d = (char*) data.getData();
  21735. short fileType, expectedTracks;
  21736. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21737. {
  21738. size -= (int) (d - (char*) data.getData());
  21739. int track = 0;
  21740. while (size > 0 && track < expectedTracks)
  21741. {
  21742. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21743. d += 4;
  21744. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21745. d += 4;
  21746. if (chunkSize <= 0)
  21747. break;
  21748. if (size < 0)
  21749. return false;
  21750. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21751. {
  21752. readNextTrack (d, chunkSize);
  21753. }
  21754. size -= chunkSize + 8;
  21755. d += chunkSize;
  21756. ++track;
  21757. }
  21758. return true;
  21759. }
  21760. }
  21761. return false;
  21762. }
  21763. // a comparator that puts all the note-offs before note-ons that have the same time
  21764. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21765. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21766. {
  21767. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21768. if (diff == 0)
  21769. {
  21770. if (first->message.isNoteOff() && second->message.isNoteOn())
  21771. return -1;
  21772. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21773. return 1;
  21774. else
  21775. return 0;
  21776. }
  21777. else
  21778. {
  21779. return (diff > 0) ? 1 : -1;
  21780. }
  21781. }
  21782. void MidiFile::readNextTrack (const char* data, int size)
  21783. {
  21784. double time = 0;
  21785. char lastStatusByte = 0;
  21786. MidiMessageSequence result;
  21787. while (size > 0)
  21788. {
  21789. int bytesUsed;
  21790. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21791. data += bytesUsed;
  21792. size -= bytesUsed;
  21793. time += delay;
  21794. int messSize = 0;
  21795. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21796. if (messSize <= 0)
  21797. break;
  21798. size -= messSize;
  21799. data += messSize;
  21800. result.addEvent (mm);
  21801. const char firstByte = *(mm.getRawData());
  21802. if ((firstByte & 0xf0) != 0xf0)
  21803. lastStatusByte = firstByte;
  21804. }
  21805. // use a sort that puts all the note-offs before note-ons that have the same time
  21806. result.list.sort (*this, true);
  21807. result.updateMatchedPairs();
  21808. addTrack (result);
  21809. }
  21810. void MidiFile::convertTimestampTicksToSeconds()
  21811. {
  21812. MidiMessageSequence tempoEvents;
  21813. findAllTempoEvents (tempoEvents);
  21814. findAllTimeSigEvents (tempoEvents);
  21815. for (int i = 0; i < tracks.size(); ++i)
  21816. {
  21817. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21818. for (int j = ms.getNumEvents(); --j >= 0;)
  21819. {
  21820. MidiMessage& m = ms.getEventPointer(j)->message;
  21821. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21822. tempoEvents,
  21823. timeFormat));
  21824. }
  21825. }
  21826. }
  21827. bool MidiFile::writeTo (OutputStream& out)
  21828. {
  21829. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21830. out.writeIntBigEndian (6);
  21831. out.writeShortBigEndian (1); // type
  21832. out.writeShortBigEndian ((short) tracks.size());
  21833. out.writeShortBigEndian (timeFormat);
  21834. for (int i = 0; i < tracks.size(); ++i)
  21835. writeTrack (out, i);
  21836. out.flush();
  21837. return true;
  21838. }
  21839. void MidiFile::writeTrack (OutputStream& mainOut,
  21840. const int trackNum)
  21841. {
  21842. MemoryOutputStream out;
  21843. const MidiMessageSequence& ms = *tracks[trackNum];
  21844. int lastTick = 0;
  21845. char lastStatusByte = 0;
  21846. for (int i = 0; i < ms.getNumEvents(); ++i)
  21847. {
  21848. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21849. const int tick = roundToInt (mm.getTimeStamp());
  21850. const int delta = jmax (0, tick - lastTick);
  21851. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21852. lastTick = tick;
  21853. const char statusByte = *(mm.getRawData());
  21854. if ((statusByte == lastStatusByte)
  21855. && ((statusByte & 0xf0) != 0xf0)
  21856. && i > 0
  21857. && mm.getRawDataSize() > 1)
  21858. {
  21859. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21860. }
  21861. else
  21862. {
  21863. out.write (mm.getRawData(), mm.getRawDataSize());
  21864. }
  21865. lastStatusByte = statusByte;
  21866. }
  21867. out.writeByte (0);
  21868. const MidiMessage m (MidiMessage::endOfTrack());
  21869. out.write (m.getRawData(),
  21870. m.getRawDataSize());
  21871. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21872. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21873. mainOut.write (out.getData(), (int) out.getDataSize());
  21874. }
  21875. END_JUCE_NAMESPACE
  21876. /*** End of inlined file: juce_MidiFile.cpp ***/
  21877. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21878. BEGIN_JUCE_NAMESPACE
  21879. MidiKeyboardState::MidiKeyboardState()
  21880. {
  21881. zeromem (noteStates, sizeof (noteStates));
  21882. }
  21883. MidiKeyboardState::~MidiKeyboardState()
  21884. {
  21885. }
  21886. void MidiKeyboardState::reset()
  21887. {
  21888. const ScopedLock sl (lock);
  21889. zeromem (noteStates, sizeof (noteStates));
  21890. eventsToAdd.clear();
  21891. }
  21892. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21893. {
  21894. jassert (midiChannel >= 0 && midiChannel <= 16);
  21895. return ((unsigned int) n) < 128
  21896. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21897. }
  21898. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21899. {
  21900. return ((unsigned int) n) < 128
  21901. && (noteStates[n] & midiChannelMask) != 0;
  21902. }
  21903. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21904. {
  21905. jassert (midiChannel >= 0 && midiChannel <= 16);
  21906. jassert (((unsigned int) midiNoteNumber) < 128);
  21907. const ScopedLock sl (lock);
  21908. if (((unsigned int) midiNoteNumber) < 128)
  21909. {
  21910. const int timeNow = (int) Time::getMillisecondCounter();
  21911. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21912. eventsToAdd.clear (0, timeNow - 500);
  21913. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21914. }
  21915. }
  21916. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21917. {
  21918. if (((unsigned int) midiNoteNumber) < 128)
  21919. {
  21920. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21921. for (int i = listeners.size(); --i >= 0;)
  21922. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21923. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21924. }
  21925. }
  21926. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21927. {
  21928. const ScopedLock sl (lock);
  21929. if (isNoteOn (midiChannel, midiNoteNumber))
  21930. {
  21931. const int timeNow = (int) Time::getMillisecondCounter();
  21932. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21933. eventsToAdd.clear (0, timeNow - 500);
  21934. noteOffInternal (midiChannel, midiNoteNumber);
  21935. }
  21936. }
  21937. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21938. {
  21939. if (isNoteOn (midiChannel, midiNoteNumber))
  21940. {
  21941. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21942. for (int i = listeners.size(); --i >= 0;)
  21943. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21944. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  21945. }
  21946. }
  21947. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21948. {
  21949. const ScopedLock sl (lock);
  21950. if (midiChannel <= 0)
  21951. {
  21952. for (int i = 1; i <= 16; ++i)
  21953. allNotesOff (i);
  21954. }
  21955. else
  21956. {
  21957. for (int i = 0; i < 128; ++i)
  21958. noteOff (midiChannel, i);
  21959. }
  21960. }
  21961. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21962. {
  21963. if (message.isNoteOn())
  21964. {
  21965. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21966. }
  21967. else if (message.isNoteOff())
  21968. {
  21969. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21970. }
  21971. else if (message.isAllNotesOff())
  21972. {
  21973. for (int i = 0; i < 128; ++i)
  21974. noteOffInternal (message.getChannel(), i);
  21975. }
  21976. }
  21977. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  21978. const int startSample,
  21979. const int numSamples,
  21980. const bool injectIndirectEvents)
  21981. {
  21982. MidiBuffer::Iterator i (buffer);
  21983. MidiMessage message (0xf4, 0.0);
  21984. int time;
  21985. const ScopedLock sl (lock);
  21986. while (i.getNextEvent (message, time))
  21987. processNextMidiEvent (message);
  21988. if (injectIndirectEvents)
  21989. {
  21990. MidiBuffer::Iterator i2 (eventsToAdd);
  21991. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  21992. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  21993. while (i2.getNextEvent (message, time))
  21994. {
  21995. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  21996. buffer.addEvent (message, startSample + pos);
  21997. }
  21998. }
  21999. eventsToAdd.clear();
  22000. }
  22001. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  22002. {
  22003. const ScopedLock sl (lock);
  22004. listeners.addIfNotAlreadyThere (listener);
  22005. }
  22006. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  22007. {
  22008. const ScopedLock sl (lock);
  22009. listeners.removeValue (listener);
  22010. }
  22011. END_JUCE_NAMESPACE
  22012. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  22013. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  22014. BEGIN_JUCE_NAMESPACE
  22015. int MidiMessage::readVariableLengthVal (const uint8* data,
  22016. int& numBytesUsed) throw()
  22017. {
  22018. numBytesUsed = 0;
  22019. int v = 0;
  22020. int i;
  22021. do
  22022. {
  22023. i = (int) *data++;
  22024. if (++numBytesUsed > 6)
  22025. break;
  22026. v = (v << 7) + (i & 0x7f);
  22027. } while (i & 0x80);
  22028. return v;
  22029. }
  22030. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  22031. {
  22032. // this method only works for valid starting bytes of a short midi message
  22033. jassert (firstByte >= 0x80
  22034. && firstByte != 0xf0
  22035. && firstByte != 0xf7);
  22036. static const char messageLengths[] =
  22037. {
  22038. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22039. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22040. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22041. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22042. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22043. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22044. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22045. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  22046. };
  22047. return messageLengths [firstByte & 0x7f];
  22048. }
  22049. MidiMessage::MidiMessage (const uint8* const d,
  22050. const int dataSize,
  22051. const double t) throw()
  22052. : timeStamp (t),
  22053. message (0),
  22054. size (dataSize)
  22055. {
  22056. jassert (dataSize > 0);
  22057. if (dataSize <= 4)
  22058. data = (uint8*) &message;
  22059. else
  22060. data = (uint8*) juce_malloc (dataSize);
  22061. memcpy (data, d, dataSize);
  22062. // check that the length matches the data..
  22063. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  22064. }
  22065. MidiMessage::MidiMessage (const int byte1,
  22066. const double t) throw()
  22067. : timeStamp (t),
  22068. data ((uint8*) &message),
  22069. size (1)
  22070. {
  22071. data[0] = (uint8) byte1;
  22072. // check that the length matches the data..
  22073. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  22074. }
  22075. MidiMessage::MidiMessage (const int byte1,
  22076. const int byte2,
  22077. const double t) throw()
  22078. : timeStamp (t),
  22079. data ((uint8*) &message),
  22080. size (2)
  22081. {
  22082. data[0] = (uint8) byte1;
  22083. data[1] = (uint8) byte2;
  22084. // check that the length matches the data..
  22085. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  22086. }
  22087. MidiMessage::MidiMessage (const int byte1,
  22088. const int byte2,
  22089. const int byte3,
  22090. const double t) throw()
  22091. : timeStamp (t),
  22092. data ((uint8*) &message),
  22093. size (3)
  22094. {
  22095. data[0] = (uint8) byte1;
  22096. data[1] = (uint8) byte2;
  22097. data[2] = (uint8) byte3;
  22098. // check that the length matches the data..
  22099. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22100. }
  22101. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22102. : timeStamp (other.timeStamp),
  22103. message (other.message),
  22104. size (other.size)
  22105. {
  22106. if (other.data != (uint8*) &other.message)
  22107. {
  22108. data = (uint8*) juce_malloc (size);
  22109. memcpy (data, other.data, size);
  22110. }
  22111. else
  22112. {
  22113. data = (uint8*) &message;
  22114. }
  22115. }
  22116. MidiMessage::MidiMessage (const MidiMessage& other,
  22117. const double newTimeStamp) throw()
  22118. : timeStamp (newTimeStamp),
  22119. message (other.message),
  22120. size (other.size)
  22121. {
  22122. if (other.data != (uint8*) &other.message)
  22123. {
  22124. data = (uint8*) juce_malloc (size);
  22125. memcpy (data, other.data, size);
  22126. }
  22127. else
  22128. {
  22129. data = (uint8*) &message;
  22130. }
  22131. }
  22132. MidiMessage::MidiMessage (const uint8* src,
  22133. int sz,
  22134. int& numBytesUsed,
  22135. const uint8 lastStatusByte,
  22136. double t) throw()
  22137. : timeStamp (t),
  22138. data ((uint8*) &message),
  22139. message (0)
  22140. {
  22141. unsigned int byte = (unsigned int) *src;
  22142. if (byte < 0x80)
  22143. {
  22144. byte = (unsigned int) (uint8) lastStatusByte;
  22145. numBytesUsed = -1;
  22146. }
  22147. else
  22148. {
  22149. numBytesUsed = 0;
  22150. --sz;
  22151. ++src;
  22152. }
  22153. if (byte >= 0x80)
  22154. {
  22155. if (byte == 0xf0)
  22156. {
  22157. const uint8* d = (const uint8*) src;
  22158. while (d < src + sz)
  22159. {
  22160. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22161. {
  22162. if (*d == 0xf7) // include an 0xf7 if we hit one
  22163. ++d;
  22164. break;
  22165. }
  22166. ++d;
  22167. }
  22168. size = 1 + (int) (d - src);
  22169. data = (uint8*) juce_malloc (size);
  22170. *data = (uint8) byte;
  22171. memcpy (data + 1, src, size - 1);
  22172. }
  22173. else if (byte == 0xff)
  22174. {
  22175. int n;
  22176. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22177. size = jmin (sz + 1, n + 2 + bytesLeft);
  22178. data = (uint8*) juce_malloc (size);
  22179. *data = (uint8) byte;
  22180. memcpy (data + 1, src, size - 1);
  22181. }
  22182. else
  22183. {
  22184. size = getMessageLengthFromFirstByte ((uint8) byte);
  22185. *data = (uint8) byte;
  22186. if (size > 1)
  22187. {
  22188. data[1] = src[0];
  22189. if (size > 2)
  22190. data[2] = src[1];
  22191. }
  22192. }
  22193. numBytesUsed += size;
  22194. }
  22195. else
  22196. {
  22197. message = 0;
  22198. size = 0;
  22199. }
  22200. }
  22201. MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22202. {
  22203. if (this != &other)
  22204. {
  22205. timeStamp = other.timeStamp;
  22206. size = other.size;
  22207. message = other.message;
  22208. if (data != (uint8*) &message)
  22209. juce_free (data);
  22210. if (other.data != (uint8*) &other.message)
  22211. {
  22212. data = (uint8*) juce_malloc (size);
  22213. memcpy (data, other.data, size);
  22214. }
  22215. else
  22216. {
  22217. data = (uint8*) &message;
  22218. }
  22219. }
  22220. return *this;
  22221. }
  22222. MidiMessage::~MidiMessage() throw()
  22223. {
  22224. if (data != (uint8*) &message)
  22225. juce_free (data);
  22226. }
  22227. int MidiMessage::getChannel() const throw()
  22228. {
  22229. if ((data[0] & 0xf0) != 0xf0)
  22230. return (data[0] & 0xf) + 1;
  22231. else
  22232. return 0;
  22233. }
  22234. bool MidiMessage::isForChannel (const int channel) const throw()
  22235. {
  22236. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22237. return ((data[0] & 0xf) == channel - 1)
  22238. && ((data[0] & 0xf0) != 0xf0);
  22239. }
  22240. void MidiMessage::setChannel (const int channel) throw()
  22241. {
  22242. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22243. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22244. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22245. | (uint8)(channel - 1));
  22246. }
  22247. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22248. {
  22249. return ((data[0] & 0xf0) == 0x90)
  22250. && (returnTrueForVelocity0 || data[2] != 0);
  22251. }
  22252. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22253. {
  22254. return ((data[0] & 0xf0) == 0x80)
  22255. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22256. }
  22257. bool MidiMessage::isNoteOnOrOff() const throw()
  22258. {
  22259. const int d = data[0] & 0xf0;
  22260. return (d == 0x90) || (d == 0x80);
  22261. }
  22262. int MidiMessage::getNoteNumber() const throw()
  22263. {
  22264. return data[1];
  22265. }
  22266. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22267. {
  22268. if (isNoteOnOrOff())
  22269. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22270. }
  22271. uint8 MidiMessage::getVelocity() const throw()
  22272. {
  22273. if (isNoteOnOrOff())
  22274. return data[2];
  22275. else
  22276. return 0;
  22277. }
  22278. float MidiMessage::getFloatVelocity() const throw()
  22279. {
  22280. return getVelocity() * (1.0f / 127.0f);
  22281. }
  22282. void MidiMessage::setVelocity (const float newVelocity) throw()
  22283. {
  22284. if (isNoteOnOrOff())
  22285. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22286. }
  22287. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22288. {
  22289. if (isNoteOnOrOff())
  22290. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22291. }
  22292. bool MidiMessage::isAftertouch() const throw()
  22293. {
  22294. return (data[0] & 0xf0) == 0xa0;
  22295. }
  22296. int MidiMessage::getAfterTouchValue() const throw()
  22297. {
  22298. return data[2];
  22299. }
  22300. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22301. const int noteNum,
  22302. const int aftertouchValue) throw()
  22303. {
  22304. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22305. jassert (((unsigned int) noteNum) <= 127);
  22306. jassert (((unsigned int) aftertouchValue) <= 127);
  22307. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22308. noteNum & 0x7f,
  22309. aftertouchValue & 0x7f);
  22310. }
  22311. bool MidiMessage::isChannelPressure() const throw()
  22312. {
  22313. return (data[0] & 0xf0) == 0xd0;
  22314. }
  22315. int MidiMessage::getChannelPressureValue() const throw()
  22316. {
  22317. jassert (isChannelPressure());
  22318. return data[1];
  22319. }
  22320. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22321. const int pressure) throw()
  22322. {
  22323. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22324. jassert (((unsigned int) pressure) <= 127);
  22325. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22326. pressure & 0x7f);
  22327. }
  22328. bool MidiMessage::isProgramChange() const throw()
  22329. {
  22330. return (data[0] & 0xf0) == 0xc0;
  22331. }
  22332. int MidiMessage::getProgramChangeNumber() const throw()
  22333. {
  22334. return data[1];
  22335. }
  22336. const MidiMessage MidiMessage::programChange (const int channel,
  22337. const int programNumber) throw()
  22338. {
  22339. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22340. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22341. programNumber & 0x7f);
  22342. }
  22343. bool MidiMessage::isPitchWheel() const throw()
  22344. {
  22345. return (data[0] & 0xf0) == 0xe0;
  22346. }
  22347. int MidiMessage::getPitchWheelValue() const throw()
  22348. {
  22349. return data[1] | (data[2] << 7);
  22350. }
  22351. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22352. const int position) throw()
  22353. {
  22354. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22355. jassert (((unsigned int) position) <= 0x3fff);
  22356. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22357. position & 127,
  22358. (position >> 7) & 127);
  22359. }
  22360. bool MidiMessage::isController() const throw()
  22361. {
  22362. return (data[0] & 0xf0) == 0xb0;
  22363. }
  22364. int MidiMessage::getControllerNumber() const throw()
  22365. {
  22366. jassert (isController());
  22367. return data[1];
  22368. }
  22369. int MidiMessage::getControllerValue() const throw()
  22370. {
  22371. jassert (isController());
  22372. return data[2];
  22373. }
  22374. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22375. const int controllerType,
  22376. const int value) throw()
  22377. {
  22378. // the channel must be between 1 and 16 inclusive
  22379. jassert (channel > 0 && channel <= 16);
  22380. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22381. controllerType & 127,
  22382. value & 127);
  22383. }
  22384. const MidiMessage MidiMessage::noteOn (const int channel,
  22385. const int noteNumber,
  22386. const float velocity) throw()
  22387. {
  22388. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22389. }
  22390. const MidiMessage MidiMessage::noteOn (const int channel,
  22391. const int noteNumber,
  22392. const uint8 velocity) throw()
  22393. {
  22394. jassert (channel > 0 && channel <= 16);
  22395. jassert (((unsigned int) noteNumber) <= 127);
  22396. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22397. noteNumber & 127,
  22398. jlimit (0, 127, roundToInt (velocity)));
  22399. }
  22400. const MidiMessage MidiMessage::noteOff (const int channel,
  22401. const int noteNumber) throw()
  22402. {
  22403. jassert (channel > 0 && channel <= 16);
  22404. jassert (((unsigned int) noteNumber) <= 127);
  22405. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22406. }
  22407. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22408. {
  22409. jassert (channel > 0 && channel <= 16);
  22410. return controllerEvent (channel, 123, 0);
  22411. }
  22412. bool MidiMessage::isAllNotesOff() const throw()
  22413. {
  22414. return (data[0] & 0xf0) == 0xb0
  22415. && data[1] == 123;
  22416. }
  22417. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22418. {
  22419. return controllerEvent (channel, 120, 0);
  22420. }
  22421. bool MidiMessage::isAllSoundOff() const throw()
  22422. {
  22423. return (data[0] & 0xf0) == 0xb0
  22424. && data[1] == 120;
  22425. }
  22426. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22427. {
  22428. return controllerEvent (channel, 121, 0);
  22429. }
  22430. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22431. {
  22432. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22433. uint8 buf[8];
  22434. buf[0] = 0xf0;
  22435. buf[1] = 0x7f;
  22436. buf[2] = 0x7f;
  22437. buf[3] = 0x04;
  22438. buf[4] = 0x01;
  22439. buf[5] = (uint8) (vol & 0x7f);
  22440. buf[6] = (uint8) (vol >> 7);
  22441. buf[7] = 0xf7;
  22442. return MidiMessage (buf, 8);
  22443. }
  22444. bool MidiMessage::isSysEx() const throw()
  22445. {
  22446. return *data == 0xf0;
  22447. }
  22448. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22449. const int dataSize) throw()
  22450. {
  22451. MemoryBlock mm (dataSize + 2);
  22452. uint8* const m = (uint8*) mm.getData();
  22453. m[0] = 0xf0;
  22454. memcpy (m + 1, sysexData, dataSize);
  22455. m[dataSize + 1] = 0xf7;
  22456. return MidiMessage (m, dataSize + 2);
  22457. }
  22458. const uint8* MidiMessage::getSysExData() const throw()
  22459. {
  22460. return (isSysEx()) ? getRawData() + 1
  22461. : 0;
  22462. }
  22463. int MidiMessage::getSysExDataSize() const throw()
  22464. {
  22465. return (isSysEx()) ? size - 2
  22466. : 0;
  22467. }
  22468. bool MidiMessage::isMetaEvent() const throw()
  22469. {
  22470. return *data == 0xff;
  22471. }
  22472. bool MidiMessage::isActiveSense() const throw()
  22473. {
  22474. return *data == 0xfe;
  22475. }
  22476. int MidiMessage::getMetaEventType() const throw()
  22477. {
  22478. if (*data != 0xff)
  22479. return -1;
  22480. else
  22481. return data[1];
  22482. }
  22483. int MidiMessage::getMetaEventLength() const throw()
  22484. {
  22485. if (*data == 0xff)
  22486. {
  22487. int n;
  22488. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22489. }
  22490. return 0;
  22491. }
  22492. const uint8* MidiMessage::getMetaEventData() const throw()
  22493. {
  22494. int n;
  22495. const uint8* d = data + 2;
  22496. readVariableLengthVal (d, n);
  22497. return d + n;
  22498. }
  22499. bool MidiMessage::isTrackMetaEvent() const throw()
  22500. {
  22501. return getMetaEventType() == 0;
  22502. }
  22503. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22504. {
  22505. return getMetaEventType() == 47;
  22506. }
  22507. bool MidiMessage::isTextMetaEvent() const throw()
  22508. {
  22509. const int t = getMetaEventType();
  22510. return t > 0 && t < 16;
  22511. }
  22512. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22513. {
  22514. return String ((const char*) getMetaEventData(),
  22515. getMetaEventLength());
  22516. }
  22517. bool MidiMessage::isTrackNameEvent() const throw()
  22518. {
  22519. return (data[1] == 3)
  22520. && (*data == 0xff);
  22521. }
  22522. bool MidiMessage::isTempoMetaEvent() const throw()
  22523. {
  22524. return (data[1] == 81)
  22525. && (*data == 0xff);
  22526. }
  22527. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22528. {
  22529. return (data[1] == 0x20)
  22530. && (*data == 0xff)
  22531. && (data[2] == 1);
  22532. }
  22533. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22534. {
  22535. return data[3] + 1;
  22536. }
  22537. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22538. {
  22539. if (! isTempoMetaEvent())
  22540. return 0.0;
  22541. const uint8* const d = getMetaEventData();
  22542. return (((unsigned int) d[0] << 16)
  22543. | ((unsigned int) d[1] << 8)
  22544. | d[2])
  22545. / 1000000.0;
  22546. }
  22547. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22548. {
  22549. if (timeFormat > 0)
  22550. {
  22551. if (! isTempoMetaEvent())
  22552. return 0.5 / timeFormat;
  22553. return getTempoSecondsPerQuarterNote() / timeFormat;
  22554. }
  22555. else
  22556. {
  22557. const int frameCode = (-timeFormat) >> 8;
  22558. double framesPerSecond;
  22559. switch (frameCode)
  22560. {
  22561. case 24: framesPerSecond = 24.0; break;
  22562. case 25: framesPerSecond = 25.0; break;
  22563. case 29: framesPerSecond = 29.97; break;
  22564. case 30: framesPerSecond = 30.0; break;
  22565. default: framesPerSecond = 30.0; break;
  22566. }
  22567. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22568. }
  22569. }
  22570. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22571. {
  22572. uint8 d[8];
  22573. d[0] = 0xff;
  22574. d[1] = 81;
  22575. d[2] = 3;
  22576. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22577. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22578. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22579. return MidiMessage (d, 6, 0.0);
  22580. }
  22581. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22582. {
  22583. return (data[1] == 0x58)
  22584. && (*data == (uint8) 0xff);
  22585. }
  22586. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22587. int& denominator) const throw()
  22588. {
  22589. if (isTimeSignatureMetaEvent())
  22590. {
  22591. const uint8* const d = getMetaEventData();
  22592. numerator = d[0];
  22593. denominator = 1 << d[1];
  22594. }
  22595. else
  22596. {
  22597. numerator = 4;
  22598. denominator = 4;
  22599. }
  22600. }
  22601. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22602. const int denominator) throw()
  22603. {
  22604. uint8 d[8];
  22605. d[0] = 0xff;
  22606. d[1] = 0x58;
  22607. d[2] = 0x04;
  22608. d[3] = (uint8) numerator;
  22609. int n = 1;
  22610. int powerOfTwo = 0;
  22611. while (n < denominator)
  22612. {
  22613. n <<= 1;
  22614. ++powerOfTwo;
  22615. }
  22616. d[4] = (uint8) powerOfTwo;
  22617. d[5] = 0x01;
  22618. d[6] = 96;
  22619. return MidiMessage (d, 7, 0.0);
  22620. }
  22621. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22622. {
  22623. uint8 d[8];
  22624. d[0] = 0xff;
  22625. d[1] = 0x20;
  22626. d[2] = 0x01;
  22627. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22628. return MidiMessage (d, 4, 0.0);
  22629. }
  22630. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22631. {
  22632. return getMetaEventType() == 89;
  22633. }
  22634. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22635. {
  22636. return (int) *getMetaEventData();
  22637. }
  22638. const MidiMessage MidiMessage::endOfTrack() throw()
  22639. {
  22640. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22641. }
  22642. bool MidiMessage::isSongPositionPointer() const throw()
  22643. {
  22644. return *data == 0xf2;
  22645. }
  22646. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22647. {
  22648. return data[1] | (data[2] << 7);
  22649. }
  22650. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22651. {
  22652. return MidiMessage (0xf2,
  22653. positionInMidiBeats & 127,
  22654. (positionInMidiBeats >> 7) & 127);
  22655. }
  22656. bool MidiMessage::isMidiStart() const throw()
  22657. {
  22658. return *data == 0xfa;
  22659. }
  22660. const MidiMessage MidiMessage::midiStart() throw()
  22661. {
  22662. return MidiMessage (0xfa);
  22663. }
  22664. bool MidiMessage::isMidiContinue() const throw()
  22665. {
  22666. return *data == 0xfb;
  22667. }
  22668. const MidiMessage MidiMessage::midiContinue() throw()
  22669. {
  22670. return MidiMessage (0xfb);
  22671. }
  22672. bool MidiMessage::isMidiStop() const throw()
  22673. {
  22674. return *data == 0xfc;
  22675. }
  22676. const MidiMessage MidiMessage::midiStop() throw()
  22677. {
  22678. return MidiMessage (0xfc);
  22679. }
  22680. bool MidiMessage::isMidiClock() const throw()
  22681. {
  22682. return *data == 0xf8;
  22683. }
  22684. const MidiMessage MidiMessage::midiClock() throw()
  22685. {
  22686. return MidiMessage (0xf8);
  22687. }
  22688. bool MidiMessage::isQuarterFrame() const throw()
  22689. {
  22690. return *data == 0xf1;
  22691. }
  22692. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22693. {
  22694. return ((int) data[1]) >> 4;
  22695. }
  22696. int MidiMessage::getQuarterFrameValue() const throw()
  22697. {
  22698. return ((int) data[1]) & 0x0f;
  22699. }
  22700. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22701. const int value) throw()
  22702. {
  22703. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22704. }
  22705. bool MidiMessage::isFullFrame() const throw()
  22706. {
  22707. return data[0] == 0xf0
  22708. && data[1] == 0x7f
  22709. && size >= 10
  22710. && data[3] == 0x01
  22711. && data[4] == 0x01;
  22712. }
  22713. void MidiMessage::getFullFrameParameters (int& hours,
  22714. int& minutes,
  22715. int& seconds,
  22716. int& frames,
  22717. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22718. {
  22719. jassert (isFullFrame());
  22720. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22721. hours = data[5] & 0x1f;
  22722. minutes = data[6];
  22723. seconds = data[7];
  22724. frames = data[8];
  22725. }
  22726. const MidiMessage MidiMessage::fullFrame (const int hours,
  22727. const int minutes,
  22728. const int seconds,
  22729. const int frames,
  22730. MidiMessage::SmpteTimecodeType timecodeType)
  22731. {
  22732. uint8 d[10];
  22733. d[0] = 0xf0;
  22734. d[1] = 0x7f;
  22735. d[2] = 0x7f;
  22736. d[3] = 0x01;
  22737. d[4] = 0x01;
  22738. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22739. d[6] = (uint8) minutes;
  22740. d[7] = (uint8) seconds;
  22741. d[8] = (uint8) frames;
  22742. d[9] = 0xf7;
  22743. return MidiMessage (d, 10, 0.0);
  22744. }
  22745. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22746. {
  22747. return data[0] == 0xf0
  22748. && data[1] == 0x7f
  22749. && data[3] == 0x06
  22750. && size > 5;
  22751. }
  22752. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22753. {
  22754. jassert (isMidiMachineControlMessage());
  22755. return (MidiMachineControlCommand) data[4];
  22756. }
  22757. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22758. {
  22759. uint8 d[6];
  22760. d[0] = 0xf0;
  22761. d[1] = 0x7f;
  22762. d[2] = 0x00;
  22763. d[3] = 0x06;
  22764. d[4] = (uint8) command;
  22765. d[5] = 0xf7;
  22766. return MidiMessage (d, 6, 0.0);
  22767. }
  22768. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22769. int& minutes,
  22770. int& seconds,
  22771. int& frames) const throw()
  22772. {
  22773. if (size >= 12
  22774. && data[0] == 0xf0
  22775. && data[1] == 0x7f
  22776. && data[3] == 0x06
  22777. && data[4] == 0x44
  22778. && data[5] == 0x06
  22779. && data[6] == 0x01)
  22780. {
  22781. hours = data[7] % 24; // (that some machines send out hours > 24)
  22782. minutes = data[8];
  22783. seconds = data[9];
  22784. frames = data[10];
  22785. return true;
  22786. }
  22787. return false;
  22788. }
  22789. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22790. int minutes,
  22791. int seconds,
  22792. int frames)
  22793. {
  22794. uint8 d[12];
  22795. d[0] = 0xf0;
  22796. d[1] = 0x7f;
  22797. d[2] = 0x00;
  22798. d[3] = 0x06;
  22799. d[4] = 0x44;
  22800. d[5] = 0x06;
  22801. d[6] = 0x01;
  22802. d[7] = (uint8) hours;
  22803. d[8] = (uint8) minutes;
  22804. d[9] = (uint8) seconds;
  22805. d[10] = (uint8) frames;
  22806. d[11] = 0xf7;
  22807. return MidiMessage (d, 12, 0.0);
  22808. }
  22809. const String MidiMessage::getMidiNoteName (int note,
  22810. bool useSharps,
  22811. bool includeOctaveNumber,
  22812. int octaveNumForMiddleC) throw()
  22813. {
  22814. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22815. "F", "F#", "G", "G#", "A",
  22816. "A#", "B" };
  22817. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22818. "F", "Gb", "G", "Ab", "A",
  22819. "Bb", "B" };
  22820. if (((unsigned int) note) < 128)
  22821. {
  22822. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22823. : flatNoteNames [note % 12]);
  22824. if (includeOctaveNumber)
  22825. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22826. else
  22827. return s;
  22828. }
  22829. return String::empty;
  22830. }
  22831. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22832. {
  22833. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22834. return 440.0 * pow (2.0, noteNumber / 12.0);
  22835. }
  22836. const String MidiMessage::getGMInstrumentName (int n) throw()
  22837. {
  22838. const char *names[] =
  22839. {
  22840. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22841. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22842. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22843. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22844. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22845. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22846. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22847. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22848. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22849. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22850. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22851. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22852. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22853. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22854. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22855. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22856. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22857. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22858. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22859. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22860. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22861. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22862. "Applause", "Gunshot"
  22863. };
  22864. return (((unsigned int) n) < 128) ? names[n]
  22865. : (const char*)0;
  22866. }
  22867. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22868. {
  22869. const char* names[] =
  22870. {
  22871. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22872. "Bass", "Strings", "Ensemble", "Brass",
  22873. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22874. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22875. };
  22876. return (((unsigned int) n) <= 15) ? names[n]
  22877. : (const char*)0;
  22878. }
  22879. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22880. {
  22881. const char* names[] =
  22882. {
  22883. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22884. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22885. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22886. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22887. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22888. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22889. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22890. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22891. "Mute Triangle", "Open Triangle"
  22892. };
  22893. return (n >= 35 && n <= 81) ? names [n - 35]
  22894. : (const char*)0;
  22895. }
  22896. const String MidiMessage::getControllerName (int n) throw()
  22897. {
  22898. const char* names[] =
  22899. {
  22900. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22901. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22902. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22903. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22904. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22905. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22906. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22907. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22908. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22909. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22910. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22911. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22912. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22913. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22914. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22915. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22916. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22917. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22918. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22920. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22921. "Poly Operation"
  22922. };
  22923. return (((unsigned int) n) < 128) ? names[n]
  22924. : (const char*)0;
  22925. }
  22926. END_JUCE_NAMESPACE
  22927. /*** End of inlined file: juce_MidiMessage.cpp ***/
  22928. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  22929. BEGIN_JUCE_NAMESPACE
  22930. MidiMessageCollector::MidiMessageCollector()
  22931. : lastCallbackTime (0),
  22932. sampleRate (44100.0001)
  22933. {
  22934. }
  22935. MidiMessageCollector::~MidiMessageCollector()
  22936. {
  22937. }
  22938. void MidiMessageCollector::reset (const double sampleRate_)
  22939. {
  22940. jassert (sampleRate_ > 0);
  22941. const ScopedLock sl (midiCallbackLock);
  22942. sampleRate = sampleRate_;
  22943. incomingMessages.clear();
  22944. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22945. }
  22946. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22947. {
  22948. // you need to call reset() to set the correct sample rate before using this object
  22949. jassert (sampleRate != 44100.0001);
  22950. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22951. // for details of what the number should be.
  22952. jassert (message.getTimeStamp() != 0);
  22953. const ScopedLock sl (midiCallbackLock);
  22954. const int sampleNumber
  22955. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22956. incomingMessages.addEvent (message, sampleNumber);
  22957. // if the messages don't get used for over a second, we'd better
  22958. // get rid of any old ones to avoid the queue getting too big
  22959. if (sampleNumber > sampleRate)
  22960. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22961. }
  22962. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22963. const int numSamples)
  22964. {
  22965. // you need to call reset() to set the correct sample rate before using this object
  22966. jassert (sampleRate != 44100.0001);
  22967. const double timeNow = Time::getMillisecondCounterHiRes();
  22968. const double msElapsed = timeNow - lastCallbackTime;
  22969. const ScopedLock sl (midiCallbackLock);
  22970. lastCallbackTime = timeNow;
  22971. if (! incomingMessages.isEmpty())
  22972. {
  22973. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  22974. int startSample = 0;
  22975. int scale = 1 << 16;
  22976. const uint8* midiData;
  22977. int numBytes, samplePosition;
  22978. MidiBuffer::Iterator iter (incomingMessages);
  22979. if (numSourceSamples > numSamples)
  22980. {
  22981. // if our list of events is longer than the buffer we're being
  22982. // asked for, scale them down to squeeze them all in..
  22983. const int maxBlockLengthToUse = numSamples << 5;
  22984. if (numSourceSamples > maxBlockLengthToUse)
  22985. {
  22986. startSample = numSourceSamples - maxBlockLengthToUse;
  22987. numSourceSamples = maxBlockLengthToUse;
  22988. iter.setNextSamplePosition (startSample);
  22989. }
  22990. scale = (numSamples << 10) / numSourceSamples;
  22991. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22992. {
  22993. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  22994. destBuffer.addEvent (midiData, numBytes,
  22995. jlimit (0, numSamples - 1, samplePosition));
  22996. }
  22997. }
  22998. else
  22999. {
  23000. // if our event list is shorter than the number we need, put them
  23001. // towards the end of the buffer
  23002. startSample = numSamples - numSourceSamples;
  23003. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23004. {
  23005. destBuffer.addEvent (midiData, numBytes,
  23006. jlimit (0, numSamples - 1, samplePosition + startSample));
  23007. }
  23008. }
  23009. incomingMessages.clear();
  23010. }
  23011. }
  23012. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  23013. {
  23014. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  23015. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23016. addMessageToQueue (m);
  23017. }
  23018. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  23019. {
  23020. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  23021. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23022. addMessageToQueue (m);
  23023. }
  23024. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  23025. {
  23026. addMessageToQueue (message);
  23027. }
  23028. END_JUCE_NAMESPACE
  23029. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  23030. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  23031. BEGIN_JUCE_NAMESPACE
  23032. MidiMessageSequence::MidiMessageSequence()
  23033. {
  23034. }
  23035. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  23036. {
  23037. list.ensureStorageAllocated (other.list.size());
  23038. for (int i = 0; i < other.list.size(); ++i)
  23039. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  23040. }
  23041. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  23042. {
  23043. MidiMessageSequence otherCopy (other);
  23044. swapWith (otherCopy);
  23045. return *this;
  23046. }
  23047. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  23048. {
  23049. list.swapWithArray (other.list);
  23050. }
  23051. MidiMessageSequence::~MidiMessageSequence()
  23052. {
  23053. }
  23054. void MidiMessageSequence::clear()
  23055. {
  23056. list.clear();
  23057. }
  23058. int MidiMessageSequence::getNumEvents() const
  23059. {
  23060. return list.size();
  23061. }
  23062. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  23063. {
  23064. return list [index];
  23065. }
  23066. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  23067. {
  23068. const MidiEventHolder* const meh = list [index];
  23069. if (meh != 0 && meh->noteOffObject != 0)
  23070. return meh->noteOffObject->message.getTimeStamp();
  23071. else
  23072. return 0.0;
  23073. }
  23074. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  23075. {
  23076. const MidiEventHolder* const meh = list [index];
  23077. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  23078. }
  23079. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  23080. {
  23081. return list.indexOf (event);
  23082. }
  23083. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  23084. {
  23085. const int numEvents = list.size();
  23086. int i;
  23087. for (i = 0; i < numEvents; ++i)
  23088. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23089. break;
  23090. return i;
  23091. }
  23092. double MidiMessageSequence::getStartTime() const
  23093. {
  23094. if (list.size() > 0)
  23095. return list.getUnchecked(0)->message.getTimeStamp();
  23096. else
  23097. return 0;
  23098. }
  23099. double MidiMessageSequence::getEndTime() const
  23100. {
  23101. if (list.size() > 0)
  23102. return list.getLast()->message.getTimeStamp();
  23103. else
  23104. return 0;
  23105. }
  23106. double MidiMessageSequence::getEventTime (const int index) const
  23107. {
  23108. if (((unsigned int) index) < (unsigned int) list.size())
  23109. return list.getUnchecked (index)->message.getTimeStamp();
  23110. return 0.0;
  23111. }
  23112. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23113. double timeAdjustment)
  23114. {
  23115. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23116. timeAdjustment += newMessage.getTimeStamp();
  23117. newOne->message.setTimeStamp (timeAdjustment);
  23118. int i;
  23119. for (i = list.size(); --i >= 0;)
  23120. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23121. break;
  23122. list.insert (i + 1, newOne);
  23123. }
  23124. void MidiMessageSequence::deleteEvent (const int index,
  23125. const bool deleteMatchingNoteUp)
  23126. {
  23127. if (((unsigned int) index) < (unsigned int) list.size())
  23128. {
  23129. if (deleteMatchingNoteUp)
  23130. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23131. list.remove (index);
  23132. }
  23133. }
  23134. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23135. double timeAdjustment,
  23136. double firstAllowableTime,
  23137. double endOfAllowableDestTimes)
  23138. {
  23139. firstAllowableTime -= timeAdjustment;
  23140. endOfAllowableDestTimes -= timeAdjustment;
  23141. for (int i = 0; i < other.list.size(); ++i)
  23142. {
  23143. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23144. const double t = m.getTimeStamp();
  23145. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23146. {
  23147. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23148. newOne->message.setTimeStamp (timeAdjustment + t);
  23149. list.add (newOne);
  23150. }
  23151. }
  23152. sort();
  23153. }
  23154. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23155. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23156. {
  23157. const double diff = first->message.getTimeStamp()
  23158. - second->message.getTimeStamp();
  23159. return (diff > 0) - (diff < 0);
  23160. }
  23161. void MidiMessageSequence::sort()
  23162. {
  23163. list.sort (*this, true);
  23164. }
  23165. void MidiMessageSequence::updateMatchedPairs()
  23166. {
  23167. for (int i = 0; i < list.size(); ++i)
  23168. {
  23169. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23170. if (m1.isNoteOn())
  23171. {
  23172. list.getUnchecked(i)->noteOffObject = 0;
  23173. const int note = m1.getNoteNumber();
  23174. const int chan = m1.getChannel();
  23175. const int len = list.size();
  23176. for (int j = i + 1; j < len; ++j)
  23177. {
  23178. const MidiMessage& m = list.getUnchecked(j)->message;
  23179. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23180. {
  23181. if (m.isNoteOff())
  23182. {
  23183. list.getUnchecked(i)->noteOffObject = list[j];
  23184. break;
  23185. }
  23186. else if (m.isNoteOn())
  23187. {
  23188. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23189. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23190. list.getUnchecked(i)->noteOffObject = list[j];
  23191. break;
  23192. }
  23193. }
  23194. }
  23195. }
  23196. }
  23197. }
  23198. void MidiMessageSequence::addTimeToMessages (const double delta)
  23199. {
  23200. for (int i = list.size(); --i >= 0;)
  23201. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23202. + delta);
  23203. }
  23204. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23205. MidiMessageSequence& destSequence,
  23206. const bool alsoIncludeMetaEvents) const
  23207. {
  23208. for (int i = 0; i < list.size(); ++i)
  23209. {
  23210. const MidiMessage& mm = list.getUnchecked(i)->message;
  23211. if (mm.isForChannel (channelNumberToExtract)
  23212. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23213. {
  23214. destSequence.addEvent (mm);
  23215. }
  23216. }
  23217. }
  23218. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23219. {
  23220. for (int i = 0; i < list.size(); ++i)
  23221. {
  23222. const MidiMessage& mm = list.getUnchecked(i)->message;
  23223. if (mm.isSysEx())
  23224. destSequence.addEvent (mm);
  23225. }
  23226. }
  23227. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23228. {
  23229. for (int i = list.size(); --i >= 0;)
  23230. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23231. list.remove(i);
  23232. }
  23233. void MidiMessageSequence::deleteSysExMessages()
  23234. {
  23235. for (int i = list.size(); --i >= 0;)
  23236. if (list.getUnchecked(i)->message.isSysEx())
  23237. list.remove(i);
  23238. }
  23239. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23240. const double time,
  23241. OwnedArray<MidiMessage>& dest)
  23242. {
  23243. bool doneProg = false;
  23244. bool donePitchWheel = false;
  23245. Array <int> doneControllers;
  23246. doneControllers.ensureStorageAllocated (32);
  23247. for (int i = list.size(); --i >= 0;)
  23248. {
  23249. const MidiMessage& mm = list.getUnchecked(i)->message;
  23250. if (mm.isForChannel (channelNumber)
  23251. && mm.getTimeStamp() <= time)
  23252. {
  23253. if (mm.isProgramChange())
  23254. {
  23255. if (! doneProg)
  23256. {
  23257. dest.add (new MidiMessage (mm, 0.0));
  23258. doneProg = true;
  23259. }
  23260. }
  23261. else if (mm.isController())
  23262. {
  23263. if (! doneControllers.contains (mm.getControllerNumber()))
  23264. {
  23265. dest.add (new MidiMessage (mm, 0.0));
  23266. doneControllers.add (mm.getControllerNumber());
  23267. }
  23268. }
  23269. else if (mm.isPitchWheel())
  23270. {
  23271. if (! donePitchWheel)
  23272. {
  23273. dest.add (new MidiMessage (mm, 0.0));
  23274. donePitchWheel = true;
  23275. }
  23276. }
  23277. }
  23278. }
  23279. }
  23280. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23281. : message (message_),
  23282. noteOffObject (0)
  23283. {
  23284. }
  23285. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23286. {
  23287. }
  23288. END_JUCE_NAMESPACE
  23289. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23290. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23291. BEGIN_JUCE_NAMESPACE
  23292. AudioPluginFormat::AudioPluginFormat() throw()
  23293. {
  23294. }
  23295. AudioPluginFormat::~AudioPluginFormat()
  23296. {
  23297. }
  23298. END_JUCE_NAMESPACE
  23299. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23300. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23301. BEGIN_JUCE_NAMESPACE
  23302. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23303. {
  23304. }
  23305. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23306. {
  23307. clearSingletonInstance();
  23308. }
  23309. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23310. void AudioPluginFormatManager::addDefaultFormats()
  23311. {
  23312. #ifdef JUCE_DEBUG
  23313. // you should only call this method once!
  23314. for (int i = formats.size(); --i >= 0;)
  23315. {
  23316. #if JUCE_PLUGINHOST_VST
  23317. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23318. #endif
  23319. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23320. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23321. #endif
  23322. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23323. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23324. #endif
  23325. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23326. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23327. #endif
  23328. }
  23329. #endif
  23330. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23331. formats.add (new AudioUnitPluginFormat());
  23332. #endif
  23333. #if JUCE_PLUGINHOST_VST
  23334. formats.add (new VSTPluginFormat());
  23335. #endif
  23336. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23337. formats.add (new DirectXPluginFormat());
  23338. #endif
  23339. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23340. formats.add (new LADSPAPluginFormat());
  23341. #endif
  23342. }
  23343. int AudioPluginFormatManager::getNumFormats() throw()
  23344. {
  23345. return formats.size();
  23346. }
  23347. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23348. {
  23349. return formats [index];
  23350. }
  23351. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23352. {
  23353. formats.add (format);
  23354. }
  23355. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23356. String& errorMessage) const
  23357. {
  23358. AudioPluginInstance* result = 0;
  23359. for (int i = 0; i < formats.size(); ++i)
  23360. {
  23361. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23362. if (result != 0)
  23363. break;
  23364. }
  23365. if (result == 0)
  23366. {
  23367. if (! doesPluginStillExist (description))
  23368. errorMessage = TRANS ("This plug-in file no longer exists");
  23369. else
  23370. errorMessage = TRANS ("This plug-in failed to load correctly");
  23371. }
  23372. return result;
  23373. }
  23374. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23375. {
  23376. for (int i = 0; i < formats.size(); ++i)
  23377. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23378. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23379. return false;
  23380. }
  23381. END_JUCE_NAMESPACE
  23382. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23383. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23384. #define JUCE_PLUGIN_HOST 1
  23385. BEGIN_JUCE_NAMESPACE
  23386. AudioPluginInstance::AudioPluginInstance()
  23387. {
  23388. }
  23389. AudioPluginInstance::~AudioPluginInstance()
  23390. {
  23391. }
  23392. END_JUCE_NAMESPACE
  23393. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23394. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23395. BEGIN_JUCE_NAMESPACE
  23396. KnownPluginList::KnownPluginList()
  23397. {
  23398. }
  23399. KnownPluginList::~KnownPluginList()
  23400. {
  23401. }
  23402. void KnownPluginList::clear()
  23403. {
  23404. if (types.size() > 0)
  23405. {
  23406. types.clear();
  23407. sendChangeMessage (this);
  23408. }
  23409. }
  23410. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23411. {
  23412. for (int i = 0; i < types.size(); ++i)
  23413. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23414. return types.getUnchecked(i);
  23415. return 0;
  23416. }
  23417. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23418. {
  23419. for (int i = 0; i < types.size(); ++i)
  23420. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23421. return types.getUnchecked(i);
  23422. return 0;
  23423. }
  23424. bool KnownPluginList::addType (const PluginDescription& type)
  23425. {
  23426. for (int i = types.size(); --i >= 0;)
  23427. {
  23428. if (types.getUnchecked(i)->isDuplicateOf (type))
  23429. {
  23430. // strange - found a duplicate plugin with different info..
  23431. jassert (types.getUnchecked(i)->name == type.name);
  23432. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23433. *types.getUnchecked(i) = type;
  23434. return false;
  23435. }
  23436. }
  23437. types.add (new PluginDescription (type));
  23438. sendChangeMessage (this);
  23439. return true;
  23440. }
  23441. void KnownPluginList::removeType (const int index) throw()
  23442. {
  23443. types.remove (index);
  23444. sendChangeMessage (this);
  23445. }
  23446. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23447. {
  23448. if (fileOrIdentifier.startsWithChar (T('/'))
  23449. || fileOrIdentifier[1] == T(':'))
  23450. {
  23451. return File (fileOrIdentifier).getLastModificationTime();
  23452. }
  23453. return Time (0);
  23454. }
  23455. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23456. {
  23457. return t1 != t2 || t1 == Time (0);
  23458. }
  23459. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23460. {
  23461. if (getTypeForFile (fileOrIdentifier) == 0)
  23462. return false;
  23463. for (int i = types.size(); --i >= 0;)
  23464. {
  23465. const PluginDescription* const d = types.getUnchecked(i);
  23466. if (d->fileOrIdentifier == fileOrIdentifier
  23467. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23468. {
  23469. return false;
  23470. }
  23471. }
  23472. return true;
  23473. }
  23474. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23475. const bool dontRescanIfAlreadyInList,
  23476. OwnedArray <PluginDescription>& typesFound,
  23477. AudioPluginFormat& format)
  23478. {
  23479. bool addedOne = false;
  23480. if (dontRescanIfAlreadyInList
  23481. && getTypeForFile (fileOrIdentifier) != 0)
  23482. {
  23483. bool needsRescanning = false;
  23484. for (int i = types.size(); --i >= 0;)
  23485. {
  23486. const PluginDescription* const d = types.getUnchecked(i);
  23487. if (d->fileOrIdentifier == fileOrIdentifier)
  23488. {
  23489. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23490. needsRescanning = true;
  23491. else
  23492. typesFound.add (new PluginDescription (*d));
  23493. }
  23494. }
  23495. if (! needsRescanning)
  23496. return false;
  23497. }
  23498. OwnedArray <PluginDescription> found;
  23499. format.findAllTypesForFile (found, fileOrIdentifier);
  23500. for (int i = 0; i < found.size(); ++i)
  23501. {
  23502. PluginDescription* const desc = found.getUnchecked(i);
  23503. jassert (desc != 0);
  23504. if (addType (*desc))
  23505. addedOne = true;
  23506. typesFound.add (new PluginDescription (*desc));
  23507. }
  23508. return addedOne;
  23509. }
  23510. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23511. OwnedArray <PluginDescription>& typesFound)
  23512. {
  23513. for (int i = 0; i < files.size(); ++i)
  23514. {
  23515. bool loaded = false;
  23516. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23517. {
  23518. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23519. if (scanAndAddFile (files[i], true, typesFound, *format))
  23520. loaded = true;
  23521. }
  23522. if (! loaded)
  23523. {
  23524. const File f (files[i]);
  23525. if (f.isDirectory())
  23526. {
  23527. StringArray s;
  23528. {
  23529. Array<File> subFiles;
  23530. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23531. for (int j = 0; j < subFiles.size(); ++j)
  23532. s.add (subFiles.getReference(j).getFullPathName());
  23533. }
  23534. scanAndAddDragAndDroppedFiles (s, typesFound);
  23535. }
  23536. }
  23537. }
  23538. }
  23539. class PluginSorter
  23540. {
  23541. public:
  23542. KnownPluginList::SortMethod method;
  23543. PluginSorter() throw() {}
  23544. int compareElements (const PluginDescription* const first,
  23545. const PluginDescription* const second) const throw()
  23546. {
  23547. int diff = 0;
  23548. if (method == KnownPluginList::sortByCategory)
  23549. diff = first->category.compareLexicographically (second->category);
  23550. else if (method == KnownPluginList::sortByManufacturer)
  23551. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23552. else if (method == KnownPluginList::sortByFileSystemLocation)
  23553. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23554. .upToLastOccurrenceOf (T("/"), false, false)
  23555. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23556. .upToLastOccurrenceOf (T("/"), false, false));
  23557. if (diff == 0)
  23558. diff = first->name.compareLexicographically (second->name);
  23559. return diff;
  23560. }
  23561. };
  23562. void KnownPluginList::sort (const SortMethod method)
  23563. {
  23564. if (method != defaultOrder)
  23565. {
  23566. PluginSorter sorter;
  23567. sorter.method = method;
  23568. types.sort (sorter, true);
  23569. sendChangeMessage (this);
  23570. }
  23571. }
  23572. XmlElement* KnownPluginList::createXml() const
  23573. {
  23574. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23575. for (int i = 0; i < types.size(); ++i)
  23576. e->addChildElement (types.getUnchecked(i)->createXml());
  23577. return e;
  23578. }
  23579. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23580. {
  23581. clear();
  23582. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23583. {
  23584. forEachXmlChildElement (xml, e)
  23585. {
  23586. PluginDescription info;
  23587. if (info.loadFromXml (*e))
  23588. addType (info);
  23589. }
  23590. }
  23591. }
  23592. const int menuIdBase = 0x324503f4;
  23593. // This is used to turn a bunch of paths into a nested menu structure.
  23594. struct PluginFilesystemTree
  23595. {
  23596. private:
  23597. String folder;
  23598. OwnedArray <PluginFilesystemTree> subFolders;
  23599. Array <PluginDescription*> plugins;
  23600. void addPlugin (PluginDescription* const pd, const String& path)
  23601. {
  23602. if (path.isEmpty())
  23603. {
  23604. plugins.add (pd);
  23605. }
  23606. else
  23607. {
  23608. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23609. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23610. for (int i = subFolders.size(); --i >= 0;)
  23611. {
  23612. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23613. {
  23614. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23615. return;
  23616. }
  23617. }
  23618. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23619. newFolder->folder = firstSubFolder;
  23620. subFolders.add (newFolder);
  23621. newFolder->addPlugin (pd, remainingPath);
  23622. }
  23623. }
  23624. // removes any deeply nested folders that don't contain any actual plugins
  23625. void optimise()
  23626. {
  23627. for (int i = subFolders.size(); --i >= 0;)
  23628. {
  23629. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23630. sub->optimise();
  23631. if (sub->plugins.size() == 0)
  23632. {
  23633. for (int j = 0; j < sub->subFolders.size(); ++j)
  23634. subFolders.add (sub->subFolders.getUnchecked(j));
  23635. sub->subFolders.clear (false);
  23636. subFolders.remove (i);
  23637. }
  23638. }
  23639. }
  23640. public:
  23641. void buildTree (const Array <PluginDescription*>& allPlugins)
  23642. {
  23643. for (int i = 0; i < allPlugins.size(); ++i)
  23644. {
  23645. String path (allPlugins.getUnchecked(i)
  23646. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23647. .upToLastOccurrenceOf (T("/"), false, false));
  23648. if (path.substring (1, 2) == T(":"))
  23649. path = path.substring (2);
  23650. addPlugin (allPlugins.getUnchecked(i), path);
  23651. }
  23652. optimise();
  23653. }
  23654. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23655. {
  23656. int i;
  23657. for (i = 0; i < subFolders.size(); ++i)
  23658. {
  23659. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23660. PopupMenu subMenu;
  23661. sub->addToMenu (subMenu, allPlugins);
  23662. #if JUCE_MAC
  23663. // avoid the special AU formatting nonsense on Mac..
  23664. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23665. #else
  23666. m.addSubMenu (sub->folder, subMenu);
  23667. #endif
  23668. }
  23669. for (i = 0; i < plugins.size(); ++i)
  23670. {
  23671. PluginDescription* const plugin = plugins.getUnchecked(i);
  23672. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23673. plugin->name, true, false);
  23674. }
  23675. }
  23676. };
  23677. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23678. {
  23679. Array <PluginDescription*> sorted;
  23680. {
  23681. PluginSorter sorter;
  23682. sorter.method = sortMethod;
  23683. for (int i = 0; i < types.size(); ++i)
  23684. sorted.addSorted (sorter, types.getUnchecked(i));
  23685. }
  23686. if (sortMethod == sortByCategory
  23687. || sortMethod == sortByManufacturer)
  23688. {
  23689. String lastSubMenuName;
  23690. PopupMenu sub;
  23691. for (int i = 0; i < sorted.size(); ++i)
  23692. {
  23693. const PluginDescription* const pd = sorted.getUnchecked(i);
  23694. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23695. : pd->manufacturerName);
  23696. if (! thisSubMenuName.containsNonWhitespaceChars())
  23697. thisSubMenuName = T("Other");
  23698. if (thisSubMenuName != lastSubMenuName)
  23699. {
  23700. if (sub.getNumItems() > 0)
  23701. {
  23702. menu.addSubMenu (lastSubMenuName, sub);
  23703. sub.clear();
  23704. }
  23705. lastSubMenuName = thisSubMenuName;
  23706. }
  23707. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23708. }
  23709. if (sub.getNumItems() > 0)
  23710. menu.addSubMenu (lastSubMenuName, sub);
  23711. }
  23712. else if (sortMethod == sortByFileSystemLocation)
  23713. {
  23714. PluginFilesystemTree root;
  23715. root.buildTree (sorted);
  23716. root.addToMenu (menu, types);
  23717. }
  23718. else
  23719. {
  23720. for (int i = 0; i < sorted.size(); ++i)
  23721. {
  23722. const PluginDescription* const pd = sorted.getUnchecked(i);
  23723. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23724. }
  23725. }
  23726. }
  23727. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23728. {
  23729. const int i = menuResultCode - menuIdBase;
  23730. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23731. }
  23732. END_JUCE_NAMESPACE
  23733. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23734. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23735. BEGIN_JUCE_NAMESPACE
  23736. PluginDescription::PluginDescription() throw()
  23737. : uid (0),
  23738. isInstrument (false),
  23739. numInputChannels (0),
  23740. numOutputChannels (0)
  23741. {
  23742. }
  23743. PluginDescription::~PluginDescription() throw()
  23744. {
  23745. }
  23746. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23747. : name (other.name),
  23748. pluginFormatName (other.pluginFormatName),
  23749. category (other.category),
  23750. manufacturerName (other.manufacturerName),
  23751. version (other.version),
  23752. fileOrIdentifier (other.fileOrIdentifier),
  23753. lastFileModTime (other.lastFileModTime),
  23754. uid (other.uid),
  23755. isInstrument (other.isInstrument),
  23756. numInputChannels (other.numInputChannels),
  23757. numOutputChannels (other.numOutputChannels)
  23758. {
  23759. }
  23760. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23761. {
  23762. name = other.name;
  23763. pluginFormatName = other.pluginFormatName;
  23764. category = other.category;
  23765. manufacturerName = other.manufacturerName;
  23766. version = other.version;
  23767. fileOrIdentifier = other.fileOrIdentifier;
  23768. uid = other.uid;
  23769. isInstrument = other.isInstrument;
  23770. lastFileModTime = other.lastFileModTime;
  23771. numInputChannels = other.numInputChannels;
  23772. numOutputChannels = other.numOutputChannels;
  23773. return *this;
  23774. }
  23775. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23776. {
  23777. return fileOrIdentifier == other.fileOrIdentifier
  23778. && uid == other.uid;
  23779. }
  23780. const String PluginDescription::createIdentifierString() const throw()
  23781. {
  23782. return pluginFormatName
  23783. + T("-") + name
  23784. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23785. + T("-") + String::toHexString (uid);
  23786. }
  23787. XmlElement* PluginDescription::createXml() const
  23788. {
  23789. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23790. e->setAttribute (T("name"), name);
  23791. e->setAttribute (T("format"), pluginFormatName);
  23792. e->setAttribute (T("category"), category);
  23793. e->setAttribute (T("manufacturer"), manufacturerName);
  23794. e->setAttribute (T("version"), version);
  23795. e->setAttribute (T("file"), fileOrIdentifier);
  23796. e->setAttribute (T("uid"), String::toHexString (uid));
  23797. e->setAttribute (T("isInstrument"), isInstrument);
  23798. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23799. e->setAttribute (T("numInputs"), numInputChannels);
  23800. e->setAttribute (T("numOutputs"), numOutputChannels);
  23801. return e;
  23802. }
  23803. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23804. {
  23805. if (xml.hasTagName (T("PLUGIN")))
  23806. {
  23807. name = xml.getStringAttribute (T("name"));
  23808. pluginFormatName = xml.getStringAttribute (T("format"));
  23809. category = xml.getStringAttribute (T("category"));
  23810. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23811. version = xml.getStringAttribute (T("version"));
  23812. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23813. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23814. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23815. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23816. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23817. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23818. return true;
  23819. }
  23820. return false;
  23821. }
  23822. END_JUCE_NAMESPACE
  23823. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23824. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23825. BEGIN_JUCE_NAMESPACE
  23826. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23827. AudioPluginFormat& formatToLookFor,
  23828. FileSearchPath directoriesToSearch,
  23829. const bool recursive,
  23830. const File& deadMansPedalFile_)
  23831. : list (listToAddTo),
  23832. format (formatToLookFor),
  23833. deadMansPedalFile (deadMansPedalFile_),
  23834. nextIndex (0),
  23835. progress (0)
  23836. {
  23837. directoriesToSearch.removeRedundantPaths();
  23838. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23839. // If any plugins have crashed recently when being loaded, move them to the
  23840. // end of the list to give the others a chance to load correctly..
  23841. const StringArray crashedPlugins (getDeadMansPedalFile());
  23842. for (int i = 0; i < crashedPlugins.size(); ++i)
  23843. {
  23844. const String f = crashedPlugins[i];
  23845. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23846. if (f == filesOrIdentifiersToScan[j])
  23847. filesOrIdentifiersToScan.move (j, -1);
  23848. }
  23849. }
  23850. PluginDirectoryScanner::~PluginDirectoryScanner()
  23851. {
  23852. }
  23853. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23854. {
  23855. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23856. }
  23857. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23858. {
  23859. String file (filesOrIdentifiersToScan [nextIndex]);
  23860. if (file.isNotEmpty())
  23861. {
  23862. if (! list.isListingUpToDate (file))
  23863. {
  23864. OwnedArray <PluginDescription> typesFound;
  23865. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23866. StringArray crashedPlugins (getDeadMansPedalFile());
  23867. crashedPlugins.removeString (file);
  23868. crashedPlugins.add (file);
  23869. setDeadMansPedalFile (crashedPlugins);
  23870. list.scanAndAddFile (file,
  23871. dontRescanIfAlreadyInList,
  23872. typesFound,
  23873. format);
  23874. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23875. crashedPlugins.removeString (file);
  23876. setDeadMansPedalFile (crashedPlugins);
  23877. if (typesFound.size() == 0)
  23878. failedFiles.add (file);
  23879. }
  23880. ++nextIndex;
  23881. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23882. }
  23883. return nextIndex < filesOrIdentifiersToScan.size();
  23884. }
  23885. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23886. {
  23887. StringArray lines;
  23888. if (deadMansPedalFile != File::nonexistent)
  23889. {
  23890. lines.addLines (deadMansPedalFile.loadFileAsString());
  23891. lines.removeEmptyStrings();
  23892. }
  23893. return lines;
  23894. }
  23895. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23896. {
  23897. if (deadMansPedalFile != File::nonexistent)
  23898. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23899. }
  23900. END_JUCE_NAMESPACE
  23901. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23902. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23903. BEGIN_JUCE_NAMESPACE
  23904. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23905. const File& deadMansPedalFile_,
  23906. PropertiesFile* const propertiesToUse_)
  23907. : list (listToEdit),
  23908. deadMansPedalFile (deadMansPedalFile_),
  23909. propertiesToUse (propertiesToUse_)
  23910. {
  23911. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23912. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23913. optionsButton->addButtonListener (this);
  23914. optionsButton->setTriggeredOnMouseDown (true);
  23915. setSize (400, 600);
  23916. list.addChangeListener (this);
  23917. }
  23918. PluginListComponent::~PluginListComponent()
  23919. {
  23920. list.removeChangeListener (this);
  23921. deleteAllChildren();
  23922. }
  23923. void PluginListComponent::resized()
  23924. {
  23925. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23926. optionsButton->changeWidthToFitText (24);
  23927. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23928. }
  23929. void PluginListComponent::changeListenerCallback (void*)
  23930. {
  23931. listBox->updateContent();
  23932. listBox->repaint();
  23933. }
  23934. int PluginListComponent::getNumRows()
  23935. {
  23936. return list.getNumTypes();
  23937. }
  23938. void PluginListComponent::paintListBoxItem (int row,
  23939. Graphics& g,
  23940. int width, int height,
  23941. bool rowIsSelected)
  23942. {
  23943. if (rowIsSelected)
  23944. g.fillAll (findColour (TextEditor::highlightColourId));
  23945. const PluginDescription* const pd = list.getType (row);
  23946. if (pd != 0)
  23947. {
  23948. GlyphArrangement ga;
  23949. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23950. g.setColour (Colours::black);
  23951. ga.draw (g);
  23952. float x, y, r, b;
  23953. ga.getBoundingBox (0, -1, x, y, r, b, false);
  23954. String desc;
  23955. desc << pd->pluginFormatName
  23956. << (pd->isInstrument ? " instrument" : " effect")
  23957. << " - "
  23958. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23959. << " / "
  23960. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23961. if (pd->manufacturerName.isNotEmpty())
  23962. desc << " - " << pd->manufacturerName;
  23963. if (pd->version.isNotEmpty())
  23964. desc << " - " << pd->version;
  23965. if (pd->category.isNotEmpty())
  23966. desc << " - category: '" << pd->category << '\'';
  23967. g.setColour (Colours::grey);
  23968. ga.clear();
  23969. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  23970. ga.draw (g);
  23971. }
  23972. }
  23973. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  23974. {
  23975. list.removeType (lastRowSelected);
  23976. }
  23977. void PluginListComponent::buttonClicked (Button* b)
  23978. {
  23979. if (optionsButton == b)
  23980. {
  23981. PopupMenu menu;
  23982. menu.addItem (1, TRANS("Clear list"));
  23983. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  23984. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  23985. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  23986. menu.addSeparator();
  23987. menu.addItem (2, TRANS("Sort alphabetically"));
  23988. menu.addItem (3, TRANS("Sort by category"));
  23989. menu.addItem (4, TRANS("Sort by manufacturer"));
  23990. menu.addSeparator();
  23991. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  23992. {
  23993. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  23994. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  23995. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  23996. }
  23997. const int r = menu.showAt (optionsButton);
  23998. if (r == 1)
  23999. {
  24000. list.clear();
  24001. }
  24002. else if (r == 2)
  24003. {
  24004. list.sort (KnownPluginList::sortAlphabetically);
  24005. }
  24006. else if (r == 3)
  24007. {
  24008. list.sort (KnownPluginList::sortByCategory);
  24009. }
  24010. else if (r == 4)
  24011. {
  24012. list.sort (KnownPluginList::sortByManufacturer);
  24013. }
  24014. else if (r == 5)
  24015. {
  24016. const SparseSet <int> selected (listBox->getSelectedRows());
  24017. for (int i = list.getNumTypes(); --i >= 0;)
  24018. if (selected.contains (i))
  24019. list.removeType (i);
  24020. }
  24021. else if (r == 6)
  24022. {
  24023. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  24024. if (desc != 0)
  24025. {
  24026. if (File (desc->fileOrIdentifier).existsAsFile())
  24027. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  24028. }
  24029. }
  24030. else if (r == 7)
  24031. {
  24032. for (int i = list.getNumTypes(); --i >= 0;)
  24033. {
  24034. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  24035. {
  24036. list.removeType (i);
  24037. }
  24038. }
  24039. }
  24040. else if (r != 0)
  24041. {
  24042. typeToScan = r - 10;
  24043. startTimer (1);
  24044. }
  24045. }
  24046. }
  24047. void PluginListComponent::timerCallback()
  24048. {
  24049. stopTimer();
  24050. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  24051. }
  24052. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  24053. {
  24054. return true;
  24055. }
  24056. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  24057. {
  24058. OwnedArray <PluginDescription> typesFound;
  24059. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  24060. }
  24061. void PluginListComponent::scanFor (AudioPluginFormat* format)
  24062. {
  24063. if (format == 0)
  24064. return;
  24065. FileSearchPath path (format->getDefaultLocationsToSearch());
  24066. if (propertiesToUse != 0)
  24067. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24068. {
  24069. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  24070. FileSearchPathListComponent pathList;
  24071. pathList.setSize (500, 300);
  24072. pathList.setPath (path);
  24073. aw.addCustomComponent (&pathList);
  24074. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  24075. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24076. if (aw.runModalLoop() == 0)
  24077. return;
  24078. path = pathList.getPath();
  24079. }
  24080. if (propertiesToUse != 0)
  24081. {
  24082. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24083. propertiesToUse->saveIfNeeded();
  24084. }
  24085. double progress = 0.0;
  24086. AlertWindow aw (TRANS("Scanning for plugins..."),
  24087. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  24088. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24089. aw.addProgressBarComponent (progress);
  24090. aw.enterModalState();
  24091. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24092. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24093. for (;;)
  24094. {
  24095. aw.setMessage (TRANS("Testing:\n\n")
  24096. + scanner.getNextPluginFileThatWillBeScanned());
  24097. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24098. if (! scanner.scanNextFile (true))
  24099. break;
  24100. if (! aw.isCurrentlyModal())
  24101. break;
  24102. progress = scanner.getProgress();
  24103. }
  24104. if (scanner.getFailedFiles().size() > 0)
  24105. {
  24106. StringArray shortNames;
  24107. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24108. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24109. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24110. TRANS("Scan complete"),
  24111. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24112. + shortNames.joinIntoString (", "));
  24113. }
  24114. }
  24115. END_JUCE_NAMESPACE
  24116. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  24117. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24118. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24119. #include <AudioUnit/AudioUnit.h>
  24120. #include <AudioUnit/AUCocoaUIView.h>
  24121. #include <CoreAudioKit/AUGenericView.h>
  24122. #if JUCE_SUPPORT_CARBON
  24123. #include <AudioToolbox/AudioUnitUtilities.h>
  24124. #include <AudioUnit/AudioUnitCarbonView.h>
  24125. #endif
  24126. BEGIN_JUCE_NAMESPACE
  24127. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24128. #endif
  24129. #if JUCE_MAC
  24130. // Change this to disable logging of various activities
  24131. #ifndef AU_LOGGING
  24132. #define AU_LOGGING 1
  24133. #endif
  24134. #if AU_LOGGING
  24135. #define log(a) Logger::writeToLog(a);
  24136. #else
  24137. #define log(a)
  24138. #endif
  24139. static int insideCallback = 0;
  24140. static const String osTypeToString (OSType type) throw()
  24141. {
  24142. char s[4];
  24143. s[0] = (char) (((uint32) type) >> 24);
  24144. s[1] = (char) (((uint32) type) >> 16);
  24145. s[2] = (char) (((uint32) type) >> 8);
  24146. s[3] = (char) ((uint32) type);
  24147. return String (s, 4);
  24148. }
  24149. static OSType stringToOSType (const String& s1) throw()
  24150. {
  24151. const String s (s1 + " ");
  24152. return (((OSType) (unsigned char) s[0]) << 24)
  24153. | (((OSType) (unsigned char) s[1]) << 16)
  24154. | (((OSType) (unsigned char) s[2]) << 8)
  24155. | ((OSType) (unsigned char) s[3]);
  24156. }
  24157. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24158. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24159. {
  24160. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24161. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24162. String s (auIdentifierPrefix);
  24163. if (desc.componentType == kAudioUnitType_MusicDevice)
  24164. s << "Synths/";
  24165. else if (desc.componentType == kAudioUnitType_MusicEffect
  24166. || desc.componentType == kAudioUnitType_Effect)
  24167. s << "Effects/";
  24168. else if (desc.componentType == kAudioUnitType_Generator)
  24169. s << "Generators/";
  24170. else if (desc.componentType == kAudioUnitType_Panner)
  24171. s << "Panners/";
  24172. s << osTypeToString (desc.componentType)
  24173. << T(",")
  24174. << osTypeToString (desc.componentSubType)
  24175. << T(",")
  24176. << osTypeToString (desc.componentManufacturer);
  24177. return s;
  24178. }
  24179. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24180. {
  24181. Handle componentNameHandle = NewHandle (sizeof (void*));
  24182. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24183. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24184. {
  24185. ComponentDescription desc;
  24186. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24187. {
  24188. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24189. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24190. if (nameString != 0 && nameString[0] != 0)
  24191. {
  24192. const String all ((const char*) nameString + 1, nameString[0]);
  24193. DBG ("name: "+ all);
  24194. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24195. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24196. }
  24197. if (infoString != 0 && infoString[0] != 0)
  24198. {
  24199. const String all ((const char*) infoString + 1, infoString[0]);
  24200. DBG ("info: " + all);
  24201. }
  24202. if (name.isEmpty())
  24203. name = "<Unknown>";
  24204. }
  24205. DisposeHandle (componentNameHandle);
  24206. DisposeHandle (componentInfoHandle);
  24207. }
  24208. }
  24209. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24210. String& name, String& version, String& manufacturer)
  24211. {
  24212. zerostruct (desc);
  24213. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24214. {
  24215. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24216. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24217. StringArray tokens;
  24218. tokens.addTokens (s, T(","), 0);
  24219. tokens.trim();
  24220. tokens.removeEmptyStrings();
  24221. if (tokens.size() == 3)
  24222. {
  24223. desc.componentType = stringToOSType (tokens[0]);
  24224. desc.componentSubType = stringToOSType (tokens[1]);
  24225. desc.componentManufacturer = stringToOSType (tokens[2]);
  24226. ComponentRecord* comp = FindNextComponent (0, &desc);
  24227. if (comp != 0)
  24228. {
  24229. getAUDetails (comp, name, manufacturer);
  24230. return true;
  24231. }
  24232. }
  24233. }
  24234. return false;
  24235. }
  24236. class AudioUnitPluginWindowCarbon;
  24237. class AudioUnitPluginWindowCocoa;
  24238. class AudioUnitPluginInstance : public AudioPluginInstance
  24239. {
  24240. public:
  24241. ~AudioUnitPluginInstance();
  24242. // AudioPluginInstance methods:
  24243. void fillInPluginDescription (PluginDescription& desc) const
  24244. {
  24245. desc.name = pluginName;
  24246. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24247. desc.uid = ((int) componentDesc.componentType)
  24248. ^ ((int) componentDesc.componentSubType)
  24249. ^ ((int) componentDesc.componentManufacturer);
  24250. desc.lastFileModTime = 0;
  24251. desc.pluginFormatName = "AudioUnit";
  24252. desc.category = getCategory();
  24253. desc.manufacturerName = manufacturer;
  24254. desc.version = version;
  24255. desc.numInputChannels = getNumInputChannels();
  24256. desc.numOutputChannels = getNumOutputChannels();
  24257. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24258. }
  24259. const String getName() const { return pluginName; }
  24260. bool acceptsMidi() const { return wantsMidiMessages; }
  24261. bool producesMidi() const { return false; }
  24262. // AudioProcessor methods:
  24263. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24264. void releaseResources();
  24265. void processBlock (AudioSampleBuffer& buffer,
  24266. MidiBuffer& midiMessages);
  24267. AudioProcessorEditor* createEditor();
  24268. const String getInputChannelName (const int index) const;
  24269. bool isInputChannelStereoPair (int index) const;
  24270. const String getOutputChannelName (const int index) const;
  24271. bool isOutputChannelStereoPair (int index) const;
  24272. int getNumParameters();
  24273. float getParameter (int index);
  24274. void setParameter (int index, float newValue);
  24275. const String getParameterName (int index);
  24276. const String getParameterText (int index);
  24277. bool isParameterAutomatable (int index) const;
  24278. int getNumPrograms();
  24279. int getCurrentProgram();
  24280. void setCurrentProgram (int index);
  24281. const String getProgramName (int index);
  24282. void changeProgramName (int index, const String& newName);
  24283. void getStateInformation (MemoryBlock& destData);
  24284. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24285. void setStateInformation (const void* data, int sizeInBytes);
  24286. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24287. juce_UseDebuggingNewOperator
  24288. private:
  24289. friend class AudioUnitPluginWindowCarbon;
  24290. friend class AudioUnitPluginWindowCocoa;
  24291. friend class AudioUnitPluginFormat;
  24292. ComponentDescription componentDesc;
  24293. String pluginName, manufacturer, version;
  24294. String fileOrIdentifier;
  24295. CriticalSection lock;
  24296. bool initialised, wantsMidiMessages, wasPlaying;
  24297. HeapBlock <AudioBufferList> outputBufferList;
  24298. AudioTimeStamp timeStamp;
  24299. AudioSampleBuffer* currentBuffer;
  24300. AudioUnit audioUnit;
  24301. Array <int> parameterIds;
  24302. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24303. void initialise();
  24304. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24305. const AudioTimeStamp* inTimeStamp,
  24306. UInt32 inBusNumber,
  24307. UInt32 inNumberFrames,
  24308. AudioBufferList* ioData) const;
  24309. static OSStatus renderGetInputCallback (void* inRefCon,
  24310. AudioUnitRenderActionFlags* ioActionFlags,
  24311. const AudioTimeStamp* inTimeStamp,
  24312. UInt32 inBusNumber,
  24313. UInt32 inNumberFrames,
  24314. AudioBufferList* ioData)
  24315. {
  24316. return ((AudioUnitPluginInstance*) inRefCon)
  24317. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24318. }
  24319. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24320. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24321. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24322. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24323. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24324. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24325. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24326. {
  24327. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24328. }
  24329. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24330. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24331. Float64* outCurrentMeasureDownBeat)
  24332. {
  24333. return ((AudioUnitPluginInstance*) inHostUserData)
  24334. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24335. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24336. }
  24337. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24338. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24339. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24340. {
  24341. return ((AudioUnitPluginInstance*) inHostUserData)
  24342. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24343. outCurrentSampleInTimeLine, outIsCycling,
  24344. outCycleStartBeat, outCycleEndBeat);
  24345. }
  24346. void getNumChannels (int& numIns, int& numOuts)
  24347. {
  24348. numIns = 0;
  24349. numOuts = 0;
  24350. AUChannelInfo supportedChannels [128];
  24351. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24352. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24353. 0, supportedChannels, &supportedChannelsSize) == noErr
  24354. && supportedChannelsSize > 0)
  24355. {
  24356. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24357. {
  24358. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24359. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24360. }
  24361. }
  24362. else
  24363. {
  24364. // (this really means the plugin will take any number of ins/outs as long
  24365. // as they are the same)
  24366. numIns = numOuts = 2;
  24367. }
  24368. }
  24369. const String getCategory() const;
  24370. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24371. };
  24372. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24373. : fileOrIdentifier (fileOrIdentifier),
  24374. initialised (false),
  24375. wantsMidiMessages (false),
  24376. audioUnit (0),
  24377. currentBuffer (0)
  24378. {
  24379. try
  24380. {
  24381. ++insideCallback;
  24382. log (T("Opening AU: ") + fileOrIdentifier);
  24383. if (getComponentDescFromFile (fileOrIdentifier))
  24384. {
  24385. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24386. if (comp != 0)
  24387. {
  24388. audioUnit = (AudioUnit) OpenComponent (comp);
  24389. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24390. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24391. }
  24392. }
  24393. --insideCallback;
  24394. }
  24395. catch (...)
  24396. {
  24397. --insideCallback;
  24398. }
  24399. }
  24400. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24401. {
  24402. {
  24403. const ScopedLock sl (lock);
  24404. jassert (insideCallback == 0);
  24405. if (audioUnit != 0)
  24406. {
  24407. AudioUnitUninitialize (audioUnit);
  24408. CloseComponent (audioUnit);
  24409. audioUnit = 0;
  24410. }
  24411. }
  24412. }
  24413. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24414. {
  24415. zerostruct (componentDesc);
  24416. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24417. return true;
  24418. const File file (fileOrIdentifier);
  24419. if (! file.hasFileExtension (T(".component")))
  24420. return false;
  24421. const char* const utf8 = fileOrIdentifier.toUTF8();
  24422. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24423. strlen (utf8), file.isDirectory());
  24424. if (url != 0)
  24425. {
  24426. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24427. CFRelease (url);
  24428. if (bundleRef != 0)
  24429. {
  24430. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24431. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24432. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24433. if (pluginName.isEmpty())
  24434. pluginName = file.getFileNameWithoutExtension();
  24435. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24436. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24437. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24438. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24439. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24440. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24441. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24442. UseResFile (resFileId);
  24443. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24444. {
  24445. Handle h = Get1IndResource ('thng', i);
  24446. if (h != 0)
  24447. {
  24448. HLock (h);
  24449. const uint32* const types = (const uint32*) *h;
  24450. if (types[0] == kAudioUnitType_MusicDevice
  24451. || types[0] == kAudioUnitType_MusicEffect
  24452. || types[0] == kAudioUnitType_Effect
  24453. || types[0] == kAudioUnitType_Generator
  24454. || types[0] == kAudioUnitType_Panner)
  24455. {
  24456. componentDesc.componentType = types[0];
  24457. componentDesc.componentSubType = types[1];
  24458. componentDesc.componentManufacturer = types[2];
  24459. break;
  24460. }
  24461. HUnlock (h);
  24462. ReleaseResource (h);
  24463. }
  24464. }
  24465. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24466. CFRelease (bundleRef);
  24467. }
  24468. }
  24469. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24470. }
  24471. void AudioUnitPluginInstance::initialise()
  24472. {
  24473. if (initialised || audioUnit == 0)
  24474. return;
  24475. log (T("Initialising AU: ") + pluginName);
  24476. parameterIds.clear();
  24477. {
  24478. UInt32 paramListSize = 0;
  24479. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24480. 0, 0, &paramListSize);
  24481. if (paramListSize > 0)
  24482. {
  24483. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24484. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24485. 0, &parameterIds.getReference(0), &paramListSize);
  24486. }
  24487. }
  24488. {
  24489. AURenderCallbackStruct info;
  24490. zerostruct (info);
  24491. info.inputProcRefCon = this;
  24492. info.inputProc = renderGetInputCallback;
  24493. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24494. 0, &info, sizeof (info));
  24495. }
  24496. {
  24497. HostCallbackInfo info;
  24498. zerostruct (info);
  24499. info.hostUserData = this;
  24500. info.beatAndTempoProc = getBeatAndTempoCallback;
  24501. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24502. info.transportStateProc = getTransportStateCallback;
  24503. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24504. 0, &info, sizeof (info));
  24505. }
  24506. int numIns, numOuts;
  24507. getNumChannels (numIns, numOuts);
  24508. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24509. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24510. setLatencySamples (0);
  24511. }
  24512. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24513. int samplesPerBlockExpected)
  24514. {
  24515. initialise();
  24516. if (initialised)
  24517. {
  24518. int numIns, numOuts;
  24519. getNumChannels (numIns, numOuts);
  24520. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24521. Float64 latencySecs = 0.0;
  24522. UInt32 latencySize = sizeof (latencySecs);
  24523. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24524. 0, &latencySecs, &latencySize);
  24525. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24526. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24527. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24528. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24529. AudioStreamBasicDescription stream;
  24530. zerostruct (stream);
  24531. stream.mSampleRate = sampleRate_;
  24532. stream.mFormatID = kAudioFormatLinearPCM;
  24533. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24534. stream.mFramesPerPacket = 1;
  24535. stream.mBytesPerPacket = 4;
  24536. stream.mBytesPerFrame = 4;
  24537. stream.mBitsPerChannel = 32;
  24538. stream.mChannelsPerFrame = numIns;
  24539. OSStatus err = AudioUnitSetProperty (audioUnit,
  24540. kAudioUnitProperty_StreamFormat,
  24541. kAudioUnitScope_Input,
  24542. 0, &stream, sizeof (stream));
  24543. stream.mChannelsPerFrame = numOuts;
  24544. err = AudioUnitSetProperty (audioUnit,
  24545. kAudioUnitProperty_StreamFormat,
  24546. kAudioUnitScope_Output,
  24547. 0, &stream, sizeof (stream));
  24548. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24549. outputBufferList->mNumberBuffers = numOuts;
  24550. for (int i = numOuts; --i >= 0;)
  24551. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24552. zerostruct (timeStamp);
  24553. timeStamp.mSampleTime = 0;
  24554. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24555. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24556. currentBuffer = 0;
  24557. wasPlaying = false;
  24558. }
  24559. }
  24560. void AudioUnitPluginInstance::releaseResources()
  24561. {
  24562. if (initialised)
  24563. {
  24564. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24565. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24566. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24567. outputBufferList.free();
  24568. currentBuffer = 0;
  24569. }
  24570. }
  24571. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24572. const AudioTimeStamp* inTimeStamp,
  24573. UInt32 inBusNumber,
  24574. UInt32 inNumberFrames,
  24575. AudioBufferList* ioData) const
  24576. {
  24577. if (inBusNumber == 0
  24578. && currentBuffer != 0)
  24579. {
  24580. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24581. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24582. {
  24583. if (i < currentBuffer->getNumChannels())
  24584. {
  24585. memcpy (ioData->mBuffers[i].mData,
  24586. currentBuffer->getSampleData (i, 0),
  24587. sizeof (float) * inNumberFrames);
  24588. }
  24589. else
  24590. {
  24591. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24592. }
  24593. }
  24594. }
  24595. return noErr;
  24596. }
  24597. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24598. MidiBuffer& midiMessages)
  24599. {
  24600. const int numSamples = buffer.getNumSamples();
  24601. if (initialised)
  24602. {
  24603. AudioUnitRenderActionFlags flags = 0;
  24604. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24605. for (int i = getNumOutputChannels(); --i >= 0;)
  24606. {
  24607. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24608. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24609. }
  24610. currentBuffer = &buffer;
  24611. if (wantsMidiMessages)
  24612. {
  24613. const uint8* midiEventData;
  24614. int midiEventSize, midiEventPosition;
  24615. MidiBuffer::Iterator i (midiMessages);
  24616. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24617. {
  24618. if (midiEventSize <= 3)
  24619. MusicDeviceMIDIEvent (audioUnit,
  24620. midiEventData[0], midiEventData[1], midiEventData[2],
  24621. midiEventPosition);
  24622. else
  24623. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24624. }
  24625. midiMessages.clear();
  24626. }
  24627. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24628. 0, numSamples, outputBufferList);
  24629. timeStamp.mSampleTime += numSamples;
  24630. }
  24631. else
  24632. {
  24633. // Not initialised, so just bypass..
  24634. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24635. buffer.clear (i, 0, buffer.getNumSamples());
  24636. }
  24637. }
  24638. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24639. {
  24640. AudioPlayHead* const ph = getPlayHead();
  24641. AudioPlayHead::CurrentPositionInfo result;
  24642. if (ph != 0 && ph->getCurrentPosition (result))
  24643. {
  24644. if (outCurrentBeat != 0)
  24645. *outCurrentBeat = result.ppqPosition;
  24646. if (outCurrentTempo != 0)
  24647. *outCurrentTempo = result.bpm;
  24648. }
  24649. else
  24650. {
  24651. if (outCurrentBeat != 0)
  24652. *outCurrentBeat = 0;
  24653. if (outCurrentTempo != 0)
  24654. *outCurrentTempo = 120.0;
  24655. }
  24656. return noErr;
  24657. }
  24658. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24659. Float32* outTimeSig_Numerator,
  24660. UInt32* outTimeSig_Denominator,
  24661. Float64* outCurrentMeasureDownBeat) const
  24662. {
  24663. AudioPlayHead* const ph = getPlayHead();
  24664. AudioPlayHead::CurrentPositionInfo result;
  24665. if (ph != 0 && ph->getCurrentPosition (result))
  24666. {
  24667. if (outTimeSig_Numerator != 0)
  24668. *outTimeSig_Numerator = result.timeSigNumerator;
  24669. if (outTimeSig_Denominator != 0)
  24670. *outTimeSig_Denominator = result.timeSigDenominator;
  24671. if (outDeltaSampleOffsetToNextBeat != 0)
  24672. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24673. if (outCurrentMeasureDownBeat != 0)
  24674. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24675. }
  24676. else
  24677. {
  24678. if (outDeltaSampleOffsetToNextBeat != 0)
  24679. *outDeltaSampleOffsetToNextBeat = 0;
  24680. if (outTimeSig_Numerator != 0)
  24681. *outTimeSig_Numerator = 4;
  24682. if (outTimeSig_Denominator != 0)
  24683. *outTimeSig_Denominator = 4;
  24684. if (outCurrentMeasureDownBeat != 0)
  24685. *outCurrentMeasureDownBeat = 0;
  24686. }
  24687. return noErr;
  24688. }
  24689. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24690. Boolean* outTransportStateChanged,
  24691. Float64* outCurrentSampleInTimeLine,
  24692. Boolean* outIsCycling,
  24693. Float64* outCycleStartBeat,
  24694. Float64* outCycleEndBeat)
  24695. {
  24696. AudioPlayHead* const ph = getPlayHead();
  24697. AudioPlayHead::CurrentPositionInfo result;
  24698. if (ph != 0 && ph->getCurrentPosition (result))
  24699. {
  24700. if (outIsPlaying != 0)
  24701. *outIsPlaying = result.isPlaying;
  24702. if (outTransportStateChanged != 0)
  24703. {
  24704. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24705. wasPlaying = result.isPlaying;
  24706. }
  24707. if (outCurrentSampleInTimeLine != 0)
  24708. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24709. if (outIsCycling != 0)
  24710. *outIsCycling = false;
  24711. if (outCycleStartBeat != 0)
  24712. *outCycleStartBeat = 0;
  24713. if (outCycleEndBeat != 0)
  24714. *outCycleEndBeat = 0;
  24715. }
  24716. else
  24717. {
  24718. if (outIsPlaying != 0)
  24719. *outIsPlaying = false;
  24720. if (outTransportStateChanged != 0)
  24721. *outTransportStateChanged = false;
  24722. if (outCurrentSampleInTimeLine != 0)
  24723. *outCurrentSampleInTimeLine = 0;
  24724. if (outIsCycling != 0)
  24725. *outIsCycling = false;
  24726. if (outCycleStartBeat != 0)
  24727. *outCycleStartBeat = 0;
  24728. if (outCycleEndBeat != 0)
  24729. *outCycleEndBeat = 0;
  24730. }
  24731. return noErr;
  24732. }
  24733. static VoidArray activeWindows;
  24734. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24735. {
  24736. public:
  24737. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24738. : AudioProcessorEditor (&plugin_),
  24739. plugin (plugin_),
  24740. wrapper (0)
  24741. {
  24742. addAndMakeVisible (wrapper = new NSViewComponent());
  24743. activeWindows.add (this);
  24744. setOpaque (true);
  24745. setVisible (true);
  24746. setSize (100, 100);
  24747. createView (createGenericViewIfNeeded);
  24748. }
  24749. ~AudioUnitPluginWindowCocoa()
  24750. {
  24751. const bool wasValid = isValid();
  24752. wrapper->setView (0);
  24753. activeWindows.removeValue (this);
  24754. if (wasValid)
  24755. plugin.editorBeingDeleted (this);
  24756. delete wrapper;
  24757. }
  24758. bool isValid() const { return wrapper->getView() != 0; }
  24759. void paint (Graphics& g)
  24760. {
  24761. g.fillAll (Colours::white);
  24762. }
  24763. void resized()
  24764. {
  24765. wrapper->setSize (getWidth(), getHeight());
  24766. }
  24767. private:
  24768. AudioUnitPluginInstance& plugin;
  24769. NSViewComponent* wrapper;
  24770. bool createView (const bool createGenericViewIfNeeded)
  24771. {
  24772. NSView* pluginView = 0;
  24773. UInt32 dataSize = 0;
  24774. Boolean isWritable = false;
  24775. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24776. 0, &dataSize, &isWritable) == noErr
  24777. && dataSize != 0
  24778. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24779. 0, &dataSize, &isWritable) == noErr)
  24780. {
  24781. HeapBlock <AudioUnitCocoaViewInfo> info;
  24782. info.calloc (dataSize, 1);
  24783. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24784. 0, info, &dataSize) == noErr)
  24785. {
  24786. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24787. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24788. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24789. Class viewClass = [viewBundle classNamed: viewClassName];
  24790. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24791. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24792. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24793. {
  24794. id factory = [[[viewClass alloc] init] autorelease];
  24795. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24796. withSize: NSMakeSize (getWidth(), getHeight())];
  24797. }
  24798. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24799. {
  24800. CFRelease (info->mCocoaAUViewClass[i]);
  24801. CFRelease (info->mCocoaAUViewBundleLocation);
  24802. }
  24803. }
  24804. }
  24805. if (createGenericViewIfNeeded && (pluginView == 0))
  24806. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24807. wrapper->setView (pluginView);
  24808. if (pluginView != 0)
  24809. setSize ([pluginView frame].size.width,
  24810. [pluginView frame].size.height);
  24811. return pluginView != 0;
  24812. }
  24813. };
  24814. #if JUCE_SUPPORT_CARBON
  24815. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24816. {
  24817. public:
  24818. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24819. : AudioProcessorEditor (&plugin_),
  24820. plugin (plugin_),
  24821. viewComponent (0)
  24822. {
  24823. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24824. activeWindows.add (this);
  24825. setOpaque (true);
  24826. setVisible (true);
  24827. setSize (400, 300);
  24828. ComponentDescription viewList [16];
  24829. UInt32 viewListSize = sizeof (viewList);
  24830. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24831. 0, &viewList, &viewListSize);
  24832. componentRecord = FindNextComponent (0, &viewList[0]);
  24833. }
  24834. ~AudioUnitPluginWindowCarbon()
  24835. {
  24836. deleteAndZero (innerWrapper);
  24837. activeWindows.removeValue (this);
  24838. if (isValid())
  24839. plugin.editorBeingDeleted (this);
  24840. }
  24841. bool isValid() const throw() { return componentRecord != 0; }
  24842. void paint (Graphics& g)
  24843. {
  24844. g.fillAll (Colours::black);
  24845. }
  24846. void resized()
  24847. {
  24848. innerWrapper->setSize (getWidth(), getHeight());
  24849. }
  24850. bool keyStateChanged (const bool)
  24851. {
  24852. return false;
  24853. }
  24854. bool keyPressed (const KeyPress&)
  24855. {
  24856. return false;
  24857. }
  24858. void broughtToFront()
  24859. {
  24860. activeWindows.removeValue (this);
  24861. activeWindows.add (this);
  24862. }
  24863. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24864. AudioUnitCarbonView getViewComponent()
  24865. {
  24866. if (viewComponent == 0 && componentRecord != 0)
  24867. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24868. return viewComponent;
  24869. }
  24870. void closeViewComponent()
  24871. {
  24872. if (viewComponent != 0)
  24873. {
  24874. CloseComponent (viewComponent);
  24875. viewComponent = 0;
  24876. }
  24877. }
  24878. juce_UseDebuggingNewOperator
  24879. private:
  24880. AudioUnitPluginInstance& plugin;
  24881. ComponentRecord* componentRecord;
  24882. AudioUnitCarbonView viewComponent;
  24883. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24884. {
  24885. public:
  24886. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24887. : owner (owner_)
  24888. {
  24889. }
  24890. ~InnerWrapperComponent()
  24891. {
  24892. deleteWindow();
  24893. }
  24894. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24895. {
  24896. log (T("Opening AU GUI: ") + owner->plugin.getName());
  24897. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24898. if (viewComponent == 0)
  24899. return 0;
  24900. Float32Point pos = { 0, 0 };
  24901. Float32Point size = { 250, 200 };
  24902. HIViewRef pluginView = 0;
  24903. AudioUnitCarbonViewCreate (viewComponent,
  24904. owner->getAudioUnit(),
  24905. windowRef,
  24906. rootView,
  24907. &pos,
  24908. &size,
  24909. (ControlRef*) &pluginView);
  24910. return pluginView;
  24911. }
  24912. void removeView (HIViewRef)
  24913. {
  24914. log (T("Closing AU GUI: ") + owner->plugin.getName());
  24915. owner->closeViewComponent();
  24916. }
  24917. private:
  24918. AudioUnitPluginWindowCarbon* const owner;
  24919. };
  24920. friend class InnerWrapperComponent;
  24921. InnerWrapperComponent* innerWrapper;
  24922. };
  24923. #endif
  24924. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24925. {
  24926. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24927. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor> (w))->isValid())
  24928. w = 0;
  24929. #if JUCE_SUPPORT_CARBON
  24930. if (w == 0)
  24931. {
  24932. w = new AudioUnitPluginWindowCarbon (*this);
  24933. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor> (w))->isValid())
  24934. w = 0;
  24935. }
  24936. #endif
  24937. if (w == 0)
  24938. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24939. return w.release();
  24940. }
  24941. const String AudioUnitPluginInstance::getCategory() const
  24942. {
  24943. const char* result = 0;
  24944. switch (componentDesc.componentType)
  24945. {
  24946. case kAudioUnitType_Effect:
  24947. case kAudioUnitType_MusicEffect:
  24948. result = "Effect";
  24949. break;
  24950. case kAudioUnitType_MusicDevice:
  24951. result = "Synth";
  24952. break;
  24953. case kAudioUnitType_Generator:
  24954. result = "Generator";
  24955. break;
  24956. case kAudioUnitType_Panner:
  24957. result = "Panner";
  24958. break;
  24959. default:
  24960. break;
  24961. }
  24962. return result;
  24963. }
  24964. int AudioUnitPluginInstance::getNumParameters()
  24965. {
  24966. return parameterIds.size();
  24967. }
  24968. float AudioUnitPluginInstance::getParameter (int index)
  24969. {
  24970. const ScopedLock sl (lock);
  24971. Float32 value = 0.0f;
  24972. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24973. {
  24974. AudioUnitGetParameter (audioUnit,
  24975. (UInt32) parameterIds.getUnchecked (index),
  24976. kAudioUnitScope_Global, 0,
  24977. &value);
  24978. }
  24979. return value;
  24980. }
  24981. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  24982. {
  24983. const ScopedLock sl (lock);
  24984. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24985. {
  24986. AudioUnitSetParameter (audioUnit,
  24987. (UInt32) parameterIds.getUnchecked (index),
  24988. kAudioUnitScope_Global, 0,
  24989. newValue, 0);
  24990. }
  24991. }
  24992. const String AudioUnitPluginInstance::getParameterName (int index)
  24993. {
  24994. AudioUnitParameterInfo info;
  24995. zerostruct (info);
  24996. UInt32 sz = sizeof (info);
  24997. String name;
  24998. if (AudioUnitGetProperty (audioUnit,
  24999. kAudioUnitProperty_ParameterInfo,
  25000. kAudioUnitScope_Global,
  25001. parameterIds [index], &info, &sz) == noErr)
  25002. {
  25003. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  25004. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  25005. else
  25006. name = String (info.name, sizeof (info.name));
  25007. }
  25008. return name;
  25009. }
  25010. const String AudioUnitPluginInstance::getParameterText (int index)
  25011. {
  25012. return String (getParameter (index));
  25013. }
  25014. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  25015. {
  25016. AudioUnitParameterInfo info;
  25017. UInt32 sz = sizeof (info);
  25018. if (AudioUnitGetProperty (audioUnit,
  25019. kAudioUnitProperty_ParameterInfo,
  25020. kAudioUnitScope_Global,
  25021. parameterIds [index], &info, &sz) == noErr)
  25022. {
  25023. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  25024. }
  25025. return true;
  25026. }
  25027. int AudioUnitPluginInstance::getNumPrograms()
  25028. {
  25029. CFArrayRef presets;
  25030. UInt32 sz = sizeof (CFArrayRef);
  25031. int num = 0;
  25032. if (AudioUnitGetProperty (audioUnit,
  25033. kAudioUnitProperty_FactoryPresets,
  25034. kAudioUnitScope_Global,
  25035. 0, &presets, &sz) == noErr)
  25036. {
  25037. num = (int) CFArrayGetCount (presets);
  25038. CFRelease (presets);
  25039. }
  25040. return num;
  25041. }
  25042. int AudioUnitPluginInstance::getCurrentProgram()
  25043. {
  25044. AUPreset current;
  25045. current.presetNumber = 0;
  25046. UInt32 sz = sizeof (AUPreset);
  25047. AudioUnitGetProperty (audioUnit,
  25048. kAudioUnitProperty_FactoryPresets,
  25049. kAudioUnitScope_Global,
  25050. 0, &current, &sz);
  25051. return current.presetNumber;
  25052. }
  25053. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  25054. {
  25055. AUPreset current;
  25056. current.presetNumber = newIndex;
  25057. current.presetName = 0;
  25058. AudioUnitSetProperty (audioUnit,
  25059. kAudioUnitProperty_FactoryPresets,
  25060. kAudioUnitScope_Global,
  25061. 0, &current, sizeof (AUPreset));
  25062. }
  25063. const String AudioUnitPluginInstance::getProgramName (int index)
  25064. {
  25065. String s;
  25066. CFArrayRef presets;
  25067. UInt32 sz = sizeof (CFArrayRef);
  25068. if (AudioUnitGetProperty (audioUnit,
  25069. kAudioUnitProperty_FactoryPresets,
  25070. kAudioUnitScope_Global,
  25071. 0, &presets, &sz) == noErr)
  25072. {
  25073. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  25074. {
  25075. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  25076. if (p != 0 && p->presetNumber == index)
  25077. {
  25078. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  25079. break;
  25080. }
  25081. }
  25082. CFRelease (presets);
  25083. }
  25084. return s;
  25085. }
  25086. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  25087. {
  25088. jassertfalse // xxx not implemented!
  25089. }
  25090. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  25091. {
  25092. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  25093. return T("Input ") + String (index + 1);
  25094. return String::empty;
  25095. }
  25096. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25097. {
  25098. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25099. return false;
  25100. return true;
  25101. }
  25102. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25103. {
  25104. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25105. return T("Output ") + String (index + 1);
  25106. return String::empty;
  25107. }
  25108. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25109. {
  25110. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25111. return false;
  25112. return true;
  25113. }
  25114. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25115. {
  25116. getCurrentProgramStateInformation (destData);
  25117. }
  25118. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25119. {
  25120. CFPropertyListRef propertyList = 0;
  25121. UInt32 sz = sizeof (CFPropertyListRef);
  25122. if (AudioUnitGetProperty (audioUnit,
  25123. kAudioUnitProperty_ClassInfo,
  25124. kAudioUnitScope_Global,
  25125. 0, &propertyList, &sz) == noErr)
  25126. {
  25127. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25128. CFWriteStreamOpen (stream);
  25129. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25130. CFWriteStreamClose (stream);
  25131. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25132. destData.setSize (bytesWritten);
  25133. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25134. CFRelease (data);
  25135. CFRelease (stream);
  25136. CFRelease (propertyList);
  25137. }
  25138. }
  25139. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25140. {
  25141. setCurrentProgramStateInformation (data, sizeInBytes);
  25142. }
  25143. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25144. {
  25145. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25146. (const UInt8*) data,
  25147. sizeInBytes,
  25148. kCFAllocatorNull);
  25149. CFReadStreamOpen (stream);
  25150. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25151. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25152. stream,
  25153. 0,
  25154. kCFPropertyListImmutable,
  25155. &format,
  25156. 0);
  25157. CFRelease (stream);
  25158. if (propertyList != 0)
  25159. AudioUnitSetProperty (audioUnit,
  25160. kAudioUnitProperty_ClassInfo,
  25161. kAudioUnitScope_Global,
  25162. 0, &propertyList, sizeof (propertyList));
  25163. }
  25164. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25165. {
  25166. }
  25167. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25168. {
  25169. }
  25170. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25171. const String& fileOrIdentifier)
  25172. {
  25173. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25174. return;
  25175. PluginDescription desc;
  25176. desc.fileOrIdentifier = fileOrIdentifier;
  25177. desc.uid = 0;
  25178. try
  25179. {
  25180. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25181. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25182. if (auInstance != 0)
  25183. {
  25184. auInstance->fillInPluginDescription (desc);
  25185. results.add (new PluginDescription (desc));
  25186. }
  25187. }
  25188. catch (...)
  25189. {
  25190. // crashed while loading...
  25191. }
  25192. }
  25193. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25194. {
  25195. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25196. {
  25197. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25198. if (result->audioUnit != 0)
  25199. {
  25200. result->initialise();
  25201. return result.release();
  25202. }
  25203. }
  25204. return 0;
  25205. }
  25206. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25207. const bool /*recursive*/)
  25208. {
  25209. StringArray result;
  25210. ComponentRecord* comp = 0;
  25211. ComponentDescription desc;
  25212. zerostruct (desc);
  25213. for (;;)
  25214. {
  25215. zerostruct (desc);
  25216. comp = FindNextComponent (comp, &desc);
  25217. if (comp == 0)
  25218. break;
  25219. GetComponentInfo (comp, &desc, 0, 0, 0);
  25220. if (desc.componentType == kAudioUnitType_MusicDevice
  25221. || desc.componentType == kAudioUnitType_MusicEffect
  25222. || desc.componentType == kAudioUnitType_Effect
  25223. || desc.componentType == kAudioUnitType_Generator
  25224. || desc.componentType == kAudioUnitType_Panner)
  25225. {
  25226. const String s (createAUPluginIdentifier (desc));
  25227. DBG (s);
  25228. result.add (s);
  25229. }
  25230. }
  25231. return result;
  25232. }
  25233. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25234. {
  25235. ComponentDescription desc;
  25236. String name, version, manufacturer;
  25237. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25238. return FindNextComponent (0, &desc) != 0;
  25239. const File f (fileOrIdentifier);
  25240. return f.hasFileExtension (T(".component"))
  25241. && f.isDirectory();
  25242. }
  25243. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25244. {
  25245. ComponentDescription desc;
  25246. String name, version, manufacturer;
  25247. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25248. if (name.isEmpty())
  25249. name = fileOrIdentifier;
  25250. return name;
  25251. }
  25252. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25253. {
  25254. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25255. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25256. else
  25257. return File (desc.fileOrIdentifier).exists();
  25258. }
  25259. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25260. {
  25261. return FileSearchPath ("/(Default AudioUnit locations)");
  25262. }
  25263. #endif
  25264. END_JUCE_NAMESPACE
  25265. #undef log
  25266. #endif
  25267. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25268. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25269. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25270. #define JUCE_MAC_VST_INCLUDED 1
  25271. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25272. #if JUCE_PLUGINHOST_VST
  25273. #if (defined (_WIN32) || defined (_WIN64))
  25274. #undef _WIN32_WINNT
  25275. #define _WIN32_WINNT 0x500
  25276. #undef STRICT
  25277. #define STRICT
  25278. #include <windows.h>
  25279. #include <float.h>
  25280. #pragma warning (disable : 4312 4355)
  25281. #elif defined (LINUX) || defined (__linux__)
  25282. #include <float.h>
  25283. #include <sys/time.h>
  25284. #include <X11/Xlib.h>
  25285. #include <X11/Xutil.h>
  25286. #include <X11/Xatom.h>
  25287. #undef Font
  25288. #undef KeyPress
  25289. #undef Drawable
  25290. #undef Time
  25291. #else
  25292. #ifndef JUCE_MAC_VST_INCLUDED
  25293. // On the mac, this file needs to be compiled indirectly, by using
  25294. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25295. #error
  25296. #endif
  25297. #include <Cocoa/Cocoa.h>
  25298. #include <Carbon/Carbon.h>
  25299. #endif
  25300. #if ! (JUCE_MAC && JUCE_64BIT)
  25301. BEGIN_JUCE_NAMESPACE
  25302. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25303. #endif
  25304. #undef PRAGMA_ALIGN_SUPPORTED
  25305. #define VST_FORCE_DEPRECATED 0
  25306. #ifdef _MSC_VER
  25307. #pragma warning (push)
  25308. #pragma warning (disable: 4996)
  25309. #endif
  25310. #include "pluginterfaces/vst2.x/aeffectx.h"
  25311. #ifdef _MSC_VER
  25312. #pragma warning (pop)
  25313. #endif
  25314. #if JUCE_LINUX
  25315. #define Font JUCE_NAMESPACE::Font
  25316. #define KeyPress JUCE_NAMESPACE::KeyPress
  25317. #define Drawable JUCE_NAMESPACE::Drawable
  25318. #define Time JUCE_NAMESPACE::Time
  25319. #endif
  25320. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25321. #ifdef __aeffect__
  25322. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25323. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25324. class VSTMidiEventList
  25325. {
  25326. public:
  25327. VSTMidiEventList()
  25328. : numEventsUsed (0), numEventsAllocated (0)
  25329. {
  25330. }
  25331. ~VSTMidiEventList()
  25332. {
  25333. freeEvents();
  25334. }
  25335. void clear()
  25336. {
  25337. numEventsUsed = 0;
  25338. if (events != 0)
  25339. events->numEvents = 0;
  25340. }
  25341. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25342. {
  25343. ensureSize (numEventsUsed + 1);
  25344. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25345. events->numEvents = ++numEventsUsed;
  25346. if (numBytes <= 4)
  25347. {
  25348. if (e->type == kVstSysExType)
  25349. {
  25350. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25351. e->type = kVstMidiType;
  25352. e->byteSize = sizeof (VstMidiEvent);
  25353. e->noteLength = 0;
  25354. e->noteOffset = 0;
  25355. e->detune = 0;
  25356. e->noteOffVelocity = 0;
  25357. }
  25358. e->deltaFrames = frameOffset;
  25359. memcpy (e->midiData, midiData, numBytes);
  25360. }
  25361. else
  25362. {
  25363. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25364. if (se->type == kVstSysExType)
  25365. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25366. else
  25367. se->sysexDump = (char*) juce_malloc (numBytes);
  25368. memcpy (se->sysexDump, midiData, numBytes);
  25369. se->type = kVstSysExType;
  25370. se->byteSize = sizeof (VstMidiSysexEvent);
  25371. se->deltaFrames = frameOffset;
  25372. se->flags = 0;
  25373. se->dumpBytes = numBytes;
  25374. se->resvd1 = 0;
  25375. se->resvd2 = 0;
  25376. }
  25377. }
  25378. // Handy method to pull the events out of an event buffer supplied by the host
  25379. // or plugin.
  25380. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25381. {
  25382. for (int i = 0; i < events->numEvents; ++i)
  25383. {
  25384. const VstEvent* const e = events->events[i];
  25385. if (e != 0)
  25386. {
  25387. if (e->type == kVstMidiType)
  25388. {
  25389. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25390. 4, e->deltaFrames);
  25391. }
  25392. else if (e->type == kVstSysExType)
  25393. {
  25394. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25395. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25396. e->deltaFrames);
  25397. }
  25398. }
  25399. }
  25400. }
  25401. void ensureSize (int numEventsNeeded)
  25402. {
  25403. if (numEventsNeeded > numEventsAllocated)
  25404. {
  25405. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25406. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25407. if (events == 0)
  25408. events.calloc (size, 1);
  25409. else
  25410. events.realloc (size, 1);
  25411. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25412. {
  25413. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25414. (int) sizeof (VstMidiSysexEvent)));
  25415. e->type = kVstMidiType;
  25416. e->byteSize = sizeof (VstMidiEvent);
  25417. events->events[i] = (VstEvent*) e;
  25418. }
  25419. numEventsAllocated = numEventsNeeded;
  25420. }
  25421. }
  25422. void freeEvents()
  25423. {
  25424. if (events != 0)
  25425. {
  25426. for (int i = numEventsAllocated; --i >= 0;)
  25427. {
  25428. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25429. if (e->type == kVstSysExType)
  25430. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25431. juce_free (e);
  25432. }
  25433. events.free();
  25434. numEventsUsed = 0;
  25435. numEventsAllocated = 0;
  25436. }
  25437. }
  25438. HeapBlock <VstEvents> events;
  25439. private:
  25440. int numEventsUsed, numEventsAllocated;
  25441. };
  25442. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25443. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25444. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25445. #if ! JUCE_WIN32
  25446. static void _fpreset() {}
  25447. static void _clearfp() {}
  25448. #endif
  25449. extern void juce_callAnyTimersSynchronously();
  25450. const int fxbVersionNum = 1;
  25451. struct fxProgram
  25452. {
  25453. long chunkMagic; // 'CcnK'
  25454. long byteSize; // of this chunk, excl. magic + byteSize
  25455. long fxMagic; // 'FxCk'
  25456. long version;
  25457. long fxID; // fx unique id
  25458. long fxVersion;
  25459. long numParams;
  25460. char prgName[28];
  25461. float params[1]; // variable no. of parameters
  25462. };
  25463. struct fxSet
  25464. {
  25465. long chunkMagic; // 'CcnK'
  25466. long byteSize; // of this chunk, excl. magic + byteSize
  25467. long fxMagic; // 'FxBk'
  25468. long version;
  25469. long fxID; // fx unique id
  25470. long fxVersion;
  25471. long numPrograms;
  25472. char future[128];
  25473. fxProgram programs[1]; // variable no. of programs
  25474. };
  25475. struct fxChunkSet
  25476. {
  25477. long chunkMagic; // 'CcnK'
  25478. long byteSize; // of this chunk, excl. magic + byteSize
  25479. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25480. long version;
  25481. long fxID; // fx unique id
  25482. long fxVersion;
  25483. long numPrograms;
  25484. char future[128];
  25485. long chunkSize;
  25486. char chunk[8]; // variable
  25487. };
  25488. struct fxProgramSet
  25489. {
  25490. long chunkMagic; // 'CcnK'
  25491. long byteSize; // of this chunk, excl. magic + byteSize
  25492. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25493. long version;
  25494. long fxID; // fx unique id
  25495. long fxVersion;
  25496. long numPrograms;
  25497. char name[28];
  25498. long chunkSize;
  25499. char chunk[8]; // variable
  25500. };
  25501. static long vst_swap (const long x) throw()
  25502. {
  25503. #ifdef JUCE_LITTLE_ENDIAN
  25504. return (long) ByteOrder::swap ((uint32) x);
  25505. #else
  25506. return x;
  25507. #endif
  25508. }
  25509. static float vst_swapFloat (const float x) throw()
  25510. {
  25511. #ifdef JUCE_LITTLE_ENDIAN
  25512. union { uint32 asInt; float asFloat; } n;
  25513. n.asFloat = x;
  25514. n.asInt = ByteOrder::swap (n.asInt);
  25515. return n.asFloat;
  25516. #else
  25517. return x;
  25518. #endif
  25519. }
  25520. typedef AEffect* (*MainCall) (audioMasterCallback);
  25521. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25522. static int shellUIDToCreate = 0;
  25523. static int insideVSTCallback = 0;
  25524. class VSTPluginWindow;
  25525. // Change this to disable logging of various VST activities
  25526. #ifndef VST_LOGGING
  25527. #define VST_LOGGING 1
  25528. #endif
  25529. #if VST_LOGGING
  25530. #define log(a) Logger::writeToLog(a);
  25531. #else
  25532. #define log(a)
  25533. #endif
  25534. #if JUCE_MAC && JUCE_PPC
  25535. static void* NewCFMFromMachO (void* const machofp) throw()
  25536. {
  25537. void* result = juce_malloc (8);
  25538. ((void**) result)[0] = machofp;
  25539. ((void**) result)[1] = result;
  25540. return result;
  25541. }
  25542. #endif
  25543. #if JUCE_LINUX
  25544. extern Display* display;
  25545. extern XContext improbableNumber;
  25546. typedef void (*EventProcPtr) (XEvent* ev);
  25547. static bool xErrorTriggered;
  25548. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25549. {
  25550. xErrorTriggered = true;
  25551. return 0;
  25552. }
  25553. static int getPropertyFromXWindow (Window handle, Atom atom)
  25554. {
  25555. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25556. xErrorTriggered = false;
  25557. int userSize;
  25558. unsigned long bytes, userCount;
  25559. unsigned char* data;
  25560. Atom userType;
  25561. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25562. &userType, &userSize, &userCount, &bytes, &data);
  25563. XSetErrorHandler (oldErrorHandler);
  25564. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25565. : 0;
  25566. }
  25567. static Window getChildWindow (Window windowToCheck)
  25568. {
  25569. Window rootWindow, parentWindow;
  25570. Window* childWindows;
  25571. unsigned int numChildren;
  25572. XQueryTree (display,
  25573. windowToCheck,
  25574. &rootWindow,
  25575. &parentWindow,
  25576. &childWindows,
  25577. &numChildren);
  25578. if (numChildren > 0)
  25579. return childWindows [0];
  25580. return 0;
  25581. }
  25582. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25583. {
  25584. if (e.mods.isLeftButtonDown())
  25585. {
  25586. ev.xbutton.button = Button1;
  25587. ev.xbutton.state |= Button1Mask;
  25588. }
  25589. else if (e.mods.isRightButtonDown())
  25590. {
  25591. ev.xbutton.button = Button3;
  25592. ev.xbutton.state |= Button3Mask;
  25593. }
  25594. else if (e.mods.isMiddleButtonDown())
  25595. {
  25596. ev.xbutton.button = Button2;
  25597. ev.xbutton.state |= Button2Mask;
  25598. }
  25599. }
  25600. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25601. {
  25602. if (e.mods.isLeftButtonDown())
  25603. ev.xmotion.state |= Button1Mask;
  25604. else if (e.mods.isRightButtonDown())
  25605. ev.xmotion.state |= Button3Mask;
  25606. else if (e.mods.isMiddleButtonDown())
  25607. ev.xmotion.state |= Button2Mask;
  25608. }
  25609. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25610. {
  25611. if (e.mods.isLeftButtonDown())
  25612. ev.xcrossing.state |= Button1Mask;
  25613. else if (e.mods.isRightButtonDown())
  25614. ev.xcrossing.state |= Button3Mask;
  25615. else if (e.mods.isMiddleButtonDown())
  25616. ev.xcrossing.state |= Button2Mask;
  25617. }
  25618. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25619. {
  25620. if (increment < 0)
  25621. {
  25622. ev.xbutton.button = Button5;
  25623. ev.xbutton.state |= Button5Mask;
  25624. }
  25625. else if (increment > 0)
  25626. {
  25627. ev.xbutton.button = Button4;
  25628. ev.xbutton.state |= Button4Mask;
  25629. }
  25630. }
  25631. #endif
  25632. static VoidArray activeModules;
  25633. class ModuleHandle : public ReferenceCountedObject
  25634. {
  25635. public:
  25636. File file;
  25637. MainCall moduleMain;
  25638. String pluginName;
  25639. static ModuleHandle* findOrCreateModule (const File& file)
  25640. {
  25641. for (int i = activeModules.size(); --i >= 0;)
  25642. {
  25643. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25644. if (module->file == file)
  25645. return module;
  25646. }
  25647. _fpreset(); // (doesn't do any harm)
  25648. ++insideVSTCallback;
  25649. shellUIDToCreate = 0;
  25650. log ("Attempting to load VST: " + file.getFullPathName());
  25651. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25652. if (! m->open())
  25653. m = 0;
  25654. --insideVSTCallback;
  25655. _fpreset(); // (doesn't do any harm)
  25656. return m.release();
  25657. }
  25658. ModuleHandle (const File& file_)
  25659. : file (file_),
  25660. moduleMain (0),
  25661. #if JUCE_WIN32 || JUCE_LINUX
  25662. hModule (0)
  25663. #elif JUCE_MAC
  25664. fragId (0),
  25665. resHandle (0),
  25666. bundleRef (0),
  25667. resFileId (0)
  25668. #endif
  25669. {
  25670. activeModules.add (this);
  25671. #if JUCE_WIN32 || JUCE_LINUX
  25672. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25673. #elif JUCE_MAC
  25674. FSRef ref;
  25675. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25676. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25677. #endif
  25678. }
  25679. ~ModuleHandle()
  25680. {
  25681. activeModules.removeValue (this);
  25682. close();
  25683. }
  25684. juce_UseDebuggingNewOperator
  25685. #if JUCE_WIN32 || JUCE_LINUX
  25686. void* hModule;
  25687. String fullParentDirectoryPathName;
  25688. bool open()
  25689. {
  25690. #if JUCE_WIN32
  25691. static bool timePeriodSet = false;
  25692. if (! timePeriodSet)
  25693. {
  25694. timePeriodSet = true;
  25695. timeBeginPeriod (2);
  25696. }
  25697. #endif
  25698. pluginName = file.getFileNameWithoutExtension();
  25699. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25700. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25701. if (moduleMain == 0)
  25702. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25703. return moduleMain != 0;
  25704. }
  25705. void close()
  25706. {
  25707. _fpreset(); // (doesn't do any harm)
  25708. PlatformUtilities::freeDynamicLibrary (hModule);
  25709. }
  25710. void closeEffect (AEffect* eff)
  25711. {
  25712. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25713. }
  25714. #else
  25715. CFragConnectionID fragId;
  25716. Handle resHandle;
  25717. CFBundleRef bundleRef;
  25718. FSSpec parentDirFSSpec;
  25719. short resFileId;
  25720. bool open()
  25721. {
  25722. bool ok = false;
  25723. const String filename (file.getFullPathName());
  25724. if (file.hasFileExtension (T(".vst")))
  25725. {
  25726. const char* const utf8 = filename.toUTF8();
  25727. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25728. strlen (utf8), file.isDirectory());
  25729. if (url != 0)
  25730. {
  25731. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25732. CFRelease (url);
  25733. if (bundleRef != 0)
  25734. {
  25735. if (CFBundleLoadExecutable (bundleRef))
  25736. {
  25737. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25738. if (moduleMain == 0)
  25739. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25740. if (moduleMain != 0)
  25741. {
  25742. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25743. if (name != 0)
  25744. {
  25745. if (CFGetTypeID (name) == CFStringGetTypeID())
  25746. {
  25747. char buffer[1024];
  25748. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25749. pluginName = buffer;
  25750. }
  25751. }
  25752. if (pluginName.isEmpty())
  25753. pluginName = file.getFileNameWithoutExtension();
  25754. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25755. ok = true;
  25756. }
  25757. }
  25758. if (! ok)
  25759. {
  25760. CFBundleUnloadExecutable (bundleRef);
  25761. CFRelease (bundleRef);
  25762. bundleRef = 0;
  25763. }
  25764. }
  25765. }
  25766. }
  25767. #if JUCE_PPC
  25768. else
  25769. {
  25770. FSRef fn;
  25771. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25772. {
  25773. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25774. if (resFileId != -1)
  25775. {
  25776. const int numEffs = Count1Resources ('aEff');
  25777. for (int i = 0; i < numEffs; ++i)
  25778. {
  25779. resHandle = Get1IndResource ('aEff', i + 1);
  25780. if (resHandle != 0)
  25781. {
  25782. OSType type;
  25783. Str255 name;
  25784. SInt16 id;
  25785. GetResInfo (resHandle, &id, &type, name);
  25786. pluginName = String ((const char*) name + 1, name[0]);
  25787. DetachResource (resHandle);
  25788. HLock (resHandle);
  25789. Ptr ptr;
  25790. Str255 errorText;
  25791. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25792. name, kPrivateCFragCopy,
  25793. &fragId, &ptr, errorText);
  25794. if (err == noErr)
  25795. {
  25796. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25797. ok = true;
  25798. }
  25799. else
  25800. {
  25801. HUnlock (resHandle);
  25802. }
  25803. break;
  25804. }
  25805. }
  25806. if (! ok)
  25807. CloseResFile (resFileId);
  25808. }
  25809. }
  25810. }
  25811. #endif
  25812. return ok;
  25813. }
  25814. void close()
  25815. {
  25816. #if JUCE_PPC
  25817. if (fragId != 0)
  25818. {
  25819. if (moduleMain != 0)
  25820. disposeMachOFromCFM ((void*) moduleMain);
  25821. CloseConnection (&fragId);
  25822. HUnlock (resHandle);
  25823. if (resFileId != 0)
  25824. CloseResFile (resFileId);
  25825. }
  25826. else
  25827. #endif
  25828. if (bundleRef != 0)
  25829. {
  25830. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25831. if (CFGetRetainCount (bundleRef) == 1)
  25832. CFBundleUnloadExecutable (bundleRef);
  25833. if (CFGetRetainCount (bundleRef) > 0)
  25834. CFRelease (bundleRef);
  25835. }
  25836. }
  25837. void closeEffect (AEffect* eff)
  25838. {
  25839. #if JUCE_PPC
  25840. if (fragId != 0)
  25841. {
  25842. VoidArray thingsToDelete;
  25843. thingsToDelete.add ((void*) eff->dispatcher);
  25844. thingsToDelete.add ((void*) eff->process);
  25845. thingsToDelete.add ((void*) eff->setParameter);
  25846. thingsToDelete.add ((void*) eff->getParameter);
  25847. thingsToDelete.add ((void*) eff->processReplacing);
  25848. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25849. for (int i = thingsToDelete.size(); --i >= 0;)
  25850. disposeMachOFromCFM (thingsToDelete[i]);
  25851. }
  25852. else
  25853. #endif
  25854. {
  25855. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25856. }
  25857. }
  25858. #if JUCE_PPC
  25859. static void* newMachOFromCFM (void* cfmfp)
  25860. {
  25861. if (cfmfp == 0)
  25862. return 0;
  25863. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25864. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25865. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25866. mfp[2] = 0x800c0000;
  25867. mfp[3] = 0x804c0004;
  25868. mfp[4] = 0x7c0903a6;
  25869. mfp[5] = 0x4e800420;
  25870. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25871. return mfp;
  25872. }
  25873. static void disposeMachOFromCFM (void* ptr)
  25874. {
  25875. juce_free (ptr);
  25876. }
  25877. void coerceAEffectFunctionCalls (AEffect* eff)
  25878. {
  25879. if (fragId != 0)
  25880. {
  25881. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25882. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25883. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25884. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25885. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25886. }
  25887. }
  25888. #endif
  25889. #endif
  25890. };
  25891. class VSTPluginInstance : public AudioPluginInstance,
  25892. private Timer,
  25893. private AsyncUpdater
  25894. {
  25895. public:
  25896. ~VSTPluginInstance();
  25897. // AudioPluginInstance methods:
  25898. void fillInPluginDescription (PluginDescription& desc) const
  25899. {
  25900. desc.name = name;
  25901. desc.fileOrIdentifier = module->file.getFullPathName();
  25902. desc.uid = getUID();
  25903. desc.lastFileModTime = module->file.getLastModificationTime();
  25904. desc.pluginFormatName = "VST";
  25905. desc.category = getCategory();
  25906. {
  25907. char buffer [kVstMaxVendorStrLen + 8];
  25908. zerostruct (buffer);
  25909. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25910. desc.manufacturerName = buffer;
  25911. }
  25912. desc.version = getVersion();
  25913. desc.numInputChannels = getNumInputChannels();
  25914. desc.numOutputChannels = getNumOutputChannels();
  25915. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25916. }
  25917. const String getName() const { return name; }
  25918. int getUID() const throw();
  25919. bool acceptsMidi() const { return wantsMidiMessages; }
  25920. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25921. // AudioProcessor methods:
  25922. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25923. void releaseResources();
  25924. void processBlock (AudioSampleBuffer& buffer,
  25925. MidiBuffer& midiMessages);
  25926. AudioProcessorEditor* createEditor();
  25927. const String getInputChannelName (const int index) const;
  25928. bool isInputChannelStereoPair (int index) const;
  25929. const String getOutputChannelName (const int index) const;
  25930. bool isOutputChannelStereoPair (int index) const;
  25931. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25932. float getParameter (int index);
  25933. void setParameter (int index, float newValue);
  25934. const String getParameterName (int index);
  25935. const String getParameterText (int index);
  25936. bool isParameterAutomatable (int index) const;
  25937. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25938. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25939. void setCurrentProgram (int index);
  25940. const String getProgramName (int index);
  25941. void changeProgramName (int index, const String& newName);
  25942. void getStateInformation (MemoryBlock& destData);
  25943. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25944. void setStateInformation (const void* data, int sizeInBytes);
  25945. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25946. void timerCallback();
  25947. void handleAsyncUpdate();
  25948. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25949. juce_UseDebuggingNewOperator
  25950. private:
  25951. friend class VSTPluginWindow;
  25952. friend class VSTPluginFormat;
  25953. AEffect* effect;
  25954. String name;
  25955. CriticalSection lock;
  25956. bool wantsMidiMessages, initialised, isPowerOn;
  25957. mutable StringArray programNames;
  25958. AudioSampleBuffer tempBuffer;
  25959. CriticalSection midiInLock;
  25960. MidiBuffer incomingMidi;
  25961. VSTMidiEventList midiEventsToSend;
  25962. VstTimeInfo vstHostTime;
  25963. HeapBlock <float*> channels;
  25964. ReferenceCountedObjectPtr <ModuleHandle> module;
  25965. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25966. bool restoreProgramSettings (const fxProgram* const prog);
  25967. const String getCurrentProgramName();
  25968. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25969. void updateStoredProgramNames();
  25970. void initialise();
  25971. void handleMidiFromPlugin (const VstEvents* const events);
  25972. void createTempParameterStore (MemoryBlock& dest);
  25973. void restoreFromTempParameterStore (const MemoryBlock& mb);
  25974. const String getParameterLabel (int index) const;
  25975. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  25976. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  25977. void setChunkData (const char* data, int size, bool isPreset);
  25978. bool loadFromFXBFile (const void* data, int numBytes);
  25979. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  25980. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  25981. const String getVersion() const throw();
  25982. const String getCategory() const throw();
  25983. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  25984. void setPower (const bool on);
  25985. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  25986. };
  25987. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  25988. : effect (0),
  25989. wantsMidiMessages (false),
  25990. initialised (false),
  25991. isPowerOn (false),
  25992. tempBuffer (1, 1),
  25993. module (module_)
  25994. {
  25995. try
  25996. {
  25997. _fpreset();
  25998. ++insideVSTCallback;
  25999. name = module->pluginName;
  26000. log (T("Creating VST instance: ") + name);
  26001. #if JUCE_MAC
  26002. if (module->resFileId != 0)
  26003. UseResFile (module->resFileId);
  26004. #if JUCE_PPC
  26005. if (module->fragId != 0)
  26006. {
  26007. static void* audioMasterCoerced = 0;
  26008. if (audioMasterCoerced == 0)
  26009. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  26010. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  26011. }
  26012. else
  26013. #endif
  26014. #endif
  26015. {
  26016. effect = module->moduleMain (&audioMaster);
  26017. }
  26018. --insideVSTCallback;
  26019. if (effect != 0 && effect->magic == kEffectMagic)
  26020. {
  26021. #if JUCE_PPC
  26022. module->coerceAEffectFunctionCalls (effect);
  26023. #endif
  26024. jassert (effect->resvd2 == 0);
  26025. jassert (effect->object != 0);
  26026. _fpreset(); // some dodgy plugs fuck around with this
  26027. }
  26028. else
  26029. {
  26030. effect = 0;
  26031. }
  26032. }
  26033. catch (...)
  26034. {
  26035. --insideVSTCallback;
  26036. }
  26037. }
  26038. VSTPluginInstance::~VSTPluginInstance()
  26039. {
  26040. {
  26041. const ScopedLock sl (lock);
  26042. jassert (insideVSTCallback == 0);
  26043. if (effect != 0 && effect->magic == kEffectMagic)
  26044. {
  26045. try
  26046. {
  26047. #if JUCE_MAC
  26048. if (module->resFileId != 0)
  26049. UseResFile (module->resFileId);
  26050. #endif
  26051. // Must delete any editors before deleting the plugin instance!
  26052. jassert (getActiveEditor() == 0);
  26053. _fpreset(); // some dodgy plugs fuck around with this
  26054. module->closeEffect (effect);
  26055. }
  26056. catch (...)
  26057. {}
  26058. }
  26059. module = 0;
  26060. effect = 0;
  26061. }
  26062. }
  26063. void VSTPluginInstance::initialise()
  26064. {
  26065. if (initialised || effect == 0)
  26066. return;
  26067. log (T("Initialising VST: ") + module->pluginName);
  26068. initialised = true;
  26069. dispatch (effIdentify, 0, 0, 0, 0);
  26070. // this code would ask the plugin for its name, but so few plugins
  26071. // actually bother implementing this correctly, that it's better to
  26072. // just ignore it and use the file name instead.
  26073. if (getSampleRate() > 0)
  26074. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  26075. if (getBlockSize() > 0)
  26076. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  26077. dispatch (effOpen, 0, 0, 0, 0);
  26078. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26079. getSampleRate(), getBlockSize());
  26080. if (getNumPrograms() > 1)
  26081. setCurrentProgram (0);
  26082. else
  26083. dispatch (effSetProgram, 0, 0, 0, 0);
  26084. int i;
  26085. for (i = effect->numInputs; --i >= 0;)
  26086. dispatch (effConnectInput, i, 1, 0, 0);
  26087. for (i = effect->numOutputs; --i >= 0;)
  26088. dispatch (effConnectOutput, i, 1, 0, 0);
  26089. updateStoredProgramNames();
  26090. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  26091. setLatencySamples (effect->initialDelay);
  26092. }
  26093. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26094. int samplesPerBlockExpected)
  26095. {
  26096. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26097. sampleRate_, samplesPerBlockExpected);
  26098. setLatencySamples (effect->initialDelay);
  26099. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26100. vstHostTime.tempo = 120.0;
  26101. vstHostTime.timeSigNumerator = 4;
  26102. vstHostTime.timeSigDenominator = 4;
  26103. vstHostTime.sampleRate = sampleRate_;
  26104. vstHostTime.samplePos = 0;
  26105. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26106. initialise();
  26107. if (initialised)
  26108. {
  26109. wantsMidiMessages = wantsMidiMessages
  26110. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26111. if (wantsMidiMessages)
  26112. midiEventsToSend.ensureSize (256);
  26113. else
  26114. midiEventsToSend.freeEvents();
  26115. incomingMidi.clear();
  26116. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26117. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26118. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26119. if (! isPowerOn)
  26120. setPower (true);
  26121. // dodgy hack to force some plugins to initialise the sample rate..
  26122. if ((! hasEditor()) && getNumParameters() > 0)
  26123. {
  26124. const float old = getParameter (0);
  26125. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26126. setParameter (0, old);
  26127. }
  26128. dispatch (effStartProcess, 0, 0, 0, 0);
  26129. }
  26130. }
  26131. void VSTPluginInstance::releaseResources()
  26132. {
  26133. if (initialised)
  26134. {
  26135. dispatch (effStopProcess, 0, 0, 0, 0);
  26136. setPower (false);
  26137. }
  26138. tempBuffer.setSize (1, 1);
  26139. incomingMidi.clear();
  26140. midiEventsToSend.freeEvents();
  26141. channels.free();
  26142. }
  26143. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26144. MidiBuffer& midiMessages)
  26145. {
  26146. const int numSamples = buffer.getNumSamples();
  26147. if (initialised)
  26148. {
  26149. AudioPlayHead* playHead = getPlayHead();
  26150. if (playHead != 0)
  26151. {
  26152. AudioPlayHead::CurrentPositionInfo position;
  26153. playHead->getCurrentPosition (position);
  26154. vstHostTime.tempo = position.bpm;
  26155. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26156. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26157. vstHostTime.ppqPos = position.ppqPosition;
  26158. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26159. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26160. if (position.isPlaying)
  26161. vstHostTime.flags |= kVstTransportPlaying;
  26162. else
  26163. vstHostTime.flags &= ~kVstTransportPlaying;
  26164. }
  26165. #if JUCE_WIN32
  26166. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26167. #elif JUCE_LINUX
  26168. timeval micro;
  26169. gettimeofday (&micro, 0);
  26170. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26171. #elif JUCE_MAC
  26172. UnsignedWide micro;
  26173. Microseconds (&micro);
  26174. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26175. #endif
  26176. if (wantsMidiMessages)
  26177. {
  26178. midiEventsToSend.clear();
  26179. midiEventsToSend.ensureSize (1);
  26180. MidiBuffer::Iterator iter (midiMessages);
  26181. const uint8* midiData;
  26182. int numBytesOfMidiData, samplePosition;
  26183. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26184. {
  26185. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26186. jlimit (0, numSamples - 1, samplePosition));
  26187. }
  26188. try
  26189. {
  26190. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26191. }
  26192. catch (...)
  26193. {}
  26194. }
  26195. int i;
  26196. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26197. for (i = 0; i < maxChans; ++i)
  26198. channels[i] = buffer.getSampleData (i);
  26199. channels [maxChans] = 0;
  26200. _clearfp();
  26201. if ((effect->flags & effFlagsCanReplacing) != 0)
  26202. {
  26203. try
  26204. {
  26205. effect->processReplacing (effect, channels, channels, numSamples);
  26206. }
  26207. catch (...)
  26208. {}
  26209. }
  26210. else
  26211. {
  26212. tempBuffer.setSize (effect->numOutputs, numSamples);
  26213. tempBuffer.clear();
  26214. float* outs [64];
  26215. for (i = effect->numOutputs; --i >= 0;)
  26216. outs[i] = tempBuffer.getSampleData (i);
  26217. outs [effect->numOutputs] = 0;
  26218. try
  26219. {
  26220. effect->process (effect, channels, outs, numSamples);
  26221. }
  26222. catch (...)
  26223. {}
  26224. for (i = effect->numOutputs; --i >= 0;)
  26225. buffer.copyFrom (i, 0, outs[i], numSamples);
  26226. }
  26227. }
  26228. else
  26229. {
  26230. // Not initialised, so just bypass..
  26231. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26232. buffer.clear (i, 0, buffer.getNumSamples());
  26233. }
  26234. {
  26235. // copy any incoming midi..
  26236. const ScopedLock sl (midiInLock);
  26237. midiMessages = incomingMidi;
  26238. incomingMidi.clear();
  26239. }
  26240. }
  26241. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26242. {
  26243. if (events != 0)
  26244. {
  26245. const ScopedLock sl (midiInLock);
  26246. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26247. }
  26248. }
  26249. static Array <VSTPluginWindow*> activeVSTWindows;
  26250. class VSTPluginWindow : public AudioProcessorEditor,
  26251. #if ! JUCE_MAC
  26252. public ComponentMovementWatcher,
  26253. #endif
  26254. public Timer
  26255. {
  26256. public:
  26257. VSTPluginWindow (VSTPluginInstance& plugin_)
  26258. : AudioProcessorEditor (&plugin_),
  26259. #if ! JUCE_MAC
  26260. ComponentMovementWatcher (this),
  26261. #endif
  26262. plugin (plugin_),
  26263. isOpen (false),
  26264. wasShowing (false),
  26265. pluginRefusesToResize (false),
  26266. pluginWantsKeys (false),
  26267. alreadyInside (false),
  26268. recursiveResize (false)
  26269. {
  26270. #if JUCE_WIN32
  26271. sizeCheckCount = 0;
  26272. pluginHWND = 0;
  26273. #elif JUCE_LINUX
  26274. pluginWindow = None;
  26275. pluginProc = None;
  26276. #else
  26277. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26278. #endif
  26279. activeVSTWindows.add (this);
  26280. setSize (1, 1);
  26281. setOpaque (true);
  26282. setVisible (true);
  26283. }
  26284. ~VSTPluginWindow()
  26285. {
  26286. #if JUCE_MAC
  26287. innerWrapper = 0;
  26288. #else
  26289. closePluginWindow();
  26290. #endif
  26291. activeVSTWindows.removeValue (this);
  26292. plugin.editorBeingDeleted (this);
  26293. }
  26294. #if ! JUCE_MAC
  26295. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26296. {
  26297. if (recursiveResize)
  26298. return;
  26299. Component* const topComp = getTopLevelComponent();
  26300. if (topComp->getPeer() != 0)
  26301. {
  26302. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26303. recursiveResize = true;
  26304. #if JUCE_WIN32
  26305. if (pluginHWND != 0)
  26306. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26307. #elif JUCE_LINUX
  26308. if (pluginWindow != 0)
  26309. {
  26310. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26311. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26312. XMapRaised (display, pluginWindow);
  26313. }
  26314. #endif
  26315. recursiveResize = false;
  26316. }
  26317. }
  26318. void componentVisibilityChanged (Component&)
  26319. {
  26320. const bool isShowingNow = isShowing();
  26321. if (wasShowing != isShowingNow)
  26322. {
  26323. wasShowing = isShowingNow;
  26324. if (isShowingNow)
  26325. openPluginWindow();
  26326. else
  26327. closePluginWindow();
  26328. }
  26329. componentMovedOrResized (true, true);
  26330. }
  26331. void componentPeerChanged()
  26332. {
  26333. closePluginWindow();
  26334. openPluginWindow();
  26335. }
  26336. #endif
  26337. bool keyStateChanged (const bool)
  26338. {
  26339. return pluginWantsKeys;
  26340. }
  26341. bool keyPressed (const KeyPress&)
  26342. {
  26343. return pluginWantsKeys;
  26344. }
  26345. #if JUCE_MAC
  26346. void paint (Graphics& g)
  26347. {
  26348. g.fillAll (Colours::black);
  26349. }
  26350. #else
  26351. void paint (Graphics& g)
  26352. {
  26353. if (isOpen)
  26354. {
  26355. ComponentPeer* const peer = getPeer();
  26356. if (peer != 0)
  26357. {
  26358. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26359. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26360. #if JUCE_LINUX
  26361. if (pluginWindow != 0)
  26362. {
  26363. const Rectangle<int> clip (g.getClipBounds());
  26364. XEvent ev;
  26365. zerostruct (ev);
  26366. ev.xexpose.type = Expose;
  26367. ev.xexpose.display = display;
  26368. ev.xexpose.window = pluginWindow;
  26369. ev.xexpose.x = clip.getX();
  26370. ev.xexpose.y = clip.getY();
  26371. ev.xexpose.width = clip.getWidth();
  26372. ev.xexpose.height = clip.getHeight();
  26373. sendEventToChild (&ev);
  26374. }
  26375. #endif
  26376. }
  26377. }
  26378. else
  26379. {
  26380. g.fillAll (Colours::black);
  26381. }
  26382. }
  26383. #endif
  26384. void timerCallback()
  26385. {
  26386. #if JUCE_WIN32
  26387. if (--sizeCheckCount <= 0)
  26388. {
  26389. sizeCheckCount = 10;
  26390. checkPluginWindowSize();
  26391. }
  26392. #endif
  26393. try
  26394. {
  26395. static bool reentrant = false;
  26396. if (! reentrant)
  26397. {
  26398. reentrant = true;
  26399. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26400. reentrant = false;
  26401. }
  26402. }
  26403. catch (...)
  26404. {}
  26405. }
  26406. void mouseDown (const MouseEvent& e)
  26407. {
  26408. #if JUCE_LINUX
  26409. if (pluginWindow == 0)
  26410. return;
  26411. toFront (true);
  26412. XEvent ev;
  26413. zerostruct (ev);
  26414. ev.xbutton.display = display;
  26415. ev.xbutton.type = ButtonPress;
  26416. ev.xbutton.window = pluginWindow;
  26417. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26418. ev.xbutton.time = CurrentTime;
  26419. ev.xbutton.x = e.x;
  26420. ev.xbutton.y = e.y;
  26421. ev.xbutton.x_root = e.getScreenX();
  26422. ev.xbutton.y_root = e.getScreenY();
  26423. translateJuceToXButtonModifiers (e, ev);
  26424. sendEventToChild (&ev);
  26425. #elif JUCE_WIN32
  26426. (void) e;
  26427. toFront (true);
  26428. #endif
  26429. }
  26430. void broughtToFront()
  26431. {
  26432. activeVSTWindows.removeValue (this);
  26433. activeVSTWindows.add (this);
  26434. #if JUCE_MAC
  26435. dispatch (effEditTop, 0, 0, 0, 0);
  26436. #endif
  26437. }
  26438. juce_UseDebuggingNewOperator
  26439. private:
  26440. VSTPluginInstance& plugin;
  26441. bool isOpen, wasShowing, recursiveResize;
  26442. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26443. #if JUCE_WIN32
  26444. HWND pluginHWND;
  26445. void* originalWndProc;
  26446. int sizeCheckCount;
  26447. #elif JUCE_LINUX
  26448. Window pluginWindow;
  26449. EventProcPtr pluginProc;
  26450. #endif
  26451. #if JUCE_MAC
  26452. void openPluginWindow (WindowRef parentWindow)
  26453. {
  26454. if (isOpen || parentWindow == 0)
  26455. return;
  26456. isOpen = true;
  26457. ERect* rect = 0;
  26458. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26459. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26460. // do this before and after like in the steinberg example
  26461. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26462. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26463. // Install keyboard hooks
  26464. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26465. // double-check it's not too tiny
  26466. int w = 250, h = 150;
  26467. if (rect != 0)
  26468. {
  26469. w = rect->right - rect->left;
  26470. h = rect->bottom - rect->top;
  26471. if (w == 0 || h == 0)
  26472. {
  26473. w = 250;
  26474. h = 150;
  26475. }
  26476. }
  26477. w = jmax (w, 32);
  26478. h = jmax (h, 32);
  26479. setSize (w, h);
  26480. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26481. repaint();
  26482. }
  26483. #else
  26484. void openPluginWindow()
  26485. {
  26486. if (isOpen || getWindowHandle() == 0)
  26487. return;
  26488. log (T("Opening VST UI: ") + plugin.name);
  26489. isOpen = true;
  26490. ERect* rect = 0;
  26491. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26492. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26493. // do this before and after like in the steinberg example
  26494. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26495. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26496. // Install keyboard hooks
  26497. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26498. #if JUCE_WIN32
  26499. originalWndProc = 0;
  26500. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26501. if (pluginHWND == 0)
  26502. {
  26503. isOpen = false;
  26504. setSize (300, 150);
  26505. return;
  26506. }
  26507. #pragma warning (push)
  26508. #pragma warning (disable: 4244)
  26509. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26510. if (! pluginWantsKeys)
  26511. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26512. #pragma warning (pop)
  26513. int w, h;
  26514. RECT r;
  26515. GetWindowRect (pluginHWND, &r);
  26516. w = r.right - r.left;
  26517. h = r.bottom - r.top;
  26518. if (rect != 0)
  26519. {
  26520. const int rw = rect->right - rect->left;
  26521. const int rh = rect->bottom - rect->top;
  26522. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26523. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26524. {
  26525. // very dodgy logic to decide which size is right.
  26526. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26527. {
  26528. SetWindowPos (pluginHWND, 0,
  26529. 0, 0, rw, rh,
  26530. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26531. GetWindowRect (pluginHWND, &r);
  26532. w = r.right - r.left;
  26533. h = r.bottom - r.top;
  26534. pluginRefusesToResize = (w != rw) || (h != rh);
  26535. w = rw;
  26536. h = rh;
  26537. }
  26538. }
  26539. }
  26540. #elif JUCE_LINUX
  26541. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26542. if (pluginWindow != 0)
  26543. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26544. XInternAtom (display, "_XEventProc", False));
  26545. int w = 250, h = 150;
  26546. if (rect != 0)
  26547. {
  26548. w = rect->right - rect->left;
  26549. h = rect->bottom - rect->top;
  26550. if (w == 0 || h == 0)
  26551. {
  26552. w = 250;
  26553. h = 150;
  26554. }
  26555. }
  26556. if (pluginWindow != 0)
  26557. XMapRaised (display, pluginWindow);
  26558. #endif
  26559. // double-check it's not too tiny
  26560. w = jmax (w, 32);
  26561. h = jmax (h, 32);
  26562. setSize (w, h);
  26563. #if JUCE_WIN32
  26564. checkPluginWindowSize();
  26565. #endif
  26566. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26567. repaint();
  26568. }
  26569. #endif
  26570. #if ! JUCE_MAC
  26571. void closePluginWindow()
  26572. {
  26573. if (isOpen)
  26574. {
  26575. log (T("Closing VST UI: ") + plugin.getName());
  26576. isOpen = false;
  26577. dispatch (effEditClose, 0, 0, 0, 0);
  26578. #if JUCE_WIN32
  26579. #pragma warning (push)
  26580. #pragma warning (disable: 4244)
  26581. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26582. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26583. #pragma warning (pop)
  26584. stopTimer();
  26585. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26586. DestroyWindow (pluginHWND);
  26587. pluginHWND = 0;
  26588. #elif JUCE_LINUX
  26589. stopTimer();
  26590. pluginWindow = 0;
  26591. pluginProc = 0;
  26592. #endif
  26593. }
  26594. }
  26595. #endif
  26596. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26597. {
  26598. return plugin.dispatch (opcode, index, value, ptr, opt);
  26599. }
  26600. #if JUCE_WIN32
  26601. void checkPluginWindowSize() throw()
  26602. {
  26603. RECT r;
  26604. GetWindowRect (pluginHWND, &r);
  26605. const int w = r.right - r.left;
  26606. const int h = r.bottom - r.top;
  26607. if (isShowing() && w > 0 && h > 0
  26608. && (w != getWidth() || h != getHeight())
  26609. && ! pluginRefusesToResize)
  26610. {
  26611. setSize (w, h);
  26612. sizeCheckCount = 0;
  26613. }
  26614. }
  26615. // hooks to get keyboard events from VST windows..
  26616. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26617. {
  26618. for (int i = activeVSTWindows.size(); --i >= 0;)
  26619. {
  26620. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26621. if (w->pluginHWND == hW)
  26622. {
  26623. if (message == WM_CHAR
  26624. || message == WM_KEYDOWN
  26625. || message == WM_SYSKEYDOWN
  26626. || message == WM_KEYUP
  26627. || message == WM_SYSKEYUP
  26628. || message == WM_APPCOMMAND)
  26629. {
  26630. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26631. message, wParam, lParam);
  26632. }
  26633. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26634. (HWND) w->pluginHWND,
  26635. message,
  26636. wParam,
  26637. lParam);
  26638. }
  26639. }
  26640. return DefWindowProc (hW, message, wParam, lParam);
  26641. }
  26642. #endif
  26643. #if JUCE_LINUX
  26644. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26645. void sendEventToChild (XEvent* event)
  26646. {
  26647. if (pluginProc != 0)
  26648. {
  26649. // if the plugin publishes an event procedure, pass the event directly..
  26650. pluginProc (event);
  26651. }
  26652. else if (pluginWindow != 0)
  26653. {
  26654. // if the plugin has a window, then send the event to the window so that
  26655. // its message thread will pick it up..
  26656. XSendEvent (display, pluginWindow, False, 0L, event);
  26657. XFlush (display);
  26658. }
  26659. }
  26660. void mouseEnter (const MouseEvent& e)
  26661. {
  26662. if (pluginWindow != 0)
  26663. {
  26664. XEvent ev;
  26665. zerostruct (ev);
  26666. ev.xcrossing.display = display;
  26667. ev.xcrossing.type = EnterNotify;
  26668. ev.xcrossing.window = pluginWindow;
  26669. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26670. ev.xcrossing.time = CurrentTime;
  26671. ev.xcrossing.x = e.x;
  26672. ev.xcrossing.y = e.y;
  26673. ev.xcrossing.x_root = e.getScreenX();
  26674. ev.xcrossing.y_root = e.getScreenY();
  26675. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26676. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26677. translateJuceToXCrossingModifiers (e, ev);
  26678. sendEventToChild (&ev);
  26679. }
  26680. }
  26681. void mouseExit (const MouseEvent& e)
  26682. {
  26683. if (pluginWindow != 0)
  26684. {
  26685. XEvent ev;
  26686. zerostruct (ev);
  26687. ev.xcrossing.display = display;
  26688. ev.xcrossing.type = LeaveNotify;
  26689. ev.xcrossing.window = pluginWindow;
  26690. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26691. ev.xcrossing.time = CurrentTime;
  26692. ev.xcrossing.x = e.x;
  26693. ev.xcrossing.y = e.y;
  26694. ev.xcrossing.x_root = e.getScreenX();
  26695. ev.xcrossing.y_root = e.getScreenY();
  26696. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26697. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26698. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26699. translateJuceToXCrossingModifiers (e, ev);
  26700. sendEventToChild (&ev);
  26701. }
  26702. }
  26703. void mouseMove (const MouseEvent& e)
  26704. {
  26705. if (pluginWindow != 0)
  26706. {
  26707. XEvent ev;
  26708. zerostruct (ev);
  26709. ev.xmotion.display = display;
  26710. ev.xmotion.type = MotionNotify;
  26711. ev.xmotion.window = pluginWindow;
  26712. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26713. ev.xmotion.time = CurrentTime;
  26714. ev.xmotion.is_hint = NotifyNormal;
  26715. ev.xmotion.x = e.x;
  26716. ev.xmotion.y = e.y;
  26717. ev.xmotion.x_root = e.getScreenX();
  26718. ev.xmotion.y_root = e.getScreenY();
  26719. sendEventToChild (&ev);
  26720. }
  26721. }
  26722. void mouseDrag (const MouseEvent& e)
  26723. {
  26724. if (pluginWindow != 0)
  26725. {
  26726. XEvent ev;
  26727. zerostruct (ev);
  26728. ev.xmotion.display = display;
  26729. ev.xmotion.type = MotionNotify;
  26730. ev.xmotion.window = pluginWindow;
  26731. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26732. ev.xmotion.time = CurrentTime;
  26733. ev.xmotion.x = e.x ;
  26734. ev.xmotion.y = e.y;
  26735. ev.xmotion.x_root = e.getScreenX();
  26736. ev.xmotion.y_root = e.getScreenY();
  26737. ev.xmotion.is_hint = NotifyNormal;
  26738. translateJuceToXMotionModifiers (e, ev);
  26739. sendEventToChild (&ev);
  26740. }
  26741. }
  26742. void mouseUp (const MouseEvent& e)
  26743. {
  26744. if (pluginWindow != 0)
  26745. {
  26746. XEvent ev;
  26747. zerostruct (ev);
  26748. ev.xbutton.display = display;
  26749. ev.xbutton.type = ButtonRelease;
  26750. ev.xbutton.window = pluginWindow;
  26751. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26752. ev.xbutton.time = CurrentTime;
  26753. ev.xbutton.x = e.x;
  26754. ev.xbutton.y = e.y;
  26755. ev.xbutton.x_root = e.getScreenX();
  26756. ev.xbutton.y_root = e.getScreenY();
  26757. translateJuceToXButtonModifiers (e, ev);
  26758. sendEventToChild (&ev);
  26759. }
  26760. }
  26761. void mouseWheelMove (const MouseEvent& e,
  26762. float incrementX,
  26763. float incrementY)
  26764. {
  26765. if (pluginWindow != 0)
  26766. {
  26767. XEvent ev;
  26768. zerostruct (ev);
  26769. ev.xbutton.display = display;
  26770. ev.xbutton.type = ButtonPress;
  26771. ev.xbutton.window = pluginWindow;
  26772. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26773. ev.xbutton.time = CurrentTime;
  26774. ev.xbutton.x = e.x;
  26775. ev.xbutton.y = e.y;
  26776. ev.xbutton.x_root = e.getScreenX();
  26777. ev.xbutton.y_root = e.getScreenY();
  26778. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26779. sendEventToChild (&ev);
  26780. // TODO - put a usleep here ?
  26781. ev.xbutton.type = ButtonRelease;
  26782. sendEventToChild (&ev);
  26783. }
  26784. }
  26785. #endif
  26786. #if JUCE_MAC
  26787. #if ! JUCE_SUPPORT_CARBON
  26788. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26789. #endif
  26790. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26791. {
  26792. public:
  26793. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26794. : owner (owner_),
  26795. alreadyInside (false)
  26796. {
  26797. }
  26798. ~InnerWrapperComponent()
  26799. {
  26800. deleteWindow();
  26801. }
  26802. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26803. {
  26804. owner->openPluginWindow (windowRef);
  26805. return 0;
  26806. }
  26807. void removeView (HIViewRef)
  26808. {
  26809. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26810. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26811. }
  26812. bool getEmbeddedViewSize (int& w, int& h)
  26813. {
  26814. ERect* rect = 0;
  26815. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26816. w = rect->right - rect->left;
  26817. h = rect->bottom - rect->top;
  26818. return true;
  26819. }
  26820. void mouseDown (int x, int y)
  26821. {
  26822. if (! alreadyInside)
  26823. {
  26824. alreadyInside = true;
  26825. getTopLevelComponent()->toFront (true);
  26826. owner->dispatch (effEditMouse, x, y, 0, 0);
  26827. alreadyInside = false;
  26828. }
  26829. else
  26830. {
  26831. PostEvent (::mouseDown, 0);
  26832. }
  26833. }
  26834. void paint()
  26835. {
  26836. ComponentPeer* const peer = getPeer();
  26837. if (peer != 0)
  26838. {
  26839. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26840. ERect r;
  26841. r.left = pos.getX();
  26842. r.right = r.left + getWidth();
  26843. r.top = pos.getY();
  26844. r.bottom = r.top + getHeight();
  26845. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26846. }
  26847. }
  26848. private:
  26849. VSTPluginWindow* const owner;
  26850. bool alreadyInside;
  26851. };
  26852. friend class InnerWrapperComponent;
  26853. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26854. void resized()
  26855. {
  26856. innerWrapper->setSize (getWidth(), getHeight());
  26857. }
  26858. #endif
  26859. };
  26860. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26861. {
  26862. if (hasEditor())
  26863. return new VSTPluginWindow (*this);
  26864. return 0;
  26865. }
  26866. void VSTPluginInstance::handleAsyncUpdate()
  26867. {
  26868. // indicates that something about the plugin has changed..
  26869. updateHostDisplay();
  26870. }
  26871. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26872. {
  26873. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26874. {
  26875. changeProgramName (getCurrentProgram(), prog->prgName);
  26876. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26877. setParameter (i, vst_swapFloat (prog->params[i]));
  26878. return true;
  26879. }
  26880. return false;
  26881. }
  26882. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26883. const int dataSize)
  26884. {
  26885. if (dataSize < 28)
  26886. return false;
  26887. const fxSet* const set = (const fxSet*) data;
  26888. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26889. || vst_swap (set->version) > fxbVersionNum)
  26890. return false;
  26891. if (vst_swap (set->fxMagic) == 'FxBk')
  26892. {
  26893. // bank of programs
  26894. if (vst_swap (set->numPrograms) >= 0)
  26895. {
  26896. const int oldProg = getCurrentProgram();
  26897. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26898. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26899. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26900. {
  26901. if (i != oldProg)
  26902. {
  26903. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26904. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26905. return false;
  26906. if (vst_swap (set->numPrograms) > 0)
  26907. setCurrentProgram (i);
  26908. if (! restoreProgramSettings (prog))
  26909. return false;
  26910. }
  26911. }
  26912. if (vst_swap (set->numPrograms) > 0)
  26913. setCurrentProgram (oldProg);
  26914. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26915. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26916. return false;
  26917. if (! restoreProgramSettings (prog))
  26918. return false;
  26919. }
  26920. }
  26921. else if (vst_swap (set->fxMagic) == 'FxCk')
  26922. {
  26923. // single program
  26924. const fxProgram* const prog = (const fxProgram*) data;
  26925. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26926. return false;
  26927. changeProgramName (getCurrentProgram(), prog->prgName);
  26928. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26929. setParameter (i, vst_swapFloat (prog->params[i]));
  26930. }
  26931. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26932. {
  26933. // non-preset chunk
  26934. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26935. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26936. return false;
  26937. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26938. }
  26939. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26940. {
  26941. // preset chunk
  26942. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26943. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26944. return false;
  26945. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26946. changeProgramName (getCurrentProgram(), cset->name);
  26947. }
  26948. else
  26949. {
  26950. return false;
  26951. }
  26952. return true;
  26953. }
  26954. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26955. {
  26956. const int numParams = getNumParameters();
  26957. prog->chunkMagic = vst_swap ('CcnK');
  26958. prog->byteSize = 0;
  26959. prog->fxMagic = vst_swap ('FxCk');
  26960. prog->version = vst_swap (fxbVersionNum);
  26961. prog->fxID = vst_swap (getUID());
  26962. prog->fxVersion = vst_swap (getVersionNumber());
  26963. prog->numParams = vst_swap (numParams);
  26964. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  26965. for (int i = 0; i < numParams; ++i)
  26966. prog->params[i] = vst_swapFloat (getParameter (i));
  26967. }
  26968. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26969. {
  26970. const int numPrograms = getNumPrograms();
  26971. const int numParams = getNumParameters();
  26972. if (usesChunks())
  26973. {
  26974. if (isFXB)
  26975. {
  26976. MemoryBlock chunk;
  26977. getChunkData (chunk, false, maxSizeMB);
  26978. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  26979. dest.setSize (totalLen, true);
  26980. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  26981. set->chunkMagic = vst_swap ('CcnK');
  26982. set->byteSize = 0;
  26983. set->fxMagic = vst_swap ('FBCh');
  26984. set->version = vst_swap (fxbVersionNum);
  26985. set->fxID = vst_swap (getUID());
  26986. set->fxVersion = vst_swap (getVersionNumber());
  26987. set->numPrograms = vst_swap (numPrograms);
  26988. set->chunkSize = vst_swap ((long) chunk.getSize());
  26989. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26990. }
  26991. else
  26992. {
  26993. MemoryBlock chunk;
  26994. getChunkData (chunk, true, maxSizeMB);
  26995. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  26996. dest.setSize (totalLen, true);
  26997. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  26998. set->chunkMagic = vst_swap ('CcnK');
  26999. set->byteSize = 0;
  27000. set->fxMagic = vst_swap ('FPCh');
  27001. set->version = vst_swap (fxbVersionNum);
  27002. set->fxID = vst_swap (getUID());
  27003. set->fxVersion = vst_swap (getVersionNumber());
  27004. set->numPrograms = vst_swap (numPrograms);
  27005. set->chunkSize = vst_swap ((long) chunk.getSize());
  27006. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  27007. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27008. }
  27009. }
  27010. else
  27011. {
  27012. if (isFXB)
  27013. {
  27014. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27015. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  27016. dest.setSize (len, true);
  27017. fxSet* const set = (fxSet*) dest.getData();
  27018. set->chunkMagic = vst_swap ('CcnK');
  27019. set->byteSize = 0;
  27020. set->fxMagic = vst_swap ('FxBk');
  27021. set->version = vst_swap (fxbVersionNum);
  27022. set->fxID = vst_swap (getUID());
  27023. set->fxVersion = vst_swap (getVersionNumber());
  27024. set->numPrograms = vst_swap (numPrograms);
  27025. const int oldProgram = getCurrentProgram();
  27026. MemoryBlock oldSettings;
  27027. createTempParameterStore (oldSettings);
  27028. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  27029. for (int i = 0; i < numPrograms; ++i)
  27030. {
  27031. if (i != oldProgram)
  27032. {
  27033. setCurrentProgram (i);
  27034. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  27035. }
  27036. }
  27037. setCurrentProgram (oldProgram);
  27038. restoreFromTempParameterStore (oldSettings);
  27039. }
  27040. else
  27041. {
  27042. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27043. dest.setSize (totalLen, true);
  27044. setParamsInProgramBlock ((fxProgram*) dest.getData());
  27045. }
  27046. }
  27047. return true;
  27048. }
  27049. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  27050. {
  27051. if (usesChunks())
  27052. {
  27053. void* data = 0;
  27054. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  27055. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  27056. {
  27057. mb.setSize (bytes);
  27058. mb.copyFrom (data, 0, bytes);
  27059. }
  27060. }
  27061. }
  27062. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  27063. {
  27064. if (size > 0 && usesChunks())
  27065. {
  27066. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  27067. if (! isPreset)
  27068. updateStoredProgramNames();
  27069. }
  27070. }
  27071. void VSTPluginInstance::timerCallback()
  27072. {
  27073. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  27074. stopTimer();
  27075. }
  27076. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  27077. {
  27078. const ScopedLock sl (lock);
  27079. ++insideVSTCallback;
  27080. int result = 0;
  27081. try
  27082. {
  27083. if (effect != 0)
  27084. {
  27085. #if JUCE_MAC
  27086. if (module->resFileId != 0)
  27087. UseResFile (module->resFileId);
  27088. CGrafPtr oldPort;
  27089. if (getActiveEditor() != 0)
  27090. {
  27091. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  27092. GetPort (&oldPort);
  27093. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27094. SetOrigin (-pos.getX(), -pos.getY());
  27095. }
  27096. #endif
  27097. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27098. #if JUCE_MAC
  27099. if (getActiveEditor() != 0)
  27100. SetPort (oldPort);
  27101. module->resFileId = CurResFile();
  27102. #endif
  27103. --insideVSTCallback;
  27104. return result;
  27105. }
  27106. }
  27107. catch (...)
  27108. {
  27109. }
  27110. --insideVSTCallback;
  27111. return result;
  27112. }
  27113. // handles non plugin-specific callbacks..
  27114. static const int defaultVSTSampleRateValue = 16384;
  27115. static const int defaultVSTBlockSizeValue = 512;
  27116. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27117. {
  27118. (void) index;
  27119. (void) value;
  27120. (void) opt;
  27121. switch (opcode)
  27122. {
  27123. case audioMasterCanDo:
  27124. {
  27125. static const char* canDos[] = { "supplyIdle",
  27126. "sendVstEvents",
  27127. "sendVstMidiEvent",
  27128. "sendVstTimeInfo",
  27129. "receiveVstEvents",
  27130. "receiveVstMidiEvent",
  27131. "supportShell",
  27132. "shellCategory" };
  27133. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27134. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27135. return 1;
  27136. return 0;
  27137. }
  27138. case audioMasterVersion:
  27139. return 0x2400;
  27140. case audioMasterCurrentId:
  27141. return shellUIDToCreate;
  27142. case audioMasterGetNumAutomatableParameters:
  27143. return 0;
  27144. case audioMasterGetAutomationState:
  27145. return 1;
  27146. case audioMasterGetVendorVersion:
  27147. return 0x0101;
  27148. case audioMasterGetVendorString:
  27149. case audioMasterGetProductString:
  27150. {
  27151. String hostName ("Juce VST Host");
  27152. if (JUCEApplication::getInstance() != 0)
  27153. hostName = JUCEApplication::getInstance()->getApplicationName();
  27154. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27155. }
  27156. break;
  27157. case audioMasterGetSampleRate:
  27158. return (VstIntPtr) defaultVSTSampleRateValue;
  27159. case audioMasterGetBlockSize:
  27160. return (VstIntPtr) defaultVSTBlockSizeValue;
  27161. case audioMasterSetOutputSampleRate:
  27162. return 0;
  27163. default:
  27164. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27165. break;
  27166. }
  27167. return 0;
  27168. }
  27169. // handles callbacks for a specific plugin
  27170. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27171. {
  27172. switch (opcode)
  27173. {
  27174. case audioMasterAutomate:
  27175. sendParamChangeMessageToListeners (index, opt);
  27176. break;
  27177. case audioMasterProcessEvents:
  27178. handleMidiFromPlugin ((const VstEvents*) ptr);
  27179. break;
  27180. case audioMasterGetTime:
  27181. #ifdef _MSC_VER
  27182. #pragma warning (push)
  27183. #pragma warning (disable: 4311)
  27184. #endif
  27185. return (VstIntPtr) &vstHostTime;
  27186. #ifdef _MSC_VER
  27187. #pragma warning (pop)
  27188. #endif
  27189. break;
  27190. case audioMasterIdle:
  27191. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27192. {
  27193. ++insideVSTCallback;
  27194. #if JUCE_MAC
  27195. if (getActiveEditor() != 0)
  27196. dispatch (effEditIdle, 0, 0, 0, 0);
  27197. #endif
  27198. juce_callAnyTimersSynchronously();
  27199. handleUpdateNowIfNeeded();
  27200. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27201. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27202. --insideVSTCallback;
  27203. }
  27204. break;
  27205. case audioMasterUpdateDisplay:
  27206. triggerAsyncUpdate();
  27207. break;
  27208. case audioMasterTempoAt:
  27209. // returns (10000 * bpm)
  27210. break;
  27211. case audioMasterNeedIdle:
  27212. startTimer (50);
  27213. break;
  27214. case audioMasterSizeWindow:
  27215. if (getActiveEditor() != 0)
  27216. getActiveEditor()->setSize (index, value);
  27217. return 1;
  27218. case audioMasterGetSampleRate:
  27219. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27220. case audioMasterGetBlockSize:
  27221. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27222. case audioMasterWantMidi:
  27223. wantsMidiMessages = true;
  27224. break;
  27225. case audioMasterGetDirectory:
  27226. #if JUCE_MAC
  27227. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27228. #else
  27229. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27230. #endif
  27231. case audioMasterGetAutomationState:
  27232. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27233. break;
  27234. // none of these are handled (yet)..
  27235. case audioMasterBeginEdit:
  27236. case audioMasterEndEdit:
  27237. case audioMasterSetTime:
  27238. case audioMasterPinConnected:
  27239. case audioMasterGetParameterQuantization:
  27240. case audioMasterIOChanged:
  27241. case audioMasterGetInputLatency:
  27242. case audioMasterGetOutputLatency:
  27243. case audioMasterGetPreviousPlug:
  27244. case audioMasterGetNextPlug:
  27245. case audioMasterWillReplaceOrAccumulate:
  27246. case audioMasterGetCurrentProcessLevel:
  27247. case audioMasterOfflineStart:
  27248. case audioMasterOfflineRead:
  27249. case audioMasterOfflineWrite:
  27250. case audioMasterOfflineGetCurrentPass:
  27251. case audioMasterOfflineGetCurrentMetaPass:
  27252. case audioMasterVendorSpecific:
  27253. case audioMasterSetIcon:
  27254. case audioMasterGetLanguage:
  27255. case audioMasterOpenWindow:
  27256. case audioMasterCloseWindow:
  27257. break;
  27258. default:
  27259. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27260. }
  27261. return 0;
  27262. }
  27263. // entry point for all callbacks from the plugin
  27264. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27265. {
  27266. try
  27267. {
  27268. if (effect != 0 && effect->resvd2 != 0)
  27269. {
  27270. return ((VSTPluginInstance*)(effect->resvd2))
  27271. ->handleCallback (opcode, index, value, ptr, opt);
  27272. }
  27273. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27274. }
  27275. catch (...)
  27276. {
  27277. return 0;
  27278. }
  27279. }
  27280. const String VSTPluginInstance::getVersion() const throw()
  27281. {
  27282. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27283. String s;
  27284. if (v == 0 || v == -1)
  27285. v = getVersionNumber();
  27286. if (v != 0)
  27287. {
  27288. int versionBits[4];
  27289. int n = 0;
  27290. while (v != 0)
  27291. {
  27292. versionBits [n++] = (v & 0xff);
  27293. v >>= 8;
  27294. }
  27295. s << 'V';
  27296. while (n > 0)
  27297. {
  27298. s << versionBits [--n];
  27299. if (n > 0)
  27300. s << '.';
  27301. }
  27302. }
  27303. return s;
  27304. }
  27305. int VSTPluginInstance::getUID() const throw()
  27306. {
  27307. int uid = effect != 0 ? effect->uniqueID : 0;
  27308. if (uid == 0)
  27309. uid = module->file.hashCode();
  27310. return uid;
  27311. }
  27312. const String VSTPluginInstance::getCategory() const throw()
  27313. {
  27314. const char* result = 0;
  27315. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27316. {
  27317. case kPlugCategEffect:
  27318. result = "Effect";
  27319. break;
  27320. case kPlugCategSynth:
  27321. result = "Synth";
  27322. break;
  27323. case kPlugCategAnalysis:
  27324. result = "Anaylsis";
  27325. break;
  27326. case kPlugCategMastering:
  27327. result = "Mastering";
  27328. break;
  27329. case kPlugCategSpacializer:
  27330. result = "Spacial";
  27331. break;
  27332. case kPlugCategRoomFx:
  27333. result = "Reverb";
  27334. break;
  27335. case kPlugSurroundFx:
  27336. result = "Surround";
  27337. break;
  27338. case kPlugCategRestoration:
  27339. result = "Restoration";
  27340. break;
  27341. case kPlugCategGenerator:
  27342. result = "Tone generation";
  27343. break;
  27344. default:
  27345. break;
  27346. }
  27347. return result;
  27348. }
  27349. float VSTPluginInstance::getParameter (int index)
  27350. {
  27351. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27352. {
  27353. try
  27354. {
  27355. const ScopedLock sl (lock);
  27356. return effect->getParameter (effect, index);
  27357. }
  27358. catch (...)
  27359. {
  27360. }
  27361. }
  27362. return 0.0f;
  27363. }
  27364. void VSTPluginInstance::setParameter (int index, float newValue)
  27365. {
  27366. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27367. {
  27368. try
  27369. {
  27370. const ScopedLock sl (lock);
  27371. if (effect->getParameter (effect, index) != newValue)
  27372. effect->setParameter (effect, index, newValue);
  27373. }
  27374. catch (...)
  27375. {
  27376. }
  27377. }
  27378. }
  27379. const String VSTPluginInstance::getParameterName (int index)
  27380. {
  27381. if (effect != 0)
  27382. {
  27383. jassert (index >= 0 && index < effect->numParams);
  27384. char nm [256];
  27385. zerostruct (nm);
  27386. dispatch (effGetParamName, index, 0, nm, 0);
  27387. return String (nm).trim();
  27388. }
  27389. return String::empty;
  27390. }
  27391. const String VSTPluginInstance::getParameterLabel (int index) const
  27392. {
  27393. if (effect != 0)
  27394. {
  27395. jassert (index >= 0 && index < effect->numParams);
  27396. char nm [256];
  27397. zerostruct (nm);
  27398. dispatch (effGetParamLabel, index, 0, nm, 0);
  27399. return String (nm).trim();
  27400. }
  27401. return String::empty;
  27402. }
  27403. const String VSTPluginInstance::getParameterText (int index)
  27404. {
  27405. if (effect != 0)
  27406. {
  27407. jassert (index >= 0 && index < effect->numParams);
  27408. char nm [256];
  27409. zerostruct (nm);
  27410. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27411. return String (nm).trim();
  27412. }
  27413. return String::empty;
  27414. }
  27415. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27416. {
  27417. if (effect != 0)
  27418. {
  27419. jassert (index >= 0 && index < effect->numParams);
  27420. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27421. }
  27422. return false;
  27423. }
  27424. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27425. {
  27426. dest.setSize (64 + 4 * getNumParameters());
  27427. dest.fillWith (0);
  27428. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27429. float* const p = (float*) (((char*) dest.getData()) + 64);
  27430. for (int i = 0; i < getNumParameters(); ++i)
  27431. p[i] = getParameter(i);
  27432. }
  27433. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27434. {
  27435. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27436. float* p = (float*) (((char*) m.getData()) + 64);
  27437. for (int i = 0; i < getNumParameters(); ++i)
  27438. setParameter (i, p[i]);
  27439. }
  27440. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27441. {
  27442. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27443. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27444. }
  27445. const String VSTPluginInstance::getProgramName (int index)
  27446. {
  27447. if (index == getCurrentProgram())
  27448. {
  27449. return getCurrentProgramName();
  27450. }
  27451. else if (effect != 0)
  27452. {
  27453. char nm [256];
  27454. zerostruct (nm);
  27455. if (dispatch (effGetProgramNameIndexed,
  27456. jlimit (0, getNumPrograms(), index),
  27457. -1, nm, 0) != 0)
  27458. {
  27459. return String (nm).trim();
  27460. }
  27461. }
  27462. return programNames [index];
  27463. }
  27464. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27465. {
  27466. if (index == getCurrentProgram())
  27467. {
  27468. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27469. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27470. }
  27471. else
  27472. {
  27473. jassertfalse // xxx not implemented!
  27474. }
  27475. }
  27476. void VSTPluginInstance::updateStoredProgramNames()
  27477. {
  27478. if (effect != 0 && getNumPrograms() > 0)
  27479. {
  27480. char nm [256];
  27481. zerostruct (nm);
  27482. // only do this if the plugin can't use indexed names..
  27483. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27484. {
  27485. const int oldProgram = getCurrentProgram();
  27486. MemoryBlock oldSettings;
  27487. createTempParameterStore (oldSettings);
  27488. for (int i = 0; i < getNumPrograms(); ++i)
  27489. {
  27490. setCurrentProgram (i);
  27491. getCurrentProgramName(); // (this updates the list)
  27492. }
  27493. setCurrentProgram (oldProgram);
  27494. restoreFromTempParameterStore (oldSettings);
  27495. }
  27496. }
  27497. }
  27498. const String VSTPluginInstance::getCurrentProgramName()
  27499. {
  27500. if (effect != 0)
  27501. {
  27502. char nm [256];
  27503. zerostruct (nm);
  27504. dispatch (effGetProgramName, 0, 0, nm, 0);
  27505. const int index = getCurrentProgram();
  27506. if (programNames[index].isEmpty())
  27507. {
  27508. while (programNames.size() < index)
  27509. programNames.add (String::empty);
  27510. programNames.set (index, String (nm).trim());
  27511. }
  27512. return String (nm).trim();
  27513. }
  27514. return String::empty;
  27515. }
  27516. const String VSTPluginInstance::getInputChannelName (const int index) const
  27517. {
  27518. if (index >= 0 && index < getNumInputChannels())
  27519. {
  27520. VstPinProperties pinProps;
  27521. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27522. return String (pinProps.label, sizeof (pinProps.label));
  27523. }
  27524. return String::empty;
  27525. }
  27526. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27527. {
  27528. if (index < 0 || index >= getNumInputChannels())
  27529. return false;
  27530. VstPinProperties pinProps;
  27531. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27532. return (pinProps.flags & kVstPinIsStereo) != 0;
  27533. return true;
  27534. }
  27535. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27536. {
  27537. if (index >= 0 && index < getNumOutputChannels())
  27538. {
  27539. VstPinProperties pinProps;
  27540. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27541. return String (pinProps.label, sizeof (pinProps.label));
  27542. }
  27543. return String::empty;
  27544. }
  27545. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27546. {
  27547. if (index < 0 || index >= getNumOutputChannels())
  27548. return false;
  27549. VstPinProperties pinProps;
  27550. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27551. return (pinProps.flags & kVstPinIsStereo) != 0;
  27552. return true;
  27553. }
  27554. void VSTPluginInstance::setPower (const bool on)
  27555. {
  27556. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27557. isPowerOn = on;
  27558. }
  27559. const int defaultMaxSizeMB = 64;
  27560. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27561. {
  27562. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27563. }
  27564. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27565. {
  27566. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27567. }
  27568. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27569. {
  27570. loadFromFXBFile (data, sizeInBytes);
  27571. }
  27572. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27573. {
  27574. loadFromFXBFile (data, sizeInBytes);
  27575. }
  27576. VSTPluginFormat::VSTPluginFormat()
  27577. {
  27578. }
  27579. VSTPluginFormat::~VSTPluginFormat()
  27580. {
  27581. }
  27582. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27583. const String& fileOrIdentifier)
  27584. {
  27585. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27586. return;
  27587. PluginDescription desc;
  27588. desc.fileOrIdentifier = fileOrIdentifier;
  27589. desc.uid = 0;
  27590. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27591. if (instance == 0)
  27592. return;
  27593. try
  27594. {
  27595. #if JUCE_MAC
  27596. if (instance->module->resFileId != 0)
  27597. UseResFile (instance->module->resFileId);
  27598. #endif
  27599. instance->fillInPluginDescription (desc);
  27600. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27601. if (category != kPlugCategShell)
  27602. {
  27603. // Normal plugin...
  27604. results.add (new PluginDescription (desc));
  27605. ++insideVSTCallback;
  27606. instance->dispatch (effOpen, 0, 0, 0, 0);
  27607. --insideVSTCallback;
  27608. }
  27609. else
  27610. {
  27611. // It's a shell plugin, so iterate all the subtypes...
  27612. char shellEffectName [64];
  27613. for (;;)
  27614. {
  27615. zerostruct (shellEffectName);
  27616. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27617. if (uid == 0)
  27618. {
  27619. break;
  27620. }
  27621. else
  27622. {
  27623. desc.uid = uid;
  27624. desc.name = shellEffectName;
  27625. bool alreadyThere = false;
  27626. for (int i = results.size(); --i >= 0;)
  27627. {
  27628. PluginDescription* const d = results.getUnchecked(i);
  27629. if (d->isDuplicateOf (desc))
  27630. {
  27631. alreadyThere = true;
  27632. break;
  27633. }
  27634. }
  27635. if (! alreadyThere)
  27636. results.add (new PluginDescription (desc));
  27637. }
  27638. }
  27639. }
  27640. }
  27641. catch (...)
  27642. {
  27643. // crashed while loading...
  27644. }
  27645. }
  27646. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27647. {
  27648. ScopedPointer <VSTPluginInstance> result;
  27649. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27650. {
  27651. File file (desc.fileOrIdentifier);
  27652. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27653. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27654. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27655. if (module != 0)
  27656. {
  27657. shellUIDToCreate = desc.uid;
  27658. result = new VSTPluginInstance (module);
  27659. if (result->effect != 0)
  27660. {
  27661. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27662. result->initialise();
  27663. }
  27664. else
  27665. {
  27666. result = 0;
  27667. }
  27668. }
  27669. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27670. }
  27671. return result.release();
  27672. }
  27673. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27674. {
  27675. const File f (fileOrIdentifier);
  27676. #if JUCE_MAC
  27677. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27678. return true;
  27679. #if JUCE_PPC
  27680. FSRef fileRef;
  27681. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27682. {
  27683. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27684. if (resFileId != -1)
  27685. {
  27686. const int numEffects = Count1Resources ('aEff');
  27687. CloseResFile (resFileId);
  27688. if (numEffects > 0)
  27689. return true;
  27690. }
  27691. }
  27692. #endif
  27693. return false;
  27694. #elif JUCE_WIN32
  27695. return f.existsAsFile()
  27696. && f.hasFileExtension (T(".dll"));
  27697. #elif JUCE_LINUX
  27698. return f.existsAsFile()
  27699. && f.hasFileExtension (T(".so"));
  27700. #endif
  27701. }
  27702. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27703. {
  27704. return fileOrIdentifier;
  27705. }
  27706. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27707. {
  27708. return File (desc.fileOrIdentifier).exists();
  27709. }
  27710. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27711. {
  27712. StringArray results;
  27713. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27714. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27715. return results;
  27716. }
  27717. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27718. {
  27719. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27720. // .component or .vst directories.
  27721. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27722. while (iter.next())
  27723. {
  27724. const File f (iter.getFile());
  27725. bool isPlugin = false;
  27726. if (fileMightContainThisPluginType (f.getFullPathName()))
  27727. {
  27728. isPlugin = true;
  27729. results.add (f.getFullPathName());
  27730. }
  27731. if (recursive && (! isPlugin) && f.isDirectory())
  27732. recursiveFileSearch (results, f, true);
  27733. }
  27734. }
  27735. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27736. {
  27737. #if JUCE_MAC
  27738. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27739. #elif JUCE_WIN32
  27740. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27741. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27742. #elif JUCE_LINUX
  27743. return FileSearchPath ("/usr/lib/vst");
  27744. #endif
  27745. }
  27746. END_JUCE_NAMESPACE
  27747. #endif
  27748. #undef log
  27749. #endif
  27750. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27751. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27752. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27753. BEGIN_JUCE_NAMESPACE
  27754. AudioProcessor::AudioProcessor()
  27755. : playHead (0),
  27756. activeEditor (0),
  27757. sampleRate (0),
  27758. blockSize (0),
  27759. numInputChannels (0),
  27760. numOutputChannels (0),
  27761. latencySamples (0),
  27762. suspended (false),
  27763. nonRealtime (false)
  27764. {
  27765. }
  27766. AudioProcessor::~AudioProcessor()
  27767. {
  27768. // ooh, nasty - the editor should have been deleted before the filter
  27769. // that it refers to is deleted..
  27770. jassert (activeEditor == 0);
  27771. #ifdef JUCE_DEBUG
  27772. // This will fail if you've called beginParameterChangeGesture() for one
  27773. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27774. jassert (changingParams.countNumberOfSetBits() == 0);
  27775. #endif
  27776. }
  27777. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27778. {
  27779. playHead = newPlayHead;
  27780. }
  27781. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27782. {
  27783. const ScopedLock sl (listenerLock);
  27784. listeners.addIfNotAlreadyThere (newListener);
  27785. }
  27786. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27787. {
  27788. const ScopedLock sl (listenerLock);
  27789. listeners.removeValue (listenerToRemove);
  27790. }
  27791. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27792. const int numOuts,
  27793. const double sampleRate_,
  27794. const int blockSize_) throw()
  27795. {
  27796. numInputChannels = numIns;
  27797. numOutputChannels = numOuts;
  27798. sampleRate = sampleRate_;
  27799. blockSize = blockSize_;
  27800. }
  27801. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27802. {
  27803. nonRealtime = nonRealtime_;
  27804. }
  27805. void AudioProcessor::setLatencySamples (const int newLatency)
  27806. {
  27807. if (latencySamples != newLatency)
  27808. {
  27809. latencySamples = newLatency;
  27810. updateHostDisplay();
  27811. }
  27812. }
  27813. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27814. const float newValue)
  27815. {
  27816. setParameter (parameterIndex, newValue);
  27817. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27818. }
  27819. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27820. {
  27821. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27822. for (int i = listeners.size(); --i >= 0;)
  27823. {
  27824. AudioProcessorListener* l;
  27825. {
  27826. const ScopedLock sl (listenerLock);
  27827. l = (AudioProcessorListener*) listeners [i];
  27828. }
  27829. if (l != 0)
  27830. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27831. }
  27832. }
  27833. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27834. {
  27835. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27836. #ifdef JUCE_DEBUG
  27837. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27838. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27839. jassert (! changingParams [parameterIndex]);
  27840. changingParams.setBit (parameterIndex);
  27841. #endif
  27842. for (int i = listeners.size(); --i >= 0;)
  27843. {
  27844. AudioProcessorListener* l;
  27845. {
  27846. const ScopedLock sl (listenerLock);
  27847. l = (AudioProcessorListener*) listeners [i];
  27848. }
  27849. if (l != 0)
  27850. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27851. }
  27852. }
  27853. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27854. {
  27855. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27856. #ifdef JUCE_DEBUG
  27857. // This means you've called endParameterChangeGesture without having previously called
  27858. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27859. // calls matched correctly.
  27860. jassert (changingParams [parameterIndex]);
  27861. changingParams.clearBit (parameterIndex);
  27862. #endif
  27863. for (int i = listeners.size(); --i >= 0;)
  27864. {
  27865. AudioProcessorListener* l;
  27866. {
  27867. const ScopedLock sl (listenerLock);
  27868. l = (AudioProcessorListener*) listeners [i];
  27869. }
  27870. if (l != 0)
  27871. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27872. }
  27873. }
  27874. void AudioProcessor::updateHostDisplay()
  27875. {
  27876. for (int i = listeners.size(); --i >= 0;)
  27877. {
  27878. AudioProcessorListener* l;
  27879. {
  27880. const ScopedLock sl (listenerLock);
  27881. l = (AudioProcessorListener*) listeners [i];
  27882. }
  27883. if (l != 0)
  27884. l->audioProcessorChanged (this);
  27885. }
  27886. }
  27887. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27888. {
  27889. return true;
  27890. }
  27891. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27892. {
  27893. return false;
  27894. }
  27895. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27896. {
  27897. const ScopedLock sl (callbackLock);
  27898. suspended = shouldBeSuspended;
  27899. }
  27900. void AudioProcessor::reset()
  27901. {
  27902. }
  27903. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27904. {
  27905. const ScopedLock sl (callbackLock);
  27906. jassert (activeEditor == editor);
  27907. if (activeEditor == editor)
  27908. activeEditor = 0;
  27909. }
  27910. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27911. {
  27912. if (activeEditor != 0)
  27913. return activeEditor;
  27914. AudioProcessorEditor* const ed = createEditor();
  27915. if (ed != 0)
  27916. {
  27917. // you must give your editor comp a size before returning it..
  27918. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27919. const ScopedLock sl (callbackLock);
  27920. activeEditor = ed;
  27921. }
  27922. return ed;
  27923. }
  27924. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27925. {
  27926. getStateInformation (destData);
  27927. }
  27928. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27929. {
  27930. setStateInformation (data, sizeInBytes);
  27931. }
  27932. // magic number to identify memory blocks that we've stored as XML
  27933. const uint32 magicXmlNumber = 0x21324356;
  27934. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27935. JUCE_NAMESPACE::MemoryBlock& destData)
  27936. {
  27937. const String xmlString (xml.createDocument (String::empty, true, false));
  27938. const int stringLength = xmlString.getNumBytesAsUTF8();
  27939. destData.setSize (stringLength + 10);
  27940. char* const d = (char*) destData.getData();
  27941. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27942. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27943. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  27944. }
  27945. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27946. const int sizeInBytes)
  27947. {
  27948. if (sizeInBytes > 8
  27949. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27950. {
  27951. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27952. if (stringLength > 0)
  27953. {
  27954. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  27955. jmin ((sizeInBytes - 8), stringLength)));
  27956. return doc.getDocumentElement();
  27957. }
  27958. }
  27959. return 0;
  27960. }
  27961. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27962. {
  27963. }
  27964. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27965. {
  27966. }
  27967. END_JUCE_NAMESPACE
  27968. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  27969. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  27970. BEGIN_JUCE_NAMESPACE
  27971. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27972. : owner (owner_)
  27973. {
  27974. // the filter must be valid..
  27975. jassert (owner != 0);
  27976. }
  27977. AudioProcessorEditor::~AudioProcessorEditor()
  27978. {
  27979. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  27980. // filter for some reason..
  27981. jassert (owner->getActiveEditor() != this);
  27982. }
  27983. END_JUCE_NAMESPACE
  27984. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  27985. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  27986. BEGIN_JUCE_NAMESPACE
  27987. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  27988. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  27989. : id (id_),
  27990. processor (processor_),
  27991. isPrepared (false)
  27992. {
  27993. jassert (processor_ != 0);
  27994. }
  27995. AudioProcessorGraph::Node::~Node()
  27996. {
  27997. delete processor;
  27998. }
  27999. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  28000. AudioProcessorGraph* const graph)
  28001. {
  28002. if (! isPrepared)
  28003. {
  28004. isPrepared = true;
  28005. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28006. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  28007. if (ioProc != 0)
  28008. ioProc->setParentGraph (graph);
  28009. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  28010. processor->getNumOutputChannels(),
  28011. sampleRate, blockSize);
  28012. processor->prepareToPlay (sampleRate, blockSize);
  28013. }
  28014. }
  28015. void AudioProcessorGraph::Node::unprepare()
  28016. {
  28017. if (isPrepared)
  28018. {
  28019. isPrepared = false;
  28020. processor->releaseResources();
  28021. }
  28022. }
  28023. AudioProcessorGraph::AudioProcessorGraph()
  28024. : lastNodeId (0),
  28025. renderingBuffers (1, 1),
  28026. currentAudioOutputBuffer (1, 1)
  28027. {
  28028. }
  28029. AudioProcessorGraph::~AudioProcessorGraph()
  28030. {
  28031. clearRenderingSequence();
  28032. clear();
  28033. }
  28034. const String AudioProcessorGraph::getName() const
  28035. {
  28036. return "Audio Graph";
  28037. }
  28038. void AudioProcessorGraph::clear()
  28039. {
  28040. nodes.clear();
  28041. connections.clear();
  28042. triggerAsyncUpdate();
  28043. }
  28044. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  28045. {
  28046. for (int i = nodes.size(); --i >= 0;)
  28047. if (nodes.getUnchecked(i)->id == nodeId)
  28048. return nodes.getUnchecked(i);
  28049. return 0;
  28050. }
  28051. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  28052. uint32 nodeId)
  28053. {
  28054. if (newProcessor == 0)
  28055. {
  28056. jassertfalse
  28057. return 0;
  28058. }
  28059. if (nodeId == 0)
  28060. {
  28061. nodeId = ++lastNodeId;
  28062. }
  28063. else
  28064. {
  28065. // you can't add a node with an id that already exists in the graph..
  28066. jassert (getNodeForId (nodeId) == 0);
  28067. removeNode (nodeId);
  28068. }
  28069. lastNodeId = nodeId;
  28070. Node* const n = new Node (nodeId, newProcessor);
  28071. nodes.add (n);
  28072. triggerAsyncUpdate();
  28073. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28074. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  28075. if (ioProc != 0)
  28076. ioProc->setParentGraph (this);
  28077. return n;
  28078. }
  28079. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  28080. {
  28081. disconnectNode (nodeId);
  28082. for (int i = nodes.size(); --i >= 0;)
  28083. {
  28084. if (nodes.getUnchecked(i)->id == nodeId)
  28085. {
  28086. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28087. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  28088. if (ioProc != 0)
  28089. ioProc->setParentGraph (0);
  28090. nodes.remove (i);
  28091. triggerAsyncUpdate();
  28092. return true;
  28093. }
  28094. }
  28095. return false;
  28096. }
  28097. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28098. const int sourceChannelIndex,
  28099. const uint32 destNodeId,
  28100. const int destChannelIndex) const
  28101. {
  28102. for (int i = connections.size(); --i >= 0;)
  28103. {
  28104. const Connection* const c = connections.getUnchecked(i);
  28105. if (c->sourceNodeId == sourceNodeId
  28106. && c->destNodeId == destNodeId
  28107. && c->sourceChannelIndex == sourceChannelIndex
  28108. && c->destChannelIndex == destChannelIndex)
  28109. {
  28110. return c;
  28111. }
  28112. }
  28113. return 0;
  28114. }
  28115. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28116. const uint32 possibleDestNodeId) const
  28117. {
  28118. for (int i = connections.size(); --i >= 0;)
  28119. {
  28120. const Connection* const c = connections.getUnchecked(i);
  28121. if (c->sourceNodeId == possibleSourceNodeId
  28122. && c->destNodeId == possibleDestNodeId)
  28123. {
  28124. return true;
  28125. }
  28126. }
  28127. return false;
  28128. }
  28129. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28130. const int sourceChannelIndex,
  28131. const uint32 destNodeId,
  28132. const int destChannelIndex) const
  28133. {
  28134. if (sourceChannelIndex < 0
  28135. || destChannelIndex < 0
  28136. || sourceNodeId == destNodeId
  28137. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28138. return false;
  28139. const Node* const source = getNodeForId (sourceNodeId);
  28140. if (source == 0
  28141. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28142. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28143. return false;
  28144. const Node* const dest = getNodeForId (destNodeId);
  28145. if (dest == 0
  28146. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28147. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28148. return false;
  28149. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28150. destNodeId, destChannelIndex) == 0;
  28151. }
  28152. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28153. const int sourceChannelIndex,
  28154. const uint32 destNodeId,
  28155. const int destChannelIndex)
  28156. {
  28157. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28158. return false;
  28159. Connection* const c = new Connection();
  28160. c->sourceNodeId = sourceNodeId;
  28161. c->sourceChannelIndex = sourceChannelIndex;
  28162. c->destNodeId = destNodeId;
  28163. c->destChannelIndex = destChannelIndex;
  28164. connections.add (c);
  28165. triggerAsyncUpdate();
  28166. return true;
  28167. }
  28168. void AudioProcessorGraph::removeConnection (const int index)
  28169. {
  28170. connections.remove (index);
  28171. triggerAsyncUpdate();
  28172. }
  28173. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28174. const uint32 destNodeId, const int destChannelIndex)
  28175. {
  28176. bool doneAnything = false;
  28177. for (int i = connections.size(); --i >= 0;)
  28178. {
  28179. const Connection* const c = connections.getUnchecked(i);
  28180. if (c->sourceNodeId == sourceNodeId
  28181. && c->destNodeId == destNodeId
  28182. && c->sourceChannelIndex == sourceChannelIndex
  28183. && c->destChannelIndex == destChannelIndex)
  28184. {
  28185. removeConnection (i);
  28186. doneAnything = true;
  28187. triggerAsyncUpdate();
  28188. }
  28189. }
  28190. return doneAnything;
  28191. }
  28192. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28193. {
  28194. bool doneAnything = false;
  28195. for (int i = connections.size(); --i >= 0;)
  28196. {
  28197. const Connection* const c = connections.getUnchecked(i);
  28198. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28199. {
  28200. removeConnection (i);
  28201. doneAnything = true;
  28202. triggerAsyncUpdate();
  28203. }
  28204. }
  28205. return doneAnything;
  28206. }
  28207. bool AudioProcessorGraph::removeIllegalConnections()
  28208. {
  28209. bool doneAnything = false;
  28210. for (int i = connections.size(); --i >= 0;)
  28211. {
  28212. const Connection* const c = connections.getUnchecked(i);
  28213. const Node* const source = getNodeForId (c->sourceNodeId);
  28214. const Node* const dest = getNodeForId (c->destNodeId);
  28215. if (source == 0 || dest == 0
  28216. || (c->sourceChannelIndex != midiChannelIndex
  28217. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28218. || (c->sourceChannelIndex == midiChannelIndex
  28219. && ! source->processor->producesMidi())
  28220. || (c->destChannelIndex != midiChannelIndex
  28221. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28222. || (c->destChannelIndex == midiChannelIndex
  28223. && ! dest->processor->acceptsMidi()))
  28224. {
  28225. removeConnection (i);
  28226. doneAnything = true;
  28227. triggerAsyncUpdate();
  28228. }
  28229. }
  28230. return doneAnything;
  28231. }
  28232. namespace GraphRenderingOps
  28233. {
  28234. class AudioGraphRenderingOp
  28235. {
  28236. public:
  28237. AudioGraphRenderingOp() {}
  28238. virtual ~AudioGraphRenderingOp() {}
  28239. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28240. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28241. const int numSamples) = 0;
  28242. juce_UseDebuggingNewOperator
  28243. };
  28244. class ClearChannelOp : public AudioGraphRenderingOp
  28245. {
  28246. public:
  28247. ClearChannelOp (const int channelNum_)
  28248. : channelNum (channelNum_)
  28249. {}
  28250. ~ClearChannelOp() {}
  28251. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28252. {
  28253. sharedBufferChans.clear (channelNum, 0, numSamples);
  28254. }
  28255. private:
  28256. const int channelNum;
  28257. ClearChannelOp (const ClearChannelOp&);
  28258. ClearChannelOp& operator= (const ClearChannelOp&);
  28259. };
  28260. class CopyChannelOp : public AudioGraphRenderingOp
  28261. {
  28262. public:
  28263. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28264. : srcChannelNum (srcChannelNum_),
  28265. dstChannelNum (dstChannelNum_)
  28266. {}
  28267. ~CopyChannelOp() {}
  28268. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28269. {
  28270. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28271. }
  28272. private:
  28273. const int srcChannelNum, dstChannelNum;
  28274. CopyChannelOp (const CopyChannelOp&);
  28275. CopyChannelOp& operator= (const CopyChannelOp&);
  28276. };
  28277. class AddChannelOp : public AudioGraphRenderingOp
  28278. {
  28279. public:
  28280. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28281. : srcChannelNum (srcChannelNum_),
  28282. dstChannelNum (dstChannelNum_)
  28283. {}
  28284. ~AddChannelOp() {}
  28285. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28286. {
  28287. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28288. }
  28289. private:
  28290. const int srcChannelNum, dstChannelNum;
  28291. AddChannelOp (const AddChannelOp&);
  28292. AddChannelOp& operator= (const AddChannelOp&);
  28293. };
  28294. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28295. {
  28296. public:
  28297. ClearMidiBufferOp (const int bufferNum_)
  28298. : bufferNum (bufferNum_)
  28299. {}
  28300. ~ClearMidiBufferOp() {}
  28301. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28302. {
  28303. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28304. }
  28305. private:
  28306. const int bufferNum;
  28307. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28308. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28309. };
  28310. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28311. {
  28312. public:
  28313. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28314. : srcBufferNum (srcBufferNum_),
  28315. dstBufferNum (dstBufferNum_)
  28316. {}
  28317. ~CopyMidiBufferOp() {}
  28318. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28319. {
  28320. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28321. }
  28322. private:
  28323. const int srcBufferNum, dstBufferNum;
  28324. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28325. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28326. };
  28327. class AddMidiBufferOp : public AudioGraphRenderingOp
  28328. {
  28329. public:
  28330. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28331. : srcBufferNum (srcBufferNum_),
  28332. dstBufferNum (dstBufferNum_)
  28333. {}
  28334. ~AddMidiBufferOp() {}
  28335. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28336. {
  28337. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28338. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28339. }
  28340. private:
  28341. const int srcBufferNum, dstBufferNum;
  28342. AddMidiBufferOp (const AddMidiBufferOp&);
  28343. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28344. };
  28345. class ProcessBufferOp : public AudioGraphRenderingOp
  28346. {
  28347. public:
  28348. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28349. const Array <int>& audioChannelsToUse_,
  28350. const int totalChans_,
  28351. const int midiBufferToUse_)
  28352. : node (node_),
  28353. processor (node_->processor),
  28354. audioChannelsToUse (audioChannelsToUse_),
  28355. totalChans (jmax (1, totalChans_)),
  28356. midiBufferToUse (midiBufferToUse_)
  28357. {
  28358. channels.calloc (totalChans);
  28359. while (audioChannelsToUse.size() < totalChans)
  28360. audioChannelsToUse.add (0);
  28361. }
  28362. ~ProcessBufferOp()
  28363. {
  28364. }
  28365. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28366. {
  28367. for (int i = totalChans; --i >= 0;)
  28368. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28369. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28370. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28371. }
  28372. const AudioProcessorGraph::Node::Ptr node;
  28373. AudioProcessor* const processor;
  28374. private:
  28375. Array <int> audioChannelsToUse;
  28376. HeapBlock <float*> channels;
  28377. int totalChans;
  28378. int midiBufferToUse;
  28379. ProcessBufferOp (const ProcessBufferOp&);
  28380. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28381. };
  28382. class RenderingOpSequenceCalculator
  28383. {
  28384. public:
  28385. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28386. const VoidArray& orderedNodes_,
  28387. VoidArray& renderingOps)
  28388. : graph (graph_),
  28389. orderedNodes (orderedNodes_)
  28390. {
  28391. nodeIds.add (-2); // first buffer is read-only zeros
  28392. channels.add (0);
  28393. midiNodeIds.add (-2);
  28394. for (int i = 0; i < orderedNodes.size(); ++i)
  28395. {
  28396. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28397. renderingOps, i);
  28398. markAnyUnusedBuffersAsFree (i);
  28399. }
  28400. }
  28401. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28402. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28403. juce_UseDebuggingNewOperator
  28404. private:
  28405. AudioProcessorGraph& graph;
  28406. const VoidArray& orderedNodes;
  28407. Array <int> nodeIds, channels, midiNodeIds;
  28408. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28409. VoidArray& renderingOps,
  28410. const int ourRenderingIndex)
  28411. {
  28412. const int numIns = node->processor->getNumInputChannels();
  28413. const int numOuts = node->processor->getNumOutputChannels();
  28414. const int totalChans = jmax (numIns, numOuts);
  28415. Array <int> audioChannelsToUse;
  28416. int midiBufferToUse = -1;
  28417. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28418. {
  28419. // get a list of all the inputs to this node
  28420. Array <int> sourceNodes, sourceOutputChans;
  28421. for (int i = graph.getNumConnections(); --i >= 0;)
  28422. {
  28423. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28424. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28425. {
  28426. sourceNodes.add (c->sourceNodeId);
  28427. sourceOutputChans.add (c->sourceChannelIndex);
  28428. }
  28429. }
  28430. int bufIndex = -1;
  28431. if (sourceNodes.size() == 0)
  28432. {
  28433. // unconnected input channel
  28434. if (inputChan >= numOuts)
  28435. {
  28436. bufIndex = getReadOnlyEmptyBuffer();
  28437. jassert (bufIndex >= 0);
  28438. }
  28439. else
  28440. {
  28441. bufIndex = getFreeBuffer (false);
  28442. renderingOps.add (new ClearChannelOp (bufIndex));
  28443. }
  28444. }
  28445. else if (sourceNodes.size() == 1)
  28446. {
  28447. // channel with a straightforward single input..
  28448. const int srcNode = sourceNodes.getUnchecked(0);
  28449. const int srcChan = sourceOutputChans.getUnchecked(0);
  28450. bufIndex = getBufferContaining (srcNode, srcChan);
  28451. if (bufIndex < 0)
  28452. {
  28453. // if not found, this is probably a feedback loop
  28454. bufIndex = getReadOnlyEmptyBuffer();
  28455. jassert (bufIndex >= 0);
  28456. }
  28457. if (inputChan < numOuts
  28458. && isBufferNeededLater (ourRenderingIndex,
  28459. inputChan,
  28460. srcNode, srcChan))
  28461. {
  28462. // can't mess up this channel because it's needed later by another node, so we
  28463. // need to use a copy of it..
  28464. const int newFreeBuffer = getFreeBuffer (false);
  28465. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28466. bufIndex = newFreeBuffer;
  28467. }
  28468. }
  28469. else
  28470. {
  28471. // channel with a mix of several inputs..
  28472. // try to find a re-usable channel from our inputs..
  28473. int reusableInputIndex = -1;
  28474. for (int i = 0; i < sourceNodes.size(); ++i)
  28475. {
  28476. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28477. sourceOutputChans.getUnchecked(i));
  28478. if (sourceBufIndex >= 0
  28479. && ! isBufferNeededLater (ourRenderingIndex,
  28480. inputChan,
  28481. sourceNodes.getUnchecked(i),
  28482. sourceOutputChans.getUnchecked(i)))
  28483. {
  28484. // we've found one of our input chans that can be re-used..
  28485. reusableInputIndex = i;
  28486. bufIndex = sourceBufIndex;
  28487. break;
  28488. }
  28489. }
  28490. if (reusableInputIndex < 0)
  28491. {
  28492. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28493. bufIndex = getFreeBuffer (false);
  28494. jassert (bufIndex != 0);
  28495. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28496. sourceOutputChans.getUnchecked (0));
  28497. if (srcIndex < 0)
  28498. {
  28499. // if not found, this is probably a feedback loop
  28500. renderingOps.add (new ClearChannelOp (bufIndex));
  28501. }
  28502. else
  28503. {
  28504. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28505. }
  28506. reusableInputIndex = 0;
  28507. }
  28508. for (int j = 0; j < sourceNodes.size(); ++j)
  28509. {
  28510. if (j != reusableInputIndex)
  28511. {
  28512. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28513. sourceOutputChans.getUnchecked(j));
  28514. if (srcIndex >= 0)
  28515. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28516. }
  28517. }
  28518. }
  28519. jassert (bufIndex >= 0);
  28520. audioChannelsToUse.add (bufIndex);
  28521. if (inputChan < numOuts)
  28522. markBufferAsContaining (bufIndex, node->id, inputChan);
  28523. }
  28524. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28525. {
  28526. const int bufIndex = getFreeBuffer (false);
  28527. jassert (bufIndex != 0);
  28528. audioChannelsToUse.add (bufIndex);
  28529. markBufferAsContaining (bufIndex, node->id, outputChan);
  28530. }
  28531. // Now the same thing for midi..
  28532. Array <int> midiSourceNodes;
  28533. for (int i = graph.getNumConnections(); --i >= 0;)
  28534. {
  28535. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28536. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28537. midiSourceNodes.add (c->sourceNodeId);
  28538. }
  28539. if (midiSourceNodes.size() == 0)
  28540. {
  28541. // No midi inputs..
  28542. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28543. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28544. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28545. }
  28546. else if (midiSourceNodes.size() == 1)
  28547. {
  28548. // One midi input..
  28549. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28550. AudioProcessorGraph::midiChannelIndex);
  28551. if (midiBufferToUse >= 0)
  28552. {
  28553. if (isBufferNeededLater (ourRenderingIndex,
  28554. AudioProcessorGraph::midiChannelIndex,
  28555. midiSourceNodes.getUnchecked(0),
  28556. AudioProcessorGraph::midiChannelIndex))
  28557. {
  28558. // can't mess up this channel because it's needed later by another node, so we
  28559. // need to use a copy of it..
  28560. const int newFreeBuffer = getFreeBuffer (true);
  28561. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28562. midiBufferToUse = newFreeBuffer;
  28563. }
  28564. }
  28565. else
  28566. {
  28567. // probably a feedback loop, so just use an empty one..
  28568. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28569. }
  28570. }
  28571. else
  28572. {
  28573. // More than one midi input being mixed..
  28574. int reusableInputIndex = -1;
  28575. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28576. {
  28577. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28578. AudioProcessorGraph::midiChannelIndex);
  28579. if (sourceBufIndex >= 0
  28580. && ! isBufferNeededLater (ourRenderingIndex,
  28581. AudioProcessorGraph::midiChannelIndex,
  28582. midiSourceNodes.getUnchecked(i),
  28583. AudioProcessorGraph::midiChannelIndex))
  28584. {
  28585. // we've found one of our input buffers that can be re-used..
  28586. reusableInputIndex = i;
  28587. midiBufferToUse = sourceBufIndex;
  28588. break;
  28589. }
  28590. }
  28591. if (reusableInputIndex < 0)
  28592. {
  28593. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28594. midiBufferToUse = getFreeBuffer (true);
  28595. jassert (midiBufferToUse >= 0);
  28596. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28597. AudioProcessorGraph::midiChannelIndex);
  28598. if (srcIndex >= 0)
  28599. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28600. else
  28601. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28602. reusableInputIndex = 0;
  28603. }
  28604. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28605. {
  28606. if (j != reusableInputIndex)
  28607. {
  28608. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28609. AudioProcessorGraph::midiChannelIndex);
  28610. if (srcIndex >= 0)
  28611. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28612. }
  28613. }
  28614. }
  28615. if (node->processor->producesMidi())
  28616. markBufferAsContaining (midiBufferToUse, node->id,
  28617. AudioProcessorGraph::midiChannelIndex);
  28618. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28619. totalChans, midiBufferToUse));
  28620. }
  28621. int getFreeBuffer (const bool forMidi)
  28622. {
  28623. if (forMidi)
  28624. {
  28625. for (int i = 1; i < midiNodeIds.size(); ++i)
  28626. if (midiNodeIds.getUnchecked(i) < 0)
  28627. return i;
  28628. midiNodeIds.add (-1);
  28629. return midiNodeIds.size() - 1;
  28630. }
  28631. else
  28632. {
  28633. for (int i = 1; i < nodeIds.size(); ++i)
  28634. if (nodeIds.getUnchecked(i) < 0)
  28635. return i;
  28636. nodeIds.add (-1);
  28637. channels.add (0);
  28638. return nodeIds.size() - 1;
  28639. }
  28640. }
  28641. int getReadOnlyEmptyBuffer() const
  28642. {
  28643. return 0;
  28644. }
  28645. int getBufferContaining (const int nodeId, const int outputChannel) const
  28646. {
  28647. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28648. {
  28649. for (int i = midiNodeIds.size(); --i >= 0;)
  28650. if (midiNodeIds.getUnchecked(i) == nodeId)
  28651. return i;
  28652. }
  28653. else
  28654. {
  28655. for (int i = nodeIds.size(); --i >= 0;)
  28656. if (nodeIds.getUnchecked(i) == nodeId
  28657. && channels.getUnchecked(i) == outputChannel)
  28658. return i;
  28659. }
  28660. return -1;
  28661. }
  28662. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28663. {
  28664. int i;
  28665. for (i = 0; i < nodeIds.size(); ++i)
  28666. {
  28667. if (nodeIds.getUnchecked(i) >= 0
  28668. && ! isBufferNeededLater (stepIndex, -1,
  28669. nodeIds.getUnchecked(i),
  28670. channels.getUnchecked(i)))
  28671. {
  28672. nodeIds.set (i, -1);
  28673. }
  28674. }
  28675. for (i = 0; i < midiNodeIds.size(); ++i)
  28676. {
  28677. if (midiNodeIds.getUnchecked(i) >= 0
  28678. && ! isBufferNeededLater (stepIndex, -1,
  28679. midiNodeIds.getUnchecked(i),
  28680. AudioProcessorGraph::midiChannelIndex))
  28681. {
  28682. midiNodeIds.set (i, -1);
  28683. }
  28684. }
  28685. }
  28686. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28687. int inputChannelOfIndexToIgnore,
  28688. const int nodeId,
  28689. const int outputChanIndex) const
  28690. {
  28691. while (stepIndexToSearchFrom < orderedNodes.size())
  28692. {
  28693. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28694. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28695. {
  28696. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28697. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28698. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28699. return true;
  28700. }
  28701. else
  28702. {
  28703. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28704. if (i != inputChannelOfIndexToIgnore
  28705. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28706. node->id, i) != 0)
  28707. return true;
  28708. }
  28709. inputChannelOfIndexToIgnore = -1;
  28710. ++stepIndexToSearchFrom;
  28711. }
  28712. return false;
  28713. }
  28714. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28715. {
  28716. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28717. {
  28718. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28719. midiNodeIds.set (bufferNum, nodeId);
  28720. }
  28721. else
  28722. {
  28723. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28724. nodeIds.set (bufferNum, nodeId);
  28725. channels.set (bufferNum, outputIndex);
  28726. }
  28727. }
  28728. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28729. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28730. };
  28731. }
  28732. void AudioProcessorGraph::clearRenderingSequence()
  28733. {
  28734. const ScopedLock sl (renderLock);
  28735. for (int i = renderingOps.size(); --i >= 0;)
  28736. {
  28737. GraphRenderingOps::AudioGraphRenderingOp* const r
  28738. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28739. renderingOps.remove (i);
  28740. delete r;
  28741. }
  28742. }
  28743. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28744. const uint32 possibleDestinationId,
  28745. const int recursionCheck) const
  28746. {
  28747. if (recursionCheck > 0)
  28748. {
  28749. for (int i = connections.size(); --i >= 0;)
  28750. {
  28751. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28752. if (c->destNodeId == possibleDestinationId
  28753. && (c->sourceNodeId == possibleInputId
  28754. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28755. return true;
  28756. }
  28757. }
  28758. return false;
  28759. }
  28760. void AudioProcessorGraph::buildRenderingSequence()
  28761. {
  28762. VoidArray newRenderingOps;
  28763. int numRenderingBuffersNeeded = 2;
  28764. int numMidiBuffersNeeded = 1;
  28765. {
  28766. MessageManagerLock mml;
  28767. VoidArray orderedNodes;
  28768. int i;
  28769. for (i = 0; i < nodes.size(); ++i)
  28770. {
  28771. Node* const node = nodes.getUnchecked(i);
  28772. node->prepare (getSampleRate(), getBlockSize(), this);
  28773. int j = 0;
  28774. for (; j < orderedNodes.size(); ++j)
  28775. if (isAnInputTo (node->id,
  28776. ((Node*) orderedNodes.getUnchecked (j))->id,
  28777. nodes.size() + 1))
  28778. break;
  28779. orderedNodes.insert (j, node);
  28780. }
  28781. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28782. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28783. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28784. }
  28785. VoidArray oldRenderingOps (renderingOps);
  28786. {
  28787. // swap over to the new rendering sequence..
  28788. const ScopedLock sl (renderLock);
  28789. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28790. renderingBuffers.clear();
  28791. for (int i = midiBuffers.size(); --i >= 0;)
  28792. midiBuffers.getUnchecked(i)->clear();
  28793. while (midiBuffers.size() < numMidiBuffersNeeded)
  28794. midiBuffers.add (new MidiBuffer());
  28795. renderingOps = newRenderingOps;
  28796. }
  28797. for (int i = oldRenderingOps.size(); --i >= 0;)
  28798. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28799. }
  28800. void AudioProcessorGraph::handleAsyncUpdate()
  28801. {
  28802. buildRenderingSequence();
  28803. }
  28804. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28805. {
  28806. currentAudioInputBuffer = 0;
  28807. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28808. currentMidiInputBuffer = 0;
  28809. currentMidiOutputBuffer.clear();
  28810. clearRenderingSequence();
  28811. buildRenderingSequence();
  28812. }
  28813. void AudioProcessorGraph::releaseResources()
  28814. {
  28815. for (int i = 0; i < nodes.size(); ++i)
  28816. nodes.getUnchecked(i)->unprepare();
  28817. renderingBuffers.setSize (1, 1);
  28818. midiBuffers.clear();
  28819. currentAudioInputBuffer = 0;
  28820. currentAudioOutputBuffer.setSize (1, 1);
  28821. currentMidiInputBuffer = 0;
  28822. currentMidiOutputBuffer.clear();
  28823. }
  28824. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28825. {
  28826. const int numSamples = buffer.getNumSamples();
  28827. const ScopedLock sl (renderLock);
  28828. currentAudioInputBuffer = &buffer;
  28829. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28830. currentAudioOutputBuffer.clear();
  28831. currentMidiInputBuffer = &midiMessages;
  28832. currentMidiOutputBuffer.clear();
  28833. int i;
  28834. for (i = 0; i < renderingOps.size(); ++i)
  28835. {
  28836. GraphRenderingOps::AudioGraphRenderingOp* const op
  28837. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28838. op->perform (renderingBuffers, midiBuffers, numSamples);
  28839. }
  28840. for (i = 0; i < buffer.getNumChannels(); ++i)
  28841. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28842. midiMessages.clear();
  28843. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28844. }
  28845. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28846. {
  28847. return "Input " + String (channelIndex + 1);
  28848. }
  28849. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28850. {
  28851. return "Output " + String (channelIndex + 1);
  28852. }
  28853. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28854. {
  28855. return true;
  28856. }
  28857. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28858. {
  28859. return true;
  28860. }
  28861. bool AudioProcessorGraph::acceptsMidi() const
  28862. {
  28863. return true;
  28864. }
  28865. bool AudioProcessorGraph::producesMidi() const
  28866. {
  28867. return true;
  28868. }
  28869. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28870. {
  28871. }
  28872. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28873. {
  28874. }
  28875. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28876. : type (type_),
  28877. graph (0)
  28878. {
  28879. }
  28880. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28881. {
  28882. }
  28883. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28884. {
  28885. switch (type)
  28886. {
  28887. case audioOutputNode:
  28888. return "Audio Output";
  28889. case audioInputNode:
  28890. return "Audio Input";
  28891. case midiOutputNode:
  28892. return "Midi Output";
  28893. case midiInputNode:
  28894. return "Midi Input";
  28895. default:
  28896. break;
  28897. }
  28898. return String::empty;
  28899. }
  28900. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28901. {
  28902. d.name = getName();
  28903. d.uid = d.name.hashCode();
  28904. d.category = "I/O devices";
  28905. d.pluginFormatName = "Internal";
  28906. d.manufacturerName = "Raw Material Software";
  28907. d.version = "1.0";
  28908. d.isInstrument = false;
  28909. d.numInputChannels = getNumInputChannels();
  28910. if (type == audioOutputNode && graph != 0)
  28911. d.numInputChannels = graph->getNumInputChannels();
  28912. d.numOutputChannels = getNumOutputChannels();
  28913. if (type == audioInputNode && graph != 0)
  28914. d.numOutputChannels = graph->getNumOutputChannels();
  28915. }
  28916. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28917. {
  28918. jassert (graph != 0);
  28919. }
  28920. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28921. {
  28922. }
  28923. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28924. MidiBuffer& midiMessages)
  28925. {
  28926. jassert (graph != 0);
  28927. switch (type)
  28928. {
  28929. case audioOutputNode:
  28930. {
  28931. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28932. buffer.getNumChannels()); --i >= 0;)
  28933. {
  28934. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28935. }
  28936. break;
  28937. }
  28938. case audioInputNode:
  28939. {
  28940. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28941. buffer.getNumChannels()); --i >= 0;)
  28942. {
  28943. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28944. }
  28945. break;
  28946. }
  28947. case midiOutputNode:
  28948. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28949. break;
  28950. case midiInputNode:
  28951. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28952. break;
  28953. default:
  28954. break;
  28955. }
  28956. }
  28957. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28958. {
  28959. return type == midiOutputNode;
  28960. }
  28961. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28962. {
  28963. return type == midiInputNode;
  28964. }
  28965. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28966. {
  28967. switch (type)
  28968. {
  28969. case audioOutputNode:
  28970. return "Output " + String (channelIndex + 1);
  28971. case midiOutputNode:
  28972. return "Midi Output";
  28973. default:
  28974. break;
  28975. }
  28976. return String::empty;
  28977. }
  28978. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  28979. {
  28980. switch (type)
  28981. {
  28982. case audioInputNode:
  28983. return "Input " + String (channelIndex + 1);
  28984. case midiInputNode:
  28985. return "Midi Input";
  28986. default:
  28987. break;
  28988. }
  28989. return String::empty;
  28990. }
  28991. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  28992. {
  28993. return type == audioInputNode || type == audioOutputNode;
  28994. }
  28995. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  28996. {
  28997. return isInputChannelStereoPair (index);
  28998. }
  28999. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  29000. {
  29001. return type == audioInputNode || type == midiInputNode;
  29002. }
  29003. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  29004. {
  29005. return type == audioOutputNode || type == midiOutputNode;
  29006. }
  29007. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  29008. {
  29009. return 0;
  29010. }
  29011. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  29012. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  29013. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  29014. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  29015. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  29016. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  29017. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  29018. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  29019. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  29020. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  29021. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  29022. {
  29023. }
  29024. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  29025. {
  29026. }
  29027. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  29028. {
  29029. graph = newGraph;
  29030. if (graph != 0)
  29031. {
  29032. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  29033. type == audioInputNode ? graph->getNumInputChannels() : 0,
  29034. getSampleRate(),
  29035. getBlockSize());
  29036. updateHostDisplay();
  29037. }
  29038. }
  29039. END_JUCE_NAMESPACE
  29040. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  29041. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29042. BEGIN_JUCE_NAMESPACE
  29043. AudioProcessorPlayer::AudioProcessorPlayer()
  29044. : processor (0),
  29045. sampleRate (0),
  29046. blockSize (0),
  29047. isPrepared (false),
  29048. numInputChans (0),
  29049. numOutputChans (0),
  29050. tempBuffer (1, 1)
  29051. {
  29052. }
  29053. AudioProcessorPlayer::~AudioProcessorPlayer()
  29054. {
  29055. setProcessor (0);
  29056. }
  29057. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  29058. {
  29059. if (processor != processorToPlay)
  29060. {
  29061. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  29062. {
  29063. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  29064. sampleRate, blockSize);
  29065. processorToPlay->prepareToPlay (sampleRate, blockSize);
  29066. }
  29067. AudioProcessor* oldOne;
  29068. {
  29069. const ScopedLock sl (lock);
  29070. oldOne = isPrepared ? processor : 0;
  29071. processor = processorToPlay;
  29072. isPrepared = true;
  29073. }
  29074. if (oldOne != 0)
  29075. oldOne->releaseResources();
  29076. }
  29077. }
  29078. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  29079. int numInputChannels,
  29080. float** outputChannelData,
  29081. int numOutputChannels,
  29082. int numSamples)
  29083. {
  29084. // these should have been prepared by audioDeviceAboutToStart()...
  29085. jassert (sampleRate > 0 && blockSize > 0);
  29086. incomingMidi.clear();
  29087. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  29088. int i, totalNumChans = 0;
  29089. if (numInputChannels > numOutputChannels)
  29090. {
  29091. // if there aren't enough output channels for the number of
  29092. // inputs, we need to create some temporary extra ones (can't
  29093. // use the input data in case it gets written to)
  29094. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29095. false, false, true);
  29096. for (i = 0; i < numOutputChannels; ++i)
  29097. {
  29098. channels[totalNumChans] = outputChannelData[i];
  29099. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29100. ++totalNumChans;
  29101. }
  29102. for (i = numOutputChannels; i < numInputChannels; ++i)
  29103. {
  29104. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29105. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29106. ++totalNumChans;
  29107. }
  29108. }
  29109. else
  29110. {
  29111. for (i = 0; i < numInputChannels; ++i)
  29112. {
  29113. channels[totalNumChans] = outputChannelData[i];
  29114. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29115. ++totalNumChans;
  29116. }
  29117. for (i = numInputChannels; i < numOutputChannels; ++i)
  29118. {
  29119. channels[totalNumChans] = outputChannelData[i];
  29120. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29121. ++totalNumChans;
  29122. }
  29123. }
  29124. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29125. const ScopedLock sl (lock);
  29126. if (processor != 0)
  29127. processor->processBlock (buffer, incomingMidi);
  29128. }
  29129. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29130. {
  29131. const ScopedLock sl (lock);
  29132. sampleRate = device->getCurrentSampleRate();
  29133. blockSize = device->getCurrentBufferSizeSamples();
  29134. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29135. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29136. messageCollector.reset (sampleRate);
  29137. zeromem (channels, sizeof (channels));
  29138. if (processor != 0)
  29139. {
  29140. if (isPrepared)
  29141. processor->releaseResources();
  29142. AudioProcessor* const oldProcessor = processor;
  29143. setProcessor (0);
  29144. setProcessor (oldProcessor);
  29145. }
  29146. }
  29147. void AudioProcessorPlayer::audioDeviceStopped()
  29148. {
  29149. const ScopedLock sl (lock);
  29150. if (processor != 0 && isPrepared)
  29151. processor->releaseResources();
  29152. sampleRate = 0.0;
  29153. blockSize = 0;
  29154. isPrepared = false;
  29155. tempBuffer.setSize (1, 1);
  29156. }
  29157. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29158. {
  29159. messageCollector.addMessageToQueue (message);
  29160. }
  29161. END_JUCE_NAMESPACE
  29162. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29163. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29164. BEGIN_JUCE_NAMESPACE
  29165. class ProcessorParameterPropertyComp : public PropertyComponent,
  29166. public AudioProcessorListener,
  29167. public AsyncUpdater
  29168. {
  29169. public:
  29170. ProcessorParameterPropertyComp (const String& name,
  29171. AudioProcessor* const owner_,
  29172. const int index_)
  29173. : PropertyComponent (name),
  29174. owner (owner_),
  29175. index (index_)
  29176. {
  29177. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29178. owner_->addListener (this);
  29179. }
  29180. ~ProcessorParameterPropertyComp()
  29181. {
  29182. owner->removeListener (this);
  29183. deleteAllChildren();
  29184. }
  29185. void refresh()
  29186. {
  29187. slider->setValue (owner->getParameter (index), false);
  29188. }
  29189. void audioProcessorChanged (AudioProcessor*) {}
  29190. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29191. {
  29192. if (parameterIndex == index)
  29193. triggerAsyncUpdate();
  29194. }
  29195. void handleAsyncUpdate()
  29196. {
  29197. refresh();
  29198. }
  29199. juce_UseDebuggingNewOperator
  29200. private:
  29201. AudioProcessor* const owner;
  29202. const int index;
  29203. Slider* slider;
  29204. class ParamSlider : public Slider
  29205. {
  29206. public:
  29207. ParamSlider (AudioProcessor* const owner_, const int index_)
  29208. : Slider (String::empty),
  29209. owner (owner_),
  29210. index (index_)
  29211. {
  29212. setRange (0.0, 1.0, 0.0);
  29213. setSliderStyle (Slider::LinearBar);
  29214. setTextBoxIsEditable (false);
  29215. setScrollWheelEnabled (false);
  29216. }
  29217. ~ParamSlider()
  29218. {
  29219. }
  29220. void valueChanged()
  29221. {
  29222. const float newVal = (float) getValue();
  29223. if (owner->getParameter (index) != newVal)
  29224. owner->setParameter (index, newVal);
  29225. }
  29226. const String getTextFromValue (double /*value*/)
  29227. {
  29228. return owner->getParameterText (index);
  29229. }
  29230. juce_UseDebuggingNewOperator
  29231. private:
  29232. AudioProcessor* const owner;
  29233. const int index;
  29234. ParamSlider (const ParamSlider&);
  29235. ParamSlider& operator= (const ParamSlider&);
  29236. };
  29237. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29238. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29239. };
  29240. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29241. : AudioProcessorEditor (owner_)
  29242. {
  29243. setOpaque (true);
  29244. addAndMakeVisible (panel = new PropertyPanel());
  29245. Array <PropertyComponent*> params;
  29246. const int numParams = owner_->getNumParameters();
  29247. int totalHeight = 0;
  29248. for (int i = 0; i < numParams; ++i)
  29249. {
  29250. String name (owner_->getParameterName (i));
  29251. if (name.trim().isEmpty())
  29252. name = "Unnamed";
  29253. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29254. params.add (pc);
  29255. totalHeight += pc->getPreferredHeight();
  29256. }
  29257. panel->addProperties (params);
  29258. setSize (400, jlimit (25, 400, totalHeight));
  29259. }
  29260. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29261. {
  29262. deleteAllChildren();
  29263. }
  29264. void GenericAudioProcessorEditor::paint (Graphics& g)
  29265. {
  29266. g.fillAll (Colours::white);
  29267. }
  29268. void GenericAudioProcessorEditor::resized()
  29269. {
  29270. panel->setSize (getWidth(), getHeight());
  29271. }
  29272. END_JUCE_NAMESPACE
  29273. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29274. /*** Start of inlined file: juce_Sampler.cpp ***/
  29275. BEGIN_JUCE_NAMESPACE
  29276. SamplerSound::SamplerSound (const String& name_,
  29277. AudioFormatReader& source,
  29278. const BitArray& midiNotes_,
  29279. const int midiNoteForNormalPitch,
  29280. const double attackTimeSecs,
  29281. const double releaseTimeSecs,
  29282. const double maxSampleLengthSeconds)
  29283. : name (name_),
  29284. midiNotes (midiNotes_),
  29285. midiRootNote (midiNoteForNormalPitch)
  29286. {
  29287. sourceSampleRate = source.sampleRate;
  29288. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29289. {
  29290. length = 0;
  29291. attackSamples = 0;
  29292. releaseSamples = 0;
  29293. }
  29294. else
  29295. {
  29296. length = jmin ((int) source.lengthInSamples,
  29297. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29298. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29299. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29300. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29301. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29302. }
  29303. }
  29304. SamplerSound::~SamplerSound()
  29305. {
  29306. }
  29307. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29308. {
  29309. return midiNotes [midiNoteNumber];
  29310. }
  29311. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29312. {
  29313. return true;
  29314. }
  29315. SamplerVoice::SamplerVoice()
  29316. : pitchRatio (0.0),
  29317. sourceSamplePosition (0.0),
  29318. lgain (0.0f),
  29319. rgain (0.0f),
  29320. isInAttack (false),
  29321. isInRelease (false)
  29322. {
  29323. }
  29324. SamplerVoice::~SamplerVoice()
  29325. {
  29326. }
  29327. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29328. {
  29329. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29330. }
  29331. void SamplerVoice::startNote (const int midiNoteNumber,
  29332. const float velocity,
  29333. SynthesiserSound* s,
  29334. const int /*currentPitchWheelPosition*/)
  29335. {
  29336. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29337. jassert (sound != 0); // this object can only play SamplerSounds!
  29338. if (sound != 0)
  29339. {
  29340. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29341. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29342. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29343. sourceSamplePosition = 0.0;
  29344. lgain = velocity;
  29345. rgain = velocity;
  29346. isInAttack = (sound->attackSamples > 0);
  29347. isInRelease = false;
  29348. if (isInAttack)
  29349. {
  29350. attackReleaseLevel = 0.0f;
  29351. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29352. }
  29353. else
  29354. {
  29355. attackReleaseLevel = 1.0f;
  29356. attackDelta = 0.0f;
  29357. }
  29358. if (sound->releaseSamples > 0)
  29359. {
  29360. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29361. }
  29362. else
  29363. {
  29364. releaseDelta = 0.0f;
  29365. }
  29366. }
  29367. }
  29368. void SamplerVoice::stopNote (const bool allowTailOff)
  29369. {
  29370. if (allowTailOff)
  29371. {
  29372. isInAttack = false;
  29373. isInRelease = true;
  29374. }
  29375. else
  29376. {
  29377. clearCurrentNote();
  29378. }
  29379. }
  29380. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29381. {
  29382. }
  29383. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29384. const int /*newValue*/)
  29385. {
  29386. }
  29387. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29388. {
  29389. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29390. if (playingSound != 0)
  29391. {
  29392. const float* const inL = playingSound->data->getSampleData (0, 0);
  29393. const float* const inR = playingSound->data->getNumChannels() > 1
  29394. ? playingSound->data->getSampleData (1, 0) : 0;
  29395. float* outL = outputBuffer.getSampleData (0, startSample);
  29396. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29397. while (--numSamples >= 0)
  29398. {
  29399. const int pos = (int) sourceSamplePosition;
  29400. const float alpha = (float) (sourceSamplePosition - pos);
  29401. const float invAlpha = 1.0f - alpha;
  29402. // just using a very simple linear interpolation here..
  29403. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29404. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29405. : l;
  29406. l *= lgain;
  29407. r *= rgain;
  29408. if (isInAttack)
  29409. {
  29410. l *= attackReleaseLevel;
  29411. r *= attackReleaseLevel;
  29412. attackReleaseLevel += attackDelta;
  29413. if (attackReleaseLevel >= 1.0f)
  29414. {
  29415. attackReleaseLevel = 1.0f;
  29416. isInAttack = false;
  29417. }
  29418. }
  29419. else if (isInRelease)
  29420. {
  29421. l *= attackReleaseLevel;
  29422. r *= attackReleaseLevel;
  29423. attackReleaseLevel += releaseDelta;
  29424. if (attackReleaseLevel <= 0.0f)
  29425. {
  29426. stopNote (false);
  29427. break;
  29428. }
  29429. }
  29430. if (outR != 0)
  29431. {
  29432. *outL++ += l;
  29433. *outR++ += r;
  29434. }
  29435. else
  29436. {
  29437. *outL++ += (l + r) * 0.5f;
  29438. }
  29439. sourceSamplePosition += pitchRatio;
  29440. if (sourceSamplePosition > playingSound->length)
  29441. {
  29442. stopNote (false);
  29443. break;
  29444. }
  29445. }
  29446. }
  29447. }
  29448. END_JUCE_NAMESPACE
  29449. /*** End of inlined file: juce_Sampler.cpp ***/
  29450. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29451. BEGIN_JUCE_NAMESPACE
  29452. SynthesiserSound::SynthesiserSound()
  29453. {
  29454. }
  29455. SynthesiserSound::~SynthesiserSound()
  29456. {
  29457. }
  29458. SynthesiserVoice::SynthesiserVoice()
  29459. : currentSampleRate (44100.0),
  29460. currentlyPlayingNote (-1),
  29461. noteOnTime (0),
  29462. currentlyPlayingSound (0)
  29463. {
  29464. }
  29465. SynthesiserVoice::~SynthesiserVoice()
  29466. {
  29467. }
  29468. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29469. {
  29470. return currentlyPlayingSound != 0
  29471. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29472. }
  29473. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29474. {
  29475. currentSampleRate = newRate;
  29476. }
  29477. void SynthesiserVoice::clearCurrentNote()
  29478. {
  29479. currentlyPlayingNote = -1;
  29480. currentlyPlayingSound = 0;
  29481. }
  29482. Synthesiser::Synthesiser()
  29483. : sampleRate (0),
  29484. lastNoteOnCounter (0),
  29485. shouldStealNotes (true)
  29486. {
  29487. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29488. lastPitchWheelValues[i] = 0x2000;
  29489. }
  29490. Synthesiser::~Synthesiser()
  29491. {
  29492. }
  29493. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29494. {
  29495. const ScopedLock sl (lock);
  29496. return voices [index];
  29497. }
  29498. void Synthesiser::clearVoices()
  29499. {
  29500. const ScopedLock sl (lock);
  29501. voices.clear();
  29502. }
  29503. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29504. {
  29505. const ScopedLock sl (lock);
  29506. voices.add (newVoice);
  29507. }
  29508. void Synthesiser::removeVoice (const int index)
  29509. {
  29510. const ScopedLock sl (lock);
  29511. voices.remove (index);
  29512. }
  29513. void Synthesiser::clearSounds()
  29514. {
  29515. const ScopedLock sl (lock);
  29516. sounds.clear();
  29517. }
  29518. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29519. {
  29520. const ScopedLock sl (lock);
  29521. sounds.add (newSound);
  29522. }
  29523. void Synthesiser::removeSound (const int index)
  29524. {
  29525. const ScopedLock sl (lock);
  29526. sounds.remove (index);
  29527. }
  29528. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29529. {
  29530. shouldStealNotes = shouldStealNotes_;
  29531. }
  29532. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29533. {
  29534. if (sampleRate != newRate)
  29535. {
  29536. const ScopedLock sl (lock);
  29537. allNotesOff (0, false);
  29538. sampleRate = newRate;
  29539. for (int i = voices.size(); --i >= 0;)
  29540. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29541. }
  29542. }
  29543. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29544. const MidiBuffer& midiData,
  29545. int startSample,
  29546. int numSamples)
  29547. {
  29548. // must set the sample rate before using this!
  29549. jassert (sampleRate != 0);
  29550. const ScopedLock sl (lock);
  29551. MidiBuffer::Iterator midiIterator (midiData);
  29552. midiIterator.setNextSamplePosition (startSample);
  29553. MidiMessage m (0xf4, 0.0);
  29554. while (numSamples > 0)
  29555. {
  29556. int midiEventPos;
  29557. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29558. && midiEventPos < startSample + numSamples;
  29559. const int numThisTime = useEvent ? midiEventPos - startSample
  29560. : numSamples;
  29561. if (numThisTime > 0)
  29562. {
  29563. for (int i = voices.size(); --i >= 0;)
  29564. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29565. }
  29566. if (useEvent)
  29567. {
  29568. if (m.isNoteOn())
  29569. {
  29570. const int channel = m.getChannel();
  29571. noteOn (channel,
  29572. m.getNoteNumber(),
  29573. m.getFloatVelocity());
  29574. }
  29575. else if (m.isNoteOff())
  29576. {
  29577. noteOff (m.getChannel(),
  29578. m.getNoteNumber(),
  29579. true);
  29580. }
  29581. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29582. {
  29583. allNotesOff (m.getChannel(), true);
  29584. }
  29585. else if (m.isPitchWheel())
  29586. {
  29587. const int channel = m.getChannel();
  29588. const int wheelPos = m.getPitchWheelValue();
  29589. lastPitchWheelValues [channel - 1] = wheelPos;
  29590. handlePitchWheel (channel, wheelPos);
  29591. }
  29592. else if (m.isController())
  29593. {
  29594. handleController (m.getChannel(),
  29595. m.getControllerNumber(),
  29596. m.getControllerValue());
  29597. }
  29598. }
  29599. startSample += numThisTime;
  29600. numSamples -= numThisTime;
  29601. }
  29602. }
  29603. void Synthesiser::noteOn (const int midiChannel,
  29604. const int midiNoteNumber,
  29605. const float velocity)
  29606. {
  29607. const ScopedLock sl (lock);
  29608. for (int i = sounds.size(); --i >= 0;)
  29609. {
  29610. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29611. if (sound->appliesToNote (midiNoteNumber)
  29612. && sound->appliesToChannel (midiChannel))
  29613. {
  29614. startVoice (findFreeVoice (sound, shouldStealNotes),
  29615. sound, midiChannel, midiNoteNumber, velocity);
  29616. }
  29617. }
  29618. }
  29619. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29620. SynthesiserSound* const sound,
  29621. const int midiChannel,
  29622. const int midiNoteNumber,
  29623. const float velocity)
  29624. {
  29625. if (voice != 0 && sound != 0)
  29626. {
  29627. if (voice->currentlyPlayingSound != 0)
  29628. voice->stopNote (false);
  29629. voice->startNote (midiNoteNumber,
  29630. velocity,
  29631. sound,
  29632. lastPitchWheelValues [midiChannel - 1]);
  29633. voice->currentlyPlayingNote = midiNoteNumber;
  29634. voice->noteOnTime = ++lastNoteOnCounter;
  29635. voice->currentlyPlayingSound = sound;
  29636. }
  29637. }
  29638. void Synthesiser::noteOff (const int midiChannel,
  29639. const int midiNoteNumber,
  29640. const bool allowTailOff)
  29641. {
  29642. const ScopedLock sl (lock);
  29643. for (int i = voices.size(); --i >= 0;)
  29644. {
  29645. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29646. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29647. {
  29648. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29649. if (sound != 0
  29650. && sound->appliesToNote (midiNoteNumber)
  29651. && sound->appliesToChannel (midiChannel))
  29652. {
  29653. voice->stopNote (allowTailOff);
  29654. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29655. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29656. }
  29657. }
  29658. }
  29659. }
  29660. void Synthesiser::allNotesOff (const int midiChannel,
  29661. const bool allowTailOff)
  29662. {
  29663. const ScopedLock sl (lock);
  29664. for (int i = voices.size(); --i >= 0;)
  29665. {
  29666. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29667. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29668. voice->stopNote (allowTailOff);
  29669. }
  29670. }
  29671. void Synthesiser::handlePitchWheel (const int midiChannel,
  29672. const int wheelValue)
  29673. {
  29674. const ScopedLock sl (lock);
  29675. for (int i = voices.size(); --i >= 0;)
  29676. {
  29677. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29678. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29679. {
  29680. voice->pitchWheelMoved (wheelValue);
  29681. }
  29682. }
  29683. }
  29684. void Synthesiser::handleController (const int midiChannel,
  29685. const int controllerNumber,
  29686. const int controllerValue)
  29687. {
  29688. const ScopedLock sl (lock);
  29689. for (int i = voices.size(); --i >= 0;)
  29690. {
  29691. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29692. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29693. voice->controllerMoved (controllerNumber, controllerValue);
  29694. }
  29695. }
  29696. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29697. const bool stealIfNoneAvailable) const
  29698. {
  29699. const ScopedLock sl (lock);
  29700. for (int i = voices.size(); --i >= 0;)
  29701. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29702. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29703. return voices.getUnchecked (i);
  29704. if (stealIfNoneAvailable)
  29705. {
  29706. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29707. SynthesiserVoice* oldest = 0;
  29708. for (int i = voices.size(); --i >= 0;)
  29709. {
  29710. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29711. if (voice->canPlaySound (soundToPlay)
  29712. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29713. oldest = voice;
  29714. }
  29715. jassert (oldest != 0);
  29716. return oldest;
  29717. }
  29718. return 0;
  29719. }
  29720. END_JUCE_NAMESPACE
  29721. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29722. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29723. BEGIN_JUCE_NAMESPACE
  29724. ActionBroadcaster::ActionBroadcaster() throw()
  29725. {
  29726. // are you trying to create this object before or after juce has been intialised??
  29727. jassert (MessageManager::instance != 0);
  29728. }
  29729. ActionBroadcaster::~ActionBroadcaster()
  29730. {
  29731. // all event-based objects must be deleted BEFORE juce is shut down!
  29732. jassert (MessageManager::instance != 0);
  29733. }
  29734. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29735. {
  29736. actionListenerList.addActionListener (listener);
  29737. }
  29738. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29739. {
  29740. jassert (actionListenerList.isValidMessageListener());
  29741. if (actionListenerList.isValidMessageListener())
  29742. actionListenerList.removeActionListener (listener);
  29743. }
  29744. void ActionBroadcaster::removeAllActionListeners()
  29745. {
  29746. actionListenerList.removeAllActionListeners();
  29747. }
  29748. void ActionBroadcaster::sendActionMessage (const String& message) const
  29749. {
  29750. actionListenerList.sendActionMessage (message);
  29751. }
  29752. END_JUCE_NAMESPACE
  29753. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29754. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29755. BEGIN_JUCE_NAMESPACE
  29756. // special message of our own with a string in it
  29757. class ActionMessage : public Message
  29758. {
  29759. public:
  29760. const String message;
  29761. ActionMessage (const String& messageText,
  29762. void* const listener_) throw()
  29763. : message (messageText)
  29764. {
  29765. pointerParameter = listener_;
  29766. }
  29767. ~ActionMessage() throw()
  29768. {
  29769. }
  29770. private:
  29771. ActionMessage (const ActionMessage&);
  29772. ActionMessage& operator= (const ActionMessage&);
  29773. };
  29774. ActionListenerList::ActionListenerList() throw()
  29775. {
  29776. }
  29777. ActionListenerList::~ActionListenerList() throw()
  29778. {
  29779. }
  29780. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29781. {
  29782. const ScopedLock sl (actionListenerLock_);
  29783. jassert (listener != 0);
  29784. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29785. if (listener != 0)
  29786. actionListeners_.add (listener);
  29787. }
  29788. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29789. {
  29790. const ScopedLock sl (actionListenerLock_);
  29791. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29792. actionListeners_.removeValue (listener);
  29793. }
  29794. void ActionListenerList::removeAllActionListeners() throw()
  29795. {
  29796. const ScopedLock sl (actionListenerLock_);
  29797. actionListeners_.clear();
  29798. }
  29799. void ActionListenerList::sendActionMessage (const String& message) const
  29800. {
  29801. const ScopedLock sl (actionListenerLock_);
  29802. for (int i = actionListeners_.size(); --i >= 0;)
  29803. {
  29804. postMessage (new ActionMessage (message,
  29805. (ActionListener*) actionListeners_.getUnchecked(i)));
  29806. }
  29807. }
  29808. void ActionListenerList::handleMessage (const Message& message)
  29809. {
  29810. const ActionMessage& am = (const ActionMessage&) message;
  29811. if (actionListeners_.contains (am.pointerParameter))
  29812. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29813. }
  29814. END_JUCE_NAMESPACE
  29815. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29816. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29817. BEGIN_JUCE_NAMESPACE
  29818. AsyncUpdater::AsyncUpdater() throw()
  29819. : asyncMessagePending (false)
  29820. {
  29821. internalAsyncHandler.owner = this;
  29822. }
  29823. AsyncUpdater::~AsyncUpdater()
  29824. {
  29825. }
  29826. void AsyncUpdater::triggerAsyncUpdate() throw()
  29827. {
  29828. if (! asyncMessagePending)
  29829. {
  29830. asyncMessagePending = true;
  29831. internalAsyncHandler.postMessage (new Message());
  29832. }
  29833. }
  29834. void AsyncUpdater::cancelPendingUpdate() throw()
  29835. {
  29836. asyncMessagePending = false;
  29837. }
  29838. void AsyncUpdater::handleUpdateNowIfNeeded()
  29839. {
  29840. if (asyncMessagePending)
  29841. {
  29842. asyncMessagePending = false;
  29843. handleAsyncUpdate();
  29844. }
  29845. }
  29846. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29847. {
  29848. owner->handleUpdateNowIfNeeded();
  29849. }
  29850. END_JUCE_NAMESPACE
  29851. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29852. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29853. BEGIN_JUCE_NAMESPACE
  29854. ChangeBroadcaster::ChangeBroadcaster() throw()
  29855. {
  29856. // are you trying to create this object before or after juce has been intialised??
  29857. jassert (MessageManager::instance != 0);
  29858. }
  29859. ChangeBroadcaster::~ChangeBroadcaster()
  29860. {
  29861. // all event-based objects must be deleted BEFORE juce is shut down!
  29862. jassert (MessageManager::instance != 0);
  29863. }
  29864. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29865. {
  29866. changeListenerList.addChangeListener (listener);
  29867. }
  29868. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29869. {
  29870. jassert (changeListenerList.isValidMessageListener());
  29871. if (changeListenerList.isValidMessageListener())
  29872. changeListenerList.removeChangeListener (listener);
  29873. }
  29874. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29875. {
  29876. changeListenerList.removeAllChangeListeners();
  29877. }
  29878. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29879. {
  29880. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29881. }
  29882. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29883. {
  29884. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29885. }
  29886. void ChangeBroadcaster::dispatchPendingMessages()
  29887. {
  29888. changeListenerList.dispatchPendingMessages();
  29889. }
  29890. END_JUCE_NAMESPACE
  29891. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29892. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29893. BEGIN_JUCE_NAMESPACE
  29894. ChangeListenerList::ChangeListenerList() throw()
  29895. : lastChangedObject (0),
  29896. messagePending (false)
  29897. {
  29898. }
  29899. ChangeListenerList::~ChangeListenerList() throw()
  29900. {
  29901. }
  29902. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29903. {
  29904. const ScopedLock sl (lock);
  29905. jassert (listener != 0);
  29906. if (listener != 0)
  29907. listeners.add (listener);
  29908. }
  29909. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29910. {
  29911. const ScopedLock sl (lock);
  29912. listeners.removeValue (listener);
  29913. }
  29914. void ChangeListenerList::removeAllChangeListeners() throw()
  29915. {
  29916. const ScopedLock sl (lock);
  29917. listeners.clear();
  29918. }
  29919. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29920. {
  29921. const ScopedLock sl (lock);
  29922. if ((! messagePending) && (listeners.size() > 0))
  29923. {
  29924. lastChangedObject = objectThatHasChanged;
  29925. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29926. messagePending = true;
  29927. }
  29928. }
  29929. void ChangeListenerList::handleMessage (const Message& message)
  29930. {
  29931. sendSynchronousChangeMessage (message.pointerParameter);
  29932. }
  29933. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29934. {
  29935. const ScopedLock sl (lock);
  29936. messagePending = false;
  29937. for (int i = listeners.size(); --i >= 0;)
  29938. {
  29939. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  29940. {
  29941. const ScopedUnlock tempUnlocker (lock);
  29942. l->changeListenerCallback (objectThatHasChanged);
  29943. }
  29944. i = jmin (i, listeners.size());
  29945. }
  29946. }
  29947. void ChangeListenerList::dispatchPendingMessages()
  29948. {
  29949. if (messagePending)
  29950. sendSynchronousChangeMessage (lastChangedObject);
  29951. }
  29952. END_JUCE_NAMESPACE
  29953. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  29954. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  29955. BEGIN_JUCE_NAMESPACE
  29956. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29957. const uint32 magicMessageHeaderNumber)
  29958. : Thread ("Juce IPC connection"),
  29959. callbackConnectionState (false),
  29960. useMessageThread (callbacksOnMessageThread),
  29961. magicMessageHeader (magicMessageHeaderNumber),
  29962. pipeReceiveMessageTimeout (-1)
  29963. {
  29964. }
  29965. InterprocessConnection::~InterprocessConnection()
  29966. {
  29967. callbackConnectionState = false;
  29968. disconnect();
  29969. }
  29970. bool InterprocessConnection::connectToSocket (const String& hostName,
  29971. const int portNumber,
  29972. const int timeOutMillisecs)
  29973. {
  29974. disconnect();
  29975. const ScopedLock sl (pipeAndSocketLock);
  29976. socket = new StreamingSocket();
  29977. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29978. {
  29979. connectionMadeInt();
  29980. startThread();
  29981. return true;
  29982. }
  29983. else
  29984. {
  29985. socket = 0;
  29986. return false;
  29987. }
  29988. }
  29989. bool InterprocessConnection::connectToPipe (const String& pipeName,
  29990. const int pipeReceiveMessageTimeoutMs)
  29991. {
  29992. disconnect();
  29993. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29994. if (newPipe->openExisting (pipeName))
  29995. {
  29996. const ScopedLock sl (pipeAndSocketLock);
  29997. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29998. initialiseWithPipe (newPipe.release());
  29999. return true;
  30000. }
  30001. return false;
  30002. }
  30003. bool InterprocessConnection::createPipe (const String& pipeName,
  30004. const int pipeReceiveMessageTimeoutMs)
  30005. {
  30006. disconnect();
  30007. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30008. if (newPipe->createNewPipe (pipeName))
  30009. {
  30010. const ScopedLock sl (pipeAndSocketLock);
  30011. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30012. initialiseWithPipe (newPipe.release());
  30013. return true;
  30014. }
  30015. return false;
  30016. }
  30017. void InterprocessConnection::disconnect()
  30018. {
  30019. if (socket != 0)
  30020. socket->close();
  30021. if (pipe != 0)
  30022. {
  30023. pipe->cancelPendingReads();
  30024. pipe->close();
  30025. }
  30026. stopThread (4000);
  30027. {
  30028. const ScopedLock sl (pipeAndSocketLock);
  30029. socket = 0;
  30030. pipe = 0;
  30031. }
  30032. connectionLostInt();
  30033. }
  30034. bool InterprocessConnection::isConnected() const
  30035. {
  30036. const ScopedLock sl (pipeAndSocketLock);
  30037. return ((socket != 0 && socket->isConnected())
  30038. || (pipe != 0 && pipe->isOpen()))
  30039. && isThreadRunning();
  30040. }
  30041. const String InterprocessConnection::getConnectedHostName() const
  30042. {
  30043. if (pipe != 0)
  30044. {
  30045. return "localhost";
  30046. }
  30047. else if (socket != 0)
  30048. {
  30049. if (! socket->isLocal())
  30050. return socket->getHostName();
  30051. return "localhost";
  30052. }
  30053. return String::empty;
  30054. }
  30055. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  30056. {
  30057. uint32 messageHeader[2];
  30058. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  30059. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  30060. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  30061. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  30062. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  30063. size_t bytesWritten = 0;
  30064. const ScopedLock sl (pipeAndSocketLock);
  30065. if (socket != 0)
  30066. {
  30067. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  30068. }
  30069. else if (pipe != 0)
  30070. {
  30071. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  30072. }
  30073. if (bytesWritten < 0)
  30074. {
  30075. // error..
  30076. return false;
  30077. }
  30078. return (bytesWritten == messageData.getSize());
  30079. }
  30080. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  30081. {
  30082. jassert (socket == 0);
  30083. socket = socket_;
  30084. connectionMadeInt();
  30085. startThread();
  30086. }
  30087. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  30088. {
  30089. jassert (pipe == 0);
  30090. pipe = pipe_;
  30091. connectionMadeInt();
  30092. startThread();
  30093. }
  30094. const int messageMagicNumber = 0xb734128b;
  30095. void InterprocessConnection::handleMessage (const Message& message)
  30096. {
  30097. if (message.intParameter1 == messageMagicNumber)
  30098. {
  30099. switch (message.intParameter2)
  30100. {
  30101. case 0:
  30102. {
  30103. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30104. messageReceived (*data);
  30105. break;
  30106. }
  30107. case 1:
  30108. connectionMade();
  30109. break;
  30110. case 2:
  30111. connectionLost();
  30112. break;
  30113. }
  30114. }
  30115. }
  30116. void InterprocessConnection::connectionMadeInt()
  30117. {
  30118. if (! callbackConnectionState)
  30119. {
  30120. callbackConnectionState = true;
  30121. if (useMessageThread)
  30122. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30123. else
  30124. connectionMade();
  30125. }
  30126. }
  30127. void InterprocessConnection::connectionLostInt()
  30128. {
  30129. if (callbackConnectionState)
  30130. {
  30131. callbackConnectionState = false;
  30132. if (useMessageThread)
  30133. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30134. else
  30135. connectionLost();
  30136. }
  30137. }
  30138. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30139. {
  30140. jassert (callbackConnectionState);
  30141. if (useMessageThread)
  30142. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30143. else
  30144. messageReceived (data);
  30145. }
  30146. bool InterprocessConnection::readNextMessageInt()
  30147. {
  30148. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30149. uint32 messageHeader[2];
  30150. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30151. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30152. if (bytes == sizeof (messageHeader)
  30153. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30154. {
  30155. const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30156. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30157. {
  30158. MemoryBlock messageData (bytesInMessage, true);
  30159. int bytesRead = 0;
  30160. while (bytesRead < bytesInMessage)
  30161. {
  30162. if (threadShouldExit())
  30163. return false;
  30164. const int numThisTime = jmin (bytesInMessage, 65536);
  30165. const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true)
  30166. : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime,
  30167. pipeReceiveMessageTimeout);
  30168. if (bytesIn <= 0)
  30169. break;
  30170. bytesRead += bytesIn;
  30171. }
  30172. if (bytesRead >= 0)
  30173. deliverDataInt (messageData);
  30174. }
  30175. }
  30176. else if (bytes < 0)
  30177. {
  30178. {
  30179. const ScopedLock sl (pipeAndSocketLock);
  30180. socket = 0;
  30181. }
  30182. connectionLostInt();
  30183. return false;
  30184. }
  30185. return true;
  30186. }
  30187. void InterprocessConnection::run()
  30188. {
  30189. while (! threadShouldExit())
  30190. {
  30191. if (socket != 0)
  30192. {
  30193. const int ready = socket->waitUntilReady (true, 0);
  30194. if (ready < 0)
  30195. {
  30196. {
  30197. const ScopedLock sl (pipeAndSocketLock);
  30198. socket = 0;
  30199. }
  30200. connectionLostInt();
  30201. break;
  30202. }
  30203. else if (ready > 0)
  30204. {
  30205. if (! readNextMessageInt())
  30206. break;
  30207. }
  30208. else
  30209. {
  30210. Thread::sleep (2);
  30211. }
  30212. }
  30213. else if (pipe != 0)
  30214. {
  30215. if (! pipe->isOpen())
  30216. {
  30217. {
  30218. const ScopedLock sl (pipeAndSocketLock);
  30219. pipe = 0;
  30220. }
  30221. connectionLostInt();
  30222. break;
  30223. }
  30224. else
  30225. {
  30226. if (! readNextMessageInt())
  30227. break;
  30228. }
  30229. }
  30230. else
  30231. {
  30232. break;
  30233. }
  30234. }
  30235. }
  30236. END_JUCE_NAMESPACE
  30237. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30238. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30239. BEGIN_JUCE_NAMESPACE
  30240. InterprocessConnectionServer::InterprocessConnectionServer()
  30241. : Thread ("Juce IPC server")
  30242. {
  30243. }
  30244. InterprocessConnectionServer::~InterprocessConnectionServer()
  30245. {
  30246. stop();
  30247. }
  30248. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30249. {
  30250. stop();
  30251. socket = new StreamingSocket();
  30252. if (socket->createListener (portNumber))
  30253. {
  30254. startThread();
  30255. return true;
  30256. }
  30257. socket = 0;
  30258. return false;
  30259. }
  30260. void InterprocessConnectionServer::stop()
  30261. {
  30262. signalThreadShouldExit();
  30263. if (socket != 0)
  30264. socket->close();
  30265. stopThread (4000);
  30266. socket = 0;
  30267. }
  30268. void InterprocessConnectionServer::run()
  30269. {
  30270. while ((! threadShouldExit()) && socket != 0)
  30271. {
  30272. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30273. if (clientSocket != 0)
  30274. {
  30275. InterprocessConnection* newConnection = createConnectionObject();
  30276. if (newConnection != 0)
  30277. newConnection->initialiseWithSocket (clientSocket.release());
  30278. }
  30279. }
  30280. }
  30281. END_JUCE_NAMESPACE
  30282. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30283. /*** Start of inlined file: juce_Message.cpp ***/
  30284. BEGIN_JUCE_NAMESPACE
  30285. Message::Message() throw()
  30286. {
  30287. }
  30288. Message::~Message() throw()
  30289. {
  30290. }
  30291. Message::Message (const int intParameter1_,
  30292. const int intParameter2_,
  30293. const int intParameter3_,
  30294. void* const pointerParameter_) throw()
  30295. : intParameter1 (intParameter1_),
  30296. intParameter2 (intParameter2_),
  30297. intParameter3 (intParameter3_),
  30298. pointerParameter (pointerParameter_)
  30299. {
  30300. }
  30301. END_JUCE_NAMESPACE
  30302. /*** End of inlined file: juce_Message.cpp ***/
  30303. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30304. BEGIN_JUCE_NAMESPACE
  30305. MessageListener::MessageListener() throw()
  30306. {
  30307. // are you trying to create a messagelistener before or after juce has been intialised??
  30308. jassert (MessageManager::instance != 0);
  30309. if (MessageManager::instance != 0)
  30310. MessageManager::instance->messageListeners.add (this);
  30311. }
  30312. MessageListener::~MessageListener()
  30313. {
  30314. if (MessageManager::instance != 0)
  30315. MessageManager::instance->messageListeners.removeValue (this);
  30316. }
  30317. void MessageListener::postMessage (Message* const message) const throw()
  30318. {
  30319. message->messageRecipient = const_cast <MessageListener*> (this);
  30320. if (MessageManager::instance == 0)
  30321. MessageManager::getInstance();
  30322. MessageManager::instance->postMessageToQueue (message);
  30323. }
  30324. bool MessageListener::isValidMessageListener() const throw()
  30325. {
  30326. return (MessageManager::instance != 0)
  30327. && MessageManager::instance->messageListeners.contains (this);
  30328. }
  30329. END_JUCE_NAMESPACE
  30330. /*** End of inlined file: juce_MessageListener.cpp ***/
  30331. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30332. BEGIN_JUCE_NAMESPACE
  30333. // platform-specific functions..
  30334. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30335. bool juce_postMessageToSystemQueue (void* message);
  30336. MessageManager* MessageManager::instance = 0;
  30337. static const int quitMessageId = 0xfffff321;
  30338. MessageManager::MessageManager() throw()
  30339. : quitMessagePosted (false),
  30340. quitMessageReceived (false),
  30341. threadWithLock (0)
  30342. {
  30343. messageThreadId = Thread::getCurrentThreadId();
  30344. }
  30345. MessageManager::~MessageManager() throw()
  30346. {
  30347. broadcastListeners = 0;
  30348. doPlatformSpecificShutdown();
  30349. jassert (instance == this);
  30350. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30351. }
  30352. MessageManager* MessageManager::getInstance() throw()
  30353. {
  30354. if (instance == 0)
  30355. {
  30356. instance = new MessageManager();
  30357. doPlatformSpecificInitialisation();
  30358. }
  30359. return instance;
  30360. }
  30361. void MessageManager::postMessageToQueue (Message* const message)
  30362. {
  30363. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30364. delete message;
  30365. }
  30366. CallbackMessage::CallbackMessage() throw() {}
  30367. CallbackMessage::~CallbackMessage() throw() {}
  30368. void CallbackMessage::post()
  30369. {
  30370. if (MessageManager::instance != 0)
  30371. MessageManager::instance->postCallbackMessage (this);
  30372. }
  30373. void MessageManager::postCallbackMessage (Message* const message)
  30374. {
  30375. message->messageRecipient = 0;
  30376. postMessageToQueue (message);
  30377. }
  30378. // not for public use..
  30379. void MessageManager::deliverMessage (void* message)
  30380. {
  30381. const ScopedPointer <Message> m ((Message*) message);
  30382. MessageListener* const recipient = m->messageRecipient;
  30383. JUCE_TRY
  30384. {
  30385. if (messageListeners.contains (recipient))
  30386. {
  30387. recipient->handleMessage (*m);
  30388. }
  30389. else if (recipient == 0)
  30390. {
  30391. if (m->intParameter1 == quitMessageId)
  30392. {
  30393. quitMessageReceived = true;
  30394. }
  30395. else
  30396. {
  30397. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30398. if (cm != 0)
  30399. cm->messageCallback();
  30400. }
  30401. }
  30402. }
  30403. JUCE_CATCH_EXCEPTION
  30404. }
  30405. #if ! (JUCE_MAC || JUCE_IPHONE)
  30406. void MessageManager::runDispatchLoop()
  30407. {
  30408. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30409. runDispatchLoopUntil (-1);
  30410. }
  30411. void MessageManager::stopDispatchLoop()
  30412. {
  30413. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30414. m->messageRecipient = 0;
  30415. postMessageToQueue (m);
  30416. quitMessagePosted = true;
  30417. }
  30418. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30419. {
  30420. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30421. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30422. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30423. && ! quitMessageReceived)
  30424. {
  30425. JUCE_TRY
  30426. {
  30427. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30428. {
  30429. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30430. if (msToWait > 0)
  30431. Thread::sleep (jmin (5, msToWait));
  30432. }
  30433. }
  30434. JUCE_CATCH_EXCEPTION
  30435. }
  30436. return ! quitMessageReceived;
  30437. }
  30438. #endif
  30439. void MessageManager::deliverBroadcastMessage (const String& value)
  30440. {
  30441. if (broadcastListeners != 0)
  30442. broadcastListeners->sendActionMessage (value);
  30443. }
  30444. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30445. {
  30446. if (broadcastListeners == 0)
  30447. broadcastListeners = new ActionListenerList();
  30448. broadcastListeners->addActionListener (listener);
  30449. }
  30450. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30451. {
  30452. if (broadcastListeners != 0)
  30453. broadcastListeners->removeActionListener (listener);
  30454. }
  30455. bool MessageManager::isThisTheMessageThread() const throw()
  30456. {
  30457. return Thread::getCurrentThreadId() == messageThreadId;
  30458. }
  30459. void MessageManager::setCurrentThreadAsMessageThread()
  30460. {
  30461. if (messageThreadId != Thread::getCurrentThreadId())
  30462. {
  30463. messageThreadId = Thread::getCurrentThreadId();
  30464. // This is needed on windows to make sure the message window is created by this thread
  30465. doPlatformSpecificShutdown();
  30466. doPlatformSpecificInitialisation();
  30467. }
  30468. }
  30469. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30470. {
  30471. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30472. return thisThread == messageThreadId || thisThread == threadWithLock;
  30473. }
  30474. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30475. {
  30476. public:
  30477. SharedEvents() {}
  30478. ~SharedEvents() {}
  30479. WaitableEvent lockedEvent, releaseEvent;
  30480. private:
  30481. SharedEvents (const SharedEvents&);
  30482. SharedEvents& operator= (const SharedEvents&);
  30483. };
  30484. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30485. {
  30486. public:
  30487. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30488. ~BlockingMessage() throw() {}
  30489. void messageCallback()
  30490. {
  30491. events->lockedEvent.signal();
  30492. events->releaseEvent.wait();
  30493. }
  30494. juce_UseDebuggingNewOperator
  30495. private:
  30496. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30497. BlockingMessage (const BlockingMessage&);
  30498. BlockingMessage& operator= (const BlockingMessage&);
  30499. };
  30500. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30501. : sharedEvents (0),
  30502. locked (false)
  30503. {
  30504. init (threadToCheck, 0);
  30505. }
  30506. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30507. : sharedEvents (0),
  30508. locked (false)
  30509. {
  30510. init (0, jobToCheckForExitSignal);
  30511. }
  30512. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30513. {
  30514. if (MessageManager::instance != 0)
  30515. {
  30516. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30517. {
  30518. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30519. }
  30520. else
  30521. {
  30522. if (threadToCheck == 0 && job == 0)
  30523. {
  30524. MessageManager::instance->lockingLock.enter();
  30525. }
  30526. else
  30527. {
  30528. while (! MessageManager::instance->lockingLock.tryEnter())
  30529. {
  30530. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30531. || (job != 0 && job->shouldExit()))
  30532. return;
  30533. Thread::sleep (1);
  30534. }
  30535. }
  30536. sharedEvents = new SharedEvents();
  30537. sharedEvents->incReferenceCount();
  30538. (new BlockingMessage (sharedEvents))->post();
  30539. while (! sharedEvents->lockedEvent.wait (50))
  30540. {
  30541. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30542. || (job != 0 && job->shouldExit()))
  30543. {
  30544. sharedEvents->releaseEvent.signal();
  30545. sharedEvents->decReferenceCount();
  30546. sharedEvents = 0;
  30547. MessageManager::instance->lockingLock.exit();
  30548. return;
  30549. }
  30550. }
  30551. jassert (MessageManager::instance->threadWithLock == 0);
  30552. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30553. locked = true;
  30554. }
  30555. }
  30556. }
  30557. MessageManagerLock::~MessageManagerLock() throw()
  30558. {
  30559. if (sharedEvents != 0)
  30560. {
  30561. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30562. sharedEvents->releaseEvent.signal();
  30563. sharedEvents->decReferenceCount();
  30564. if (MessageManager::instance != 0)
  30565. {
  30566. MessageManager::instance->threadWithLock = 0;
  30567. MessageManager::instance->lockingLock.exit();
  30568. }
  30569. }
  30570. }
  30571. END_JUCE_NAMESPACE
  30572. /*** End of inlined file: juce_MessageManager.cpp ***/
  30573. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30574. BEGIN_JUCE_NAMESPACE
  30575. class MultiTimer::MultiTimerCallback : public Timer
  30576. {
  30577. public:
  30578. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30579. : timerId (timerId_),
  30580. owner (owner_)
  30581. {
  30582. }
  30583. ~MultiTimerCallback()
  30584. {
  30585. }
  30586. void timerCallback()
  30587. {
  30588. owner.timerCallback (timerId);
  30589. }
  30590. const int timerId;
  30591. private:
  30592. MultiTimer& owner;
  30593. };
  30594. MultiTimer::MultiTimer() throw()
  30595. {
  30596. }
  30597. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30598. {
  30599. }
  30600. MultiTimer::~MultiTimer()
  30601. {
  30602. const ScopedLock sl (timerListLock);
  30603. timers.clear();
  30604. }
  30605. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30606. {
  30607. const ScopedLock sl (timerListLock);
  30608. for (int i = timers.size(); --i >= 0;)
  30609. {
  30610. MultiTimerCallback* const t = timers.getUnchecked(i);
  30611. if (t->timerId == timerId)
  30612. {
  30613. t->startTimer (intervalInMilliseconds);
  30614. return;
  30615. }
  30616. }
  30617. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30618. timers.add (newTimer);
  30619. newTimer->startTimer (intervalInMilliseconds);
  30620. }
  30621. void MultiTimer::stopTimer (const int timerId) throw()
  30622. {
  30623. const ScopedLock sl (timerListLock);
  30624. for (int i = timers.size(); --i >= 0;)
  30625. {
  30626. MultiTimerCallback* const t = timers.getUnchecked(i);
  30627. if (t->timerId == timerId)
  30628. t->stopTimer();
  30629. }
  30630. }
  30631. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30632. {
  30633. const ScopedLock sl (timerListLock);
  30634. for (int i = timers.size(); --i >= 0;)
  30635. {
  30636. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30637. if (t->timerId == timerId)
  30638. return t->isTimerRunning();
  30639. }
  30640. return false;
  30641. }
  30642. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30643. {
  30644. const ScopedLock sl (timerListLock);
  30645. for (int i = timers.size(); --i >= 0;)
  30646. {
  30647. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30648. if (t->timerId == timerId)
  30649. return t->getTimerInterval();
  30650. }
  30651. return 0;
  30652. }
  30653. END_JUCE_NAMESPACE
  30654. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30655. /*** Start of inlined file: juce_Timer.cpp ***/
  30656. BEGIN_JUCE_NAMESPACE
  30657. class InternalTimerThread : private Thread,
  30658. private MessageListener,
  30659. private DeletedAtShutdown,
  30660. private AsyncUpdater
  30661. {
  30662. public:
  30663. InternalTimerThread()
  30664. : Thread ("Juce Timer"),
  30665. firstTimer (0),
  30666. callbackNeeded (false)
  30667. {
  30668. triggerAsyncUpdate();
  30669. }
  30670. ~InternalTimerThread() throw()
  30671. {
  30672. stopThread (4000);
  30673. jassert (instance == this || instance == 0);
  30674. if (instance == this)
  30675. instance = 0;
  30676. }
  30677. void run()
  30678. {
  30679. uint32 lastTime = Time::getMillisecondCounter();
  30680. while (! threadShouldExit())
  30681. {
  30682. const uint32 now = Time::getMillisecondCounter();
  30683. if (now <= lastTime)
  30684. {
  30685. wait (2);
  30686. continue;
  30687. }
  30688. const int elapsed = now - lastTime;
  30689. lastTime = now;
  30690. int timeUntilFirstTimer = 1000;
  30691. {
  30692. const ScopedLock sl (lock);
  30693. decrementAllCounters (elapsed);
  30694. if (firstTimer != 0)
  30695. timeUntilFirstTimer = firstTimer->countdownMs;
  30696. }
  30697. if (timeUntilFirstTimer <= 0)
  30698. {
  30699. if (callbackNeeded.set (true))
  30700. {
  30701. postMessage (new Message());
  30702. const uint32 messageDeliveryTimeout = now + 2000;
  30703. while (callbackNeeded.get())
  30704. {
  30705. wait (4);
  30706. if (threadShouldExit())
  30707. return;
  30708. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30709. break;
  30710. }
  30711. }
  30712. }
  30713. else
  30714. {
  30715. // don't wait for too long because running this loop also helps keep the
  30716. // Time::getApproximateMillisecondTimer value stay up-to-date
  30717. wait (jlimit (1, 50, timeUntilFirstTimer));
  30718. }
  30719. }
  30720. }
  30721. void callTimers()
  30722. {
  30723. const ScopedLock sl (lock);
  30724. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30725. {
  30726. Timer* const t = firstTimer;
  30727. t->countdownMs = t->periodMs;
  30728. removeTimer (t);
  30729. addTimer (t);
  30730. const ScopedUnlock ul (lock);
  30731. JUCE_TRY
  30732. {
  30733. t->timerCallback();
  30734. }
  30735. JUCE_CATCH_EXCEPTION
  30736. }
  30737. callbackNeeded.set (false);
  30738. }
  30739. void handleMessage (const Message&)
  30740. {
  30741. callTimers();
  30742. }
  30743. void callTimersSynchronously()
  30744. {
  30745. if (! isThreadRunning())
  30746. {
  30747. // (This is relied on by some plugins in cases where the MM has
  30748. // had to restart and the async callback never started)
  30749. cancelPendingUpdate();
  30750. triggerAsyncUpdate();
  30751. }
  30752. callTimers();
  30753. }
  30754. static void callAnyTimersSynchronously()
  30755. {
  30756. if (InternalTimerThread::instance != 0)
  30757. InternalTimerThread::instance->callTimersSynchronously();
  30758. }
  30759. static inline void add (Timer* const tim) throw()
  30760. {
  30761. if (instance == 0)
  30762. instance = new InternalTimerThread();
  30763. const ScopedLock sl (instance->lock);
  30764. instance->addTimer (tim);
  30765. }
  30766. static inline void remove (Timer* const tim) throw()
  30767. {
  30768. if (instance != 0)
  30769. {
  30770. const ScopedLock sl (instance->lock);
  30771. instance->removeTimer (tim);
  30772. }
  30773. }
  30774. static inline void resetCounter (Timer* const tim,
  30775. const int newCounter) throw()
  30776. {
  30777. if (instance != 0)
  30778. {
  30779. tim->countdownMs = newCounter;
  30780. tim->periodMs = newCounter;
  30781. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30782. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30783. {
  30784. const ScopedLock sl (instance->lock);
  30785. instance->removeTimer (tim);
  30786. instance->addTimer (tim);
  30787. }
  30788. }
  30789. }
  30790. private:
  30791. friend class Timer;
  30792. static InternalTimerThread* instance;
  30793. static CriticalSection lock;
  30794. Timer* volatile firstTimer;
  30795. class AtomicBool
  30796. {
  30797. public:
  30798. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30799. ~AtomicBool() throw() {}
  30800. bool get() const throw() { return value != 0; }
  30801. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30802. private:
  30803. int32 value;
  30804. AtomicBool (const AtomicBool&);
  30805. AtomicBool& operator= (const AtomicBool&);
  30806. };
  30807. AtomicBool callbackNeeded;
  30808. void addTimer (Timer* const t) throw()
  30809. {
  30810. #ifdef JUCE_DEBUG
  30811. Timer* tt = firstTimer;
  30812. while (tt != 0)
  30813. {
  30814. // trying to add a timer that's already here - shouldn't get to this point,
  30815. // so if you get this assertion, let me know!
  30816. jassert (tt != t);
  30817. tt = tt->next;
  30818. }
  30819. jassert (t->previous == 0 && t->next == 0);
  30820. #endif
  30821. Timer* i = firstTimer;
  30822. if (i == 0 || i->countdownMs > t->countdownMs)
  30823. {
  30824. t->next = firstTimer;
  30825. firstTimer = t;
  30826. }
  30827. else
  30828. {
  30829. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30830. i = i->next;
  30831. jassert (i != 0);
  30832. t->next = i->next;
  30833. t->previous = i;
  30834. i->next = t;
  30835. }
  30836. if (t->next != 0)
  30837. t->next->previous = t;
  30838. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30839. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30840. notify();
  30841. }
  30842. void removeTimer (Timer* const t) throw()
  30843. {
  30844. #ifdef JUCE_DEBUG
  30845. Timer* tt = firstTimer;
  30846. bool found = false;
  30847. while (tt != 0)
  30848. {
  30849. if (tt == t)
  30850. {
  30851. found = true;
  30852. break;
  30853. }
  30854. tt = tt->next;
  30855. }
  30856. // trying to remove a timer that's not here - shouldn't get to this point,
  30857. // so if you get this assertion, let me know!
  30858. jassert (found);
  30859. #endif
  30860. if (t->previous != 0)
  30861. {
  30862. jassert (firstTimer != t);
  30863. t->previous->next = t->next;
  30864. }
  30865. else
  30866. {
  30867. jassert (firstTimer == t);
  30868. firstTimer = t->next;
  30869. }
  30870. if (t->next != 0)
  30871. t->next->previous = t->previous;
  30872. t->next = 0;
  30873. t->previous = 0;
  30874. }
  30875. void decrementAllCounters (const int numMillisecs) const
  30876. {
  30877. Timer* t = firstTimer;
  30878. while (t != 0)
  30879. {
  30880. t->countdownMs -= numMillisecs;
  30881. t = t->next;
  30882. }
  30883. }
  30884. void handleAsyncUpdate()
  30885. {
  30886. startThread (7);
  30887. }
  30888. InternalTimerThread (const InternalTimerThread&);
  30889. InternalTimerThread& operator= (const InternalTimerThread&);
  30890. };
  30891. InternalTimerThread* InternalTimerThread::instance = 0;
  30892. CriticalSection InternalTimerThread::lock;
  30893. void juce_callAnyTimersSynchronously()
  30894. {
  30895. InternalTimerThread::callAnyTimersSynchronously();
  30896. }
  30897. #ifdef JUCE_DEBUG
  30898. static SortedSet <Timer*> activeTimers;
  30899. #endif
  30900. Timer::Timer() throw()
  30901. : countdownMs (0),
  30902. periodMs (0),
  30903. previous (0),
  30904. next (0)
  30905. {
  30906. #ifdef JUCE_DEBUG
  30907. activeTimers.add (this);
  30908. #endif
  30909. }
  30910. Timer::Timer (const Timer&) throw()
  30911. : countdownMs (0),
  30912. periodMs (0),
  30913. previous (0),
  30914. next (0)
  30915. {
  30916. #ifdef JUCE_DEBUG
  30917. activeTimers.add (this);
  30918. #endif
  30919. }
  30920. Timer::~Timer()
  30921. {
  30922. stopTimer();
  30923. #ifdef JUCE_DEBUG
  30924. activeTimers.removeValue (this);
  30925. #endif
  30926. }
  30927. void Timer::startTimer (const int interval) throw()
  30928. {
  30929. const ScopedLock sl (InternalTimerThread::lock);
  30930. #ifdef JUCE_DEBUG
  30931. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30932. jassert (activeTimers.contains (this));
  30933. #endif
  30934. if (periodMs == 0)
  30935. {
  30936. countdownMs = interval;
  30937. periodMs = jmax (1, interval);
  30938. InternalTimerThread::add (this);
  30939. }
  30940. else
  30941. {
  30942. InternalTimerThread::resetCounter (this, interval);
  30943. }
  30944. }
  30945. void Timer::stopTimer() throw()
  30946. {
  30947. const ScopedLock sl (InternalTimerThread::lock);
  30948. #ifdef JUCE_DEBUG
  30949. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30950. jassert (activeTimers.contains (this));
  30951. #endif
  30952. if (periodMs > 0)
  30953. {
  30954. InternalTimerThread::remove (this);
  30955. periodMs = 0;
  30956. }
  30957. }
  30958. END_JUCE_NAMESPACE
  30959. /*** End of inlined file: juce_Timer.cpp ***/
  30960. #endif
  30961. #if JUCE_BUILD_GUI
  30962. /*** Start of inlined file: juce_Component.cpp ***/
  30963. BEGIN_JUCE_NAMESPACE
  30964. Component* Component::currentlyFocusedComponent = 0;
  30965. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30966. static Array <int> modalReturnValues;
  30967. enum ComponentMessageNumbers
  30968. {
  30969. customCommandMessage = 0x7fff0001,
  30970. exitModalStateMessage = 0x7fff0002
  30971. };
  30972. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  30973. static uint32 nextComponentUID = 0;
  30974. Component::Component()
  30975. : parentComponent_ (0),
  30976. componentUID (++nextComponentUID),
  30977. numDeepMouseListeners (0),
  30978. lookAndFeel_ (0),
  30979. effect_ (0),
  30980. bufferedImage_ (0),
  30981. mouseListeners_ (0),
  30982. keyListeners_ (0),
  30983. componentFlags_ (0)
  30984. {
  30985. }
  30986. Component::Component (const String& name)
  30987. : componentName_ (name),
  30988. parentComponent_ (0),
  30989. componentUID (++nextComponentUID),
  30990. numDeepMouseListeners (0),
  30991. lookAndFeel_ (0),
  30992. effect_ (0),
  30993. bufferedImage_ (0),
  30994. mouseListeners_ (0),
  30995. keyListeners_ (0),
  30996. componentFlags_ (0)
  30997. {
  30998. }
  30999. Component::~Component()
  31000. {
  31001. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  31002. if (parentComponent_ != 0)
  31003. {
  31004. parentComponent_->removeChildComponent (this);
  31005. }
  31006. else if ((currentlyFocusedComponent == this)
  31007. || isParentOf (currentlyFocusedComponent))
  31008. {
  31009. giveAwayFocus();
  31010. }
  31011. if (flags.hasHeavyweightPeerFlag)
  31012. removeFromDesktop();
  31013. modalComponentStack.removeValue (this);
  31014. for (int i = childComponentList_.size(); --i >= 0;)
  31015. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31016. delete bufferedImage_;
  31017. delete mouseListeners_;
  31018. delete keyListeners_;
  31019. }
  31020. void Component::setName (const String& name)
  31021. {
  31022. // if component methods are being called from threads other than the message
  31023. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31024. checkMessageManagerIsLocked
  31025. if (componentName_ != name)
  31026. {
  31027. componentName_ = name;
  31028. if (flags.hasHeavyweightPeerFlag)
  31029. {
  31030. ComponentPeer* const peer = getPeer();
  31031. jassert (peer != 0);
  31032. if (peer != 0)
  31033. peer->setTitle (name);
  31034. }
  31035. BailOutChecker checker (this);
  31036. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  31037. }
  31038. }
  31039. void Component::setVisible (bool shouldBeVisible)
  31040. {
  31041. if (flags.visibleFlag != shouldBeVisible)
  31042. {
  31043. // if component methods are being called from threads other than the message
  31044. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31045. checkMessageManagerIsLocked
  31046. SafePointer<Component> safePointer (this);
  31047. flags.visibleFlag = shouldBeVisible;
  31048. internalRepaint (0, 0, getWidth(), getHeight());
  31049. sendFakeMouseMove();
  31050. if (! shouldBeVisible)
  31051. {
  31052. if (currentlyFocusedComponent == this
  31053. || isParentOf (currentlyFocusedComponent))
  31054. {
  31055. if (parentComponent_ != 0)
  31056. parentComponent_->grabKeyboardFocus();
  31057. else
  31058. giveAwayFocus();
  31059. }
  31060. }
  31061. sendVisibilityChangeMessage();
  31062. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  31063. {
  31064. ComponentPeer* const peer = getPeer();
  31065. jassert (peer != 0);
  31066. if (peer != 0)
  31067. {
  31068. peer->setVisible (shouldBeVisible);
  31069. internalHierarchyChanged();
  31070. }
  31071. }
  31072. }
  31073. }
  31074. void Component::visibilityChanged()
  31075. {
  31076. }
  31077. void Component::sendVisibilityChangeMessage()
  31078. {
  31079. BailOutChecker checker (this);
  31080. visibilityChanged();
  31081. if (! checker.shouldBailOut())
  31082. componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
  31083. }
  31084. bool Component::isShowing() const
  31085. {
  31086. if (flags.visibleFlag)
  31087. {
  31088. if (parentComponent_ != 0)
  31089. {
  31090. return parentComponent_->isShowing();
  31091. }
  31092. else
  31093. {
  31094. const ComponentPeer* const peer = getPeer();
  31095. return peer != 0 && ! peer->isMinimised();
  31096. }
  31097. }
  31098. return false;
  31099. }
  31100. class FadeOutProxyComponent : public Component,
  31101. public Timer
  31102. {
  31103. public:
  31104. FadeOutProxyComponent (Component* comp,
  31105. const int fadeLengthMs,
  31106. const int deltaXToMove,
  31107. const int deltaYToMove,
  31108. const float scaleFactorAtEnd)
  31109. : lastTime (0),
  31110. alpha (1.0f),
  31111. scale (1.0f)
  31112. {
  31113. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  31114. setBounds (comp->getBounds());
  31115. comp->getParentComponent()->addAndMakeVisible (this);
  31116. toBehind (comp);
  31117. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31118. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31119. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31120. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31121. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31122. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31123. setInterceptsMouseClicks (false, false);
  31124. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31125. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31126. }
  31127. ~FadeOutProxyComponent()
  31128. {
  31129. delete image;
  31130. }
  31131. void paint (Graphics& g)
  31132. {
  31133. g.setOpacity (alpha);
  31134. g.drawImage (image,
  31135. 0, 0, getWidth(), getHeight(),
  31136. 0, 0, image->getWidth(), image->getHeight());
  31137. }
  31138. void timerCallback()
  31139. {
  31140. const uint32 now = Time::getMillisecondCounter();
  31141. if (lastTime == 0)
  31142. lastTime = now;
  31143. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31144. lastTime = now;
  31145. alpha += alphaChangePerMs * msPassed;
  31146. if (alpha > 0)
  31147. {
  31148. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31149. {
  31150. centreX += xChangePerMs * msPassed;
  31151. centreY += yChangePerMs * msPassed;
  31152. scale += scaleChangePerMs * msPassed;
  31153. const int w = roundToInt (image->getWidth() * scale);
  31154. const int h = roundToInt (image->getHeight() * scale);
  31155. setBounds (roundToInt (centreX) - w / 2,
  31156. roundToInt (centreY) - h / 2,
  31157. w, h);
  31158. }
  31159. repaint();
  31160. }
  31161. else
  31162. {
  31163. delete this;
  31164. }
  31165. }
  31166. juce_UseDebuggingNewOperator
  31167. private:
  31168. Image* image;
  31169. uint32 lastTime;
  31170. float alpha, alphaChangePerMs;
  31171. float centreX, xChangePerMs;
  31172. float centreY, yChangePerMs;
  31173. float scale, scaleChangePerMs;
  31174. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31175. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31176. };
  31177. void Component::fadeOutComponent (const int millisecondsToFade,
  31178. const int deltaXToMove,
  31179. const int deltaYToMove,
  31180. const float scaleFactorAtEnd)
  31181. {
  31182. //xxx won't work for comps without parents
  31183. if (isShowing() && millisecondsToFade > 0)
  31184. new FadeOutProxyComponent (this, millisecondsToFade,
  31185. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31186. setVisible (false);
  31187. }
  31188. bool Component::isValidComponent() const
  31189. {
  31190. return (this != 0) && isValidMessageListener();
  31191. }
  31192. void* Component::getWindowHandle() const
  31193. {
  31194. const ComponentPeer* const peer = getPeer();
  31195. if (peer != 0)
  31196. return peer->getNativeHandle();
  31197. return 0;
  31198. }
  31199. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31200. {
  31201. // if component methods are being called from threads other than the message
  31202. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31203. checkMessageManagerIsLocked
  31204. if (isOpaque())
  31205. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31206. else
  31207. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31208. int currentStyleFlags = 0;
  31209. // don't use getPeer(), so that we only get the peer that's specifically
  31210. // for this comp, and not for one of its parents.
  31211. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31212. if (peer != 0)
  31213. currentStyleFlags = peer->getStyleFlags();
  31214. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31215. {
  31216. SafePointer<Component> safePointer (this);
  31217. #if JUCE_LINUX
  31218. // it's wise to give the component a non-zero size before
  31219. // putting it on the desktop, as X windows get confused by this, and
  31220. // a (1, 1) minimum size is enforced here.
  31221. setSize (jmax (1, getWidth()),
  31222. jmax (1, getHeight()));
  31223. #endif
  31224. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31225. bool wasFullscreen = false;
  31226. bool wasMinimised = false;
  31227. ComponentBoundsConstrainer* currentConstainer = 0;
  31228. Rectangle<int> oldNonFullScreenBounds;
  31229. if (peer != 0)
  31230. {
  31231. wasFullscreen = peer->isFullScreen();
  31232. wasMinimised = peer->isMinimised();
  31233. currentConstainer = peer->getConstrainer();
  31234. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31235. removeFromDesktop();
  31236. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31237. }
  31238. if (parentComponent_ != 0)
  31239. parentComponent_->removeChildComponent (this);
  31240. if (safePointer != 0)
  31241. {
  31242. flags.hasHeavyweightPeerFlag = true;
  31243. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31244. Desktop::getInstance().addDesktopComponent (this);
  31245. bounds_.setPosition (topLeft);
  31246. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31247. peer->setVisible (isVisible());
  31248. if (wasFullscreen)
  31249. {
  31250. peer->setFullScreen (true);
  31251. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31252. }
  31253. if (wasMinimised)
  31254. peer->setMinimised (true);
  31255. if (isAlwaysOnTop())
  31256. peer->setAlwaysOnTop (true);
  31257. peer->setConstrainer (currentConstainer);
  31258. repaint();
  31259. }
  31260. internalHierarchyChanged();
  31261. }
  31262. }
  31263. void Component::removeFromDesktop()
  31264. {
  31265. // if component methods are being called from threads other than the message
  31266. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31267. checkMessageManagerIsLocked
  31268. if (flags.hasHeavyweightPeerFlag)
  31269. {
  31270. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31271. flags.hasHeavyweightPeerFlag = false;
  31272. jassert (peer != 0);
  31273. delete peer;
  31274. Desktop::getInstance().removeDesktopComponent (this);
  31275. }
  31276. }
  31277. bool Component::isOnDesktop() const throw()
  31278. {
  31279. return flags.hasHeavyweightPeerFlag;
  31280. }
  31281. void Component::userTriedToCloseWindow()
  31282. {
  31283. /* This means that the user's trying to get rid of your window with the 'close window' system
  31284. menu option (on windows) or possibly the task manager - you should really handle this
  31285. and delete or hide your component in an appropriate way.
  31286. If you want to ignore the event and don't want to trigger this assertion, just override
  31287. this method and do nothing.
  31288. */
  31289. jassertfalse
  31290. }
  31291. void Component::minimisationStateChanged (bool)
  31292. {
  31293. }
  31294. void Component::setOpaque (const bool shouldBeOpaque)
  31295. {
  31296. if (shouldBeOpaque != flags.opaqueFlag)
  31297. {
  31298. flags.opaqueFlag = shouldBeOpaque;
  31299. if (flags.hasHeavyweightPeerFlag)
  31300. {
  31301. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31302. if (peer != 0)
  31303. {
  31304. // to make it recreate the heavyweight window
  31305. addToDesktop (peer->getStyleFlags());
  31306. }
  31307. }
  31308. repaint();
  31309. }
  31310. }
  31311. bool Component::isOpaque() const throw()
  31312. {
  31313. return flags.opaqueFlag;
  31314. }
  31315. void Component::setBufferedToImage (const bool shouldBeBuffered)
  31316. {
  31317. if (shouldBeBuffered != flags.bufferToImageFlag)
  31318. {
  31319. deleteAndZero (bufferedImage_);
  31320. flags.bufferToImageFlag = shouldBeBuffered;
  31321. }
  31322. }
  31323. void Component::toFront (const bool setAsForeground)
  31324. {
  31325. // if component methods are being called from threads other than the message
  31326. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31327. checkMessageManagerIsLocked
  31328. if (flags.hasHeavyweightPeerFlag)
  31329. {
  31330. ComponentPeer* const peer = getPeer();
  31331. if (peer != 0)
  31332. {
  31333. peer->toFront (setAsForeground);
  31334. if (setAsForeground && ! hasKeyboardFocus (true))
  31335. grabKeyboardFocus();
  31336. }
  31337. }
  31338. else if (parentComponent_ != 0)
  31339. {
  31340. if (parentComponent_->childComponentList_.getLast() != this)
  31341. {
  31342. const int index = parentComponent_->childComponentList_.indexOf (this);
  31343. if (index >= 0)
  31344. {
  31345. int insertIndex = -1;
  31346. if (! flags.alwaysOnTopFlag)
  31347. {
  31348. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31349. while (insertIndex > 0
  31350. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31351. {
  31352. --insertIndex;
  31353. }
  31354. }
  31355. if (index != insertIndex)
  31356. {
  31357. parentComponent_->childComponentList_.move (index, insertIndex);
  31358. sendFakeMouseMove();
  31359. repaintParent();
  31360. }
  31361. }
  31362. }
  31363. if (setAsForeground)
  31364. {
  31365. internalBroughtToFront();
  31366. grabKeyboardFocus();
  31367. }
  31368. }
  31369. }
  31370. void Component::toBehind (Component* const other)
  31371. {
  31372. if (other != 0)
  31373. {
  31374. // the two components must belong to the same parent..
  31375. jassert (parentComponent_ == other->parentComponent_);
  31376. if (parentComponent_ != 0)
  31377. {
  31378. const int index = parentComponent_->childComponentList_.indexOf (this);
  31379. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31380. if (index >= 0
  31381. && otherIndex >= 0
  31382. && index != otherIndex - 1
  31383. && other != this)
  31384. {
  31385. if (index < otherIndex)
  31386. --otherIndex;
  31387. parentComponent_->childComponentList_.move (index, otherIndex);
  31388. sendFakeMouseMove();
  31389. repaintParent();
  31390. }
  31391. }
  31392. else if (isOnDesktop())
  31393. {
  31394. jassert (other->isOnDesktop());
  31395. if (other->isOnDesktop())
  31396. {
  31397. ComponentPeer* const us = getPeer();
  31398. ComponentPeer* const them = other->getPeer();
  31399. jassert (us != 0 && them != 0);
  31400. if (us != 0 && them != 0)
  31401. us->toBehind (them);
  31402. }
  31403. }
  31404. }
  31405. }
  31406. void Component::toBack()
  31407. {
  31408. if (isOnDesktop())
  31409. {
  31410. jassertfalse //xxx need to add this to native window
  31411. }
  31412. else if (parentComponent_ != 0
  31413. && parentComponent_->childComponentList_.getFirst() != this)
  31414. {
  31415. const int index = parentComponent_->childComponentList_.indexOf (this);
  31416. if (index > 0)
  31417. {
  31418. int insertIndex = 0;
  31419. if (flags.alwaysOnTopFlag)
  31420. {
  31421. while (insertIndex < parentComponent_->childComponentList_.size()
  31422. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31423. {
  31424. ++insertIndex;
  31425. }
  31426. }
  31427. if (index != insertIndex)
  31428. {
  31429. parentComponent_->childComponentList_.move (index, insertIndex);
  31430. sendFakeMouseMove();
  31431. repaintParent();
  31432. }
  31433. }
  31434. }
  31435. }
  31436. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31437. {
  31438. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31439. {
  31440. flags.alwaysOnTopFlag = shouldStayOnTop;
  31441. if (isOnDesktop())
  31442. {
  31443. ComponentPeer* const peer = getPeer();
  31444. jassert (peer != 0);
  31445. if (peer != 0)
  31446. {
  31447. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31448. {
  31449. // some kinds of peer can't change their always-on-top status, so
  31450. // for these, we'll need to create a new window
  31451. const int oldFlags = peer->getStyleFlags();
  31452. removeFromDesktop();
  31453. addToDesktop (oldFlags);
  31454. }
  31455. }
  31456. }
  31457. if (shouldStayOnTop)
  31458. toFront (false);
  31459. internalHierarchyChanged();
  31460. }
  31461. }
  31462. bool Component::isAlwaysOnTop() const throw()
  31463. {
  31464. return flags.alwaysOnTopFlag;
  31465. }
  31466. int Component::proportionOfWidth (const float proportion) const throw()
  31467. {
  31468. return roundToInt (proportion * bounds_.getWidth());
  31469. }
  31470. int Component::proportionOfHeight (const float proportion) const throw()
  31471. {
  31472. return roundToInt (proportion * bounds_.getHeight());
  31473. }
  31474. int Component::getParentWidth() const throw()
  31475. {
  31476. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31477. : getParentMonitorArea().getWidth();
  31478. }
  31479. int Component::getParentHeight() const throw()
  31480. {
  31481. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31482. : getParentMonitorArea().getHeight();
  31483. }
  31484. int Component::getScreenX() const
  31485. {
  31486. return getScreenPosition().getX();
  31487. }
  31488. int Component::getScreenY() const
  31489. {
  31490. return getScreenPosition().getY();
  31491. }
  31492. const Point<int> Component::getScreenPosition() const
  31493. {
  31494. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31495. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31496. : getPosition());
  31497. }
  31498. const Rectangle<int> Component::getScreenBounds() const
  31499. {
  31500. return bounds_.withPosition (getScreenPosition());
  31501. }
  31502. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31503. {
  31504. const Component* c = this;
  31505. Point<int> p (relativePosition);
  31506. do
  31507. {
  31508. if (c->flags.hasHeavyweightPeerFlag)
  31509. return c->getPeer()->relativePositionToGlobal (p);
  31510. p += c->getPosition();
  31511. c = c->parentComponent_;
  31512. }
  31513. while (c != 0);
  31514. return p;
  31515. }
  31516. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31517. {
  31518. if (flags.hasHeavyweightPeerFlag)
  31519. {
  31520. return getPeer()->globalPositionToRelative (screenPosition);
  31521. }
  31522. else
  31523. {
  31524. if (parentComponent_ != 0)
  31525. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31526. return screenPosition - getPosition();
  31527. }
  31528. }
  31529. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31530. {
  31531. Point<int> p (positionRelativeToThis);
  31532. if (targetComponent != 0)
  31533. {
  31534. const Component* c = this;
  31535. do
  31536. {
  31537. if (c == targetComponent)
  31538. return p;
  31539. if (c->flags.hasHeavyweightPeerFlag)
  31540. {
  31541. p = c->getPeer()->relativePositionToGlobal (p);
  31542. break;
  31543. }
  31544. p += c->getPosition();
  31545. c = c->parentComponent_;
  31546. }
  31547. while (c != 0);
  31548. p = targetComponent->globalPositionToRelative (p);
  31549. }
  31550. return p;
  31551. }
  31552. void Component::setBounds (int x, int y, int w, int h)
  31553. {
  31554. // if component methods are being called from threads other than the message
  31555. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31556. checkMessageManagerIsLocked
  31557. if (w < 0) w = 0;
  31558. if (h < 0) h = 0;
  31559. const bool wasResized = (getWidth() != w || getHeight() != h);
  31560. const bool wasMoved = (getX() != x || getY() != y);
  31561. #ifdef JUCE_DEBUG
  31562. // It's a very bad idea to try to resize a window during its paint() method!
  31563. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31564. #endif
  31565. if (wasMoved || wasResized)
  31566. {
  31567. if (flags.visibleFlag)
  31568. {
  31569. // send a fake mouse move to trigger enter/exit messages if needed..
  31570. sendFakeMouseMove();
  31571. if (! flags.hasHeavyweightPeerFlag)
  31572. repaintParent();
  31573. }
  31574. bounds_.setBounds (x, y, w, h);
  31575. if (wasResized)
  31576. repaint();
  31577. else if (! flags.hasHeavyweightPeerFlag)
  31578. repaintParent();
  31579. if (flags.hasHeavyweightPeerFlag)
  31580. {
  31581. ComponentPeer* const peer = getPeer();
  31582. if (peer != 0)
  31583. {
  31584. if (wasMoved && wasResized)
  31585. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31586. else if (wasMoved)
  31587. peer->setPosition (getX(), getY());
  31588. else if (wasResized)
  31589. peer->setSize (getWidth(), getHeight());
  31590. }
  31591. }
  31592. sendMovedResizedMessages (wasMoved, wasResized);
  31593. }
  31594. }
  31595. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31596. {
  31597. JUCE_TRY
  31598. {
  31599. if (wasMoved)
  31600. moved();
  31601. if (wasResized)
  31602. {
  31603. resized();
  31604. for (int i = childComponentList_.size(); --i >= 0;)
  31605. {
  31606. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31607. i = jmin (i, childComponentList_.size());
  31608. }
  31609. }
  31610. BailOutChecker checker (this);
  31611. if (parentComponent_ != 0)
  31612. parentComponent_->childBoundsChanged (this);
  31613. if (! checker.shouldBailOut())
  31614. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31615. *this, wasMoved, wasResized);
  31616. }
  31617. JUCE_CATCH_EXCEPTION
  31618. }
  31619. void Component::setSize (const int w, const int h)
  31620. {
  31621. setBounds (getX(), getY(), w, h);
  31622. }
  31623. void Component::setTopLeftPosition (const int x, const int y)
  31624. {
  31625. setBounds (x, y, getWidth(), getHeight());
  31626. }
  31627. void Component::setTopRightPosition (const int x, const int y)
  31628. {
  31629. setTopLeftPosition (x - getWidth(), y);
  31630. }
  31631. void Component::setBounds (const Rectangle<int>& r)
  31632. {
  31633. setBounds (r.getX(),
  31634. r.getY(),
  31635. r.getWidth(),
  31636. r.getHeight());
  31637. }
  31638. void Component::setBoundsRelative (const float x, const float y,
  31639. const float w, const float h)
  31640. {
  31641. const int pw = getParentWidth();
  31642. const int ph = getParentHeight();
  31643. setBounds (roundToInt (x * pw),
  31644. roundToInt (y * ph),
  31645. roundToInt (w * pw),
  31646. roundToInt (h * ph));
  31647. }
  31648. void Component::setCentrePosition (const int x, const int y)
  31649. {
  31650. setTopLeftPosition (x - getWidth() / 2,
  31651. y - getHeight() / 2);
  31652. }
  31653. void Component::setCentreRelative (const float x, const float y)
  31654. {
  31655. setCentrePosition (roundToInt (getParentWidth() * x),
  31656. roundToInt (getParentHeight() * y));
  31657. }
  31658. void Component::centreWithSize (const int width, const int height)
  31659. {
  31660. setBounds ((getParentWidth() - width) / 2,
  31661. (getParentHeight() - height) / 2,
  31662. width,
  31663. height);
  31664. }
  31665. void Component::setBoundsInset (const BorderSize& borders)
  31666. {
  31667. setBounds (borders.getLeft(),
  31668. borders.getTop(),
  31669. getParentWidth() - (borders.getLeftAndRight()),
  31670. getParentHeight() - (borders.getTopAndBottom()));
  31671. }
  31672. void Component::setBoundsToFit (int x, int y, int width, int height,
  31673. const Justification& justification,
  31674. const bool onlyReduceInSize)
  31675. {
  31676. // it's no good calling this method unless both the component and
  31677. // target rectangle have a finite size.
  31678. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31679. if (getWidth() > 0 && getHeight() > 0
  31680. && width > 0 && height > 0)
  31681. {
  31682. int newW, newH;
  31683. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31684. {
  31685. newW = getWidth();
  31686. newH = getHeight();
  31687. }
  31688. else
  31689. {
  31690. const double imageRatio = getHeight() / (double) getWidth();
  31691. const double targetRatio = height / (double) width;
  31692. if (imageRatio <= targetRatio)
  31693. {
  31694. newW = width;
  31695. newH = jmin (height, roundToInt (newW * imageRatio));
  31696. }
  31697. else
  31698. {
  31699. newH = height;
  31700. newW = jmin (width, roundToInt (newH / imageRatio));
  31701. }
  31702. }
  31703. if (newW > 0 && newH > 0)
  31704. {
  31705. int newX, newY;
  31706. justification.applyToRectangle (newX, newY, newW, newH,
  31707. x, y, width, height);
  31708. setBounds (newX, newY, newW, newH);
  31709. }
  31710. }
  31711. }
  31712. bool Component::hitTest (int x, int y)
  31713. {
  31714. if (! flags.ignoresMouseClicksFlag)
  31715. return true;
  31716. if (flags.allowChildMouseClicksFlag)
  31717. {
  31718. for (int i = getNumChildComponents(); --i >= 0;)
  31719. {
  31720. Component* const c = getChildComponent (i);
  31721. if (c->isVisible()
  31722. && c->bounds_.contains (x, y)
  31723. && c->hitTest (x - c->getX(),
  31724. y - c->getY()))
  31725. {
  31726. return true;
  31727. }
  31728. }
  31729. }
  31730. return false;
  31731. }
  31732. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31733. const bool allowClicksOnChildComponents) throw()
  31734. {
  31735. flags.ignoresMouseClicksFlag = ! allowClicks;
  31736. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31737. }
  31738. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31739. bool& allowsClicksOnChildComponents) const throw()
  31740. {
  31741. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31742. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31743. }
  31744. bool Component::contains (const int x, const int y)
  31745. {
  31746. if (((unsigned int) x) < (unsigned int) getWidth()
  31747. && ((unsigned int) y) < (unsigned int) getHeight()
  31748. && hitTest (x, y))
  31749. {
  31750. if (parentComponent_ != 0)
  31751. {
  31752. return parentComponent_->contains (x + getX(),
  31753. y + getY());
  31754. }
  31755. else if (flags.hasHeavyweightPeerFlag)
  31756. {
  31757. const ComponentPeer* const peer = getPeer();
  31758. if (peer != 0)
  31759. return peer->contains (Point<int> (x, y), true);
  31760. }
  31761. }
  31762. return false;
  31763. }
  31764. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31765. {
  31766. if (! contains (x, y))
  31767. return false;
  31768. Component* p = this;
  31769. while (p->parentComponent_ != 0)
  31770. {
  31771. x += p->getX();
  31772. y += p->getY();
  31773. p = p->parentComponent_;
  31774. }
  31775. const Component* const c = p->getComponentAt (x, y);
  31776. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31777. }
  31778. Component* Component::getComponentAt (const Point<int>& position)
  31779. {
  31780. return getComponentAt (position.getX(), position.getY());
  31781. }
  31782. Component* Component::getComponentAt (const int x, const int y)
  31783. {
  31784. if (flags.visibleFlag
  31785. && ((unsigned int) x) < (unsigned int) getWidth()
  31786. && ((unsigned int) y) < (unsigned int) getHeight()
  31787. && hitTest (x, y))
  31788. {
  31789. for (int i = childComponentList_.size(); --i >= 0;)
  31790. {
  31791. Component* const child = childComponentList_.getUnchecked(i);
  31792. Component* const c = child->getComponentAt (x - child->getX(),
  31793. y - child->getY());
  31794. if (c != 0)
  31795. return c;
  31796. }
  31797. return this;
  31798. }
  31799. return 0;
  31800. }
  31801. void Component::addChildComponent (Component* const child, int zOrder)
  31802. {
  31803. // if component methods are being called from threads other than the message
  31804. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31805. checkMessageManagerIsLocked
  31806. if (child != 0 && child->parentComponent_ != this)
  31807. {
  31808. if (child->parentComponent_ != 0)
  31809. child->parentComponent_->removeChildComponent (child);
  31810. else
  31811. child->removeFromDesktop();
  31812. child->parentComponent_ = this;
  31813. if (child->isVisible())
  31814. child->repaintParent();
  31815. if (! child->isAlwaysOnTop())
  31816. {
  31817. if (zOrder < 0 || zOrder > childComponentList_.size())
  31818. zOrder = childComponentList_.size();
  31819. while (zOrder > 0)
  31820. {
  31821. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31822. break;
  31823. --zOrder;
  31824. }
  31825. }
  31826. childComponentList_.insert (zOrder, child);
  31827. child->internalHierarchyChanged();
  31828. internalChildrenChanged();
  31829. }
  31830. }
  31831. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31832. {
  31833. if (child != 0)
  31834. {
  31835. child->setVisible (true);
  31836. addChildComponent (child, zOrder);
  31837. }
  31838. }
  31839. void Component::removeChildComponent (Component* const child)
  31840. {
  31841. removeChildComponent (childComponentList_.indexOf (child));
  31842. }
  31843. Component* Component::removeChildComponent (const int index)
  31844. {
  31845. // if component methods are being called from threads other than the message
  31846. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31847. checkMessageManagerIsLocked
  31848. Component* const child = childComponentList_ [index];
  31849. if (child != 0)
  31850. {
  31851. sendFakeMouseMove();
  31852. child->repaintParent();
  31853. childComponentList_.remove (index);
  31854. child->parentComponent_ = 0;
  31855. JUCE_TRY
  31856. {
  31857. if ((currentlyFocusedComponent == child)
  31858. || child->isParentOf (currentlyFocusedComponent))
  31859. {
  31860. // get rid first to force the grabKeyboardFocus to change to us.
  31861. giveAwayFocus();
  31862. grabKeyboardFocus();
  31863. }
  31864. }
  31865. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31866. catch (const std::exception& e)
  31867. {
  31868. currentlyFocusedComponent = 0;
  31869. Desktop::getInstance().triggerFocusCallback();
  31870. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31871. }
  31872. catch (...)
  31873. {
  31874. currentlyFocusedComponent = 0;
  31875. Desktop::getInstance().triggerFocusCallback();
  31876. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31877. }
  31878. #endif
  31879. child->internalHierarchyChanged();
  31880. internalChildrenChanged();
  31881. }
  31882. return child;
  31883. }
  31884. void Component::removeAllChildren()
  31885. {
  31886. for (int i = childComponentList_.size(); --i >= 0;)
  31887. removeChildComponent (i);
  31888. }
  31889. void Component::deleteAllChildren()
  31890. {
  31891. for (int i = childComponentList_.size(); --i >= 0;)
  31892. delete (removeChildComponent (i));
  31893. }
  31894. int Component::getNumChildComponents() const throw()
  31895. {
  31896. return childComponentList_.size();
  31897. }
  31898. Component* Component::getChildComponent (const int index) const throw()
  31899. {
  31900. return childComponentList_ [index];
  31901. }
  31902. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31903. {
  31904. return childComponentList_.indexOf (const_cast <Component*> (child));
  31905. }
  31906. Component* Component::getTopLevelComponent() const throw()
  31907. {
  31908. const Component* comp = this;
  31909. while (comp->parentComponent_ != 0)
  31910. comp = comp->parentComponent_;
  31911. return const_cast <Component*> (comp);
  31912. }
  31913. bool Component::isParentOf (const Component* possibleChild) const throw()
  31914. {
  31915. if (! possibleChild->isValidComponent())
  31916. {
  31917. jassert (possibleChild == 0);
  31918. return false;
  31919. }
  31920. while (possibleChild != 0)
  31921. {
  31922. possibleChild = possibleChild->parentComponent_;
  31923. if (possibleChild == this)
  31924. return true;
  31925. }
  31926. return false;
  31927. }
  31928. void Component::parentHierarchyChanged()
  31929. {
  31930. }
  31931. void Component::childrenChanged()
  31932. {
  31933. }
  31934. void Component::internalChildrenChanged()
  31935. {
  31936. if (componentListeners.isEmpty())
  31937. {
  31938. childrenChanged();
  31939. }
  31940. else
  31941. {
  31942. BailOutChecker checker (this);
  31943. childrenChanged();
  31944. if (! checker.shouldBailOut())
  31945. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  31946. }
  31947. }
  31948. void Component::internalHierarchyChanged()
  31949. {
  31950. BailOutChecker checker (this);
  31951. parentHierarchyChanged();
  31952. if (checker.shouldBailOut())
  31953. return;
  31954. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  31955. if (checker.shouldBailOut())
  31956. return;
  31957. for (int i = childComponentList_.size(); --i >= 0;)
  31958. {
  31959. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  31960. if (checker.shouldBailOut())
  31961. {
  31962. // you really shouldn't delete the parent component during a callback telling you
  31963. // that it's changed..
  31964. jassertfalse;
  31965. return;
  31966. }
  31967. i = jmin (i, childComponentList_.size());
  31968. }
  31969. }
  31970. void* Component::runModalLoopCallback (void* userData)
  31971. {
  31972. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  31973. }
  31974. int Component::runModalLoop()
  31975. {
  31976. if (! MessageManager::getInstance()->isThisTheMessageThread())
  31977. {
  31978. // use a callback so this can be called from non-gui threads
  31979. return (int) (pointer_sized_int)
  31980. MessageManager::getInstance()
  31981. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  31982. }
  31983. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  31984. if (! isCurrentlyModal())
  31985. enterModalState();
  31986. JUCE_TRY
  31987. {
  31988. while (flags.currentlyModalFlag && flags.visibleFlag)
  31989. {
  31990. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  31991. break;
  31992. // check whether this component was deleted during the last message
  31993. if (! isValidMessageListener())
  31994. break;
  31995. }
  31996. }
  31997. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31998. catch (const std::exception& e)
  31999. {
  32000. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32001. return 0;
  32002. }
  32003. catch (...)
  32004. {
  32005. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32006. return 0;
  32007. }
  32008. #endif
  32009. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32010. int returnValue = 0;
  32011. if (modalIndex >= 0)
  32012. {
  32013. modalComponentReturnValueKeys.remove (modalIndex);
  32014. returnValue = modalReturnValues.remove (modalIndex);
  32015. }
  32016. modalComponentStack.removeValue (this);
  32017. if (prevFocused != 0)
  32018. prevFocused->grabKeyboardFocus();
  32019. return returnValue;
  32020. }
  32021. void Component::enterModalState (const bool takeKeyboardFocus_)
  32022. {
  32023. // if component methods are being called from threads other than the message
  32024. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32025. checkMessageManagerIsLocked
  32026. // Check for an attempt to make a component modal when it already is!
  32027. // This can cause nasty problems..
  32028. jassert (! flags.currentlyModalFlag);
  32029. if (! isCurrentlyModal())
  32030. {
  32031. modalComponentStack.add (this);
  32032. modalComponentReturnValueKeys.add (this);
  32033. modalReturnValues.add (0);
  32034. flags.currentlyModalFlag = true;
  32035. setVisible (true);
  32036. if (takeKeyboardFocus_)
  32037. grabKeyboardFocus();
  32038. }
  32039. }
  32040. void Component::exitModalState (const int returnValue)
  32041. {
  32042. if (isCurrentlyModal())
  32043. {
  32044. if (MessageManager::getInstance()->isThisTheMessageThread())
  32045. {
  32046. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32047. if (modalIndex >= 0)
  32048. {
  32049. modalReturnValues.set (modalIndex, returnValue);
  32050. }
  32051. else
  32052. {
  32053. modalComponentReturnValueKeys.add (this);
  32054. modalReturnValues.add (returnValue);
  32055. }
  32056. modalComponentStack.removeValue (this);
  32057. flags.currentlyModalFlag = false;
  32058. bringModalComponentToFront();
  32059. }
  32060. else
  32061. {
  32062. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32063. }
  32064. }
  32065. }
  32066. bool Component::isCurrentlyModal() const throw()
  32067. {
  32068. return flags.currentlyModalFlag
  32069. && getCurrentlyModalComponent() == this;
  32070. }
  32071. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  32072. {
  32073. Component* const mc = getCurrentlyModalComponent();
  32074. return mc != 0
  32075. && mc != this
  32076. && (! mc->isParentOf (this))
  32077. && ! mc->canModalEventBeSentToComponent (this);
  32078. }
  32079. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32080. {
  32081. return modalComponentStack.size();
  32082. }
  32083. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32084. {
  32085. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  32086. return c->isValidComponent() ? c : 0;
  32087. }
  32088. void Component::bringModalComponentToFront()
  32089. {
  32090. ComponentPeer* lastOne = 0;
  32091. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32092. {
  32093. Component* const c = getCurrentlyModalComponent (i);
  32094. if (c == 0)
  32095. break;
  32096. ComponentPeer* peer = c->getPeer();
  32097. if (peer != 0 && peer != lastOne)
  32098. {
  32099. if (lastOne == 0)
  32100. {
  32101. peer->toFront (true);
  32102. peer->grabFocus();
  32103. }
  32104. else
  32105. peer->toBehind (lastOne);
  32106. lastOne = peer;
  32107. }
  32108. }
  32109. }
  32110. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32111. {
  32112. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32113. }
  32114. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32115. {
  32116. return flags.bringToFrontOnClickFlag;
  32117. }
  32118. void Component::setMouseCursor (const MouseCursor& cursor)
  32119. {
  32120. if (cursor_ != cursor)
  32121. {
  32122. cursor_ = cursor;
  32123. if (flags.visibleFlag)
  32124. updateMouseCursor();
  32125. }
  32126. }
  32127. const MouseCursor Component::getMouseCursor()
  32128. {
  32129. return cursor_;
  32130. }
  32131. void Component::updateMouseCursor() const
  32132. {
  32133. sendFakeMouseMove();
  32134. }
  32135. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32136. {
  32137. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32138. }
  32139. void Component::repaintParent()
  32140. {
  32141. if (flags.visibleFlag)
  32142. internalRepaint (0, 0, getWidth(), getHeight());
  32143. }
  32144. void Component::repaint()
  32145. {
  32146. repaint (0, 0, getWidth(), getHeight());
  32147. }
  32148. void Component::repaint (const int x, const int y,
  32149. const int w, const int h)
  32150. {
  32151. deleteAndZero (bufferedImage_);
  32152. if (flags.visibleFlag)
  32153. internalRepaint (x, y, w, h);
  32154. }
  32155. void Component::internalRepaint (int x, int y, int w, int h)
  32156. {
  32157. // if component methods are being called from threads other than the message
  32158. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32159. checkMessageManagerIsLocked
  32160. if (x < 0)
  32161. {
  32162. w += x;
  32163. x = 0;
  32164. }
  32165. if (x + w > getWidth())
  32166. w = getWidth() - x;
  32167. if (w > 0)
  32168. {
  32169. if (y < 0)
  32170. {
  32171. h += y;
  32172. y = 0;
  32173. }
  32174. if (y + h > getHeight())
  32175. h = getHeight() - y;
  32176. if (h > 0)
  32177. {
  32178. if (parentComponent_ != 0)
  32179. {
  32180. x += getX();
  32181. y += getY();
  32182. if (parentComponent_->flags.visibleFlag)
  32183. parentComponent_->internalRepaint (x, y, w, h);
  32184. }
  32185. else if (flags.hasHeavyweightPeerFlag)
  32186. {
  32187. ComponentPeer* const peer = getPeer();
  32188. if (peer != 0)
  32189. peer->repaint (x, y, w, h);
  32190. }
  32191. }
  32192. }
  32193. }
  32194. void Component::renderComponent (Graphics& g)
  32195. {
  32196. const Rectangle<int> clipBounds (g.getClipBounds());
  32197. g.saveState();
  32198. clipObscuredRegions (g, clipBounds, 0, 0);
  32199. if (! g.isClipEmpty())
  32200. {
  32201. if (flags.bufferToImageFlag)
  32202. {
  32203. if (bufferedImage_ == 0)
  32204. {
  32205. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32206. getWidth(), getHeight(), ! flags.opaqueFlag);
  32207. Graphics imG (*bufferedImage_);
  32208. paint (imG);
  32209. }
  32210. g.setColour (Colours::black);
  32211. g.drawImageAt (bufferedImage_, 0, 0);
  32212. }
  32213. else
  32214. {
  32215. paint (g);
  32216. }
  32217. }
  32218. g.restoreState();
  32219. for (int i = 0; i < childComponentList_.size(); ++i)
  32220. {
  32221. Component* const child = childComponentList_.getUnchecked (i);
  32222. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  32223. {
  32224. g.saveState();
  32225. if (g.reduceClipRegion (child->getX(), child->getY(),
  32226. child->getWidth(), child->getHeight()))
  32227. {
  32228. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32229. {
  32230. const Component* const sibling = childComponentList_.getUnchecked (j);
  32231. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32232. g.excludeClipRegion (sibling->getBounds());
  32233. }
  32234. if (! g.isClipEmpty())
  32235. {
  32236. g.setOrigin (child->getX(), child->getY());
  32237. child->paintEntireComponent (g);
  32238. }
  32239. }
  32240. g.restoreState();
  32241. }
  32242. }
  32243. g.saveState();
  32244. paintOverChildren (g);
  32245. g.restoreState();
  32246. }
  32247. void Component::paintEntireComponent (Graphics& g)
  32248. {
  32249. jassert (! g.isClipEmpty());
  32250. #ifdef JUCE_DEBUG
  32251. flags.isInsidePaintCall = true;
  32252. #endif
  32253. if (effect_ != 0)
  32254. {
  32255. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32256. getWidth(), getHeight(),
  32257. ! flags.opaqueFlag));
  32258. {
  32259. Graphics g2 (*effectImage);
  32260. renderComponent (g2);
  32261. }
  32262. effect_->applyEffect (*effectImage, g);
  32263. }
  32264. else
  32265. {
  32266. renderComponent (g);
  32267. }
  32268. #ifdef JUCE_DEBUG
  32269. flags.isInsidePaintCall = false;
  32270. #endif
  32271. }
  32272. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32273. const bool clipImageToComponentBounds)
  32274. {
  32275. Rectangle<int> r (areaToGrab);
  32276. if (clipImageToComponentBounds)
  32277. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32278. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32279. jmax (1, r.getWidth()),
  32280. jmax (1, r.getHeight()),
  32281. true));
  32282. Graphics imageContext (*componentImage);
  32283. imageContext.setOrigin (-r.getX(), -r.getY());
  32284. paintEntireComponent (imageContext);
  32285. return componentImage.release();
  32286. }
  32287. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32288. {
  32289. if (effect_ != effect)
  32290. {
  32291. effect_ = effect;
  32292. repaint();
  32293. }
  32294. }
  32295. LookAndFeel& Component::getLookAndFeel() const throw()
  32296. {
  32297. const Component* c = this;
  32298. do
  32299. {
  32300. if (c->lookAndFeel_ != 0)
  32301. return *(c->lookAndFeel_);
  32302. c = c->parentComponent_;
  32303. }
  32304. while (c != 0);
  32305. return LookAndFeel::getDefaultLookAndFeel();
  32306. }
  32307. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32308. {
  32309. if (lookAndFeel_ != newLookAndFeel)
  32310. {
  32311. lookAndFeel_ = newLookAndFeel;
  32312. sendLookAndFeelChange();
  32313. }
  32314. }
  32315. void Component::lookAndFeelChanged()
  32316. {
  32317. }
  32318. void Component::sendLookAndFeelChange()
  32319. {
  32320. repaint();
  32321. lookAndFeelChanged();
  32322. // (it's not a great idea to do anything that would delete this component
  32323. // during the lookAndFeelChanged() callback)
  32324. jassert (isValidComponent());
  32325. SafePointer<Component> safePointer (this);
  32326. for (int i = childComponentList_.size(); --i >= 0;)
  32327. {
  32328. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32329. if (safePointer == 0)
  32330. return;
  32331. i = jmin (i, childComponentList_.size());
  32332. }
  32333. }
  32334. static const var::identifier getColourPropertyId (const int colourId)
  32335. {
  32336. String s;
  32337. s.preallocateStorage (18);
  32338. s << T("jcclr_") << String::toHexString (colourId);
  32339. return s;
  32340. }
  32341. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32342. {
  32343. var* v = properties.getItem (getColourPropertyId (colourId));
  32344. if (v != 0)
  32345. return Colour ((int) *v);
  32346. if (inheritFromParent && parentComponent_ != 0)
  32347. return parentComponent_->findColour (colourId, true);
  32348. return getLookAndFeel().findColour (colourId);
  32349. }
  32350. bool Component::isColourSpecified (const int colourId) const
  32351. {
  32352. return properties.contains (getColourPropertyId (colourId));
  32353. }
  32354. void Component::removeColour (const int colourId)
  32355. {
  32356. if (properties.remove (getColourPropertyId (colourId)))
  32357. colourChanged();
  32358. }
  32359. void Component::setColour (const int colourId, const Colour& colour)
  32360. {
  32361. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32362. colourChanged();
  32363. }
  32364. void Component::copyAllExplicitColoursTo (Component& target) const
  32365. {
  32366. bool changed = false;
  32367. for (int i = properties.size(); --i >= 0;)
  32368. {
  32369. const var::identifier name (properties.getName(i));
  32370. if (name.name.startsWith (T("jcclr_")))
  32371. if (target.properties.set (name, properties [name]))
  32372. changed = true;
  32373. }
  32374. if (changed)
  32375. target.colourChanged();
  32376. }
  32377. void Component::colourChanged()
  32378. {
  32379. }
  32380. const Rectangle<int> Component::getUnclippedArea() const
  32381. {
  32382. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32383. Component* p = parentComponent_;
  32384. int px = getX();
  32385. int py = getY();
  32386. while (p != 0)
  32387. {
  32388. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32389. return Rectangle<int>();
  32390. px += p->getX();
  32391. py += p->getY();
  32392. p = p->parentComponent_;
  32393. }
  32394. return Rectangle<int> (x, y, w, h);
  32395. }
  32396. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32397. const int deltaX, const int deltaY) const
  32398. {
  32399. for (int i = childComponentList_.size(); --i >= 0;)
  32400. {
  32401. const Component* const c = childComponentList_.getUnchecked(i);
  32402. if (c->isVisible())
  32403. {
  32404. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32405. if (! newClip.isEmpty())
  32406. {
  32407. if (c->isOpaque())
  32408. {
  32409. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32410. }
  32411. else
  32412. {
  32413. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32414. c->getX() + deltaX,
  32415. c->getY() + deltaY);
  32416. }
  32417. }
  32418. }
  32419. }
  32420. }
  32421. void Component::getVisibleArea (RectangleList& result,
  32422. const bool includeSiblings) const
  32423. {
  32424. result.clear();
  32425. const Rectangle<int> unclipped (getUnclippedArea());
  32426. if (! unclipped.isEmpty())
  32427. {
  32428. result.add (unclipped);
  32429. if (includeSiblings)
  32430. {
  32431. const Component* const c = getTopLevelComponent();
  32432. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32433. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32434. this);
  32435. }
  32436. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32437. result.consolidate();
  32438. }
  32439. }
  32440. void Component::subtractObscuredRegions (RectangleList& result,
  32441. const Point<int>& delta,
  32442. const Rectangle<int>& clipRect,
  32443. const Component* const compToAvoid) const
  32444. {
  32445. for (int i = childComponentList_.size(); --i >= 0;)
  32446. {
  32447. const Component* const c = childComponentList_.getUnchecked(i);
  32448. if (c != compToAvoid && c->isVisible())
  32449. {
  32450. if (c->isOpaque())
  32451. {
  32452. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32453. childBounds.translate (delta.getX(), delta.getY());
  32454. result.subtract (childBounds);
  32455. }
  32456. else
  32457. {
  32458. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32459. newClip.translate (-c->getX(), -c->getY());
  32460. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32461. newClip, compToAvoid);
  32462. }
  32463. }
  32464. }
  32465. }
  32466. void Component::mouseEnter (const MouseEvent&)
  32467. {
  32468. // base class does nothing
  32469. }
  32470. void Component::mouseExit (const MouseEvent&)
  32471. {
  32472. // base class does nothing
  32473. }
  32474. void Component::mouseDown (const MouseEvent&)
  32475. {
  32476. // base class does nothing
  32477. }
  32478. void Component::mouseUp (const MouseEvent&)
  32479. {
  32480. // base class does nothing
  32481. }
  32482. void Component::mouseDrag (const MouseEvent&)
  32483. {
  32484. // base class does nothing
  32485. }
  32486. void Component::mouseMove (const MouseEvent&)
  32487. {
  32488. // base class does nothing
  32489. }
  32490. void Component::mouseDoubleClick (const MouseEvent&)
  32491. {
  32492. // base class does nothing
  32493. }
  32494. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32495. {
  32496. // the base class just passes this event up to its parent..
  32497. if (parentComponent_ != 0)
  32498. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32499. wheelIncrementX, wheelIncrementY);
  32500. }
  32501. void Component::resized()
  32502. {
  32503. // base class does nothing
  32504. }
  32505. void Component::moved()
  32506. {
  32507. // base class does nothing
  32508. }
  32509. void Component::childBoundsChanged (Component*)
  32510. {
  32511. // base class does nothing
  32512. }
  32513. void Component::parentSizeChanged()
  32514. {
  32515. // base class does nothing
  32516. }
  32517. void Component::addComponentListener (ComponentListener* const newListener)
  32518. {
  32519. componentListeners.add (newListener);
  32520. }
  32521. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32522. {
  32523. jassert (isValidComponent());
  32524. componentListeners.remove (listenerToRemove);
  32525. }
  32526. void Component::inputAttemptWhenModal()
  32527. {
  32528. bringModalComponentToFront();
  32529. getLookAndFeel().playAlertSound();
  32530. }
  32531. bool Component::canModalEventBeSentToComponent (const Component*)
  32532. {
  32533. return false;
  32534. }
  32535. void Component::internalModalInputAttempt()
  32536. {
  32537. Component* const current = getCurrentlyModalComponent();
  32538. if (current != 0)
  32539. current->inputAttemptWhenModal();
  32540. }
  32541. void Component::paint (Graphics&)
  32542. {
  32543. // all painting is done in the subclasses
  32544. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32545. }
  32546. void Component::paintOverChildren (Graphics&)
  32547. {
  32548. // all painting is done in the subclasses
  32549. }
  32550. void Component::handleMessage (const Message& message)
  32551. {
  32552. if (message.intParameter1 == exitModalStateMessage)
  32553. {
  32554. exitModalState (message.intParameter2);
  32555. }
  32556. else if (message.intParameter1 == customCommandMessage)
  32557. {
  32558. handleCommandMessage (message.intParameter2);
  32559. }
  32560. }
  32561. void Component::postCommandMessage (const int commandId)
  32562. {
  32563. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32564. }
  32565. void Component::handleCommandMessage (int)
  32566. {
  32567. // used by subclasses
  32568. }
  32569. void Component::addMouseListener (MouseListener* const newListener,
  32570. const bool wantsEventsForAllNestedChildComponents)
  32571. {
  32572. // if component methods are being called from threads other than the message
  32573. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32574. checkMessageManagerIsLocked
  32575. if (mouseListeners_ == 0)
  32576. mouseListeners_ = new VoidArray();
  32577. if (! mouseListeners_->contains (newListener))
  32578. {
  32579. if (wantsEventsForAllNestedChildComponents)
  32580. {
  32581. mouseListeners_->insert (0, newListener);
  32582. ++numDeepMouseListeners;
  32583. }
  32584. else
  32585. {
  32586. mouseListeners_->add (newListener);
  32587. }
  32588. }
  32589. }
  32590. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32591. {
  32592. // if component methods are being called from threads other than the message
  32593. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32594. checkMessageManagerIsLocked
  32595. if (mouseListeners_ != 0)
  32596. {
  32597. const int index = mouseListeners_->indexOf (listenerToRemove);
  32598. if (index >= 0)
  32599. {
  32600. if (index < numDeepMouseListeners)
  32601. --numDeepMouseListeners;
  32602. mouseListeners_->remove (index);
  32603. }
  32604. }
  32605. }
  32606. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32607. {
  32608. if (isCurrentlyBlockedByAnotherModalComponent())
  32609. {
  32610. // if something else is modal, always just show a normal mouse cursor
  32611. source.showMouseCursor (MouseCursor::NormalCursor);
  32612. return;
  32613. }
  32614. if (! flags.mouseInsideFlag)
  32615. {
  32616. flags.mouseInsideFlag = true;
  32617. flags.mouseOverFlag = true;
  32618. flags.draggingFlag = false;
  32619. BailOutChecker checker (this);
  32620. if (flags.repaintOnMouseActivityFlag)
  32621. repaint();
  32622. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32623. this, time, relativePos,
  32624. time, 0, false);
  32625. mouseEnter (me);
  32626. if (checker.shouldBailOut())
  32627. return;
  32628. Desktop::getInstance().resetTimer();
  32629. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32630. if (checker.shouldBailOut())
  32631. return;
  32632. if (mouseListeners_ != 0)
  32633. {
  32634. for (int i = mouseListeners_->size(); --i >= 0;)
  32635. {
  32636. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32637. if (checker.shouldBailOut())
  32638. return;
  32639. i = jmin (i, mouseListeners_->size());
  32640. }
  32641. }
  32642. Component* p = parentComponent_;
  32643. while (p != 0)
  32644. {
  32645. if (p->numDeepMouseListeners > 0)
  32646. {
  32647. BailOutChecker checker (this, p);
  32648. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32649. {
  32650. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32651. if (checker.shouldBailOut())
  32652. return;
  32653. i = jmin (i, p->numDeepMouseListeners);
  32654. }
  32655. }
  32656. p = p->parentComponent_;
  32657. }
  32658. }
  32659. }
  32660. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32661. {
  32662. BailOutChecker checker (this);
  32663. if (flags.draggingFlag)
  32664. {
  32665. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32666. if (checker.shouldBailOut())
  32667. return;
  32668. }
  32669. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32670. {
  32671. flags.mouseInsideFlag = false;
  32672. flags.mouseOverFlag = false;
  32673. flags.draggingFlag = false;
  32674. if (flags.repaintOnMouseActivityFlag)
  32675. repaint();
  32676. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32677. this, time, relativePos,
  32678. time, 0, false);
  32679. mouseExit (me);
  32680. if (checker.shouldBailOut())
  32681. return;
  32682. Desktop::getInstance().resetTimer();
  32683. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32684. if (checker.shouldBailOut())
  32685. return;
  32686. if (mouseListeners_ != 0)
  32687. {
  32688. for (int i = mouseListeners_->size(); --i >= 0;)
  32689. {
  32690. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32691. if (checker.shouldBailOut())
  32692. return;
  32693. i = jmin (i, mouseListeners_->size());
  32694. }
  32695. }
  32696. Component* p = parentComponent_;
  32697. while (p != 0)
  32698. {
  32699. if (p->numDeepMouseListeners > 0)
  32700. {
  32701. BailOutChecker checker (this, p);
  32702. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32703. {
  32704. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32705. if (checker.shouldBailOut())
  32706. return;
  32707. i = jmin (i, p->numDeepMouseListeners);
  32708. }
  32709. }
  32710. p = p->parentComponent_;
  32711. }
  32712. }
  32713. }
  32714. class InternalDragRepeater : public Timer
  32715. {
  32716. public:
  32717. InternalDragRepeater()
  32718. {}
  32719. ~InternalDragRepeater()
  32720. {
  32721. clearSingletonInstance();
  32722. }
  32723. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32724. void timerCallback()
  32725. {
  32726. Desktop& desktop = Desktop::getInstance();
  32727. int numMiceDown = 0;
  32728. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32729. {
  32730. MouseInputSource* const source = desktop.getMouseSource(i);
  32731. if (source->isDragging())
  32732. {
  32733. source->triggerFakeMove();
  32734. ++numMiceDown;
  32735. }
  32736. }
  32737. if (numMiceDown == 0)
  32738. deleteInstance();
  32739. }
  32740. juce_UseDebuggingNewOperator
  32741. private:
  32742. InternalDragRepeater (const InternalDragRepeater&);
  32743. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32744. };
  32745. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32746. void Component::beginDragAutoRepeat (const int interval)
  32747. {
  32748. if (interval > 0)
  32749. {
  32750. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32751. InternalDragRepeater::getInstance()->startTimer (interval);
  32752. }
  32753. else
  32754. {
  32755. InternalDragRepeater::deleteInstance();
  32756. }
  32757. }
  32758. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32759. {
  32760. Desktop& desktop = Desktop::getInstance();
  32761. BailOutChecker checker (this);
  32762. if (isCurrentlyBlockedByAnotherModalComponent())
  32763. {
  32764. internalModalInputAttempt();
  32765. if (checker.shouldBailOut())
  32766. return;
  32767. // If processing the input attempt has exited the modal loop, we'll allow the event
  32768. // to be delivered..
  32769. if (isCurrentlyBlockedByAnotherModalComponent())
  32770. {
  32771. // allow blocked mouse-events to go to global listeners..
  32772. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32773. this, time, relativePos, time,
  32774. source.getNumberOfMultipleClicks(), false);
  32775. desktop.resetTimer();
  32776. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32777. return;
  32778. }
  32779. }
  32780. {
  32781. Component* c = this;
  32782. while (c != 0)
  32783. {
  32784. if (c->isBroughtToFrontOnMouseClick())
  32785. {
  32786. c->toFront (true);
  32787. if (checker.shouldBailOut())
  32788. return;
  32789. }
  32790. c = c->parentComponent_;
  32791. }
  32792. }
  32793. if (! flags.dontFocusOnMouseClickFlag)
  32794. {
  32795. grabFocusInternal (focusChangedByMouseClick);
  32796. if (checker.shouldBailOut())
  32797. return;
  32798. }
  32799. flags.draggingFlag = true;
  32800. flags.mouseOverFlag = true;
  32801. if (flags.repaintOnMouseActivityFlag)
  32802. repaint();
  32803. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32804. this, time, relativePos, time,
  32805. source.getNumberOfMultipleClicks(), false);
  32806. mouseDown (me);
  32807. if (checker.shouldBailOut())
  32808. return;
  32809. desktop.resetTimer();
  32810. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32811. if (checker.shouldBailOut())
  32812. return;
  32813. if (mouseListeners_ != 0)
  32814. {
  32815. for (int i = mouseListeners_->size(); --i >= 0;)
  32816. {
  32817. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32818. if (checker.shouldBailOut())
  32819. return;
  32820. i = jmin (i, mouseListeners_->size());
  32821. }
  32822. }
  32823. Component* p = parentComponent_;
  32824. while (p != 0)
  32825. {
  32826. if (p->numDeepMouseListeners > 0)
  32827. {
  32828. BailOutChecker checker (this, p);
  32829. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32830. {
  32831. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  32832. if (checker.shouldBailOut())
  32833. return;
  32834. i = jmin (i, p->numDeepMouseListeners);
  32835. }
  32836. }
  32837. p = p->parentComponent_;
  32838. }
  32839. }
  32840. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32841. {
  32842. if (flags.draggingFlag)
  32843. {
  32844. Desktop& desktop = Desktop::getInstance();
  32845. flags.draggingFlag = false;
  32846. BailOutChecker checker (this);
  32847. if (flags.repaintOnMouseActivityFlag)
  32848. repaint();
  32849. const MouseEvent me (source, relativePos,
  32850. oldModifiers, this, time,
  32851. globalPositionToRelative (source.getLastMouseDownPosition()),
  32852. source.getLastMouseDownTime(),
  32853. source.getNumberOfMultipleClicks(),
  32854. source.hasMouseMovedSignificantlySincePressed());
  32855. mouseUp (me);
  32856. if (checker.shouldBailOut())
  32857. return;
  32858. desktop.resetTimer();
  32859. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32860. if (checker.shouldBailOut())
  32861. return;
  32862. if (mouseListeners_ != 0)
  32863. {
  32864. for (int i = mouseListeners_->size(); --i >= 0;)
  32865. {
  32866. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32867. if (checker.shouldBailOut())
  32868. return;
  32869. i = jmin (i, mouseListeners_->size());
  32870. }
  32871. }
  32872. {
  32873. Component* p = parentComponent_;
  32874. while (p != 0)
  32875. {
  32876. if (p->numDeepMouseListeners > 0)
  32877. {
  32878. BailOutChecker checker (this, p);
  32879. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32880. {
  32881. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  32882. if (checker.shouldBailOut())
  32883. return;
  32884. i = jmin (i, p->numDeepMouseListeners);
  32885. }
  32886. }
  32887. p = p->parentComponent_;
  32888. }
  32889. }
  32890. // check for double-click
  32891. if (me.getNumberOfClicks() >= 2)
  32892. {
  32893. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32894. mouseDoubleClick (me);
  32895. if (checker.shouldBailOut())
  32896. return;
  32897. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32898. if (checker.shouldBailOut())
  32899. return;
  32900. for (int i = numListeners; --i >= 0;)
  32901. {
  32902. if (checker.shouldBailOut())
  32903. return;
  32904. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32905. if (ml != 0)
  32906. ml->mouseDoubleClick (me);
  32907. }
  32908. if (checker.shouldBailOut())
  32909. return;
  32910. Component* p = parentComponent_;
  32911. while (p != 0)
  32912. {
  32913. if (p->numDeepMouseListeners > 0)
  32914. {
  32915. BailOutChecker checker (this, p);
  32916. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32917. {
  32918. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  32919. if (checker.shouldBailOut())
  32920. return;
  32921. i = jmin (i, p->numDeepMouseListeners);
  32922. }
  32923. }
  32924. p = p->parentComponent_;
  32925. }
  32926. }
  32927. }
  32928. }
  32929. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32930. {
  32931. if (flags.draggingFlag)
  32932. {
  32933. Desktop& desktop = Desktop::getInstance();
  32934. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  32935. BailOutChecker checker (this);
  32936. const MouseEvent me (source, relativePos,
  32937. source.getCurrentModifiers(), this, time,
  32938. globalPositionToRelative (source.getLastMouseDownPosition()),
  32939. source.getLastMouseDownTime(),
  32940. source.getNumberOfMultipleClicks(),
  32941. source.hasMouseMovedSignificantlySincePressed());
  32942. mouseDrag (me);
  32943. if (checker.shouldBailOut())
  32944. return;
  32945. desktop.resetTimer();
  32946. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  32947. if (checker.shouldBailOut())
  32948. return;
  32949. if (mouseListeners_ != 0)
  32950. {
  32951. for (int i = mouseListeners_->size(); --i >= 0;)
  32952. {
  32953. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  32954. if (checker.shouldBailOut())
  32955. return;
  32956. i = jmin (i, mouseListeners_->size());
  32957. }
  32958. }
  32959. Component* p = parentComponent_;
  32960. while (p != 0)
  32961. {
  32962. if (p->numDeepMouseListeners > 0)
  32963. {
  32964. BailOutChecker checker (this, p);
  32965. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32966. {
  32967. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  32968. if (checker.shouldBailOut())
  32969. return;
  32970. i = jmin (i, p->numDeepMouseListeners);
  32971. }
  32972. }
  32973. p = p->parentComponent_;
  32974. }
  32975. }
  32976. }
  32977. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32978. {
  32979. Desktop& desktop = Desktop::getInstance();
  32980. BailOutChecker checker (this);
  32981. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32982. this, time, relativePos,
  32983. time, 0, false);
  32984. if (isCurrentlyBlockedByAnotherModalComponent())
  32985. {
  32986. // allow blocked mouse-events to go to global listeners..
  32987. desktop.sendMouseMove();
  32988. }
  32989. else
  32990. {
  32991. flags.mouseOverFlag = true;
  32992. mouseMove (me);
  32993. if (checker.shouldBailOut())
  32994. return;
  32995. desktop.resetTimer();
  32996. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  32997. if (checker.shouldBailOut())
  32998. return;
  32999. if (mouseListeners_ != 0)
  33000. {
  33001. for (int i = mouseListeners_->size(); --i >= 0;)
  33002. {
  33003. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  33004. if (checker.shouldBailOut())
  33005. return;
  33006. i = jmin (i, mouseListeners_->size());
  33007. }
  33008. }
  33009. Component* p = parentComponent_;
  33010. while (p != 0)
  33011. {
  33012. if (p->numDeepMouseListeners > 0)
  33013. {
  33014. BailOutChecker checker (this, p);
  33015. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33016. {
  33017. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  33018. if (checker.shouldBailOut())
  33019. return;
  33020. i = jmin (i, p->numDeepMouseListeners);
  33021. }
  33022. }
  33023. p = p->parentComponent_;
  33024. }
  33025. }
  33026. }
  33027. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  33028. const Time& time, const float amountX, const float amountY)
  33029. {
  33030. Desktop& desktop = Desktop::getInstance();
  33031. BailOutChecker checker (this);
  33032. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  33033. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  33034. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  33035. this, time, relativePos, time, 0, false);
  33036. if (isCurrentlyBlockedByAnotherModalComponent())
  33037. {
  33038. // allow blocked mouse-events to go to global listeners..
  33039. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  33040. }
  33041. else
  33042. {
  33043. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33044. if (checker.shouldBailOut())
  33045. return;
  33046. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  33047. if (checker.shouldBailOut())
  33048. return;
  33049. if (mouseListeners_ != 0)
  33050. {
  33051. for (int i = mouseListeners_->size(); --i >= 0;)
  33052. {
  33053. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33054. if (checker.shouldBailOut())
  33055. return;
  33056. i = jmin (i, mouseListeners_->size());
  33057. }
  33058. }
  33059. Component* p = parentComponent_;
  33060. while (p != 0)
  33061. {
  33062. if (p->numDeepMouseListeners > 0)
  33063. {
  33064. BailOutChecker checker (this, p);
  33065. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33066. {
  33067. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33068. if (checker.shouldBailOut())
  33069. return;
  33070. i = jmin (i, p->numDeepMouseListeners);
  33071. }
  33072. }
  33073. p = p->parentComponent_;
  33074. }
  33075. }
  33076. }
  33077. void Component::sendFakeMouseMove() const
  33078. {
  33079. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  33080. }
  33081. void Component::broughtToFront()
  33082. {
  33083. }
  33084. void Component::internalBroughtToFront()
  33085. {
  33086. if (! isValidComponent())
  33087. return;
  33088. if (flags.hasHeavyweightPeerFlag)
  33089. Desktop::getInstance().componentBroughtToFront (this);
  33090. BailOutChecker checker (this);
  33091. broughtToFront();
  33092. if (checker.shouldBailOut())
  33093. return;
  33094. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  33095. if (checker.shouldBailOut())
  33096. return;
  33097. // When brought to the front and there's a modal component blocking this one,
  33098. // we need to bring the modal one to the front instead..
  33099. Component* const cm = getCurrentlyModalComponent();
  33100. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33101. bringModalComponentToFront();
  33102. }
  33103. void Component::focusGained (FocusChangeType)
  33104. {
  33105. // base class does nothing
  33106. }
  33107. void Component::internalFocusGain (const FocusChangeType cause)
  33108. {
  33109. SafePointer<Component> safePointer (this);
  33110. focusGained (cause);
  33111. if (safePointer != 0)
  33112. internalChildFocusChange (cause);
  33113. }
  33114. void Component::focusLost (FocusChangeType)
  33115. {
  33116. // base class does nothing
  33117. }
  33118. void Component::internalFocusLoss (const FocusChangeType cause)
  33119. {
  33120. SafePointer<Component> safePointer (this);
  33121. focusLost (focusChangedDirectly);
  33122. if (safePointer != 0)
  33123. internalChildFocusChange (cause);
  33124. }
  33125. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33126. {
  33127. // base class does nothing
  33128. }
  33129. void Component::internalChildFocusChange (FocusChangeType cause)
  33130. {
  33131. const bool childIsNowFocused = hasKeyboardFocus (true);
  33132. if (flags.childCompFocusedFlag != childIsNowFocused)
  33133. {
  33134. flags.childCompFocusedFlag = childIsNowFocused;
  33135. SafePointer<Component> safePointer (this);
  33136. focusOfChildComponentChanged (cause);
  33137. if (safePointer == 0)
  33138. return;
  33139. }
  33140. if (parentComponent_ != 0)
  33141. parentComponent_->internalChildFocusChange (cause);
  33142. }
  33143. bool Component::isEnabled() const throw()
  33144. {
  33145. return (! flags.isDisabledFlag)
  33146. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33147. }
  33148. void Component::setEnabled (const bool shouldBeEnabled)
  33149. {
  33150. if (flags.isDisabledFlag == shouldBeEnabled)
  33151. {
  33152. flags.isDisabledFlag = ! shouldBeEnabled;
  33153. // if any parent components are disabled, setting our flag won't make a difference,
  33154. // so no need to send a change message
  33155. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33156. sendEnablementChangeMessage();
  33157. }
  33158. }
  33159. void Component::sendEnablementChangeMessage()
  33160. {
  33161. SafePointer<Component> safePointer (this);
  33162. enablementChanged();
  33163. if (safePointer == 0)
  33164. return;
  33165. for (int i = getNumChildComponents(); --i >= 0;)
  33166. {
  33167. Component* const c = getChildComponent (i);
  33168. if (c != 0)
  33169. {
  33170. c->sendEnablementChangeMessage();
  33171. if (safePointer == 0)
  33172. return;
  33173. }
  33174. }
  33175. }
  33176. void Component::enablementChanged()
  33177. {
  33178. }
  33179. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33180. {
  33181. flags.wantsFocusFlag = wantsFocus;
  33182. }
  33183. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33184. {
  33185. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33186. }
  33187. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33188. {
  33189. return ! flags.dontFocusOnMouseClickFlag;
  33190. }
  33191. bool Component::getWantsKeyboardFocus() const throw()
  33192. {
  33193. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33194. }
  33195. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33196. {
  33197. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33198. }
  33199. bool Component::isFocusContainer() const throw()
  33200. {
  33201. return flags.isFocusContainerFlag;
  33202. }
  33203. int Component::getExplicitFocusOrder() const
  33204. {
  33205. return properties ["_jexfo"];
  33206. }
  33207. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  33208. {
  33209. properties.set ("_jexfo", newFocusOrderIndex);
  33210. }
  33211. KeyboardFocusTraverser* Component::createFocusTraverser()
  33212. {
  33213. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33214. return new KeyboardFocusTraverser();
  33215. return parentComponent_->createFocusTraverser();
  33216. }
  33217. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33218. {
  33219. // give the focus to this component
  33220. if (currentlyFocusedComponent != this)
  33221. {
  33222. JUCE_TRY
  33223. {
  33224. // get the focus onto our desktop window
  33225. ComponentPeer* const peer = getPeer();
  33226. if (peer != 0)
  33227. {
  33228. SafePointer<Component> safePointer (this);
  33229. peer->grabFocus();
  33230. if (peer->isFocused() && currentlyFocusedComponent != this)
  33231. {
  33232. Component* const componentLosingFocus = currentlyFocusedComponent;
  33233. currentlyFocusedComponent = this;
  33234. Desktop::getInstance().triggerFocusCallback();
  33235. // call this after setting currentlyFocusedComponent so that the one that's
  33236. // losing it has a chance to see where focus is going
  33237. if (componentLosingFocus->isValidComponent())
  33238. componentLosingFocus->internalFocusLoss (cause);
  33239. if (currentlyFocusedComponent == this)
  33240. {
  33241. focusGained (cause);
  33242. if (safePointer != 0)
  33243. internalChildFocusChange (cause);
  33244. }
  33245. }
  33246. }
  33247. }
  33248. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33249. catch (const std::exception& e)
  33250. {
  33251. currentlyFocusedComponent = 0;
  33252. Desktop::getInstance().triggerFocusCallback();
  33253. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33254. }
  33255. catch (...)
  33256. {
  33257. currentlyFocusedComponent = 0;
  33258. Desktop::getInstance().triggerFocusCallback();
  33259. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33260. }
  33261. #endif
  33262. }
  33263. }
  33264. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33265. {
  33266. if (isShowing())
  33267. {
  33268. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33269. {
  33270. takeKeyboardFocus (cause);
  33271. }
  33272. else
  33273. {
  33274. if (isParentOf (currentlyFocusedComponent)
  33275. && currentlyFocusedComponent->isShowing())
  33276. {
  33277. // do nothing if the focused component is actually a child of ours..
  33278. }
  33279. else
  33280. {
  33281. // find the default child component..
  33282. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33283. if (traverser != 0)
  33284. {
  33285. Component* const defaultComp = traverser->getDefaultComponent (this);
  33286. traverser = 0;
  33287. if (defaultComp != 0)
  33288. {
  33289. defaultComp->grabFocusInternal (cause, false);
  33290. return;
  33291. }
  33292. }
  33293. if (canTryParent && parentComponent_ != 0)
  33294. {
  33295. // if no children want it and we're allowed to try our parent comp,
  33296. // then pass up to parent, which will try our siblings.
  33297. parentComponent_->grabFocusInternal (cause, true);
  33298. }
  33299. }
  33300. }
  33301. }
  33302. }
  33303. void Component::grabKeyboardFocus()
  33304. {
  33305. // if component methods are being called from threads other than the message
  33306. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33307. checkMessageManagerIsLocked
  33308. grabFocusInternal (focusChangedDirectly);
  33309. }
  33310. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33311. {
  33312. // if component methods are being called from threads other than the message
  33313. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33314. checkMessageManagerIsLocked
  33315. if (parentComponent_ != 0)
  33316. {
  33317. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33318. if (traverser != 0)
  33319. {
  33320. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33321. : traverser->getPreviousComponent (this);
  33322. traverser = 0;
  33323. if (nextComp != 0)
  33324. {
  33325. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33326. {
  33327. SafePointer<Component> safePointer (this);
  33328. internalModalInputAttempt();
  33329. if (safePointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33330. return;
  33331. }
  33332. nextComp->grabFocusInternal (focusChangedByTabKey);
  33333. return;
  33334. }
  33335. }
  33336. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33337. }
  33338. }
  33339. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33340. {
  33341. return (currentlyFocusedComponent == this)
  33342. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33343. }
  33344. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33345. {
  33346. return currentlyFocusedComponent;
  33347. }
  33348. void Component::giveAwayFocus()
  33349. {
  33350. // use a copy so we can clear the value before the call
  33351. Component* const componentLosingFocus = currentlyFocusedComponent;
  33352. currentlyFocusedComponent = 0;
  33353. Desktop::getInstance().triggerFocusCallback();
  33354. if (componentLosingFocus->isValidComponent())
  33355. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33356. }
  33357. bool Component::isMouseOver() const throw()
  33358. {
  33359. return flags.mouseOverFlag;
  33360. }
  33361. bool Component::isMouseButtonDown() const throw()
  33362. {
  33363. return flags.draggingFlag;
  33364. }
  33365. bool Component::isMouseOverOrDragging() const throw()
  33366. {
  33367. return flags.mouseOverFlag || flags.draggingFlag;
  33368. }
  33369. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33370. {
  33371. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33372. }
  33373. const Point<int> Component::getMouseXYRelative() const
  33374. {
  33375. return globalPositionToRelative (Desktop::getMousePosition());
  33376. }
  33377. const Rectangle<int> Component::getParentMonitorArea() const
  33378. {
  33379. return Desktop::getInstance()
  33380. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33381. getHeight() / 2)));
  33382. }
  33383. void Component::addKeyListener (KeyListener* const newListener)
  33384. {
  33385. if (keyListeners_ == 0)
  33386. keyListeners_ = new VoidArray();
  33387. keyListeners_->addIfNotAlreadyThere (newListener);
  33388. }
  33389. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33390. {
  33391. if (keyListeners_ != 0)
  33392. keyListeners_->removeValue (listenerToRemove);
  33393. }
  33394. bool Component::keyPressed (const KeyPress&)
  33395. {
  33396. return false;
  33397. }
  33398. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33399. {
  33400. return false;
  33401. }
  33402. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33403. {
  33404. if (parentComponent_ != 0)
  33405. parentComponent_->modifierKeysChanged (modifiers);
  33406. }
  33407. void Component::internalModifierKeysChanged()
  33408. {
  33409. sendFakeMouseMove();
  33410. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33411. }
  33412. ComponentPeer* Component::getPeer() const
  33413. {
  33414. if (flags.hasHeavyweightPeerFlag)
  33415. return ComponentPeer::getPeerFor (this);
  33416. else if (parentComponent_ != 0)
  33417. return parentComponent_->getPeer();
  33418. else
  33419. return 0;
  33420. }
  33421. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33422. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33423. {
  33424. jassert (component1 != 0);
  33425. }
  33426. bool Component::BailOutChecker::shouldBailOut() const throw()
  33427. {
  33428. return safePointer1 == 0 || safePointer2.getComponent() != component2;
  33429. }
  33430. END_JUCE_NAMESPACE
  33431. /*** End of inlined file: juce_Component.cpp ***/
  33432. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33433. BEGIN_JUCE_NAMESPACE
  33434. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33435. void ComponentListener::componentBroughtToFront (Component&) {}
  33436. void ComponentListener::componentVisibilityChanged (Component&) {}
  33437. void ComponentListener::componentChildrenChanged (Component&) {}
  33438. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33439. void ComponentListener::componentNameChanged (Component&) {}
  33440. void ComponentListener::componentBeingDeleted (Component&) {}
  33441. END_JUCE_NAMESPACE
  33442. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33443. /*** Start of inlined file: juce_Desktop.cpp ***/
  33444. BEGIN_JUCE_NAMESPACE
  33445. Desktop::Desktop()
  33446. : mouseClickCounter (0),
  33447. kioskModeComponent (0)
  33448. {
  33449. createMouseInputSources();
  33450. refreshMonitorSizes();
  33451. }
  33452. Desktop::~Desktop()
  33453. {
  33454. jassert (instance == this);
  33455. instance = 0;
  33456. // doh! If you don't delete all your windows before exiting, you're going to
  33457. // be leaking memory!
  33458. jassert (desktopComponents.size() == 0);
  33459. }
  33460. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33461. {
  33462. if (instance == 0)
  33463. instance = new Desktop();
  33464. return *instance;
  33465. }
  33466. Desktop* Desktop::instance = 0;
  33467. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33468. const bool clipToWorkArea);
  33469. void Desktop::refreshMonitorSizes()
  33470. {
  33471. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33472. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33473. monitorCoordsClipped.clear();
  33474. monitorCoordsUnclipped.clear();
  33475. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33476. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33477. jassert (monitorCoordsClipped.size() > 0
  33478. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33479. if (oldClipped != monitorCoordsClipped
  33480. || oldUnclipped != monitorCoordsUnclipped)
  33481. {
  33482. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33483. {
  33484. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33485. if (p != 0)
  33486. p->handleScreenSizeChange();
  33487. }
  33488. }
  33489. }
  33490. int Desktop::getNumDisplayMonitors() const throw()
  33491. {
  33492. return monitorCoordsClipped.size();
  33493. }
  33494. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33495. {
  33496. return clippedToWorkArea ? monitorCoordsClipped [index]
  33497. : monitorCoordsUnclipped [index];
  33498. }
  33499. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33500. {
  33501. RectangleList rl;
  33502. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33503. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33504. return rl;
  33505. }
  33506. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33507. {
  33508. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33509. }
  33510. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33511. {
  33512. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33513. double bestDistance = 1.0e10;
  33514. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33515. {
  33516. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33517. if (rect.contains (position))
  33518. return rect;
  33519. const double distance = rect.getCentre().getDistanceFrom (position);
  33520. if (distance < bestDistance)
  33521. {
  33522. bestDistance = distance;
  33523. best = rect;
  33524. }
  33525. }
  33526. return best;
  33527. }
  33528. int Desktop::getNumComponents() const throw()
  33529. {
  33530. return desktopComponents.size();
  33531. }
  33532. Component* Desktop::getComponent (const int index) const throw()
  33533. {
  33534. return desktopComponents [index];
  33535. }
  33536. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33537. {
  33538. for (int i = desktopComponents.size(); --i >= 0;)
  33539. {
  33540. Component* const c = desktopComponents.getUnchecked(i);
  33541. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33542. if (c->contains (relative.getX(), relative.getY()))
  33543. return c->getComponentAt (relative.getX(), relative.getY());
  33544. }
  33545. return 0;
  33546. }
  33547. void Desktop::addDesktopComponent (Component* const c)
  33548. {
  33549. jassert (c != 0);
  33550. jassert (! desktopComponents.contains (c));
  33551. desktopComponents.addIfNotAlreadyThere (c);
  33552. }
  33553. void Desktop::removeDesktopComponent (Component* const c)
  33554. {
  33555. desktopComponents.removeValue (c);
  33556. }
  33557. void Desktop::componentBroughtToFront (Component* const c)
  33558. {
  33559. const int index = desktopComponents.indexOf (c);
  33560. jassert (index >= 0);
  33561. if (index >= 0)
  33562. {
  33563. int newIndex = -1;
  33564. if (! c->isAlwaysOnTop())
  33565. {
  33566. newIndex = desktopComponents.size();
  33567. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33568. --newIndex;
  33569. --newIndex;
  33570. }
  33571. desktopComponents.move (index, newIndex);
  33572. }
  33573. }
  33574. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33575. {
  33576. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33577. }
  33578. int Desktop::getMouseButtonClickCounter() throw()
  33579. {
  33580. return getInstance().mouseClickCounter;
  33581. }
  33582. void Desktop::incrementMouseClickCounter() throw()
  33583. {
  33584. ++mouseClickCounter;
  33585. }
  33586. int Desktop::getNumDraggingMouseSources() const throw()
  33587. {
  33588. int num = 0;
  33589. for (int i = mouseSources.size(); --i >= 0;)
  33590. if (mouseSources.getUnchecked(i)->isDragging())
  33591. ++num;
  33592. return num;
  33593. }
  33594. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33595. {
  33596. int num = 0;
  33597. for (int i = mouseSources.size(); --i >= 0;)
  33598. {
  33599. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33600. if (mi->isDragging())
  33601. {
  33602. if (index == num)
  33603. return mi;
  33604. ++num;
  33605. }
  33606. }
  33607. return 0;
  33608. }
  33609. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33610. {
  33611. focusListeners.add (listener);
  33612. }
  33613. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33614. {
  33615. focusListeners.remove (listener);
  33616. }
  33617. void Desktop::triggerFocusCallback()
  33618. {
  33619. triggerAsyncUpdate();
  33620. }
  33621. void Desktop::handleAsyncUpdate()
  33622. {
  33623. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33624. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33625. }
  33626. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33627. {
  33628. mouseListeners.add (listener);
  33629. resetTimer();
  33630. }
  33631. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33632. {
  33633. mouseListeners.remove (listener);
  33634. resetTimer();
  33635. }
  33636. void Desktop::timerCallback()
  33637. {
  33638. if (lastFakeMouseMove != getMousePosition())
  33639. sendMouseMove();
  33640. }
  33641. void Desktop::sendMouseMove()
  33642. {
  33643. if (! mouseListeners.isEmpty())
  33644. {
  33645. startTimer (20);
  33646. lastFakeMouseMove = getMousePosition();
  33647. Component* const target = findComponentAt (lastFakeMouseMove);
  33648. if (target != 0)
  33649. {
  33650. Component::BailOutChecker checker (target);
  33651. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33652. const Time now (Time::getCurrentTime());
  33653. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33654. target, now, pos, now, 0, false);
  33655. if (me.mods.isAnyMouseButtonDown())
  33656. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33657. else
  33658. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33659. }
  33660. }
  33661. }
  33662. void Desktop::resetTimer()
  33663. {
  33664. if (mouseListeners.size() == 0)
  33665. stopTimer();
  33666. else
  33667. startTimer (100);
  33668. lastFakeMouseMove = getMousePosition();
  33669. }
  33670. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33671. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33672. {
  33673. if (kioskModeComponent != componentToUse)
  33674. {
  33675. // agh! Don't delete a component without first stopping it being the kiosk comp
  33676. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33677. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33678. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33679. if (kioskModeComponent->isValidComponent())
  33680. {
  33681. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33682. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33683. }
  33684. kioskModeComponent = componentToUse;
  33685. if (kioskModeComponent != 0)
  33686. {
  33687. jassert (kioskModeComponent->isValidComponent());
  33688. // Only components that are already on the desktop can be put into kiosk mode!
  33689. jassert (kioskModeComponent->isOnDesktop());
  33690. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33691. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33692. }
  33693. }
  33694. }
  33695. END_JUCE_NAMESPACE
  33696. /*** End of inlined file: juce_Desktop.cpp ***/
  33697. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33698. BEGIN_JUCE_NAMESPACE
  33699. ArrowButton::ArrowButton (const String& name,
  33700. float arrowDirectionInRadians,
  33701. const Colour& arrowColour)
  33702. : Button (name),
  33703. colour (arrowColour)
  33704. {
  33705. path.lineTo (0.0f, 1.0f);
  33706. path.lineTo (1.0f, 0.5f);
  33707. path.closeSubPath();
  33708. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33709. 0.5f, 0.5f));
  33710. setComponentEffect (&shadow);
  33711. buttonStateChanged();
  33712. }
  33713. ArrowButton::~ArrowButton()
  33714. {
  33715. }
  33716. void ArrowButton::paintButton (Graphics& g,
  33717. bool /*isMouseOverButton*/,
  33718. bool /*isButtonDown*/)
  33719. {
  33720. g.setColour (colour);
  33721. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33722. (float) offset,
  33723. (float) (getWidth() - 3),
  33724. (float) (getHeight() - 3),
  33725. false));
  33726. }
  33727. void ArrowButton::buttonStateChanged()
  33728. {
  33729. offset = (isDown()) ? 1 : 0;
  33730. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33731. 0.3f, -1, 0);
  33732. }
  33733. END_JUCE_NAMESPACE
  33734. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33735. /*** Start of inlined file: juce_Button.cpp ***/
  33736. BEGIN_JUCE_NAMESPACE
  33737. class Button::RepeatTimer : public Timer
  33738. {
  33739. public:
  33740. RepeatTimer (Button& owner_) : owner (owner_) {}
  33741. void timerCallback() { owner.repeatTimerCallback(); }
  33742. juce_UseDebuggingNewOperator
  33743. private:
  33744. Button& owner;
  33745. RepeatTimer (const RepeatTimer&);
  33746. RepeatTimer& operator= (const RepeatTimer&);
  33747. };
  33748. Button::Button (const String& name)
  33749. : Component (name),
  33750. text (name),
  33751. buttonPressTime (0),
  33752. lastTimeCallbackTime (0),
  33753. commandManagerToUse (0),
  33754. autoRepeatDelay (-1),
  33755. autoRepeatSpeed (0),
  33756. autoRepeatMinimumDelay (-1),
  33757. radioGroupId (0),
  33758. commandID (0),
  33759. connectedEdgeFlags (0),
  33760. buttonState (buttonNormal),
  33761. lastToggleState (false),
  33762. clickTogglesState (false),
  33763. needsToRelease (false),
  33764. needsRepainting (false),
  33765. isKeyDown (false),
  33766. triggerOnMouseDown (false),
  33767. generateTooltip (false)
  33768. {
  33769. setWantsKeyboardFocus (true);
  33770. isOn.addListener (this);
  33771. }
  33772. Button::~Button()
  33773. {
  33774. isOn.removeListener (this);
  33775. if (commandManagerToUse != 0)
  33776. commandManagerToUse->removeListener (this);
  33777. repeatTimer = 0;
  33778. clearShortcuts();
  33779. }
  33780. void Button::setButtonText (const String& newText)
  33781. {
  33782. if (text != newText)
  33783. {
  33784. text = newText;
  33785. repaint();
  33786. }
  33787. }
  33788. void Button::setTooltip (const String& newTooltip)
  33789. {
  33790. SettableTooltipClient::setTooltip (newTooltip);
  33791. generateTooltip = false;
  33792. }
  33793. const String Button::getTooltip()
  33794. {
  33795. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33796. {
  33797. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33798. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33799. for (int i = 0; i < keyPresses.size(); ++i)
  33800. {
  33801. const String key (keyPresses.getReference(i).getTextDescription());
  33802. tt << " [";
  33803. if (key.length() == 1)
  33804. tt << TRANS("shortcut") << ": '" << key << "']";
  33805. else
  33806. tt << key << ']';
  33807. }
  33808. return tt;
  33809. }
  33810. return SettableTooltipClient::getTooltip();
  33811. }
  33812. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33813. {
  33814. if (connectedEdgeFlags != connectedEdgeFlags_)
  33815. {
  33816. connectedEdgeFlags = connectedEdgeFlags_;
  33817. repaint();
  33818. }
  33819. }
  33820. void Button::setToggleState (const bool shouldBeOn,
  33821. const bool sendChangeNotification)
  33822. {
  33823. if (shouldBeOn != lastToggleState)
  33824. {
  33825. isOn = shouldBeOn;
  33826. lastToggleState = shouldBeOn;
  33827. repaint();
  33828. if (sendChangeNotification)
  33829. {
  33830. Component::SafePointer<Component> deletionWatcher (this);
  33831. sendClickMessage (ModifierKeys());
  33832. if (deletionWatcher == 0)
  33833. return;
  33834. }
  33835. if (lastToggleState)
  33836. turnOffOtherButtonsInGroup (sendChangeNotification);
  33837. }
  33838. }
  33839. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33840. {
  33841. clickTogglesState = shouldToggle;
  33842. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33843. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33844. // it is that this button represents, and the button will update its state to reflect this
  33845. // in the applicationCommandListChanged() method.
  33846. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33847. }
  33848. bool Button::getClickingTogglesState() const throw()
  33849. {
  33850. return clickTogglesState;
  33851. }
  33852. void Button::valueChanged (Value& value)
  33853. {
  33854. if (value.refersToSameSourceAs (isOn))
  33855. setToggleState (isOn.getValue(), true);
  33856. }
  33857. void Button::setRadioGroupId (const int newGroupId)
  33858. {
  33859. if (radioGroupId != newGroupId)
  33860. {
  33861. radioGroupId = newGroupId;
  33862. if (lastToggleState)
  33863. turnOffOtherButtonsInGroup (true);
  33864. }
  33865. }
  33866. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33867. {
  33868. Component* const p = getParentComponent();
  33869. if (p != 0 && radioGroupId != 0)
  33870. {
  33871. Component::SafePointer<Component> deletionWatcher (this);
  33872. for (int i = p->getNumChildComponents(); --i >= 0;)
  33873. {
  33874. Component* const c = p->getChildComponent (i);
  33875. if (c != this)
  33876. {
  33877. Button* const b = dynamic_cast <Button*> (c);
  33878. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33879. {
  33880. b->setToggleState (false, sendChangeNotification);
  33881. if (deletionWatcher == 0)
  33882. return;
  33883. }
  33884. }
  33885. }
  33886. }
  33887. }
  33888. void Button::enablementChanged()
  33889. {
  33890. updateState (0);
  33891. repaint();
  33892. }
  33893. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33894. {
  33895. ButtonState state = buttonNormal;
  33896. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33897. {
  33898. Point<int> mousePos;
  33899. if (e == 0)
  33900. mousePos = getMouseXYRelative();
  33901. else
  33902. mousePos = e->getEventRelativeTo (this).getPosition();
  33903. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33904. const bool down = isMouseButtonDown();
  33905. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33906. state = buttonDown;
  33907. else if (over)
  33908. state = buttonOver;
  33909. }
  33910. setState (state);
  33911. return state;
  33912. }
  33913. void Button::setState (const ButtonState newState)
  33914. {
  33915. if (buttonState != newState)
  33916. {
  33917. buttonState = newState;
  33918. repaint();
  33919. if (buttonState == buttonDown)
  33920. {
  33921. buttonPressTime = Time::getApproximateMillisecondCounter();
  33922. lastTimeCallbackTime = buttonPressTime;
  33923. }
  33924. sendStateMessage();
  33925. }
  33926. }
  33927. bool Button::isDown() const throw()
  33928. {
  33929. return buttonState == buttonDown;
  33930. }
  33931. bool Button::isOver() const throw()
  33932. {
  33933. return buttonState != buttonNormal;
  33934. }
  33935. void Button::buttonStateChanged()
  33936. {
  33937. }
  33938. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  33939. {
  33940. const uint32 now = Time::getApproximateMillisecondCounter();
  33941. return now > buttonPressTime ? now - buttonPressTime : 0;
  33942. }
  33943. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  33944. {
  33945. triggerOnMouseDown = isTriggeredOnMouseDown;
  33946. }
  33947. void Button::clicked()
  33948. {
  33949. }
  33950. void Button::clicked (const ModifierKeys& /*modifiers*/)
  33951. {
  33952. clicked();
  33953. }
  33954. static const int clickMessageId = 0x2f3f4f99;
  33955. void Button::triggerClick()
  33956. {
  33957. postCommandMessage (clickMessageId);
  33958. }
  33959. void Button::internalClickCallback (const ModifierKeys& modifiers)
  33960. {
  33961. if (clickTogglesState)
  33962. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  33963. sendClickMessage (modifiers);
  33964. }
  33965. void Button::flashButtonState()
  33966. {
  33967. if (isEnabled())
  33968. {
  33969. needsToRelease = true;
  33970. setState (buttonDown);
  33971. getRepeatTimer().startTimer (100);
  33972. }
  33973. }
  33974. void Button::handleCommandMessage (int commandId)
  33975. {
  33976. if (commandId == clickMessageId)
  33977. {
  33978. if (isEnabled())
  33979. {
  33980. flashButtonState();
  33981. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33982. }
  33983. }
  33984. else
  33985. {
  33986. Component::handleCommandMessage (commandId);
  33987. }
  33988. }
  33989. void Button::addButtonListener (ButtonListener* const newListener)
  33990. {
  33991. buttonListeners.add (newListener);
  33992. }
  33993. void Button::removeButtonListener (ButtonListener* const listener)
  33994. {
  33995. buttonListeners.remove (listener);
  33996. }
  33997. void Button::sendClickMessage (const ModifierKeys& modifiers)
  33998. {
  33999. Component::BailOutChecker checker (this);
  34000. if (commandManagerToUse != 0 && commandID != 0)
  34001. {
  34002. ApplicationCommandTarget::InvocationInfo info (commandID);
  34003. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34004. info.originatingComponent = this;
  34005. commandManagerToUse->invoke (info, true);
  34006. }
  34007. clicked (modifiers);
  34008. if (! checker.shouldBailOut())
  34009. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  34010. }
  34011. void Button::sendStateMessage()
  34012. {
  34013. Component::BailOutChecker checker (this);
  34014. buttonStateChanged();
  34015. if (! checker.shouldBailOut())
  34016. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  34017. }
  34018. void Button::paint (Graphics& g)
  34019. {
  34020. if (needsToRelease && isEnabled())
  34021. {
  34022. needsToRelease = false;
  34023. needsRepainting = true;
  34024. }
  34025. paintButton (g, isOver(), isDown());
  34026. }
  34027. void Button::mouseEnter (const MouseEvent& e)
  34028. {
  34029. updateState (&e);
  34030. }
  34031. void Button::mouseExit (const MouseEvent& e)
  34032. {
  34033. updateState (&e);
  34034. }
  34035. void Button::mouseDown (const MouseEvent& e)
  34036. {
  34037. updateState (&e);
  34038. if (isDown())
  34039. {
  34040. if (autoRepeatDelay >= 0)
  34041. getRepeatTimer().startTimer (autoRepeatDelay);
  34042. if (triggerOnMouseDown)
  34043. internalClickCallback (e.mods);
  34044. }
  34045. }
  34046. void Button::mouseUp (const MouseEvent& e)
  34047. {
  34048. const bool wasDown = isDown();
  34049. updateState (&e);
  34050. if (wasDown && isOver() && ! triggerOnMouseDown)
  34051. internalClickCallback (e.mods);
  34052. }
  34053. void Button::mouseDrag (const MouseEvent& e)
  34054. {
  34055. const ButtonState oldState = buttonState;
  34056. updateState (&e);
  34057. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34058. getRepeatTimer().startTimer (autoRepeatSpeed);
  34059. }
  34060. void Button::focusGained (FocusChangeType)
  34061. {
  34062. updateState (0);
  34063. repaint();
  34064. }
  34065. void Button::focusLost (FocusChangeType)
  34066. {
  34067. updateState (0);
  34068. repaint();
  34069. }
  34070. void Button::setVisible (bool shouldBeVisible)
  34071. {
  34072. if (shouldBeVisible != isVisible())
  34073. {
  34074. Component::setVisible (shouldBeVisible);
  34075. if (! shouldBeVisible)
  34076. needsToRelease = false;
  34077. updateState (0);
  34078. }
  34079. else
  34080. {
  34081. Component::setVisible (shouldBeVisible);
  34082. }
  34083. }
  34084. void Button::parentHierarchyChanged()
  34085. {
  34086. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34087. if (newKeySource != keySource.getComponent())
  34088. {
  34089. if (keySource != 0)
  34090. keySource->removeKeyListener (this);
  34091. keySource = newKeySource;
  34092. if (keySource != 0)
  34093. keySource->addKeyListener (this);
  34094. }
  34095. }
  34096. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34097. const int commandID_,
  34098. const bool generateTooltip_)
  34099. {
  34100. commandID = commandID_;
  34101. generateTooltip = generateTooltip_;
  34102. if (commandManagerToUse != commandManagerToUse_)
  34103. {
  34104. if (commandManagerToUse != 0)
  34105. commandManagerToUse->removeListener (this);
  34106. commandManagerToUse = commandManagerToUse_;
  34107. if (commandManagerToUse != 0)
  34108. commandManagerToUse->addListener (this);
  34109. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34110. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34111. // it is that this button represents, and the button will update its state to reflect this
  34112. // in the applicationCommandListChanged() method.
  34113. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34114. }
  34115. if (commandManagerToUse != 0)
  34116. applicationCommandListChanged();
  34117. else
  34118. setEnabled (true);
  34119. }
  34120. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34121. {
  34122. if (info.commandID == commandID
  34123. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34124. {
  34125. flashButtonState();
  34126. }
  34127. }
  34128. void Button::applicationCommandListChanged()
  34129. {
  34130. if (commandManagerToUse != 0)
  34131. {
  34132. ApplicationCommandInfo info (0);
  34133. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34134. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34135. if (target != 0)
  34136. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34137. }
  34138. }
  34139. void Button::addShortcut (const KeyPress& key)
  34140. {
  34141. if (key.isValid())
  34142. {
  34143. jassert (! isRegisteredForShortcut (key)); // already registered!
  34144. shortcuts.add (key);
  34145. parentHierarchyChanged();
  34146. }
  34147. }
  34148. void Button::clearShortcuts()
  34149. {
  34150. shortcuts.clear();
  34151. parentHierarchyChanged();
  34152. }
  34153. bool Button::isShortcutPressed() const
  34154. {
  34155. if (! isCurrentlyBlockedByAnotherModalComponent())
  34156. {
  34157. for (int i = shortcuts.size(); --i >= 0;)
  34158. if (shortcuts.getReference(i).isCurrentlyDown())
  34159. return true;
  34160. }
  34161. return false;
  34162. }
  34163. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34164. {
  34165. for (int i = shortcuts.size(); --i >= 0;)
  34166. if (key == shortcuts.getReference(i))
  34167. return true;
  34168. return false;
  34169. }
  34170. bool Button::keyStateChanged (const bool, Component*)
  34171. {
  34172. if (! isEnabled())
  34173. return false;
  34174. const bool wasDown = isKeyDown;
  34175. isKeyDown = isShortcutPressed();
  34176. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34177. getRepeatTimer().startTimer (autoRepeatDelay);
  34178. updateState (0);
  34179. if (isEnabled() && wasDown && ! isKeyDown)
  34180. {
  34181. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34182. // (return immediately - this button may now have been deleted)
  34183. return true;
  34184. }
  34185. return wasDown || isKeyDown;
  34186. }
  34187. bool Button::keyPressed (const KeyPress&, Component*)
  34188. {
  34189. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34190. return isShortcutPressed();
  34191. }
  34192. bool Button::keyPressed (const KeyPress& key)
  34193. {
  34194. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34195. {
  34196. triggerClick();
  34197. return true;
  34198. }
  34199. return false;
  34200. }
  34201. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34202. const int repeatMillisecs,
  34203. const int minimumDelayInMillisecs) throw()
  34204. {
  34205. autoRepeatDelay = initialDelayMillisecs;
  34206. autoRepeatSpeed = repeatMillisecs;
  34207. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34208. }
  34209. void Button::repeatTimerCallback()
  34210. {
  34211. if (needsRepainting)
  34212. {
  34213. getRepeatTimer().stopTimer();
  34214. updateState (0);
  34215. needsRepainting = false;
  34216. }
  34217. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34218. {
  34219. int repeatSpeed = autoRepeatSpeed;
  34220. if (autoRepeatMinimumDelay >= 0)
  34221. {
  34222. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34223. timeHeldDown *= timeHeldDown;
  34224. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34225. }
  34226. repeatSpeed = jmax (1, repeatSpeed);
  34227. getRepeatTimer().startTimer (repeatSpeed);
  34228. const uint32 now = Time::getApproximateMillisecondCounter();
  34229. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34230. lastTimeCallbackTime = now;
  34231. Component::SafePointer<Component> deletionWatcher (this);
  34232. for (int i = numTimesToCallback; --i >= 0;)
  34233. {
  34234. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34235. if (deletionWatcher == 0 || ! isDown())
  34236. return;
  34237. }
  34238. }
  34239. else if (! needsToRelease)
  34240. {
  34241. getRepeatTimer().stopTimer();
  34242. }
  34243. }
  34244. Button::RepeatTimer& Button::getRepeatTimer()
  34245. {
  34246. if (repeatTimer == 0)
  34247. repeatTimer = new RepeatTimer (*this);
  34248. return *repeatTimer;
  34249. }
  34250. END_JUCE_NAMESPACE
  34251. /*** End of inlined file: juce_Button.cpp ***/
  34252. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34253. BEGIN_JUCE_NAMESPACE
  34254. DrawableButton::DrawableButton (const String& name,
  34255. const DrawableButton::ButtonStyle buttonStyle)
  34256. : Button (name),
  34257. style (buttonStyle),
  34258. edgeIndent (3)
  34259. {
  34260. if (buttonStyle == ImageOnButtonBackground)
  34261. {
  34262. backgroundOff = Colour (0xffbbbbff);
  34263. backgroundOn = Colour (0xff3333ff);
  34264. }
  34265. else
  34266. {
  34267. backgroundOff = Colours::transparentBlack;
  34268. backgroundOn = Colour (0xaabbbbff);
  34269. }
  34270. }
  34271. DrawableButton::~DrawableButton()
  34272. {
  34273. deleteImages();
  34274. }
  34275. void DrawableButton::deleteImages()
  34276. {
  34277. }
  34278. void DrawableButton::setImages (const Drawable* normal,
  34279. const Drawable* over,
  34280. const Drawable* down,
  34281. const Drawable* disabled,
  34282. const Drawable* normalOn,
  34283. const Drawable* overOn,
  34284. const Drawable* downOn,
  34285. const Drawable* disabledOn)
  34286. {
  34287. deleteImages();
  34288. jassert (normal != 0); // you really need to give it at least a normal image..
  34289. if (normal != 0)
  34290. normalImage = normal->createCopy();
  34291. if (over != 0)
  34292. overImage = over->createCopy();
  34293. if (down != 0)
  34294. downImage = down->createCopy();
  34295. if (disabled != 0)
  34296. disabledImage = disabled->createCopy();
  34297. if (normalOn != 0)
  34298. normalImageOn = normalOn->createCopy();
  34299. if (overOn != 0)
  34300. overImageOn = overOn->createCopy();
  34301. if (downOn != 0)
  34302. downImageOn = downOn->createCopy();
  34303. if (disabledOn != 0)
  34304. disabledImageOn = disabledOn->createCopy();
  34305. repaint();
  34306. }
  34307. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34308. {
  34309. if (style != newStyle)
  34310. {
  34311. style = newStyle;
  34312. repaint();
  34313. }
  34314. }
  34315. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34316. const Colour& toggledOnColour)
  34317. {
  34318. if (backgroundOff != toggledOffColour
  34319. || backgroundOn != toggledOnColour)
  34320. {
  34321. backgroundOff = toggledOffColour;
  34322. backgroundOn = toggledOnColour;
  34323. repaint();
  34324. }
  34325. }
  34326. const Colour& DrawableButton::getBackgroundColour() const throw()
  34327. {
  34328. return getToggleState() ? backgroundOn
  34329. : backgroundOff;
  34330. }
  34331. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34332. {
  34333. edgeIndent = numPixelsIndent;
  34334. repaint();
  34335. }
  34336. void DrawableButton::paintButton (Graphics& g,
  34337. bool isMouseOverButton,
  34338. bool isButtonDown)
  34339. {
  34340. Rectangle<int> imageSpace;
  34341. if (style == ImageOnButtonBackground)
  34342. {
  34343. const int insetX = getWidth() / 4;
  34344. const int insetY = getHeight() / 4;
  34345. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34346. getLookAndFeel().drawButtonBackground (g, *this,
  34347. getBackgroundColour(),
  34348. isMouseOverButton,
  34349. isButtonDown);
  34350. }
  34351. else
  34352. {
  34353. g.fillAll (getBackgroundColour());
  34354. const int textH = (style == ImageAboveTextLabel)
  34355. ? jmin (16, proportionOfHeight (0.25f))
  34356. : 0;
  34357. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34358. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34359. imageSpace.setBounds (indentX, indentY,
  34360. getWidth() - indentX * 2,
  34361. getHeight() - indentY * 2 - textH);
  34362. if (textH > 0)
  34363. {
  34364. g.setFont ((float) textH);
  34365. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34366. g.drawFittedText (getButtonText(),
  34367. 2, getHeight() - textH - 1,
  34368. getWidth() - 4, textH,
  34369. Justification::centred, 1);
  34370. }
  34371. }
  34372. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34373. g.setOpacity (1.0f);
  34374. const Drawable* imageToDraw = 0;
  34375. if (isEnabled())
  34376. {
  34377. imageToDraw = getCurrentImage();
  34378. }
  34379. else
  34380. {
  34381. imageToDraw = getToggleState() ? disabledImageOn
  34382. : disabledImage;
  34383. if (imageToDraw == 0)
  34384. {
  34385. g.setOpacity (0.4f);
  34386. imageToDraw = getNormalImage();
  34387. }
  34388. }
  34389. if (imageToDraw != 0)
  34390. {
  34391. if (style == ImageRaw)
  34392. {
  34393. imageToDraw->draw (g, 1.0f);
  34394. }
  34395. else
  34396. {
  34397. imageToDraw->drawWithin (g,
  34398. imageSpace.getX(),
  34399. imageSpace.getY(),
  34400. imageSpace.getWidth(),
  34401. imageSpace.getHeight(),
  34402. RectanglePlacement::centred,
  34403. 1.0f);
  34404. }
  34405. }
  34406. }
  34407. const Drawable* DrawableButton::getCurrentImage() const throw()
  34408. {
  34409. if (isDown())
  34410. return getDownImage();
  34411. if (isOver())
  34412. return getOverImage();
  34413. return getNormalImage();
  34414. }
  34415. const Drawable* DrawableButton::getNormalImage() const throw()
  34416. {
  34417. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34418. : normalImage;
  34419. }
  34420. const Drawable* DrawableButton::getOverImage() const throw()
  34421. {
  34422. const Drawable* d = normalImage;
  34423. if (getToggleState())
  34424. {
  34425. if (overImageOn != 0)
  34426. d = overImageOn;
  34427. else if (normalImageOn != 0)
  34428. d = normalImageOn;
  34429. else if (overImage != 0)
  34430. d = overImage;
  34431. }
  34432. else
  34433. {
  34434. if (overImage != 0)
  34435. d = overImage;
  34436. }
  34437. return d;
  34438. }
  34439. const Drawable* DrawableButton::getDownImage() const throw()
  34440. {
  34441. const Drawable* d = normalImage;
  34442. if (getToggleState())
  34443. {
  34444. if (downImageOn != 0)
  34445. d = downImageOn;
  34446. else if (overImageOn != 0)
  34447. d = overImageOn;
  34448. else if (normalImageOn != 0)
  34449. d = normalImageOn;
  34450. else if (downImage != 0)
  34451. d = downImage;
  34452. else
  34453. d = getOverImage();
  34454. }
  34455. else
  34456. {
  34457. if (downImage != 0)
  34458. d = downImage;
  34459. else
  34460. d = getOverImage();
  34461. }
  34462. return d;
  34463. }
  34464. END_JUCE_NAMESPACE
  34465. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34466. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34467. BEGIN_JUCE_NAMESPACE
  34468. HyperlinkButton::HyperlinkButton (const String& linkText,
  34469. const URL& linkURL)
  34470. : Button (linkText),
  34471. url (linkURL),
  34472. font (14.0f, Font::underlined),
  34473. resizeFont (true),
  34474. justification (Justification::centred)
  34475. {
  34476. setMouseCursor (MouseCursor::PointingHandCursor);
  34477. setTooltip (linkURL.toString (false));
  34478. }
  34479. HyperlinkButton::~HyperlinkButton()
  34480. {
  34481. }
  34482. void HyperlinkButton::setFont (const Font& newFont,
  34483. const bool resizeToMatchComponentHeight,
  34484. const Justification& justificationType)
  34485. {
  34486. font = newFont;
  34487. resizeFont = resizeToMatchComponentHeight;
  34488. justification = justificationType;
  34489. repaint();
  34490. }
  34491. void HyperlinkButton::setURL (const URL& newURL) throw()
  34492. {
  34493. url = newURL;
  34494. setTooltip (newURL.toString (false));
  34495. }
  34496. const Font HyperlinkButton::getFontToUse() const
  34497. {
  34498. Font f (font);
  34499. if (resizeFont)
  34500. f.setHeight (getHeight() * 0.7f);
  34501. return f;
  34502. }
  34503. void HyperlinkButton::changeWidthToFitText()
  34504. {
  34505. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34506. }
  34507. void HyperlinkButton::colourChanged()
  34508. {
  34509. repaint();
  34510. }
  34511. void HyperlinkButton::clicked()
  34512. {
  34513. if (url.isWellFormed())
  34514. url.launchInDefaultBrowser();
  34515. }
  34516. void HyperlinkButton::paintButton (Graphics& g,
  34517. bool isMouseOverButton,
  34518. bool isButtonDown)
  34519. {
  34520. const Colour textColour (findColour (textColourId));
  34521. if (isEnabled())
  34522. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34523. : textColour);
  34524. else
  34525. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34526. g.setFont (getFontToUse());
  34527. g.drawText (getButtonText(),
  34528. 2, 0, getWidth() - 2, getHeight(),
  34529. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34530. true);
  34531. }
  34532. END_JUCE_NAMESPACE
  34533. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34534. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34535. BEGIN_JUCE_NAMESPACE
  34536. ImageButton::ImageButton (const String& text_)
  34537. : Button (text_),
  34538. scaleImageToFit (true),
  34539. preserveProportions (true),
  34540. alphaThreshold (0),
  34541. imageX (0),
  34542. imageY (0),
  34543. imageW (0),
  34544. imageH (0),
  34545. normalImage (0),
  34546. overImage (0),
  34547. downImage (0)
  34548. {
  34549. }
  34550. ImageButton::~ImageButton()
  34551. {
  34552. deleteImages();
  34553. }
  34554. void ImageButton::deleteImages()
  34555. {
  34556. ImageCache::releaseOrDelete (normalImage);
  34557. ImageCache::releaseOrDelete (overImage);
  34558. ImageCache::releaseOrDelete (downImage);
  34559. }
  34560. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34561. const bool rescaleImagesWhenButtonSizeChanges,
  34562. const bool preserveImageProportions,
  34563. Image* const normalImage_,
  34564. const float imageOpacityWhenNormal,
  34565. const Colour& overlayColourWhenNormal,
  34566. Image* const overImage_,
  34567. const float imageOpacityWhenOver,
  34568. const Colour& overlayColourWhenOver,
  34569. Image* const downImage_,
  34570. const float imageOpacityWhenDown,
  34571. const Colour& overlayColourWhenDown,
  34572. const float hitTestAlphaThreshold)
  34573. {
  34574. deleteImages();
  34575. normalImage = normalImage_;
  34576. overImage = overImage_;
  34577. downImage = downImage_;
  34578. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34579. {
  34580. imageW = normalImage->getWidth();
  34581. imageH = normalImage->getHeight();
  34582. setSize (imageW, imageH);
  34583. }
  34584. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34585. preserveProportions = preserveImageProportions;
  34586. normalOpacity = imageOpacityWhenNormal;
  34587. normalOverlay = overlayColourWhenNormal;
  34588. overOpacity = imageOpacityWhenOver;
  34589. overOverlay = overlayColourWhenOver;
  34590. downOpacity = imageOpacityWhenDown;
  34591. downOverlay = overlayColourWhenDown;
  34592. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34593. repaint();
  34594. }
  34595. Image* ImageButton::getCurrentImage() const
  34596. {
  34597. if (isDown() || getToggleState())
  34598. return getDownImage();
  34599. if (isOver())
  34600. return getOverImage();
  34601. return getNormalImage();
  34602. }
  34603. Image* ImageButton::getNormalImage() const throw()
  34604. {
  34605. return normalImage;
  34606. }
  34607. Image* ImageButton::getOverImage() const throw()
  34608. {
  34609. return (overImage != 0) ? overImage
  34610. : normalImage;
  34611. }
  34612. Image* ImageButton::getDownImage() const throw()
  34613. {
  34614. return (downImage != 0) ? downImage
  34615. : getOverImage();
  34616. }
  34617. void ImageButton::paintButton (Graphics& g,
  34618. bool isMouseOverButton,
  34619. bool isButtonDown)
  34620. {
  34621. if (! isEnabled())
  34622. {
  34623. isMouseOverButton = false;
  34624. isButtonDown = false;
  34625. }
  34626. Image* const im = getCurrentImage();
  34627. if (im != 0)
  34628. {
  34629. const int iw = im->getWidth();
  34630. const int ih = im->getHeight();
  34631. imageW = getWidth();
  34632. imageH = getHeight();
  34633. imageX = (imageW - iw) >> 1;
  34634. imageY = (imageH - ih) >> 1;
  34635. if (scaleImageToFit)
  34636. {
  34637. if (preserveProportions)
  34638. {
  34639. int newW, newH;
  34640. const float imRatio = ih / (float)iw;
  34641. const float destRatio = imageH / (float)imageW;
  34642. if (imRatio > destRatio)
  34643. {
  34644. newW = roundToInt (imageH / imRatio);
  34645. newH = imageH;
  34646. }
  34647. else
  34648. {
  34649. newW = imageW;
  34650. newH = roundToInt (imageW * imRatio);
  34651. }
  34652. imageX = (imageW - newW) / 2;
  34653. imageY = (imageH - newH) / 2;
  34654. imageW = newW;
  34655. imageH = newH;
  34656. }
  34657. else
  34658. {
  34659. imageX = 0;
  34660. imageY = 0;
  34661. }
  34662. }
  34663. if (! scaleImageToFit)
  34664. {
  34665. imageW = iw;
  34666. imageH = ih;
  34667. }
  34668. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34669. isButtonDown ? downOverlay
  34670. : (isMouseOverButton ? overOverlay
  34671. : normalOverlay),
  34672. isButtonDown ? downOpacity
  34673. : (isMouseOverButton ? overOpacity
  34674. : normalOpacity),
  34675. *this);
  34676. }
  34677. }
  34678. bool ImageButton::hitTest (int x, int y)
  34679. {
  34680. if (alphaThreshold == 0)
  34681. return true;
  34682. Image* const im = getCurrentImage();
  34683. return im == 0
  34684. || (imageW > 0 && imageH > 0
  34685. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34686. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34687. }
  34688. END_JUCE_NAMESPACE
  34689. /*** End of inlined file: juce_ImageButton.cpp ***/
  34690. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34691. BEGIN_JUCE_NAMESPACE
  34692. ShapeButton::ShapeButton (const String& text_,
  34693. const Colour& normalColour_,
  34694. const Colour& overColour_,
  34695. const Colour& downColour_)
  34696. : Button (text_),
  34697. normalColour (normalColour_),
  34698. overColour (overColour_),
  34699. downColour (downColour_),
  34700. maintainShapeProportions (false),
  34701. outlineWidth (0.0f)
  34702. {
  34703. }
  34704. ShapeButton::~ShapeButton()
  34705. {
  34706. }
  34707. void ShapeButton::setColours (const Colour& newNormalColour,
  34708. const Colour& newOverColour,
  34709. const Colour& newDownColour)
  34710. {
  34711. normalColour = newNormalColour;
  34712. overColour = newOverColour;
  34713. downColour = newDownColour;
  34714. }
  34715. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34716. const float newOutlineWidth)
  34717. {
  34718. outlineColour = newOutlineColour;
  34719. outlineWidth = newOutlineWidth;
  34720. }
  34721. void ShapeButton::setShape (const Path& newShape,
  34722. const bool resizeNowToFitThisShape,
  34723. const bool maintainShapeProportions_,
  34724. const bool hasShadow)
  34725. {
  34726. shape = newShape;
  34727. maintainShapeProportions = maintainShapeProportions_;
  34728. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34729. setComponentEffect ((hasShadow) ? &shadow : 0);
  34730. if (resizeNowToFitThisShape)
  34731. {
  34732. Rectangle<float> bounds (shape.getBounds());
  34733. if (hasShadow)
  34734. bounds.expand (4.0f, 4.0f);
  34735. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34736. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34737. 1 + (int) (bounds.getHeight() + outlineWidth));
  34738. }
  34739. }
  34740. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34741. {
  34742. if (! isEnabled())
  34743. {
  34744. isMouseOverButton = false;
  34745. isButtonDown = false;
  34746. }
  34747. g.setColour ((isButtonDown) ? downColour
  34748. : (isMouseOverButton) ? overColour
  34749. : normalColour);
  34750. int w = getWidth();
  34751. int h = getHeight();
  34752. if (getComponentEffect() != 0)
  34753. {
  34754. w -= 4;
  34755. h -= 4;
  34756. }
  34757. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34758. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34759. w - offset - outlineWidth,
  34760. h - offset - outlineWidth,
  34761. maintainShapeProportions));
  34762. g.fillPath (shape, trans);
  34763. if (outlineWidth > 0.0f)
  34764. {
  34765. g.setColour (outlineColour);
  34766. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34767. }
  34768. }
  34769. END_JUCE_NAMESPACE
  34770. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34771. /*** Start of inlined file: juce_TextButton.cpp ***/
  34772. BEGIN_JUCE_NAMESPACE
  34773. TextButton::TextButton (const String& name,
  34774. const String& toolTip)
  34775. : Button (name)
  34776. {
  34777. setTooltip (toolTip);
  34778. }
  34779. TextButton::~TextButton()
  34780. {
  34781. }
  34782. void TextButton::paintButton (Graphics& g,
  34783. bool isMouseOverButton,
  34784. bool isButtonDown)
  34785. {
  34786. getLookAndFeel().drawButtonBackground (g, *this,
  34787. findColour (getToggleState() ? buttonOnColourId
  34788. : buttonColourId),
  34789. isMouseOverButton,
  34790. isButtonDown);
  34791. getLookAndFeel().drawButtonText (g, *this,
  34792. isMouseOverButton,
  34793. isButtonDown);
  34794. }
  34795. void TextButton::colourChanged()
  34796. {
  34797. repaint();
  34798. }
  34799. const Font TextButton::getFont()
  34800. {
  34801. return Font (jmin (15.0f, getHeight() * 0.6f));
  34802. }
  34803. void TextButton::changeWidthToFitText (const int newHeight)
  34804. {
  34805. if (newHeight >= 0)
  34806. setSize (jmax (1, getWidth()), newHeight);
  34807. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34808. getHeight());
  34809. }
  34810. END_JUCE_NAMESPACE
  34811. /*** End of inlined file: juce_TextButton.cpp ***/
  34812. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34813. BEGIN_JUCE_NAMESPACE
  34814. ToggleButton::ToggleButton (const String& buttonText)
  34815. : Button (buttonText)
  34816. {
  34817. setClickingTogglesState (true);
  34818. }
  34819. ToggleButton::~ToggleButton()
  34820. {
  34821. }
  34822. void ToggleButton::paintButton (Graphics& g,
  34823. bool isMouseOverButton,
  34824. bool isButtonDown)
  34825. {
  34826. getLookAndFeel().drawToggleButton (g, *this,
  34827. isMouseOverButton,
  34828. isButtonDown);
  34829. }
  34830. void ToggleButton::changeWidthToFitText()
  34831. {
  34832. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34833. }
  34834. void ToggleButton::colourChanged()
  34835. {
  34836. repaint();
  34837. }
  34838. END_JUCE_NAMESPACE
  34839. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34840. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34841. BEGIN_JUCE_NAMESPACE
  34842. ToolbarButton::ToolbarButton (const int itemId_,
  34843. const String& buttonText,
  34844. Drawable* const normalImage_,
  34845. Drawable* const toggledOnImage_)
  34846. : ToolbarItemComponent (itemId_, buttonText, true),
  34847. normalImage (normalImage_),
  34848. toggledOnImage (toggledOnImage_)
  34849. {
  34850. }
  34851. ToolbarButton::~ToolbarButton()
  34852. {
  34853. }
  34854. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34855. bool /*isToolbarVertical*/,
  34856. int& preferredSize,
  34857. int& minSize, int& maxSize)
  34858. {
  34859. preferredSize = minSize = maxSize = toolbarDepth;
  34860. return true;
  34861. }
  34862. void ToolbarButton::paintButtonArea (Graphics& g,
  34863. int width, int height,
  34864. bool /*isMouseOver*/,
  34865. bool /*isMouseDown*/)
  34866. {
  34867. Drawable* d = normalImage;
  34868. if (getToggleState() && toggledOnImage != 0)
  34869. d = toggledOnImage;
  34870. if (! isEnabled())
  34871. {
  34872. Image im (Image::ARGB, width, height, true);
  34873. Graphics g2 (im);
  34874. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34875. im.desaturate();
  34876. g.drawImageAt (&im, 0, 0);
  34877. }
  34878. else
  34879. {
  34880. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34881. }
  34882. }
  34883. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34884. {
  34885. }
  34886. END_JUCE_NAMESPACE
  34887. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34888. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34889. BEGIN_JUCE_NAMESPACE
  34890. class CodeDocumentLine
  34891. {
  34892. public:
  34893. CodeDocumentLine (const tchar* const line_,
  34894. const int lineLength_,
  34895. const int numNewLineChars,
  34896. const int lineStartInFile_)
  34897. : line (line_, lineLength_),
  34898. lineStartInFile (lineStartInFile_),
  34899. lineLength (lineLength_),
  34900. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34901. {
  34902. }
  34903. ~CodeDocumentLine()
  34904. {
  34905. }
  34906. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34907. {
  34908. const tchar* const t = (const tchar*) text;
  34909. int pos = 0;
  34910. while (t [pos] != 0)
  34911. {
  34912. const int startOfLine = pos;
  34913. int numNewLineChars = 0;
  34914. while (t[pos] != 0)
  34915. {
  34916. if (t[pos] == T('\r'))
  34917. {
  34918. ++numNewLineChars;
  34919. ++pos;
  34920. if (t[pos] == T('\n'))
  34921. {
  34922. ++numNewLineChars;
  34923. ++pos;
  34924. }
  34925. break;
  34926. }
  34927. if (t[pos] == T('\n'))
  34928. {
  34929. ++numNewLineChars;
  34930. ++pos;
  34931. break;
  34932. }
  34933. ++pos;
  34934. }
  34935. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  34936. numNewLineChars, startOfLine));
  34937. }
  34938. jassert (pos == text.length());
  34939. }
  34940. bool endsWithLineBreak() const throw()
  34941. {
  34942. return lineLengthWithoutNewLines != lineLength;
  34943. }
  34944. void updateLength() throw()
  34945. {
  34946. lineLengthWithoutNewLines = lineLength = line.length();
  34947. while (lineLengthWithoutNewLines > 0
  34948. && (line [lineLengthWithoutNewLines - 1] == '\n'
  34949. || line [lineLengthWithoutNewLines - 1] == '\r'))
  34950. {
  34951. --lineLengthWithoutNewLines;
  34952. }
  34953. }
  34954. String line;
  34955. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  34956. };
  34957. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  34958. : document (document_),
  34959. currentLine (document_->lines[0]),
  34960. line (0),
  34961. position (0)
  34962. {
  34963. }
  34964. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  34965. : document (other.document),
  34966. currentLine (other.currentLine),
  34967. line (other.line),
  34968. position (other.position)
  34969. {
  34970. }
  34971. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  34972. {
  34973. document = other.document;
  34974. currentLine = other.currentLine;
  34975. line = other.line;
  34976. position = other.position;
  34977. return *this;
  34978. }
  34979. CodeDocument::Iterator::~Iterator() throw()
  34980. {
  34981. }
  34982. juce_wchar CodeDocument::Iterator::nextChar()
  34983. {
  34984. if (currentLine == 0)
  34985. return 0;
  34986. jassert (currentLine == document->lines.getUnchecked (line));
  34987. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  34988. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34989. {
  34990. ++line;
  34991. currentLine = document->lines [line];
  34992. }
  34993. return result;
  34994. }
  34995. void CodeDocument::Iterator::skip()
  34996. {
  34997. if (currentLine != 0)
  34998. {
  34999. jassert (currentLine == document->lines.getUnchecked (line));
  35000. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35001. {
  35002. ++line;
  35003. currentLine = document->lines [line];
  35004. }
  35005. }
  35006. }
  35007. void CodeDocument::Iterator::skipToEndOfLine()
  35008. {
  35009. if (currentLine != 0)
  35010. {
  35011. jassert (currentLine == document->lines.getUnchecked (line));
  35012. ++line;
  35013. currentLine = document->lines [line];
  35014. if (currentLine != 0)
  35015. position = currentLine->lineStartInFile;
  35016. else
  35017. position = document->getNumCharacters();
  35018. }
  35019. }
  35020. juce_wchar CodeDocument::Iterator::peekNextChar() const
  35021. {
  35022. if (currentLine == 0)
  35023. return 0;
  35024. jassert (currentLine == document->lines.getUnchecked (line));
  35025. return const_cast <const String&> (currentLine->line) [position - currentLine->lineStartInFile];
  35026. }
  35027. void CodeDocument::Iterator::skipWhitespace()
  35028. {
  35029. while (CharacterFunctions::isWhitespace (peekNextChar()))
  35030. skip();
  35031. }
  35032. bool CodeDocument::Iterator::isEOF() const throw()
  35033. {
  35034. return currentLine == 0;
  35035. }
  35036. CodeDocument::Position::Position() throw()
  35037. : owner (0), characterPos (0), line (0),
  35038. indexInLine (0), positionMaintained (false)
  35039. {
  35040. }
  35041. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35042. const int line_, const int indexInLine_) throw()
  35043. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35044. characterPos (0), line (line_),
  35045. indexInLine (indexInLine_), positionMaintained (false)
  35046. {
  35047. setLineAndIndex (line_, indexInLine_);
  35048. }
  35049. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35050. const int characterPos_) throw()
  35051. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35052. positionMaintained (false)
  35053. {
  35054. setPosition (characterPos_);
  35055. }
  35056. CodeDocument::Position::Position (const Position& other) throw()
  35057. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35058. indexInLine (other.indexInLine), positionMaintained (false)
  35059. {
  35060. jassert (*this == other);
  35061. }
  35062. CodeDocument::Position::~Position() throw()
  35063. {
  35064. setPositionMaintained (false);
  35065. }
  35066. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35067. {
  35068. if (this != &other)
  35069. {
  35070. const bool wasPositionMaintained = positionMaintained;
  35071. if (owner != other.owner)
  35072. setPositionMaintained (false);
  35073. owner = other.owner;
  35074. line = other.line;
  35075. indexInLine = other.indexInLine;
  35076. characterPos = other.characterPos;
  35077. setPositionMaintained (wasPositionMaintained);
  35078. jassert (*this == other);
  35079. }
  35080. return *this;
  35081. }
  35082. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35083. {
  35084. jassert ((characterPos == other.characterPos)
  35085. == (line == other.line && indexInLine == other.indexInLine));
  35086. return characterPos == other.characterPos
  35087. && line == other.line
  35088. && indexInLine == other.indexInLine
  35089. && owner == other.owner;
  35090. }
  35091. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35092. {
  35093. return ! operator== (other);
  35094. }
  35095. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35096. {
  35097. jassert (owner != 0);
  35098. if (owner->lines.size() == 0)
  35099. {
  35100. line = 0;
  35101. indexInLine = 0;
  35102. characterPos = 0;
  35103. }
  35104. else
  35105. {
  35106. if (newLine >= owner->lines.size())
  35107. {
  35108. line = owner->lines.size() - 1;
  35109. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35110. jassert (l != 0);
  35111. indexInLine = l->lineLengthWithoutNewLines;
  35112. characterPos = l->lineStartInFile + indexInLine;
  35113. }
  35114. else
  35115. {
  35116. line = jmax (0, newLine);
  35117. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35118. jassert (l != 0);
  35119. if (l->lineLengthWithoutNewLines > 0)
  35120. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35121. else
  35122. indexInLine = 0;
  35123. characterPos = l->lineStartInFile + indexInLine;
  35124. }
  35125. }
  35126. }
  35127. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35128. {
  35129. jassert (owner != 0);
  35130. line = 0;
  35131. indexInLine = 0;
  35132. characterPos = 0;
  35133. if (newPosition > 0)
  35134. {
  35135. int lineStart = 0;
  35136. int lineEnd = owner->lines.size();
  35137. for (;;)
  35138. {
  35139. if (lineEnd - lineStart < 4)
  35140. {
  35141. for (int i = lineStart; i < lineEnd; ++i)
  35142. {
  35143. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35144. int index = newPosition - l->lineStartInFile;
  35145. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35146. {
  35147. line = i;
  35148. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35149. characterPos = l->lineStartInFile + indexInLine;
  35150. }
  35151. }
  35152. break;
  35153. }
  35154. else
  35155. {
  35156. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35157. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35158. if (newPosition >= mid->lineStartInFile)
  35159. lineStart = midIndex;
  35160. else
  35161. lineEnd = midIndex;
  35162. }
  35163. }
  35164. }
  35165. }
  35166. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35167. {
  35168. jassert (owner != 0);
  35169. if (characterDelta == 1)
  35170. {
  35171. setPosition (getPosition());
  35172. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35173. if (line < owner->lines.size())
  35174. {
  35175. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35176. if (indexInLine + characterDelta < l->lineLength
  35177. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35178. ++characterDelta;
  35179. }
  35180. }
  35181. setPosition (characterPos + characterDelta);
  35182. }
  35183. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35184. {
  35185. CodeDocument::Position p (*this);
  35186. p.moveBy (characterDelta);
  35187. return p;
  35188. }
  35189. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35190. {
  35191. CodeDocument::Position p (*this);
  35192. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35193. return p;
  35194. }
  35195. const tchar CodeDocument::Position::getCharacter() const throw()
  35196. {
  35197. const CodeDocumentLine* const l = owner->lines [line];
  35198. return l == 0 ? 0 : l->line [getIndexInLine()];
  35199. }
  35200. const String CodeDocument::Position::getLineText() const throw()
  35201. {
  35202. const CodeDocumentLine* const l = owner->lines [line];
  35203. return l == 0 ? String::empty : l->line;
  35204. }
  35205. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35206. {
  35207. if (isMaintained != positionMaintained)
  35208. {
  35209. positionMaintained = isMaintained;
  35210. if (owner != 0)
  35211. {
  35212. if (isMaintained)
  35213. {
  35214. jassert (! owner->positionsToMaintain.contains (this));
  35215. owner->positionsToMaintain.add (this);
  35216. }
  35217. else
  35218. {
  35219. jassert (owner->positionsToMaintain.contains (this));
  35220. owner->positionsToMaintain.removeValue (this);
  35221. }
  35222. }
  35223. }
  35224. }
  35225. CodeDocument::CodeDocument()
  35226. : undoManager (std::numeric_limits<int>::max(), 10000),
  35227. currentActionIndex (0),
  35228. indexOfSavedState (-1),
  35229. maximumLineLength (-1),
  35230. newLineChars ("\r\n")
  35231. {
  35232. }
  35233. CodeDocument::~CodeDocument()
  35234. {
  35235. }
  35236. const String CodeDocument::getAllContent() const throw()
  35237. {
  35238. return getTextBetween (Position (this, 0),
  35239. Position (this, lines.size(), 0));
  35240. }
  35241. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35242. {
  35243. if (end.getPosition() <= start.getPosition())
  35244. return String::empty;
  35245. const int startLine = start.getLineNumber();
  35246. const int endLine = end.getLineNumber();
  35247. if (startLine == endLine)
  35248. {
  35249. CodeDocumentLine* const line = lines [startLine];
  35250. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35251. }
  35252. String result;
  35253. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35254. String::Concatenator concatenator (result);
  35255. const int maxLine = jmin (lines.size() - 1, endLine);
  35256. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35257. {
  35258. const CodeDocumentLine* line = lines.getUnchecked(i);
  35259. int len = line->lineLength;
  35260. if (i == startLine)
  35261. {
  35262. const int index = start.getIndexInLine();
  35263. concatenator.append (line->line.substring (index, len));
  35264. }
  35265. else if (i == endLine)
  35266. {
  35267. len = end.getIndexInLine();
  35268. concatenator.append (line->line.substring (0, len));
  35269. }
  35270. else
  35271. {
  35272. concatenator.append (line->line);
  35273. }
  35274. }
  35275. return result;
  35276. }
  35277. int CodeDocument::getNumCharacters() const throw()
  35278. {
  35279. const CodeDocumentLine* const lastLine = lines.getLast();
  35280. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35281. }
  35282. const String CodeDocument::getLine (const int lineIndex) const throw()
  35283. {
  35284. const CodeDocumentLine* const line = lines [lineIndex];
  35285. return (line == 0) ? String::empty : line->line;
  35286. }
  35287. int CodeDocument::getMaximumLineLength() throw()
  35288. {
  35289. if (maximumLineLength < 0)
  35290. {
  35291. maximumLineLength = 0;
  35292. for (int i = lines.size(); --i >= 0;)
  35293. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35294. }
  35295. return maximumLineLength;
  35296. }
  35297. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35298. {
  35299. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35300. }
  35301. void CodeDocument::insertText (const Position& position, const String& text)
  35302. {
  35303. insert (text, position.getPosition(), true);
  35304. }
  35305. void CodeDocument::replaceAllContent (const String& newContent)
  35306. {
  35307. remove (0, getNumCharacters(), true);
  35308. insert (newContent, 0, true);
  35309. }
  35310. bool CodeDocument::loadFromStream (InputStream& stream)
  35311. {
  35312. replaceAllContent (stream.readEntireStreamAsString());
  35313. setSavePoint();
  35314. clearUndoHistory();
  35315. return true;
  35316. }
  35317. bool CodeDocument::writeToStream (OutputStream& stream)
  35318. {
  35319. for (int i = 0; i < lines.size(); ++i)
  35320. {
  35321. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35322. const char* utf8 = temp.toUTF8();
  35323. if (! stream.write (utf8, (int) strlen (utf8)))
  35324. return false;
  35325. }
  35326. return true;
  35327. }
  35328. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35329. {
  35330. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35331. newLineChars = newLine;
  35332. }
  35333. void CodeDocument::newTransaction()
  35334. {
  35335. undoManager.beginNewTransaction (String::empty);
  35336. }
  35337. void CodeDocument::undo()
  35338. {
  35339. newTransaction();
  35340. undoManager.undo();
  35341. }
  35342. void CodeDocument::redo()
  35343. {
  35344. undoManager.redo();
  35345. }
  35346. void CodeDocument::clearUndoHistory()
  35347. {
  35348. undoManager.clearUndoHistory();
  35349. }
  35350. void CodeDocument::setSavePoint() throw()
  35351. {
  35352. indexOfSavedState = currentActionIndex;
  35353. }
  35354. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35355. {
  35356. return currentActionIndex != indexOfSavedState;
  35357. }
  35358. static int getCodeCharacterCategory (const tchar character) throw()
  35359. {
  35360. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35361. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35362. }
  35363. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35364. {
  35365. Position p (position);
  35366. const int maxDistance = 256;
  35367. int i = 0;
  35368. while (i < maxDistance
  35369. && CharacterFunctions::isWhitespace (p.getCharacter())
  35370. && (i == 0 || (p.getCharacter() != T('\n')
  35371. && p.getCharacter() != T('\r'))))
  35372. {
  35373. ++i;
  35374. p.moveBy (1);
  35375. }
  35376. if (i == 0)
  35377. {
  35378. const int type = getCodeCharacterCategory (p.getCharacter());
  35379. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35380. {
  35381. ++i;
  35382. p.moveBy (1);
  35383. }
  35384. while (i < maxDistance
  35385. && CharacterFunctions::isWhitespace (p.getCharacter())
  35386. && (i == 0 || (p.getCharacter() != T('\n')
  35387. && p.getCharacter() != T('\r'))))
  35388. {
  35389. ++i;
  35390. p.moveBy (1);
  35391. }
  35392. }
  35393. return p;
  35394. }
  35395. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35396. {
  35397. Position p (position);
  35398. const int maxDistance = 256;
  35399. int i = 0;
  35400. bool stoppedAtLineStart = false;
  35401. while (i < maxDistance)
  35402. {
  35403. const tchar c = p.movedBy (-1).getCharacter();
  35404. if (c == T('\r') || c == T('\n'))
  35405. {
  35406. stoppedAtLineStart = true;
  35407. if (i > 0)
  35408. break;
  35409. }
  35410. if (! CharacterFunctions::isWhitespace (c))
  35411. break;
  35412. p.moveBy (-1);
  35413. ++i;
  35414. }
  35415. if (i < maxDistance && ! stoppedAtLineStart)
  35416. {
  35417. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35418. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35419. {
  35420. p.moveBy (-1);
  35421. ++i;
  35422. }
  35423. }
  35424. return p;
  35425. }
  35426. void CodeDocument::checkLastLineStatus()
  35427. {
  35428. while (lines.size() > 0
  35429. && lines.getLast()->lineLength == 0
  35430. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35431. {
  35432. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35433. lines.removeLast();
  35434. }
  35435. const CodeDocumentLine* const lastLine = lines.getLast();
  35436. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35437. {
  35438. // check that there's an empty line at the end if the preceding one ends in a newline..
  35439. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35440. }
  35441. }
  35442. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35443. {
  35444. listeners.addIfNotAlreadyThere (listener);
  35445. }
  35446. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35447. {
  35448. listeners.removeValue (listener);
  35449. }
  35450. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35451. {
  35452. const Position startPos (this, startLine, 0);
  35453. const Position endPos (this, endLine, 0);
  35454. for (int i = listeners.size(); --i >= 0;)
  35455. {
  35456. Listener* const l = (Listener*) listeners[i];
  35457. if (l != 0)
  35458. l->codeDocumentChanged (startPos, endPos);
  35459. }
  35460. }
  35461. class CodeDocumentInsertAction : public UndoableAction
  35462. {
  35463. CodeDocument& owner;
  35464. const String text;
  35465. int insertPos;
  35466. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35467. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35468. public:
  35469. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35470. : owner (owner_),
  35471. text (text_),
  35472. insertPos (insertPos_)
  35473. {
  35474. }
  35475. ~CodeDocumentInsertAction() {}
  35476. bool perform()
  35477. {
  35478. owner.currentActionIndex++;
  35479. owner.insert (text, insertPos, false);
  35480. return true;
  35481. }
  35482. bool undo()
  35483. {
  35484. owner.currentActionIndex--;
  35485. owner.remove (insertPos, insertPos + text.length(), false);
  35486. return true;
  35487. }
  35488. int getSizeInUnits() { return text.length() + 32; }
  35489. };
  35490. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35491. {
  35492. if (text.isEmpty())
  35493. return;
  35494. if (undoable)
  35495. {
  35496. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35497. }
  35498. else
  35499. {
  35500. Position pos (this, insertPos);
  35501. const int firstAffectedLine = pos.getLineNumber();
  35502. int lastAffectedLine = firstAffectedLine + 1;
  35503. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35504. String textInsideOriginalLine (text);
  35505. if (firstLine != 0)
  35506. {
  35507. const int index = pos.getIndexInLine();
  35508. textInsideOriginalLine = firstLine->line.substring (0, index)
  35509. + textInsideOriginalLine
  35510. + firstLine->line.substring (index);
  35511. }
  35512. maximumLineLength = -1;
  35513. Array <CodeDocumentLine*> newLines;
  35514. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35515. jassert (newLines.size() > 0);
  35516. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35517. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35518. lines.set (firstAffectedLine, newFirstLine);
  35519. if (newLines.size() > 1)
  35520. {
  35521. for (int i = 1; i < newLines.size(); ++i)
  35522. {
  35523. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35524. lines.insert (firstAffectedLine + i, l);
  35525. }
  35526. lastAffectedLine = lines.size();
  35527. }
  35528. int i, lineStart = newFirstLine->lineStartInFile;
  35529. for (i = firstAffectedLine; i < lines.size(); ++i)
  35530. {
  35531. CodeDocumentLine* const l = lines.getUnchecked (i);
  35532. l->lineStartInFile = lineStart;
  35533. lineStart += l->lineLength;
  35534. }
  35535. checkLastLineStatus();
  35536. const int newTextLength = text.length();
  35537. for (i = 0; i < positionsToMaintain.size(); ++i)
  35538. {
  35539. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35540. if (p->getPosition() >= insertPos)
  35541. p->setPosition (p->getPosition() + newTextLength);
  35542. }
  35543. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35544. }
  35545. }
  35546. class CodeDocumentDeleteAction : public UndoableAction
  35547. {
  35548. CodeDocument& owner;
  35549. int startPos, endPos;
  35550. String removedText;
  35551. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35552. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35553. public:
  35554. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35555. : owner (owner_),
  35556. startPos (startPos_),
  35557. endPos (endPos_)
  35558. {
  35559. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35560. CodeDocument::Position (&owner, endPos));
  35561. }
  35562. ~CodeDocumentDeleteAction() {}
  35563. bool perform()
  35564. {
  35565. owner.currentActionIndex++;
  35566. owner.remove (startPos, endPos, false);
  35567. return true;
  35568. }
  35569. bool undo()
  35570. {
  35571. owner.currentActionIndex--;
  35572. owner.insert (removedText, startPos, false);
  35573. return true;
  35574. }
  35575. int getSizeInUnits() { return removedText.length() + 32; }
  35576. };
  35577. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35578. {
  35579. if (endPos <= startPos)
  35580. return;
  35581. if (undoable)
  35582. {
  35583. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35584. }
  35585. else
  35586. {
  35587. Position startPosition (this, startPos);
  35588. Position endPosition (this, endPos);
  35589. maximumLineLength = -1;
  35590. const int firstAffectedLine = startPosition.getLineNumber();
  35591. const int endLine = endPosition.getLineNumber();
  35592. int lastAffectedLine = firstAffectedLine + 1;
  35593. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35594. if (firstAffectedLine == endLine)
  35595. {
  35596. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35597. + firstLine->line.substring (endPosition.getIndexInLine());
  35598. firstLine->updateLength();
  35599. }
  35600. else
  35601. {
  35602. lastAffectedLine = lines.size();
  35603. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35604. jassert (lastLine != 0);
  35605. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35606. + lastLine->line.substring (endPosition.getIndexInLine());
  35607. firstLine->updateLength();
  35608. int numLinesToRemove = endLine - firstAffectedLine;
  35609. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35610. }
  35611. int i;
  35612. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35613. {
  35614. CodeDocumentLine* const l = lines.getUnchecked (i);
  35615. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35616. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35617. }
  35618. checkLastLineStatus();
  35619. const int totalChars = getNumCharacters();
  35620. for (i = 0; i < positionsToMaintain.size(); ++i)
  35621. {
  35622. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35623. if (p->getPosition() > startPosition.getPosition())
  35624. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35625. if (p->getPosition() > totalChars)
  35626. p->setPosition (totalChars);
  35627. }
  35628. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35629. }
  35630. }
  35631. END_JUCE_NAMESPACE
  35632. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35633. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35634. BEGIN_JUCE_NAMESPACE
  35635. class CaretComponent : public Component,
  35636. public Timer
  35637. {
  35638. public:
  35639. CaretComponent()
  35640. {
  35641. setAlwaysOnTop (true);
  35642. setInterceptsMouseClicks (false, false);
  35643. }
  35644. ~CaretComponent()
  35645. {
  35646. }
  35647. void paint (Graphics& g)
  35648. {
  35649. if (getParentComponent()->hasKeyboardFocus (true))
  35650. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35651. }
  35652. void timerCallback()
  35653. {
  35654. setVisible (! isVisible());
  35655. }
  35656. void updatePosition (CodeEditorComponent& owner)
  35657. {
  35658. startTimer (400);
  35659. setVisible (true);
  35660. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35661. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35662. }
  35663. };
  35664. class CodeEditorComponent::CodeEditorLine
  35665. {
  35666. public:
  35667. CodeEditorLine() throw()
  35668. {
  35669. }
  35670. ~CodeEditorLine() throw()
  35671. {
  35672. }
  35673. bool update (CodeDocument& document, int lineNum,
  35674. CodeDocument::Iterator& source,
  35675. CodeTokeniser* analyser, const int spacesPerTab,
  35676. const CodeDocument::Position& selectionStart,
  35677. const CodeDocument::Position& selectionEnd)
  35678. {
  35679. Array <SyntaxToken> newTokens;
  35680. newTokens.ensureStorageAllocated (8);
  35681. if (analyser == 0)
  35682. {
  35683. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35684. }
  35685. else if (lineNum < document.getNumLines())
  35686. {
  35687. const CodeDocument::Position pos (&document, lineNum, 0);
  35688. createTokens (pos.getPosition(), pos.getLineText(),
  35689. source, analyser, newTokens);
  35690. }
  35691. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35692. int newHighlightStart = 0;
  35693. int newHighlightEnd = 0;
  35694. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35695. {
  35696. const String line (document.getLine (lineNum));
  35697. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35698. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35699. line, spacesPerTab);
  35700. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35701. line, spacesPerTab);
  35702. }
  35703. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35704. {
  35705. highlightColumnStart = newHighlightStart;
  35706. highlightColumnEnd = newHighlightEnd;
  35707. }
  35708. else
  35709. {
  35710. if (tokens.size() == newTokens.size())
  35711. {
  35712. bool allTheSame = true;
  35713. for (int i = newTokens.size(); --i >= 0;)
  35714. {
  35715. if (tokens.getReference(i) != newTokens.getReference(i))
  35716. {
  35717. allTheSame = false;
  35718. break;
  35719. }
  35720. }
  35721. if (allTheSame)
  35722. return false;
  35723. }
  35724. }
  35725. tokens.swapWithArray (newTokens);
  35726. return true;
  35727. }
  35728. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35729. float x, const int y, const int baselineOffset, const int lineHeight,
  35730. const Colour& highlightColour) const throw()
  35731. {
  35732. if (highlightColumnStart < highlightColumnEnd)
  35733. {
  35734. g.setColour (highlightColour);
  35735. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35736. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35737. }
  35738. int lastType = std::numeric_limits<int>::min();
  35739. for (int i = 0; i < tokens.size(); ++i)
  35740. {
  35741. SyntaxToken& token = tokens.getReference(i);
  35742. if (lastType != token.tokenType)
  35743. {
  35744. lastType = token.tokenType;
  35745. g.setColour (owner.getColourForTokenType (lastType));
  35746. }
  35747. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35748. if (i < tokens.size() - 1)
  35749. {
  35750. if (token.width < 0)
  35751. token.width = font.getStringWidthFloat (token.text);
  35752. x += token.width;
  35753. }
  35754. }
  35755. }
  35756. private:
  35757. struct SyntaxToken
  35758. {
  35759. String text;
  35760. int tokenType;
  35761. float width;
  35762. SyntaxToken (const String& text_, const int type) throw()
  35763. : text (text_), tokenType (type), width (-1.0f)
  35764. {
  35765. }
  35766. bool operator!= (const SyntaxToken& other) const throw()
  35767. {
  35768. return text != other.text || tokenType != other.tokenType;
  35769. }
  35770. };
  35771. Array <SyntaxToken> tokens;
  35772. int highlightColumnStart, highlightColumnEnd;
  35773. static void createTokens (int startPosition, const String& lineText,
  35774. CodeDocument::Iterator& source,
  35775. CodeTokeniser* analyser,
  35776. Array <SyntaxToken>& newTokens)
  35777. {
  35778. CodeDocument::Iterator lastIterator (source);
  35779. const int lineLength = lineText.length();
  35780. for (;;)
  35781. {
  35782. int tokenType = analyser->readNextToken (source);
  35783. int tokenStart = lastIterator.getPosition();
  35784. int tokenEnd = source.getPosition();
  35785. if (tokenEnd <= tokenStart)
  35786. break;
  35787. tokenEnd -= startPosition;
  35788. if (tokenEnd > 0)
  35789. {
  35790. tokenStart -= startPosition;
  35791. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35792. tokenType));
  35793. if (tokenEnd >= lineLength)
  35794. break;
  35795. }
  35796. lastIterator = source;
  35797. }
  35798. source = lastIterator;
  35799. }
  35800. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35801. {
  35802. int x = 0;
  35803. for (int i = 0; i < tokens.size(); ++i)
  35804. {
  35805. SyntaxToken& t = tokens.getReference(i);
  35806. for (;;)
  35807. {
  35808. int tabPos = t.text.indexOfChar (T('\t'));
  35809. if (tabPos < 0)
  35810. break;
  35811. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35812. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  35813. }
  35814. x += t.text.length();
  35815. }
  35816. }
  35817. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35818. {
  35819. jassert (index <= line.length());
  35820. int col = 0;
  35821. for (int i = 0; i < index; ++i)
  35822. {
  35823. if (line[i] != T('\t'))
  35824. ++col;
  35825. else
  35826. col += spacesPerTab - (col % spacesPerTab);
  35827. }
  35828. return col;
  35829. }
  35830. };
  35831. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35832. CodeTokeniser* const codeTokeniser_)
  35833. : document (document_),
  35834. firstLineOnScreen (0),
  35835. gutter (5),
  35836. spacesPerTab (4),
  35837. lineHeight (0),
  35838. linesOnScreen (0),
  35839. columnsOnScreen (0),
  35840. scrollbarThickness (16),
  35841. columnToTryToMaintain (-1),
  35842. useSpacesForTabs (false),
  35843. xOffset (0),
  35844. codeTokeniser (codeTokeniser_)
  35845. {
  35846. caretPos = CodeDocument::Position (&document_, 0, 0);
  35847. caretPos.setPositionMaintained (true);
  35848. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35849. selectionStart.setPositionMaintained (true);
  35850. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35851. selectionEnd.setPositionMaintained (true);
  35852. setOpaque (true);
  35853. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35854. setWantsKeyboardFocus (true);
  35855. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35856. verticalScrollBar->setSingleStepSize (1.0);
  35857. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35858. horizontalScrollBar->setSingleStepSize (1.0);
  35859. addAndMakeVisible (caret = new CaretComponent());
  35860. Font f (12.0f);
  35861. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35862. setFont (f);
  35863. resetToDefaultColours();
  35864. verticalScrollBar->addListener (this);
  35865. horizontalScrollBar->addListener (this);
  35866. document.addListener (this);
  35867. }
  35868. CodeEditorComponent::~CodeEditorComponent()
  35869. {
  35870. document.removeListener (this);
  35871. deleteAllChildren();
  35872. }
  35873. void CodeEditorComponent::loadContent (const String& newContent)
  35874. {
  35875. clearCachedIterators (0);
  35876. document.replaceAllContent (newContent);
  35877. document.clearUndoHistory();
  35878. document.setSavePoint();
  35879. caretPos.setPosition (0);
  35880. selectionStart.setPosition (0);
  35881. selectionEnd.setPosition (0);
  35882. scrollToLine (0);
  35883. }
  35884. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35885. const CodeDocument::Position& affectedTextEnd)
  35886. {
  35887. clearCachedIterators (affectedTextStart.getLineNumber());
  35888. triggerAsyncUpdate();
  35889. ((CaretComponent*) caret)->updatePosition (*this);
  35890. columnToTryToMaintain = -1;
  35891. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35892. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35893. deselectAll();
  35894. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35895. || caretPos.getPosition() < affectedTextStart.getPosition())
  35896. moveCaretTo (affectedTextStart, false);
  35897. updateScrollBars();
  35898. }
  35899. void CodeEditorComponent::resized()
  35900. {
  35901. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35902. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35903. lines.clear();
  35904. rebuildLineTokens();
  35905. ((CaretComponent*) caret)->updatePosition (*this);
  35906. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35907. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35908. updateScrollBars();
  35909. }
  35910. void CodeEditorComponent::paint (Graphics& g)
  35911. {
  35912. handleUpdateNowIfNeeded();
  35913. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35914. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  35915. g.setFont (font);
  35916. const int baselineOffset = (int) font.getAscent();
  35917. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  35918. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  35919. const Rectangle<int> clip (g.getClipBounds());
  35920. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  35921. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  35922. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  35923. {
  35924. lines.getUnchecked(j)->draw (*this, g, font,
  35925. (float) (gutter - xOffset * charWidth),
  35926. lineHeight * j, baselineOffset, lineHeight,
  35927. highlightColour);
  35928. }
  35929. }
  35930. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  35931. {
  35932. if (scrollbarThickness != thickness)
  35933. {
  35934. scrollbarThickness = thickness;
  35935. resized();
  35936. }
  35937. }
  35938. void CodeEditorComponent::handleAsyncUpdate()
  35939. {
  35940. rebuildLineTokens();
  35941. }
  35942. void CodeEditorComponent::rebuildLineTokens()
  35943. {
  35944. cancelPendingUpdate();
  35945. const int numNeeded = linesOnScreen + 1;
  35946. int minLineToRepaint = numNeeded;
  35947. int maxLineToRepaint = 0;
  35948. if (numNeeded != lines.size())
  35949. {
  35950. lines.clear();
  35951. for (int i = numNeeded; --i >= 0;)
  35952. lines.add (new CodeEditorLine());
  35953. minLineToRepaint = 0;
  35954. maxLineToRepaint = numNeeded;
  35955. }
  35956. jassert (numNeeded == lines.size());
  35957. CodeDocument::Iterator source (&document);
  35958. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  35959. for (int i = 0; i < numNeeded; ++i)
  35960. {
  35961. CodeEditorLine* const line = lines.getUnchecked(i);
  35962. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  35963. selectionStart, selectionEnd))
  35964. {
  35965. minLineToRepaint = jmin (minLineToRepaint, i);
  35966. maxLineToRepaint = jmax (maxLineToRepaint, i);
  35967. }
  35968. }
  35969. if (minLineToRepaint <= maxLineToRepaint)
  35970. {
  35971. repaint (gutter, lineHeight * minLineToRepaint - 1,
  35972. verticalScrollBar->getX() - gutter,
  35973. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  35974. }
  35975. }
  35976. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  35977. {
  35978. caretPos = newPos;
  35979. columnToTryToMaintain = -1;
  35980. if (highlighting)
  35981. {
  35982. if (dragType == notDragging)
  35983. {
  35984. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  35985. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  35986. dragType = draggingSelectionStart;
  35987. else
  35988. dragType = draggingSelectionEnd;
  35989. }
  35990. if (dragType == draggingSelectionStart)
  35991. {
  35992. selectionStart = caretPos;
  35993. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35994. {
  35995. const CodeDocument::Position temp (selectionStart);
  35996. selectionStart = selectionEnd;
  35997. selectionEnd = temp;
  35998. dragType = draggingSelectionEnd;
  35999. }
  36000. }
  36001. else
  36002. {
  36003. selectionEnd = caretPos;
  36004. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36005. {
  36006. const CodeDocument::Position temp (selectionStart);
  36007. selectionStart = selectionEnd;
  36008. selectionEnd = temp;
  36009. dragType = draggingSelectionStart;
  36010. }
  36011. }
  36012. triggerAsyncUpdate();
  36013. }
  36014. else
  36015. {
  36016. deselectAll();
  36017. }
  36018. ((CaretComponent*) caret)->updatePosition (*this);
  36019. scrollToKeepCaretOnScreen();
  36020. updateScrollBars();
  36021. }
  36022. void CodeEditorComponent::deselectAll()
  36023. {
  36024. if (selectionStart != selectionEnd)
  36025. triggerAsyncUpdate();
  36026. selectionStart = caretPos;
  36027. selectionEnd = caretPos;
  36028. }
  36029. void CodeEditorComponent::updateScrollBars()
  36030. {
  36031. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36032. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36033. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36034. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36035. }
  36036. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36037. {
  36038. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36039. newFirstLineOnScreen);
  36040. if (newFirstLineOnScreen != firstLineOnScreen)
  36041. {
  36042. firstLineOnScreen = newFirstLineOnScreen;
  36043. ((CaretComponent*) caret)->updatePosition (*this);
  36044. updateCachedIterators (firstLineOnScreen);
  36045. triggerAsyncUpdate();
  36046. }
  36047. }
  36048. void CodeEditorComponent::scrollToColumnInternal (double column)
  36049. {
  36050. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36051. if (xOffset != newOffset)
  36052. {
  36053. xOffset = newOffset;
  36054. ((CaretComponent*) caret)->updatePosition (*this);
  36055. repaint();
  36056. }
  36057. }
  36058. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36059. {
  36060. scrollToLineInternal (newFirstLineOnScreen);
  36061. updateScrollBars();
  36062. }
  36063. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36064. {
  36065. scrollToColumnInternal (newFirstColumnOnScreen);
  36066. updateScrollBars();
  36067. }
  36068. void CodeEditorComponent::scrollBy (int deltaLines)
  36069. {
  36070. scrollToLine (firstLineOnScreen + deltaLines);
  36071. }
  36072. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36073. {
  36074. if (caretPos.getLineNumber() < firstLineOnScreen)
  36075. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36076. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36077. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36078. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36079. if (column >= xOffset + columnsOnScreen - 1)
  36080. scrollToColumn (column + 1 - columnsOnScreen);
  36081. else if (column < xOffset)
  36082. scrollToColumn (column);
  36083. }
  36084. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36085. {
  36086. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36087. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36088. roundToInt (charWidth),
  36089. lineHeight);
  36090. }
  36091. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36092. {
  36093. const int line = y / lineHeight + firstLineOnScreen;
  36094. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36095. const int index = columnToIndex (line, column);
  36096. return CodeDocument::Position (&document, line, index);
  36097. }
  36098. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36099. {
  36100. document.deleteSection (selectionStart, selectionEnd);
  36101. if (newText.isNotEmpty())
  36102. document.insertText (caretPos, newText);
  36103. scrollToKeepCaretOnScreen();
  36104. }
  36105. void CodeEditorComponent::insertTabAtCaret()
  36106. {
  36107. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36108. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36109. {
  36110. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36111. }
  36112. if (useSpacesForTabs)
  36113. {
  36114. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36115. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36116. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36117. }
  36118. else
  36119. {
  36120. insertTextAtCaret (T("\t"));
  36121. }
  36122. }
  36123. void CodeEditorComponent::cut()
  36124. {
  36125. insertTextAtCaret (String::empty);
  36126. }
  36127. void CodeEditorComponent::copy()
  36128. {
  36129. newTransaction();
  36130. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36131. if (selection.isNotEmpty())
  36132. SystemClipboard::copyTextToClipboard (selection);
  36133. }
  36134. void CodeEditorComponent::copyThenCut()
  36135. {
  36136. copy();
  36137. cut();
  36138. newTransaction();
  36139. }
  36140. void CodeEditorComponent::paste()
  36141. {
  36142. newTransaction();
  36143. const String clip (SystemClipboard::getTextFromClipboard());
  36144. if (clip.isNotEmpty())
  36145. insertTextAtCaret (clip);
  36146. newTransaction();
  36147. }
  36148. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36149. {
  36150. newTransaction();
  36151. if (moveInWholeWordSteps)
  36152. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36153. else
  36154. moveCaretTo (caretPos.movedBy (-1), selecting);
  36155. }
  36156. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36157. {
  36158. newTransaction();
  36159. if (moveInWholeWordSteps)
  36160. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36161. else
  36162. moveCaretTo (caretPos.movedBy (1), selecting);
  36163. }
  36164. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36165. {
  36166. CodeDocument::Position pos (caretPos);
  36167. const int newLineNum = pos.getLineNumber() + delta;
  36168. if (columnToTryToMaintain < 0)
  36169. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36170. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36171. const int colToMaintain = columnToTryToMaintain;
  36172. moveCaretTo (pos, selecting);
  36173. columnToTryToMaintain = colToMaintain;
  36174. }
  36175. void CodeEditorComponent::cursorDown (const bool selecting)
  36176. {
  36177. newTransaction();
  36178. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36179. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36180. else
  36181. moveLineDelta (1, selecting);
  36182. }
  36183. void CodeEditorComponent::cursorUp (const bool selecting)
  36184. {
  36185. newTransaction();
  36186. if (caretPos.getLineNumber() == 0)
  36187. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36188. else
  36189. moveLineDelta (-1, selecting);
  36190. }
  36191. void CodeEditorComponent::pageDown (const bool selecting)
  36192. {
  36193. newTransaction();
  36194. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36195. moveLineDelta (linesOnScreen, selecting);
  36196. }
  36197. void CodeEditorComponent::pageUp (const bool selecting)
  36198. {
  36199. newTransaction();
  36200. scrollBy (-linesOnScreen);
  36201. moveLineDelta (-linesOnScreen, selecting);
  36202. }
  36203. void CodeEditorComponent::scrollUp()
  36204. {
  36205. newTransaction();
  36206. scrollBy (1);
  36207. if (caretPos.getLineNumber() < firstLineOnScreen)
  36208. moveLineDelta (1, false);
  36209. }
  36210. void CodeEditorComponent::scrollDown()
  36211. {
  36212. newTransaction();
  36213. scrollBy (-1);
  36214. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36215. moveLineDelta (-1, false);
  36216. }
  36217. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36218. {
  36219. newTransaction();
  36220. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36221. }
  36222. static int findFirstNonWhitespaceChar (const String& line) throw()
  36223. {
  36224. const int len = line.length();
  36225. for (int i = 0; i < len; ++i)
  36226. if (! CharacterFunctions::isWhitespace (line [i]))
  36227. return i;
  36228. return 0;
  36229. }
  36230. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36231. {
  36232. newTransaction();
  36233. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36234. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36235. index = 0;
  36236. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36237. }
  36238. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36239. {
  36240. newTransaction();
  36241. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36242. }
  36243. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36244. {
  36245. newTransaction();
  36246. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36247. }
  36248. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36249. {
  36250. if (moveInWholeWordSteps)
  36251. {
  36252. cut(); // in case something is already highlighted
  36253. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36254. }
  36255. else
  36256. {
  36257. if (selectionStart == selectionEnd)
  36258. selectionStart.moveBy (-1);
  36259. }
  36260. cut();
  36261. }
  36262. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36263. {
  36264. if (moveInWholeWordSteps)
  36265. {
  36266. cut(); // in case something is already highlighted
  36267. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36268. }
  36269. else
  36270. {
  36271. if (selectionStart == selectionEnd)
  36272. selectionEnd.moveBy (1);
  36273. else
  36274. newTransaction();
  36275. }
  36276. cut();
  36277. }
  36278. void CodeEditorComponent::selectAll()
  36279. {
  36280. newTransaction();
  36281. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36282. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36283. }
  36284. void CodeEditorComponent::undo()
  36285. {
  36286. document.undo();
  36287. scrollToKeepCaretOnScreen();
  36288. }
  36289. void CodeEditorComponent::redo()
  36290. {
  36291. document.redo();
  36292. scrollToKeepCaretOnScreen();
  36293. }
  36294. void CodeEditorComponent::newTransaction()
  36295. {
  36296. document.newTransaction();
  36297. startTimer (600);
  36298. }
  36299. void CodeEditorComponent::timerCallback()
  36300. {
  36301. newTransaction();
  36302. }
  36303. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36304. {
  36305. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36306. }
  36307. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36308. {
  36309. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36310. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36311. }
  36312. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36313. {
  36314. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36315. CodeDocument::Position (&document, range.getEnd()));
  36316. }
  36317. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36318. {
  36319. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36320. const bool shiftDown = key.getModifiers().isShiftDown();
  36321. if (key.isKeyCode (KeyPress::leftKey))
  36322. {
  36323. cursorLeft (moveInWholeWordSteps, shiftDown);
  36324. }
  36325. else if (key.isKeyCode (KeyPress::rightKey))
  36326. {
  36327. cursorRight (moveInWholeWordSteps, shiftDown);
  36328. }
  36329. else if (key.isKeyCode (KeyPress::upKey))
  36330. {
  36331. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36332. scrollDown();
  36333. #if JUCE_MAC
  36334. else if (key.getModifiers().isCommandDown())
  36335. goToStartOfDocument (shiftDown);
  36336. #endif
  36337. else
  36338. cursorUp (shiftDown);
  36339. }
  36340. else if (key.isKeyCode (KeyPress::downKey))
  36341. {
  36342. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36343. scrollUp();
  36344. #if JUCE_MAC
  36345. else if (key.getModifiers().isCommandDown())
  36346. goToEndOfDocument (shiftDown);
  36347. #endif
  36348. else
  36349. cursorDown (shiftDown);
  36350. }
  36351. else if (key.isKeyCode (KeyPress::pageDownKey))
  36352. {
  36353. pageDown (shiftDown);
  36354. }
  36355. else if (key.isKeyCode (KeyPress::pageUpKey))
  36356. {
  36357. pageUp (shiftDown);
  36358. }
  36359. else if (key.isKeyCode (KeyPress::homeKey))
  36360. {
  36361. if (moveInWholeWordSteps)
  36362. goToStartOfDocument (shiftDown);
  36363. else
  36364. goToStartOfLine (shiftDown);
  36365. }
  36366. else if (key.isKeyCode (KeyPress::endKey))
  36367. {
  36368. if (moveInWholeWordSteps)
  36369. goToEndOfDocument (shiftDown);
  36370. else
  36371. goToEndOfLine (shiftDown);
  36372. }
  36373. else if (key.isKeyCode (KeyPress::backspaceKey))
  36374. {
  36375. backspace (moveInWholeWordSteps);
  36376. }
  36377. else if (key.isKeyCode (KeyPress::deleteKey))
  36378. {
  36379. deleteForward (moveInWholeWordSteps);
  36380. }
  36381. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36382. {
  36383. copy();
  36384. }
  36385. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36386. {
  36387. copyThenCut();
  36388. }
  36389. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36390. {
  36391. paste();
  36392. }
  36393. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36394. {
  36395. undo();
  36396. }
  36397. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36398. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36399. {
  36400. redo();
  36401. }
  36402. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36403. {
  36404. selectAll();
  36405. }
  36406. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36407. {
  36408. insertTabAtCaret();
  36409. }
  36410. else if (key == KeyPress::returnKey)
  36411. {
  36412. newTransaction();
  36413. insertTextAtCaret (document.getNewLineCharacters());
  36414. }
  36415. else if (key.isKeyCode (KeyPress::escapeKey))
  36416. {
  36417. newTransaction();
  36418. }
  36419. else if (key.getTextCharacter() >= ' ')
  36420. {
  36421. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36422. }
  36423. else
  36424. {
  36425. return false;
  36426. }
  36427. return true;
  36428. }
  36429. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36430. {
  36431. newTransaction();
  36432. dragType = notDragging;
  36433. if (! e.mods.isPopupMenu())
  36434. {
  36435. beginDragAutoRepeat (100);
  36436. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36437. }
  36438. else
  36439. {
  36440. }
  36441. }
  36442. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36443. {
  36444. if (! e.mods.isPopupMenu())
  36445. moveCaretTo (getPositionAt (e.x, e.y), true);
  36446. }
  36447. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36448. {
  36449. newTransaction();
  36450. beginDragAutoRepeat (0);
  36451. dragType = notDragging;
  36452. }
  36453. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36454. {
  36455. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36456. CodeDocument::Position tokenEnd (tokenStart);
  36457. if (e.getNumberOfClicks() > 2)
  36458. {
  36459. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36460. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36461. }
  36462. else
  36463. {
  36464. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36465. tokenEnd.moveBy (1);
  36466. tokenStart = tokenEnd;
  36467. while (tokenStart.getIndexInLine() > 0
  36468. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36469. tokenStart.moveBy (-1);
  36470. }
  36471. moveCaretTo (tokenEnd, false);
  36472. moveCaretTo (tokenStart, true);
  36473. }
  36474. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36475. {
  36476. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36477. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36478. }
  36479. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  36480. {
  36481. if (scrollBarThatHasMoved == verticalScrollBar)
  36482. scrollToLineInternal ((int) newRangeStart);
  36483. else
  36484. scrollToColumnInternal (newRangeStart);
  36485. }
  36486. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36487. {
  36488. useSpacesForTabs = insertSpaces;
  36489. if (spacesPerTab != numSpaces)
  36490. {
  36491. spacesPerTab = numSpaces;
  36492. triggerAsyncUpdate();
  36493. }
  36494. }
  36495. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36496. {
  36497. const String line (document.getLine (lineNum));
  36498. jassert (index <= line.length());
  36499. int col = 0;
  36500. for (int i = 0; i < index; ++i)
  36501. {
  36502. if (line[i] != T('\t'))
  36503. ++col;
  36504. else
  36505. col += getTabSize() - (col % getTabSize());
  36506. }
  36507. return col;
  36508. }
  36509. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36510. {
  36511. const String line (document.getLine (lineNum));
  36512. const int lineLength = line.length();
  36513. int i, col = 0;
  36514. for (i = 0; i < lineLength; ++i)
  36515. {
  36516. if (line[i] != T('\t'))
  36517. ++col;
  36518. else
  36519. col += getTabSize() - (col % getTabSize());
  36520. if (col > column)
  36521. break;
  36522. }
  36523. return i;
  36524. }
  36525. void CodeEditorComponent::setFont (const Font& newFont)
  36526. {
  36527. font = newFont;
  36528. charWidth = font.getStringWidthFloat (T("0"));
  36529. lineHeight = roundToInt (font.getHeight());
  36530. resized();
  36531. }
  36532. void CodeEditorComponent::resetToDefaultColours()
  36533. {
  36534. coloursForTokenCategories.clear();
  36535. if (codeTokeniser != 0)
  36536. {
  36537. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36538. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36539. }
  36540. }
  36541. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36542. {
  36543. jassert (tokenType < 256);
  36544. while (coloursForTokenCategories.size() < tokenType)
  36545. coloursForTokenCategories.add (Colours::black);
  36546. coloursForTokenCategories.set (tokenType, colour);
  36547. repaint();
  36548. }
  36549. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36550. {
  36551. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36552. return findColour (CodeEditorComponent::defaultTextColourId);
  36553. return coloursForTokenCategories.getReference (tokenType);
  36554. }
  36555. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36556. {
  36557. int i;
  36558. for (i = cachedIterators.size(); --i >= 0;)
  36559. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36560. break;
  36561. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36562. }
  36563. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36564. {
  36565. const int maxNumCachedPositions = 5000;
  36566. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36567. if (cachedIterators.size() == 0)
  36568. cachedIterators.add (new CodeDocument::Iterator (&document));
  36569. if (codeTokeniser == 0)
  36570. return;
  36571. for (;;)
  36572. {
  36573. CodeDocument::Iterator* last = cachedIterators.getLast();
  36574. if (last->getLine() >= maxLineNum)
  36575. break;
  36576. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36577. cachedIterators.add (t);
  36578. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36579. for (;;)
  36580. {
  36581. codeTokeniser->readNextToken (*t);
  36582. if (t->getLine() >= targetLine)
  36583. break;
  36584. if (t->isEOF())
  36585. return;
  36586. }
  36587. }
  36588. }
  36589. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36590. {
  36591. if (codeTokeniser == 0)
  36592. return;
  36593. for (int i = cachedIterators.size(); --i >= 0;)
  36594. {
  36595. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36596. if (t->getPosition() <= position)
  36597. {
  36598. source = *t;
  36599. break;
  36600. }
  36601. }
  36602. while (source.getPosition() < position)
  36603. {
  36604. const CodeDocument::Iterator original (source);
  36605. codeTokeniser->readNextToken (source);
  36606. if (source.getPosition() > position || source.isEOF())
  36607. {
  36608. source = original;
  36609. break;
  36610. }
  36611. }
  36612. }
  36613. END_JUCE_NAMESPACE
  36614. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36615. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36616. BEGIN_JUCE_NAMESPACE
  36617. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36618. {
  36619. }
  36620. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36621. {
  36622. }
  36623. namespace CppTokeniser
  36624. {
  36625. static bool isIdentifierStart (const tchar c) throw()
  36626. {
  36627. return CharacterFunctions::isLetter (c)
  36628. || c == T('_') || c == T('@');
  36629. }
  36630. static bool isIdentifierBody (const tchar c) throw()
  36631. {
  36632. return CharacterFunctions::isLetter (c)
  36633. || CharacterFunctions::isDigit (c)
  36634. || c == T('_') || c == T('@');
  36635. }
  36636. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36637. {
  36638. static const tchar* keywords2Char[] =
  36639. { T("if"), T("do"), T("or"), 0 };
  36640. static const tchar* keywords3Char[] =
  36641. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36642. static const tchar* keywords4Char[] =
  36643. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36644. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36645. static const tchar* keywords5Char[] =
  36646. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36647. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36648. static const tchar* keywords6Char[] =
  36649. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36650. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36651. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36652. static const tchar* keywordsOther[] =
  36653. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36654. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36655. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36656. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36657. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36658. int tokenLength = 0;
  36659. tchar possibleIdentifier [19];
  36660. while (isIdentifierBody (source.peekNextChar()))
  36661. {
  36662. const tchar c = source.nextChar();
  36663. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36664. possibleIdentifier [tokenLength] = c;
  36665. ++tokenLength;
  36666. }
  36667. if (tokenLength > 1 && tokenLength <= 16)
  36668. {
  36669. possibleIdentifier [tokenLength] = 0;
  36670. const tchar** k;
  36671. switch (tokenLength)
  36672. {
  36673. case 2: k = keywords2Char; break;
  36674. case 3: k = keywords3Char; break;
  36675. case 4: k = keywords4Char; break;
  36676. case 5: k = keywords5Char; break;
  36677. case 6: k = keywords6Char; break;
  36678. default: k = keywordsOther; break;
  36679. }
  36680. int i = 0;
  36681. while (k[i] != 0)
  36682. {
  36683. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36684. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36685. ++i;
  36686. }
  36687. }
  36688. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36689. }
  36690. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36691. {
  36692. const juce_wchar c = source.peekNextChar();
  36693. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36694. source.skip();
  36695. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36696. return false;
  36697. return true;
  36698. }
  36699. static bool isHexDigit (const juce_wchar c) throw()
  36700. {
  36701. return (c >= '0' && c <= '9')
  36702. || (c >= 'a' && c <= 'f')
  36703. || (c >= 'A' && c <= 'F');
  36704. }
  36705. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36706. {
  36707. if (source.nextChar() != '0')
  36708. return false;
  36709. juce_wchar c = source.nextChar();
  36710. if (c != 'x' && c != 'X')
  36711. return false;
  36712. int numDigits = 0;
  36713. while (isHexDigit (source.peekNextChar()))
  36714. {
  36715. ++numDigits;
  36716. source.skip();
  36717. }
  36718. if (numDigits == 0)
  36719. return false;
  36720. return skipNumberSuffix (source);
  36721. }
  36722. static bool isOctalDigit (const juce_wchar c) throw()
  36723. {
  36724. return c >= '0' && c <= '7';
  36725. }
  36726. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36727. {
  36728. if (source.nextChar() != '0')
  36729. return false;
  36730. if (! isOctalDigit (source.nextChar()))
  36731. return false;
  36732. while (isOctalDigit (source.peekNextChar()))
  36733. source.skip();
  36734. return skipNumberSuffix (source);
  36735. }
  36736. static bool isDecimalDigit (const juce_wchar c) throw()
  36737. {
  36738. return c >= '0' && c <= '9';
  36739. }
  36740. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36741. {
  36742. int numChars = 0;
  36743. while (isDecimalDigit (source.peekNextChar()))
  36744. {
  36745. ++numChars;
  36746. source.skip();
  36747. }
  36748. if (numChars == 0)
  36749. return false;
  36750. return skipNumberSuffix (source);
  36751. }
  36752. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36753. {
  36754. int numDigits = 0;
  36755. while (isDecimalDigit (source.peekNextChar()))
  36756. {
  36757. source.skip();
  36758. ++numDigits;
  36759. }
  36760. const bool hasPoint = (source.peekNextChar() == '.');
  36761. if (hasPoint)
  36762. {
  36763. source.skip();
  36764. while (isDecimalDigit (source.peekNextChar()))
  36765. {
  36766. source.skip();
  36767. ++numDigits;
  36768. }
  36769. }
  36770. if (numDigits == 0)
  36771. return false;
  36772. juce_wchar c = source.peekNextChar();
  36773. const bool hasExponent = (c == 'e' || c == 'E');
  36774. if (hasExponent)
  36775. {
  36776. source.skip();
  36777. c = source.peekNextChar();
  36778. if (c == '+' || c == '-')
  36779. source.skip();
  36780. int numExpDigits = 0;
  36781. while (isDecimalDigit (source.peekNextChar()))
  36782. {
  36783. source.skip();
  36784. ++numExpDigits;
  36785. }
  36786. if (numExpDigits == 0)
  36787. return false;
  36788. }
  36789. c = source.peekNextChar();
  36790. if (c == 'f' || c == 'F')
  36791. source.skip();
  36792. else if (! (hasExponent || hasPoint))
  36793. return false;
  36794. return true;
  36795. }
  36796. static int parseNumber (CodeDocument::Iterator& source)
  36797. {
  36798. const CodeDocument::Iterator original (source);
  36799. if (parseFloatLiteral (source))
  36800. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36801. source = original;
  36802. if (parseHexLiteral (source))
  36803. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36804. source = original;
  36805. if (parseOctalLiteral (source))
  36806. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36807. source = original;
  36808. if (parseDecimalLiteral (source))
  36809. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36810. source = original;
  36811. source.skip();
  36812. return CPlusPlusCodeTokeniser::tokenType_error;
  36813. }
  36814. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36815. {
  36816. const juce_wchar quote = source.nextChar();
  36817. for (;;)
  36818. {
  36819. const juce_wchar c = source.nextChar();
  36820. if (c == quote || c == 0)
  36821. break;
  36822. if (c == '\\')
  36823. source.skip();
  36824. }
  36825. }
  36826. static void skipComment (CodeDocument::Iterator& source) throw()
  36827. {
  36828. bool lastWasStar = false;
  36829. for (;;)
  36830. {
  36831. const juce_wchar c = source.nextChar();
  36832. if (c == 0 || (c == T('/') && lastWasStar))
  36833. break;
  36834. lastWasStar = (c == '*');
  36835. }
  36836. }
  36837. }
  36838. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36839. {
  36840. int result = tokenType_error;
  36841. source.skipWhitespace();
  36842. tchar firstChar = source.peekNextChar();
  36843. switch (firstChar)
  36844. {
  36845. case 0:
  36846. source.skip();
  36847. break;
  36848. case T('0'):
  36849. case T('1'):
  36850. case T('2'):
  36851. case T('3'):
  36852. case T('4'):
  36853. case T('5'):
  36854. case T('6'):
  36855. case T('7'):
  36856. case T('8'):
  36857. case T('9'):
  36858. result = CppTokeniser::parseNumber (source);
  36859. break;
  36860. case T('.'):
  36861. result = CppTokeniser::parseNumber (source);
  36862. if (result == tokenType_error)
  36863. result = tokenType_punctuation;
  36864. break;
  36865. case T(','):
  36866. case T(';'):
  36867. case T(':'):
  36868. source.skip();
  36869. result = tokenType_punctuation;
  36870. break;
  36871. case T('('):
  36872. case T(')'):
  36873. case T('{'):
  36874. case T('}'):
  36875. case T('['):
  36876. case T(']'):
  36877. source.skip();
  36878. result = tokenType_bracket;
  36879. break;
  36880. case T('"'):
  36881. case T('\''):
  36882. CppTokeniser::skipQuotedString (source);
  36883. result = tokenType_stringLiteral;
  36884. break;
  36885. case T('+'):
  36886. result = tokenType_operator;
  36887. source.skip();
  36888. if (source.peekNextChar() == T('+'))
  36889. source.skip();
  36890. else if (source.peekNextChar() == T('='))
  36891. source.skip();
  36892. break;
  36893. case T('-'):
  36894. source.skip();
  36895. result = CppTokeniser::parseNumber (source);
  36896. if (result == tokenType_error)
  36897. {
  36898. result = tokenType_operator;
  36899. if (source.peekNextChar() == T('-'))
  36900. source.skip();
  36901. else if (source.peekNextChar() == T('='))
  36902. source.skip();
  36903. }
  36904. break;
  36905. case T('*'):
  36906. case T('%'):
  36907. case T('='):
  36908. case T('!'):
  36909. result = tokenType_operator;
  36910. source.skip();
  36911. if (source.peekNextChar() == T('='))
  36912. source.skip();
  36913. break;
  36914. case T('/'):
  36915. result = tokenType_operator;
  36916. source.skip();
  36917. if (source.peekNextChar() == T('='))
  36918. {
  36919. source.skip();
  36920. }
  36921. else if (source.peekNextChar() == T('/'))
  36922. {
  36923. result = tokenType_comment;
  36924. source.skipToEndOfLine();
  36925. }
  36926. else if (source.peekNextChar() == T('*'))
  36927. {
  36928. source.skip();
  36929. result = tokenType_comment;
  36930. CppTokeniser::skipComment (source);
  36931. }
  36932. break;
  36933. case T('?'):
  36934. case T('~'):
  36935. source.skip();
  36936. result = tokenType_operator;
  36937. break;
  36938. case T('<'):
  36939. source.skip();
  36940. result = tokenType_operator;
  36941. if (source.peekNextChar() == T('='))
  36942. {
  36943. source.skip();
  36944. }
  36945. else if (source.peekNextChar() == T('<'))
  36946. {
  36947. source.skip();
  36948. if (source.peekNextChar() == T('='))
  36949. source.skip();
  36950. }
  36951. break;
  36952. case T('>'):
  36953. source.skip();
  36954. result = tokenType_operator;
  36955. if (source.peekNextChar() == T('='))
  36956. {
  36957. source.skip();
  36958. }
  36959. else if (source.peekNextChar() == T('<'))
  36960. {
  36961. source.skip();
  36962. if (source.peekNextChar() == T('='))
  36963. source.skip();
  36964. }
  36965. break;
  36966. case T('|'):
  36967. source.skip();
  36968. result = tokenType_operator;
  36969. if (source.peekNextChar() == T('='))
  36970. {
  36971. source.skip();
  36972. }
  36973. else if (source.peekNextChar() == T('|'))
  36974. {
  36975. source.skip();
  36976. if (source.peekNextChar() == T('='))
  36977. source.skip();
  36978. }
  36979. break;
  36980. case T('&'):
  36981. source.skip();
  36982. result = tokenType_operator;
  36983. if (source.peekNextChar() == T('='))
  36984. {
  36985. source.skip();
  36986. }
  36987. else if (source.peekNextChar() == T('&'))
  36988. {
  36989. source.skip();
  36990. if (source.peekNextChar() == T('='))
  36991. source.skip();
  36992. }
  36993. break;
  36994. case T('^'):
  36995. source.skip();
  36996. result = tokenType_operator;
  36997. if (source.peekNextChar() == T('='))
  36998. {
  36999. source.skip();
  37000. }
  37001. else if (source.peekNextChar() == T('^'))
  37002. {
  37003. source.skip();
  37004. if (source.peekNextChar() == T('='))
  37005. source.skip();
  37006. }
  37007. break;
  37008. case T('#'):
  37009. result = tokenType_preprocessor;
  37010. source.skipToEndOfLine();
  37011. break;
  37012. default:
  37013. if (CppTokeniser::isIdentifierStart (firstChar))
  37014. result = CppTokeniser::parseIdentifier (source);
  37015. else
  37016. source.skip();
  37017. break;
  37018. }
  37019. //jassert (result != tokenType_unknown);
  37020. return result;
  37021. }
  37022. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37023. {
  37024. StringArray s;
  37025. s.add ("Error");
  37026. s.add ("Comment");
  37027. s.add ("C++ keyword");
  37028. s.add ("Identifier");
  37029. s.add ("Integer literal");
  37030. s.add ("Float literal");
  37031. s.add ("String literal");
  37032. s.add ("Operator");
  37033. s.add ("Bracket");
  37034. s.add ("Punctuation");
  37035. s.add ("Preprocessor line");
  37036. return s;
  37037. }
  37038. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37039. {
  37040. const uint32 colours[] =
  37041. {
  37042. 0xffcc0000, // error
  37043. 0xff00aa00, // comment
  37044. 0xff0000cc, // keyword
  37045. 0xff000000, // identifier
  37046. 0xff880000, // int literal
  37047. 0xff885500, // float literal
  37048. 0xff990099, // string literal
  37049. 0xff225500, // operator
  37050. 0xff000055, // bracket
  37051. 0xff004400, // punctuation
  37052. 0xff660000 // preprocessor
  37053. };
  37054. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37055. return Colour (colours [tokenType]);
  37056. return Colours::black;
  37057. }
  37058. END_JUCE_NAMESPACE
  37059. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37060. /*** Start of inlined file: juce_ComboBox.cpp ***/
  37061. BEGIN_JUCE_NAMESPACE
  37062. ComboBox::ComboBox (const String& name)
  37063. : Component (name),
  37064. lastCurrentId (0),
  37065. isButtonDown (false),
  37066. separatorPending (false),
  37067. menuActive (false),
  37068. label (0)
  37069. {
  37070. noChoicesMessage = TRANS("(no choices)");
  37071. setRepaintsOnMouseActivity (true);
  37072. lookAndFeelChanged();
  37073. currentId.addListener (this);
  37074. }
  37075. ComboBox::~ComboBox()
  37076. {
  37077. currentId.removeListener (this);
  37078. if (menuActive)
  37079. PopupMenu::dismissAllActiveMenus();
  37080. label = 0;
  37081. deleteAllChildren();
  37082. }
  37083. void ComboBox::setEditableText (const bool isEditable)
  37084. {
  37085. label->setEditable (isEditable, isEditable, false);
  37086. setWantsKeyboardFocus (! isEditable);
  37087. resized();
  37088. }
  37089. bool ComboBox::isTextEditable() const throw()
  37090. {
  37091. return label->isEditable();
  37092. }
  37093. void ComboBox::setJustificationType (const Justification& justification) throw()
  37094. {
  37095. label->setJustificationType (justification);
  37096. }
  37097. const Justification ComboBox::getJustificationType() const throw()
  37098. {
  37099. return label->getJustificationType();
  37100. }
  37101. void ComboBox::setTooltip (const String& newTooltip)
  37102. {
  37103. SettableTooltipClient::setTooltip (newTooltip);
  37104. label->setTooltip (newTooltip);
  37105. }
  37106. void ComboBox::addItem (const String& newItemText,
  37107. const int newItemId) throw()
  37108. {
  37109. // you can't add empty strings to the list..
  37110. jassert (newItemText.isNotEmpty());
  37111. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37112. jassert (newItemId != 0);
  37113. // you shouldn't use duplicate item IDs!
  37114. jassert (getItemForId (newItemId) == 0);
  37115. if (newItemText.isNotEmpty() && newItemId != 0)
  37116. {
  37117. if (separatorPending)
  37118. {
  37119. separatorPending = false;
  37120. ItemInfo* const item = new ItemInfo();
  37121. item->itemId = 0;
  37122. item->isEnabled = false;
  37123. item->isHeading = false;
  37124. items.add (item);
  37125. }
  37126. ItemInfo* const item = new ItemInfo();
  37127. item->name = newItemText;
  37128. item->itemId = newItemId;
  37129. item->isEnabled = true;
  37130. item->isHeading = false;
  37131. items.add (item);
  37132. }
  37133. }
  37134. void ComboBox::addSeparator() throw()
  37135. {
  37136. separatorPending = (items.size() > 0);
  37137. }
  37138. void ComboBox::addSectionHeading (const String& headingName) throw()
  37139. {
  37140. // you can't add empty strings to the list..
  37141. jassert (headingName.isNotEmpty());
  37142. if (headingName.isNotEmpty())
  37143. {
  37144. if (separatorPending)
  37145. {
  37146. separatorPending = false;
  37147. ItemInfo* const item = new ItemInfo();
  37148. item->itemId = 0;
  37149. item->isEnabled = false;
  37150. item->isHeading = false;
  37151. items.add (item);
  37152. }
  37153. ItemInfo* const item = new ItemInfo();
  37154. item->name = headingName;
  37155. item->itemId = 0;
  37156. item->isEnabled = true;
  37157. item->isHeading = true;
  37158. items.add (item);
  37159. }
  37160. }
  37161. void ComboBox::setItemEnabled (const int itemId,
  37162. const bool shouldBeEnabled) throw()
  37163. {
  37164. ItemInfo* const item = getItemForId (itemId);
  37165. if (item != 0)
  37166. item->isEnabled = shouldBeEnabled;
  37167. }
  37168. void ComboBox::changeItemText (const int itemId,
  37169. const String& newText) throw()
  37170. {
  37171. ItemInfo* const item = getItemForId (itemId);
  37172. jassert (item != 0);
  37173. if (item != 0)
  37174. item->name = newText;
  37175. }
  37176. void ComboBox::clear (const bool dontSendChangeMessage)
  37177. {
  37178. items.clear();
  37179. separatorPending = false;
  37180. if (! label->isEditable())
  37181. setSelectedItemIndex (-1, dontSendChangeMessage);
  37182. }
  37183. bool ComboBox::ItemInfo::isSeparator() const throw()
  37184. {
  37185. return name.isEmpty();
  37186. }
  37187. bool ComboBox::ItemInfo::isRealItem() const throw()
  37188. {
  37189. return ! (isHeading || name.isEmpty());
  37190. }
  37191. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37192. {
  37193. if (itemId != 0)
  37194. {
  37195. for (int i = items.size(); --i >= 0;)
  37196. if (items.getUnchecked(i)->itemId == itemId)
  37197. return items.getUnchecked(i);
  37198. }
  37199. return 0;
  37200. }
  37201. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37202. {
  37203. int n = 0;
  37204. for (int i = 0; i < items.size(); ++i)
  37205. {
  37206. ItemInfo* const item = items.getUnchecked(i);
  37207. if (item->isRealItem())
  37208. if (n++ == index)
  37209. return item;
  37210. }
  37211. return 0;
  37212. }
  37213. int ComboBox::getNumItems() const throw()
  37214. {
  37215. int n = 0;
  37216. for (int i = items.size(); --i >= 0;)
  37217. if (items.getUnchecked(i)->isRealItem())
  37218. ++n;
  37219. return n;
  37220. }
  37221. const String ComboBox::getItemText (const int index) const throw()
  37222. {
  37223. const ItemInfo* const item = getItemForIndex (index);
  37224. if (item != 0)
  37225. return item->name;
  37226. return String::empty;
  37227. }
  37228. int ComboBox::getItemId (const int index) const throw()
  37229. {
  37230. const ItemInfo* const item = getItemForIndex (index);
  37231. return (item != 0) ? item->itemId : 0;
  37232. }
  37233. int ComboBox::indexOfItemId (const int itemId) const throw()
  37234. {
  37235. int n = 0;
  37236. for (int i = 0; i < items.size(); ++i)
  37237. {
  37238. const ItemInfo* const item = items.getUnchecked(i);
  37239. if (item->isRealItem())
  37240. {
  37241. if (item->itemId == itemId)
  37242. return n;
  37243. ++n;
  37244. }
  37245. }
  37246. return -1;
  37247. }
  37248. int ComboBox::getSelectedItemIndex() const throw()
  37249. {
  37250. int index = indexOfItemId (currentId.getValue());
  37251. if (getText() != getItemText (index))
  37252. index = -1;
  37253. return index;
  37254. }
  37255. void ComboBox::setSelectedItemIndex (const int index,
  37256. const bool dontSendChangeMessage) throw()
  37257. {
  37258. setSelectedId (getItemId (index), dontSendChangeMessage);
  37259. }
  37260. int ComboBox::getSelectedId() const throw()
  37261. {
  37262. const ItemInfo* const item = getItemForId (currentId.getValue());
  37263. return (item != 0 && getText() == item->name)
  37264. ? item->itemId
  37265. : 0;
  37266. }
  37267. void ComboBox::setSelectedId (const int newItemId,
  37268. const bool dontSendChangeMessage) throw()
  37269. {
  37270. const ItemInfo* const item = getItemForId (newItemId);
  37271. const String newItemText (item != 0 ? item->name : String::empty);
  37272. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37273. {
  37274. if (! dontSendChangeMessage)
  37275. triggerAsyncUpdate();
  37276. label->setText (newItemText, false);
  37277. lastCurrentId = newItemId;
  37278. currentId = newItemId;
  37279. repaint(); // for the benefit of the 'none selected' text
  37280. }
  37281. }
  37282. void ComboBox::valueChanged (Value&)
  37283. {
  37284. if (lastCurrentId != (int) currentId.getValue())
  37285. setSelectedId (currentId.getValue(), false);
  37286. }
  37287. const String ComboBox::getText() const throw()
  37288. {
  37289. return label->getText();
  37290. }
  37291. void ComboBox::setText (const String& newText,
  37292. const bool dontSendChangeMessage) throw()
  37293. {
  37294. for (int i = items.size(); --i >= 0;)
  37295. {
  37296. const ItemInfo* const item = items.getUnchecked(i);
  37297. if (item->isRealItem()
  37298. && item->name == newText)
  37299. {
  37300. setSelectedId (item->itemId, dontSendChangeMessage);
  37301. return;
  37302. }
  37303. }
  37304. lastCurrentId = 0;
  37305. currentId = 0;
  37306. if (label->getText() != newText)
  37307. {
  37308. label->setText (newText, false);
  37309. if (! dontSendChangeMessage)
  37310. triggerAsyncUpdate();
  37311. }
  37312. repaint();
  37313. }
  37314. void ComboBox::showEditor()
  37315. {
  37316. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37317. label->showEditor();
  37318. }
  37319. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37320. {
  37321. textWhenNothingSelected = newMessage;
  37322. repaint();
  37323. }
  37324. const String ComboBox::getTextWhenNothingSelected() const throw()
  37325. {
  37326. return textWhenNothingSelected;
  37327. }
  37328. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37329. {
  37330. noChoicesMessage = newMessage;
  37331. }
  37332. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37333. {
  37334. return noChoicesMessage;
  37335. }
  37336. void ComboBox::paint (Graphics& g)
  37337. {
  37338. getLookAndFeel().drawComboBox (g,
  37339. getWidth(),
  37340. getHeight(),
  37341. isButtonDown,
  37342. label->getRight(),
  37343. 0,
  37344. getWidth() - label->getRight(),
  37345. getHeight(),
  37346. *this);
  37347. if (textWhenNothingSelected.isNotEmpty()
  37348. && label->getText().isEmpty()
  37349. && ! label->isBeingEdited())
  37350. {
  37351. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37352. g.setFont (label->getFont());
  37353. g.drawFittedText (textWhenNothingSelected,
  37354. label->getX() + 2, label->getY() + 1,
  37355. label->getWidth() - 4, label->getHeight() - 2,
  37356. label->getJustificationType(),
  37357. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37358. }
  37359. }
  37360. void ComboBox::resized()
  37361. {
  37362. if (getHeight() > 0 && getWidth() > 0)
  37363. getLookAndFeel().positionComboBoxText (*this, *label);
  37364. }
  37365. void ComboBox::enablementChanged()
  37366. {
  37367. repaint();
  37368. }
  37369. void ComboBox::lookAndFeelChanged()
  37370. {
  37371. repaint();
  37372. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37373. if (label != 0)
  37374. {
  37375. newLabel->setEditable (label->isEditable());
  37376. newLabel->setJustificationType (label->getJustificationType());
  37377. newLabel->setTooltip (label->getTooltip());
  37378. newLabel->setText (label->getText(), false);
  37379. }
  37380. label = newLabel;
  37381. addAndMakeVisible (newLabel);
  37382. newLabel->addListener (this);
  37383. newLabel->addMouseListener (this, false);
  37384. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37385. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37386. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37387. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37388. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37389. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37390. resized();
  37391. }
  37392. void ComboBox::colourChanged()
  37393. {
  37394. lookAndFeelChanged();
  37395. }
  37396. bool ComboBox::keyPressed (const KeyPress& key)
  37397. {
  37398. bool used = false;
  37399. if (key.isKeyCode (KeyPress::upKey)
  37400. || key.isKeyCode (KeyPress::leftKey))
  37401. {
  37402. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37403. used = true;
  37404. }
  37405. else if (key.isKeyCode (KeyPress::downKey)
  37406. || key.isKeyCode (KeyPress::rightKey))
  37407. {
  37408. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37409. used = true;
  37410. }
  37411. else if (key.isKeyCode (KeyPress::returnKey))
  37412. {
  37413. showPopup();
  37414. used = true;
  37415. }
  37416. return used;
  37417. }
  37418. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37419. {
  37420. // only forward key events that aren't used by this component
  37421. return isKeyDown
  37422. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37423. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37424. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37425. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37426. }
  37427. void ComboBox::focusGained (FocusChangeType)
  37428. {
  37429. repaint();
  37430. }
  37431. void ComboBox::focusLost (FocusChangeType)
  37432. {
  37433. repaint();
  37434. }
  37435. void ComboBox::labelTextChanged (Label*)
  37436. {
  37437. triggerAsyncUpdate();
  37438. }
  37439. void ComboBox::showPopup()
  37440. {
  37441. if (! menuActive)
  37442. {
  37443. const int selectedId = getSelectedId();
  37444. Component::SafePointer<Component> deletionWatcher (this);
  37445. PopupMenu menu;
  37446. menu.setLookAndFeel (&getLookAndFeel());
  37447. for (int i = 0; i < items.size(); ++i)
  37448. {
  37449. const ItemInfo* const item = items.getUnchecked(i);
  37450. if (item->isSeparator())
  37451. menu.addSeparator();
  37452. else if (item->isHeading)
  37453. menu.addSectionHeader (item->name);
  37454. else
  37455. menu.addItem (item->itemId, item->name,
  37456. item->isEnabled, item->itemId == selectedId);
  37457. }
  37458. if (items.size() == 0)
  37459. menu.addItem (1, noChoicesMessage, false);
  37460. const int itemHeight = jlimit (12, 24, getHeight());
  37461. menuActive = true;
  37462. const int resultId = menu.showAt (this, selectedId,
  37463. getWidth(), 1, itemHeight);
  37464. if (deletionWatcher == 0)
  37465. return;
  37466. menuActive = false;
  37467. if (resultId != 0)
  37468. setSelectedId (resultId);
  37469. }
  37470. }
  37471. void ComboBox::mouseDown (const MouseEvent& e)
  37472. {
  37473. beginDragAutoRepeat (300);
  37474. isButtonDown = isEnabled();
  37475. if (isButtonDown
  37476. && (e.eventComponent == this || ! label->isEditable()))
  37477. {
  37478. showPopup();
  37479. }
  37480. }
  37481. void ComboBox::mouseDrag (const MouseEvent& e)
  37482. {
  37483. beginDragAutoRepeat (50);
  37484. if (isButtonDown && ! e.mouseWasClicked())
  37485. showPopup();
  37486. }
  37487. void ComboBox::mouseUp (const MouseEvent& e2)
  37488. {
  37489. if (isButtonDown)
  37490. {
  37491. isButtonDown = false;
  37492. repaint();
  37493. const MouseEvent e (e2.getEventRelativeTo (this));
  37494. if (reallyContains (e.x, e.y, true)
  37495. && (e2.eventComponent == this || ! label->isEditable()))
  37496. {
  37497. showPopup();
  37498. }
  37499. }
  37500. }
  37501. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37502. {
  37503. listeners.add (listener);
  37504. }
  37505. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37506. {
  37507. listeners.remove (listener);
  37508. }
  37509. void ComboBox::handleAsyncUpdate()
  37510. {
  37511. Component::BailOutChecker checker (this);
  37512. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37513. }
  37514. END_JUCE_NAMESPACE
  37515. /*** End of inlined file: juce_ComboBox.cpp ***/
  37516. /*** Start of inlined file: juce_Label.cpp ***/
  37517. BEGIN_JUCE_NAMESPACE
  37518. Label::Label (const String& componentName,
  37519. const String& labelText)
  37520. : Component (componentName),
  37521. textValue (labelText),
  37522. lastTextValue (labelText),
  37523. font (15.0f),
  37524. justification (Justification::centredLeft),
  37525. ownerComponent (0),
  37526. horizontalBorderSize (5),
  37527. verticalBorderSize (1),
  37528. minimumHorizontalScale (0.7f),
  37529. editSingleClick (false),
  37530. editDoubleClick (false),
  37531. lossOfFocusDiscardsChanges (false)
  37532. {
  37533. setColour (TextEditor::textColourId, Colours::black);
  37534. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37535. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37536. textValue.addListener (this);
  37537. }
  37538. Label::~Label()
  37539. {
  37540. textValue.removeListener (this);
  37541. if (ownerComponent != 0)
  37542. ownerComponent->removeComponentListener (this);
  37543. editor = 0;
  37544. }
  37545. void Label::setText (const String& newText,
  37546. const bool broadcastChangeMessage)
  37547. {
  37548. hideEditor (true);
  37549. if (lastTextValue != newText)
  37550. {
  37551. lastTextValue = newText;
  37552. textValue = newText;
  37553. repaint();
  37554. textWasChanged();
  37555. if (ownerComponent != 0)
  37556. componentMovedOrResized (*ownerComponent, true, true);
  37557. if (broadcastChangeMessage)
  37558. callChangeListeners();
  37559. }
  37560. }
  37561. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37562. {
  37563. return (returnActiveEditorContents && isBeingEdited())
  37564. ? editor->getText()
  37565. : textValue.toString();
  37566. }
  37567. void Label::valueChanged (Value&)
  37568. {
  37569. if (lastTextValue != textValue.toString())
  37570. setText (textValue.toString(), true);
  37571. }
  37572. void Label::setFont (const Font& newFont) throw()
  37573. {
  37574. font = newFont;
  37575. repaint();
  37576. }
  37577. const Font& Label::getFont() const throw()
  37578. {
  37579. return font;
  37580. }
  37581. void Label::setEditable (const bool editOnSingleClick,
  37582. const bool editOnDoubleClick,
  37583. const bool lossOfFocusDiscardsChanges_) throw()
  37584. {
  37585. editSingleClick = editOnSingleClick;
  37586. editDoubleClick = editOnDoubleClick;
  37587. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37588. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37589. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37590. }
  37591. void Label::setJustificationType (const Justification& justification_) throw()
  37592. {
  37593. justification = justification_;
  37594. repaint();
  37595. }
  37596. void Label::setBorderSize (int h, int v)
  37597. {
  37598. horizontalBorderSize = h;
  37599. verticalBorderSize = v;
  37600. repaint();
  37601. }
  37602. Component* Label::getAttachedComponent() const
  37603. {
  37604. return static_cast<Component*> (ownerComponent);
  37605. }
  37606. void Label::attachToComponent (Component* owner,
  37607. const bool onLeft)
  37608. {
  37609. if (ownerComponent != 0)
  37610. ownerComponent->removeComponentListener (this);
  37611. ownerComponent = owner;
  37612. leftOfOwnerComp = onLeft;
  37613. if (ownerComponent != 0)
  37614. {
  37615. setVisible (owner->isVisible());
  37616. ownerComponent->addComponentListener (this);
  37617. componentParentHierarchyChanged (*ownerComponent);
  37618. componentMovedOrResized (*ownerComponent, true, true);
  37619. }
  37620. }
  37621. void Label::componentMovedOrResized (Component& component,
  37622. bool /*wasMoved*/,
  37623. bool /*wasResized*/)
  37624. {
  37625. if (leftOfOwnerComp)
  37626. {
  37627. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37628. component.getHeight());
  37629. setTopRightPosition (component.getX(), component.getY());
  37630. }
  37631. else
  37632. {
  37633. setSize (component.getWidth(),
  37634. 8 + roundToInt (getFont().getHeight()));
  37635. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37636. }
  37637. }
  37638. void Label::componentParentHierarchyChanged (Component& component)
  37639. {
  37640. if (component.getParentComponent() != 0)
  37641. component.getParentComponent()->addChildComponent (this);
  37642. }
  37643. void Label::componentVisibilityChanged (Component& component)
  37644. {
  37645. setVisible (component.isVisible());
  37646. }
  37647. void Label::textWasEdited()
  37648. {
  37649. }
  37650. void Label::textWasChanged()
  37651. {
  37652. }
  37653. void Label::showEditor()
  37654. {
  37655. if (editor == 0)
  37656. {
  37657. addAndMakeVisible (editor = createEditorComponent());
  37658. editor->setText (getText(), false);
  37659. editor->addListener (this);
  37660. editor->grabKeyboardFocus();
  37661. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37662. editor->addListener (this);
  37663. resized();
  37664. repaint();
  37665. editorShown (editor);
  37666. enterModalState();
  37667. editor->grabKeyboardFocus();
  37668. }
  37669. }
  37670. void Label::editorShown (TextEditor* /*editorComponent*/)
  37671. {
  37672. }
  37673. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37674. {
  37675. }
  37676. bool Label::updateFromTextEditorContents()
  37677. {
  37678. jassert (editor != 0);
  37679. const String newText (editor->getText());
  37680. if (textValue.toString() != newText)
  37681. {
  37682. lastTextValue = newText;
  37683. textValue = newText;
  37684. repaint();
  37685. textWasChanged();
  37686. if (ownerComponent != 0)
  37687. componentMovedOrResized (*ownerComponent, true, true);
  37688. return true;
  37689. }
  37690. return false;
  37691. }
  37692. void Label::hideEditor (const bool discardCurrentEditorContents)
  37693. {
  37694. if (editor != 0)
  37695. {
  37696. Component::SafePointer<Component> deletionChecker (this);
  37697. editorAboutToBeHidden (editor);
  37698. const bool changed = (! discardCurrentEditorContents)
  37699. && updateFromTextEditorContents();
  37700. editor = 0;
  37701. repaint();
  37702. if (changed)
  37703. textWasEdited();
  37704. if (deletionChecker != 0)
  37705. exitModalState (0);
  37706. if (changed && deletionChecker != 0)
  37707. callChangeListeners();
  37708. }
  37709. }
  37710. void Label::inputAttemptWhenModal()
  37711. {
  37712. if (editor != 0)
  37713. {
  37714. if (lossOfFocusDiscardsChanges)
  37715. textEditorEscapeKeyPressed (*editor);
  37716. else
  37717. textEditorReturnKeyPressed (*editor);
  37718. }
  37719. }
  37720. bool Label::isBeingEdited() const throw()
  37721. {
  37722. return editor != 0;
  37723. }
  37724. TextEditor* Label::createEditorComponent()
  37725. {
  37726. TextEditor* const ed = new TextEditor (getName());
  37727. ed->setFont (font);
  37728. // copy these colours from our own settings..
  37729. const int cols[] = { TextEditor::backgroundColourId,
  37730. TextEditor::textColourId,
  37731. TextEditor::highlightColourId,
  37732. TextEditor::highlightedTextColourId,
  37733. TextEditor::caretColourId,
  37734. TextEditor::outlineColourId,
  37735. TextEditor::focusedOutlineColourId,
  37736. TextEditor::shadowColourId };
  37737. for (int i = 0; i < numElementsInArray (cols); ++i)
  37738. ed->setColour (cols[i], findColour (cols[i]));
  37739. return ed;
  37740. }
  37741. void Label::paint (Graphics& g)
  37742. {
  37743. getLookAndFeel().drawLabel (g, *this);
  37744. }
  37745. void Label::mouseUp (const MouseEvent& e)
  37746. {
  37747. if (editSingleClick
  37748. && e.mouseWasClicked()
  37749. && contains (e.x, e.y)
  37750. && ! e.mods.isPopupMenu())
  37751. {
  37752. showEditor();
  37753. }
  37754. }
  37755. void Label::mouseDoubleClick (const MouseEvent& e)
  37756. {
  37757. if (editDoubleClick && ! e.mods.isPopupMenu())
  37758. showEditor();
  37759. }
  37760. void Label::resized()
  37761. {
  37762. if (editor != 0)
  37763. editor->setBoundsInset (BorderSize (0));
  37764. }
  37765. void Label::focusGained (FocusChangeType cause)
  37766. {
  37767. if (editSingleClick && cause == focusChangedByTabKey)
  37768. showEditor();
  37769. }
  37770. void Label::enablementChanged()
  37771. {
  37772. repaint();
  37773. }
  37774. void Label::colourChanged()
  37775. {
  37776. repaint();
  37777. }
  37778. void Label::setMinimumHorizontalScale (const float newScale)
  37779. {
  37780. if (minimumHorizontalScale != newScale)
  37781. {
  37782. minimumHorizontalScale = newScale;
  37783. repaint();
  37784. }
  37785. }
  37786. // We'll use a custom focus traverser here to make sure focus goes from the
  37787. // text editor to another component rather than back to the label itself.
  37788. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37789. {
  37790. public:
  37791. LabelKeyboardFocusTraverser() {}
  37792. Component* getNextComponent (Component* current)
  37793. {
  37794. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37795. ? current->getParentComponent() : current);
  37796. }
  37797. Component* getPreviousComponent (Component* current)
  37798. {
  37799. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37800. ? current->getParentComponent() : current);
  37801. }
  37802. };
  37803. KeyboardFocusTraverser* Label::createFocusTraverser()
  37804. {
  37805. return new LabelKeyboardFocusTraverser();
  37806. }
  37807. void Label::addListener (LabelListener* const listener) throw()
  37808. {
  37809. listeners.add (listener);
  37810. }
  37811. void Label::removeListener (LabelListener* const listener) throw()
  37812. {
  37813. listeners.remove (listener);
  37814. }
  37815. void Label::callChangeListeners()
  37816. {
  37817. Component::BailOutChecker checker (this);
  37818. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37819. }
  37820. void Label::textEditorTextChanged (TextEditor& ed)
  37821. {
  37822. if (editor != 0)
  37823. {
  37824. jassert (&ed == editor);
  37825. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37826. {
  37827. if (lossOfFocusDiscardsChanges)
  37828. textEditorEscapeKeyPressed (ed);
  37829. else
  37830. textEditorReturnKeyPressed (ed);
  37831. }
  37832. }
  37833. }
  37834. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37835. {
  37836. if (editor != 0)
  37837. {
  37838. jassert (&ed == editor);
  37839. (void) ed;
  37840. const bool changed = updateFromTextEditorContents();
  37841. hideEditor (true);
  37842. if (changed)
  37843. {
  37844. Component::SafePointer<Component> deletionChecker (this);
  37845. textWasEdited();
  37846. if (deletionChecker != 0)
  37847. callChangeListeners();
  37848. }
  37849. }
  37850. }
  37851. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37852. {
  37853. if (editor != 0)
  37854. {
  37855. jassert (&ed == editor);
  37856. (void) ed;
  37857. editor->setText (textValue.toString(), false);
  37858. hideEditor (true);
  37859. }
  37860. }
  37861. void Label::textEditorFocusLost (TextEditor& ed)
  37862. {
  37863. textEditorTextChanged (ed);
  37864. }
  37865. END_JUCE_NAMESPACE
  37866. /*** End of inlined file: juce_Label.cpp ***/
  37867. /*** Start of inlined file: juce_ListBox.cpp ***/
  37868. BEGIN_JUCE_NAMESPACE
  37869. class ListBoxRowComponent : public Component,
  37870. public TooltipClient
  37871. {
  37872. public:
  37873. ListBoxRowComponent (ListBox& owner_)
  37874. : owner (owner_),
  37875. row (-1),
  37876. selected (false),
  37877. isDragging (false)
  37878. {
  37879. }
  37880. ~ListBoxRowComponent()
  37881. {
  37882. deleteAllChildren();
  37883. }
  37884. void paint (Graphics& g)
  37885. {
  37886. if (owner.getModel() != 0)
  37887. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37888. }
  37889. void update (const int row_, const bool selected_)
  37890. {
  37891. if (row != row_ || selected != selected_)
  37892. {
  37893. repaint();
  37894. row = row_;
  37895. selected = selected_;
  37896. }
  37897. if (owner.getModel() != 0)
  37898. {
  37899. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37900. if (customComp != 0)
  37901. {
  37902. addAndMakeVisible (customComp);
  37903. customComp->setBounds (0, 0, getWidth(), getHeight());
  37904. for (int i = getNumChildComponents(); --i >= 0;)
  37905. if (getChildComponent (i) != customComp)
  37906. delete getChildComponent (i);
  37907. }
  37908. else
  37909. {
  37910. deleteAllChildren();
  37911. }
  37912. }
  37913. }
  37914. void mouseDown (const MouseEvent& e)
  37915. {
  37916. isDragging = false;
  37917. selectRowOnMouseUp = false;
  37918. if (isEnabled())
  37919. {
  37920. if (! selected)
  37921. {
  37922. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37923. if (owner.getModel() != 0)
  37924. owner.getModel()->listBoxItemClicked (row, e);
  37925. }
  37926. else
  37927. {
  37928. selectRowOnMouseUp = true;
  37929. }
  37930. }
  37931. }
  37932. void mouseUp (const MouseEvent& e)
  37933. {
  37934. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  37935. {
  37936. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37937. if (owner.getModel() != 0)
  37938. owner.getModel()->listBoxItemClicked (row, e);
  37939. }
  37940. }
  37941. void mouseDoubleClick (const MouseEvent& e)
  37942. {
  37943. if (owner.getModel() != 0 && isEnabled())
  37944. owner.getModel()->listBoxItemDoubleClicked (row, e);
  37945. }
  37946. void mouseDrag (const MouseEvent& e)
  37947. {
  37948. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  37949. {
  37950. const SparseSet <int> selectedRows (owner.getSelectedRows());
  37951. if (selectedRows.size() > 0)
  37952. {
  37953. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  37954. if (dragDescription.isNotEmpty())
  37955. {
  37956. isDragging = true;
  37957. owner.startDragAndDrop (e, dragDescription);
  37958. }
  37959. }
  37960. }
  37961. }
  37962. void resized()
  37963. {
  37964. if (getNumChildComponents() > 0)
  37965. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  37966. }
  37967. const String getTooltip()
  37968. {
  37969. if (owner.getModel() != 0)
  37970. return owner.getModel()->getTooltipForRow (row);
  37971. return String::empty;
  37972. }
  37973. juce_UseDebuggingNewOperator
  37974. bool neededFlag;
  37975. private:
  37976. ListBox& owner;
  37977. int row;
  37978. bool selected, isDragging, selectRowOnMouseUp;
  37979. ListBoxRowComponent (const ListBoxRowComponent&);
  37980. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  37981. };
  37982. class ListViewport : public Viewport
  37983. {
  37984. public:
  37985. int firstIndex, firstWholeIndex, lastWholeIndex;
  37986. bool hasUpdated;
  37987. ListViewport (ListBox& owner_)
  37988. : owner (owner_)
  37989. {
  37990. setWantsKeyboardFocus (false);
  37991. setViewedComponent (new Component());
  37992. getViewedComponent()->addMouseListener (this, false);
  37993. getViewedComponent()->setWantsKeyboardFocus (false);
  37994. }
  37995. ~ListViewport()
  37996. {
  37997. getViewedComponent()->removeMouseListener (this);
  37998. getViewedComponent()->deleteAllChildren();
  37999. }
  38000. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  38001. {
  38002. return (ListBoxRowComponent*) getViewedComponent()
  38003. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38004. }
  38005. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38006. {
  38007. const int index = getIndexOfChildComponent (rowComponent);
  38008. const int num = getViewedComponent()->getNumChildComponents();
  38009. for (int i = num; --i >= 0;)
  38010. if (((firstIndex + i) % jmax (1, num)) == index)
  38011. return firstIndex + i;
  38012. return -1;
  38013. }
  38014. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38015. {
  38016. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38017. ? getComponentForRow (row) : 0;
  38018. }
  38019. void visibleAreaChanged (int, int, int, int)
  38020. {
  38021. updateVisibleArea (true);
  38022. if (owner.getModel() != 0)
  38023. owner.getModel()->listWasScrolled();
  38024. }
  38025. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38026. {
  38027. hasUpdated = false;
  38028. const int newX = getViewedComponent()->getX();
  38029. int newY = getViewedComponent()->getY();
  38030. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38031. const int newH = owner.totalItems * owner.getRowHeight();
  38032. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38033. newY = getMaximumVisibleHeight() - newH;
  38034. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38035. if (makeSureItUpdatesContent && ! hasUpdated)
  38036. updateContents();
  38037. }
  38038. void updateContents()
  38039. {
  38040. hasUpdated = true;
  38041. const int rowHeight = owner.getRowHeight();
  38042. if (rowHeight > 0)
  38043. {
  38044. const int y = getViewPositionY();
  38045. const int w = getViewedComponent()->getWidth();
  38046. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38047. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38048. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38049. jassert (numNeeded >= 0);
  38050. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38051. {
  38052. Component* const rowToRemove
  38053. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38054. delete rowToRemove;
  38055. }
  38056. firstIndex = y / rowHeight;
  38057. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38058. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38059. for (int i = 0; i < numNeeded; ++i)
  38060. {
  38061. const int row = i + firstIndex;
  38062. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38063. if (rowComp != 0)
  38064. {
  38065. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38066. rowComp->update (row, owner.isRowSelected (row));
  38067. }
  38068. }
  38069. }
  38070. if (owner.headerComponent != 0)
  38071. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38072. owner.outlineThickness,
  38073. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38074. getViewedComponent()->getWidth()),
  38075. owner.headerComponent->getHeight());
  38076. }
  38077. void paint (Graphics& g)
  38078. {
  38079. if (isOpaque())
  38080. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38081. }
  38082. bool keyPressed (const KeyPress& key)
  38083. {
  38084. if (key.isKeyCode (KeyPress::upKey)
  38085. || key.isKeyCode (KeyPress::downKey)
  38086. || key.isKeyCode (KeyPress::pageUpKey)
  38087. || key.isKeyCode (KeyPress::pageDownKey)
  38088. || key.isKeyCode (KeyPress::homeKey)
  38089. || key.isKeyCode (KeyPress::endKey))
  38090. {
  38091. // we want to avoid these keypresses going to the viewport, and instead allow
  38092. // them to pass up to our listbox..
  38093. return false;
  38094. }
  38095. return Viewport::keyPressed (key);
  38096. }
  38097. juce_UseDebuggingNewOperator
  38098. private:
  38099. ListBox& owner;
  38100. ListViewport (const ListViewport&);
  38101. ListViewport& operator= (const ListViewport&);
  38102. };
  38103. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38104. : Component (name),
  38105. model (model_),
  38106. headerComponent (0),
  38107. totalItems (0),
  38108. rowHeight (22),
  38109. minimumRowWidth (0),
  38110. outlineThickness (0),
  38111. lastRowSelected (-1),
  38112. mouseMoveSelects (false),
  38113. multipleSelection (false),
  38114. hasDoneInitialUpdate (false)
  38115. {
  38116. addAndMakeVisible (viewport = new ListViewport (*this));
  38117. setWantsKeyboardFocus (true);
  38118. colourChanged();
  38119. }
  38120. ListBox::~ListBox()
  38121. {
  38122. deleteAllChildren();
  38123. }
  38124. void ListBox::setModel (ListBoxModel* const newModel)
  38125. {
  38126. if (model != newModel)
  38127. {
  38128. model = newModel;
  38129. updateContent();
  38130. }
  38131. }
  38132. void ListBox::setMultipleSelectionEnabled (bool b)
  38133. {
  38134. multipleSelection = b;
  38135. }
  38136. void ListBox::setMouseMoveSelectsRows (bool b)
  38137. {
  38138. mouseMoveSelects = b;
  38139. if (b)
  38140. addMouseListener (this, true);
  38141. }
  38142. void ListBox::paint (Graphics& g)
  38143. {
  38144. if (! hasDoneInitialUpdate)
  38145. updateContent();
  38146. g.fillAll (findColour (backgroundColourId));
  38147. }
  38148. void ListBox::paintOverChildren (Graphics& g)
  38149. {
  38150. if (outlineThickness > 0)
  38151. {
  38152. g.setColour (findColour (outlineColourId));
  38153. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38154. }
  38155. }
  38156. void ListBox::resized()
  38157. {
  38158. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38159. outlineThickness,
  38160. outlineThickness,
  38161. outlineThickness));
  38162. viewport->setSingleStepSizes (20, getRowHeight());
  38163. viewport->updateVisibleArea (false);
  38164. }
  38165. void ListBox::visibilityChanged()
  38166. {
  38167. viewport->updateVisibleArea (true);
  38168. }
  38169. Viewport* ListBox::getViewport() const throw()
  38170. {
  38171. return viewport;
  38172. }
  38173. void ListBox::updateContent()
  38174. {
  38175. hasDoneInitialUpdate = true;
  38176. totalItems = (model != 0) ? model->getNumRows() : 0;
  38177. bool selectionChanged = false;
  38178. if (selected [selected.size() - 1] >= totalItems)
  38179. {
  38180. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38181. lastRowSelected = getSelectedRow (0);
  38182. selectionChanged = true;
  38183. }
  38184. viewport->updateVisibleArea (isVisible());
  38185. viewport->resized();
  38186. if (selectionChanged && model != 0)
  38187. model->selectedRowsChanged (lastRowSelected);
  38188. }
  38189. void ListBox::selectRow (const int row,
  38190. bool dontScroll,
  38191. bool deselectOthersFirst)
  38192. {
  38193. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38194. }
  38195. void ListBox::selectRowInternal (const int row,
  38196. bool dontScroll,
  38197. bool deselectOthersFirst,
  38198. bool isMouseClick)
  38199. {
  38200. if (! multipleSelection)
  38201. deselectOthersFirst = true;
  38202. if ((! isRowSelected (row))
  38203. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38204. {
  38205. if (((unsigned int) row) < (unsigned int) totalItems)
  38206. {
  38207. if (deselectOthersFirst)
  38208. selected.clear();
  38209. selected.addRange (row, 1);
  38210. if (getHeight() == 0 || getWidth() == 0)
  38211. dontScroll = true;
  38212. viewport->hasUpdated = false;
  38213. if (row < viewport->firstWholeIndex && ! dontScroll)
  38214. {
  38215. viewport->setViewPosition (viewport->getViewPositionX(),
  38216. row * getRowHeight());
  38217. }
  38218. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38219. {
  38220. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38221. if (row >= lastRowSelected + rowsOnScreen
  38222. && rowsOnScreen < totalItems - 1
  38223. && ! isMouseClick)
  38224. {
  38225. viewport->setViewPosition (viewport->getViewPositionX(),
  38226. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38227. * getRowHeight());
  38228. }
  38229. else
  38230. {
  38231. viewport->setViewPosition (viewport->getViewPositionX(),
  38232. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38233. }
  38234. }
  38235. if (! viewport->hasUpdated)
  38236. viewport->updateContents();
  38237. lastRowSelected = row;
  38238. model->selectedRowsChanged (row);
  38239. }
  38240. else
  38241. {
  38242. if (deselectOthersFirst)
  38243. deselectAllRows();
  38244. }
  38245. }
  38246. }
  38247. void ListBox::deselectRow (const int row)
  38248. {
  38249. if (selected.contains (row))
  38250. {
  38251. selected.removeRange (row, 1);
  38252. if (row == lastRowSelected)
  38253. lastRowSelected = getSelectedRow (0);
  38254. viewport->updateContents();
  38255. model->selectedRowsChanged (lastRowSelected);
  38256. }
  38257. }
  38258. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38259. const bool sendNotificationEventToModel)
  38260. {
  38261. selected = setOfRowsToBeSelected;
  38262. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38263. if (! isRowSelected (lastRowSelected))
  38264. lastRowSelected = getSelectedRow (0);
  38265. viewport->updateContents();
  38266. if ((model != 0) && sendNotificationEventToModel)
  38267. model->selectedRowsChanged (lastRowSelected);
  38268. }
  38269. const SparseSet<int> ListBox::getSelectedRows() const
  38270. {
  38271. return selected;
  38272. }
  38273. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38274. {
  38275. if (multipleSelection && (firstRow != lastRow))
  38276. {
  38277. const int numRows = totalItems - 1;
  38278. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38279. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38280. selected.addRange (jmin (firstRow, lastRow),
  38281. abs (firstRow - lastRow) + 1);
  38282. selected.removeRange (lastRow, 1);
  38283. }
  38284. selectRowInternal (lastRow, false, false, true);
  38285. }
  38286. void ListBox::flipRowSelection (const int row)
  38287. {
  38288. if (isRowSelected (row))
  38289. deselectRow (row);
  38290. else
  38291. selectRowInternal (row, false, false, true);
  38292. }
  38293. void ListBox::deselectAllRows()
  38294. {
  38295. if (! selected.isEmpty())
  38296. {
  38297. selected.clear();
  38298. lastRowSelected = -1;
  38299. viewport->updateContents();
  38300. if (model != 0)
  38301. model->selectedRowsChanged (lastRowSelected);
  38302. }
  38303. }
  38304. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38305. const ModifierKeys& mods)
  38306. {
  38307. if (multipleSelection && mods.isCommandDown())
  38308. {
  38309. flipRowSelection (row);
  38310. }
  38311. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38312. {
  38313. selectRangeOfRows (lastRowSelected, row);
  38314. }
  38315. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38316. {
  38317. selectRowInternal (row, false, true, true);
  38318. }
  38319. }
  38320. int ListBox::getNumSelectedRows() const
  38321. {
  38322. return selected.size();
  38323. }
  38324. int ListBox::getSelectedRow (const int index) const
  38325. {
  38326. return (((unsigned int) index) < (unsigned int) selected.size())
  38327. ? selected [index] : -1;
  38328. }
  38329. bool ListBox::isRowSelected (const int row) const
  38330. {
  38331. return selected.contains (row);
  38332. }
  38333. int ListBox::getLastRowSelected() const
  38334. {
  38335. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38336. }
  38337. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38338. {
  38339. if (((unsigned int) x) < (unsigned int) getWidth())
  38340. {
  38341. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38342. if (((unsigned int) row) < (unsigned int) totalItems)
  38343. return row;
  38344. }
  38345. return -1;
  38346. }
  38347. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38348. {
  38349. if (((unsigned int) x) < (unsigned int) getWidth())
  38350. {
  38351. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38352. return jlimit (0, totalItems, row);
  38353. }
  38354. return -1;
  38355. }
  38356. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38357. {
  38358. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38359. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38360. }
  38361. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38362. {
  38363. return viewport->getRowNumberOfComponent (rowComponent);
  38364. }
  38365. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38366. const bool relativeToComponentTopLeft) const throw()
  38367. {
  38368. const int rowHeight = getRowHeight();
  38369. int y = viewport->getY() + rowHeight * rowNumber;
  38370. if (relativeToComponentTopLeft)
  38371. y -= viewport->getViewPositionY();
  38372. return Rectangle<int> (viewport->getX(), y,
  38373. viewport->getViewedComponent()->getWidth(), rowHeight);
  38374. }
  38375. void ListBox::setVerticalPosition (const double proportion)
  38376. {
  38377. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38378. viewport->setViewPosition (viewport->getViewPositionX(),
  38379. jmax (0, roundToInt (proportion * offscreen)));
  38380. }
  38381. double ListBox::getVerticalPosition() const
  38382. {
  38383. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38384. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38385. : 0;
  38386. }
  38387. int ListBox::getVisibleRowWidth() const throw()
  38388. {
  38389. return viewport->getViewWidth();
  38390. }
  38391. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38392. {
  38393. if (row < viewport->firstWholeIndex)
  38394. {
  38395. viewport->setViewPosition (viewport->getViewPositionX(),
  38396. row * getRowHeight());
  38397. }
  38398. else if (row >= viewport->lastWholeIndex)
  38399. {
  38400. viewport->setViewPosition (viewport->getViewPositionX(),
  38401. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38402. }
  38403. }
  38404. bool ListBox::keyPressed (const KeyPress& key)
  38405. {
  38406. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38407. const bool multiple = multipleSelection
  38408. && (lastRowSelected >= 0)
  38409. && (key.getModifiers().isShiftDown()
  38410. || key.getModifiers().isCtrlDown()
  38411. || key.getModifiers().isCommandDown());
  38412. if (key.isKeyCode (KeyPress::upKey))
  38413. {
  38414. if (multiple)
  38415. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38416. else
  38417. selectRow (jmax (0, lastRowSelected - 1));
  38418. }
  38419. else if (key.isKeyCode (KeyPress::returnKey)
  38420. && isRowSelected (lastRowSelected))
  38421. {
  38422. if (model != 0)
  38423. model->returnKeyPressed (lastRowSelected);
  38424. }
  38425. else if (key.isKeyCode (KeyPress::pageUpKey))
  38426. {
  38427. if (multiple)
  38428. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38429. else
  38430. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38431. }
  38432. else if (key.isKeyCode (KeyPress::pageDownKey))
  38433. {
  38434. if (multiple)
  38435. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38436. else
  38437. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38438. }
  38439. else if (key.isKeyCode (KeyPress::homeKey))
  38440. {
  38441. if (multiple && key.getModifiers().isShiftDown())
  38442. selectRangeOfRows (lastRowSelected, 0);
  38443. else
  38444. selectRow (0);
  38445. }
  38446. else if (key.isKeyCode (KeyPress::endKey))
  38447. {
  38448. if (multiple && key.getModifiers().isShiftDown())
  38449. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38450. else
  38451. selectRow (totalItems - 1);
  38452. }
  38453. else if (key.isKeyCode (KeyPress::downKey))
  38454. {
  38455. if (multiple)
  38456. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38457. else
  38458. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38459. }
  38460. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38461. && isRowSelected (lastRowSelected))
  38462. {
  38463. if (model != 0)
  38464. model->deleteKeyPressed (lastRowSelected);
  38465. }
  38466. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38467. {
  38468. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38469. }
  38470. else
  38471. {
  38472. return false;
  38473. }
  38474. return true;
  38475. }
  38476. bool ListBox::keyStateChanged (const bool isKeyDown)
  38477. {
  38478. return isKeyDown
  38479. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38480. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38481. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38482. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38483. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38484. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38485. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38486. }
  38487. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38488. {
  38489. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38490. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38491. }
  38492. void ListBox::mouseMove (const MouseEvent& e)
  38493. {
  38494. if (mouseMoveSelects)
  38495. {
  38496. const MouseEvent e2 (e.getEventRelativeTo (this));
  38497. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38498. }
  38499. }
  38500. void ListBox::mouseExit (const MouseEvent& e)
  38501. {
  38502. mouseMove (e);
  38503. }
  38504. void ListBox::mouseUp (const MouseEvent& e)
  38505. {
  38506. if (e.mouseWasClicked() && model != 0)
  38507. model->backgroundClicked();
  38508. }
  38509. void ListBox::setRowHeight (const int newHeight)
  38510. {
  38511. rowHeight = jmax (1, newHeight);
  38512. viewport->setSingleStepSizes (20, rowHeight);
  38513. updateContent();
  38514. }
  38515. int ListBox::getNumRowsOnScreen() const throw()
  38516. {
  38517. return viewport->getMaximumVisibleHeight() / rowHeight;
  38518. }
  38519. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38520. {
  38521. minimumRowWidth = newMinimumWidth;
  38522. updateContent();
  38523. }
  38524. int ListBox::getVisibleContentWidth() const throw()
  38525. {
  38526. return viewport->getMaximumVisibleWidth();
  38527. }
  38528. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38529. {
  38530. return viewport->getVerticalScrollBar();
  38531. }
  38532. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38533. {
  38534. return viewport->getHorizontalScrollBar();
  38535. }
  38536. void ListBox::colourChanged()
  38537. {
  38538. setOpaque (findColour (backgroundColourId).isOpaque());
  38539. viewport->setOpaque (isOpaque());
  38540. repaint();
  38541. }
  38542. void ListBox::setOutlineThickness (const int outlineThickness_)
  38543. {
  38544. outlineThickness = outlineThickness_;
  38545. resized();
  38546. }
  38547. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38548. {
  38549. if (headerComponent != newHeaderComponent)
  38550. {
  38551. delete headerComponent;
  38552. headerComponent = newHeaderComponent;
  38553. addAndMakeVisible (newHeaderComponent);
  38554. ListBox::resized();
  38555. }
  38556. }
  38557. void ListBox::repaintRow (const int rowNumber) throw()
  38558. {
  38559. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38560. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38561. }
  38562. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38563. {
  38564. Rectangle<int> imageArea;
  38565. const int firstRow = getRowContainingPosition (0, 0);
  38566. int i;
  38567. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38568. {
  38569. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38570. if (rowComp != 0 && isRowSelected (firstRow + i))
  38571. {
  38572. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38573. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38574. if (imageArea.isEmpty())
  38575. imageArea = rowRect;
  38576. else
  38577. imageArea = imageArea.getUnion (rowRect);
  38578. }
  38579. }
  38580. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  38581. imageX = imageArea.getX();
  38582. imageY = imageArea.getY();
  38583. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38584. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38585. {
  38586. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38587. if (rowComp != 0 && isRowSelected (firstRow + i))
  38588. {
  38589. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38590. Graphics g (*snapshot);
  38591. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38592. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38593. rowComp->paintEntireComponent (g);
  38594. }
  38595. }
  38596. return snapshot;
  38597. }
  38598. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38599. {
  38600. DragAndDropContainer* const dragContainer
  38601. = DragAndDropContainer::findParentDragContainerFor (this);
  38602. if (dragContainer != 0)
  38603. {
  38604. int x, y;
  38605. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38606. dragImage->multiplyAllAlphas (0.6f);
  38607. MouseEvent e2 (e.getEventRelativeTo (this));
  38608. const Point<int> p (x - e2.x, y - e2.y);
  38609. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38610. }
  38611. else
  38612. {
  38613. // to be able to do a drag-and-drop operation, the listbox needs to
  38614. // be inside a component which is also a DragAndDropContainer.
  38615. jassertfalse
  38616. }
  38617. }
  38618. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38619. {
  38620. (void) existingComponentToUpdate;
  38621. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38622. return 0;
  38623. }
  38624. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38625. {
  38626. }
  38627. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38628. {
  38629. }
  38630. void ListBoxModel::backgroundClicked()
  38631. {
  38632. }
  38633. void ListBoxModel::selectedRowsChanged (int)
  38634. {
  38635. }
  38636. void ListBoxModel::deleteKeyPressed (int)
  38637. {
  38638. }
  38639. void ListBoxModel::returnKeyPressed (int)
  38640. {
  38641. }
  38642. void ListBoxModel::listWasScrolled()
  38643. {
  38644. }
  38645. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38646. {
  38647. return String::empty;
  38648. }
  38649. const String ListBoxModel::getTooltipForRow (int)
  38650. {
  38651. return String::empty;
  38652. }
  38653. END_JUCE_NAMESPACE
  38654. /*** End of inlined file: juce_ListBox.cpp ***/
  38655. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38656. BEGIN_JUCE_NAMESPACE
  38657. ProgressBar::ProgressBar (double& progress_)
  38658. : progress (progress_),
  38659. displayPercentage (true),
  38660. lastCallbackTime (0)
  38661. {
  38662. currentValue = jlimit (0.0, 1.0, progress);
  38663. }
  38664. ProgressBar::~ProgressBar()
  38665. {
  38666. }
  38667. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38668. {
  38669. displayPercentage = shouldDisplayPercentage;
  38670. repaint();
  38671. }
  38672. void ProgressBar::setTextToDisplay (const String& text)
  38673. {
  38674. displayPercentage = false;
  38675. displayedMessage = text;
  38676. }
  38677. void ProgressBar::lookAndFeelChanged()
  38678. {
  38679. setOpaque (findColour (backgroundColourId).isOpaque());
  38680. }
  38681. void ProgressBar::colourChanged()
  38682. {
  38683. lookAndFeelChanged();
  38684. }
  38685. void ProgressBar::paint (Graphics& g)
  38686. {
  38687. String text;
  38688. if (displayPercentage)
  38689. {
  38690. if (currentValue >= 0 && currentValue <= 1.0)
  38691. text << roundToInt (currentValue * 100.0) << T("%");
  38692. }
  38693. else
  38694. {
  38695. text = displayedMessage;
  38696. }
  38697. getLookAndFeel().drawProgressBar (g, *this,
  38698. getWidth(), getHeight(),
  38699. currentValue, text);
  38700. }
  38701. void ProgressBar::visibilityChanged()
  38702. {
  38703. if (isVisible())
  38704. startTimer (30);
  38705. else
  38706. stopTimer();
  38707. }
  38708. void ProgressBar::timerCallback()
  38709. {
  38710. double newProgress = progress;
  38711. const uint32 now = Time::getMillisecondCounter();
  38712. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38713. lastCallbackTime = now;
  38714. if (currentValue != newProgress
  38715. || newProgress < 0 || newProgress >= 1.0
  38716. || currentMessage != displayedMessage)
  38717. {
  38718. if (currentValue < newProgress
  38719. && newProgress >= 0 && newProgress < 1.0
  38720. && currentValue >= 0 && currentValue < 1.0)
  38721. {
  38722. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38723. newProgress);
  38724. }
  38725. currentValue = newProgress;
  38726. currentMessage = displayedMessage;
  38727. repaint();
  38728. }
  38729. }
  38730. END_JUCE_NAMESPACE
  38731. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38732. /*** Start of inlined file: juce_Slider.cpp ***/
  38733. BEGIN_JUCE_NAMESPACE
  38734. class SliderPopupDisplayComponent : public BubbleComponent
  38735. {
  38736. public:
  38737. SliderPopupDisplayComponent (Slider* const owner_)
  38738. : owner (owner_),
  38739. font (15.0f, Font::bold)
  38740. {
  38741. setAlwaysOnTop (true);
  38742. }
  38743. ~SliderPopupDisplayComponent()
  38744. {
  38745. }
  38746. void paintContent (Graphics& g, int w, int h)
  38747. {
  38748. g.setFont (font);
  38749. g.setColour (Colours::black);
  38750. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38751. }
  38752. void getContentSize (int& w, int& h)
  38753. {
  38754. w = font.getStringWidth (text) + 18;
  38755. h = (int) (font.getHeight() * 1.6f);
  38756. }
  38757. void updatePosition (const String& newText)
  38758. {
  38759. if (text != newText)
  38760. {
  38761. text = newText;
  38762. repaint();
  38763. }
  38764. BubbleComponent::setPosition (owner);
  38765. }
  38766. juce_UseDebuggingNewOperator
  38767. private:
  38768. Slider* owner;
  38769. Font font;
  38770. String text;
  38771. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38772. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38773. };
  38774. Slider::Slider (const String& name)
  38775. : Component (name),
  38776. lastCurrentValue (0),
  38777. lastValueMin (0),
  38778. lastValueMax (0),
  38779. minimum (0),
  38780. maximum (10),
  38781. interval (0),
  38782. skewFactor (1.0),
  38783. velocityModeSensitivity (1.0),
  38784. velocityModeOffset (0.0),
  38785. velocityModeThreshold (1),
  38786. rotaryStart (float_Pi * 1.2f),
  38787. rotaryEnd (float_Pi * 2.8f),
  38788. numDecimalPlaces (7),
  38789. sliderRegionStart (0),
  38790. sliderRegionSize (1),
  38791. sliderBeingDragged (-1),
  38792. pixelsForFullDragExtent (250),
  38793. style (LinearHorizontal),
  38794. textBoxPos (TextBoxLeft),
  38795. textBoxWidth (80),
  38796. textBoxHeight (20),
  38797. incDecButtonMode (incDecButtonsNotDraggable),
  38798. editableText (true),
  38799. doubleClickToValue (false),
  38800. isVelocityBased (false),
  38801. userKeyOverridesVelocity (true),
  38802. rotaryStop (true),
  38803. incDecButtonsSideBySide (false),
  38804. sendChangeOnlyOnRelease (false),
  38805. popupDisplayEnabled (false),
  38806. menuEnabled (false),
  38807. menuShown (false),
  38808. scrollWheelEnabled (true),
  38809. snapsToMousePos (true),
  38810. valueBox (0),
  38811. incButton (0),
  38812. decButton (0),
  38813. popupDisplay (0),
  38814. parentForPopupDisplay (0)
  38815. {
  38816. setWantsKeyboardFocus (false);
  38817. setRepaintsOnMouseActivity (true);
  38818. lookAndFeelChanged();
  38819. updateText();
  38820. currentValue.addListener (this);
  38821. valueMin.addListener (this);
  38822. valueMax.addListener (this);
  38823. }
  38824. Slider::~Slider()
  38825. {
  38826. currentValue.removeListener (this);
  38827. valueMin.removeListener (this);
  38828. valueMax.removeListener (this);
  38829. popupDisplay = 0;
  38830. deleteAllChildren();
  38831. }
  38832. void Slider::handleAsyncUpdate()
  38833. {
  38834. cancelPendingUpdate();
  38835. Component::BailOutChecker checker (this);
  38836. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38837. }
  38838. void Slider::sendDragStart()
  38839. {
  38840. startedDragging();
  38841. Component::BailOutChecker checker (this);
  38842. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38843. }
  38844. void Slider::sendDragEnd()
  38845. {
  38846. stoppedDragging();
  38847. sliderBeingDragged = -1;
  38848. Component::BailOutChecker checker (this);
  38849. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38850. }
  38851. void Slider::addListener (SliderListener* const listener)
  38852. {
  38853. listeners.add (listener);
  38854. }
  38855. void Slider::removeListener (SliderListener* const listener)
  38856. {
  38857. listeners.remove (listener);
  38858. }
  38859. void Slider::setSliderStyle (const SliderStyle newStyle)
  38860. {
  38861. if (style != newStyle)
  38862. {
  38863. style = newStyle;
  38864. repaint();
  38865. lookAndFeelChanged();
  38866. }
  38867. }
  38868. void Slider::setRotaryParameters (const float startAngleRadians,
  38869. const float endAngleRadians,
  38870. const bool stopAtEnd)
  38871. {
  38872. // make sure the values are sensible..
  38873. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38874. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38875. jassert (rotaryStart < rotaryEnd);
  38876. rotaryStart = startAngleRadians;
  38877. rotaryEnd = endAngleRadians;
  38878. rotaryStop = stopAtEnd;
  38879. }
  38880. void Slider::setVelocityBasedMode (const bool velBased)
  38881. {
  38882. isVelocityBased = velBased;
  38883. }
  38884. void Slider::setVelocityModeParameters (const double sensitivity,
  38885. const int threshold,
  38886. const double offset,
  38887. const bool userCanPressKeyToSwapMode)
  38888. {
  38889. jassert (threshold >= 0);
  38890. jassert (sensitivity > 0);
  38891. jassert (offset >= 0);
  38892. velocityModeSensitivity = sensitivity;
  38893. velocityModeOffset = offset;
  38894. velocityModeThreshold = threshold;
  38895. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38896. }
  38897. void Slider::setSkewFactor (const double factor)
  38898. {
  38899. skewFactor = factor;
  38900. }
  38901. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38902. {
  38903. if (maximum > minimum)
  38904. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38905. / (maximum - minimum));
  38906. }
  38907. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38908. {
  38909. jassert (distanceForFullScaleDrag > 0);
  38910. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38911. }
  38912. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38913. {
  38914. if (incDecButtonMode != mode)
  38915. {
  38916. incDecButtonMode = mode;
  38917. lookAndFeelChanged();
  38918. }
  38919. }
  38920. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  38921. const bool isReadOnly,
  38922. const int textEntryBoxWidth,
  38923. const int textEntryBoxHeight)
  38924. {
  38925. textBoxPos = newPosition;
  38926. editableText = ! isReadOnly;
  38927. textBoxWidth = textEntryBoxWidth;
  38928. textBoxHeight = textEntryBoxHeight;
  38929. repaint();
  38930. lookAndFeelChanged();
  38931. }
  38932. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  38933. {
  38934. editableText = shouldBeEditable;
  38935. if (valueBox != 0)
  38936. valueBox->setEditable (shouldBeEditable && isEnabled());
  38937. }
  38938. void Slider::showTextBox()
  38939. {
  38940. jassert (editableText); // this should probably be avoided in read-only sliders.
  38941. if (valueBox != 0)
  38942. valueBox->showEditor();
  38943. }
  38944. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  38945. {
  38946. if (valueBox != 0)
  38947. {
  38948. valueBox->hideEditor (discardCurrentEditorContents);
  38949. if (discardCurrentEditorContents)
  38950. updateText();
  38951. }
  38952. }
  38953. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  38954. {
  38955. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  38956. }
  38957. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  38958. {
  38959. snapsToMousePos = shouldSnapToMouse;
  38960. }
  38961. void Slider::setPopupDisplayEnabled (const bool enabled,
  38962. Component* const parentComponentToUse)
  38963. {
  38964. popupDisplayEnabled = enabled;
  38965. parentForPopupDisplay = parentComponentToUse;
  38966. }
  38967. void Slider::colourChanged()
  38968. {
  38969. lookAndFeelChanged();
  38970. }
  38971. void Slider::lookAndFeelChanged()
  38972. {
  38973. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  38974. : getTextFromValue (currentValue.getValue()));
  38975. deleteAllChildren();
  38976. valueBox = 0;
  38977. LookAndFeel& lf = getLookAndFeel();
  38978. if (textBoxPos != NoTextBox)
  38979. {
  38980. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  38981. valueBox->setWantsKeyboardFocus (false);
  38982. valueBox->setText (previousTextBoxContent, false);
  38983. valueBox->setEditable (editableText && isEnabled());
  38984. valueBox->addListener (this);
  38985. if (style == LinearBar)
  38986. valueBox->addMouseListener (this, false);
  38987. valueBox->setTooltip (getTooltip());
  38988. }
  38989. if (style == IncDecButtons)
  38990. {
  38991. addAndMakeVisible (incButton = lf.createSliderButton (true));
  38992. incButton->addButtonListener (this);
  38993. addAndMakeVisible (decButton = lf.createSliderButton (false));
  38994. decButton->addButtonListener (this);
  38995. if (incDecButtonMode != incDecButtonsNotDraggable)
  38996. {
  38997. incButton->addMouseListener (this, false);
  38998. decButton->addMouseListener (this, false);
  38999. }
  39000. else
  39001. {
  39002. incButton->setRepeatSpeed (300, 100, 20);
  39003. incButton->addMouseListener (decButton, false);
  39004. decButton->setRepeatSpeed (300, 100, 20);
  39005. decButton->addMouseListener (incButton, false);
  39006. }
  39007. incButton->setTooltip (getTooltip());
  39008. decButton->setTooltip (getTooltip());
  39009. }
  39010. setComponentEffect (lf.getSliderEffect());
  39011. resized();
  39012. repaint();
  39013. }
  39014. void Slider::setRange (const double newMin,
  39015. const double newMax,
  39016. const double newInt)
  39017. {
  39018. if (minimum != newMin
  39019. || maximum != newMax
  39020. || interval != newInt)
  39021. {
  39022. minimum = newMin;
  39023. maximum = newMax;
  39024. interval = newInt;
  39025. // figure out the number of DPs needed to display all values at this
  39026. // interval setting.
  39027. numDecimalPlaces = 7;
  39028. if (newInt != 0)
  39029. {
  39030. int v = abs ((int) (newInt * 10000000));
  39031. while ((v % 10) == 0)
  39032. {
  39033. --numDecimalPlaces;
  39034. v /= 10;
  39035. }
  39036. }
  39037. // keep the current values inside the new range..
  39038. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39039. {
  39040. setValue (getValue(), false, false);
  39041. }
  39042. else
  39043. {
  39044. setMinValue (getMinValue(), false, false);
  39045. setMaxValue (getMaxValue(), false, false);
  39046. }
  39047. updateText();
  39048. }
  39049. }
  39050. void Slider::triggerChangeMessage (const bool synchronous)
  39051. {
  39052. if (synchronous)
  39053. handleAsyncUpdate();
  39054. else
  39055. triggerAsyncUpdate();
  39056. valueChanged();
  39057. }
  39058. void Slider::valueChanged (Value& value)
  39059. {
  39060. if (value.refersToSameSourceAs (currentValue))
  39061. {
  39062. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39063. setValue (currentValue.getValue(), false, false);
  39064. }
  39065. else if (value.refersToSameSourceAs (valueMin))
  39066. setMinValue (valueMin.getValue(), false, false, true);
  39067. else if (value.refersToSameSourceAs (valueMax))
  39068. setMaxValue (valueMax.getValue(), false, false, true);
  39069. }
  39070. double Slider::getValue() const
  39071. {
  39072. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39073. // methods to get the two values.
  39074. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39075. return currentValue.getValue();
  39076. }
  39077. void Slider::setValue (double newValue,
  39078. const bool sendUpdateMessage,
  39079. const bool sendMessageSynchronously)
  39080. {
  39081. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39082. // methods to set the two values.
  39083. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39084. newValue = constrainedValue (newValue);
  39085. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39086. {
  39087. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39088. newValue = jlimit ((double) valueMin.getValue(),
  39089. (double) valueMax.getValue(),
  39090. newValue);
  39091. }
  39092. if (newValue != lastCurrentValue)
  39093. {
  39094. if (valueBox != 0)
  39095. valueBox->hideEditor (true);
  39096. lastCurrentValue = newValue;
  39097. currentValue = newValue;
  39098. updateText();
  39099. repaint();
  39100. if (popupDisplay != 0)
  39101. {
  39102. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39103. ->updatePosition (getTextFromValue (newValue));
  39104. popupDisplay->repaint();
  39105. }
  39106. if (sendUpdateMessage)
  39107. triggerChangeMessage (sendMessageSynchronously);
  39108. }
  39109. }
  39110. double Slider::getMinValue() const
  39111. {
  39112. // The minimum value only applies to sliders that are in two- or three-value mode.
  39113. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39114. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39115. return valueMin.getValue();
  39116. }
  39117. double Slider::getMaxValue() const
  39118. {
  39119. // The maximum value only applies to sliders that are in two- or three-value mode.
  39120. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39121. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39122. return valueMax.getValue();
  39123. }
  39124. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39125. {
  39126. // The minimum value only applies to sliders that are in two- or three-value mode.
  39127. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39128. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39129. newValue = constrainedValue (newValue);
  39130. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39131. {
  39132. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39133. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39134. newValue = jmin ((double) valueMax.getValue(), newValue);
  39135. }
  39136. else
  39137. {
  39138. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39139. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39140. newValue = jmin (lastCurrentValue, newValue);
  39141. }
  39142. if (lastValueMin != newValue)
  39143. {
  39144. lastValueMin = newValue;
  39145. valueMin = newValue;
  39146. repaint();
  39147. if (popupDisplay != 0)
  39148. {
  39149. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39150. ->updatePosition (getTextFromValue (newValue));
  39151. popupDisplay->repaint();
  39152. }
  39153. if (sendUpdateMessage)
  39154. triggerChangeMessage (sendMessageSynchronously);
  39155. }
  39156. }
  39157. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39158. {
  39159. // The maximum value only applies to sliders that are in two- or three-value mode.
  39160. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39161. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39162. newValue = constrainedValue (newValue);
  39163. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39164. {
  39165. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39166. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39167. newValue = jmax ((double) valueMin.getValue(), newValue);
  39168. }
  39169. else
  39170. {
  39171. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39172. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39173. newValue = jmax (lastCurrentValue, newValue);
  39174. }
  39175. if (lastValueMax != newValue)
  39176. {
  39177. lastValueMax = newValue;
  39178. valueMax = newValue;
  39179. repaint();
  39180. if (popupDisplay != 0)
  39181. {
  39182. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39183. ->updatePosition (getTextFromValue (valueMax.getValue()));
  39184. popupDisplay->repaint();
  39185. }
  39186. if (sendUpdateMessage)
  39187. triggerChangeMessage (sendMessageSynchronously);
  39188. }
  39189. }
  39190. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39191. const double valueToSetOnDoubleClick)
  39192. {
  39193. doubleClickToValue = isDoubleClickEnabled;
  39194. doubleClickReturnValue = valueToSetOnDoubleClick;
  39195. }
  39196. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39197. {
  39198. isEnabled_ = doubleClickToValue;
  39199. return doubleClickReturnValue;
  39200. }
  39201. void Slider::updateText()
  39202. {
  39203. if (valueBox != 0)
  39204. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39205. }
  39206. void Slider::setTextValueSuffix (const String& suffix)
  39207. {
  39208. if (textSuffix != suffix)
  39209. {
  39210. textSuffix = suffix;
  39211. updateText();
  39212. }
  39213. }
  39214. const String Slider::getTextFromValue (double v)
  39215. {
  39216. if (numDecimalPlaces > 0)
  39217. return String (v, numDecimalPlaces) + textSuffix;
  39218. else
  39219. return String (roundToInt (v)) + textSuffix;
  39220. }
  39221. double Slider::getValueFromText (const String& text)
  39222. {
  39223. String t (text.trimStart());
  39224. if (t.endsWith (textSuffix))
  39225. t = t.substring (0, t.length() - textSuffix.length());
  39226. while (t.startsWithChar (T('+')))
  39227. t = t.substring (1).trimStart();
  39228. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39229. .getDoubleValue();
  39230. }
  39231. double Slider::proportionOfLengthToValue (double proportion)
  39232. {
  39233. if (skewFactor != 1.0 && proportion > 0.0)
  39234. proportion = exp (log (proportion) / skewFactor);
  39235. return minimum + (maximum - minimum) * proportion;
  39236. }
  39237. double Slider::valueToProportionOfLength (double value)
  39238. {
  39239. const double n = (value - minimum) / (maximum - minimum);
  39240. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39241. }
  39242. double Slider::snapValue (double attemptedValue, const bool)
  39243. {
  39244. return attemptedValue;
  39245. }
  39246. void Slider::startedDragging()
  39247. {
  39248. }
  39249. void Slider::stoppedDragging()
  39250. {
  39251. }
  39252. void Slider::valueChanged()
  39253. {
  39254. }
  39255. void Slider::enablementChanged()
  39256. {
  39257. repaint();
  39258. }
  39259. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39260. {
  39261. menuEnabled = menuEnabled_;
  39262. }
  39263. void Slider::setScrollWheelEnabled (const bool enabled)
  39264. {
  39265. scrollWheelEnabled = enabled;
  39266. }
  39267. void Slider::labelTextChanged (Label* label)
  39268. {
  39269. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39270. if (newValue != (double) currentValue.getValue())
  39271. {
  39272. sendDragStart();
  39273. setValue (newValue, true, true);
  39274. sendDragEnd();
  39275. }
  39276. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39277. }
  39278. void Slider::buttonClicked (Button* button)
  39279. {
  39280. if (style == IncDecButtons)
  39281. {
  39282. sendDragStart();
  39283. if (button == incButton)
  39284. setValue (snapValue (getValue() + interval, false), true, true);
  39285. else if (button == decButton)
  39286. setValue (snapValue (getValue() - interval, false), true, true);
  39287. sendDragEnd();
  39288. }
  39289. }
  39290. double Slider::constrainedValue (double value) const
  39291. {
  39292. if (interval > 0)
  39293. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39294. if (value <= minimum || maximum <= minimum)
  39295. value = minimum;
  39296. else if (value >= maximum)
  39297. value = maximum;
  39298. return value;
  39299. }
  39300. float Slider::getLinearSliderPos (const double value)
  39301. {
  39302. double sliderPosProportional;
  39303. if (maximum > minimum)
  39304. {
  39305. if (value < minimum)
  39306. {
  39307. sliderPosProportional = 0.0;
  39308. }
  39309. else if (value > maximum)
  39310. {
  39311. sliderPosProportional = 1.0;
  39312. }
  39313. else
  39314. {
  39315. sliderPosProportional = valueToProportionOfLength (value);
  39316. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39317. }
  39318. }
  39319. else
  39320. {
  39321. sliderPosProportional = 0.5;
  39322. }
  39323. if (isVertical() || style == IncDecButtons)
  39324. sliderPosProportional = 1.0 - sliderPosProportional;
  39325. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39326. }
  39327. bool Slider::isHorizontal() const
  39328. {
  39329. return style == LinearHorizontal
  39330. || style == LinearBar
  39331. || style == TwoValueHorizontal
  39332. || style == ThreeValueHorizontal;
  39333. }
  39334. bool Slider::isVertical() const
  39335. {
  39336. return style == LinearVertical
  39337. || style == TwoValueVertical
  39338. || style == ThreeValueVertical;
  39339. }
  39340. bool Slider::incDecDragDirectionIsHorizontal() const
  39341. {
  39342. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39343. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39344. }
  39345. float Slider::getPositionOfValue (const double value)
  39346. {
  39347. if (isHorizontal() || isVertical())
  39348. {
  39349. return getLinearSliderPos (value);
  39350. }
  39351. else
  39352. {
  39353. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39354. return 0.0f;
  39355. }
  39356. }
  39357. void Slider::paint (Graphics& g)
  39358. {
  39359. if (style != IncDecButtons)
  39360. {
  39361. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39362. {
  39363. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39364. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39365. getLookAndFeel().drawRotarySlider (g,
  39366. sliderRect.getX(),
  39367. sliderRect.getY(),
  39368. sliderRect.getWidth(),
  39369. sliderRect.getHeight(),
  39370. sliderPos,
  39371. rotaryStart, rotaryEnd,
  39372. *this);
  39373. }
  39374. else
  39375. {
  39376. getLookAndFeel().drawLinearSlider (g,
  39377. sliderRect.getX(),
  39378. sliderRect.getY(),
  39379. sliderRect.getWidth(),
  39380. sliderRect.getHeight(),
  39381. getLinearSliderPos (lastCurrentValue),
  39382. getLinearSliderPos (lastValueMin),
  39383. getLinearSliderPos (lastValueMax),
  39384. style,
  39385. *this);
  39386. }
  39387. if (style == LinearBar && valueBox == 0)
  39388. {
  39389. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39390. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39391. }
  39392. }
  39393. }
  39394. void Slider::resized()
  39395. {
  39396. int minXSpace = 0;
  39397. int minYSpace = 0;
  39398. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39399. minXSpace = 30;
  39400. else
  39401. minYSpace = 15;
  39402. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39403. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39404. if (style == LinearBar)
  39405. {
  39406. if (valueBox != 0)
  39407. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39408. }
  39409. else
  39410. {
  39411. if (textBoxPos == NoTextBox)
  39412. {
  39413. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39414. }
  39415. else if (textBoxPos == TextBoxLeft)
  39416. {
  39417. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39418. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39419. }
  39420. else if (textBoxPos == TextBoxRight)
  39421. {
  39422. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39423. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39424. }
  39425. else if (textBoxPos == TextBoxAbove)
  39426. {
  39427. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39428. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39429. }
  39430. else if (textBoxPos == TextBoxBelow)
  39431. {
  39432. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39433. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39434. }
  39435. }
  39436. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39437. if (style == LinearBar)
  39438. {
  39439. const int barIndent = 1;
  39440. sliderRegionStart = barIndent;
  39441. sliderRegionSize = getWidth() - barIndent * 2;
  39442. sliderRect.setBounds (sliderRegionStart, barIndent,
  39443. sliderRegionSize, getHeight() - barIndent * 2);
  39444. }
  39445. else if (isHorizontal())
  39446. {
  39447. sliderRegionStart = sliderRect.getX() + indent;
  39448. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39449. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39450. sliderRegionSize, sliderRect.getHeight());
  39451. }
  39452. else if (isVertical())
  39453. {
  39454. sliderRegionStart = sliderRect.getY() + indent;
  39455. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39456. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39457. sliderRect.getWidth(), sliderRegionSize);
  39458. }
  39459. else
  39460. {
  39461. sliderRegionStart = 0;
  39462. sliderRegionSize = 100;
  39463. }
  39464. if (style == IncDecButtons)
  39465. {
  39466. Rectangle<int> buttonRect (sliderRect);
  39467. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39468. buttonRect.expand (-2, 0);
  39469. else
  39470. buttonRect.expand (0, -2);
  39471. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39472. if (incDecButtonsSideBySide)
  39473. {
  39474. decButton->setBounds (buttonRect.getX(),
  39475. buttonRect.getY(),
  39476. buttonRect.getWidth() / 2,
  39477. buttonRect.getHeight());
  39478. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39479. incButton->setBounds (buttonRect.getCentreX(),
  39480. buttonRect.getY(),
  39481. buttonRect.getWidth() / 2,
  39482. buttonRect.getHeight());
  39483. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39484. }
  39485. else
  39486. {
  39487. incButton->setBounds (buttonRect.getX(),
  39488. buttonRect.getY(),
  39489. buttonRect.getWidth(),
  39490. buttonRect.getHeight() / 2);
  39491. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39492. decButton->setBounds (buttonRect.getX(),
  39493. buttonRect.getCentreY(),
  39494. buttonRect.getWidth(),
  39495. buttonRect.getHeight() / 2);
  39496. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39497. }
  39498. }
  39499. }
  39500. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39501. {
  39502. repaint();
  39503. }
  39504. void Slider::mouseDown (const MouseEvent& e)
  39505. {
  39506. mouseWasHidden = false;
  39507. incDecDragged = false;
  39508. mouseXWhenLastDragged = e.x;
  39509. mouseYWhenLastDragged = e.y;
  39510. mouseDragStartX = e.getMouseDownX();
  39511. mouseDragStartY = e.getMouseDownY();
  39512. if (isEnabled())
  39513. {
  39514. if (e.mods.isPopupMenu() && menuEnabled)
  39515. {
  39516. menuShown = true;
  39517. PopupMenu m;
  39518. m.setLookAndFeel (&getLookAndFeel());
  39519. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39520. m.addSeparator();
  39521. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39522. {
  39523. PopupMenu rotaryMenu;
  39524. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39525. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39526. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39527. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39528. }
  39529. const int r = m.show();
  39530. if (r == 1)
  39531. {
  39532. setVelocityBasedMode (! isVelocityBased);
  39533. }
  39534. else if (r == 2)
  39535. {
  39536. setSliderStyle (Rotary);
  39537. }
  39538. else if (r == 3)
  39539. {
  39540. setSliderStyle (RotaryHorizontalDrag);
  39541. }
  39542. else if (r == 4)
  39543. {
  39544. setSliderStyle (RotaryVerticalDrag);
  39545. }
  39546. }
  39547. else if (maximum > minimum)
  39548. {
  39549. menuShown = false;
  39550. if (valueBox != 0)
  39551. valueBox->hideEditor (true);
  39552. sliderBeingDragged = 0;
  39553. if (style == TwoValueHorizontal
  39554. || style == TwoValueVertical
  39555. || style == ThreeValueHorizontal
  39556. || style == ThreeValueVertical)
  39557. {
  39558. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39559. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39560. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39561. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39562. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39563. {
  39564. if (maxPosDistance <= minPosDistance)
  39565. sliderBeingDragged = 2;
  39566. else
  39567. sliderBeingDragged = 1;
  39568. }
  39569. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39570. {
  39571. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39572. sliderBeingDragged = 1;
  39573. else if (normalPosDistance >= maxPosDistance)
  39574. sliderBeingDragged = 2;
  39575. }
  39576. }
  39577. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39578. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39579. * valueToProportionOfLength (currentValue.getValue());
  39580. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39581. : ((sliderBeingDragged == 1) ? valueMin
  39582. : currentValue)).getValue();
  39583. valueOnMouseDown = valueWhenLastDragged;
  39584. if (popupDisplayEnabled)
  39585. {
  39586. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39587. popupDisplay = popup;
  39588. if (parentForPopupDisplay != 0)
  39589. {
  39590. parentForPopupDisplay->addChildComponent (popup);
  39591. }
  39592. else
  39593. {
  39594. popup->addToDesktop (0);
  39595. }
  39596. popup->setVisible (true);
  39597. }
  39598. sendDragStart();
  39599. mouseDrag (e);
  39600. }
  39601. }
  39602. }
  39603. void Slider::mouseUp (const MouseEvent&)
  39604. {
  39605. if (isEnabled()
  39606. && (! menuShown)
  39607. && (maximum > minimum)
  39608. && (style != IncDecButtons || incDecDragged))
  39609. {
  39610. restoreMouseIfHidden();
  39611. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39612. triggerChangeMessage (false);
  39613. sendDragEnd();
  39614. popupDisplay = 0;
  39615. if (style == IncDecButtons)
  39616. {
  39617. incButton->setState (Button::buttonNormal);
  39618. decButton->setState (Button::buttonNormal);
  39619. }
  39620. }
  39621. }
  39622. void Slider::restoreMouseIfHidden()
  39623. {
  39624. if (mouseWasHidden)
  39625. {
  39626. mouseWasHidden = false;
  39627. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39628. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39629. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39630. : ((sliderBeingDragged == 1) ? getMinValue()
  39631. : (double) currentValue.getValue());
  39632. Point<int> mousePos;
  39633. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39634. {
  39635. mousePos = Desktop::getLastMouseDownPosition();
  39636. if (style == RotaryHorizontalDrag)
  39637. {
  39638. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39639. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39640. }
  39641. else
  39642. {
  39643. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39644. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39645. }
  39646. }
  39647. else
  39648. {
  39649. const int pixelPos = (int) getLinearSliderPos (pos);
  39650. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39651. isVertical() ? pixelPos : (getHeight() / 2)));
  39652. }
  39653. Desktop::setMousePosition (mousePos);
  39654. }
  39655. }
  39656. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39657. {
  39658. if (isEnabled()
  39659. && style != IncDecButtons
  39660. && style != Rotary
  39661. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39662. {
  39663. restoreMouseIfHidden();
  39664. }
  39665. }
  39666. static double smallestAngleBetween (double a1, double a2)
  39667. {
  39668. return jmin (fabs (a1 - a2),
  39669. fabs (a1 + double_Pi * 2.0 - a2),
  39670. fabs (a2 + double_Pi * 2.0 - a1));
  39671. }
  39672. void Slider::mouseDrag (const MouseEvent& e)
  39673. {
  39674. if (isEnabled()
  39675. && (! menuShown)
  39676. && (maximum > minimum))
  39677. {
  39678. if (style == Rotary)
  39679. {
  39680. int dx = e.x - sliderRect.getCentreX();
  39681. int dy = e.y - sliderRect.getCentreY();
  39682. if (dx * dx + dy * dy > 25)
  39683. {
  39684. double angle = atan2 ((double) dx, (double) -dy);
  39685. while (angle < 0.0)
  39686. angle += double_Pi * 2.0;
  39687. if (rotaryStop && ! e.mouseWasClicked())
  39688. {
  39689. if (fabs (angle - lastAngle) > double_Pi)
  39690. {
  39691. if (angle >= lastAngle)
  39692. angle -= double_Pi * 2.0;
  39693. else
  39694. angle += double_Pi * 2.0;
  39695. }
  39696. if (angle >= lastAngle)
  39697. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39698. else
  39699. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39700. }
  39701. else
  39702. {
  39703. while (angle < rotaryStart)
  39704. angle += double_Pi * 2.0;
  39705. if (angle > rotaryEnd)
  39706. {
  39707. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39708. angle = rotaryStart;
  39709. else
  39710. angle = rotaryEnd;
  39711. }
  39712. }
  39713. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39714. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39715. lastAngle = angle;
  39716. }
  39717. }
  39718. else
  39719. {
  39720. if (style == LinearBar && e.mouseWasClicked()
  39721. && valueBox != 0 && valueBox->isEditable())
  39722. return;
  39723. if (style == IncDecButtons && ! incDecDragged)
  39724. {
  39725. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39726. return;
  39727. incDecDragged = true;
  39728. mouseDragStartX = e.x;
  39729. mouseDragStartY = e.y;
  39730. }
  39731. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39732. : false))
  39733. || ((maximum - minimum) / sliderRegionSize < interval))
  39734. {
  39735. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39736. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39737. if (style == RotaryHorizontalDrag
  39738. || style == RotaryVerticalDrag
  39739. || style == IncDecButtons
  39740. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39741. && ! snapsToMousePos))
  39742. {
  39743. const int mouseDiff = (style == RotaryHorizontalDrag
  39744. || style == LinearHorizontal
  39745. || style == LinearBar
  39746. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39747. ? e.x - mouseDragStartX
  39748. : mouseDragStartY - e.y;
  39749. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39750. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39751. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39752. if (style == IncDecButtons)
  39753. {
  39754. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39755. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39756. }
  39757. }
  39758. else
  39759. {
  39760. if (isVertical())
  39761. scaledMousePos = 1.0 - scaledMousePos;
  39762. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39763. }
  39764. }
  39765. else
  39766. {
  39767. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39768. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39769. ? e.x - mouseXWhenLastDragged
  39770. : e.y - mouseYWhenLastDragged;
  39771. const double maxSpeed = jmax (200, sliderRegionSize);
  39772. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39773. if (speed != 0)
  39774. {
  39775. speed = 0.2 * velocityModeSensitivity
  39776. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39777. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39778. / maxSpeed))));
  39779. if (mouseDiff < 0)
  39780. speed = -speed;
  39781. if (isVertical() || style == RotaryVerticalDrag
  39782. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39783. speed = -speed;
  39784. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39785. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39786. e.source.enableUnboundedMouseMovement (true, false);
  39787. mouseWasHidden = true;
  39788. }
  39789. }
  39790. }
  39791. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39792. if (sliderBeingDragged == 0)
  39793. {
  39794. setValue (snapValue (valueWhenLastDragged, true),
  39795. ! sendChangeOnlyOnRelease, true);
  39796. }
  39797. else if (sliderBeingDragged == 1)
  39798. {
  39799. setMinValue (snapValue (valueWhenLastDragged, true),
  39800. ! sendChangeOnlyOnRelease, false, true);
  39801. if (e.mods.isShiftDown())
  39802. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39803. else
  39804. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39805. }
  39806. else
  39807. {
  39808. jassert (sliderBeingDragged == 2);
  39809. setMaxValue (snapValue (valueWhenLastDragged, true),
  39810. ! sendChangeOnlyOnRelease, false, true);
  39811. if (e.mods.isShiftDown())
  39812. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39813. else
  39814. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39815. }
  39816. mouseXWhenLastDragged = e.x;
  39817. mouseYWhenLastDragged = e.y;
  39818. }
  39819. }
  39820. void Slider::mouseDoubleClick (const MouseEvent&)
  39821. {
  39822. if (doubleClickToValue
  39823. && isEnabled()
  39824. && style != IncDecButtons
  39825. && minimum <= doubleClickReturnValue
  39826. && maximum >= doubleClickReturnValue)
  39827. {
  39828. sendDragStart();
  39829. setValue (doubleClickReturnValue, true, true);
  39830. sendDragEnd();
  39831. }
  39832. }
  39833. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39834. {
  39835. if (scrollWheelEnabled && isEnabled()
  39836. && style != TwoValueHorizontal
  39837. && style != TwoValueVertical)
  39838. {
  39839. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39840. {
  39841. if (valueBox != 0)
  39842. valueBox->hideEditor (false);
  39843. const double value = (double) currentValue.getValue();
  39844. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39845. const double currentPos = valueToProportionOfLength (value);
  39846. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39847. double delta = (newValue != value)
  39848. ? jmax (fabs (newValue - value), interval) : 0;
  39849. if (value > newValue)
  39850. delta = -delta;
  39851. sendDragStart();
  39852. setValue (snapValue (value + delta, false), true, true);
  39853. sendDragEnd();
  39854. }
  39855. }
  39856. else
  39857. {
  39858. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39859. }
  39860. }
  39861. void SliderListener::sliderDragStarted (Slider*)
  39862. {
  39863. }
  39864. void SliderListener::sliderDragEnded (Slider*)
  39865. {
  39866. }
  39867. END_JUCE_NAMESPACE
  39868. /*** End of inlined file: juce_Slider.cpp ***/
  39869. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39870. BEGIN_JUCE_NAMESPACE
  39871. class DragOverlayComp : public Component
  39872. {
  39873. public:
  39874. DragOverlayComp (Image* const image_)
  39875. : image (image_)
  39876. {
  39877. image->multiplyAllAlphas (0.8f);
  39878. setAlwaysOnTop (true);
  39879. }
  39880. ~DragOverlayComp()
  39881. {
  39882. }
  39883. void paint (Graphics& g)
  39884. {
  39885. g.drawImageAt (image, 0, 0);
  39886. }
  39887. private:
  39888. ScopedPointer <Image> image;
  39889. DragOverlayComp (const DragOverlayComp&);
  39890. DragOverlayComp& operator= (const DragOverlayComp&);
  39891. };
  39892. TableHeaderComponent::TableHeaderComponent()
  39893. : columnsChanged (false),
  39894. columnsResized (false),
  39895. sortChanged (false),
  39896. menuActive (true),
  39897. stretchToFit (false),
  39898. columnIdBeingResized (0),
  39899. columnIdBeingDragged (0),
  39900. columnIdUnderMouse (0),
  39901. lastDeliberateWidth (0)
  39902. {
  39903. }
  39904. TableHeaderComponent::~TableHeaderComponent()
  39905. {
  39906. dragOverlayComp = 0;
  39907. }
  39908. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39909. {
  39910. menuActive = hasMenu;
  39911. }
  39912. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39913. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39914. {
  39915. if (onlyCountVisibleColumns)
  39916. {
  39917. int num = 0;
  39918. for (int i = columns.size(); --i >= 0;)
  39919. if (columns.getUnchecked(i)->isVisible())
  39920. ++num;
  39921. return num;
  39922. }
  39923. else
  39924. {
  39925. return columns.size();
  39926. }
  39927. }
  39928. const String TableHeaderComponent::getColumnName (const int columnId) const
  39929. {
  39930. const ColumnInfo* const ci = getInfoForId (columnId);
  39931. return ci != 0 ? ci->name : String::empty;
  39932. }
  39933. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  39934. {
  39935. ColumnInfo* const ci = getInfoForId (columnId);
  39936. if (ci != 0 && ci->name != newName)
  39937. {
  39938. ci->name = newName;
  39939. sendColumnsChanged();
  39940. }
  39941. }
  39942. void TableHeaderComponent::addColumn (const String& columnName,
  39943. const int columnId,
  39944. const int width,
  39945. const int minimumWidth,
  39946. const int maximumWidth,
  39947. const int propertyFlags,
  39948. const int insertIndex)
  39949. {
  39950. // can't have a duplicate or null ID!
  39951. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  39952. jassert (width > 0);
  39953. ColumnInfo* const ci = new ColumnInfo();
  39954. ci->name = columnName;
  39955. ci->id = columnId;
  39956. ci->width = width;
  39957. ci->lastDeliberateWidth = width;
  39958. ci->minimumWidth = minimumWidth;
  39959. ci->maximumWidth = maximumWidth;
  39960. if (ci->maximumWidth < 0)
  39961. ci->maximumWidth = std::numeric_limits<int>::max();
  39962. jassert (ci->maximumWidth >= ci->minimumWidth);
  39963. ci->propertyFlags = propertyFlags;
  39964. columns.insert (insertIndex, ci);
  39965. sendColumnsChanged();
  39966. }
  39967. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  39968. {
  39969. const int index = getIndexOfColumnId (columnIdToRemove, false);
  39970. if (index >= 0)
  39971. {
  39972. columns.remove (index);
  39973. sortChanged = true;
  39974. sendColumnsChanged();
  39975. }
  39976. }
  39977. void TableHeaderComponent::removeAllColumns()
  39978. {
  39979. if (columns.size() > 0)
  39980. {
  39981. columns.clear();
  39982. sendColumnsChanged();
  39983. }
  39984. }
  39985. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  39986. {
  39987. const int currentIndex = getIndexOfColumnId (columnId, false);
  39988. newIndex = visibleIndexToTotalIndex (newIndex);
  39989. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  39990. {
  39991. columns.move (currentIndex, newIndex);
  39992. sendColumnsChanged();
  39993. }
  39994. }
  39995. int TableHeaderComponent::getColumnWidth (const int columnId) const
  39996. {
  39997. const ColumnInfo* const ci = getInfoForId (columnId);
  39998. return ci != 0 ? ci->width : 0;
  39999. }
  40000. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  40001. {
  40002. ColumnInfo* const ci = getInfoForId (columnId);
  40003. if (ci != 0 && ci->width != newWidth)
  40004. {
  40005. const int numColumns = getNumColumns (true);
  40006. ci->lastDeliberateWidth = ci->width
  40007. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40008. if (stretchToFit)
  40009. {
  40010. const int index = getIndexOfColumnId (columnId, true) + 1;
  40011. if (((unsigned int) index) < (unsigned int) numColumns)
  40012. {
  40013. const int x = getColumnPosition (index).getX();
  40014. if (lastDeliberateWidth == 0)
  40015. lastDeliberateWidth = getTotalWidth();
  40016. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40017. }
  40018. }
  40019. repaint();
  40020. columnsResized = true;
  40021. triggerAsyncUpdate();
  40022. }
  40023. }
  40024. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40025. {
  40026. int n = 0;
  40027. for (int i = 0; i < columns.size(); ++i)
  40028. {
  40029. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40030. {
  40031. if (columns.getUnchecked(i)->id == columnId)
  40032. return n;
  40033. ++n;
  40034. }
  40035. }
  40036. return -1;
  40037. }
  40038. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40039. {
  40040. if (onlyCountVisibleColumns)
  40041. index = visibleIndexToTotalIndex (index);
  40042. const ColumnInfo* const ci = columns [index];
  40043. return (ci != 0) ? ci->id : 0;
  40044. }
  40045. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  40046. {
  40047. int x = 0, width = 0, n = 0;
  40048. for (int i = 0; i < columns.size(); ++i)
  40049. {
  40050. x += width;
  40051. if (columns.getUnchecked(i)->isVisible())
  40052. {
  40053. width = columns.getUnchecked(i)->width;
  40054. if (n++ == index)
  40055. break;
  40056. }
  40057. else
  40058. {
  40059. width = 0;
  40060. }
  40061. }
  40062. return Rectangle<int> (x, 0, width, getHeight());
  40063. }
  40064. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40065. {
  40066. if (xToFind >= 0)
  40067. {
  40068. int x = 0;
  40069. for (int i = 0; i < columns.size(); ++i)
  40070. {
  40071. const ColumnInfo* const ci = columns.getUnchecked(i);
  40072. if (ci->isVisible())
  40073. {
  40074. x += ci->width;
  40075. if (xToFind < x)
  40076. return ci->id;
  40077. }
  40078. }
  40079. }
  40080. return 0;
  40081. }
  40082. int TableHeaderComponent::getTotalWidth() const
  40083. {
  40084. int w = 0;
  40085. for (int i = columns.size(); --i >= 0;)
  40086. if (columns.getUnchecked(i)->isVisible())
  40087. w += columns.getUnchecked(i)->width;
  40088. return w;
  40089. }
  40090. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40091. {
  40092. stretchToFit = shouldStretchToFit;
  40093. lastDeliberateWidth = getTotalWidth();
  40094. resized();
  40095. }
  40096. bool TableHeaderComponent::isStretchToFitActive() const
  40097. {
  40098. return stretchToFit;
  40099. }
  40100. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40101. {
  40102. if (stretchToFit && getWidth() > 0
  40103. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40104. {
  40105. lastDeliberateWidth = targetTotalWidth;
  40106. resizeColumnsToFit (0, targetTotalWidth);
  40107. }
  40108. }
  40109. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40110. {
  40111. targetTotalWidth = jmax (targetTotalWidth, 0);
  40112. StretchableObjectResizer sor;
  40113. int i;
  40114. for (i = firstColumnIndex; i < columns.size(); ++i)
  40115. {
  40116. ColumnInfo* const ci = columns.getUnchecked(i);
  40117. if (ci->isVisible())
  40118. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40119. }
  40120. sor.resizeToFit (targetTotalWidth);
  40121. int visIndex = 0;
  40122. for (i = firstColumnIndex; i < columns.size(); ++i)
  40123. {
  40124. ColumnInfo* const ci = columns.getUnchecked(i);
  40125. if (ci->isVisible())
  40126. {
  40127. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40128. (int) floor (sor.getItemSize (visIndex++)));
  40129. if (newWidth != ci->width)
  40130. {
  40131. ci->width = newWidth;
  40132. repaint();
  40133. columnsResized = true;
  40134. triggerAsyncUpdate();
  40135. }
  40136. }
  40137. }
  40138. }
  40139. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40140. {
  40141. ColumnInfo* const ci = getInfoForId (columnId);
  40142. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40143. {
  40144. if (shouldBeVisible)
  40145. ci->propertyFlags |= visible;
  40146. else
  40147. ci->propertyFlags &= ~visible;
  40148. sendColumnsChanged();
  40149. resized();
  40150. }
  40151. }
  40152. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40153. {
  40154. const ColumnInfo* const ci = getInfoForId (columnId);
  40155. return ci != 0 && ci->isVisible();
  40156. }
  40157. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40158. {
  40159. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40160. {
  40161. for (int i = columns.size(); --i >= 0;)
  40162. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40163. ColumnInfo* const ci = getInfoForId (columnId);
  40164. if (ci != 0)
  40165. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40166. reSortTable();
  40167. }
  40168. }
  40169. int TableHeaderComponent::getSortColumnId() const
  40170. {
  40171. for (int i = columns.size(); --i >= 0;)
  40172. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40173. return columns.getUnchecked(i)->id;
  40174. return 0;
  40175. }
  40176. bool TableHeaderComponent::isSortedForwards() const
  40177. {
  40178. for (int i = columns.size(); --i >= 0;)
  40179. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40180. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40181. return true;
  40182. }
  40183. void TableHeaderComponent::reSortTable()
  40184. {
  40185. sortChanged = true;
  40186. repaint();
  40187. triggerAsyncUpdate();
  40188. }
  40189. const String TableHeaderComponent::toString() const
  40190. {
  40191. String s;
  40192. XmlElement doc ("TABLELAYOUT");
  40193. doc.setAttribute ("sortedCol", getSortColumnId());
  40194. doc.setAttribute ("sortForwards", isSortedForwards());
  40195. for (int i = 0; i < columns.size(); ++i)
  40196. {
  40197. const ColumnInfo* const ci = columns.getUnchecked (i);
  40198. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40199. e->setAttribute ("id", ci->id);
  40200. e->setAttribute ("visible", ci->isVisible());
  40201. e->setAttribute ("width", ci->width);
  40202. }
  40203. return doc.createDocument (String::empty, true, false);
  40204. }
  40205. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40206. {
  40207. XmlDocument doc (storedVersion);
  40208. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40209. int index = 0;
  40210. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40211. {
  40212. forEachXmlChildElement (*storedXml, col)
  40213. {
  40214. const int tabId = col->getIntAttribute ("id");
  40215. ColumnInfo* const ci = getInfoForId (tabId);
  40216. if (ci != 0)
  40217. {
  40218. columns.move (columns.indexOf (ci), index);
  40219. ci->width = col->getIntAttribute ("width");
  40220. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40221. }
  40222. ++index;
  40223. }
  40224. columnsResized = true;
  40225. sendColumnsChanged();
  40226. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40227. storedXml->getBoolAttribute ("sortForwards", true));
  40228. }
  40229. }
  40230. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40231. {
  40232. listeners.addIfNotAlreadyThere (newListener);
  40233. }
  40234. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40235. {
  40236. listeners.removeValue (listenerToRemove);
  40237. }
  40238. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40239. {
  40240. const ColumnInfo* const ci = getInfoForId (columnId);
  40241. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40242. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40243. }
  40244. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40245. {
  40246. for (int i = 0; i < columns.size(); ++i)
  40247. {
  40248. const ColumnInfo* const ci = columns.getUnchecked(i);
  40249. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40250. menu.addItem (ci->id, ci->name,
  40251. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40252. isColumnVisible (ci->id));
  40253. }
  40254. }
  40255. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40256. {
  40257. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40258. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40259. }
  40260. void TableHeaderComponent::paint (Graphics& g)
  40261. {
  40262. LookAndFeel& lf = getLookAndFeel();
  40263. lf.drawTableHeaderBackground (g, *this);
  40264. const Rectangle<int> clip (g.getClipBounds());
  40265. int x = 0;
  40266. for (int i = 0; i < columns.size(); ++i)
  40267. {
  40268. const ColumnInfo* const ci = columns.getUnchecked(i);
  40269. if (ci->isVisible())
  40270. {
  40271. if (x + ci->width > clip.getX()
  40272. && (ci->id != columnIdBeingDragged
  40273. || dragOverlayComp == 0
  40274. || ! dragOverlayComp->isVisible()))
  40275. {
  40276. g.saveState();
  40277. g.setOrigin (x, 0);
  40278. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40279. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40280. ci->id == columnIdUnderMouse,
  40281. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40282. ci->propertyFlags);
  40283. g.restoreState();
  40284. }
  40285. x += ci->width;
  40286. if (x >= clip.getRight())
  40287. break;
  40288. }
  40289. }
  40290. }
  40291. void TableHeaderComponent::resized()
  40292. {
  40293. }
  40294. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40295. {
  40296. updateColumnUnderMouse (e.x, e.y);
  40297. }
  40298. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40299. {
  40300. updateColumnUnderMouse (e.x, e.y);
  40301. }
  40302. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40303. {
  40304. updateColumnUnderMouse (e.x, e.y);
  40305. }
  40306. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40307. {
  40308. repaint();
  40309. columnIdBeingResized = 0;
  40310. columnIdBeingDragged = 0;
  40311. if (columnIdUnderMouse != 0)
  40312. {
  40313. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40314. if (e.mods.isPopupMenu())
  40315. columnClicked (columnIdUnderMouse, e.mods);
  40316. }
  40317. if (menuActive && e.mods.isPopupMenu())
  40318. showColumnChooserMenu (columnIdUnderMouse);
  40319. }
  40320. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40321. {
  40322. if (columnIdBeingResized == 0
  40323. && columnIdBeingDragged == 0
  40324. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40325. {
  40326. dragOverlayComp = 0;
  40327. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40328. if (columnIdBeingResized != 0)
  40329. {
  40330. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40331. initialColumnWidth = ci->width;
  40332. }
  40333. else
  40334. {
  40335. beginDrag (e);
  40336. }
  40337. }
  40338. if (columnIdBeingResized != 0)
  40339. {
  40340. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40341. if (ci != 0)
  40342. {
  40343. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40344. initialColumnWidth + e.getDistanceFromDragStartX());
  40345. if (stretchToFit)
  40346. {
  40347. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40348. int minWidthOnRight = 0;
  40349. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40350. if (columns.getUnchecked (i)->isVisible())
  40351. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40352. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40353. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40354. }
  40355. setColumnWidth (columnIdBeingResized, w);
  40356. }
  40357. }
  40358. else if (columnIdBeingDragged != 0)
  40359. {
  40360. if (e.y >= -50 && e.y < getHeight() + 50)
  40361. {
  40362. if (dragOverlayComp != 0)
  40363. {
  40364. dragOverlayComp->setVisible (true);
  40365. dragOverlayComp->setBounds (jlimit (0,
  40366. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40367. e.x - draggingColumnOffset),
  40368. 0,
  40369. dragOverlayComp->getWidth(),
  40370. getHeight());
  40371. for (int i = columns.size(); --i >= 0;)
  40372. {
  40373. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40374. int newIndex = currentIndex;
  40375. if (newIndex > 0)
  40376. {
  40377. // if the previous column isn't draggable, we can't move our column
  40378. // past it, because that'd change the undraggable column's position..
  40379. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40380. if ((previous->propertyFlags & draggable) != 0)
  40381. {
  40382. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40383. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40384. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40385. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40386. {
  40387. --newIndex;
  40388. }
  40389. }
  40390. }
  40391. if (newIndex < columns.size() - 1)
  40392. {
  40393. // if the next column isn't draggable, we can't move our column
  40394. // past it, because that'd change the undraggable column's position..
  40395. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40396. if ((nextCol->propertyFlags & draggable) != 0)
  40397. {
  40398. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40399. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40400. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40401. > abs (dragOverlayComp->getRight() - rightOfNext))
  40402. {
  40403. ++newIndex;
  40404. }
  40405. }
  40406. }
  40407. if (newIndex != currentIndex)
  40408. moveColumn (columnIdBeingDragged, newIndex);
  40409. else
  40410. break;
  40411. }
  40412. }
  40413. }
  40414. else
  40415. {
  40416. endDrag (draggingColumnOriginalIndex);
  40417. }
  40418. }
  40419. }
  40420. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40421. {
  40422. if (columnIdBeingDragged == 0)
  40423. {
  40424. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40425. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40426. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40427. {
  40428. columnIdBeingDragged = 0;
  40429. }
  40430. else
  40431. {
  40432. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40433. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40434. const int temp = columnIdBeingDragged;
  40435. columnIdBeingDragged = 0;
  40436. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40437. columnIdBeingDragged = temp;
  40438. dragOverlayComp->setBounds (columnRect);
  40439. for (int i = listeners.size(); --i >= 0;)
  40440. {
  40441. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40442. i = jmin (i, listeners.size() - 1);
  40443. }
  40444. }
  40445. }
  40446. }
  40447. void TableHeaderComponent::endDrag (const int finalIndex)
  40448. {
  40449. if (columnIdBeingDragged != 0)
  40450. {
  40451. moveColumn (columnIdBeingDragged, finalIndex);
  40452. columnIdBeingDragged = 0;
  40453. repaint();
  40454. for (int i = listeners.size(); --i >= 0;)
  40455. {
  40456. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40457. i = jmin (i, listeners.size() - 1);
  40458. }
  40459. }
  40460. }
  40461. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40462. {
  40463. mouseDrag (e);
  40464. for (int i = columns.size(); --i >= 0;)
  40465. if (columns.getUnchecked (i)->isVisible())
  40466. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40467. columnIdBeingResized = 0;
  40468. repaint();
  40469. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40470. updateColumnUnderMouse (e.x, e.y);
  40471. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40472. columnClicked (columnIdUnderMouse, e.mods);
  40473. dragOverlayComp = 0;
  40474. }
  40475. const MouseCursor TableHeaderComponent::getMouseCursor()
  40476. {
  40477. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40478. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40479. return Component::getMouseCursor();
  40480. }
  40481. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40482. {
  40483. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40484. }
  40485. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40486. {
  40487. for (int i = columns.size(); --i >= 0;)
  40488. if (columns.getUnchecked(i)->id == id)
  40489. return columns.getUnchecked(i);
  40490. return 0;
  40491. }
  40492. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40493. {
  40494. int n = 0;
  40495. for (int i = 0; i < columns.size(); ++i)
  40496. {
  40497. if (columns.getUnchecked(i)->isVisible())
  40498. {
  40499. if (n == visibleIndex)
  40500. return i;
  40501. ++n;
  40502. }
  40503. }
  40504. return -1;
  40505. }
  40506. void TableHeaderComponent::sendColumnsChanged()
  40507. {
  40508. if (stretchToFit && lastDeliberateWidth > 0)
  40509. resizeAllColumnsToFit (lastDeliberateWidth);
  40510. repaint();
  40511. columnsChanged = true;
  40512. triggerAsyncUpdate();
  40513. }
  40514. void TableHeaderComponent::handleAsyncUpdate()
  40515. {
  40516. const bool changed = columnsChanged || sortChanged;
  40517. const bool sized = columnsResized || changed;
  40518. const bool sorted = sortChanged;
  40519. columnsChanged = false;
  40520. columnsResized = false;
  40521. sortChanged = false;
  40522. if (sorted)
  40523. {
  40524. for (int i = listeners.size(); --i >= 0;)
  40525. {
  40526. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40527. i = jmin (i, listeners.size() - 1);
  40528. }
  40529. }
  40530. if (changed)
  40531. {
  40532. for (int i = listeners.size(); --i >= 0;)
  40533. {
  40534. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40535. i = jmin (i, listeners.size() - 1);
  40536. }
  40537. }
  40538. if (sized)
  40539. {
  40540. for (int i = listeners.size(); --i >= 0;)
  40541. {
  40542. listeners.getUnchecked(i)->tableColumnsResized (this);
  40543. i = jmin (i, listeners.size() - 1);
  40544. }
  40545. }
  40546. }
  40547. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40548. {
  40549. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40550. {
  40551. const int draggableDistance = 3;
  40552. int x = 0;
  40553. for (int i = 0; i < columns.size(); ++i)
  40554. {
  40555. const ColumnInfo* const ci = columns.getUnchecked(i);
  40556. if (ci->isVisible())
  40557. {
  40558. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40559. && (ci->propertyFlags & resizable) != 0)
  40560. return ci->id;
  40561. x += ci->width;
  40562. }
  40563. }
  40564. }
  40565. return 0;
  40566. }
  40567. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40568. {
  40569. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40570. ? getColumnIdAtX (x) : 0;
  40571. if (newCol != columnIdUnderMouse)
  40572. {
  40573. columnIdUnderMouse = newCol;
  40574. repaint();
  40575. }
  40576. }
  40577. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40578. {
  40579. PopupMenu m;
  40580. addMenuItems (m, columnIdClicked);
  40581. if (m.getNumItems() > 0)
  40582. {
  40583. m.setLookAndFeel (&getLookAndFeel());
  40584. const int result = m.show();
  40585. if (result != 0)
  40586. reactToMenuItem (result, columnIdClicked);
  40587. }
  40588. }
  40589. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40590. {
  40591. }
  40592. END_JUCE_NAMESPACE
  40593. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40594. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40595. BEGIN_JUCE_NAMESPACE
  40596. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40597. class TableListRowComp : public Component,
  40598. public TooltipClient
  40599. {
  40600. public:
  40601. TableListRowComp (TableListBox& owner_)
  40602. : owner (owner_),
  40603. row (-1),
  40604. isSelected (false)
  40605. {
  40606. }
  40607. ~TableListRowComp()
  40608. {
  40609. deleteAllChildren();
  40610. }
  40611. void paint (Graphics& g)
  40612. {
  40613. TableListBoxModel* const model = owner.getModel();
  40614. if (model != 0)
  40615. {
  40616. const TableHeaderComponent* const header = owner.getHeader();
  40617. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40618. const int numColumns = header->getNumColumns (true);
  40619. for (int i = 0; i < numColumns; ++i)
  40620. {
  40621. if (! columnsWithComponents [i])
  40622. {
  40623. const int columnId = header->getColumnIdOfIndex (i, true);
  40624. Rectangle<int> columnRect (header->getColumnPosition (i));
  40625. columnRect.setSize (columnRect.getWidth(), getHeight());
  40626. g.saveState();
  40627. g.reduceClipRegion (columnRect);
  40628. g.setOrigin (columnRect.getX(), 0);
  40629. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40630. g.restoreState();
  40631. }
  40632. }
  40633. }
  40634. }
  40635. void update (const int newRow, const bool isNowSelected)
  40636. {
  40637. if (newRow != row || isNowSelected != isSelected)
  40638. {
  40639. row = newRow;
  40640. isSelected = isNowSelected;
  40641. repaint();
  40642. }
  40643. if (row < owner.getNumRows())
  40644. {
  40645. jassert (row >= 0);
  40646. const var::identifier tagPropertyName ("_tableLastUseNum");
  40647. const int newTag = Random::getSystemRandom().nextInt();
  40648. const TableHeaderComponent* const header = owner.getHeader();
  40649. const int numColumns = header->getNumColumns (true);
  40650. int i;
  40651. columnsWithComponents.clear();
  40652. if (owner.getModel() != 0)
  40653. {
  40654. for (i = 0; i < numColumns; ++i)
  40655. {
  40656. const int columnId = header->getColumnIdOfIndex (i, true);
  40657. Component* const newComp
  40658. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40659. findChildComponentForColumn (columnId));
  40660. if (newComp != 0)
  40661. {
  40662. addAndMakeVisible (newComp);
  40663. newComp->getProperties().set (tagPropertyName, newTag);
  40664. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40665. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40666. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40667. columnsWithComponents.setBit (i);
  40668. }
  40669. }
  40670. }
  40671. for (i = getNumChildComponents(); --i >= 0;)
  40672. {
  40673. Component* const c = getChildComponent (i);
  40674. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40675. delete c;
  40676. }
  40677. }
  40678. else
  40679. {
  40680. columnsWithComponents.clear();
  40681. deleteAllChildren();
  40682. }
  40683. }
  40684. void resized()
  40685. {
  40686. for (int i = getNumChildComponents(); --i >= 0;)
  40687. {
  40688. Component* const c = getChildComponent (i);
  40689. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40690. if (columnId != 0)
  40691. {
  40692. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40693. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40694. }
  40695. }
  40696. }
  40697. void mouseDown (const MouseEvent& e)
  40698. {
  40699. isDragging = false;
  40700. selectRowOnMouseUp = false;
  40701. if (isEnabled())
  40702. {
  40703. if (! isSelected)
  40704. {
  40705. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40706. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40707. if (columnId != 0 && owner.getModel() != 0)
  40708. owner.getModel()->cellClicked (row, columnId, e);
  40709. }
  40710. else
  40711. {
  40712. selectRowOnMouseUp = true;
  40713. }
  40714. }
  40715. }
  40716. void mouseDrag (const MouseEvent& e)
  40717. {
  40718. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40719. {
  40720. const SparseSet <int> selectedRows (owner.getSelectedRows());
  40721. if (selectedRows.size() > 0)
  40722. {
  40723. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40724. if (dragDescription.isNotEmpty())
  40725. {
  40726. isDragging = true;
  40727. owner.startDragAndDrop (e, dragDescription);
  40728. }
  40729. }
  40730. }
  40731. }
  40732. void mouseUp (const MouseEvent& e)
  40733. {
  40734. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40735. {
  40736. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40737. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40738. if (columnId != 0 && owner.getModel() != 0)
  40739. owner.getModel()->cellClicked (row, columnId, e);
  40740. }
  40741. }
  40742. void mouseDoubleClick (const MouseEvent& e)
  40743. {
  40744. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40745. if (columnId != 0 && owner.getModel() != 0)
  40746. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40747. }
  40748. const String getTooltip()
  40749. {
  40750. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40751. if (columnId != 0 && owner.getModel() != 0)
  40752. return owner.getModel()->getCellTooltip (row, columnId);
  40753. return String::empty;
  40754. }
  40755. juce_UseDebuggingNewOperator
  40756. private:
  40757. TableListBox& owner;
  40758. int row;
  40759. bool isSelected, isDragging, selectRowOnMouseUp;
  40760. BitArray columnsWithComponents;
  40761. Component* findChildComponentForColumn (const int columnId) const
  40762. {
  40763. for (int i = getNumChildComponents(); --i >= 0;)
  40764. {
  40765. Component* const c = getChildComponent (i);
  40766. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40767. return c;
  40768. }
  40769. return 0;
  40770. }
  40771. TableListRowComp (const TableListRowComp&);
  40772. TableListRowComp& operator= (const TableListRowComp&);
  40773. };
  40774. class TableListBoxHeader : public TableHeaderComponent
  40775. {
  40776. public:
  40777. TableListBoxHeader (TableListBox& owner_)
  40778. : owner (owner_)
  40779. {
  40780. }
  40781. ~TableListBoxHeader()
  40782. {
  40783. }
  40784. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  40785. {
  40786. if (owner.isAutoSizeMenuOptionShown())
  40787. {
  40788. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40789. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40790. menu.addSeparator();
  40791. }
  40792. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40793. }
  40794. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  40795. {
  40796. if (menuReturnId == 0xf836743)
  40797. {
  40798. owner.autoSizeColumn (columnIdClicked);
  40799. }
  40800. else if (menuReturnId == 0xf836744)
  40801. {
  40802. owner.autoSizeAllColumns();
  40803. }
  40804. else
  40805. {
  40806. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40807. }
  40808. }
  40809. juce_UseDebuggingNewOperator
  40810. private:
  40811. TableListBox& owner;
  40812. TableListBoxHeader (const TableListBoxHeader&);
  40813. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40814. };
  40815. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40816. : ListBox (name, 0),
  40817. model (model_),
  40818. autoSizeOptionsShown (true)
  40819. {
  40820. ListBox::model = this;
  40821. header = new TableListBoxHeader (*this);
  40822. header->setSize (100, 28);
  40823. header->addListener (this);
  40824. setHeaderComponent (header);
  40825. }
  40826. TableListBox::~TableListBox()
  40827. {
  40828. deleteAllChildren();
  40829. }
  40830. void TableListBox::setModel (TableListBoxModel* const newModel)
  40831. {
  40832. if (model != newModel)
  40833. {
  40834. model = newModel;
  40835. updateContent();
  40836. }
  40837. }
  40838. int TableListBox::getHeaderHeight() const
  40839. {
  40840. return header->getHeight();
  40841. }
  40842. void TableListBox::setHeaderHeight (const int newHeight)
  40843. {
  40844. header->setSize (header->getWidth(), newHeight);
  40845. resized();
  40846. }
  40847. void TableListBox::autoSizeColumn (const int columnId)
  40848. {
  40849. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40850. if (width > 0)
  40851. header->setColumnWidth (columnId, width);
  40852. }
  40853. void TableListBox::autoSizeAllColumns()
  40854. {
  40855. for (int i = 0; i < header->getNumColumns (true); ++i)
  40856. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40857. }
  40858. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40859. {
  40860. autoSizeOptionsShown = shouldBeShown;
  40861. }
  40862. bool TableListBox::isAutoSizeMenuOptionShown() const
  40863. {
  40864. return autoSizeOptionsShown;
  40865. }
  40866. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40867. const int rowNumber,
  40868. const bool relativeToComponentTopLeft) const
  40869. {
  40870. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40871. if (relativeToComponentTopLeft)
  40872. headerCell.translate (header->getX(), 0);
  40873. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40874. return Rectangle<int> (headerCell.getX(), row.getY(),
  40875. headerCell.getWidth(), row.getHeight());
  40876. }
  40877. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40878. {
  40879. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40880. if (scrollbar != 0)
  40881. {
  40882. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40883. double x = scrollbar->getCurrentRangeStart();
  40884. const double w = scrollbar->getCurrentRangeSize();
  40885. if (pos.getX() < x)
  40886. x = pos.getX();
  40887. else if (pos.getRight() > x + w)
  40888. x += jmax (0.0, pos.getRight() - (x + w));
  40889. scrollbar->setCurrentRangeStart (x);
  40890. }
  40891. }
  40892. int TableListBox::getNumRows()
  40893. {
  40894. return model != 0 ? model->getNumRows() : 0;
  40895. }
  40896. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40897. {
  40898. }
  40899. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40900. {
  40901. if (existingComponentToUpdate == 0)
  40902. existingComponentToUpdate = new TableListRowComp (*this);
  40903. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40904. return existingComponentToUpdate;
  40905. }
  40906. void TableListBox::selectedRowsChanged (int row)
  40907. {
  40908. if (model != 0)
  40909. model->selectedRowsChanged (row);
  40910. }
  40911. void TableListBox::deleteKeyPressed (int row)
  40912. {
  40913. if (model != 0)
  40914. model->deleteKeyPressed (row);
  40915. }
  40916. void TableListBox::returnKeyPressed (int row)
  40917. {
  40918. if (model != 0)
  40919. model->returnKeyPressed (row);
  40920. }
  40921. void TableListBox::backgroundClicked()
  40922. {
  40923. if (model != 0)
  40924. model->backgroundClicked();
  40925. }
  40926. void TableListBox::listWasScrolled()
  40927. {
  40928. if (model != 0)
  40929. model->listWasScrolled();
  40930. }
  40931. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  40932. {
  40933. setMinimumContentWidth (header->getTotalWidth());
  40934. repaint();
  40935. updateColumnComponents();
  40936. }
  40937. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  40938. {
  40939. setMinimumContentWidth (header->getTotalWidth());
  40940. repaint();
  40941. updateColumnComponents();
  40942. }
  40943. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  40944. {
  40945. if (model != 0)
  40946. model->sortOrderChanged (header->getSortColumnId(),
  40947. header->isSortedForwards());
  40948. }
  40949. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  40950. {
  40951. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  40952. repaint();
  40953. }
  40954. void TableListBox::resized()
  40955. {
  40956. ListBox::resized();
  40957. header->resizeAllColumnsToFit (getVisibleContentWidth());
  40958. setMinimumContentWidth (header->getTotalWidth());
  40959. }
  40960. void TableListBox::updateColumnComponents() const
  40961. {
  40962. const int firstRow = getRowContainingPosition (0, 0);
  40963. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  40964. {
  40965. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  40966. if (rowComp != 0)
  40967. rowComp->resized();
  40968. }
  40969. }
  40970. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  40971. {
  40972. }
  40973. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  40974. {
  40975. }
  40976. void TableListBoxModel::backgroundClicked()
  40977. {
  40978. }
  40979. void TableListBoxModel::sortOrderChanged (int, const bool)
  40980. {
  40981. }
  40982. int TableListBoxModel::getColumnAutoSizeWidth (int)
  40983. {
  40984. return 0;
  40985. }
  40986. void TableListBoxModel::selectedRowsChanged (int)
  40987. {
  40988. }
  40989. void TableListBoxModel::deleteKeyPressed (int)
  40990. {
  40991. }
  40992. void TableListBoxModel::returnKeyPressed (int)
  40993. {
  40994. }
  40995. void TableListBoxModel::listWasScrolled()
  40996. {
  40997. }
  40998. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  40999. {
  41000. return String::empty;
  41001. }
  41002. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  41003. {
  41004. return String::empty;
  41005. }
  41006. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41007. {
  41008. (void) existingComponentToUpdate;
  41009. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41010. return 0;
  41011. }
  41012. END_JUCE_NAMESPACE
  41013. /*** End of inlined file: juce_TableListBox.cpp ***/
  41014. /*** Start of inlined file: juce_TextEditor.cpp ***/
  41015. BEGIN_JUCE_NAMESPACE
  41016. // a word or space that can't be broken down any further
  41017. struct TextAtom
  41018. {
  41019. String atomText;
  41020. float width;
  41021. uint16 numChars;
  41022. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41023. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41024. const String getText (const tchar passwordCharacter) const
  41025. {
  41026. if (passwordCharacter == 0)
  41027. return atomText;
  41028. else
  41029. return String::repeatedString (String::charToString (passwordCharacter),
  41030. atomText.length());
  41031. }
  41032. const String getTrimmedText (const tchar passwordCharacter) const
  41033. {
  41034. if (passwordCharacter == 0)
  41035. return atomText.substring (0, numChars);
  41036. else if (isNewLine())
  41037. return String::empty;
  41038. else
  41039. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41040. }
  41041. };
  41042. // a run of text with a single font and colour
  41043. class UniformTextSection
  41044. {
  41045. public:
  41046. UniformTextSection (const String& text,
  41047. const Font& font_,
  41048. const Colour& colour_,
  41049. const tchar passwordCharacter)
  41050. : font (font_),
  41051. colour (colour_)
  41052. {
  41053. initialiseAtoms (text, passwordCharacter);
  41054. }
  41055. UniformTextSection (const UniformTextSection& other)
  41056. : font (other.font),
  41057. colour (other.colour)
  41058. {
  41059. atoms.ensureStorageAllocated (other.atoms.size());
  41060. for (int i = 0; i < other.atoms.size(); ++i)
  41061. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41062. }
  41063. ~UniformTextSection()
  41064. {
  41065. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41066. }
  41067. void clear()
  41068. {
  41069. for (int i = atoms.size(); --i >= 0;)
  41070. delete getAtom(i);
  41071. atoms.clear();
  41072. }
  41073. int getNumAtoms() const
  41074. {
  41075. return atoms.size();
  41076. }
  41077. TextAtom* getAtom (const int index) const
  41078. {
  41079. return (TextAtom*) atoms.getUnchecked (index);
  41080. }
  41081. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41082. {
  41083. if (other.atoms.size() > 0)
  41084. {
  41085. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41086. int i = 0;
  41087. if (lastAtom != 0)
  41088. {
  41089. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41090. {
  41091. TextAtom* const first = other.getAtom(0);
  41092. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41093. {
  41094. lastAtom->atomText += first->atomText;
  41095. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41096. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41097. delete first;
  41098. ++i;
  41099. }
  41100. }
  41101. }
  41102. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41103. while (i < other.atoms.size())
  41104. {
  41105. atoms.add (other.getAtom(i));
  41106. ++i;
  41107. }
  41108. }
  41109. }
  41110. UniformTextSection* split (const int indexToBreakAt,
  41111. const tchar passwordCharacter)
  41112. {
  41113. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41114. font, colour,
  41115. passwordCharacter);
  41116. int index = 0;
  41117. for (int i = 0; i < atoms.size(); ++i)
  41118. {
  41119. TextAtom* const atom = getAtom(i);
  41120. const int nextIndex = index + atom->numChars;
  41121. if (index == indexToBreakAt)
  41122. {
  41123. int j;
  41124. for (j = i; j < atoms.size(); ++j)
  41125. section2->atoms.add (getAtom (j));
  41126. for (j = atoms.size(); --j >= i;)
  41127. atoms.remove (j);
  41128. break;
  41129. }
  41130. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41131. {
  41132. TextAtom* const secondAtom = new TextAtom();
  41133. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41134. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41135. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41136. section2->atoms.add (secondAtom);
  41137. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41138. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41139. atom->numChars = (uint16) (indexToBreakAt - index);
  41140. int j;
  41141. for (j = i + 1; j < atoms.size(); ++j)
  41142. section2->atoms.add (getAtom (j));
  41143. for (j = atoms.size(); --j > i;)
  41144. atoms.remove (j);
  41145. break;
  41146. }
  41147. index = nextIndex;
  41148. }
  41149. return section2;
  41150. }
  41151. void appendAllText (String::Concatenator& concatenator) const
  41152. {
  41153. for (int i = 0; i < atoms.size(); ++i)
  41154. concatenator.append (getAtom(i)->atomText);
  41155. }
  41156. void appendSubstring (String::Concatenator& concatenator,
  41157. const Range<int>& range) const
  41158. {
  41159. int index = 0;
  41160. for (int i = 0; i < atoms.size(); ++i)
  41161. {
  41162. const TextAtom* const atom = getAtom (i);
  41163. const int nextIndex = index + atom->numChars;
  41164. if (range.getStart() < nextIndex)
  41165. {
  41166. if (range.getEnd() <= index)
  41167. break;
  41168. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41169. if (! r.isEmpty())
  41170. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41171. }
  41172. index = nextIndex;
  41173. }
  41174. }
  41175. int getTotalLength() const
  41176. {
  41177. int total = 0;
  41178. for (int i = atoms.size(); --i >= 0;)
  41179. total += getAtom(i)->numChars;
  41180. return total;
  41181. }
  41182. void setFont (const Font& newFont,
  41183. const tchar passwordCharacter)
  41184. {
  41185. if (font != newFont)
  41186. {
  41187. font = newFont;
  41188. for (int i = atoms.size(); --i >= 0;)
  41189. {
  41190. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41191. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41192. }
  41193. }
  41194. }
  41195. juce_UseDebuggingNewOperator
  41196. Font font;
  41197. Colour colour;
  41198. private:
  41199. VoidArray atoms;
  41200. void initialiseAtoms (const String& textToParse,
  41201. const tchar passwordCharacter)
  41202. {
  41203. int i = 0;
  41204. const int len = textToParse.length();
  41205. const tchar* const text = (const tchar*) textToParse;
  41206. while (i < len)
  41207. {
  41208. int start = i;
  41209. // create a whitespace atom unless it starts with non-ws
  41210. if (CharacterFunctions::isWhitespace (text[i])
  41211. && text[i] != T('\r')
  41212. && text[i] != T('\n'))
  41213. {
  41214. while (i < len
  41215. && CharacterFunctions::isWhitespace (text[i])
  41216. && text[i] != T('\r')
  41217. && text[i] != T('\n'))
  41218. {
  41219. ++i;
  41220. }
  41221. }
  41222. else
  41223. {
  41224. if (text[i] == T('\r'))
  41225. {
  41226. ++i;
  41227. if ((i < len) && (text[i] == T('\n')))
  41228. {
  41229. ++start;
  41230. ++i;
  41231. }
  41232. }
  41233. else if (text[i] == T('\n'))
  41234. {
  41235. ++i;
  41236. }
  41237. else
  41238. {
  41239. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41240. ++i;
  41241. }
  41242. }
  41243. TextAtom* const atom = new TextAtom();
  41244. atom->atomText = String (text + start, i - start);
  41245. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41246. atom->numChars = (uint16) (i - start);
  41247. atoms.add (atom);
  41248. }
  41249. }
  41250. UniformTextSection& operator= (const UniformTextSection& other);
  41251. };
  41252. class TextEditorIterator
  41253. {
  41254. public:
  41255. TextEditorIterator (const VoidArray& sections_,
  41256. const float wordWrapWidth_,
  41257. const tchar passwordCharacter_)
  41258. : indexInText (0),
  41259. lineY (0),
  41260. lineHeight (0),
  41261. maxDescent (0),
  41262. atomX (0),
  41263. atomRight (0),
  41264. atom (0),
  41265. currentSection (0),
  41266. sections (sections_),
  41267. sectionIndex (0),
  41268. atomIndex (0),
  41269. wordWrapWidth (wordWrapWidth_),
  41270. passwordCharacter (passwordCharacter_)
  41271. {
  41272. jassert (wordWrapWidth_ > 0);
  41273. if (sections.size() > 0)
  41274. {
  41275. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41276. if (currentSection != 0)
  41277. beginNewLine();
  41278. }
  41279. }
  41280. TextEditorIterator (const TextEditorIterator& other)
  41281. : indexInText (other.indexInText),
  41282. lineY (other.lineY),
  41283. lineHeight (other.lineHeight),
  41284. maxDescent (other.maxDescent),
  41285. atomX (other.atomX),
  41286. atomRight (other.atomRight),
  41287. atom (other.atom),
  41288. currentSection (other.currentSection),
  41289. sections (other.sections),
  41290. sectionIndex (other.sectionIndex),
  41291. atomIndex (other.atomIndex),
  41292. wordWrapWidth (other.wordWrapWidth),
  41293. passwordCharacter (other.passwordCharacter),
  41294. tempAtom (other.tempAtom)
  41295. {
  41296. }
  41297. ~TextEditorIterator()
  41298. {
  41299. }
  41300. bool next()
  41301. {
  41302. if (atom == &tempAtom)
  41303. {
  41304. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41305. if (numRemaining > 0)
  41306. {
  41307. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41308. atomX = 0;
  41309. if (tempAtom.numChars > 0)
  41310. lineY += lineHeight;
  41311. indexInText += tempAtom.numChars;
  41312. GlyphArrangement g;
  41313. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41314. int split;
  41315. for (split = 0; split < g.getNumGlyphs(); ++split)
  41316. if (shouldWrap (g.getGlyph (split).getRight()))
  41317. break;
  41318. if (split > 0 && split <= numRemaining)
  41319. {
  41320. tempAtom.numChars = (uint16) split;
  41321. tempAtom.width = g.getGlyph (split - 1).getRight();
  41322. atomRight = atomX + tempAtom.width;
  41323. return true;
  41324. }
  41325. }
  41326. }
  41327. bool forceNewLine = false;
  41328. if (sectionIndex >= sections.size())
  41329. {
  41330. moveToEndOfLastAtom();
  41331. return false;
  41332. }
  41333. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41334. {
  41335. if (atomIndex >= currentSection->getNumAtoms())
  41336. {
  41337. if (++sectionIndex >= sections.size())
  41338. {
  41339. moveToEndOfLastAtom();
  41340. return false;
  41341. }
  41342. atomIndex = 0;
  41343. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41344. }
  41345. else
  41346. {
  41347. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41348. if (! lastAtom->isWhitespace())
  41349. {
  41350. // handle the case where the last atom in a section is actually part of the same
  41351. // word as the first atom of the next section...
  41352. float right = atomRight + lastAtom->width;
  41353. float lineHeight2 = lineHeight;
  41354. float maxDescent2 = maxDescent;
  41355. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41356. {
  41357. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41358. if (s->getNumAtoms() == 0)
  41359. break;
  41360. const TextAtom* const nextAtom = s->getAtom (0);
  41361. if (nextAtom->isWhitespace())
  41362. break;
  41363. right += nextAtom->width;
  41364. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41365. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41366. if (shouldWrap (right))
  41367. {
  41368. lineHeight = lineHeight2;
  41369. maxDescent = maxDescent2;
  41370. forceNewLine = true;
  41371. break;
  41372. }
  41373. if (s->getNumAtoms() > 1)
  41374. break;
  41375. }
  41376. }
  41377. }
  41378. }
  41379. if (atom != 0)
  41380. {
  41381. atomX = atomRight;
  41382. indexInText += atom->numChars;
  41383. if (atom->isNewLine())
  41384. beginNewLine();
  41385. }
  41386. atom = currentSection->getAtom (atomIndex);
  41387. atomRight = atomX + atom->width;
  41388. ++atomIndex;
  41389. if (shouldWrap (atomRight) || forceNewLine)
  41390. {
  41391. if (atom->isWhitespace())
  41392. {
  41393. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41394. atomRight = jmin (atomRight, wordWrapWidth);
  41395. }
  41396. else
  41397. {
  41398. atomRight = atom->width;
  41399. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41400. {
  41401. tempAtom = *atom;
  41402. tempAtom.width = 0;
  41403. tempAtom.numChars = 0;
  41404. atom = &tempAtom;
  41405. if (atomX > 0)
  41406. beginNewLine();
  41407. return next();
  41408. }
  41409. beginNewLine();
  41410. return true;
  41411. }
  41412. }
  41413. return true;
  41414. }
  41415. void beginNewLine()
  41416. {
  41417. atomX = 0;
  41418. lineY += lineHeight;
  41419. int tempSectionIndex = sectionIndex;
  41420. int tempAtomIndex = atomIndex;
  41421. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41422. lineHeight = section->font.getHeight();
  41423. maxDescent = section->font.getDescent();
  41424. float x = (atom != 0) ? atom->width : 0;
  41425. while (! shouldWrap (x))
  41426. {
  41427. if (tempSectionIndex >= sections.size())
  41428. break;
  41429. bool checkSize = false;
  41430. if (tempAtomIndex >= section->getNumAtoms())
  41431. {
  41432. if (++tempSectionIndex >= sections.size())
  41433. break;
  41434. tempAtomIndex = 0;
  41435. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41436. checkSize = true;
  41437. }
  41438. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41439. if (nextAtom == 0)
  41440. break;
  41441. x += nextAtom->width;
  41442. if (shouldWrap (x) || nextAtom->isNewLine())
  41443. break;
  41444. if (checkSize)
  41445. {
  41446. lineHeight = jmax (lineHeight, section->font.getHeight());
  41447. maxDescent = jmax (maxDescent, section->font.getDescent());
  41448. }
  41449. ++tempAtomIndex;
  41450. }
  41451. }
  41452. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41453. {
  41454. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41455. {
  41456. if (lastSection != currentSection)
  41457. {
  41458. lastSection = currentSection;
  41459. g.setColour (currentSection->colour);
  41460. g.setFont (currentSection->font);
  41461. }
  41462. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41463. GlyphArrangement ga;
  41464. ga.addLineOfText (currentSection->font,
  41465. atom->getTrimmedText (passwordCharacter),
  41466. atomX,
  41467. (float) roundToInt (lineY + lineHeight - maxDescent));
  41468. ga.draw (g);
  41469. }
  41470. }
  41471. void drawSelection (Graphics& g,
  41472. const Range<int>& selection) const
  41473. {
  41474. const int startX = roundToInt (indexToX (selection.getStart()));
  41475. const int endX = roundToInt (indexToX (selection.getEnd()));
  41476. const int y = roundToInt (lineY);
  41477. const int nextY = roundToInt (lineY + lineHeight);
  41478. g.fillRect (startX, y, endX - startX, nextY - y);
  41479. }
  41480. void drawSelectedText (Graphics& g,
  41481. const Range<int>& selection,
  41482. const Colour& selectedTextColour) const
  41483. {
  41484. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41485. {
  41486. GlyphArrangement ga;
  41487. ga.addLineOfText (currentSection->font,
  41488. atom->getTrimmedText (passwordCharacter),
  41489. atomX,
  41490. (float) roundToInt (lineY + lineHeight - maxDescent));
  41491. if (selection.getEnd() < indexInText + atom->numChars)
  41492. {
  41493. GlyphArrangement ga2 (ga);
  41494. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41495. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41496. g.setColour (currentSection->colour);
  41497. ga2.draw (g);
  41498. }
  41499. if (selection.getStart() > indexInText)
  41500. {
  41501. GlyphArrangement ga2 (ga);
  41502. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41503. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41504. g.setColour (currentSection->colour);
  41505. ga2.draw (g);
  41506. }
  41507. g.setColour (selectedTextColour);
  41508. ga.draw (g);
  41509. }
  41510. }
  41511. float indexToX (const int indexToFind) const
  41512. {
  41513. if (indexToFind <= indexInText)
  41514. return atomX;
  41515. if (indexToFind >= indexInText + atom->numChars)
  41516. return atomRight;
  41517. GlyphArrangement g;
  41518. g.addLineOfText (currentSection->font,
  41519. atom->getText (passwordCharacter),
  41520. atomX, 0.0f);
  41521. if (indexToFind - indexInText >= g.getNumGlyphs())
  41522. return atomRight;
  41523. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41524. }
  41525. int xToIndex (const float xToFind) const
  41526. {
  41527. if (xToFind <= atomX || atom->isNewLine())
  41528. return indexInText;
  41529. if (xToFind >= atomRight)
  41530. return indexInText + atom->numChars;
  41531. GlyphArrangement g;
  41532. g.addLineOfText (currentSection->font,
  41533. atom->getText (passwordCharacter),
  41534. atomX, 0.0f);
  41535. int j;
  41536. for (j = 0; j < g.getNumGlyphs(); ++j)
  41537. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41538. break;
  41539. return indexInText + j;
  41540. }
  41541. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41542. {
  41543. while (next())
  41544. {
  41545. if (indexInText + atom->numChars > index)
  41546. {
  41547. cx = indexToX (index);
  41548. cy = lineY;
  41549. lineHeight_ = lineHeight;
  41550. return true;
  41551. }
  41552. }
  41553. cx = atomX;
  41554. cy = lineY;
  41555. lineHeight_ = lineHeight;
  41556. return false;
  41557. }
  41558. juce_UseDebuggingNewOperator
  41559. int indexInText;
  41560. float lineY, lineHeight, maxDescent;
  41561. float atomX, atomRight;
  41562. const TextAtom* atom;
  41563. const UniformTextSection* currentSection;
  41564. private:
  41565. const VoidArray& sections;
  41566. int sectionIndex, atomIndex;
  41567. const float wordWrapWidth;
  41568. const tchar passwordCharacter;
  41569. TextAtom tempAtom;
  41570. TextEditorIterator& operator= (const TextEditorIterator&);
  41571. void moveToEndOfLastAtom()
  41572. {
  41573. if (atom != 0)
  41574. {
  41575. atomX = atomRight;
  41576. if (atom->isNewLine())
  41577. {
  41578. atomX = 0.0f;
  41579. lineY += lineHeight;
  41580. }
  41581. }
  41582. }
  41583. bool shouldWrap (const float x) const
  41584. {
  41585. return (x - 0.0001f) >= wordWrapWidth;
  41586. }
  41587. };
  41588. class TextEditorInsertAction : public UndoableAction
  41589. {
  41590. TextEditor& owner;
  41591. const String text;
  41592. const int insertIndex, oldCaretPos, newCaretPos;
  41593. const Font font;
  41594. const Colour colour;
  41595. TextEditorInsertAction (const TextEditorInsertAction&);
  41596. TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  41597. public:
  41598. TextEditorInsertAction (TextEditor& owner_,
  41599. const String& text_,
  41600. const int insertIndex_,
  41601. const Font& font_,
  41602. const Colour& colour_,
  41603. const int oldCaretPos_,
  41604. const int newCaretPos_)
  41605. : owner (owner_),
  41606. text (text_),
  41607. insertIndex (insertIndex_),
  41608. oldCaretPos (oldCaretPos_),
  41609. newCaretPos (newCaretPos_),
  41610. font (font_),
  41611. colour (colour_)
  41612. {
  41613. }
  41614. ~TextEditorInsertAction()
  41615. {
  41616. }
  41617. bool perform()
  41618. {
  41619. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41620. return true;
  41621. }
  41622. bool undo()
  41623. {
  41624. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41625. return true;
  41626. }
  41627. int getSizeInUnits()
  41628. {
  41629. return text.length() + 16;
  41630. }
  41631. };
  41632. class TextEditorRemoveAction : public UndoableAction
  41633. {
  41634. TextEditor& owner;
  41635. const Range<int> range;
  41636. const int oldCaretPos, newCaretPos;
  41637. VoidArray removedSections;
  41638. TextEditorRemoveAction (const TextEditorRemoveAction&);
  41639. TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  41640. public:
  41641. TextEditorRemoveAction (TextEditor& owner_,
  41642. const Range<int> range_,
  41643. const int oldCaretPos_,
  41644. const int newCaretPos_,
  41645. const VoidArray& removedSections_)
  41646. : owner (owner_),
  41647. range (range_),
  41648. oldCaretPos (oldCaretPos_),
  41649. newCaretPos (newCaretPos_),
  41650. removedSections (removedSections_)
  41651. {
  41652. }
  41653. ~TextEditorRemoveAction()
  41654. {
  41655. for (int i = removedSections.size(); --i >= 0;)
  41656. {
  41657. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41658. section->clear();
  41659. delete section;
  41660. }
  41661. }
  41662. bool perform()
  41663. {
  41664. owner.remove (range, 0, newCaretPos);
  41665. return true;
  41666. }
  41667. bool undo()
  41668. {
  41669. owner.reinsert (range.getStart(), removedSections);
  41670. owner.moveCursorTo (oldCaretPos, false);
  41671. return true;
  41672. }
  41673. int getSizeInUnits()
  41674. {
  41675. int n = 0;
  41676. for (int i = removedSections.size(); --i >= 0;)
  41677. {
  41678. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41679. n += section->getTotalLength();
  41680. }
  41681. return n + 16;
  41682. }
  41683. };
  41684. class TextHolderComponent : public Component,
  41685. public Timer,
  41686. public Value::Listener
  41687. {
  41688. TextEditor& owner;
  41689. TextHolderComponent (const TextHolderComponent&);
  41690. TextHolderComponent& operator= (const TextHolderComponent&);
  41691. public:
  41692. TextHolderComponent (TextEditor& owner_)
  41693. : owner (owner_)
  41694. {
  41695. setWantsKeyboardFocus (false);
  41696. setInterceptsMouseClicks (false, true);
  41697. owner.getTextValue().addListener (this);
  41698. }
  41699. ~TextHolderComponent()
  41700. {
  41701. owner.getTextValue().removeListener (this);
  41702. }
  41703. void paint (Graphics& g)
  41704. {
  41705. owner.drawContent (g);
  41706. }
  41707. void timerCallback()
  41708. {
  41709. owner.timerCallbackInt();
  41710. }
  41711. const MouseCursor getMouseCursor()
  41712. {
  41713. return owner.getMouseCursor();
  41714. }
  41715. void valueChanged (Value&)
  41716. {
  41717. owner.textWasChangedByValue();
  41718. }
  41719. };
  41720. class TextEditorViewport : public Viewport
  41721. {
  41722. TextEditor* const owner;
  41723. float lastWordWrapWidth;
  41724. TextEditorViewport (const TextEditorViewport&);
  41725. TextEditorViewport& operator= (const TextEditorViewport&);
  41726. public:
  41727. TextEditorViewport (TextEditor* const owner_)
  41728. : owner (owner_),
  41729. lastWordWrapWidth (0)
  41730. {
  41731. }
  41732. ~TextEditorViewport()
  41733. {
  41734. }
  41735. void visibleAreaChanged (int, int, int, int)
  41736. {
  41737. const float wordWrapWidth = owner->getWordWrapWidth();
  41738. if (wordWrapWidth != lastWordWrapWidth)
  41739. {
  41740. lastWordWrapWidth = wordWrapWidth;
  41741. owner->updateTextHolderSize();
  41742. }
  41743. }
  41744. };
  41745. namespace TextEditorDefs
  41746. {
  41747. const int flashSpeedIntervalMs = 380;
  41748. const int textChangeMessageId = 0x10003001;
  41749. const int returnKeyMessageId = 0x10003002;
  41750. const int escapeKeyMessageId = 0x10003003;
  41751. const int focusLossMessageId = 0x10003004;
  41752. const int maxActionsPerTransaction = 100;
  41753. }
  41754. TextEditor::TextEditor (const String& name,
  41755. const tchar passwordCharacter_)
  41756. : Component (name),
  41757. borderSize (1, 1, 1, 3),
  41758. readOnly (false),
  41759. multiline (false),
  41760. wordWrap (false),
  41761. returnKeyStartsNewLine (false),
  41762. caretVisible (true),
  41763. popupMenuEnabled (true),
  41764. selectAllTextWhenFocused (false),
  41765. scrollbarVisible (true),
  41766. wasFocused (false),
  41767. caretFlashState (true),
  41768. keepCursorOnScreen (true),
  41769. tabKeyUsed (false),
  41770. menuActive (false),
  41771. valueTextNeedsUpdating (false),
  41772. cursorX (0),
  41773. cursorY (0),
  41774. cursorHeight (0),
  41775. maxTextLength (0),
  41776. leftIndent (4),
  41777. topIndent (4),
  41778. lastTransactionTime (0),
  41779. currentFont (14.0f),
  41780. totalNumChars (0),
  41781. caretPosition (0),
  41782. passwordCharacter (passwordCharacter_),
  41783. dragType (notDragging)
  41784. {
  41785. setOpaque (true);
  41786. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41787. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41788. viewport->setWantsKeyboardFocus (false);
  41789. viewport->setScrollBarsShown (false, false);
  41790. setMouseCursor (MouseCursor::IBeamCursor);
  41791. setWantsKeyboardFocus (true);
  41792. }
  41793. TextEditor::~TextEditor()
  41794. {
  41795. textValue.referTo (Value());
  41796. clearInternal (0);
  41797. viewport = 0;
  41798. textHolder = 0;
  41799. }
  41800. void TextEditor::newTransaction()
  41801. {
  41802. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41803. undoManager.beginNewTransaction();
  41804. }
  41805. void TextEditor::doUndoRedo (const bool isRedo)
  41806. {
  41807. if (! isReadOnly())
  41808. {
  41809. if (isRedo ? undoManager.redo()
  41810. : undoManager.undo())
  41811. {
  41812. scrollToMakeSureCursorIsVisible();
  41813. repaint();
  41814. textChanged();
  41815. }
  41816. }
  41817. }
  41818. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41819. const bool shouldWordWrap)
  41820. {
  41821. multiline = shouldBeMultiLine;
  41822. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41823. setScrollbarsShown (scrollbarVisible);
  41824. viewport->setViewPosition (0, 0);
  41825. resized();
  41826. scrollToMakeSureCursorIsVisible();
  41827. }
  41828. bool TextEditor::isMultiLine() const
  41829. {
  41830. return multiline;
  41831. }
  41832. void TextEditor::setScrollbarsShown (bool enabled)
  41833. {
  41834. scrollbarVisible = enabled;
  41835. enabled = enabled && isMultiLine();
  41836. viewport->setScrollBarsShown (enabled, enabled);
  41837. }
  41838. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41839. {
  41840. readOnly = shouldBeReadOnly;
  41841. enablementChanged();
  41842. }
  41843. bool TextEditor::isReadOnly() const
  41844. {
  41845. return readOnly || ! isEnabled();
  41846. }
  41847. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41848. {
  41849. returnKeyStartsNewLine = shouldStartNewLine;
  41850. }
  41851. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41852. {
  41853. tabKeyUsed = shouldTabKeyBeUsed;
  41854. }
  41855. void TextEditor::setPopupMenuEnabled (const bool b)
  41856. {
  41857. popupMenuEnabled = b;
  41858. }
  41859. void TextEditor::setSelectAllWhenFocused (const bool b)
  41860. {
  41861. selectAllTextWhenFocused = b;
  41862. }
  41863. const Font TextEditor::getFont() const
  41864. {
  41865. return currentFont;
  41866. }
  41867. void TextEditor::setFont (const Font& newFont)
  41868. {
  41869. currentFont = newFont;
  41870. scrollToMakeSureCursorIsVisible();
  41871. }
  41872. void TextEditor::applyFontToAllText (const Font& newFont)
  41873. {
  41874. currentFont = newFont;
  41875. const Colour overallColour (findColour (textColourId));
  41876. for (int i = sections.size(); --i >= 0;)
  41877. {
  41878. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  41879. uts->setFont (newFont, passwordCharacter);
  41880. uts->colour = overallColour;
  41881. }
  41882. coalesceSimilarSections();
  41883. updateTextHolderSize();
  41884. scrollToMakeSureCursorIsVisible();
  41885. repaint();
  41886. }
  41887. void TextEditor::colourChanged()
  41888. {
  41889. setOpaque (findColour (backgroundColourId).isOpaque());
  41890. repaint();
  41891. }
  41892. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41893. {
  41894. caretVisible = shouldCaretBeVisible;
  41895. if (shouldCaretBeVisible)
  41896. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41897. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41898. : MouseCursor::NormalCursor);
  41899. }
  41900. void TextEditor::setInputRestrictions (const int maxLen,
  41901. const String& chars)
  41902. {
  41903. maxTextLength = jmax (0, maxLen);
  41904. allowedCharacters = chars;
  41905. }
  41906. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41907. {
  41908. textToShowWhenEmpty = text;
  41909. colourForTextWhenEmpty = colourToUse;
  41910. }
  41911. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  41912. {
  41913. if (passwordCharacter != newPasswordCharacter)
  41914. {
  41915. passwordCharacter = newPasswordCharacter;
  41916. resized();
  41917. repaint();
  41918. }
  41919. }
  41920. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  41921. {
  41922. viewport->setScrollBarThickness (newThicknessPixels);
  41923. }
  41924. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  41925. {
  41926. viewport->setScrollBarButtonVisibility (buttonsVisible);
  41927. }
  41928. void TextEditor::clear()
  41929. {
  41930. clearInternal (0);
  41931. updateTextHolderSize();
  41932. undoManager.clearUndoHistory();
  41933. }
  41934. void TextEditor::setText (const String& newText,
  41935. const bool sendTextChangeMessage)
  41936. {
  41937. const int newLength = newText.length();
  41938. if (newLength != getTotalNumChars() || getText() != newText)
  41939. {
  41940. const int oldCursorPos = caretPosition;
  41941. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  41942. clearInternal (0);
  41943. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  41944. // if you're adding text with line-feeds to a single-line text editor, it
  41945. // ain't gonna look right!
  41946. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  41947. if (cursorWasAtEnd && ! isMultiLine())
  41948. moveCursorTo (getTotalNumChars(), false);
  41949. else
  41950. moveCursorTo (oldCursorPos, false);
  41951. if (sendTextChangeMessage)
  41952. textChanged();
  41953. repaint();
  41954. }
  41955. updateTextHolderSize();
  41956. scrollToMakeSureCursorIsVisible();
  41957. undoManager.clearUndoHistory();
  41958. }
  41959. Value& TextEditor::getTextValue()
  41960. {
  41961. if (valueTextNeedsUpdating)
  41962. {
  41963. valueTextNeedsUpdating = false;
  41964. textValue = getText();
  41965. }
  41966. return textValue;
  41967. }
  41968. void TextEditor::textWasChangedByValue()
  41969. {
  41970. if (textValue.getValueSource().getReferenceCount() > 1)
  41971. setText (textValue.getValue());
  41972. }
  41973. void TextEditor::textChanged()
  41974. {
  41975. updateTextHolderSize();
  41976. postCommandMessage (TextEditorDefs::textChangeMessageId);
  41977. if (textValue.getValueSource().getReferenceCount() > 1)
  41978. {
  41979. valueTextNeedsUpdating = false;
  41980. textValue = getText();
  41981. }
  41982. }
  41983. void TextEditor::returnPressed()
  41984. {
  41985. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  41986. }
  41987. void TextEditor::escapePressed()
  41988. {
  41989. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  41990. }
  41991. void TextEditor::addListener (TextEditorListener* const newListener)
  41992. {
  41993. listeners.add (newListener);
  41994. }
  41995. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  41996. {
  41997. listeners.remove (listenerToRemove);
  41998. }
  41999. void TextEditor::timerCallbackInt()
  42000. {
  42001. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  42002. if (caretFlashState != newState)
  42003. {
  42004. caretFlashState = newState;
  42005. if (caretFlashState)
  42006. wasFocused = true;
  42007. if (caretVisible
  42008. && hasKeyboardFocus (false)
  42009. && ! isReadOnly())
  42010. {
  42011. repaintCaret();
  42012. }
  42013. }
  42014. const unsigned int now = Time::getApproximateMillisecondCounter();
  42015. if (now > lastTransactionTime + 200)
  42016. newTransaction();
  42017. }
  42018. void TextEditor::repaintCaret()
  42019. {
  42020. if (! findColour (caretColourId).isTransparent())
  42021. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42022. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42023. 4,
  42024. roundToInt (cursorHeight) + 2);
  42025. }
  42026. void TextEditor::repaintText (const Range<int>& range)
  42027. {
  42028. if (! range.isEmpty())
  42029. {
  42030. float x = 0, y = 0, lh = currentFont.getHeight();
  42031. const float wordWrapWidth = getWordWrapWidth();
  42032. if (wordWrapWidth > 0)
  42033. {
  42034. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42035. i.getCharPosition (range.getStart(), x, y, lh);
  42036. const int y1 = (int) y;
  42037. int y2;
  42038. if (range.getEnd() >= getTotalNumChars())
  42039. {
  42040. y2 = textHolder->getHeight();
  42041. }
  42042. else
  42043. {
  42044. i.getCharPosition (range.getEnd(), x, y, lh);
  42045. y2 = (int) (y + lh * 2.0f);
  42046. }
  42047. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42048. }
  42049. }
  42050. }
  42051. void TextEditor::moveCaret (int newCaretPos)
  42052. {
  42053. if (newCaretPos < 0)
  42054. newCaretPos = 0;
  42055. else if (newCaretPos > getTotalNumChars())
  42056. newCaretPos = getTotalNumChars();
  42057. if (newCaretPos != getCaretPosition())
  42058. {
  42059. repaintCaret();
  42060. caretFlashState = true;
  42061. caretPosition = newCaretPos;
  42062. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42063. scrollToMakeSureCursorIsVisible();
  42064. repaintCaret();
  42065. }
  42066. }
  42067. void TextEditor::setCaretPosition (const int newIndex)
  42068. {
  42069. moveCursorTo (newIndex, false);
  42070. }
  42071. int TextEditor::getCaretPosition() const
  42072. {
  42073. return caretPosition;
  42074. }
  42075. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42076. const int desiredCaretY)
  42077. {
  42078. updateCaretPosition();
  42079. int vx = roundToInt (cursorX) - desiredCaretX;
  42080. int vy = roundToInt (cursorY) - desiredCaretY;
  42081. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42082. {
  42083. vx += desiredCaretX - proportionOfWidth (0.2f);
  42084. }
  42085. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42086. {
  42087. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42088. }
  42089. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42090. if (! isMultiLine())
  42091. {
  42092. vy = viewport->getViewPositionY();
  42093. }
  42094. else
  42095. {
  42096. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42097. const int curH = roundToInt (cursorHeight);
  42098. if (desiredCaretY < 0)
  42099. {
  42100. vy = jmax (0, desiredCaretY + vy);
  42101. }
  42102. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42103. {
  42104. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42105. }
  42106. }
  42107. viewport->setViewPosition (vx, vy);
  42108. }
  42109. const Rectangle<int> TextEditor::getCaretRectangle()
  42110. {
  42111. updateCaretPosition();
  42112. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42113. roundToInt (cursorY) - viewport->getY(),
  42114. 1, roundToInt (cursorHeight));
  42115. }
  42116. float TextEditor::getWordWrapWidth() const
  42117. {
  42118. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42119. : 1.0e10f;
  42120. }
  42121. void TextEditor::updateTextHolderSize()
  42122. {
  42123. const float wordWrapWidth = getWordWrapWidth();
  42124. if (wordWrapWidth > 0)
  42125. {
  42126. float maxWidth = 0.0f;
  42127. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42128. while (i.next())
  42129. maxWidth = jmax (maxWidth, i.atomRight);
  42130. const int w = leftIndent + roundToInt (maxWidth);
  42131. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42132. currentFont.getHeight()));
  42133. textHolder->setSize (w + 1, h + 1);
  42134. }
  42135. }
  42136. int TextEditor::getTextWidth() const
  42137. {
  42138. return textHolder->getWidth();
  42139. }
  42140. int TextEditor::getTextHeight() const
  42141. {
  42142. return textHolder->getHeight();
  42143. }
  42144. void TextEditor::setIndents (const int newLeftIndent,
  42145. const int newTopIndent)
  42146. {
  42147. leftIndent = newLeftIndent;
  42148. topIndent = newTopIndent;
  42149. }
  42150. void TextEditor::setBorder (const BorderSize& border)
  42151. {
  42152. borderSize = border;
  42153. resized();
  42154. }
  42155. const BorderSize TextEditor::getBorder() const
  42156. {
  42157. return borderSize;
  42158. }
  42159. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42160. {
  42161. keepCursorOnScreen = shouldScrollToShowCursor;
  42162. }
  42163. void TextEditor::updateCaretPosition()
  42164. {
  42165. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42166. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42167. }
  42168. void TextEditor::scrollToMakeSureCursorIsVisible()
  42169. {
  42170. updateCaretPosition();
  42171. if (keepCursorOnScreen)
  42172. {
  42173. int x = viewport->getViewPositionX();
  42174. int y = viewport->getViewPositionY();
  42175. const int relativeCursorX = roundToInt (cursorX) - x;
  42176. const int relativeCursorY = roundToInt (cursorY) - y;
  42177. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42178. {
  42179. x += relativeCursorX - proportionOfWidth (0.2f);
  42180. }
  42181. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42182. {
  42183. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42184. }
  42185. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42186. if (! isMultiLine())
  42187. {
  42188. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42189. }
  42190. else
  42191. {
  42192. const int curH = roundToInt (cursorHeight);
  42193. if (relativeCursorY < 0)
  42194. {
  42195. y = jmax (0, relativeCursorY + y);
  42196. }
  42197. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42198. {
  42199. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42200. }
  42201. }
  42202. viewport->setViewPosition (x, y);
  42203. }
  42204. }
  42205. void TextEditor::moveCursorTo (const int newPosition,
  42206. const bool isSelecting)
  42207. {
  42208. if (isSelecting)
  42209. {
  42210. moveCaret (newPosition);
  42211. const Range<int> oldSelection (selection);
  42212. if (dragType == notDragging)
  42213. {
  42214. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42215. dragType = draggingSelectionStart;
  42216. else
  42217. dragType = draggingSelectionEnd;
  42218. }
  42219. if (dragType == draggingSelectionStart)
  42220. {
  42221. if (getCaretPosition() >= selection.getEnd())
  42222. dragType = draggingSelectionEnd;
  42223. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42224. }
  42225. else
  42226. {
  42227. if (getCaretPosition() < selection.getStart())
  42228. dragType = draggingSelectionStart;
  42229. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42230. }
  42231. repaintText (selection.getUnionWith (oldSelection));
  42232. }
  42233. else
  42234. {
  42235. dragType = notDragging;
  42236. repaintText (selection);
  42237. moveCaret (newPosition);
  42238. selection = Range<int>::emptyRange (getCaretPosition());
  42239. }
  42240. }
  42241. int TextEditor::getTextIndexAt (const int x,
  42242. const int y)
  42243. {
  42244. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42245. (float) (y + viewport->getViewPositionY() - topIndent));
  42246. }
  42247. void TextEditor::insertTextAtCaret (const String& newText_)
  42248. {
  42249. String newText (newText_);
  42250. if (allowedCharacters.isNotEmpty())
  42251. newText = newText.retainCharacters (allowedCharacters);
  42252. if (! isMultiLine())
  42253. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42254. else
  42255. newText = newText.replace (T("\r\n"), T("\n"));
  42256. const int newCaretPos = selection.getStart() + newText.length();
  42257. const int insertIndex = selection.getStart();
  42258. remove (selection, getUndoManager(),
  42259. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42260. if (maxTextLength > 0)
  42261. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42262. if (newText.isNotEmpty())
  42263. insert (newText,
  42264. insertIndex,
  42265. currentFont,
  42266. findColour (textColourId),
  42267. getUndoManager(),
  42268. newCaretPos);
  42269. textChanged();
  42270. }
  42271. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42272. {
  42273. moveCursorTo (newSelection.getStart(), false);
  42274. moveCursorTo (newSelection.getEnd(), true);
  42275. }
  42276. void TextEditor::copy()
  42277. {
  42278. if (passwordCharacter == 0)
  42279. {
  42280. const String selection (getHighlightedText());
  42281. if (selection.isNotEmpty())
  42282. SystemClipboard::copyTextToClipboard (selection);
  42283. }
  42284. }
  42285. void TextEditor::paste()
  42286. {
  42287. if (! isReadOnly())
  42288. {
  42289. const String clip (SystemClipboard::getTextFromClipboard());
  42290. if (clip.isNotEmpty())
  42291. insertTextAtCaret (clip);
  42292. }
  42293. }
  42294. void TextEditor::cut()
  42295. {
  42296. if (! isReadOnly())
  42297. {
  42298. moveCaret (selection.getEnd());
  42299. insertTextAtCaret (String::empty);
  42300. }
  42301. }
  42302. void TextEditor::drawContent (Graphics& g)
  42303. {
  42304. const float wordWrapWidth = getWordWrapWidth();
  42305. if (wordWrapWidth > 0)
  42306. {
  42307. g.setOrigin (leftIndent, topIndent);
  42308. const Rectangle<int> clip (g.getClipBounds());
  42309. Colour selectedTextColour;
  42310. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42311. while (i.lineY + 200.0 < clip.getY() && i.next())
  42312. {}
  42313. if (! selection.isEmpty())
  42314. {
  42315. g.setColour (findColour (highlightColourId)
  42316. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42317. selectedTextColour = findColour (highlightedTextColourId);
  42318. TextEditorIterator i2 (i);
  42319. while (i2.next() && i2.lineY < clip.getBottom())
  42320. {
  42321. if (i2.lineY + i2.lineHeight >= clip.getY()
  42322. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42323. {
  42324. i2.drawSelection (g, selection);
  42325. }
  42326. }
  42327. }
  42328. const UniformTextSection* lastSection = 0;
  42329. while (i.next() && i.lineY < clip.getBottom())
  42330. {
  42331. if (i.lineY + i.lineHeight >= clip.getY())
  42332. {
  42333. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42334. {
  42335. i.drawSelectedText (g, selection, selectedTextColour);
  42336. lastSection = 0;
  42337. }
  42338. else
  42339. {
  42340. i.draw (g, lastSection);
  42341. }
  42342. }
  42343. }
  42344. }
  42345. }
  42346. void TextEditor::paint (Graphics& g)
  42347. {
  42348. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42349. }
  42350. void TextEditor::paintOverChildren (Graphics& g)
  42351. {
  42352. if (caretFlashState
  42353. && hasKeyboardFocus (false)
  42354. && caretVisible
  42355. && ! isReadOnly())
  42356. {
  42357. g.setColour (findColour (caretColourId));
  42358. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42359. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42360. 2.0f, cursorHeight);
  42361. }
  42362. if (textToShowWhenEmpty.isNotEmpty()
  42363. && (! hasKeyboardFocus (false))
  42364. && getTotalNumChars() == 0)
  42365. {
  42366. g.setColour (colourForTextWhenEmpty);
  42367. g.setFont (getFont());
  42368. if (isMultiLine())
  42369. {
  42370. g.drawText (textToShowWhenEmpty,
  42371. 0, 0, getWidth(), getHeight(),
  42372. Justification::centred, true);
  42373. }
  42374. else
  42375. {
  42376. g.drawText (textToShowWhenEmpty,
  42377. leftIndent, topIndent,
  42378. viewport->getWidth() - leftIndent,
  42379. viewport->getHeight() - topIndent,
  42380. Justification::centredLeft, true);
  42381. }
  42382. }
  42383. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42384. }
  42385. void TextEditor::mouseDown (const MouseEvent& e)
  42386. {
  42387. beginDragAutoRepeat (100);
  42388. newTransaction();
  42389. if (wasFocused || ! selectAllTextWhenFocused)
  42390. {
  42391. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42392. {
  42393. moveCursorTo (getTextIndexAt (e.x, e.y),
  42394. e.mods.isShiftDown());
  42395. }
  42396. else
  42397. {
  42398. PopupMenu m;
  42399. m.setLookAndFeel (&getLookAndFeel());
  42400. addPopupMenuItems (m, &e);
  42401. menuActive = true;
  42402. const int result = m.show();
  42403. menuActive = false;
  42404. if (result != 0)
  42405. performPopupMenuAction (result);
  42406. }
  42407. }
  42408. }
  42409. void TextEditor::mouseDrag (const MouseEvent& e)
  42410. {
  42411. if (wasFocused || ! selectAllTextWhenFocused)
  42412. {
  42413. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42414. {
  42415. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42416. }
  42417. }
  42418. }
  42419. void TextEditor::mouseUp (const MouseEvent& e)
  42420. {
  42421. newTransaction();
  42422. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42423. if (wasFocused || ! selectAllTextWhenFocused)
  42424. {
  42425. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42426. {
  42427. moveCaret (getTextIndexAt (e.x, e.y));
  42428. }
  42429. }
  42430. wasFocused = true;
  42431. }
  42432. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42433. {
  42434. int tokenEnd = getTextIndexAt (e.x, e.y);
  42435. int tokenStart = tokenEnd;
  42436. if (e.getNumberOfClicks() > 3)
  42437. {
  42438. tokenStart = 0;
  42439. tokenEnd = getTotalNumChars();
  42440. }
  42441. else
  42442. {
  42443. const String t (getText());
  42444. const int totalLength = getTotalNumChars();
  42445. while (tokenEnd < totalLength)
  42446. {
  42447. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42448. ++tokenEnd;
  42449. else
  42450. break;
  42451. }
  42452. tokenStart = tokenEnd;
  42453. while (tokenStart > 0)
  42454. {
  42455. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42456. --tokenStart;
  42457. else
  42458. break;
  42459. }
  42460. if (e.getNumberOfClicks() > 2)
  42461. {
  42462. while (tokenEnd < totalLength)
  42463. {
  42464. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42465. ++tokenEnd;
  42466. else
  42467. break;
  42468. }
  42469. while (tokenStart > 0)
  42470. {
  42471. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42472. --tokenStart;
  42473. else
  42474. break;
  42475. }
  42476. }
  42477. }
  42478. moveCursorTo (tokenEnd, false);
  42479. moveCursorTo (tokenStart, true);
  42480. }
  42481. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42482. {
  42483. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42484. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42485. }
  42486. bool TextEditor::keyPressed (const KeyPress& key)
  42487. {
  42488. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42489. return false;
  42490. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42491. if (key.isKeyCode (KeyPress::leftKey)
  42492. || key.isKeyCode (KeyPress::upKey))
  42493. {
  42494. newTransaction();
  42495. int newPos;
  42496. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42497. newPos = indexAtPosition (cursorX, cursorY - 1);
  42498. else if (moveInWholeWordSteps)
  42499. newPos = findWordBreakBefore (getCaretPosition());
  42500. else
  42501. newPos = getCaretPosition() - 1;
  42502. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42503. }
  42504. else if (key.isKeyCode (KeyPress::rightKey)
  42505. || key.isKeyCode (KeyPress::downKey))
  42506. {
  42507. newTransaction();
  42508. int newPos;
  42509. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42510. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42511. else if (moveInWholeWordSteps)
  42512. newPos = findWordBreakAfter (getCaretPosition());
  42513. else
  42514. newPos = getCaretPosition() + 1;
  42515. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42516. }
  42517. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42518. {
  42519. newTransaction();
  42520. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42521. key.getModifiers().isShiftDown());
  42522. }
  42523. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42524. {
  42525. newTransaction();
  42526. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42527. key.getModifiers().isShiftDown());
  42528. }
  42529. else if (key.isKeyCode (KeyPress::homeKey))
  42530. {
  42531. newTransaction();
  42532. if (isMultiLine() && ! moveInWholeWordSteps)
  42533. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42534. key.getModifiers().isShiftDown());
  42535. else
  42536. moveCursorTo (0, key.getModifiers().isShiftDown());
  42537. }
  42538. else if (key.isKeyCode (KeyPress::endKey))
  42539. {
  42540. newTransaction();
  42541. if (isMultiLine() && ! moveInWholeWordSteps)
  42542. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42543. key.getModifiers().isShiftDown());
  42544. else
  42545. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42546. }
  42547. else if (key.isKeyCode (KeyPress::backspaceKey))
  42548. {
  42549. if (moveInWholeWordSteps)
  42550. {
  42551. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42552. }
  42553. else
  42554. {
  42555. if (selection.isEmpty() && selection.getStart() > 0)
  42556. selection.setStart (selection.getEnd() - 1);
  42557. }
  42558. cut();
  42559. }
  42560. else if (key.isKeyCode (KeyPress::deleteKey))
  42561. {
  42562. if (key.getModifiers().isShiftDown())
  42563. copy();
  42564. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42565. selection.setEnd (selection.getStart() + 1);
  42566. cut();
  42567. }
  42568. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  42569. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42570. {
  42571. newTransaction();
  42572. copy();
  42573. }
  42574. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  42575. {
  42576. newTransaction();
  42577. copy();
  42578. cut();
  42579. }
  42580. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  42581. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42582. {
  42583. newTransaction();
  42584. paste();
  42585. }
  42586. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  42587. {
  42588. newTransaction();
  42589. doUndoRedo (false);
  42590. }
  42591. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  42592. {
  42593. newTransaction();
  42594. doUndoRedo (true);
  42595. }
  42596. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  42597. {
  42598. newTransaction();
  42599. moveCursorTo (getTotalNumChars(), false);
  42600. moveCursorTo (0, true);
  42601. }
  42602. else if (key == KeyPress::returnKey)
  42603. {
  42604. newTransaction();
  42605. if (returnKeyStartsNewLine)
  42606. insertTextAtCaret (T("\n"));
  42607. else
  42608. returnPressed();
  42609. }
  42610. else if (key.isKeyCode (KeyPress::escapeKey))
  42611. {
  42612. newTransaction();
  42613. moveCursorTo (getCaretPosition(), false);
  42614. escapePressed();
  42615. }
  42616. else if (key.getTextCharacter() >= ' '
  42617. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42618. {
  42619. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42620. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42621. }
  42622. else
  42623. {
  42624. return false;
  42625. }
  42626. return true;
  42627. }
  42628. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42629. {
  42630. if (! isKeyDown)
  42631. return false;
  42632. #if JUCE_WIN32
  42633. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42634. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42635. #endif
  42636. // (overridden to avoid forwarding key events to the parent)
  42637. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42638. }
  42639. const int baseMenuItemID = 0x7fff0000;
  42640. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42641. {
  42642. const bool writable = ! isReadOnly();
  42643. if (passwordCharacter == 0)
  42644. {
  42645. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42646. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42647. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42648. }
  42649. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42650. m.addSeparator();
  42651. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42652. m.addSeparator();
  42653. if (getUndoManager() != 0)
  42654. {
  42655. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42656. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42657. }
  42658. }
  42659. void TextEditor::performPopupMenuAction (const int menuItemID)
  42660. {
  42661. switch (menuItemID)
  42662. {
  42663. case baseMenuItemID + 1:
  42664. copy();
  42665. cut();
  42666. break;
  42667. case baseMenuItemID + 2:
  42668. copy();
  42669. break;
  42670. case baseMenuItemID + 3:
  42671. paste();
  42672. break;
  42673. case baseMenuItemID + 4:
  42674. cut();
  42675. break;
  42676. case baseMenuItemID + 5:
  42677. moveCursorTo (getTotalNumChars(), false);
  42678. moveCursorTo (0, true);
  42679. break;
  42680. case baseMenuItemID + 6:
  42681. doUndoRedo (false);
  42682. break;
  42683. case baseMenuItemID + 7:
  42684. doUndoRedo (true);
  42685. break;
  42686. default:
  42687. break;
  42688. }
  42689. }
  42690. void TextEditor::focusGained (FocusChangeType)
  42691. {
  42692. newTransaction();
  42693. caretFlashState = true;
  42694. if (selectAllTextWhenFocused)
  42695. {
  42696. moveCursorTo (0, false);
  42697. moveCursorTo (getTotalNumChars(), true);
  42698. }
  42699. repaint();
  42700. if (caretVisible)
  42701. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42702. ComponentPeer* const peer = getPeer();
  42703. if (peer != 0 && ! isReadOnly())
  42704. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42705. }
  42706. void TextEditor::focusLost (FocusChangeType)
  42707. {
  42708. newTransaction();
  42709. wasFocused = false;
  42710. textHolder->stopTimer();
  42711. caretFlashState = false;
  42712. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42713. repaint();
  42714. }
  42715. void TextEditor::resized()
  42716. {
  42717. viewport->setBoundsInset (borderSize);
  42718. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42719. updateTextHolderSize();
  42720. if (! isMultiLine())
  42721. {
  42722. scrollToMakeSureCursorIsVisible();
  42723. }
  42724. else
  42725. {
  42726. updateCaretPosition();
  42727. }
  42728. }
  42729. void TextEditor::handleCommandMessage (const int commandId)
  42730. {
  42731. Component::BailOutChecker checker (this);
  42732. switch (commandId)
  42733. {
  42734. case TextEditorDefs::textChangeMessageId:
  42735. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42736. break;
  42737. case TextEditorDefs::returnKeyMessageId:
  42738. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42739. break;
  42740. case TextEditorDefs::escapeKeyMessageId:
  42741. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42742. break;
  42743. case TextEditorDefs::focusLossMessageId:
  42744. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42745. break;
  42746. default:
  42747. jassertfalse
  42748. break;
  42749. }
  42750. }
  42751. void TextEditor::enablementChanged()
  42752. {
  42753. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42754. : MouseCursor::IBeamCursor);
  42755. repaint();
  42756. }
  42757. UndoManager* TextEditor::getUndoManager() throw()
  42758. {
  42759. return isReadOnly() ? &undoManager : 0;
  42760. }
  42761. void TextEditor::clearInternal (UndoManager* const um)
  42762. {
  42763. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42764. }
  42765. void TextEditor::insert (const String& text,
  42766. const int insertIndex,
  42767. const Font& font,
  42768. const Colour& colour,
  42769. UndoManager* const um,
  42770. const int caretPositionToMoveTo)
  42771. {
  42772. if (text.isNotEmpty())
  42773. {
  42774. if (um != 0)
  42775. {
  42776. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42777. newTransaction();
  42778. um->perform (new TextEditorInsertAction (*this,
  42779. text,
  42780. insertIndex,
  42781. font,
  42782. colour,
  42783. caretPosition,
  42784. caretPositionToMoveTo));
  42785. }
  42786. else
  42787. {
  42788. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42789. // a line gets moved due to word wrap
  42790. int index = 0;
  42791. int nextIndex = 0;
  42792. for (int i = 0; i < sections.size(); ++i)
  42793. {
  42794. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42795. if (insertIndex == index)
  42796. {
  42797. sections.insert (i, new UniformTextSection (text,
  42798. font, colour,
  42799. passwordCharacter));
  42800. break;
  42801. }
  42802. else if (insertIndex > index && insertIndex < nextIndex)
  42803. {
  42804. splitSection (i, insertIndex - index);
  42805. sections.insert (i + 1, new UniformTextSection (text,
  42806. font, colour,
  42807. passwordCharacter));
  42808. break;
  42809. }
  42810. index = nextIndex;
  42811. }
  42812. if (nextIndex == insertIndex)
  42813. sections.add (new UniformTextSection (text,
  42814. font, colour,
  42815. passwordCharacter));
  42816. coalesceSimilarSections();
  42817. totalNumChars = -1;
  42818. valueTextNeedsUpdating = true;
  42819. moveCursorTo (caretPositionToMoveTo, false);
  42820. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42821. }
  42822. }
  42823. }
  42824. void TextEditor::reinsert (const int insertIndex,
  42825. const VoidArray& sectionsToInsert)
  42826. {
  42827. int index = 0;
  42828. int nextIndex = 0;
  42829. for (int i = 0; i < sections.size(); ++i)
  42830. {
  42831. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42832. if (insertIndex == index)
  42833. {
  42834. for (int j = sectionsToInsert.size(); --j >= 0;)
  42835. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42836. break;
  42837. }
  42838. else if (insertIndex > index && insertIndex < nextIndex)
  42839. {
  42840. splitSection (i, insertIndex - index);
  42841. for (int j = sectionsToInsert.size(); --j >= 0;)
  42842. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42843. break;
  42844. }
  42845. index = nextIndex;
  42846. }
  42847. if (nextIndex == insertIndex)
  42848. {
  42849. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42850. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42851. }
  42852. coalesceSimilarSections();
  42853. totalNumChars = -1;
  42854. valueTextNeedsUpdating = true;
  42855. }
  42856. void TextEditor::remove (const Range<int>& range,
  42857. UndoManager* const um,
  42858. const int caretPositionToMoveTo)
  42859. {
  42860. if (! range.isEmpty())
  42861. {
  42862. int index = 0;
  42863. for (int i = 0; i < sections.size(); ++i)
  42864. {
  42865. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  42866. if (range.getStart() > index && range.getStart() < nextIndex)
  42867. {
  42868. splitSection (i, range.getStart() - index);
  42869. --i;
  42870. }
  42871. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42872. {
  42873. splitSection (i, range.getEnd() - index);
  42874. --i;
  42875. }
  42876. else
  42877. {
  42878. index = nextIndex;
  42879. if (index > range.getEnd())
  42880. break;
  42881. }
  42882. }
  42883. index = 0;
  42884. if (um != 0)
  42885. {
  42886. VoidArray removedSections;
  42887. for (int i = 0; i < sections.size(); ++i)
  42888. {
  42889. if (range.getEnd() <= range.getStart())
  42890. break;
  42891. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42892. const int nextIndex = index + section->getTotalLength();
  42893. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42894. removedSections.add (new UniformTextSection (*section));
  42895. index = nextIndex;
  42896. }
  42897. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42898. newTransaction();
  42899. um->perform (new TextEditorRemoveAction (*this,
  42900. range,
  42901. caretPosition,
  42902. caretPositionToMoveTo,
  42903. removedSections));
  42904. }
  42905. else
  42906. {
  42907. Range<int> remainingRange (range);
  42908. for (int i = 0; i < sections.size(); ++i)
  42909. {
  42910. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42911. const int nextIndex = index + section->getTotalLength();
  42912. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42913. {
  42914. sections.remove(i);
  42915. section->clear();
  42916. delete section;
  42917. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  42918. if (remainingRange.isEmpty())
  42919. break;
  42920. --i;
  42921. }
  42922. else
  42923. {
  42924. index = nextIndex;
  42925. }
  42926. }
  42927. coalesceSimilarSections();
  42928. totalNumChars = -1;
  42929. valueTextNeedsUpdating = true;
  42930. moveCursorTo (caretPositionToMoveTo, false);
  42931. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  42932. }
  42933. }
  42934. }
  42935. const String TextEditor::getText() const
  42936. {
  42937. String t;
  42938. t.preallocateStorage (getTotalNumChars());
  42939. String::Concatenator concatenator (t);
  42940. for (int i = 0; i < sections.size(); ++i)
  42941. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  42942. return t;
  42943. }
  42944. const String TextEditor::getTextInRange (const Range<int>& range) const
  42945. {
  42946. String t;
  42947. if (! range.isEmpty())
  42948. {
  42949. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  42950. String::Concatenator concatenator (t);
  42951. int index = 0;
  42952. for (int i = 0; i < sections.size(); ++i)
  42953. {
  42954. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  42955. const int nextIndex = index + s->getTotalLength();
  42956. if (range.getStart() < nextIndex)
  42957. {
  42958. if (range.getEnd() <= index)
  42959. break;
  42960. s->appendSubstring (concatenator, range - index);
  42961. }
  42962. index = nextIndex;
  42963. }
  42964. }
  42965. return t;
  42966. }
  42967. const String TextEditor::getHighlightedText() const
  42968. {
  42969. return getTextInRange (selection);
  42970. }
  42971. int TextEditor::getTotalNumChars() const
  42972. {
  42973. if (totalNumChars < 0)
  42974. {
  42975. totalNumChars = 0;
  42976. for (int i = sections.size(); --i >= 0;)
  42977. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42978. }
  42979. return totalNumChars;
  42980. }
  42981. bool TextEditor::isEmpty() const
  42982. {
  42983. return getTotalNumChars() == 0;
  42984. }
  42985. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  42986. {
  42987. const float wordWrapWidth = getWordWrapWidth();
  42988. if (wordWrapWidth > 0 && sections.size() > 0)
  42989. {
  42990. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42991. i.getCharPosition (index, cx, cy, lineHeight);
  42992. }
  42993. else
  42994. {
  42995. cx = cy = 0;
  42996. lineHeight = currentFont.getHeight();
  42997. }
  42998. }
  42999. int TextEditor::indexAtPosition (const float x, const float y)
  43000. {
  43001. const float wordWrapWidth = getWordWrapWidth();
  43002. if (wordWrapWidth > 0)
  43003. {
  43004. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43005. while (i.next())
  43006. {
  43007. if (i.lineY + i.lineHeight > y)
  43008. {
  43009. if (i.lineY > y)
  43010. return jmax (0, i.indexInText - 1);
  43011. if (i.atomX >= x)
  43012. return i.indexInText;
  43013. if (x < i.atomRight)
  43014. return i.xToIndex (x);
  43015. }
  43016. }
  43017. }
  43018. return getTotalNumChars();
  43019. }
  43020. static int getCharacterCategory (const tchar character)
  43021. {
  43022. return CharacterFunctions::isLetterOrDigit (character)
  43023. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43024. }
  43025. int TextEditor::findWordBreakAfter (const int position) const
  43026. {
  43027. const String t (getTextInRange (Range<int> (position, position + 512)));
  43028. const int totalLength = t.length();
  43029. int i = 0;
  43030. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43031. ++i;
  43032. const int type = getCharacterCategory (t[i]);
  43033. while (i < totalLength && type == getCharacterCategory (t[i]))
  43034. ++i;
  43035. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43036. ++i;
  43037. return position + i;
  43038. }
  43039. int TextEditor::findWordBreakBefore (const int position) const
  43040. {
  43041. if (position <= 0)
  43042. return 0;
  43043. const int startOfBuffer = jmax (0, position - 512);
  43044. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  43045. int i = position - startOfBuffer;
  43046. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43047. --i;
  43048. if (i > 0)
  43049. {
  43050. const int type = getCharacterCategory (t [i - 1]);
  43051. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43052. --i;
  43053. }
  43054. jassert (startOfBuffer + i >= 0);
  43055. return startOfBuffer + i;
  43056. }
  43057. void TextEditor::splitSection (const int sectionIndex,
  43058. const int charToSplitAt)
  43059. {
  43060. jassert (sections[sectionIndex] != 0);
  43061. sections.insert (sectionIndex + 1,
  43062. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43063. ->split (charToSplitAt, passwordCharacter));
  43064. }
  43065. void TextEditor::coalesceSimilarSections()
  43066. {
  43067. for (int i = 0; i < sections.size() - 1; ++i)
  43068. {
  43069. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43070. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43071. if (s1->font == s2->font
  43072. && s1->colour == s2->colour)
  43073. {
  43074. s1->append (*s2, passwordCharacter);
  43075. sections.remove (i + 1);
  43076. delete s2;
  43077. --i;
  43078. }
  43079. }
  43080. }
  43081. END_JUCE_NAMESPACE
  43082. /*** End of inlined file: juce_TextEditor.cpp ***/
  43083. /*** Start of inlined file: juce_Toolbar.cpp ***/
  43084. BEGIN_JUCE_NAMESPACE
  43085. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43086. class ToolbarSpacerComp : public ToolbarItemComponent
  43087. {
  43088. public:
  43089. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43090. : ToolbarItemComponent (itemId_, String::empty, false),
  43091. fixedSize (fixedSize_),
  43092. drawBar (drawBar_)
  43093. {
  43094. }
  43095. ~ToolbarSpacerComp()
  43096. {
  43097. }
  43098. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43099. int& preferredSize, int& minSize, int& maxSize)
  43100. {
  43101. if (fixedSize <= 0)
  43102. {
  43103. preferredSize = toolbarThickness * 2;
  43104. minSize = 4;
  43105. maxSize = 32768;
  43106. }
  43107. else
  43108. {
  43109. maxSize = roundToInt (toolbarThickness * fixedSize);
  43110. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43111. preferredSize = maxSize;
  43112. if (getEditingMode() == editableOnPalette)
  43113. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43114. }
  43115. return true;
  43116. }
  43117. void paintButtonArea (Graphics&, int, int, bool, bool)
  43118. {
  43119. }
  43120. void contentAreaChanged (const Rectangle<int>&)
  43121. {
  43122. }
  43123. int getResizeOrder() const throw()
  43124. {
  43125. return fixedSize <= 0 ? 0 : 1;
  43126. }
  43127. void paint (Graphics& g)
  43128. {
  43129. const int w = getWidth();
  43130. const int h = getHeight();
  43131. if (drawBar)
  43132. {
  43133. g.setColour (findColour (Toolbar::separatorColourId, true));
  43134. const float thickness = 0.2f;
  43135. if (isToolbarVertical())
  43136. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43137. else
  43138. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43139. }
  43140. if (getEditingMode() != normalMode && ! drawBar)
  43141. {
  43142. g.setColour (findColour (Toolbar::separatorColourId, true));
  43143. const int indentX = jmin (2, (w - 3) / 2);
  43144. const int indentY = jmin (2, (h - 3) / 2);
  43145. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43146. if (fixedSize <= 0)
  43147. {
  43148. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43149. if (isToolbarVertical())
  43150. {
  43151. x1 = w * 0.5f;
  43152. y1 = h * 0.4f;
  43153. x2 = x1;
  43154. y2 = indentX * 2.0f;
  43155. x3 = x1;
  43156. y3 = h * 0.6f;
  43157. x4 = x1;
  43158. y4 = h - y2;
  43159. hw = w * 0.15f;
  43160. hl = w * 0.2f;
  43161. }
  43162. else
  43163. {
  43164. x1 = w * 0.4f;
  43165. y1 = h * 0.5f;
  43166. x2 = indentX * 2.0f;
  43167. y2 = y1;
  43168. x3 = w * 0.6f;
  43169. y3 = y1;
  43170. x4 = w - x2;
  43171. y4 = y1;
  43172. hw = h * 0.15f;
  43173. hl = h * 0.2f;
  43174. }
  43175. Path p;
  43176. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43177. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43178. g.fillPath (p);
  43179. }
  43180. }
  43181. }
  43182. juce_UseDebuggingNewOperator
  43183. private:
  43184. const float fixedSize;
  43185. const bool drawBar;
  43186. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43187. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43188. };
  43189. class MissingItemsComponent : public PopupMenuCustomComponent
  43190. {
  43191. public:
  43192. MissingItemsComponent (Toolbar& owner_, const int height_)
  43193. : PopupMenuCustomComponent (true),
  43194. owner (owner_),
  43195. height (height_)
  43196. {
  43197. for (int i = owner_.items.size(); --i >= 0;)
  43198. {
  43199. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43200. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43201. {
  43202. oldIndexes.insert (0, i);
  43203. addAndMakeVisible (tc, 0);
  43204. }
  43205. }
  43206. layout (400);
  43207. }
  43208. ~MissingItemsComponent()
  43209. {
  43210. // deleting the toolbar while its menu it open??
  43211. jassert (owner.isValidComponent());
  43212. for (int i = 0; i < getNumChildComponents(); ++i)
  43213. {
  43214. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43215. if (tc != 0)
  43216. {
  43217. tc->setVisible (false);
  43218. const int index = oldIndexes.remove (i);
  43219. owner.addChildComponent (tc, index);
  43220. --i;
  43221. }
  43222. }
  43223. owner.resized();
  43224. }
  43225. void layout (const int preferredWidth)
  43226. {
  43227. const int indent = 8;
  43228. int x = indent;
  43229. int y = indent;
  43230. int maxX = 0;
  43231. for (int i = 0; i < getNumChildComponents(); ++i)
  43232. {
  43233. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43234. if (tc != 0)
  43235. {
  43236. int preferredSize = 1, minSize = 1, maxSize = 1;
  43237. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43238. {
  43239. if (x + preferredSize > preferredWidth && x > indent)
  43240. {
  43241. x = indent;
  43242. y += height;
  43243. }
  43244. tc->setBounds (x, y, preferredSize, height);
  43245. x += preferredSize;
  43246. maxX = jmax (maxX, x);
  43247. }
  43248. }
  43249. }
  43250. setSize (maxX + 8, y + height + 8);
  43251. }
  43252. void getIdealSize (int& idealWidth, int& idealHeight)
  43253. {
  43254. idealWidth = getWidth();
  43255. idealHeight = getHeight();
  43256. }
  43257. juce_UseDebuggingNewOperator
  43258. private:
  43259. Toolbar& owner;
  43260. const int height;
  43261. Array <int> oldIndexes;
  43262. MissingItemsComponent (const MissingItemsComponent&);
  43263. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43264. };
  43265. Toolbar::Toolbar()
  43266. : vertical (false),
  43267. isEditingActive (false),
  43268. toolbarStyle (Toolbar::iconsOnly)
  43269. {
  43270. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43271. missingItemsButton->setAlwaysOnTop (true);
  43272. missingItemsButton->addButtonListener (this);
  43273. }
  43274. Toolbar::~Toolbar()
  43275. {
  43276. animator.cancelAllAnimations (true);
  43277. deleteAllChildren();
  43278. }
  43279. void Toolbar::setVertical (const bool shouldBeVertical)
  43280. {
  43281. if (vertical != shouldBeVertical)
  43282. {
  43283. vertical = shouldBeVertical;
  43284. resized();
  43285. }
  43286. }
  43287. void Toolbar::clear()
  43288. {
  43289. for (int i = items.size(); --i >= 0;)
  43290. {
  43291. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43292. items.remove (i);
  43293. delete tc;
  43294. }
  43295. resized();
  43296. }
  43297. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43298. {
  43299. if (itemId == ToolbarItemFactory::separatorBarId)
  43300. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43301. else if (itemId == ToolbarItemFactory::spacerId)
  43302. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43303. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43304. return new ToolbarSpacerComp (itemId, 0, false);
  43305. return factory.createItem (itemId);
  43306. }
  43307. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43308. const int itemId,
  43309. const int insertIndex)
  43310. {
  43311. // An ID can't be zero - this might indicate a mistake somewhere?
  43312. jassert (itemId != 0);
  43313. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43314. if (tc != 0)
  43315. {
  43316. #ifdef JUCE_DEBUG
  43317. Array <int> allowedIds;
  43318. factory.getAllToolbarItemIds (allowedIds);
  43319. // If your factory can create an item for a given ID, it must also return
  43320. // that ID from its getAllToolbarItemIds() method!
  43321. jassert (allowedIds.contains (itemId));
  43322. #endif
  43323. items.insert (insertIndex, tc);
  43324. addAndMakeVisible (tc, insertIndex);
  43325. }
  43326. }
  43327. void Toolbar::addItem (ToolbarItemFactory& factory,
  43328. const int itemId,
  43329. const int insertIndex)
  43330. {
  43331. addItemInternal (factory, itemId, insertIndex);
  43332. resized();
  43333. }
  43334. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43335. {
  43336. Array <int> ids;
  43337. factoryToUse.getDefaultItemSet (ids);
  43338. clear();
  43339. for (int i = 0; i < ids.size(); ++i)
  43340. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43341. resized();
  43342. }
  43343. void Toolbar::removeToolbarItem (const int itemIndex)
  43344. {
  43345. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43346. if (tc != 0)
  43347. {
  43348. items.removeValue (tc);
  43349. delete tc;
  43350. resized();
  43351. }
  43352. }
  43353. int Toolbar::getNumItems() const throw()
  43354. {
  43355. return items.size();
  43356. }
  43357. int Toolbar::getItemId (const int itemIndex) const throw()
  43358. {
  43359. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43360. return tc != 0 ? tc->getItemId() : 0;
  43361. }
  43362. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43363. {
  43364. return items [itemIndex];
  43365. }
  43366. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43367. {
  43368. for (;;)
  43369. {
  43370. index += delta;
  43371. ToolbarItemComponent* const tc = getItemComponent (index);
  43372. if (tc == 0)
  43373. break;
  43374. if (tc->isActive)
  43375. return tc;
  43376. }
  43377. return 0;
  43378. }
  43379. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43380. {
  43381. if (toolbarStyle != newStyle)
  43382. {
  43383. toolbarStyle = newStyle;
  43384. updateAllItemPositions (false);
  43385. }
  43386. }
  43387. const String Toolbar::toString() const
  43388. {
  43389. String s (T("TB:"));
  43390. for (int i = 0; i < getNumItems(); ++i)
  43391. s << getItemId(i) << T(' ');
  43392. return s.trimEnd();
  43393. }
  43394. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43395. const String& savedVersion)
  43396. {
  43397. if (! savedVersion.startsWith (T("TB:")))
  43398. return false;
  43399. StringArray tokens;
  43400. tokens.addTokens (savedVersion.substring (3), false);
  43401. clear();
  43402. for (int i = 0; i < tokens.size(); ++i)
  43403. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43404. resized();
  43405. return true;
  43406. }
  43407. void Toolbar::paint (Graphics& g)
  43408. {
  43409. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43410. }
  43411. int Toolbar::getThickness() const throw()
  43412. {
  43413. return vertical ? getWidth() : getHeight();
  43414. }
  43415. int Toolbar::getLength() const throw()
  43416. {
  43417. return vertical ? getHeight() : getWidth();
  43418. }
  43419. void Toolbar::setEditingActive (const bool active)
  43420. {
  43421. if (isEditingActive != active)
  43422. {
  43423. isEditingActive = active;
  43424. updateAllItemPositions (false);
  43425. }
  43426. }
  43427. void Toolbar::resized()
  43428. {
  43429. updateAllItemPositions (false);
  43430. }
  43431. void Toolbar::updateAllItemPositions (const bool animate)
  43432. {
  43433. if (getWidth() > 0 && getHeight() > 0)
  43434. {
  43435. StretchableObjectResizer resizer;
  43436. int i;
  43437. for (i = 0; i < items.size(); ++i)
  43438. {
  43439. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43440. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43441. : ToolbarItemComponent::normalMode);
  43442. tc->setStyle (toolbarStyle);
  43443. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43444. int preferredSize = 1, minSize = 1, maxSize = 1;
  43445. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43446. preferredSize, minSize, maxSize))
  43447. {
  43448. tc->isActive = true;
  43449. resizer.addItem (preferredSize, minSize, maxSize,
  43450. spacer != 0 ? spacer->getResizeOrder() : 2);
  43451. }
  43452. else
  43453. {
  43454. tc->isActive = false;
  43455. tc->setVisible (false);
  43456. }
  43457. }
  43458. resizer.resizeToFit (getLength());
  43459. int totalLength = 0;
  43460. for (i = 0; i < resizer.getNumItems(); ++i)
  43461. totalLength += (int) resizer.getItemSize (i);
  43462. const bool itemsOffTheEnd = totalLength > getLength();
  43463. const int extrasButtonSize = getThickness() / 2;
  43464. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43465. missingItemsButton->setVisible (itemsOffTheEnd);
  43466. missingItemsButton->setEnabled (! isEditingActive);
  43467. if (vertical)
  43468. missingItemsButton->setCentrePosition (getWidth() / 2,
  43469. getHeight() - 4 - extrasButtonSize / 2);
  43470. else
  43471. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43472. getHeight() / 2);
  43473. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43474. : missingItemsButton->getX()) - 4
  43475. : getLength();
  43476. int pos = 0, activeIndex = 0;
  43477. for (i = 0; i < items.size(); ++i)
  43478. {
  43479. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43480. if (tc->isActive)
  43481. {
  43482. const int size = (int) resizer.getItemSize (activeIndex++);
  43483. Rectangle<int> newBounds;
  43484. if (vertical)
  43485. newBounds.setBounds (0, pos, getWidth(), size);
  43486. else
  43487. newBounds.setBounds (pos, 0, size, getHeight());
  43488. if (animate)
  43489. {
  43490. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43491. }
  43492. else
  43493. {
  43494. animator.cancelAnimation (tc, false);
  43495. tc->setBounds (newBounds);
  43496. }
  43497. pos += size;
  43498. tc->setVisible (pos <= maxLength
  43499. && ((! tc->isBeingDragged)
  43500. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43501. }
  43502. }
  43503. }
  43504. }
  43505. void Toolbar::buttonClicked (Button*)
  43506. {
  43507. jassert (missingItemsButton->isShowing());
  43508. if (missingItemsButton->isShowing())
  43509. {
  43510. PopupMenu m;
  43511. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43512. m.showAt (missingItemsButton);
  43513. }
  43514. }
  43515. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43516. Component* /*sourceComponent*/)
  43517. {
  43518. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43519. }
  43520. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43521. {
  43522. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43523. if (tc != 0)
  43524. {
  43525. if (getNumItems() == 0)
  43526. {
  43527. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43528. {
  43529. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43530. if (palette != 0)
  43531. palette->replaceComponent (tc);
  43532. }
  43533. else
  43534. {
  43535. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43536. }
  43537. items.add (tc);
  43538. addChildComponent (tc);
  43539. updateAllItemPositions (false);
  43540. }
  43541. else
  43542. {
  43543. for (int i = getNumItems(); --i >= 0;)
  43544. {
  43545. int currentIndex = getIndexOfChildComponent (tc);
  43546. if (currentIndex < 0)
  43547. {
  43548. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43549. {
  43550. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43551. if (palette != 0)
  43552. palette->replaceComponent (tc);
  43553. }
  43554. else
  43555. {
  43556. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43557. }
  43558. items.add (tc);
  43559. addChildComponent (tc);
  43560. currentIndex = getIndexOfChildComponent (tc);
  43561. updateAllItemPositions (true);
  43562. }
  43563. int newIndex = currentIndex;
  43564. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43565. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43566. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43567. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43568. if (prev != 0)
  43569. {
  43570. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43571. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43572. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43573. {
  43574. newIndex = getIndexOfChildComponent (prev);
  43575. }
  43576. }
  43577. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43578. if (next != 0)
  43579. {
  43580. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43581. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43582. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43583. {
  43584. newIndex = getIndexOfChildComponent (next) + 1;
  43585. }
  43586. }
  43587. if (newIndex != currentIndex)
  43588. {
  43589. items.removeValue (tc);
  43590. removeChildComponent (tc);
  43591. addChildComponent (tc, newIndex);
  43592. items.insert (newIndex, tc);
  43593. updateAllItemPositions (true);
  43594. }
  43595. else
  43596. {
  43597. break;
  43598. }
  43599. }
  43600. }
  43601. }
  43602. }
  43603. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43604. {
  43605. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43606. if (tc != 0)
  43607. {
  43608. if (isParentOf (tc))
  43609. {
  43610. items.removeValue (tc);
  43611. removeChildComponent (tc);
  43612. updateAllItemPositions (true);
  43613. }
  43614. }
  43615. }
  43616. void Toolbar::itemDropped (const String&, Component*, int, int)
  43617. {
  43618. }
  43619. void Toolbar::mouseDown (const MouseEvent& e)
  43620. {
  43621. if (e.mods.isPopupMenu())
  43622. {
  43623. }
  43624. }
  43625. class ToolbarCustomisationDialog : public DialogWindow
  43626. {
  43627. public:
  43628. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43629. Toolbar* const toolbar_,
  43630. const int optionFlags)
  43631. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43632. toolbar (toolbar_)
  43633. {
  43634. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43635. setResizable (true, true);
  43636. setResizeLimits (400, 300, 1500, 1000);
  43637. positionNearBar();
  43638. }
  43639. ~ToolbarCustomisationDialog()
  43640. {
  43641. setContentComponent (0, true);
  43642. }
  43643. void closeButtonPressed()
  43644. {
  43645. setVisible (false);
  43646. }
  43647. bool canModalEventBeSentToComponent (const Component* comp)
  43648. {
  43649. return toolbar->isParentOf (comp);
  43650. }
  43651. void positionNearBar()
  43652. {
  43653. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43654. const int tbx = toolbar->getScreenX();
  43655. const int tby = toolbar->getScreenY();
  43656. const int gap = 8;
  43657. int x, y;
  43658. if (toolbar->isVertical())
  43659. {
  43660. y = tby;
  43661. if (tbx > screenSize.getCentreX())
  43662. x = tbx - getWidth() - gap;
  43663. else
  43664. x = tbx + toolbar->getWidth() + gap;
  43665. }
  43666. else
  43667. {
  43668. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43669. if (tby > screenSize.getCentreY())
  43670. y = tby - getHeight() - gap;
  43671. else
  43672. y = tby + toolbar->getHeight() + gap;
  43673. }
  43674. setTopLeftPosition (x, y);
  43675. }
  43676. private:
  43677. Toolbar* const toolbar;
  43678. class CustomiserPanel : public Component,
  43679. private ComboBoxListener,
  43680. private ButtonListener
  43681. {
  43682. public:
  43683. CustomiserPanel (ToolbarItemFactory& factory_,
  43684. Toolbar* const toolbar_,
  43685. const int optionFlags)
  43686. : factory (factory_),
  43687. toolbar (toolbar_),
  43688. styleBox (0),
  43689. defaultButton (0)
  43690. {
  43691. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43692. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43693. | Toolbar::allowIconsWithTextChoice
  43694. | Toolbar::allowTextOnlyChoice)) != 0)
  43695. {
  43696. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43697. styleBox->setEditableText (false);
  43698. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43699. styleBox->addItem (TRANS("Show icons only"), 1);
  43700. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43701. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43702. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43703. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43704. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43705. styleBox->setSelectedId (1);
  43706. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43707. styleBox->setSelectedId (2);
  43708. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43709. styleBox->setSelectedId (3);
  43710. styleBox->addListener (this);
  43711. }
  43712. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43713. {
  43714. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43715. defaultButton->addButtonListener (this);
  43716. }
  43717. addAndMakeVisible (instructions = new Label (String::empty,
  43718. 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.")));
  43719. instructions->setFont (Font (13.0f));
  43720. setSize (500, 300);
  43721. }
  43722. ~CustomiserPanel()
  43723. {
  43724. deleteAllChildren();
  43725. }
  43726. void comboBoxChanged (ComboBox*)
  43727. {
  43728. if (styleBox->getSelectedId() == 1)
  43729. toolbar->setStyle (Toolbar::iconsOnly);
  43730. else if (styleBox->getSelectedId() == 2)
  43731. toolbar->setStyle (Toolbar::iconsWithText);
  43732. else if (styleBox->getSelectedId() == 3)
  43733. toolbar->setStyle (Toolbar::textOnly);
  43734. palette->resized(); // to make it update the styles
  43735. }
  43736. void buttonClicked (Button*)
  43737. {
  43738. toolbar->addDefaultItems (factory);
  43739. }
  43740. void paint (Graphics& g)
  43741. {
  43742. Colour background;
  43743. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43744. if (dw != 0)
  43745. background = dw->getBackgroundColour();
  43746. g.setColour (background.contrasting().withAlpha (0.3f));
  43747. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43748. }
  43749. void resized()
  43750. {
  43751. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43752. if (styleBox != 0)
  43753. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43754. if (defaultButton != 0)
  43755. {
  43756. defaultButton->changeWidthToFitText (22);
  43757. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43758. }
  43759. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43760. }
  43761. private:
  43762. ToolbarItemFactory& factory;
  43763. Toolbar* const toolbar;
  43764. Label* instructions;
  43765. ToolbarItemPalette* palette;
  43766. ComboBox* styleBox;
  43767. TextButton* defaultButton;
  43768. };
  43769. };
  43770. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43771. {
  43772. setEditingActive (true);
  43773. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43774. dw.runModalLoop();
  43775. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43776. setEditingActive (false);
  43777. }
  43778. END_JUCE_NAMESPACE
  43779. /*** End of inlined file: juce_Toolbar.cpp ***/
  43780. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43781. BEGIN_JUCE_NAMESPACE
  43782. ToolbarItemFactory::ToolbarItemFactory()
  43783. {
  43784. }
  43785. ToolbarItemFactory::~ToolbarItemFactory()
  43786. {
  43787. }
  43788. class ItemDragAndDropOverlayComponent : public Component
  43789. {
  43790. public:
  43791. ItemDragAndDropOverlayComponent()
  43792. : isDragging (false)
  43793. {
  43794. setAlwaysOnTop (true);
  43795. setRepaintsOnMouseActivity (true);
  43796. setMouseCursor (MouseCursor::DraggingHandCursor);
  43797. }
  43798. ~ItemDragAndDropOverlayComponent()
  43799. {
  43800. }
  43801. void paint (Graphics& g)
  43802. {
  43803. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43804. if (isMouseOverOrDragging()
  43805. && tc != 0
  43806. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43807. {
  43808. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43809. g.drawRect (0, 0, getWidth(), getHeight(),
  43810. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43811. }
  43812. }
  43813. void mouseDown (const MouseEvent& e)
  43814. {
  43815. isDragging = false;
  43816. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43817. if (tc != 0)
  43818. {
  43819. tc->dragOffsetX = e.x;
  43820. tc->dragOffsetY = e.y;
  43821. }
  43822. }
  43823. void mouseDrag (const MouseEvent& e)
  43824. {
  43825. if (! (isDragging || e.mouseWasClicked()))
  43826. {
  43827. isDragging = true;
  43828. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43829. if (dnd != 0)
  43830. {
  43831. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43832. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43833. if (tc != 0)
  43834. {
  43835. tc->isBeingDragged = true;
  43836. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43837. tc->setVisible (false);
  43838. }
  43839. }
  43840. }
  43841. }
  43842. void mouseUp (const MouseEvent&)
  43843. {
  43844. isDragging = false;
  43845. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43846. if (tc != 0)
  43847. {
  43848. tc->isBeingDragged = false;
  43849. Toolbar* const tb = tc->getToolbar();
  43850. if (tb != 0)
  43851. tb->updateAllItemPositions (true);
  43852. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43853. delete tc;
  43854. }
  43855. }
  43856. void parentSizeChanged()
  43857. {
  43858. setBounds (0, 0, getParentWidth(), getParentHeight());
  43859. }
  43860. juce_UseDebuggingNewOperator
  43861. private:
  43862. bool isDragging;
  43863. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43864. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43865. };
  43866. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43867. const String& labelText,
  43868. const bool isBeingUsedAsAButton_)
  43869. : Button (labelText),
  43870. itemId (itemId_),
  43871. mode (normalMode),
  43872. toolbarStyle (Toolbar::iconsOnly),
  43873. dragOffsetX (0),
  43874. dragOffsetY (0),
  43875. isActive (true),
  43876. isBeingDragged (false),
  43877. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43878. {
  43879. // Your item ID can't be 0!
  43880. jassert (itemId_ != 0);
  43881. }
  43882. ToolbarItemComponent::~ToolbarItemComponent()
  43883. {
  43884. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43885. overlayComp = 0;
  43886. }
  43887. Toolbar* ToolbarItemComponent::getToolbar() const
  43888. {
  43889. return dynamic_cast <Toolbar*> (getParentComponent());
  43890. }
  43891. bool ToolbarItemComponent::isToolbarVertical() const
  43892. {
  43893. const Toolbar* const t = getToolbar();
  43894. return t != 0 && t->isVertical();
  43895. }
  43896. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43897. {
  43898. if (toolbarStyle != newStyle)
  43899. {
  43900. toolbarStyle = newStyle;
  43901. repaint();
  43902. resized();
  43903. }
  43904. }
  43905. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43906. {
  43907. if (isBeingUsedAsAButton)
  43908. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43909. isMouseOver, isMouseDown, *this);
  43910. if (toolbarStyle != Toolbar::iconsOnly)
  43911. {
  43912. const int indent = contentArea.getX();
  43913. int y = indent;
  43914. int h = getHeight() - indent * 2;
  43915. if (toolbarStyle == Toolbar::iconsWithText)
  43916. {
  43917. y = contentArea.getBottom() + indent / 2;
  43918. h -= contentArea.getHeight();
  43919. }
  43920. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  43921. getButtonText(), *this);
  43922. }
  43923. if (! contentArea.isEmpty())
  43924. {
  43925. g.saveState();
  43926. g.setOrigin (contentArea.getX(), contentArea.getY());
  43927. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  43928. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  43929. g.restoreState();
  43930. }
  43931. }
  43932. void ToolbarItemComponent::resized()
  43933. {
  43934. if (toolbarStyle != Toolbar::textOnly)
  43935. {
  43936. const int indent = jmin (proportionOfWidth (0.08f),
  43937. proportionOfHeight (0.08f));
  43938. contentArea = Rectangle<int> (indent, indent,
  43939. getWidth() - indent * 2,
  43940. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  43941. : (getHeight() - indent * 2));
  43942. }
  43943. else
  43944. {
  43945. contentArea = Rectangle<int>();
  43946. }
  43947. contentAreaChanged (contentArea);
  43948. }
  43949. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  43950. {
  43951. if (mode != newMode)
  43952. {
  43953. mode = newMode;
  43954. repaint();
  43955. if (mode == normalMode)
  43956. {
  43957. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43958. overlayComp = 0;
  43959. }
  43960. else if (overlayComp == 0)
  43961. {
  43962. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  43963. overlayComp->parentSizeChanged();
  43964. }
  43965. resized();
  43966. }
  43967. }
  43968. END_JUCE_NAMESPACE
  43969. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  43970. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  43971. BEGIN_JUCE_NAMESPACE
  43972. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  43973. Toolbar* const toolbar_)
  43974. : factory (factory_),
  43975. toolbar (toolbar_)
  43976. {
  43977. Component* const itemHolder = new Component();
  43978. Array <int> allIds;
  43979. factory_.getAllToolbarItemIds (allIds);
  43980. for (int i = 0; i < allIds.size(); ++i)
  43981. {
  43982. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  43983. jassert (tc != 0);
  43984. if (tc != 0)
  43985. {
  43986. itemHolder->addAndMakeVisible (tc);
  43987. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  43988. }
  43989. }
  43990. viewport = new Viewport();
  43991. viewport->setViewedComponent (itemHolder);
  43992. addAndMakeVisible (viewport);
  43993. }
  43994. ToolbarItemPalette::~ToolbarItemPalette()
  43995. {
  43996. viewport->getViewedComponent()->deleteAllChildren();
  43997. deleteAllChildren();
  43998. }
  43999. void ToolbarItemPalette::resized()
  44000. {
  44001. viewport->setBoundsInset (BorderSize (1));
  44002. Component* const itemHolder = viewport->getViewedComponent();
  44003. const int indent = 8;
  44004. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44005. const int height = toolbar->getThickness();
  44006. int x = indent;
  44007. int y = indent;
  44008. int maxX = 0;
  44009. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44010. {
  44011. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44012. if (tc != 0)
  44013. {
  44014. tc->setStyle (toolbar->getStyle());
  44015. int preferredSize = 1, minSize = 1, maxSize = 1;
  44016. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44017. {
  44018. if (x + preferredSize > preferredWidth && x > indent)
  44019. {
  44020. x = indent;
  44021. y += height;
  44022. }
  44023. tc->setBounds (x, y, preferredSize, height);
  44024. x += preferredSize + 8;
  44025. maxX = jmax (maxX, x);
  44026. }
  44027. }
  44028. }
  44029. itemHolder->setSize (maxX, y + height + 8);
  44030. }
  44031. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44032. {
  44033. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44034. jassert (tc != 0);
  44035. if (tc != 0)
  44036. {
  44037. tc->setBounds (comp->getBounds());
  44038. tc->setStyle (toolbar->getStyle());
  44039. tc->setEditingMode (comp->getEditingMode());
  44040. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44041. }
  44042. }
  44043. END_JUCE_NAMESPACE
  44044. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  44045. /*** Start of inlined file: juce_TreeView.cpp ***/
  44046. BEGIN_JUCE_NAMESPACE
  44047. class TreeViewContentComponent : public Component,
  44048. public TooltipClient
  44049. {
  44050. public:
  44051. TreeViewContentComponent (TreeView* const owner_)
  44052. : owner (owner_),
  44053. buttonUnderMouse (0),
  44054. isDragging (false)
  44055. {
  44056. }
  44057. ~TreeViewContentComponent()
  44058. {
  44059. deleteAllChildren();
  44060. }
  44061. void mouseDown (const MouseEvent& e)
  44062. {
  44063. updateButtonUnderMouse (e);
  44064. isDragging = false;
  44065. needSelectionOnMouseUp = false;
  44066. Rectangle<int> pos;
  44067. TreeViewItem* const item = findItemAt (e.y, pos);
  44068. if (item == 0)
  44069. return;
  44070. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44071. // as selection clicks)
  44072. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44073. {
  44074. if (e.x >= pos.getX() - owner->getIndentSize())
  44075. item->setOpen (! item->isOpen());
  44076. // (clicks to the left of an open/close button are ignored)
  44077. }
  44078. else
  44079. {
  44080. // mouse-down inside the body of the item..
  44081. if (! owner->isMultiSelectEnabled())
  44082. item->setSelected (true, true);
  44083. else if (item->isSelected())
  44084. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44085. else
  44086. selectBasedOnModifiers (item, e.mods);
  44087. if (e.x >= pos.getX())
  44088. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  44089. }
  44090. }
  44091. void mouseUp (const MouseEvent& e)
  44092. {
  44093. updateButtonUnderMouse (e);
  44094. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44095. {
  44096. Rectangle<int> pos;
  44097. TreeViewItem* const item = findItemAt (e.y, pos);
  44098. if (item != 0)
  44099. selectBasedOnModifiers (item, e.mods);
  44100. }
  44101. }
  44102. void mouseDoubleClick (const MouseEvent& e)
  44103. {
  44104. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44105. {
  44106. Rectangle<int> pos;
  44107. TreeViewItem* const item = findItemAt (e.y, pos);
  44108. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44109. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  44110. }
  44111. }
  44112. void mouseDrag (const MouseEvent& e)
  44113. {
  44114. if (isEnabled()
  44115. && ! (isDragging || e.mouseWasClicked()
  44116. || e.getDistanceFromDragStart() < 5
  44117. || e.mods.isPopupMenu()))
  44118. {
  44119. isDragging = true;
  44120. Rectangle<int> pos;
  44121. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44122. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44123. {
  44124. const String dragDescription (item->getDragSourceDescription());
  44125. if (dragDescription.isNotEmpty())
  44126. {
  44127. DragAndDropContainer* const dragContainer
  44128. = DragAndDropContainer::findParentDragContainerFor (this);
  44129. if (dragContainer != 0)
  44130. {
  44131. pos.setSize (pos.getWidth(), item->itemHeight);
  44132. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44133. dragImage->multiplyAllAlphas (0.6f);
  44134. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44135. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44136. }
  44137. else
  44138. {
  44139. // to be able to do a drag-and-drop operation, the treeview needs to
  44140. // be inside a component which is also a DragAndDropContainer.
  44141. jassertfalse
  44142. }
  44143. }
  44144. }
  44145. }
  44146. }
  44147. void mouseMove (const MouseEvent& e)
  44148. {
  44149. updateButtonUnderMouse (e);
  44150. }
  44151. void mouseExit (const MouseEvent& e)
  44152. {
  44153. updateButtonUnderMouse (e);
  44154. }
  44155. void paint (Graphics& g);
  44156. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44157. static bool isMouseDraggingInChildCompOf (Component* const comp)
  44158. {
  44159. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  44160. {
  44161. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  44162. if (source->isDragging())
  44163. {
  44164. Component* const underMouse = source->getComponentUnderMouse();
  44165. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  44166. return true;
  44167. }
  44168. }
  44169. return false;
  44170. }
  44171. void updateComponents()
  44172. {
  44173. const int visibleTop = -getY();
  44174. const int visibleBottom = visibleTop + getParentHeight();
  44175. BitArray itemsToKeep;
  44176. TreeViewItem* item = owner->rootItem;
  44177. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44178. while (item != 0 && y < visibleBottom)
  44179. {
  44180. y += item->itemHeight;
  44181. if (y >= visibleTop)
  44182. {
  44183. const int index = rowComponentIds.indexOf (item->uid);
  44184. if (index < 0)
  44185. {
  44186. Component* const comp = item->createItemComponent();
  44187. if (comp != 0)
  44188. {
  44189. addAndMakeVisible (comp);
  44190. itemsToKeep.setBit (rowComponentItems.size());
  44191. rowComponentItems.add (item);
  44192. rowComponentIds.add (item->uid);
  44193. rowComponents.add (comp);
  44194. }
  44195. }
  44196. else
  44197. {
  44198. itemsToKeep.setBit (index);
  44199. }
  44200. }
  44201. item = item->getNextVisibleItem (true);
  44202. }
  44203. for (int i = rowComponentItems.size(); --i >= 0;)
  44204. {
  44205. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44206. bool keep = false;
  44207. if (isParentOf (comp))
  44208. {
  44209. if (itemsToKeep[i])
  44210. {
  44211. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44212. Rectangle<int> pos (item->getItemPosition (false));
  44213. pos.setSize (pos.getWidth(), item->itemHeight);
  44214. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44215. {
  44216. keep = true;
  44217. comp->setBounds (pos);
  44218. }
  44219. }
  44220. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  44221. {
  44222. keep = true;
  44223. comp->setSize (0, 0);
  44224. }
  44225. }
  44226. if (! keep)
  44227. {
  44228. delete comp;
  44229. rowComponents.remove (i);
  44230. rowComponentIds.remove (i);
  44231. rowComponentItems.remove (i);
  44232. }
  44233. }
  44234. }
  44235. void updateButtonUnderMouse (const MouseEvent& e)
  44236. {
  44237. TreeViewItem* newItem = 0;
  44238. if (owner->openCloseButtonsVisible)
  44239. {
  44240. Rectangle<int> pos;
  44241. TreeViewItem* item = findItemAt (e.y, pos);
  44242. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44243. {
  44244. newItem = item;
  44245. if (! newItem->mightContainSubItems())
  44246. newItem = 0;
  44247. }
  44248. }
  44249. if (buttonUnderMouse != newItem)
  44250. {
  44251. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44252. {
  44253. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44254. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44255. }
  44256. buttonUnderMouse = newItem;
  44257. if (buttonUnderMouse != 0)
  44258. {
  44259. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44260. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44261. }
  44262. }
  44263. }
  44264. bool isMouseOverButton (TreeViewItem* item) const throw()
  44265. {
  44266. return item == buttonUnderMouse;
  44267. }
  44268. void resized()
  44269. {
  44270. owner->itemsChanged();
  44271. }
  44272. const String getTooltip()
  44273. {
  44274. Rectangle<int> pos;
  44275. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44276. if (item != 0)
  44277. return item->getTooltip();
  44278. return owner->getTooltip();
  44279. }
  44280. juce_UseDebuggingNewOperator
  44281. private:
  44282. TreeView* const owner;
  44283. VoidArray rowComponentItems;
  44284. Array <int> rowComponentIds;
  44285. VoidArray rowComponents;
  44286. TreeViewItem* buttonUnderMouse;
  44287. bool isDragging, needSelectionOnMouseUp;
  44288. TreeViewContentComponent (const TreeViewContentComponent&);
  44289. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44290. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44291. {
  44292. TreeViewItem* firstSelected = 0;
  44293. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44294. {
  44295. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44296. jassert (lastSelected != 0);
  44297. int rowStart = firstSelected->getRowNumberInTree();
  44298. int rowEnd = lastSelected->getRowNumberInTree();
  44299. if (rowStart > rowEnd)
  44300. swapVariables (rowStart, rowEnd);
  44301. int ourRow = item->getRowNumberInTree();
  44302. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44303. if (ourRow > otherEnd)
  44304. swapVariables (ourRow, otherEnd);
  44305. for (int i = ourRow; i <= otherEnd; ++i)
  44306. owner->getItemOnRow (i)->setSelected (true, false);
  44307. }
  44308. else
  44309. {
  44310. const bool cmd = modifiers.isCommandDown();
  44311. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44312. }
  44313. }
  44314. bool containsItem (TreeViewItem* const item) const
  44315. {
  44316. for (int i = rowComponentItems.size(); --i >= 0;)
  44317. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44318. return true;
  44319. return false;
  44320. }
  44321. };
  44322. class TreeViewport : public Viewport
  44323. {
  44324. public:
  44325. TreeViewport() throw() {}
  44326. ~TreeViewport() throw() {}
  44327. void updateComponents()
  44328. {
  44329. if (getViewedComponent() != 0)
  44330. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44331. repaint();
  44332. }
  44333. void visibleAreaChanged (int, int, int, int)
  44334. {
  44335. updateComponents();
  44336. }
  44337. juce_UseDebuggingNewOperator
  44338. private:
  44339. TreeViewport (const TreeViewport&);
  44340. TreeViewport& operator= (const TreeViewport&);
  44341. };
  44342. TreeView::TreeView (const String& componentName)
  44343. : Component (componentName),
  44344. rootItem (0),
  44345. dragInsertPointHighlight (0),
  44346. dragTargetGroupHighlight (0),
  44347. indentSize (24),
  44348. defaultOpenness (false),
  44349. needsRecalculating (true),
  44350. rootItemVisible (true),
  44351. multiSelectEnabled (false),
  44352. openCloseButtonsVisible (true)
  44353. {
  44354. addAndMakeVisible (viewport = new TreeViewport());
  44355. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44356. viewport->setWantsKeyboardFocus (false);
  44357. setWantsKeyboardFocus (true);
  44358. }
  44359. TreeView::~TreeView()
  44360. {
  44361. if (rootItem != 0)
  44362. rootItem->setOwnerView (0);
  44363. deleteAllChildren();
  44364. }
  44365. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44366. {
  44367. if (rootItem != newRootItem)
  44368. {
  44369. if (newRootItem != 0)
  44370. {
  44371. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44372. if (newRootItem->ownerView != 0)
  44373. newRootItem->ownerView->setRootItem (0);
  44374. }
  44375. if (rootItem != 0)
  44376. rootItem->setOwnerView (0);
  44377. rootItem = newRootItem;
  44378. if (newRootItem != 0)
  44379. newRootItem->setOwnerView (this);
  44380. needsRecalculating = true;
  44381. handleAsyncUpdate();
  44382. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44383. {
  44384. rootItem->setOpen (false); // force a re-open
  44385. rootItem->setOpen (true);
  44386. }
  44387. }
  44388. }
  44389. void TreeView::deleteRootItem()
  44390. {
  44391. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44392. setRootItem (0);
  44393. }
  44394. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44395. {
  44396. rootItemVisible = shouldBeVisible;
  44397. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44398. {
  44399. rootItem->setOpen (false); // force a re-open
  44400. rootItem->setOpen (true);
  44401. }
  44402. itemsChanged();
  44403. }
  44404. void TreeView::colourChanged()
  44405. {
  44406. setOpaque (findColour (backgroundColourId).isOpaque());
  44407. repaint();
  44408. }
  44409. void TreeView::setIndentSize (const int newIndentSize)
  44410. {
  44411. if (indentSize != newIndentSize)
  44412. {
  44413. indentSize = newIndentSize;
  44414. resized();
  44415. }
  44416. }
  44417. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44418. {
  44419. if (defaultOpenness != isOpenByDefault)
  44420. {
  44421. defaultOpenness = isOpenByDefault;
  44422. itemsChanged();
  44423. }
  44424. }
  44425. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44426. {
  44427. multiSelectEnabled = canMultiSelect;
  44428. }
  44429. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44430. {
  44431. if (openCloseButtonsVisible != shouldBeVisible)
  44432. {
  44433. openCloseButtonsVisible = shouldBeVisible;
  44434. itemsChanged();
  44435. }
  44436. }
  44437. void TreeView::clearSelectedItems()
  44438. {
  44439. if (rootItem != 0)
  44440. rootItem->deselectAllRecursively();
  44441. }
  44442. int TreeView::getNumSelectedItems() const throw()
  44443. {
  44444. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44445. }
  44446. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44447. {
  44448. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44449. }
  44450. int TreeView::getNumRowsInTree() const
  44451. {
  44452. if (rootItem != 0)
  44453. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44454. return 0;
  44455. }
  44456. TreeViewItem* TreeView::getItemOnRow (int index) const
  44457. {
  44458. if (! rootItemVisible)
  44459. ++index;
  44460. if (rootItem != 0 && index >= 0)
  44461. return rootItem->getItemOnRow (index);
  44462. return 0;
  44463. }
  44464. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44465. {
  44466. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44467. Rectangle<int> pos;
  44468. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44469. }
  44470. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44471. {
  44472. if (rootItem == 0)
  44473. return 0;
  44474. return rootItem->findItemFromIdentifierString (identifierString);
  44475. }
  44476. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44477. {
  44478. XmlElement* e = 0;
  44479. if (rootItem != 0)
  44480. {
  44481. e = rootItem->getOpennessState();
  44482. if (e != 0 && alsoIncludeScrollPosition)
  44483. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44484. }
  44485. return e;
  44486. }
  44487. void TreeView::restoreOpennessState (const XmlElement& newState)
  44488. {
  44489. if (rootItem != 0)
  44490. {
  44491. rootItem->restoreOpennessState (newState);
  44492. if (newState.hasAttribute (T("scrollPos")))
  44493. viewport->setViewPosition (viewport->getViewPositionX(),
  44494. newState.getIntAttribute (T("scrollPos")));
  44495. }
  44496. }
  44497. void TreeView::paint (Graphics& g)
  44498. {
  44499. g.fillAll (findColour (backgroundColourId));
  44500. }
  44501. void TreeView::resized()
  44502. {
  44503. viewport->setBounds (0, 0, getWidth(), getHeight());
  44504. itemsChanged();
  44505. handleAsyncUpdate();
  44506. }
  44507. void TreeView::enablementChanged()
  44508. {
  44509. repaint();
  44510. }
  44511. void TreeView::moveSelectedRow (int delta)
  44512. {
  44513. if (delta == 0)
  44514. return;
  44515. int rowSelected = 0;
  44516. TreeViewItem* const firstSelected = getSelectedItem (0);
  44517. if (firstSelected != 0)
  44518. rowSelected = firstSelected->getRowNumberInTree();
  44519. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44520. for (;;)
  44521. {
  44522. TreeViewItem* item = getItemOnRow (rowSelected);
  44523. if (item != 0)
  44524. {
  44525. if (! item->canBeSelected())
  44526. {
  44527. // if the row we want to highlight doesn't allow it, try skipping
  44528. // to the next item..
  44529. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44530. rowSelected + (delta < 0 ? -1 : 1));
  44531. if (rowSelected != nextRowToTry)
  44532. {
  44533. rowSelected = nextRowToTry;
  44534. continue;
  44535. }
  44536. else
  44537. {
  44538. break;
  44539. }
  44540. }
  44541. item->setSelected (true, true);
  44542. scrollToKeepItemVisible (item);
  44543. }
  44544. break;
  44545. }
  44546. }
  44547. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44548. {
  44549. if (item != 0 && item->ownerView == this)
  44550. {
  44551. handleAsyncUpdate();
  44552. item = item->getDeepestOpenParentItem();
  44553. int y = item->y;
  44554. int viewTop = viewport->getViewPositionY();
  44555. if (y < viewTop)
  44556. {
  44557. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44558. }
  44559. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44560. {
  44561. viewport->setViewPosition (viewport->getViewPositionX(),
  44562. (y + item->itemHeight) - viewport->getViewHeight());
  44563. }
  44564. }
  44565. }
  44566. bool TreeView::keyPressed (const KeyPress& key)
  44567. {
  44568. if (key.isKeyCode (KeyPress::upKey))
  44569. {
  44570. moveSelectedRow (-1);
  44571. }
  44572. else if (key.isKeyCode (KeyPress::downKey))
  44573. {
  44574. moveSelectedRow (1);
  44575. }
  44576. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44577. {
  44578. if (rootItem != 0)
  44579. {
  44580. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44581. if (key.isKeyCode (KeyPress::pageUpKey))
  44582. rowsOnScreen = -rowsOnScreen;
  44583. moveSelectedRow (rowsOnScreen);
  44584. }
  44585. }
  44586. else if (key.isKeyCode (KeyPress::homeKey))
  44587. {
  44588. moveSelectedRow (-0x3fffffff);
  44589. }
  44590. else if (key.isKeyCode (KeyPress::endKey))
  44591. {
  44592. moveSelectedRow (0x3fffffff);
  44593. }
  44594. else if (key.isKeyCode (KeyPress::returnKey))
  44595. {
  44596. TreeViewItem* const firstSelected = getSelectedItem (0);
  44597. if (firstSelected != 0)
  44598. firstSelected->setOpen (! firstSelected->isOpen());
  44599. }
  44600. else if (key.isKeyCode (KeyPress::leftKey))
  44601. {
  44602. TreeViewItem* const firstSelected = getSelectedItem (0);
  44603. if (firstSelected != 0)
  44604. {
  44605. if (firstSelected->isOpen())
  44606. {
  44607. firstSelected->setOpen (false);
  44608. }
  44609. else
  44610. {
  44611. TreeViewItem* parent = firstSelected->parentItem;
  44612. if ((! rootItemVisible) && parent == rootItem)
  44613. parent = 0;
  44614. if (parent != 0)
  44615. {
  44616. parent->setSelected (true, true);
  44617. scrollToKeepItemVisible (parent);
  44618. }
  44619. }
  44620. }
  44621. }
  44622. else if (key.isKeyCode (KeyPress::rightKey))
  44623. {
  44624. TreeViewItem* const firstSelected = getSelectedItem (0);
  44625. if (firstSelected != 0)
  44626. {
  44627. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44628. moveSelectedRow (1);
  44629. else
  44630. firstSelected->setOpen (true);
  44631. }
  44632. }
  44633. else
  44634. {
  44635. return false;
  44636. }
  44637. return true;
  44638. }
  44639. void TreeView::itemsChanged() throw()
  44640. {
  44641. needsRecalculating = true;
  44642. repaint();
  44643. triggerAsyncUpdate();
  44644. }
  44645. void TreeView::handleAsyncUpdate()
  44646. {
  44647. if (needsRecalculating)
  44648. {
  44649. needsRecalculating = false;
  44650. const ScopedLock sl (nodeAlterationLock);
  44651. if (rootItem != 0)
  44652. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44653. ((TreeViewport*) viewport)->updateComponents();
  44654. if (rootItem != 0)
  44655. {
  44656. viewport->getViewedComponent()
  44657. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44658. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44659. }
  44660. else
  44661. {
  44662. viewport->getViewedComponent()->setSize (0, 0);
  44663. }
  44664. }
  44665. }
  44666. class TreeViewDragInsertPointHighlight : public Component
  44667. {
  44668. public:
  44669. TreeViewDragInsertPointHighlight()
  44670. : lastItem (0)
  44671. {
  44672. setSize (100, 12);
  44673. setAlwaysOnTop (true);
  44674. setInterceptsMouseClicks (false, false);
  44675. }
  44676. ~TreeViewDragInsertPointHighlight() {}
  44677. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44678. {
  44679. lastItem = item;
  44680. lastIndex = insertIndex;
  44681. const int offset = getHeight() / 2;
  44682. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44683. }
  44684. void paint (Graphics& g)
  44685. {
  44686. Path p;
  44687. const float h = (float) getHeight();
  44688. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44689. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44690. p.lineTo ((float) getWidth(), h / 2.0f);
  44691. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44692. g.strokePath (p, PathStrokeType (2.0f));
  44693. }
  44694. TreeViewItem* lastItem;
  44695. int lastIndex;
  44696. };
  44697. class TreeViewDragTargetGroupHighlight : public Component
  44698. {
  44699. public:
  44700. TreeViewDragTargetGroupHighlight()
  44701. {
  44702. setAlwaysOnTop (true);
  44703. setInterceptsMouseClicks (false, false);
  44704. }
  44705. ~TreeViewDragTargetGroupHighlight() {}
  44706. void setTargetPosition (TreeViewItem* const item) throw()
  44707. {
  44708. Rectangle<int> r (item->getItemPosition (true));
  44709. r.setHeight (item->getItemHeight());
  44710. setBounds (r);
  44711. }
  44712. void paint (Graphics& g)
  44713. {
  44714. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44715. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44716. }
  44717. };
  44718. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44719. {
  44720. beginDragAutoRepeat (1000 / 30);
  44721. if (dragInsertPointHighlight == 0)
  44722. {
  44723. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  44724. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  44725. }
  44726. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  44727. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44728. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  44729. ->setTargetPosition (item);
  44730. }
  44731. void TreeView::hideDragHighlight() throw()
  44732. {
  44733. deleteAndZero (dragInsertPointHighlight);
  44734. deleteAndZero (dragTargetGroupHighlight);
  44735. }
  44736. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44737. const StringArray& files, const String& sourceDescription,
  44738. Component* sourceComponent) const throw()
  44739. {
  44740. insertIndex = 0;
  44741. TreeViewItem* item = getItemAt (y);
  44742. if (item == 0)
  44743. return 0;
  44744. Rectangle<int> itemPos (item->getItemPosition (true));
  44745. insertIndex = item->getIndexInParent();
  44746. const int oldY = y;
  44747. y = itemPos.getY();
  44748. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44749. {
  44750. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44751. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44752. {
  44753. // Check if we're trying to drag into an empty group item..
  44754. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44755. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44756. {
  44757. insertIndex = 0;
  44758. x = itemPos.getX() + getIndentSize();
  44759. y = itemPos.getBottom();
  44760. return item;
  44761. }
  44762. }
  44763. }
  44764. if (oldY > itemPos.getCentreY())
  44765. {
  44766. y += item->getItemHeight();
  44767. while (item->isLastOfSiblings() && item->parentItem != 0
  44768. && item->parentItem->parentItem != 0)
  44769. {
  44770. if (x > itemPos.getX())
  44771. break;
  44772. item = item->parentItem;
  44773. itemPos = item->getItemPosition (true);
  44774. insertIndex = item->getIndexInParent();
  44775. }
  44776. ++insertIndex;
  44777. }
  44778. x = itemPos.getX();
  44779. return item->parentItem;
  44780. }
  44781. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44782. {
  44783. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44784. int insertIndex;
  44785. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44786. if (item != 0)
  44787. {
  44788. if (scrolled || dragInsertPointHighlight == 0
  44789. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  44790. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  44791. {
  44792. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44793. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44794. showDragHighlight (item, insertIndex, x, y);
  44795. else
  44796. hideDragHighlight();
  44797. }
  44798. }
  44799. else
  44800. {
  44801. hideDragHighlight();
  44802. }
  44803. }
  44804. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44805. {
  44806. hideDragHighlight();
  44807. int insertIndex;
  44808. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44809. if (item != 0)
  44810. {
  44811. if (files.size() > 0)
  44812. {
  44813. if (item->isInterestedInFileDrag (files))
  44814. item->filesDropped (files, insertIndex);
  44815. }
  44816. else
  44817. {
  44818. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44819. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44820. }
  44821. }
  44822. }
  44823. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44824. {
  44825. return true;
  44826. }
  44827. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44828. {
  44829. fileDragMove (files, x, y);
  44830. }
  44831. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44832. {
  44833. handleDrag (files, String::empty, 0, x, y);
  44834. }
  44835. void TreeView::fileDragExit (const StringArray&)
  44836. {
  44837. hideDragHighlight();
  44838. }
  44839. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44840. {
  44841. handleDrop (files, String::empty, 0, x, y);
  44842. }
  44843. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44844. {
  44845. return true;
  44846. }
  44847. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44848. {
  44849. itemDragMove (sourceDescription, sourceComponent, x, y);
  44850. }
  44851. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44852. {
  44853. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44854. }
  44855. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44856. {
  44857. hideDragHighlight();
  44858. }
  44859. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44860. {
  44861. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44862. }
  44863. void TreeViewContentComponent::paint (Graphics& g)
  44864. {
  44865. if (owner->rootItem != 0)
  44866. {
  44867. owner->handleAsyncUpdate();
  44868. if (! owner->rootItemVisible)
  44869. g.setOrigin (0, -owner->rootItem->itemHeight);
  44870. owner->rootItem->paintRecursively (g, getWidth());
  44871. }
  44872. }
  44873. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44874. {
  44875. if (owner->rootItem != 0)
  44876. {
  44877. owner->handleAsyncUpdate();
  44878. if (! owner->rootItemVisible)
  44879. y += owner->rootItem->itemHeight;
  44880. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44881. if (ti != 0)
  44882. itemPosition = ti->getItemPosition (false);
  44883. return ti;
  44884. }
  44885. return 0;
  44886. }
  44887. enum TreeViewOpenness
  44888. {
  44889. opennessDefault = 0,
  44890. opennessClosed = 1,
  44891. opennessOpen = 2
  44892. };
  44893. TreeViewItem::TreeViewItem()
  44894. : ownerView (0),
  44895. parentItem (0),
  44896. y (0),
  44897. itemHeight (0),
  44898. totalHeight (0),
  44899. selected (false),
  44900. redrawNeeded (true),
  44901. drawLinesInside (true),
  44902. drawsInLeftMargin (false),
  44903. openness (opennessDefault)
  44904. {
  44905. static int nextUID = 0;
  44906. uid = nextUID++;
  44907. }
  44908. TreeViewItem::~TreeViewItem()
  44909. {
  44910. }
  44911. const String TreeViewItem::getUniqueName() const
  44912. {
  44913. return String::empty;
  44914. }
  44915. void TreeViewItem::itemOpennessChanged (bool)
  44916. {
  44917. }
  44918. int TreeViewItem::getNumSubItems() const throw()
  44919. {
  44920. return subItems.size();
  44921. }
  44922. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  44923. {
  44924. return subItems [index];
  44925. }
  44926. void TreeViewItem::clearSubItems()
  44927. {
  44928. if (subItems.size() > 0)
  44929. {
  44930. if (ownerView != 0)
  44931. {
  44932. const ScopedLock sl (ownerView->nodeAlterationLock);
  44933. subItems.clear();
  44934. treeHasChanged();
  44935. }
  44936. else
  44937. {
  44938. subItems.clear();
  44939. }
  44940. }
  44941. }
  44942. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  44943. {
  44944. if (newItem != 0)
  44945. {
  44946. newItem->parentItem = this;
  44947. newItem->setOwnerView (ownerView);
  44948. newItem->y = 0;
  44949. newItem->itemHeight = newItem->getItemHeight();
  44950. newItem->totalHeight = 0;
  44951. newItem->itemWidth = newItem->getItemWidth();
  44952. newItem->totalWidth = 0;
  44953. if (ownerView != 0)
  44954. {
  44955. const ScopedLock sl (ownerView->nodeAlterationLock);
  44956. subItems.insert (insertPosition, newItem);
  44957. treeHasChanged();
  44958. if (newItem->isOpen())
  44959. newItem->itemOpennessChanged (true);
  44960. }
  44961. else
  44962. {
  44963. subItems.insert (insertPosition, newItem);
  44964. if (newItem->isOpen())
  44965. newItem->itemOpennessChanged (true);
  44966. }
  44967. }
  44968. }
  44969. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  44970. {
  44971. if (ownerView != 0)
  44972. {
  44973. const ScopedLock sl (ownerView->nodeAlterationLock);
  44974. if (((unsigned int) index) < (unsigned int) subItems.size())
  44975. {
  44976. subItems.remove (index, deleteItem);
  44977. treeHasChanged();
  44978. }
  44979. }
  44980. else
  44981. {
  44982. subItems.remove (index, deleteItem);
  44983. }
  44984. }
  44985. bool TreeViewItem::isOpen() const throw()
  44986. {
  44987. if (openness == opennessDefault)
  44988. return ownerView != 0 && ownerView->defaultOpenness;
  44989. else
  44990. return openness == opennessOpen;
  44991. }
  44992. void TreeViewItem::setOpen (const bool shouldBeOpen)
  44993. {
  44994. if (isOpen() != shouldBeOpen)
  44995. {
  44996. openness = shouldBeOpen ? opennessOpen
  44997. : opennessClosed;
  44998. treeHasChanged();
  44999. itemOpennessChanged (isOpen());
  45000. }
  45001. }
  45002. bool TreeViewItem::isSelected() const throw()
  45003. {
  45004. return selected;
  45005. }
  45006. void TreeViewItem::deselectAllRecursively()
  45007. {
  45008. setSelected (false, false);
  45009. for (int i = 0; i < subItems.size(); ++i)
  45010. subItems.getUnchecked(i)->deselectAllRecursively();
  45011. }
  45012. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45013. const bool deselectOtherItemsFirst)
  45014. {
  45015. if (shouldBeSelected && ! canBeSelected())
  45016. return;
  45017. if (deselectOtherItemsFirst)
  45018. getTopLevelItem()->deselectAllRecursively();
  45019. if (shouldBeSelected != selected)
  45020. {
  45021. selected = shouldBeSelected;
  45022. if (ownerView != 0)
  45023. ownerView->repaint();
  45024. itemSelectionChanged (shouldBeSelected);
  45025. }
  45026. }
  45027. void TreeViewItem::paintItem (Graphics&, int, int)
  45028. {
  45029. }
  45030. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45031. {
  45032. ownerView->getLookAndFeel()
  45033. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45034. }
  45035. void TreeViewItem::itemClicked (const MouseEvent&)
  45036. {
  45037. }
  45038. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45039. {
  45040. if (mightContainSubItems())
  45041. setOpen (! isOpen());
  45042. }
  45043. void TreeViewItem::itemSelectionChanged (bool)
  45044. {
  45045. }
  45046. const String TreeViewItem::getTooltip()
  45047. {
  45048. return String::empty;
  45049. }
  45050. const String TreeViewItem::getDragSourceDescription()
  45051. {
  45052. return String::empty;
  45053. }
  45054. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45055. {
  45056. return false;
  45057. }
  45058. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45059. {
  45060. }
  45061. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45062. {
  45063. return false;
  45064. }
  45065. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45066. {
  45067. }
  45068. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45069. {
  45070. const int indentX = getIndentX();
  45071. int width = itemWidth;
  45072. if (ownerView != 0 && width < 0)
  45073. width = ownerView->viewport->getViewWidth() - indentX;
  45074. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  45075. if (relativeToTreeViewTopLeft)
  45076. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45077. r.getY() - ownerView->viewport->getViewPositionY());
  45078. return r;
  45079. }
  45080. void TreeViewItem::treeHasChanged() const throw()
  45081. {
  45082. if (ownerView != 0)
  45083. ownerView->itemsChanged();
  45084. }
  45085. void TreeViewItem::repaintItem() const
  45086. {
  45087. if (ownerView != 0 && areAllParentsOpen())
  45088. {
  45089. const Rectangle<int> r (getItemPosition (true));
  45090. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45091. }
  45092. }
  45093. bool TreeViewItem::areAllParentsOpen() const throw()
  45094. {
  45095. return parentItem == 0
  45096. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45097. }
  45098. void TreeViewItem::updatePositions (int newY)
  45099. {
  45100. y = newY;
  45101. itemHeight = getItemHeight();
  45102. totalHeight = itemHeight;
  45103. itemWidth = getItemWidth();
  45104. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45105. if (isOpen())
  45106. {
  45107. newY += totalHeight;
  45108. for (int i = 0; i < subItems.size(); ++i)
  45109. {
  45110. TreeViewItem* const ti = subItems.getUnchecked(i);
  45111. ti->updatePositions (newY);
  45112. newY += ti->totalHeight;
  45113. totalHeight += ti->totalHeight;
  45114. totalWidth = jmax (totalWidth, ti->totalWidth);
  45115. }
  45116. }
  45117. }
  45118. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45119. {
  45120. TreeViewItem* result = this;
  45121. TreeViewItem* item = this;
  45122. while (item->parentItem != 0)
  45123. {
  45124. item = item->parentItem;
  45125. if (! item->isOpen())
  45126. result = item;
  45127. }
  45128. return result;
  45129. }
  45130. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45131. {
  45132. ownerView = newOwner;
  45133. for (int i = subItems.size(); --i >= 0;)
  45134. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45135. }
  45136. int TreeViewItem::getIndentX() const throw()
  45137. {
  45138. const int indentWidth = ownerView->getIndentSize();
  45139. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45140. if (! ownerView->openCloseButtonsVisible)
  45141. x -= indentWidth;
  45142. TreeViewItem* p = parentItem;
  45143. while (p != 0)
  45144. {
  45145. x += indentWidth;
  45146. p = p->parentItem;
  45147. }
  45148. return x;
  45149. }
  45150. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45151. {
  45152. drawsInLeftMargin = canDrawInLeftMargin;
  45153. }
  45154. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45155. {
  45156. jassert (ownerView != 0);
  45157. if (ownerView == 0)
  45158. return;
  45159. const int indent = getIndentX();
  45160. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45161. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45162. const float halfH = itemHeight * 0.5f;
  45163. int depth = 0;
  45164. TreeViewItem* p = parentItem;
  45165. while (p != 0)
  45166. {
  45167. ++depth;
  45168. p = p->parentItem;
  45169. }
  45170. if (! ownerView->rootItemVisible)
  45171. --depth;
  45172. const int indentWidth = ownerView->getIndentSize();
  45173. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45174. {
  45175. float x = (depth + 0.5f) * indentWidth;
  45176. if (depth >= 0)
  45177. {
  45178. if (parentItem != 0 && parentItem->drawLinesInside)
  45179. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45180. if ((parentItem != 0 && parentItem->drawLinesInside)
  45181. || (parentItem == 0 && drawLinesInside))
  45182. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45183. }
  45184. p = parentItem;
  45185. int d = depth;
  45186. while (p != 0 && --d >= 0)
  45187. {
  45188. x -= (float) indentWidth;
  45189. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45190. && ! p->isLastOfSiblings())
  45191. {
  45192. g.drawLine (x, 0, x, (float) itemHeight);
  45193. }
  45194. p = p->parentItem;
  45195. }
  45196. if (mightContainSubItems())
  45197. {
  45198. g.saveState();
  45199. g.setOrigin (depth * indentWidth, 0);
  45200. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45201. paintOpenCloseButton (g, indentWidth, itemHeight,
  45202. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45203. ->isMouseOverButton (this));
  45204. g.restoreState();
  45205. }
  45206. }
  45207. {
  45208. g.saveState();
  45209. g.setOrigin (indent, 0);
  45210. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45211. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45212. paintItem (g, itemW, itemHeight);
  45213. g.restoreState();
  45214. }
  45215. if (isOpen())
  45216. {
  45217. const Rectangle<int> clip (g.getClipBounds());
  45218. for (int i = 0; i < subItems.size(); ++i)
  45219. {
  45220. TreeViewItem* const ti = subItems.getUnchecked(i);
  45221. const int relY = ti->y - y;
  45222. if (relY >= clip.getBottom())
  45223. break;
  45224. if (relY + ti->totalHeight >= clip.getY())
  45225. {
  45226. g.saveState();
  45227. g.setOrigin (0, relY);
  45228. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45229. ti->paintRecursively (g, width);
  45230. g.restoreState();
  45231. }
  45232. }
  45233. }
  45234. }
  45235. bool TreeViewItem::isLastOfSiblings() const throw()
  45236. {
  45237. return parentItem == 0
  45238. || parentItem->subItems.getLast() == this;
  45239. }
  45240. int TreeViewItem::getIndexInParent() const throw()
  45241. {
  45242. if (parentItem == 0)
  45243. return 0;
  45244. return parentItem->subItems.indexOf (this);
  45245. }
  45246. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45247. {
  45248. return (parentItem == 0) ? this
  45249. : parentItem->getTopLevelItem();
  45250. }
  45251. int TreeViewItem::getNumRows() const throw()
  45252. {
  45253. int num = 1;
  45254. if (isOpen())
  45255. {
  45256. for (int i = subItems.size(); --i >= 0;)
  45257. num += subItems.getUnchecked(i)->getNumRows();
  45258. }
  45259. return num;
  45260. }
  45261. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45262. {
  45263. if (index == 0)
  45264. return this;
  45265. if (index > 0 && isOpen())
  45266. {
  45267. --index;
  45268. for (int i = 0; i < subItems.size(); ++i)
  45269. {
  45270. TreeViewItem* const item = subItems.getUnchecked(i);
  45271. if (index == 0)
  45272. return item;
  45273. const int numRows = item->getNumRows();
  45274. if (numRows > index)
  45275. return item->getItemOnRow (index);
  45276. index -= numRows;
  45277. }
  45278. }
  45279. return 0;
  45280. }
  45281. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45282. {
  45283. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45284. {
  45285. const int h = itemHeight;
  45286. if (targetY < h)
  45287. return this;
  45288. if (isOpen())
  45289. {
  45290. targetY -= h;
  45291. for (int i = 0; i < subItems.size(); ++i)
  45292. {
  45293. TreeViewItem* const ti = subItems.getUnchecked(i);
  45294. if (targetY < ti->totalHeight)
  45295. return ti->findItemRecursively (targetY);
  45296. targetY -= ti->totalHeight;
  45297. }
  45298. }
  45299. }
  45300. return 0;
  45301. }
  45302. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45303. {
  45304. int total = 0;
  45305. if (isSelected())
  45306. ++total;
  45307. for (int i = subItems.size(); --i >= 0;)
  45308. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45309. return total;
  45310. }
  45311. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45312. {
  45313. if (isSelected())
  45314. {
  45315. if (index == 0)
  45316. return this;
  45317. --index;
  45318. }
  45319. if (index >= 0)
  45320. {
  45321. for (int i = 0; i < subItems.size(); ++i)
  45322. {
  45323. TreeViewItem* const item = subItems.getUnchecked(i);
  45324. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45325. if (found != 0)
  45326. return found;
  45327. index -= item->countSelectedItemsRecursively();
  45328. }
  45329. }
  45330. return 0;
  45331. }
  45332. int TreeViewItem::getRowNumberInTree() const throw()
  45333. {
  45334. if (parentItem != 0 && ownerView != 0)
  45335. {
  45336. int n = 1 + parentItem->getRowNumberInTree();
  45337. int ourIndex = parentItem->subItems.indexOf (this);
  45338. jassert (ourIndex >= 0);
  45339. while (--ourIndex >= 0)
  45340. n += parentItem->subItems [ourIndex]->getNumRows();
  45341. if (parentItem->parentItem == 0
  45342. && ! ownerView->rootItemVisible)
  45343. --n;
  45344. return n;
  45345. }
  45346. else
  45347. {
  45348. return 0;
  45349. }
  45350. }
  45351. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45352. {
  45353. drawLinesInside = drawLines;
  45354. }
  45355. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45356. {
  45357. if (recurse && isOpen() && subItems.size() > 0)
  45358. return subItems [0];
  45359. if (parentItem != 0)
  45360. {
  45361. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45362. if (nextIndex >= parentItem->subItems.size())
  45363. return parentItem->getNextVisibleItem (false);
  45364. return parentItem->subItems [nextIndex];
  45365. }
  45366. return 0;
  45367. }
  45368. const String TreeViewItem::getItemIdentifierString() const
  45369. {
  45370. String s;
  45371. if (parentItem != 0)
  45372. s = parentItem->getItemIdentifierString();
  45373. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45374. }
  45375. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45376. {
  45377. const String uid (getUniqueName());
  45378. if (uid == identifierString)
  45379. return this;
  45380. if (identifierString.startsWith (uid + T("/")))
  45381. {
  45382. const String remainingPath (identifierString.substring (uid.length() + 1));
  45383. bool wasOpen = isOpen();
  45384. setOpen (true);
  45385. for (int i = subItems.size(); --i >= 0;)
  45386. {
  45387. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45388. if (item != 0)
  45389. return item;
  45390. }
  45391. setOpen (wasOpen);
  45392. }
  45393. return 0;
  45394. }
  45395. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45396. {
  45397. if (e.hasTagName (T("CLOSED")))
  45398. {
  45399. setOpen (false);
  45400. }
  45401. else if (e.hasTagName (T("OPEN")))
  45402. {
  45403. setOpen (true);
  45404. forEachXmlChildElement (e, n)
  45405. {
  45406. const String id (n->getStringAttribute (T("id")));
  45407. for (int i = 0; i < subItems.size(); ++i)
  45408. {
  45409. TreeViewItem* const ti = subItems.getUnchecked(i);
  45410. if (ti->getUniqueName() == id)
  45411. {
  45412. ti->restoreOpennessState (*n);
  45413. break;
  45414. }
  45415. }
  45416. }
  45417. }
  45418. }
  45419. XmlElement* TreeViewItem::getOpennessState() const throw()
  45420. {
  45421. const String name (getUniqueName());
  45422. if (name.isNotEmpty())
  45423. {
  45424. XmlElement* e;
  45425. if (isOpen())
  45426. {
  45427. e = new XmlElement (T("OPEN"));
  45428. for (int i = 0; i < subItems.size(); ++i)
  45429. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45430. }
  45431. else
  45432. {
  45433. e = new XmlElement (T("CLOSED"));
  45434. }
  45435. e->setAttribute (T("id"), name);
  45436. return e;
  45437. }
  45438. else
  45439. {
  45440. // trying to save the openness for an element that has no name - this won't
  45441. // work because it needs the names to identify what to open.
  45442. jassertfalse
  45443. }
  45444. return 0;
  45445. }
  45446. END_JUCE_NAMESPACE
  45447. /*** End of inlined file: juce_TreeView.cpp ***/
  45448. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45449. BEGIN_JUCE_NAMESPACE
  45450. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45451. : fileList (listToShow)
  45452. {
  45453. }
  45454. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45455. {
  45456. }
  45457. FileBrowserListener::~FileBrowserListener()
  45458. {
  45459. }
  45460. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45461. {
  45462. listeners.add (listener);
  45463. }
  45464. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45465. {
  45466. listeners.remove (listener);
  45467. }
  45468. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45469. {
  45470. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45471. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45472. }
  45473. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45474. {
  45475. if (fileList.getDirectory().exists())
  45476. {
  45477. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45478. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45479. }
  45480. }
  45481. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45482. {
  45483. if (fileList.getDirectory().exists())
  45484. {
  45485. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45486. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45487. }
  45488. }
  45489. END_JUCE_NAMESPACE
  45490. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45491. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45492. BEGIN_JUCE_NAMESPACE
  45493. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45494. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45495. Time* creationTime, bool* isReadOnly);
  45496. bool juce_findFileNext (void* handle, String& resultFile,
  45497. bool* isDirectory, bool* isHidden, int64* fileSize,
  45498. Time* modTime, Time* creationTime, bool* isReadOnly);
  45499. void juce_findFileClose (void* handle);
  45500. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45501. TimeSliceThread& thread_)
  45502. : fileFilter (fileFilter_),
  45503. thread (thread_),
  45504. includeDirectories (false),
  45505. includeFiles (false),
  45506. ignoreHiddenFiles (true),
  45507. fileFindHandle (0),
  45508. shouldStop (true)
  45509. {
  45510. }
  45511. DirectoryContentsList::~DirectoryContentsList()
  45512. {
  45513. clear();
  45514. }
  45515. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45516. {
  45517. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45518. }
  45519. const File& DirectoryContentsList::getDirectory() const
  45520. {
  45521. return root;
  45522. }
  45523. void DirectoryContentsList::setDirectory (const File& directory,
  45524. const bool includeDirectories_,
  45525. const bool includeFiles_)
  45526. {
  45527. if (directory != root
  45528. || includeDirectories != includeDirectories_
  45529. || includeFiles != includeFiles_)
  45530. {
  45531. clear();
  45532. root = directory;
  45533. includeDirectories = includeDirectories_;
  45534. includeFiles = includeFiles_;
  45535. refresh();
  45536. }
  45537. }
  45538. void DirectoryContentsList::clear()
  45539. {
  45540. shouldStop = true;
  45541. thread.removeTimeSliceClient (this);
  45542. if (fileFindHandle != 0)
  45543. {
  45544. juce_findFileClose (fileFindHandle);
  45545. fileFindHandle = 0;
  45546. }
  45547. if (files.size() > 0)
  45548. {
  45549. files.clear();
  45550. changed();
  45551. }
  45552. }
  45553. void DirectoryContentsList::refresh()
  45554. {
  45555. clear();
  45556. if (root.isDirectory())
  45557. {
  45558. String fileFound;
  45559. bool fileFoundIsDir, isHidden, isReadOnly;
  45560. int64 fileSize;
  45561. Time modTime, creationTime;
  45562. String path (root.getFullPathName());
  45563. if (! path.endsWithChar (File::separator))
  45564. path += File::separator;
  45565. jassert (fileFindHandle == 0);
  45566. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  45567. &fileFoundIsDir,
  45568. &isHidden,
  45569. &fileSize,
  45570. &modTime,
  45571. &creationTime,
  45572. &isReadOnly);
  45573. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45574. {
  45575. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45576. fileSize, modTime, creationTime, isReadOnly))
  45577. {
  45578. changed();
  45579. }
  45580. }
  45581. shouldStop = false;
  45582. thread.addTimeSliceClient (this);
  45583. }
  45584. }
  45585. int DirectoryContentsList::getNumFiles() const
  45586. {
  45587. return files.size();
  45588. }
  45589. bool DirectoryContentsList::getFileInfo (const int index,
  45590. FileInfo& result) const
  45591. {
  45592. const ScopedLock sl (fileListLock);
  45593. const FileInfo* const info = files [index];
  45594. if (info != 0)
  45595. {
  45596. result = *info;
  45597. return true;
  45598. }
  45599. return false;
  45600. }
  45601. const File DirectoryContentsList::getFile (const int index) const
  45602. {
  45603. const ScopedLock sl (fileListLock);
  45604. const FileInfo* const info = files [index];
  45605. if (info != 0)
  45606. return root.getChildFile (info->filename);
  45607. return File::nonexistent;
  45608. }
  45609. bool DirectoryContentsList::isStillLoading() const
  45610. {
  45611. return fileFindHandle != 0;
  45612. }
  45613. void DirectoryContentsList::changed()
  45614. {
  45615. sendChangeMessage (this);
  45616. }
  45617. bool DirectoryContentsList::useTimeSlice()
  45618. {
  45619. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45620. bool hasChanged = false;
  45621. for (int i = 100; --i >= 0;)
  45622. {
  45623. if (! checkNextFile (hasChanged))
  45624. {
  45625. if (hasChanged)
  45626. changed();
  45627. return false;
  45628. }
  45629. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45630. break;
  45631. }
  45632. if (hasChanged)
  45633. changed();
  45634. return true;
  45635. }
  45636. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45637. {
  45638. if (fileFindHandle != 0)
  45639. {
  45640. String fileFound;
  45641. bool fileFoundIsDir, isHidden, isReadOnly;
  45642. int64 fileSize;
  45643. Time modTime, creationTime;
  45644. if (juce_findFileNext (fileFindHandle, fileFound,
  45645. &fileFoundIsDir, &isHidden,
  45646. &fileSize,
  45647. &modTime,
  45648. &creationTime,
  45649. &isReadOnly))
  45650. {
  45651. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45652. modTime, creationTime, isReadOnly))
  45653. {
  45654. hasChanged = true;
  45655. }
  45656. return true;
  45657. }
  45658. else
  45659. {
  45660. juce_findFileClose (fileFindHandle);
  45661. fileFindHandle = 0;
  45662. }
  45663. }
  45664. return false;
  45665. }
  45666. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45667. const DirectoryContentsList::FileInfo* const second)
  45668. {
  45669. #if JUCE_WINDOWS
  45670. if (first->isDirectory != second->isDirectory)
  45671. return first->isDirectory ? -1 : 1;
  45672. #endif
  45673. return first->filename.compareIgnoreCase (second->filename);
  45674. }
  45675. bool DirectoryContentsList::addFile (const String& filename,
  45676. const bool isDir,
  45677. const bool isHidden,
  45678. const int64 fileSize,
  45679. const Time& modTime,
  45680. const Time& creationTime,
  45681. const bool isReadOnly)
  45682. {
  45683. if (filename == T("..")
  45684. || filename == T(".")
  45685. || (ignoreHiddenFiles && isHidden))
  45686. return false;
  45687. const File file (root.getChildFile (filename));
  45688. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  45689. && (fileFilter == 0
  45690. || ((! isDir) && fileFilter->isFileSuitable (file))
  45691. || (isDir && fileFilter->isDirectorySuitable (file))))
  45692. {
  45693. ScopedPointer <FileInfo> info (new FileInfo());
  45694. info->filename = filename;
  45695. info->fileSize = fileSize;
  45696. info->modificationTime = modTime;
  45697. info->creationTime = creationTime;
  45698. info->isDirectory = isDir;
  45699. info->isReadOnly = isReadOnly;
  45700. const ScopedLock sl (fileListLock);
  45701. for (int i = files.size(); --i >= 0;)
  45702. if (files.getUnchecked(i)->filename == info->filename)
  45703. return false;
  45704. files.addSorted (*this, info.release());
  45705. return true;
  45706. }
  45707. return false;
  45708. }
  45709. END_JUCE_NAMESPACE
  45710. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45711. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45712. BEGIN_JUCE_NAMESPACE
  45713. FileBrowserComponent::FileBrowserComponent (int flags_,
  45714. const File& initialFileOrDirectory,
  45715. const FileFilter* fileFilter_,
  45716. FilePreviewComponent* previewComp_)
  45717. : FileFilter (String::empty),
  45718. fileFilter (fileFilter_),
  45719. flags (flags_),
  45720. previewComp (previewComp_),
  45721. thread ("Juce FileBrowser")
  45722. {
  45723. // You need to specify one or other of the open/save flags..
  45724. jassert ((flags & (saveMode | openMode)) != 0);
  45725. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45726. // You need to specify at least one of these flags..
  45727. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45728. String filename;
  45729. if (initialFileOrDirectory == File::nonexistent)
  45730. {
  45731. currentRoot = File::getCurrentWorkingDirectory();
  45732. }
  45733. else if (initialFileOrDirectory.isDirectory())
  45734. {
  45735. currentRoot = initialFileOrDirectory;
  45736. }
  45737. else
  45738. {
  45739. chosenFiles.add (initialFileOrDirectory);
  45740. currentRoot = initialFileOrDirectory.getParentDirectory();
  45741. filename = initialFileOrDirectory.getFileName();
  45742. }
  45743. fileList = new DirectoryContentsList (this, thread);
  45744. if ((flags & useTreeView) != 0)
  45745. {
  45746. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45747. if ((flags & canSelectMultipleItems) != 0)
  45748. tree->setMultiSelectEnabled (true);
  45749. addAndMakeVisible (tree);
  45750. fileListComponent = tree;
  45751. }
  45752. else
  45753. {
  45754. FileListComponent* const list = new FileListComponent (*fileList);
  45755. list->setOutlineThickness (1);
  45756. if ((flags & canSelectMultipleItems) != 0)
  45757. list->setMultipleSelectionEnabled (true);
  45758. addAndMakeVisible (list);
  45759. fileListComponent = list;
  45760. }
  45761. fileListComponent->addListener (this);
  45762. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45763. currentPathBox->setEditableText (true);
  45764. StringArray rootNames, rootPaths;
  45765. const BitArray separators (getRoots (rootNames, rootPaths));
  45766. for (int i = 0; i < rootNames.size(); ++i)
  45767. {
  45768. if (separators [i])
  45769. currentPathBox->addSeparator();
  45770. currentPathBox->addItem (rootNames[i], i + 1);
  45771. }
  45772. currentPathBox->addSeparator();
  45773. currentPathBox->addListener (this);
  45774. addAndMakeVisible (filenameBox = new TextEditor());
  45775. filenameBox->setMultiLine (false);
  45776. filenameBox->setSelectAllWhenFocused (true);
  45777. filenameBox->setText (filename, false);
  45778. filenameBox->addListener (this);
  45779. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45780. Label* label = new Label ("f", TRANS("file:"));
  45781. addAndMakeVisible (label);
  45782. label->attachToComponent (filenameBox, true);
  45783. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45784. goUpButton->addButtonListener (this);
  45785. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45786. if (previewComp != 0)
  45787. addAndMakeVisible (previewComp);
  45788. setRoot (currentRoot);
  45789. thread.startThread (4);
  45790. }
  45791. FileBrowserComponent::~FileBrowserComponent()
  45792. {
  45793. if (previewComp != 0)
  45794. removeChildComponent (previewComp);
  45795. deleteAllChildren();
  45796. fileList = 0;
  45797. thread.stopThread (10000);
  45798. }
  45799. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  45800. {
  45801. listeners.add (newListener);
  45802. }
  45803. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  45804. {
  45805. listeners.remove (listener);
  45806. }
  45807. bool FileBrowserComponent::isSaveMode() const throw()
  45808. {
  45809. return (flags & saveMode) != 0;
  45810. }
  45811. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45812. {
  45813. if (chosenFiles.size() == 0 && currentFileIsValid())
  45814. return 1;
  45815. return chosenFiles.size();
  45816. }
  45817. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45818. {
  45819. if (! filenameBox->isReadOnly())
  45820. return currentRoot.getChildFile (filenameBox->getText());
  45821. else
  45822. return chosenFiles[index];
  45823. }
  45824. bool FileBrowserComponent::currentFileIsValid() const
  45825. {
  45826. if (isSaveMode())
  45827. return ! getSelectedFile (0).isDirectory();
  45828. else
  45829. return getSelectedFile (0).exists();
  45830. }
  45831. const File FileBrowserComponent::getHighlightedFile() const throw()
  45832. {
  45833. return fileListComponent->getSelectedFile (0);
  45834. }
  45835. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45836. {
  45837. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45838. : false;
  45839. }
  45840. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45841. {
  45842. return true;
  45843. }
  45844. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45845. {
  45846. if (f.isDirectory())
  45847. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45848. return (flags & canSelectFiles) != 0 && f.exists()
  45849. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45850. }
  45851. const File FileBrowserComponent::getRoot() const
  45852. {
  45853. return currentRoot;
  45854. }
  45855. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45856. {
  45857. if (currentRoot != newRootDirectory)
  45858. {
  45859. fileListComponent->scrollToTop();
  45860. String path (newRootDirectory.getFullPathName());
  45861. if (path.isEmpty())
  45862. path += File::separator;
  45863. StringArray rootNames, rootPaths;
  45864. getRoots (rootNames, rootPaths);
  45865. if (! rootPaths.contains (path, true))
  45866. {
  45867. bool alreadyListed = false;
  45868. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45869. {
  45870. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45871. {
  45872. alreadyListed = true;
  45873. break;
  45874. }
  45875. }
  45876. if (! alreadyListed)
  45877. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45878. }
  45879. }
  45880. currentRoot = newRootDirectory;
  45881. fileList->setDirectory (currentRoot, true, true);
  45882. String currentRootName (currentRoot.getFullPathName());
  45883. if (currentRootName.isEmpty())
  45884. currentRootName += File::separator;
  45885. currentPathBox->setText (currentRootName, true);
  45886. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45887. && currentRoot.getParentDirectory() != currentRoot);
  45888. }
  45889. void FileBrowserComponent::goUp()
  45890. {
  45891. setRoot (getRoot().getParentDirectory());
  45892. }
  45893. void FileBrowserComponent::refresh()
  45894. {
  45895. fileList->refresh();
  45896. }
  45897. const String FileBrowserComponent::getActionVerb() const
  45898. {
  45899. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45900. }
  45901. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45902. {
  45903. return previewComp;
  45904. }
  45905. void FileBrowserComponent::resized()
  45906. {
  45907. getLookAndFeel()
  45908. .layoutFileBrowserComponent (*this, fileListComponent,
  45909. previewComp, currentPathBox,
  45910. filenameBox, goUpButton);
  45911. }
  45912. void FileBrowserComponent::sendListenerChangeMessage()
  45913. {
  45914. Component::BailOutChecker checker (this);
  45915. if (previewComp != 0)
  45916. previewComp->selectedFileChanged (getSelectedFile (0));
  45917. // You shouldn't delete the browser when the file gets changed!
  45918. jassert (! checker.shouldBailOut());
  45919. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45920. }
  45921. void FileBrowserComponent::selectionChanged()
  45922. {
  45923. StringArray newFilenames;
  45924. bool resetChosenFiles = true;
  45925. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  45926. {
  45927. const File f (fileListComponent->getSelectedFile (i));
  45928. if (isFileOrDirSuitable (f))
  45929. {
  45930. if (resetChosenFiles)
  45931. {
  45932. chosenFiles.clear();
  45933. resetChosenFiles = false;
  45934. }
  45935. chosenFiles.add (f);
  45936. newFilenames.add (f.getRelativePathFrom (getRoot()));
  45937. }
  45938. }
  45939. if (newFilenames.size() > 0)
  45940. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  45941. sendListenerChangeMessage();
  45942. }
  45943. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  45944. {
  45945. Component::BailOutChecker checker (this);
  45946. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  45947. }
  45948. void FileBrowserComponent::fileDoubleClicked (const File& f)
  45949. {
  45950. if (f.isDirectory())
  45951. {
  45952. setRoot (f);
  45953. }
  45954. else
  45955. {
  45956. Component::BailOutChecker checker (this);
  45957. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  45958. }
  45959. }
  45960. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  45961. {
  45962. #if JUCE_LINUX || JUCE_WINDOWS
  45963. if (key.getModifiers().isCommandDown()
  45964. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  45965. {
  45966. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  45967. fileList->refresh();
  45968. return true;
  45969. }
  45970. #endif
  45971. return false;
  45972. }
  45973. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  45974. {
  45975. sendListenerChangeMessage();
  45976. }
  45977. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  45978. {
  45979. if (filenameBox->getText().containsChar (File::separator))
  45980. {
  45981. const File f (currentRoot.getChildFile (filenameBox->getText()));
  45982. if (f.isDirectory())
  45983. {
  45984. setRoot (f);
  45985. chosenFiles.clear();
  45986. filenameBox->setText (String::empty);
  45987. }
  45988. else
  45989. {
  45990. setRoot (f.getParentDirectory());
  45991. chosenFiles.clear();
  45992. chosenFiles.add (f);
  45993. filenameBox->setText (f.getFileName());
  45994. }
  45995. }
  45996. else
  45997. {
  45998. fileDoubleClicked (getSelectedFile (0));
  45999. }
  46000. }
  46001. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  46002. {
  46003. }
  46004. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46005. {
  46006. if (! isSaveMode())
  46007. selectionChanged();
  46008. }
  46009. void FileBrowserComponent::buttonClicked (Button*)
  46010. {
  46011. goUp();
  46012. }
  46013. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46014. {
  46015. const String newText (currentPathBox->getText().trim().unquoted());
  46016. if (newText.isNotEmpty())
  46017. {
  46018. const int index = currentPathBox->getSelectedId() - 1;
  46019. StringArray rootNames, rootPaths;
  46020. getRoots (rootNames, rootPaths);
  46021. if (rootPaths [index].isNotEmpty())
  46022. {
  46023. setRoot (File (rootPaths [index]));
  46024. }
  46025. else
  46026. {
  46027. File f (newText);
  46028. for (;;)
  46029. {
  46030. if (f.isDirectory())
  46031. {
  46032. setRoot (f);
  46033. break;
  46034. }
  46035. if (f.getParentDirectory() == f)
  46036. break;
  46037. f = f.getParentDirectory();
  46038. }
  46039. }
  46040. }
  46041. }
  46042. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46043. {
  46044. BitArray separators;
  46045. #if JUCE_WINDOWS
  46046. Array<File> roots;
  46047. File::findFileSystemRoots (roots);
  46048. rootPaths.clear();
  46049. for (int i = 0; i < roots.size(); ++i)
  46050. {
  46051. const File& drive = roots.getReference(i);
  46052. String name (drive.getFullPathName());
  46053. rootPaths.add (name);
  46054. if (drive.isOnHardDisk())
  46055. {
  46056. String volume (drive.getVolumeLabel());
  46057. if (volume.isEmpty())
  46058. volume = TRANS("Hard Drive");
  46059. name << " [" << drive.getVolumeLabel() << ']';
  46060. }
  46061. else if (drive.isOnCDRomDrive())
  46062. {
  46063. name << TRANS(" [CD/DVD drive]");
  46064. }
  46065. rootNames.add (name);
  46066. }
  46067. separators.setBit (rootPaths.size());
  46068. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46069. rootNames.add ("Documents");
  46070. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46071. rootNames.add ("Desktop");
  46072. #endif
  46073. #if JUCE_MAC
  46074. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46075. rootNames.add ("Home folder");
  46076. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46077. rootNames.add ("Documents");
  46078. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46079. rootNames.add ("Desktop");
  46080. separators.setBit (rootPaths.size());
  46081. Array <File> volumes;
  46082. File vol ("/Volumes");
  46083. vol.findChildFiles (volumes, File::findDirectories, false);
  46084. for (int i = 0; i < volumes.size(); ++i)
  46085. {
  46086. const File& volume = volumes.getReference(i);
  46087. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  46088. {
  46089. rootPaths.add (volume.getFullPathName());
  46090. rootNames.add (volume.getFileName());
  46091. }
  46092. }
  46093. #endif
  46094. #if JUCE_LINUX
  46095. rootPaths.add ("/");
  46096. rootNames.add ("/");
  46097. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46098. rootNames.add ("Home folder");
  46099. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46100. rootNames.add ("Desktop");
  46101. #endif
  46102. return separators;
  46103. }
  46104. END_JUCE_NAMESPACE
  46105. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46106. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46107. BEGIN_JUCE_NAMESPACE
  46108. FileChooser::FileChooser (const String& chooserBoxTitle,
  46109. const File& currentFileOrDirectory,
  46110. const String& fileFilters,
  46111. const bool useNativeDialogBox_)
  46112. : title (chooserBoxTitle),
  46113. filters (fileFilters),
  46114. startingFile (currentFileOrDirectory),
  46115. useNativeDialogBox (useNativeDialogBox_)
  46116. {
  46117. #if JUCE_LINUX
  46118. useNativeDialogBox = false;
  46119. #endif
  46120. if (! fileFilters.containsNonWhitespaceChars())
  46121. filters = T("*");
  46122. }
  46123. FileChooser::~FileChooser()
  46124. {
  46125. }
  46126. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46127. {
  46128. return showDialog (false, true, false, false, false, previewComponent);
  46129. }
  46130. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46131. {
  46132. return showDialog (false, true, false, false, true, previewComponent);
  46133. }
  46134. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46135. {
  46136. return showDialog (true, true, false, false, true, previewComponent);
  46137. }
  46138. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46139. {
  46140. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46141. }
  46142. bool FileChooser::browseForDirectory()
  46143. {
  46144. return showDialog (true, false, false, false, false, 0);
  46145. }
  46146. const File FileChooser::getResult() const
  46147. {
  46148. // if you've used a multiple-file select, you should use the getResults() method
  46149. // to retrieve all the files that were chosen.
  46150. jassert (results.size() <= 1);
  46151. return results.getFirst();
  46152. }
  46153. const Array<File>& FileChooser::getResults() const
  46154. {
  46155. return results;
  46156. }
  46157. bool FileChooser::showDialog (const bool selectsDirectories,
  46158. const bool selectsFiles,
  46159. const bool isSave,
  46160. const bool warnAboutOverwritingExistingFiles,
  46161. const bool selectMultipleFiles,
  46162. FilePreviewComponent* const previewComponent)
  46163. {
  46164. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  46165. results.clear();
  46166. // the preview component needs to be the right size before you pass it in here..
  46167. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46168. && previewComponent->getHeight() > 10));
  46169. #if JUCE_WINDOWS
  46170. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46171. #elif JUCE_MAC
  46172. if (useNativeDialogBox && (previewComponent == 0))
  46173. #else
  46174. if (false)
  46175. #endif
  46176. {
  46177. showPlatformDialog (results, title, startingFile, filters,
  46178. selectsDirectories, selectsFiles, isSave,
  46179. warnAboutOverwritingExistingFiles,
  46180. selectMultipleFiles,
  46181. previewComponent);
  46182. }
  46183. else
  46184. {
  46185. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46186. selectsDirectories ? "*" : String::empty,
  46187. String::empty);
  46188. int flags = isSave ? FileBrowserComponent::saveMode
  46189. : FileBrowserComponent::openMode;
  46190. if (selectsFiles)
  46191. flags |= FileBrowserComponent::canSelectFiles;
  46192. if (selectsDirectories)
  46193. flags |= FileBrowserComponent::canSelectDirectories;
  46194. if (selectMultipleFiles)
  46195. flags |= FileBrowserComponent::canSelectMultipleItems;
  46196. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46197. FileChooserDialogBox box (title, String::empty,
  46198. browserComponent,
  46199. warnAboutOverwritingExistingFiles,
  46200. browserComponent.findColour (AlertWindow::backgroundColourId));
  46201. if (box.show())
  46202. {
  46203. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46204. results.add (browserComponent.getSelectedFile (i));
  46205. }
  46206. }
  46207. if (previouslyFocused != 0)
  46208. previouslyFocused->grabKeyboardFocus();
  46209. return results.size() > 0;
  46210. }
  46211. FilePreviewComponent::FilePreviewComponent()
  46212. {
  46213. }
  46214. FilePreviewComponent::~FilePreviewComponent()
  46215. {
  46216. }
  46217. END_JUCE_NAMESPACE
  46218. /*** End of inlined file: juce_FileChooser.cpp ***/
  46219. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46220. BEGIN_JUCE_NAMESPACE
  46221. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46222. const String& instructions,
  46223. FileBrowserComponent& chooserComponent,
  46224. const bool warnAboutOverwritingExistingFiles_,
  46225. const Colour& backgroundColour)
  46226. : ResizableWindow (name, backgroundColour, true),
  46227. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46228. {
  46229. content = new ContentComponent();
  46230. content->setName (name);
  46231. content->instructions = instructions;
  46232. content->chooserComponent = &chooserComponent;
  46233. content->addAndMakeVisible (&chooserComponent);
  46234. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46235. content->addAndMakeVisible (content->okButton);
  46236. content->okButton->addButtonListener (this);
  46237. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46238. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46239. content->cancelButton = new TextButton (TRANS("Cancel"));
  46240. content->addAndMakeVisible (content->cancelButton);
  46241. content->cancelButton->addButtonListener (this);
  46242. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46243. setContentComponent (content);
  46244. setResizable (true, true);
  46245. setResizeLimits (300, 300, 1200, 1000);
  46246. content->chooserComponent->addListener (this);
  46247. }
  46248. FileChooserDialogBox::~FileChooserDialogBox()
  46249. {
  46250. content->chooserComponent->removeListener (this);
  46251. }
  46252. bool FileChooserDialogBox::show (int w, int h)
  46253. {
  46254. if (w <= 0)
  46255. {
  46256. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46257. if (previewComp != 0)
  46258. w = 400 + previewComp->getWidth();
  46259. else
  46260. w = 600;
  46261. }
  46262. if (h <= 0)
  46263. h = 500;
  46264. centreWithSize (w, h);
  46265. const bool ok = (runModalLoop() != 0);
  46266. setVisible (false);
  46267. return ok;
  46268. }
  46269. void FileChooserDialogBox::buttonClicked (Button* button)
  46270. {
  46271. if (button == content->okButton)
  46272. {
  46273. if (warnAboutOverwritingExistingFiles
  46274. && content->chooserComponent->isSaveMode()
  46275. && content->chooserComponent->getSelectedFile(0).exists())
  46276. {
  46277. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46278. TRANS("File already exists"),
  46279. TRANS("There's already a file called:\n\n")
  46280. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46281. + T("\n\nAre you sure you want to overwrite it?"),
  46282. TRANS("overwrite"),
  46283. TRANS("cancel")))
  46284. {
  46285. return;
  46286. }
  46287. }
  46288. exitModalState (1);
  46289. }
  46290. else if (button == content->cancelButton)
  46291. closeButtonPressed();
  46292. }
  46293. void FileChooserDialogBox::closeButtonPressed()
  46294. {
  46295. setVisible (false);
  46296. }
  46297. void FileChooserDialogBox::selectionChanged()
  46298. {
  46299. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46300. }
  46301. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46302. {
  46303. }
  46304. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46305. {
  46306. selectionChanged();
  46307. content->okButton->triggerClick();
  46308. }
  46309. FileChooserDialogBox::ContentComponent::ContentComponent()
  46310. {
  46311. setInterceptsMouseClicks (false, true);
  46312. }
  46313. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46314. {
  46315. delete okButton;
  46316. delete cancelButton;
  46317. }
  46318. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46319. {
  46320. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46321. text.draw (g);
  46322. }
  46323. void FileChooserDialogBox::ContentComponent::resized()
  46324. {
  46325. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46326. float left, top, right, bottom;
  46327. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46328. const int y = roundToInt (bottom) + 10;
  46329. const int buttonHeight = 26;
  46330. const int buttonY = getHeight() - buttonHeight - 8;
  46331. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46332. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46333. proportionOfWidth (0.2f), buttonHeight);
  46334. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46335. proportionOfWidth (0.2f), buttonHeight);
  46336. }
  46337. END_JUCE_NAMESPACE
  46338. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46339. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46340. BEGIN_JUCE_NAMESPACE
  46341. FileFilter::FileFilter (const String& filterDescription)
  46342. : description (filterDescription)
  46343. {
  46344. }
  46345. FileFilter::~FileFilter()
  46346. {
  46347. }
  46348. const String& FileFilter::getDescription() const throw()
  46349. {
  46350. return description;
  46351. }
  46352. END_JUCE_NAMESPACE
  46353. /*** End of inlined file: juce_FileFilter.cpp ***/
  46354. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46355. BEGIN_JUCE_NAMESPACE
  46356. Image* juce_createIconForFile (const File& file);
  46357. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46358. : ListBox (String::empty, 0),
  46359. DirectoryContentsDisplayComponent (listToShow)
  46360. {
  46361. setModel (this);
  46362. fileList.addChangeListener (this);
  46363. }
  46364. FileListComponent::~FileListComponent()
  46365. {
  46366. fileList.removeChangeListener (this);
  46367. deleteAllChildren();
  46368. }
  46369. int FileListComponent::getNumSelectedFiles() const
  46370. {
  46371. return getNumSelectedRows();
  46372. }
  46373. const File FileListComponent::getSelectedFile (int index) const
  46374. {
  46375. return fileList.getFile (getSelectedRow (index));
  46376. }
  46377. void FileListComponent::scrollToTop()
  46378. {
  46379. getVerticalScrollBar()->setCurrentRangeStart (0);
  46380. }
  46381. void FileListComponent::changeListenerCallback (void*)
  46382. {
  46383. updateContent();
  46384. if (lastDirectory != fileList.getDirectory())
  46385. {
  46386. lastDirectory = fileList.getDirectory();
  46387. deselectAllRows();
  46388. }
  46389. }
  46390. class FileListItemComponent : public Component,
  46391. public TimeSliceClient,
  46392. public AsyncUpdater
  46393. {
  46394. public:
  46395. FileListItemComponent (FileListComponent& owner_,
  46396. TimeSliceThread& thread_) throw()
  46397. : owner (owner_),
  46398. thread (thread_),
  46399. icon (0)
  46400. {
  46401. }
  46402. ~FileListItemComponent() throw()
  46403. {
  46404. thread.removeTimeSliceClient (this);
  46405. clearIcon();
  46406. }
  46407. void paint (Graphics& g)
  46408. {
  46409. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46410. file.getFileName(),
  46411. icon,
  46412. fileSize, modTime,
  46413. isDirectory, highlighted,
  46414. index);
  46415. }
  46416. void mouseDown (const MouseEvent& e)
  46417. {
  46418. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46419. owner.sendMouseClickMessage (file, e);
  46420. }
  46421. void mouseDoubleClick (const MouseEvent&)
  46422. {
  46423. owner.sendDoubleClickMessage (file);
  46424. }
  46425. void update (const File& root,
  46426. const DirectoryContentsList::FileInfo* const fileInfo,
  46427. const int index_,
  46428. const bool highlighted_) throw()
  46429. {
  46430. thread.removeTimeSliceClient (this);
  46431. if (highlighted_ != highlighted
  46432. || index_ != index)
  46433. {
  46434. index = index_;
  46435. highlighted = highlighted_;
  46436. repaint();
  46437. }
  46438. File newFile;
  46439. String newFileSize;
  46440. String newModTime;
  46441. if (fileInfo != 0)
  46442. {
  46443. newFile = root.getChildFile (fileInfo->filename);
  46444. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46445. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46446. }
  46447. if (newFile != file
  46448. || fileSize != newFileSize
  46449. || modTime != newModTime)
  46450. {
  46451. file = newFile;
  46452. fileSize = newFileSize;
  46453. modTime = newModTime;
  46454. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46455. repaint();
  46456. clearIcon();
  46457. }
  46458. if (file != File::nonexistent
  46459. && icon == 0 && ! isDirectory)
  46460. {
  46461. updateIcon (true);
  46462. if (icon == 0)
  46463. thread.addTimeSliceClient (this);
  46464. }
  46465. }
  46466. bool useTimeSlice()
  46467. {
  46468. updateIcon (false);
  46469. return false;
  46470. }
  46471. void handleAsyncUpdate()
  46472. {
  46473. repaint();
  46474. }
  46475. juce_UseDebuggingNewOperator
  46476. private:
  46477. FileListComponent& owner;
  46478. TimeSliceThread& thread;
  46479. bool highlighted;
  46480. int index;
  46481. File file;
  46482. String fileSize;
  46483. String modTime;
  46484. Image* icon;
  46485. bool isDirectory;
  46486. void clearIcon() throw()
  46487. {
  46488. ImageCache::release (icon);
  46489. icon = 0;
  46490. }
  46491. void updateIcon (const bool onlyUpdateIfCached) throw()
  46492. {
  46493. if (icon == 0)
  46494. {
  46495. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46496. Image* im = ImageCache::getFromHashCode (hashCode);
  46497. if (im == 0 && ! onlyUpdateIfCached)
  46498. {
  46499. im = juce_createIconForFile (file);
  46500. if (im != 0)
  46501. ImageCache::addImageToCache (im, hashCode);
  46502. }
  46503. if (im != 0)
  46504. {
  46505. icon = im;
  46506. triggerAsyncUpdate();
  46507. }
  46508. }
  46509. }
  46510. };
  46511. int FileListComponent::getNumRows()
  46512. {
  46513. return fileList.getNumFiles();
  46514. }
  46515. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46516. {
  46517. }
  46518. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46519. {
  46520. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46521. if (comp == 0)
  46522. {
  46523. delete existingComponentToUpdate;
  46524. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46525. }
  46526. DirectoryContentsList::FileInfo fileInfo;
  46527. if (fileList.getFileInfo (row, fileInfo))
  46528. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46529. else
  46530. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46531. return comp;
  46532. }
  46533. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46534. {
  46535. sendSelectionChangeMessage();
  46536. }
  46537. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46538. {
  46539. }
  46540. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46541. {
  46542. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46543. }
  46544. END_JUCE_NAMESPACE
  46545. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46546. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46547. BEGIN_JUCE_NAMESPACE
  46548. FilenameComponent::FilenameComponent (const String& name,
  46549. const File& currentFile,
  46550. const bool canEditFilename,
  46551. const bool isDirectory,
  46552. const bool isForSaving,
  46553. const String& fileBrowserWildcard,
  46554. const String& enforcedSuffix_,
  46555. const String& textWhenNothingSelected)
  46556. : Component (name),
  46557. maxRecentFiles (30),
  46558. isDir (isDirectory),
  46559. isSaving (isForSaving),
  46560. isFileDragOver (false),
  46561. wildcard (fileBrowserWildcard),
  46562. enforcedSuffix (enforcedSuffix_)
  46563. {
  46564. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  46565. filenameBox->setEditableText (canEditFilename);
  46566. filenameBox->addListener (this);
  46567. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46568. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46569. browseButton = 0;
  46570. setBrowseButtonText (T("..."));
  46571. setCurrentFile (currentFile, true);
  46572. }
  46573. FilenameComponent::~FilenameComponent()
  46574. {
  46575. deleteAllChildren();
  46576. }
  46577. void FilenameComponent::paintOverChildren (Graphics& g)
  46578. {
  46579. if (isFileDragOver)
  46580. {
  46581. g.setColour (Colours::red.withAlpha (0.2f));
  46582. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46583. }
  46584. }
  46585. void FilenameComponent::resized()
  46586. {
  46587. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46588. }
  46589. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46590. {
  46591. browseButtonText = newBrowseButtonText;
  46592. lookAndFeelChanged();
  46593. }
  46594. void FilenameComponent::lookAndFeelChanged()
  46595. {
  46596. deleteAndZero (browseButton);
  46597. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46598. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46599. resized();
  46600. browseButton->addButtonListener (this);
  46601. }
  46602. void FilenameComponent::setTooltip (const String& newTooltip)
  46603. {
  46604. SettableTooltipClient::setTooltip (newTooltip);
  46605. filenameBox->setTooltip (newTooltip);
  46606. }
  46607. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46608. {
  46609. defaultBrowseFile = newDefaultDirectory;
  46610. }
  46611. void FilenameComponent::buttonClicked (Button*)
  46612. {
  46613. FileChooser fc (TRANS("Choose a new file"),
  46614. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46615. : getCurrentFile(),
  46616. wildcard);
  46617. if (isDir ? fc.browseForDirectory()
  46618. : (isSaving ? fc.browseForFileToSave (false)
  46619. : fc.browseForFileToOpen()))
  46620. {
  46621. setCurrentFile (fc.getResult(), true);
  46622. }
  46623. }
  46624. void FilenameComponent::comboBoxChanged (ComboBox*)
  46625. {
  46626. setCurrentFile (getCurrentFile(), true);
  46627. }
  46628. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46629. {
  46630. return true;
  46631. }
  46632. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46633. {
  46634. isFileDragOver = false;
  46635. repaint();
  46636. const File f (filenames[0]);
  46637. if (f.exists() && (f.isDirectory() == isDir))
  46638. setCurrentFile (f, true);
  46639. }
  46640. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46641. {
  46642. isFileDragOver = true;
  46643. repaint();
  46644. }
  46645. void FilenameComponent::fileDragExit (const StringArray&)
  46646. {
  46647. isFileDragOver = false;
  46648. repaint();
  46649. }
  46650. const File FilenameComponent::getCurrentFile() const
  46651. {
  46652. File f (filenameBox->getText());
  46653. if (enforcedSuffix.isNotEmpty())
  46654. f = f.withFileExtension (enforcedSuffix);
  46655. return f;
  46656. }
  46657. void FilenameComponent::setCurrentFile (File newFile,
  46658. const bool addToRecentlyUsedList,
  46659. const bool sendChangeNotification)
  46660. {
  46661. if (enforcedSuffix.isNotEmpty())
  46662. newFile = newFile.withFileExtension (enforcedSuffix);
  46663. if (newFile.getFullPathName() != lastFilename)
  46664. {
  46665. lastFilename = newFile.getFullPathName();
  46666. if (addToRecentlyUsedList)
  46667. addRecentlyUsedFile (newFile);
  46668. filenameBox->setText (lastFilename, true);
  46669. if (sendChangeNotification)
  46670. triggerAsyncUpdate();
  46671. }
  46672. }
  46673. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46674. {
  46675. filenameBox->setEditableText (shouldBeEditable);
  46676. }
  46677. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46678. {
  46679. StringArray names;
  46680. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46681. names.add (filenameBox->getItemText (i));
  46682. return names;
  46683. }
  46684. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46685. {
  46686. if (filenames != getRecentlyUsedFilenames())
  46687. {
  46688. filenameBox->clear();
  46689. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46690. filenameBox->addItem (filenames[i], i + 1);
  46691. }
  46692. }
  46693. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46694. {
  46695. maxRecentFiles = jmax (1, newMaximum);
  46696. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46697. }
  46698. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46699. {
  46700. StringArray files (getRecentlyUsedFilenames());
  46701. if (file.getFullPathName().isNotEmpty())
  46702. {
  46703. files.removeString (file.getFullPathName(), true);
  46704. files.insert (0, file.getFullPathName());
  46705. setRecentlyUsedFilenames (files);
  46706. }
  46707. }
  46708. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  46709. {
  46710. listeners.add (listener);
  46711. }
  46712. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  46713. {
  46714. listeners.remove (listener);
  46715. }
  46716. void FilenameComponent::handleAsyncUpdate()
  46717. {
  46718. Component::BailOutChecker checker (this);
  46719. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46720. }
  46721. END_JUCE_NAMESPACE
  46722. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46723. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46724. BEGIN_JUCE_NAMESPACE
  46725. FileSearchPathListComponent::FileSearchPathListComponent()
  46726. {
  46727. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46728. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46729. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46730. listBox->setOutlineThickness (1);
  46731. addAndMakeVisible (addButton = new TextButton ("+"));
  46732. addButton->addButtonListener (this);
  46733. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46734. addAndMakeVisible (removeButton = new TextButton ("-"));
  46735. removeButton->addButtonListener (this);
  46736. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46737. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46738. changeButton->addButtonListener (this);
  46739. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46740. upButton->addButtonListener (this);
  46741. {
  46742. Path arrowPath;
  46743. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46744. DrawablePath arrowImage;
  46745. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46746. arrowImage.setPath (arrowPath);
  46747. ((DrawableButton*) upButton)->setImages (&arrowImage);
  46748. }
  46749. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46750. downButton->addButtonListener (this);
  46751. {
  46752. Path arrowPath;
  46753. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46754. DrawablePath arrowImage;
  46755. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46756. arrowImage.setPath (arrowPath);
  46757. ((DrawableButton*) downButton)->setImages (&arrowImage);
  46758. }
  46759. updateButtons();
  46760. }
  46761. FileSearchPathListComponent::~FileSearchPathListComponent()
  46762. {
  46763. deleteAllChildren();
  46764. }
  46765. void FileSearchPathListComponent::updateButtons() throw()
  46766. {
  46767. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46768. removeButton->setEnabled (anythingSelected);
  46769. changeButton->setEnabled (anythingSelected);
  46770. upButton->setEnabled (anythingSelected);
  46771. downButton->setEnabled (anythingSelected);
  46772. }
  46773. void FileSearchPathListComponent::changed() throw()
  46774. {
  46775. listBox->updateContent();
  46776. listBox->repaint();
  46777. updateButtons();
  46778. }
  46779. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46780. {
  46781. if (newPath.toString() != path.toString())
  46782. {
  46783. path = newPath;
  46784. changed();
  46785. }
  46786. }
  46787. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46788. {
  46789. defaultBrowseTarget = newDefaultDirectory;
  46790. }
  46791. int FileSearchPathListComponent::getNumRows()
  46792. {
  46793. return path.getNumPaths();
  46794. }
  46795. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46796. {
  46797. if (rowIsSelected)
  46798. g.fillAll (findColour (TextEditor::highlightColourId));
  46799. g.setColour (findColour (ListBox::textColourId));
  46800. Font f (height * 0.7f);
  46801. f.setHorizontalScale (0.9f);
  46802. g.setFont (f);
  46803. g.drawText (path [rowNumber].getFullPathName(),
  46804. 4, 0, width - 6, height,
  46805. Justification::centredLeft, true);
  46806. }
  46807. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46808. {
  46809. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46810. {
  46811. path.remove (row);
  46812. changed();
  46813. }
  46814. }
  46815. void FileSearchPathListComponent::returnKeyPressed (int row)
  46816. {
  46817. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  46818. if (chooser.browseForDirectory())
  46819. {
  46820. path.remove (row);
  46821. path.add (chooser.getResult(), row);
  46822. changed();
  46823. }
  46824. }
  46825. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46826. {
  46827. returnKeyPressed (row);
  46828. }
  46829. void FileSearchPathListComponent::selectedRowsChanged (int)
  46830. {
  46831. updateButtons();
  46832. }
  46833. void FileSearchPathListComponent::paint (Graphics& g)
  46834. {
  46835. g.fillAll (findColour (backgroundColourId));
  46836. }
  46837. void FileSearchPathListComponent::resized()
  46838. {
  46839. const int buttonH = 22;
  46840. const int buttonY = getHeight() - buttonH - 4;
  46841. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46842. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46843. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46844. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  46845. downButton->setSize (buttonH * 2, buttonH);
  46846. upButton->setSize (buttonH * 2, buttonH);
  46847. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46848. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46849. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46850. }
  46851. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46852. {
  46853. return true;
  46854. }
  46855. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46856. {
  46857. for (int i = filenames.size(); --i >= 0;)
  46858. {
  46859. const File f (filenames[i]);
  46860. if (f.isDirectory())
  46861. {
  46862. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46863. path.add (f, row);
  46864. changed();
  46865. }
  46866. }
  46867. }
  46868. void FileSearchPathListComponent::buttonClicked (Button* button)
  46869. {
  46870. const int currentRow = listBox->getSelectedRow();
  46871. if (button == removeButton)
  46872. {
  46873. deleteKeyPressed (currentRow);
  46874. }
  46875. else if (button == addButton)
  46876. {
  46877. File start (defaultBrowseTarget);
  46878. if (start == File::nonexistent)
  46879. start = path [0];
  46880. if (start == File::nonexistent)
  46881. start = File::getCurrentWorkingDirectory();
  46882. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  46883. if (chooser.browseForDirectory())
  46884. {
  46885. path.add (chooser.getResult(), currentRow);
  46886. }
  46887. }
  46888. else if (button == changeButton)
  46889. {
  46890. returnKeyPressed (currentRow);
  46891. }
  46892. else if (button == upButton)
  46893. {
  46894. if (currentRow > 0 && currentRow < path.getNumPaths())
  46895. {
  46896. const File f (path[currentRow]);
  46897. path.remove (currentRow);
  46898. path.add (f, currentRow - 1);
  46899. listBox->selectRow (currentRow - 1);
  46900. }
  46901. }
  46902. else if (button == downButton)
  46903. {
  46904. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46905. {
  46906. const File f (path[currentRow]);
  46907. path.remove (currentRow);
  46908. path.add (f, currentRow + 1);
  46909. listBox->selectRow (currentRow + 1);
  46910. }
  46911. }
  46912. changed();
  46913. }
  46914. END_JUCE_NAMESPACE
  46915. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46916. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  46917. BEGIN_JUCE_NAMESPACE
  46918. Image* juce_createIconForFile (const File& file);
  46919. class FileListTreeItem : public TreeViewItem,
  46920. public TimeSliceClient,
  46921. public AsyncUpdater,
  46922. public ChangeListener
  46923. {
  46924. public:
  46925. FileListTreeItem (FileTreeComponent& owner_,
  46926. DirectoryContentsList* const parentContentsList_,
  46927. const int indexInContentsList_,
  46928. const File& file_,
  46929. TimeSliceThread& thread_) throw()
  46930. : file (file_),
  46931. owner (owner_),
  46932. parentContentsList (parentContentsList_),
  46933. indexInContentsList (indexInContentsList_),
  46934. subContentsList (0),
  46935. canDeleteSubContentsList (false),
  46936. thread (thread_),
  46937. icon (0)
  46938. {
  46939. DirectoryContentsList::FileInfo fileInfo;
  46940. if (parentContentsList_ != 0
  46941. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  46942. {
  46943. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  46944. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  46945. isDirectory = fileInfo.isDirectory;
  46946. }
  46947. else
  46948. {
  46949. isDirectory = true;
  46950. }
  46951. }
  46952. ~FileListTreeItem() throw()
  46953. {
  46954. thread.removeTimeSliceClient (this);
  46955. clearSubItems();
  46956. ImageCache::release (icon);
  46957. if (canDeleteSubContentsList)
  46958. delete subContentsList;
  46959. }
  46960. bool mightContainSubItems() { return isDirectory; }
  46961. const String getUniqueName() const { return file.getFullPathName(); }
  46962. int getItemHeight() const { return 22; }
  46963. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  46964. void itemOpennessChanged (bool isNowOpen)
  46965. {
  46966. if (isNowOpen)
  46967. {
  46968. clearSubItems();
  46969. isDirectory = file.isDirectory();
  46970. if (isDirectory)
  46971. {
  46972. if (subContentsList == 0)
  46973. {
  46974. jassert (parentContentsList != 0);
  46975. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  46976. l->setDirectory (file, true, true);
  46977. setSubContentsList (l);
  46978. canDeleteSubContentsList = true;
  46979. }
  46980. changeListenerCallback (0);
  46981. }
  46982. }
  46983. }
  46984. void setSubContentsList (DirectoryContentsList* newList) throw()
  46985. {
  46986. jassert (subContentsList == 0);
  46987. subContentsList = newList;
  46988. newList->addChangeListener (this);
  46989. }
  46990. void changeListenerCallback (void*)
  46991. {
  46992. clearSubItems();
  46993. if (isOpen() && subContentsList != 0)
  46994. {
  46995. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  46996. {
  46997. FileListTreeItem* const item
  46998. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  46999. addSubItem (item);
  47000. }
  47001. }
  47002. }
  47003. void paintItem (Graphics& g, int width, int height)
  47004. {
  47005. if (file != File::nonexistent)
  47006. {
  47007. updateIcon (true);
  47008. if (icon == 0)
  47009. thread.addTimeSliceClient (this);
  47010. }
  47011. owner.getLookAndFeel()
  47012. .drawFileBrowserRow (g, width, height,
  47013. file.getFileName(),
  47014. icon,
  47015. fileSize, modTime,
  47016. isDirectory, isSelected(),
  47017. indexInContentsList);
  47018. }
  47019. void itemClicked (const MouseEvent& e)
  47020. {
  47021. owner.sendMouseClickMessage (file, e);
  47022. }
  47023. void itemDoubleClicked (const MouseEvent& e)
  47024. {
  47025. TreeViewItem::itemDoubleClicked (e);
  47026. owner.sendDoubleClickMessage (file);
  47027. }
  47028. void itemSelectionChanged (bool)
  47029. {
  47030. owner.sendSelectionChangeMessage();
  47031. }
  47032. bool useTimeSlice()
  47033. {
  47034. updateIcon (false);
  47035. thread.removeTimeSliceClient (this);
  47036. return false;
  47037. }
  47038. void handleAsyncUpdate()
  47039. {
  47040. owner.repaint();
  47041. }
  47042. const File file;
  47043. juce_UseDebuggingNewOperator
  47044. private:
  47045. FileTreeComponent& owner;
  47046. DirectoryContentsList* parentContentsList;
  47047. int indexInContentsList;
  47048. DirectoryContentsList* subContentsList;
  47049. bool isDirectory, canDeleteSubContentsList;
  47050. TimeSliceThread& thread;
  47051. Image* icon;
  47052. String fileSize;
  47053. String modTime;
  47054. void updateIcon (const bool onlyUpdateIfCached) throw()
  47055. {
  47056. if (icon == 0)
  47057. {
  47058. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47059. Image* im = ImageCache::getFromHashCode (hashCode);
  47060. if (im == 0 && ! onlyUpdateIfCached)
  47061. {
  47062. im = juce_createIconForFile (file);
  47063. if (im != 0)
  47064. ImageCache::addImageToCache (im, hashCode);
  47065. }
  47066. if (im != 0)
  47067. {
  47068. icon = im;
  47069. triggerAsyncUpdate();
  47070. }
  47071. }
  47072. }
  47073. };
  47074. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47075. : DirectoryContentsDisplayComponent (listToShow)
  47076. {
  47077. FileListTreeItem* const root
  47078. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47079. listToShow.getTimeSliceThread());
  47080. root->setSubContentsList (&listToShow);
  47081. setRootItemVisible (false);
  47082. setRootItem (root);
  47083. }
  47084. FileTreeComponent::~FileTreeComponent()
  47085. {
  47086. deleteRootItem();
  47087. }
  47088. const File FileTreeComponent::getSelectedFile (const int index) const
  47089. {
  47090. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47091. if (item != 0)
  47092. return item->file;
  47093. return File::nonexistent;
  47094. }
  47095. void FileTreeComponent::scrollToTop()
  47096. {
  47097. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47098. }
  47099. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47100. {
  47101. dragAndDropDescription = description;
  47102. }
  47103. END_JUCE_NAMESPACE
  47104. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47105. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47106. BEGIN_JUCE_NAMESPACE
  47107. ImagePreviewComponent::ImagePreviewComponent()
  47108. {
  47109. }
  47110. ImagePreviewComponent::~ImagePreviewComponent()
  47111. {
  47112. }
  47113. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47114. {
  47115. const int availableW = proportionOfWidth (0.97f);
  47116. const int availableH = getHeight() - 13 * 4;
  47117. const double scale = jmin (1.0,
  47118. availableW / (double) w,
  47119. availableH / (double) h);
  47120. w = roundToInt (scale * w);
  47121. h = roundToInt (scale * h);
  47122. }
  47123. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47124. {
  47125. if (fileToLoad != file)
  47126. {
  47127. fileToLoad = file;
  47128. startTimer (100);
  47129. }
  47130. }
  47131. void ImagePreviewComponent::timerCallback()
  47132. {
  47133. stopTimer();
  47134. currentThumbnail = 0;
  47135. currentDetails = String::empty;
  47136. repaint();
  47137. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47138. if (in != 0)
  47139. {
  47140. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47141. if (format != 0)
  47142. {
  47143. currentThumbnail = format->decodeImage (*in);
  47144. if (currentThumbnail != 0)
  47145. {
  47146. int w = currentThumbnail->getWidth();
  47147. int h = currentThumbnail->getHeight();
  47148. currentDetails
  47149. << fileToLoad.getFileName() << "\n"
  47150. << format->getFormatName() << "\n"
  47151. << w << " x " << h << " pixels\n"
  47152. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47153. getThumbSize (w, h);
  47154. currentThumbnail = currentThumbnail->createCopy (w, h);
  47155. }
  47156. }
  47157. }
  47158. }
  47159. void ImagePreviewComponent::paint (Graphics& g)
  47160. {
  47161. if (currentThumbnail != 0)
  47162. {
  47163. g.setFont (13.0f);
  47164. int w = currentThumbnail->getWidth();
  47165. int h = currentThumbnail->getHeight();
  47166. getThumbSize (w, h);
  47167. const int numLines = 4;
  47168. const int totalH = 13 * numLines + h + 4;
  47169. const int y = (getHeight() - totalH) / 2;
  47170. g.drawImageWithin (currentThumbnail,
  47171. (getWidth() - w) / 2, y, w, h,
  47172. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47173. false);
  47174. g.drawFittedText (currentDetails,
  47175. 0, y + h + 4, getWidth(), 100,
  47176. Justification::centredTop, numLines);
  47177. }
  47178. }
  47179. END_JUCE_NAMESPACE
  47180. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47181. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47182. BEGIN_JUCE_NAMESPACE
  47183. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47184. const String& directoryWildcardPatterns,
  47185. const String& description_)
  47186. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47187. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47188. {
  47189. parse (fileWildcardPatterns, fileWildcards);
  47190. parse (directoryWildcardPatterns, directoryWildcards);
  47191. }
  47192. WildcardFileFilter::~WildcardFileFilter()
  47193. {
  47194. }
  47195. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47196. {
  47197. return match (file, fileWildcards);
  47198. }
  47199. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47200. {
  47201. return match (file, directoryWildcards);
  47202. }
  47203. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47204. {
  47205. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47206. result.trim();
  47207. result.removeEmptyStrings();
  47208. // special case for *.*, because people use it to mean "any file", but it
  47209. // would actually ignore files with no extension.
  47210. for (int i = result.size(); --i >= 0;)
  47211. if (result[i] == T("*.*"))
  47212. result.set (i, T("*"));
  47213. }
  47214. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47215. {
  47216. const String filename (file.getFileName());
  47217. for (int i = wildcards.size(); --i >= 0;)
  47218. if (filename.matchesWildcard (wildcards[i], true))
  47219. return true;
  47220. return false;
  47221. }
  47222. END_JUCE_NAMESPACE
  47223. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47224. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47225. BEGIN_JUCE_NAMESPACE
  47226. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47227. {
  47228. }
  47229. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47230. {
  47231. }
  47232. namespace KeyboardFocusHelpers
  47233. {
  47234. // This will sort a set of components, so that they are ordered in terms of
  47235. // left-to-right and then top-to-bottom.
  47236. class ScreenPositionComparator
  47237. {
  47238. public:
  47239. ScreenPositionComparator() {}
  47240. static int compareElements (const Component* const first, const Component* const second) throw()
  47241. {
  47242. int explicitOrder1 = first->getExplicitFocusOrder();
  47243. if (explicitOrder1 <= 0)
  47244. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47245. int explicitOrder2 = second->getExplicitFocusOrder();
  47246. if (explicitOrder2 <= 0)
  47247. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47248. if (explicitOrder1 != explicitOrder2)
  47249. return explicitOrder1 - explicitOrder2;
  47250. const int diff = first->getY() - second->getY();
  47251. return (diff == 0) ? first->getX() - second->getX()
  47252. : diff;
  47253. }
  47254. };
  47255. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47256. {
  47257. if (parent->getNumChildComponents() > 0)
  47258. {
  47259. Array <Component*> localComps;
  47260. ScreenPositionComparator comparator;
  47261. int i;
  47262. for (i = parent->getNumChildComponents(); --i >= 0;)
  47263. {
  47264. Component* const c = parent->getChildComponent (i);
  47265. if (c->isVisible() && c->isEnabled())
  47266. localComps.addSorted (comparator, c);
  47267. }
  47268. for (i = 0; i < localComps.size(); ++i)
  47269. {
  47270. Component* const c = localComps.getUnchecked (i);
  47271. if (c->getWantsKeyboardFocus())
  47272. comps.add (c);
  47273. if (! c->isFocusContainer())
  47274. findAllFocusableComponents (c, comps);
  47275. }
  47276. }
  47277. }
  47278. }
  47279. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47280. {
  47281. Component* focusContainer = current->getParentComponent();
  47282. if (focusContainer != 0)
  47283. {
  47284. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47285. focusContainer = focusContainer->getParentComponent();
  47286. if (focusContainer != 0)
  47287. {
  47288. Array <Component*> comps;
  47289. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47290. if (comps.size() > 0)
  47291. {
  47292. const int index = comps.indexOf (current);
  47293. return comps [(index + comps.size() + delta) % comps.size()];
  47294. }
  47295. }
  47296. }
  47297. return 0;
  47298. }
  47299. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47300. {
  47301. return getIncrementedComponent (current, 1);
  47302. }
  47303. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47304. {
  47305. return getIncrementedComponent (current, -1);
  47306. }
  47307. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47308. {
  47309. Array <Component*> comps;
  47310. if (parentComponent != 0)
  47311. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47312. return comps.getFirst();
  47313. }
  47314. END_JUCE_NAMESPACE
  47315. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47316. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47317. BEGIN_JUCE_NAMESPACE
  47318. bool KeyListener::keyStateChanged (const bool, Component*)
  47319. {
  47320. return false;
  47321. }
  47322. END_JUCE_NAMESPACE
  47323. /*** End of inlined file: juce_KeyListener.cpp ***/
  47324. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47325. BEGIN_JUCE_NAMESPACE
  47326. // N.B. these two includes are put here deliberately to avoid problems with
  47327. // old GCCs failing on long include paths
  47328. const int maxKeys = 3;
  47329. class KeyMappingChangeButton : public Button
  47330. {
  47331. public:
  47332. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47333. const CommandID commandID_,
  47334. const String& keyName,
  47335. const int keyNum_)
  47336. : Button (keyName),
  47337. owner (owner_),
  47338. commandID (commandID_),
  47339. keyNum (keyNum_)
  47340. {
  47341. setWantsKeyboardFocus (false);
  47342. setTriggeredOnMouseDown (keyNum >= 0);
  47343. if (keyNum_ < 0)
  47344. setTooltip (TRANS("adds a new key-mapping"));
  47345. else
  47346. setTooltip (TRANS("click to change this key-mapping"));
  47347. }
  47348. ~KeyMappingChangeButton()
  47349. {
  47350. }
  47351. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47352. {
  47353. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47354. keyNum >= 0 ? getName() : String::empty);
  47355. }
  47356. void clicked()
  47357. {
  47358. if (keyNum >= 0)
  47359. {
  47360. // existing key clicked..
  47361. PopupMenu m;
  47362. m.addItem (1, TRANS("change this key-mapping"));
  47363. m.addSeparator();
  47364. m.addItem (2, TRANS("remove this key-mapping"));
  47365. const int res = m.show();
  47366. if (res == 1)
  47367. {
  47368. owner->assignNewKey (commandID, keyNum);
  47369. }
  47370. else if (res == 2)
  47371. {
  47372. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47373. }
  47374. }
  47375. else
  47376. {
  47377. // + button pressed..
  47378. owner->assignNewKey (commandID, -1);
  47379. }
  47380. }
  47381. void fitToContent (const int h) throw()
  47382. {
  47383. if (keyNum < 0)
  47384. {
  47385. setSize (h, h);
  47386. }
  47387. else
  47388. {
  47389. Font f (h * 0.6f);
  47390. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47391. }
  47392. }
  47393. juce_UseDebuggingNewOperator
  47394. private:
  47395. KeyMappingEditorComponent* const owner;
  47396. const CommandID commandID;
  47397. const int keyNum;
  47398. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47399. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47400. };
  47401. class KeyMappingItemComponent : public Component
  47402. {
  47403. public:
  47404. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47405. const CommandID commandID_)
  47406. : owner (owner_),
  47407. commandID (commandID_)
  47408. {
  47409. setInterceptsMouseClicks (false, true);
  47410. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47411. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47412. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47413. {
  47414. KeyMappingChangeButton* const kb
  47415. = new KeyMappingChangeButton (owner_, commandID,
  47416. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47417. kb->setEnabled (! isReadOnly);
  47418. addAndMakeVisible (kb);
  47419. }
  47420. KeyMappingChangeButton* const kb
  47421. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47422. addChildComponent (kb);
  47423. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47424. }
  47425. ~KeyMappingItemComponent()
  47426. {
  47427. deleteAllChildren();
  47428. }
  47429. void paint (Graphics& g)
  47430. {
  47431. g.setFont (getHeight() * 0.7f);
  47432. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47433. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47434. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47435. Justification::centredLeft, true);
  47436. }
  47437. void resized()
  47438. {
  47439. int x = getWidth() - 4;
  47440. for (int i = getNumChildComponents(); --i >= 0;)
  47441. {
  47442. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47443. kb->fitToContent (getHeight() - 2);
  47444. kb->setTopRightPosition (x, 1);
  47445. x -= kb->getWidth() + 5;
  47446. }
  47447. }
  47448. juce_UseDebuggingNewOperator
  47449. private:
  47450. KeyMappingEditorComponent* const owner;
  47451. const CommandID commandID;
  47452. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47453. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47454. };
  47455. class KeyMappingTreeViewItem : public TreeViewItem
  47456. {
  47457. public:
  47458. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47459. const CommandID commandID_)
  47460. : owner (owner_),
  47461. commandID (commandID_)
  47462. {
  47463. }
  47464. ~KeyMappingTreeViewItem()
  47465. {
  47466. }
  47467. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47468. bool mightContainSubItems() { return false; }
  47469. int getItemHeight() const { return 20; }
  47470. Component* createItemComponent()
  47471. {
  47472. return new KeyMappingItemComponent (owner, commandID);
  47473. }
  47474. juce_UseDebuggingNewOperator
  47475. private:
  47476. KeyMappingEditorComponent* const owner;
  47477. const CommandID commandID;
  47478. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47479. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47480. };
  47481. class KeyCategoryTreeViewItem : public TreeViewItem
  47482. {
  47483. public:
  47484. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47485. const String& name)
  47486. : owner (owner_),
  47487. categoryName (name)
  47488. {
  47489. }
  47490. ~KeyCategoryTreeViewItem()
  47491. {
  47492. }
  47493. const String getUniqueName() const { return categoryName + "_cat"; }
  47494. bool mightContainSubItems() { return true; }
  47495. int getItemHeight() const { return 28; }
  47496. void paintItem (Graphics& g, int width, int height)
  47497. {
  47498. g.setFont (height * 0.6f, Font::bold);
  47499. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47500. g.drawText (categoryName,
  47501. 2, 0, width - 2, height,
  47502. Justification::centredLeft, true);
  47503. }
  47504. void itemOpennessChanged (bool isNowOpen)
  47505. {
  47506. if (isNowOpen)
  47507. {
  47508. if (getNumSubItems() == 0)
  47509. {
  47510. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47511. for (int i = 0; i < commands.size(); ++i)
  47512. {
  47513. if (owner->shouldCommandBeIncluded (commands[i]))
  47514. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47515. }
  47516. }
  47517. }
  47518. else
  47519. {
  47520. clearSubItems();
  47521. }
  47522. }
  47523. juce_UseDebuggingNewOperator
  47524. private:
  47525. KeyMappingEditorComponent* owner;
  47526. String categoryName;
  47527. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47528. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47529. };
  47530. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47531. const bool showResetToDefaultButton)
  47532. : mappings (mappingManager)
  47533. {
  47534. jassert (mappingManager != 0); // can't be null!
  47535. mappingManager->addChangeListener (this);
  47536. setLinesDrawnForSubItems (false);
  47537. resetButton = 0;
  47538. if (showResetToDefaultButton)
  47539. {
  47540. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47541. resetButton->addButtonListener (this);
  47542. }
  47543. addAndMakeVisible (tree = new TreeView());
  47544. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47545. tree->setRootItemVisible (false);
  47546. tree->setDefaultOpenness (true);
  47547. tree->setRootItem (this);
  47548. }
  47549. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47550. {
  47551. mappings->removeChangeListener (this);
  47552. deleteAllChildren();
  47553. }
  47554. bool KeyMappingEditorComponent::mightContainSubItems()
  47555. {
  47556. return true;
  47557. }
  47558. const String KeyMappingEditorComponent::getUniqueName() const
  47559. {
  47560. return T("keys");
  47561. }
  47562. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47563. const Colour& textColour)
  47564. {
  47565. setColour (backgroundColourId, mainBackground);
  47566. setColour (textColourId, textColour);
  47567. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47568. }
  47569. void KeyMappingEditorComponent::parentHierarchyChanged()
  47570. {
  47571. changeListenerCallback (0);
  47572. }
  47573. void KeyMappingEditorComponent::resized()
  47574. {
  47575. int h = getHeight();
  47576. if (resetButton != 0)
  47577. {
  47578. const int buttonHeight = 20;
  47579. h -= buttonHeight + 8;
  47580. int x = getWidth() - 8;
  47581. const int y = h + 6;
  47582. resetButton->changeWidthToFitText (buttonHeight);
  47583. resetButton->setTopRightPosition (x, y);
  47584. }
  47585. tree->setBounds (0, 0, getWidth(), h);
  47586. }
  47587. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47588. {
  47589. if (button == resetButton)
  47590. {
  47591. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47592. TRANS("Reset to defaults"),
  47593. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47594. TRANS("Reset")))
  47595. {
  47596. mappings->resetToDefaultMappings();
  47597. }
  47598. }
  47599. }
  47600. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47601. {
  47602. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47603. clearSubItems();
  47604. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47605. for (int i = 0; i < categories.size(); ++i)
  47606. {
  47607. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47608. int count = 0;
  47609. for (int j = 0; j < commands.size(); ++j)
  47610. if (shouldCommandBeIncluded (commands[j]))
  47611. ++count;
  47612. if (count > 0)
  47613. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47614. }
  47615. if (openness != 0)
  47616. tree->restoreOpennessState (*openness);
  47617. }
  47618. class KeyEntryWindow : public AlertWindow
  47619. {
  47620. public:
  47621. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47622. : AlertWindow (TRANS("New key-mapping"),
  47623. TRANS("Please press a key combination now..."),
  47624. AlertWindow::NoIcon),
  47625. owner (owner_)
  47626. {
  47627. addButton (TRANS("ok"), 1);
  47628. addButton (TRANS("cancel"), 0);
  47629. // (avoid return + escape keys getting processed by the buttons..)
  47630. for (int i = getNumChildComponents(); --i >= 0;)
  47631. getChildComponent (i)->setWantsKeyboardFocus (false);
  47632. setWantsKeyboardFocus (true);
  47633. grabKeyboardFocus();
  47634. }
  47635. ~KeyEntryWindow()
  47636. {
  47637. }
  47638. bool keyPressed (const KeyPress& key)
  47639. {
  47640. lastPress = key;
  47641. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47642. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47643. if (previousCommand != 0)
  47644. {
  47645. message << "\n\n"
  47646. << TRANS("(Currently assigned to \"")
  47647. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47648. << "\")";
  47649. }
  47650. setMessage (message);
  47651. return true;
  47652. }
  47653. bool keyStateChanged (const bool)
  47654. {
  47655. return true;
  47656. }
  47657. KeyPress lastPress;
  47658. juce_UseDebuggingNewOperator
  47659. private:
  47660. KeyMappingEditorComponent* owner;
  47661. KeyEntryWindow (const KeyEntryWindow&);
  47662. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47663. };
  47664. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47665. {
  47666. KeyEntryWindow entryWindow (this);
  47667. if (entryWindow.runModalLoop() != 0)
  47668. {
  47669. entryWindow.setVisible (false);
  47670. if (entryWindow.lastPress.isValid())
  47671. {
  47672. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47673. if (previousCommand != 0)
  47674. {
  47675. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47676. TRANS("Change key-mapping"),
  47677. TRANS("This key is already assigned to the command \"")
  47678. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47679. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47680. TRANS("re-assign"),
  47681. TRANS("cancel")))
  47682. {
  47683. return;
  47684. }
  47685. }
  47686. mappings->removeKeyPress (entryWindow.lastPress);
  47687. if (index >= 0)
  47688. mappings->removeKeyPress (commandID, index);
  47689. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47690. }
  47691. }
  47692. }
  47693. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47694. {
  47695. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47696. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47697. }
  47698. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47699. {
  47700. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47701. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47702. }
  47703. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47704. {
  47705. return key.getTextDescription();
  47706. }
  47707. END_JUCE_NAMESPACE
  47708. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47709. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47710. BEGIN_JUCE_NAMESPACE
  47711. KeyPress::KeyPress() throw()
  47712. : keyCode (0),
  47713. mods (0),
  47714. textCharacter (0)
  47715. {
  47716. }
  47717. KeyPress::KeyPress (const int keyCode_,
  47718. const ModifierKeys& mods_,
  47719. const juce_wchar textCharacter_) throw()
  47720. : keyCode (keyCode_),
  47721. mods (mods_),
  47722. textCharacter (textCharacter_)
  47723. {
  47724. }
  47725. KeyPress::KeyPress (const int keyCode_) throw()
  47726. : keyCode (keyCode_),
  47727. textCharacter (0)
  47728. {
  47729. }
  47730. KeyPress::KeyPress (const KeyPress& other) throw()
  47731. : keyCode (other.keyCode),
  47732. mods (other.mods),
  47733. textCharacter (other.textCharacter)
  47734. {
  47735. }
  47736. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47737. {
  47738. keyCode = other.keyCode;
  47739. mods = other.mods;
  47740. textCharacter = other.textCharacter;
  47741. return *this;
  47742. }
  47743. bool KeyPress::operator== (const KeyPress& other) const throw()
  47744. {
  47745. return mods.getRawFlags() == other.mods.getRawFlags()
  47746. && (textCharacter == other.textCharacter
  47747. || textCharacter == 0
  47748. || other.textCharacter == 0)
  47749. && (keyCode == other.keyCode
  47750. || (keyCode < 256
  47751. && other.keyCode < 256
  47752. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  47753. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  47754. }
  47755. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47756. {
  47757. return ! operator== (other);
  47758. }
  47759. bool KeyPress::isCurrentlyDown() const throw()
  47760. {
  47761. return isKeyCurrentlyDown (keyCode)
  47762. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47763. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47764. }
  47765. struct KeyNameAndCode
  47766. {
  47767. const char* name;
  47768. int code;
  47769. };
  47770. static const KeyNameAndCode keyNameTranslations[] =
  47771. {
  47772. { "spacebar", KeyPress::spaceKey },
  47773. { "return", KeyPress::returnKey },
  47774. { "escape", KeyPress::escapeKey },
  47775. { "backspace", KeyPress::backspaceKey },
  47776. { "cursor left", KeyPress::leftKey },
  47777. { "cursor right", KeyPress::rightKey },
  47778. { "cursor up", KeyPress::upKey },
  47779. { "cursor down", KeyPress::downKey },
  47780. { "page up", KeyPress::pageUpKey },
  47781. { "page down", KeyPress::pageDownKey },
  47782. { "home", KeyPress::homeKey },
  47783. { "end", KeyPress::endKey },
  47784. { "delete", KeyPress::deleteKey },
  47785. { "insert", KeyPress::insertKey },
  47786. { "tab", KeyPress::tabKey },
  47787. { "play", KeyPress::playKey },
  47788. { "stop", KeyPress::stopKey },
  47789. { "fast forward", KeyPress::fastForwardKey },
  47790. { "rewind", KeyPress::rewindKey }
  47791. };
  47792. static const tchar* const numberPadPrefix = T("numpad ");
  47793. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  47794. {
  47795. int modifiers = 0;
  47796. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  47797. || desc.containsWholeWordIgnoreCase (T("control"))
  47798. || desc.containsWholeWordIgnoreCase (T("ctl")))
  47799. modifiers |= ModifierKeys::ctrlModifier;
  47800. if (desc.containsWholeWordIgnoreCase (T("shift"))
  47801. || desc.containsWholeWordIgnoreCase (T("shft")))
  47802. modifiers |= ModifierKeys::shiftModifier;
  47803. if (desc.containsWholeWordIgnoreCase (T("alt"))
  47804. || desc.containsWholeWordIgnoreCase (T("option")))
  47805. modifiers |= ModifierKeys::altModifier;
  47806. if (desc.containsWholeWordIgnoreCase (T("command"))
  47807. || desc.containsWholeWordIgnoreCase (T("cmd")))
  47808. modifiers |= ModifierKeys::commandModifier;
  47809. int key = 0;
  47810. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  47811. {
  47812. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  47813. {
  47814. key = keyNameTranslations[i].code;
  47815. break;
  47816. }
  47817. }
  47818. if (key == 0)
  47819. {
  47820. // see if it's a numpad key..
  47821. if (desc.containsIgnoreCase (numberPadPrefix))
  47822. {
  47823. const tchar lastChar = desc.trimEnd().getLastCharacter();
  47824. if (lastChar >= T('0') && lastChar <= T('9'))
  47825. key = numberPad0 + lastChar - T('0');
  47826. else if (lastChar == T('+'))
  47827. key = numberPadAdd;
  47828. else if (lastChar == T('-'))
  47829. key = numberPadSubtract;
  47830. else if (lastChar == T('*'))
  47831. key = numberPadMultiply;
  47832. else if (lastChar == T('/'))
  47833. key = numberPadDivide;
  47834. else if (lastChar == T('.'))
  47835. key = numberPadDecimalPoint;
  47836. else if (lastChar == T('='))
  47837. key = numberPadEquals;
  47838. else if (desc.endsWith (T("separator")))
  47839. key = numberPadSeparator;
  47840. else if (desc.endsWith (T("delete")))
  47841. key = numberPadDelete;
  47842. }
  47843. if (key == 0)
  47844. {
  47845. // see if it's a function key..
  47846. for (int i = 1; i <= 12; ++i)
  47847. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  47848. key = F1Key + i - 1;
  47849. if (key == 0)
  47850. {
  47851. // give up and use the hex code..
  47852. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  47853. .toLowerCase()
  47854. .retainCharacters (T("0123456789abcdef"))
  47855. .getHexValue32();
  47856. if (hexCode > 0)
  47857. key = hexCode;
  47858. else
  47859. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47860. }
  47861. }
  47862. }
  47863. return KeyPress (key, ModifierKeys (modifiers), 0);
  47864. }
  47865. const String KeyPress::getTextDescription() const throw()
  47866. {
  47867. String desc;
  47868. if (keyCode > 0)
  47869. {
  47870. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47871. // want to store it as being a slash, not shift+whatever.
  47872. if (textCharacter == T('/'))
  47873. return "/";
  47874. if (mods.isCtrlDown())
  47875. desc << "ctrl + ";
  47876. if (mods.isShiftDown())
  47877. desc << "shift + ";
  47878. #if JUCE_MAC
  47879. // only do this on the mac, because on Windows ctrl and command are the same,
  47880. // and this would get confusing
  47881. if (mods.isCommandDown())
  47882. desc << "command + ";
  47883. if (mods.isAltDown())
  47884. desc << "option + ";
  47885. #else
  47886. if (mods.isAltDown())
  47887. desc << "alt + ";
  47888. #endif
  47889. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  47890. if (keyCode == keyNameTranslations[i].code)
  47891. return desc + keyNameTranslations[i].name;
  47892. if (keyCode >= F1Key && keyCode <= F16Key)
  47893. desc << 'F' << (1 + keyCode - F1Key);
  47894. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47895. desc << numberPadPrefix << (keyCode - numberPad0);
  47896. else if (keyCode >= 33 && keyCode < 176)
  47897. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  47898. else if (keyCode == numberPadAdd)
  47899. desc << numberPadPrefix << '+';
  47900. else if (keyCode == numberPadSubtract)
  47901. desc << numberPadPrefix << '-';
  47902. else if (keyCode == numberPadMultiply)
  47903. desc << numberPadPrefix << '*';
  47904. else if (keyCode == numberPadDivide)
  47905. desc << numberPadPrefix << '/';
  47906. else if (keyCode == numberPadSeparator)
  47907. desc << numberPadPrefix << "separator";
  47908. else if (keyCode == numberPadDecimalPoint)
  47909. desc << numberPadPrefix << '.';
  47910. else if (keyCode == numberPadDelete)
  47911. desc << numberPadPrefix << "delete";
  47912. else
  47913. desc << '#' << String::toHexString (keyCode);
  47914. }
  47915. return desc;
  47916. }
  47917. END_JUCE_NAMESPACE
  47918. /*** End of inlined file: juce_KeyPress.cpp ***/
  47919. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  47920. BEGIN_JUCE_NAMESPACE
  47921. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  47922. : commandManager (commandManager_)
  47923. {
  47924. // A manager is needed to get the descriptions of commands, and will be called when
  47925. // a command is invoked. So you can't leave this null..
  47926. jassert (commandManager_ != 0);
  47927. Desktop::getInstance().addFocusChangeListener (this);
  47928. }
  47929. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  47930. : commandManager (other.commandManager)
  47931. {
  47932. Desktop::getInstance().addFocusChangeListener (this);
  47933. }
  47934. KeyPressMappingSet::~KeyPressMappingSet()
  47935. {
  47936. Desktop::getInstance().removeFocusChangeListener (this);
  47937. }
  47938. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  47939. {
  47940. for (int i = 0; i < mappings.size(); ++i)
  47941. if (mappings.getUnchecked(i)->commandID == commandID)
  47942. return mappings.getUnchecked (i)->keypresses;
  47943. return Array <KeyPress> ();
  47944. }
  47945. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  47946. const KeyPress& newKeyPress,
  47947. int insertIndex) throw()
  47948. {
  47949. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  47950. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  47951. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  47952. && ! newKeyPress.getModifiers().isShiftDown()));
  47953. if (findCommandForKeyPress (newKeyPress) != commandID)
  47954. {
  47955. removeKeyPress (newKeyPress);
  47956. if (newKeyPress.isValid())
  47957. {
  47958. for (int i = mappings.size(); --i >= 0;)
  47959. {
  47960. if (mappings.getUnchecked(i)->commandID == commandID)
  47961. {
  47962. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  47963. sendChangeMessage (this);
  47964. return;
  47965. }
  47966. }
  47967. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47968. if (ci != 0)
  47969. {
  47970. CommandMapping* const cm = new CommandMapping();
  47971. cm->commandID = commandID;
  47972. cm->keypresses.add (newKeyPress);
  47973. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  47974. mappings.add (cm);
  47975. sendChangeMessage (this);
  47976. }
  47977. }
  47978. }
  47979. }
  47980. void KeyPressMappingSet::resetToDefaultMappings() throw()
  47981. {
  47982. mappings.clear();
  47983. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  47984. {
  47985. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  47986. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47987. {
  47988. addKeyPress (ci->commandID,
  47989. ci->defaultKeypresses.getReference (j));
  47990. }
  47991. }
  47992. sendChangeMessage (this);
  47993. }
  47994. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  47995. {
  47996. clearAllKeyPresses (commandID);
  47997. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47998. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47999. {
  48000. addKeyPress (ci->commandID,
  48001. ci->defaultKeypresses.getReference (j));
  48002. }
  48003. }
  48004. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48005. {
  48006. if (mappings.size() > 0)
  48007. {
  48008. sendChangeMessage (this);
  48009. mappings.clear();
  48010. }
  48011. }
  48012. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48013. {
  48014. for (int i = mappings.size(); --i >= 0;)
  48015. {
  48016. if (mappings.getUnchecked(i)->commandID == commandID)
  48017. {
  48018. mappings.remove (i);
  48019. sendChangeMessage (this);
  48020. }
  48021. }
  48022. }
  48023. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48024. {
  48025. if (keypress.isValid())
  48026. {
  48027. for (int i = mappings.size(); --i >= 0;)
  48028. {
  48029. CommandMapping* const cm = mappings.getUnchecked(i);
  48030. for (int j = cm->keypresses.size(); --j >= 0;)
  48031. {
  48032. if (keypress == cm->keypresses [j])
  48033. {
  48034. cm->keypresses.remove (j);
  48035. sendChangeMessage (this);
  48036. }
  48037. }
  48038. }
  48039. }
  48040. }
  48041. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48042. const int keyPressIndex) throw()
  48043. {
  48044. for (int i = mappings.size(); --i >= 0;)
  48045. {
  48046. if (mappings.getUnchecked(i)->commandID == commandID)
  48047. {
  48048. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48049. sendChangeMessage (this);
  48050. break;
  48051. }
  48052. }
  48053. }
  48054. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48055. {
  48056. for (int i = 0; i < mappings.size(); ++i)
  48057. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48058. return mappings.getUnchecked(i)->commandID;
  48059. return 0;
  48060. }
  48061. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48062. const KeyPress& keyPress) const throw()
  48063. {
  48064. for (int i = mappings.size(); --i >= 0;)
  48065. if (mappings.getUnchecked(i)->commandID == commandID)
  48066. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48067. return false;
  48068. }
  48069. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48070. const KeyPress& key,
  48071. const bool isKeyDown,
  48072. const int millisecsSinceKeyPressed,
  48073. Component* const originatingComponent) const
  48074. {
  48075. ApplicationCommandTarget::InvocationInfo info (commandID);
  48076. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48077. info.isKeyDown = isKeyDown;
  48078. info.keyPress = key;
  48079. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48080. info.originatingComponent = originatingComponent;
  48081. commandManager->invoke (info, false);
  48082. }
  48083. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48084. {
  48085. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48086. {
  48087. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48088. {
  48089. // if the XML was created as a set of differences from the default mappings,
  48090. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48091. resetToDefaultMappings();
  48092. }
  48093. else
  48094. {
  48095. // if the XML was created calling createXml (false), then we need to clear all
  48096. // the keys and treat the xml as describing the entire set of mappings.
  48097. clearAllKeyPresses();
  48098. }
  48099. forEachXmlChildElement (xmlVersion, map)
  48100. {
  48101. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48102. if (commandId != 0)
  48103. {
  48104. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48105. if (map->hasTagName (T("MAPPING")))
  48106. {
  48107. addKeyPress (commandId, key);
  48108. }
  48109. else if (map->hasTagName (T("UNMAPPING")))
  48110. {
  48111. if (containsMapping (commandId, key))
  48112. removeKeyPress (key);
  48113. }
  48114. }
  48115. }
  48116. return true;
  48117. }
  48118. return false;
  48119. }
  48120. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48121. {
  48122. ScopedPointer <KeyPressMappingSet> defaultSet;
  48123. if (saveDifferencesFromDefaultSet)
  48124. {
  48125. defaultSet = new KeyPressMappingSet (commandManager);
  48126. defaultSet->resetToDefaultMappings();
  48127. }
  48128. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48129. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48130. int i;
  48131. for (i = 0; i < mappings.size(); ++i)
  48132. {
  48133. const CommandMapping* const cm = mappings.getUnchecked(i);
  48134. for (int j = 0; j < cm->keypresses.size(); ++j)
  48135. {
  48136. if (defaultSet == 0
  48137. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48138. {
  48139. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48140. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48141. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48142. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48143. }
  48144. }
  48145. }
  48146. if (defaultSet != 0)
  48147. {
  48148. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48149. {
  48150. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48151. for (int j = 0; j < cm->keypresses.size(); ++j)
  48152. {
  48153. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48154. {
  48155. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48156. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48157. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48158. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48159. }
  48160. }
  48161. }
  48162. }
  48163. return doc;
  48164. }
  48165. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48166. Component* originatingComponent)
  48167. {
  48168. bool used = false;
  48169. const CommandID commandID = findCommandForKeyPress (key);
  48170. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48171. if (ci != 0
  48172. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48173. {
  48174. ApplicationCommandInfo info (0);
  48175. if (commandManager->getTargetForCommand (commandID, info) != 0
  48176. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48177. {
  48178. invokeCommand (commandID, key, true, 0, originatingComponent);
  48179. used = true;
  48180. }
  48181. else
  48182. {
  48183. if (originatingComponent != 0)
  48184. originatingComponent->getLookAndFeel().playAlertSound();
  48185. }
  48186. }
  48187. return used;
  48188. }
  48189. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48190. {
  48191. bool used = false;
  48192. const uint32 now = Time::getMillisecondCounter();
  48193. for (int i = mappings.size(); --i >= 0;)
  48194. {
  48195. CommandMapping* const cm = mappings.getUnchecked(i);
  48196. if (cm->wantsKeyUpDownCallbacks)
  48197. {
  48198. for (int j = cm->keypresses.size(); --j >= 0;)
  48199. {
  48200. const KeyPress key (cm->keypresses.getReference (j));
  48201. const bool isDown = key.isCurrentlyDown();
  48202. int keyPressEntryIndex = 0;
  48203. bool wasDown = false;
  48204. for (int k = keysDown.size(); --k >= 0;)
  48205. {
  48206. if (key == keysDown.getUnchecked(k)->key)
  48207. {
  48208. keyPressEntryIndex = k;
  48209. wasDown = true;
  48210. used = true;
  48211. break;
  48212. }
  48213. }
  48214. if (isDown != wasDown)
  48215. {
  48216. int millisecs = 0;
  48217. if (isDown)
  48218. {
  48219. KeyPressTime* const k = new KeyPressTime();
  48220. k->key = key;
  48221. k->timeWhenPressed = now;
  48222. keysDown.add (k);
  48223. }
  48224. else
  48225. {
  48226. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48227. if (now > pressTime)
  48228. millisecs = now - pressTime;
  48229. keysDown.remove (keyPressEntryIndex);
  48230. }
  48231. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48232. used = true;
  48233. }
  48234. }
  48235. }
  48236. }
  48237. return used;
  48238. }
  48239. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48240. {
  48241. if (focusedComponent != 0)
  48242. focusedComponent->keyStateChanged (false);
  48243. }
  48244. END_JUCE_NAMESPACE
  48245. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48246. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48247. BEGIN_JUCE_NAMESPACE
  48248. ModifierKeys::ModifierKeys (const int flags_) throw()
  48249. : flags (flags_)
  48250. {
  48251. }
  48252. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48253. : flags (other.flags)
  48254. {
  48255. }
  48256. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48257. {
  48258. flags = other.flags;
  48259. return *this;
  48260. }
  48261. ModifierKeys ModifierKeys::currentModifiers;
  48262. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48263. {
  48264. return currentModifiers;
  48265. }
  48266. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48267. {
  48268. int num = 0;
  48269. if (isLeftButtonDown()) ++num;
  48270. if (isRightButtonDown()) ++num;
  48271. if (isMiddleButtonDown()) ++num;
  48272. return num;
  48273. }
  48274. END_JUCE_NAMESPACE
  48275. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48276. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48277. BEGIN_JUCE_NAMESPACE
  48278. struct AnimationTask
  48279. {
  48280. AnimationTask (Component* const comp)
  48281. : component (comp)
  48282. {
  48283. }
  48284. Component::SafePointer<Component> component;
  48285. Rectangle<int> destination;
  48286. int msElapsed, msTotal;
  48287. double startSpeed, midSpeed, endSpeed, lastProgress;
  48288. double left, top, right, bottom;
  48289. bool useTimeslice (const int elapsed)
  48290. {
  48291. if (component == 0)
  48292. return false;
  48293. msElapsed += elapsed;
  48294. double newProgress = msElapsed / (double) msTotal;
  48295. if (newProgress >= 0 && newProgress < 1.0)
  48296. {
  48297. newProgress = timeToDistance (newProgress);
  48298. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48299. jassert (newProgress >= lastProgress);
  48300. lastProgress = newProgress;
  48301. left += (destination.getX() - left) * delta;
  48302. top += (destination.getY() - top) * delta;
  48303. right += (destination.getRight() - right) * delta;
  48304. bottom += (destination.getBottom() - bottom) * delta;
  48305. if (delta < 1.0)
  48306. {
  48307. const Rectangle<int> newBounds (roundToInt (left),
  48308. roundToInt (top),
  48309. roundToInt (right - left),
  48310. roundToInt (bottom - top));
  48311. if (newBounds != destination)
  48312. {
  48313. component->setBounds (newBounds);
  48314. return true;
  48315. }
  48316. }
  48317. }
  48318. component->setBounds (destination);
  48319. return false;
  48320. }
  48321. void moveToFinalDestination()
  48322. {
  48323. if (component != 0)
  48324. component->setBounds (destination);
  48325. }
  48326. private:
  48327. inline double timeToDistance (const double time) const
  48328. {
  48329. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48330. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48331. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48332. }
  48333. };
  48334. ComponentAnimator::ComponentAnimator()
  48335. : lastTime (0)
  48336. {
  48337. }
  48338. ComponentAnimator::~ComponentAnimator()
  48339. {
  48340. cancelAllAnimations (false);
  48341. jassert (tasks.size() == 0);
  48342. }
  48343. void* ComponentAnimator::findTaskFor (Component* const component) const
  48344. {
  48345. for (int i = tasks.size(); --i >= 0;)
  48346. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component.getComponent())
  48347. return tasks.getUnchecked(i);
  48348. return 0;
  48349. }
  48350. void ComponentAnimator::animateComponent (Component* const component,
  48351. const Rectangle<int>& finalPosition,
  48352. const int millisecondsToSpendMoving,
  48353. const double startSpeed,
  48354. const double endSpeed)
  48355. {
  48356. if (component != 0)
  48357. {
  48358. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48359. if (at == 0)
  48360. {
  48361. at = new AnimationTask (component);
  48362. tasks.add (at);
  48363. sendChangeMessage (this);
  48364. }
  48365. at->msElapsed = 0;
  48366. at->lastProgress = 0;
  48367. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48368. at->destination = finalPosition;
  48369. // the speeds must be 0 or greater!
  48370. jassert (startSpeed >= 0 && endSpeed >= 0)
  48371. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48372. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48373. at->midSpeed = invTotalDistance;
  48374. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48375. at->left = component->getX();
  48376. at->top = component->getY();
  48377. at->right = component->getRight();
  48378. at->bottom = component->getBottom();
  48379. if (! isTimerRunning())
  48380. {
  48381. lastTime = Time::getMillisecondCounter();
  48382. startTimer (1000 / 50);
  48383. }
  48384. }
  48385. }
  48386. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48387. {
  48388. for (int i = tasks.size(); --i >= 0;)
  48389. {
  48390. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48391. if (moveComponentsToTheirFinalPositions)
  48392. at->moveToFinalDestination();
  48393. delete at;
  48394. tasks.remove (i);
  48395. sendChangeMessage (this);
  48396. }
  48397. }
  48398. void ComponentAnimator::cancelAnimation (Component* const component,
  48399. const bool moveComponentToItsFinalPosition)
  48400. {
  48401. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48402. if (at != 0)
  48403. {
  48404. if (moveComponentToItsFinalPosition)
  48405. at->moveToFinalDestination();
  48406. tasks.removeValue (at);
  48407. delete at;
  48408. sendChangeMessage (this);
  48409. }
  48410. }
  48411. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48412. {
  48413. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48414. if (at != 0)
  48415. return at->destination;
  48416. else if (component != 0)
  48417. return component->getBounds();
  48418. return Rectangle<int>();
  48419. }
  48420. bool ComponentAnimator::isAnimating (Component* component) const
  48421. {
  48422. return findTaskFor (component) != 0;
  48423. }
  48424. void ComponentAnimator::timerCallback()
  48425. {
  48426. const uint32 timeNow = Time::getMillisecondCounter();
  48427. if (lastTime == 0 || lastTime == timeNow)
  48428. lastTime = timeNow;
  48429. const int elapsed = timeNow - lastTime;
  48430. for (int i = tasks.size(); --i >= 0;)
  48431. {
  48432. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48433. if (! at->useTimeslice (elapsed))
  48434. {
  48435. tasks.remove (i);
  48436. delete at;
  48437. sendChangeMessage (this);
  48438. }
  48439. }
  48440. lastTime = timeNow;
  48441. if (tasks.size() == 0)
  48442. stopTimer();
  48443. }
  48444. END_JUCE_NAMESPACE
  48445. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48446. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48447. BEGIN_JUCE_NAMESPACE
  48448. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48449. : minW (0),
  48450. maxW (0x3fffffff),
  48451. minH (0),
  48452. maxH (0x3fffffff),
  48453. minOffTop (0),
  48454. minOffLeft (0),
  48455. minOffBottom (0),
  48456. minOffRight (0),
  48457. aspectRatio (0.0)
  48458. {
  48459. }
  48460. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48461. {
  48462. }
  48463. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48464. {
  48465. minW = minimumWidth;
  48466. }
  48467. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48468. {
  48469. maxW = maximumWidth;
  48470. }
  48471. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48472. {
  48473. minH = minimumHeight;
  48474. }
  48475. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48476. {
  48477. maxH = maximumHeight;
  48478. }
  48479. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48480. {
  48481. jassert (maxW >= minimumWidth);
  48482. jassert (maxH >= minimumHeight);
  48483. jassert (minimumWidth > 0 && minimumHeight > 0);
  48484. minW = minimumWidth;
  48485. minH = minimumHeight;
  48486. if (minW > maxW)
  48487. maxW = minW;
  48488. if (minH > maxH)
  48489. maxH = minH;
  48490. }
  48491. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48492. {
  48493. jassert (maximumWidth >= minW);
  48494. jassert (maximumHeight >= minH);
  48495. jassert (maximumWidth > 0 && maximumHeight > 0);
  48496. maxW = jmax (minW, maximumWidth);
  48497. maxH = jmax (minH, maximumHeight);
  48498. }
  48499. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48500. const int minimumHeight,
  48501. const int maximumWidth,
  48502. const int maximumHeight) throw()
  48503. {
  48504. jassert (maximumWidth >= minimumWidth);
  48505. jassert (maximumHeight >= minimumHeight);
  48506. jassert (maximumWidth > 0 && maximumHeight > 0);
  48507. jassert (minimumWidth > 0 && minimumHeight > 0);
  48508. minW = jmax (0, minimumWidth);
  48509. minH = jmax (0, minimumHeight);
  48510. maxW = jmax (minW, maximumWidth);
  48511. maxH = jmax (minH, maximumHeight);
  48512. }
  48513. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48514. const int minimumWhenOffTheLeft,
  48515. const int minimumWhenOffTheBottom,
  48516. const int minimumWhenOffTheRight) throw()
  48517. {
  48518. minOffTop = minimumWhenOffTheTop;
  48519. minOffLeft = minimumWhenOffTheLeft;
  48520. minOffBottom = minimumWhenOffTheBottom;
  48521. minOffRight = minimumWhenOffTheRight;
  48522. }
  48523. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48524. {
  48525. aspectRatio = jmax (0.0, widthOverHeight);
  48526. }
  48527. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48528. {
  48529. return aspectRatio;
  48530. }
  48531. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48532. const Rectangle<int>& targetBounds,
  48533. const bool isStretchingTop,
  48534. const bool isStretchingLeft,
  48535. const bool isStretchingBottom,
  48536. const bool isStretchingRight)
  48537. {
  48538. jassert (component != 0);
  48539. Rectangle<int> limits, bounds (targetBounds);
  48540. BorderSize border;
  48541. Component* const parent = component->getParentComponent();
  48542. if (parent == 0)
  48543. {
  48544. ComponentPeer* peer = component->getPeer();
  48545. if (peer != 0)
  48546. border = peer->getFrameSize();
  48547. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48548. }
  48549. else
  48550. {
  48551. limits.setSize (parent->getWidth(), parent->getHeight());
  48552. }
  48553. border.addTo (bounds);
  48554. checkBounds (bounds,
  48555. border.addedTo (component->getBounds()), limits,
  48556. isStretchingTop, isStretchingLeft,
  48557. isStretchingBottom, isStretchingRight);
  48558. border.subtractFrom (bounds);
  48559. applyBoundsToComponent (component, bounds);
  48560. }
  48561. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48562. {
  48563. setBoundsForComponent (component, component->getBounds(),
  48564. false, false, false, false);
  48565. }
  48566. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48567. const Rectangle<int>& bounds)
  48568. {
  48569. component->setBounds (bounds);
  48570. }
  48571. void ComponentBoundsConstrainer::resizeStart()
  48572. {
  48573. }
  48574. void ComponentBoundsConstrainer::resizeEnd()
  48575. {
  48576. }
  48577. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48578. const Rectangle<int>& old,
  48579. const Rectangle<int>& limits,
  48580. const bool isStretchingTop,
  48581. const bool isStretchingLeft,
  48582. const bool isStretchingBottom,
  48583. const bool isStretchingRight)
  48584. {
  48585. int x = bounds.getX();
  48586. int y = bounds.getY();
  48587. int w = bounds.getWidth();
  48588. int h = bounds.getHeight();
  48589. // constrain the size if it's being stretched..
  48590. if (isStretchingLeft)
  48591. {
  48592. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48593. w = old.getRight() - x;
  48594. }
  48595. if (isStretchingRight)
  48596. {
  48597. w = jlimit (minW, maxW, w);
  48598. }
  48599. if (isStretchingTop)
  48600. {
  48601. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48602. h = old.getBottom() - y;
  48603. }
  48604. if (isStretchingBottom)
  48605. {
  48606. h = jlimit (minH, maxH, h);
  48607. }
  48608. // constrain the aspect ratio if one has been specified..
  48609. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48610. {
  48611. bool adjustWidth;
  48612. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48613. {
  48614. adjustWidth = true;
  48615. }
  48616. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48617. {
  48618. adjustWidth = false;
  48619. }
  48620. else
  48621. {
  48622. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48623. const double newRatio = fabs (w / (double) h);
  48624. adjustWidth = (oldRatio > newRatio);
  48625. }
  48626. if (adjustWidth)
  48627. {
  48628. w = roundToInt (h * aspectRatio);
  48629. if (w > maxW || w < minW)
  48630. {
  48631. w = jlimit (minW, maxW, w);
  48632. h = roundToInt (w / aspectRatio);
  48633. }
  48634. }
  48635. else
  48636. {
  48637. h = roundToInt (w / aspectRatio);
  48638. if (h > maxH || h < minH)
  48639. {
  48640. h = jlimit (minH, maxH, h);
  48641. w = roundToInt (h * aspectRatio);
  48642. }
  48643. }
  48644. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48645. {
  48646. x = old.getX() + (old.getWidth() - w) / 2;
  48647. }
  48648. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48649. {
  48650. y = old.getY() + (old.getHeight() - h) / 2;
  48651. }
  48652. else
  48653. {
  48654. if (isStretchingLeft)
  48655. x = old.getRight() - w;
  48656. if (isStretchingTop)
  48657. y = old.getBottom() - h;
  48658. }
  48659. }
  48660. // ...and constrain the position if limits have been set for that.
  48661. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48662. {
  48663. if (minOffTop > 0)
  48664. {
  48665. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48666. if (y < limit)
  48667. {
  48668. if (isStretchingTop)
  48669. h -= (limit - y);
  48670. y = limit;
  48671. }
  48672. }
  48673. if (minOffLeft > 0)
  48674. {
  48675. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48676. if (x < limit)
  48677. {
  48678. if (isStretchingLeft)
  48679. w -= (limit - x);
  48680. x = limit;
  48681. }
  48682. }
  48683. if (minOffBottom > 0)
  48684. {
  48685. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48686. if (y > limit)
  48687. {
  48688. if (isStretchingBottom)
  48689. h += (limit - y);
  48690. else
  48691. y = limit;
  48692. }
  48693. }
  48694. if (minOffRight > 0)
  48695. {
  48696. const int limit = limits.getRight() - jmin (minOffRight, w);
  48697. if (x > limit)
  48698. {
  48699. if (isStretchingRight)
  48700. w += (limit - x);
  48701. else
  48702. x = limit;
  48703. }
  48704. }
  48705. }
  48706. jassert (w >= 0 && h >= 0);
  48707. bounds = Rectangle<int> (x, y, w, h);
  48708. }
  48709. END_JUCE_NAMESPACE
  48710. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48711. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48712. BEGIN_JUCE_NAMESPACE
  48713. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48714. : component (component_),
  48715. lastPeer (0),
  48716. reentrant (false)
  48717. {
  48718. jassert (component != 0); // can't use this with a null pointer..
  48719. component->addComponentListener (this);
  48720. registerWithParentComps();
  48721. }
  48722. ComponentMovementWatcher::~ComponentMovementWatcher()
  48723. {
  48724. component->removeComponentListener (this);
  48725. unregister();
  48726. }
  48727. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48728. {
  48729. // agh! don't delete the target component without deleting this object first!
  48730. jassert (component != 0);
  48731. if (! reentrant)
  48732. {
  48733. reentrant = true;
  48734. ComponentPeer* const peer = component->getPeer();
  48735. if (peer != lastPeer)
  48736. {
  48737. componentPeerChanged();
  48738. if (component == 0)
  48739. return;
  48740. lastPeer = peer;
  48741. }
  48742. unregister();
  48743. registerWithParentComps();
  48744. reentrant = false;
  48745. componentMovedOrResized (*component, true, true);
  48746. }
  48747. }
  48748. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48749. {
  48750. // agh! don't delete the target component without deleting this object first!
  48751. jassert (component != 0);
  48752. if (wasMoved)
  48753. {
  48754. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48755. wasMoved = lastBounds.getPosition() != pos;
  48756. lastBounds.setPosition (pos);
  48757. }
  48758. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48759. lastBounds.setSize (component->getWidth(), component->getHeight());
  48760. if (wasMoved || wasResized)
  48761. componentMovedOrResized (wasMoved, wasResized);
  48762. }
  48763. void ComponentMovementWatcher::registerWithParentComps() throw()
  48764. {
  48765. Component* p = component->getParentComponent();
  48766. while (p != 0)
  48767. {
  48768. p->addComponentListener (this);
  48769. registeredParentComps.add (p);
  48770. p = p->getParentComponent();
  48771. }
  48772. }
  48773. void ComponentMovementWatcher::unregister() throw()
  48774. {
  48775. for (int i = registeredParentComps.size(); --i >= 0;)
  48776. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48777. registeredParentComps.clear();
  48778. }
  48779. END_JUCE_NAMESPACE
  48780. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48781. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48782. BEGIN_JUCE_NAMESPACE
  48783. GroupComponent::GroupComponent (const String& componentName,
  48784. const String& labelText)
  48785. : Component (componentName),
  48786. text (labelText),
  48787. justification (Justification::left)
  48788. {
  48789. setInterceptsMouseClicks (false, true);
  48790. }
  48791. GroupComponent::~GroupComponent()
  48792. {
  48793. }
  48794. void GroupComponent::setText (const String& newText) throw()
  48795. {
  48796. if (text != newText)
  48797. {
  48798. text = newText;
  48799. repaint();
  48800. }
  48801. }
  48802. const String GroupComponent::getText() const throw()
  48803. {
  48804. return text;
  48805. }
  48806. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48807. {
  48808. if (justification.getFlags() != newJustification.getFlags())
  48809. {
  48810. justification = newJustification;
  48811. repaint();
  48812. }
  48813. }
  48814. void GroupComponent::paint (Graphics& g)
  48815. {
  48816. getLookAndFeel()
  48817. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48818. text, justification,
  48819. *this);
  48820. }
  48821. void GroupComponent::enablementChanged()
  48822. {
  48823. repaint();
  48824. }
  48825. void GroupComponent::colourChanged()
  48826. {
  48827. repaint();
  48828. }
  48829. END_JUCE_NAMESPACE
  48830. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48831. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48832. BEGIN_JUCE_NAMESPACE
  48833. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48834. : DocumentWindow (String::empty, backgroundColour,
  48835. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48836. {
  48837. }
  48838. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48839. {
  48840. }
  48841. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48842. {
  48843. MultiDocumentPanel* const owner = getOwner();
  48844. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48845. if (owner != 0)
  48846. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48847. }
  48848. void MultiDocumentPanelWindow::closeButtonPressed()
  48849. {
  48850. MultiDocumentPanel* const owner = getOwner();
  48851. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48852. if (owner != 0)
  48853. owner->closeDocument (getContentComponent(), true);
  48854. }
  48855. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48856. {
  48857. DocumentWindow::activeWindowStatusChanged();
  48858. updateOrder();
  48859. }
  48860. void MultiDocumentPanelWindow::broughtToFront()
  48861. {
  48862. DocumentWindow::broughtToFront();
  48863. updateOrder();
  48864. }
  48865. void MultiDocumentPanelWindow::updateOrder()
  48866. {
  48867. MultiDocumentPanel* const owner = getOwner();
  48868. if (owner != 0)
  48869. owner->updateOrder();
  48870. }
  48871. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48872. {
  48873. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48874. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48875. }
  48876. class MDITabbedComponentInternal : public TabbedComponent
  48877. {
  48878. public:
  48879. MDITabbedComponentInternal()
  48880. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48881. {
  48882. }
  48883. ~MDITabbedComponentInternal()
  48884. {
  48885. }
  48886. void currentTabChanged (const int, const String&)
  48887. {
  48888. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48889. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48890. if (owner != 0)
  48891. owner->updateOrder();
  48892. }
  48893. };
  48894. MultiDocumentPanel::MultiDocumentPanel()
  48895. : mode (MaximisedWindowsWithTabs),
  48896. tabComponent (0),
  48897. backgroundColour (Colours::lightblue),
  48898. maximumNumDocuments (0),
  48899. numDocsBeforeTabsUsed (0)
  48900. {
  48901. setOpaque (true);
  48902. }
  48903. MultiDocumentPanel::~MultiDocumentPanel()
  48904. {
  48905. closeAllDocuments (false);
  48906. }
  48907. static bool shouldDeleteComp (Component* const c)
  48908. {
  48909. return c->getProperties() ["mdiDocumentDelete_"];
  48910. }
  48911. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48912. {
  48913. while (components.size() > 0)
  48914. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  48915. return false;
  48916. return true;
  48917. }
  48918. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  48919. {
  48920. return new MultiDocumentPanelWindow (backgroundColour);
  48921. }
  48922. void MultiDocumentPanel::addWindow (Component* component)
  48923. {
  48924. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  48925. dw->setResizable (true, false);
  48926. dw->setContentComponent (component, false, true);
  48927. dw->setName (component->getName());
  48928. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  48929. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  48930. int x = 4;
  48931. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  48932. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  48933. x += 16;
  48934. dw->setTopLeftPosition (x, x);
  48935. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  48936. if (pos.toString().isNotEmpty())
  48937. dw->restoreWindowStateFromString (pos.toString());
  48938. addAndMakeVisible (dw);
  48939. dw->toFront (true);
  48940. }
  48941. bool MultiDocumentPanel::addDocument (Component* const component,
  48942. const Colour& docColour,
  48943. const bool deleteWhenRemoved)
  48944. {
  48945. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  48946. // with a frame-within-a-frame! Just pass in the bare content component.
  48947. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  48948. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  48949. return false;
  48950. components.add (component);
  48951. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  48952. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  48953. component->addComponentListener (this);
  48954. if (mode == FloatingWindows)
  48955. {
  48956. if (isFullscreenWhenOneDocument())
  48957. {
  48958. if (components.size() == 1)
  48959. {
  48960. addAndMakeVisible (component);
  48961. }
  48962. else
  48963. {
  48964. if (components.size() == 2)
  48965. addWindow (components.getFirst());
  48966. addWindow (component);
  48967. }
  48968. }
  48969. else
  48970. {
  48971. addWindow (component);
  48972. }
  48973. }
  48974. else
  48975. {
  48976. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  48977. {
  48978. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  48979. Array <Component*> temp (components);
  48980. for (int i = 0; i < temp.size(); ++i)
  48981. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  48982. resized();
  48983. }
  48984. else
  48985. {
  48986. if (tabComponent != 0)
  48987. tabComponent->addTab (component->getName(), docColour, component, false);
  48988. else
  48989. addAndMakeVisible (component);
  48990. }
  48991. setActiveDocument (component);
  48992. }
  48993. resized();
  48994. activeDocumentChanged();
  48995. return true;
  48996. }
  48997. bool MultiDocumentPanel::closeDocument (Component* component,
  48998. const bool checkItsOkToCloseFirst)
  48999. {
  49000. if (components.contains (component))
  49001. {
  49002. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  49003. return false;
  49004. component->removeComponentListener (this);
  49005. const bool shouldDelete = shouldDeleteComp (component);
  49006. component->getProperties().remove ("mdiDocumentDelete_");
  49007. component->getProperties().remove ("mdiDocumentBkg_");
  49008. if (mode == FloatingWindows)
  49009. {
  49010. for (int i = getNumChildComponents(); --i >= 0;)
  49011. {
  49012. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49013. if (dw != 0 && dw->getContentComponent() == component)
  49014. {
  49015. dw->setContentComponent (0, false);
  49016. delete dw;
  49017. break;
  49018. }
  49019. }
  49020. if (shouldDelete)
  49021. delete component;
  49022. components.removeValue (component);
  49023. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49024. {
  49025. for (int i = getNumChildComponents(); --i >= 0;)
  49026. {
  49027. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49028. if (dw != 0)
  49029. {
  49030. dw->setContentComponent (0, false);
  49031. delete dw;
  49032. }
  49033. }
  49034. addAndMakeVisible (components.getFirst());
  49035. }
  49036. }
  49037. else
  49038. {
  49039. jassert (components.indexOf (component) >= 0);
  49040. if (tabComponent != 0)
  49041. {
  49042. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49043. if (tabComponent->getTabContentComponent (i) == component)
  49044. tabComponent->removeTab (i);
  49045. }
  49046. else
  49047. {
  49048. removeChildComponent (component);
  49049. }
  49050. if (shouldDelete)
  49051. delete component;
  49052. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49053. deleteAndZero (tabComponent);
  49054. components.removeValue (component);
  49055. if (components.size() > 0 && tabComponent == 0)
  49056. addAndMakeVisible (components.getFirst());
  49057. }
  49058. resized();
  49059. activeDocumentChanged();
  49060. }
  49061. else
  49062. {
  49063. jassertfalse
  49064. }
  49065. return true;
  49066. }
  49067. int MultiDocumentPanel::getNumDocuments() const throw()
  49068. {
  49069. return components.size();
  49070. }
  49071. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49072. {
  49073. return components [index];
  49074. }
  49075. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49076. {
  49077. if (mode == FloatingWindows)
  49078. {
  49079. for (int i = getNumChildComponents(); --i >= 0;)
  49080. {
  49081. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49082. if (dw != 0 && dw->isActiveWindow())
  49083. return dw->getContentComponent();
  49084. }
  49085. }
  49086. return components.getLast();
  49087. }
  49088. void MultiDocumentPanel::setActiveDocument (Component* component)
  49089. {
  49090. if (mode == FloatingWindows)
  49091. {
  49092. component = getContainerComp (component);
  49093. if (component != 0)
  49094. component->toFront (true);
  49095. }
  49096. else if (tabComponent != 0)
  49097. {
  49098. jassert (components.indexOf (component) >= 0);
  49099. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49100. {
  49101. if (tabComponent->getTabContentComponent (i) == component)
  49102. {
  49103. tabComponent->setCurrentTabIndex (i);
  49104. break;
  49105. }
  49106. }
  49107. }
  49108. else
  49109. {
  49110. component->grabKeyboardFocus();
  49111. }
  49112. }
  49113. void MultiDocumentPanel::activeDocumentChanged()
  49114. {
  49115. }
  49116. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49117. {
  49118. maximumNumDocuments = newNumber;
  49119. }
  49120. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49121. {
  49122. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49123. }
  49124. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49125. {
  49126. return numDocsBeforeTabsUsed != 0;
  49127. }
  49128. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49129. {
  49130. if (mode != newLayoutMode)
  49131. {
  49132. mode = newLayoutMode;
  49133. if (mode == FloatingWindows)
  49134. {
  49135. deleteAndZero (tabComponent);
  49136. }
  49137. else
  49138. {
  49139. for (int i = getNumChildComponents(); --i >= 0;)
  49140. {
  49141. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49142. if (dw != 0)
  49143. {
  49144. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49145. dw->setContentComponent (0, false);
  49146. delete dw;
  49147. }
  49148. }
  49149. }
  49150. resized();
  49151. const Array <Component*> tempComps (components);
  49152. components.clear();
  49153. for (int i = 0; i < tempComps.size(); ++i)
  49154. {
  49155. Component* const c = tempComps.getUnchecked(i);
  49156. addDocument (c,
  49157. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49158. shouldDeleteComp (c));
  49159. }
  49160. }
  49161. }
  49162. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49163. {
  49164. if (backgroundColour != newBackgroundColour)
  49165. {
  49166. backgroundColour = newBackgroundColour;
  49167. setOpaque (newBackgroundColour.isOpaque());
  49168. repaint();
  49169. }
  49170. }
  49171. void MultiDocumentPanel::paint (Graphics& g)
  49172. {
  49173. g.fillAll (backgroundColour);
  49174. }
  49175. void MultiDocumentPanel::resized()
  49176. {
  49177. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49178. {
  49179. for (int i = getNumChildComponents(); --i >= 0;)
  49180. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49181. }
  49182. setWantsKeyboardFocus (components.size() == 0);
  49183. }
  49184. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49185. {
  49186. if (mode == FloatingWindows)
  49187. {
  49188. for (int i = 0; i < getNumChildComponents(); ++i)
  49189. {
  49190. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49191. if (dw != 0 && dw->getContentComponent() == c)
  49192. {
  49193. c = dw;
  49194. break;
  49195. }
  49196. }
  49197. }
  49198. return c;
  49199. }
  49200. void MultiDocumentPanel::componentNameChanged (Component&)
  49201. {
  49202. if (mode == FloatingWindows)
  49203. {
  49204. for (int i = 0; i < getNumChildComponents(); ++i)
  49205. {
  49206. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49207. if (dw != 0)
  49208. dw->setName (dw->getContentComponent()->getName());
  49209. }
  49210. }
  49211. else if (tabComponent != 0)
  49212. {
  49213. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49214. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49215. }
  49216. }
  49217. void MultiDocumentPanel::updateOrder()
  49218. {
  49219. const Array <Component*> oldList (components);
  49220. if (mode == FloatingWindows)
  49221. {
  49222. components.clear();
  49223. for (int i = 0; i < getNumChildComponents(); ++i)
  49224. {
  49225. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49226. if (dw != 0)
  49227. components.add (dw->getContentComponent());
  49228. }
  49229. }
  49230. else
  49231. {
  49232. if (tabComponent != 0)
  49233. {
  49234. Component* const current = tabComponent->getCurrentContentComponent();
  49235. if (current != 0)
  49236. {
  49237. components.removeValue (current);
  49238. components.add (current);
  49239. }
  49240. }
  49241. }
  49242. if (components != oldList)
  49243. activeDocumentChanged();
  49244. }
  49245. END_JUCE_NAMESPACE
  49246. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49247. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49248. BEGIN_JUCE_NAMESPACE
  49249. enum ResizableBorderComponentZones
  49250. {
  49251. zoneL = 1,
  49252. zoneR = 2,
  49253. zoneT = 4,
  49254. zoneB = 8
  49255. };
  49256. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49257. ComponentBoundsConstrainer* const constrainer_)
  49258. : component (componentToResize),
  49259. constrainer (constrainer_),
  49260. borderSize (5),
  49261. mouseZone (0)
  49262. {
  49263. }
  49264. ResizableBorderComponent::~ResizableBorderComponent()
  49265. {
  49266. }
  49267. void ResizableBorderComponent::paint (Graphics& g)
  49268. {
  49269. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49270. }
  49271. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49272. {
  49273. updateMouseZone (e);
  49274. }
  49275. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49276. {
  49277. updateMouseZone (e);
  49278. }
  49279. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49280. {
  49281. if (component == 0)
  49282. {
  49283. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49284. return;
  49285. }
  49286. updateMouseZone (e);
  49287. originalBounds = component->getBounds();
  49288. if (constrainer != 0)
  49289. constrainer->resizeStart();
  49290. }
  49291. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49292. {
  49293. if (component == 0)
  49294. {
  49295. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49296. return;
  49297. }
  49298. Rectangle<int> bounds (originalBounds);
  49299. if ((mouseZone & zoneL) != 0)
  49300. bounds.setLeft (bounds.getX() + e.getDistanceFromDragStartX());
  49301. if ((mouseZone & zoneT) != 0)
  49302. bounds.setTop (bounds.getY() + e.getDistanceFromDragStartY());
  49303. if ((mouseZone & zoneR) != 0)
  49304. bounds.setWidth (bounds.getWidth() + e.getDistanceFromDragStartX());
  49305. if ((mouseZone & zoneB) != 0)
  49306. bounds.setHeight (bounds.getHeight() + e.getDistanceFromDragStartY());
  49307. if (constrainer != 0)
  49308. constrainer->setBoundsForComponent (component, bounds,
  49309. (mouseZone & zoneT) != 0,
  49310. (mouseZone & zoneL) != 0,
  49311. (mouseZone & zoneB) != 0,
  49312. (mouseZone & zoneR) != 0);
  49313. else
  49314. component->setBounds (bounds);
  49315. }
  49316. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49317. {
  49318. if (constrainer != 0)
  49319. constrainer->resizeEnd();
  49320. }
  49321. bool ResizableBorderComponent::hitTest (int x, int y)
  49322. {
  49323. return x < borderSize.getLeft()
  49324. || x >= getWidth() - borderSize.getRight()
  49325. || y < borderSize.getTop()
  49326. || y >= getHeight() - borderSize.getBottom();
  49327. }
  49328. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49329. {
  49330. if (borderSize != newBorderSize)
  49331. {
  49332. borderSize = newBorderSize;
  49333. repaint();
  49334. }
  49335. }
  49336. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49337. {
  49338. return borderSize;
  49339. }
  49340. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49341. {
  49342. int newZone = 0;
  49343. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49344. {
  49345. if (e.x < jmax (borderSize.getLeft(),
  49346. proportionOfWidth (0.1f),
  49347. jmin (10, proportionOfWidth (0.33f))))
  49348. newZone |= zoneL;
  49349. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49350. proportionOfWidth (0.9f),
  49351. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49352. newZone |= zoneR;
  49353. if (e.y < jmax (borderSize.getTop(),
  49354. proportionOfHeight (0.1f),
  49355. jmin (10, proportionOfHeight (0.33f))))
  49356. newZone |= zoneT;
  49357. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49358. proportionOfHeight (0.9f),
  49359. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49360. newZone |= zoneB;
  49361. }
  49362. if (mouseZone != newZone)
  49363. {
  49364. mouseZone = newZone;
  49365. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49366. switch (newZone)
  49367. {
  49368. case (zoneL | zoneT): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  49369. case zoneT: mc = MouseCursor::TopEdgeResizeCursor; break;
  49370. case (zoneR | zoneT): mc = MouseCursor::TopRightCornerResizeCursor; break;
  49371. case zoneL: mc = MouseCursor::LeftEdgeResizeCursor; break;
  49372. case zoneR: mc = MouseCursor::RightEdgeResizeCursor; break;
  49373. case (zoneL | zoneB): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  49374. case zoneB: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49375. case (zoneR | zoneB): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49376. default: break;
  49377. }
  49378. setMouseCursor (mc);
  49379. }
  49380. }
  49381. END_JUCE_NAMESPACE
  49382. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49383. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49384. BEGIN_JUCE_NAMESPACE
  49385. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49386. ComponentBoundsConstrainer* const constrainer_)
  49387. : component (componentToResize),
  49388. constrainer (constrainer_)
  49389. {
  49390. setRepaintsOnMouseActivity (true);
  49391. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49392. }
  49393. ResizableCornerComponent::~ResizableCornerComponent()
  49394. {
  49395. }
  49396. void ResizableCornerComponent::paint (Graphics& g)
  49397. {
  49398. getLookAndFeel()
  49399. .drawCornerResizer (g, getWidth(), getHeight(),
  49400. isMouseOverOrDragging(),
  49401. isMouseButtonDown());
  49402. }
  49403. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49404. {
  49405. if (component == 0)
  49406. {
  49407. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49408. return;
  49409. }
  49410. originalBounds = component->getBounds();
  49411. if (constrainer != 0)
  49412. constrainer->resizeStart();
  49413. }
  49414. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49415. {
  49416. if (component == 0)
  49417. {
  49418. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49419. return;
  49420. }
  49421. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49422. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49423. if (constrainer != 0)
  49424. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49425. else
  49426. component->setBounds (r);
  49427. }
  49428. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49429. {
  49430. if (constrainer != 0)
  49431. constrainer->resizeStart();
  49432. }
  49433. bool ResizableCornerComponent::hitTest (int x, int y)
  49434. {
  49435. if (getWidth() <= 0)
  49436. return false;
  49437. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49438. return y >= yAtX - getHeight() / 4;
  49439. }
  49440. END_JUCE_NAMESPACE
  49441. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49442. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49443. BEGIN_JUCE_NAMESPACE
  49444. class ScrollbarButton : public Button
  49445. {
  49446. public:
  49447. int direction;
  49448. ScrollbarButton (const int direction_,
  49449. ScrollBar& owner_) throw()
  49450. : Button (String::empty),
  49451. direction (direction_),
  49452. owner (owner_)
  49453. {
  49454. setWantsKeyboardFocus (false);
  49455. }
  49456. ~ScrollbarButton()
  49457. {
  49458. }
  49459. void paintButton (Graphics& g,
  49460. bool isMouseOver,
  49461. bool isMouseDown)
  49462. {
  49463. getLookAndFeel()
  49464. .drawScrollbarButton (g, owner,
  49465. getWidth(), getHeight(),
  49466. direction,
  49467. owner.isVertical(),
  49468. isMouseOver, isMouseDown);
  49469. }
  49470. void clicked()
  49471. {
  49472. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49473. }
  49474. juce_UseDebuggingNewOperator
  49475. private:
  49476. ScrollBar& owner;
  49477. ScrollbarButton (const ScrollbarButton&);
  49478. ScrollbarButton& operator= (const ScrollbarButton&);
  49479. };
  49480. ScrollBar::ScrollBar (const bool vertical_,
  49481. const bool buttonsAreVisible)
  49482. : minimum (0.0),
  49483. maximum (1.0),
  49484. rangeStart (0.0),
  49485. rangeSize (0.1),
  49486. singleStepSize (0.1),
  49487. thumbAreaStart (0),
  49488. thumbAreaSize (0),
  49489. thumbStart (0),
  49490. thumbSize (0),
  49491. initialDelayInMillisecs (100),
  49492. repeatDelayInMillisecs (50),
  49493. minimumDelayInMillisecs (10),
  49494. vertical (vertical_),
  49495. isDraggingThumb (false),
  49496. alwaysVisible (false),
  49497. upButton (0),
  49498. downButton (0)
  49499. {
  49500. setButtonVisibility (buttonsAreVisible);
  49501. setRepaintsOnMouseActivity (true);
  49502. setFocusContainer (true);
  49503. }
  49504. ScrollBar::~ScrollBar()
  49505. {
  49506. deleteAllChildren();
  49507. }
  49508. void ScrollBar::setRangeLimits (const double newMinimum,
  49509. const double newMaximum) throw()
  49510. {
  49511. minimum = newMinimum;
  49512. maximum = newMaximum;
  49513. jassert (maximum >= minimum); // these can't be the wrong way round!
  49514. setCurrentRangeStart (rangeStart);
  49515. updateThumbPosition();
  49516. }
  49517. void ScrollBar::setCurrentRange (double newStart,
  49518. double newSize) throw()
  49519. {
  49520. newSize = jlimit (0.0, maximum - minimum, newSize);
  49521. newStart = jlimit (minimum, maximum - newSize, newStart);
  49522. if (rangeStart != newStart
  49523. || rangeSize != newSize)
  49524. {
  49525. rangeStart = newStart;
  49526. rangeSize = newSize;
  49527. updateThumbPosition();
  49528. triggerAsyncUpdate();
  49529. }
  49530. }
  49531. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  49532. {
  49533. setCurrentRange (newStart, rangeSize);
  49534. }
  49535. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  49536. {
  49537. singleStepSize = newSingleStepSize;
  49538. }
  49539. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  49540. {
  49541. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  49542. }
  49543. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  49544. {
  49545. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  49546. }
  49547. void ScrollBar::scrollToTop() throw()
  49548. {
  49549. setCurrentRangeStart (minimum);
  49550. }
  49551. void ScrollBar::scrollToBottom() throw()
  49552. {
  49553. setCurrentRangeStart (maximum - rangeSize);
  49554. }
  49555. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49556. const int repeatDelayInMillisecs_,
  49557. const int minimumDelayInMillisecs_) throw()
  49558. {
  49559. initialDelayInMillisecs = initialDelayInMillisecs_;
  49560. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49561. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49562. if (upButton != 0)
  49563. {
  49564. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49565. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49566. }
  49567. }
  49568. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  49569. {
  49570. listeners.add (listener);
  49571. }
  49572. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  49573. {
  49574. listeners.remove (listener);
  49575. }
  49576. void ScrollBar::handleAsyncUpdate()
  49577. {
  49578. listeners.call (&ScrollBarListener::scrollBarMoved, this, rangeStart);
  49579. }
  49580. void ScrollBar::updateThumbPosition() throw()
  49581. {
  49582. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  49583. : thumbAreaSize);
  49584. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49585. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49586. if (newThumbSize > thumbAreaSize)
  49587. newThumbSize = thumbAreaSize;
  49588. int newThumbStart = thumbAreaStart;
  49589. if (maximum - minimum > rangeSize)
  49590. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  49591. / ((maximum - minimum) - rangeSize));
  49592. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  49593. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49594. {
  49595. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49596. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49597. if (vertical)
  49598. repaint (0, repaintStart, getWidth(), repaintSize);
  49599. else
  49600. repaint (repaintStart, 0, repaintSize, getHeight());
  49601. thumbStart = newThumbStart;
  49602. thumbSize = newThumbSize;
  49603. }
  49604. }
  49605. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  49606. {
  49607. if (vertical != shouldBeVertical)
  49608. {
  49609. vertical = shouldBeVertical;
  49610. if (upButton != 0)
  49611. {
  49612. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  49613. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  49614. }
  49615. updateThumbPosition();
  49616. }
  49617. }
  49618. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49619. {
  49620. deleteAndZero (upButton);
  49621. deleteAndZero (downButton);
  49622. if (buttonsAreVisible)
  49623. {
  49624. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  49625. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  49626. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49627. }
  49628. updateThumbPosition();
  49629. }
  49630. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49631. {
  49632. alwaysVisible = ! shouldHideWhenFullRange;
  49633. updateThumbPosition();
  49634. }
  49635. void ScrollBar::paint (Graphics& g)
  49636. {
  49637. if (thumbAreaSize > 0)
  49638. {
  49639. LookAndFeel& lf = getLookAndFeel();
  49640. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49641. ? thumbSize : 0;
  49642. if (vertical)
  49643. {
  49644. lf.drawScrollbar (g, *this,
  49645. 0, thumbAreaStart,
  49646. getWidth(), thumbAreaSize,
  49647. vertical,
  49648. thumbStart, thumb,
  49649. isMouseOver(), isMouseButtonDown());
  49650. }
  49651. else
  49652. {
  49653. lf.drawScrollbar (g, *this,
  49654. thumbAreaStart, 0,
  49655. thumbAreaSize, getHeight(),
  49656. vertical,
  49657. thumbStart, thumb,
  49658. isMouseOver(), isMouseButtonDown());
  49659. }
  49660. }
  49661. }
  49662. void ScrollBar::lookAndFeelChanged()
  49663. {
  49664. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49665. }
  49666. void ScrollBar::resized()
  49667. {
  49668. const int length = ((vertical) ? getHeight() : getWidth());
  49669. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49670. : 0;
  49671. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49672. {
  49673. thumbAreaStart = length >> 1;
  49674. thumbAreaSize = 0;
  49675. }
  49676. else
  49677. {
  49678. thumbAreaStart = buttonSize;
  49679. thumbAreaSize = length - (buttonSize << 1);
  49680. }
  49681. if (upButton != 0)
  49682. {
  49683. if (vertical)
  49684. {
  49685. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49686. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49687. }
  49688. else
  49689. {
  49690. upButton->setBounds (0, 0, buttonSize, getHeight());
  49691. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49692. }
  49693. }
  49694. updateThumbPosition();
  49695. }
  49696. void ScrollBar::mouseDown (const MouseEvent& e)
  49697. {
  49698. isDraggingThumb = false;
  49699. lastMousePos = vertical ? e.y : e.x;
  49700. dragStartMousePos = lastMousePos;
  49701. dragStartRange = rangeStart;
  49702. if (dragStartMousePos < thumbStart)
  49703. {
  49704. moveScrollbarInPages (-1);
  49705. startTimer (400);
  49706. }
  49707. else if (dragStartMousePos >= thumbStart + thumbSize)
  49708. {
  49709. moveScrollbarInPages (1);
  49710. startTimer (400);
  49711. }
  49712. else
  49713. {
  49714. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49715. && (thumbAreaSize > thumbSize);
  49716. }
  49717. }
  49718. void ScrollBar::mouseDrag (const MouseEvent& e)
  49719. {
  49720. if (isDraggingThumb)
  49721. {
  49722. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49723. setCurrentRangeStart (dragStartRange
  49724. + deltaPixels * ((maximum - minimum) - rangeSize)
  49725. / (thumbAreaSize - thumbSize));
  49726. }
  49727. else
  49728. {
  49729. lastMousePos = (vertical) ? e.y : e.x;
  49730. }
  49731. }
  49732. void ScrollBar::mouseUp (const MouseEvent&)
  49733. {
  49734. isDraggingThumb = false;
  49735. stopTimer();
  49736. repaint();
  49737. }
  49738. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49739. float wheelIncrementX,
  49740. float wheelIncrementY)
  49741. {
  49742. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49743. if (increment < 0)
  49744. increment = jmin (increment * 10.0f, -1.0f);
  49745. else if (increment > 0)
  49746. increment = jmax (increment * 10.0f, 1.0f);
  49747. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  49748. }
  49749. void ScrollBar::timerCallback()
  49750. {
  49751. if (isMouseButtonDown())
  49752. {
  49753. startTimer (40);
  49754. if (lastMousePos < thumbStart)
  49755. setCurrentRangeStart (rangeStart - rangeSize);
  49756. else if (lastMousePos > thumbStart + thumbSize)
  49757. setCurrentRangeStart (rangeStart + rangeSize);
  49758. }
  49759. else
  49760. {
  49761. stopTimer();
  49762. }
  49763. }
  49764. bool ScrollBar::keyPressed (const KeyPress& key)
  49765. {
  49766. if (! isVisible())
  49767. return false;
  49768. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49769. moveScrollbarInSteps (-1);
  49770. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49771. moveScrollbarInSteps (1);
  49772. else if (key.isKeyCode (KeyPress::pageUpKey))
  49773. moveScrollbarInPages (-1);
  49774. else if (key.isKeyCode (KeyPress::pageDownKey))
  49775. moveScrollbarInPages (1);
  49776. else if (key.isKeyCode (KeyPress::homeKey))
  49777. scrollToTop();
  49778. else if (key.isKeyCode (KeyPress::endKey))
  49779. scrollToBottom();
  49780. else
  49781. return false;
  49782. return true;
  49783. }
  49784. END_JUCE_NAMESPACE
  49785. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49786. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49787. BEGIN_JUCE_NAMESPACE
  49788. StretchableLayoutManager::StretchableLayoutManager()
  49789. : totalSize (0)
  49790. {
  49791. }
  49792. StretchableLayoutManager::~StretchableLayoutManager()
  49793. {
  49794. }
  49795. void StretchableLayoutManager::clearAllItems()
  49796. {
  49797. items.clear();
  49798. totalSize = 0;
  49799. }
  49800. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49801. const double minimumSize,
  49802. const double maximumSize,
  49803. const double preferredSize)
  49804. {
  49805. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49806. if (layout == 0)
  49807. {
  49808. layout = new ItemLayoutProperties();
  49809. layout->itemIndex = itemIndex;
  49810. int i;
  49811. for (i = 0; i < items.size(); ++i)
  49812. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49813. break;
  49814. items.insert (i, layout);
  49815. }
  49816. layout->minSize = minimumSize;
  49817. layout->maxSize = maximumSize;
  49818. layout->preferredSize = preferredSize;
  49819. layout->currentSize = 0;
  49820. }
  49821. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49822. double& minimumSize,
  49823. double& maximumSize,
  49824. double& preferredSize) const
  49825. {
  49826. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49827. if (layout != 0)
  49828. {
  49829. minimumSize = layout->minSize;
  49830. maximumSize = layout->maxSize;
  49831. preferredSize = layout->preferredSize;
  49832. return true;
  49833. }
  49834. return false;
  49835. }
  49836. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49837. {
  49838. totalSize = newTotalSize;
  49839. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49840. }
  49841. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49842. {
  49843. int pos = 0;
  49844. for (int i = 0; i < itemIndex; ++i)
  49845. {
  49846. const ItemLayoutProperties* const layout = getInfoFor (i);
  49847. if (layout != 0)
  49848. pos += layout->currentSize;
  49849. }
  49850. return pos;
  49851. }
  49852. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49853. {
  49854. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49855. if (layout != 0)
  49856. return layout->currentSize;
  49857. return 0;
  49858. }
  49859. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49860. {
  49861. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49862. if (layout != 0)
  49863. return -layout->currentSize / (double) totalSize;
  49864. return 0;
  49865. }
  49866. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49867. int newPosition)
  49868. {
  49869. for (int i = items.size(); --i >= 0;)
  49870. {
  49871. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49872. if (layout->itemIndex == itemIndex)
  49873. {
  49874. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49875. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49876. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49877. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49878. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49879. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49880. endPos += layout->currentSize;
  49881. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49882. updatePrefSizesToMatchCurrentPositions();
  49883. break;
  49884. }
  49885. }
  49886. }
  49887. void StretchableLayoutManager::layOutComponents (Component** const components,
  49888. int numComponents,
  49889. int x, int y, int w, int h,
  49890. const bool vertically,
  49891. const bool resizeOtherDimension)
  49892. {
  49893. setTotalSize (vertically ? h : w);
  49894. int pos = vertically ? y : x;
  49895. for (int i = 0; i < numComponents; ++i)
  49896. {
  49897. const ItemLayoutProperties* const layout = getInfoFor (i);
  49898. if (layout != 0)
  49899. {
  49900. Component* const c = components[i];
  49901. if (c != 0)
  49902. {
  49903. if (i == numComponents - 1)
  49904. {
  49905. // if it's the last item, crop it to exactly fit the available space..
  49906. if (resizeOtherDimension)
  49907. {
  49908. if (vertically)
  49909. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49910. else
  49911. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49912. }
  49913. else
  49914. {
  49915. if (vertically)
  49916. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  49917. else
  49918. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  49919. }
  49920. }
  49921. else
  49922. {
  49923. if (resizeOtherDimension)
  49924. {
  49925. if (vertically)
  49926. c->setBounds (x, pos, w, layout->currentSize);
  49927. else
  49928. c->setBounds (pos, y, layout->currentSize, h);
  49929. }
  49930. else
  49931. {
  49932. if (vertically)
  49933. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  49934. else
  49935. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  49936. }
  49937. }
  49938. }
  49939. pos += layout->currentSize;
  49940. }
  49941. }
  49942. }
  49943. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  49944. {
  49945. for (int i = items.size(); --i >= 0;)
  49946. if (items.getUnchecked(i)->itemIndex == itemIndex)
  49947. return items.getUnchecked(i);
  49948. return 0;
  49949. }
  49950. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  49951. const int endIndex,
  49952. const int availableSpace,
  49953. int startPos)
  49954. {
  49955. // calculate the total sizes
  49956. int i;
  49957. double totalIdealSize = 0.0;
  49958. int totalMinimums = 0;
  49959. for (i = startIndex; i < endIndex; ++i)
  49960. {
  49961. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49962. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  49963. totalMinimums += layout->currentSize;
  49964. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  49965. }
  49966. if (totalIdealSize <= 0)
  49967. totalIdealSize = 1.0;
  49968. // now calc the best sizes..
  49969. int extraSpace = availableSpace - totalMinimums;
  49970. while (extraSpace > 0)
  49971. {
  49972. int numWantingMoreSpace = 0;
  49973. int numHavingTakenExtraSpace = 0;
  49974. // first figure out how many comps want a slice of the extra space..
  49975. for (i = startIndex; i < endIndex; ++i)
  49976. {
  49977. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49978. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49979. const int bestSize = jlimit (layout->currentSize,
  49980. jmax (layout->currentSize,
  49981. sizeToRealSize (layout->maxSize, totalSize)),
  49982. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49983. if (bestSize > layout->currentSize)
  49984. ++numWantingMoreSpace;
  49985. }
  49986. // ..share out the extra space..
  49987. for (i = startIndex; i < endIndex; ++i)
  49988. {
  49989. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49990. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49991. int bestSize = jlimit (layout->currentSize,
  49992. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  49993. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49994. const int extraWanted = bestSize - layout->currentSize;
  49995. if (extraWanted > 0)
  49996. {
  49997. const int extraAllowed = jmin (extraWanted,
  49998. extraSpace / jmax (1, numWantingMoreSpace));
  49999. if (extraAllowed > 0)
  50000. {
  50001. ++numHavingTakenExtraSpace;
  50002. --numWantingMoreSpace;
  50003. layout->currentSize += extraAllowed;
  50004. extraSpace -= extraAllowed;
  50005. }
  50006. }
  50007. }
  50008. if (numHavingTakenExtraSpace <= 0)
  50009. break;
  50010. }
  50011. // ..and calculate the end position
  50012. for (i = startIndex; i < endIndex; ++i)
  50013. {
  50014. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50015. startPos += layout->currentSize;
  50016. }
  50017. return startPos;
  50018. }
  50019. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50020. const int endIndex) const
  50021. {
  50022. int totalMinimums = 0;
  50023. for (int i = startIndex; i < endIndex; ++i)
  50024. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50025. return totalMinimums;
  50026. }
  50027. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50028. {
  50029. int totalMaximums = 0;
  50030. for (int i = startIndex; i < endIndex; ++i)
  50031. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50032. return totalMaximums;
  50033. }
  50034. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50035. {
  50036. for (int i = 0; i < items.size(); ++i)
  50037. {
  50038. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50039. layout->preferredSize
  50040. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50041. : getItemCurrentAbsoluteSize (i);
  50042. }
  50043. }
  50044. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50045. {
  50046. if (size < 0)
  50047. size *= -totalSpace;
  50048. return roundToInt (size);
  50049. }
  50050. END_JUCE_NAMESPACE
  50051. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  50052. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50053. BEGIN_JUCE_NAMESPACE
  50054. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50055. const int itemIndex_,
  50056. const bool isVertical_)
  50057. : layout (layout_),
  50058. itemIndex (itemIndex_),
  50059. isVertical (isVertical_)
  50060. {
  50061. setRepaintsOnMouseActivity (true);
  50062. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50063. : MouseCursor::UpDownResizeCursor));
  50064. }
  50065. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50066. {
  50067. }
  50068. void StretchableLayoutResizerBar::paint (Graphics& g)
  50069. {
  50070. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50071. getWidth(), getHeight(),
  50072. isVertical,
  50073. isMouseOver(),
  50074. isMouseButtonDown());
  50075. }
  50076. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50077. {
  50078. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50079. }
  50080. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50081. {
  50082. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50083. : e.getDistanceFromDragStartY());
  50084. layout->setItemPosition (itemIndex, desiredPos);
  50085. hasBeenMoved();
  50086. }
  50087. void StretchableLayoutResizerBar::hasBeenMoved()
  50088. {
  50089. if (getParentComponent() != 0)
  50090. getParentComponent()->resized();
  50091. }
  50092. END_JUCE_NAMESPACE
  50093. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50094. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50095. BEGIN_JUCE_NAMESPACE
  50096. StretchableObjectResizer::StretchableObjectResizer()
  50097. {
  50098. }
  50099. StretchableObjectResizer::~StretchableObjectResizer()
  50100. {
  50101. }
  50102. void StretchableObjectResizer::addItem (const double size,
  50103. const double minSize, const double maxSize,
  50104. const int order)
  50105. {
  50106. // the order must be >= 0 but less than the maximum integer value.
  50107. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50108. Item* const item = new Item();
  50109. item->size = size;
  50110. item->minSize = minSize;
  50111. item->maxSize = maxSize;
  50112. item->order = order;
  50113. items.add (item);
  50114. }
  50115. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50116. {
  50117. const Item* const it = items [index];
  50118. return it != 0 ? it->size : 0;
  50119. }
  50120. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50121. {
  50122. int order = 0;
  50123. for (;;)
  50124. {
  50125. double currentSize = 0;
  50126. double minSize = 0;
  50127. double maxSize = 0;
  50128. int nextHighestOrder = std::numeric_limits<int>::max();
  50129. for (int i = 0; i < items.size(); ++i)
  50130. {
  50131. const Item* const it = items.getUnchecked(i);
  50132. currentSize += it->size;
  50133. if (it->order <= order)
  50134. {
  50135. minSize += it->minSize;
  50136. maxSize += it->maxSize;
  50137. }
  50138. else
  50139. {
  50140. minSize += it->size;
  50141. maxSize += it->size;
  50142. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50143. }
  50144. }
  50145. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50146. if (thisIterationTarget >= currentSize)
  50147. {
  50148. const double availableExtraSpace = maxSize - currentSize;
  50149. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50150. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50151. for (int i = 0; i < items.size(); ++i)
  50152. {
  50153. Item* const it = items.getUnchecked(i);
  50154. if (it->order <= order)
  50155. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50156. }
  50157. }
  50158. else
  50159. {
  50160. const double amountOfSlack = currentSize - minSize;
  50161. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50162. const double scale = targetAmountOfSlack / amountOfSlack;
  50163. for (int i = 0; i < items.size(); ++i)
  50164. {
  50165. Item* const it = items.getUnchecked(i);
  50166. if (it->order <= order)
  50167. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50168. }
  50169. }
  50170. if (nextHighestOrder < std::numeric_limits<int>::max())
  50171. order = nextHighestOrder;
  50172. else
  50173. break;
  50174. }
  50175. }
  50176. END_JUCE_NAMESPACE
  50177. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50178. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50179. BEGIN_JUCE_NAMESPACE
  50180. TabBarButton::TabBarButton (const String& name,
  50181. TabbedButtonBar* const owner_,
  50182. const int index)
  50183. : Button (name),
  50184. owner (owner_),
  50185. tabIndex (index),
  50186. overlapPixels (0)
  50187. {
  50188. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50189. setComponentEffect (&shadow);
  50190. setWantsKeyboardFocus (false);
  50191. }
  50192. TabBarButton::~TabBarButton()
  50193. {
  50194. }
  50195. void TabBarButton::paintButton (Graphics& g,
  50196. bool isMouseOverButton,
  50197. bool isButtonDown)
  50198. {
  50199. int x, y, w, h;
  50200. getActiveArea (x, y, w, h);
  50201. g.setOrigin (x, y);
  50202. getLookAndFeel()
  50203. .drawTabButton (g, w, h,
  50204. owner->getTabBackgroundColour (tabIndex),
  50205. tabIndex, getButtonText(), *this,
  50206. owner->getOrientation(),
  50207. isMouseOverButton, isButtonDown,
  50208. getToggleState());
  50209. }
  50210. void TabBarButton::clicked (const ModifierKeys& mods)
  50211. {
  50212. if (mods.isPopupMenu())
  50213. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50214. else
  50215. owner->setCurrentTabIndex (tabIndex);
  50216. }
  50217. bool TabBarButton::hitTest (int mx, int my)
  50218. {
  50219. int x, y, w, h;
  50220. getActiveArea (x, y, w, h);
  50221. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50222. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50223. {
  50224. if (((unsigned int) mx) < (unsigned int) getWidth()
  50225. && my >= y + overlapPixels
  50226. && my < y + h - overlapPixels)
  50227. return true;
  50228. }
  50229. else
  50230. {
  50231. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50232. && ((unsigned int) my) < (unsigned int) getHeight())
  50233. return true;
  50234. }
  50235. Path p;
  50236. getLookAndFeel()
  50237. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50238. owner->getOrientation(),
  50239. false, false, getToggleState());
  50240. return p.contains ((float) (mx - x),
  50241. (float) (my - y));
  50242. }
  50243. int TabBarButton::getBestTabLength (const int depth)
  50244. {
  50245. return jlimit (depth * 2,
  50246. depth * 7,
  50247. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50248. }
  50249. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50250. {
  50251. x = 0;
  50252. y = 0;
  50253. int r = getWidth();
  50254. int b = getHeight();
  50255. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50256. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50257. r -= spaceAroundImage;
  50258. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50259. x += spaceAroundImage;
  50260. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50261. y += spaceAroundImage;
  50262. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50263. b -= spaceAroundImage;
  50264. w = r - x;
  50265. h = b - y;
  50266. }
  50267. class TabAreaBehindFrontButtonComponent : public Component
  50268. {
  50269. public:
  50270. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50271. : owner (owner_)
  50272. {
  50273. setInterceptsMouseClicks (false, false);
  50274. }
  50275. ~TabAreaBehindFrontButtonComponent()
  50276. {
  50277. }
  50278. void paint (Graphics& g)
  50279. {
  50280. getLookAndFeel()
  50281. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50282. *owner, owner->getOrientation());
  50283. }
  50284. void enablementChanged()
  50285. {
  50286. repaint();
  50287. }
  50288. private:
  50289. TabbedButtonBar* const owner;
  50290. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50291. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50292. };
  50293. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50294. : orientation (orientation_),
  50295. currentTabIndex (-1),
  50296. extraTabsButton (0)
  50297. {
  50298. setInterceptsMouseClicks (false, true);
  50299. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50300. setFocusContainer (true);
  50301. }
  50302. TabbedButtonBar::~TabbedButtonBar()
  50303. {
  50304. deleteAllChildren();
  50305. }
  50306. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50307. {
  50308. orientation = newOrientation;
  50309. for (int i = getNumChildComponents(); --i >= 0;)
  50310. getChildComponent (i)->resized();
  50311. resized();
  50312. }
  50313. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50314. {
  50315. return new TabBarButton (name, this, index);
  50316. }
  50317. void TabbedButtonBar::clearTabs()
  50318. {
  50319. tabs.clear();
  50320. tabColours.clear();
  50321. currentTabIndex = -1;
  50322. deleteAndZero (extraTabsButton);
  50323. removeChildComponent (behindFrontTab);
  50324. deleteAllChildren();
  50325. addChildComponent (behindFrontTab);
  50326. setCurrentTabIndex (-1);
  50327. }
  50328. void TabbedButtonBar::addTab (const String& tabName,
  50329. const Colour& tabBackgroundColour,
  50330. int insertIndex)
  50331. {
  50332. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50333. if (tabName.isNotEmpty())
  50334. {
  50335. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50336. insertIndex = tabs.size();
  50337. for (int i = tabs.size(); --i >= insertIndex;)
  50338. {
  50339. TabBarButton* const tb = getTabButton (i);
  50340. if (tb != 0)
  50341. tb->tabIndex++;
  50342. }
  50343. tabs.insert (insertIndex, tabName);
  50344. tabColours.insert (insertIndex, tabBackgroundColour);
  50345. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50346. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50347. addAndMakeVisible (tb, insertIndex);
  50348. resized();
  50349. if (currentTabIndex < 0)
  50350. setCurrentTabIndex (0);
  50351. }
  50352. }
  50353. void TabbedButtonBar::setTabName (const int tabIndex,
  50354. const String& newName)
  50355. {
  50356. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50357. && tabs[tabIndex] != newName)
  50358. {
  50359. tabs.set (tabIndex, newName);
  50360. TabBarButton* const tb = getTabButton (tabIndex);
  50361. if (tb != 0)
  50362. tb->setButtonText (newName);
  50363. resized();
  50364. }
  50365. }
  50366. void TabbedButtonBar::removeTab (const int tabIndex)
  50367. {
  50368. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50369. {
  50370. const int oldTabIndex = currentTabIndex;
  50371. if (currentTabIndex == tabIndex)
  50372. currentTabIndex = -1;
  50373. tabs.remove (tabIndex);
  50374. tabColours.remove (tabIndex);
  50375. delete getTabButton (tabIndex);
  50376. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50377. {
  50378. TabBarButton* const tb = getTabButton (i);
  50379. if (tb != 0)
  50380. tb->tabIndex--;
  50381. }
  50382. resized();
  50383. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50384. }
  50385. }
  50386. void TabbedButtonBar::moveTab (const int currentIndex,
  50387. const int newIndex)
  50388. {
  50389. tabs.move (currentIndex, newIndex);
  50390. tabColours.move (currentIndex, newIndex);
  50391. resized();
  50392. }
  50393. int TabbedButtonBar::getNumTabs() const
  50394. {
  50395. return tabs.size();
  50396. }
  50397. const StringArray TabbedButtonBar::getTabNames() const
  50398. {
  50399. return tabs;
  50400. }
  50401. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50402. {
  50403. if (currentTabIndex != newIndex)
  50404. {
  50405. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50406. newIndex = -1;
  50407. currentTabIndex = newIndex;
  50408. for (int i = 0; i < getNumChildComponents(); ++i)
  50409. {
  50410. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50411. if (tb != 0)
  50412. tb->setToggleState (tb->tabIndex == newIndex, false);
  50413. }
  50414. resized();
  50415. if (sendChangeMessage_)
  50416. sendChangeMessage (this);
  50417. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50418. }
  50419. }
  50420. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50421. {
  50422. for (int i = getNumChildComponents(); --i >= 0;)
  50423. {
  50424. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50425. if (tb != 0 && tb->tabIndex == index)
  50426. return tb;
  50427. }
  50428. return 0;
  50429. }
  50430. void TabbedButtonBar::lookAndFeelChanged()
  50431. {
  50432. deleteAndZero (extraTabsButton);
  50433. resized();
  50434. }
  50435. void TabbedButtonBar::resized()
  50436. {
  50437. const double minimumScale = 0.7;
  50438. int depth = getWidth();
  50439. int length = getHeight();
  50440. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50441. swapVariables (depth, length);
  50442. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50443. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50444. int i, totalLength = overlap;
  50445. int numVisibleButtons = tabs.size();
  50446. for (i = 0; i < getNumChildComponents(); ++i)
  50447. {
  50448. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50449. if (tb != 0)
  50450. {
  50451. totalLength += tb->getBestTabLength (depth) - overlap;
  50452. tb->overlapPixels = overlap / 2;
  50453. }
  50454. }
  50455. double scale = 1.0;
  50456. if (totalLength > length)
  50457. scale = jmax (minimumScale, length / (double) totalLength);
  50458. const bool isTooBig = totalLength * scale > length;
  50459. int tabsButtonPos = 0;
  50460. if (isTooBig)
  50461. {
  50462. if (extraTabsButton == 0)
  50463. {
  50464. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50465. extraTabsButton->addButtonListener (this);
  50466. extraTabsButton->setAlwaysOnTop (true);
  50467. extraTabsButton->setTriggeredOnMouseDown (true);
  50468. }
  50469. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50470. extraTabsButton->setSize (buttonSize, buttonSize);
  50471. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50472. {
  50473. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50474. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50475. }
  50476. else
  50477. {
  50478. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50479. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50480. }
  50481. totalLength = 0;
  50482. for (i = 0; i < tabs.size(); ++i)
  50483. {
  50484. TabBarButton* const tb = getTabButton (i);
  50485. if (tb != 0)
  50486. {
  50487. const int newLength = totalLength + tb->getBestTabLength (depth);
  50488. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50489. {
  50490. totalLength += overlap;
  50491. break;
  50492. }
  50493. numVisibleButtons = i + 1;
  50494. totalLength = newLength - overlap;
  50495. }
  50496. }
  50497. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50498. }
  50499. else
  50500. {
  50501. deleteAndZero (extraTabsButton);
  50502. }
  50503. int pos = 0;
  50504. TabBarButton* frontTab = 0;
  50505. for (i = 0; i < tabs.size(); ++i)
  50506. {
  50507. TabBarButton* const tb = getTabButton (i);
  50508. if (tb != 0)
  50509. {
  50510. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50511. if (i < numVisibleButtons)
  50512. {
  50513. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50514. tb->setBounds (pos, 0, bestLength, getHeight());
  50515. else
  50516. tb->setBounds (0, pos, getWidth(), bestLength);
  50517. tb->toBack();
  50518. if (tb->tabIndex == currentTabIndex)
  50519. frontTab = tb;
  50520. tb->setVisible (true);
  50521. }
  50522. else
  50523. {
  50524. tb->setVisible (false);
  50525. }
  50526. pos += bestLength - overlap;
  50527. }
  50528. }
  50529. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50530. if (frontTab != 0)
  50531. {
  50532. frontTab->toFront (false);
  50533. behindFrontTab->toBehind (frontTab);
  50534. }
  50535. }
  50536. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50537. {
  50538. return tabColours [tabIndex];
  50539. }
  50540. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50541. {
  50542. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50543. && tabColours [tabIndex] != newColour)
  50544. {
  50545. tabColours.set (tabIndex, newColour);
  50546. repaint();
  50547. }
  50548. }
  50549. void TabbedButtonBar::buttonClicked (Button* button)
  50550. {
  50551. if (extraTabsButton == button)
  50552. {
  50553. PopupMenu m;
  50554. for (int i = 0; i < tabs.size(); ++i)
  50555. {
  50556. TabBarButton* const tb = getTabButton (i);
  50557. if (tb != 0 && ! tb->isVisible())
  50558. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50559. }
  50560. const int res = m.showAt (extraTabsButton);
  50561. if (res != 0)
  50562. setCurrentTabIndex (res - 1);
  50563. }
  50564. }
  50565. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50566. {
  50567. }
  50568. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50569. {
  50570. }
  50571. END_JUCE_NAMESPACE
  50572. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50573. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50574. BEGIN_JUCE_NAMESPACE
  50575. class TabCompButtonBar : public TabbedButtonBar
  50576. {
  50577. public:
  50578. TabCompButtonBar (TabbedComponent* const owner_,
  50579. const TabbedButtonBar::Orientation orientation)
  50580. : TabbedButtonBar (orientation),
  50581. owner (owner_)
  50582. {
  50583. }
  50584. ~TabCompButtonBar()
  50585. {
  50586. }
  50587. void currentTabChanged (const int newCurrentTabIndex,
  50588. const String& newTabName)
  50589. {
  50590. owner->changeCallback (newCurrentTabIndex, newTabName);
  50591. }
  50592. void popupMenuClickOnTab (const int tabIndex,
  50593. const String& tabName)
  50594. {
  50595. owner->popupMenuClickOnTab (tabIndex, tabName);
  50596. }
  50597. const Colour getTabBackgroundColour (const int tabIndex)
  50598. {
  50599. return owner->tabs->getTabBackgroundColour (tabIndex);
  50600. }
  50601. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  50602. {
  50603. return owner->createTabButton (tabName, tabIndex);
  50604. }
  50605. juce_UseDebuggingNewOperator
  50606. private:
  50607. TabbedComponent* const owner;
  50608. TabCompButtonBar (const TabCompButtonBar&);
  50609. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50610. };
  50611. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50612. : panelComponent (0),
  50613. tabDepth (30),
  50614. outlineThickness (1),
  50615. edgeIndent (0)
  50616. {
  50617. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50618. }
  50619. TabbedComponent::~TabbedComponent()
  50620. {
  50621. clearTabs();
  50622. delete tabs;
  50623. }
  50624. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50625. {
  50626. tabs->setOrientation (orientation);
  50627. resized();
  50628. }
  50629. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50630. {
  50631. return tabs->getOrientation();
  50632. }
  50633. void TabbedComponent::setTabBarDepth (const int newDepth)
  50634. {
  50635. if (tabDepth != newDepth)
  50636. {
  50637. tabDepth = newDepth;
  50638. resized();
  50639. }
  50640. }
  50641. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50642. {
  50643. return new TabBarButton (tabName, tabs, tabIndex);
  50644. }
  50645. void TabbedComponent::clearTabs()
  50646. {
  50647. if (panelComponent != 0)
  50648. {
  50649. panelComponent->setVisible (false);
  50650. removeChildComponent (panelComponent);
  50651. panelComponent = 0;
  50652. }
  50653. tabs->clearTabs();
  50654. for (int i = contentComponents.size(); --i >= 0;)
  50655. {
  50656. Component* const c = contentComponents.getUnchecked(i);
  50657. // be careful not to delete these components until they've been removed from the tab component
  50658. jassert (c == 0 || c->isValidComponent());
  50659. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50660. delete c;
  50661. }
  50662. contentComponents.clear();
  50663. }
  50664. void TabbedComponent::addTab (const String& tabName,
  50665. const Colour& tabBackgroundColour,
  50666. Component* const contentComponent,
  50667. const bool deleteComponentWhenNotNeeded,
  50668. const int insertIndex)
  50669. {
  50670. contentComponents.insert (insertIndex, contentComponent);
  50671. if (contentComponent != 0)
  50672. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50673. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50674. }
  50675. void TabbedComponent::setTabName (const int tabIndex,
  50676. const String& newName)
  50677. {
  50678. tabs->setTabName (tabIndex, newName);
  50679. }
  50680. void TabbedComponent::removeTab (const int tabIndex)
  50681. {
  50682. Component* const c = contentComponents [tabIndex];
  50683. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50684. {
  50685. if (c == panelComponent)
  50686. panelComponent = 0;
  50687. delete c;
  50688. }
  50689. contentComponents.remove (tabIndex);
  50690. tabs->removeTab (tabIndex);
  50691. }
  50692. int TabbedComponent::getNumTabs() const
  50693. {
  50694. return tabs->getNumTabs();
  50695. }
  50696. const StringArray TabbedComponent::getTabNames() const
  50697. {
  50698. return tabs->getTabNames();
  50699. }
  50700. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50701. {
  50702. return contentComponents [tabIndex];
  50703. }
  50704. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50705. {
  50706. return tabs->getTabBackgroundColour (tabIndex);
  50707. }
  50708. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50709. {
  50710. tabs->setTabBackgroundColour (tabIndex, newColour);
  50711. if (getCurrentTabIndex() == tabIndex)
  50712. repaint();
  50713. }
  50714. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50715. {
  50716. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50717. }
  50718. int TabbedComponent::getCurrentTabIndex() const
  50719. {
  50720. return tabs->getCurrentTabIndex();
  50721. }
  50722. const String& TabbedComponent::getCurrentTabName() const
  50723. {
  50724. return tabs->getCurrentTabName();
  50725. }
  50726. void TabbedComponent::setOutline (int thickness)
  50727. {
  50728. outlineThickness = thickness;
  50729. repaint();
  50730. }
  50731. void TabbedComponent::setIndent (const int indentThickness)
  50732. {
  50733. edgeIndent = indentThickness;
  50734. }
  50735. void TabbedComponent::paint (Graphics& g)
  50736. {
  50737. g.fillAll (findColour (backgroundColourId));
  50738. const TabbedButtonBar::Orientation o = getOrientation();
  50739. int x = 0;
  50740. int y = 0;
  50741. int r = getWidth();
  50742. int b = getHeight();
  50743. if (o == TabbedButtonBar::TabsAtTop)
  50744. y += tabDepth;
  50745. else if (o == TabbedButtonBar::TabsAtBottom)
  50746. b -= tabDepth;
  50747. else if (o == TabbedButtonBar::TabsAtLeft)
  50748. x += tabDepth;
  50749. else if (o == TabbedButtonBar::TabsAtRight)
  50750. r -= tabDepth;
  50751. g.reduceClipRegion (x, y, r - x, b - y);
  50752. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50753. if (outlineThickness > 0)
  50754. {
  50755. if (o == TabbedButtonBar::TabsAtTop)
  50756. --y;
  50757. else if (o == TabbedButtonBar::TabsAtBottom)
  50758. ++b;
  50759. else if (o == TabbedButtonBar::TabsAtLeft)
  50760. --x;
  50761. else if (o == TabbedButtonBar::TabsAtRight)
  50762. ++r;
  50763. g.setColour (findColour (outlineColourId));
  50764. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50765. }
  50766. }
  50767. void TabbedComponent::resized()
  50768. {
  50769. const TabbedButtonBar::Orientation o = getOrientation();
  50770. const int indent = edgeIndent + outlineThickness;
  50771. BorderSize indents (indent);
  50772. if (o == TabbedButtonBar::TabsAtTop)
  50773. {
  50774. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50775. indents.setTop (tabDepth + edgeIndent);
  50776. }
  50777. else if (o == TabbedButtonBar::TabsAtBottom)
  50778. {
  50779. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50780. indents.setBottom (tabDepth + edgeIndent);
  50781. }
  50782. else if (o == TabbedButtonBar::TabsAtLeft)
  50783. {
  50784. tabs->setBounds (0, 0, tabDepth, getHeight());
  50785. indents.setLeft (tabDepth + edgeIndent);
  50786. }
  50787. else if (o == TabbedButtonBar::TabsAtRight)
  50788. {
  50789. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50790. indents.setRight (tabDepth + edgeIndent);
  50791. }
  50792. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  50793. for (int i = contentComponents.size(); --i >= 0;)
  50794. if (contentComponents.getUnchecked (i) != 0)
  50795. contentComponents.getUnchecked (i)->setBounds (bounds);
  50796. }
  50797. void TabbedComponent::lookAndFeelChanged()
  50798. {
  50799. for (int i = contentComponents.size(); --i >= 0;)
  50800. if (contentComponents.getUnchecked (i) != 0)
  50801. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50802. }
  50803. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50804. const String& newTabName)
  50805. {
  50806. if (panelComponent != 0)
  50807. {
  50808. panelComponent->setVisible (false);
  50809. removeChildComponent (panelComponent);
  50810. panelComponent = 0;
  50811. }
  50812. if (getCurrentTabIndex() >= 0)
  50813. {
  50814. panelComponent = contentComponents [getCurrentTabIndex()];
  50815. if (panelComponent != 0)
  50816. {
  50817. // do these ops as two stages instead of addAndMakeVisible() so that the
  50818. // component has always got a parent when it gets the visibilityChanged() callback
  50819. addChildComponent (panelComponent);
  50820. panelComponent->setVisible (true);
  50821. panelComponent->toFront (true);
  50822. }
  50823. repaint();
  50824. }
  50825. resized();
  50826. currentTabChanged (newCurrentTabIndex, newTabName);
  50827. }
  50828. void TabbedComponent::currentTabChanged (const int, const String&)
  50829. {
  50830. }
  50831. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50832. {
  50833. }
  50834. END_JUCE_NAMESPACE
  50835. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50836. /*** Start of inlined file: juce_Viewport.cpp ***/
  50837. BEGIN_JUCE_NAMESPACE
  50838. Viewport::Viewport (const String& componentName)
  50839. : Component (componentName),
  50840. contentComp (0),
  50841. lastVX (0),
  50842. lastVY (0),
  50843. lastVW (0),
  50844. lastVH (0),
  50845. scrollBarThickness (0),
  50846. singleStepX (16),
  50847. singleStepY (16),
  50848. showHScrollbar (true),
  50849. showVScrollbar (true)
  50850. {
  50851. // content holder is used to clip the contents so they don't overlap the scrollbars
  50852. addAndMakeVisible (contentHolder = new Component());
  50853. contentHolder->setInterceptsMouseClicks (false, true);
  50854. verticalScrollBar = new ScrollBar (true);
  50855. horizontalScrollBar = new ScrollBar (false);
  50856. addChildComponent (verticalScrollBar);
  50857. addChildComponent (horizontalScrollBar);
  50858. verticalScrollBar->addListener (this);
  50859. horizontalScrollBar->addListener (this);
  50860. setInterceptsMouseClicks (false, true);
  50861. setWantsKeyboardFocus (true);
  50862. }
  50863. Viewport::~Viewport()
  50864. {
  50865. contentHolder->deleteAllChildren();
  50866. deleteAllChildren();
  50867. }
  50868. void Viewport::visibleAreaChanged (int, int, int, int)
  50869. {
  50870. }
  50871. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50872. {
  50873. if (contentComp.getComponent() != newViewedComponent)
  50874. {
  50875. {
  50876. ScopedPointer<Component> oldCompDeleter (contentComp);
  50877. contentComp = 0;
  50878. }
  50879. contentComp = newViewedComponent;
  50880. if (contentComp != 0)
  50881. {
  50882. contentComp->setTopLeftPosition (0, 0);
  50883. contentHolder->addAndMakeVisible (contentComp);
  50884. contentComp->addComponentListener (this);
  50885. }
  50886. updateVisibleRegion();
  50887. }
  50888. }
  50889. int Viewport::getMaximumVisibleWidth() const throw()
  50890. {
  50891. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50892. }
  50893. int Viewport::getMaximumVisibleHeight() const throw()
  50894. {
  50895. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50896. }
  50897. void Viewport::setViewPosition (const int xPixelsOffset,
  50898. const int yPixelsOffset)
  50899. {
  50900. if (contentComp != 0)
  50901. contentComp->setTopLeftPosition (-xPixelsOffset,
  50902. -yPixelsOffset);
  50903. }
  50904. void Viewport::setViewPositionProportionately (const double x,
  50905. const double y)
  50906. {
  50907. if (contentComp != 0)
  50908. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50909. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50910. }
  50911. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50912. {
  50913. if (contentComp != 0)
  50914. {
  50915. int dx = 0, dy = 0;
  50916. if (mouseX < activeBorderThickness)
  50917. dx = activeBorderThickness - mouseX;
  50918. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  50919. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  50920. if (dx < 0)
  50921. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  50922. else
  50923. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  50924. if (mouseY < activeBorderThickness)
  50925. dy = activeBorderThickness - mouseY;
  50926. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  50927. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  50928. if (dy < 0)
  50929. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  50930. else
  50931. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  50932. if (dx != 0 || dy != 0)
  50933. {
  50934. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  50935. contentComp->getY() + dy);
  50936. return true;
  50937. }
  50938. }
  50939. return false;
  50940. }
  50941. void Viewport::componentMovedOrResized (Component&, bool, bool)
  50942. {
  50943. updateVisibleRegion();
  50944. }
  50945. void Viewport::resized()
  50946. {
  50947. updateVisibleRegion();
  50948. }
  50949. void Viewport::updateVisibleRegion()
  50950. {
  50951. if (contentComp != 0)
  50952. {
  50953. const int newVX = -contentComp->getX();
  50954. const int newVY = -contentComp->getY();
  50955. if (newVX == 0 && newVY == 0
  50956. && contentComp->getWidth() <= getWidth()
  50957. && contentComp->getHeight() <= getHeight())
  50958. {
  50959. horizontalScrollBar->setVisible (false);
  50960. verticalScrollBar->setVisible (false);
  50961. }
  50962. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  50963. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50964. horizontalScrollBar->setSingleStepSize (singleStepX);
  50965. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  50966. horizontalScrollBar->setVisible (false);
  50967. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  50968. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50969. verticalScrollBar->setSingleStepSize (singleStepY);
  50970. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  50971. verticalScrollBar->setVisible (false);
  50972. if (verticalScrollBar->isVisible())
  50973. {
  50974. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50975. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50976. verticalScrollBar
  50977. ->setBounds (getMaximumVisibleWidth(), 0,
  50978. getScrollBarThickness(), getMaximumVisibleHeight());
  50979. }
  50980. if (horizontalScrollBar->isVisible())
  50981. {
  50982. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50983. horizontalScrollBar
  50984. ->setBounds (0, getMaximumVisibleHeight(),
  50985. getMaximumVisibleWidth(), getScrollBarThickness());
  50986. }
  50987. contentHolder->setSize (getMaximumVisibleWidth(),
  50988. getMaximumVisibleHeight());
  50989. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  50990. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  50991. if (newVX != lastVX
  50992. || newVY != lastVY
  50993. || newVW != lastVW
  50994. || newVH != lastVH)
  50995. {
  50996. lastVX = newVX;
  50997. lastVY = newVY;
  50998. lastVW = newVW;
  50999. lastVH = newVH;
  51000. visibleAreaChanged (newVX, newVY, newVW, newVH);
  51001. }
  51002. horizontalScrollBar->handleUpdateNowIfNeeded();
  51003. verticalScrollBar->handleUpdateNowIfNeeded();
  51004. }
  51005. else
  51006. {
  51007. horizontalScrollBar->setVisible (false);
  51008. verticalScrollBar->setVisible (false);
  51009. }
  51010. }
  51011. void Viewport::setSingleStepSizes (const int stepX,
  51012. const int stepY)
  51013. {
  51014. singleStepX = stepX;
  51015. singleStepY = stepY;
  51016. updateVisibleRegion();
  51017. }
  51018. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51019. const bool showHorizontalScrollbarIfNeeded)
  51020. {
  51021. showVScrollbar = showVerticalScrollbarIfNeeded;
  51022. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51023. updateVisibleRegion();
  51024. }
  51025. void Viewport::setScrollBarThickness (const int thickness)
  51026. {
  51027. scrollBarThickness = thickness;
  51028. updateVisibleRegion();
  51029. }
  51030. int Viewport::getScrollBarThickness() const throw()
  51031. {
  51032. return (scrollBarThickness > 0) ? scrollBarThickness
  51033. : getLookAndFeel().getDefaultScrollbarWidth();
  51034. }
  51035. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51036. {
  51037. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51038. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51039. }
  51040. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  51041. {
  51042. if (scrollBarThatHasMoved == horizontalScrollBar)
  51043. {
  51044. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51045. }
  51046. else if (scrollBarThatHasMoved == verticalScrollBar)
  51047. {
  51048. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51049. }
  51050. }
  51051. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51052. {
  51053. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51054. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51055. }
  51056. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51057. {
  51058. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51059. {
  51060. const bool hasVertBar = verticalScrollBar->isVisible();
  51061. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51062. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51063. {
  51064. if (wheelIncrementX == 0 && ! hasVertBar)
  51065. wheelIncrementX = wheelIncrementY;
  51066. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51067. wheelIncrementX, wheelIncrementY);
  51068. return true;
  51069. }
  51070. else if (hasVertBar && wheelIncrementY != 0)
  51071. {
  51072. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51073. wheelIncrementX, wheelIncrementY);
  51074. return true;
  51075. }
  51076. }
  51077. return false;
  51078. }
  51079. bool Viewport::keyPressed (const KeyPress& key)
  51080. {
  51081. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51082. || key.isKeyCode (KeyPress::downKey)
  51083. || key.isKeyCode (KeyPress::pageUpKey)
  51084. || key.isKeyCode (KeyPress::pageDownKey)
  51085. || key.isKeyCode (KeyPress::homeKey)
  51086. || key.isKeyCode (KeyPress::endKey);
  51087. if (verticalScrollBar->isVisible() && isUpDownKey)
  51088. return verticalScrollBar->keyPressed (key);
  51089. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51090. || key.isKeyCode (KeyPress::rightKey);
  51091. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51092. return horizontalScrollBar->keyPressed (key);
  51093. return false;
  51094. }
  51095. END_JUCE_NAMESPACE
  51096. /*** End of inlined file: juce_Viewport.cpp ***/
  51097. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51098. BEGIN_JUCE_NAMESPACE
  51099. static const Colour createBaseColour (const Colour& buttonColour,
  51100. const bool hasKeyboardFocus,
  51101. const bool isMouseOverButton,
  51102. const bool isButtonDown) throw()
  51103. {
  51104. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51105. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51106. if (isButtonDown)
  51107. return baseColour.contrasting (0.2f);
  51108. else if (isMouseOverButton)
  51109. return baseColour.contrasting (0.1f);
  51110. return baseColour;
  51111. }
  51112. static String defaultSansName, defaultSerifName, defaultFixedName;
  51113. void clearUpDefaultFontNames() throw()
  51114. {
  51115. defaultSansName = String::empty;
  51116. defaultSerifName = String::empty;
  51117. defaultFixedName = String::empty;
  51118. }
  51119. LookAndFeel::LookAndFeel()
  51120. {
  51121. /* if this fails it means you're trying to create a LookAndFeel object before
  51122. the static Colours have been initialised. That ain't gonna work. It probably
  51123. means that you're using a static LookAndFeel object and that your compiler has
  51124. decided to intialise it before the Colours class.
  51125. */
  51126. jassert (Colours::white == Colour (0xffffffff));
  51127. // set up the standard set of colours..
  51128. const int textButtonColour = 0xffbbbbff;
  51129. const int textHighlightColour = 0x401111ee;
  51130. const int standardOutlineColour = 0xb2808080;
  51131. static const int standardColours[] =
  51132. {
  51133. TextButton::buttonColourId, textButtonColour,
  51134. TextButton::buttonOnColourId, 0xff4444ff,
  51135. TextButton::textColourOnId, 0xff000000,
  51136. TextButton::textColourOffId, 0xff000000,
  51137. ComboBox::buttonColourId, 0xffbbbbff,
  51138. ComboBox::outlineColourId, standardOutlineColour,
  51139. ToggleButton::textColourId, 0xff000000,
  51140. TextEditor::backgroundColourId, 0xffffffff,
  51141. TextEditor::textColourId, 0xff000000,
  51142. TextEditor::highlightColourId, textHighlightColour,
  51143. TextEditor::highlightedTextColourId, 0xff000000,
  51144. TextEditor::caretColourId, 0xff000000,
  51145. TextEditor::outlineColourId, 0x00000000,
  51146. TextEditor::focusedOutlineColourId, textButtonColour,
  51147. TextEditor::shadowColourId, 0x38000000,
  51148. Label::backgroundColourId, 0x00000000,
  51149. Label::textColourId, 0xff000000,
  51150. Label::outlineColourId, 0x00000000,
  51151. ScrollBar::backgroundColourId, 0x00000000,
  51152. ScrollBar::thumbColourId, 0xffffffff,
  51153. ScrollBar::trackColourId, 0xffffffff,
  51154. TreeView::linesColourId, 0x4c000000,
  51155. TreeView::backgroundColourId, 0x00000000,
  51156. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51157. PopupMenu::backgroundColourId, 0xffffffff,
  51158. PopupMenu::textColourId, 0xff000000,
  51159. PopupMenu::headerTextColourId, 0xff000000,
  51160. PopupMenu::highlightedTextColourId, 0xffffffff,
  51161. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51162. ComboBox::textColourId, 0xff000000,
  51163. ComboBox::backgroundColourId, 0xffffffff,
  51164. ComboBox::arrowColourId, 0x99000000,
  51165. ListBox::backgroundColourId, 0xffffffff,
  51166. ListBox::outlineColourId, standardOutlineColour,
  51167. ListBox::textColourId, 0xff000000,
  51168. Slider::backgroundColourId, 0x00000000,
  51169. Slider::thumbColourId, textButtonColour,
  51170. Slider::trackColourId, 0x7fffffff,
  51171. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51172. Slider::rotarySliderOutlineColourId, 0x66000000,
  51173. Slider::textBoxTextColourId, 0xff000000,
  51174. Slider::textBoxBackgroundColourId, 0xffffffff,
  51175. Slider::textBoxHighlightColourId, textHighlightColour,
  51176. Slider::textBoxOutlineColourId, standardOutlineColour,
  51177. ResizableWindow::backgroundColourId, 0xff777777,
  51178. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51179. AlertWindow::backgroundColourId, 0xffededed,
  51180. AlertWindow::textColourId, 0xff000000,
  51181. AlertWindow::outlineColourId, 0xff666666,
  51182. ProgressBar::backgroundColourId, 0xffeeeeee,
  51183. ProgressBar::foregroundColourId, 0xffaaaaee,
  51184. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51185. TooltipWindow::textColourId, 0xff000000,
  51186. TooltipWindow::outlineColourId, 0x4c000000,
  51187. TabbedComponent::backgroundColourId, 0x00000000,
  51188. TabbedComponent::outlineColourId, 0xff777777,
  51189. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51190. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51191. Toolbar::backgroundColourId, 0xfff6f8f9,
  51192. Toolbar::separatorColourId, 0x4c000000,
  51193. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51194. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51195. Toolbar::labelTextColourId, 0xff000000,
  51196. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51197. HyperlinkButton::textColourId, 0xcc1111ee,
  51198. GroupComponent::outlineColourId, 0x66000000,
  51199. GroupComponent::textColourId, 0xff000000,
  51200. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51201. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51202. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51203. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51204. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51205. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51206. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51207. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51208. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51209. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51210. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51211. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51212. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51213. CodeEditorComponent::caretColourId, 0xff000000,
  51214. CodeEditorComponent::highlightColourId, textHighlightColour,
  51215. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51216. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51217. ColourSelector::labelTextColourId, 0xff000000,
  51218. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51219. KeyMappingEditorComponent::textColourId, 0xff000000,
  51220. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51221. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51222. };
  51223. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51224. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51225. if (defaultSansName.isEmpty())
  51226. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51227. defaultSans = defaultSansName;
  51228. defaultSerif = defaultSerifName;
  51229. defaultFixed = defaultFixedName;
  51230. }
  51231. LookAndFeel::~LookAndFeel()
  51232. {
  51233. }
  51234. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51235. {
  51236. const int index = colourIds.indexOf (colourId);
  51237. if (index >= 0)
  51238. return colours [index];
  51239. jassertfalse
  51240. return Colours::black;
  51241. }
  51242. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51243. {
  51244. const int index = colourIds.indexOf (colourId);
  51245. if (index >= 0)
  51246. colours.set (index, colour);
  51247. colourIds.add (colourId);
  51248. colours.add (colour);
  51249. }
  51250. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51251. {
  51252. return colourIds.contains (colourId);
  51253. }
  51254. static LookAndFeel* defaultLF = 0;
  51255. static LookAndFeel* currentDefaultLF = 0;
  51256. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51257. {
  51258. // if this happens, your app hasn't initialised itself properly.. if you're
  51259. // trying to hack your own main() function, have a look at
  51260. // JUCEApplication::initialiseForGUI()
  51261. jassert (currentDefaultLF != 0);
  51262. return *currentDefaultLF;
  51263. }
  51264. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51265. {
  51266. if (newDefaultLookAndFeel == 0)
  51267. {
  51268. if (defaultLF == 0)
  51269. defaultLF = new LookAndFeel();
  51270. newDefaultLookAndFeel = defaultLF;
  51271. }
  51272. currentDefaultLF = newDefaultLookAndFeel;
  51273. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51274. {
  51275. Component* const c = Desktop::getInstance().getComponent (i);
  51276. if (c != 0)
  51277. c->sendLookAndFeelChange();
  51278. }
  51279. }
  51280. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51281. {
  51282. if (currentDefaultLF == defaultLF)
  51283. currentDefaultLF = 0;
  51284. deleteAndZero (defaultLF);
  51285. }
  51286. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51287. {
  51288. String faceName (font.getTypefaceName());
  51289. if (faceName == Font::getDefaultSansSerifFontName())
  51290. faceName = defaultSans;
  51291. else if (faceName == Font::getDefaultSerifFontName())
  51292. faceName = defaultSerif;
  51293. else if (faceName == Font::getDefaultMonospacedFontName())
  51294. faceName = defaultFixed;
  51295. Font f (font);
  51296. f.setTypefaceName (faceName);
  51297. return Typeface::createSystemTypefaceFor (f);
  51298. }
  51299. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51300. {
  51301. defaultSans = newName;
  51302. }
  51303. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51304. {
  51305. return component.getMouseCursor();
  51306. }
  51307. void LookAndFeel::drawButtonBackground (Graphics& g,
  51308. Button& button,
  51309. const Colour& backgroundColour,
  51310. bool isMouseOverButton,
  51311. bool isButtonDown)
  51312. {
  51313. const int width = button.getWidth();
  51314. const int height = button.getHeight();
  51315. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51316. const float halfThickness = outlineThickness * 0.5f;
  51317. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51318. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51319. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51320. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51321. const Colour baseColour (createBaseColour (backgroundColour,
  51322. button.hasKeyboardFocus (true),
  51323. isMouseOverButton, isButtonDown)
  51324. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51325. drawGlassLozenge (g,
  51326. indentL,
  51327. indentT,
  51328. width - indentL - indentR,
  51329. height - indentT - indentB,
  51330. baseColour, outlineThickness, -1.0f,
  51331. button.isConnectedOnLeft(),
  51332. button.isConnectedOnRight(),
  51333. button.isConnectedOnTop(),
  51334. button.isConnectedOnBottom());
  51335. }
  51336. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51337. {
  51338. return button.getFont();
  51339. }
  51340. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51341. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51342. {
  51343. Font font (getFontForTextButton (button));
  51344. g.setFont (font);
  51345. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51346. : TextButton::textColourOffId)
  51347. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51348. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51349. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51350. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51351. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51352. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51353. g.drawFittedText (button.getButtonText(),
  51354. leftIndent,
  51355. yIndent,
  51356. button.getWidth() - leftIndent - rightIndent,
  51357. button.getHeight() - yIndent * 2,
  51358. Justification::centred, 2);
  51359. }
  51360. void LookAndFeel::drawTickBox (Graphics& g,
  51361. Component& component,
  51362. float x, float y, float w, float h,
  51363. const bool ticked,
  51364. const bool isEnabled,
  51365. const bool isMouseOverButton,
  51366. const bool isButtonDown)
  51367. {
  51368. const float boxSize = w * 0.7f;
  51369. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51370. createBaseColour (component.findColour (TextButton::buttonColourId)
  51371. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51372. true,
  51373. isMouseOverButton,
  51374. isButtonDown),
  51375. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51376. if (ticked)
  51377. {
  51378. Path tick;
  51379. tick.startNewSubPath (1.5f, 3.0f);
  51380. tick.lineTo (3.0f, 6.0f);
  51381. tick.lineTo (6.0f, 0.0f);
  51382. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51383. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51384. .translated (x, y));
  51385. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51386. }
  51387. }
  51388. void LookAndFeel::drawToggleButton (Graphics& g,
  51389. ToggleButton& button,
  51390. bool isMouseOverButton,
  51391. bool isButtonDown)
  51392. {
  51393. if (button.hasKeyboardFocus (true))
  51394. {
  51395. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51396. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51397. }
  51398. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51399. const float tickWidth = fontSize * 1.1f;
  51400. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51401. tickWidth, tickWidth,
  51402. button.getToggleState(),
  51403. button.isEnabled(),
  51404. isMouseOverButton,
  51405. isButtonDown);
  51406. g.setColour (button.findColour (ToggleButton::textColourId));
  51407. g.setFont (fontSize);
  51408. if (! button.isEnabled())
  51409. g.setOpacity (0.5f);
  51410. const int textX = (int) tickWidth + 5;
  51411. g.drawFittedText (button.getButtonText(),
  51412. textX, 0,
  51413. button.getWidth() - textX - 2, button.getHeight(),
  51414. Justification::centredLeft, 10);
  51415. }
  51416. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51417. {
  51418. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51419. const int tickWidth = jmin (24, button.getHeight());
  51420. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51421. button.getHeight());
  51422. }
  51423. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51424. const String& message,
  51425. const String& button1,
  51426. const String& button2,
  51427. const String& button3,
  51428. AlertWindow::AlertIconType iconType,
  51429. int numButtons,
  51430. Component* associatedComponent)
  51431. {
  51432. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51433. if (numButtons == 1)
  51434. {
  51435. aw->addButton (button1, 0,
  51436. KeyPress (KeyPress::escapeKey, 0, 0),
  51437. KeyPress (KeyPress::returnKey, 0, 0));
  51438. }
  51439. else
  51440. {
  51441. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51442. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51443. if (button1ShortCut == button2ShortCut)
  51444. button2ShortCut = KeyPress();
  51445. if (numButtons == 2)
  51446. {
  51447. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51448. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51449. }
  51450. else if (numButtons == 3)
  51451. {
  51452. aw->addButton (button1, 1, button1ShortCut);
  51453. aw->addButton (button2, 2, button2ShortCut);
  51454. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51455. }
  51456. }
  51457. return aw;
  51458. }
  51459. void LookAndFeel::drawAlertBox (Graphics& g,
  51460. AlertWindow& alert,
  51461. const Rectangle<int>& textArea,
  51462. TextLayout& textLayout)
  51463. {
  51464. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51465. int iconSpaceUsed = 0;
  51466. Justification alignment (Justification::horizontallyCentred);
  51467. const int iconWidth = 80;
  51468. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51469. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51470. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51471. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51472. iconSize, iconSize);
  51473. if (alert.getAlertType() != AlertWindow::NoIcon)
  51474. {
  51475. Path icon;
  51476. uint32 colour;
  51477. char character;
  51478. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51479. {
  51480. colour = 0x55ff5555;
  51481. character = '!';
  51482. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51483. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51484. (float) iconRect.getX(), (float) iconRect.getBottom());
  51485. icon = icon.createPathWithRoundedCorners (5.0f);
  51486. }
  51487. else
  51488. {
  51489. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51490. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51491. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51492. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51493. }
  51494. GlyphArrangement ga;
  51495. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51496. String::charToString (character),
  51497. (float) iconRect.getX(), (float) iconRect.getY(),
  51498. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51499. Justification::centred, false);
  51500. ga.createPath (icon);
  51501. icon.setUsingNonZeroWinding (false);
  51502. g.setColour (Colour (colour));
  51503. g.fillPath (icon);
  51504. iconSpaceUsed = iconWidth;
  51505. alignment = Justification::left;
  51506. }
  51507. g.setColour (alert.findColour (AlertWindow::textColourId));
  51508. textLayout.drawWithin (g,
  51509. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51510. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51511. alignment.getFlags() | Justification::top);
  51512. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51513. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51514. }
  51515. int LookAndFeel::getAlertBoxWindowFlags()
  51516. {
  51517. return ComponentPeer::windowAppearsOnTaskbar
  51518. | ComponentPeer::windowHasDropShadow;
  51519. }
  51520. int LookAndFeel::getAlertWindowButtonHeight()
  51521. {
  51522. return 28;
  51523. }
  51524. const Font LookAndFeel::getAlertWindowFont()
  51525. {
  51526. return Font (12.0f);
  51527. }
  51528. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51529. int width, int height,
  51530. double progress, const String& textToShow)
  51531. {
  51532. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51533. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51534. g.fillAll (background);
  51535. if (progress >= 0.0f && progress < 1.0f)
  51536. {
  51537. drawGlassLozenge (g, 1.0f, 1.0f,
  51538. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51539. (float) (height - 2),
  51540. foreground,
  51541. 0.5f, 0.0f,
  51542. true, true, true, true);
  51543. }
  51544. else
  51545. {
  51546. // spinning bar..
  51547. g.setColour (foreground);
  51548. const int stripeWidth = height * 2;
  51549. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51550. Path p;
  51551. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51552. p.addQuadrilateral (x, 0.0f,
  51553. x + stripeWidth * 0.5f, 0.0f,
  51554. x, (float) height,
  51555. x - stripeWidth * 0.5f, (float) height);
  51556. Image im (Image::ARGB, width, height, true);
  51557. {
  51558. Graphics g2 (im);
  51559. drawGlassLozenge (g2, 1.0f, 1.0f,
  51560. (float) (width - 2),
  51561. (float) (height - 2),
  51562. foreground,
  51563. 0.5f, 0.0f,
  51564. true, true, true, true);
  51565. }
  51566. g.setTiledImageFill (im, 0, 0, 0.85f);
  51567. g.fillPath (p);
  51568. }
  51569. if (textToShow.isNotEmpty())
  51570. {
  51571. g.setColour (Colour::contrasting (background, foreground));
  51572. g.setFont (height * 0.6f);
  51573. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51574. }
  51575. }
  51576. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51577. {
  51578. const float radius = jmin (w, h) * 0.4f;
  51579. const float thickness = radius * 0.15f;
  51580. Path p;
  51581. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51582. radius * 0.6f, thickness,
  51583. thickness * 0.5f);
  51584. const float cx = x + w * 0.5f;
  51585. const float cy = y + h * 0.5f;
  51586. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51587. for (int i = 0; i < 12; ++i)
  51588. {
  51589. const int n = (i + 12 - animationIndex) % 12;
  51590. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51591. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51592. .translated (cx, cy));
  51593. }
  51594. }
  51595. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51596. ScrollBar& scrollbar,
  51597. int width, int height,
  51598. int buttonDirection,
  51599. bool /*isScrollbarVertical*/,
  51600. bool /*isMouseOverButton*/,
  51601. bool isButtonDown)
  51602. {
  51603. Path p;
  51604. if (buttonDirection == 0)
  51605. p.addTriangle (width * 0.5f, height * 0.2f,
  51606. width * 0.1f, height * 0.7f,
  51607. width * 0.9f, height * 0.7f);
  51608. else if (buttonDirection == 1)
  51609. p.addTriangle (width * 0.8f, height * 0.5f,
  51610. width * 0.3f, height * 0.1f,
  51611. width * 0.3f, height * 0.9f);
  51612. else if (buttonDirection == 2)
  51613. p.addTriangle (width * 0.5f, height * 0.8f,
  51614. width * 0.1f, height * 0.3f,
  51615. width * 0.9f, height * 0.3f);
  51616. else if (buttonDirection == 3)
  51617. p.addTriangle (width * 0.2f, height * 0.5f,
  51618. width * 0.7f, height * 0.1f,
  51619. width * 0.7f, height * 0.9f);
  51620. if (isButtonDown)
  51621. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51622. else
  51623. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51624. g.fillPath (p);
  51625. g.setColour (Colour (0x80000000));
  51626. g.strokePath (p, PathStrokeType (0.5f));
  51627. }
  51628. void LookAndFeel::drawScrollbar (Graphics& g,
  51629. ScrollBar& scrollbar,
  51630. int x, int y,
  51631. int width, int height,
  51632. bool isScrollbarVertical,
  51633. int thumbStartPosition,
  51634. int thumbSize,
  51635. bool /*isMouseOver*/,
  51636. bool /*isMouseDown*/)
  51637. {
  51638. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51639. Path slotPath, thumbPath;
  51640. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51641. const float slotIndentx2 = slotIndent * 2.0f;
  51642. const float thumbIndent = slotIndent + 1.0f;
  51643. const float thumbIndentx2 = thumbIndent * 2.0f;
  51644. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51645. if (isScrollbarVertical)
  51646. {
  51647. slotPath.addRoundedRectangle (x + slotIndent,
  51648. y + slotIndent,
  51649. width - slotIndentx2,
  51650. height - slotIndentx2,
  51651. (width - slotIndentx2) * 0.5f);
  51652. if (thumbSize > 0)
  51653. thumbPath.addRoundedRectangle (x + thumbIndent,
  51654. thumbStartPosition + thumbIndent,
  51655. width - thumbIndentx2,
  51656. thumbSize - thumbIndentx2,
  51657. (width - thumbIndentx2) * 0.5f);
  51658. gx1 = (float) x;
  51659. gx2 = x + width * 0.7f;
  51660. }
  51661. else
  51662. {
  51663. slotPath.addRoundedRectangle (x + slotIndent,
  51664. y + slotIndent,
  51665. width - slotIndentx2,
  51666. height - slotIndentx2,
  51667. (height - slotIndentx2) * 0.5f);
  51668. if (thumbSize > 0)
  51669. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51670. y + thumbIndent,
  51671. thumbSize - thumbIndentx2,
  51672. height - thumbIndentx2,
  51673. (height - thumbIndentx2) * 0.5f);
  51674. gy1 = (float) y;
  51675. gy2 = y + height * 0.7f;
  51676. }
  51677. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51678. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51679. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51680. g.fillPath (slotPath);
  51681. if (isScrollbarVertical)
  51682. {
  51683. gx1 = x + width * 0.6f;
  51684. gx2 = (float) x + width;
  51685. }
  51686. else
  51687. {
  51688. gy1 = y + height * 0.6f;
  51689. gy2 = (float) y + height;
  51690. }
  51691. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51692. Colour (0x19000000), gx2, gy2, false));
  51693. g.fillPath (slotPath);
  51694. g.setColour (thumbColour);
  51695. g.fillPath (thumbPath);
  51696. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51697. Colours::transparentBlack, gx2, gy2, false));
  51698. g.saveState();
  51699. if (isScrollbarVertical)
  51700. g.reduceClipRegion (x + width / 2, y, width, height);
  51701. else
  51702. g.reduceClipRegion (x, y + height / 2, width, height);
  51703. g.fillPath (thumbPath);
  51704. g.restoreState();
  51705. g.setColour (Colour (0x4c000000));
  51706. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51707. }
  51708. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51709. {
  51710. return 0;
  51711. }
  51712. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51713. {
  51714. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51715. }
  51716. int LookAndFeel::getDefaultScrollbarWidth()
  51717. {
  51718. return 18;
  51719. }
  51720. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51721. {
  51722. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51723. : scrollbar.getHeight());
  51724. }
  51725. const Path LookAndFeel::getTickShape (const float height)
  51726. {
  51727. static const unsigned char tickShapeData[] =
  51728. {
  51729. 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,
  51730. 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,
  51731. 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,
  51732. 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,
  51733. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51734. };
  51735. Path p;
  51736. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51737. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51738. return p;
  51739. }
  51740. const Path LookAndFeel::getCrossShape (const float height)
  51741. {
  51742. static const unsigned char crossShapeData[] =
  51743. {
  51744. 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,
  51745. 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,
  51746. 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,
  51747. 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,
  51748. 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,
  51749. 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,
  51750. 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
  51751. };
  51752. Path p;
  51753. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51754. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51755. return p;
  51756. }
  51757. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51758. {
  51759. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51760. x += (w - boxSize) >> 1;
  51761. y += (h - boxSize) >> 1;
  51762. w = boxSize;
  51763. h = boxSize;
  51764. g.setColour (Colour (0xe5ffffff));
  51765. g.fillRect (x, y, w, h);
  51766. g.setColour (Colour (0x80000000));
  51767. g.drawRect (x, y, w, h);
  51768. const float size = boxSize / 2 + 1.0f;
  51769. const float centre = (float) (boxSize / 2);
  51770. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51771. if (isPlus)
  51772. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51773. }
  51774. void LookAndFeel::drawBubble (Graphics& g,
  51775. float tipX, float tipY,
  51776. float boxX, float boxY,
  51777. float boxW, float boxH)
  51778. {
  51779. int side = 0;
  51780. if (tipX < boxX)
  51781. side = 1;
  51782. else if (tipX > boxX + boxW)
  51783. side = 3;
  51784. else if (tipY > boxY + boxH)
  51785. side = 2;
  51786. const float indent = 2.0f;
  51787. Path p;
  51788. p.addBubble (boxX + indent,
  51789. boxY + indent,
  51790. boxW - indent * 2.0f,
  51791. boxH - indent * 2.0f,
  51792. 5.0f,
  51793. tipX, tipY,
  51794. side,
  51795. 0.5f,
  51796. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51797. //xxx need to take comp as param for colour
  51798. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51799. g.fillPath (p);
  51800. //xxx as above
  51801. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51802. g.strokePath (p, PathStrokeType (1.33f));
  51803. }
  51804. const Font LookAndFeel::getPopupMenuFont()
  51805. {
  51806. return Font (17.0f);
  51807. }
  51808. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51809. const bool isSeparator,
  51810. int standardMenuItemHeight,
  51811. int& idealWidth,
  51812. int& idealHeight)
  51813. {
  51814. if (isSeparator)
  51815. {
  51816. idealWidth = 50;
  51817. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51818. }
  51819. else
  51820. {
  51821. Font font (getPopupMenuFont());
  51822. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51823. font.setHeight (standardMenuItemHeight / 1.3f);
  51824. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51825. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51826. }
  51827. }
  51828. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51829. {
  51830. const Colour background (findColour (PopupMenu::backgroundColourId));
  51831. g.fillAll (background);
  51832. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51833. for (int i = 0; i < height; i += 3)
  51834. g.fillRect (0, i, width, 1);
  51835. #if ! JUCE_MAC
  51836. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51837. g.drawRect (0, 0, width, height);
  51838. #endif
  51839. }
  51840. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51841. int width, int height,
  51842. bool isScrollUpArrow)
  51843. {
  51844. const Colour background (findColour (PopupMenu::backgroundColourId));
  51845. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51846. background.withAlpha (0.0f),
  51847. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51848. false));
  51849. g.fillRect (1, 1, width - 2, height - 2);
  51850. const float hw = width * 0.5f;
  51851. const float arrowW = height * 0.3f;
  51852. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51853. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51854. Path p;
  51855. p.addTriangle (hw - arrowW, y1,
  51856. hw + arrowW, y1,
  51857. hw, y2);
  51858. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51859. g.fillPath (p);
  51860. }
  51861. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51862. int width, int height,
  51863. const bool isSeparator,
  51864. const bool isActive,
  51865. const bool isHighlighted,
  51866. const bool isTicked,
  51867. const bool hasSubMenu,
  51868. const String& text,
  51869. const String& shortcutKeyText,
  51870. Image* image,
  51871. const Colour* const textColourToUse)
  51872. {
  51873. const float halfH = height * 0.5f;
  51874. if (isSeparator)
  51875. {
  51876. const float separatorIndent = 5.5f;
  51877. g.setColour (Colour (0x33000000));
  51878. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51879. g.setColour (Colour (0x66ffffff));
  51880. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51881. }
  51882. else
  51883. {
  51884. Colour textColour (findColour (PopupMenu::textColourId));
  51885. if (textColourToUse != 0)
  51886. textColour = *textColourToUse;
  51887. if (isHighlighted)
  51888. {
  51889. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51890. g.fillRect (1, 1, width - 2, height - 2);
  51891. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51892. }
  51893. else
  51894. {
  51895. g.setColour (textColour);
  51896. }
  51897. if (! isActive)
  51898. g.setOpacity (0.3f);
  51899. Font font (getPopupMenuFont());
  51900. if (font.getHeight() > height / 1.3f)
  51901. font.setHeight (height / 1.3f);
  51902. g.setFont (font);
  51903. const int leftBorder = (height * 5) / 4;
  51904. const int rightBorder = 4;
  51905. if (image != 0)
  51906. {
  51907. g.drawImageWithin (image,
  51908. 2, 1, leftBorder - 4, height - 2,
  51909. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51910. }
  51911. else if (isTicked)
  51912. {
  51913. const Path tick (getTickShape (1.0f));
  51914. const float th = font.getAscent();
  51915. const float ty = halfH - th * 0.5f;
  51916. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  51917. th, true));
  51918. }
  51919. g.drawFittedText (text,
  51920. leftBorder, 0,
  51921. width - (leftBorder + rightBorder), height,
  51922. Justification::centredLeft, 1);
  51923. if (shortcutKeyText.isNotEmpty())
  51924. {
  51925. Font f2 (font);
  51926. f2.setHeight (f2.getHeight() * 0.75f);
  51927. f2.setHorizontalScale (0.95f);
  51928. g.setFont (f2);
  51929. g.drawText (shortcutKeyText,
  51930. leftBorder,
  51931. 0,
  51932. width - (leftBorder + rightBorder + 4),
  51933. height,
  51934. Justification::centredRight,
  51935. true);
  51936. }
  51937. if (hasSubMenu)
  51938. {
  51939. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  51940. const float x = width - height * 0.6f;
  51941. Path p;
  51942. p.addTriangle (x, halfH - arrowH * 0.5f,
  51943. x, halfH + arrowH * 0.5f,
  51944. x + arrowH * 0.6f, halfH);
  51945. g.fillPath (p);
  51946. }
  51947. }
  51948. }
  51949. int LookAndFeel::getMenuWindowFlags()
  51950. {
  51951. return ComponentPeer::windowHasDropShadow;
  51952. }
  51953. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  51954. bool, MenuBarComponent& menuBar)
  51955. {
  51956. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  51957. if (menuBar.isEnabled())
  51958. {
  51959. drawShinyButtonShape (g,
  51960. -4.0f, 0.0f,
  51961. width + 8.0f, (float) height,
  51962. 0.0f,
  51963. baseColour,
  51964. 0.4f,
  51965. true, true, true, true);
  51966. }
  51967. else
  51968. {
  51969. g.fillAll (baseColour);
  51970. }
  51971. }
  51972. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  51973. {
  51974. return Font (menuBar.getHeight() * 0.7f);
  51975. }
  51976. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  51977. {
  51978. return getMenuBarFont (menuBar, itemIndex, itemText)
  51979. .getStringWidth (itemText) + menuBar.getHeight();
  51980. }
  51981. void LookAndFeel::drawMenuBarItem (Graphics& g,
  51982. int width, int height,
  51983. int itemIndex,
  51984. const String& itemText,
  51985. bool isMouseOverItem,
  51986. bool isMenuOpen,
  51987. bool /*isMouseOverBar*/,
  51988. MenuBarComponent& menuBar)
  51989. {
  51990. if (! menuBar.isEnabled())
  51991. {
  51992. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  51993. .withMultipliedAlpha (0.5f));
  51994. }
  51995. else if (isMenuOpen || isMouseOverItem)
  51996. {
  51997. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  51998. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  51999. }
  52000. else
  52001. {
  52002. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  52003. }
  52004. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52005. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52006. }
  52007. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52008. TextEditor& textEditor)
  52009. {
  52010. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52011. }
  52012. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52013. {
  52014. if (textEditor.isEnabled())
  52015. {
  52016. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52017. {
  52018. const int border = 2;
  52019. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52020. g.drawRect (0, 0, width, height, border);
  52021. g.setOpacity (1.0f);
  52022. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52023. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52024. }
  52025. else
  52026. {
  52027. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52028. g.drawRect (0, 0, width, height);
  52029. g.setOpacity (1.0f);
  52030. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52031. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52032. }
  52033. }
  52034. }
  52035. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52036. const bool isButtonDown,
  52037. int buttonX, int buttonY,
  52038. int buttonW, int buttonH,
  52039. ComboBox& box)
  52040. {
  52041. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52042. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52043. {
  52044. g.setColour (box.findColour (TextButton::buttonColourId));
  52045. g.drawRect (0, 0, width, height, 2);
  52046. }
  52047. else
  52048. {
  52049. g.setColour (box.findColour (ComboBox::outlineColourId));
  52050. g.drawRect (0, 0, width, height);
  52051. }
  52052. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52053. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52054. box.hasKeyboardFocus (true),
  52055. false, isButtonDown)
  52056. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52057. drawGlassLozenge (g,
  52058. buttonX + outlineThickness, buttonY + outlineThickness,
  52059. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52060. baseColour, outlineThickness, -1.0f,
  52061. true, true, true, true);
  52062. if (box.isEnabled())
  52063. {
  52064. const float arrowX = 0.3f;
  52065. const float arrowH = 0.2f;
  52066. Path p;
  52067. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52068. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52069. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52070. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52071. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52072. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52073. g.setColour (box.findColour (ComboBox::arrowColourId));
  52074. g.fillPath (p);
  52075. }
  52076. }
  52077. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52078. {
  52079. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52080. }
  52081. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52082. {
  52083. return new Label (String::empty, String::empty);
  52084. }
  52085. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52086. {
  52087. label.setBounds (1, 1,
  52088. box.getWidth() + 3 - box.getHeight(),
  52089. box.getHeight() - 2);
  52090. label.setFont (getComboBoxFont (box));
  52091. }
  52092. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52093. {
  52094. g.fillAll (label.findColour (Label::backgroundColourId));
  52095. if (! label.isBeingEdited())
  52096. {
  52097. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52098. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52099. g.setFont (label.getFont());
  52100. g.drawFittedText (label.getText(),
  52101. label.getHorizontalBorderSize(),
  52102. label.getVerticalBorderSize(),
  52103. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52104. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52105. label.getJustificationType(),
  52106. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52107. label.getMinimumHorizontalScale());
  52108. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52109. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52110. }
  52111. else if (label.isEnabled())
  52112. {
  52113. g.setColour (label.findColour (Label::outlineColourId));
  52114. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52115. }
  52116. }
  52117. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52118. int x, int y,
  52119. int width, int height,
  52120. float /*sliderPos*/,
  52121. float /*minSliderPos*/,
  52122. float /*maxSliderPos*/,
  52123. const Slider::SliderStyle /*style*/,
  52124. Slider& slider)
  52125. {
  52126. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52127. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52128. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52129. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52130. Path indent;
  52131. if (slider.isHorizontal())
  52132. {
  52133. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52134. const float ih = sliderRadius;
  52135. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52136. gradCol2, 0.0f, iy + ih, false));
  52137. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52138. width + sliderRadius, ih,
  52139. 5.0f);
  52140. g.fillPath (indent);
  52141. }
  52142. else
  52143. {
  52144. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52145. const float iw = sliderRadius;
  52146. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52147. gradCol2, ix + iw, 0.0f, false));
  52148. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52149. iw, height + sliderRadius,
  52150. 5.0f);
  52151. g.fillPath (indent);
  52152. }
  52153. g.setColour (Colour (0x4c000000));
  52154. g.strokePath (indent, PathStrokeType (0.5f));
  52155. }
  52156. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52157. int x, int y,
  52158. int width, int height,
  52159. float sliderPos,
  52160. float minSliderPos,
  52161. float maxSliderPos,
  52162. const Slider::SliderStyle style,
  52163. Slider& slider)
  52164. {
  52165. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52166. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52167. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52168. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52169. slider.isMouseButtonDown() && slider.isEnabled()));
  52170. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52171. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52172. {
  52173. float kx, ky;
  52174. if (style == Slider::LinearVertical)
  52175. {
  52176. kx = x + width * 0.5f;
  52177. ky = sliderPos;
  52178. }
  52179. else
  52180. {
  52181. kx = sliderPos;
  52182. ky = y + height * 0.5f;
  52183. }
  52184. drawGlassSphere (g,
  52185. kx - sliderRadius,
  52186. ky - sliderRadius,
  52187. sliderRadius * 2.0f,
  52188. knobColour, outlineThickness);
  52189. }
  52190. else
  52191. {
  52192. if (style == Slider::ThreeValueVertical)
  52193. {
  52194. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52195. sliderPos - sliderRadius,
  52196. sliderRadius * 2.0f,
  52197. knobColour, outlineThickness);
  52198. }
  52199. else if (style == Slider::ThreeValueHorizontal)
  52200. {
  52201. drawGlassSphere (g,sliderPos - sliderRadius,
  52202. y + height * 0.5f - sliderRadius,
  52203. sliderRadius * 2.0f,
  52204. knobColour, outlineThickness);
  52205. }
  52206. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52207. {
  52208. const float sr = jmin (sliderRadius, width * 0.4f);
  52209. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52210. minSliderPos - sliderRadius,
  52211. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52212. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52213. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52214. }
  52215. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52216. {
  52217. const float sr = jmin (sliderRadius, height * 0.4f);
  52218. drawGlassPointer (g, minSliderPos - sr,
  52219. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52220. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52221. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52222. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52223. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52224. }
  52225. }
  52226. }
  52227. void LookAndFeel::drawLinearSlider (Graphics& g,
  52228. int x, int y,
  52229. int width, int height,
  52230. float sliderPos,
  52231. float minSliderPos,
  52232. float maxSliderPos,
  52233. const Slider::SliderStyle style,
  52234. Slider& slider)
  52235. {
  52236. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52237. if (style == Slider::LinearBar)
  52238. {
  52239. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52240. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52241. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52242. false,
  52243. isMouseOver,
  52244. isMouseOver || slider.isMouseButtonDown()));
  52245. drawShinyButtonShape (g,
  52246. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52247. baseColour,
  52248. slider.isEnabled() ? 0.9f : 0.3f,
  52249. true, true, true, true);
  52250. }
  52251. else
  52252. {
  52253. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52254. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52255. }
  52256. }
  52257. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52258. {
  52259. return jmin (7,
  52260. slider.getHeight() / 2,
  52261. slider.getWidth() / 2) + 2;
  52262. }
  52263. void LookAndFeel::drawRotarySlider (Graphics& g,
  52264. int x, int y,
  52265. int width, int height,
  52266. float sliderPos,
  52267. const float rotaryStartAngle,
  52268. const float rotaryEndAngle,
  52269. Slider& slider)
  52270. {
  52271. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52272. const float centreX = x + width * 0.5f;
  52273. const float centreY = y + height * 0.5f;
  52274. const float rx = centreX - radius;
  52275. const float ry = centreY - radius;
  52276. const float rw = radius * 2.0f;
  52277. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52278. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52279. if (radius > 12.0f)
  52280. {
  52281. if (slider.isEnabled())
  52282. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52283. else
  52284. g.setColour (Colour (0x80808080));
  52285. const float thickness = 0.7f;
  52286. {
  52287. Path filledArc;
  52288. filledArc.addPieSegment (rx, ry, rw, rw,
  52289. rotaryStartAngle,
  52290. angle,
  52291. thickness);
  52292. g.fillPath (filledArc);
  52293. }
  52294. if (thickness > 0)
  52295. {
  52296. const float innerRadius = radius * 0.2f;
  52297. Path p;
  52298. p.addTriangle (-innerRadius, 0.0f,
  52299. 0.0f, -radius * thickness * 1.1f,
  52300. innerRadius, 0.0f);
  52301. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52302. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52303. }
  52304. if (slider.isEnabled())
  52305. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52306. else
  52307. g.setColour (Colour (0x80808080));
  52308. Path outlineArc;
  52309. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52310. outlineArc.closeSubPath();
  52311. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52312. }
  52313. else
  52314. {
  52315. if (slider.isEnabled())
  52316. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52317. else
  52318. g.setColour (Colour (0x80808080));
  52319. Path p;
  52320. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52321. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52322. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52323. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52324. }
  52325. }
  52326. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52327. {
  52328. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52329. }
  52330. class SliderLabelComp : public Label
  52331. {
  52332. public:
  52333. SliderLabelComp() : Label (String::empty, String::empty) {}
  52334. ~SliderLabelComp() {}
  52335. void mouseWheelMove (const MouseEvent&, float, float) {}
  52336. };
  52337. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52338. {
  52339. Label* const l = new SliderLabelComp();
  52340. l->setJustificationType (Justification::centred);
  52341. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52342. l->setColour (Label::backgroundColourId,
  52343. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52344. : slider.findColour (Slider::textBoxBackgroundColourId));
  52345. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52346. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52347. l->setColour (TextEditor::backgroundColourId,
  52348. slider.findColour (Slider::textBoxBackgroundColourId)
  52349. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52350. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52351. return l;
  52352. }
  52353. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52354. {
  52355. return 0;
  52356. }
  52357. static const TextLayout layoutTooltipText (const String& text) throw()
  52358. {
  52359. const float tooltipFontSize = 12.0f;
  52360. const int maxToolTipWidth = 400;
  52361. const Font f (tooltipFontSize, Font::bold);
  52362. TextLayout tl (text, f);
  52363. tl.layout (maxToolTipWidth, Justification::left, true);
  52364. return tl;
  52365. }
  52366. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52367. {
  52368. const TextLayout tl (layoutTooltipText (tipText));
  52369. width = tl.getWidth() + 14;
  52370. height = tl.getHeight() + 6;
  52371. }
  52372. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52373. {
  52374. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52375. const Colour textCol (findColour (TooltipWindow::textColourId));
  52376. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52377. g.setColour (findColour (TooltipWindow::outlineColourId));
  52378. g.drawRect (0, 0, width, height, 1);
  52379. #endif
  52380. const TextLayout tl (layoutTooltipText (text));
  52381. g.setColour (findColour (TooltipWindow::textColourId));
  52382. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52383. }
  52384. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52385. {
  52386. return new TextButton (text, TRANS("click to browse for a different file"));
  52387. }
  52388. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52389. ComboBox* filenameBox,
  52390. Button* browseButton)
  52391. {
  52392. browseButton->setSize (80, filenameComp.getHeight());
  52393. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52394. if (tb != 0)
  52395. tb->changeWidthToFitText();
  52396. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52397. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52398. }
  52399. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52400. int imageX, int imageY, int imageW, int imageH,
  52401. const Colour& overlayColour,
  52402. float imageOpacity,
  52403. ImageButton& button)
  52404. {
  52405. if (! button.isEnabled())
  52406. imageOpacity *= 0.3f;
  52407. if (! overlayColour.isOpaque())
  52408. {
  52409. g.setOpacity (imageOpacity);
  52410. g.drawImage (image, imageX, imageY, imageW, imageH,
  52411. 0, 0, image->getWidth(), image->getHeight(), false);
  52412. }
  52413. if (! overlayColour.isTransparent())
  52414. {
  52415. g.setColour (overlayColour);
  52416. g.drawImage (image, imageX, imageY, imageW, imageH,
  52417. 0, 0, image->getWidth(), image->getHeight(), true);
  52418. }
  52419. }
  52420. void LookAndFeel::drawCornerResizer (Graphics& g,
  52421. int w, int h,
  52422. bool /*isMouseOver*/,
  52423. bool /*isMouseDragging*/)
  52424. {
  52425. const float lineThickness = jmin (w, h) * 0.075f;
  52426. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52427. {
  52428. g.setColour (Colours::lightgrey);
  52429. g.drawLine (w * i,
  52430. h + 1.0f,
  52431. w + 1.0f,
  52432. h * i,
  52433. lineThickness);
  52434. g.setColour (Colours::darkgrey);
  52435. g.drawLine (w * i + lineThickness,
  52436. h + 1.0f,
  52437. w + 1.0f,
  52438. h * i + lineThickness,
  52439. lineThickness);
  52440. }
  52441. }
  52442. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52443. const BorderSize& /*borders*/)
  52444. {
  52445. }
  52446. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52447. const BorderSize& /*border*/, ResizableWindow& window)
  52448. {
  52449. g.fillAll (window.getBackgroundColour());
  52450. }
  52451. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52452. const BorderSize& border, ResizableWindow&)
  52453. {
  52454. g.setColour (Colour (0x80000000));
  52455. g.drawRect (0, 0, w, h);
  52456. g.setColour (Colour (0x19000000));
  52457. g.drawRect (border.getLeft() - 1,
  52458. border.getTop() - 1,
  52459. w + 2 - border.getLeftAndRight(),
  52460. h + 2 - border.getTopAndBottom());
  52461. }
  52462. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52463. Graphics& g, int w, int h,
  52464. int titleSpaceX, int titleSpaceW,
  52465. const Image* icon,
  52466. bool drawTitleTextOnLeft)
  52467. {
  52468. const bool isActive = window.isActiveWindow();
  52469. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52470. 0.0f, 0.0f,
  52471. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52472. 0.0f, (float) h, false));
  52473. g.fillAll();
  52474. Font font (h * 0.65f, Font::bold);
  52475. g.setFont (font);
  52476. int textW = font.getStringWidth (window.getName());
  52477. int iconW = 0;
  52478. int iconH = 0;
  52479. if (icon != 0)
  52480. {
  52481. iconH = (int) font.getHeight();
  52482. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52483. }
  52484. textW = jmin (titleSpaceW, textW + iconW);
  52485. int textX = drawTitleTextOnLeft ? titleSpaceX
  52486. : jmax (titleSpaceX, (w - textW) / 2);
  52487. if (textX + textW > titleSpaceX + titleSpaceW)
  52488. textX = titleSpaceX + titleSpaceW - textW;
  52489. if (icon != 0)
  52490. {
  52491. g.setOpacity (isActive ? 1.0f : 0.6f);
  52492. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52493. RectanglePlacement::centred, false);
  52494. textX += iconW;
  52495. textW -= iconW;
  52496. }
  52497. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52498. g.setColour (findColour (DocumentWindow::textColourId));
  52499. else
  52500. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52501. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52502. }
  52503. class GlassWindowButton : public Button
  52504. {
  52505. public:
  52506. GlassWindowButton (const String& name, const Colour& col,
  52507. const Path& normalShape_,
  52508. const Path& toggledShape_) throw()
  52509. : Button (name),
  52510. colour (col),
  52511. normalShape (normalShape_),
  52512. toggledShape (toggledShape_)
  52513. {
  52514. }
  52515. ~GlassWindowButton()
  52516. {
  52517. }
  52518. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52519. {
  52520. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52521. if (! isEnabled())
  52522. alpha *= 0.5f;
  52523. float x = 0, y = 0, diam;
  52524. if (getWidth() < getHeight())
  52525. {
  52526. diam = (float) getWidth();
  52527. y = (getHeight() - getWidth()) * 0.5f;
  52528. }
  52529. else
  52530. {
  52531. diam = (float) getHeight();
  52532. y = (getWidth() - getHeight()) * 0.5f;
  52533. }
  52534. x += diam * 0.05f;
  52535. y += diam * 0.05f;
  52536. diam *= 0.9f;
  52537. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52538. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52539. g.fillEllipse (x, y, diam, diam);
  52540. x += 2.0f;
  52541. y += 2.0f;
  52542. diam -= 4.0f;
  52543. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52544. Path& p = getToggleState() ? toggledShape : normalShape;
  52545. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52546. diam * 0.4f, diam * 0.4f, true));
  52547. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52548. g.fillPath (p, t);
  52549. }
  52550. juce_UseDebuggingNewOperator
  52551. private:
  52552. Colour colour;
  52553. Path normalShape, toggledShape;
  52554. GlassWindowButton (const GlassWindowButton&);
  52555. GlassWindowButton& operator= (const GlassWindowButton&);
  52556. };
  52557. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52558. {
  52559. Path shape;
  52560. const float crossThickness = 0.25f;
  52561. if (buttonType == DocumentWindow::closeButton)
  52562. {
  52563. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52564. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52565. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52566. }
  52567. else if (buttonType == DocumentWindow::minimiseButton)
  52568. {
  52569. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52570. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52571. }
  52572. else if (buttonType == DocumentWindow::maximiseButton)
  52573. {
  52574. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52575. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52576. Path fullscreenShape;
  52577. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52578. fullscreenShape.lineTo (0.0f, 100.0f);
  52579. fullscreenShape.lineTo (0.0f, 0.0f);
  52580. fullscreenShape.lineTo (100.0f, 0.0f);
  52581. fullscreenShape.lineTo (100.0f, 45.0f);
  52582. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52583. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52584. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52585. }
  52586. jassertfalse
  52587. return 0;
  52588. }
  52589. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52590. int titleBarX,
  52591. int titleBarY,
  52592. int titleBarW,
  52593. int titleBarH,
  52594. Button* minimiseButton,
  52595. Button* maximiseButton,
  52596. Button* closeButton,
  52597. bool positionTitleBarButtonsOnLeft)
  52598. {
  52599. const int buttonW = titleBarH - titleBarH / 8;
  52600. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52601. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52602. if (closeButton != 0)
  52603. {
  52604. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52605. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52606. }
  52607. if (positionTitleBarButtonsOnLeft)
  52608. swapVariables (minimiseButton, maximiseButton);
  52609. if (maximiseButton != 0)
  52610. {
  52611. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52612. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52613. }
  52614. if (minimiseButton != 0)
  52615. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52616. }
  52617. int LookAndFeel::getDefaultMenuBarHeight()
  52618. {
  52619. return 24;
  52620. }
  52621. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52622. {
  52623. return new DropShadower (0.4f, 1, 5, 10);
  52624. }
  52625. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52626. int w, int h,
  52627. bool /*isVerticalBar*/,
  52628. bool isMouseOver,
  52629. bool isMouseDragging)
  52630. {
  52631. float alpha = 0.5f;
  52632. if (isMouseOver || isMouseDragging)
  52633. {
  52634. g.fillAll (Colour (0x190000ff));
  52635. alpha = 1.0f;
  52636. }
  52637. const float cx = w * 0.5f;
  52638. const float cy = h * 0.5f;
  52639. const float cr = jmin (w, h) * 0.4f;
  52640. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52641. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52642. true));
  52643. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52644. }
  52645. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52646. const String& text,
  52647. const Justification& position,
  52648. GroupComponent& group)
  52649. {
  52650. const float textH = 15.0f;
  52651. const float indent = 3.0f;
  52652. const float textEdgeGap = 4.0f;
  52653. float cs = 5.0f;
  52654. Font f (textH);
  52655. Path p;
  52656. float x = indent;
  52657. float y = f.getAscent() - 3.0f;
  52658. float w = jmax (0.0f, width - x * 2.0f);
  52659. float h = jmax (0.0f, height - y - indent);
  52660. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52661. const float cs2 = 2.0f * cs;
  52662. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52663. float textX = cs + textEdgeGap;
  52664. if (position.testFlags (Justification::horizontallyCentred))
  52665. textX = cs + (w - cs2 - textW) * 0.5f;
  52666. else if (position.testFlags (Justification::right))
  52667. textX = w - cs - textW - textEdgeGap;
  52668. p.startNewSubPath (x + textX + textW, y);
  52669. p.lineTo (x + w - cs, y);
  52670. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52671. p.lineTo (x + w, y + h - cs);
  52672. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52673. p.lineTo (x + cs, y + h);
  52674. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52675. p.lineTo (x, y + cs);
  52676. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52677. p.lineTo (x + textX, y);
  52678. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52679. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52680. .withMultipliedAlpha (alpha));
  52681. g.strokePath (p, PathStrokeType (2.0f));
  52682. g.setColour (group.findColour (GroupComponent::textColourId)
  52683. .withMultipliedAlpha (alpha));
  52684. g.setFont (f);
  52685. g.drawText (text,
  52686. roundToInt (x + textX), 0,
  52687. roundToInt (textW),
  52688. roundToInt (textH),
  52689. Justification::centred, true);
  52690. }
  52691. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52692. {
  52693. return 1 + tabDepth / 3;
  52694. }
  52695. int LookAndFeel::getTabButtonSpaceAroundImage()
  52696. {
  52697. return 4;
  52698. }
  52699. void LookAndFeel::createTabButtonShape (Path& p,
  52700. int width, int height,
  52701. int /*tabIndex*/,
  52702. const String& /*text*/,
  52703. Button& /*button*/,
  52704. TabbedButtonBar::Orientation orientation,
  52705. const bool /*isMouseOver*/,
  52706. const bool /*isMouseDown*/,
  52707. const bool /*isFrontTab*/)
  52708. {
  52709. const float w = (float) width;
  52710. const float h = (float) height;
  52711. float length = w;
  52712. float depth = h;
  52713. if (orientation == TabbedButtonBar::TabsAtLeft
  52714. || orientation == TabbedButtonBar::TabsAtRight)
  52715. {
  52716. swapVariables (length, depth);
  52717. }
  52718. const float indent = (float) getTabButtonOverlap ((int) depth);
  52719. const float overhang = 4.0f;
  52720. if (orientation == TabbedButtonBar::TabsAtLeft)
  52721. {
  52722. p.startNewSubPath (w, 0.0f);
  52723. p.lineTo (0.0f, indent);
  52724. p.lineTo (0.0f, h - indent);
  52725. p.lineTo (w, h);
  52726. p.lineTo (w + overhang, h + overhang);
  52727. p.lineTo (w + overhang, -overhang);
  52728. }
  52729. else if (orientation == TabbedButtonBar::TabsAtRight)
  52730. {
  52731. p.startNewSubPath (0.0f, 0.0f);
  52732. p.lineTo (w, indent);
  52733. p.lineTo (w, h - indent);
  52734. p.lineTo (0.0f, h);
  52735. p.lineTo (-overhang, h + overhang);
  52736. p.lineTo (-overhang, -overhang);
  52737. }
  52738. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52739. {
  52740. p.startNewSubPath (0.0f, 0.0f);
  52741. p.lineTo (indent, h);
  52742. p.lineTo (w - indent, h);
  52743. p.lineTo (w, 0.0f);
  52744. p.lineTo (w + overhang, -overhang);
  52745. p.lineTo (-overhang, -overhang);
  52746. }
  52747. else
  52748. {
  52749. p.startNewSubPath (0.0f, h);
  52750. p.lineTo (indent, 0.0f);
  52751. p.lineTo (w - indent, 0.0f);
  52752. p.lineTo (w, h);
  52753. p.lineTo (w + overhang, h + overhang);
  52754. p.lineTo (-overhang, h + overhang);
  52755. }
  52756. p.closeSubPath();
  52757. p = p.createPathWithRoundedCorners (3.0f);
  52758. }
  52759. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52760. const Path& path,
  52761. const Colour& preferredColour,
  52762. int /*tabIndex*/,
  52763. const String& /*text*/,
  52764. Button& button,
  52765. TabbedButtonBar::Orientation /*orientation*/,
  52766. const bool /*isMouseOver*/,
  52767. const bool /*isMouseDown*/,
  52768. const bool isFrontTab)
  52769. {
  52770. g.setColour (isFrontTab ? preferredColour
  52771. : preferredColour.withMultipliedAlpha (0.9f));
  52772. g.fillPath (path);
  52773. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52774. : TabbedButtonBar::tabOutlineColourId, false)
  52775. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52776. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52777. }
  52778. void LookAndFeel::drawTabButtonText (Graphics& g,
  52779. int x, int y, int w, int h,
  52780. const Colour& preferredBackgroundColour,
  52781. int /*tabIndex*/,
  52782. const String& text,
  52783. Button& button,
  52784. TabbedButtonBar::Orientation orientation,
  52785. const bool isMouseOver,
  52786. const bool isMouseDown,
  52787. const bool isFrontTab)
  52788. {
  52789. int length = w;
  52790. int depth = h;
  52791. if (orientation == TabbedButtonBar::TabsAtLeft
  52792. || orientation == TabbedButtonBar::TabsAtRight)
  52793. {
  52794. swapVariables (length, depth);
  52795. }
  52796. Font font (depth * 0.6f);
  52797. font.setUnderline (button.hasKeyboardFocus (false));
  52798. GlyphArrangement textLayout;
  52799. textLayout.addFittedText (font, text.trim(),
  52800. 0.0f, 0.0f, (float) length, (float) depth,
  52801. Justification::centred,
  52802. jmax (1, depth / 12));
  52803. AffineTransform transform;
  52804. if (orientation == TabbedButtonBar::TabsAtLeft)
  52805. {
  52806. transform = transform.rotated (float_Pi * -0.5f)
  52807. .translated ((float) x, (float) (y + h));
  52808. }
  52809. else if (orientation == TabbedButtonBar::TabsAtRight)
  52810. {
  52811. transform = transform.rotated (float_Pi * 0.5f)
  52812. .translated ((float) (x + w), (float) y);
  52813. }
  52814. else
  52815. {
  52816. transform = transform.translated ((float) x, (float) y);
  52817. }
  52818. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52819. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52820. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52821. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52822. else
  52823. g.setColour (preferredBackgroundColour.contrasting());
  52824. if (! (isMouseOver || isMouseDown))
  52825. g.setOpacity (0.8f);
  52826. if (! button.isEnabled())
  52827. g.setOpacity (0.3f);
  52828. textLayout.draw (g, transform);
  52829. }
  52830. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52831. const String& text,
  52832. int tabDepth,
  52833. Button&)
  52834. {
  52835. Font f (tabDepth * 0.6f);
  52836. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52837. }
  52838. void LookAndFeel::drawTabButton (Graphics& g,
  52839. int w, int h,
  52840. const Colour& preferredColour,
  52841. int tabIndex,
  52842. const String& text,
  52843. Button& button,
  52844. TabbedButtonBar::Orientation orientation,
  52845. const bool isMouseOver,
  52846. const bool isMouseDown,
  52847. const bool isFrontTab)
  52848. {
  52849. int length = w;
  52850. int depth = h;
  52851. if (orientation == TabbedButtonBar::TabsAtLeft
  52852. || orientation == TabbedButtonBar::TabsAtRight)
  52853. {
  52854. swapVariables (length, depth);
  52855. }
  52856. Path tabShape;
  52857. createTabButtonShape (tabShape, w, h,
  52858. tabIndex, text, button, orientation,
  52859. isMouseOver, isMouseDown, isFrontTab);
  52860. fillTabButtonShape (g, tabShape, preferredColour,
  52861. tabIndex, text, button, orientation,
  52862. isMouseOver, isMouseDown, isFrontTab);
  52863. const int indent = getTabButtonOverlap (depth);
  52864. int x = 0, y = 0;
  52865. if (orientation == TabbedButtonBar::TabsAtLeft
  52866. || orientation == TabbedButtonBar::TabsAtRight)
  52867. {
  52868. y += indent;
  52869. h -= indent * 2;
  52870. }
  52871. else
  52872. {
  52873. x += indent;
  52874. w -= indent * 2;
  52875. }
  52876. drawTabButtonText (g, x, y, w, h, preferredColour,
  52877. tabIndex, text, button, orientation,
  52878. isMouseOver, isMouseDown, isFrontTab);
  52879. }
  52880. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52881. int w, int h,
  52882. TabbedButtonBar& tabBar,
  52883. TabbedButtonBar::Orientation orientation)
  52884. {
  52885. const float shadowSize = 0.2f;
  52886. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52887. Rectangle<int> shadowRect;
  52888. if (orientation == TabbedButtonBar::TabsAtLeft)
  52889. {
  52890. x1 = (float) w;
  52891. x2 = w * (1.0f - shadowSize);
  52892. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52893. }
  52894. else if (orientation == TabbedButtonBar::TabsAtRight)
  52895. {
  52896. x2 = w * shadowSize;
  52897. shadowRect.setBounds (0, 0, (int) x2, h);
  52898. }
  52899. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52900. {
  52901. y2 = h * shadowSize;
  52902. shadowRect.setBounds (0, 0, w, (int) y2);
  52903. }
  52904. else
  52905. {
  52906. y1 = (float) h;
  52907. y2 = h * (1.0f - shadowSize);
  52908. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52909. }
  52910. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52911. Colours::transparentBlack, x2, y2, false));
  52912. shadowRect.expand (2, 2);
  52913. g.fillRect (shadowRect);
  52914. g.setColour (Colour (0x80000000));
  52915. if (orientation == TabbedButtonBar::TabsAtLeft)
  52916. {
  52917. g.fillRect (w - 1, 0, 1, h);
  52918. }
  52919. else if (orientation == TabbedButtonBar::TabsAtRight)
  52920. {
  52921. g.fillRect (0, 0, 1, h);
  52922. }
  52923. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52924. {
  52925. g.fillRect (0, 0, w, 1);
  52926. }
  52927. else
  52928. {
  52929. g.fillRect (0, h - 1, w, 1);
  52930. }
  52931. }
  52932. Button* LookAndFeel::createTabBarExtrasButton()
  52933. {
  52934. const float thickness = 7.0f;
  52935. const float indent = 22.0f;
  52936. Path p;
  52937. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  52938. DrawablePath ellipse;
  52939. ellipse.setPath (p);
  52940. ellipse.setFill (Colour (0x99ffffff));
  52941. p.clear();
  52942. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  52943. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  52944. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  52945. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  52946. p.setUsingNonZeroWinding (false);
  52947. DrawablePath dp;
  52948. dp.setPath (p);
  52949. dp.setFill (Colour (0x59000000));
  52950. DrawableComposite normalImage;
  52951. normalImage.insertDrawable (ellipse);
  52952. normalImage.insertDrawable (dp);
  52953. dp.setFill (Colour (0xcc000000));
  52954. DrawableComposite overImage;
  52955. overImage.insertDrawable (ellipse);
  52956. overImage.insertDrawable (dp);
  52957. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  52958. db->setImages (&normalImage, &overImage, 0);
  52959. return db;
  52960. }
  52961. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  52962. {
  52963. g.fillAll (Colours::white);
  52964. const int w = header.getWidth();
  52965. const int h = header.getHeight();
  52966. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  52967. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  52968. false));
  52969. g.fillRect (0, h / 2, w, h);
  52970. g.setColour (Colour (0x33000000));
  52971. g.fillRect (0, h - 1, w, 1);
  52972. for (int i = header.getNumColumns (true); --i >= 0;)
  52973. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  52974. }
  52975. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  52976. int width, int height,
  52977. bool isMouseOver, bool isMouseDown,
  52978. int columnFlags)
  52979. {
  52980. if (isMouseDown)
  52981. g.fillAll (Colour (0x8899aadd));
  52982. else if (isMouseOver)
  52983. g.fillAll (Colour (0x5599aadd));
  52984. int rightOfText = width - 4;
  52985. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  52986. {
  52987. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  52988. const float bottom = height - top;
  52989. const float w = height * 0.5f;
  52990. const float x = rightOfText - (w * 1.25f);
  52991. rightOfText = (int) x;
  52992. Path sortArrow;
  52993. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  52994. g.setColour (Colour (0x99000000));
  52995. g.fillPath (sortArrow);
  52996. }
  52997. g.setColour (Colours::black);
  52998. g.setFont (height * 0.5f, Font::bold);
  52999. const int textX = 4;
  53000. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  53001. }
  53002. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  53003. {
  53004. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53005. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53006. background.darker (0.1f),
  53007. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53008. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53009. false));
  53010. g.fillAll();
  53011. }
  53012. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53013. {
  53014. return createTabBarExtrasButton();
  53015. }
  53016. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53017. bool isMouseOver, bool isMouseDown,
  53018. ToolbarItemComponent& component)
  53019. {
  53020. if (isMouseDown)
  53021. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53022. else if (isMouseOver)
  53023. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53024. }
  53025. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53026. const String& text, ToolbarItemComponent& component)
  53027. {
  53028. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53029. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53030. const float fontHeight = jmin (14.0f, height * 0.85f);
  53031. g.setFont (fontHeight);
  53032. g.drawFittedText (text,
  53033. x, y, width, height,
  53034. Justification::centred,
  53035. jmax (1, height / (int) fontHeight));
  53036. }
  53037. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53038. bool isOpen, int width, int height)
  53039. {
  53040. const int buttonSize = (height * 3) / 4;
  53041. const int buttonIndent = (height - buttonSize) / 2;
  53042. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53043. const int textX = buttonIndent * 2 + buttonSize + 2;
  53044. g.setColour (Colours::black);
  53045. g.setFont (height * 0.7f, Font::bold);
  53046. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53047. }
  53048. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53049. PropertyComponent&)
  53050. {
  53051. g.setColour (Colour (0x66ffffff));
  53052. g.fillRect (0, 0, width, height - 1);
  53053. }
  53054. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53055. PropertyComponent& component)
  53056. {
  53057. g.setColour (Colours::black);
  53058. if (! component.isEnabled())
  53059. g.setOpacity (0.6f);
  53060. g.setFont (jmin (height, 24) * 0.65f);
  53061. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  53062. g.drawFittedText (component.getName(),
  53063. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53064. Justification::centredLeft, 2);
  53065. }
  53066. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53067. {
  53068. return Rectangle<int> (component.getWidth() / 3, 1,
  53069. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53070. }
  53071. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53072. const String& instructions,
  53073. GlyphArrangement& text,
  53074. int width)
  53075. {
  53076. text.clear();
  53077. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53078. 8.0f, 22.0f, width - 16.0f,
  53079. Justification::centred);
  53080. text.addJustifiedText (Font (14.0f), instructions,
  53081. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53082. Justification::centred);
  53083. }
  53084. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53085. const String& filename, Image* icon,
  53086. const String& fileSizeDescription,
  53087. const String& fileTimeDescription,
  53088. const bool isDirectory,
  53089. const bool isItemSelected,
  53090. const int /*itemIndex*/)
  53091. {
  53092. if (isItemSelected)
  53093. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53094. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53095. g.setFont (height * 0.7f);
  53096. Image* im = icon;
  53097. Image* toRelease = 0;
  53098. if (im == 0)
  53099. {
  53100. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53101. : getDefaultDocumentFileImage());
  53102. }
  53103. const int x = 32;
  53104. if (im != 0)
  53105. {
  53106. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53107. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53108. false);
  53109. ImageCache::release (toRelease);
  53110. }
  53111. if (width > 450 && ! isDirectory)
  53112. {
  53113. const int sizeX = roundToInt (width * 0.7f);
  53114. const int dateX = roundToInt (width * 0.8f);
  53115. g.drawFittedText (filename,
  53116. x, 0, sizeX - x, height,
  53117. Justification::centredLeft, 1);
  53118. g.setFont (height * 0.5f);
  53119. g.setColour (Colours::darkgrey);
  53120. if (! isDirectory)
  53121. {
  53122. g.drawFittedText (fileSizeDescription,
  53123. sizeX, 0, dateX - sizeX - 8, height,
  53124. Justification::centredRight, 1);
  53125. g.drawFittedText (fileTimeDescription,
  53126. dateX, 0, width - 8 - dateX, height,
  53127. Justification::centredRight, 1);
  53128. }
  53129. }
  53130. else
  53131. {
  53132. g.drawFittedText (filename,
  53133. x, 0, width - x, height,
  53134. Justification::centredLeft, 1);
  53135. }
  53136. }
  53137. Button* LookAndFeel::createFileBrowserGoUpButton()
  53138. {
  53139. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53140. Path arrowPath;
  53141. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53142. DrawablePath arrowImage;
  53143. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53144. arrowImage.setPath (arrowPath);
  53145. goUpButton->setImages (&arrowImage);
  53146. return goUpButton;
  53147. }
  53148. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53149. DirectoryContentsDisplayComponent* fileListComponent,
  53150. FilePreviewComponent* previewComp,
  53151. ComboBox* currentPathBox,
  53152. TextEditor* filenameBox,
  53153. Button* goUpButton)
  53154. {
  53155. const int x = 8;
  53156. int w = browserComp.getWidth() - x - x;
  53157. if (previewComp != 0)
  53158. {
  53159. const int previewWidth = w / 3;
  53160. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53161. w -= previewWidth + 4;
  53162. }
  53163. int y = 4;
  53164. const int controlsHeight = 22;
  53165. const int bottomSectionHeight = controlsHeight + 8;
  53166. const int upButtonWidth = 50;
  53167. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53168. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53169. y += controlsHeight + 4;
  53170. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53171. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53172. y = listAsComp->getBottom() + 4;
  53173. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53174. }
  53175. Image* LookAndFeel::getDefaultFolderImage()
  53176. {
  53177. 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,
  53178. 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,
  53179. 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,
  53180. 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,
  53181. 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,
  53182. 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,
  53183. 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,
  53184. 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,
  53185. 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,
  53186. 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,
  53187. 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,
  53188. 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,
  53189. 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,
  53190. 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,
  53191. 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,
  53192. 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,
  53193. 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,
  53194. 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,
  53195. 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,
  53196. 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,
  53197. 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,
  53198. 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,
  53199. 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,
  53200. 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,
  53201. 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,
  53202. 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,
  53203. 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,
  53204. 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,
  53205. 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,
  53206. 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,
  53207. 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,
  53208. 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,
  53209. 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,
  53210. 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,
  53211. 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,
  53212. 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,
  53213. 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,
  53214. 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,
  53215. 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,
  53216. 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,
  53217. 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,
  53218. 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,
  53219. 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,
  53220. 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};
  53221. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53222. }
  53223. Image* LookAndFeel::getDefaultDocumentFileImage()
  53224. {
  53225. 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,
  53226. 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,
  53227. 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,
  53228. 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,
  53229. 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,
  53230. 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,
  53231. 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,
  53232. 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,
  53233. 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,
  53234. 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,
  53235. 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,
  53236. 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,
  53237. 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,
  53238. 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,
  53239. 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,
  53240. 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,
  53241. 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,
  53242. 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,
  53243. 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,
  53244. 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,
  53245. 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,
  53246. 174,66,96,130,0,0};
  53247. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53248. }
  53249. void LookAndFeel::playAlertSound()
  53250. {
  53251. PlatformUtilities::beep();
  53252. }
  53253. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53254. {
  53255. g.setColour (Colours::white.withAlpha (0.7f));
  53256. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53257. g.setColour (Colours::black.withAlpha (0.2f));
  53258. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53259. const int totalBlocks = 7;
  53260. const int numBlocks = roundToInt (totalBlocks * level);
  53261. const float w = (width - 6.0f) / (float) totalBlocks;
  53262. for (int i = 0; i < totalBlocks; ++i)
  53263. {
  53264. if (i >= numBlocks)
  53265. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53266. else
  53267. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53268. : Colours::red);
  53269. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53270. }
  53271. }
  53272. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53273. {
  53274. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53275. if (keyDescription.isNotEmpty())
  53276. {
  53277. if (button.isEnabled())
  53278. {
  53279. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53280. g.fillAll (textColour.withAlpha (alpha));
  53281. g.setOpacity (0.3f);
  53282. g.drawBevel (0, 0, width, height, 2);
  53283. }
  53284. g.setColour (textColour);
  53285. g.setFont (height * 0.6f);
  53286. g.drawFittedText (keyDescription,
  53287. 3, 0, width - 6, height,
  53288. Justification::centred, 1);
  53289. }
  53290. else
  53291. {
  53292. const float thickness = 7.0f;
  53293. const float indent = 22.0f;
  53294. Path p;
  53295. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53296. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53297. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53298. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53299. p.setUsingNonZeroWinding (false);
  53300. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53301. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53302. }
  53303. if (button.hasKeyboardFocus (false))
  53304. {
  53305. g.setColour (textColour.withAlpha (0.4f));
  53306. g.drawRect (0, 0, width, height);
  53307. }
  53308. }
  53309. static void createRoundedPath (Path& p,
  53310. const float x, const float y,
  53311. const float w, const float h,
  53312. const float cs,
  53313. const bool curveTopLeft, const bool curveTopRight,
  53314. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53315. {
  53316. const float cs2 = 2.0f * cs;
  53317. if (curveTopLeft)
  53318. {
  53319. p.startNewSubPath (x, y + cs);
  53320. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53321. }
  53322. else
  53323. {
  53324. p.startNewSubPath (x, y);
  53325. }
  53326. if (curveTopRight)
  53327. {
  53328. p.lineTo (x + w - cs, y);
  53329. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53330. }
  53331. else
  53332. {
  53333. p.lineTo (x + w, y);
  53334. }
  53335. if (curveBottomRight)
  53336. {
  53337. p.lineTo (x + w, y + h - cs);
  53338. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53339. }
  53340. else
  53341. {
  53342. p.lineTo (x + w, y + h);
  53343. }
  53344. if (curveBottomLeft)
  53345. {
  53346. p.lineTo (x + cs, y + h);
  53347. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53348. }
  53349. else
  53350. {
  53351. p.lineTo (x, y + h);
  53352. }
  53353. p.closeSubPath();
  53354. }
  53355. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53356. float x, float y, float w, float h,
  53357. float maxCornerSize,
  53358. const Colour& baseColour,
  53359. const float strokeWidth,
  53360. const bool flatOnLeft,
  53361. const bool flatOnRight,
  53362. const bool flatOnTop,
  53363. const bool flatOnBottom) throw()
  53364. {
  53365. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53366. return;
  53367. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53368. Path outline;
  53369. createRoundedPath (outline, x, y, w, h, cs,
  53370. ! (flatOnLeft || flatOnTop),
  53371. ! (flatOnRight || flatOnTop),
  53372. ! (flatOnLeft || flatOnBottom),
  53373. ! (flatOnRight || flatOnBottom));
  53374. ColourGradient cg (baseColour, 0.0f, y,
  53375. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53376. false);
  53377. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53378. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53379. g.setGradientFill (cg);
  53380. g.fillPath (outline);
  53381. g.setColour (Colour (0x80000000));
  53382. g.strokePath (outline, PathStrokeType (strokeWidth));
  53383. }
  53384. void LookAndFeel::drawGlassSphere (Graphics& g,
  53385. const float x, const float y,
  53386. const float diameter,
  53387. const Colour& colour,
  53388. const float outlineThickness) throw()
  53389. {
  53390. if (diameter <= outlineThickness)
  53391. return;
  53392. Path p;
  53393. p.addEllipse (x, y, diameter, diameter);
  53394. {
  53395. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53396. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53397. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53398. g.setGradientFill (cg);
  53399. g.fillPath (p);
  53400. }
  53401. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53402. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53403. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53404. ColourGradient cg (Colours::transparentBlack,
  53405. x + diameter * 0.5f, y + diameter * 0.5f,
  53406. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53407. x, y + diameter * 0.5f, true);
  53408. cg.addColour (0.7, Colours::transparentBlack);
  53409. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53410. g.setGradientFill (cg);
  53411. g.fillPath (p);
  53412. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53413. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53414. }
  53415. void LookAndFeel::drawGlassPointer (Graphics& g,
  53416. const float x, const float y,
  53417. const float diameter,
  53418. const Colour& colour, const float outlineThickness,
  53419. const int direction) throw()
  53420. {
  53421. if (diameter <= outlineThickness)
  53422. return;
  53423. Path p;
  53424. p.startNewSubPath (x + diameter * 0.5f, y);
  53425. p.lineTo (x + diameter, y + diameter * 0.6f);
  53426. p.lineTo (x + diameter, y + diameter);
  53427. p.lineTo (x, y + diameter);
  53428. p.lineTo (x, y + diameter * 0.6f);
  53429. p.closeSubPath();
  53430. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53431. {
  53432. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53433. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53434. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53435. g.setGradientFill (cg);
  53436. g.fillPath (p);
  53437. }
  53438. ColourGradient cg (Colours::transparentBlack,
  53439. x + diameter * 0.5f, y + diameter * 0.5f,
  53440. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53441. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53442. cg.addColour (0.5, Colours::transparentBlack);
  53443. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53444. g.setGradientFill (cg);
  53445. g.fillPath (p);
  53446. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53447. g.strokePath (p, PathStrokeType (outlineThickness));
  53448. }
  53449. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53450. const float x, const float y,
  53451. const float width, const float height,
  53452. const Colour& colour,
  53453. const float outlineThickness,
  53454. const float cornerSize,
  53455. const bool flatOnLeft,
  53456. const bool flatOnRight,
  53457. const bool flatOnTop,
  53458. const bool flatOnBottom) throw()
  53459. {
  53460. if (width <= outlineThickness || height <= outlineThickness)
  53461. return;
  53462. const int intX = (int) x;
  53463. const int intY = (int) y;
  53464. const int intW = (int) width;
  53465. const int intH = (int) height;
  53466. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53467. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53468. const int intEdge = (int) edgeBlurRadius;
  53469. Path outline;
  53470. createRoundedPath (outline, x, y, width, height, cs,
  53471. ! (flatOnLeft || flatOnTop),
  53472. ! (flatOnRight || flatOnTop),
  53473. ! (flatOnLeft || flatOnBottom),
  53474. ! (flatOnRight || flatOnBottom));
  53475. {
  53476. ColourGradient cg (colour.darker (0.2f), 0, y,
  53477. colour.darker (0.2f), 0, y + height, false);
  53478. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53479. cg.addColour (0.4, colour);
  53480. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53481. g.setGradientFill (cg);
  53482. g.fillPath (outline);
  53483. }
  53484. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53485. colour.darker (0.2f), x, y + height * 0.5f, true);
  53486. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53487. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53488. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53489. {
  53490. g.saveState();
  53491. g.setGradientFill (cg);
  53492. g.reduceClipRegion (intX, intY, intEdge, intH);
  53493. g.fillPath (outline);
  53494. g.restoreState();
  53495. }
  53496. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53497. {
  53498. cg.x1 = x + width - edgeBlurRadius;
  53499. cg.x2 = x + width;
  53500. g.saveState();
  53501. g.setGradientFill (cg);
  53502. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53503. g.fillPath (outline);
  53504. g.restoreState();
  53505. }
  53506. {
  53507. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53508. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53509. Path highlight;
  53510. createRoundedPath (highlight,
  53511. x + leftIndent,
  53512. y + cs * 0.1f,
  53513. width - (leftIndent + rightIndent),
  53514. height * 0.4f, cs * 0.4f,
  53515. ! (flatOnLeft || flatOnTop),
  53516. ! (flatOnRight || flatOnTop),
  53517. ! (flatOnLeft || flatOnBottom),
  53518. ! (flatOnRight || flatOnBottom));
  53519. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53520. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53521. g.fillPath (highlight);
  53522. }
  53523. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53524. g.strokePath (outline, PathStrokeType (outlineThickness));
  53525. }
  53526. END_JUCE_NAMESPACE
  53527. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53528. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53529. BEGIN_JUCE_NAMESPACE
  53530. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53531. {
  53532. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53533. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53534. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53535. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53536. setColour (Slider::thumbColourId, Colours::white);
  53537. setColour (Slider::trackColourId, Colour (0x7f000000));
  53538. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53539. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53540. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53541. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53542. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53543. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53544. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53545. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53546. }
  53547. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53548. {
  53549. }
  53550. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53551. Button& button,
  53552. const Colour& backgroundColour,
  53553. bool isMouseOverButton,
  53554. bool isButtonDown)
  53555. {
  53556. const int width = button.getWidth();
  53557. const int height = button.getHeight();
  53558. const float indent = 2.0f;
  53559. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53560. roundToInt (height * 0.4f));
  53561. Path p;
  53562. p.addRoundedRectangle (indent, indent,
  53563. width - indent * 2.0f,
  53564. height - indent * 2.0f,
  53565. (float) cornerSize);
  53566. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53567. if (isMouseOverButton)
  53568. {
  53569. if (isButtonDown)
  53570. bc = bc.brighter();
  53571. else if (bc.getBrightness() > 0.5f)
  53572. bc = bc.darker (0.1f);
  53573. else
  53574. bc = bc.brighter (0.1f);
  53575. }
  53576. g.setColour (bc);
  53577. g.fillPath (p);
  53578. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53579. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53580. }
  53581. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53582. Component& /*component*/,
  53583. float x, float y, float w, float h,
  53584. const bool ticked,
  53585. const bool isEnabled,
  53586. const bool /*isMouseOverButton*/,
  53587. const bool isButtonDown)
  53588. {
  53589. Path box;
  53590. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53591. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53592. : Colours::lightgrey.withAlpha (0.1f));
  53593. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53594. g.fillPath (box, trans);
  53595. g.setColour (Colours::black.withAlpha (0.6f));
  53596. g.strokePath (box, PathStrokeType (0.9f), trans);
  53597. if (ticked)
  53598. {
  53599. Path tick;
  53600. tick.startNewSubPath (1.5f, 3.0f);
  53601. tick.lineTo (3.0f, 6.0f);
  53602. tick.lineTo (6.0f, 0.0f);
  53603. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53604. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53605. }
  53606. }
  53607. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53608. ToggleButton& button,
  53609. bool isMouseOverButton,
  53610. bool isButtonDown)
  53611. {
  53612. if (button.hasKeyboardFocus (true))
  53613. {
  53614. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53615. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53616. }
  53617. const int tickWidth = jmin (20, button.getHeight() - 4);
  53618. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53619. (float) tickWidth, (float) tickWidth,
  53620. button.getToggleState(),
  53621. button.isEnabled(),
  53622. isMouseOverButton,
  53623. isButtonDown);
  53624. g.setColour (button.findColour (ToggleButton::textColourId));
  53625. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53626. if (! button.isEnabled())
  53627. g.setOpacity (0.5f);
  53628. const int textX = tickWidth + 5;
  53629. g.drawFittedText (button.getButtonText(),
  53630. textX, 4,
  53631. button.getWidth() - textX - 2, button.getHeight() - 8,
  53632. Justification::centredLeft, 10);
  53633. }
  53634. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53635. int width, int height,
  53636. double progress, const String& textToShow)
  53637. {
  53638. if (progress < 0 || progress >= 1.0)
  53639. {
  53640. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53641. }
  53642. else
  53643. {
  53644. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53645. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53646. g.fillAll (background);
  53647. g.setColour (foreground);
  53648. g.fillRect (1, 1,
  53649. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53650. height - 2);
  53651. if (textToShow.isNotEmpty())
  53652. {
  53653. g.setColour (Colour::contrasting (background, foreground));
  53654. g.setFont (height * 0.6f);
  53655. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53656. }
  53657. }
  53658. }
  53659. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53660. ScrollBar& bar,
  53661. int width, int height,
  53662. int buttonDirection,
  53663. bool isScrollbarVertical,
  53664. bool isMouseOverButton,
  53665. bool isButtonDown)
  53666. {
  53667. if (isScrollbarVertical)
  53668. width -= 2;
  53669. else
  53670. height -= 2;
  53671. Path p;
  53672. if (buttonDirection == 0)
  53673. p.addTriangle (width * 0.5f, height * 0.2f,
  53674. width * 0.1f, height * 0.7f,
  53675. width * 0.9f, height * 0.7f);
  53676. else if (buttonDirection == 1)
  53677. p.addTriangle (width * 0.8f, height * 0.5f,
  53678. width * 0.3f, height * 0.1f,
  53679. width * 0.3f, height * 0.9f);
  53680. else if (buttonDirection == 2)
  53681. p.addTriangle (width * 0.5f, height * 0.8f,
  53682. width * 0.1f, height * 0.3f,
  53683. width * 0.9f, height * 0.3f);
  53684. else if (buttonDirection == 3)
  53685. p.addTriangle (width * 0.2f, height * 0.5f,
  53686. width * 0.7f, height * 0.1f,
  53687. width * 0.7f, height * 0.9f);
  53688. if (isButtonDown)
  53689. g.setColour (Colours::white);
  53690. else if (isMouseOverButton)
  53691. g.setColour (Colours::white.withAlpha (0.7f));
  53692. else
  53693. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53694. g.fillPath (p);
  53695. g.setColour (Colours::black.withAlpha (0.5f));
  53696. g.strokePath (p, PathStrokeType (0.5f));
  53697. }
  53698. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53699. ScrollBar& bar,
  53700. int x, int y,
  53701. int width, int height,
  53702. bool isScrollbarVertical,
  53703. int thumbStartPosition,
  53704. int thumbSize,
  53705. bool isMouseOver,
  53706. bool isMouseDown)
  53707. {
  53708. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53709. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53710. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53711. if (thumbSize > 0.0f)
  53712. {
  53713. Rectangle<int> thumb;
  53714. if (isScrollbarVertical)
  53715. {
  53716. width -= 2;
  53717. g.fillRect (x + roundToInt (width * 0.35f), y,
  53718. roundToInt (width * 0.3f), height);
  53719. thumb.setBounds (x + 1, thumbStartPosition,
  53720. width - 2, thumbSize);
  53721. }
  53722. else
  53723. {
  53724. height -= 2;
  53725. g.fillRect (x, y + roundToInt (height * 0.35f),
  53726. width, roundToInt (height * 0.3f));
  53727. thumb.setBounds (thumbStartPosition, y + 1,
  53728. thumbSize, height - 2);
  53729. }
  53730. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53731. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53732. g.fillRect (thumb);
  53733. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53734. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53735. if (thumbSize > 16)
  53736. {
  53737. for (int i = 3; --i >= 0;)
  53738. {
  53739. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53740. g.setColour (Colours::black.withAlpha (0.15f));
  53741. if (isScrollbarVertical)
  53742. {
  53743. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53744. g.setColour (Colours::white.withAlpha (0.15f));
  53745. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53746. }
  53747. else
  53748. {
  53749. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53750. g.setColour (Colours::white.withAlpha (0.15f));
  53751. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53752. }
  53753. }
  53754. }
  53755. }
  53756. }
  53757. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53758. {
  53759. return &scrollbarShadow;
  53760. }
  53761. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53762. {
  53763. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53764. g.setColour (Colours::black.withAlpha (0.6f));
  53765. g.drawRect (0, 0, width, height);
  53766. }
  53767. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53768. bool, MenuBarComponent& menuBar)
  53769. {
  53770. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53771. }
  53772. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53773. {
  53774. if (textEditor.isEnabled())
  53775. {
  53776. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53777. g.drawRect (0, 0, width, height);
  53778. }
  53779. }
  53780. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53781. const bool isButtonDown,
  53782. int buttonX, int buttonY,
  53783. int buttonW, int buttonH,
  53784. ComboBox& box)
  53785. {
  53786. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53787. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53788. : ComboBox::backgroundColourId));
  53789. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53790. g.setColour (box.findColour (ComboBox::outlineColourId));
  53791. g.drawRect (0, 0, width, height);
  53792. const float arrowX = 0.2f;
  53793. const float arrowH = 0.3f;
  53794. if (box.isEnabled())
  53795. {
  53796. Path p;
  53797. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53798. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53799. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53800. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53801. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53802. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53803. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53804. : ComboBox::buttonColourId));
  53805. g.fillPath (p);
  53806. }
  53807. }
  53808. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53809. {
  53810. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53811. f.setHorizontalScale (0.9f);
  53812. return f;
  53813. }
  53814. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53815. {
  53816. Path p;
  53817. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53818. g.setColour (fill);
  53819. g.fillPath (p);
  53820. g.setColour (outline);
  53821. g.strokePath (p, PathStrokeType (0.3f));
  53822. }
  53823. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53824. int x, int y,
  53825. int w, int h,
  53826. float sliderPos,
  53827. float minSliderPos,
  53828. float maxSliderPos,
  53829. const Slider::SliderStyle style,
  53830. Slider& slider)
  53831. {
  53832. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53833. if (style == Slider::LinearBar)
  53834. {
  53835. g.setColour (slider.findColour (Slider::thumbColourId));
  53836. g.fillRect (x, y, (int) sliderPos - x, h);
  53837. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53838. g.drawRect (x, y, (int) sliderPos - x, h);
  53839. }
  53840. else
  53841. {
  53842. g.setColour (slider.findColour (Slider::trackColourId)
  53843. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53844. if (slider.isHorizontal())
  53845. {
  53846. g.fillRect (x, y + roundToInt (h * 0.6f),
  53847. w, roundToInt (h * 0.2f));
  53848. }
  53849. else
  53850. {
  53851. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53852. jmin (4, roundToInt (w * 0.2f)), h);
  53853. }
  53854. float alpha = 0.35f;
  53855. if (slider.isEnabled())
  53856. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53857. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53858. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53859. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53860. {
  53861. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53862. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53863. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53864. fill, outline);
  53865. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53866. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53867. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53868. fill, outline);
  53869. }
  53870. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53871. {
  53872. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53873. minSliderPos - 7.0f, y + h * 0.9f ,
  53874. minSliderPos, y + h * 0.9f,
  53875. fill, outline);
  53876. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53877. maxSliderPos, y + h * 0.9f,
  53878. maxSliderPos + 7.0f, y + h * 0.9f,
  53879. fill, outline);
  53880. }
  53881. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53882. {
  53883. drawTriangle (g, sliderPos, y + h * 0.9f,
  53884. sliderPos - 7.0f, y + h * 0.2f,
  53885. sliderPos + 7.0f, y + h * 0.2f,
  53886. fill, outline);
  53887. }
  53888. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53889. {
  53890. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53891. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53892. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53893. fill, outline);
  53894. }
  53895. }
  53896. }
  53897. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53898. {
  53899. if (isIncrement)
  53900. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53901. else
  53902. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53903. }
  53904. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53905. {
  53906. return &scrollbarShadow;
  53907. }
  53908. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53909. {
  53910. return 8;
  53911. }
  53912. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53913. int w, int h,
  53914. bool isMouseOver,
  53915. bool isMouseDragging)
  53916. {
  53917. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  53918. : Colours::darkgrey);
  53919. const float lineThickness = jmin (w, h) * 0.1f;
  53920. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53921. {
  53922. g.drawLine (w * i,
  53923. h + 1.0f,
  53924. w + 1.0f,
  53925. h * i,
  53926. lineThickness);
  53927. }
  53928. }
  53929. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  53930. {
  53931. Path shape;
  53932. if (buttonType == DocumentWindow::closeButton)
  53933. {
  53934. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  53935. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  53936. ShapeButton* const b = new ShapeButton ("close",
  53937. Colour (0x7fff3333),
  53938. Colour (0xd7ff3333),
  53939. Colour (0xf7ff3333));
  53940. b->setShape (shape, true, true, true);
  53941. return b;
  53942. }
  53943. else if (buttonType == DocumentWindow::minimiseButton)
  53944. {
  53945. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53946. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  53947. DrawablePath dp;
  53948. dp.setPath (shape);
  53949. dp.setFill (Colours::black.withAlpha (0.3f));
  53950. b->setImages (&dp);
  53951. return b;
  53952. }
  53953. else if (buttonType == DocumentWindow::maximiseButton)
  53954. {
  53955. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  53956. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53957. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  53958. DrawablePath dp;
  53959. dp.setPath (shape);
  53960. dp.setFill (Colours::black.withAlpha (0.3f));
  53961. b->setImages (&dp);
  53962. return b;
  53963. }
  53964. jassertfalse
  53965. return 0;
  53966. }
  53967. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53968. int titleBarX,
  53969. int titleBarY,
  53970. int titleBarW,
  53971. int titleBarH,
  53972. Button* minimiseButton,
  53973. Button* maximiseButton,
  53974. Button* closeButton,
  53975. bool positionTitleBarButtonsOnLeft)
  53976. {
  53977. titleBarY += titleBarH / 8;
  53978. titleBarH -= titleBarH / 4;
  53979. const int buttonW = titleBarH;
  53980. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53981. : titleBarX + titleBarW - buttonW - 4;
  53982. if (closeButton != 0)
  53983. {
  53984. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53985. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  53986. : -(buttonW + buttonW / 5);
  53987. }
  53988. if (positionTitleBarButtonsOnLeft)
  53989. swapVariables (minimiseButton, maximiseButton);
  53990. if (maximiseButton != 0)
  53991. {
  53992. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53993. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53994. }
  53995. if (minimiseButton != 0)
  53996. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53997. }
  53998. END_JUCE_NAMESPACE
  53999. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54000. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  54001. BEGIN_JUCE_NAMESPACE
  54002. class DummyMenuComponent : public Component
  54003. {
  54004. DummyMenuComponent (const DummyMenuComponent&);
  54005. DummyMenuComponent& operator= (const DummyMenuComponent&);
  54006. public:
  54007. DummyMenuComponent() {}
  54008. ~DummyMenuComponent() {}
  54009. void inputAttemptWhenModal()
  54010. {
  54011. exitModalState (0);
  54012. }
  54013. };
  54014. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54015. : model (0),
  54016. itemUnderMouse (-1),
  54017. currentPopupIndex (-1),
  54018. indexToShowAgain (-1),
  54019. lastMouseX (0),
  54020. lastMouseY (0),
  54021. inModalState (false)
  54022. {
  54023. setRepaintsOnMouseActivity (true);
  54024. setWantsKeyboardFocus (false);
  54025. setMouseClickGrabsKeyboardFocus (false);
  54026. setModel (model_);
  54027. }
  54028. MenuBarComponent::~MenuBarComponent()
  54029. {
  54030. setModel (0);
  54031. Desktop::getInstance().removeGlobalMouseListener (this);
  54032. currentPopup = 0;
  54033. }
  54034. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54035. {
  54036. if (model != newModel)
  54037. {
  54038. if (model != 0)
  54039. model->removeListener (this);
  54040. model = newModel;
  54041. if (model != 0)
  54042. model->addListener (this);
  54043. repaint();
  54044. menuBarItemsChanged (0);
  54045. }
  54046. }
  54047. void MenuBarComponent::paint (Graphics& g)
  54048. {
  54049. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54050. getLookAndFeel().drawMenuBarBackground (g,
  54051. getWidth(),
  54052. getHeight(),
  54053. isMouseOverBar,
  54054. *this);
  54055. if (model != 0)
  54056. {
  54057. for (int i = 0; i < menuNames.size(); ++i)
  54058. {
  54059. g.saveState();
  54060. g.setOrigin (xPositions [i], 0);
  54061. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54062. getLookAndFeel().drawMenuBarItem (g,
  54063. xPositions[i + 1] - xPositions[i],
  54064. getHeight(),
  54065. i,
  54066. menuNames[i],
  54067. i == itemUnderMouse,
  54068. i == currentPopupIndex,
  54069. isMouseOverBar,
  54070. *this);
  54071. g.restoreState();
  54072. }
  54073. }
  54074. }
  54075. void MenuBarComponent::resized()
  54076. {
  54077. xPositions.clear();
  54078. int x = 2;
  54079. xPositions.add (x);
  54080. for (int i = 0; i < menuNames.size(); ++i)
  54081. {
  54082. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54083. xPositions.add (x);
  54084. }
  54085. }
  54086. int MenuBarComponent::getItemAt (const int x, const int y)
  54087. {
  54088. for (int i = 0; i < xPositions.size(); ++i)
  54089. if (x >= xPositions[i] && x < xPositions[i + 1])
  54090. return reallyContains (x, y, true) ? i : -1;
  54091. return -1;
  54092. }
  54093. void MenuBarComponent::repaintMenuItem (int index)
  54094. {
  54095. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54096. {
  54097. const int x1 = xPositions [index];
  54098. const int x2 = xPositions [index + 1];
  54099. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54100. }
  54101. }
  54102. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54103. {
  54104. const int newItem = getItemAt (x, y);
  54105. if (itemUnderMouse != newItem)
  54106. {
  54107. repaintMenuItem (itemUnderMouse);
  54108. itemUnderMouse = newItem;
  54109. repaintMenuItem (itemUnderMouse);
  54110. }
  54111. }
  54112. void MenuBarComponent::hideCurrentMenu()
  54113. {
  54114. currentPopup = 0;
  54115. repaint();
  54116. }
  54117. void MenuBarComponent::showMenu (int index)
  54118. {
  54119. if (index != currentPopupIndex)
  54120. {
  54121. if (inModalState)
  54122. {
  54123. hideCurrentMenu();
  54124. indexToShowAgain = index;
  54125. return;
  54126. }
  54127. indexToShowAgain = -1;
  54128. currentPopupIndex = -1;
  54129. itemUnderMouse = index;
  54130. currentPopup = 0;
  54131. menuBarItemsChanged (0);
  54132. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  54133. Component::SafePointer<Component> deletionChecker (this);
  54134. enterModalState (false);
  54135. inModalState = true;
  54136. int result = 0;
  54137. ApplicationCommandManager* managerOfChosenCommand = 0;
  54138. Desktop::getInstance().addGlobalMouseListener (this);
  54139. for (;;)
  54140. {
  54141. const int x = getScreenX() + xPositions [itemUnderMouse];
  54142. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54143. currentPopupIndex = itemUnderMouse;
  54144. indexToShowAgain = -1;
  54145. repaint();
  54146. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54147. {
  54148. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54149. menuNames [itemUnderMouse]));
  54150. if (m.lookAndFeel == 0)
  54151. m.setLookAndFeel (&getLookAndFeel());
  54152. currentPopup = m.createMenuComponent (x, getScreenY(),
  54153. w, getHeight(),
  54154. 0, w, 0, 0,
  54155. true, this,
  54156. &managerOfChosenCommand,
  54157. this);
  54158. }
  54159. if (currentPopup == 0)
  54160. {
  54161. currentPopup = new DummyMenuComponent();
  54162. addAndMakeVisible (currentPopup);
  54163. }
  54164. currentPopup->enterModalState (false);
  54165. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54166. // be stuck behind other comps that are already modal..
  54167. result = currentPopup->runModalLoop();
  54168. if (deletionChecker == 0)
  54169. return;
  54170. const int lastPopupIndex = currentPopupIndex;
  54171. currentPopup = 0;
  54172. currentPopupIndex = -1;
  54173. if (result != 0)
  54174. {
  54175. topLevelIndexClicked = lastPopupIndex;
  54176. break;
  54177. }
  54178. else if (indexToShowAgain >= 0)
  54179. {
  54180. menuBarItemsChanged (0);
  54181. repaint();
  54182. itemUnderMouse = indexToShowAgain;
  54183. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54184. break;
  54185. }
  54186. else
  54187. {
  54188. break;
  54189. }
  54190. }
  54191. Desktop::getInstance().removeGlobalMouseListener (this);
  54192. inModalState = false;
  54193. exitModalState (0);
  54194. if (prevFocused != 0)
  54195. prevFocused->grabKeyboardFocus();
  54196. const Point<int> mousePos (getMouseXYRelative());
  54197. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54198. repaint();
  54199. if (result != 0)
  54200. {
  54201. if (managerOfChosenCommand != 0)
  54202. {
  54203. ApplicationCommandTarget::InvocationInfo info (result);
  54204. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54205. managerOfChosenCommand->invoke (info, true);
  54206. }
  54207. postCommandMessage (result);
  54208. }
  54209. }
  54210. }
  54211. void MenuBarComponent::handleCommandMessage (int commandId)
  54212. {
  54213. if (model != 0)
  54214. model->menuItemSelected (commandId, topLevelIndexClicked);
  54215. }
  54216. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54217. {
  54218. if (e.eventComponent == this)
  54219. updateItemUnderMouse (e.x, e.y);
  54220. }
  54221. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54222. {
  54223. if (e.eventComponent == this)
  54224. updateItemUnderMouse (e.x, e.y);
  54225. }
  54226. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54227. {
  54228. if (currentPopupIndex < 0)
  54229. {
  54230. const MouseEvent e2 (e.getEventRelativeTo (this));
  54231. updateItemUnderMouse (e2.x, e2.y);
  54232. currentPopupIndex = -2;
  54233. showMenu (itemUnderMouse);
  54234. }
  54235. }
  54236. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54237. {
  54238. const MouseEvent e2 (e.getEventRelativeTo (this));
  54239. const int item = getItemAt (e2.x, e2.y);
  54240. if (item >= 0)
  54241. showMenu (item);
  54242. }
  54243. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54244. {
  54245. const MouseEvent e2 (e.getEventRelativeTo (this));
  54246. updateItemUnderMouse (e2.x, e2.y);
  54247. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54248. hideCurrentMenu();
  54249. }
  54250. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54251. {
  54252. const MouseEvent e2 (e.getEventRelativeTo (this));
  54253. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54254. {
  54255. if (currentPopupIndex >= 0)
  54256. {
  54257. const int item = getItemAt (e2.x, e2.y);
  54258. if (item >= 0)
  54259. showMenu (item);
  54260. }
  54261. else
  54262. {
  54263. updateItemUnderMouse (e2.x, e2.y);
  54264. }
  54265. lastMouseX = e2.x;
  54266. lastMouseY = e2.y;
  54267. }
  54268. }
  54269. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54270. {
  54271. bool used = false;
  54272. const int numMenus = menuNames.size();
  54273. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54274. if (key.isKeyCode (KeyPress::leftKey))
  54275. {
  54276. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54277. used = true;
  54278. }
  54279. else if (key.isKeyCode (KeyPress::rightKey))
  54280. {
  54281. showMenu ((currentIndex + 1) % numMenus);
  54282. used = true;
  54283. }
  54284. return used;
  54285. }
  54286. void MenuBarComponent::inputAttemptWhenModal()
  54287. {
  54288. hideCurrentMenu();
  54289. }
  54290. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54291. {
  54292. StringArray newNames;
  54293. if (model != 0)
  54294. newNames = model->getMenuBarNames();
  54295. if (newNames != menuNames)
  54296. {
  54297. menuNames = newNames;
  54298. repaint();
  54299. resized();
  54300. }
  54301. }
  54302. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54303. const ApplicationCommandTarget::InvocationInfo& info)
  54304. {
  54305. if (model == 0
  54306. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54307. return;
  54308. for (int i = 0; i < menuNames.size(); ++i)
  54309. {
  54310. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54311. if (menu.containsCommandItem (info.commandID))
  54312. {
  54313. itemUnderMouse = i;
  54314. repaintMenuItem (i);
  54315. startTimer (200);
  54316. break;
  54317. }
  54318. }
  54319. }
  54320. void MenuBarComponent::timerCallback()
  54321. {
  54322. stopTimer();
  54323. const Point<int> mousePos (getMouseXYRelative());
  54324. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54325. }
  54326. END_JUCE_NAMESPACE
  54327. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54328. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54329. BEGIN_JUCE_NAMESPACE
  54330. MenuBarModel::MenuBarModel() throw()
  54331. : manager (0)
  54332. {
  54333. }
  54334. MenuBarModel::~MenuBarModel()
  54335. {
  54336. setApplicationCommandManagerToWatch (0);
  54337. }
  54338. void MenuBarModel::menuItemsChanged()
  54339. {
  54340. triggerAsyncUpdate();
  54341. }
  54342. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54343. {
  54344. if (manager != newManager)
  54345. {
  54346. if (manager != 0)
  54347. manager->removeListener (this);
  54348. manager = newManager;
  54349. if (manager != 0)
  54350. manager->addListener (this);
  54351. }
  54352. }
  54353. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54354. {
  54355. listeners.add (newListener);
  54356. }
  54357. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54358. {
  54359. // Trying to remove a listener that isn't on the list!
  54360. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54361. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54362. jassert (listeners.contains (listenerToRemove));
  54363. listeners.remove (listenerToRemove);
  54364. }
  54365. void MenuBarModel::handleAsyncUpdate()
  54366. {
  54367. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54368. }
  54369. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54370. {
  54371. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54372. }
  54373. void MenuBarModel::applicationCommandListChanged()
  54374. {
  54375. menuItemsChanged();
  54376. }
  54377. END_JUCE_NAMESPACE
  54378. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54379. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54380. BEGIN_JUCE_NAMESPACE
  54381. class PopupMenu::Item
  54382. {
  54383. public:
  54384. Item()
  54385. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54386. usesColour (false), customComp (0), commandManager (0)
  54387. {
  54388. }
  54389. Item (const int itemId_,
  54390. const String& text_,
  54391. const bool active_,
  54392. const bool isTicked_,
  54393. const Image* im,
  54394. const Colour& textColour_,
  54395. const bool usesColour_,
  54396. PopupMenuCustomComponent* const customComp_,
  54397. const PopupMenu* const subMenu_,
  54398. ApplicationCommandManager* const commandManager_)
  54399. : itemId (itemId_), text (text_), textColour (textColour_),
  54400. active (active_), isSeparator (false), isTicked (isTicked_),
  54401. usesColour (usesColour_), customComp (customComp_),
  54402. commandManager (commandManager_)
  54403. {
  54404. if (subMenu_ != 0)
  54405. subMenu = new PopupMenu (*subMenu_);
  54406. if (im != 0)
  54407. image = im->createCopy();
  54408. if (commandManager_ != 0 && itemId_ != 0)
  54409. {
  54410. String shortcutKey;
  54411. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54412. ->getKeyPressesAssignedToCommand (itemId_));
  54413. for (int i = 0; i < keyPresses.size(); ++i)
  54414. {
  54415. const String key (keyPresses.getReference(i).getTextDescription());
  54416. if (shortcutKey.isNotEmpty())
  54417. shortcutKey << ", ";
  54418. if (key.length() == 1)
  54419. shortcutKey << "shortcut: '" << key << '\'';
  54420. else
  54421. shortcutKey << key;
  54422. }
  54423. shortcutKey = shortcutKey.trim();
  54424. if (shortcutKey.isNotEmpty())
  54425. text << "<end>" << shortcutKey;
  54426. }
  54427. }
  54428. Item (const Item& other)
  54429. : itemId (other.itemId),
  54430. text (other.text),
  54431. textColour (other.textColour),
  54432. active (other.active),
  54433. isSeparator (other.isSeparator),
  54434. isTicked (other.isTicked),
  54435. usesColour (other.usesColour),
  54436. customComp (other.customComp),
  54437. commandManager (other.commandManager)
  54438. {
  54439. if (other.subMenu != 0)
  54440. subMenu = new PopupMenu (*(other.subMenu));
  54441. if (other.image != 0)
  54442. image = other.image->createCopy();
  54443. }
  54444. ~Item()
  54445. {
  54446. customComp = 0;
  54447. }
  54448. bool canBeTriggered() const throw()
  54449. {
  54450. return active && ! (isSeparator || (subMenu != 0));
  54451. }
  54452. bool hasActiveSubMenu() const throw()
  54453. {
  54454. return active && (subMenu != 0);
  54455. }
  54456. const int itemId;
  54457. String text;
  54458. const Colour textColour;
  54459. const bool active, isSeparator, isTicked, usesColour;
  54460. ScopedPointer <Image> image;
  54461. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54462. ScopedPointer <PopupMenu> subMenu;
  54463. ApplicationCommandManager* const commandManager;
  54464. juce_UseDebuggingNewOperator
  54465. private:
  54466. Item& operator= (const Item&);
  54467. };
  54468. class PopupMenu::ItemComponent : public Component
  54469. {
  54470. public:
  54471. ItemComponent (const PopupMenu::Item& itemInfo_)
  54472. : itemInfo (itemInfo_),
  54473. isHighlighted (false)
  54474. {
  54475. if (itemInfo.customComp != 0)
  54476. addAndMakeVisible (itemInfo.customComp);
  54477. }
  54478. ~ItemComponent()
  54479. {
  54480. if (itemInfo.customComp != 0)
  54481. removeChildComponent (itemInfo.customComp);
  54482. }
  54483. void getIdealSize (int& idealWidth,
  54484. int& idealHeight,
  54485. const int standardItemHeight)
  54486. {
  54487. if (itemInfo.customComp != 0)
  54488. {
  54489. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54490. }
  54491. else
  54492. {
  54493. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54494. itemInfo.isSeparator,
  54495. standardItemHeight,
  54496. idealWidth,
  54497. idealHeight);
  54498. }
  54499. }
  54500. void paint (Graphics& g)
  54501. {
  54502. if (itemInfo.customComp == 0)
  54503. {
  54504. String mainText (itemInfo.text);
  54505. String endText;
  54506. const int endIndex = mainText.indexOf (T("<end>"));
  54507. if (endIndex >= 0)
  54508. {
  54509. endText = mainText.substring (endIndex + 5).trim();
  54510. mainText = mainText.substring (0, endIndex);
  54511. }
  54512. getLookAndFeel()
  54513. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54514. itemInfo.isSeparator,
  54515. itemInfo.active,
  54516. isHighlighted,
  54517. itemInfo.isTicked,
  54518. itemInfo.subMenu != 0,
  54519. mainText, endText,
  54520. itemInfo.image,
  54521. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54522. }
  54523. }
  54524. void resized()
  54525. {
  54526. if (getNumChildComponents() > 0)
  54527. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54528. }
  54529. void setHighlighted (bool shouldBeHighlighted)
  54530. {
  54531. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54532. if (isHighlighted != shouldBeHighlighted)
  54533. {
  54534. isHighlighted = shouldBeHighlighted;
  54535. if (itemInfo.customComp != 0)
  54536. {
  54537. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54538. itemInfo.customComp->repaint();
  54539. }
  54540. repaint();
  54541. }
  54542. }
  54543. PopupMenu::Item itemInfo;
  54544. juce_UseDebuggingNewOperator
  54545. private:
  54546. bool isHighlighted;
  54547. ItemComponent (const ItemComponent&);
  54548. ItemComponent& operator= (const ItemComponent&);
  54549. };
  54550. namespace PopupMenuSettings
  54551. {
  54552. static const int scrollZone = 24;
  54553. static const int borderSize = 2;
  54554. static const int timerInterval = 50;
  54555. static const int dismissCommandId = 0x6287345f;
  54556. }
  54557. class PopupMenu::Window : public Component,
  54558. private Timer
  54559. {
  54560. public:
  54561. Window()
  54562. : Component (T("menu")),
  54563. owner (0),
  54564. currentChild (0),
  54565. activeSubMenu (0),
  54566. menuBarComponent (0),
  54567. managerOfChosenCommand (0),
  54568. minimumWidth (0),
  54569. maximumNumColumns (7),
  54570. standardItemHeight (0),
  54571. isOver (false),
  54572. hasBeenOver (false),
  54573. isDown (false),
  54574. needsToScroll (false),
  54575. hideOnExit (false),
  54576. disableMouseMoves (false),
  54577. hasAnyJuceCompHadFocus (false),
  54578. numColumns (0),
  54579. contentHeight (0),
  54580. childYOffset (0),
  54581. timeEnteredCurrentChildComp (0),
  54582. scrollAcceleration (1.0)
  54583. {
  54584. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54585. setWantsKeyboardFocus (true);
  54586. setMouseClickGrabsKeyboardFocus (false);
  54587. setOpaque (true);
  54588. setAlwaysOnTop (true);
  54589. Desktop::getInstance().addGlobalMouseListener (this);
  54590. getActiveWindows().add (this);
  54591. }
  54592. ~Window()
  54593. {
  54594. getActiveWindows().removeValue (this);
  54595. Desktop::getInstance().removeGlobalMouseListener (this);
  54596. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54597. activeSubMenu = 0;
  54598. deleteAllChildren();
  54599. }
  54600. static Window* create (const PopupMenu& menu,
  54601. const bool dismissOnMouseUp,
  54602. Window* const owner_,
  54603. const int minX, const int maxX,
  54604. const int minY, const int maxY,
  54605. const int minimumWidth,
  54606. const int maximumNumColumns,
  54607. const int standardItemHeight,
  54608. const bool alignToRectangle,
  54609. const int itemIdThatMustBeVisible,
  54610. Component* const menuBarComponent,
  54611. ApplicationCommandManager** managerOfChosenCommand,
  54612. Component* const componentAttachedTo)
  54613. {
  54614. if (menu.items.size() > 0)
  54615. {
  54616. int totalItems = 0;
  54617. ScopedPointer <Window> mw (new Window());
  54618. mw->setLookAndFeel (menu.lookAndFeel);
  54619. mw->setWantsKeyboardFocus (false);
  54620. mw->minimumWidth = minimumWidth;
  54621. mw->maximumNumColumns = maximumNumColumns;
  54622. mw->standardItemHeight = standardItemHeight;
  54623. mw->dismissOnMouseUp = dismissOnMouseUp;
  54624. for (int i = 0; i < menu.items.size(); ++i)
  54625. {
  54626. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54627. mw->addItem (*item);
  54628. ++totalItems;
  54629. }
  54630. if (totalItems > 0)
  54631. {
  54632. mw->owner = owner_;
  54633. mw->menuBarComponent = menuBarComponent;
  54634. mw->managerOfChosenCommand = managerOfChosenCommand;
  54635. mw->componentAttachedTo = componentAttachedTo;
  54636. mw->componentAttachedToOriginal = componentAttachedTo;
  54637. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54638. mw->setTopLeftPosition (mw->windowPos.getX(),
  54639. mw->windowPos.getY());
  54640. mw->updateYPositions();
  54641. if (itemIdThatMustBeVisible != 0)
  54642. {
  54643. const int y = minY - mw->windowPos.getY();
  54644. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54645. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54646. }
  54647. mw->resizeToBestWindowPos();
  54648. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54649. | mw->getLookAndFeel().getMenuWindowFlags());
  54650. return mw.release();
  54651. }
  54652. }
  54653. return 0;
  54654. }
  54655. void paint (Graphics& g)
  54656. {
  54657. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54658. }
  54659. void paintOverChildren (Graphics& g)
  54660. {
  54661. if (isScrolling())
  54662. {
  54663. LookAndFeel& lf = getLookAndFeel();
  54664. if (isScrollZoneActive (false))
  54665. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54666. if (isScrollZoneActive (true))
  54667. {
  54668. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54669. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54670. }
  54671. }
  54672. }
  54673. bool isScrollZoneActive (bool bottomOne) const
  54674. {
  54675. return isScrolling()
  54676. && (bottomOne
  54677. ? childYOffset < contentHeight - windowPos.getHeight()
  54678. : childYOffset > 0);
  54679. }
  54680. void addItem (const PopupMenu::Item& item)
  54681. {
  54682. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54683. addAndMakeVisible (mic);
  54684. int itemW = 80;
  54685. int itemH = 16;
  54686. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54687. mic->setSize (itemW, jlimit (2, 600, itemH));
  54688. mic->addMouseListener (this, false);
  54689. }
  54690. // hide this and all sub-comps
  54691. void hide (const PopupMenu::Item* const item)
  54692. {
  54693. if (isVisible())
  54694. {
  54695. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54696. activeSubMenu = 0;
  54697. currentChild = 0;
  54698. exitModalState (item != 0 ? item->itemId : 0);
  54699. setVisible (false);
  54700. if (item != 0
  54701. && item->commandManager != 0
  54702. && item->itemId != 0)
  54703. {
  54704. *managerOfChosenCommand = item->commandManager;
  54705. }
  54706. }
  54707. }
  54708. void dismissMenu (const PopupMenu::Item* const item)
  54709. {
  54710. if (owner != 0)
  54711. {
  54712. owner->dismissMenu (item);
  54713. }
  54714. else
  54715. {
  54716. if (item != 0)
  54717. {
  54718. // need a copy of this on the stack as the one passed in will get deleted during this call
  54719. const PopupMenu::Item mi (*item);
  54720. hide (&mi);
  54721. }
  54722. else
  54723. {
  54724. hide (0);
  54725. }
  54726. }
  54727. }
  54728. void mouseMove (const MouseEvent&)
  54729. {
  54730. timerCallback();
  54731. }
  54732. void mouseDown (const MouseEvent&)
  54733. {
  54734. timerCallback();
  54735. }
  54736. void mouseDrag (const MouseEvent&)
  54737. {
  54738. timerCallback();
  54739. }
  54740. void mouseUp (const MouseEvent&)
  54741. {
  54742. timerCallback();
  54743. }
  54744. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54745. {
  54746. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54747. lastMouse = Point<int> (-1, -1);
  54748. }
  54749. bool keyPressed (const KeyPress& key)
  54750. {
  54751. if (key.isKeyCode (KeyPress::downKey))
  54752. {
  54753. selectNextItem (1);
  54754. }
  54755. else if (key.isKeyCode (KeyPress::upKey))
  54756. {
  54757. selectNextItem (-1);
  54758. }
  54759. else if (key.isKeyCode (KeyPress::leftKey))
  54760. {
  54761. if (owner != 0)
  54762. {
  54763. Component::SafePointer<Window> parentWindow (owner);
  54764. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54765. hide (0);
  54766. if (parentWindow != 0)
  54767. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54768. disableTimerUntilMouseMoves();
  54769. }
  54770. else if (menuBarComponent != 0)
  54771. {
  54772. menuBarComponent->keyPressed (key);
  54773. }
  54774. }
  54775. else if (key.isKeyCode (KeyPress::rightKey))
  54776. {
  54777. disableTimerUntilMouseMoves();
  54778. if (showSubMenuFor (currentChild))
  54779. {
  54780. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54781. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54782. activeSubMenu->selectNextItem (1);
  54783. }
  54784. else if (menuBarComponent != 0)
  54785. {
  54786. menuBarComponent->keyPressed (key);
  54787. }
  54788. }
  54789. else if (key.isKeyCode (KeyPress::returnKey))
  54790. {
  54791. triggerCurrentlyHighlightedItem();
  54792. }
  54793. else if (key.isKeyCode (KeyPress::escapeKey))
  54794. {
  54795. dismissMenu (0);
  54796. }
  54797. else
  54798. {
  54799. return false;
  54800. }
  54801. return true;
  54802. }
  54803. void inputAttemptWhenModal()
  54804. {
  54805. timerCallback();
  54806. if (! isOverAnyMenu())
  54807. {
  54808. if (componentAttachedTo != 0)
  54809. {
  54810. // we want to dismiss the menu, but if we do it synchronously, then
  54811. // the mouse-click will be allowed to pass through. That's good, except
  54812. // when the user clicks on the button that orginally popped the menu up,
  54813. // as they'll expect the menu to go away, and in fact it'll just
  54814. // come back. So only dismiss synchronously if they're not on the original
  54815. // comp that we're attached to.
  54816. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54817. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54818. {
  54819. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54820. return;
  54821. }
  54822. }
  54823. dismissMenu (0);
  54824. }
  54825. }
  54826. void handleCommandMessage (int commandId)
  54827. {
  54828. Component::handleCommandMessage (commandId);
  54829. if (commandId == PopupMenuSettings::dismissCommandId)
  54830. dismissMenu (0);
  54831. }
  54832. void timerCallback()
  54833. {
  54834. if (! isVisible())
  54835. return;
  54836. if (componentAttachedTo != componentAttachedToOriginal)
  54837. {
  54838. dismissMenu (0);
  54839. return;
  54840. }
  54841. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54842. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54843. return;
  54844. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54845. // move rather than a real timer callback
  54846. const Point<int> globalMousePos (Desktop::getMousePosition());
  54847. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54848. const uint32 now = Time::getMillisecondCounter();
  54849. if (now > timeEnteredCurrentChildComp + 100
  54850. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54851. && currentChild->isValidComponent()
  54852. && (! disableMouseMoves)
  54853. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54854. {
  54855. showSubMenuFor (currentChild);
  54856. }
  54857. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54858. {
  54859. highlightItemUnderMouse (globalMousePos, localMousePos);
  54860. }
  54861. bool overScrollArea = false;
  54862. if (isScrolling()
  54863. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54864. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54865. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54866. {
  54867. if (now > lastScroll + 20)
  54868. {
  54869. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54870. int amount = 0;
  54871. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54872. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54873. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54874. lastScroll = now;
  54875. }
  54876. overScrollArea = true;
  54877. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54878. }
  54879. else
  54880. {
  54881. scrollAcceleration = 1.0;
  54882. }
  54883. const bool wasDown = isDown;
  54884. bool isOverAny = isOverAnyMenu();
  54885. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54886. {
  54887. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54888. isOverAny = isOverAnyMenu();
  54889. }
  54890. if (hideOnExit && hasBeenOver && ! isOverAny)
  54891. {
  54892. hide (0);
  54893. }
  54894. else
  54895. {
  54896. isDown = hasBeenOver
  54897. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54898. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54899. bool anyFocused = Process::isForegroundProcess();
  54900. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54901. {
  54902. // because no component at all may have focus, our test here will
  54903. // only be triggered when something has focus and then loses it.
  54904. anyFocused = ! hasAnyJuceCompHadFocus;
  54905. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54906. {
  54907. if (ComponentPeer::getPeer (i)->isFocused())
  54908. {
  54909. anyFocused = true;
  54910. hasAnyJuceCompHadFocus = true;
  54911. break;
  54912. }
  54913. }
  54914. }
  54915. if (! anyFocused)
  54916. {
  54917. if (now > lastFocused + 10)
  54918. {
  54919. wasHiddenBecauseOfAppChange() = true;
  54920. dismissMenu (0);
  54921. return; // may have been deleted by the previous call..
  54922. }
  54923. }
  54924. else if (wasDown && now > menuCreationTime + 250
  54925. && ! (isDown || overScrollArea))
  54926. {
  54927. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54928. if (isOver)
  54929. {
  54930. triggerCurrentlyHighlightedItem();
  54931. }
  54932. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  54933. {
  54934. dismissMenu (0);
  54935. }
  54936. return; // may have been deleted by the previous calls..
  54937. }
  54938. else
  54939. {
  54940. lastFocused = now;
  54941. }
  54942. }
  54943. }
  54944. static Array<Window*>& getActiveWindows()
  54945. {
  54946. static Array<Window*> activeMenuWindows;
  54947. return activeMenuWindows;
  54948. }
  54949. static bool& wasHiddenBecauseOfAppChange() throw()
  54950. {
  54951. static bool b = false;
  54952. return b;
  54953. }
  54954. juce_UseDebuggingNewOperator
  54955. private:
  54956. Window* owner;
  54957. PopupMenu::ItemComponent* currentChild;
  54958. ScopedPointer <Window> activeSubMenu;
  54959. Component* menuBarComponent;
  54960. ApplicationCommandManager** managerOfChosenCommand;
  54961. Component::SafePointer<Component> componentAttachedTo;
  54962. Component* componentAttachedToOriginal;
  54963. Rectangle<int> windowPos;
  54964. Point<int> lastMouse;
  54965. int minimumWidth, maximumNumColumns, standardItemHeight;
  54966. bool isOver, hasBeenOver, isDown, needsToScroll;
  54967. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  54968. int numColumns, contentHeight, childYOffset;
  54969. Array <int> columnWidths;
  54970. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  54971. double scrollAcceleration;
  54972. bool overlaps (const Rectangle<int>& r) const
  54973. {
  54974. return r.intersects (getBounds())
  54975. || (owner != 0 && owner->overlaps (r));
  54976. }
  54977. bool isOverAnyMenu() const
  54978. {
  54979. return (owner != 0) ? owner->isOverAnyMenu()
  54980. : isOverChildren();
  54981. }
  54982. bool isOverChildren() const
  54983. {
  54984. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54985. return isVisible()
  54986. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  54987. }
  54988. void updateMouseOverStatus (const Point<int>& globalMousePos)
  54989. {
  54990. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  54991. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  54992. if (activeSubMenu != 0)
  54993. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54994. }
  54995. bool treeContains (const Window* const window) const throw()
  54996. {
  54997. const Window* mw = this;
  54998. while (mw->owner != 0)
  54999. mw = mw->owner;
  55000. while (mw != 0)
  55001. {
  55002. if (mw == window)
  55003. return true;
  55004. mw = mw->activeSubMenu;
  55005. }
  55006. return false;
  55007. }
  55008. void calculateWindowPos (const int minX, const int maxX,
  55009. const int minY, const int maxY,
  55010. const bool alignToRectangle)
  55011. {
  55012. const Rectangle<int> mon (Desktop::getInstance()
  55013. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  55014. (minY + maxY) / 2),
  55015. #if JUCE_MAC
  55016. true));
  55017. #else
  55018. false)); // on windows, don't stop the menu overlapping the taskbar
  55019. #endif
  55020. int x, y, widthToUse, heightToUse;
  55021. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55022. if (alignToRectangle)
  55023. {
  55024. x = minX;
  55025. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55026. const int spaceOver = minY - mon.getY();
  55027. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55028. y = maxY;
  55029. else
  55030. y = minY - heightToUse;
  55031. }
  55032. else
  55033. {
  55034. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55035. if (owner != 0)
  55036. {
  55037. if (owner->owner != 0)
  55038. {
  55039. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55040. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55041. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55042. tendTowardsRight = true;
  55043. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55044. tendTowardsRight = false;
  55045. }
  55046. else if (maxX + widthToUse < mon.getRight() - 32)
  55047. {
  55048. tendTowardsRight = true;
  55049. }
  55050. }
  55051. const int biggestSpace = jmax (mon.getRight() - maxX,
  55052. minX - mon.getX()) - 32;
  55053. if (biggestSpace < widthToUse)
  55054. {
  55055. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55056. if (numColumns > 1)
  55057. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55058. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55059. }
  55060. if (tendTowardsRight)
  55061. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55062. else
  55063. x = jmax (mon.getX() + 4, minX - widthToUse);
  55064. y = minY;
  55065. if ((minY + maxY) / 2 > mon.getCentreY())
  55066. y = jmax (mon.getY(), maxY - heightToUse);
  55067. }
  55068. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55069. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55070. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55071. // sets this flag if it's big enough to obscure any of its parent menus
  55072. hideOnExit = (owner != 0)
  55073. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55074. }
  55075. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55076. {
  55077. numColumns = 0;
  55078. contentHeight = 0;
  55079. const int maxMenuH = getParentHeight() - 24;
  55080. int totalW;
  55081. do
  55082. {
  55083. ++numColumns;
  55084. totalW = workOutBestSize (maxMenuW);
  55085. if (totalW > maxMenuW)
  55086. {
  55087. numColumns = jmax (1, numColumns - 1);
  55088. totalW = workOutBestSize (maxMenuW); // to update col widths
  55089. break;
  55090. }
  55091. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55092. {
  55093. break;
  55094. }
  55095. } while (numColumns < maximumNumColumns);
  55096. const int actualH = jmin (contentHeight, maxMenuH);
  55097. needsToScroll = contentHeight > actualH;
  55098. width = updateYPositions();
  55099. height = actualH + PopupMenuSettings::borderSize * 2;
  55100. }
  55101. int workOutBestSize (const int maxMenuW)
  55102. {
  55103. int totalW = 0;
  55104. contentHeight = 0;
  55105. int childNum = 0;
  55106. for (int col = 0; col < numColumns; ++col)
  55107. {
  55108. int i, colW = 50, colH = 0;
  55109. const int numChildren = jmin (getNumChildComponents() - childNum,
  55110. (getNumChildComponents() + numColumns - 1) / numColumns);
  55111. for (i = numChildren; --i >= 0;)
  55112. {
  55113. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55114. colH += getChildComponent (childNum + i)->getHeight();
  55115. }
  55116. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55117. columnWidths.set (col, colW);
  55118. totalW += colW;
  55119. contentHeight = jmax (contentHeight, colH);
  55120. childNum += numChildren;
  55121. }
  55122. if (totalW < minimumWidth)
  55123. {
  55124. totalW = minimumWidth;
  55125. for (int col = 0; col < numColumns; ++col)
  55126. columnWidths.set (0, totalW / numColumns);
  55127. }
  55128. return totalW;
  55129. }
  55130. void ensureItemIsVisible (const int itemId, int wantedY)
  55131. {
  55132. jassert (itemId != 0)
  55133. for (int i = getNumChildComponents(); --i >= 0;)
  55134. {
  55135. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55136. if (m != 0
  55137. && m->itemInfo.itemId == itemId
  55138. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55139. {
  55140. const int currentY = m->getY();
  55141. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55142. {
  55143. if (wantedY < 0)
  55144. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55145. jmax (PopupMenuSettings::scrollZone,
  55146. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55147. currentY);
  55148. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55149. int deltaY = wantedY - currentY;
  55150. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55151. jmin (windowPos.getHeight(), mon.getHeight()));
  55152. const int newY = jlimit (mon.getY(),
  55153. mon.getBottom() - windowPos.getHeight(),
  55154. windowPos.getY() + deltaY);
  55155. deltaY -= newY - windowPos.getY();
  55156. childYOffset -= deltaY;
  55157. windowPos.setPosition (windowPos.getX(), newY);
  55158. updateYPositions();
  55159. }
  55160. break;
  55161. }
  55162. }
  55163. }
  55164. void resizeToBestWindowPos()
  55165. {
  55166. Rectangle<int> r (windowPos);
  55167. if (childYOffset < 0)
  55168. {
  55169. r.setBounds (r.getX(), r.getY() - childYOffset,
  55170. r.getWidth(), r.getHeight() + childYOffset);
  55171. }
  55172. else if (childYOffset > 0)
  55173. {
  55174. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55175. if (spaceAtBottom > 0)
  55176. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55177. }
  55178. setBounds (r);
  55179. updateYPositions();
  55180. }
  55181. void alterChildYPos (const int delta)
  55182. {
  55183. if (isScrolling())
  55184. {
  55185. childYOffset += delta;
  55186. if (delta < 0)
  55187. {
  55188. childYOffset = jmax (childYOffset, 0);
  55189. }
  55190. else if (delta > 0)
  55191. {
  55192. childYOffset = jmin (childYOffset,
  55193. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55194. }
  55195. updateYPositions();
  55196. }
  55197. else
  55198. {
  55199. childYOffset = 0;
  55200. }
  55201. resizeToBestWindowPos();
  55202. repaint();
  55203. }
  55204. int updateYPositions()
  55205. {
  55206. int x = 0;
  55207. int childNum = 0;
  55208. for (int col = 0; col < numColumns; ++col)
  55209. {
  55210. const int numChildren = jmin (getNumChildComponents() - childNum,
  55211. (getNumChildComponents() + numColumns - 1) / numColumns);
  55212. const int colW = columnWidths [col];
  55213. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55214. for (int i = 0; i < numChildren; ++i)
  55215. {
  55216. Component* const c = getChildComponent (childNum + i);
  55217. c->setBounds (x, y, colW, c->getHeight());
  55218. y += c->getHeight();
  55219. }
  55220. x += colW;
  55221. childNum += numChildren;
  55222. }
  55223. return x;
  55224. }
  55225. bool isScrolling() const throw()
  55226. {
  55227. return childYOffset != 0 || needsToScroll;
  55228. }
  55229. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55230. {
  55231. if (currentChild->isValidComponent())
  55232. currentChild->setHighlighted (false);
  55233. currentChild = child;
  55234. if (currentChild != 0)
  55235. {
  55236. currentChild->setHighlighted (true);
  55237. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55238. }
  55239. }
  55240. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55241. {
  55242. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55243. activeSubMenu = 0;
  55244. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55245. {
  55246. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55247. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55248. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55249. dismissOnMouseUp,
  55250. this,
  55251. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55252. 0, maximumNumColumns,
  55253. standardItemHeight,
  55254. false, 0, menuBarComponent,
  55255. managerOfChosenCommand,
  55256. componentAttachedTo);
  55257. if (activeSubMenu != 0)
  55258. {
  55259. activeSubMenu->setVisible (true);
  55260. activeSubMenu->enterModalState (false);
  55261. activeSubMenu->toFront (false);
  55262. return true;
  55263. }
  55264. }
  55265. return false;
  55266. }
  55267. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55268. {
  55269. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55270. if (isOver)
  55271. hasBeenOver = true;
  55272. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55273. {
  55274. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55275. if (disableMouseMoves && isOver)
  55276. disableMouseMoves = false;
  55277. }
  55278. if (disableMouseMoves)
  55279. return;
  55280. bool isMovingTowardsMenu = false;
  55281. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55282. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55283. {
  55284. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55285. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55286. // extends from the last mouse pos to the submenu's rectangle..
  55287. float subX = (float) activeSubMenu->getScreenX();
  55288. if (activeSubMenu->getX() > getX())
  55289. {
  55290. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55291. }
  55292. else
  55293. {
  55294. lastMouse += Point<int> (2, 0);
  55295. subX += activeSubMenu->getWidth();
  55296. }
  55297. Path areaTowardsSubMenu;
  55298. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55299. (float) lastMouse.getY(),
  55300. subX,
  55301. (float) activeSubMenu->getScreenY(),
  55302. subX,
  55303. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55304. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55305. }
  55306. lastMouse = globalMousePos;
  55307. if (! isMovingTowardsMenu)
  55308. {
  55309. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55310. if (c == this)
  55311. c = 0;
  55312. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55313. if (mic == 0 && c != 0)
  55314. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55315. if (mic != currentChild
  55316. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55317. {
  55318. if (isOver && (c != 0) && (activeSubMenu != 0))
  55319. {
  55320. activeSubMenu->hide (0);
  55321. }
  55322. if (! isOver)
  55323. mic = 0;
  55324. setCurrentlyHighlightedChild (mic);
  55325. }
  55326. }
  55327. }
  55328. void triggerCurrentlyHighlightedItem()
  55329. {
  55330. if (currentChild->isValidComponent()
  55331. && currentChild->itemInfo.canBeTriggered()
  55332. && (currentChild->itemInfo.customComp == 0
  55333. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55334. {
  55335. dismissMenu (&currentChild->itemInfo);
  55336. }
  55337. }
  55338. void selectNextItem (const int delta)
  55339. {
  55340. disableTimerUntilMouseMoves();
  55341. PopupMenu::ItemComponent* mic = 0;
  55342. bool wasLastOne = (currentChild == 0);
  55343. const int numItems = getNumChildComponents();
  55344. for (int i = 0; i < numItems + 1; ++i)
  55345. {
  55346. int index = (delta > 0) ? i : (numItems - 1 - i);
  55347. index = (index + numItems) % numItems;
  55348. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55349. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55350. && wasLastOne)
  55351. break;
  55352. if (mic == currentChild)
  55353. wasLastOne = true;
  55354. }
  55355. setCurrentlyHighlightedChild (mic);
  55356. }
  55357. void disableTimerUntilMouseMoves()
  55358. {
  55359. disableMouseMoves = true;
  55360. if (owner != 0)
  55361. owner->disableTimerUntilMouseMoves();
  55362. }
  55363. Window (const Window&);
  55364. Window& operator= (const Window&);
  55365. };
  55366. PopupMenu::PopupMenu()
  55367. : lookAndFeel (0),
  55368. separatorPending (false)
  55369. {
  55370. }
  55371. PopupMenu::PopupMenu (const PopupMenu& other)
  55372. : lookAndFeel (other.lookAndFeel),
  55373. separatorPending (false)
  55374. {
  55375. items.ensureStorageAllocated (other.items.size());
  55376. for (int i = 0; i < other.items.size(); ++i)
  55377. items.add (new Item (*other.items.getUnchecked(i)));
  55378. }
  55379. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55380. {
  55381. if (this != &other)
  55382. {
  55383. lookAndFeel = other.lookAndFeel;
  55384. clear();
  55385. items.ensureStorageAllocated (other.items.size());
  55386. for (int i = 0; i < other.items.size(); ++i)
  55387. items.add (new Item (*other.items.getUnchecked(i)));
  55388. }
  55389. return *this;
  55390. }
  55391. PopupMenu::~PopupMenu()
  55392. {
  55393. clear();
  55394. }
  55395. void PopupMenu::clear()
  55396. {
  55397. items.clear();
  55398. separatorPending = false;
  55399. }
  55400. void PopupMenu::addSeparatorIfPending()
  55401. {
  55402. if (separatorPending)
  55403. {
  55404. separatorPending = false;
  55405. if (items.size() > 0)
  55406. items.add (new Item());
  55407. }
  55408. }
  55409. void PopupMenu::addItem (const int itemResultId,
  55410. const String& itemText,
  55411. const bool isActive,
  55412. const bool isTicked,
  55413. const Image* const iconToUse)
  55414. {
  55415. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55416. // didn't pick anything, so you shouldn't use it as the id
  55417. // for an item..
  55418. addSeparatorIfPending();
  55419. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55420. iconToUse, Colours::black, false, 0, 0, 0));
  55421. }
  55422. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55423. const int commandID,
  55424. const String& displayName)
  55425. {
  55426. jassert (commandManager != 0 && commandID != 0);
  55427. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55428. if (registeredInfo != 0)
  55429. {
  55430. ApplicationCommandInfo info (*registeredInfo);
  55431. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55432. addSeparatorIfPending();
  55433. items.add (new Item (commandID,
  55434. displayName.isNotEmpty() ? displayName
  55435. : info.shortName,
  55436. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55437. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55438. 0,
  55439. Colours::black,
  55440. false,
  55441. 0, 0,
  55442. commandManager));
  55443. }
  55444. }
  55445. void PopupMenu::addColouredItem (const int itemResultId,
  55446. const String& itemText,
  55447. const Colour& itemTextColour,
  55448. const bool isActive,
  55449. const bool isTicked,
  55450. const Image* const iconToUse)
  55451. {
  55452. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55453. // didn't pick anything, so you shouldn't use it as the id
  55454. // for an item..
  55455. addSeparatorIfPending();
  55456. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55457. iconToUse, itemTextColour, true, 0, 0, 0));
  55458. }
  55459. void PopupMenu::addCustomItem (const int itemResultId,
  55460. PopupMenuCustomComponent* const customComponent)
  55461. {
  55462. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55463. // didn't pick anything, so you shouldn't use it as the id
  55464. // for an item..
  55465. addSeparatorIfPending();
  55466. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55467. Colours::black, false, customComponent, 0, 0));
  55468. }
  55469. class NormalComponentWrapper : public PopupMenuCustomComponent
  55470. {
  55471. public:
  55472. NormalComponentWrapper (Component* const comp,
  55473. const int w, const int h,
  55474. const bool triggerMenuItemAutomaticallyWhenClicked)
  55475. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55476. width (w),
  55477. height (h)
  55478. {
  55479. addAndMakeVisible (comp);
  55480. }
  55481. ~NormalComponentWrapper() {}
  55482. void getIdealSize (int& idealWidth, int& idealHeight)
  55483. {
  55484. idealWidth = width;
  55485. idealHeight = height;
  55486. }
  55487. void resized()
  55488. {
  55489. if (getChildComponent(0) != 0)
  55490. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55491. }
  55492. juce_UseDebuggingNewOperator
  55493. private:
  55494. const int width, height;
  55495. NormalComponentWrapper (const NormalComponentWrapper&);
  55496. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55497. };
  55498. void PopupMenu::addCustomItem (const int itemResultId,
  55499. Component* customComponent,
  55500. int idealWidth, int idealHeight,
  55501. const bool triggerMenuItemAutomaticallyWhenClicked)
  55502. {
  55503. addCustomItem (itemResultId,
  55504. new NormalComponentWrapper (customComponent,
  55505. idealWidth, idealHeight,
  55506. triggerMenuItemAutomaticallyWhenClicked));
  55507. }
  55508. void PopupMenu::addSubMenu (const String& subMenuName,
  55509. const PopupMenu& subMenu,
  55510. const bool isActive,
  55511. Image* const iconToUse,
  55512. const bool isTicked)
  55513. {
  55514. addSeparatorIfPending();
  55515. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55516. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55517. }
  55518. void PopupMenu::addSeparator()
  55519. {
  55520. separatorPending = true;
  55521. }
  55522. class HeaderItemComponent : public PopupMenuCustomComponent
  55523. {
  55524. public:
  55525. HeaderItemComponent (const String& name)
  55526. : PopupMenuCustomComponent (false)
  55527. {
  55528. setName (name);
  55529. }
  55530. ~HeaderItemComponent()
  55531. {
  55532. }
  55533. void paint (Graphics& g)
  55534. {
  55535. Font f (getLookAndFeel().getPopupMenuFont());
  55536. f.setBold (true);
  55537. g.setFont (f);
  55538. g.setColour (findColour (PopupMenu::headerTextColourId));
  55539. g.drawFittedText (getName(),
  55540. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55541. Justification::bottomLeft, 1);
  55542. }
  55543. void getIdealSize (int& idealWidth,
  55544. int& idealHeight)
  55545. {
  55546. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55547. idealHeight += idealHeight / 2;
  55548. idealWidth += idealWidth / 4;
  55549. }
  55550. juce_UseDebuggingNewOperator
  55551. };
  55552. void PopupMenu::addSectionHeader (const String& title)
  55553. {
  55554. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55555. }
  55556. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55557. const int itemIdThatMustBeVisible,
  55558. const int minimumWidth,
  55559. const int maximumNumColumns,
  55560. const int standardItemHeight,
  55561. const bool alignToRectangle,
  55562. Component* menuBarComponent,
  55563. ApplicationCommandManager** managerOfChosenCommand,
  55564. Component* const componentAttachedTo)
  55565. {
  55566. Window* const pw
  55567. = Window::create (*this,
  55568. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55569. 0,
  55570. x, x + w,
  55571. y, y + h,
  55572. minimumWidth,
  55573. maximumNumColumns,
  55574. standardItemHeight,
  55575. alignToRectangle,
  55576. itemIdThatMustBeVisible,
  55577. menuBarComponent,
  55578. managerOfChosenCommand,
  55579. componentAttachedTo);
  55580. if (pw != 0)
  55581. pw->setVisible (true);
  55582. return pw;
  55583. }
  55584. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55585. const int itemIdThatMustBeVisible,
  55586. const int minimumWidth,
  55587. const int maximumNumColumns,
  55588. const int standardItemHeight,
  55589. const bool alignToRectangle,
  55590. Component* const componentAttachedTo)
  55591. {
  55592. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55593. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55594. Window::wasHiddenBecauseOfAppChange() = false;
  55595. int result = 0;
  55596. ApplicationCommandManager* managerOfChosenCommand = 0;
  55597. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55598. itemIdThatMustBeVisible,
  55599. minimumWidth,
  55600. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55601. standardItemHeight,
  55602. alignToRectangle, 0,
  55603. &managerOfChosenCommand,
  55604. componentAttachedTo));
  55605. if (popupComp != 0)
  55606. {
  55607. popupComp->enterModalState (false);
  55608. popupComp->toFront (false); // need to do this after making it modal, or it could
  55609. // be stuck behind other comps that are already modal..
  55610. result = popupComp->runModalLoop();
  55611. popupComp = 0;
  55612. if (! Window::wasHiddenBecauseOfAppChange())
  55613. {
  55614. if (prevTopLevel != 0)
  55615. prevTopLevel->toFront (true);
  55616. if (prevFocused != 0)
  55617. prevFocused->grabKeyboardFocus();
  55618. }
  55619. }
  55620. if (managerOfChosenCommand != 0 && result != 0)
  55621. {
  55622. ApplicationCommandTarget::InvocationInfo info (result);
  55623. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55624. managerOfChosenCommand->invoke (info, true);
  55625. }
  55626. return result;
  55627. }
  55628. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55629. const int minimumWidth,
  55630. const int maximumNumColumns,
  55631. const int standardItemHeight)
  55632. {
  55633. const Point<int> mousePos (Desktop::getMousePosition());
  55634. return showAt (mousePos.getX(), mousePos.getY(),
  55635. itemIdThatMustBeVisible,
  55636. minimumWidth,
  55637. maximumNumColumns,
  55638. standardItemHeight);
  55639. }
  55640. int PopupMenu::showAt (const int screenX,
  55641. const int screenY,
  55642. const int itemIdThatMustBeVisible,
  55643. const int minimumWidth,
  55644. const int maximumNumColumns,
  55645. const int standardItemHeight)
  55646. {
  55647. return showMenu (screenX, screenY, 1, 1,
  55648. itemIdThatMustBeVisible,
  55649. minimumWidth, maximumNumColumns,
  55650. standardItemHeight,
  55651. false, 0);
  55652. }
  55653. int PopupMenu::showAt (Component* componentToAttachTo,
  55654. const int itemIdThatMustBeVisible,
  55655. const int minimumWidth,
  55656. const int maximumNumColumns,
  55657. const int standardItemHeight)
  55658. {
  55659. if (componentToAttachTo != 0)
  55660. {
  55661. return showMenu (componentToAttachTo->getScreenX(),
  55662. componentToAttachTo->getScreenY(),
  55663. componentToAttachTo->getWidth(),
  55664. componentToAttachTo->getHeight(),
  55665. itemIdThatMustBeVisible,
  55666. minimumWidth,
  55667. maximumNumColumns,
  55668. standardItemHeight,
  55669. true, componentToAttachTo);
  55670. }
  55671. else
  55672. {
  55673. return show (itemIdThatMustBeVisible,
  55674. minimumWidth,
  55675. maximumNumColumns,
  55676. standardItemHeight);
  55677. }
  55678. }
  55679. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55680. {
  55681. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55682. {
  55683. Window* const pmw = Window::getActiveWindows()[i];
  55684. if (pmw != 0)
  55685. pmw->dismissMenu (0);
  55686. }
  55687. }
  55688. int PopupMenu::getNumItems() const throw()
  55689. {
  55690. int num = 0;
  55691. for (int i = items.size(); --i >= 0;)
  55692. if (! (items.getUnchecked(i))->isSeparator)
  55693. ++num;
  55694. return num;
  55695. }
  55696. bool PopupMenu::containsCommandItem (const int commandID) const
  55697. {
  55698. for (int i = items.size(); --i >= 0;)
  55699. {
  55700. const Item* mi = items.getUnchecked (i);
  55701. if ((mi->itemId == commandID && mi->commandManager != 0)
  55702. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55703. {
  55704. return true;
  55705. }
  55706. }
  55707. return false;
  55708. }
  55709. bool PopupMenu::containsAnyActiveItems() const throw()
  55710. {
  55711. for (int i = items.size(); --i >= 0;)
  55712. {
  55713. const Item* const mi = items.getUnchecked (i);
  55714. if (mi->subMenu != 0)
  55715. {
  55716. if (mi->subMenu->containsAnyActiveItems())
  55717. return true;
  55718. }
  55719. else if (mi->active)
  55720. {
  55721. return true;
  55722. }
  55723. }
  55724. return false;
  55725. }
  55726. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55727. {
  55728. lookAndFeel = newLookAndFeel;
  55729. }
  55730. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55731. : isHighlighted (false),
  55732. isTriggeredAutomatically (isTriggeredAutomatically_)
  55733. {
  55734. }
  55735. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55736. {
  55737. }
  55738. void PopupMenuCustomComponent::triggerMenuItem()
  55739. {
  55740. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55741. if (mic != 0)
  55742. {
  55743. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55744. if (pmw != 0)
  55745. {
  55746. pmw->dismissMenu (&mic->itemInfo);
  55747. }
  55748. else
  55749. {
  55750. // something must have gone wrong with the component hierarchy if this happens..
  55751. jassertfalse
  55752. }
  55753. }
  55754. else
  55755. {
  55756. // why isn't this component inside a menu? Not much point triggering the item if
  55757. // there's no menu.
  55758. jassertfalse
  55759. }
  55760. }
  55761. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55762. : subMenu (0),
  55763. itemId (0),
  55764. isSeparator (false),
  55765. isTicked (false),
  55766. isEnabled (false),
  55767. isCustomComponent (false),
  55768. isSectionHeader (false),
  55769. customColour (0),
  55770. customImage (0),
  55771. menu (menu_),
  55772. index (0)
  55773. {
  55774. }
  55775. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55776. {
  55777. }
  55778. bool PopupMenu::MenuItemIterator::next()
  55779. {
  55780. if (index >= menu.items.size())
  55781. return false;
  55782. const Item* const item = menu.items.getUnchecked (index);
  55783. ++index;
  55784. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55785. subMenu = item->subMenu;
  55786. itemId = item->itemId;
  55787. isSeparator = item->isSeparator;
  55788. isTicked = item->isTicked;
  55789. isEnabled = item->active;
  55790. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55791. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55792. customColour = item->usesColour ? &(item->textColour) : 0;
  55793. customImage = item->image;
  55794. commandManager = item->commandManager;
  55795. return true;
  55796. }
  55797. END_JUCE_NAMESPACE
  55798. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55799. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55800. BEGIN_JUCE_NAMESPACE
  55801. ComponentDragger::ComponentDragger()
  55802. : constrainer (0)
  55803. {
  55804. }
  55805. ComponentDragger::~ComponentDragger()
  55806. {
  55807. }
  55808. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55809. ComponentBoundsConstrainer* const constrainer_)
  55810. {
  55811. jassert (componentToDrag->isValidComponent());
  55812. if (componentToDrag != 0)
  55813. {
  55814. constrainer = constrainer_;
  55815. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55816. }
  55817. }
  55818. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55819. {
  55820. jassert (componentToDrag->isValidComponent());
  55821. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55822. if (componentToDrag != 0)
  55823. {
  55824. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55825. const Component* const parentComp = componentToDrag->getParentComponent();
  55826. if (parentComp != 0)
  55827. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55828. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55829. if (constrainer != 0)
  55830. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55831. else
  55832. componentToDrag->setBounds (bounds);
  55833. }
  55834. }
  55835. END_JUCE_NAMESPACE
  55836. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55837. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55838. BEGIN_JUCE_NAMESPACE
  55839. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55840. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55841. class DragImageComponent : public Component,
  55842. public Timer
  55843. {
  55844. public:
  55845. DragImageComponent (Image* const im,
  55846. const String& desc,
  55847. Component* const sourceComponent,
  55848. Component* const mouseDragSource_,
  55849. DragAndDropContainer* const o,
  55850. const Point<int>& imageOffset_)
  55851. : image (im),
  55852. source (sourceComponent),
  55853. mouseDragSource (mouseDragSource_),
  55854. owner (o),
  55855. dragDesc (desc),
  55856. imageOffset (imageOffset_),
  55857. hasCheckedForExternalDrag (false),
  55858. drawImage (true)
  55859. {
  55860. setSize (im->getWidth(), im->getHeight());
  55861. if (mouseDragSource == 0)
  55862. mouseDragSource = source;
  55863. mouseDragSource->addMouseListener (this, false);
  55864. startTimer (200);
  55865. setInterceptsMouseClicks (false, false);
  55866. setAlwaysOnTop (true);
  55867. }
  55868. ~DragImageComponent()
  55869. {
  55870. if (owner->dragImageComponent == this)
  55871. owner->dragImageComponent.release();
  55872. if (mouseDragSource != 0)
  55873. {
  55874. mouseDragSource->removeMouseListener (this);
  55875. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55876. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55877. }
  55878. }
  55879. void paint (Graphics& g)
  55880. {
  55881. if (isOpaque())
  55882. g.fillAll (Colours::white);
  55883. if (drawImage)
  55884. {
  55885. g.setOpacity (1.0f);
  55886. g.drawImageAt (image, 0, 0);
  55887. }
  55888. }
  55889. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55890. {
  55891. Component* hit = getParentComponent();
  55892. if (hit == 0)
  55893. {
  55894. hit = Desktop::getInstance().findComponentAt (screenPos);
  55895. }
  55896. else
  55897. {
  55898. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55899. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55900. }
  55901. // (note: use a local copy of the dragDesc member in case the callback runs
  55902. // a modal loop and deletes this object before the method completes)
  55903. const String dragDescLocal (dragDesc);
  55904. while (hit != 0)
  55905. {
  55906. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55907. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55908. {
  55909. relativePos = hit->globalPositionToRelative (screenPos);
  55910. return ddt;
  55911. }
  55912. hit = hit->getParentComponent();
  55913. }
  55914. return 0;
  55915. }
  55916. void mouseUp (const MouseEvent& e)
  55917. {
  55918. if (e.originalComponent != this)
  55919. {
  55920. if (mouseDragSource != 0)
  55921. mouseDragSource->removeMouseListener (this);
  55922. bool dropAccepted = false;
  55923. DragAndDropTarget* ddt = 0;
  55924. Point<int> relPos;
  55925. if (isVisible())
  55926. {
  55927. setVisible (false);
  55928. ddt = findTarget (e.getScreenPosition(), relPos);
  55929. // fade this component and remove it - it'll be deleted later by the timer callback
  55930. dropAccepted = ddt != 0;
  55931. setVisible (true);
  55932. if (dropAccepted || source == 0)
  55933. {
  55934. fadeOutComponent (120);
  55935. }
  55936. else
  55937. {
  55938. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  55939. source->getHeight() / 2)));
  55940. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  55941. getHeight() / 2)));
  55942. fadeOutComponent (120,
  55943. target.getX() - ourCentre.getX(),
  55944. target.getY() - ourCentre.getY());
  55945. }
  55946. }
  55947. if (getParentComponent() != 0)
  55948. getParentComponent()->removeChildComponent (this);
  55949. if (dropAccepted && ddt != 0)
  55950. {
  55951. // (note: use a local copy of the dragDesc member in case the callback runs
  55952. // a modal loop and deletes this object before the method completes)
  55953. const String dragDescLocal (dragDesc);
  55954. currentlyOverComp = 0;
  55955. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  55956. }
  55957. // careful - this object could now be deleted..
  55958. }
  55959. }
  55960. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  55961. {
  55962. // (note: use a local copy of the dragDesc member in case the callback runs
  55963. // a modal loop and deletes this object before it returns)
  55964. const String dragDescLocal (dragDesc);
  55965. Point<int> newPos (screenPos + imageOffset);
  55966. if (getParentComponent() != 0)
  55967. newPos = getParentComponent()->globalPositionToRelative (newPos);
  55968. //if (newX != getX() || newY != getY())
  55969. {
  55970. setTopLeftPosition (newPos.getX(), newPos.getY());
  55971. Point<int> relPos;
  55972. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  55973. Component* ddtComp = dynamic_cast <Component*> (ddt);
  55974. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  55975. if (ddtComp != currentlyOverComp)
  55976. {
  55977. if (currentlyOverComp != 0 && source != 0
  55978. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55979. {
  55980. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  55981. }
  55982. currentlyOverComp = ddtComp;
  55983. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55984. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  55985. }
  55986. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55987. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  55988. if (getCurrentlyOver() == 0
  55989. && canDoExternalDrag
  55990. && ! hasCheckedForExternalDrag)
  55991. {
  55992. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  55993. {
  55994. hasCheckedForExternalDrag = true;
  55995. StringArray files;
  55996. bool canMoveFiles = false;
  55997. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  55998. && files.size() > 0)
  55999. {
  56000. Component::SafePointer<Component> cdw (this);
  56001. setVisible (false);
  56002. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  56003. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56004. if (cdw != 0)
  56005. delete this;
  56006. return;
  56007. }
  56008. }
  56009. }
  56010. }
  56011. }
  56012. void mouseDrag (const MouseEvent& e)
  56013. {
  56014. if (e.originalComponent != this)
  56015. updateLocation (true, e.getScreenPosition());
  56016. }
  56017. void timerCallback()
  56018. {
  56019. if (source == 0)
  56020. {
  56021. delete this;
  56022. }
  56023. else if (! isMouseButtonDownAnywhere())
  56024. {
  56025. if (mouseDragSource != 0)
  56026. mouseDragSource->removeMouseListener (this);
  56027. delete this;
  56028. }
  56029. }
  56030. private:
  56031. ScopedPointer<Image> image;
  56032. Component::SafePointer<Component> source;
  56033. Component::SafePointer<Component> mouseDragSource;
  56034. DragAndDropContainer* const owner;
  56035. Component::SafePointer<Component> currentlyOverComp;
  56036. DragAndDropTarget* getCurrentlyOver()
  56037. {
  56038. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  56039. }
  56040. String dragDesc;
  56041. const Point<int> imageOffset;
  56042. bool hasCheckedForExternalDrag, drawImage;
  56043. DragImageComponent (const DragImageComponent&);
  56044. DragImageComponent& operator= (const DragImageComponent&);
  56045. };
  56046. DragAndDropContainer::DragAndDropContainer()
  56047. {
  56048. }
  56049. DragAndDropContainer::~DragAndDropContainer()
  56050. {
  56051. dragImageComponent = 0;
  56052. }
  56053. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56054. Component* sourceComponent,
  56055. Image* dragImage_,
  56056. const bool allowDraggingToExternalWindows,
  56057. const Point<int>* imageOffsetFromMouse)
  56058. {
  56059. ScopedPointer <Image> dragImage (dragImage_);
  56060. if (dragImageComponent == 0)
  56061. {
  56062. Component* const thisComp = dynamic_cast <Component*> (this);
  56063. if (thisComp == 0)
  56064. {
  56065. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  56066. return;
  56067. }
  56068. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  56069. if (draggingSource == 0 || ! draggingSource->isDragging())
  56070. {
  56071. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  56072. return;
  56073. }
  56074. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  56075. Point<int> imageOffset;
  56076. if (dragImage == 0)
  56077. {
  56078. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56079. if (dragImage->getFormat() != Image::ARGB)
  56080. {
  56081. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56082. Graphics g2 (*newIm);
  56083. g2.drawImageAt (dragImage, 0, 0);
  56084. dragImage = newIm;
  56085. }
  56086. dragImage->multiplyAllAlphas (0.6f);
  56087. const int lo = 150;
  56088. const int hi = 400;
  56089. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  56090. Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
  56091. .getConstrainedPoint (relPos));
  56092. for (int y = dragImage->getHeight(); --y >= 0;)
  56093. {
  56094. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  56095. for (int x = dragImage->getWidth(); --x >= 0;)
  56096. {
  56097. const int dx = x - clipped.getX();
  56098. const int distance = roundToInt (sqrt (dx * dx + dy));
  56099. if (distance > lo)
  56100. {
  56101. const float alpha = (distance > hi) ? 0
  56102. : (hi - distance) / (float) (hi - lo)
  56103. + Random::getSystemRandom().nextFloat() * 0.008f;
  56104. dragImage->multiplyAlphaAt (x, y, alpha);
  56105. }
  56106. }
  56107. }
  56108. imageOffset = -clipped;
  56109. }
  56110. else
  56111. {
  56112. if (imageOffsetFromMouse == 0)
  56113. imageOffset = Point<int> (dragImage->getWidth() / -2,
  56114. dragImage->getHeight() / -2);
  56115. else
  56116. imageOffset = *imageOffsetFromMouse;
  56117. }
  56118. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56119. draggingSource->getComponentUnderMouse(), this, imageOffset);
  56120. currentDragDesc = sourceDescription;
  56121. if (allowDraggingToExternalWindows)
  56122. {
  56123. if (! Desktop::canUseSemiTransparentWindows())
  56124. dragImageComponent->setOpaque (true);
  56125. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56126. | ComponentPeer::windowIsTemporary
  56127. | ComponentPeer::windowIgnoresKeyPresses);
  56128. }
  56129. else
  56130. thisComp->addChildComponent (dragImageComponent);
  56131. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  56132. dragImageComponent->setVisible (true);
  56133. }
  56134. }
  56135. bool DragAndDropContainer::isDragAndDropActive() const
  56136. {
  56137. return dragImageComponent != 0;
  56138. }
  56139. const String DragAndDropContainer::getCurrentDragDescription() const
  56140. {
  56141. return (dragImageComponent != 0) ? currentDragDesc
  56142. : String::empty;
  56143. }
  56144. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56145. {
  56146. if (c == 0)
  56147. return 0;
  56148. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56149. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56150. }
  56151. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56152. {
  56153. return false;
  56154. }
  56155. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56156. {
  56157. }
  56158. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56159. {
  56160. }
  56161. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56162. {
  56163. }
  56164. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56165. {
  56166. return true;
  56167. }
  56168. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56169. {
  56170. }
  56171. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56172. {
  56173. }
  56174. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56175. {
  56176. }
  56177. END_JUCE_NAMESPACE
  56178. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56179. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56180. BEGIN_JUCE_NAMESPACE
  56181. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56182. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56183. // isStandard set depending on which interface was used to create the cursor
  56184. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56185. static CriticalSection activeCursorListLock;
  56186. static VoidArray activeCursors;
  56187. class SharedMouseCursorInternal : public ReferenceCountedObject
  56188. {
  56189. public:
  56190. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56191. : standardType (type),
  56192. isStandard (true)
  56193. {
  56194. handle = juce_createStandardMouseCursor (standardType);
  56195. activeCursors.add (this);
  56196. }
  56197. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56198. : standardType (MouseCursor::NormalCursor),
  56199. isStandard (false)
  56200. {
  56201. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56202. }
  56203. ~SharedMouseCursorInternal() throw()
  56204. {
  56205. juce_deleteMouseCursor (handle, isStandard);
  56206. activeCursors.removeValue (this);
  56207. }
  56208. void* getHandle() const throw()
  56209. {
  56210. return handle;
  56211. }
  56212. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56213. {
  56214. for (int i = activeCursors.size(); --i >= 0;)
  56215. {
  56216. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56217. if (r->standardType == type)
  56218. return r;
  56219. }
  56220. return new SharedMouseCursorInternal (type);
  56221. }
  56222. juce_UseDebuggingNewOperator
  56223. private:
  56224. void* handle;
  56225. const MouseCursor::StandardCursorType standardType;
  56226. const bool isStandard;
  56227. SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56228. };
  56229. MouseCursor::MouseCursor() throw()
  56230. {
  56231. const ScopedLock sl (activeCursorListLock);
  56232. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56233. }
  56234. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56235. {
  56236. const ScopedLock sl (activeCursorListLock);
  56237. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56238. }
  56239. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56240. {
  56241. const ScopedLock sl (activeCursorListLock);
  56242. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56243. }
  56244. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56245. : cursorHandle (other.cursorHandle)
  56246. {
  56247. }
  56248. MouseCursor::~MouseCursor() throw()
  56249. {
  56250. }
  56251. MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56252. {
  56253. cursorHandle = other.cursorHandle;
  56254. return *this;
  56255. }
  56256. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56257. {
  56258. return cursorHandle == other.cursorHandle;
  56259. }
  56260. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56261. {
  56262. return cursorHandle != other.cursorHandle;
  56263. }
  56264. void* MouseCursor::getHandle() const throw()
  56265. {
  56266. return cursorHandle->getHandle();
  56267. }
  56268. void MouseCursor::showWaitCursor() throw()
  56269. {
  56270. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56271. }
  56272. void MouseCursor::hideWaitCursor() throw()
  56273. {
  56274. Desktop::getInstance().getMainMouseSource().revealCursor();
  56275. }
  56276. END_JUCE_NAMESPACE
  56277. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56278. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56279. BEGIN_JUCE_NAMESPACE
  56280. MouseEvent::MouseEvent (MouseInputSource& source_,
  56281. const Point<int>& position,
  56282. const ModifierKeys& mods_,
  56283. Component* const originator,
  56284. const Time& eventTime_,
  56285. const Point<int> mouseDownPos_,
  56286. const Time& mouseDownTime_,
  56287. const int numberOfClicks_,
  56288. const bool mouseWasDragged) throw()
  56289. : x (position.getX()),
  56290. y (position.getY()),
  56291. mods (mods_),
  56292. eventComponent (originator),
  56293. originalComponent (originator),
  56294. eventTime (eventTime_),
  56295. source (source_),
  56296. mouseDownPos (mouseDownPos_),
  56297. mouseDownTime (mouseDownTime_),
  56298. numberOfClicks (numberOfClicks_),
  56299. wasMovedSinceMouseDown (mouseWasDragged)
  56300. {
  56301. }
  56302. MouseEvent::~MouseEvent() throw()
  56303. {
  56304. }
  56305. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56306. {
  56307. if (otherComponent == 0)
  56308. {
  56309. jassertfalse
  56310. return *this;
  56311. }
  56312. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56313. mods, originalComponent, eventTime,
  56314. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56315. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56316. }
  56317. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56318. {
  56319. return MouseEvent (source, newPosition, mods, originalComponent,
  56320. eventTime, mouseDownPos, mouseDownTime,
  56321. numberOfClicks, wasMovedSinceMouseDown);
  56322. }
  56323. bool MouseEvent::mouseWasClicked() const throw()
  56324. {
  56325. return ! wasMovedSinceMouseDown;
  56326. }
  56327. int MouseEvent::getMouseDownX() const throw()
  56328. {
  56329. return mouseDownPos.getX();
  56330. }
  56331. int MouseEvent::getMouseDownY() const throw()
  56332. {
  56333. return mouseDownPos.getY();
  56334. }
  56335. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56336. {
  56337. return mouseDownPos;
  56338. }
  56339. int MouseEvent::getDistanceFromDragStartX() const throw()
  56340. {
  56341. return x - mouseDownPos.getX();
  56342. }
  56343. int MouseEvent::getDistanceFromDragStartY() const throw()
  56344. {
  56345. return y - mouseDownPos.getY();
  56346. }
  56347. int MouseEvent::getDistanceFromDragStart() const throw()
  56348. {
  56349. return mouseDownPos.getDistanceFrom (getPosition());
  56350. }
  56351. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56352. {
  56353. return getPosition() - mouseDownPos;
  56354. }
  56355. int MouseEvent::getLengthOfMousePress() const throw()
  56356. {
  56357. if (mouseDownTime.toMilliseconds() > 0)
  56358. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56359. return 0;
  56360. }
  56361. const Point<int> MouseEvent::getPosition() const throw()
  56362. {
  56363. return Point<int> (x, y);
  56364. }
  56365. int MouseEvent::getScreenX() const
  56366. {
  56367. return getScreenPosition().getX();
  56368. }
  56369. int MouseEvent::getScreenY() const
  56370. {
  56371. return getScreenPosition().getY();
  56372. }
  56373. const Point<int> MouseEvent::getScreenPosition() const
  56374. {
  56375. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56376. }
  56377. int MouseEvent::getMouseDownScreenX() const
  56378. {
  56379. return getMouseDownScreenPosition().getX();
  56380. }
  56381. int MouseEvent::getMouseDownScreenY() const
  56382. {
  56383. return getMouseDownScreenPosition().getY();
  56384. }
  56385. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56386. {
  56387. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56388. }
  56389. static int doubleClickTimeOutMs = 400;
  56390. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56391. {
  56392. doubleClickTimeOutMs = newTime;
  56393. }
  56394. int MouseEvent::getDoubleClickTimeout() throw()
  56395. {
  56396. return doubleClickTimeOutMs;
  56397. }
  56398. END_JUCE_NAMESPACE
  56399. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56400. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56401. BEGIN_JUCE_NAMESPACE
  56402. class MouseInputSourceInternal : public AsyncUpdater
  56403. {
  56404. public:
  56405. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56406. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56407. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56408. {
  56409. zerostruct (mouseDowns);
  56410. }
  56411. ~MouseInputSourceInternal()
  56412. {
  56413. }
  56414. bool isDragging() const throw()
  56415. {
  56416. return buttonState.isAnyMouseButtonDown();
  56417. }
  56418. Component* getComponentUnderMouse() const
  56419. {
  56420. return static_cast <Component*> (componentUnderMouse);
  56421. }
  56422. const ModifierKeys getCurrentModifiers() const
  56423. {
  56424. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56425. }
  56426. ComponentPeer* getPeer()
  56427. {
  56428. if (! ComponentPeer::isValidPeer (lastPeer))
  56429. lastPeer = 0;
  56430. return lastPeer;
  56431. }
  56432. Component* findComponentAt (const Point<int>& screenPos)
  56433. {
  56434. ComponentPeer* const peer = getPeer();
  56435. if (peer != 0)
  56436. {
  56437. Component* const comp = peer->getComponent();
  56438. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56439. // (the contains() call is needed to test for overlapping desktop windows)
  56440. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56441. return comp->getComponentAt (relativePos);
  56442. }
  56443. return 0;
  56444. }
  56445. const Point<int> getScreenPosition() const throw()
  56446. {
  56447. return lastScreenPos + unboundedMouseOffset;
  56448. }
  56449. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56450. {
  56451. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56452. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56453. }
  56454. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56455. {
  56456. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56457. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56458. }
  56459. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56460. {
  56461. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56462. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56463. }
  56464. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56465. {
  56466. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56467. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56468. }
  56469. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56470. {
  56471. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56472. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56473. }
  56474. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56475. {
  56476. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56477. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56478. }
  56479. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56480. {
  56481. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56482. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56483. }
  56484. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56485. {
  56486. if (buttonState != newButtonState)
  56487. {
  56488. // (ignore secondary clicks when there's already a button down)
  56489. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56490. {
  56491. buttonState = newButtonState;
  56492. return;
  56493. }
  56494. if (buttonState.isAnyMouseButtonDown())
  56495. {
  56496. Component* const current = getComponentUnderMouse();
  56497. if (current != 0)
  56498. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56499. enableUnboundedMouseMovement (false, false);
  56500. }
  56501. buttonState = newButtonState;
  56502. if (buttonState.isAnyMouseButtonDown())
  56503. {
  56504. Desktop::getInstance().incrementMouseClickCounter();
  56505. Component* const current = getComponentUnderMouse();
  56506. if (current != 0)
  56507. {
  56508. registerMouseDown (screenPos, time, current);
  56509. sendMouseDown (current, screenPos, time);
  56510. }
  56511. }
  56512. }
  56513. }
  56514. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56515. {
  56516. Component* current = getComponentUnderMouse();
  56517. if (newComponent != current)
  56518. {
  56519. Component::SafePointer<Component> safeNewComp (newComponent);
  56520. const ModifierKeys originalButtonState (buttonState);
  56521. if (current != 0)
  56522. {
  56523. setButtons (screenPos, time, ModifierKeys());
  56524. sendMouseExit (current, screenPos, time);
  56525. buttonState = originalButtonState;
  56526. }
  56527. componentUnderMouse = safeNewComp;
  56528. current = getComponentUnderMouse();
  56529. if (current != 0)
  56530. sendMouseEnter (current, screenPos, time);
  56531. revealCursor (false);
  56532. setButtons (screenPos, time, originalButtonState);
  56533. }
  56534. }
  56535. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56536. {
  56537. ModifierKeys::updateCurrentModifiers();
  56538. if (newPeer != lastPeer)
  56539. {
  56540. setComponentUnderMouse (0, screenPos, time);
  56541. lastPeer = newPeer;
  56542. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56543. }
  56544. }
  56545. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56546. {
  56547. if (! isDragging())
  56548. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56549. if (newScreenPos != lastScreenPos || forceUpdate)
  56550. {
  56551. cancelPendingUpdate();
  56552. lastScreenPos = newScreenPos;
  56553. Component* const current = getComponentUnderMouse();
  56554. if (current != 0)
  56555. {
  56556. if (isDragging())
  56557. {
  56558. registerMouseDrag (newScreenPos);
  56559. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56560. if (isUnboundedMouseModeOn)
  56561. handleUnboundedDrag (current);
  56562. }
  56563. else
  56564. {
  56565. sendMouseMove (current, newScreenPos, time);
  56566. }
  56567. }
  56568. revealCursor (false);
  56569. }
  56570. }
  56571. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56572. {
  56573. jassert (newPeer != 0);
  56574. lastTime = time;
  56575. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56576. if (isDragging() && newMods.isAnyMouseButtonDown())
  56577. {
  56578. setScreenPos (screenPos, time, false);
  56579. }
  56580. else
  56581. {
  56582. setPeer (newPeer, screenPos, time);
  56583. ComponentPeer* peer = getPeer();
  56584. if (peer != 0)
  56585. {
  56586. setButtons (screenPos, time, newMods);
  56587. peer = getPeer();
  56588. if (peer != 0)
  56589. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56590. }
  56591. }
  56592. }
  56593. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56594. {
  56595. jassert (peer != 0);
  56596. lastTime = time;
  56597. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56598. setPeer (peer, screenPos, time);
  56599. setScreenPos (screenPos, time, false);
  56600. triggerFakeMove();
  56601. if (! isDragging())
  56602. {
  56603. Component* current = getComponentUnderMouse();
  56604. if (current != 0)
  56605. sendMouseWheel (current, screenPos, time, x, y);
  56606. }
  56607. }
  56608. const Time getLastMouseDownTime() const throw()
  56609. {
  56610. return Time (mouseDowns[0].time);
  56611. }
  56612. const Point<int> getLastMouseDownPosition() const throw()
  56613. {
  56614. return mouseDowns[0].position;
  56615. }
  56616. int getNumberOfMultipleClicks() const throw()
  56617. {
  56618. int numClicks = 0;
  56619. if (mouseDowns[0].time != 0)
  56620. {
  56621. if (! mouseMovedSignificantlySincePressed)
  56622. ++numClicks;
  56623. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56624. {
  56625. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56626. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56627. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56628. && mouseDowns[0].component == mouseDowns[i].component)
  56629. {
  56630. ++numClicks;
  56631. }
  56632. else
  56633. {
  56634. break;
  56635. }
  56636. }
  56637. }
  56638. return numClicks;
  56639. }
  56640. bool hasMouseMovedSignificantlySincePressed() const throw()
  56641. {
  56642. return mouseMovedSignificantlySincePressed
  56643. || lastTime > mouseDowns[0].time + 300;
  56644. }
  56645. void triggerFakeMove()
  56646. {
  56647. triggerAsyncUpdate();
  56648. }
  56649. void handleAsyncUpdate()
  56650. {
  56651. if (! isDragging())
  56652. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56653. }
  56654. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56655. {
  56656. enable = enable && isDragging();
  56657. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56658. if (enable != isUnboundedMouseModeOn)
  56659. {
  56660. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56661. {
  56662. // when released, return the mouse to within the component's bounds
  56663. Component* current = getComponentUnderMouse();
  56664. if (current != 0)
  56665. Desktop::setMousePosition (current->getScreenBounds()
  56666. .getConstrainedPoint (current->getMouseXYRelative()));
  56667. }
  56668. isUnboundedMouseModeOn = enable;
  56669. unboundedMouseOffset = Point<int>();
  56670. revealCursor (true);
  56671. }
  56672. }
  56673. void handleUnboundedDrag (Component* current)
  56674. {
  56675. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56676. if (! screenArea.contains (lastScreenPos))
  56677. {
  56678. const Point<int> compPos (current->getScreenPosition());
  56679. int deltaX = 0, deltaY = 0;
  56680. if (lastScreenPos.getX() <= screenArea.getX() || lastScreenPos.getX() >= screenArea.getRight())
  56681. deltaX = compPos.getX() + current->getWidth() / 2 - lastScreenPos.getX();
  56682. if (lastScreenPos.getY() <= screenArea.getY() || lastScreenPos.getY() >= screenArea.getBottom())
  56683. deltaY = compPos.getY() + current->getHeight() / 2 - lastScreenPos.getY();
  56684. const Point<int> delta (deltaX, deltaY);
  56685. unboundedMouseOffset -= delta;
  56686. Desktop::setMousePosition (lastScreenPos + delta);
  56687. }
  56688. else if (isCursorVisibleUntilOffscreen
  56689. && (! unboundedMouseOffset.isOrigin())
  56690. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56691. {
  56692. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56693. unboundedMouseOffset = Point<int>();
  56694. }
  56695. }
  56696. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56697. {
  56698. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56699. {
  56700. cursor = MouseCursor::NoCursor;
  56701. forcedUpdate = true;
  56702. }
  56703. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56704. {
  56705. currentCursorHandle = cursor.getHandle();
  56706. cursor.showInWindow (getPeer());
  56707. }
  56708. }
  56709. void hideCursor()
  56710. {
  56711. showMouseCursor (MouseCursor::NoCursor, true);
  56712. }
  56713. void revealCursor (bool forcedUpdate)
  56714. {
  56715. MouseCursor mc (MouseCursor::NormalCursor);
  56716. Component* current = getComponentUnderMouse();
  56717. if (current != 0)
  56718. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56719. showMouseCursor (mc, forcedUpdate);
  56720. }
  56721. int index;
  56722. bool isMouseDevice;
  56723. Point<int> lastScreenPos;
  56724. ModifierKeys buttonState;
  56725. private:
  56726. MouseInputSource& source;
  56727. Component::SafePointer<Component> componentUnderMouse;
  56728. ComponentPeer* lastPeer;
  56729. Point<int> unboundedMouseOffset;
  56730. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56731. void* currentCursorHandle;
  56732. struct RecentMouseDown
  56733. {
  56734. Point<int> position;
  56735. int64 time;
  56736. Component* component;
  56737. };
  56738. RecentMouseDown mouseDowns[4];
  56739. bool mouseMovedSignificantlySincePressed;
  56740. int64 lastTime;
  56741. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56742. {
  56743. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56744. mouseDowns[i] = mouseDowns[i - 1];
  56745. mouseDowns[0].position = screenPos;
  56746. mouseDowns[0].time = time;
  56747. mouseDowns[0].component = component;
  56748. mouseMovedSignificantlySincePressed = false;
  56749. }
  56750. void registerMouseDrag (const Point<int>& screenPos) throw()
  56751. {
  56752. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56753. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56754. }
  56755. };
  56756. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56757. {
  56758. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56759. }
  56760. MouseInputSource::~MouseInputSource()
  56761. {
  56762. }
  56763. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56764. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56765. bool MouseInputSource::canHover() const { return isMouse(); }
  56766. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56767. int MouseInputSource::getIndex() const { return pimpl->index; }
  56768. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56769. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56770. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56771. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56772. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56773. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56774. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56775. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56776. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56777. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56778. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56779. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56780. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56781. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56782. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56783. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  56784. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56785. {
  56786. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56787. }
  56788. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56789. {
  56790. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56791. }
  56792. END_JUCE_NAMESPACE
  56793. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56794. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56795. BEGIN_JUCE_NAMESPACE
  56796. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56797. : source (0),
  56798. hoverTimeMillisecs (hoverTimeMillisecs_),
  56799. hasJustHovered (false)
  56800. {
  56801. internalTimer.owner = this;
  56802. }
  56803. MouseHoverDetector::~MouseHoverDetector()
  56804. {
  56805. setHoverComponent (0);
  56806. }
  56807. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56808. {
  56809. hoverTimeMillisecs = newTimeInMillisecs;
  56810. }
  56811. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56812. {
  56813. if (source != newSourceComponent)
  56814. {
  56815. internalTimer.stopTimer();
  56816. hasJustHovered = false;
  56817. if (source != 0)
  56818. {
  56819. // ! you need to delete the hover detector before deleting its component
  56820. jassert (source->isValidComponent());
  56821. source->removeMouseListener (&internalTimer);
  56822. }
  56823. source = newSourceComponent;
  56824. if (newSourceComponent != 0)
  56825. newSourceComponent->addMouseListener (&internalTimer, false);
  56826. }
  56827. }
  56828. void MouseHoverDetector::hoverTimerCallback()
  56829. {
  56830. internalTimer.stopTimer();
  56831. if (source != 0)
  56832. {
  56833. const Point<int> pos (source->getMouseXYRelative());
  56834. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56835. {
  56836. hasJustHovered = true;
  56837. mouseHovered (pos.getX(), pos.getY());
  56838. }
  56839. }
  56840. }
  56841. void MouseHoverDetector::checkJustHoveredCallback()
  56842. {
  56843. if (hasJustHovered)
  56844. {
  56845. hasJustHovered = false;
  56846. mouseMovedAfterHover();
  56847. }
  56848. }
  56849. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56850. {
  56851. owner->hoverTimerCallback();
  56852. }
  56853. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56854. {
  56855. stopTimer();
  56856. owner->checkJustHoveredCallback();
  56857. }
  56858. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56859. {
  56860. stopTimer();
  56861. owner->checkJustHoveredCallback();
  56862. }
  56863. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56864. {
  56865. stopTimer();
  56866. owner->checkJustHoveredCallback();
  56867. }
  56868. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56869. {
  56870. stopTimer();
  56871. owner->checkJustHoveredCallback();
  56872. }
  56873. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56874. {
  56875. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56876. {
  56877. lastX = e.x;
  56878. lastY = e.y;
  56879. if (owner->source != 0)
  56880. startTimer (owner->hoverTimeMillisecs);
  56881. owner->checkJustHoveredCallback();
  56882. }
  56883. }
  56884. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56885. {
  56886. stopTimer();
  56887. owner->checkJustHoveredCallback();
  56888. }
  56889. END_JUCE_NAMESPACE
  56890. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56891. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56892. BEGIN_JUCE_NAMESPACE
  56893. void MouseListener::mouseEnter (const MouseEvent&)
  56894. {
  56895. }
  56896. void MouseListener::mouseExit (const MouseEvent&)
  56897. {
  56898. }
  56899. void MouseListener::mouseDown (const MouseEvent&)
  56900. {
  56901. }
  56902. void MouseListener::mouseUp (const MouseEvent&)
  56903. {
  56904. }
  56905. void MouseListener::mouseDrag (const MouseEvent&)
  56906. {
  56907. }
  56908. void MouseListener::mouseMove (const MouseEvent&)
  56909. {
  56910. }
  56911. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56912. {
  56913. }
  56914. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56915. {
  56916. }
  56917. END_JUCE_NAMESPACE
  56918. /*** End of inlined file: juce_MouseListener.cpp ***/
  56919. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56920. BEGIN_JUCE_NAMESPACE
  56921. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  56922. const String& buttonTextWhenTrue,
  56923. const String& buttonTextWhenFalse)
  56924. : PropertyComponent (name),
  56925. onText (buttonTextWhenTrue),
  56926. offText (buttonTextWhenFalse)
  56927. {
  56928. createButton();
  56929. button->addButtonListener (this);
  56930. }
  56931. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  56932. const String& name,
  56933. const String& buttonText)
  56934. : PropertyComponent (name),
  56935. onText (buttonText),
  56936. offText (buttonText)
  56937. {
  56938. createButton();
  56939. button->setButtonText (buttonText);
  56940. button->getToggleStateValue().referTo (valueToControl);
  56941. button->setClickingTogglesState (true);
  56942. }
  56943. BooleanPropertyComponent::~BooleanPropertyComponent()
  56944. {
  56945. deleteAllChildren();
  56946. }
  56947. void BooleanPropertyComponent::createButton()
  56948. {
  56949. addAndMakeVisible (button = new ToggleButton (String::empty));
  56950. button->setClickingTogglesState (false);
  56951. }
  56952. void BooleanPropertyComponent::setState (const bool newState)
  56953. {
  56954. button->setToggleState (newState, true);
  56955. }
  56956. bool BooleanPropertyComponent::getState() const
  56957. {
  56958. return button->getToggleState();
  56959. }
  56960. void BooleanPropertyComponent::paint (Graphics& g)
  56961. {
  56962. PropertyComponent::paint (g);
  56963. const Rectangle<int> r (button->getBounds());
  56964. g.setColour (Colours::white);
  56965. g.fillRect (r);
  56966. g.setColour (findColour (ComboBox::outlineColourId));
  56967. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  56968. }
  56969. void BooleanPropertyComponent::refresh()
  56970. {
  56971. button->setToggleState (getState(), false);
  56972. button->setButtonText (button->getToggleState() ? onText : offText);
  56973. }
  56974. void BooleanPropertyComponent::buttonClicked (Button*)
  56975. {
  56976. setState (! getState());
  56977. }
  56978. END_JUCE_NAMESPACE
  56979. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56980. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56981. BEGIN_JUCE_NAMESPACE
  56982. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  56983. const bool triggerOnMouseDown)
  56984. : PropertyComponent (name)
  56985. {
  56986. addAndMakeVisible (button = new TextButton (String::empty));
  56987. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  56988. button->addButtonListener (this);
  56989. }
  56990. ButtonPropertyComponent::~ButtonPropertyComponent()
  56991. {
  56992. deleteAllChildren();
  56993. }
  56994. void ButtonPropertyComponent::refresh()
  56995. {
  56996. button->setButtonText (getButtonText());
  56997. }
  56998. void ButtonPropertyComponent::buttonClicked (Button*)
  56999. {
  57000. buttonClicked();
  57001. }
  57002. END_JUCE_NAMESPACE
  57003. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57004. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57005. BEGIN_JUCE_NAMESPACE
  57006. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57007. : PropertyComponent (name),
  57008. comboBox (0)
  57009. {
  57010. }
  57011. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57012. const String& name,
  57013. const StringArray& choices_,
  57014. const Array <int>* choiceIDs)
  57015. : PropertyComponent (name),
  57016. choices (choices_),
  57017. comboBox (0)
  57018. {
  57019. createComboBox (choiceIDs);
  57020. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57021. }
  57022. ChoicePropertyComponent::~ChoicePropertyComponent()
  57023. {
  57024. deleteAllChildren();
  57025. }
  57026. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  57027. {
  57028. // The array of IDs must contain the same number of values as the choices list!
  57029. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  57030. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57031. for (int i = 0; i < choices.size(); ++i)
  57032. {
  57033. if (choices[i].isNotEmpty())
  57034. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  57035. : ((*choiceIDs)[i]));
  57036. else
  57037. comboBox->addSeparator();
  57038. }
  57039. comboBox->setEditableText (false);
  57040. }
  57041. void ChoicePropertyComponent::setIndex (const int newIndex)
  57042. {
  57043. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57044. }
  57045. int ChoicePropertyComponent::getIndex() const
  57046. {
  57047. return comboBox->getSelectedItemIndex();
  57048. }
  57049. const StringArray& ChoicePropertyComponent::getChoices() const
  57050. {
  57051. return choices;
  57052. }
  57053. void ChoicePropertyComponent::refresh()
  57054. {
  57055. if (comboBox == 0)
  57056. {
  57057. createComboBox (0);
  57058. comboBox->addListener (this);
  57059. }
  57060. comboBox->setSelectedId (getIndex() + 1, true);
  57061. }
  57062. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57063. {
  57064. const int newIndex = comboBox->getSelectedId() - 1;
  57065. if (newIndex != getIndex())
  57066. setIndex (newIndex);
  57067. }
  57068. END_JUCE_NAMESPACE
  57069. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57070. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  57071. BEGIN_JUCE_NAMESPACE
  57072. PropertyComponent::PropertyComponent (const String& name,
  57073. const int preferredHeight_)
  57074. : Component (name),
  57075. preferredHeight (preferredHeight_)
  57076. {
  57077. jassert (name.isNotEmpty());
  57078. }
  57079. PropertyComponent::~PropertyComponent()
  57080. {
  57081. }
  57082. void PropertyComponent::paint (Graphics& g)
  57083. {
  57084. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57085. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57086. }
  57087. void PropertyComponent::resized()
  57088. {
  57089. if (getNumChildComponents() > 0)
  57090. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57091. }
  57092. void PropertyComponent::enablementChanged()
  57093. {
  57094. repaint();
  57095. }
  57096. END_JUCE_NAMESPACE
  57097. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  57098. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  57099. BEGIN_JUCE_NAMESPACE
  57100. class PropertyHolderComponent : public Component
  57101. {
  57102. public:
  57103. PropertyHolderComponent()
  57104. {
  57105. }
  57106. ~PropertyHolderComponent()
  57107. {
  57108. deleteAllChildren();
  57109. }
  57110. void paint (Graphics&)
  57111. {
  57112. }
  57113. void updateLayout (const int width);
  57114. void refreshAll() const;
  57115. };
  57116. class PropertySectionComponent : public Component
  57117. {
  57118. public:
  57119. PropertySectionComponent (const String& sectionTitle,
  57120. const Array <PropertyComponent*>& newProperties,
  57121. const bool open)
  57122. : Component (sectionTitle),
  57123. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57124. isOpen_ (open)
  57125. {
  57126. for (int i = newProperties.size(); --i >= 0;)
  57127. {
  57128. addAndMakeVisible (newProperties.getUnchecked(i));
  57129. newProperties.getUnchecked(i)->refresh();
  57130. }
  57131. }
  57132. ~PropertySectionComponent()
  57133. {
  57134. deleteAllChildren();
  57135. }
  57136. void paint (Graphics& g)
  57137. {
  57138. if (titleHeight > 0)
  57139. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57140. }
  57141. void resized()
  57142. {
  57143. int y = titleHeight;
  57144. for (int i = getNumChildComponents(); --i >= 0;)
  57145. {
  57146. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57147. if (pec != 0)
  57148. {
  57149. const int prefH = pec->getPreferredHeight();
  57150. pec->setBounds (1, y, getWidth() - 2, prefH);
  57151. y += prefH;
  57152. }
  57153. }
  57154. }
  57155. int getPreferredHeight() const
  57156. {
  57157. int y = titleHeight;
  57158. if (isOpen())
  57159. {
  57160. for (int i = 0; i < getNumChildComponents(); ++i)
  57161. {
  57162. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57163. if (pec != 0)
  57164. y += pec->getPreferredHeight();
  57165. }
  57166. }
  57167. return y;
  57168. }
  57169. void setOpen (const bool open)
  57170. {
  57171. if (isOpen_ != open)
  57172. {
  57173. isOpen_ = open;
  57174. for (int i = 0; i < getNumChildComponents(); ++i)
  57175. {
  57176. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57177. if (pec != 0)
  57178. pec->setVisible (open);
  57179. }
  57180. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57181. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57182. if (pp != 0)
  57183. pp->resized();
  57184. }
  57185. }
  57186. bool isOpen() const
  57187. {
  57188. return isOpen_;
  57189. }
  57190. void refreshAll() const
  57191. {
  57192. for (int i = 0; i < getNumChildComponents(); ++i)
  57193. {
  57194. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57195. if (pec != 0)
  57196. pec->refresh();
  57197. }
  57198. }
  57199. void mouseDown (const MouseEvent&)
  57200. {
  57201. }
  57202. void mouseUp (const MouseEvent& e)
  57203. {
  57204. if (e.getMouseDownX() < titleHeight
  57205. && e.x < titleHeight
  57206. && e.y < titleHeight
  57207. && e.getNumberOfClicks() != 2)
  57208. {
  57209. setOpen (! isOpen());
  57210. }
  57211. }
  57212. void mouseDoubleClick (const MouseEvent& e)
  57213. {
  57214. if (e.y < titleHeight)
  57215. setOpen (! isOpen());
  57216. }
  57217. private:
  57218. int titleHeight;
  57219. bool isOpen_;
  57220. };
  57221. void PropertyHolderComponent::updateLayout (const int width)
  57222. {
  57223. int y = 0;
  57224. for (int i = getNumChildComponents(); --i >= 0;)
  57225. {
  57226. PropertySectionComponent* const section
  57227. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57228. if (section != 0)
  57229. {
  57230. const int prefH = section->getPreferredHeight();
  57231. section->setBounds (0, y, width, prefH);
  57232. y += prefH;
  57233. }
  57234. }
  57235. setSize (width, y);
  57236. repaint();
  57237. }
  57238. void PropertyHolderComponent::refreshAll() const
  57239. {
  57240. for (int i = getNumChildComponents(); --i >= 0;)
  57241. {
  57242. PropertySectionComponent* const section
  57243. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57244. if (section != 0)
  57245. section->refreshAll();
  57246. }
  57247. }
  57248. PropertyPanel::PropertyPanel()
  57249. {
  57250. messageWhenEmpty = TRANS("(nothing selected)");
  57251. addAndMakeVisible (viewport = new Viewport());
  57252. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57253. viewport->setFocusContainer (true);
  57254. }
  57255. PropertyPanel::~PropertyPanel()
  57256. {
  57257. clear();
  57258. deleteAllChildren();
  57259. }
  57260. void PropertyPanel::paint (Graphics& g)
  57261. {
  57262. if (propertyHolderComponent->getNumChildComponents() == 0)
  57263. {
  57264. g.setColour (Colours::black.withAlpha (0.5f));
  57265. g.setFont (14.0f);
  57266. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57267. Justification::centred, true);
  57268. }
  57269. }
  57270. void PropertyPanel::resized()
  57271. {
  57272. viewport->setBounds (0, 0, getWidth(), getHeight());
  57273. updatePropHolderLayout();
  57274. }
  57275. void PropertyPanel::clear()
  57276. {
  57277. if (propertyHolderComponent->getNumChildComponents() > 0)
  57278. {
  57279. propertyHolderComponent->deleteAllChildren();
  57280. repaint();
  57281. }
  57282. }
  57283. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57284. {
  57285. if (propertyHolderComponent->getNumChildComponents() == 0)
  57286. repaint();
  57287. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57288. newProperties,
  57289. true), 0);
  57290. updatePropHolderLayout();
  57291. }
  57292. void PropertyPanel::addSection (const String& sectionTitle,
  57293. const Array <PropertyComponent*>& newProperties,
  57294. const bool shouldBeOpen)
  57295. {
  57296. jassert (sectionTitle.isNotEmpty());
  57297. if (propertyHolderComponent->getNumChildComponents() == 0)
  57298. repaint();
  57299. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57300. newProperties,
  57301. shouldBeOpen), 0);
  57302. updatePropHolderLayout();
  57303. }
  57304. void PropertyPanel::updatePropHolderLayout() const
  57305. {
  57306. const int maxWidth = viewport->getMaximumVisibleWidth();
  57307. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57308. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57309. if (maxWidth != newMaxWidth)
  57310. {
  57311. // need to do this twice because of scrollbars changing the size, etc.
  57312. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57313. }
  57314. }
  57315. void PropertyPanel::refreshAll() const
  57316. {
  57317. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57318. }
  57319. const StringArray PropertyPanel::getSectionNames() const
  57320. {
  57321. StringArray s;
  57322. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57323. {
  57324. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57325. if (section != 0 && section->getName().isNotEmpty())
  57326. s.add (section->getName());
  57327. }
  57328. return s;
  57329. }
  57330. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57331. {
  57332. int index = 0;
  57333. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57334. {
  57335. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57336. if (section != 0 && section->getName().isNotEmpty())
  57337. {
  57338. if (index == sectionIndex)
  57339. return section->isOpen();
  57340. ++index;
  57341. }
  57342. }
  57343. return false;
  57344. }
  57345. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57346. {
  57347. int index = 0;
  57348. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57349. {
  57350. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57351. if (section != 0 && section->getName().isNotEmpty())
  57352. {
  57353. if (index == sectionIndex)
  57354. {
  57355. section->setOpen (shouldBeOpen);
  57356. break;
  57357. }
  57358. ++index;
  57359. }
  57360. }
  57361. }
  57362. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57363. {
  57364. int index = 0;
  57365. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57366. {
  57367. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57368. if (section != 0 && section->getName().isNotEmpty())
  57369. {
  57370. if (index == sectionIndex)
  57371. {
  57372. section->setEnabled (shouldBeEnabled);
  57373. break;
  57374. }
  57375. ++index;
  57376. }
  57377. }
  57378. }
  57379. XmlElement* PropertyPanel::getOpennessState() const
  57380. {
  57381. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57382. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57383. const StringArray sections (getSectionNames());
  57384. for (int i = 0; i < sections.size(); ++i)
  57385. {
  57386. if (sections[i].isNotEmpty())
  57387. {
  57388. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57389. e->setAttribute ("name", sections[i]);
  57390. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57391. }
  57392. }
  57393. return xml;
  57394. }
  57395. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57396. {
  57397. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57398. {
  57399. const StringArray sections (getSectionNames());
  57400. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57401. {
  57402. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57403. e->getBoolAttribute (T("open")));
  57404. }
  57405. viewport->setViewPosition (viewport->getViewPositionX(),
  57406. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57407. }
  57408. }
  57409. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57410. {
  57411. if (messageWhenEmpty != newMessage)
  57412. {
  57413. messageWhenEmpty = newMessage;
  57414. repaint();
  57415. }
  57416. }
  57417. const String& PropertyPanel::getMessageWhenEmpty() const
  57418. {
  57419. return messageWhenEmpty;
  57420. }
  57421. END_JUCE_NAMESPACE
  57422. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57423. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57424. BEGIN_JUCE_NAMESPACE
  57425. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57426. const double rangeMin,
  57427. const double rangeMax,
  57428. const double interval,
  57429. const double skewFactor)
  57430. : PropertyComponent (name)
  57431. {
  57432. addAndMakeVisible (slider = new Slider (name));
  57433. slider->setRange (rangeMin, rangeMax, interval);
  57434. slider->setSkewFactor (skewFactor);
  57435. slider->setSliderStyle (Slider::LinearBar);
  57436. slider->addListener (this);
  57437. }
  57438. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57439. const String& name,
  57440. const double rangeMin,
  57441. const double rangeMax,
  57442. const double interval,
  57443. const double skewFactor)
  57444. : PropertyComponent (name)
  57445. {
  57446. addAndMakeVisible (slider = new Slider (name));
  57447. slider->setRange (rangeMin, rangeMax, interval);
  57448. slider->setSkewFactor (skewFactor);
  57449. slider->setSliderStyle (Slider::LinearBar);
  57450. slider->getValueObject().referTo (valueToControl);
  57451. }
  57452. SliderPropertyComponent::~SliderPropertyComponent()
  57453. {
  57454. deleteAllChildren();
  57455. }
  57456. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57457. {
  57458. }
  57459. const double SliderPropertyComponent::getValue() const
  57460. {
  57461. return slider->getValue();
  57462. }
  57463. void SliderPropertyComponent::refresh()
  57464. {
  57465. slider->setValue (getValue(), false);
  57466. }
  57467. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57468. {
  57469. if (getValue() != slider->getValue())
  57470. setValue (slider->getValue());
  57471. }
  57472. END_JUCE_NAMESPACE
  57473. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57474. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57475. BEGIN_JUCE_NAMESPACE
  57476. class TextPropLabel : public Label
  57477. {
  57478. TextPropertyComponent& owner;
  57479. int maxChars;
  57480. bool isMultiline;
  57481. public:
  57482. TextPropLabel (TextPropertyComponent& owner_,
  57483. const int maxChars_, const bool isMultiline_)
  57484. : Label (String::empty, String::empty),
  57485. owner (owner_),
  57486. maxChars (maxChars_),
  57487. isMultiline (isMultiline_)
  57488. {
  57489. setEditable (true, true, false);
  57490. setColour (backgroundColourId, Colours::white);
  57491. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57492. }
  57493. ~TextPropLabel()
  57494. {
  57495. }
  57496. TextEditor* createEditorComponent()
  57497. {
  57498. TextEditor* const textEditor = Label::createEditorComponent();
  57499. textEditor->setInputRestrictions (maxChars);
  57500. if (isMultiline)
  57501. {
  57502. textEditor->setMultiLine (true, true);
  57503. textEditor->setReturnKeyStartsNewLine (true);
  57504. }
  57505. return textEditor;
  57506. }
  57507. void textWasEdited()
  57508. {
  57509. owner.textWasEdited();
  57510. }
  57511. };
  57512. TextPropertyComponent::TextPropertyComponent (const String& name,
  57513. const int maxNumChars,
  57514. const bool isMultiLine)
  57515. : PropertyComponent (name)
  57516. {
  57517. createEditor (maxNumChars, isMultiLine);
  57518. }
  57519. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57520. const String& name,
  57521. const int maxNumChars,
  57522. const bool isMultiLine)
  57523. : PropertyComponent (name)
  57524. {
  57525. createEditor (maxNumChars, isMultiLine);
  57526. textEditor->getTextValue().referTo (valueToControl);
  57527. }
  57528. TextPropertyComponent::~TextPropertyComponent()
  57529. {
  57530. deleteAllChildren();
  57531. }
  57532. void TextPropertyComponent::setText (const String& newText)
  57533. {
  57534. textEditor->setText (newText, true);
  57535. }
  57536. const String TextPropertyComponent::getText() const
  57537. {
  57538. return textEditor->getText();
  57539. }
  57540. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57541. {
  57542. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57543. if (isMultiLine)
  57544. {
  57545. textEditor->setJustificationType (Justification::topLeft);
  57546. preferredHeight = 120;
  57547. }
  57548. }
  57549. void TextPropertyComponent::refresh()
  57550. {
  57551. textEditor->setText (getText(), false);
  57552. }
  57553. void TextPropertyComponent::textWasEdited()
  57554. {
  57555. const String newText (textEditor->getText());
  57556. if (getText() != newText)
  57557. setText (newText);
  57558. }
  57559. END_JUCE_NAMESPACE
  57560. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57561. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57562. BEGIN_JUCE_NAMESPACE
  57563. class SimpleDeviceManagerInputLevelMeter : public Component,
  57564. public Timer
  57565. {
  57566. public:
  57567. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57568. : manager (manager_),
  57569. level (0)
  57570. {
  57571. startTimer (50);
  57572. manager->enableInputLevelMeasurement (true);
  57573. }
  57574. ~SimpleDeviceManagerInputLevelMeter()
  57575. {
  57576. manager->enableInputLevelMeasurement (false);
  57577. }
  57578. void timerCallback()
  57579. {
  57580. const float newLevel = (float) manager->getCurrentInputLevel();
  57581. if (fabsf (level - newLevel) > 0.005f)
  57582. {
  57583. level = newLevel;
  57584. repaint();
  57585. }
  57586. }
  57587. void paint (Graphics& g)
  57588. {
  57589. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57590. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57591. }
  57592. private:
  57593. AudioDeviceManager* const manager;
  57594. float level;
  57595. SimpleDeviceManagerInputLevelMeter (const SimpleDeviceManagerInputLevelMeter&);
  57596. SimpleDeviceManagerInputLevelMeter& operator= (const SimpleDeviceManagerInputLevelMeter&);
  57597. };
  57598. class MidiInputSelectorComponentListBox : public ListBox,
  57599. public ListBoxModel
  57600. {
  57601. public:
  57602. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57603. const String& noItemsMessage_,
  57604. const int minNumber_,
  57605. const int maxNumber_)
  57606. : ListBox (String::empty, 0),
  57607. deviceManager (deviceManager_),
  57608. noItemsMessage (noItemsMessage_),
  57609. minNumber (minNumber_),
  57610. maxNumber (maxNumber_)
  57611. {
  57612. items = MidiInput::getDevices();
  57613. setModel (this);
  57614. setOutlineThickness (1);
  57615. }
  57616. ~MidiInputSelectorComponentListBox()
  57617. {
  57618. }
  57619. int getNumRows()
  57620. {
  57621. return items.size();
  57622. }
  57623. void paintListBoxItem (int row,
  57624. Graphics& g,
  57625. int width, int height,
  57626. bool rowIsSelected)
  57627. {
  57628. if (((unsigned int) row) < (unsigned int) items.size())
  57629. {
  57630. if (rowIsSelected)
  57631. g.fillAll (findColour (TextEditor::highlightColourId)
  57632. .withMultipliedAlpha (0.3f));
  57633. const String item (items [row]);
  57634. bool enabled = deviceManager.isMidiInputEnabled (item);
  57635. const int x = getTickX();
  57636. const float tickW = height * 0.75f;
  57637. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57638. enabled, true, true, false);
  57639. g.setFont (height * 0.6f);
  57640. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57641. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57642. }
  57643. }
  57644. void listBoxItemClicked (int row, const MouseEvent& e)
  57645. {
  57646. selectRow (row);
  57647. if (e.x < getTickX())
  57648. flipEnablement (row);
  57649. }
  57650. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57651. {
  57652. flipEnablement (row);
  57653. }
  57654. void returnKeyPressed (int row)
  57655. {
  57656. flipEnablement (row);
  57657. }
  57658. void paint (Graphics& g)
  57659. {
  57660. ListBox::paint (g);
  57661. if (items.size() == 0)
  57662. {
  57663. g.setColour (Colours::grey);
  57664. g.setFont (13.0f);
  57665. g.drawText (noItemsMessage,
  57666. 0, 0, getWidth(), getHeight() / 2,
  57667. Justification::centred, true);
  57668. }
  57669. }
  57670. int getBestHeight (const int preferredHeight)
  57671. {
  57672. const int extra = getOutlineThickness() * 2;
  57673. return jmax (getRowHeight() * 2 + extra,
  57674. jmin (getRowHeight() * getNumRows() + extra,
  57675. preferredHeight));
  57676. }
  57677. juce_UseDebuggingNewOperator
  57678. private:
  57679. AudioDeviceManager& deviceManager;
  57680. const String noItemsMessage;
  57681. StringArray items;
  57682. int minNumber, maxNumber;
  57683. void flipEnablement (const int row)
  57684. {
  57685. if (((unsigned int) row) < (unsigned int) items.size())
  57686. {
  57687. const String item (items [row]);
  57688. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57689. }
  57690. }
  57691. int getTickX() const
  57692. {
  57693. return getRowHeight() + 5;
  57694. }
  57695. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57696. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57697. };
  57698. class AudioDeviceSettingsPanel : public Component,
  57699. public ComboBoxListener,
  57700. public ChangeListener,
  57701. public ButtonListener
  57702. {
  57703. public:
  57704. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57705. AudioIODeviceType::DeviceSetupDetails& setup_,
  57706. const bool hideAdvancedOptionsWithButton)
  57707. : type (type_),
  57708. setup (setup_)
  57709. {
  57710. sampleRateDropDown = 0;
  57711. sampleRateLabel = 0;
  57712. bufferSizeDropDown = 0;
  57713. bufferSizeLabel = 0;
  57714. outputDeviceDropDown = 0;
  57715. outputDeviceLabel = 0;
  57716. inputDeviceDropDown = 0;
  57717. inputDeviceLabel = 0;
  57718. testButton = 0;
  57719. inputLevelMeter = 0;
  57720. showUIButton = 0;
  57721. inputChanList = 0;
  57722. outputChanList = 0;
  57723. inputChanLabel = 0;
  57724. outputChanLabel = 0;
  57725. showAdvancedSettingsButton = 0;
  57726. if (hideAdvancedOptionsWithButton)
  57727. {
  57728. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57729. showAdvancedSettingsButton->addButtonListener (this);
  57730. }
  57731. type->scanForDevices();
  57732. setup.manager->addChangeListener (this);
  57733. changeListenerCallback (0);
  57734. }
  57735. ~AudioDeviceSettingsPanel()
  57736. {
  57737. setup.manager->removeChangeListener (this);
  57738. deleteAndZero (outputDeviceLabel);
  57739. deleteAndZero (inputDeviceLabel);
  57740. deleteAndZero (sampleRateLabel);
  57741. deleteAndZero (bufferSizeLabel);
  57742. deleteAndZero (showUIButton);
  57743. deleteAndZero (inputChanLabel);
  57744. deleteAndZero (outputChanLabel);
  57745. deleteAndZero (showAdvancedSettingsButton);
  57746. deleteAllChildren();
  57747. }
  57748. void resized()
  57749. {
  57750. const int lx = proportionOfWidth (0.35f);
  57751. const int w = proportionOfWidth (0.4f);
  57752. const int h = 24;
  57753. const int space = 6;
  57754. const int dh = h + space;
  57755. int y = 0;
  57756. if (outputDeviceDropDown != 0)
  57757. {
  57758. outputDeviceDropDown->setBounds (lx, y, w, h);
  57759. if (testButton != 0)
  57760. testButton->setBounds (proportionOfWidth (0.77f),
  57761. outputDeviceDropDown->getY(),
  57762. proportionOfWidth (0.18f),
  57763. h);
  57764. y += dh;
  57765. }
  57766. if (inputDeviceDropDown != 0)
  57767. {
  57768. inputDeviceDropDown->setBounds (lx, y, w, h);
  57769. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57770. inputDeviceDropDown->getY(),
  57771. proportionOfWidth (0.18f),
  57772. h);
  57773. y += dh;
  57774. }
  57775. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57776. if (outputChanList != 0)
  57777. {
  57778. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57779. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57780. y += bh + space;
  57781. }
  57782. if (inputChanList != 0)
  57783. {
  57784. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57785. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57786. y += bh + space;
  57787. }
  57788. y += space * 2;
  57789. if (showAdvancedSettingsButton != 0)
  57790. {
  57791. showAdvancedSettingsButton->changeWidthToFitText (h);
  57792. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57793. }
  57794. if (sampleRateDropDown != 0)
  57795. {
  57796. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57797. || ! showAdvancedSettingsButton->isVisible());
  57798. sampleRateDropDown->setBounds (lx, y, w, h);
  57799. y += dh;
  57800. }
  57801. if (bufferSizeDropDown != 0)
  57802. {
  57803. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57804. || ! showAdvancedSettingsButton->isVisible());
  57805. bufferSizeDropDown->setBounds (lx, y, w, h);
  57806. y += dh;
  57807. }
  57808. if (showUIButton != 0)
  57809. {
  57810. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57811. || ! showAdvancedSettingsButton->isVisible());
  57812. showUIButton->changeWidthToFitText (h);
  57813. showUIButton->setTopLeftPosition (lx, y);
  57814. }
  57815. }
  57816. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57817. {
  57818. if (comboBoxThatHasChanged == 0)
  57819. return;
  57820. AudioDeviceManager::AudioDeviceSetup config;
  57821. setup.manager->getAudioDeviceSetup (config);
  57822. String error;
  57823. if (comboBoxThatHasChanged == outputDeviceDropDown
  57824. || comboBoxThatHasChanged == inputDeviceDropDown)
  57825. {
  57826. if (outputDeviceDropDown != 0)
  57827. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57828. : outputDeviceDropDown->getText();
  57829. if (inputDeviceDropDown != 0)
  57830. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57831. : inputDeviceDropDown->getText();
  57832. if (! type->hasSeparateInputsAndOutputs())
  57833. config.inputDeviceName = config.outputDeviceName;
  57834. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57835. config.useDefaultInputChannels = true;
  57836. else
  57837. config.useDefaultOutputChannels = true;
  57838. error = setup.manager->setAudioDeviceSetup (config, true);
  57839. showCorrectDeviceName (inputDeviceDropDown, true);
  57840. showCorrectDeviceName (outputDeviceDropDown, false);
  57841. updateControlPanelButton();
  57842. resized();
  57843. }
  57844. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57845. {
  57846. if (sampleRateDropDown->getSelectedId() > 0)
  57847. {
  57848. config.sampleRate = sampleRateDropDown->getSelectedId();
  57849. error = setup.manager->setAudioDeviceSetup (config, true);
  57850. }
  57851. }
  57852. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57853. {
  57854. if (bufferSizeDropDown->getSelectedId() > 0)
  57855. {
  57856. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57857. error = setup.manager->setAudioDeviceSetup (config, true);
  57858. }
  57859. }
  57860. if (error.isNotEmpty())
  57861. {
  57862. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57863. T("Error when trying to open audio device!"),
  57864. error);
  57865. }
  57866. }
  57867. void buttonClicked (Button* button)
  57868. {
  57869. if (button == showAdvancedSettingsButton)
  57870. {
  57871. showAdvancedSettingsButton->setVisible (false);
  57872. resized();
  57873. }
  57874. else if (button == showUIButton)
  57875. {
  57876. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57877. if (device != 0 && device->showControlPanel())
  57878. {
  57879. setup.manager->closeAudioDevice();
  57880. setup.manager->restartLastAudioDevice();
  57881. getTopLevelComponent()->toFront (true);
  57882. }
  57883. }
  57884. else if (button == testButton && testButton != 0)
  57885. {
  57886. setup.manager->playTestSound();
  57887. }
  57888. }
  57889. void updateControlPanelButton()
  57890. {
  57891. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57892. deleteAndZero (showUIButton);
  57893. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57894. {
  57895. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57896. TRANS ("opens the device's own control panel")));
  57897. showUIButton->addButtonListener (this);
  57898. }
  57899. resized();
  57900. }
  57901. void changeListenerCallback (void*)
  57902. {
  57903. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57904. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57905. {
  57906. if (outputDeviceDropDown == 0)
  57907. {
  57908. outputDeviceDropDown = new ComboBox (String::empty);
  57909. outputDeviceDropDown->addListener (this);
  57910. addAndMakeVisible (outputDeviceDropDown);
  57911. outputDeviceLabel = new Label (String::empty,
  57912. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57913. : TRANS ("device:"));
  57914. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57915. if (setup.maxNumOutputChannels > 0)
  57916. {
  57917. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  57918. testButton->addButtonListener (this);
  57919. }
  57920. }
  57921. addNamesToDeviceBox (*outputDeviceDropDown, false);
  57922. }
  57923. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  57924. {
  57925. if (inputDeviceDropDown == 0)
  57926. {
  57927. inputDeviceDropDown = new ComboBox (String::empty);
  57928. inputDeviceDropDown->addListener (this);
  57929. addAndMakeVisible (inputDeviceDropDown);
  57930. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  57931. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  57932. addAndMakeVisible (inputLevelMeter
  57933. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  57934. }
  57935. addNamesToDeviceBox (*inputDeviceDropDown, true);
  57936. }
  57937. updateControlPanelButton();
  57938. showCorrectDeviceName (inputDeviceDropDown, true);
  57939. showCorrectDeviceName (outputDeviceDropDown, false);
  57940. if (currentDevice != 0)
  57941. {
  57942. if (setup.maxNumOutputChannels > 0
  57943. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  57944. {
  57945. if (outputChanList == 0)
  57946. {
  57947. addAndMakeVisible (outputChanList
  57948. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  57949. TRANS ("(no audio output channels found)")));
  57950. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  57951. outputChanLabel->attachToComponent (outputChanList, true);
  57952. }
  57953. outputChanList->refresh();
  57954. }
  57955. else
  57956. {
  57957. deleteAndZero (outputChanLabel);
  57958. deleteAndZero (outputChanList);
  57959. }
  57960. if (setup.maxNumInputChannels > 0
  57961. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  57962. {
  57963. if (inputChanList == 0)
  57964. {
  57965. addAndMakeVisible (inputChanList
  57966. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  57967. TRANS ("(no audio input channels found)")));
  57968. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  57969. inputChanLabel->attachToComponent (inputChanList, true);
  57970. }
  57971. inputChanList->refresh();
  57972. }
  57973. else
  57974. {
  57975. deleteAndZero (inputChanLabel);
  57976. deleteAndZero (inputChanList);
  57977. }
  57978. // sample rate..
  57979. {
  57980. if (sampleRateDropDown == 0)
  57981. {
  57982. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  57983. sampleRateDropDown->addListener (this);
  57984. delete sampleRateLabel;
  57985. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  57986. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  57987. }
  57988. else
  57989. {
  57990. sampleRateDropDown->clear();
  57991. sampleRateDropDown->removeListener (this);
  57992. }
  57993. const int numRates = currentDevice->getNumSampleRates();
  57994. for (int i = 0; i < numRates; ++i)
  57995. {
  57996. const int rate = roundToInt (currentDevice->getSampleRate (i));
  57997. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  57998. }
  57999. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  58000. sampleRateDropDown->addListener (this);
  58001. }
  58002. // buffer size
  58003. {
  58004. if (bufferSizeDropDown == 0)
  58005. {
  58006. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58007. bufferSizeDropDown->addListener (this);
  58008. delete bufferSizeLabel;
  58009. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58010. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58011. }
  58012. else
  58013. {
  58014. bufferSizeDropDown->clear();
  58015. }
  58016. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58017. double currentRate = currentDevice->getCurrentSampleRate();
  58018. if (currentRate == 0)
  58019. currentRate = 48000.0;
  58020. for (int i = 0; i < numBufferSizes; ++i)
  58021. {
  58022. const int bs = currentDevice->getBufferSizeSamples (i);
  58023. bufferSizeDropDown->addItem (String (bs)
  58024. + T(" samples (")
  58025. + String (bs * 1000.0 / currentRate, 1)
  58026. + T(" ms)"),
  58027. bs);
  58028. }
  58029. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58030. }
  58031. }
  58032. else
  58033. {
  58034. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58035. deleteAndZero (sampleRateLabel);
  58036. deleteAndZero (bufferSizeLabel);
  58037. deleteAndZero (sampleRateDropDown);
  58038. deleteAndZero (bufferSizeDropDown);
  58039. if (outputDeviceDropDown != 0)
  58040. outputDeviceDropDown->setSelectedId (-1, true);
  58041. if (inputDeviceDropDown != 0)
  58042. inputDeviceDropDown->setSelectedId (-1, true);
  58043. }
  58044. resized();
  58045. setSize (getWidth(), getLowestY() + 4);
  58046. }
  58047. private:
  58048. AudioIODeviceType* const type;
  58049. const AudioIODeviceType::DeviceSetupDetails setup;
  58050. ComboBox* outputDeviceDropDown;
  58051. ComboBox* inputDeviceDropDown;
  58052. ComboBox* sampleRateDropDown;
  58053. ComboBox* bufferSizeDropDown;
  58054. Label* outputDeviceLabel;
  58055. Label* inputDeviceLabel;
  58056. Label* sampleRateLabel;
  58057. Label* bufferSizeLabel;
  58058. Label* inputChanLabel;
  58059. Label* outputChanLabel;
  58060. TextButton* testButton;
  58061. Component* inputLevelMeter;
  58062. TextButton* showUIButton;
  58063. TextButton* showAdvancedSettingsButton;
  58064. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58065. {
  58066. if (box != 0)
  58067. {
  58068. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58069. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58070. box->setSelectedId (index + 1, true);
  58071. if (testButton != 0 && ! isInput)
  58072. testButton->setEnabled (index >= 0);
  58073. }
  58074. }
  58075. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58076. {
  58077. const StringArray devs (type->getDeviceNames (isInputs));
  58078. combo.clear (true);
  58079. for (int i = 0; i < devs.size(); ++i)
  58080. combo.addItem (devs[i], i + 1);
  58081. combo.addItem (TRANS("<< none >>"), -1);
  58082. combo.setSelectedId (-1, true);
  58083. }
  58084. int getLowestY() const
  58085. {
  58086. int y = 0;
  58087. for (int i = getNumChildComponents(); --i >= 0;)
  58088. y = jmax (y, getChildComponent (i)->getBottom());
  58089. return y;
  58090. }
  58091. public:
  58092. class ChannelSelectorListBox : public ListBox,
  58093. public ListBoxModel
  58094. {
  58095. public:
  58096. enum BoxType
  58097. {
  58098. audioInputType,
  58099. audioOutputType
  58100. };
  58101. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58102. const BoxType type_,
  58103. const String& noItemsMessage_)
  58104. : ListBox (String::empty, 0),
  58105. setup (setup_),
  58106. type (type_),
  58107. noItemsMessage (noItemsMessage_)
  58108. {
  58109. refresh();
  58110. setModel (this);
  58111. setOutlineThickness (1);
  58112. }
  58113. ~ChannelSelectorListBox()
  58114. {
  58115. }
  58116. void refresh()
  58117. {
  58118. items.clear();
  58119. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58120. if (currentDevice != 0)
  58121. {
  58122. if (type == audioInputType)
  58123. items = currentDevice->getInputChannelNames();
  58124. else if (type == audioOutputType)
  58125. items = currentDevice->getOutputChannelNames();
  58126. if (setup.useStereoPairs)
  58127. {
  58128. StringArray pairs;
  58129. for (int i = 0; i < items.size(); i += 2)
  58130. {
  58131. String name (items[i]);
  58132. String name2 (items[i + 1]);
  58133. String commonBit;
  58134. for (int j = 0; j < name.length(); ++j)
  58135. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58136. commonBit = name.substring (0, j);
  58137. pairs.add (name.trim()
  58138. + " + "
  58139. + name2.substring (commonBit.length()).trim());
  58140. }
  58141. items = pairs;
  58142. }
  58143. }
  58144. updateContent();
  58145. repaint();
  58146. }
  58147. int getNumRows()
  58148. {
  58149. return items.size();
  58150. }
  58151. void paintListBoxItem (int row,
  58152. Graphics& g,
  58153. int width, int height,
  58154. bool rowIsSelected)
  58155. {
  58156. if (((unsigned int) row) < (unsigned int) items.size())
  58157. {
  58158. if (rowIsSelected)
  58159. g.fillAll (findColour (TextEditor::highlightColourId)
  58160. .withMultipliedAlpha (0.3f));
  58161. const String item (items [row]);
  58162. bool enabled = false;
  58163. AudioDeviceManager::AudioDeviceSetup config;
  58164. setup.manager->getAudioDeviceSetup (config);
  58165. if (setup.useStereoPairs)
  58166. {
  58167. if (type == audioInputType)
  58168. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58169. else if (type == audioOutputType)
  58170. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58171. }
  58172. else
  58173. {
  58174. if (type == audioInputType)
  58175. enabled = config.inputChannels [row];
  58176. else if (type == audioOutputType)
  58177. enabled = config.outputChannels [row];
  58178. }
  58179. const int x = getTickX();
  58180. const float tickW = height * 0.75f;
  58181. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58182. enabled, true, true, false);
  58183. g.setFont (height * 0.6f);
  58184. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58185. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58186. }
  58187. }
  58188. void listBoxItemClicked (int row, const MouseEvent& e)
  58189. {
  58190. selectRow (row);
  58191. if (e.x < getTickX())
  58192. flipEnablement (row);
  58193. }
  58194. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58195. {
  58196. flipEnablement (row);
  58197. }
  58198. void returnKeyPressed (int row)
  58199. {
  58200. flipEnablement (row);
  58201. }
  58202. void paint (Graphics& g)
  58203. {
  58204. ListBox::paint (g);
  58205. if (items.size() == 0)
  58206. {
  58207. g.setColour (Colours::grey);
  58208. g.setFont (13.0f);
  58209. g.drawText (noItemsMessage,
  58210. 0, 0, getWidth(), getHeight() / 2,
  58211. Justification::centred, true);
  58212. }
  58213. }
  58214. int getBestHeight (int maxHeight)
  58215. {
  58216. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58217. getNumRows())
  58218. + getOutlineThickness() * 2;
  58219. }
  58220. juce_UseDebuggingNewOperator
  58221. private:
  58222. const AudioIODeviceType::DeviceSetupDetails setup;
  58223. const BoxType type;
  58224. const String noItemsMessage;
  58225. StringArray items;
  58226. void flipEnablement (const int row)
  58227. {
  58228. jassert (type == audioInputType || type == audioOutputType);
  58229. if (((unsigned int) row) < (unsigned int) items.size())
  58230. {
  58231. AudioDeviceManager::AudioDeviceSetup config;
  58232. setup.manager->getAudioDeviceSetup (config);
  58233. if (setup.useStereoPairs)
  58234. {
  58235. BitArray bits;
  58236. BitArray& original = (type == audioInputType ? config.inputChannels
  58237. : config.outputChannels);
  58238. int i;
  58239. for (i = 0; i < 256; i += 2)
  58240. bits.setBit (i / 2, original [i] || original [i + 1]);
  58241. if (type == audioInputType)
  58242. {
  58243. config.useDefaultInputChannels = false;
  58244. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58245. }
  58246. else
  58247. {
  58248. config.useDefaultOutputChannels = false;
  58249. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58250. }
  58251. for (i = 0; i < 256; ++i)
  58252. original.setBit (i, bits [i / 2]);
  58253. }
  58254. else
  58255. {
  58256. if (type == audioInputType)
  58257. {
  58258. config.useDefaultInputChannels = false;
  58259. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58260. }
  58261. else
  58262. {
  58263. config.useDefaultOutputChannels = false;
  58264. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58265. }
  58266. }
  58267. String error (setup.manager->setAudioDeviceSetup (config, true));
  58268. if (! error.isEmpty())
  58269. {
  58270. //xxx
  58271. }
  58272. }
  58273. }
  58274. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58275. {
  58276. const int numActive = chans.countNumberOfSetBits();
  58277. if (chans [index])
  58278. {
  58279. if (numActive > minNumber)
  58280. chans.setBit (index, false);
  58281. }
  58282. else
  58283. {
  58284. if (numActive >= maxNumber)
  58285. {
  58286. const int firstActiveChan = chans.findNextSetBit();
  58287. chans.setBit (index > firstActiveChan
  58288. ? firstActiveChan : chans.getHighestBit(),
  58289. false);
  58290. }
  58291. chans.setBit (index, true);
  58292. }
  58293. }
  58294. int getTickX() const
  58295. {
  58296. return getRowHeight() + 5;
  58297. }
  58298. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58299. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58300. };
  58301. private:
  58302. ChannelSelectorListBox* inputChanList;
  58303. ChannelSelectorListBox* outputChanList;
  58304. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58305. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58306. };
  58307. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58308. const int minInputChannels_,
  58309. const int maxInputChannels_,
  58310. const int minOutputChannels_,
  58311. const int maxOutputChannels_,
  58312. const bool showMidiInputOptions,
  58313. const bool showMidiOutputSelector,
  58314. const bool showChannelsAsStereoPairs_,
  58315. const bool hideAdvancedOptionsWithButton_)
  58316. : deviceManager (deviceManager_),
  58317. deviceTypeDropDown (0),
  58318. deviceTypeDropDownLabel (0),
  58319. audioDeviceSettingsComp (0),
  58320. minOutputChannels (minOutputChannels_),
  58321. maxOutputChannels (maxOutputChannels_),
  58322. minInputChannels (minInputChannels_),
  58323. maxInputChannels (maxInputChannels_),
  58324. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58325. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58326. {
  58327. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58328. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58329. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58330. {
  58331. deviceTypeDropDown = new ComboBox (String::empty);
  58332. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58333. {
  58334. deviceTypeDropDown
  58335. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58336. i + 1);
  58337. }
  58338. addAndMakeVisible (deviceTypeDropDown);
  58339. deviceTypeDropDown->addListener (this);
  58340. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58341. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58342. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58343. }
  58344. if (showMidiInputOptions)
  58345. {
  58346. addAndMakeVisible (midiInputsList
  58347. = new MidiInputSelectorComponentListBox (deviceManager,
  58348. TRANS("(no midi inputs available)"),
  58349. 0, 0));
  58350. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58351. midiInputsLabel->setJustificationType (Justification::topRight);
  58352. midiInputsLabel->attachToComponent (midiInputsList, true);
  58353. }
  58354. else
  58355. {
  58356. midiInputsList = 0;
  58357. midiInputsLabel = 0;
  58358. }
  58359. if (showMidiOutputSelector)
  58360. {
  58361. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58362. midiOutputSelector->addListener (this);
  58363. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58364. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58365. }
  58366. else
  58367. {
  58368. midiOutputSelector = 0;
  58369. midiOutputLabel = 0;
  58370. }
  58371. deviceManager_.addChangeListener (this);
  58372. changeListenerCallback (0);
  58373. }
  58374. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58375. {
  58376. deviceManager.removeChangeListener (this);
  58377. deleteAllChildren();
  58378. }
  58379. void AudioDeviceSelectorComponent::resized()
  58380. {
  58381. const int lx = proportionOfWidth (0.35f);
  58382. const int w = proportionOfWidth (0.4f);
  58383. const int h = 24;
  58384. const int space = 6;
  58385. const int dh = h + space;
  58386. int y = 15;
  58387. if (deviceTypeDropDown != 0)
  58388. {
  58389. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58390. y += dh + space * 2;
  58391. }
  58392. if (audioDeviceSettingsComp != 0)
  58393. {
  58394. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58395. y += audioDeviceSettingsComp->getHeight() + space;
  58396. }
  58397. if (midiInputsList != 0)
  58398. {
  58399. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58400. midiInputsList->setBounds (lx, y, w, bh);
  58401. y += bh + space;
  58402. }
  58403. if (midiOutputSelector != 0)
  58404. midiOutputSelector->setBounds (lx, y, w, h);
  58405. }
  58406. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58407. {
  58408. if (child == audioDeviceSettingsComp)
  58409. resized();
  58410. }
  58411. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58412. {
  58413. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58414. if (device != 0 && device->hasControlPanel())
  58415. {
  58416. if (device->showControlPanel())
  58417. deviceManager.restartLastAudioDevice();
  58418. getTopLevelComponent()->toFront (true);
  58419. }
  58420. }
  58421. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58422. {
  58423. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58424. {
  58425. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58426. if (type != 0)
  58427. {
  58428. deleteAndZero (audioDeviceSettingsComp);
  58429. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58430. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58431. }
  58432. }
  58433. else if (comboBoxThatHasChanged == midiOutputSelector)
  58434. {
  58435. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58436. }
  58437. }
  58438. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58439. {
  58440. if (deviceTypeDropDown != 0)
  58441. {
  58442. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58443. }
  58444. if (audioDeviceSettingsComp == 0
  58445. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58446. {
  58447. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58448. deleteAndZero (audioDeviceSettingsComp);
  58449. AudioIODeviceType* const type
  58450. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58451. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58452. if (type != 0)
  58453. {
  58454. AudioIODeviceType::DeviceSetupDetails details;
  58455. details.manager = &deviceManager;
  58456. details.minNumInputChannels = minInputChannels;
  58457. details.maxNumInputChannels = maxInputChannels;
  58458. details.minNumOutputChannels = minOutputChannels;
  58459. details.maxNumOutputChannels = maxOutputChannels;
  58460. details.useStereoPairs = showChannelsAsStereoPairs;
  58461. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58462. if (audioDeviceSettingsComp != 0)
  58463. {
  58464. addAndMakeVisible (audioDeviceSettingsComp);
  58465. audioDeviceSettingsComp->resized();
  58466. }
  58467. }
  58468. }
  58469. if (midiInputsList != 0)
  58470. {
  58471. midiInputsList->updateContent();
  58472. midiInputsList->repaint();
  58473. }
  58474. if (midiOutputSelector != 0)
  58475. {
  58476. midiOutputSelector->clear();
  58477. const StringArray midiOuts (MidiOutput::getDevices());
  58478. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58479. midiOutputSelector->addSeparator();
  58480. for (int i = 0; i < midiOuts.size(); ++i)
  58481. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58482. int current = -1;
  58483. if (deviceManager.getDefaultMidiOutput() != 0)
  58484. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58485. midiOutputSelector->setSelectedId (current, true);
  58486. }
  58487. resized();
  58488. }
  58489. END_JUCE_NAMESPACE
  58490. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58491. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58492. BEGIN_JUCE_NAMESPACE
  58493. BubbleComponent::BubbleComponent()
  58494. : side (0),
  58495. allowablePlacements (above | below | left | right),
  58496. arrowTipX (0.0f),
  58497. arrowTipY (0.0f)
  58498. {
  58499. setInterceptsMouseClicks (false, false);
  58500. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58501. setComponentEffect (&shadow);
  58502. }
  58503. BubbleComponent::~BubbleComponent()
  58504. {
  58505. }
  58506. void BubbleComponent::paint (Graphics& g)
  58507. {
  58508. int x = content.getX();
  58509. int y = content.getY();
  58510. int w = content.getWidth();
  58511. int h = content.getHeight();
  58512. int cw, ch;
  58513. getContentSize (cw, ch);
  58514. if (side == 3)
  58515. x += w - cw;
  58516. else if (side != 1)
  58517. x += (w - cw) / 2;
  58518. w = cw;
  58519. if (side == 2)
  58520. y += h - ch;
  58521. else if (side != 0)
  58522. y += (h - ch) / 2;
  58523. h = ch;
  58524. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58525. (float) x, (float) y,
  58526. (float) w, (float) h);
  58527. const int cx = x + (w - cw) / 2;
  58528. const int cy = y + (h - ch) / 2;
  58529. const int indent = 3;
  58530. g.setOrigin (cx + indent, cy + indent);
  58531. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58532. paintContent (g, cw - indent * 2, ch - indent * 2);
  58533. }
  58534. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58535. {
  58536. allowablePlacements = newPlacement;
  58537. }
  58538. void BubbleComponent::setPosition (Component* componentToPointTo)
  58539. {
  58540. jassert (componentToPointTo->isValidComponent());
  58541. Point<int> pos;
  58542. if (getParentComponent() != 0)
  58543. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58544. else
  58545. pos = componentToPointTo->relativePositionToGlobal (pos);
  58546. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58547. }
  58548. void BubbleComponent::setPosition (const int arrowTipX_,
  58549. const int arrowTipY_)
  58550. {
  58551. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58552. }
  58553. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58554. {
  58555. Rectangle<int> availableSpace;
  58556. if (getParentComponent() != 0)
  58557. {
  58558. availableSpace.setSize (getParentComponent()->getWidth(),
  58559. getParentComponent()->getHeight());
  58560. }
  58561. else
  58562. {
  58563. availableSpace = getParentMonitorArea();
  58564. }
  58565. int x = 0;
  58566. int y = 0;
  58567. int w = 150;
  58568. int h = 30;
  58569. getContentSize (w, h);
  58570. w += 30;
  58571. h += 30;
  58572. const float edgeIndent = 2.0f;
  58573. const int arrowLength = jmin (10, h / 3, w / 3);
  58574. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58575. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58576. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58577. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58578. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58579. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58580. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58581. {
  58582. spaceLeft = spaceRight = 0;
  58583. }
  58584. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58585. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58586. {
  58587. spaceAbove = spaceBelow = 0;
  58588. }
  58589. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58590. {
  58591. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58592. arrowTipX = w * 0.5f;
  58593. content.setSize (w, h - arrowLength);
  58594. if (spaceAbove >= spaceBelow)
  58595. {
  58596. // above
  58597. y = rectangleToPointTo.getY() - h;
  58598. content.setPosition (0, 0);
  58599. arrowTipY = h - edgeIndent;
  58600. side = 2;
  58601. }
  58602. else
  58603. {
  58604. // below
  58605. y = rectangleToPointTo.getBottom();
  58606. content.setPosition (0, arrowLength);
  58607. arrowTipY = edgeIndent;
  58608. side = 0;
  58609. }
  58610. }
  58611. else
  58612. {
  58613. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58614. arrowTipY = h * 0.5f;
  58615. content.setSize (w - arrowLength, h);
  58616. if (spaceLeft > spaceRight)
  58617. {
  58618. // on the left
  58619. x = rectangleToPointTo.getX() - w;
  58620. content.setPosition (0, 0);
  58621. arrowTipX = w - edgeIndent;
  58622. side = 3;
  58623. }
  58624. else
  58625. {
  58626. // on the right
  58627. x = rectangleToPointTo.getRight();
  58628. content.setPosition (arrowLength, 0);
  58629. arrowTipX = edgeIndent;
  58630. side = 1;
  58631. }
  58632. }
  58633. setBounds (x, y, w, h);
  58634. }
  58635. END_JUCE_NAMESPACE
  58636. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58637. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58638. BEGIN_JUCE_NAMESPACE
  58639. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58640. : fadeOutLength (fadeOutLengthMs),
  58641. deleteAfterUse (false)
  58642. {
  58643. }
  58644. BubbleMessageComponent::~BubbleMessageComponent()
  58645. {
  58646. fadeOutComponent (fadeOutLength);
  58647. }
  58648. void BubbleMessageComponent::showAt (int x, int y,
  58649. const String& text,
  58650. const int numMillisecondsBeforeRemoving,
  58651. const bool removeWhenMouseClicked,
  58652. const bool deleteSelfAfterUse)
  58653. {
  58654. textLayout.clear();
  58655. textLayout.setText (text, Font (14.0f));
  58656. textLayout.layout (256, Justification::centredLeft, true);
  58657. setPosition (x, y);
  58658. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58659. }
  58660. void BubbleMessageComponent::showAt (Component* const component,
  58661. const String& text,
  58662. const int numMillisecondsBeforeRemoving,
  58663. const bool removeWhenMouseClicked,
  58664. const bool deleteSelfAfterUse)
  58665. {
  58666. textLayout.clear();
  58667. textLayout.setText (text, Font (14.0f));
  58668. textLayout.layout (256, Justification::centredLeft, true);
  58669. setPosition (component);
  58670. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58671. }
  58672. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58673. const bool removeWhenMouseClicked,
  58674. const bool deleteSelfAfterUse)
  58675. {
  58676. setVisible (true);
  58677. deleteAfterUse = deleteSelfAfterUse;
  58678. if (numMillisecondsBeforeRemoving > 0)
  58679. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58680. else
  58681. expiryTime = 0;
  58682. startTimer (77);
  58683. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58684. if (! (removeWhenMouseClicked && isShowing()))
  58685. mouseClickCounter += 0xfffff;
  58686. repaint();
  58687. }
  58688. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58689. {
  58690. w = textLayout.getWidth() + 16;
  58691. h = textLayout.getHeight() + 16;
  58692. }
  58693. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58694. {
  58695. g.setColour (findColour (TooltipWindow::textColourId));
  58696. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58697. }
  58698. void BubbleMessageComponent::timerCallback()
  58699. {
  58700. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58701. {
  58702. stopTimer();
  58703. setVisible (false);
  58704. if (deleteAfterUse)
  58705. delete this;
  58706. }
  58707. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58708. {
  58709. stopTimer();
  58710. fadeOutComponent (fadeOutLength);
  58711. if (deleteAfterUse)
  58712. delete this;
  58713. }
  58714. }
  58715. END_JUCE_NAMESPACE
  58716. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58717. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58718. BEGIN_JUCE_NAMESPACE
  58719. static const int swatchesPerRow = 8;
  58720. static const int swatchHeight = 22;
  58721. class ColourComponentSlider : public Slider
  58722. {
  58723. public:
  58724. ColourComponentSlider (const String& name)
  58725. : Slider (name)
  58726. {
  58727. setRange (0.0, 255.0, 1.0);
  58728. }
  58729. ~ColourComponentSlider()
  58730. {
  58731. }
  58732. const String getTextFromValue (double value)
  58733. {
  58734. return String::toHexString ((int) value).toUpperCase().paddedLeft ('0', 2);
  58735. }
  58736. double getValueFromText (const String& text)
  58737. {
  58738. return (double) text.getHexValue32();
  58739. }
  58740. private:
  58741. ColourComponentSlider (const ColourComponentSlider&);
  58742. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58743. };
  58744. class ColourSpaceMarker : public Component
  58745. {
  58746. public:
  58747. ColourSpaceMarker()
  58748. {
  58749. setInterceptsMouseClicks (false, false);
  58750. }
  58751. ~ColourSpaceMarker()
  58752. {
  58753. }
  58754. void paint (Graphics& g)
  58755. {
  58756. g.setColour (Colour::greyLevel (0.1f));
  58757. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58758. g.setColour (Colour::greyLevel (0.9f));
  58759. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58760. }
  58761. private:
  58762. ColourSpaceMarker (const ColourSpaceMarker&);
  58763. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58764. };
  58765. class ColourSpaceView : public Component
  58766. {
  58767. ColourSelector* const owner;
  58768. float& h;
  58769. float& s;
  58770. float& v;
  58771. float lastHue;
  58772. ColourSpaceMarker* marker;
  58773. const int edge;
  58774. public:
  58775. ColourSpaceView (ColourSelector* owner_,
  58776. float& h_, float& s_, float& v_,
  58777. const int edgeSize)
  58778. : owner (owner_),
  58779. h (h_), s (s_), v (v_),
  58780. lastHue (0.0f),
  58781. edge (edgeSize)
  58782. {
  58783. addAndMakeVisible (marker = new ColourSpaceMarker());
  58784. setMouseCursor (MouseCursor::CrosshairCursor);
  58785. }
  58786. ~ColourSpaceView()
  58787. {
  58788. deleteAllChildren();
  58789. }
  58790. void paint (Graphics& g)
  58791. {
  58792. if (colours == 0)
  58793. {
  58794. const int width = getWidth() / 2;
  58795. const int height = getHeight() / 2;
  58796. colours = new Image (Image::RGB, width, height, false);
  58797. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58798. for (int y = 0; y < height; ++y)
  58799. {
  58800. const float v = 1.0f - y / (float) height;
  58801. for (int x = 0; x < width; ++x)
  58802. {
  58803. const float s = x / (float) width;
  58804. const Colour col (h, s, v, 1.0f);
  58805. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58806. pix->set (col.getPixelARGB());
  58807. }
  58808. }
  58809. }
  58810. g.setOpacity (1.0f);
  58811. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58812. 0, 0, colours->getWidth(), colours->getHeight());
  58813. }
  58814. void mouseDown (const MouseEvent& e)
  58815. {
  58816. mouseDrag (e);
  58817. }
  58818. void mouseDrag (const MouseEvent& e)
  58819. {
  58820. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58821. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58822. owner->setSV (s, v);
  58823. }
  58824. void updateIfNeeded()
  58825. {
  58826. if (lastHue != h)
  58827. {
  58828. lastHue = h;
  58829. colours = 0;
  58830. repaint();
  58831. }
  58832. updateMarker();
  58833. }
  58834. void resized()
  58835. {
  58836. colours = 0;
  58837. updateMarker();
  58838. }
  58839. private:
  58840. ScopedPointer <Image> colours;
  58841. void updateMarker() const throw()
  58842. {
  58843. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58844. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58845. edge * 2, edge * 2);
  58846. }
  58847. ColourSpaceView (const ColourSpaceView&);
  58848. ColourSpaceView& operator= (const ColourSpaceView&);
  58849. };
  58850. class HueSelectorMarker : public Component
  58851. {
  58852. public:
  58853. HueSelectorMarker()
  58854. {
  58855. setInterceptsMouseClicks (false, false);
  58856. }
  58857. ~HueSelectorMarker()
  58858. {
  58859. }
  58860. void paint (Graphics& g)
  58861. {
  58862. Path p;
  58863. p.addTriangle (1.0f, 1.0f,
  58864. getWidth() * 0.3f, getHeight() * 0.5f,
  58865. 1.0f, getHeight() - 1.0f);
  58866. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58867. getWidth() * 0.7f, getHeight() * 0.5f,
  58868. getWidth() - 1.0f, getHeight() - 1.0f);
  58869. g.setColour (Colours::white.withAlpha (0.75f));
  58870. g.fillPath (p);
  58871. g.setColour (Colours::black.withAlpha (0.75f));
  58872. g.strokePath (p, PathStrokeType (1.2f));
  58873. }
  58874. private:
  58875. HueSelectorMarker (const HueSelectorMarker&);
  58876. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58877. };
  58878. class HueSelectorComp : public Component
  58879. {
  58880. public:
  58881. HueSelectorComp (ColourSelector* owner_,
  58882. float& h_, float& s_, float& v_,
  58883. const int edgeSize)
  58884. : owner (owner_),
  58885. h (h_), s (s_), v (v_),
  58886. lastHue (0.0f),
  58887. edge (edgeSize)
  58888. {
  58889. addAndMakeVisible (marker = new HueSelectorMarker());
  58890. }
  58891. ~HueSelectorComp()
  58892. {
  58893. deleteAllChildren();
  58894. }
  58895. void paint (Graphics& g)
  58896. {
  58897. const float yScale = 1.0f / (getHeight() - edge * 2);
  58898. const Rectangle<int> clip (g.getClipBounds());
  58899. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58900. {
  58901. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58902. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58903. }
  58904. }
  58905. void resized()
  58906. {
  58907. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58908. getWidth(), edge * 2);
  58909. }
  58910. void mouseDown (const MouseEvent& e)
  58911. {
  58912. mouseDrag (e);
  58913. }
  58914. void mouseDrag (const MouseEvent& e)
  58915. {
  58916. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  58917. owner->setHue (hue);
  58918. }
  58919. void updateIfNeeded()
  58920. {
  58921. resized();
  58922. }
  58923. private:
  58924. ColourSelector* const owner;
  58925. float& h;
  58926. float& s;
  58927. float& v;
  58928. float lastHue;
  58929. HueSelectorMarker* marker;
  58930. const int edge;
  58931. HueSelectorComp (const HueSelectorComp&);
  58932. HueSelectorComp& operator= (const HueSelectorComp&);
  58933. };
  58934. class ColourSelector::SwatchComponent : public Component
  58935. {
  58936. public:
  58937. SwatchComponent (ColourSelector* owner_, int index_)
  58938. : owner (owner_),
  58939. index (index_)
  58940. {
  58941. }
  58942. ~SwatchComponent()
  58943. {
  58944. }
  58945. void paint (Graphics& g)
  58946. {
  58947. const Colour colour (owner->getSwatchColour (index));
  58948. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  58949. 6, 6,
  58950. Colour (0xffdddddd).overlaidWith (colour),
  58951. Colour (0xffffffff).overlaidWith (colour));
  58952. }
  58953. void mouseDown (const MouseEvent&)
  58954. {
  58955. PopupMenu m;
  58956. m.addItem (1, TRANS("Use this swatch as the current colour"));
  58957. m.addSeparator();
  58958. m.addItem (2, TRANS("Set this swatch to the current colour"));
  58959. const int r = m.showAt (this);
  58960. if (r == 1)
  58961. {
  58962. owner->setCurrentColour (owner->getSwatchColour (index));
  58963. }
  58964. else if (r == 2)
  58965. {
  58966. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  58967. {
  58968. owner->setSwatchColour (index, owner->getCurrentColour());
  58969. repaint();
  58970. }
  58971. }
  58972. }
  58973. private:
  58974. ColourSelector* const owner;
  58975. const int index;
  58976. SwatchComponent (const SwatchComponent&);
  58977. SwatchComponent& operator= (const SwatchComponent&);
  58978. };
  58979. ColourSelector::ColourSelector (const int flags_,
  58980. const int edgeGap_,
  58981. const int gapAroundColourSpaceComponent)
  58982. : colour (Colours::white),
  58983. flags (flags_),
  58984. topSpace (0),
  58985. edgeGap (edgeGap_)
  58986. {
  58987. // not much point having a selector with no components in it!
  58988. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  58989. updateHSV();
  58990. if ((flags & showSliders) != 0)
  58991. {
  58992. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  58993. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  58994. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  58995. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  58996. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  58997. for (int i = 4; --i >= 0;)
  58998. sliders[i]->addListener (this);
  58999. }
  59000. else
  59001. {
  59002. zeromem (sliders, sizeof (sliders));
  59003. }
  59004. if ((flags & showColourspace) != 0)
  59005. {
  59006. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59007. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59008. }
  59009. else
  59010. {
  59011. colourSpace = 0;
  59012. hueSelector = 0;
  59013. }
  59014. update();
  59015. }
  59016. ColourSelector::~ColourSelector()
  59017. {
  59018. dispatchPendingMessages();
  59019. swatchComponents.clear();
  59020. deleteAllChildren();
  59021. }
  59022. const Colour ColourSelector::getCurrentColour() const
  59023. {
  59024. return ((flags & showAlphaChannel) != 0) ? colour
  59025. : colour.withAlpha ((uint8) 0xff);
  59026. }
  59027. void ColourSelector::setCurrentColour (const Colour& c)
  59028. {
  59029. if (c != colour)
  59030. {
  59031. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59032. updateHSV();
  59033. update();
  59034. }
  59035. }
  59036. void ColourSelector::setHue (float newH)
  59037. {
  59038. newH = jlimit (0.0f, 1.0f, newH);
  59039. if (h != newH)
  59040. {
  59041. h = newH;
  59042. colour = Colour (h, s, v, colour.getFloatAlpha());
  59043. update();
  59044. }
  59045. }
  59046. void ColourSelector::setSV (float newS, float newV)
  59047. {
  59048. newS = jlimit (0.0f, 1.0f, newS);
  59049. newV = jlimit (0.0f, 1.0f, newV);
  59050. if (s != newS || v != newV)
  59051. {
  59052. s = newS;
  59053. v = newV;
  59054. colour = Colour (h, s, v, colour.getFloatAlpha());
  59055. update();
  59056. }
  59057. }
  59058. void ColourSelector::updateHSV()
  59059. {
  59060. colour.getHSB (h, s, v);
  59061. }
  59062. void ColourSelector::update()
  59063. {
  59064. if (sliders[0] != 0)
  59065. {
  59066. sliders[0]->setValue ((int) colour.getRed());
  59067. sliders[1]->setValue ((int) colour.getGreen());
  59068. sliders[2]->setValue ((int) colour.getBlue());
  59069. sliders[3]->setValue ((int) colour.getAlpha());
  59070. }
  59071. if (colourSpace != 0)
  59072. {
  59073. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59074. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59075. }
  59076. if ((flags & showColourAtTop) != 0)
  59077. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59078. sendChangeMessage (this);
  59079. }
  59080. void ColourSelector::paint (Graphics& g)
  59081. {
  59082. g.fillAll (findColour (backgroundColourId));
  59083. if ((flags & showColourAtTop) != 0)
  59084. {
  59085. const Colour colour (getCurrentColour());
  59086. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59087. 10, 10,
  59088. Colour (0xffdddddd).overlaidWith (colour),
  59089. Colour (0xffffffff).overlaidWith (colour));
  59090. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59091. g.setFont (14.0f, true);
  59092. g.drawText (colour.toDisplayString ((flags & showAlphaChannel) != 0),
  59093. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59094. Justification::centred, false);
  59095. }
  59096. if ((flags & showSliders) != 0)
  59097. {
  59098. g.setColour (findColour (labelTextColourId));
  59099. g.setFont (11.0f);
  59100. for (int i = 4; --i >= 0;)
  59101. {
  59102. if (sliders[i]->isVisible())
  59103. g.drawText (sliders[i]->getName() + T(":"),
  59104. 0, sliders[i]->getY(),
  59105. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59106. Justification::centredRight, false);
  59107. }
  59108. }
  59109. }
  59110. void ColourSelector::resized()
  59111. {
  59112. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59113. const int numSwatches = getNumSwatches();
  59114. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59115. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59116. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59117. int y = topSpace;
  59118. if ((flags & showColourspace) != 0)
  59119. {
  59120. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59121. colourSpace->setBounds (edgeGap, y,
  59122. getWidth() - hueWidth - edgeGap - 4,
  59123. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59124. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59125. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59126. colourSpace->getHeight());
  59127. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59128. }
  59129. if ((flags & showSliders) != 0)
  59130. {
  59131. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59132. for (int i = 0; i < numSliders; ++i)
  59133. {
  59134. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59135. proportionOfWidth (0.72f), sliderHeight - 2);
  59136. y += sliderHeight;
  59137. }
  59138. }
  59139. if (numSwatches > 0)
  59140. {
  59141. const int startX = 8;
  59142. const int xGap = 4;
  59143. const int yGap = 4;
  59144. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59145. y += edgeGap;
  59146. if (swatchComponents.size() != numSwatches)
  59147. {
  59148. swatchComponents.clear();
  59149. for (int i = 0; i < numSwatches; ++i)
  59150. {
  59151. SwatchComponent* const sc = new SwatchComponent (this, i);
  59152. swatchComponents.add (sc);
  59153. addAndMakeVisible (sc);
  59154. }
  59155. }
  59156. int x = startX;
  59157. for (int i = 0; i < swatchComponents.size(); ++i)
  59158. {
  59159. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59160. sc->setBounds (x + xGap / 2,
  59161. y + yGap / 2,
  59162. swatchWidth - xGap,
  59163. swatchHeight - yGap);
  59164. if (((i + 1) % swatchesPerRow) == 0)
  59165. {
  59166. x = startX;
  59167. y += swatchHeight;
  59168. }
  59169. else
  59170. {
  59171. x += swatchWidth;
  59172. }
  59173. }
  59174. }
  59175. }
  59176. void ColourSelector::sliderValueChanged (Slider*)
  59177. {
  59178. if (sliders[0] != 0)
  59179. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59180. (uint8) sliders[1]->getValue(),
  59181. (uint8) sliders[2]->getValue(),
  59182. (uint8) sliders[3]->getValue()));
  59183. }
  59184. int ColourSelector::getNumSwatches() const
  59185. {
  59186. return 0;
  59187. }
  59188. const Colour ColourSelector::getSwatchColour (const int) const
  59189. {
  59190. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59191. return Colours::black;
  59192. }
  59193. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59194. {
  59195. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59196. }
  59197. END_JUCE_NAMESPACE
  59198. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59199. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59200. BEGIN_JUCE_NAMESPACE
  59201. class ShadowWindow : public Component
  59202. {
  59203. Component* owner;
  59204. Image** shadowImageSections;
  59205. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59206. public:
  59207. ShadowWindow (Component* const owner_,
  59208. const int type_,
  59209. Image** const shadowImageSections_)
  59210. : owner (owner_),
  59211. shadowImageSections (shadowImageSections_),
  59212. type (type_)
  59213. {
  59214. setInterceptsMouseClicks (false, false);
  59215. if (owner_->isOnDesktop())
  59216. {
  59217. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59218. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59219. | ComponentPeer::windowIsTemporary
  59220. | ComponentPeer::windowIgnoresKeyPresses);
  59221. }
  59222. else if (owner_->getParentComponent() != 0)
  59223. {
  59224. owner_->getParentComponent()->addChildComponent (this);
  59225. }
  59226. }
  59227. ~ShadowWindow()
  59228. {
  59229. }
  59230. void paint (Graphics& g)
  59231. {
  59232. Image* const topLeft = shadowImageSections [type * 3];
  59233. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59234. Image* const filler = shadowImageSections [type * 3 + 2];
  59235. g.setOpacity (1.0f);
  59236. if (type < 2)
  59237. {
  59238. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59239. g.drawImage (topLeft,
  59240. 0, 0, topLeft->getWidth(), imH,
  59241. 0, 0, topLeft->getWidth(), imH);
  59242. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59243. g.drawImage (bottomRight,
  59244. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59245. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59246. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59247. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59248. }
  59249. else
  59250. {
  59251. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59252. g.drawImage (topLeft,
  59253. 0, 0, imW, topLeft->getHeight(),
  59254. 0, 0, imW, topLeft->getHeight());
  59255. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59256. g.drawImage (bottomRight,
  59257. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59258. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59259. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59260. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59261. }
  59262. }
  59263. void resized()
  59264. {
  59265. repaint(); // (needed for correct repainting)
  59266. }
  59267. private:
  59268. ShadowWindow (const ShadowWindow&);
  59269. ShadowWindow& operator= (const ShadowWindow&);
  59270. };
  59271. DropShadower::DropShadower (const float alpha_,
  59272. const int xOffset_,
  59273. const int yOffset_,
  59274. const float blurRadius_)
  59275. : owner (0),
  59276. numShadows (0),
  59277. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59278. xOffset (xOffset_),
  59279. yOffset (yOffset_),
  59280. alpha (alpha_),
  59281. blurRadius (blurRadius_),
  59282. inDestructor (false),
  59283. reentrant (false)
  59284. {
  59285. }
  59286. DropShadower::~DropShadower()
  59287. {
  59288. if (owner != 0)
  59289. owner->removeComponentListener (this);
  59290. inDestructor = true;
  59291. deleteShadowWindows();
  59292. }
  59293. void DropShadower::deleteShadowWindows()
  59294. {
  59295. if (numShadows > 0)
  59296. {
  59297. int i;
  59298. for (i = numShadows; --i >= 0;)
  59299. delete shadowWindows[i];
  59300. for (i = 12; --i >= 0;)
  59301. delete shadowImageSections[i];
  59302. numShadows = 0;
  59303. }
  59304. }
  59305. void DropShadower::setOwner (Component* componentToFollow)
  59306. {
  59307. if (componentToFollow != owner)
  59308. {
  59309. if (owner != 0)
  59310. owner->removeComponentListener (this);
  59311. // (the component can't be null)
  59312. jassert (componentToFollow != 0);
  59313. owner = componentToFollow;
  59314. jassert (owner != 0);
  59315. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59316. owner->addComponentListener (this);
  59317. updateShadows();
  59318. }
  59319. }
  59320. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59321. {
  59322. updateShadows();
  59323. }
  59324. void DropShadower::componentBroughtToFront (Component&)
  59325. {
  59326. bringShadowWindowsToFront();
  59327. }
  59328. void DropShadower::componentChildrenChanged (Component&)
  59329. {
  59330. }
  59331. void DropShadower::componentParentHierarchyChanged (Component&)
  59332. {
  59333. deleteShadowWindows();
  59334. updateShadows();
  59335. }
  59336. void DropShadower::componentVisibilityChanged (Component&)
  59337. {
  59338. updateShadows();
  59339. }
  59340. void DropShadower::updateShadows()
  59341. {
  59342. if (reentrant || inDestructor || (owner == 0))
  59343. return;
  59344. reentrant = true;
  59345. ComponentPeer* const nw = owner->getPeer();
  59346. const bool isOwnerVisible = owner->isVisible()
  59347. && (nw == 0 || ! nw->isMinimised());
  59348. const bool createShadowWindows = numShadows == 0
  59349. && owner->getWidth() > 0
  59350. && owner->getHeight() > 0
  59351. && isOwnerVisible
  59352. && (Desktop::canUseSemiTransparentWindows()
  59353. || owner->getParentComponent() != 0);
  59354. if (createShadowWindows)
  59355. {
  59356. // keep a cached version of the image to save doing the gaussian too often
  59357. String imageId;
  59358. imageId << shadowEdge << T(',')
  59359. << xOffset << T(',')
  59360. << yOffset << T(',')
  59361. << alpha;
  59362. const int hash = imageId.hashCode();
  59363. Image* bigIm = ImageCache::getFromHashCode (hash);
  59364. if (bigIm == 0)
  59365. {
  59366. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59367. Graphics bigG (*bigIm);
  59368. bigG.setColour (Colours::black.withAlpha (alpha));
  59369. bigG.fillRect (shadowEdge + xOffset,
  59370. shadowEdge + yOffset,
  59371. bigIm->getWidth() - (shadowEdge * 2),
  59372. bigIm->getHeight() - (shadowEdge * 2));
  59373. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59374. blurKernel.createGaussianBlur (blurRadius);
  59375. blurKernel.applyToImage (*bigIm, 0,
  59376. xOffset,
  59377. yOffset,
  59378. bigIm->getWidth(),
  59379. bigIm->getHeight());
  59380. ImageCache::addImageToCache (bigIm, hash);
  59381. }
  59382. const int iw = bigIm->getWidth();
  59383. const int ih = bigIm->getHeight();
  59384. const int shadowEdge2 = shadowEdge * 2;
  59385. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59386. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59387. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59388. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59389. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59390. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59391. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59392. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59393. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59394. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59395. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59396. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59397. ImageCache::release (bigIm);
  59398. for (int i = 0; i < 4; ++i)
  59399. {
  59400. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59401. ++numShadows;
  59402. }
  59403. }
  59404. if (numShadows > 0)
  59405. {
  59406. for (int i = numShadows; --i >= 0;)
  59407. {
  59408. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59409. shadowWindows[i]->setVisible (isOwnerVisible);
  59410. }
  59411. const int x = owner->getX();
  59412. const int y = owner->getY() - shadowEdge;
  59413. const int w = owner->getWidth();
  59414. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59415. shadowWindows[0]->setBounds (x - shadowEdge,
  59416. y,
  59417. shadowEdge,
  59418. h);
  59419. shadowWindows[1]->setBounds (x + w,
  59420. y,
  59421. shadowEdge,
  59422. h);
  59423. shadowWindows[2]->setBounds (x,
  59424. y,
  59425. w,
  59426. shadowEdge);
  59427. shadowWindows[3]->setBounds (x,
  59428. owner->getBottom(),
  59429. w,
  59430. shadowEdge);
  59431. }
  59432. reentrant = false;
  59433. if (createShadowWindows)
  59434. bringShadowWindowsToFront();
  59435. }
  59436. void DropShadower::setShadowImage (Image* const src,
  59437. const int num,
  59438. const int w,
  59439. const int h,
  59440. const int sx,
  59441. const int sy)
  59442. {
  59443. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59444. Graphics g (*shadowImageSections[num]);
  59445. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59446. }
  59447. void DropShadower::bringShadowWindowsToFront()
  59448. {
  59449. if (! (inDestructor || reentrant))
  59450. {
  59451. updateShadows();
  59452. reentrant = true;
  59453. for (int i = numShadows; --i >= 0;)
  59454. shadowWindows[i]->toBehind (owner);
  59455. reentrant = false;
  59456. }
  59457. }
  59458. END_JUCE_NAMESPACE
  59459. /*** End of inlined file: juce_DropShadower.cpp ***/
  59460. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59461. BEGIN_JUCE_NAMESPACE
  59462. class MagnifyingPeer : public ComponentPeer
  59463. {
  59464. public:
  59465. MagnifyingPeer (Component* const component_,
  59466. MagnifierComponent* const magnifierComp_)
  59467. : ComponentPeer (component_, 0),
  59468. magnifierComp (magnifierComp_)
  59469. {
  59470. }
  59471. ~MagnifyingPeer()
  59472. {
  59473. }
  59474. void* getNativeHandle() const { return 0; }
  59475. void setVisible (bool) {}
  59476. void setTitle (const String&) {}
  59477. void setPosition (int, int) {}
  59478. void setSize (int, int) {}
  59479. void setBounds (int, int, int, int, const bool) {}
  59480. void setMinimised (bool) {}
  59481. bool isMinimised() const { return false; }
  59482. void setFullScreen (bool) {}
  59483. bool isFullScreen() const { return false; }
  59484. const BorderSize getFrameSize() const { return BorderSize (0); }
  59485. bool setAlwaysOnTop (bool) { return true; }
  59486. void toFront (bool) {}
  59487. void toBehind (ComponentPeer*) {}
  59488. void setIcon (const Image&) {}
  59489. bool isFocused() const
  59490. {
  59491. return magnifierComp->hasKeyboardFocus (true);
  59492. }
  59493. void grabFocus()
  59494. {
  59495. ComponentPeer* peer = magnifierComp->getPeer();
  59496. if (peer != 0)
  59497. peer->grabFocus();
  59498. }
  59499. void textInputRequired (const Point<int>& position)
  59500. {
  59501. ComponentPeer* peer = magnifierComp->getPeer();
  59502. if (peer != 0)
  59503. peer->textInputRequired (position);
  59504. }
  59505. const Rectangle<int> getBounds() const
  59506. {
  59507. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59508. component->getWidth(), component->getHeight());
  59509. }
  59510. const Point<int> getScreenPosition() const
  59511. {
  59512. return magnifierComp->getScreenPosition();
  59513. }
  59514. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59515. {
  59516. const double zoom = magnifierComp->getScaleFactor();
  59517. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59518. roundToInt (relativePosition.getY() * zoom)));
  59519. }
  59520. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59521. {
  59522. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59523. const double zoom = magnifierComp->getScaleFactor();
  59524. return Point<int> (roundToInt (p.getX() / zoom),
  59525. roundToInt (p.getY() / zoom));
  59526. }
  59527. bool contains (const Point<int>& position, bool) const
  59528. {
  59529. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59530. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59531. }
  59532. void repaint (int x, int y, int w, int h)
  59533. {
  59534. const double zoom = magnifierComp->getScaleFactor();
  59535. magnifierComp->repaint ((int) (x * zoom),
  59536. (int) (y * zoom),
  59537. roundToInt (w * zoom) + 1,
  59538. roundToInt (h * zoom) + 1);
  59539. }
  59540. void performAnyPendingRepaintsNow()
  59541. {
  59542. }
  59543. juce_UseDebuggingNewOperator
  59544. private:
  59545. MagnifierComponent* const magnifierComp;
  59546. MagnifyingPeer (const MagnifyingPeer&);
  59547. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59548. };
  59549. class PeerHolderComp : public Component
  59550. {
  59551. public:
  59552. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59553. : magnifierComp (magnifierComp_)
  59554. {
  59555. setVisible (true);
  59556. }
  59557. ~PeerHolderComp()
  59558. {
  59559. }
  59560. ComponentPeer* createNewPeer (int, void*)
  59561. {
  59562. return new MagnifyingPeer (this, magnifierComp);
  59563. }
  59564. void childBoundsChanged (Component* c)
  59565. {
  59566. if (c != 0)
  59567. {
  59568. setSize (c->getWidth(), c->getHeight());
  59569. magnifierComp->childBoundsChanged (this);
  59570. }
  59571. }
  59572. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59573. {
  59574. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59575. Component* const p = magnifierComp->getParentComponent();
  59576. if (p != 0)
  59577. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59578. }
  59579. private:
  59580. MagnifierComponent* const magnifierComp;
  59581. PeerHolderComp (const PeerHolderComp&);
  59582. PeerHolderComp& operator= (const PeerHolderComp&);
  59583. };
  59584. MagnifierComponent::MagnifierComponent (Component* const content_,
  59585. const bool deleteContentCompWhenNoLongerNeeded)
  59586. : content (content_),
  59587. scaleFactor (0.0),
  59588. peer (0),
  59589. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59590. quality (Graphics::lowResamplingQuality),
  59591. mouseSource (0, true)
  59592. {
  59593. holderComp = new PeerHolderComp (this);
  59594. setScaleFactor (1.0);
  59595. }
  59596. MagnifierComponent::~MagnifierComponent()
  59597. {
  59598. delete holderComp;
  59599. if (deleteContent)
  59600. delete content;
  59601. }
  59602. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59603. {
  59604. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59605. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59606. if (scaleFactor != newScaleFactor)
  59607. {
  59608. scaleFactor = newScaleFactor;
  59609. if (scaleFactor == 1.0)
  59610. {
  59611. holderComp->removeFromDesktop();
  59612. peer = 0;
  59613. addChildComponent (content);
  59614. childBoundsChanged (content);
  59615. }
  59616. else
  59617. {
  59618. holderComp->addAndMakeVisible (content);
  59619. holderComp->childBoundsChanged (content);
  59620. childBoundsChanged (holderComp);
  59621. holderComp->addToDesktop (0);
  59622. peer = holderComp->getPeer();
  59623. }
  59624. repaint();
  59625. }
  59626. }
  59627. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59628. {
  59629. quality = newQuality;
  59630. }
  59631. void MagnifierComponent::paint (Graphics& g)
  59632. {
  59633. const int w = holderComp->getWidth();
  59634. const int h = holderComp->getHeight();
  59635. if (w == 0 || h == 0)
  59636. return;
  59637. const Rectangle<int> r (g.getClipBounds());
  59638. const int srcX = (int) (r.getX() / scaleFactor);
  59639. const int srcY = (int) (r.getY() / scaleFactor);
  59640. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59641. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59642. if (scaleFactor >= 1.0)
  59643. {
  59644. ++srcW;
  59645. ++srcH;
  59646. }
  59647. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59648. temp.clear (srcX, srcY, srcW, srcH);
  59649. {
  59650. Graphics g2 (temp);
  59651. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59652. holderComp->paintEntireComponent (g2);
  59653. }
  59654. g.setImageResamplingQuality (quality);
  59655. g.drawImageTransformed (&temp, temp.getBounds(),
  59656. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59657. false);
  59658. }
  59659. void MagnifierComponent::childBoundsChanged (Component* c)
  59660. {
  59661. if (c != 0)
  59662. setSize (roundToInt (c->getWidth() * scaleFactor),
  59663. roundToInt (c->getHeight() * scaleFactor));
  59664. }
  59665. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59666. {
  59667. if (peer != 0)
  59668. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59669. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59670. }
  59671. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59672. {
  59673. passOnMouseEventToPeer (e);
  59674. }
  59675. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59676. {
  59677. passOnMouseEventToPeer (e);
  59678. }
  59679. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59680. {
  59681. passOnMouseEventToPeer (e);
  59682. }
  59683. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59684. {
  59685. passOnMouseEventToPeer (e);
  59686. }
  59687. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59688. {
  59689. passOnMouseEventToPeer (e);
  59690. }
  59691. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59692. {
  59693. passOnMouseEventToPeer (e);
  59694. }
  59695. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59696. {
  59697. if (peer != 0)
  59698. peer->handleMouseWheel (e.source.getIndex(),
  59699. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59700. ix * 256.0f, iy * 256.0f);
  59701. else
  59702. Component::mouseWheelMove (e, ix, iy);
  59703. }
  59704. int MagnifierComponent::scaleInt (const int n) const
  59705. {
  59706. return roundToInt (n / scaleFactor);
  59707. }
  59708. END_JUCE_NAMESPACE
  59709. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59710. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59711. BEGIN_JUCE_NAMESPACE
  59712. class MidiKeyboardUpDownButton : public Button
  59713. {
  59714. public:
  59715. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59716. const int delta_)
  59717. : Button (String::empty),
  59718. owner (owner_),
  59719. delta (delta_)
  59720. {
  59721. setOpaque (true);
  59722. }
  59723. ~MidiKeyboardUpDownButton()
  59724. {
  59725. }
  59726. void clicked()
  59727. {
  59728. int note = owner->getLowestVisibleKey();
  59729. if (delta < 0)
  59730. note = (note - 1) / 12;
  59731. else
  59732. note = note / 12 + 1;
  59733. owner->setLowestVisibleKey (note * 12);
  59734. }
  59735. void paintButton (Graphics& g,
  59736. bool isMouseOverButton,
  59737. bool isButtonDown)
  59738. {
  59739. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59740. isMouseOverButton, isButtonDown,
  59741. delta > 0);
  59742. }
  59743. private:
  59744. MidiKeyboardComponent* const owner;
  59745. const int delta;
  59746. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59747. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59748. };
  59749. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59750. const Orientation orientation_)
  59751. : state (state_),
  59752. xOffset (0),
  59753. blackNoteLength (1),
  59754. keyWidth (16.0f),
  59755. orientation (orientation_),
  59756. midiChannel (1),
  59757. midiInChannelMask (0xffff),
  59758. velocity (1.0f),
  59759. noteUnderMouse (-1),
  59760. mouseDownNote (-1),
  59761. rangeStart (0),
  59762. rangeEnd (127),
  59763. firstKey (12 * 4),
  59764. canScroll (true),
  59765. mouseDragging (false),
  59766. useMousePositionForVelocity (true),
  59767. keyMappingOctave (6),
  59768. octaveNumForMiddleC (3)
  59769. {
  59770. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59771. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59772. // initialise with a default set of querty key-mappings..
  59773. const char* const keymap = "awsedftgyhujkolp;";
  59774. for (int i = String (keymap).length(); --i >= 0;)
  59775. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59776. setOpaque (true);
  59777. setWantsKeyboardFocus (true);
  59778. state.addListener (this);
  59779. }
  59780. MidiKeyboardComponent::~MidiKeyboardComponent()
  59781. {
  59782. state.removeListener (this);
  59783. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59784. deleteAllChildren();
  59785. }
  59786. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59787. {
  59788. keyWidth = widthInPixels;
  59789. resized();
  59790. }
  59791. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59792. {
  59793. if (orientation != newOrientation)
  59794. {
  59795. orientation = newOrientation;
  59796. resized();
  59797. }
  59798. }
  59799. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59800. const int highestNote)
  59801. {
  59802. jassert (lowestNote >= 0 && lowestNote <= 127);
  59803. jassert (highestNote >= 0 && highestNote <= 127);
  59804. jassert (lowestNote <= highestNote);
  59805. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59806. {
  59807. rangeStart = jlimit (0, 127, lowestNote);
  59808. rangeEnd = jlimit (0, 127, highestNote);
  59809. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59810. resized();
  59811. }
  59812. }
  59813. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59814. {
  59815. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59816. if (noteNumber != firstKey)
  59817. {
  59818. firstKey = noteNumber;
  59819. sendChangeMessage (this);
  59820. resized();
  59821. }
  59822. }
  59823. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59824. {
  59825. if (canScroll != canScroll_)
  59826. {
  59827. canScroll = canScroll_;
  59828. resized();
  59829. }
  59830. }
  59831. void MidiKeyboardComponent::colourChanged()
  59832. {
  59833. repaint();
  59834. }
  59835. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59836. {
  59837. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59838. if (midiChannel != midiChannelNumber)
  59839. {
  59840. resetAnyKeysInUse();
  59841. midiChannel = jlimit (1, 16, midiChannelNumber);
  59842. }
  59843. }
  59844. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59845. {
  59846. midiInChannelMask = midiChannelMask;
  59847. triggerAsyncUpdate();
  59848. }
  59849. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59850. {
  59851. velocity = jlimit (0.0f, 1.0f, velocity_);
  59852. useMousePositionForVelocity = useMousePositionForVelocity_;
  59853. }
  59854. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59855. {
  59856. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59857. static const float blackNoteWidth = 0.7f;
  59858. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59859. 1.0f, 2 - blackNoteWidth * 0.4f,
  59860. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59861. 4.0f, 5 - blackNoteWidth * 0.5f,
  59862. 5.0f, 6 - blackNoteWidth * 0.3f,
  59863. 6.0f };
  59864. static const float widths[] = { 1.0f, blackNoteWidth,
  59865. 1.0f, blackNoteWidth,
  59866. 1.0f, 1.0f, blackNoteWidth,
  59867. 1.0f, blackNoteWidth,
  59868. 1.0f, blackNoteWidth,
  59869. 1.0f };
  59870. const int octave = midiNoteNumber / 12;
  59871. const int note = midiNoteNumber % 12;
  59872. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59873. w = roundToInt (widths [note] * keyWidth);
  59874. }
  59875. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59876. {
  59877. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59878. int rx, rw;
  59879. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59880. x -= xOffset + rx;
  59881. }
  59882. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59883. {
  59884. int x, y;
  59885. getKeyPos (midiNoteNumber, x, y);
  59886. return x;
  59887. }
  59888. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59889. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59890. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59891. {
  59892. if (! reallyContains (pos.getX(), pos.getY(), false))
  59893. return -1;
  59894. Point<int> p (pos);
  59895. if (orientation != horizontalKeyboard)
  59896. {
  59897. p = Point<int> (p.getY(), p.getX());
  59898. if (orientation == verticalKeyboardFacingLeft)
  59899. p = Point<int> (p.getX(), getWidth() - p.getY());
  59900. else
  59901. p = Point<int> (getHeight() - p.getX(), p.getY());
  59902. }
  59903. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59904. }
  59905. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59906. {
  59907. if (pos.getY() < blackNoteLength)
  59908. {
  59909. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59910. {
  59911. for (int i = 0; i < 5; ++i)
  59912. {
  59913. const int note = octaveStart + blackNotes [i];
  59914. if (note >= rangeStart && note <= rangeEnd)
  59915. {
  59916. int kx, kw;
  59917. getKeyPos (note, kx, kw);
  59918. kx += xOffset;
  59919. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59920. {
  59921. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  59922. return note;
  59923. }
  59924. }
  59925. }
  59926. }
  59927. }
  59928. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59929. {
  59930. for (int i = 0; i < 7; ++i)
  59931. {
  59932. const int note = octaveStart + whiteNotes [i];
  59933. if (note >= rangeStart && note <= rangeEnd)
  59934. {
  59935. int kx, kw;
  59936. getKeyPos (note, kx, kw);
  59937. kx += xOffset;
  59938. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59939. {
  59940. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  59941. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  59942. return note;
  59943. }
  59944. }
  59945. }
  59946. }
  59947. mousePositionVelocity = 0;
  59948. return -1;
  59949. }
  59950. void MidiKeyboardComponent::repaintNote (const int noteNum)
  59951. {
  59952. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59953. {
  59954. int x, w;
  59955. getKeyPos (noteNum, x, w);
  59956. if (orientation == horizontalKeyboard)
  59957. repaint (x, 0, w, getHeight());
  59958. else if (orientation == verticalKeyboardFacingLeft)
  59959. repaint (0, x, getWidth(), w);
  59960. else if (orientation == verticalKeyboardFacingRight)
  59961. repaint (0, getHeight() - x - w, getWidth(), w);
  59962. }
  59963. }
  59964. void MidiKeyboardComponent::paint (Graphics& g)
  59965. {
  59966. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  59967. const Colour lineColour (findColour (keySeparatorLineColourId));
  59968. const Colour textColour (findColour (textLabelColourId));
  59969. int x, w, octave;
  59970. for (octave = 0; octave < 128; octave += 12)
  59971. {
  59972. for (int white = 0; white < 7; ++white)
  59973. {
  59974. const int noteNum = octave + whiteNotes [white];
  59975. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59976. {
  59977. getKeyPos (noteNum, x, w);
  59978. if (orientation == horizontalKeyboard)
  59979. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  59980. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59981. noteUnderMouse == noteNum,
  59982. lineColour, textColour);
  59983. else if (orientation == verticalKeyboardFacingLeft)
  59984. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  59985. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59986. noteUnderMouse == noteNum,
  59987. lineColour, textColour);
  59988. else if (orientation == verticalKeyboardFacingRight)
  59989. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  59990. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59991. noteUnderMouse == noteNum,
  59992. lineColour, textColour);
  59993. }
  59994. }
  59995. }
  59996. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  59997. if (orientation == verticalKeyboardFacingLeft)
  59998. {
  59999. x1 = getWidth() - 1.0f;
  60000. x2 = getWidth() - 5.0f;
  60001. }
  60002. else if (orientation == verticalKeyboardFacingRight)
  60003. x2 = 5.0f;
  60004. else
  60005. y2 = 5.0f;
  60006. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  60007. Colours::transparentBlack, x2, y2, false));
  60008. getKeyPos (rangeEnd, x, w);
  60009. x += w;
  60010. if (orientation == verticalKeyboardFacingLeft)
  60011. g.fillRect (getWidth() - 5, 0, 5, x);
  60012. else if (orientation == verticalKeyboardFacingRight)
  60013. g.fillRect (0, 0, 5, x);
  60014. else
  60015. g.fillRect (0, 0, x, 5);
  60016. g.setColour (lineColour);
  60017. if (orientation == verticalKeyboardFacingLeft)
  60018. g.fillRect (0, 0, 1, x);
  60019. else if (orientation == verticalKeyboardFacingRight)
  60020. g.fillRect (getWidth() - 1, 0, 1, x);
  60021. else
  60022. g.fillRect (0, getHeight() - 1, x, 1);
  60023. const Colour blackNoteColour (findColour (blackNoteColourId));
  60024. for (octave = 0; octave < 128; octave += 12)
  60025. {
  60026. for (int black = 0; black < 5; ++black)
  60027. {
  60028. const int noteNum = octave + blackNotes [black];
  60029. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60030. {
  60031. getKeyPos (noteNum, x, w);
  60032. if (orientation == horizontalKeyboard)
  60033. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  60034. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60035. noteUnderMouse == noteNum,
  60036. blackNoteColour);
  60037. else if (orientation == verticalKeyboardFacingLeft)
  60038. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  60039. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60040. noteUnderMouse == noteNum,
  60041. blackNoteColour);
  60042. else if (orientation == verticalKeyboardFacingRight)
  60043. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  60044. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60045. noteUnderMouse == noteNum,
  60046. blackNoteColour);
  60047. }
  60048. }
  60049. }
  60050. }
  60051. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  60052. Graphics& g, int x, int y, int w, int h,
  60053. bool isDown, bool isOver,
  60054. const Colour& lineColour,
  60055. const Colour& textColour)
  60056. {
  60057. Colour c (Colours::transparentWhite);
  60058. if (isDown)
  60059. c = findColour (keyDownOverlayColourId);
  60060. if (isOver)
  60061. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60062. g.setColour (c);
  60063. g.fillRect (x, y, w, h);
  60064. const String text (getWhiteNoteText (midiNoteNumber));
  60065. if (! text.isEmpty())
  60066. {
  60067. g.setColour (textColour);
  60068. Font f (jmin (12.0f, keyWidth * 0.9f));
  60069. f.setHorizontalScale (0.8f);
  60070. g.setFont (f);
  60071. Justification justification (Justification::centredBottom);
  60072. if (orientation == verticalKeyboardFacingLeft)
  60073. justification = Justification::centredLeft;
  60074. else if (orientation == verticalKeyboardFacingRight)
  60075. justification = Justification::centredRight;
  60076. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60077. }
  60078. g.setColour (lineColour);
  60079. if (orientation == horizontalKeyboard)
  60080. g.fillRect (x, y, 1, h);
  60081. else if (orientation == verticalKeyboardFacingLeft)
  60082. g.fillRect (x, y, w, 1);
  60083. else if (orientation == verticalKeyboardFacingRight)
  60084. g.fillRect (x, y + h - 1, w, 1);
  60085. if (midiNoteNumber == rangeEnd)
  60086. {
  60087. if (orientation == horizontalKeyboard)
  60088. g.fillRect (x + w, y, 1, h);
  60089. else if (orientation == verticalKeyboardFacingLeft)
  60090. g.fillRect (x, y + h, w, 1);
  60091. else if (orientation == verticalKeyboardFacingRight)
  60092. g.fillRect (x, y - 1, w, 1);
  60093. }
  60094. }
  60095. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60096. Graphics& g, int x, int y, int w, int h,
  60097. bool isDown, bool isOver,
  60098. const Colour& noteFillColour)
  60099. {
  60100. Colour c (noteFillColour);
  60101. if (isDown)
  60102. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60103. if (isOver)
  60104. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60105. g.setColour (c);
  60106. g.fillRect (x, y, w, h);
  60107. if (isDown)
  60108. {
  60109. g.setColour (noteFillColour);
  60110. g.drawRect (x, y, w, h);
  60111. }
  60112. else
  60113. {
  60114. const int xIndent = jmax (1, jmin (w, h) / 8);
  60115. g.setColour (c.brighter());
  60116. if (orientation == horizontalKeyboard)
  60117. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60118. else if (orientation == verticalKeyboardFacingLeft)
  60119. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60120. else if (orientation == verticalKeyboardFacingRight)
  60121. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60122. }
  60123. }
  60124. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60125. {
  60126. octaveNumForMiddleC = octaveNumForMiddleC_;
  60127. repaint();
  60128. }
  60129. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60130. {
  60131. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60132. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60133. return String::empty;
  60134. }
  60135. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60136. const bool isMouseOver,
  60137. const bool isButtonDown,
  60138. const bool movesOctavesUp)
  60139. {
  60140. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60141. float angle;
  60142. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60143. angle = movesOctavesUp ? 0.0f : 0.5f;
  60144. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60145. angle = movesOctavesUp ? 0.25f : 0.75f;
  60146. else
  60147. angle = movesOctavesUp ? 0.75f : 0.25f;
  60148. Path path;
  60149. path.lineTo (0.0f, 1.0f);
  60150. path.lineTo (1.0f, 0.5f);
  60151. path.closeSubPath();
  60152. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60153. g.setColour (findColour (upDownButtonArrowColourId)
  60154. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60155. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60156. w - 2.0f,
  60157. h - 2.0f,
  60158. true));
  60159. }
  60160. void MidiKeyboardComponent::resized()
  60161. {
  60162. int w = getWidth();
  60163. int h = getHeight();
  60164. if (w > 0 && h > 0)
  60165. {
  60166. if (orientation != horizontalKeyboard)
  60167. swapVariables (w, h);
  60168. blackNoteLength = roundToInt (h * 0.7f);
  60169. int kx2, kw2;
  60170. getKeyPos (rangeEnd, kx2, kw2);
  60171. kx2 += kw2;
  60172. if (firstKey != rangeStart)
  60173. {
  60174. int kx1, kw1;
  60175. getKeyPos (rangeStart, kx1, kw1);
  60176. if (kx2 - kx1 <= w)
  60177. {
  60178. firstKey = rangeStart;
  60179. sendChangeMessage (this);
  60180. repaint();
  60181. }
  60182. }
  60183. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60184. scrollDown->setVisible (showScrollButtons);
  60185. scrollUp->setVisible (showScrollButtons);
  60186. xOffset = 0;
  60187. if (showScrollButtons)
  60188. {
  60189. const int scrollButtonW = jmin (12, w / 2);
  60190. if (orientation == horizontalKeyboard)
  60191. {
  60192. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60193. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60194. }
  60195. else if (orientation == verticalKeyboardFacingLeft)
  60196. {
  60197. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60198. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60199. }
  60200. else if (orientation == verticalKeyboardFacingRight)
  60201. {
  60202. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60203. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60204. }
  60205. int endOfLastKey, kw;
  60206. getKeyPos (rangeEnd, endOfLastKey, kw);
  60207. endOfLastKey += kw;
  60208. float mousePositionVelocity;
  60209. const int spaceAvailable = w - scrollButtonW * 2;
  60210. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60211. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60212. {
  60213. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60214. sendChangeMessage (this);
  60215. }
  60216. int newOffset = 0;
  60217. getKeyPos (firstKey, newOffset, kw);
  60218. xOffset = newOffset - scrollButtonW;
  60219. }
  60220. else
  60221. {
  60222. firstKey = rangeStart;
  60223. }
  60224. timerCallback();
  60225. repaint();
  60226. }
  60227. }
  60228. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60229. {
  60230. triggerAsyncUpdate();
  60231. }
  60232. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60233. {
  60234. triggerAsyncUpdate();
  60235. }
  60236. void MidiKeyboardComponent::handleAsyncUpdate()
  60237. {
  60238. for (int i = rangeStart; i <= rangeEnd; ++i)
  60239. {
  60240. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60241. {
  60242. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60243. repaintNote (i);
  60244. }
  60245. }
  60246. }
  60247. void MidiKeyboardComponent::resetAnyKeysInUse()
  60248. {
  60249. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60250. {
  60251. state.allNotesOff (midiChannel);
  60252. keysPressed.clear();
  60253. mouseDownNote = -1;
  60254. }
  60255. }
  60256. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60257. {
  60258. float mousePositionVelocity = 0.0f;
  60259. const int newNote = (mouseDragging || isMouseOver())
  60260. ? xyToNote (pos, mousePositionVelocity) : -1;
  60261. if (noteUnderMouse != newNote)
  60262. {
  60263. if (mouseDownNote >= 0)
  60264. {
  60265. state.noteOff (midiChannel, mouseDownNote);
  60266. mouseDownNote = -1;
  60267. }
  60268. if (mouseDragging && newNote >= 0)
  60269. {
  60270. if (! useMousePositionForVelocity)
  60271. mousePositionVelocity = 1.0f;
  60272. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60273. mouseDownNote = newNote;
  60274. }
  60275. repaintNote (noteUnderMouse);
  60276. noteUnderMouse = newNote;
  60277. repaintNote (noteUnderMouse);
  60278. }
  60279. else if (mouseDownNote >= 0 && ! mouseDragging)
  60280. {
  60281. state.noteOff (midiChannel, mouseDownNote);
  60282. mouseDownNote = -1;
  60283. }
  60284. }
  60285. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60286. {
  60287. updateNoteUnderMouse (e.getPosition());
  60288. stopTimer();
  60289. }
  60290. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60291. {
  60292. float mousePositionVelocity;
  60293. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60294. if (newNote >= 0)
  60295. mouseDraggedToKey (newNote, e);
  60296. updateNoteUnderMouse (e.getPosition());
  60297. }
  60298. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60299. {
  60300. return true;
  60301. }
  60302. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60303. {
  60304. }
  60305. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60306. {
  60307. float mousePositionVelocity;
  60308. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60309. mouseDragging = false;
  60310. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60311. {
  60312. repaintNote (noteUnderMouse);
  60313. noteUnderMouse = -1;
  60314. mouseDragging = true;
  60315. updateNoteUnderMouse (e.getPosition());
  60316. startTimer (500);
  60317. }
  60318. }
  60319. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60320. {
  60321. mouseDragging = false;
  60322. updateNoteUnderMouse (e.getPosition());
  60323. stopTimer();
  60324. }
  60325. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60326. {
  60327. updateNoteUnderMouse (e.getPosition());
  60328. }
  60329. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60330. {
  60331. updateNoteUnderMouse (e.getPosition());
  60332. }
  60333. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60334. {
  60335. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60336. }
  60337. void MidiKeyboardComponent::timerCallback()
  60338. {
  60339. updateNoteUnderMouse (getMouseXYRelative());
  60340. }
  60341. void MidiKeyboardComponent::clearKeyMappings()
  60342. {
  60343. resetAnyKeysInUse();
  60344. keyPressNotes.clear();
  60345. keyPresses.clear();
  60346. }
  60347. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60348. const int midiNoteOffsetFromC)
  60349. {
  60350. removeKeyPressForNote (midiNoteOffsetFromC);
  60351. keyPressNotes.add (midiNoteOffsetFromC);
  60352. keyPresses.add (key);
  60353. }
  60354. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60355. {
  60356. for (int i = keyPressNotes.size(); --i >= 0;)
  60357. {
  60358. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60359. {
  60360. keyPressNotes.remove (i);
  60361. keyPresses.remove (i);
  60362. }
  60363. }
  60364. }
  60365. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60366. {
  60367. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60368. keyMappingOctave = newOctaveNumber;
  60369. }
  60370. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60371. {
  60372. bool keyPressUsed = false;
  60373. for (int i = keyPresses.size(); --i >= 0;)
  60374. {
  60375. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60376. if (keyPresses.getReference(i).isCurrentlyDown())
  60377. {
  60378. if (! keysPressed [note])
  60379. {
  60380. keysPressed.setBit (note);
  60381. state.noteOn (midiChannel, note, velocity);
  60382. keyPressUsed = true;
  60383. }
  60384. }
  60385. else
  60386. {
  60387. if (keysPressed [note])
  60388. {
  60389. keysPressed.clearBit (note);
  60390. state.noteOff (midiChannel, note);
  60391. keyPressUsed = true;
  60392. }
  60393. }
  60394. }
  60395. return keyPressUsed;
  60396. }
  60397. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60398. {
  60399. resetAnyKeysInUse();
  60400. }
  60401. END_JUCE_NAMESPACE
  60402. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60403. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60404. #if JUCE_OPENGL
  60405. BEGIN_JUCE_NAMESPACE
  60406. extern void juce_glViewport (const int w, const int h);
  60407. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60408. const int alphaBits_,
  60409. const int depthBufferBits_,
  60410. const int stencilBufferBits_) throw()
  60411. : redBits (bitsPerRGBComponent),
  60412. greenBits (bitsPerRGBComponent),
  60413. blueBits (bitsPerRGBComponent),
  60414. alphaBits (alphaBits_),
  60415. depthBufferBits (depthBufferBits_),
  60416. stencilBufferBits (stencilBufferBits_),
  60417. accumulationBufferRedBits (0),
  60418. accumulationBufferGreenBits (0),
  60419. accumulationBufferBlueBits (0),
  60420. accumulationBufferAlphaBits (0),
  60421. fullSceneAntiAliasingNumSamples (0)
  60422. {
  60423. }
  60424. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const throw()
  60425. {
  60426. return memcmp (this, &other, sizeof (other)) == 0;
  60427. }
  60428. static VoidArray knownContexts;
  60429. OpenGLContext::OpenGLContext() throw()
  60430. {
  60431. knownContexts.add (this);
  60432. }
  60433. OpenGLContext::~OpenGLContext()
  60434. {
  60435. knownContexts.removeValue (this);
  60436. }
  60437. OpenGLContext* OpenGLContext::getCurrentContext()
  60438. {
  60439. for (int i = knownContexts.size(); --i >= 0;)
  60440. {
  60441. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60442. if (oglc->isActive())
  60443. return oglc;
  60444. }
  60445. return 0;
  60446. }
  60447. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60448. {
  60449. public:
  60450. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60451. : ComponentMovementWatcher (owner_),
  60452. owner (owner_),
  60453. wasShowing (false)
  60454. {
  60455. }
  60456. ~OpenGLComponentWatcher() {}
  60457. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60458. {
  60459. owner->updateContextPosition();
  60460. }
  60461. void componentPeerChanged()
  60462. {
  60463. const ScopedLock sl (owner->getContextLock());
  60464. owner->deleteContext();
  60465. }
  60466. void componentVisibilityChanged (Component&)
  60467. {
  60468. const bool isShowingNow = owner->isShowing();
  60469. if (wasShowing != isShowingNow)
  60470. {
  60471. wasShowing = isShowingNow;
  60472. owner->updateContextPosition();
  60473. }
  60474. }
  60475. juce_UseDebuggingNewOperator
  60476. private:
  60477. OpenGLComponent* const owner;
  60478. bool wasShowing;
  60479. };
  60480. OpenGLComponent::OpenGLComponent()
  60481. : context (0),
  60482. contextToShareListsWith (0),
  60483. needToUpdateViewport (true)
  60484. {
  60485. setOpaque (true);
  60486. componentWatcher = new OpenGLComponentWatcher (this);
  60487. }
  60488. OpenGLComponent::~OpenGLComponent()
  60489. {
  60490. deleteContext();
  60491. componentWatcher = 0;
  60492. }
  60493. void OpenGLComponent::deleteContext()
  60494. {
  60495. const ScopedLock sl (contextLock);
  60496. deleteAndZero (context);
  60497. }
  60498. void OpenGLComponent::updateContextPosition()
  60499. {
  60500. needToUpdateViewport = true;
  60501. if (getWidth() > 0 && getHeight() > 0)
  60502. {
  60503. Component* const topComp = getTopLevelComponent();
  60504. if (topComp->getPeer() != 0)
  60505. {
  60506. const ScopedLock sl (contextLock);
  60507. if (context != 0)
  60508. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60509. getScreenY() - topComp->getScreenY(),
  60510. getWidth(),
  60511. getHeight(),
  60512. topComp->getHeight());
  60513. }
  60514. }
  60515. }
  60516. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60517. {
  60518. OpenGLPixelFormat pf;
  60519. const ScopedLock sl (contextLock);
  60520. if (context != 0)
  60521. pf = context->getPixelFormat();
  60522. return pf;
  60523. }
  60524. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60525. {
  60526. if (! (preferredPixelFormat == formatToUse))
  60527. {
  60528. const ScopedLock sl (contextLock);
  60529. deleteContext();
  60530. preferredPixelFormat = formatToUse;
  60531. }
  60532. }
  60533. void OpenGLComponent::shareWith (OpenGLContext* c)
  60534. {
  60535. if (contextToShareListsWith != c)
  60536. {
  60537. const ScopedLock sl (contextLock);
  60538. deleteContext();
  60539. contextToShareListsWith = c;
  60540. }
  60541. }
  60542. bool OpenGLComponent::makeCurrentContextActive()
  60543. {
  60544. if (context == 0)
  60545. {
  60546. const ScopedLock sl (contextLock);
  60547. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60548. {
  60549. context = OpenGLContext::createContextForWindow (this,
  60550. preferredPixelFormat,
  60551. contextToShareListsWith);
  60552. if (context != 0)
  60553. {
  60554. updateContextPosition();
  60555. if (context->makeActive())
  60556. newOpenGLContextCreated();
  60557. }
  60558. }
  60559. }
  60560. return context != 0 && context->makeActive();
  60561. }
  60562. void OpenGLComponent::makeCurrentContextInactive()
  60563. {
  60564. if (context != 0)
  60565. context->makeInactive();
  60566. }
  60567. bool OpenGLComponent::isActiveContext() const throw()
  60568. {
  60569. return context != 0 && context->isActive();
  60570. }
  60571. void OpenGLComponent::swapBuffers()
  60572. {
  60573. if (context != 0)
  60574. context->swapBuffers();
  60575. }
  60576. void OpenGLComponent::paint (Graphics&)
  60577. {
  60578. if (renderAndSwapBuffers())
  60579. {
  60580. ComponentPeer* const peer = getPeer();
  60581. if (peer != 0)
  60582. {
  60583. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60584. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60585. }
  60586. }
  60587. }
  60588. bool OpenGLComponent::renderAndSwapBuffers()
  60589. {
  60590. const ScopedLock sl (contextLock);
  60591. if (! makeCurrentContextActive())
  60592. return false;
  60593. if (needToUpdateViewport)
  60594. {
  60595. needToUpdateViewport = false;
  60596. juce_glViewport (getWidth(), getHeight());
  60597. }
  60598. renderOpenGL();
  60599. swapBuffers();
  60600. return true;
  60601. }
  60602. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60603. {
  60604. Component::internalRepaint (x, y, w, h);
  60605. if (context != 0)
  60606. context->repaint();
  60607. }
  60608. END_JUCE_NAMESPACE
  60609. #endif
  60610. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60611. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60612. BEGIN_JUCE_NAMESPACE
  60613. PreferencesPanel::PreferencesPanel()
  60614. : buttonSize (70)
  60615. {
  60616. }
  60617. PreferencesPanel::~PreferencesPanel()
  60618. {
  60619. currentPage = 0;
  60620. deleteAllChildren();
  60621. }
  60622. void PreferencesPanel::addSettingsPage (const String& title,
  60623. const Drawable* icon,
  60624. const Drawable* overIcon,
  60625. const Drawable* downIcon)
  60626. {
  60627. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60628. button->setImages (icon, overIcon, downIcon);
  60629. button->setRadioGroupId (1);
  60630. button->addButtonListener (this);
  60631. button->setClickingTogglesState (true);
  60632. button->setWantsKeyboardFocus (false);
  60633. addAndMakeVisible (button);
  60634. resized();
  60635. if (currentPage == 0)
  60636. setCurrentPage (title);
  60637. }
  60638. void PreferencesPanel::addSettingsPage (const String& title,
  60639. const char* imageData,
  60640. const int imageDataSize)
  60641. {
  60642. DrawableImage icon, iconOver, iconDown;
  60643. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60644. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60645. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60646. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60647. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60648. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60649. }
  60650. class PrefsDialogWindow : public DialogWindow
  60651. {
  60652. public:
  60653. PrefsDialogWindow (const String& dialogtitle,
  60654. const Colour& backgroundColour)
  60655. : DialogWindow (dialogtitle, backgroundColour, true)
  60656. {
  60657. }
  60658. ~PrefsDialogWindow()
  60659. {
  60660. }
  60661. void closeButtonPressed()
  60662. {
  60663. exitModalState (0);
  60664. }
  60665. private:
  60666. PrefsDialogWindow (const PrefsDialogWindow&);
  60667. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60668. };
  60669. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60670. int dialogWidth,
  60671. int dialogHeight,
  60672. const Colour& backgroundColour)
  60673. {
  60674. setSize (dialogWidth, dialogHeight);
  60675. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60676. dw.setContentComponent (this, true, true);
  60677. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60678. dw.runModalLoop();
  60679. dw.setContentComponent (0, false, false);
  60680. }
  60681. void PreferencesPanel::resized()
  60682. {
  60683. int x = 0;
  60684. for (int i = 0; i < getNumChildComponents(); ++i)
  60685. {
  60686. Component* c = getChildComponent (i);
  60687. if (dynamic_cast <DrawableButton*> (c) == 0)
  60688. {
  60689. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60690. }
  60691. else
  60692. {
  60693. c->setBounds (x, 0, buttonSize, buttonSize);
  60694. x += buttonSize;
  60695. }
  60696. }
  60697. }
  60698. void PreferencesPanel::paint (Graphics& g)
  60699. {
  60700. g.setColour (Colours::grey);
  60701. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60702. }
  60703. void PreferencesPanel::setCurrentPage (const String& pageName)
  60704. {
  60705. if (currentPageName != pageName)
  60706. {
  60707. currentPageName = pageName;
  60708. currentPage = 0;
  60709. currentPage = createComponentForPage (pageName);
  60710. if (currentPage != 0)
  60711. {
  60712. addAndMakeVisible (currentPage);
  60713. currentPage->toBack();
  60714. resized();
  60715. }
  60716. for (int i = 0; i < getNumChildComponents(); ++i)
  60717. {
  60718. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60719. if (db != 0 && db->getName() == pageName)
  60720. {
  60721. db->setToggleState (true, false);
  60722. break;
  60723. }
  60724. }
  60725. }
  60726. }
  60727. void PreferencesPanel::buttonClicked (Button*)
  60728. {
  60729. for (int i = 0; i < getNumChildComponents(); ++i)
  60730. {
  60731. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60732. if (db != 0 && db->getToggleState())
  60733. {
  60734. setCurrentPage (db->getName());
  60735. break;
  60736. }
  60737. }
  60738. }
  60739. END_JUCE_NAMESPACE
  60740. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60741. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60742. #if JUCE_WINDOWS || JUCE_LINUX
  60743. BEGIN_JUCE_NAMESPACE
  60744. SystemTrayIconComponent::SystemTrayIconComponent()
  60745. {
  60746. addToDesktop (0);
  60747. }
  60748. SystemTrayIconComponent::~SystemTrayIconComponent()
  60749. {
  60750. }
  60751. END_JUCE_NAMESPACE
  60752. #endif
  60753. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60754. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60755. BEGIN_JUCE_NAMESPACE
  60756. static const int titleH = 24;
  60757. static const int iconWidth = 80;
  60758. class AlertWindowTextEditor : public TextEditor
  60759. {
  60760. public:
  60761. static const tchar passwordChar;
  60762. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60763. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  60764. {
  60765. setSelectAllWhenFocused (true);
  60766. }
  60767. ~AlertWindowTextEditor()
  60768. {
  60769. }
  60770. void returnPressed()
  60771. {
  60772. // pass these up the component hierarchy to be trigger the buttons
  60773. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  60774. }
  60775. void escapePressed()
  60776. {
  60777. // pass these up the component hierarchy to be trigger the buttons
  60778. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60779. }
  60780. private:
  60781. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60782. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60783. };
  60784. #if JUCE_LINUX
  60785. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  60786. #else
  60787. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  60788. #endif
  60789. AlertWindow::AlertWindow (const String& title,
  60790. const String& message,
  60791. AlertIconType iconType,
  60792. Component* associatedComponent_)
  60793. : TopLevelWindow (title, true),
  60794. alertIconType (iconType),
  60795. associatedComponent (associatedComponent_)
  60796. {
  60797. if (message.isEmpty())
  60798. text = T(" "); // to force an update if the message is empty
  60799. setMessage (message);
  60800. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60801. {
  60802. Component* const c = Desktop::getInstance().getComponent (i);
  60803. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60804. {
  60805. setAlwaysOnTop (true);
  60806. break;
  60807. }
  60808. }
  60809. if (JUCEApplication::getInstance() == 0)
  60810. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60811. lookAndFeelChanged();
  60812. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60813. }
  60814. AlertWindow::~AlertWindow()
  60815. {
  60816. for (int i = customComps.size(); --i >= 0;)
  60817. removeChildComponent ((Component*) customComps[i]);
  60818. deleteAllChildren();
  60819. }
  60820. void AlertWindow::userTriedToCloseWindow()
  60821. {
  60822. exitModalState (0);
  60823. }
  60824. void AlertWindow::setMessage (const String& message)
  60825. {
  60826. const String newMessage (message.substring (0, 2048));
  60827. if (text != newMessage)
  60828. {
  60829. text = newMessage;
  60830. font.setHeight (15.0f);
  60831. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60832. textLayout.setText (getName() + T("\n\n"), titleFont);
  60833. textLayout.appendText (text, font);
  60834. updateLayout (true);
  60835. repaint();
  60836. }
  60837. }
  60838. void AlertWindow::buttonClicked (Button* button)
  60839. {
  60840. for (int i = 0; i < buttons.size(); i++)
  60841. {
  60842. TextButton* const c = (TextButton*) buttons[i];
  60843. if (button->getName() == c->getName())
  60844. {
  60845. if (c->getParentComponent() != 0)
  60846. c->getParentComponent()->exitModalState (c->getCommandID());
  60847. break;
  60848. }
  60849. }
  60850. }
  60851. void AlertWindow::addButton (const String& name,
  60852. const int returnValue,
  60853. const KeyPress& shortcutKey1,
  60854. const KeyPress& shortcutKey2)
  60855. {
  60856. TextButton* const b = new TextButton (name, String::empty);
  60857. b->setWantsKeyboardFocus (true);
  60858. b->setMouseClickGrabsKeyboardFocus (false);
  60859. b->setCommandToTrigger (0, returnValue, false);
  60860. b->addShortcut (shortcutKey1);
  60861. b->addShortcut (shortcutKey2);
  60862. b->addButtonListener (this);
  60863. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60864. addAndMakeVisible (b, 0);
  60865. buttons.add (b);
  60866. updateLayout (false);
  60867. }
  60868. int AlertWindow::getNumButtons() const
  60869. {
  60870. return buttons.size();
  60871. }
  60872. void AlertWindow::addTextEditor (const String& name,
  60873. const String& initialContents,
  60874. const String& onScreenLabel,
  60875. const bool isPasswordBox)
  60876. {
  60877. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60878. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60879. tc->setFont (font);
  60880. tc->setText (initialContents);
  60881. tc->setCaretPosition (initialContents.length());
  60882. addAndMakeVisible (tc);
  60883. textBoxes.add (tc);
  60884. allComps.add (tc);
  60885. textboxNames.add (onScreenLabel);
  60886. updateLayout (false);
  60887. }
  60888. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60889. {
  60890. for (int i = textBoxes.size(); --i >= 0;)
  60891. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60892. return ((TextEditor*)textBoxes[i])->getText();
  60893. return String::empty;
  60894. }
  60895. void AlertWindow::addComboBox (const String& name,
  60896. const StringArray& items,
  60897. const String& onScreenLabel)
  60898. {
  60899. ComboBox* const cb = new ComboBox (name);
  60900. for (int i = 0; i < items.size(); ++i)
  60901. cb->addItem (items[i], i + 1);
  60902. addAndMakeVisible (cb);
  60903. cb->setSelectedItemIndex (0);
  60904. comboBoxes.add (cb);
  60905. allComps.add (cb);
  60906. comboBoxNames.add (onScreenLabel);
  60907. updateLayout (false);
  60908. }
  60909. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  60910. {
  60911. for (int i = comboBoxes.size(); --i >= 0;)
  60912. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  60913. return (ComboBox*) comboBoxes[i];
  60914. return 0;
  60915. }
  60916. class AlertTextComp : public TextEditor
  60917. {
  60918. public:
  60919. AlertTextComp (const String& message,
  60920. const Font& font)
  60921. {
  60922. setReadOnly (true);
  60923. setMultiLine (true, true);
  60924. setCaretVisible (false);
  60925. setScrollbarsShown (true);
  60926. lookAndFeelChanged();
  60927. setWantsKeyboardFocus (false);
  60928. setFont (font);
  60929. setText (message, false);
  60930. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  60931. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  60932. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  60933. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  60934. }
  60935. ~AlertTextComp()
  60936. {
  60937. }
  60938. int getPreferredWidth() const throw() { return bestWidth; }
  60939. void updateLayout (const int width)
  60940. {
  60941. TextLayout text;
  60942. text.appendText (getText(), getFont());
  60943. text.layout (width - 8, Justification::topLeft, true);
  60944. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  60945. }
  60946. private:
  60947. int bestWidth;
  60948. AlertTextComp (const AlertTextComp&);
  60949. AlertTextComp& operator= (const AlertTextComp&);
  60950. };
  60951. void AlertWindow::addTextBlock (const String& text)
  60952. {
  60953. AlertTextComp* const c = new AlertTextComp (text, font);
  60954. textBlocks.add (c);
  60955. allComps.add (c);
  60956. addAndMakeVisible (c);
  60957. updateLayout (false);
  60958. }
  60959. void AlertWindow::addProgressBarComponent (double& progressValue)
  60960. {
  60961. ProgressBar* const pb = new ProgressBar (progressValue);
  60962. progressBars.add (pb);
  60963. allComps.add (pb);
  60964. addAndMakeVisible (pb);
  60965. updateLayout (false);
  60966. }
  60967. void AlertWindow::addCustomComponent (Component* const component)
  60968. {
  60969. customComps.add (component);
  60970. allComps.add (component);
  60971. addAndMakeVisible (component);
  60972. updateLayout (false);
  60973. }
  60974. int AlertWindow::getNumCustomComponents() const
  60975. {
  60976. return customComps.size();
  60977. }
  60978. Component* AlertWindow::getCustomComponent (const int index) const
  60979. {
  60980. return (Component*) customComps [index];
  60981. }
  60982. Component* AlertWindow::removeCustomComponent (const int index)
  60983. {
  60984. Component* const c = getCustomComponent (index);
  60985. if (c != 0)
  60986. {
  60987. customComps.removeValue (c);
  60988. allComps.removeValue (c);
  60989. removeChildComponent (c);
  60990. updateLayout (false);
  60991. }
  60992. return c;
  60993. }
  60994. void AlertWindow::paint (Graphics& g)
  60995. {
  60996. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  60997. g.setColour (findColour (textColourId));
  60998. g.setFont (getLookAndFeel().getAlertWindowFont());
  60999. int i;
  61000. for (i = textBoxes.size(); --i >= 0;)
  61001. {
  61002. const TextEditor* const te = (TextEditor*) textBoxes[i];
  61003. g.drawFittedText (textboxNames[i],
  61004. te->getX(), te->getY() - 14,
  61005. te->getWidth(), 14,
  61006. Justification::centredLeft, 1);
  61007. }
  61008. for (i = comboBoxNames.size(); --i >= 0;)
  61009. {
  61010. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61011. g.drawFittedText (comboBoxNames[i],
  61012. cb->getX(), cb->getY() - 14,
  61013. cb->getWidth(), 14,
  61014. Justification::centredLeft, 1);
  61015. }
  61016. for (i = customComps.size(); --i >= 0;)
  61017. {
  61018. const Component* const c = (Component*) customComps[i];
  61019. g.drawFittedText (c->getName(),
  61020. c->getX(), c->getY() - 14,
  61021. c->getWidth(), 14,
  61022. Justification::centredLeft, 1);
  61023. }
  61024. }
  61025. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61026. {
  61027. const int wid = jmax (font.getStringWidth (text),
  61028. font.getStringWidth (getName()));
  61029. const int sw = (int) sqrt (font.getHeight() * wid);
  61030. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61031. const int edgeGap = 10;
  61032. const int labelHeight = 18;
  61033. int iconSpace;
  61034. if (alertIconType == NoIcon)
  61035. {
  61036. textLayout.layout (w, Justification::horizontallyCentred, true);
  61037. iconSpace = 0;
  61038. }
  61039. else
  61040. {
  61041. textLayout.layout (w, Justification::left, true);
  61042. iconSpace = iconWidth;
  61043. }
  61044. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61045. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61046. const int textLayoutH = textLayout.getHeight();
  61047. const int textBottom = 16 + titleH + textLayoutH;
  61048. int h = textBottom;
  61049. int buttonW = 40;
  61050. int i;
  61051. for (i = 0; i < buttons.size(); ++i)
  61052. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61053. w = jmax (buttonW, w);
  61054. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61055. if (buttons.size() > 0)
  61056. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61057. for (i = customComps.size(); --i >= 0;)
  61058. {
  61059. Component* c = (Component*) customComps[i];
  61060. w = jmax (w, (c->getWidth() * 100) / 80);
  61061. h += 10 + c->getHeight();
  61062. if (c->getName().isNotEmpty())
  61063. h += labelHeight;
  61064. }
  61065. for (i = textBlocks.size(); --i >= 0;)
  61066. {
  61067. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61068. w = jmax (w, ac->getPreferredWidth());
  61069. }
  61070. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61071. for (i = textBlocks.size(); --i >= 0;)
  61072. {
  61073. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61074. ac->updateLayout ((int) (w * 0.8f));
  61075. h += ac->getHeight() + 10;
  61076. }
  61077. h = jmin (getParentHeight() - 50, h);
  61078. if (onlyIncreaseSize)
  61079. {
  61080. w = jmax (w, getWidth());
  61081. h = jmax (h, getHeight());
  61082. }
  61083. if (! isVisible())
  61084. {
  61085. centreAroundComponent (associatedComponent, w, h);
  61086. }
  61087. else
  61088. {
  61089. const int cx = getX() + getWidth() / 2;
  61090. const int cy = getY() + getHeight() / 2;
  61091. setBounds (cx - w / 2,
  61092. cy - h / 2,
  61093. w, h);
  61094. }
  61095. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61096. const int spacer = 16;
  61097. int totalWidth = -spacer;
  61098. for (i = buttons.size(); --i >= 0;)
  61099. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61100. int x = (w - totalWidth) / 2;
  61101. int y = (int) (getHeight() * 0.95f);
  61102. for (i = 0; i < buttons.size(); ++i)
  61103. {
  61104. TextButton* const c = (TextButton*) buttons[i];
  61105. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61106. c->setTopLeftPosition (x, ny);
  61107. if (ny < y)
  61108. y = ny;
  61109. x += c->getWidth() + spacer;
  61110. c->toFront (false);
  61111. }
  61112. y = textBottom;
  61113. for (i = 0; i < allComps.size(); ++i)
  61114. {
  61115. Component* const c = (Component*) allComps[i];
  61116. int h = 22;
  61117. const int comboIndex = comboBoxes.indexOf (c);
  61118. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61119. y += labelHeight;
  61120. const int tbIndex = textBoxes.indexOf (c);
  61121. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61122. y += labelHeight;
  61123. if (customComps.contains (c))
  61124. {
  61125. if (c->getName().isNotEmpty())
  61126. y += labelHeight;
  61127. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61128. h = c->getHeight();
  61129. }
  61130. else if (textBlocks.contains (c))
  61131. {
  61132. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61133. h = c->getHeight();
  61134. }
  61135. else
  61136. {
  61137. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61138. }
  61139. y += h + 10;
  61140. }
  61141. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61142. }
  61143. bool AlertWindow::containsAnyExtraComponents() const
  61144. {
  61145. return textBoxes.size()
  61146. + comboBoxes.size()
  61147. + progressBars.size()
  61148. + customComps.size() > 0;
  61149. }
  61150. void AlertWindow::mouseDown (const MouseEvent&)
  61151. {
  61152. dragger.startDraggingComponent (this, &constrainer);
  61153. }
  61154. void AlertWindow::mouseDrag (const MouseEvent& e)
  61155. {
  61156. dragger.dragComponent (this, e);
  61157. }
  61158. bool AlertWindow::keyPressed (const KeyPress& key)
  61159. {
  61160. for (int i = buttons.size(); --i >= 0;)
  61161. {
  61162. TextButton* const b = (TextButton*) buttons[i];
  61163. if (b->isRegisteredForShortcut (key))
  61164. {
  61165. b->triggerClick();
  61166. return true;
  61167. }
  61168. }
  61169. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61170. {
  61171. exitModalState (0);
  61172. return true;
  61173. }
  61174. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61175. {
  61176. ((TextButton*) buttons.getFirst())->triggerClick();
  61177. return true;
  61178. }
  61179. return false;
  61180. }
  61181. void AlertWindow::lookAndFeelChanged()
  61182. {
  61183. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61184. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61185. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61186. }
  61187. int AlertWindow::getDesktopWindowStyleFlags() const
  61188. {
  61189. return getLookAndFeel().getAlertBoxWindowFlags();
  61190. }
  61191. struct AlertWindowInfo
  61192. {
  61193. String title, message, button1, button2, button3;
  61194. AlertWindow::AlertIconType iconType;
  61195. int numButtons;
  61196. Component::SafePointer<Component> associatedComponent;
  61197. int run() const
  61198. {
  61199. return (int) (pointer_sized_int)
  61200. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61201. }
  61202. private:
  61203. int show() const
  61204. {
  61205. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  61206. : LookAndFeel::getDefaultLookAndFeel();
  61207. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61208. iconType, numButtons, associatedComponent));
  61209. jassert (alertBox != 0); // you have to return one of these!
  61210. return alertBox->runModalLoop();
  61211. }
  61212. static void* showCallback (void* userData)
  61213. {
  61214. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61215. }
  61216. };
  61217. void AlertWindow::showMessageBox (AlertIconType iconType,
  61218. const String& title,
  61219. const String& message,
  61220. const String& buttonText,
  61221. Component* associatedComponent)
  61222. {
  61223. AlertWindowInfo info;
  61224. info.title = title;
  61225. info.message = message;
  61226. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61227. info.iconType = iconType;
  61228. info.numButtons = 1;
  61229. info.associatedComponent = associatedComponent;
  61230. info.run();
  61231. }
  61232. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61233. const String& title,
  61234. const String& message,
  61235. const String& button1Text,
  61236. const String& button2Text,
  61237. Component* associatedComponent)
  61238. {
  61239. AlertWindowInfo info;
  61240. info.title = title;
  61241. info.message = message;
  61242. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61243. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61244. info.iconType = iconType;
  61245. info.numButtons = 2;
  61246. info.associatedComponent = associatedComponent;
  61247. return info.run() != 0;
  61248. }
  61249. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61250. const String& title,
  61251. const String& message,
  61252. const String& button1Text,
  61253. const String& button2Text,
  61254. const String& button3Text,
  61255. Component* associatedComponent)
  61256. {
  61257. AlertWindowInfo info;
  61258. info.title = title;
  61259. info.message = message;
  61260. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61261. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61262. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61263. info.iconType = iconType;
  61264. info.numButtons = 3;
  61265. info.associatedComponent = associatedComponent;
  61266. return info.run();
  61267. }
  61268. END_JUCE_NAMESPACE
  61269. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61270. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61271. BEGIN_JUCE_NAMESPACE
  61272. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61273. static VoidArray heavyweightPeers;
  61274. ComponentPeer::ComponentPeer (Component* const component_,
  61275. const int styleFlags_) throw()
  61276. : component (component_),
  61277. styleFlags (styleFlags_),
  61278. lastPaintTime (0),
  61279. constrainer (0),
  61280. lastDragAndDropCompUnderMouse (0),
  61281. fakeMouseMessageSent (false),
  61282. isWindowMinimised (false)
  61283. {
  61284. heavyweightPeers.add (this);
  61285. }
  61286. ComponentPeer::~ComponentPeer()
  61287. {
  61288. heavyweightPeers.removeValue (this);
  61289. Desktop::getInstance().triggerFocusCallback();
  61290. }
  61291. int ComponentPeer::getNumPeers() throw()
  61292. {
  61293. return heavyweightPeers.size();
  61294. }
  61295. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61296. {
  61297. return (ComponentPeer*) heavyweightPeers [index];
  61298. }
  61299. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61300. {
  61301. for (int i = heavyweightPeers.size(); --i >= 0;)
  61302. {
  61303. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61304. if (peer->getComponent() == component)
  61305. return peer;
  61306. }
  61307. return 0;
  61308. }
  61309. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61310. {
  61311. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61312. }
  61313. void ComponentPeer::updateCurrentModifiers() throw()
  61314. {
  61315. ModifierKeys::updateCurrentModifiers();
  61316. }
  61317. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61318. {
  61319. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61320. jassert (mouse != 0); // not enough sources!
  61321. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61322. }
  61323. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61324. {
  61325. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61326. jassert (mouse != 0); // not enough sources!
  61327. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61328. }
  61329. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61330. {
  61331. Graphics g (&contextToPaintTo);
  61332. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61333. g.saveState();
  61334. #endif
  61335. JUCE_TRY
  61336. {
  61337. component->paintEntireComponent (g);
  61338. }
  61339. JUCE_CATCH_EXCEPTION
  61340. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61341. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61342. // clearly when things are being repainted.
  61343. {
  61344. g.restoreState();
  61345. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61346. (uint8) Random::getSystemRandom().nextInt (255),
  61347. (uint8) Random::getSystemRandom().nextInt (255),
  61348. (uint8) 0x50));
  61349. }
  61350. #endif
  61351. }
  61352. bool ComponentPeer::handleKeyPress (const int keyCode,
  61353. const juce_wchar textCharacter)
  61354. {
  61355. updateCurrentModifiers();
  61356. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61357. ? Component::getCurrentlyFocusedComponent()
  61358. : component;
  61359. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61360. {
  61361. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61362. if (currentModalComp != 0)
  61363. target = currentModalComp;
  61364. }
  61365. const KeyPress keyInfo (keyCode,
  61366. ModifierKeys::getCurrentModifiers().getRawFlags()
  61367. & ModifierKeys::allKeyboardModifiers,
  61368. textCharacter);
  61369. bool keyWasUsed = false;
  61370. while (target != 0)
  61371. {
  61372. const Component::SafePointer<Component> deletionChecker (target);
  61373. if (target->keyListeners_ != 0)
  61374. {
  61375. for (int i = target->keyListeners_->size(); --i >= 0;)
  61376. {
  61377. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61378. if (keyWasUsed || deletionChecker == 0)
  61379. return keyWasUsed;
  61380. i = jmin (i, target->keyListeners_->size());
  61381. }
  61382. }
  61383. keyWasUsed = target->keyPressed (keyInfo);
  61384. if (keyWasUsed || deletionChecker == 0)
  61385. break;
  61386. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61387. {
  61388. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61389. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61390. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61391. break;
  61392. }
  61393. target = target->parentComponent_;
  61394. }
  61395. return keyWasUsed;
  61396. }
  61397. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61398. {
  61399. updateCurrentModifiers();
  61400. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61401. ? Component::getCurrentlyFocusedComponent()
  61402. : component;
  61403. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61404. {
  61405. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61406. if (currentModalComp != 0)
  61407. target = currentModalComp;
  61408. }
  61409. bool keyWasUsed = false;
  61410. while (target != 0)
  61411. {
  61412. const Component::SafePointer<Component> deletionChecker (target);
  61413. keyWasUsed = target->keyStateChanged (isKeyDown);
  61414. if (keyWasUsed || deletionChecker == 0)
  61415. break;
  61416. if (target->keyListeners_ != 0)
  61417. {
  61418. for (int i = target->keyListeners_->size(); --i >= 0;)
  61419. {
  61420. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61421. if (keyWasUsed || deletionChecker == 0)
  61422. return keyWasUsed;
  61423. i = jmin (i, target->keyListeners_->size());
  61424. }
  61425. }
  61426. target = target->parentComponent_;
  61427. }
  61428. return keyWasUsed;
  61429. }
  61430. void ComponentPeer::handleModifierKeysChange()
  61431. {
  61432. updateCurrentModifiers();
  61433. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61434. if (target == 0)
  61435. target = Component::getCurrentlyFocusedComponent();
  61436. if (target == 0)
  61437. target = component;
  61438. if (target != 0)
  61439. target->internalModifierKeysChanged();
  61440. }
  61441. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61442. {
  61443. Component* const c = Component::getCurrentlyFocusedComponent();
  61444. if (component->isParentOf (c))
  61445. return dynamic_cast <TextInputTarget*> (c);
  61446. return 0;
  61447. }
  61448. void ComponentPeer::handleBroughtToFront()
  61449. {
  61450. updateCurrentModifiers();
  61451. if (component != 0)
  61452. component->internalBroughtToFront();
  61453. }
  61454. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61455. {
  61456. constrainer = newConstrainer;
  61457. }
  61458. void ComponentPeer::handleMovedOrResized()
  61459. {
  61460. jassert (component->isValidComponent());
  61461. updateCurrentModifiers();
  61462. const bool nowMinimised = isMinimised();
  61463. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61464. {
  61465. const Component::SafePointer<Component> deletionChecker (component);
  61466. const Rectangle<int> newBounds (getBounds());
  61467. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61468. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61469. if (wasMoved || wasResized)
  61470. {
  61471. component->bounds_ = newBounds;
  61472. if (wasResized)
  61473. component->repaint();
  61474. component->sendMovedResizedMessages (wasMoved, wasResized);
  61475. if (deletionChecker == 0)
  61476. return;
  61477. }
  61478. }
  61479. if (isWindowMinimised != nowMinimised)
  61480. {
  61481. isWindowMinimised = nowMinimised;
  61482. component->minimisationStateChanged (nowMinimised);
  61483. component->sendVisibilityChangeMessage();
  61484. }
  61485. if (! isFullScreen())
  61486. lastNonFullscreenBounds = component->getBounds();
  61487. }
  61488. void ComponentPeer::handleFocusGain()
  61489. {
  61490. updateCurrentModifiers();
  61491. if (component->isParentOf (lastFocusedComponent))
  61492. {
  61493. Component::currentlyFocusedComponent = lastFocusedComponent;
  61494. Desktop::getInstance().triggerFocusCallback();
  61495. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61496. }
  61497. else
  61498. {
  61499. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61500. component->grabKeyboardFocus();
  61501. else
  61502. Component::bringModalComponentToFront();
  61503. }
  61504. }
  61505. void ComponentPeer::handleFocusLoss()
  61506. {
  61507. updateCurrentModifiers();
  61508. if (component->hasKeyboardFocus (true))
  61509. {
  61510. lastFocusedComponent = Component::currentlyFocusedComponent;
  61511. if (lastFocusedComponent != 0)
  61512. {
  61513. Component::currentlyFocusedComponent = 0;
  61514. Desktop::getInstance().triggerFocusCallback();
  61515. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61516. }
  61517. }
  61518. }
  61519. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61520. {
  61521. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61522. ? static_cast <Component*> (lastFocusedComponent)
  61523. : component;
  61524. }
  61525. void ComponentPeer::handleScreenSizeChange()
  61526. {
  61527. updateCurrentModifiers();
  61528. component->parentSizeChanged();
  61529. handleMovedOrResized();
  61530. }
  61531. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61532. {
  61533. lastNonFullscreenBounds = newBounds;
  61534. }
  61535. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61536. {
  61537. return lastNonFullscreenBounds;
  61538. }
  61539. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61540. const StringArray& files,
  61541. FileDragAndDropTarget* const lastOne)
  61542. {
  61543. while (c != 0)
  61544. {
  61545. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61546. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61547. return t;
  61548. c = c->getParentComponent();
  61549. }
  61550. return 0;
  61551. }
  61552. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61553. {
  61554. updateCurrentModifiers();
  61555. FileDragAndDropTarget* lastTarget
  61556. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61557. FileDragAndDropTarget* newTarget = 0;
  61558. Component* const compUnderMouse = component->getComponentAt (position);
  61559. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61560. {
  61561. lastDragAndDropCompUnderMouse = compUnderMouse;
  61562. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61563. if (newTarget != lastTarget)
  61564. {
  61565. if (lastTarget != 0)
  61566. lastTarget->fileDragExit (files);
  61567. dragAndDropTargetComponent = 0;
  61568. if (newTarget != 0)
  61569. {
  61570. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61571. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61572. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61573. }
  61574. }
  61575. }
  61576. else
  61577. {
  61578. newTarget = lastTarget;
  61579. }
  61580. if (newTarget != 0)
  61581. {
  61582. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61583. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61584. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61585. }
  61586. }
  61587. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61588. {
  61589. handleFileDragMove (files, Point<int> (-1, -1));
  61590. jassert (dragAndDropTargetComponent == 0);
  61591. lastDragAndDropCompUnderMouse = 0;
  61592. }
  61593. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61594. {
  61595. handleFileDragMove (files, position);
  61596. if (dragAndDropTargetComponent != 0)
  61597. {
  61598. FileDragAndDropTarget* const target
  61599. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61600. dragAndDropTargetComponent = 0;
  61601. lastDragAndDropCompUnderMouse = 0;
  61602. if (target != 0)
  61603. {
  61604. Component* const targetComp = dynamic_cast <Component*> (target);
  61605. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61606. {
  61607. targetComp->internalModalInputAttempt();
  61608. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61609. return;
  61610. }
  61611. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61612. target->filesDropped (files, pos.getX(), pos.getY());
  61613. }
  61614. }
  61615. }
  61616. void ComponentPeer::handleUserClosingWindow()
  61617. {
  61618. updateCurrentModifiers();
  61619. component->userTriedToCloseWindow();
  61620. }
  61621. void ComponentPeer::bringModalComponentToFront()
  61622. {
  61623. Component::bringModalComponentToFront();
  61624. }
  61625. void ComponentPeer::clearMaskedRegion() throw()
  61626. {
  61627. maskedRegion.clear();
  61628. }
  61629. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61630. {
  61631. maskedRegion.add (x, y, w, h);
  61632. }
  61633. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61634. {
  61635. StringArray s;
  61636. s.add ("Software Renderer");
  61637. return s;
  61638. }
  61639. int ComponentPeer::getCurrentRenderingEngine() throw()
  61640. {
  61641. return 0;
  61642. }
  61643. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61644. {
  61645. }
  61646. END_JUCE_NAMESPACE
  61647. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61648. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61649. BEGIN_JUCE_NAMESPACE
  61650. DialogWindow::DialogWindow (const String& name,
  61651. const Colour& backgroundColour_,
  61652. const bool escapeKeyTriggersCloseButton_,
  61653. const bool addToDesktop_)
  61654. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61655. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61656. {
  61657. }
  61658. DialogWindow::~DialogWindow()
  61659. {
  61660. }
  61661. void DialogWindow::resized()
  61662. {
  61663. DocumentWindow::resized();
  61664. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61665. if (escapeKeyTriggersCloseButton
  61666. && getCloseButton() != 0
  61667. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61668. {
  61669. getCloseButton()->addShortcut (esc);
  61670. }
  61671. }
  61672. class TempDialogWindow : public DialogWindow
  61673. {
  61674. public:
  61675. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61676. : DialogWindow (title, colour, escapeCloses, true)
  61677. {
  61678. }
  61679. ~TempDialogWindow()
  61680. {
  61681. }
  61682. void closeButtonPressed()
  61683. {
  61684. setVisible (false);
  61685. }
  61686. private:
  61687. TempDialogWindow (const TempDialogWindow&);
  61688. TempDialogWindow& operator= (const TempDialogWindow&);
  61689. };
  61690. int DialogWindow::showModalDialog (const String& dialogTitle,
  61691. Component* contentComponent,
  61692. Component* componentToCentreAround,
  61693. const Colour& colour,
  61694. const bool escapeKeyTriggersCloseButton,
  61695. const bool shouldBeResizable,
  61696. const bool useBottomRightCornerResizer)
  61697. {
  61698. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61699. dw.setContentComponent (contentComponent, true, true);
  61700. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61701. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61702. const int result = dw.runModalLoop();
  61703. dw.setContentComponent (0, false);
  61704. return result;
  61705. }
  61706. END_JUCE_NAMESPACE
  61707. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61708. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61709. BEGIN_JUCE_NAMESPACE
  61710. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61711. {
  61712. public:
  61713. ButtonListenerProxy (DocumentWindow& owner_)
  61714. : owner (owner_)
  61715. {
  61716. }
  61717. void buttonClicked (Button* button)
  61718. {
  61719. if (button == owner.getMinimiseButton())
  61720. owner.minimiseButtonPressed();
  61721. else if (button == owner.getMaximiseButton())
  61722. owner.maximiseButtonPressed();
  61723. else if (button == owner.getCloseButton())
  61724. owner.closeButtonPressed();
  61725. }
  61726. juce_UseDebuggingNewOperator
  61727. private:
  61728. DocumentWindow& owner;
  61729. ButtonListenerProxy (const ButtonListenerProxy&);
  61730. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61731. };
  61732. DocumentWindow::DocumentWindow (const String& title,
  61733. const Colour& backgroundColour,
  61734. const int requiredButtons_,
  61735. const bool addToDesktop_)
  61736. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61737. titleBarHeight (26),
  61738. menuBarHeight (24),
  61739. requiredButtons (requiredButtons_),
  61740. #if JUCE_MAC
  61741. positionTitleBarButtonsOnLeft (true),
  61742. #else
  61743. positionTitleBarButtonsOnLeft (false),
  61744. #endif
  61745. drawTitleTextCentred (true),
  61746. menuBarModel (0)
  61747. {
  61748. setResizeLimits (128, 128, 32768, 32768);
  61749. lookAndFeelChanged();
  61750. }
  61751. DocumentWindow::~DocumentWindow()
  61752. {
  61753. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61754. titleBarButtons[i] = 0;
  61755. menuBar = 0;
  61756. }
  61757. void DocumentWindow::repaintTitleBar()
  61758. {
  61759. const Rectangle<int> titleBarArea (getTitleBarArea());
  61760. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61761. titleBarArea.getWidth(), titleBarArea.getHeight());
  61762. }
  61763. void DocumentWindow::setName (const String& newName)
  61764. {
  61765. if (newName != getName())
  61766. {
  61767. Component::setName (newName);
  61768. repaintTitleBar();
  61769. }
  61770. }
  61771. void DocumentWindow::setIcon (const Image* imageToUse)
  61772. {
  61773. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61774. repaintTitleBar();
  61775. }
  61776. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61777. {
  61778. titleBarHeight = newHeight;
  61779. resized();
  61780. repaintTitleBar();
  61781. }
  61782. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61783. const bool positionTitleBarButtonsOnLeft_)
  61784. {
  61785. requiredButtons = requiredButtons_;
  61786. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61787. lookAndFeelChanged();
  61788. }
  61789. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61790. {
  61791. drawTitleTextCentred = textShouldBeCentred;
  61792. repaintTitleBar();
  61793. }
  61794. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61795. const int menuBarHeight_)
  61796. {
  61797. if (menuBarModel != menuBarModel_)
  61798. {
  61799. menuBar = 0;
  61800. menuBarModel = menuBarModel_;
  61801. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61802. : getLookAndFeel().getDefaultMenuBarHeight();
  61803. if (menuBarModel != 0)
  61804. {
  61805. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61806. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61807. menuBar->setEnabled (isActiveWindow());
  61808. }
  61809. resized();
  61810. }
  61811. }
  61812. void DocumentWindow::closeButtonPressed()
  61813. {
  61814. /* If you've got a close button, you have to override this method to get
  61815. rid of your window!
  61816. If the window is just a pop-up, you should override this method and make
  61817. it delete the window in whatever way is appropriate for your app. E.g. you
  61818. might just want to call "delete this".
  61819. If your app is centred around this window such that the whole app should quit when
  61820. the window is closed, then you will probably want to use this method as an opportunity
  61821. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61822. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61823. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61824. or closing it via the taskbar icon on Windows).
  61825. */
  61826. jassertfalse
  61827. }
  61828. void DocumentWindow::minimiseButtonPressed()
  61829. {
  61830. setMinimised (true);
  61831. }
  61832. void DocumentWindow::maximiseButtonPressed()
  61833. {
  61834. setFullScreen (! isFullScreen());
  61835. }
  61836. void DocumentWindow::paint (Graphics& g)
  61837. {
  61838. ResizableWindow::paint (g);
  61839. if (resizableBorder == 0)
  61840. {
  61841. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61842. const BorderSize border (getBorderThickness());
  61843. g.fillRect (0, 0, getWidth(), border.getTop());
  61844. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61845. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61846. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61847. }
  61848. const Rectangle<int> titleBarArea (getTitleBarArea());
  61849. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61850. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61851. int titleSpaceX1 = 6;
  61852. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61853. for (int i = 0; i < 3; ++i)
  61854. {
  61855. if (titleBarButtons[i] != 0)
  61856. {
  61857. if (positionTitleBarButtonsOnLeft)
  61858. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61859. else
  61860. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61861. }
  61862. }
  61863. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61864. titleBarArea.getWidth(),
  61865. titleBarArea.getHeight(),
  61866. titleSpaceX1,
  61867. jmax (1, titleSpaceX2 - titleSpaceX1),
  61868. titleBarIcon,
  61869. ! drawTitleTextCentred);
  61870. }
  61871. void DocumentWindow::resized()
  61872. {
  61873. ResizableWindow::resized();
  61874. if (titleBarButtons[1] != 0)
  61875. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61876. const Rectangle<int> titleBarArea (getTitleBarArea());
  61877. getLookAndFeel()
  61878. .positionDocumentWindowButtons (*this,
  61879. titleBarArea.getX(), titleBarArea.getY(),
  61880. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61881. titleBarButtons[0],
  61882. titleBarButtons[1],
  61883. titleBarButtons[2],
  61884. positionTitleBarButtonsOnLeft);
  61885. if (menuBar != 0)
  61886. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61887. titleBarArea.getWidth(), menuBarHeight);
  61888. }
  61889. const BorderSize DocumentWindow::getBorderThickness()
  61890. {
  61891. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61892. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61893. }
  61894. const BorderSize DocumentWindow::getContentComponentBorder()
  61895. {
  61896. BorderSize border (getBorderThickness());
  61897. border.setTop (border.getTop()
  61898. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61899. + (menuBar != 0 ? menuBarHeight : 0));
  61900. return border;
  61901. }
  61902. int DocumentWindow::getTitleBarHeight() const
  61903. {
  61904. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61905. }
  61906. const Rectangle<int> DocumentWindow::getTitleBarArea()
  61907. {
  61908. const BorderSize border (getBorderThickness());
  61909. return Rectangle<int> (border.getLeft(), border.getTop(),
  61910. getWidth() - border.getLeftAndRight(),
  61911. getTitleBarHeight());
  61912. }
  61913. Button* DocumentWindow::getCloseButton() const throw()
  61914. {
  61915. return titleBarButtons[2];
  61916. }
  61917. Button* DocumentWindow::getMinimiseButton() const throw()
  61918. {
  61919. return titleBarButtons[0];
  61920. }
  61921. Button* DocumentWindow::getMaximiseButton() const throw()
  61922. {
  61923. return titleBarButtons[1];
  61924. }
  61925. int DocumentWindow::getDesktopWindowStyleFlags() const
  61926. {
  61927. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  61928. if ((requiredButtons & minimiseButton) != 0)
  61929. flags |= ComponentPeer::windowHasMinimiseButton;
  61930. if ((requiredButtons & maximiseButton) != 0)
  61931. flags |= ComponentPeer::windowHasMaximiseButton;
  61932. if ((requiredButtons & closeButton) != 0)
  61933. flags |= ComponentPeer::windowHasCloseButton;
  61934. return flags;
  61935. }
  61936. void DocumentWindow::lookAndFeelChanged()
  61937. {
  61938. int i;
  61939. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  61940. titleBarButtons[i] = 0;
  61941. if (! isUsingNativeTitleBar())
  61942. {
  61943. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  61944. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  61945. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  61946. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  61947. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  61948. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  61949. for (i = 0; i < 3; ++i)
  61950. {
  61951. if (titleBarButtons[i] != 0)
  61952. {
  61953. if (buttonListener == 0)
  61954. buttonListener = new ButtonListenerProxy (*this);
  61955. titleBarButtons[i]->addButtonListener (buttonListener);
  61956. titleBarButtons[i]->setWantsKeyboardFocus (false);
  61957. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61958. Component::addAndMakeVisible (titleBarButtons[i]);
  61959. }
  61960. }
  61961. if (getCloseButton() != 0)
  61962. {
  61963. #if JUCE_MAC
  61964. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  61965. #else
  61966. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  61967. #endif
  61968. }
  61969. }
  61970. activeWindowStatusChanged();
  61971. ResizableWindow::lookAndFeelChanged();
  61972. }
  61973. void DocumentWindow::parentHierarchyChanged()
  61974. {
  61975. lookAndFeelChanged();
  61976. }
  61977. void DocumentWindow::activeWindowStatusChanged()
  61978. {
  61979. ResizableWindow::activeWindowStatusChanged();
  61980. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61981. if (titleBarButtons[i] != 0)
  61982. titleBarButtons[i]->setEnabled (isActiveWindow());
  61983. if (menuBar != 0)
  61984. menuBar->setEnabled (isActiveWindow());
  61985. }
  61986. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  61987. {
  61988. if (getTitleBarArea().contains (e.x, e.y)
  61989. && getMaximiseButton() != 0)
  61990. {
  61991. getMaximiseButton()->triggerClick();
  61992. }
  61993. }
  61994. void DocumentWindow::userTriedToCloseWindow()
  61995. {
  61996. closeButtonPressed();
  61997. }
  61998. END_JUCE_NAMESPACE
  61999. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  62000. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  62001. BEGIN_JUCE_NAMESPACE
  62002. ResizableWindow::ResizableWindow (const String& name,
  62003. const bool addToDesktop_)
  62004. : TopLevelWindow (name, addToDesktop_),
  62005. resizeToFitContent (false),
  62006. fullscreen (false),
  62007. lastNonFullScreenPos (50, 50, 256, 256),
  62008. constrainer (0)
  62009. #ifdef JUCE_DEBUG
  62010. , hasBeenResized (false)
  62011. #endif
  62012. {
  62013. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62014. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62015. if (addToDesktop_)
  62016. Component::addToDesktop (getDesktopWindowStyleFlags());
  62017. }
  62018. ResizableWindow::ResizableWindow (const String& name,
  62019. const Colour& backgroundColour_,
  62020. const bool addToDesktop_)
  62021. : TopLevelWindow (name, addToDesktop_),
  62022. resizeToFitContent (false),
  62023. fullscreen (false),
  62024. lastNonFullScreenPos (50, 50, 256, 256),
  62025. constrainer (0)
  62026. #ifdef JUCE_DEBUG
  62027. , hasBeenResized (false)
  62028. #endif
  62029. {
  62030. setBackgroundColour (backgroundColour_);
  62031. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62032. if (addToDesktop_)
  62033. Component::addToDesktop (getDesktopWindowStyleFlags());
  62034. }
  62035. ResizableWindow::~ResizableWindow()
  62036. {
  62037. resizableCorner = 0;
  62038. resizableBorder = 0;
  62039. contentComponent = 0;
  62040. // have you been adding your own components directly to this window..? tut tut tut.
  62041. // Read the instructions for using a ResizableWindow!
  62042. jassert (getNumChildComponents() == 0);
  62043. }
  62044. int ResizableWindow::getDesktopWindowStyleFlags() const
  62045. {
  62046. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62047. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62048. flags |= ComponentPeer::windowIsResizable;
  62049. return flags;
  62050. }
  62051. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62052. const bool deleteOldOne,
  62053. const bool resizeToFit)
  62054. {
  62055. resizeToFitContent = resizeToFit;
  62056. if (newContentComponent != (Component*) contentComponent)
  62057. {
  62058. if (! deleteOldOne)
  62059. removeChildComponent (contentComponent.release());
  62060. contentComponent = newContentComponent;
  62061. Component::addAndMakeVisible (contentComponent);
  62062. }
  62063. if (resizeToFit)
  62064. childBoundsChanged (contentComponent);
  62065. resized(); // must always be called to position the new content comp
  62066. }
  62067. void ResizableWindow::setContentComponentSize (int width, int height)
  62068. {
  62069. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62070. const BorderSize border (getContentComponentBorder());
  62071. setSize (width + border.getLeftAndRight(),
  62072. height + border.getTopAndBottom());
  62073. }
  62074. const BorderSize ResizableWindow::getBorderThickness()
  62075. {
  62076. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62077. }
  62078. const BorderSize ResizableWindow::getContentComponentBorder()
  62079. {
  62080. return getBorderThickness();
  62081. }
  62082. void ResizableWindow::moved()
  62083. {
  62084. updateLastPos();
  62085. }
  62086. void ResizableWindow::visibilityChanged()
  62087. {
  62088. TopLevelWindow::visibilityChanged();
  62089. updateLastPos();
  62090. }
  62091. void ResizableWindow::resized()
  62092. {
  62093. if (resizableBorder != 0)
  62094. {
  62095. resizableBorder->setVisible (! isFullScreen());
  62096. resizableBorder->setBorderThickness (getBorderThickness());
  62097. resizableBorder->setSize (getWidth(), getHeight());
  62098. resizableBorder->toBack();
  62099. }
  62100. if (resizableCorner != 0)
  62101. {
  62102. resizableCorner->setVisible (! isFullScreen());
  62103. const int resizerSize = 18;
  62104. resizableCorner->setBounds (getWidth() - resizerSize,
  62105. getHeight() - resizerSize,
  62106. resizerSize, resizerSize);
  62107. }
  62108. if (contentComponent != 0)
  62109. contentComponent->setBoundsInset (getContentComponentBorder());
  62110. updateLastPos();
  62111. #ifdef JUCE_DEBUG
  62112. hasBeenResized = true;
  62113. #endif
  62114. }
  62115. void ResizableWindow::childBoundsChanged (Component* child)
  62116. {
  62117. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62118. {
  62119. // not going to look very good if this component has a zero size..
  62120. jassert (child->getWidth() > 0);
  62121. jassert (child->getHeight() > 0);
  62122. const BorderSize borders (getContentComponentBorder());
  62123. setSize (child->getWidth() + borders.getLeftAndRight(),
  62124. child->getHeight() + borders.getTopAndBottom());
  62125. }
  62126. }
  62127. void ResizableWindow::activeWindowStatusChanged()
  62128. {
  62129. const BorderSize borders (getContentComponentBorder());
  62130. repaint (0, 0, getWidth(), borders.getTop());
  62131. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62132. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62133. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62134. }
  62135. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62136. const bool useBottomRightCornerResizer)
  62137. {
  62138. if (shouldBeResizable)
  62139. {
  62140. if (useBottomRightCornerResizer)
  62141. {
  62142. resizableBorder = 0;
  62143. if (resizableCorner == 0)
  62144. {
  62145. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62146. resizableCorner->setAlwaysOnTop (true);
  62147. }
  62148. }
  62149. else
  62150. {
  62151. resizableCorner = 0;
  62152. if (resizableBorder == 0)
  62153. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62154. }
  62155. }
  62156. else
  62157. {
  62158. resizableCorner = 0;
  62159. resizableBorder = 0;
  62160. }
  62161. if (isUsingNativeTitleBar())
  62162. recreateDesktopWindow();
  62163. childBoundsChanged (contentComponent);
  62164. resized();
  62165. }
  62166. bool ResizableWindow::isResizable() const throw()
  62167. {
  62168. return resizableCorner != 0
  62169. || resizableBorder != 0;
  62170. }
  62171. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62172. const int newMinimumHeight,
  62173. const int newMaximumWidth,
  62174. const int newMaximumHeight) throw()
  62175. {
  62176. // if you've set up a custom constrainer then these settings won't have any effect..
  62177. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62178. if (constrainer == 0)
  62179. setConstrainer (&defaultConstrainer);
  62180. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62181. newMaximumWidth, newMaximumHeight);
  62182. setBoundsConstrained (getBounds());
  62183. }
  62184. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62185. {
  62186. if (constrainer != newConstrainer)
  62187. {
  62188. constrainer = newConstrainer;
  62189. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62190. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62191. resizableCorner = 0;
  62192. resizableBorder = 0;
  62193. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62194. ComponentPeer* const peer = getPeer();
  62195. if (peer != 0)
  62196. peer->setConstrainer (newConstrainer);
  62197. }
  62198. }
  62199. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62200. {
  62201. if (constrainer != 0)
  62202. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62203. else
  62204. setBounds (bounds);
  62205. }
  62206. void ResizableWindow::paint (Graphics& g)
  62207. {
  62208. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62209. getBorderThickness(), *this);
  62210. if (! isFullScreen())
  62211. {
  62212. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62213. getBorderThickness(), *this);
  62214. }
  62215. #ifdef JUCE_DEBUG
  62216. /* If this fails, then you've probably written a subclass with a resized()
  62217. callback but forgotten to make it call its parent class's resized() method.
  62218. It's important when you override methods like resized(), moved(),
  62219. etc., that you make sure the base class methods also get called.
  62220. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62221. because your content should all be inside the content component - and it's the
  62222. content component's resized() method that you should be using to do your
  62223. layout.
  62224. */
  62225. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62226. #endif
  62227. }
  62228. void ResizableWindow::lookAndFeelChanged()
  62229. {
  62230. resized();
  62231. if (isOnDesktop())
  62232. {
  62233. Component::addToDesktop (getDesktopWindowStyleFlags());
  62234. ComponentPeer* const peer = getPeer();
  62235. if (peer != 0)
  62236. peer->setConstrainer (constrainer);
  62237. }
  62238. }
  62239. const Colour ResizableWindow::getBackgroundColour() const throw()
  62240. {
  62241. return findColour (backgroundColourId, false);
  62242. }
  62243. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62244. {
  62245. Colour backgroundColour (newColour);
  62246. if (! Desktop::canUseSemiTransparentWindows())
  62247. backgroundColour = newColour.withAlpha (1.0f);
  62248. setColour (backgroundColourId, backgroundColour);
  62249. setOpaque (backgroundColour.isOpaque());
  62250. repaint();
  62251. }
  62252. bool ResizableWindow::isFullScreen() const
  62253. {
  62254. if (isOnDesktop())
  62255. {
  62256. ComponentPeer* const peer = getPeer();
  62257. return peer != 0 && peer->isFullScreen();
  62258. }
  62259. return fullscreen;
  62260. }
  62261. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62262. {
  62263. if (shouldBeFullScreen != isFullScreen())
  62264. {
  62265. updateLastPos();
  62266. fullscreen = shouldBeFullScreen;
  62267. if (isOnDesktop())
  62268. {
  62269. ComponentPeer* const peer = getPeer();
  62270. if (peer != 0)
  62271. {
  62272. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62273. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62274. peer->setFullScreen (shouldBeFullScreen);
  62275. if (! shouldBeFullScreen)
  62276. setBounds (lastPos);
  62277. }
  62278. else
  62279. {
  62280. jassertfalse
  62281. }
  62282. }
  62283. else
  62284. {
  62285. if (shouldBeFullScreen)
  62286. setBounds (0, 0, getParentWidth(), getParentHeight());
  62287. else
  62288. setBounds (lastNonFullScreenPos);
  62289. }
  62290. resized();
  62291. }
  62292. }
  62293. bool ResizableWindow::isMinimised() const
  62294. {
  62295. ComponentPeer* const peer = getPeer();
  62296. return (peer != 0) && peer->isMinimised();
  62297. }
  62298. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62299. {
  62300. if (shouldMinimise != isMinimised())
  62301. {
  62302. ComponentPeer* const peer = getPeer();
  62303. if (peer != 0)
  62304. {
  62305. updateLastPos();
  62306. peer->setMinimised (shouldMinimise);
  62307. }
  62308. else
  62309. {
  62310. jassertfalse
  62311. }
  62312. }
  62313. }
  62314. void ResizableWindow::updateLastPos()
  62315. {
  62316. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62317. {
  62318. lastNonFullScreenPos = getBounds();
  62319. }
  62320. }
  62321. void ResizableWindow::parentSizeChanged()
  62322. {
  62323. if (isFullScreen() && getParentComponent() != 0)
  62324. {
  62325. setBounds (0, 0, getParentWidth(), getParentHeight());
  62326. }
  62327. }
  62328. const String ResizableWindow::getWindowStateAsString()
  62329. {
  62330. updateLastPos();
  62331. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62332. }
  62333. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62334. {
  62335. StringArray tokens;
  62336. tokens.addTokens (s, false);
  62337. tokens.removeEmptyStrings();
  62338. tokens.trim();
  62339. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62340. const int firstCoord = fs ? 1 : 0;
  62341. if (tokens.size() != firstCoord + 4)
  62342. return false;
  62343. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62344. tokens[firstCoord + 1].getIntValue(),
  62345. tokens[firstCoord + 2].getIntValue(),
  62346. tokens[firstCoord + 3].getIntValue());
  62347. if (newPos.isEmpty())
  62348. return false;
  62349. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62350. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62351. if (peer != 0)
  62352. peer->getFrameSize().addTo (newPos);
  62353. if (! screen.contains (newPos))
  62354. {
  62355. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62356. jmin (newPos.getHeight(), screen.getHeight()));
  62357. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62358. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62359. }
  62360. if (peer != 0)
  62361. {
  62362. peer->getFrameSize().subtractFrom (newPos);
  62363. peer->setNonFullScreenBounds (newPos);
  62364. }
  62365. lastNonFullScreenPos = newPos;
  62366. setFullScreen (fs);
  62367. if (! fs)
  62368. setBoundsConstrained (newPos);
  62369. return true;
  62370. }
  62371. void ResizableWindow::mouseDown (const MouseEvent&)
  62372. {
  62373. if (! isFullScreen())
  62374. dragger.startDraggingComponent (this, constrainer);
  62375. }
  62376. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62377. {
  62378. if (! isFullScreen())
  62379. dragger.dragComponent (this, e);
  62380. }
  62381. #ifdef JUCE_DEBUG
  62382. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62383. {
  62384. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62385. manages its child components automatically, and if you add your own it'll cause
  62386. trouble. Instead, use setContentComponent() to give it a component which
  62387. will be automatically resized and kept in the right place - then you can add
  62388. subcomponents to the content comp. See the notes for the ResizableWindow class
  62389. for more info.
  62390. If you really know what you're doing and want to avoid this assertion, just call
  62391. Component::addChildComponent directly.
  62392. */
  62393. jassertfalse
  62394. Component::addChildComponent (child, zOrder);
  62395. }
  62396. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62397. {
  62398. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62399. manages its child components automatically, and if you add your own it'll cause
  62400. trouble. Instead, use setContentComponent() to give it a component which
  62401. will be automatically resized and kept in the right place - then you can add
  62402. subcomponents to the content comp. See the notes for the ResizableWindow class
  62403. for more info.
  62404. If you really know what you're doing and want to avoid this assertion, just call
  62405. Component::addAndMakeVisible directly.
  62406. */
  62407. jassertfalse
  62408. Component::addAndMakeVisible (child, zOrder);
  62409. }
  62410. #endif
  62411. END_JUCE_NAMESPACE
  62412. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62413. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62414. BEGIN_JUCE_NAMESPACE
  62415. SplashScreen::SplashScreen()
  62416. : backgroundImage (0)
  62417. {
  62418. setOpaque (true);
  62419. }
  62420. SplashScreen::~SplashScreen()
  62421. {
  62422. ImageCache::releaseOrDelete (backgroundImage);
  62423. }
  62424. void SplashScreen::show (const String& title,
  62425. Image* const backgroundImage_,
  62426. const int minimumTimeToDisplayFor,
  62427. const bool useDropShadow,
  62428. const bool removeOnMouseClick)
  62429. {
  62430. backgroundImage = backgroundImage_;
  62431. jassert (backgroundImage_ != 0);
  62432. if (backgroundImage_ != 0)
  62433. {
  62434. setOpaque (! backgroundImage_->hasAlphaChannel());
  62435. show (title,
  62436. backgroundImage_->getWidth(),
  62437. backgroundImage_->getHeight(),
  62438. minimumTimeToDisplayFor,
  62439. useDropShadow,
  62440. removeOnMouseClick);
  62441. }
  62442. }
  62443. void SplashScreen::show (const String& title,
  62444. const int width,
  62445. const int height,
  62446. const int minimumTimeToDisplayFor,
  62447. const bool useDropShadow,
  62448. const bool removeOnMouseClick)
  62449. {
  62450. setName (title);
  62451. setAlwaysOnTop (true);
  62452. setVisible (true);
  62453. centreWithSize (width, height);
  62454. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62455. toFront (false);
  62456. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62457. repaint();
  62458. originalClickCounter = removeOnMouseClick
  62459. ? Desktop::getMouseButtonClickCounter()
  62460. : std::numeric_limits<int>::max();
  62461. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62462. startTimer (50);
  62463. }
  62464. void SplashScreen::paint (Graphics& g)
  62465. {
  62466. if (backgroundImage != 0)
  62467. {
  62468. g.setOpacity (1.0f);
  62469. g.drawImage (backgroundImage,
  62470. 0, 0, getWidth(), getHeight(),
  62471. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62472. }
  62473. }
  62474. void SplashScreen::timerCallback()
  62475. {
  62476. if (Time::getCurrentTime() > earliestTimeToDelete
  62477. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62478. {
  62479. delete this;
  62480. }
  62481. }
  62482. END_JUCE_NAMESPACE
  62483. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62484. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62485. BEGIN_JUCE_NAMESPACE
  62486. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62487. const bool hasProgressBar,
  62488. const bool hasCancelButton,
  62489. const int timeOutMsWhenCancelling_,
  62490. const String& cancelButtonText)
  62491. : Thread ("Juce Progress Window"),
  62492. progress (0.0),
  62493. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62494. {
  62495. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62496. .createAlertWindow (title, String::empty, cancelButtonText,
  62497. String::empty, String::empty,
  62498. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62499. if (hasProgressBar)
  62500. alertWindow->addProgressBarComponent (progress);
  62501. }
  62502. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62503. {
  62504. stopThread (timeOutMsWhenCancelling);
  62505. }
  62506. bool ThreadWithProgressWindow::runThread (const int priority)
  62507. {
  62508. startThread (priority);
  62509. startTimer (100);
  62510. {
  62511. const ScopedLock sl (messageLock);
  62512. alertWindow->setMessage (message);
  62513. }
  62514. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62515. stopThread (timeOutMsWhenCancelling);
  62516. alertWindow->setVisible (false);
  62517. return finishedNaturally;
  62518. }
  62519. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62520. {
  62521. progress = newProgress;
  62522. }
  62523. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62524. {
  62525. const ScopedLock sl (messageLock);
  62526. message = newStatusMessage;
  62527. }
  62528. void ThreadWithProgressWindow::timerCallback()
  62529. {
  62530. if (! isThreadRunning())
  62531. {
  62532. // thread has finished normally..
  62533. alertWindow->exitModalState (1);
  62534. alertWindow->setVisible (false);
  62535. }
  62536. else
  62537. {
  62538. const ScopedLock sl (messageLock);
  62539. alertWindow->setMessage (message);
  62540. }
  62541. }
  62542. END_JUCE_NAMESPACE
  62543. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62544. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62545. BEGIN_JUCE_NAMESPACE
  62546. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62547. const int millisecondsBeforeTipAppears_)
  62548. : Component ("tooltip"),
  62549. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62550. lastHideTime (0),
  62551. lastComponentUnderMouse (0),
  62552. changedCompsSinceShown (true)
  62553. {
  62554. startTimer (123);
  62555. setAlwaysOnTop (true);
  62556. setOpaque (true);
  62557. if (parentComponent != 0)
  62558. parentComponent->addChildComponent (this);
  62559. }
  62560. TooltipWindow::~TooltipWindow()
  62561. {
  62562. hide();
  62563. }
  62564. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62565. {
  62566. millisecondsBeforeTipAppears = newTimeMs;
  62567. }
  62568. void TooltipWindow::paint (Graphics& g)
  62569. {
  62570. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62571. }
  62572. void TooltipWindow::mouseEnter (const MouseEvent&)
  62573. {
  62574. hide();
  62575. }
  62576. void TooltipWindow::showFor (const String& tip)
  62577. {
  62578. jassert (tip.isNotEmpty());
  62579. tipShowing = tip;
  62580. Point<int> mousePos (Desktop::getMousePosition());
  62581. if (getParentComponent() != 0)
  62582. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62583. int x, y, w, h;
  62584. getLookAndFeel().getTooltipSize (tip, w, h);
  62585. if (mousePos.getX() > getParentWidth() / 2)
  62586. x = mousePos.getX() - (w + 12);
  62587. else
  62588. x = mousePos.getX() + 24;
  62589. if (mousePos.getY() > getParentHeight() / 2)
  62590. y = mousePos.getY() - (h + 6);
  62591. else
  62592. y = mousePos.getY() + 6;
  62593. setBounds (x, y, w, h);
  62594. setVisible (true);
  62595. if (getParentComponent() == 0)
  62596. {
  62597. addToDesktop (ComponentPeer::windowHasDropShadow
  62598. | ComponentPeer::windowIsTemporary
  62599. | ComponentPeer::windowIgnoresKeyPresses);
  62600. }
  62601. toFront (false);
  62602. }
  62603. const String TooltipWindow::getTipFor (Component* const c)
  62604. {
  62605. if (c != 0
  62606. && Process::isForegroundProcess()
  62607. && ! Component::isMouseButtonDownAnywhere())
  62608. {
  62609. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62610. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62611. return ttc->getTooltip();
  62612. }
  62613. return String::empty;
  62614. }
  62615. void TooltipWindow::hide()
  62616. {
  62617. tipShowing = String::empty;
  62618. removeFromDesktop();
  62619. setVisible (false);
  62620. }
  62621. void TooltipWindow::timerCallback()
  62622. {
  62623. const unsigned int now = Time::getApproximateMillisecondCounter();
  62624. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  62625. const String newTip (getTipFor (newComp));
  62626. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62627. lastComponentUnderMouse = newComp;
  62628. lastTipUnderMouse = newTip;
  62629. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62630. const bool mouseWasClicked = clickCount > mouseClicks;
  62631. mouseClicks = clickCount;
  62632. const Point<int> mousePos (Desktop::getMousePosition());
  62633. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62634. lastMousePos = mousePos;
  62635. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62636. lastCompChangeTime = now;
  62637. if (isVisible() || now < lastHideTime + 500)
  62638. {
  62639. // if a tip is currently visible (or has just disappeared), update to a new one
  62640. // immediately if needed..
  62641. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62642. {
  62643. if (isVisible())
  62644. {
  62645. lastHideTime = now;
  62646. hide();
  62647. }
  62648. }
  62649. else if (tipChanged)
  62650. {
  62651. showFor (newTip);
  62652. }
  62653. }
  62654. else
  62655. {
  62656. // if there isn't currently a tip, but one is needed, only let it
  62657. // appear after a timeout..
  62658. if (newTip.isNotEmpty()
  62659. && newTip != tipShowing
  62660. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62661. {
  62662. showFor (newTip);
  62663. }
  62664. }
  62665. }
  62666. END_JUCE_NAMESPACE
  62667. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62668. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62669. BEGIN_JUCE_NAMESPACE
  62670. class TopLevelWindowManager : public Timer,
  62671. public DeletedAtShutdown
  62672. {
  62673. public:
  62674. TopLevelWindowManager()
  62675. : currentActive (0)
  62676. {
  62677. }
  62678. ~TopLevelWindowManager()
  62679. {
  62680. clearSingletonInstance();
  62681. }
  62682. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62683. void timerCallback()
  62684. {
  62685. startTimer (jmin (1731, getTimerInterval() * 2));
  62686. TopLevelWindow* active = 0;
  62687. if (Process::isForegroundProcess())
  62688. {
  62689. active = currentActive;
  62690. Component* const c = Component::getCurrentlyFocusedComponent();
  62691. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  62692. if (tlw == 0 && c != 0)
  62693. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  62694. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  62695. if (tlw != 0)
  62696. active = tlw;
  62697. }
  62698. if (active != currentActive)
  62699. {
  62700. currentActive = active;
  62701. for (int i = windows.size(); --i >= 0;)
  62702. {
  62703. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  62704. tlw->setWindowActive (isWindowActive (tlw));
  62705. i = jmin (i, windows.size() - 1);
  62706. }
  62707. Desktop::getInstance().triggerFocusCallback();
  62708. }
  62709. }
  62710. bool addWindow (TopLevelWindow* const w) throw()
  62711. {
  62712. windows.add (w);
  62713. startTimer (10);
  62714. return isWindowActive (w);
  62715. }
  62716. void removeWindow (TopLevelWindow* const w) throw()
  62717. {
  62718. startTimer (10);
  62719. if (currentActive == w)
  62720. currentActive = 0;
  62721. windows.removeValue (w);
  62722. if (windows.size() == 0)
  62723. deleteInstance();
  62724. }
  62725. VoidArray windows;
  62726. private:
  62727. TopLevelWindow* currentActive;
  62728. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  62729. {
  62730. return (tlw == currentActive
  62731. || tlw->isParentOf (currentActive)
  62732. || tlw->hasKeyboardFocus (true))
  62733. && tlw->isShowing();
  62734. }
  62735. TopLevelWindowManager (const TopLevelWindowManager&);
  62736. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  62737. };
  62738. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  62739. void juce_CheckCurrentlyFocusedTopLevelWindow()
  62740. {
  62741. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  62742. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  62743. }
  62744. TopLevelWindow::TopLevelWindow (const String& name,
  62745. const bool addToDesktop_)
  62746. : Component (name),
  62747. useDropShadow (true),
  62748. useNativeTitleBar (false),
  62749. windowIsActive_ (false)
  62750. {
  62751. setOpaque (true);
  62752. if (addToDesktop_)
  62753. Component::addToDesktop (getDesktopWindowStyleFlags());
  62754. else
  62755. setDropShadowEnabled (true);
  62756. setWantsKeyboardFocus (true);
  62757. setBroughtToFrontOnMouseClick (true);
  62758. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  62759. }
  62760. TopLevelWindow::~TopLevelWindow()
  62761. {
  62762. shadower = 0;
  62763. TopLevelWindowManager::getInstance()->removeWindow (this);
  62764. }
  62765. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  62766. {
  62767. if (hasKeyboardFocus (true))
  62768. TopLevelWindowManager::getInstance()->timerCallback();
  62769. else
  62770. TopLevelWindowManager::getInstance()->startTimer (10);
  62771. }
  62772. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  62773. {
  62774. if (windowIsActive_ != isNowActive)
  62775. {
  62776. windowIsActive_ = isNowActive;
  62777. activeWindowStatusChanged();
  62778. }
  62779. }
  62780. void TopLevelWindow::activeWindowStatusChanged()
  62781. {
  62782. }
  62783. void TopLevelWindow::parentHierarchyChanged()
  62784. {
  62785. setDropShadowEnabled (useDropShadow);
  62786. }
  62787. void TopLevelWindow::visibilityChanged()
  62788. {
  62789. if (isShowing())
  62790. toFront (true);
  62791. }
  62792. int TopLevelWindow::getDesktopWindowStyleFlags() const
  62793. {
  62794. int flags = ComponentPeer::windowAppearsOnTaskbar;
  62795. if (useDropShadow)
  62796. flags |= ComponentPeer::windowHasDropShadow;
  62797. if (useNativeTitleBar)
  62798. flags |= ComponentPeer::windowHasTitleBar;
  62799. return flags;
  62800. }
  62801. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  62802. {
  62803. useDropShadow = useShadow;
  62804. if (isOnDesktop())
  62805. {
  62806. shadower = 0;
  62807. Component::addToDesktop (getDesktopWindowStyleFlags());
  62808. }
  62809. else
  62810. {
  62811. if (useShadow && isOpaque())
  62812. {
  62813. if (shadower == 0)
  62814. {
  62815. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  62816. if (shadower != 0)
  62817. shadower->setOwner (this);
  62818. }
  62819. }
  62820. else
  62821. {
  62822. shadower = 0;
  62823. }
  62824. }
  62825. }
  62826. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  62827. {
  62828. if (useNativeTitleBar != useNativeTitleBar_)
  62829. {
  62830. useNativeTitleBar = useNativeTitleBar_;
  62831. recreateDesktopWindow();
  62832. sendLookAndFeelChange();
  62833. }
  62834. }
  62835. void TopLevelWindow::recreateDesktopWindow()
  62836. {
  62837. if (isOnDesktop())
  62838. {
  62839. Component::addToDesktop (getDesktopWindowStyleFlags());
  62840. toFront (true);
  62841. }
  62842. }
  62843. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  62844. {
  62845. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  62846. because this class needs to make sure its layout corresponds with settings like whether
  62847. it's got a native title bar or not.
  62848. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  62849. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  62850. method, then add or remove whatever flags are necessary from this value before returning it.
  62851. */
  62852. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  62853. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  62854. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  62855. if (windowStyleFlags != getDesktopWindowStyleFlags())
  62856. sendLookAndFeelChange();
  62857. }
  62858. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  62859. {
  62860. if (c == 0)
  62861. c = TopLevelWindow::getActiveTopLevelWindow();
  62862. if (c == 0)
  62863. {
  62864. centreWithSize (width, height);
  62865. }
  62866. else
  62867. {
  62868. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  62869. (c->getHeight() - height) / 2)));
  62870. Rectangle<int> parentArea (c->getParentMonitorArea());
  62871. if (getParentComponent() != 0)
  62872. {
  62873. p = getParentComponent()->globalPositionToRelative (p);
  62874. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  62875. }
  62876. parentArea.reduce (12, 12);
  62877. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  62878. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  62879. width, height);
  62880. }
  62881. }
  62882. int TopLevelWindow::getNumTopLevelWindows() throw()
  62883. {
  62884. return TopLevelWindowManager::getInstance()->windows.size();
  62885. }
  62886. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  62887. {
  62888. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  62889. }
  62890. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  62891. {
  62892. TopLevelWindow* best = 0;
  62893. int bestNumTWLParents = -1;
  62894. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  62895. {
  62896. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  62897. if (tlw->isActiveWindow())
  62898. {
  62899. int numTWLParents = 0;
  62900. const Component* c = tlw->getParentComponent();
  62901. while (c != 0)
  62902. {
  62903. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  62904. ++numTWLParents;
  62905. c = c->getParentComponent();
  62906. }
  62907. if (bestNumTWLParents < numTWLParents)
  62908. {
  62909. best = tlw;
  62910. bestNumTWLParents = numTWLParents;
  62911. }
  62912. }
  62913. }
  62914. return best;
  62915. }
  62916. END_JUCE_NAMESPACE
  62917. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  62918. /*** Start of inlined file: juce_Colour.cpp ***/
  62919. BEGIN_JUCE_NAMESPACE
  62920. namespace ColourHelpers
  62921. {
  62922. static uint8 floatAlphaToInt (const float alpha) throw()
  62923. {
  62924. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  62925. }
  62926. static void convertHSBtoRGB (float h, float s, float v,
  62927. uint8& r, uint8& g, uint8& b) throw()
  62928. {
  62929. v = jlimit (0.0f, 1.0f, v);
  62930. v *= 255.0f;
  62931. const uint8 intV = (uint8) roundToInt (v);
  62932. if (s <= 0)
  62933. {
  62934. r = intV;
  62935. g = intV;
  62936. b = intV;
  62937. }
  62938. else
  62939. {
  62940. s = jmin (1.0f, s);
  62941. h = jlimit (0.0f, 1.0f, h);
  62942. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  62943. const float f = h - floorf (h);
  62944. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  62945. const float y = v * (1.0f - s * f);
  62946. const float z = v * (1.0f - (s * (1.0f - f)));
  62947. if (h < 1.0f)
  62948. {
  62949. r = intV;
  62950. g = (uint8) roundToInt (z);
  62951. b = x;
  62952. }
  62953. else if (h < 2.0f)
  62954. {
  62955. r = (uint8) roundToInt (y);
  62956. g = intV;
  62957. b = x;
  62958. }
  62959. else if (h < 3.0f)
  62960. {
  62961. r = x;
  62962. g = intV;
  62963. b = (uint8) roundToInt (z);
  62964. }
  62965. else if (h < 4.0f)
  62966. {
  62967. r = x;
  62968. g = (uint8) roundToInt (y);
  62969. b = intV;
  62970. }
  62971. else if (h < 5.0f)
  62972. {
  62973. r = (uint8) roundToInt (z);
  62974. g = x;
  62975. b = intV;
  62976. }
  62977. else if (h < 6.0f)
  62978. {
  62979. r = intV;
  62980. g = x;
  62981. b = (uint8) roundToInt (y);
  62982. }
  62983. else
  62984. {
  62985. r = 0;
  62986. g = 0;
  62987. b = 0;
  62988. }
  62989. }
  62990. }
  62991. }
  62992. Colour::Colour() throw()
  62993. : argb (0)
  62994. {
  62995. }
  62996. Colour::Colour (const Colour& other) throw()
  62997. : argb (other.argb)
  62998. {
  62999. }
  63000. Colour& Colour::operator= (const Colour& other) throw()
  63001. {
  63002. argb = other.argb;
  63003. return *this;
  63004. }
  63005. bool Colour::operator== (const Colour& other) const throw()
  63006. {
  63007. return argb.getARGB() == other.argb.getARGB();
  63008. }
  63009. bool Colour::operator!= (const Colour& other) const throw()
  63010. {
  63011. return argb.getARGB() != other.argb.getARGB();
  63012. }
  63013. Colour::Colour (const uint32 argb_) throw()
  63014. : argb (argb_)
  63015. {
  63016. }
  63017. Colour::Colour (const uint8 red,
  63018. const uint8 green,
  63019. const uint8 blue) throw()
  63020. {
  63021. argb.setARGB (0xff, red, green, blue);
  63022. }
  63023. const Colour Colour::fromRGB (const uint8 red,
  63024. const uint8 green,
  63025. const uint8 blue) throw()
  63026. {
  63027. return Colour (red, green, blue);
  63028. }
  63029. Colour::Colour (const uint8 red,
  63030. const uint8 green,
  63031. const uint8 blue,
  63032. const uint8 alpha) throw()
  63033. {
  63034. argb.setARGB (alpha, red, green, blue);
  63035. }
  63036. const Colour Colour::fromRGBA (const uint8 red,
  63037. const uint8 green,
  63038. const uint8 blue,
  63039. const uint8 alpha) throw()
  63040. {
  63041. return Colour (red, green, blue, alpha);
  63042. }
  63043. Colour::Colour (const uint8 red,
  63044. const uint8 green,
  63045. const uint8 blue,
  63046. const float alpha) throw()
  63047. {
  63048. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), red, green, blue);
  63049. }
  63050. const Colour Colour::fromRGBAFloat (const uint8 red,
  63051. const uint8 green,
  63052. const uint8 blue,
  63053. const float alpha) throw()
  63054. {
  63055. return Colour (red, green, blue, alpha);
  63056. }
  63057. Colour::Colour (const float hue,
  63058. const float saturation,
  63059. const float brightness,
  63060. const float alpha) throw()
  63061. {
  63062. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63063. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63064. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), r, g, b);
  63065. }
  63066. const Colour Colour::fromHSV (const float hue,
  63067. const float saturation,
  63068. const float brightness,
  63069. const float alpha) throw()
  63070. {
  63071. return Colour (hue, saturation, brightness, alpha);
  63072. }
  63073. Colour::Colour (const float hue,
  63074. const float saturation,
  63075. const float brightness,
  63076. const uint8 alpha) throw()
  63077. {
  63078. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63079. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63080. argb.setARGB (alpha, r, g, b);
  63081. }
  63082. Colour::~Colour() throw()
  63083. {
  63084. }
  63085. const PixelARGB Colour::getPixelARGB() const throw()
  63086. {
  63087. PixelARGB p (argb);
  63088. p.premultiply();
  63089. return p;
  63090. }
  63091. uint32 Colour::getARGB() const throw()
  63092. {
  63093. return argb.getARGB();
  63094. }
  63095. bool Colour::isTransparent() const throw()
  63096. {
  63097. return getAlpha() == 0;
  63098. }
  63099. bool Colour::isOpaque() const throw()
  63100. {
  63101. return getAlpha() == 0xff;
  63102. }
  63103. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63104. {
  63105. PixelARGB newCol (argb);
  63106. newCol.setAlpha (newAlpha);
  63107. return Colour (newCol.getARGB());
  63108. }
  63109. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63110. {
  63111. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63112. PixelARGB newCol (argb);
  63113. newCol.setAlpha (ColourHelpers::floatAlphaToInt (newAlpha));
  63114. return Colour (newCol.getARGB());
  63115. }
  63116. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63117. {
  63118. jassert (alphaMultiplier >= 0);
  63119. PixelARGB newCol (argb);
  63120. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63121. return Colour (newCol.getARGB());
  63122. }
  63123. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63124. {
  63125. const int destAlpha = getAlpha();
  63126. if (destAlpha > 0)
  63127. {
  63128. const int invA = 0xff - (int) src.getAlpha();
  63129. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63130. if (resA > 0)
  63131. {
  63132. const int da = (invA * destAlpha) / resA;
  63133. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63134. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63135. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63136. (uint8) resA);
  63137. }
  63138. return *this;
  63139. }
  63140. else
  63141. {
  63142. return src;
  63143. }
  63144. }
  63145. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63146. {
  63147. if (proportionOfOther <= 0)
  63148. return *this;
  63149. if (proportionOfOther >= 1.0f)
  63150. return other;
  63151. PixelARGB c1 (getPixelARGB());
  63152. const PixelARGB c2 (other.getPixelARGB());
  63153. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63154. c1.unpremultiply();
  63155. return Colour (c1.getARGB());
  63156. }
  63157. float Colour::getFloatRed() const throw()
  63158. {
  63159. return getRed() / 255.0f;
  63160. }
  63161. float Colour::getFloatGreen() const throw()
  63162. {
  63163. return getGreen() / 255.0f;
  63164. }
  63165. float Colour::getFloatBlue() const throw()
  63166. {
  63167. return getBlue() / 255.0f;
  63168. }
  63169. float Colour::getFloatAlpha() const throw()
  63170. {
  63171. return getAlpha() / 255.0f;
  63172. }
  63173. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63174. {
  63175. const int r = getRed();
  63176. const int g = getGreen();
  63177. const int b = getBlue();
  63178. const int hi = jmax (r, g, b);
  63179. const int lo = jmin (r, g, b);
  63180. if (hi != 0)
  63181. {
  63182. s = (hi - lo) / (float) hi;
  63183. if (s != 0)
  63184. {
  63185. const float invDiff = 1.0f / (hi - lo);
  63186. const float red = (hi - r) * invDiff;
  63187. const float green = (hi - g) * invDiff;
  63188. const float blue = (hi - b) * invDiff;
  63189. if (r == hi)
  63190. h = blue - green;
  63191. else if (g == hi)
  63192. h = 2.0f + red - blue;
  63193. else
  63194. h = 4.0f + green - red;
  63195. h *= 1.0f / 6.0f;
  63196. if (h < 0)
  63197. ++h;
  63198. }
  63199. else
  63200. {
  63201. h = 0;
  63202. }
  63203. }
  63204. else
  63205. {
  63206. s = 0;
  63207. h = 0;
  63208. }
  63209. v = hi / 255.0f;
  63210. }
  63211. float Colour::getHue() const throw()
  63212. {
  63213. float h, s, b;
  63214. getHSB (h, s, b);
  63215. return h;
  63216. }
  63217. const Colour Colour::withHue (const float hue) const throw()
  63218. {
  63219. float h, s, b;
  63220. getHSB (h, s, b);
  63221. return Colour (hue, s, b, getAlpha());
  63222. }
  63223. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63224. {
  63225. float h, s, b;
  63226. getHSB (h, s, b);
  63227. h += amountToRotate;
  63228. h -= floorf (h);
  63229. return Colour (h, s, b, getAlpha());
  63230. }
  63231. float Colour::getSaturation() const throw()
  63232. {
  63233. float h, s, b;
  63234. getHSB (h, s, b);
  63235. return s;
  63236. }
  63237. const Colour Colour::withSaturation (const float saturation) const throw()
  63238. {
  63239. float h, s, b;
  63240. getHSB (h, s, b);
  63241. return Colour (h, saturation, b, getAlpha());
  63242. }
  63243. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63244. {
  63245. float h, s, b;
  63246. getHSB (h, s, b);
  63247. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63248. }
  63249. float Colour::getBrightness() const throw()
  63250. {
  63251. float h, s, b;
  63252. getHSB (h, s, b);
  63253. return b;
  63254. }
  63255. const Colour Colour::withBrightness (const float brightness) const throw()
  63256. {
  63257. float h, s, b;
  63258. getHSB (h, s, b);
  63259. return Colour (h, s, brightness, getAlpha());
  63260. }
  63261. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63262. {
  63263. float h, s, b;
  63264. getHSB (h, s, b);
  63265. b *= amount;
  63266. if (b > 1.0f)
  63267. b = 1.0f;
  63268. return Colour (h, s, b, getAlpha());
  63269. }
  63270. const Colour Colour::brighter (float amount) const throw()
  63271. {
  63272. amount = 1.0f / (1.0f + amount);
  63273. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63274. (uint8) (255 - (amount * (255 - getGreen()))),
  63275. (uint8) (255 - (amount * (255 - getBlue()))),
  63276. getAlpha());
  63277. }
  63278. const Colour Colour::darker (float amount) const throw()
  63279. {
  63280. amount = 1.0f / (1.0f + amount);
  63281. return Colour ((uint8) (amount * getRed()),
  63282. (uint8) (amount * getGreen()),
  63283. (uint8) (amount * getBlue()),
  63284. getAlpha());
  63285. }
  63286. const Colour Colour::greyLevel (const float brightness) throw()
  63287. {
  63288. const uint8 level
  63289. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63290. return Colour (level, level, level);
  63291. }
  63292. const Colour Colour::contrasting (const float amount) const throw()
  63293. {
  63294. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63295. ? Colours::black
  63296. : Colours::white).withAlpha (amount));
  63297. }
  63298. const Colour Colour::contrasting (const Colour& colour1,
  63299. const Colour& colour2) throw()
  63300. {
  63301. const float b1 = colour1.getBrightness();
  63302. const float b2 = colour2.getBrightness();
  63303. float best = 0.0f;
  63304. float bestDist = 0.0f;
  63305. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63306. {
  63307. const float d1 = fabsf (i - b1);
  63308. const float d2 = fabsf (i - b2);
  63309. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63310. if (dist > bestDist)
  63311. {
  63312. best = i;
  63313. bestDist = dist;
  63314. }
  63315. }
  63316. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63317. .withBrightness (best);
  63318. }
  63319. const String Colour::toString() const
  63320. {
  63321. return String::toHexString ((int) argb.getARGB());
  63322. }
  63323. const Colour Colour::fromString (const String& encodedColourString)
  63324. {
  63325. return Colour ((uint32) encodedColourString.getHexValue32());
  63326. }
  63327. const String Colour::toDisplayString (const bool includeAlphaValue) const
  63328. {
  63329. return String::toHexString ((int) (argb.getARGB() & (includeAlphaValue ? 0xffffffff : 0xffffff)))
  63330. .paddedLeft ('0', includeAlphaValue ? 8 : 6)
  63331. .toUpperCase();
  63332. }
  63333. END_JUCE_NAMESPACE
  63334. /*** End of inlined file: juce_Colour.cpp ***/
  63335. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63336. BEGIN_JUCE_NAMESPACE
  63337. ColourGradient::ColourGradient() throw()
  63338. {
  63339. #ifdef JUCE_DEBUG
  63340. x1 = 987654.0f;
  63341. #endif
  63342. }
  63343. ColourGradient::ColourGradient (const Colour& colour1,
  63344. const float x1_,
  63345. const float y1_,
  63346. const Colour& colour2,
  63347. const float x2_,
  63348. const float y2_,
  63349. const bool isRadial_) throw()
  63350. : x1 (x1_),
  63351. y1 (y1_),
  63352. x2 (x2_),
  63353. y2 (y2_),
  63354. isRadial (isRadial_)
  63355. {
  63356. colours.add (0);
  63357. colours.add (colour1.getARGB());
  63358. colours.add (1 << 16);
  63359. colours.add (colour2.getARGB());
  63360. }
  63361. ColourGradient::~ColourGradient() throw()
  63362. {
  63363. }
  63364. void ColourGradient::clearColours() throw()
  63365. {
  63366. colours.clear();
  63367. }
  63368. void ColourGradient::addColour (const double proportionAlongGradient,
  63369. const Colour& colour) throw()
  63370. {
  63371. // must be within the two end-points
  63372. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63373. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63374. int i;
  63375. for (i = 0; i < colours.size(); i += 2)
  63376. if (colours.getUnchecked(i) > pos)
  63377. break;
  63378. colours.insert (i, pos);
  63379. colours.insert (i + 1, colour.getARGB());
  63380. }
  63381. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63382. {
  63383. for (int i = 1; i < colours.size(); i += 2)
  63384. {
  63385. const Colour c (colours.getUnchecked(i));
  63386. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63387. }
  63388. }
  63389. int ColourGradient::getNumColours() const throw()
  63390. {
  63391. return colours.size() >> 1;
  63392. }
  63393. double ColourGradient::getColourPosition (const int index) const throw()
  63394. {
  63395. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63396. }
  63397. const Colour ColourGradient::getColour (const int index) const throw()
  63398. {
  63399. return Colour (colours [(index << 1) + 1]);
  63400. }
  63401. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63402. {
  63403. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63404. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63405. if (integerPos <= 0 || colours.size() <= 2)
  63406. return getColour (0);
  63407. int i = colours.size() - 2;
  63408. while (integerPos < (int) colours.getUnchecked(i))
  63409. i -= 2;
  63410. if (i >= colours.size() - 2)
  63411. return Colour (colours.getUnchecked(i));
  63412. const int pos1 = colours.getUnchecked (i);
  63413. const Colour col1 (colours.getUnchecked (i + 1));
  63414. const int pos2 = colours.getUnchecked (i + 2);
  63415. const Colour col2 (colours.getUnchecked (i + 3));
  63416. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63417. }
  63418. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63419. {
  63420. #ifdef JUCE_DEBUG
  63421. // trying to use the object without setting its co-ordinates? Have a careful read of
  63422. // the comments for the constructors.
  63423. jassert (x1 != 987654.0f);
  63424. #endif
  63425. const int numColours = colours.size() >> 1;
  63426. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63427. transform.transformPoint (tx1, ty1);
  63428. transform.transformPoint (tx2, ty2);
  63429. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63430. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63431. lookupTable.malloc (numEntries);
  63432. if (numColours >= 2)
  63433. {
  63434. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63435. PixelARGB pix1 (colours.getUnchecked (1));
  63436. pix1.premultiply();
  63437. int index = 0;
  63438. for (int j = 2; j < colours.size(); j += 2)
  63439. {
  63440. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63441. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63442. pix2.premultiply();
  63443. for (int i = 0; i < numToDo; ++i)
  63444. {
  63445. jassert (index >= 0 && index < numEntries);
  63446. lookupTable[index] = pix1;
  63447. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63448. ++index;
  63449. }
  63450. pix1 = pix2;
  63451. }
  63452. while (index < numEntries)
  63453. lookupTable [index++] = pix1;
  63454. }
  63455. else
  63456. {
  63457. jassertfalse // no colours specified!
  63458. }
  63459. return numEntries;
  63460. }
  63461. bool ColourGradient::isOpaque() const throw()
  63462. {
  63463. for (int i = 1; i < colours.size(); i += 2)
  63464. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63465. return false;
  63466. return true;
  63467. }
  63468. bool ColourGradient::isInvisible() const throw()
  63469. {
  63470. for (int i = 1; i < colours.size(); i += 2)
  63471. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63472. return false;
  63473. return true;
  63474. }
  63475. END_JUCE_NAMESPACE
  63476. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63477. /*** Start of inlined file: juce_Colours.cpp ***/
  63478. BEGIN_JUCE_NAMESPACE
  63479. const Colour Colours::transparentBlack (0);
  63480. const Colour Colours::transparentWhite (0x00ffffff);
  63481. const Colour Colours::aliceblue (0xfff0f8ff);
  63482. const Colour Colours::antiquewhite (0xfffaebd7);
  63483. const Colour Colours::aqua (0xff00ffff);
  63484. const Colour Colours::aquamarine (0xff7fffd4);
  63485. const Colour Colours::azure (0xfff0ffff);
  63486. const Colour Colours::beige (0xfff5f5dc);
  63487. const Colour Colours::bisque (0xffffe4c4);
  63488. const Colour Colours::black (0xff000000);
  63489. const Colour Colours::blanchedalmond (0xffffebcd);
  63490. const Colour Colours::blue (0xff0000ff);
  63491. const Colour Colours::blueviolet (0xff8a2be2);
  63492. const Colour Colours::brown (0xffa52a2a);
  63493. const Colour Colours::burlywood (0xffdeb887);
  63494. const Colour Colours::cadetblue (0xff5f9ea0);
  63495. const Colour Colours::chartreuse (0xff7fff00);
  63496. const Colour Colours::chocolate (0xffd2691e);
  63497. const Colour Colours::coral (0xffff7f50);
  63498. const Colour Colours::cornflowerblue (0xff6495ed);
  63499. const Colour Colours::cornsilk (0xfffff8dc);
  63500. const Colour Colours::crimson (0xffdc143c);
  63501. const Colour Colours::cyan (0xff00ffff);
  63502. const Colour Colours::darkblue (0xff00008b);
  63503. const Colour Colours::darkcyan (0xff008b8b);
  63504. const Colour Colours::darkgoldenrod (0xffb8860b);
  63505. const Colour Colours::darkgrey (0xff555555);
  63506. const Colour Colours::darkgreen (0xff006400);
  63507. const Colour Colours::darkkhaki (0xffbdb76b);
  63508. const Colour Colours::darkmagenta (0xff8b008b);
  63509. const Colour Colours::darkolivegreen (0xff556b2f);
  63510. const Colour Colours::darkorange (0xffff8c00);
  63511. const Colour Colours::darkorchid (0xff9932cc);
  63512. const Colour Colours::darkred (0xff8b0000);
  63513. const Colour Colours::darksalmon (0xffe9967a);
  63514. const Colour Colours::darkseagreen (0xff8fbc8f);
  63515. const Colour Colours::darkslateblue (0xff483d8b);
  63516. const Colour Colours::darkslategrey (0xff2f4f4f);
  63517. const Colour Colours::darkturquoise (0xff00ced1);
  63518. const Colour Colours::darkviolet (0xff9400d3);
  63519. const Colour Colours::deeppink (0xffff1493);
  63520. const Colour Colours::deepskyblue (0xff00bfff);
  63521. const Colour Colours::dimgrey (0xff696969);
  63522. const Colour Colours::dodgerblue (0xff1e90ff);
  63523. const Colour Colours::firebrick (0xffb22222);
  63524. const Colour Colours::floralwhite (0xfffffaf0);
  63525. const Colour Colours::forestgreen (0xff228b22);
  63526. const Colour Colours::fuchsia (0xffff00ff);
  63527. const Colour Colours::gainsboro (0xffdcdcdc);
  63528. const Colour Colours::gold (0xffffd700);
  63529. const Colour Colours::goldenrod (0xffdaa520);
  63530. const Colour Colours::grey (0xff808080);
  63531. const Colour Colours::green (0xff008000);
  63532. const Colour Colours::greenyellow (0xffadff2f);
  63533. const Colour Colours::honeydew (0xfff0fff0);
  63534. const Colour Colours::hotpink (0xffff69b4);
  63535. const Colour Colours::indianred (0xffcd5c5c);
  63536. const Colour Colours::indigo (0xff4b0082);
  63537. const Colour Colours::ivory (0xfffffff0);
  63538. const Colour Colours::khaki (0xfff0e68c);
  63539. const Colour Colours::lavender (0xffe6e6fa);
  63540. const Colour Colours::lavenderblush (0xfffff0f5);
  63541. const Colour Colours::lemonchiffon (0xfffffacd);
  63542. const Colour Colours::lightblue (0xffadd8e6);
  63543. const Colour Colours::lightcoral (0xfff08080);
  63544. const Colour Colours::lightcyan (0xffe0ffff);
  63545. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63546. const Colour Colours::lightgreen (0xff90ee90);
  63547. const Colour Colours::lightgrey (0xffd3d3d3);
  63548. const Colour Colours::lightpink (0xffffb6c1);
  63549. const Colour Colours::lightsalmon (0xffffa07a);
  63550. const Colour Colours::lightseagreen (0xff20b2aa);
  63551. const Colour Colours::lightskyblue (0xff87cefa);
  63552. const Colour Colours::lightslategrey (0xff778899);
  63553. const Colour Colours::lightsteelblue (0xffb0c4de);
  63554. const Colour Colours::lightyellow (0xffffffe0);
  63555. const Colour Colours::lime (0xff00ff00);
  63556. const Colour Colours::limegreen (0xff32cd32);
  63557. const Colour Colours::linen (0xfffaf0e6);
  63558. const Colour Colours::magenta (0xffff00ff);
  63559. const Colour Colours::maroon (0xff800000);
  63560. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63561. const Colour Colours::mediumblue (0xff0000cd);
  63562. const Colour Colours::mediumorchid (0xffba55d3);
  63563. const Colour Colours::mediumpurple (0xff9370db);
  63564. const Colour Colours::mediumseagreen (0xff3cb371);
  63565. const Colour Colours::mediumslateblue (0xff7b68ee);
  63566. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63567. const Colour Colours::mediumturquoise (0xff48d1cc);
  63568. const Colour Colours::mediumvioletred (0xffc71585);
  63569. const Colour Colours::midnightblue (0xff191970);
  63570. const Colour Colours::mintcream (0xfff5fffa);
  63571. const Colour Colours::mistyrose (0xffffe4e1);
  63572. const Colour Colours::navajowhite (0xffffdead);
  63573. const Colour Colours::navy (0xff000080);
  63574. const Colour Colours::oldlace (0xfffdf5e6);
  63575. const Colour Colours::olive (0xff808000);
  63576. const Colour Colours::olivedrab (0xff6b8e23);
  63577. const Colour Colours::orange (0xffffa500);
  63578. const Colour Colours::orangered (0xffff4500);
  63579. const Colour Colours::orchid (0xffda70d6);
  63580. const Colour Colours::palegoldenrod (0xffeee8aa);
  63581. const Colour Colours::palegreen (0xff98fb98);
  63582. const Colour Colours::paleturquoise (0xffafeeee);
  63583. const Colour Colours::palevioletred (0xffdb7093);
  63584. const Colour Colours::papayawhip (0xffffefd5);
  63585. const Colour Colours::peachpuff (0xffffdab9);
  63586. const Colour Colours::peru (0xffcd853f);
  63587. const Colour Colours::pink (0xffffc0cb);
  63588. const Colour Colours::plum (0xffdda0dd);
  63589. const Colour Colours::powderblue (0xffb0e0e6);
  63590. const Colour Colours::purple (0xff800080);
  63591. const Colour Colours::red (0xffff0000);
  63592. const Colour Colours::rosybrown (0xffbc8f8f);
  63593. const Colour Colours::royalblue (0xff4169e1);
  63594. const Colour Colours::saddlebrown (0xff8b4513);
  63595. const Colour Colours::salmon (0xfffa8072);
  63596. const Colour Colours::sandybrown (0xfff4a460);
  63597. const Colour Colours::seagreen (0xff2e8b57);
  63598. const Colour Colours::seashell (0xfffff5ee);
  63599. const Colour Colours::sienna (0xffa0522d);
  63600. const Colour Colours::silver (0xffc0c0c0);
  63601. const Colour Colours::skyblue (0xff87ceeb);
  63602. const Colour Colours::slateblue (0xff6a5acd);
  63603. const Colour Colours::slategrey (0xff708090);
  63604. const Colour Colours::snow (0xfffffafa);
  63605. const Colour Colours::springgreen (0xff00ff7f);
  63606. const Colour Colours::steelblue (0xff4682b4);
  63607. const Colour Colours::tan (0xffd2b48c);
  63608. const Colour Colours::teal (0xff008080);
  63609. const Colour Colours::thistle (0xffd8bfd8);
  63610. const Colour Colours::tomato (0xffff6347);
  63611. const Colour Colours::turquoise (0xff40e0d0);
  63612. const Colour Colours::violet (0xffee82ee);
  63613. const Colour Colours::wheat (0xfff5deb3);
  63614. const Colour Colours::white (0xffffffff);
  63615. const Colour Colours::whitesmoke (0xfff5f5f5);
  63616. const Colour Colours::yellow (0xffffff00);
  63617. const Colour Colours::yellowgreen (0xff9acd32);
  63618. const Colour Colours::findColourForName (const String& colourName,
  63619. const Colour& defaultColour)
  63620. {
  63621. static const int presets[] =
  63622. {
  63623. // (first value is the string's hashcode, second is ARGB)
  63624. 0x05978fff, 0xff000000, /* black */
  63625. 0x06bdcc29, 0xffffffff, /* white */
  63626. 0x002e305a, 0xff0000ff, /* blue */
  63627. 0x00308adf, 0xff808080, /* grey */
  63628. 0x05e0cf03, 0xff008000, /* green */
  63629. 0x0001b891, 0xffff0000, /* red */
  63630. 0xd43c6474, 0xffffff00, /* yellow */
  63631. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63632. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63633. 0x002dcebc, 0xff00ffff, /* aqua */
  63634. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63635. 0x0590228f, 0xfff0ffff, /* azure */
  63636. 0x05947fe4, 0xfff5f5dc, /* beige */
  63637. 0xad388e35, 0xffffe4c4, /* bisque */
  63638. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63639. 0x39129959, 0xff8a2be2, /* blueviolet */
  63640. 0x059a8136, 0xffa52a2a, /* brown */
  63641. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63642. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63643. 0x6b748956, 0xff7fff00, /* chartreuse */
  63644. 0x2903623c, 0xffd2691e, /* chocolate */
  63645. 0x05a74431, 0xffff7f50, /* coral */
  63646. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63647. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63648. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63649. 0x002ed323, 0xff00ffff, /* cyan */
  63650. 0x67cc74d0, 0xff00008b, /* darkblue */
  63651. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63652. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63653. 0x67cecf55, 0xff555555, /* darkgrey */
  63654. 0x920b194d, 0xff006400, /* darkgreen */
  63655. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63656. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63657. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63658. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63659. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63660. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63661. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63662. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63663. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63664. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63665. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63666. 0xc8769375, 0xff9400d3, /* darkviolet */
  63667. 0x25832862, 0xffff1493, /* deeppink */
  63668. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63669. 0x634c8b67, 0xff696969, /* dimgrey */
  63670. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63671. 0xef19e3cb, 0xffb22222, /* firebrick */
  63672. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63673. 0xd086fd06, 0xff228b22, /* forestgreen */
  63674. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63675. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63676. 0x00308060, 0xffffd700, /* gold */
  63677. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63678. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63679. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63680. 0x41892743, 0xffff69b4, /* hotpink */
  63681. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63682. 0xb969fed2, 0xff4b0082, /* indigo */
  63683. 0x05fef6a9, 0xfffffff0, /* ivory */
  63684. 0x06149302, 0xfff0e68c, /* khaki */
  63685. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63686. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63687. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63688. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63689. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63690. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63691. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63692. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63693. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63694. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63695. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63696. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63697. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  63698. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  63699. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  63700. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  63701. 0x0032afd5, 0xff00ff00, /* lime */
  63702. 0x607bbc4e, 0xff32cd32, /* limegreen */
  63703. 0x06234efa, 0xfffaf0e6, /* linen */
  63704. 0x316858a9, 0xffff00ff, /* magenta */
  63705. 0xbf8ca470, 0xff800000, /* maroon */
  63706. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  63707. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  63708. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  63709. 0x07556b71, 0xff9370db, /* mediumpurple */
  63710. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  63711. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  63712. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  63713. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  63714. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  63715. 0x168eb32a, 0xff191970, /* midnightblue */
  63716. 0x4306b960, 0xfff5fffa, /* mintcream */
  63717. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  63718. 0xe97218a6, 0xffffdead, /* navajowhite */
  63719. 0x00337bb6, 0xff000080, /* navy */
  63720. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  63721. 0x064ee1db, 0xff808000, /* olive */
  63722. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  63723. 0xc3de262e, 0xffffa500, /* orange */
  63724. 0x58bebba3, 0xffff4500, /* orangered */
  63725. 0xc3def8a3, 0xffda70d6, /* orchid */
  63726. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  63727. 0x3d9dd619, 0xff98fb98, /* palegreen */
  63728. 0x74022737, 0xffafeeee, /* paleturquoise */
  63729. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  63730. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  63731. 0x93e1b776, 0xffffdab9, /* peachpuff */
  63732. 0x003472f8, 0xffcd853f, /* peru */
  63733. 0x00348176, 0xffffc0cb, /* pink */
  63734. 0x00348d94, 0xffdda0dd, /* plum */
  63735. 0xd036be93, 0xffb0e0e6, /* powderblue */
  63736. 0xc5c507bc, 0xff800080, /* purple */
  63737. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  63738. 0xbd9413e1, 0xff4169e1, /* royalblue */
  63739. 0xf456044f, 0xff8b4513, /* saddlebrown */
  63740. 0xc9c6f66e, 0xfffa8072, /* salmon */
  63741. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  63742. 0x34636c14, 0xff2e8b57, /* seagreen */
  63743. 0x3507fb41, 0xfffff5ee, /* seashell */
  63744. 0xca348772, 0xffa0522d, /* sienna */
  63745. 0xca37d30d, 0xffc0c0c0, /* silver */
  63746. 0x80da74fb, 0xff87ceeb, /* skyblue */
  63747. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  63748. 0x44ab37f8, 0xff708090, /* slategrey */
  63749. 0x0035f183, 0xfffffafa, /* snow */
  63750. 0xd5440d16, 0xff00ff7f, /* springgreen */
  63751. 0x3e1524a5, 0xff4682b4, /* steelblue */
  63752. 0x0001bfa1, 0xffd2b48c, /* tan */
  63753. 0x0036425c, 0xff008080, /* teal */
  63754. 0xafc8858f, 0xffd8bfd8, /* thistle */
  63755. 0xcc41600a, 0xffff6347, /* tomato */
  63756. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  63757. 0xcf57947f, 0xffee82ee, /* violet */
  63758. 0x06bdbae7, 0xfff5deb3, /* wheat */
  63759. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  63760. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  63761. };
  63762. const int hash = colourName.trim().toLowerCase().hashCode();
  63763. for (int i = 0; i < numElementsInArray (presets); i += 2)
  63764. if (presets [i] == hash)
  63765. return Colour (presets [i + 1]);
  63766. return defaultColour;
  63767. }
  63768. END_JUCE_NAMESPACE
  63769. /*** End of inlined file: juce_Colours.cpp ***/
  63770. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  63771. BEGIN_JUCE_NAMESPACE
  63772. const int juce_edgeTableDefaultEdgesPerLine = 32;
  63773. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  63774. const Path& path, const AffineTransform& transform)
  63775. : bounds (bounds_),
  63776. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63777. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63778. needToCheckEmptinesss (true)
  63779. {
  63780. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  63781. int* t = table;
  63782. for (int i = bounds.getHeight(); --i >= 0;)
  63783. {
  63784. *t = 0;
  63785. t += lineStrideElements;
  63786. }
  63787. const int topLimit = bounds.getY() << 8;
  63788. const int heightLimit = bounds.getHeight() << 8;
  63789. const int leftLimit = bounds.getX() << 8;
  63790. const int rightLimit = bounds.getRight() << 8;
  63791. PathFlatteningIterator iter (path, transform);
  63792. while (iter.next())
  63793. {
  63794. int y1 = roundToInt (iter.y1 * 256.0f);
  63795. int y2 = roundToInt (iter.y2 * 256.0f);
  63796. if (y1 != y2)
  63797. {
  63798. y1 -= topLimit;
  63799. y2 -= topLimit;
  63800. const int startY = y1;
  63801. int direction = -1;
  63802. if (y1 > y2)
  63803. {
  63804. swapVariables (y1, y2);
  63805. direction = 1;
  63806. }
  63807. if (y1 < 0)
  63808. y1 = 0;
  63809. if (y2 > heightLimit)
  63810. y2 = heightLimit;
  63811. if (y1 < y2)
  63812. {
  63813. const double startX = 256.0f * iter.x1;
  63814. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  63815. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  63816. do
  63817. {
  63818. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  63819. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  63820. if (x < leftLimit)
  63821. x = leftLimit;
  63822. else if (x >= rightLimit)
  63823. x = rightLimit - 1;
  63824. addEdgePoint (x, y1 >> 8, direction * step);
  63825. y1 += step;
  63826. }
  63827. while (y1 < y2);
  63828. }
  63829. }
  63830. }
  63831. sanitiseLevels (path.isUsingNonZeroWinding());
  63832. }
  63833. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  63834. : bounds (rectangleToAdd),
  63835. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63836. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63837. needToCheckEmptinesss (true)
  63838. {
  63839. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63840. table[0] = 0;
  63841. const int x1 = rectangleToAdd.getX() << 8;
  63842. const int x2 = rectangleToAdd.getRight() << 8;
  63843. int* t = table;
  63844. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  63845. {
  63846. t[0] = 2;
  63847. t[1] = x1;
  63848. t[2] = 255;
  63849. t[3] = x2;
  63850. t[4] = 0;
  63851. t += lineStrideElements;
  63852. }
  63853. }
  63854. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd)
  63855. : bounds (rectanglesToAdd.getBounds()),
  63856. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63857. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63858. needToCheckEmptinesss (true)
  63859. {
  63860. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63861. int* t = table;
  63862. for (int i = bounds.getHeight(); --i >= 0;)
  63863. {
  63864. *t = 0;
  63865. t += lineStrideElements;
  63866. }
  63867. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  63868. {
  63869. const Rectangle<int>* const r = iter.getRectangle();
  63870. const int x1 = r->getX() << 8;
  63871. const int x2 = r->getRight() << 8;
  63872. int y = r->getY() - bounds.getY();
  63873. for (int j = r->getHeight(); --j >= 0;)
  63874. {
  63875. addEdgePoint (x1, y, 255);
  63876. addEdgePoint (x2, y, -255);
  63877. ++y;
  63878. }
  63879. }
  63880. sanitiseLevels (true);
  63881. }
  63882. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h)
  63883. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  63884. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63885. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63886. needToCheckEmptinesss (true)
  63887. {
  63888. jassert (w > 0 && h > 0);
  63889. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63890. table[0] = 0;
  63891. const int x1 = roundToInt (x * 256.0f);
  63892. const int x2 = roundToInt ((x + w) * 256.0f);
  63893. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  63894. jassert (y1 < 256);
  63895. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  63896. if (x2 <= x1 || y2 <= y1)
  63897. {
  63898. bounds.setHeight (0);
  63899. return;
  63900. }
  63901. int lineY = 0;
  63902. int* t = table;
  63903. if ((y1 >> 8) == (y2 >> 8))
  63904. {
  63905. t[0] = 2;
  63906. t[1] = x1;
  63907. t[2] = y2 - y1;
  63908. t[3] = x2;
  63909. t[4] = 0;
  63910. ++lineY;
  63911. t += lineStrideElements;
  63912. }
  63913. else
  63914. {
  63915. t[0] = 2;
  63916. t[1] = x1;
  63917. t[2] = 255 - (y1 & 255);
  63918. t[3] = x2;
  63919. t[4] = 0;
  63920. ++lineY;
  63921. t += lineStrideElements;
  63922. while (lineY < (y2 >> 8))
  63923. {
  63924. t[0] = 2;
  63925. t[1] = x1;
  63926. t[2] = 255;
  63927. t[3] = x2;
  63928. t[4] = 0;
  63929. ++lineY;
  63930. t += lineStrideElements;
  63931. }
  63932. jassert (lineY < bounds.getHeight());
  63933. t[0] = 2;
  63934. t[1] = x1;
  63935. t[2] = y2 & 255;
  63936. t[3] = x2;
  63937. t[4] = 0;
  63938. ++lineY;
  63939. t += lineStrideElements;
  63940. }
  63941. while (lineY < bounds.getHeight())
  63942. {
  63943. t[0] = 0;
  63944. t += lineStrideElements;
  63945. ++lineY;
  63946. }
  63947. }
  63948. EdgeTable::EdgeTable (const EdgeTable& other)
  63949. : table (0)
  63950. {
  63951. operator= (other);
  63952. }
  63953. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  63954. {
  63955. bounds = other.bounds;
  63956. maxEdgesPerLine = other.maxEdgesPerLine;
  63957. lineStrideElements = other.lineStrideElements;
  63958. needToCheckEmptinesss = other.needToCheckEmptinesss;
  63959. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63960. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  63961. return *this;
  63962. }
  63963. EdgeTable::~EdgeTable()
  63964. {
  63965. }
  63966. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  63967. {
  63968. while (--numLines >= 0)
  63969. {
  63970. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  63971. src += srcLineStride;
  63972. dest += destLineStride;
  63973. }
  63974. }
  63975. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  63976. {
  63977. // Convert the table from relative windings to absolute levels..
  63978. int* lineStart = table;
  63979. for (int i = bounds.getHeight(); --i >= 0;)
  63980. {
  63981. int* line = lineStart;
  63982. lineStart += lineStrideElements;
  63983. int num = *line;
  63984. if (num == 0)
  63985. continue;
  63986. int level = 0;
  63987. if (useNonZeroWinding)
  63988. {
  63989. while (--num > 0)
  63990. {
  63991. line += 2;
  63992. level += *line;
  63993. int corrected = abs (level);
  63994. if (corrected >> 8)
  63995. corrected = 255;
  63996. *line = corrected;
  63997. }
  63998. }
  63999. else
  64000. {
  64001. while (--num > 0)
  64002. {
  64003. line += 2;
  64004. level += *line;
  64005. int corrected = abs (level);
  64006. if (corrected >> 8)
  64007. {
  64008. corrected &= 511;
  64009. if (corrected >> 8)
  64010. corrected = 511 - corrected;
  64011. }
  64012. *line = corrected;
  64013. }
  64014. }
  64015. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64016. }
  64017. }
  64018. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64019. {
  64020. if (newNumEdgesPerLine != maxEdgesPerLine)
  64021. {
  64022. maxEdgesPerLine = newNumEdgesPerLine;
  64023. jassert (bounds.getHeight() > 0);
  64024. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64025. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64026. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64027. table.swapWith (newTable);
  64028. lineStrideElements = newLineStrideElements;
  64029. }
  64030. }
  64031. void EdgeTable::optimiseTable() throw()
  64032. {
  64033. int maxLineElements = 0;
  64034. for (int i = bounds.getHeight(); --i >= 0;)
  64035. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64036. remapTableForNumEdges (maxLineElements);
  64037. }
  64038. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64039. {
  64040. jassert (y >= 0 && y < bounds.getHeight());
  64041. int* line = table + lineStrideElements * y;
  64042. const int numPoints = line[0];
  64043. int n = numPoints << 1;
  64044. if (n > 0)
  64045. {
  64046. while (n > 0)
  64047. {
  64048. const int cx = line [n - 1];
  64049. if (cx <= x)
  64050. {
  64051. if (cx == x)
  64052. {
  64053. line [n] += winding;
  64054. return;
  64055. }
  64056. break;
  64057. }
  64058. n -= 2;
  64059. }
  64060. if (numPoints >= maxEdgesPerLine)
  64061. {
  64062. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64063. jassert (numPoints < maxEdgesPerLine);
  64064. line = table + lineStrideElements * y;
  64065. }
  64066. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64067. }
  64068. line [n + 1] = x;
  64069. line [n + 2] = winding;
  64070. line[0]++;
  64071. }
  64072. void EdgeTable::translate (float dx, int dy) throw()
  64073. {
  64074. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64075. int* lineStart = table;
  64076. const int intDx = (int) (dx * 256.0f);
  64077. for (int i = bounds.getHeight(); --i >= 0;)
  64078. {
  64079. int* line = lineStart;
  64080. lineStart += lineStrideElements;
  64081. int num = *line++;
  64082. while (--num >= 0)
  64083. {
  64084. *line += intDx;
  64085. line += 2;
  64086. }
  64087. }
  64088. }
  64089. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64090. {
  64091. jassert (y >= 0 && y < bounds.getHeight());
  64092. int* dest = table + lineStrideElements * y;
  64093. if (dest[0] == 0)
  64094. return;
  64095. int otherNumPoints = *otherLine;
  64096. if (otherNumPoints == 0)
  64097. {
  64098. *dest = 0;
  64099. return;
  64100. }
  64101. const int right = bounds.getRight() << 8;
  64102. // optimise for the common case where our line lies entirely within a
  64103. // single pair of points, as happens when clipping to a simple rect.
  64104. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64105. {
  64106. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64107. return;
  64108. }
  64109. ++otherLine;
  64110. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64111. int* temp = (int*) alloca (lineSizeBytes);
  64112. memcpy (temp, dest, lineSizeBytes);
  64113. const int* src1 = temp;
  64114. int srcNum1 = *src1++;
  64115. int x1 = *src1++;
  64116. const int* src2 = otherLine;
  64117. int srcNum2 = otherNumPoints;
  64118. int x2 = *src2++;
  64119. int destIndex = 0, destTotal = 0;
  64120. int level1 = 0, level2 = 0;
  64121. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64122. while (srcNum1 > 0 && srcNum2 > 0)
  64123. {
  64124. int nextX;
  64125. if (x1 < x2)
  64126. {
  64127. nextX = x1;
  64128. level1 = *src1++;
  64129. x1 = *src1++;
  64130. --srcNum1;
  64131. }
  64132. else if (x1 == x2)
  64133. {
  64134. nextX = x1;
  64135. level1 = *src1++;
  64136. level2 = *src2++;
  64137. x1 = *src1++;
  64138. x2 = *src2++;
  64139. --srcNum1;
  64140. --srcNum2;
  64141. }
  64142. else
  64143. {
  64144. nextX = x2;
  64145. level2 = *src2++;
  64146. x2 = *src2++;
  64147. --srcNum2;
  64148. }
  64149. if (nextX > lastX)
  64150. {
  64151. if (nextX >= right)
  64152. break;
  64153. lastX = nextX;
  64154. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64155. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64156. if (nextLevel != lastLevel)
  64157. {
  64158. if (destTotal >= maxEdgesPerLine)
  64159. {
  64160. dest[0] = destTotal;
  64161. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64162. dest = table + lineStrideElements * y;
  64163. }
  64164. ++destTotal;
  64165. lastLevel = nextLevel;
  64166. dest[++destIndex] = nextX;
  64167. dest[++destIndex] = nextLevel;
  64168. }
  64169. }
  64170. }
  64171. if (lastLevel > 0)
  64172. {
  64173. if (destTotal >= maxEdgesPerLine)
  64174. {
  64175. dest[0] = destTotal;
  64176. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64177. dest = table + lineStrideElements * y;
  64178. }
  64179. ++destTotal;
  64180. dest[++destIndex] = right;
  64181. dest[++destIndex] = 0;
  64182. }
  64183. dest[0] = destTotal;
  64184. #if JUCE_DEBUG
  64185. int last = std::numeric_limits<int>::min();
  64186. for (int i = 0; i < dest[0]; ++i)
  64187. {
  64188. jassert (dest[i * 2 + 1] > last);
  64189. last = dest[i * 2 + 1];
  64190. }
  64191. jassert (dest [dest[0] * 2] == 0);
  64192. #endif
  64193. }
  64194. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64195. {
  64196. int* lastItem = dest + (dest[0] * 2 - 1);
  64197. if (x2 < lastItem[0])
  64198. {
  64199. if (x2 <= dest[1])
  64200. {
  64201. dest[0] = 0;
  64202. return;
  64203. }
  64204. while (x2 < lastItem[-2])
  64205. {
  64206. --(dest[0]);
  64207. lastItem -= 2;
  64208. }
  64209. lastItem[0] = x2;
  64210. lastItem[1] = 0;
  64211. }
  64212. if (x1 > dest[1])
  64213. {
  64214. while (lastItem[0] > x1)
  64215. lastItem -= 2;
  64216. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64217. if (itemsRemoved > 0)
  64218. {
  64219. dest[0] -= itemsRemoved;
  64220. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64221. }
  64222. dest[1] = x1;
  64223. }
  64224. }
  64225. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64226. {
  64227. const Rectangle<int> clipped (r.getIntersection (bounds));
  64228. if (clipped.isEmpty())
  64229. {
  64230. needToCheckEmptinesss = false;
  64231. bounds.setHeight (0);
  64232. }
  64233. else
  64234. {
  64235. const int top = clipped.getY() - bounds.getY();
  64236. const int bottom = clipped.getBottom() - bounds.getY();
  64237. if (bottom < bounds.getHeight())
  64238. bounds.setHeight (bottom);
  64239. if (clipped.getRight() < bounds.getRight())
  64240. bounds.setRight (clipped.getRight());
  64241. for (int i = top; --i >= 0;)
  64242. table [lineStrideElements * i] = 0;
  64243. if (clipped.getX() > bounds.getX())
  64244. {
  64245. const int x1 = clipped.getX() << 8;
  64246. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64247. int* line = table + lineStrideElements * top;
  64248. for (int i = bottom - top; --i >= 0;)
  64249. {
  64250. if (line[0] != 0)
  64251. clipEdgeTableLineToRange (line, x1, x2);
  64252. line += lineStrideElements;
  64253. }
  64254. }
  64255. needToCheckEmptinesss = true;
  64256. }
  64257. }
  64258. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64259. {
  64260. const Rectangle<int> clipped (r.getIntersection (bounds));
  64261. if (! clipped.isEmpty())
  64262. {
  64263. const int top = clipped.getY() - bounds.getY();
  64264. const int bottom = clipped.getBottom() - bounds.getY();
  64265. //XXX optimise here by shortening the table if it fills top or bottom
  64266. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64267. clipped.getX() << 8, 0,
  64268. clipped.getRight() << 8, 255,
  64269. std::numeric_limits<int>::max(), 0 };
  64270. for (int i = top; i < bottom; ++i)
  64271. intersectWithEdgeTableLine (i, rectLine);
  64272. needToCheckEmptinesss = true;
  64273. }
  64274. }
  64275. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64276. {
  64277. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64278. if (clipped.isEmpty())
  64279. {
  64280. needToCheckEmptinesss = false;
  64281. bounds.setHeight (0);
  64282. }
  64283. else
  64284. {
  64285. const int top = clipped.getY() - bounds.getY();
  64286. const int bottom = clipped.getBottom() - bounds.getY();
  64287. if (bottom < bounds.getHeight())
  64288. bounds.setHeight (bottom);
  64289. if (clipped.getRight() < bounds.getRight())
  64290. bounds.setRight (clipped.getRight());
  64291. int i = 0;
  64292. for (i = top; --i >= 0;)
  64293. table [lineStrideElements * i] = 0;
  64294. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64295. for (i = top; i < bottom; ++i)
  64296. {
  64297. intersectWithEdgeTableLine (i, otherLine);
  64298. otherLine += other.lineStrideElements;
  64299. }
  64300. needToCheckEmptinesss = true;
  64301. }
  64302. }
  64303. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw()
  64304. {
  64305. y -= bounds.getY();
  64306. if (y < 0 || y >= bounds.getHeight())
  64307. return;
  64308. needToCheckEmptinesss = true;
  64309. if (numPixels <= 0)
  64310. {
  64311. table [lineStrideElements * y] = 0;
  64312. return;
  64313. }
  64314. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64315. int destIndex = 0, lastLevel = 0;
  64316. while (--numPixels >= 0)
  64317. {
  64318. const int alpha = *mask;
  64319. mask += maskStride;
  64320. if (alpha != lastLevel)
  64321. {
  64322. tempLine[++destIndex] = (x << 8);
  64323. tempLine[++destIndex] = alpha;
  64324. lastLevel = alpha;
  64325. }
  64326. ++x;
  64327. }
  64328. if (lastLevel > 0)
  64329. {
  64330. tempLine[++destIndex] = (x << 8);
  64331. tempLine[++destIndex] = 0;
  64332. }
  64333. tempLine[0] = destIndex >> 1;
  64334. intersectWithEdgeTableLine (y, tempLine);
  64335. }
  64336. bool EdgeTable::isEmpty() throw()
  64337. {
  64338. if (needToCheckEmptinesss)
  64339. {
  64340. needToCheckEmptinesss = false;
  64341. int* t = table;
  64342. for (int i = bounds.getHeight(); --i >= 0;)
  64343. {
  64344. if (t[0] > 1)
  64345. return false;
  64346. t += lineStrideElements;
  64347. }
  64348. bounds.setHeight (0);
  64349. }
  64350. return bounds.getHeight() == 0;
  64351. }
  64352. END_JUCE_NAMESPACE
  64353. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64354. /*** Start of inlined file: juce_FillType.cpp ***/
  64355. BEGIN_JUCE_NAMESPACE
  64356. FillType::FillType() throw()
  64357. : colour (0xff000000), image (0)
  64358. {
  64359. }
  64360. FillType::FillType (const Colour& colour_) throw()
  64361. : colour (colour_), image (0)
  64362. {
  64363. }
  64364. FillType::FillType (const ColourGradient& gradient_) throw()
  64365. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64366. {
  64367. }
  64368. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64369. : colour (0xff000000), image (&image_), transform (transform_)
  64370. {
  64371. }
  64372. FillType::FillType (const FillType& other) throw()
  64373. : colour (other.colour),
  64374. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64375. image (other.image), transform (other.transform)
  64376. {
  64377. }
  64378. FillType& FillType::operator= (const FillType& other) throw()
  64379. {
  64380. if (this != &other)
  64381. {
  64382. colour = other.colour;
  64383. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64384. image = other.image;
  64385. transform = other.transform;
  64386. }
  64387. return *this;
  64388. }
  64389. FillType::~FillType() throw()
  64390. {
  64391. }
  64392. void FillType::setColour (const Colour& newColour) throw()
  64393. {
  64394. gradient = 0;
  64395. image = 0;
  64396. colour = newColour;
  64397. }
  64398. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64399. {
  64400. if (gradient != 0)
  64401. {
  64402. *gradient = newGradient;
  64403. }
  64404. else
  64405. {
  64406. image = 0;
  64407. gradient = new ColourGradient (newGradient);
  64408. colour = Colours::black;
  64409. }
  64410. }
  64411. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64412. {
  64413. gradient = 0;
  64414. image = &image_;
  64415. transform = transform_;
  64416. colour = Colours::black;
  64417. }
  64418. void FillType::setOpacity (const float newOpacity) throw()
  64419. {
  64420. colour = colour.withAlpha (newOpacity);
  64421. }
  64422. END_JUCE_NAMESPACE
  64423. /*** End of inlined file: juce_FillType.cpp ***/
  64424. /*** Start of inlined file: juce_Graphics.cpp ***/
  64425. BEGIN_JUCE_NAMESPACE
  64426. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64427. template <typename Type>
  64428. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64429. {
  64430. const int maxVal = 0x3fffffff;
  64431. return (int) x >= -maxVal && (int) x <= maxVal
  64432. && (int) y >= -maxVal && (int) y <= maxVal
  64433. && (int) w >= -maxVal && (int) w <= maxVal
  64434. && (int) h >= -maxVal && (int) h <= maxVal;
  64435. }
  64436. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64437. {
  64438. }
  64439. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64440. {
  64441. }
  64442. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64443. : context (imageToDrawOnto.createLowLevelContext()),
  64444. contextToDelete (context),
  64445. saveStatePending (false)
  64446. {
  64447. }
  64448. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64449. : context (internalContext),
  64450. saveStatePending (false)
  64451. {
  64452. }
  64453. Graphics::~Graphics() throw()
  64454. {
  64455. }
  64456. void Graphics::resetToDefaultState() throw()
  64457. {
  64458. saveStateIfPending();
  64459. context->setFill (FillType());
  64460. context->setFont (Font());
  64461. context->setInterpolationQuality (defaultQuality);
  64462. }
  64463. bool Graphics::isVectorDevice() const throw()
  64464. {
  64465. return context->isVectorDevice();
  64466. }
  64467. bool Graphics::reduceClipRegion (const int x, const int y,
  64468. const int w, const int h) throw()
  64469. {
  64470. saveStateIfPending();
  64471. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64472. }
  64473. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64474. {
  64475. saveStateIfPending();
  64476. return context->clipToRectangleList (clipRegion);
  64477. }
  64478. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64479. {
  64480. saveStateIfPending();
  64481. context->clipToPath (path, transform);
  64482. return ! context->isClipEmpty();
  64483. }
  64484. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64485. {
  64486. saveStateIfPending();
  64487. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64488. return ! context->isClipEmpty();
  64489. }
  64490. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude) throw()
  64491. {
  64492. saveStateIfPending();
  64493. context->excludeClipRectangle (rectangleToExclude);
  64494. }
  64495. bool Graphics::isClipEmpty() const throw()
  64496. {
  64497. return context->isClipEmpty();
  64498. }
  64499. const Rectangle<int> Graphics::getClipBounds() const throw()
  64500. {
  64501. return context->getClipBounds();
  64502. }
  64503. void Graphics::saveState() throw()
  64504. {
  64505. saveStateIfPending();
  64506. saveStatePending = true;
  64507. }
  64508. void Graphics::restoreState() throw()
  64509. {
  64510. if (saveStatePending)
  64511. saveStatePending = false;
  64512. else
  64513. context->restoreState();
  64514. }
  64515. void Graphics::saveStateIfPending() throw()
  64516. {
  64517. if (saveStatePending)
  64518. {
  64519. saveStatePending = false;
  64520. context->saveState();
  64521. }
  64522. }
  64523. void Graphics::setOrigin (const int newOriginX,
  64524. const int newOriginY) throw()
  64525. {
  64526. saveStateIfPending();
  64527. context->setOrigin (newOriginX, newOriginY);
  64528. }
  64529. bool Graphics::clipRegionIntersects (const int x, const int y,
  64530. const int w, const int h) const throw()
  64531. {
  64532. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64533. }
  64534. void Graphics::setColour (const Colour& newColour) throw()
  64535. {
  64536. saveStateIfPending();
  64537. context->setFill (FillType (newColour));
  64538. }
  64539. void Graphics::setOpacity (const float newOpacity) throw()
  64540. {
  64541. saveStateIfPending();
  64542. context->setOpacity (newOpacity);
  64543. }
  64544. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64545. {
  64546. saveStateIfPending();
  64547. context->setFill (FillType (gradient));
  64548. }
  64549. void Graphics::setTiledImageFill (const Image& imageToUse,
  64550. const int anchorX,
  64551. const int anchorY,
  64552. const float opacity) throw()
  64553. {
  64554. saveStateIfPending();
  64555. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64556. context->setOpacity (opacity);
  64557. }
  64558. void Graphics::setFillType (const FillType& newFill) throw()
  64559. {
  64560. saveStateIfPending();
  64561. context->setFill (newFill);
  64562. }
  64563. void Graphics::setFont (const Font& newFont) throw()
  64564. {
  64565. saveStateIfPending();
  64566. context->setFont (newFont);
  64567. }
  64568. void Graphics::setFont (const float newFontHeight,
  64569. const int newFontStyleFlags) throw()
  64570. {
  64571. saveStateIfPending();
  64572. Font f (context->getFont());
  64573. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64574. context->setFont (f);
  64575. }
  64576. void Graphics::drawSingleLineText (const String& text,
  64577. const int startX,
  64578. const int baselineY) const throw()
  64579. {
  64580. if (text.isNotEmpty()
  64581. && startX < context->getClipBounds().getRight())
  64582. {
  64583. GlyphArrangement arr;
  64584. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64585. arr.draw (*this);
  64586. }
  64587. }
  64588. void Graphics::drawTextAsPath (const String& text,
  64589. const AffineTransform& transform) const throw()
  64590. {
  64591. if (text.isNotEmpty())
  64592. {
  64593. GlyphArrangement arr;
  64594. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64595. arr.draw (*this, transform);
  64596. }
  64597. }
  64598. void Graphics::drawMultiLineText (const String& text,
  64599. const int startX,
  64600. const int baselineY,
  64601. const int maximumLineWidth) const throw()
  64602. {
  64603. if (text.isNotEmpty()
  64604. && startX < context->getClipBounds().getRight())
  64605. {
  64606. GlyphArrangement arr;
  64607. arr.addJustifiedText (context->getFont(), text,
  64608. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64609. Justification::left);
  64610. arr.draw (*this);
  64611. }
  64612. }
  64613. void Graphics::drawText (const String& text,
  64614. const int x,
  64615. const int y,
  64616. const int width,
  64617. const int height,
  64618. const Justification& justificationType,
  64619. const bool useEllipsesIfTooBig) const throw()
  64620. {
  64621. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64622. {
  64623. GlyphArrangement arr;
  64624. arr.addCurtailedLineOfText (context->getFont(), text,
  64625. 0.0f, 0.0f, (float)width,
  64626. useEllipsesIfTooBig);
  64627. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64628. (float) x, (float) y,
  64629. (float) width, (float) height,
  64630. justificationType);
  64631. arr.draw (*this);
  64632. }
  64633. }
  64634. void Graphics::drawFittedText (const String& text,
  64635. const int x,
  64636. const int y,
  64637. const int width,
  64638. const int height,
  64639. const Justification& justification,
  64640. const int maximumNumberOfLines,
  64641. const float minimumHorizontalScale) const throw()
  64642. {
  64643. if (text.isNotEmpty()
  64644. && width > 0 && height > 0
  64645. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64646. {
  64647. GlyphArrangement arr;
  64648. arr.addFittedText (context->getFont(), text,
  64649. (float) x, (float) y,
  64650. (float) width, (float) height,
  64651. justification,
  64652. maximumNumberOfLines,
  64653. minimumHorizontalScale);
  64654. arr.draw (*this);
  64655. }
  64656. }
  64657. void Graphics::fillRect (int x,
  64658. int y,
  64659. int width,
  64660. int height) const throw()
  64661. {
  64662. // passing in a silly number can cause maths problems in rendering!
  64663. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64664. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64665. }
  64666. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  64667. {
  64668. context->fillRect (r, false);
  64669. }
  64670. void Graphics::fillRect (const float x,
  64671. const float y,
  64672. const float width,
  64673. const float height) const throw()
  64674. {
  64675. // passing in a silly number can cause maths problems in rendering!
  64676. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64677. Path p;
  64678. p.addRectangle (x, y, width, height);
  64679. fillPath (p);
  64680. }
  64681. void Graphics::setPixel (int x, int y) const throw()
  64682. {
  64683. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64684. }
  64685. void Graphics::fillAll() const throw()
  64686. {
  64687. fillRect (context->getClipBounds());
  64688. }
  64689. void Graphics::fillAll (const Colour& colourToUse) const throw()
  64690. {
  64691. if (! colourToUse.isTransparent())
  64692. {
  64693. const Rectangle<int> clip (context->getClipBounds());
  64694. context->saveState();
  64695. context->setFill (FillType (colourToUse));
  64696. context->fillRect (clip, false);
  64697. context->restoreState();
  64698. }
  64699. }
  64700. void Graphics::fillPath (const Path& path,
  64701. const AffineTransform& transform) const throw()
  64702. {
  64703. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64704. context->fillPath (path, transform);
  64705. }
  64706. void Graphics::strokePath (const Path& path,
  64707. const PathStrokeType& strokeType,
  64708. const AffineTransform& transform) const throw()
  64709. {
  64710. Path stroke;
  64711. strokeType.createStrokedPath (stroke, path, transform);
  64712. fillPath (stroke);
  64713. }
  64714. void Graphics::drawRect (const int x,
  64715. const int y,
  64716. const int width,
  64717. const int height,
  64718. const int lineThickness) const throw()
  64719. {
  64720. // passing in a silly number can cause maths problems in rendering!
  64721. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64722. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64723. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64724. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64725. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64726. }
  64727. void Graphics::drawRect (const float x,
  64728. const float y,
  64729. const float width,
  64730. const float height,
  64731. const float lineThickness) const throw()
  64732. {
  64733. // passing in a silly number can cause maths problems in rendering!
  64734. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64735. Path p;
  64736. p.addRectangle (x, y, width, lineThickness);
  64737. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64738. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64739. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64740. fillPath (p);
  64741. }
  64742. void Graphics::drawRect (const Rectangle<int>& r,
  64743. const int lineThickness) const throw()
  64744. {
  64745. drawRect (r.getX(), r.getY(),
  64746. r.getWidth(), r.getHeight(),
  64747. lineThickness);
  64748. }
  64749. void Graphics::drawBevel (const int x,
  64750. const int y,
  64751. const int width,
  64752. const int height,
  64753. const int bevelThickness,
  64754. const Colour& topLeftColour,
  64755. const Colour& bottomRightColour,
  64756. const bool useGradient,
  64757. const bool sharpEdgeOnOutside) const throw()
  64758. {
  64759. // passing in a silly number can cause maths problems in rendering!
  64760. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64761. if (clipRegionIntersects (x, y, width, height))
  64762. {
  64763. context->saveState();
  64764. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64765. const float ramp = oldOpacity / bevelThickness;
  64766. for (int i = bevelThickness; --i >= 0;)
  64767. {
  64768. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64769. : oldOpacity;
  64770. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  64771. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64772. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  64773. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64774. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  64775. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64776. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  64777. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64778. }
  64779. context->restoreState();
  64780. }
  64781. }
  64782. void Graphics::fillEllipse (const float x,
  64783. const float y,
  64784. const float width,
  64785. const float height) const throw()
  64786. {
  64787. // passing in a silly number can cause maths problems in rendering!
  64788. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64789. Path p;
  64790. p.addEllipse (x, y, width, height);
  64791. fillPath (p);
  64792. }
  64793. void Graphics::drawEllipse (const float x,
  64794. const float y,
  64795. const float width,
  64796. const float height,
  64797. const float lineThickness) const throw()
  64798. {
  64799. // passing in a silly number can cause maths problems in rendering!
  64800. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64801. Path p;
  64802. p.addEllipse (x, y, width, height);
  64803. strokePath (p, PathStrokeType (lineThickness));
  64804. }
  64805. void Graphics::fillRoundedRectangle (const float x,
  64806. const float y,
  64807. const float width,
  64808. const float height,
  64809. const float cornerSize) const throw()
  64810. {
  64811. // passing in a silly number can cause maths problems in rendering!
  64812. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64813. Path p;
  64814. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64815. fillPath (p);
  64816. }
  64817. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  64818. const float cornerSize) const throw()
  64819. {
  64820. fillRoundedRectangle ((float) r.getX(),
  64821. (float) r.getY(),
  64822. (float) r.getWidth(),
  64823. (float) r.getHeight(),
  64824. cornerSize);
  64825. }
  64826. void Graphics::drawRoundedRectangle (const float x,
  64827. const float y,
  64828. const float width,
  64829. const float height,
  64830. const float cornerSize,
  64831. const float lineThickness) const throw()
  64832. {
  64833. // passing in a silly number can cause maths problems in rendering!
  64834. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64835. Path p;
  64836. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64837. strokePath (p, PathStrokeType (lineThickness));
  64838. }
  64839. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  64840. const float cornerSize,
  64841. const float lineThickness) const throw()
  64842. {
  64843. drawRoundedRectangle ((float) r.getX(),
  64844. (float) r.getY(),
  64845. (float) r.getWidth(),
  64846. (float) r.getHeight(),
  64847. cornerSize, lineThickness);
  64848. }
  64849. void Graphics::drawArrow (const float startX,
  64850. const float startY,
  64851. const float endX,
  64852. const float endY,
  64853. const float lineThickness,
  64854. const float arrowheadWidth,
  64855. const float arrowheadLength) const throw()
  64856. {
  64857. Path p;
  64858. p.addArrow (startX, startY, endX, endY,
  64859. lineThickness, arrowheadWidth, arrowheadLength);
  64860. fillPath (p);
  64861. }
  64862. void Graphics::fillCheckerBoard (int x, int y,
  64863. int width, int height,
  64864. const int checkWidth,
  64865. const int checkHeight,
  64866. const Colour& colour1,
  64867. const Colour& colour2) const throw()
  64868. {
  64869. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64870. if (checkWidth > 0 && checkHeight > 0)
  64871. {
  64872. context->saveState();
  64873. if (colour1 == colour2)
  64874. {
  64875. context->setFill (FillType (colour1));
  64876. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64877. }
  64878. else
  64879. {
  64880. const Rectangle<int> clip (context->getClipBounds());
  64881. const int right = jmin (x + width, clip.getRight());
  64882. const int bottom = jmin (y + height, clip.getBottom());
  64883. int cy = 0;
  64884. while (y < bottom)
  64885. {
  64886. int cx = cy;
  64887. for (int xx = x; xx < right; xx += checkWidth)
  64888. {
  64889. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  64890. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64891. false);
  64892. }
  64893. ++cy;
  64894. y += checkHeight;
  64895. }
  64896. }
  64897. context->restoreState();
  64898. }
  64899. }
  64900. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  64901. {
  64902. context->drawVerticalLine (x, top, bottom);
  64903. }
  64904. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  64905. {
  64906. context->drawHorizontalLine (y, left, right);
  64907. }
  64908. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  64909. {
  64910. context->drawLine (x1, y1, x2, y2);
  64911. }
  64912. void Graphics::drawLine (const float startX,
  64913. const float startY,
  64914. const float endX,
  64915. const float endY,
  64916. const float lineThickness) const throw()
  64917. {
  64918. Path p;
  64919. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  64920. fillPath (p);
  64921. }
  64922. void Graphics::drawLine (const Line& line) const throw()
  64923. {
  64924. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  64925. }
  64926. void Graphics::drawLine (const Line& line,
  64927. const float lineThickness) const throw()
  64928. {
  64929. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  64930. }
  64931. void Graphics::drawDashedLine (const float startX,
  64932. const float startY,
  64933. const float endX,
  64934. const float endY,
  64935. const float* const dashLengths,
  64936. const int numDashLengths,
  64937. const float lineThickness) const throw()
  64938. {
  64939. const double dx = endX - startX;
  64940. const double dy = endY - startY;
  64941. const double totalLen = juce_hypot (dx, dy);
  64942. if (totalLen >= 0.5)
  64943. {
  64944. const double onePixAlpha = 1.0 / totalLen;
  64945. double alpha = 0.0;
  64946. float x = startX;
  64947. float y = startY;
  64948. int n = 0;
  64949. while (alpha < 1.0f)
  64950. {
  64951. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  64952. n = n % numDashLengths;
  64953. const float oldX = x;
  64954. const float oldY = y;
  64955. x = (float) (startX + dx * alpha);
  64956. y = (float) (startY + dy * alpha);
  64957. if ((n & 1) != 0)
  64958. {
  64959. if (lineThickness != 1.0f)
  64960. drawLine (oldX, oldY, x, y, lineThickness);
  64961. else
  64962. drawLine (oldX, oldY, x, y);
  64963. }
  64964. }
  64965. }
  64966. }
  64967. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  64968. {
  64969. saveStateIfPending();
  64970. context->setInterpolationQuality (newQuality);
  64971. }
  64972. void Graphics::drawImageAt (const Image* const imageToDraw,
  64973. const int topLeftX,
  64974. const int topLeftY,
  64975. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64976. {
  64977. if (imageToDraw != 0)
  64978. {
  64979. const int imageW = imageToDraw->getWidth();
  64980. const int imageH = imageToDraw->getHeight();
  64981. drawImage (imageToDraw,
  64982. topLeftX, topLeftY, imageW, imageH,
  64983. 0, 0, imageW, imageH,
  64984. fillAlphaChannelWithCurrentBrush);
  64985. }
  64986. }
  64987. void Graphics::drawImageWithin (const Image* const imageToDraw,
  64988. const int destX,
  64989. const int destY,
  64990. const int destW,
  64991. const int destH,
  64992. const RectanglePlacement& placementWithinTarget,
  64993. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64994. {
  64995. // passing in a silly number can cause maths problems in rendering!
  64996. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  64997. if (imageToDraw != 0)
  64998. {
  64999. const int imageW = imageToDraw->getWidth();
  65000. const int imageH = imageToDraw->getHeight();
  65001. if (imageW > 0 && imageH > 0)
  65002. {
  65003. double newX = 0.0, newY = 0.0;
  65004. double newW = imageW;
  65005. double newH = imageH;
  65006. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65007. destX, destY, destW, destH);
  65008. if (newW > 0 && newH > 0)
  65009. {
  65010. drawImage (imageToDraw,
  65011. roundToInt (newX), roundToInt (newY),
  65012. roundToInt (newW), roundToInt (newH),
  65013. 0, 0, imageW, imageH,
  65014. fillAlphaChannelWithCurrentBrush);
  65015. }
  65016. }
  65017. }
  65018. }
  65019. void Graphics::drawImage (const Image* const imageToDraw,
  65020. int dx, int dy, int dw, int dh,
  65021. int sx, int sy, int sw, int sh,
  65022. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65023. {
  65024. // passing in a silly number can cause maths problems in rendering!
  65025. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65026. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65027. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  65028. {
  65029. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  65030. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65031. .translated ((float) dx, (float) dy),
  65032. fillAlphaChannelWithCurrentBrush);
  65033. }
  65034. }
  65035. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65036. const Rectangle<int>& imageSubRegion,
  65037. const AffineTransform& transform,
  65038. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65039. {
  65040. if (imageToDraw != 0 && ! context->isClipEmpty())
  65041. {
  65042. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65043. if (fillAlphaChannelWithCurrentBrush)
  65044. {
  65045. context->saveState();
  65046. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65047. fillAll();
  65048. context->restoreState();
  65049. }
  65050. else
  65051. {
  65052. context->drawImage (*imageToDraw, srcClip, transform, false);
  65053. }
  65054. }
  65055. }
  65056. END_JUCE_NAMESPACE
  65057. /*** End of inlined file: juce_Graphics.cpp ***/
  65058. /*** Start of inlined file: juce_Justification.cpp ***/
  65059. BEGIN_JUCE_NAMESPACE
  65060. Justification::Justification (const Justification& other) throw()
  65061. : flags (other.flags)
  65062. {
  65063. }
  65064. Justification& Justification::operator= (const Justification& other) throw()
  65065. {
  65066. flags = other.flags;
  65067. return *this;
  65068. }
  65069. int Justification::getOnlyVerticalFlags() const throw()
  65070. {
  65071. return flags & (top | bottom | verticallyCentred);
  65072. }
  65073. int Justification::getOnlyHorizontalFlags() const throw()
  65074. {
  65075. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65076. }
  65077. void Justification::applyToRectangle (int& x, int& y,
  65078. const int w, const int h,
  65079. const int spaceX, const int spaceY,
  65080. const int spaceW, const int spaceH) const throw()
  65081. {
  65082. if ((flags & horizontallyCentred) != 0)
  65083. {
  65084. x = spaceX + ((spaceW - w) >> 1);
  65085. }
  65086. else if ((flags & right) != 0)
  65087. {
  65088. x = spaceX + spaceW - w;
  65089. }
  65090. else
  65091. {
  65092. x = spaceX;
  65093. }
  65094. if ((flags & verticallyCentred) != 0)
  65095. {
  65096. y = spaceY + ((spaceH - h) >> 1);
  65097. }
  65098. else if ((flags & bottom) != 0)
  65099. {
  65100. y = spaceY + spaceH - h;
  65101. }
  65102. else
  65103. {
  65104. y = spaceY;
  65105. }
  65106. }
  65107. END_JUCE_NAMESPACE
  65108. /*** End of inlined file: juce_Justification.cpp ***/
  65109. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65110. BEGIN_JUCE_NAMESPACE
  65111. // this will throw an assertion if you try to draw something that's not
  65112. // possible in postscript
  65113. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65114. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65115. #define notPossibleInPostscriptAssert jassertfalse
  65116. #else
  65117. #define notPossibleInPostscriptAssert
  65118. #endif
  65119. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65120. const String& documentTitle,
  65121. const int totalWidth_,
  65122. const int totalHeight_)
  65123. : out (resultingPostScript),
  65124. totalWidth (totalWidth_),
  65125. totalHeight (totalHeight_),
  65126. needToClip (true)
  65127. {
  65128. stateStack.add (new SavedState());
  65129. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65130. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65131. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65132. "\n%%BoundingBox: 0 0 600 824"
  65133. "\n%%Pages: 0"
  65134. "\n%%Creator: Raw Material Software JUCE"
  65135. "\n%%Title: " << documentTitle <<
  65136. "\n%%CreationDate: none"
  65137. "\n%%LanguageLevel: 2"
  65138. "\n%%EndComments"
  65139. "\n%%BeginProlog"
  65140. "\n%%BeginResource: JRes"
  65141. "\n/bd {bind def} bind def"
  65142. "\n/c {setrgbcolor} bd"
  65143. "\n/m {moveto} bd"
  65144. "\n/l {lineto} bd"
  65145. "\n/rl {rlineto} bd"
  65146. "\n/ct {curveto} bd"
  65147. "\n/cp {closepath} bd"
  65148. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65149. "\n/doclip {initclip newpath} bd"
  65150. "\n/endclip {clip newpath} bd"
  65151. "\n%%EndResource"
  65152. "\n%%EndProlog"
  65153. "\n%%BeginSetup"
  65154. "\n%%EndSetup"
  65155. "\n%%Page: 1 1"
  65156. "\n%%BeginPageSetup"
  65157. "\n%%EndPageSetup\n\n"
  65158. << "40 800 translate\n"
  65159. << scale << ' ' << scale << " scale\n\n";
  65160. }
  65161. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65162. {
  65163. }
  65164. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65165. {
  65166. return true;
  65167. }
  65168. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65169. {
  65170. if (x != 0 || y != 0)
  65171. {
  65172. stateStack.getLast()->xOffset += x;
  65173. stateStack.getLast()->yOffset += y;
  65174. needToClip = true;
  65175. }
  65176. }
  65177. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65178. {
  65179. needToClip = true;
  65180. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65181. }
  65182. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65183. {
  65184. needToClip = true;
  65185. return stateStack.getLast()->clip.clipTo (clipRegion);
  65186. }
  65187. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65188. {
  65189. needToClip = true;
  65190. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65191. }
  65192. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65193. {
  65194. writeClip();
  65195. Path p (path);
  65196. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65197. writePath (p);
  65198. out << "clip\n";
  65199. }
  65200. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65201. {
  65202. needToClip = true;
  65203. jassertfalse // xxx
  65204. }
  65205. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65206. {
  65207. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65208. }
  65209. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65210. {
  65211. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65212. -stateStack.getLast()->yOffset);
  65213. }
  65214. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65215. {
  65216. return stateStack.getLast()->clip.isEmpty();
  65217. }
  65218. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65219. : xOffset (0),
  65220. yOffset (0)
  65221. {
  65222. }
  65223. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65224. {
  65225. }
  65226. void LowLevelGraphicsPostScriptRenderer::saveState()
  65227. {
  65228. stateStack.add (new SavedState (*stateStack.getLast()));
  65229. }
  65230. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65231. {
  65232. jassert (stateStack.size() > 0);
  65233. if (stateStack.size() > 0)
  65234. stateStack.removeLast();
  65235. }
  65236. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65237. {
  65238. if (needToClip)
  65239. {
  65240. needToClip = false;
  65241. out << "doclip ";
  65242. int itemsOnLine = 0;
  65243. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65244. {
  65245. if (++itemsOnLine == 6)
  65246. {
  65247. itemsOnLine = 0;
  65248. out << '\n';
  65249. }
  65250. const Rectangle<int>& r = *i.getRectangle();
  65251. out << r.getX() << ' ' << -r.getY() << ' '
  65252. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65253. }
  65254. out << "endclip\n";
  65255. }
  65256. }
  65257. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65258. {
  65259. Colour c (Colours::white.overlaidWith (colour));
  65260. if (lastColour != c)
  65261. {
  65262. lastColour = c;
  65263. out << String (c.getFloatRed(), 3) << ' '
  65264. << String (c.getFloatGreen(), 3) << ' '
  65265. << String (c.getFloatBlue(), 3) << " c\n";
  65266. }
  65267. }
  65268. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65269. {
  65270. out << String (x, 2) << ' '
  65271. << String (-y, 2) << ' ';
  65272. }
  65273. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65274. {
  65275. out << "newpath ";
  65276. float lastX = 0.0f;
  65277. float lastY = 0.0f;
  65278. int itemsOnLine = 0;
  65279. Path::Iterator i (path);
  65280. while (i.next())
  65281. {
  65282. if (++itemsOnLine == 4)
  65283. {
  65284. itemsOnLine = 0;
  65285. out << '\n';
  65286. }
  65287. switch (i.elementType)
  65288. {
  65289. case Path::Iterator::startNewSubPath:
  65290. writeXY (i.x1, i.y1);
  65291. lastX = i.x1;
  65292. lastY = i.y1;
  65293. out << "m ";
  65294. break;
  65295. case Path::Iterator::lineTo:
  65296. writeXY (i.x1, i.y1);
  65297. lastX = i.x1;
  65298. lastY = i.y1;
  65299. out << "l ";
  65300. break;
  65301. case Path::Iterator::quadraticTo:
  65302. {
  65303. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65304. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65305. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65306. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65307. writeXY (cp1x, cp1y);
  65308. writeXY (cp2x, cp2y);
  65309. writeXY (i.x2, i.y2);
  65310. out << "ct ";
  65311. lastX = i.x2;
  65312. lastY = i.y2;
  65313. }
  65314. break;
  65315. case Path::Iterator::cubicTo:
  65316. writeXY (i.x1, i.y1);
  65317. writeXY (i.x2, i.y2);
  65318. writeXY (i.x3, i.y3);
  65319. out << "ct ";
  65320. lastX = i.x3;
  65321. lastY = i.y3;
  65322. break;
  65323. case Path::Iterator::closePath:
  65324. out << "cp ";
  65325. break;
  65326. default:
  65327. jassertfalse
  65328. break;
  65329. }
  65330. }
  65331. out << '\n';
  65332. }
  65333. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65334. {
  65335. out << "[ "
  65336. << trans.mat00 << ' '
  65337. << trans.mat10 << ' '
  65338. << trans.mat01 << ' '
  65339. << trans.mat11 << ' '
  65340. << trans.mat02 << ' '
  65341. << trans.mat12 << " ] concat ";
  65342. }
  65343. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65344. {
  65345. stateStack.getLast()->fillType = fillType;
  65346. }
  65347. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65348. {
  65349. }
  65350. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65351. {
  65352. }
  65353. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65354. {
  65355. if (stateStack.getLast()->fillType.isColour())
  65356. {
  65357. writeClip();
  65358. writeColour (stateStack.getLast()->fillType.colour);
  65359. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65360. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65361. }
  65362. else
  65363. {
  65364. Path p;
  65365. p.addRectangle (r);
  65366. fillPath (p, AffineTransform::identity);
  65367. }
  65368. }
  65369. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65370. {
  65371. if (stateStack.getLast()->fillType.isColour())
  65372. {
  65373. writeClip();
  65374. Path p (path);
  65375. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65376. (float) stateStack.getLast()->yOffset));
  65377. writePath (p);
  65378. writeColour (stateStack.getLast()->fillType.colour);
  65379. out << "fill\n";
  65380. }
  65381. else if (stateStack.getLast()->fillType.isGradient())
  65382. {
  65383. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65384. // postscript can't do semi-transparent ones.
  65385. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65386. writeClip();
  65387. out << "gsave ";
  65388. {
  65389. Path p (path);
  65390. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65391. writePath (p);
  65392. out << "clip\n";
  65393. }
  65394. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65395. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65396. // time-being, this just fills it with the average colour..
  65397. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65398. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65399. out << "grestore\n";
  65400. }
  65401. }
  65402. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65403. const int sx, const int sy,
  65404. const int maxW, const int maxH) const
  65405. {
  65406. out << "{<\n";
  65407. const int w = jmin (maxW, im.getWidth());
  65408. const int h = jmin (maxH, im.getHeight());
  65409. int charsOnLine = 0;
  65410. const Image::BitmapData srcData (im, 0, 0, w, h);
  65411. Colour pixel;
  65412. for (int y = h; --y >= 0;)
  65413. {
  65414. for (int x = 0; x < w; ++x)
  65415. {
  65416. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65417. if (x >= sx && y >= sy)
  65418. {
  65419. if (im.isARGB())
  65420. {
  65421. PixelARGB p (*(const PixelARGB*) pixelData);
  65422. p.unpremultiply();
  65423. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65424. }
  65425. else if (im.isRGB())
  65426. {
  65427. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65428. }
  65429. else
  65430. {
  65431. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65432. }
  65433. }
  65434. else
  65435. {
  65436. pixel = Colours::transparentWhite;
  65437. }
  65438. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65439. out << String::toHexString (pixelValues, 3, 0);
  65440. charsOnLine += 3;
  65441. if (charsOnLine > 100)
  65442. {
  65443. out << '\n';
  65444. charsOnLine = 0;
  65445. }
  65446. }
  65447. }
  65448. out << "\n>}\n";
  65449. }
  65450. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65451. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65452. {
  65453. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65454. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65455. writeClip();
  65456. out << "gsave ";
  65457. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65458. .scaled (1.0f, -1.0f));
  65459. RectangleList imageClip;
  65460. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65461. imageClip.clipTo (srcClip);
  65462. out << "newpath ";
  65463. int itemsOnLine = 0;
  65464. for (RectangleList::Iterator i (imageClip); i.next();)
  65465. {
  65466. if (++itemsOnLine == 6)
  65467. {
  65468. out << '\n';
  65469. itemsOnLine = 0;
  65470. }
  65471. const Rectangle<int>& r = *i.getRectangle();
  65472. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65473. }
  65474. out << " clip newpath\n";
  65475. out << w << ' ' << h << " scale\n";
  65476. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65477. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65478. out << "false 3 colorimage grestore\n";
  65479. needToClip = true;
  65480. }
  65481. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65482. {
  65483. Path p;
  65484. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65485. fillPath (p, AffineTransform::identity);
  65486. }
  65487. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65488. {
  65489. drawLine (x, top, x, bottom);
  65490. }
  65491. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65492. {
  65493. drawLine (left, y, right, y);
  65494. }
  65495. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65496. {
  65497. stateStack.getLast()->font = newFont;
  65498. }
  65499. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65500. {
  65501. return stateStack.getLast()->font;
  65502. }
  65503. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65504. {
  65505. Path p;
  65506. Font& font = stateStack.getLast()->font;
  65507. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65508. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65509. }
  65510. END_JUCE_NAMESPACE
  65511. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65512. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65513. BEGIN_JUCE_NAMESPACE
  65514. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65515. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65516. #endif
  65517. #if JUCE_MSVC && JUCE_DEBUG
  65518. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65519. #endif
  65520. #if JUCE_MSVC
  65521. #pragma warning (push)
  65522. #pragma warning (disable: 4127) // "expression is constant" warning
  65523. #endif
  65524. template <class PixelType, bool replaceExisting = false>
  65525. class SolidColourEdgeTableRenderer
  65526. {
  65527. public:
  65528. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65529. : data (data_),
  65530. sourceColour (colour)
  65531. {
  65532. if (sizeof (PixelType) == 3)
  65533. {
  65534. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65535. && sourceColour.getGreen() == sourceColour.getBlue();
  65536. filler[0].set (sourceColour);
  65537. filler[1].set (sourceColour);
  65538. filler[2].set (sourceColour);
  65539. filler[3].set (sourceColour);
  65540. }
  65541. }
  65542. forcedinline void setEdgeTableYPos (const int y) throw()
  65543. {
  65544. linePixels = (PixelType*) data.getLinePointer (y);
  65545. }
  65546. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65547. {
  65548. if (replaceExisting)
  65549. linePixels[x].set (sourceColour);
  65550. else
  65551. linePixels[x].blend (sourceColour, alphaLevel);
  65552. }
  65553. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65554. {
  65555. PixelARGB p (sourceColour);
  65556. p.multiplyAlpha (alphaLevel);
  65557. PixelType* dest = linePixels + x;
  65558. if (replaceExisting || p.getAlpha() >= 0xff)
  65559. replaceLine (dest, p, width);
  65560. else
  65561. blendLine (dest, p, width);
  65562. }
  65563. private:
  65564. const Image::BitmapData& data;
  65565. PixelType* linePixels;
  65566. PixelARGB sourceColour;
  65567. PixelRGB filler [4];
  65568. bool areRGBComponentsEqual;
  65569. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const throw()
  65570. {
  65571. do
  65572. {
  65573. dest->blend (colour);
  65574. ++dest;
  65575. } while (--width > 0);
  65576. }
  65577. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65578. {
  65579. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65580. {
  65581. memset (dest, colour.getRed(), width * 3);
  65582. }
  65583. else
  65584. {
  65585. if (width >> 5)
  65586. {
  65587. const int* const intFiller = (const int*) filler;
  65588. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65589. {
  65590. dest->set (colour);
  65591. ++dest;
  65592. --width;
  65593. }
  65594. while (width > 4)
  65595. {
  65596. ((int*) dest) [0] = intFiller[0];
  65597. ((int*) dest) [1] = intFiller[1];
  65598. ((int*) dest) [2] = intFiller[2];
  65599. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65600. width -= 4;
  65601. }
  65602. }
  65603. while (--width >= 0)
  65604. {
  65605. dest->set (colour);
  65606. ++dest;
  65607. }
  65608. }
  65609. }
  65610. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65611. {
  65612. memset (dest, colour.getAlpha(), width);
  65613. }
  65614. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65615. {
  65616. do
  65617. {
  65618. dest->set (colour);
  65619. ++dest;
  65620. } while (--width > 0);
  65621. }
  65622. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65623. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65624. };
  65625. class LinearGradientPixelGenerator
  65626. {
  65627. public:
  65628. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65629. : lookupTable (lookupTable_), numEntries (numEntries_)
  65630. {
  65631. jassert (numEntries_ >= 0);
  65632. float x1 = gradient.x1;
  65633. float y1 = gradient.y1;
  65634. float x2 = gradient.x2;
  65635. float y2 = gradient.y2;
  65636. if (! transform.isIdentity())
  65637. {
  65638. const Line l (x2, y2, x1, y1);
  65639. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65640. float x3 = p3.getX();
  65641. float y3 = p3.getY();
  65642. transform.transformPoint (x1, y1);
  65643. transform.transformPoint (x2, y2);
  65644. transform.transformPoint (x3, y3);
  65645. const Line l2 (x2, y2, x3, y3);
  65646. const float prop = l2.findNearestPointTo (x1, y1);
  65647. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65648. x2 = newP2.getX();
  65649. y2 = newP2.getY();
  65650. }
  65651. vertical = fabs (x1 - x2) < 0.001f;
  65652. horizontal = fabs (y1 - y2) < 0.001f;
  65653. if (vertical)
  65654. {
  65655. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65656. start = roundToInt (y1 * scale);
  65657. }
  65658. else if (horizontal)
  65659. {
  65660. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65661. start = roundToInt (x1 * scale);
  65662. }
  65663. else
  65664. {
  65665. grad = (y2 - y1) / (double) (x1 - x2);
  65666. yTerm = y1 - x1 / grad;
  65667. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65668. grad *= scale;
  65669. }
  65670. }
  65671. forcedinline void setY (const int y) throw()
  65672. {
  65673. if (vertical)
  65674. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65675. else if (! horizontal)
  65676. start = roundToInt ((y - yTerm) * grad);
  65677. }
  65678. inline const PixelARGB getPixel (const int x) const throw()
  65679. {
  65680. return vertical ? linePix
  65681. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65682. }
  65683. private:
  65684. const PixelARGB* const lookupTable;
  65685. const int numEntries;
  65686. PixelARGB linePix;
  65687. int start, scale;
  65688. double grad, yTerm;
  65689. bool vertical, horizontal;
  65690. enum { numScaleBits = 12 };
  65691. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65692. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65693. };
  65694. class RadialGradientPixelGenerator
  65695. {
  65696. public:
  65697. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65698. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65699. : lookupTable (lookupTable_),
  65700. numEntries (numEntries_),
  65701. gx1 (gradient.x1),
  65702. gy1 (gradient.y1)
  65703. {
  65704. jassert (numEntries_ >= 0);
  65705. const float gdx = gradient.x1 - gradient.x2;
  65706. const float gdy = gradient.y1 - gradient.y2;
  65707. maxDist = gdx * gdx + gdy * gdy;
  65708. invScale = numEntries / sqrt (maxDist);
  65709. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65710. }
  65711. forcedinline void setY (const int y) throw()
  65712. {
  65713. dy = y - gy1;
  65714. dy *= dy;
  65715. }
  65716. inline const PixelARGB getPixel (const int px) const throw()
  65717. {
  65718. double x = px - gx1;
  65719. x *= x;
  65720. x += dy;
  65721. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65722. }
  65723. protected:
  65724. const PixelARGB* const lookupTable;
  65725. const int numEntries;
  65726. const double gx1, gy1;
  65727. double maxDist, invScale, dy;
  65728. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65729. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65730. };
  65731. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65732. {
  65733. public:
  65734. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65735. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65736. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65737. inverseTransform (transform.inverted())
  65738. {
  65739. tM10 = inverseTransform.mat10;
  65740. tM00 = inverseTransform.mat00;
  65741. }
  65742. forcedinline void setY (const int y) throw()
  65743. {
  65744. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65745. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65746. }
  65747. inline const PixelARGB getPixel (const int px) const throw()
  65748. {
  65749. double x = px;
  65750. const double y = tM10 * x + lineYM11;
  65751. x = tM00 * x + lineYM01;
  65752. x *= x;
  65753. x += y * y;
  65754. if (x >= maxDist)
  65755. return lookupTable [numEntries];
  65756. else
  65757. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65758. }
  65759. private:
  65760. double tM10, tM00, lineYM01, lineYM11;
  65761. const AffineTransform inverseTransform;
  65762. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65763. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65764. };
  65765. template <class PixelType, class GradientType>
  65766. class GradientEdgeTableRenderer : public GradientType
  65767. {
  65768. public:
  65769. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65770. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65771. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65772. destData (destData_)
  65773. {
  65774. }
  65775. forcedinline void setEdgeTableYPos (const int y) throw()
  65776. {
  65777. linePixels = (PixelType*) destData.getLinePointer (y);
  65778. GradientType::setY (y);
  65779. }
  65780. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65781. {
  65782. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65783. }
  65784. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65785. {
  65786. PixelType* dest = linePixels + x;
  65787. if (alphaLevel < 0xff)
  65788. {
  65789. do
  65790. {
  65791. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65792. } while (--width > 0);
  65793. }
  65794. else
  65795. {
  65796. do
  65797. {
  65798. (dest++)->blend (GradientType::getPixel (x++));
  65799. } while (--width > 0);
  65800. }
  65801. }
  65802. private:
  65803. const Image::BitmapData& destData;
  65804. PixelType* linePixels;
  65805. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65806. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65807. };
  65808. static forcedinline int safeModulo (int n, const int divisor) throw()
  65809. {
  65810. jassert (divisor > 0);
  65811. n %= divisor;
  65812. return (n < 0) ? (n + divisor) : n;
  65813. }
  65814. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65815. class ImageFillEdgeTableRenderer
  65816. {
  65817. public:
  65818. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65819. const Image::BitmapData& srcData_,
  65820. const int extraAlpha_,
  65821. const int x, const int y) throw()
  65822. : destData (destData_),
  65823. srcData (srcData_),
  65824. extraAlpha (extraAlpha_ + 1),
  65825. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65826. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65827. {
  65828. }
  65829. forcedinline void setEdgeTableYPos (int y) throw()
  65830. {
  65831. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65832. y -= yOffset;
  65833. if (repeatPattern)
  65834. {
  65835. jassert (y >= 0);
  65836. y %= srcData.height;
  65837. }
  65838. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65839. }
  65840. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65841. {
  65842. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65843. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65844. }
  65845. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65846. {
  65847. DestPixelType* dest = linePixels + x;
  65848. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65849. x -= xOffset;
  65850. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65851. if (alphaLevel < 0xfe)
  65852. {
  65853. do
  65854. {
  65855. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65856. } while (--width > 0);
  65857. }
  65858. else
  65859. {
  65860. if (repeatPattern)
  65861. {
  65862. do
  65863. {
  65864. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65865. } while (--width > 0);
  65866. }
  65867. else
  65868. {
  65869. copyRow (dest, sourceLineStart + x, width);
  65870. }
  65871. }
  65872. }
  65873. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65874. {
  65875. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65876. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65877. uint8* mask = (uint8*) (s + x - xOffset);
  65878. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65879. mask += PixelARGB::indexA;
  65880. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65881. }
  65882. private:
  65883. const Image::BitmapData& destData;
  65884. const Image::BitmapData& srcData;
  65885. const int extraAlpha, xOffset, yOffset;
  65886. DestPixelType* linePixels;
  65887. SrcPixelType* sourceLineStart;
  65888. template <class PixelType1, class PixelType2>
  65889. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65890. {
  65891. do
  65892. {
  65893. dest++ ->blend (*src++);
  65894. } while (--width > 0);
  65895. }
  65896. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65897. {
  65898. memcpy (dest, src, width * sizeof (PixelRGB));
  65899. }
  65900. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65901. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65902. };
  65903. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65904. class TransformedImageFillEdgeTableRenderer
  65905. {
  65906. public:
  65907. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65908. const Image::BitmapData& srcData_,
  65909. const AffineTransform& transform,
  65910. const int extraAlpha_,
  65911. const bool betterQuality_) throw()
  65912. : interpolator (transform),
  65913. destData (destData_),
  65914. srcData (srcData_),
  65915. extraAlpha (extraAlpha_ + 1),
  65916. betterQuality (betterQuality_),
  65917. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  65918. pixelOffsetInt (betterQuality_ ? -128 : 0),
  65919. maxX (srcData_.width - 1),
  65920. maxY (srcData_.height - 1),
  65921. scratchSize (2048)
  65922. {
  65923. scratchBuffer.malloc (scratchSize);
  65924. }
  65925. ~TransformedImageFillEdgeTableRenderer() throw()
  65926. {
  65927. }
  65928. forcedinline void setEdgeTableYPos (const int newY) throw()
  65929. {
  65930. y = newY;
  65931. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  65932. }
  65933. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  65934. {
  65935. alphaLevel *= extraAlpha;
  65936. alphaLevel >>= 8;
  65937. SrcPixelType p;
  65938. generate (&p, x, 1);
  65939. linePixels[x].blend (p, alphaLevel);
  65940. }
  65941. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  65942. {
  65943. if (width > scratchSize)
  65944. {
  65945. scratchSize = width;
  65946. scratchBuffer.malloc (scratchSize);
  65947. }
  65948. SrcPixelType* span = scratchBuffer;
  65949. generate (span, x, width);
  65950. DestPixelType* dest = linePixels + x;
  65951. alphaLevel *= extraAlpha;
  65952. alphaLevel >>= 8;
  65953. if (alphaLevel < 0xfe)
  65954. {
  65955. do
  65956. {
  65957. dest++ ->blend (*span++, alphaLevel);
  65958. } while (--width > 0);
  65959. }
  65960. else
  65961. {
  65962. do
  65963. {
  65964. dest++ ->blend (*span++);
  65965. } while (--width > 0);
  65966. }
  65967. }
  65968. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  65969. {
  65970. if (width > scratchSize)
  65971. {
  65972. scratchSize = width;
  65973. scratchBuffer.malloc (scratchSize);
  65974. }
  65975. y = y_;
  65976. generate (scratchBuffer, x, width);
  65977. const uint8* mask = reinterpret_cast <uint8*> (scratchBuffer.getData());
  65978. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65979. mask += PixelARGB::indexA;
  65980. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  65981. }
  65982. private:
  65983. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  65984. {
  65985. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65986. do
  65987. {
  65988. int hiResX, hiResY;
  65989. this->interpolator.next (hiResX, hiResY);
  65990. hiResX += pixelOffsetInt;
  65991. hiResY += pixelOffsetInt;
  65992. int loResX = hiResX >> 8;
  65993. int loResY = hiResY >> 8;
  65994. if (repeatPattern)
  65995. {
  65996. loResX = safeModulo (loResX, srcData.width);
  65997. loResY = safeModulo (loResY, srcData.height);
  65998. }
  65999. if (betterQuality
  66000. && ((unsigned int) loResX) < (unsigned int) maxX
  66001. && ((unsigned int) loResY) < (unsigned int) maxY)
  66002. {
  66003. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  66004. hiResX &= 255;
  66005. hiResY &= 255;
  66006. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66007. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66008. c[0] += weight * src[0];
  66009. c[1] += weight * src[1];
  66010. c[2] += weight * src[2];
  66011. c[3] += weight * src[3];
  66012. weight = hiResX * (256 - hiResY);
  66013. c[0] += weight * src[4];
  66014. c[1] += weight * src[5];
  66015. c[2] += weight * src[6];
  66016. c[3] += weight * src[7];
  66017. src += this->srcData.lineStride;
  66018. weight = (256 - hiResX) * hiResY;
  66019. c[0] += weight * src[0];
  66020. c[1] += weight * src[1];
  66021. c[2] += weight * src[2];
  66022. c[3] += weight * src[3];
  66023. weight = hiResX * hiResY;
  66024. c[0] += weight * src[4];
  66025. c[1] += weight * src[5];
  66026. c[2] += weight * src[6];
  66027. c[3] += weight * src[7];
  66028. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66029. (uint8) (c[PixelARGB::indexR] >> 16),
  66030. (uint8) (c[PixelARGB::indexG] >> 16),
  66031. (uint8) (c[PixelARGB::indexB] >> 16));
  66032. }
  66033. else
  66034. {
  66035. if (! repeatPattern)
  66036. {
  66037. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66038. if (loResX < 0) loResX = 0;
  66039. if (loResY < 0) loResY = 0;
  66040. if (loResX > maxX) loResX = maxX;
  66041. if (loResY > maxY) loResY = maxY;
  66042. }
  66043. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66044. }
  66045. ++dest;
  66046. } while (--numPixels > 0);
  66047. }
  66048. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66049. {
  66050. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66051. do
  66052. {
  66053. int hiResX, hiResY;
  66054. this->interpolator.next (hiResX, hiResY);
  66055. hiResX += pixelOffsetInt;
  66056. hiResY += pixelOffsetInt;
  66057. int loResX = hiResX >> 8;
  66058. int loResY = hiResY >> 8;
  66059. if (repeatPattern)
  66060. {
  66061. loResX = safeModulo (loResX, srcData.width);
  66062. loResY = safeModulo (loResY, srcData.height);
  66063. }
  66064. if (betterQuality
  66065. && ((unsigned int) loResX) < (unsigned int) maxX
  66066. && ((unsigned int) loResY) < (unsigned int) maxY)
  66067. {
  66068. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66069. hiResX &= 255;
  66070. hiResY &= 255;
  66071. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66072. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66073. c[0] += weight * src[0];
  66074. c[1] += weight * src[1];
  66075. c[2] += weight * src[2];
  66076. weight = hiResX * (256 - hiResY);
  66077. c[0] += weight * src[3];
  66078. c[1] += weight * src[4];
  66079. c[2] += weight * src[5];
  66080. src += this->srcData.lineStride;
  66081. weight = (256 - hiResX) * hiResY;
  66082. c[0] += weight * src[0];
  66083. c[1] += weight * src[1];
  66084. c[2] += weight * src[2];
  66085. weight = hiResX * hiResY;
  66086. c[0] += weight * src[3];
  66087. c[1] += weight * src[4];
  66088. c[2] += weight * src[5];
  66089. dest->setARGB ((uint8) 255,
  66090. (uint8) (c[PixelRGB::indexR] >> 16),
  66091. (uint8) (c[PixelRGB::indexG] >> 16),
  66092. (uint8) (c[PixelRGB::indexB] >> 16));
  66093. }
  66094. else
  66095. {
  66096. if (! repeatPattern)
  66097. {
  66098. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66099. if (loResX < 0) loResX = 0;
  66100. if (loResY < 0) loResY = 0;
  66101. if (loResX > maxX) loResX = maxX;
  66102. if (loResY > maxY) loResY = maxY;
  66103. }
  66104. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66105. }
  66106. ++dest;
  66107. } while (--numPixels > 0);
  66108. }
  66109. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66110. {
  66111. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66112. do
  66113. {
  66114. int hiResX, hiResY;
  66115. this->interpolator.next (hiResX, hiResY);
  66116. hiResX += pixelOffsetInt;
  66117. hiResY += pixelOffsetInt;
  66118. int loResX = hiResX >> 8;
  66119. int loResY = hiResY >> 8;
  66120. if (repeatPattern)
  66121. {
  66122. loResX = safeModulo (loResX, srcData.width);
  66123. loResY = safeModulo (loResY, srcData.height);
  66124. }
  66125. if (betterQuality
  66126. && ((unsigned int) loResX) < (unsigned int) maxX
  66127. && ((unsigned int) loResY) < (unsigned int) maxY)
  66128. {
  66129. hiResX &= 255;
  66130. hiResY &= 255;
  66131. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66132. uint32 c = 256 * 128;
  66133. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66134. c += src[1] * (hiResX * (256 - hiResY));
  66135. src += this->srcData.lineStride;
  66136. c += src[0] * ((256 - hiResX) * hiResY);
  66137. c += src[1] * (hiResX * hiResY);
  66138. *((uint8*) dest) = (uint8) c;
  66139. }
  66140. else
  66141. {
  66142. if (! repeatPattern)
  66143. {
  66144. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66145. if (loResX < 0) loResX = 0;
  66146. if (loResY < 0) loResY = 0;
  66147. if (loResX > maxX) loResX = maxX;
  66148. if (loResY > maxY) loResY = maxY;
  66149. }
  66150. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66151. }
  66152. ++dest;
  66153. } while (--numPixels > 0);
  66154. }
  66155. class TransformedImageSpanInterpolator
  66156. {
  66157. public:
  66158. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66159. : inverseTransform (transform.inverted())
  66160. {}
  66161. void setStartOfLine (float x, float y, const int numPixels) throw()
  66162. {
  66163. float x1 = x, y1 = y;
  66164. inverseTransform.transformPoint (x1, y1);
  66165. x += numPixels;
  66166. inverseTransform.transformPoint (x, y);
  66167. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66168. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66169. }
  66170. void next (int& x, int& y) throw()
  66171. {
  66172. x = xBresenham.n;
  66173. xBresenham.stepToNext();
  66174. y = yBresenham.n;
  66175. yBresenham.stepToNext();
  66176. }
  66177. private:
  66178. class BresenhamInterpolator
  66179. {
  66180. public:
  66181. BresenhamInterpolator() throw() {}
  66182. void set (const int n1, const int n2, const int numSteps_) throw()
  66183. {
  66184. numSteps = jmax (1, numSteps_);
  66185. step = (n2 - n1) / numSteps;
  66186. remainder = modulo = (n2 - n1) % numSteps;
  66187. n = n1;
  66188. if (modulo <= 0)
  66189. {
  66190. modulo += numSteps;
  66191. remainder += numSteps;
  66192. --step;
  66193. }
  66194. modulo -= numSteps;
  66195. }
  66196. forcedinline void stepToNext() throw()
  66197. {
  66198. modulo += remainder;
  66199. n += step;
  66200. if (modulo > 0)
  66201. {
  66202. modulo -= numSteps;
  66203. ++n;
  66204. }
  66205. }
  66206. int n;
  66207. private:
  66208. int numSteps, step, modulo, remainder;
  66209. };
  66210. const AffineTransform inverseTransform;
  66211. BresenhamInterpolator xBresenham, yBresenham;
  66212. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66213. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66214. };
  66215. TransformedImageSpanInterpolator interpolator;
  66216. const Image::BitmapData& destData;
  66217. const Image::BitmapData& srcData;
  66218. const int extraAlpha;
  66219. const bool betterQuality;
  66220. const float pixelOffset;
  66221. const int pixelOffsetInt, maxX, maxY;
  66222. int y;
  66223. DestPixelType* linePixels;
  66224. HeapBlock <SrcPixelType> scratchBuffer;
  66225. int scratchSize;
  66226. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66227. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66228. };
  66229. class LLGCSavedState
  66230. {
  66231. public:
  66232. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66233. const Font& font_, const FillType& fillType_,
  66234. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66235. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66236. xOffset (xOffset_), yOffset (yOffset_),
  66237. font (font_), fillType (fillType_),
  66238. interpolationQuality (interpolationQuality_)
  66239. {
  66240. }
  66241. LLGCSavedState (const LLGCSavedState& other) throw()
  66242. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66243. yOffset (other.yOffset), font (other.font),
  66244. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66245. {
  66246. }
  66247. ~LLGCSavedState() throw()
  66248. {
  66249. }
  66250. bool clipToRectangle (const Rectangle<int>& r) throw()
  66251. {
  66252. dupeEdgeTableIfMultiplyReferenced();
  66253. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66254. return ! edgeTable->edgeTable.isEmpty();
  66255. }
  66256. bool clipToRectangleList (const RectangleList& r) throw()
  66257. {
  66258. dupeEdgeTableIfMultiplyReferenced();
  66259. RectangleList offsetList (r);
  66260. offsetList.offsetAll (xOffset, yOffset);
  66261. EdgeTable e2 (offsetList);
  66262. edgeTable->edgeTable.clipToEdgeTable (e2);
  66263. return ! edgeTable->edgeTable.isEmpty();
  66264. }
  66265. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66266. {
  66267. dupeEdgeTableIfMultiplyReferenced();
  66268. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66269. return ! edgeTable->edgeTable.isEmpty();
  66270. }
  66271. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66272. {
  66273. dupeEdgeTableIfMultiplyReferenced();
  66274. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66275. edgeTable->edgeTable.clipToEdgeTable (et);
  66276. }
  66277. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66278. {
  66279. et.clipToEdgeTable (edgeTable->edgeTable);
  66280. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66281. if (fillType.isGradient())
  66282. {
  66283. jassert (! replaceContents); // that option is just for solid colours
  66284. ColourGradient g2 (*(fillType.gradient));
  66285. g2.multiplyOpacity (fillType.getOpacity());
  66286. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66287. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66288. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66289. const bool isIdentity = transform.isOnlyTranslation();
  66290. if (isIdentity)
  66291. {
  66292. // If our translation doesn't involve any distortion, we can speed it up..
  66293. transform.transformPoint (g2.x1, g2.y1);
  66294. transform.transformPoint (g2.x2, g2.y2);
  66295. transform = AffineTransform::identity;
  66296. }
  66297. HeapBlock <PixelARGB> lookupTable;
  66298. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66299. jassert (numLookupEntries > 0);
  66300. switch (image.getFormat())
  66301. {
  66302. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66303. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66304. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66305. }
  66306. }
  66307. else if (fillType.isTiledImage())
  66308. {
  66309. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66310. }
  66311. else
  66312. {
  66313. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66314. switch (image.getFormat())
  66315. {
  66316. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66317. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66318. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66319. }
  66320. }
  66321. }
  66322. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66323. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66324. {
  66325. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66326. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66327. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66328. const int alpha = fillType.colour.getAlpha();
  66329. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66330. if (transform.isOnlyTranslation())
  66331. {
  66332. // If our translation doesn't involve any distortion, just use a simple blit..
  66333. int tx = (int) (transform.getTranslationX() * 256.0f);
  66334. int ty = (int) (transform.getTranslationY() * 256.0f);
  66335. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66336. {
  66337. tx = ((tx + 128) >> 8);
  66338. ty = ((ty + 128) >> 8);
  66339. if (tiledFillClipRegion != 0)
  66340. {
  66341. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66342. }
  66343. else
  66344. {
  66345. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66346. et.clipToEdgeTable (edgeTable->edgeTable);
  66347. if (! et.isEmpty())
  66348. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66349. }
  66350. return;
  66351. }
  66352. }
  66353. if (transform.isSingularity())
  66354. return;
  66355. if (tiledFillClipRegion != 0)
  66356. {
  66357. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66358. }
  66359. else
  66360. {
  66361. Path p;
  66362. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66363. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66364. et.clipToEdgeTable (edgeTable->edgeTable);
  66365. if (! et.isEmpty())
  66366. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66367. }
  66368. }
  66369. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66370. {
  66371. if (! image.hasAlphaChannel())
  66372. {
  66373. Path p;
  66374. p.addRectangle (srcClip);
  66375. clipToPath (p, t);
  66376. return;
  66377. }
  66378. dupeEdgeTableIfMultiplyReferenced();
  66379. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66380. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66381. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66382. EdgeTable& et = edgeTable->edgeTable;
  66383. if (transform.isOnlyTranslation())
  66384. {
  66385. // If our translation doesn't involve any distortion, just use a simple blit..
  66386. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66387. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66388. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66389. {
  66390. const int imageX = ((tx + 128) >> 8);
  66391. const int imageY = ((ty + 128) >> 8);
  66392. if (image.getFormat() == Image::ARGB)
  66393. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66394. else
  66395. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66396. return;
  66397. }
  66398. }
  66399. if (transform.isSingularity())
  66400. {
  66401. et.clipToRectangle (Rectangle<int>());
  66402. return;
  66403. }
  66404. {
  66405. Path p;
  66406. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66407. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66408. et.clipToEdgeTable (et2);
  66409. }
  66410. if (! et.isEmpty())
  66411. {
  66412. if (image.getFormat() == Image::ARGB)
  66413. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66414. else
  66415. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66416. }
  66417. }
  66418. template <class SrcPixelType>
  66419. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66420. {
  66421. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66422. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66423. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66424. et.getMaximumBounds().getWidth());
  66425. }
  66426. template <class SrcPixelType>
  66427. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66428. {
  66429. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66430. et.clipToRectangle (r);
  66431. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66432. for (int y = 0; y < r.getHeight(); ++y)
  66433. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66434. }
  66435. class EdgeTableHolder : public ReferenceCountedObject
  66436. {
  66437. public:
  66438. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66439. EdgeTable edgeTable;
  66440. };
  66441. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66442. int xOffset, yOffset;
  66443. Font font;
  66444. FillType fillType;
  66445. Graphics::ResamplingQuality interpolationQuality;
  66446. private:
  66447. LLGCSavedState& operator= (const LLGCSavedState&);
  66448. void dupeEdgeTableIfMultiplyReferenced() throw()
  66449. {
  66450. if (edgeTable->getReferenceCount() > 1)
  66451. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66452. }
  66453. template <class DestPixelType>
  66454. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66455. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66456. {
  66457. jassert (destData.pixelStride == sizeof (DestPixelType));
  66458. if (g.isRadial)
  66459. {
  66460. if (isIdentity)
  66461. {
  66462. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66463. et.iterate (renderer);
  66464. }
  66465. else
  66466. {
  66467. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66468. et.iterate (renderer);
  66469. }
  66470. }
  66471. else
  66472. {
  66473. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66474. et.iterate (renderer);
  66475. }
  66476. }
  66477. template <class DestPixelType>
  66478. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66479. {
  66480. jassert (destData.pixelStride == sizeof (DestPixelType));
  66481. if (replaceContents)
  66482. {
  66483. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66484. et.iterate (r);
  66485. }
  66486. else
  66487. {
  66488. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66489. et.iterate (r);
  66490. }
  66491. }
  66492. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66493. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66494. {
  66495. switch (destImage.getFormat())
  66496. {
  66497. case Image::ARGB:
  66498. switch (srcImage.getFormat())
  66499. {
  66500. case Image::ARGB:
  66501. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66502. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66503. break;
  66504. case Image::RGB:
  66505. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66506. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66507. break;
  66508. default:
  66509. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66510. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66511. break;
  66512. }
  66513. break;
  66514. case Image::RGB:
  66515. switch (srcImage.getFormat())
  66516. {
  66517. case Image::ARGB:
  66518. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66519. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66520. break;
  66521. case Image::RGB:
  66522. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66523. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66524. break;
  66525. default:
  66526. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66527. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66528. break;
  66529. }
  66530. break;
  66531. default:
  66532. switch (srcImage.getFormat())
  66533. {
  66534. case Image::ARGB:
  66535. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66536. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66537. break;
  66538. case Image::RGB:
  66539. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66540. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66541. break;
  66542. default:
  66543. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66544. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66545. break;
  66546. }
  66547. break;
  66548. }
  66549. }
  66550. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66551. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66552. {
  66553. switch (destImage.getFormat())
  66554. {
  66555. case Image::ARGB:
  66556. switch (srcImage.getFormat())
  66557. {
  66558. case Image::ARGB:
  66559. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66560. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66561. break;
  66562. case Image::RGB:
  66563. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66564. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66565. break;
  66566. default:
  66567. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66568. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66569. break;
  66570. }
  66571. break;
  66572. case Image::RGB:
  66573. switch (srcImage.getFormat())
  66574. {
  66575. case Image::ARGB:
  66576. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66577. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66578. break;
  66579. case Image::RGB:
  66580. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66581. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66582. break;
  66583. default:
  66584. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66585. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66586. break;
  66587. }
  66588. break;
  66589. default:
  66590. switch (srcImage.getFormat())
  66591. {
  66592. case Image::ARGB:
  66593. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66594. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66595. break;
  66596. case Image::RGB:
  66597. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66598. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66599. break;
  66600. default:
  66601. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66602. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66603. break;
  66604. }
  66605. break;
  66606. }
  66607. }
  66608. };
  66609. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66610. : image (image_)
  66611. {
  66612. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66613. FillType(), Graphics::mediumResamplingQuality);
  66614. }
  66615. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66616. {
  66617. }
  66618. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66619. {
  66620. return false;
  66621. }
  66622. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66623. {
  66624. currentState->xOffset += x;
  66625. currentState->yOffset += y;
  66626. }
  66627. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66628. {
  66629. return currentState->clipToRectangle (r);
  66630. }
  66631. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66632. {
  66633. return currentState->clipToRectangleList (clipRegion);
  66634. }
  66635. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66636. {
  66637. currentState->excludeClipRectangle (r);
  66638. }
  66639. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66640. {
  66641. currentState->clipToPath (path, transform);
  66642. }
  66643. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66644. {
  66645. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66646. }
  66647. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66648. {
  66649. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66650. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66651. }
  66652. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66653. {
  66654. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66655. }
  66656. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66657. {
  66658. return currentState->edgeTable->edgeTable.isEmpty();
  66659. }
  66660. void LowLevelGraphicsSoftwareRenderer::saveState()
  66661. {
  66662. stateStack.add (new LLGCSavedState (*currentState));
  66663. }
  66664. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66665. {
  66666. LLGCSavedState* const top = stateStack.getLast();
  66667. if (top != 0)
  66668. {
  66669. currentState = top;
  66670. stateStack.removeLast (1, false);
  66671. }
  66672. else
  66673. {
  66674. jassertfalse // trying to pop with an empty stack!
  66675. }
  66676. }
  66677. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66678. {
  66679. currentState->fillType = fillType;
  66680. }
  66681. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66682. {
  66683. currentState->fillType.setOpacity (newOpacity);
  66684. }
  66685. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66686. {
  66687. currentState->interpolationQuality = quality;
  66688. }
  66689. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66690. {
  66691. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66692. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66693. if (! clipped.isEmpty())
  66694. {
  66695. EdgeTable et (clipped);
  66696. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66697. }
  66698. }
  66699. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66700. {
  66701. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66702. path, transform.translated ((float) currentState->xOffset,
  66703. (float) currentState->yOffset));
  66704. currentState->fillEdgeTable (image, et);
  66705. }
  66706. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66707. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66708. {
  66709. jassert (sourceImage.getBounds().contains (srcClip));
  66710. currentState->renderImage (image, sourceImage, srcClip, transform,
  66711. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66712. }
  66713. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66714. {
  66715. Path p;
  66716. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66717. fillPath (p, AffineTransform::identity);
  66718. }
  66719. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66720. {
  66721. if (bottom > top)
  66722. {
  66723. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66724. currentState->fillEdgeTable (image, et);
  66725. }
  66726. }
  66727. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66728. {
  66729. if (right > left)
  66730. {
  66731. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66732. (float) (right - left), 1.0f);
  66733. currentState->fillEdgeTable (image, et);
  66734. }
  66735. }
  66736. class GlyphCache : private DeletedAtShutdown
  66737. {
  66738. public:
  66739. GlyphCache() throw()
  66740. : accessCounter (0), hits (0), misses (0)
  66741. {
  66742. for (int i = 120; --i >= 0;)
  66743. glyphs.add (new CachedGlyph());
  66744. }
  66745. ~GlyphCache() throw()
  66746. {
  66747. clearSingletonInstance();
  66748. }
  66749. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66750. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66751. {
  66752. ++accessCounter;
  66753. int oldestCounter = std::numeric_limits<int>::max();
  66754. CachedGlyph* oldest = 0;
  66755. for (int i = glyphs.size(); --i >= 0;)
  66756. {
  66757. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66758. if (glyph->glyph == glyphNumber && glyph->font == font)
  66759. {
  66760. ++hits;
  66761. glyph->lastAccessCount = accessCounter;
  66762. glyph->draw (state, image, x, y);
  66763. return;
  66764. }
  66765. if (glyph->lastAccessCount <= oldestCounter)
  66766. {
  66767. oldestCounter = glyph->lastAccessCount;
  66768. oldest = glyph;
  66769. }
  66770. }
  66771. if (hits + ++misses > (glyphs.size() << 4))
  66772. {
  66773. if (misses * 2 > hits)
  66774. {
  66775. for (int i = 32; --i >= 0;)
  66776. glyphs.add (new CachedGlyph());
  66777. }
  66778. hits = misses = 0;
  66779. oldest = glyphs.getLast();
  66780. }
  66781. jassert (oldest != 0);
  66782. oldest->lastAccessCount = accessCounter;
  66783. oldest->generate (font, glyphNumber);
  66784. oldest->draw (state, image, x, y);
  66785. }
  66786. class CachedGlyph
  66787. {
  66788. public:
  66789. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66790. ~CachedGlyph() {}
  66791. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66792. {
  66793. if (edgeTable != 0)
  66794. {
  66795. EdgeTable et (*edgeTable);
  66796. et.translate (x, roundToInt (y));
  66797. state.fillEdgeTable (image, et, false);
  66798. }
  66799. }
  66800. void generate (const Font& newFont, const int glyphNumber) throw()
  66801. {
  66802. font = newFont;
  66803. glyph = glyphNumber;
  66804. edgeTable = 0;
  66805. Path glyphPath;
  66806. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66807. if (! glyphPath.isEmpty())
  66808. {
  66809. const float fontHeight = font.getHeight();
  66810. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66811. .translated (0.0f, -0.5f));
  66812. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66813. glyphPath, transform);
  66814. }
  66815. }
  66816. int glyph, lastAccessCount;
  66817. Font font;
  66818. juce_UseDebuggingNewOperator
  66819. private:
  66820. ScopedPointer <EdgeTable> edgeTable;
  66821. CachedGlyph (const CachedGlyph&);
  66822. CachedGlyph& operator= (const CachedGlyph&);
  66823. };
  66824. juce_UseDebuggingNewOperator
  66825. private:
  66826. OwnedArray <CachedGlyph> glyphs;
  66827. int accessCounter, hits, misses;
  66828. GlyphCache (const GlyphCache&);
  66829. GlyphCache& operator= (const GlyphCache&);
  66830. };
  66831. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66832. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66833. {
  66834. currentState->font = newFont;
  66835. }
  66836. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66837. {
  66838. return currentState->font;
  66839. }
  66840. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66841. {
  66842. Font& f = currentState->font;
  66843. if (transform.isOnlyTranslation())
  66844. {
  66845. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66846. transform.getTranslationX() + (float) currentState->xOffset,
  66847. transform.getTranslationY() + (float) currentState->yOffset);
  66848. }
  66849. else
  66850. {
  66851. Path p;
  66852. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66853. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66854. }
  66855. }
  66856. #if JUCE_MSVC
  66857. #pragma warning (pop)
  66858. #endif
  66859. END_JUCE_NAMESPACE
  66860. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66861. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66862. BEGIN_JUCE_NAMESPACE
  66863. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66864. : flags (other.flags)
  66865. {
  66866. }
  66867. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66868. {
  66869. flags = other.flags;
  66870. return *this;
  66871. }
  66872. void RectanglePlacement::applyTo (double& x, double& y,
  66873. double& w, double& h,
  66874. const double dx, const double dy,
  66875. const double dw, const double dh) const throw()
  66876. {
  66877. if (w == 0 || h == 0)
  66878. return;
  66879. if ((flags & stretchToFit) != 0)
  66880. {
  66881. x = dx;
  66882. y = dy;
  66883. w = dw;
  66884. h = dh;
  66885. }
  66886. else
  66887. {
  66888. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66889. : jmin (dw / w, dh / h);
  66890. if ((flags & onlyReduceInSize) != 0)
  66891. scale = jmin (scale, 1.0);
  66892. if ((flags & onlyIncreaseInSize) != 0)
  66893. scale = jmax (scale, 1.0);
  66894. w *= scale;
  66895. h *= scale;
  66896. if ((flags & xLeft) != 0)
  66897. x = dx;
  66898. else if ((flags & xRight) != 0)
  66899. x = dx + dw - w;
  66900. else
  66901. x = dx + (dw - w) * 0.5;
  66902. if ((flags & yTop) != 0)
  66903. y = dy;
  66904. else if ((flags & yBottom) != 0)
  66905. y = dy + dh - h;
  66906. else
  66907. y = dy + (dh - h) * 0.5;
  66908. }
  66909. }
  66910. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66911. float w, float h,
  66912. const float dx, const float dy,
  66913. const float dw, const float dh) const throw()
  66914. {
  66915. if (w == 0 || h == 0)
  66916. return AffineTransform::identity;
  66917. const float scaleX = dw / w;
  66918. const float scaleY = dh / h;
  66919. if ((flags & stretchToFit) != 0)
  66920. return AffineTransform::translation (-x, -y)
  66921. .scaled (scaleX, scaleY)
  66922. .translated (dx, dy);
  66923. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  66924. : jmin (scaleX, scaleY);
  66925. if ((flags & onlyReduceInSize) != 0)
  66926. scale = jmin (scale, 1.0f);
  66927. if ((flags & onlyIncreaseInSize) != 0)
  66928. scale = jmax (scale, 1.0f);
  66929. w *= scale;
  66930. h *= scale;
  66931. float newX = dx;
  66932. if ((flags & xRight) != 0)
  66933. newX += dw - w; // right
  66934. else if ((flags & xLeft) == 0)
  66935. newX += (dw - w) / 2.0f; // centre
  66936. float newY = dy;
  66937. if ((flags & yBottom) != 0)
  66938. newY += dh - h; // bottom
  66939. else if ((flags & yTop) == 0)
  66940. newY += (dh - h) / 2.0f; // centre
  66941. return AffineTransform::translation (-x, -y)
  66942. .scaled (scale, scale)
  66943. .translated (newX, newY);
  66944. }
  66945. END_JUCE_NAMESPACE
  66946. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  66947. /*** Start of inlined file: juce_Drawable.cpp ***/
  66948. BEGIN_JUCE_NAMESPACE
  66949. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  66950. const AffineTransform& transform_,
  66951. const float opacity_) throw()
  66952. : g (g_),
  66953. transform (transform_),
  66954. opacity (opacity_)
  66955. {
  66956. }
  66957. Drawable::Drawable()
  66958. {
  66959. }
  66960. Drawable::~Drawable()
  66961. {
  66962. }
  66963. void Drawable::draw (Graphics& g, const float opacity,
  66964. const AffineTransform& transform) const
  66965. {
  66966. render (RenderingContext (g, transform, opacity));
  66967. }
  66968. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  66969. {
  66970. draw (g, opacity, AffineTransform::translation (x, y));
  66971. }
  66972. void Drawable::drawWithin (Graphics& g,
  66973. const int destX,
  66974. const int destY,
  66975. const int destW,
  66976. const int destH,
  66977. const RectanglePlacement& placement,
  66978. const float opacity) const
  66979. {
  66980. if (destW > 0 && destH > 0)
  66981. {
  66982. Rectangle<float> bounds (getBounds());
  66983. draw (g, opacity,
  66984. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  66985. (float) destX, (float) destY,
  66986. (float) destW, (float) destH));
  66987. }
  66988. }
  66989. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  66990. {
  66991. Drawable* result = 0;
  66992. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  66993. if (image != 0)
  66994. {
  66995. DrawableImage* const di = new DrawableImage();
  66996. di->setImage (image, true);
  66997. result = di;
  66998. }
  66999. else
  67000. {
  67001. const String asString (String::createStringFromData (data, (int) numBytes));
  67002. XmlDocument doc (asString);
  67003. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  67004. if (outer != 0 && outer->hasTagName (T("svg")))
  67005. {
  67006. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67007. if (svg != 0)
  67008. result = Drawable::createFromSVG (*svg);
  67009. }
  67010. }
  67011. return result;
  67012. }
  67013. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67014. {
  67015. MemoryBlock mb;
  67016. dataSource.readIntoMemoryBlock (mb);
  67017. return createFromImageData (mb.getData(), mb.getSize());
  67018. }
  67019. Drawable* Drawable::createFromImageFile (const File& file)
  67020. {
  67021. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67022. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67023. }
  67024. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67025. {
  67026. Drawable* d = DrawablePath::createFromValueTree (tree);
  67027. if (d == 0)
  67028. {
  67029. d = DrawableComposite::createFromValueTree (tree);
  67030. if (d == 0)
  67031. {
  67032. d = DrawableImage::createFromValueTree (tree);
  67033. if (d == 0)
  67034. d = DrawableText::createFromValueTree (tree);
  67035. }
  67036. }
  67037. return d;
  67038. }
  67039. END_JUCE_NAMESPACE
  67040. /*** End of inlined file: juce_Drawable.cpp ***/
  67041. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  67042. BEGIN_JUCE_NAMESPACE
  67043. DrawableComposite::DrawableComposite()
  67044. {
  67045. }
  67046. DrawableComposite::~DrawableComposite()
  67047. {
  67048. }
  67049. void DrawableComposite::insertDrawable (Drawable* drawable,
  67050. const AffineTransform& transform,
  67051. const int index)
  67052. {
  67053. if (drawable != 0)
  67054. {
  67055. if (! drawables.contains (drawable))
  67056. {
  67057. drawables.insert (index, drawable);
  67058. if (transform.isIdentity())
  67059. transforms.insert (index, 0);
  67060. else
  67061. transforms.insert (index, new AffineTransform (transform));
  67062. }
  67063. else
  67064. {
  67065. jassertfalse // trying to add a drawable that's already in here!
  67066. }
  67067. }
  67068. }
  67069. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67070. const AffineTransform& transform,
  67071. const int index)
  67072. {
  67073. insertDrawable (drawable.createCopy(), transform, index);
  67074. }
  67075. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67076. {
  67077. drawables.remove (index, deleteDrawable);
  67078. transforms.remove (index);
  67079. }
  67080. void DrawableComposite::bringToFront (const int index)
  67081. {
  67082. if (index >= 0 && index < drawables.size() - 1)
  67083. {
  67084. drawables.move (index, -1);
  67085. transforms.move (index, -1);
  67086. }
  67087. }
  67088. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67089. {
  67090. if (drawables.size() > 0 && context.opacity > 0)
  67091. {
  67092. if (context.opacity >= 1.0f || drawables.size() == 1)
  67093. {
  67094. Drawable::RenderingContext contextCopy (context);
  67095. for (int i = 0; i < drawables.size(); ++i)
  67096. {
  67097. const AffineTransform* const t = transforms.getUnchecked(i);
  67098. contextCopy.transform = (t == 0) ? context.transform
  67099. : t->followedBy (context.transform);
  67100. drawables.getUnchecked(i)->render (contextCopy);
  67101. }
  67102. }
  67103. else
  67104. {
  67105. // To correctly render a whole composite layer with an overall transparency,
  67106. // we need to render everything opaquely into a temp buffer, then blend that
  67107. // with the target opacity...
  67108. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67109. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67110. {
  67111. Graphics tempG (tempImage);
  67112. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67113. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67114. render (tempContext);
  67115. }
  67116. context.g.setOpacity (context.opacity);
  67117. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67118. }
  67119. }
  67120. }
  67121. const Rectangle<float> DrawableComposite::getBounds() const
  67122. {
  67123. Rectangle<float> bounds;
  67124. for (int i = 0; i < drawables.size(); ++i)
  67125. {
  67126. const Drawable* const d = drawables.getUnchecked(i);
  67127. const AffineTransform* const t = transforms.getUnchecked(i);
  67128. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  67129. : d->getBounds().transformed (*t));
  67130. if (bounds.isEmpty())
  67131. bounds = childBounds;
  67132. else if (! childBounds.isEmpty())
  67133. bounds = bounds.getUnion (childBounds);
  67134. }
  67135. return bounds;
  67136. }
  67137. bool DrawableComposite::hitTest (float x, float y) const
  67138. {
  67139. for (int i = 0; i < drawables.size(); ++i)
  67140. {
  67141. float tx = x;
  67142. float ty = y;
  67143. const AffineTransform* const t = transforms.getUnchecked(i);
  67144. if (t != 0)
  67145. t->inverted().transformPoint (tx, ty);
  67146. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67147. return true;
  67148. }
  67149. return false;
  67150. }
  67151. Drawable* DrawableComposite::createCopy() const
  67152. {
  67153. DrawableComposite* const dc = new DrawableComposite();
  67154. for (int i = 0; i < drawables.size(); ++i)
  67155. {
  67156. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67157. const AffineTransform* const t = transforms.getUnchecked(i);
  67158. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67159. }
  67160. return dc;
  67161. }
  67162. ValueTree DrawableComposite::createValueTree() const throw()
  67163. {
  67164. ValueTree v (T("Group"));
  67165. if (getName().isNotEmpty())
  67166. v.setProperty ("id", getName(), 0);
  67167. for (int i = 0; i < drawables.size(); ++i)
  67168. {
  67169. Drawable* const d = drawables.getUnchecked(i);
  67170. ValueTree child (d->createValueTree());
  67171. AffineTransform* transform = transforms.getUnchecked(i);
  67172. if (transform != 0)
  67173. {
  67174. String t;
  67175. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67176. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67177. child.setProperty ("transform", t, 0);
  67178. }
  67179. v.addChild (child, -1, 0);
  67180. }
  67181. return v;
  67182. }
  67183. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67184. {
  67185. if (! tree.hasType ("Group"))
  67186. return 0;
  67187. DrawableComposite* dc = new DrawableComposite();
  67188. dc->setName (tree ["id"]);
  67189. for (int i = 0; i < tree.getNumChildren(); ++i)
  67190. {
  67191. ValueTree childTree (tree.getChild (i));
  67192. Drawable* d = Drawable::createFromValueTree (childTree);
  67193. if (d != 0)
  67194. {
  67195. AffineTransform transform;
  67196. const String transformAtt (childTree ["transform"].toString());
  67197. if (transformAtt.isNotEmpty())
  67198. {
  67199. StringArray tokens;
  67200. tokens.addTokens (transformAtt.trim(), false);
  67201. tokens.removeEmptyStrings (true);
  67202. if (tokens.size() == 6)
  67203. {
  67204. float f[6];
  67205. for (int j = 0; j < 6; ++j)
  67206. f[j] = (float) tokens[j].getDoubleValue();
  67207. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67208. }
  67209. }
  67210. dc->insertDrawable (d, transform);
  67211. }
  67212. }
  67213. return dc;
  67214. }
  67215. END_JUCE_NAMESPACE
  67216. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67217. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67218. BEGIN_JUCE_NAMESPACE
  67219. DrawableImage::DrawableImage()
  67220. : image (0),
  67221. canDeleteImage (false),
  67222. opacity (1.0f),
  67223. overlayColour (0x00000000)
  67224. {
  67225. }
  67226. DrawableImage::~DrawableImage()
  67227. {
  67228. clearImage();
  67229. }
  67230. void DrawableImage::clearImage()
  67231. {
  67232. if (canDeleteImage && image != 0)
  67233. ImageCache::releaseOrDelete (image);
  67234. image = 0;
  67235. }
  67236. void DrawableImage::setImage (const Image& imageToCopy)
  67237. {
  67238. clearImage();
  67239. image = new Image (imageToCopy);
  67240. canDeleteImage = true;
  67241. }
  67242. void DrawableImage::setImage (Image* imageToUse,
  67243. const bool releaseWhenNotNeeded)
  67244. {
  67245. clearImage();
  67246. image = imageToUse;
  67247. canDeleteImage = releaseWhenNotNeeded;
  67248. }
  67249. void DrawableImage::setOpacity (const float newOpacity)
  67250. {
  67251. opacity = newOpacity;
  67252. }
  67253. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67254. {
  67255. overlayColour = newOverlayColour;
  67256. }
  67257. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67258. {
  67259. if (image != 0)
  67260. {
  67261. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67262. {
  67263. context.g.setOpacity (context.opacity * opacity);
  67264. context.g.drawImageTransformed (image, image->getBounds(),
  67265. context.transform, false);
  67266. }
  67267. if (! overlayColour.isTransparent())
  67268. {
  67269. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67270. context.g.drawImageTransformed (image, image->getBounds(),
  67271. context.transform, true);
  67272. }
  67273. }
  67274. }
  67275. const Rectangle<float> DrawableImage::getBounds() const
  67276. {
  67277. if (image == 0)
  67278. return Rectangle<float>();
  67279. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67280. }
  67281. bool DrawableImage::hitTest (float x, float y) const
  67282. {
  67283. return image != 0
  67284. && x >= 0.0f
  67285. && y >= 0.0f
  67286. && x < image->getWidth()
  67287. && y < image->getHeight()
  67288. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67289. }
  67290. Drawable* DrawableImage::createCopy() const
  67291. {
  67292. DrawableImage* const di = new DrawableImage();
  67293. di->opacity = opacity;
  67294. di->overlayColour = overlayColour;
  67295. if (image != 0)
  67296. {
  67297. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67298. {
  67299. di->setImage (*image);
  67300. }
  67301. else
  67302. {
  67303. ImageCache::incReferenceCount (image);
  67304. di->setImage (image, true);
  67305. }
  67306. }
  67307. return di;
  67308. }
  67309. ValueTree DrawableImage::createValueTree() const throw()
  67310. {
  67311. ValueTree v (T("Image"));
  67312. if (getName().isNotEmpty())
  67313. v.setProperty ("id", getName(), 0);
  67314. if (opacity < 1.0f)
  67315. v.setProperty ("opacity", (double) opacity, 0);
  67316. if (! overlayColour.isTransparent())
  67317. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67318. if (image != 0)
  67319. {
  67320. MemoryOutputStream imageData;
  67321. PNGImageFormat pngFormat;
  67322. if (pngFormat.writeImageToStream (*image, imageData))
  67323. {
  67324. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67325. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67326. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67327. v.setProperty ("data", base64, 0);
  67328. }
  67329. }
  67330. return v;
  67331. }
  67332. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67333. {
  67334. if (! tree.hasType ("Image"))
  67335. return 0;
  67336. DrawableImage* di = new DrawableImage();
  67337. di->setName (tree ["id"]);
  67338. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67339. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67340. MemoryBlock imageData;
  67341. if (imageData.fromBase64Encoding (tree ["data"]))
  67342. {
  67343. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67344. if (im == 0)
  67345. return false;
  67346. di->setImage (im, true);
  67347. }
  67348. return di;
  67349. }
  67350. END_JUCE_NAMESPACE
  67351. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67352. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67353. BEGIN_JUCE_NAMESPACE
  67354. DrawablePath::DrawablePath()
  67355. : mainFill (FillType (Colours::black)),
  67356. strokeFill (FillType (Colours::transparentBlack)),
  67357. strokeType (0.0f)
  67358. {
  67359. }
  67360. DrawablePath::~DrawablePath()
  67361. {
  67362. }
  67363. void DrawablePath::setPath (const Path& newPath) throw()
  67364. {
  67365. path = newPath;
  67366. updateOutline();
  67367. }
  67368. void DrawablePath::setFill (const FillType& newFill) throw()
  67369. {
  67370. mainFill = newFill;
  67371. }
  67372. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67373. {
  67374. strokeFill = newFill;
  67375. }
  67376. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67377. {
  67378. strokeType = newStrokeType;
  67379. updateOutline();
  67380. }
  67381. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67382. {
  67383. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67384. }
  67385. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67386. {
  67387. {
  67388. FillType f (mainFill);
  67389. if (f.isGradient())
  67390. f.gradient->multiplyOpacity (context.opacity);
  67391. f.transform = f.transform.followedBy (context.transform);
  67392. context.g.setFillType (f);
  67393. context.g.fillPath (path, context.transform);
  67394. }
  67395. if (strokeType.getStrokeThickness() > 0.0f)
  67396. {
  67397. FillType f (strokeFill);
  67398. if (f.isGradient())
  67399. f.gradient->multiplyOpacity (context.opacity);
  67400. f.transform = f.transform.followedBy (context.transform);
  67401. context.g.setFillType (f);
  67402. context.g.fillPath (stroke, context.transform);
  67403. }
  67404. }
  67405. void DrawablePath::updateOutline()
  67406. {
  67407. stroke.clear();
  67408. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67409. }
  67410. const Rectangle<float> DrawablePath::getBounds() const
  67411. {
  67412. if (strokeType.getStrokeThickness() > 0.0f)
  67413. return stroke.getBounds();
  67414. else
  67415. return path.getBounds();
  67416. }
  67417. bool DrawablePath::hitTest (float x, float y) const
  67418. {
  67419. return path.contains (x, y)
  67420. || stroke.contains (x, y);
  67421. }
  67422. Drawable* DrawablePath::createCopy() const
  67423. {
  67424. DrawablePath* const dp = new DrawablePath();
  67425. dp->path = path;
  67426. dp->stroke = stroke;
  67427. dp->mainFill = mainFill;
  67428. dp->strokeFill = strokeFill;
  67429. dp->strokeType = strokeType;
  67430. return dp;
  67431. }
  67432. static const FillType readFillTypeFromTree (const ValueTree& v)
  67433. {
  67434. const String type (v["type"].toString());
  67435. if (type.equalsIgnoreCase (T("solid")))
  67436. {
  67437. const String colour (v ["colour"].toString());
  67438. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67439. : (uint32) colour.getHexValue32()));
  67440. }
  67441. else if (type.equalsIgnoreCase ("gradient"))
  67442. {
  67443. ColourGradient g;
  67444. g.x1 = v["x1"];
  67445. g.y1 = v["y1"];
  67446. g.x2 = v["x2"];
  67447. g.y2 = v["y2"];
  67448. g.isRadial = v["radial"];
  67449. StringArray colours;
  67450. colours.addTokens (v["colours"].toString(), false);
  67451. for (int i = 0; i < colours.size() / 2; ++i)
  67452. g.addColour (colours[i * 2].getDoubleValue(),
  67453. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67454. return FillType (g);
  67455. }
  67456. jassertfalse
  67457. return FillType();
  67458. }
  67459. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67460. {
  67461. ValueTree v (tagName);
  67462. if (fillType.isColour())
  67463. {
  67464. v.setProperty ("type", T("solid"), 0);
  67465. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67466. }
  67467. else if (fillType.isGradient())
  67468. {
  67469. v.setProperty ("type", T("gradient"), 0);
  67470. v.setProperty ("x1", fillType.gradient->x1, 0);
  67471. v.setProperty ("y1", fillType.gradient->y1, 0);
  67472. v.setProperty ("x2", fillType.gradient->x2, 0);
  67473. v.setProperty ("y2", fillType.gradient->y2, 0);
  67474. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67475. String s;
  67476. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67477. s << " " << fillType.gradient->getColourPosition (i)
  67478. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67479. v.setProperty ("colours", s.trimStart(), 0);
  67480. }
  67481. else
  67482. {
  67483. jassertfalse //xxx
  67484. }
  67485. return v;
  67486. }
  67487. ValueTree DrawablePath::createValueTree() const throw()
  67488. {
  67489. ValueTree v (T("Path"));
  67490. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67491. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67492. if (getName().isNotEmpty())
  67493. v.setProperty ("id", getName(), 0);
  67494. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67495. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67496. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67497. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67498. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67499. v.setProperty ("path", path.toString(), 0);
  67500. return v;
  67501. }
  67502. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67503. {
  67504. if (! tree.hasType ("Path"))
  67505. return 0;
  67506. DrawablePath* p = new DrawablePath();
  67507. p->setName (tree ["id"]);
  67508. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67509. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67510. const String jointStyle (tree ["jointStyle"].toString());
  67511. const String endStyle (tree ["capStyle"].toString());
  67512. p->strokeType
  67513. = PathStrokeType (tree ["strokeWidth"],
  67514. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67515. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67516. : PathStrokeType::mitered),
  67517. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67518. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67519. : PathStrokeType::butt));
  67520. p->path.clear();
  67521. p->path.restoreFromString (tree ["path"]);
  67522. p->updateOutline();
  67523. return p;
  67524. }
  67525. END_JUCE_NAMESPACE
  67526. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67527. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67528. BEGIN_JUCE_NAMESPACE
  67529. DrawableText::DrawableText()
  67530. : colour (Colours::white)
  67531. {
  67532. }
  67533. DrawableText::~DrawableText()
  67534. {
  67535. }
  67536. void DrawableText::setText (const GlyphArrangement& newText)
  67537. {
  67538. text = newText;
  67539. }
  67540. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67541. {
  67542. text.clear();
  67543. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67544. }
  67545. void DrawableText::setColour (const Colour& newColour)
  67546. {
  67547. colour = newColour;
  67548. }
  67549. void DrawableText::render (const Drawable::RenderingContext& context) const
  67550. {
  67551. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67552. text.draw (context.g, context.transform);
  67553. }
  67554. const Rectangle<float> DrawableText::getBounds() const
  67555. {
  67556. float x, y, w, h;
  67557. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67558. w -= x;
  67559. h -= y;
  67560. return Rectangle<float> (x, y, w, h);
  67561. }
  67562. bool DrawableText::hitTest (float x, float y) const
  67563. {
  67564. return text.findGlyphIndexAt (x, y) >= 0;
  67565. }
  67566. Drawable* DrawableText::createCopy() const
  67567. {
  67568. DrawableText* const dt = new DrawableText();
  67569. dt->text = text;
  67570. dt->colour = colour;
  67571. return dt;
  67572. }
  67573. ValueTree DrawableText::createValueTree() const throw()
  67574. {
  67575. ValueTree v (T("Text"));
  67576. if (getName().isNotEmpty())
  67577. v.setProperty ("id", getName(), 0);
  67578. jassertfalse // xxx not finished!
  67579. return v;
  67580. }
  67581. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67582. {
  67583. if (! tree.hasType ("Text"))
  67584. return 0;
  67585. DrawableText* dt = new DrawableText();
  67586. dt->setName (tree ["id"]);
  67587. jassertfalse // xxx not finished!
  67588. return dt;
  67589. }
  67590. END_JUCE_NAMESPACE
  67591. /*** End of inlined file: juce_DrawableText.cpp ***/
  67592. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67593. BEGIN_JUCE_NAMESPACE
  67594. class SVGState
  67595. {
  67596. public:
  67597. SVGState (const XmlElement* const topLevel)
  67598. : topLevelXml (topLevel),
  67599. elementX (0), elementY (0),
  67600. width (512), height (512),
  67601. viewBoxW (0), viewBoxH (0)
  67602. {
  67603. }
  67604. ~SVGState()
  67605. {
  67606. }
  67607. Drawable* parseSVGElement (const XmlElement& xml)
  67608. {
  67609. if (! xml.hasTagName (T("svg")))
  67610. return 0;
  67611. DrawableComposite* const drawable = new DrawableComposite();
  67612. drawable->setName (xml.getStringAttribute (T("id")));
  67613. SVGState newState (*this);
  67614. if (xml.hasAttribute (T("transform")))
  67615. newState.addTransform (xml);
  67616. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  67617. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  67618. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  67619. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  67620. if (xml.hasAttribute (T("viewBox")))
  67621. {
  67622. const String viewParams (xml.getStringAttribute (T("viewBox")));
  67623. int i = 0;
  67624. float vx, vy, vw, vh;
  67625. if (parseCoords (viewParams, vx, vy, i, true)
  67626. && parseCoords (viewParams, vw, vh, i, true)
  67627. && vw > 0
  67628. && vh > 0)
  67629. {
  67630. newState.viewBoxW = vw;
  67631. newState.viewBoxH = vh;
  67632. int placementFlags = 0;
  67633. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  67634. if (aspect.containsIgnoreCase (T("none")))
  67635. {
  67636. placementFlags = RectanglePlacement::stretchToFit;
  67637. }
  67638. else
  67639. {
  67640. if (aspect.containsIgnoreCase (T("slice")))
  67641. placementFlags |= RectanglePlacement::fillDestination;
  67642. if (aspect.containsIgnoreCase (T("xMin")))
  67643. placementFlags |= RectanglePlacement::xLeft;
  67644. else if (aspect.containsIgnoreCase (T("xMax")))
  67645. placementFlags |= RectanglePlacement::xRight;
  67646. else
  67647. placementFlags |= RectanglePlacement::xMid;
  67648. if (aspect.containsIgnoreCase (T("yMin")))
  67649. placementFlags |= RectanglePlacement::yTop;
  67650. else if (aspect.containsIgnoreCase (T("yMax")))
  67651. placementFlags |= RectanglePlacement::yBottom;
  67652. else
  67653. placementFlags |= RectanglePlacement::yMid;
  67654. }
  67655. const RectanglePlacement placement (placementFlags);
  67656. newState.transform
  67657. = placement.getTransformToFit (vx, vy, vw, vh,
  67658. 0.0f, 0.0f, newState.width, newState.height)
  67659. .followedBy (newState.transform);
  67660. }
  67661. }
  67662. else
  67663. {
  67664. if (viewBoxW == 0)
  67665. newState.viewBoxW = newState.width;
  67666. if (viewBoxH == 0)
  67667. newState.viewBoxH = newState.height;
  67668. }
  67669. newState.parseSubElements (xml, drawable);
  67670. return drawable;
  67671. }
  67672. private:
  67673. const XmlElement* const topLevelXml;
  67674. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67675. AffineTransform transform;
  67676. String cssStyleText;
  67677. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67678. {
  67679. forEachXmlChildElement (xml, e)
  67680. {
  67681. Drawable* d = 0;
  67682. if (e->hasTagName (T("g")))
  67683. d = parseGroupElement (*e);
  67684. else if (e->hasTagName (T("svg")))
  67685. d = parseSVGElement (*e);
  67686. else if (e->hasTagName (T("path")))
  67687. d = parsePath (*e);
  67688. else if (e->hasTagName (T("rect")))
  67689. d = parseRect (*e);
  67690. else if (e->hasTagName (T("circle")))
  67691. d = parseCircle (*e);
  67692. else if (e->hasTagName (T("ellipse")))
  67693. d = parseEllipse (*e);
  67694. else if (e->hasTagName (T("line")))
  67695. d = parseLine (*e);
  67696. else if (e->hasTagName (T("polyline")))
  67697. d = parsePolygon (*e, true);
  67698. else if (e->hasTagName (T("polygon")))
  67699. d = parsePolygon (*e, false);
  67700. else if (e->hasTagName (T("text")))
  67701. d = parseText (*e);
  67702. else if (e->hasTagName (T("switch")))
  67703. d = parseSwitch (*e);
  67704. else if (e->hasTagName (T("style")))
  67705. parseCSSStyle (*e);
  67706. parentDrawable->insertDrawable (d);
  67707. }
  67708. }
  67709. DrawableComposite* parseSwitch (const XmlElement& xml)
  67710. {
  67711. const XmlElement* const group = xml.getChildByName (T("g"));
  67712. if (group != 0)
  67713. return parseGroupElement (*group);
  67714. return 0;
  67715. }
  67716. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67717. {
  67718. DrawableComposite* const drawable = new DrawableComposite();
  67719. drawable->setName (xml.getStringAttribute (T("id")));
  67720. if (xml.hasAttribute (T("transform")))
  67721. {
  67722. SVGState newState (*this);
  67723. newState.addTransform (xml);
  67724. newState.parseSubElements (xml, drawable);
  67725. }
  67726. else
  67727. {
  67728. parseSubElements (xml, drawable);
  67729. }
  67730. return drawable;
  67731. }
  67732. Drawable* parsePath (const XmlElement& xml) const
  67733. {
  67734. const String d (xml.getStringAttribute (T("d")).trimStart());
  67735. Path path;
  67736. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  67737. path.setUsingNonZeroWinding (false);
  67738. int index = 0;
  67739. float lastX = 0, lastY = 0;
  67740. float lastX2 = 0, lastY2 = 0;
  67741. tchar lastCommandChar = 0;
  67742. bool isRelative = true;
  67743. bool carryOn = true;
  67744. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  67745. for (;;)
  67746. {
  67747. float x, y, x2, y2, x3, y3;
  67748. if (validCommandChars.containsChar (d[index]))
  67749. {
  67750. lastCommandChar = d [index++];
  67751. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67752. }
  67753. switch (lastCommandChar)
  67754. {
  67755. case T('M'):
  67756. case T('m'):
  67757. case T('L'):
  67758. case T('l'):
  67759. if (parseCoords (d, x, y, index, false))
  67760. {
  67761. if (isRelative)
  67762. {
  67763. x += lastX;
  67764. y += lastY;
  67765. }
  67766. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  67767. path.startNewSubPath (x, y);
  67768. else
  67769. path.lineTo (x, y);
  67770. lastX2 = lastX;
  67771. lastY2 = lastY;
  67772. lastX = x;
  67773. lastY = y;
  67774. }
  67775. else
  67776. {
  67777. ++index;
  67778. }
  67779. break;
  67780. case T('H'):
  67781. case T('h'):
  67782. if (parseCoord (d, x, index, false, true))
  67783. {
  67784. if (isRelative)
  67785. x += lastX;
  67786. path.lineTo (x, lastY);
  67787. lastX2 = lastX;
  67788. lastX = x;
  67789. }
  67790. else
  67791. {
  67792. ++index;
  67793. }
  67794. break;
  67795. case T('V'):
  67796. case T('v'):
  67797. if (parseCoord (d, y, index, false, false))
  67798. {
  67799. if (isRelative)
  67800. y += lastY;
  67801. path.lineTo (lastX, y);
  67802. lastY2 = lastY;
  67803. lastY = y;
  67804. }
  67805. else
  67806. {
  67807. ++index;
  67808. }
  67809. break;
  67810. case T('C'):
  67811. case T('c'):
  67812. if (parseCoords (d, x, y, index, false)
  67813. && parseCoords (d, x2, y2, index, false)
  67814. && parseCoords (d, x3, y3, index, false))
  67815. {
  67816. if (isRelative)
  67817. {
  67818. x += lastX;
  67819. y += lastY;
  67820. x2 += lastX;
  67821. y2 += lastY;
  67822. x3 += lastX;
  67823. y3 += lastY;
  67824. }
  67825. path.cubicTo (x, y, x2, y2, x3, y3);
  67826. lastX2 = x2;
  67827. lastY2 = y2;
  67828. lastX = x3;
  67829. lastY = y3;
  67830. }
  67831. else
  67832. {
  67833. ++index;
  67834. }
  67835. break;
  67836. case T('S'):
  67837. case T('s'):
  67838. if (parseCoords (d, x, y, index, false)
  67839. && parseCoords (d, x3, y3, index, false))
  67840. {
  67841. if (isRelative)
  67842. {
  67843. x += lastX;
  67844. y += lastY;
  67845. x3 += lastX;
  67846. y3 += lastY;
  67847. }
  67848. x2 = lastX + (lastX - lastX2);
  67849. y2 = lastY + (lastY - lastY2);
  67850. path.cubicTo (x2, y2, x, y, x3, y3);
  67851. lastX2 = x;
  67852. lastY2 = y;
  67853. lastX = x3;
  67854. lastY = y3;
  67855. }
  67856. else
  67857. {
  67858. ++index;
  67859. }
  67860. break;
  67861. case T('Q'):
  67862. case T('q'):
  67863. if (parseCoords (d, x, y, index, false)
  67864. && parseCoords (d, x2, y2, index, false))
  67865. {
  67866. if (isRelative)
  67867. {
  67868. x += lastX;
  67869. y += lastY;
  67870. x2 += lastX;
  67871. y2 += lastY;
  67872. }
  67873. path.quadraticTo (x, y, x2, y2);
  67874. lastX2 = x;
  67875. lastY2 = y;
  67876. lastX = x2;
  67877. lastY = y2;
  67878. }
  67879. else
  67880. {
  67881. ++index;
  67882. }
  67883. break;
  67884. case T('T'):
  67885. case T('t'):
  67886. if (parseCoords (d, x, y, index, false))
  67887. {
  67888. if (isRelative)
  67889. {
  67890. x += lastX;
  67891. y += lastY;
  67892. }
  67893. x2 = lastX + (lastX - lastX2);
  67894. y2 = lastY + (lastY - lastY2);
  67895. path.quadraticTo (x2, y2, x, y);
  67896. lastX2 = x2;
  67897. lastY2 = y2;
  67898. lastX = x;
  67899. lastY = y;
  67900. }
  67901. else
  67902. {
  67903. ++index;
  67904. }
  67905. break;
  67906. case T('A'):
  67907. case T('a'):
  67908. if (parseCoords (d, x, y, index, false))
  67909. {
  67910. String num;
  67911. if (parseNextNumber (d, num, index, false))
  67912. {
  67913. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67914. if (parseNextNumber (d, num, index, false))
  67915. {
  67916. const bool largeArc = num.getIntValue() != 0;
  67917. if (parseNextNumber (d, num, index, false))
  67918. {
  67919. const bool sweep = num.getIntValue() != 0;
  67920. if (parseCoords (d, x2, y2, index, false))
  67921. {
  67922. if (isRelative)
  67923. {
  67924. x2 += lastX;
  67925. y2 += lastY;
  67926. }
  67927. if (lastX != x2 || lastY != y2)
  67928. {
  67929. double centreX, centreY, startAngle, deltaAngle;
  67930. double rx = x, ry = y;
  67931. endpointToCentreParameters (lastX, lastY, x2, y2,
  67932. angle, largeArc, sweep,
  67933. rx, ry, centreX, centreY,
  67934. startAngle, deltaAngle);
  67935. path.addCentredArc ((float) centreX, (float) centreY,
  67936. (float) rx, (float) ry,
  67937. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  67938. false);
  67939. path.lineTo (x2, y2);
  67940. }
  67941. lastX2 = lastX;
  67942. lastY2 = lastY;
  67943. lastX = x2;
  67944. lastY = y2;
  67945. }
  67946. }
  67947. }
  67948. }
  67949. }
  67950. else
  67951. {
  67952. ++index;
  67953. }
  67954. break;
  67955. case T('Z'):
  67956. case T('z'):
  67957. path.closeSubPath();
  67958. while (CharacterFunctions::isWhitespace (d [index]))
  67959. ++index;
  67960. break;
  67961. default:
  67962. carryOn = false;
  67963. break;
  67964. }
  67965. if (! carryOn)
  67966. break;
  67967. }
  67968. return parseShape (xml, path);
  67969. }
  67970. Drawable* parseRect (const XmlElement& xml) const
  67971. {
  67972. Path rect;
  67973. const bool hasRX = xml.hasAttribute (T("rx"));
  67974. const bool hasRY = xml.hasAttribute (T("ry"));
  67975. if (hasRX || hasRY)
  67976. {
  67977. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  67978. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  67979. if (! hasRX)
  67980. rx = ry;
  67981. else if (! hasRY)
  67982. ry = rx;
  67983. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  67984. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  67985. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  67986. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  67987. rx, ry);
  67988. }
  67989. else
  67990. {
  67991. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  67992. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  67993. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  67994. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  67995. }
  67996. return parseShape (xml, rect);
  67997. }
  67998. Drawable* parseCircle (const XmlElement& xml) const
  67999. {
  68000. Path circle;
  68001. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68002. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68003. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  68004. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  68005. return parseShape (xml, circle);
  68006. }
  68007. Drawable* parseEllipse (const XmlElement& xml) const
  68008. {
  68009. Path ellipse;
  68010. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68011. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68012. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68013. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68014. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68015. return parseShape (xml, ellipse);
  68016. }
  68017. Drawable* parseLine (const XmlElement& xml) const
  68018. {
  68019. Path line;
  68020. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68021. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68022. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68023. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68024. line.startNewSubPath (x1, y1);
  68025. line.lineTo (x2, y2);
  68026. return parseShape (xml, line);
  68027. }
  68028. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68029. {
  68030. const String points (xml.getStringAttribute (T("points")));
  68031. Path path;
  68032. int index = 0;
  68033. float x, y;
  68034. if (parseCoords (points, x, y, index, true))
  68035. {
  68036. float firstX = x;
  68037. float firstY = y;
  68038. float lastX = 0, lastY = 0;
  68039. path.startNewSubPath (x, y);
  68040. while (parseCoords (points, x, y, index, true))
  68041. {
  68042. lastX = x;
  68043. lastY = y;
  68044. path.lineTo (x, y);
  68045. }
  68046. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68047. path.closeSubPath();
  68048. }
  68049. return parseShape (xml, path);
  68050. }
  68051. Drawable* parseShape (const XmlElement& xml, Path& path,
  68052. const bool shouldParseTransform = true) const
  68053. {
  68054. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68055. {
  68056. SVGState newState (*this);
  68057. newState.addTransform (xml);
  68058. return newState.parseShape (xml, path, false);
  68059. }
  68060. DrawablePath* dp = new DrawablePath();
  68061. dp->setName (xml.getStringAttribute (T("id")));
  68062. dp->setFill (FillType (Colours::transparentBlack));
  68063. path.applyTransform (transform);
  68064. dp->setPath (path);
  68065. Path::Iterator iter (path);
  68066. bool containsClosedSubPath = false;
  68067. while (iter.next())
  68068. {
  68069. if (iter.elementType == Path::Iterator::closePath)
  68070. {
  68071. containsClosedSubPath = true;
  68072. break;
  68073. }
  68074. }
  68075. dp->setFill (getPathFillType (path,
  68076. getStyleAttribute (&xml, T("fill")),
  68077. getStyleAttribute (&xml, T("fill-opacity")),
  68078. getStyleAttribute (&xml, T("opacity")),
  68079. containsClosedSubPath ? Colours::black
  68080. : Colours::transparentBlack));
  68081. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68082. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68083. {
  68084. dp->setStrokeFill (getPathFillType (path, strokeType,
  68085. getStyleAttribute (&xml, T("stroke-opacity")),
  68086. getStyleAttribute (&xml, T("opacity")),
  68087. Colours::transparentBlack));
  68088. dp->setStrokeType (getStrokeFor (&xml));
  68089. }
  68090. return dp;
  68091. }
  68092. const XmlElement* findLinkedElement (const XmlElement* e) const
  68093. {
  68094. const String id (e->getStringAttribute (T("xlink:href")));
  68095. if (! id.startsWithChar (T('#')))
  68096. return 0;
  68097. return findElementForId (topLevelXml, id.substring (1));
  68098. }
  68099. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68100. {
  68101. if (fillXml == 0)
  68102. return;
  68103. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68104. {
  68105. int index = 0;
  68106. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68107. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68108. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68109. double offset = e->getDoubleAttribute (T("offset"));
  68110. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68111. offset *= 0.01;
  68112. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68113. }
  68114. }
  68115. const FillType getPathFillType (const Path& path,
  68116. const String& fill,
  68117. const String& fillOpacity,
  68118. const String& overallOpacity,
  68119. const Colour& defaultColour) const
  68120. {
  68121. float opacity = 1.0f;
  68122. if (overallOpacity.isNotEmpty())
  68123. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68124. if (fillOpacity.isNotEmpty())
  68125. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68126. if (fill.startsWithIgnoreCase (T("url")))
  68127. {
  68128. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68129. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68130. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68131. if (fillXml != 0
  68132. && (fillXml->hasTagName (T("linearGradient"))
  68133. || fillXml->hasTagName (T("radialGradient"))))
  68134. {
  68135. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68136. ColourGradient gradient;
  68137. addGradientStopsIn (gradient, inheritedFrom);
  68138. addGradientStopsIn (gradient, fillXml);
  68139. if (gradient.getNumColours() > 0)
  68140. {
  68141. gradient.addColour (0.0, gradient.getColour (0));
  68142. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68143. }
  68144. else
  68145. {
  68146. gradient.addColour (0.0, Colours::black);
  68147. gradient.addColour (1.0, Colours::black);
  68148. }
  68149. if (overallOpacity.isNotEmpty())
  68150. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68151. jassert (gradient.getNumColours() > 0);
  68152. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68153. float width = viewBoxW;
  68154. float height = viewBoxH;
  68155. float dx = 0.0f;
  68156. float dy = 0.0f;
  68157. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68158. if (! userSpace)
  68159. {
  68160. const Rectangle<float> bounds (path.getBounds());
  68161. dx = bounds.getX();
  68162. dy = bounds.getY();
  68163. width = bounds.getWidth();
  68164. height = bounds.getHeight();
  68165. }
  68166. if (gradient.isRadial)
  68167. {
  68168. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68169. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68170. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68171. gradient.x2 = gradient.x1 + radius;
  68172. gradient.y2 = gradient.y1;
  68173. //xxx (the fx, fy focal point isn't handled properly here..)
  68174. }
  68175. else
  68176. {
  68177. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68178. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68179. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68180. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68181. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68182. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68183. }
  68184. FillType type (gradient);
  68185. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68186. .followedBy (transform);
  68187. return type;
  68188. }
  68189. }
  68190. if (fill.equalsIgnoreCase (T("none")))
  68191. return Colours::transparentBlack;
  68192. int i = 0;
  68193. const Colour colour (parseColour (fill, i, defaultColour));
  68194. return colour.withMultipliedAlpha (opacity);
  68195. }
  68196. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68197. {
  68198. const String width (getStyleAttribute (xml, T("stroke-width")));
  68199. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68200. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68201. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68202. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68203. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68204. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68205. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68206. if (join.equalsIgnoreCase (T("round")))
  68207. joinStyle = PathStrokeType::curved;
  68208. else if (join.equalsIgnoreCase (T("bevel")))
  68209. joinStyle = PathStrokeType::beveled;
  68210. if (cap.equalsIgnoreCase (T("round")))
  68211. capStyle = PathStrokeType::rounded;
  68212. else if (cap.equalsIgnoreCase (T("square")))
  68213. capStyle = PathStrokeType::square;
  68214. float ox = 0.0f, oy = 0.0f;
  68215. transform.transformPoint (ox, oy);
  68216. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68217. transform.transformPoint (x, y);
  68218. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68219. joinStyle, capStyle);
  68220. }
  68221. Drawable* parseText (const XmlElement& xml)
  68222. {
  68223. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68224. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68225. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68226. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68227. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68228. //xxx not done text yet!
  68229. forEachXmlChildElement (xml, e)
  68230. {
  68231. if (e->isTextElement())
  68232. {
  68233. const String text (e->getText());
  68234. Path path;
  68235. Drawable* s = parseShape (*e, path);
  68236. delete s;
  68237. }
  68238. else if (e->hasTagName (T("tspan")))
  68239. {
  68240. Drawable* s = parseText (*e);
  68241. delete s;
  68242. }
  68243. }
  68244. return 0;
  68245. }
  68246. void addTransform (const XmlElement& xml)
  68247. {
  68248. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68249. .followedBy (transform);
  68250. }
  68251. bool parseCoord (const String& s, float& value, int& index,
  68252. const bool allowUnits, const bool isX) const
  68253. {
  68254. String number;
  68255. if (! parseNextNumber (s, number, index, allowUnits))
  68256. {
  68257. value = 0;
  68258. return false;
  68259. }
  68260. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68261. return true;
  68262. }
  68263. bool parseCoords (const String& s, float& x, float& y,
  68264. int& index, const bool allowUnits) const
  68265. {
  68266. return parseCoord (s, x, index, allowUnits, true)
  68267. && parseCoord (s, y, index, allowUnits, false);
  68268. }
  68269. float getCoordLength (const String& s, const float sizeForProportions) const
  68270. {
  68271. float n = s.getFloatValue();
  68272. const int len = s.length();
  68273. if (len > 2)
  68274. {
  68275. const float dpi = 96.0f;
  68276. const tchar n1 = s [len - 2];
  68277. const tchar n2 = s [len - 1];
  68278. if (n1 == T('i') && n2 == T('n'))
  68279. n *= dpi;
  68280. else if (n1 == T('m') && n2 == T('m'))
  68281. n *= dpi / 25.4f;
  68282. else if (n1 == T('c') && n2 == T('m'))
  68283. n *= dpi / 2.54f;
  68284. else if (n1 == T('p') && n2 == T('c'))
  68285. n *= 15.0f;
  68286. else if (n2 == T('%'))
  68287. n *= 0.01f * sizeForProportions;
  68288. }
  68289. return n;
  68290. }
  68291. void getCoordList (Array <float>& coords, const String& list,
  68292. const bool allowUnits, const bool isX) const
  68293. {
  68294. int index = 0;
  68295. float value;
  68296. while (parseCoord (list, value, index, allowUnits, isX))
  68297. coords.add (value);
  68298. }
  68299. void parseCSSStyle (const XmlElement& xml)
  68300. {
  68301. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68302. }
  68303. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68304. const String& defaultValue = String::empty) const
  68305. {
  68306. if (xml->hasAttribute (attributeName))
  68307. return xml->getStringAttribute (attributeName, defaultValue);
  68308. const String styleAtt (xml->getStringAttribute (T("style")));
  68309. if (styleAtt.isNotEmpty())
  68310. {
  68311. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68312. if (value.isNotEmpty())
  68313. return value;
  68314. }
  68315. else if (xml->hasAttribute (T("class")))
  68316. {
  68317. const String className (T(".") + xml->getStringAttribute (T("class")));
  68318. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68319. if (index < 0)
  68320. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68321. if (index >= 0)
  68322. {
  68323. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68324. if (openBracket > index)
  68325. {
  68326. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68327. if (closeBracket > openBracket)
  68328. {
  68329. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68330. if (value.isNotEmpty())
  68331. return value;
  68332. }
  68333. }
  68334. }
  68335. }
  68336. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68337. if (xml != 0)
  68338. return getStyleAttribute (xml, attributeName, defaultValue);
  68339. return defaultValue;
  68340. }
  68341. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68342. {
  68343. if (xml->hasAttribute (attributeName))
  68344. return xml->getStringAttribute (attributeName);
  68345. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68346. if (xml != 0)
  68347. return getInheritedAttribute (xml, attributeName);
  68348. return String::empty;
  68349. }
  68350. static bool isIdentifierChar (const tchar c)
  68351. {
  68352. return CharacterFunctions::isLetter (c) || c == T('-');
  68353. }
  68354. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68355. {
  68356. int i = 0;
  68357. for (;;)
  68358. {
  68359. i = list.indexOf (i, attributeName);
  68360. if (i < 0)
  68361. break;
  68362. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68363. && ! isIdentifierChar (list [i + attributeName.length()]))
  68364. {
  68365. i = list.indexOfChar (i, T(':'));
  68366. if (i < 0)
  68367. break;
  68368. int end = list.indexOfChar (i, T(';'));
  68369. if (end < 0)
  68370. end = 0x7ffff;
  68371. return list.substring (i + 1, end).trim();
  68372. }
  68373. ++i;
  68374. }
  68375. return defaultValue;
  68376. }
  68377. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68378. {
  68379. const tchar* const s = (const tchar*) source;
  68380. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68381. ++index;
  68382. int start = index;
  68383. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68384. ++index;
  68385. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68386. ++index;
  68387. if ((s[index] == T('e') || s[index] == T('E'))
  68388. && (CharacterFunctions::isDigit (s[index + 1])
  68389. || s[index + 1] == T('-')
  68390. || s[index + 1] == T('+')))
  68391. {
  68392. index += 2;
  68393. while (CharacterFunctions::isDigit (s[index]))
  68394. ++index;
  68395. }
  68396. if (allowUnits)
  68397. {
  68398. while (CharacterFunctions::isLetter (s[index]))
  68399. ++index;
  68400. }
  68401. if (index == start)
  68402. return false;
  68403. value = String (s + start, index - start);
  68404. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68405. ++index;
  68406. return true;
  68407. }
  68408. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68409. {
  68410. if (s [index] == T('#'))
  68411. {
  68412. uint32 hex [6];
  68413. zeromem (hex, sizeof (hex));
  68414. int numChars = 0;
  68415. for (int i = 6; --i >= 0;)
  68416. {
  68417. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68418. if (hexValue >= 0)
  68419. hex [numChars++] = hexValue;
  68420. else
  68421. break;
  68422. }
  68423. if (numChars <= 3)
  68424. return Colour ((uint8) (hex [0] * 0x11),
  68425. (uint8) (hex [1] * 0x11),
  68426. (uint8) (hex [2] * 0x11));
  68427. else
  68428. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68429. (uint8) ((hex [2] << 4) + hex [3]),
  68430. (uint8) ((hex [4] << 4) + hex [5]));
  68431. }
  68432. else if (s [index] == T('r')
  68433. && s [index + 1] == T('g')
  68434. && s [index + 2] == T('b'))
  68435. {
  68436. const int openBracket = s.indexOfChar (index, T('('));
  68437. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68438. if (openBracket >= 3 && closeBracket > openBracket)
  68439. {
  68440. index = closeBracket;
  68441. StringArray tokens;
  68442. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68443. tokens.trim();
  68444. tokens.removeEmptyStrings();
  68445. if (tokens[0].containsChar (T('%')))
  68446. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68447. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68448. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68449. else
  68450. return Colour ((uint8) tokens[0].getIntValue(),
  68451. (uint8) tokens[1].getIntValue(),
  68452. (uint8) tokens[2].getIntValue());
  68453. }
  68454. }
  68455. return Colours::findColourForName (s, defaultColour);
  68456. }
  68457. static const AffineTransform parseTransform (String t)
  68458. {
  68459. AffineTransform result;
  68460. while (t.isNotEmpty())
  68461. {
  68462. StringArray tokens;
  68463. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68464. .upToFirstOccurrenceOf (T(")"), false, false),
  68465. T(", "), String::empty);
  68466. tokens.removeEmptyStrings (true);
  68467. float numbers [6];
  68468. for (int i = 0; i < 6; ++i)
  68469. numbers[i] = tokens[i].getFloatValue();
  68470. AffineTransform trans;
  68471. if (t.startsWithIgnoreCase (T("matrix")))
  68472. {
  68473. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68474. numbers[1], numbers[3], numbers[5]);
  68475. }
  68476. else if (t.startsWithIgnoreCase (T("translate")))
  68477. {
  68478. jassert (tokens.size() == 2);
  68479. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68480. }
  68481. else if (t.startsWithIgnoreCase (T("scale")))
  68482. {
  68483. if (tokens.size() == 1)
  68484. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68485. else
  68486. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68487. }
  68488. else if (t.startsWithIgnoreCase (T("rotate")))
  68489. {
  68490. if (tokens.size() != 3)
  68491. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68492. else
  68493. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68494. numbers[1], numbers[2]);
  68495. }
  68496. else if (t.startsWithIgnoreCase (T("skewX")))
  68497. {
  68498. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68499. 0.0f, 1.0f, 0.0f);
  68500. }
  68501. else if (t.startsWithIgnoreCase (T("skewY")))
  68502. {
  68503. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68504. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68505. }
  68506. result = trans.followedBy (result);
  68507. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68508. }
  68509. return result;
  68510. }
  68511. static void endpointToCentreParameters (const double x1, const double y1,
  68512. const double x2, const double y2,
  68513. const double angle,
  68514. const bool largeArc, const bool sweep,
  68515. double& rx, double& ry,
  68516. double& centreX, double& centreY,
  68517. double& startAngle, double& deltaAngle)
  68518. {
  68519. const double midX = (x1 - x2) * 0.5;
  68520. const double midY = (y1 - y2) * 0.5;
  68521. const double cosAngle = cos (angle);
  68522. const double sinAngle = sin (angle);
  68523. const double xp = cosAngle * midX + sinAngle * midY;
  68524. const double yp = cosAngle * midY - sinAngle * midX;
  68525. const double xp2 = xp * xp;
  68526. const double yp2 = yp * yp;
  68527. double rx2 = rx * rx;
  68528. double ry2 = ry * ry;
  68529. const double s = (xp2 / rx2) + (yp2 / ry2);
  68530. double c;
  68531. if (s <= 1.0)
  68532. {
  68533. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68534. / (( rx2 * yp2) + (ry2 * xp2))));
  68535. if (largeArc == sweep)
  68536. c = -c;
  68537. }
  68538. else
  68539. {
  68540. const double s2 = sqrt (s);
  68541. rx *= s2;
  68542. ry *= s2;
  68543. rx2 = rx * rx;
  68544. ry2 = ry * ry;
  68545. c = 0;
  68546. }
  68547. const double cpx = ((rx * yp) / ry) * c;
  68548. const double cpy = ((-ry * xp) / rx) * c;
  68549. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68550. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68551. const double ux = (xp - cpx) / rx;
  68552. const double uy = (yp - cpy) / ry;
  68553. const double vx = (-xp - cpx) / rx;
  68554. const double vy = (-yp - cpy) / ry;
  68555. const double length = juce_hypot (ux, uy);
  68556. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68557. if (uy < 0)
  68558. startAngle = -startAngle;
  68559. startAngle += double_Pi * 0.5;
  68560. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68561. / (length * juce_hypot (vx, vy))));
  68562. if ((ux * vy) - (uy * vx) < 0)
  68563. deltaAngle = -deltaAngle;
  68564. if (sweep)
  68565. {
  68566. if (deltaAngle < 0)
  68567. deltaAngle += double_Pi * 2.0;
  68568. }
  68569. else
  68570. {
  68571. if (deltaAngle > 0)
  68572. deltaAngle -= double_Pi * 2.0;
  68573. }
  68574. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68575. }
  68576. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68577. {
  68578. forEachXmlChildElement (*parent, e)
  68579. {
  68580. if (e->compareAttribute (T("id"), id))
  68581. return e;
  68582. const XmlElement* const found = findElementForId (e, id);
  68583. if (found != 0)
  68584. return found;
  68585. }
  68586. return 0;
  68587. }
  68588. SVGState& operator= (const SVGState&);
  68589. };
  68590. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68591. {
  68592. SVGState state (&svgDocument);
  68593. return state.parseSVGElement (svgDocument);
  68594. }
  68595. END_JUCE_NAMESPACE
  68596. /*** End of inlined file: juce_SVGParser.cpp ***/
  68597. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68598. BEGIN_JUCE_NAMESPACE
  68599. #if JUCE_MSVC
  68600. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68601. #endif
  68602. DropShadowEffect::DropShadowEffect()
  68603. : offsetX (0),
  68604. offsetY (0),
  68605. radius (4),
  68606. opacity (0.6f)
  68607. {
  68608. }
  68609. DropShadowEffect::~DropShadowEffect()
  68610. {
  68611. }
  68612. void DropShadowEffect::setShadowProperties (const float newRadius,
  68613. const float newOpacity,
  68614. const int newShadowOffsetX,
  68615. const int newShadowOffsetY)
  68616. {
  68617. radius = jmax (1.1f, newRadius);
  68618. offsetX = newShadowOffsetX;
  68619. offsetY = newShadowOffsetY;
  68620. opacity = newOpacity;
  68621. }
  68622. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68623. {
  68624. const int w = image.getWidth();
  68625. const int h = image.getHeight();
  68626. Image shadowImage (Image::SingleChannel, w, h, false);
  68627. const Image::BitmapData srcData (image, 0, 0, w, h);
  68628. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68629. const int filter = roundToInt (63.0f / radius);
  68630. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68631. for (int x = w; --x >= 0;)
  68632. {
  68633. int shadowAlpha = 0;
  68634. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68635. uint8* shadowPix = destData.data + x;
  68636. for (int y = h; --y >= 0;)
  68637. {
  68638. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68639. *shadowPix = (uint8) shadowAlpha;
  68640. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68641. shadowPix += destData.lineStride;
  68642. }
  68643. }
  68644. for (int y = h; --y >= 0;)
  68645. {
  68646. int shadowAlpha = 0;
  68647. uint8* shadowPix = destData.getLinePointer (y);
  68648. for (int x = w; --x >= 0;)
  68649. {
  68650. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68651. *shadowPix++ = (uint8) shadowAlpha;
  68652. }
  68653. }
  68654. g.setColour (Colours::black.withAlpha (opacity));
  68655. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68656. g.setOpacity (1.0f);
  68657. g.drawImageAt (&image, 0, 0);
  68658. }
  68659. END_JUCE_NAMESPACE
  68660. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68661. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68662. BEGIN_JUCE_NAMESPACE
  68663. GlowEffect::GlowEffect()
  68664. : radius (2.0f),
  68665. colour (Colours::white)
  68666. {
  68667. }
  68668. GlowEffect::~GlowEffect()
  68669. {
  68670. }
  68671. void GlowEffect::setGlowProperties (const float newRadius,
  68672. const Colour& newColour)
  68673. {
  68674. radius = newRadius;
  68675. colour = newColour;
  68676. }
  68677. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68678. {
  68679. const int w = image.getWidth();
  68680. const int h = image.getHeight();
  68681. Image temp (image.getFormat(), w, h, true);
  68682. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68683. blurKernel.createGaussianBlur (radius);
  68684. blurKernel.rescaleAllValues (radius);
  68685. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  68686. g.setColour (colour);
  68687. g.drawImageAt (&temp, 0, 0, true);
  68688. g.setOpacity (1.0f);
  68689. g.drawImageAt (&image, 0, 0, false);
  68690. }
  68691. END_JUCE_NAMESPACE
  68692. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68693. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68694. BEGIN_JUCE_NAMESPACE
  68695. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68696. : opacity (opacity_)
  68697. {
  68698. }
  68699. ReduceOpacityEffect::~ReduceOpacityEffect()
  68700. {
  68701. }
  68702. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68703. {
  68704. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68705. }
  68706. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68707. {
  68708. g.setOpacity (opacity);
  68709. g.drawImageAt (&image, 0, 0);
  68710. }
  68711. END_JUCE_NAMESPACE
  68712. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68713. /*** Start of inlined file: juce_Font.cpp ***/
  68714. BEGIN_JUCE_NAMESPACE
  68715. static const float minFontHeight = 0.1f;
  68716. static const float maxFontHeight = 10000.0f;
  68717. static const float defaultFontHeight = 14.0f;
  68718. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  68719. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  68720. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  68721. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  68722. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  68723. const float kerning_, const float ascent_, const int styleFlags_,
  68724. Typeface* const typeface_) throw()
  68725. : typefaceName (typefaceName_),
  68726. height (height_),
  68727. horizontalScale (horizontalScale_),
  68728. kerning (kerning_),
  68729. ascent (ascent_),
  68730. styleFlags (styleFlags_),
  68731. typeface (typeface_)
  68732. {
  68733. }
  68734. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  68735. : typefaceName (other.typefaceName),
  68736. height (other.height),
  68737. horizontalScale (other.horizontalScale),
  68738. kerning (other.kerning),
  68739. ascent (other.ascent),
  68740. styleFlags (other.styleFlags),
  68741. typeface (other.typeface)
  68742. {
  68743. }
  68744. Font::Font() throw()
  68745. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  68746. 1.0f, 0, 0, Font::plain, 0))
  68747. {
  68748. }
  68749. Font::Font (const float fontHeight, const int styleFlags_) throw()
  68750. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  68751. 1.0f, 0, 0, styleFlags_, 0))
  68752. {
  68753. }
  68754. Font::Font (const String& typefaceName_,
  68755. const float fontHeight,
  68756. const int styleFlags_) throw()
  68757. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  68758. 1.0f, 0, 0, styleFlags_, 0))
  68759. {
  68760. }
  68761. Font::Font (const Font& other) throw()
  68762. : font (other.font)
  68763. {
  68764. }
  68765. Font& Font::operator= (const Font& other) throw()
  68766. {
  68767. font = other.font;
  68768. return *this;
  68769. }
  68770. Font::~Font() throw()
  68771. {
  68772. }
  68773. Font::Font (const Typeface::Ptr& typeface) throw()
  68774. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  68775. 1.0f, 0, 0, Font::plain, typeface))
  68776. {
  68777. }
  68778. bool Font::operator== (const Font& other) const throw()
  68779. {
  68780. return font == other.font
  68781. || (font->height == other.font->height
  68782. && font->styleFlags == other.font->styleFlags
  68783. && font->horizontalScale == other.font->horizontalScale
  68784. && font->kerning == other.font->kerning
  68785. && font->typefaceName == other.font->typefaceName);
  68786. }
  68787. bool Font::operator!= (const Font& other) const throw()
  68788. {
  68789. return ! operator== (other);
  68790. }
  68791. void Font::dupeInternalIfShared() throw()
  68792. {
  68793. if (font->getReferenceCount() > 1)
  68794. font = new SharedFontInternal (*font);
  68795. }
  68796. const String Font::getDefaultSansSerifFontName() throw()
  68797. {
  68798. return juce_defaultFontNameSans;
  68799. }
  68800. const String Font::getDefaultSerifFontName() throw()
  68801. {
  68802. return juce_defaultFontNameSerif;
  68803. }
  68804. const String Font::getDefaultMonospacedFontName() throw()
  68805. {
  68806. return juce_defaultFontNameMono;
  68807. }
  68808. void Font::setTypefaceName (const String& faceName) throw()
  68809. {
  68810. if (faceName != font->typefaceName)
  68811. {
  68812. dupeInternalIfShared();
  68813. font->typefaceName = faceName;
  68814. font->typeface = 0;
  68815. font->ascent = 0;
  68816. }
  68817. }
  68818. static String fallbackFont;
  68819. const String Font::getFallbackFontName() throw()
  68820. {
  68821. return fallbackFont;
  68822. }
  68823. void Font::setFallbackFontName (const String& name) throw()
  68824. {
  68825. fallbackFont = name;
  68826. }
  68827. void Font::setHeight (float newHeight) throw()
  68828. {
  68829. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68830. if (font->height != newHeight)
  68831. {
  68832. dupeInternalIfShared();
  68833. font->height = newHeight;
  68834. }
  68835. }
  68836. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68837. {
  68838. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68839. if (font->height != newHeight)
  68840. {
  68841. dupeInternalIfShared();
  68842. font->horizontalScale *= (font->height / newHeight);
  68843. font->height = newHeight;
  68844. }
  68845. }
  68846. void Font::setStyleFlags (const int newFlags) throw()
  68847. {
  68848. if (font->styleFlags != newFlags)
  68849. {
  68850. dupeInternalIfShared();
  68851. font->styleFlags = newFlags;
  68852. font->typeface = 0;
  68853. font->ascent = 0;
  68854. }
  68855. }
  68856. void Font::setSizeAndStyle (float newHeight,
  68857. const int newStyleFlags,
  68858. const float newHorizontalScale,
  68859. const float newKerningAmount) throw()
  68860. {
  68861. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68862. if (font->height != newHeight
  68863. || font->horizontalScale != newHorizontalScale
  68864. || font->kerning != newKerningAmount)
  68865. {
  68866. dupeInternalIfShared();
  68867. font->height = newHeight;
  68868. font->horizontalScale = newHorizontalScale;
  68869. font->kerning = newKerningAmount;
  68870. }
  68871. setStyleFlags (newStyleFlags);
  68872. }
  68873. void Font::setHorizontalScale (const float scaleFactor) throw()
  68874. {
  68875. dupeInternalIfShared();
  68876. font->horizontalScale = scaleFactor;
  68877. }
  68878. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68879. {
  68880. dupeInternalIfShared();
  68881. font->kerning = extraKerning;
  68882. }
  68883. void Font::setBold (const bool shouldBeBold) throw()
  68884. {
  68885. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68886. : (font->styleFlags & ~bold));
  68887. }
  68888. bool Font::isBold() const throw()
  68889. {
  68890. return (font->styleFlags & bold) != 0;
  68891. }
  68892. void Font::setItalic (const bool shouldBeItalic) throw()
  68893. {
  68894. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68895. : (font->styleFlags & ~italic));
  68896. }
  68897. bool Font::isItalic() const throw()
  68898. {
  68899. return (font->styleFlags & italic) != 0;
  68900. }
  68901. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68902. {
  68903. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68904. : (font->styleFlags & ~underlined));
  68905. }
  68906. bool Font::isUnderlined() const throw()
  68907. {
  68908. return (font->styleFlags & underlined) != 0;
  68909. }
  68910. float Font::getAscent() const throw()
  68911. {
  68912. if (font->ascent == 0)
  68913. font->ascent = getTypeface()->getAscent();
  68914. return font->height * font->ascent;
  68915. }
  68916. float Font::getDescent() const throw()
  68917. {
  68918. return font->height - getAscent();
  68919. }
  68920. int Font::getStringWidth (const String& text) const throw()
  68921. {
  68922. return roundToInt (getStringWidthFloat (text));
  68923. }
  68924. float Font::getStringWidthFloat (const String& text) const throw()
  68925. {
  68926. float w = getTypeface()->getStringWidth (text);
  68927. if (font->kerning != 0)
  68928. w += font->kerning * text.length();
  68929. return w * font->height * font->horizontalScale;
  68930. }
  68931. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  68932. {
  68933. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  68934. const float scale = font->height * font->horizontalScale;
  68935. const int num = xOffsets.size();
  68936. if (num > 0)
  68937. {
  68938. float* const x = &(xOffsets.getReference(0));
  68939. if (font->kerning != 0)
  68940. {
  68941. for (int i = 0; i < num; ++i)
  68942. x[i] = (x[i] + i * font->kerning) * scale;
  68943. }
  68944. else
  68945. {
  68946. for (int i = 0; i < num; ++i)
  68947. x[i] *= scale;
  68948. }
  68949. }
  68950. }
  68951. void Font::findFonts (Array<Font>& destArray) throw()
  68952. {
  68953. const StringArray names (findAllTypefaceNames());
  68954. for (int i = 0; i < names.size(); ++i)
  68955. destArray.add (Font (names[i], defaultFontHeight, Font::plain));
  68956. }
  68957. class TypefaceCache : public DeletedAtShutdown
  68958. {
  68959. public:
  68960. TypefaceCache (int numToCache = 10) throw()
  68961. : counter (1)
  68962. {
  68963. while (--numToCache >= 0)
  68964. faces.add (new CachedFace());
  68965. }
  68966. ~TypefaceCache()
  68967. {
  68968. clearUpDefaultFontNames();
  68969. clearSingletonInstance();
  68970. }
  68971. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  68972. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  68973. {
  68974. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  68975. const String faceName (font.getTypefaceName());
  68976. int i;
  68977. for (i = faces.size(); --i >= 0;)
  68978. {
  68979. CachedFace* const face = faces.getUnchecked(i);
  68980. if (face->flags == flags
  68981. && face->typefaceName == faceName)
  68982. {
  68983. face->lastUsageCount = ++counter;
  68984. return face->typeFace;
  68985. }
  68986. }
  68987. int replaceIndex = 0;
  68988. int bestLastUsageCount = std::numeric_limits<int>::max();
  68989. for (i = faces.size(); --i >= 0;)
  68990. {
  68991. const int lu = faces.getUnchecked(i)->lastUsageCount;
  68992. if (bestLastUsageCount > lu)
  68993. {
  68994. bestLastUsageCount = lu;
  68995. replaceIndex = i;
  68996. }
  68997. }
  68998. CachedFace* const face = faces.getUnchecked (replaceIndex);
  68999. face->typefaceName = faceName;
  69000. face->flags = flags;
  69001. face->lastUsageCount = ++counter;
  69002. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  69003. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  69004. return face->typeFace;
  69005. }
  69006. juce_UseDebuggingNewOperator
  69007. private:
  69008. struct CachedFace
  69009. {
  69010. CachedFace() throw()
  69011. : lastUsageCount (0), flags (-1)
  69012. {
  69013. }
  69014. String typefaceName;
  69015. int lastUsageCount;
  69016. int flags;
  69017. Typeface::Ptr typeFace;
  69018. };
  69019. int counter;
  69020. OwnedArray <CachedFace> faces;
  69021. TypefaceCache (const TypefaceCache&);
  69022. TypefaceCache& operator= (const TypefaceCache&);
  69023. };
  69024. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69025. Typeface* Font::getTypeface() const throw()
  69026. {
  69027. if (font->typeface == 0)
  69028. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69029. return font->typeface;
  69030. }
  69031. END_JUCE_NAMESPACE
  69032. /*** End of inlined file: juce_Font.cpp ***/
  69033. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  69034. BEGIN_JUCE_NAMESPACE
  69035. PositionedGlyph::PositionedGlyph (const float x_, const float y_, const float w_, const Font& font_,
  69036. const juce_wchar character_, const int glyph_)
  69037. : x (x_),
  69038. y (y_),
  69039. w (w_),
  69040. font (font_),
  69041. character (character_),
  69042. glyph (glyph_)
  69043. {
  69044. }
  69045. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  69046. : x (other.x),
  69047. y (other.y),
  69048. w (other.w),
  69049. font (other.font),
  69050. character (other.character),
  69051. glyph (other.glyph)
  69052. {
  69053. }
  69054. void PositionedGlyph::draw (const Graphics& g) const
  69055. {
  69056. if (! isWhitespace())
  69057. {
  69058. g.getInternalContext()->setFont (font);
  69059. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69060. }
  69061. }
  69062. void PositionedGlyph::draw (const Graphics& g,
  69063. const AffineTransform& transform) const
  69064. {
  69065. if (! isWhitespace())
  69066. {
  69067. g.getInternalContext()->setFont (font);
  69068. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69069. .followedBy (transform));
  69070. }
  69071. }
  69072. void PositionedGlyph::createPath (Path& path) const
  69073. {
  69074. if (! isWhitespace())
  69075. {
  69076. Typeface* const t = font.getTypeface();
  69077. if (t != 0)
  69078. {
  69079. Path p;
  69080. t->getOutlineForGlyph (glyph, p);
  69081. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69082. .translated (x, y));
  69083. }
  69084. }
  69085. }
  69086. bool PositionedGlyph::hitTest (float px, float py) const
  69087. {
  69088. if (px >= getLeft() && px < getRight()
  69089. && py >= getTop() && py < getBottom()
  69090. && ! isWhitespace())
  69091. {
  69092. Typeface* const t = font.getTypeface();
  69093. if (t != 0)
  69094. {
  69095. Path p;
  69096. t->getOutlineForGlyph (glyph, p);
  69097. AffineTransform::translation (-x, -y)
  69098. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69099. .transformPoint (px, py);
  69100. return p.contains (px, py);
  69101. }
  69102. }
  69103. return false;
  69104. }
  69105. void PositionedGlyph::moveBy (const float deltaX,
  69106. const float deltaY)
  69107. {
  69108. x += deltaX;
  69109. y += deltaY;
  69110. }
  69111. GlyphArrangement::GlyphArrangement()
  69112. {
  69113. glyphs.ensureStorageAllocated (128);
  69114. }
  69115. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69116. {
  69117. addGlyphArrangement (other);
  69118. }
  69119. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69120. {
  69121. if (this != &other)
  69122. {
  69123. clear();
  69124. addGlyphArrangement (other);
  69125. }
  69126. return *this;
  69127. }
  69128. GlyphArrangement::~GlyphArrangement()
  69129. {
  69130. }
  69131. void GlyphArrangement::clear()
  69132. {
  69133. glyphs.clear();
  69134. }
  69135. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69136. {
  69137. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69138. return *glyphs [index];
  69139. }
  69140. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69141. {
  69142. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69143. for (int i = 0; i < other.glyphs.size(); ++i)
  69144. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69145. }
  69146. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69147. {
  69148. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69149. }
  69150. void GlyphArrangement::addLineOfText (const Font& font,
  69151. const String& text,
  69152. const float xOffset,
  69153. const float yOffset)
  69154. {
  69155. addCurtailedLineOfText (font, text,
  69156. xOffset, yOffset,
  69157. 1.0e10f, false);
  69158. }
  69159. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69160. const String& text,
  69161. float xOffset,
  69162. const float yOffset,
  69163. const float maxWidthPixels,
  69164. const bool useEllipsis)
  69165. {
  69166. if (text.isNotEmpty())
  69167. {
  69168. Array <int> newGlyphs;
  69169. Array <float> xOffsets;
  69170. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69171. const int textLen = newGlyphs.size();
  69172. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69173. for (int i = 0; i < textLen; ++i)
  69174. {
  69175. const float thisX = xOffsets.getUnchecked (i);
  69176. const float nextX = xOffsets.getUnchecked (i + 1);
  69177. if (nextX > maxWidthPixels + 1.0f)
  69178. {
  69179. // curtail the string if it's too wide..
  69180. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69181. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69182. break;
  69183. }
  69184. else
  69185. {
  69186. glyphs.add (new PositionedGlyph (xOffset + thisX, yOffset, nextX - thisX,
  69187. font, unicodeText[i], newGlyphs.getUnchecked(i)));
  69188. }
  69189. }
  69190. }
  69191. }
  69192. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69193. const int startIndex, int endIndex)
  69194. {
  69195. int numDeleted = 0;
  69196. if (glyphs.size() > 0)
  69197. {
  69198. Array<int> dotGlyphs;
  69199. Array<float> dotXs;
  69200. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69201. const float dx = dotXs[1];
  69202. float xOffset = 0.0f, yOffset = 0.0f;
  69203. while (endIndex > startIndex)
  69204. {
  69205. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69206. xOffset = pg->x;
  69207. yOffset = pg->y;
  69208. glyphs.remove (endIndex);
  69209. ++numDeleted;
  69210. if (xOffset + dx * 3 <= maxXPos)
  69211. break;
  69212. }
  69213. for (int i = 3; --i >= 0;)
  69214. {
  69215. glyphs.insert (endIndex++, new PositionedGlyph (xOffset, yOffset, dx,
  69216. font, '.', dotGlyphs.getFirst()));
  69217. --numDeleted;
  69218. xOffset += dx;
  69219. if (xOffset > maxXPos)
  69220. break;
  69221. }
  69222. }
  69223. return numDeleted;
  69224. }
  69225. void GlyphArrangement::addJustifiedText (const Font& font,
  69226. const String& text,
  69227. float x, float y,
  69228. const float maxLineWidth,
  69229. const Justification& horizontalLayout)
  69230. {
  69231. int lineStartIndex = glyphs.size();
  69232. addLineOfText (font, text, x, y);
  69233. const float originalY = y;
  69234. while (lineStartIndex < glyphs.size())
  69235. {
  69236. int i = lineStartIndex;
  69237. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69238. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69239. ++i;
  69240. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69241. int lastWordBreakIndex = -1;
  69242. while (i < glyphs.size())
  69243. {
  69244. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69245. const juce_wchar c = pg->getCharacter();
  69246. if (c == T('\r') || c == T('\n'))
  69247. {
  69248. ++i;
  69249. if (c == T('\r') && i < glyphs.size()
  69250. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69251. ++i;
  69252. break;
  69253. }
  69254. else if (pg->isWhitespace())
  69255. {
  69256. lastWordBreakIndex = i + 1;
  69257. }
  69258. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69259. {
  69260. if (lastWordBreakIndex >= 0)
  69261. i = lastWordBreakIndex;
  69262. break;
  69263. }
  69264. ++i;
  69265. }
  69266. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69267. float currentLineEndX = currentLineStartX;
  69268. for (int j = i; --j >= lineStartIndex;)
  69269. {
  69270. if (! glyphs.getUnchecked (j)->isWhitespace())
  69271. {
  69272. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69273. break;
  69274. }
  69275. }
  69276. float deltaX = 0.0f;
  69277. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69278. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69279. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69280. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69281. else if (horizontalLayout.testFlags (Justification::right))
  69282. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69283. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69284. x + deltaX - currentLineStartX, y - originalY);
  69285. lineStartIndex = i;
  69286. y += font.getHeight();
  69287. }
  69288. }
  69289. void GlyphArrangement::addFittedText (const Font& f,
  69290. const String& text,
  69291. const float x, const float y,
  69292. const float width, const float height,
  69293. const Justification& layout,
  69294. int maximumLines,
  69295. const float minimumHorizontalScale)
  69296. {
  69297. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69298. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69299. if (text.containsAnyOf (T("\r\n")))
  69300. {
  69301. GlyphArrangement ga;
  69302. ga.addJustifiedText (f, text, x, y, width, layout);
  69303. float l, t, r, b;
  69304. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69305. float dy = y - t;
  69306. if (layout.testFlags (Justification::verticallyCentred))
  69307. dy += (height - (b - t)) * 0.5f;
  69308. else if (layout.testFlags (Justification::bottom))
  69309. dy += height - (b - t);
  69310. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69311. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69312. for (int i = 0; i < ga.glyphs.size(); ++i)
  69313. glyphs.add (ga.glyphs.getUnchecked (i));
  69314. ga.glyphs.clear (false);
  69315. return;
  69316. }
  69317. int startIndex = glyphs.size();
  69318. addLineOfText (f, text.trim(), x, y);
  69319. if (glyphs.size() > startIndex)
  69320. {
  69321. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69322. - glyphs.getUnchecked (startIndex)->getLeft();
  69323. if (lineWidth <= 0)
  69324. return;
  69325. if (lineWidth * minimumHorizontalScale < width)
  69326. {
  69327. if (lineWidth > width)
  69328. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69329. width / lineWidth);
  69330. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69331. x, y, width, height, layout);
  69332. }
  69333. else if (maximumLines <= 1)
  69334. {
  69335. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69336. x, y, width, height, f, layout, minimumHorizontalScale);
  69337. }
  69338. else
  69339. {
  69340. Font font (f);
  69341. String txt (text.trim());
  69342. const int length = txt.length();
  69343. const int originalStartIndex = startIndex;
  69344. int numLines = 1;
  69345. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69346. maximumLines = 1;
  69347. maximumLines = jmin (maximumLines, length);
  69348. while (numLines < maximumLines)
  69349. {
  69350. ++numLines;
  69351. const float newFontHeight = height / (float) numLines;
  69352. if (newFontHeight < font.getHeight())
  69353. {
  69354. font.setHeight (jmax (8.0f, newFontHeight));
  69355. removeRangeOfGlyphs (startIndex, -1);
  69356. addLineOfText (font, txt, x, y);
  69357. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69358. - glyphs.getUnchecked (startIndex)->getLeft();
  69359. }
  69360. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69361. break;
  69362. }
  69363. if (numLines < 1)
  69364. numLines = 1;
  69365. float lineY = y;
  69366. float widthPerLine = lineWidth / numLines;
  69367. int lastLineStartIndex = 0;
  69368. for (int line = 0; line < numLines; ++line)
  69369. {
  69370. int i = startIndex;
  69371. lastLineStartIndex = i;
  69372. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69373. if (line == numLines - 1)
  69374. {
  69375. widthPerLine = width;
  69376. i = glyphs.size();
  69377. }
  69378. else
  69379. {
  69380. while (i < glyphs.size())
  69381. {
  69382. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69383. if (lineWidth > widthPerLine)
  69384. {
  69385. // got to a point where the line's too long, so skip forward to find a
  69386. // good place to break it..
  69387. const int searchStartIndex = i;
  69388. while (i < glyphs.size())
  69389. {
  69390. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69391. {
  69392. if (glyphs.getUnchecked (i)->isWhitespace()
  69393. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69394. {
  69395. ++i;
  69396. break;
  69397. }
  69398. }
  69399. else
  69400. {
  69401. // can't find a suitable break, so try looking backwards..
  69402. i = searchStartIndex;
  69403. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69404. {
  69405. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69406. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69407. {
  69408. i -= back - 1;
  69409. break;
  69410. }
  69411. }
  69412. break;
  69413. }
  69414. ++i;
  69415. }
  69416. break;
  69417. }
  69418. ++i;
  69419. }
  69420. int wsStart = i;
  69421. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69422. --wsStart;
  69423. int wsEnd = i;
  69424. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69425. ++wsEnd;
  69426. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69427. i = jmax (wsStart, startIndex + 1);
  69428. }
  69429. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69430. x, lineY, width, font.getHeight(), font,
  69431. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69432. minimumHorizontalScale);
  69433. startIndex = i;
  69434. lineY += font.getHeight();
  69435. if (startIndex >= glyphs.size())
  69436. break;
  69437. }
  69438. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69439. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69440. }
  69441. }
  69442. }
  69443. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69444. const float dx, const float dy)
  69445. {
  69446. jassert (startIndex >= 0);
  69447. if (dx != 0.0f || dy != 0.0f)
  69448. {
  69449. if (num < 0 || startIndex + num > glyphs.size())
  69450. num = glyphs.size() - startIndex;
  69451. while (--num >= 0)
  69452. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69453. }
  69454. }
  69455. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69456. const Justification& justification, float minimumHorizontalScale)
  69457. {
  69458. int numDeleted = 0;
  69459. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69460. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69461. if (lineWidth > w)
  69462. {
  69463. if (minimumHorizontalScale < 1.0f)
  69464. {
  69465. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69466. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69467. }
  69468. if (lineWidth > w)
  69469. {
  69470. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69471. numGlyphs -= numDeleted;
  69472. }
  69473. }
  69474. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69475. return numDeleted;
  69476. }
  69477. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69478. const float horizontalScaleFactor)
  69479. {
  69480. jassert (startIndex >= 0);
  69481. if (num < 0 || startIndex + num > glyphs.size())
  69482. num = glyphs.size() - startIndex;
  69483. if (num > 0)
  69484. {
  69485. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69486. while (--num >= 0)
  69487. {
  69488. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69489. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69490. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69491. pg->w *= horizontalScaleFactor;
  69492. }
  69493. }
  69494. }
  69495. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69496. float& left,
  69497. float& top,
  69498. float& right,
  69499. float& bottom,
  69500. const bool includeWhitespace) const
  69501. {
  69502. jassert (startIndex >= 0);
  69503. if (num < 0 || startIndex + num > glyphs.size())
  69504. num = glyphs.size() - startIndex;
  69505. left = 0.0f;
  69506. top = 0.0f;
  69507. right = 0.0f;
  69508. bottom = 0.0f;
  69509. bool isFirst = true;
  69510. while (--num >= 0)
  69511. {
  69512. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69513. if (includeWhitespace || ! pg->isWhitespace())
  69514. {
  69515. if (isFirst)
  69516. {
  69517. isFirst = false;
  69518. left = pg->getLeft();
  69519. top = pg->getTop();
  69520. right = pg->getRight();
  69521. bottom = pg->getBottom();
  69522. }
  69523. else
  69524. {
  69525. left = jmin (left, pg->getLeft());
  69526. top = jmin (top, pg->getTop());
  69527. right = jmax (right, pg->getRight());
  69528. bottom = jmax (bottom, pg->getBottom());
  69529. }
  69530. }
  69531. }
  69532. }
  69533. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69534. const int num,
  69535. const float x, const float y,
  69536. const float width, const float height,
  69537. const Justification& justification)
  69538. {
  69539. jassert (num >= 0 && startIndex >= 0);
  69540. if (glyphs.size() > 0 && num > 0)
  69541. {
  69542. float left, top, right, bottom;
  69543. getBoundingBox (startIndex, num, left, top, right, bottom,
  69544. ! justification.testFlags (Justification::horizontallyJustified
  69545. | Justification::horizontallyCentred));
  69546. float deltaX = 0.0f;
  69547. if (justification.testFlags (Justification::horizontallyJustified))
  69548. deltaX = x - left;
  69549. else if (justification.testFlags (Justification::horizontallyCentred))
  69550. deltaX = x + (width - (right - left)) * 0.5f - left;
  69551. else if (justification.testFlags (Justification::right))
  69552. deltaX = (x + width) - right;
  69553. else
  69554. deltaX = x - left;
  69555. float deltaY = 0.0f;
  69556. if (justification.testFlags (Justification::top))
  69557. deltaY = y - top;
  69558. else if (justification.testFlags (Justification::bottom))
  69559. deltaY = (y + height) - bottom;
  69560. else
  69561. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69562. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69563. if (justification.testFlags (Justification::horizontallyJustified))
  69564. {
  69565. int lineStart = 0;
  69566. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69567. int i;
  69568. for (i = 0; i < num; ++i)
  69569. {
  69570. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69571. if (glyphY != baseY)
  69572. {
  69573. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69574. lineStart = i;
  69575. baseY = glyphY;
  69576. }
  69577. }
  69578. if (i > lineStart)
  69579. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69580. }
  69581. }
  69582. }
  69583. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69584. {
  69585. if (start + num < glyphs.size()
  69586. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  69587. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  69588. {
  69589. int numSpaces = 0;
  69590. int spacesAtEnd = 0;
  69591. for (int i = 0; i < num; ++i)
  69592. {
  69593. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69594. {
  69595. ++spacesAtEnd;
  69596. ++numSpaces;
  69597. }
  69598. else
  69599. {
  69600. spacesAtEnd = 0;
  69601. }
  69602. }
  69603. numSpaces -= spacesAtEnd;
  69604. if (numSpaces > 0)
  69605. {
  69606. const float startX = glyphs.getUnchecked (start)->getLeft();
  69607. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69608. const float extraPaddingBetweenWords
  69609. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69610. float deltaX = 0.0f;
  69611. for (int i = 0; i < num; ++i)
  69612. {
  69613. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69614. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69615. deltaX += extraPaddingBetweenWords;
  69616. }
  69617. }
  69618. }
  69619. }
  69620. void GlyphArrangement::draw (const Graphics& g) const
  69621. {
  69622. for (int i = 0; i < glyphs.size(); ++i)
  69623. {
  69624. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69625. if (pg->font.isUnderlined())
  69626. {
  69627. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69628. float nextX = pg->x + pg->w;
  69629. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69630. nextX = glyphs.getUnchecked (i + 1)->x;
  69631. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69632. nextX - pg->x, lineThickness);
  69633. }
  69634. pg->draw (g);
  69635. }
  69636. }
  69637. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69638. {
  69639. for (int i = 0; i < glyphs.size(); ++i)
  69640. {
  69641. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69642. if (pg->font.isUnderlined())
  69643. {
  69644. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69645. float nextX = pg->x + pg->w;
  69646. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69647. nextX = glyphs.getUnchecked (i + 1)->x;
  69648. Path p;
  69649. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69650. nextX, pg->y + lineThickness * 2.0f,
  69651. lineThickness);
  69652. g.fillPath (p, transform);
  69653. }
  69654. pg->draw (g, transform);
  69655. }
  69656. }
  69657. void GlyphArrangement::createPath (Path& path) const
  69658. {
  69659. for (int i = 0; i < glyphs.size(); ++i)
  69660. glyphs.getUnchecked (i)->createPath (path);
  69661. }
  69662. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69663. {
  69664. for (int i = 0; i < glyphs.size(); ++i)
  69665. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69666. return i;
  69667. return -1;
  69668. }
  69669. END_JUCE_NAMESPACE
  69670. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69671. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69672. BEGIN_JUCE_NAMESPACE
  69673. class TextLayout::Token
  69674. {
  69675. public:
  69676. String text;
  69677. Font font;
  69678. int x, y, w, h;
  69679. int line, lineHeight;
  69680. bool isWhitespace, isNewLine;
  69681. Token (const String& t,
  69682. const Font& f,
  69683. const bool isWhitespace_) throw()
  69684. : text (t),
  69685. font (f),
  69686. x(0),
  69687. y(0),
  69688. isWhitespace (isWhitespace_)
  69689. {
  69690. w = font.getStringWidth (t);
  69691. h = roundToInt (f.getHeight());
  69692. isNewLine = t.containsAnyOf (T("\r\n"));
  69693. }
  69694. Token (const Token& other) throw()
  69695. : text (other.text),
  69696. font (other.font),
  69697. x (other.x),
  69698. y (other.y),
  69699. w (other.w),
  69700. h (other.h),
  69701. line (other.line),
  69702. lineHeight (other.lineHeight),
  69703. isWhitespace (other.isWhitespace),
  69704. isNewLine (other.isNewLine)
  69705. {
  69706. }
  69707. ~Token() throw()
  69708. {
  69709. }
  69710. void draw (Graphics& g,
  69711. const int xOffset,
  69712. const int yOffset) throw()
  69713. {
  69714. if (! isWhitespace)
  69715. {
  69716. g.setFont (font);
  69717. g.drawSingleLineText (text.trimEnd(),
  69718. xOffset + x,
  69719. yOffset + y + (lineHeight - h)
  69720. + roundToInt (font.getAscent()));
  69721. }
  69722. }
  69723. juce_UseDebuggingNewOperator
  69724. };
  69725. TextLayout::TextLayout() throw()
  69726. : totalLines (0)
  69727. {
  69728. tokens.ensureStorageAllocated (64);
  69729. }
  69730. TextLayout::TextLayout (const String& text,
  69731. const Font& font) throw()
  69732. : totalLines (0)
  69733. {
  69734. tokens.ensureStorageAllocated (64);
  69735. appendText (text, font);
  69736. }
  69737. TextLayout::TextLayout (const TextLayout& other) throw()
  69738. : totalLines (0)
  69739. {
  69740. *this = other;
  69741. }
  69742. TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  69743. {
  69744. if (this != &other)
  69745. {
  69746. clear();
  69747. totalLines = other.totalLines;
  69748. for (int i = 0; i < other.tokens.size(); ++i)
  69749. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69750. }
  69751. return *this;
  69752. }
  69753. TextLayout::~TextLayout() throw()
  69754. {
  69755. clear();
  69756. }
  69757. void TextLayout::clear() throw()
  69758. {
  69759. tokens.clear();
  69760. totalLines = 0;
  69761. }
  69762. void TextLayout::appendText (const String& text,
  69763. const Font& font) throw()
  69764. {
  69765. const tchar* t = text;
  69766. String currentString;
  69767. int lastCharType = 0;
  69768. for (;;)
  69769. {
  69770. const tchar c = *t++;
  69771. if (c == 0)
  69772. break;
  69773. int charType;
  69774. if (c == T('\r') || c == T('\n'))
  69775. {
  69776. charType = 0;
  69777. }
  69778. else if (CharacterFunctions::isWhitespace (c))
  69779. {
  69780. charType = 2;
  69781. }
  69782. else
  69783. {
  69784. charType = 1;
  69785. }
  69786. if (charType == 0 || charType != lastCharType)
  69787. {
  69788. if (currentString.isNotEmpty())
  69789. {
  69790. tokens.add (new Token (currentString, font,
  69791. lastCharType == 2 || lastCharType == 0));
  69792. }
  69793. currentString = String::charToString (c);
  69794. if (c == T('\r') && *t == T('\n'))
  69795. currentString += *t++;
  69796. }
  69797. else
  69798. {
  69799. currentString += c;
  69800. }
  69801. lastCharType = charType;
  69802. }
  69803. if (currentString.isNotEmpty())
  69804. tokens.add (new Token (currentString, font, lastCharType == 2));
  69805. }
  69806. void TextLayout::setText (const String& text, const Font& font) throw()
  69807. {
  69808. clear();
  69809. appendText (text, font);
  69810. }
  69811. void TextLayout::layout (int maxWidth,
  69812. const Justification& justification,
  69813. const bool attemptToBalanceLineLengths) throw()
  69814. {
  69815. if (attemptToBalanceLineLengths)
  69816. {
  69817. const int originalW = maxWidth;
  69818. int bestWidth = maxWidth;
  69819. float bestLineProportion = 0.0f;
  69820. while (maxWidth > originalW / 2)
  69821. {
  69822. layout (maxWidth, justification, false);
  69823. if (getNumLines() <= 1)
  69824. return;
  69825. const int lastLineW = getLineWidth (getNumLines() - 1);
  69826. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69827. const float prop = lastLineW / (float) lastButOneLineW;
  69828. if (prop > 0.9f)
  69829. return;
  69830. if (prop > bestLineProportion)
  69831. {
  69832. bestLineProportion = prop;
  69833. bestWidth = maxWidth;
  69834. }
  69835. maxWidth -= 10;
  69836. }
  69837. layout (bestWidth, justification, false);
  69838. }
  69839. else
  69840. {
  69841. int x = 0;
  69842. int y = 0;
  69843. int h = 0;
  69844. totalLines = 0;
  69845. int i;
  69846. for (i = 0; i < tokens.size(); ++i)
  69847. {
  69848. Token* const t = tokens.getUnchecked(i);
  69849. t->x = x;
  69850. t->y = y;
  69851. t->line = totalLines;
  69852. x += t->w;
  69853. h = jmax (h, t->h);
  69854. const Token* nextTok = tokens [i + 1];
  69855. if (nextTok == 0)
  69856. break;
  69857. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69858. {
  69859. // finished a line, so go back and update the heights of the things on it
  69860. for (int j = i; j >= 0; --j)
  69861. {
  69862. Token* const tok = tokens.getUnchecked(j);
  69863. if (tok->line == totalLines)
  69864. tok->lineHeight = h;
  69865. else
  69866. break;
  69867. }
  69868. x = 0;
  69869. y += h;
  69870. h = 0;
  69871. ++totalLines;
  69872. }
  69873. }
  69874. // finished a line, so go back and update the heights of the things on it
  69875. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69876. {
  69877. Token* const t = tokens.getUnchecked(j);
  69878. if (t->line == totalLines)
  69879. t->lineHeight = h;
  69880. else
  69881. break;
  69882. }
  69883. ++totalLines;
  69884. if (! justification.testFlags (Justification::left))
  69885. {
  69886. int totalW = getWidth();
  69887. for (i = totalLines; --i >= 0;)
  69888. {
  69889. const int lineW = getLineWidth (i);
  69890. int dx = 0;
  69891. if (justification.testFlags (Justification::horizontallyCentred))
  69892. dx = (totalW - lineW) / 2;
  69893. else if (justification.testFlags (Justification::right))
  69894. dx = totalW - lineW;
  69895. for (int j = tokens.size(); --j >= 0;)
  69896. {
  69897. Token* const t = tokens.getUnchecked(j);
  69898. if (t->line == i)
  69899. t->x += dx;
  69900. }
  69901. }
  69902. }
  69903. }
  69904. }
  69905. int TextLayout::getLineWidth (const int lineNumber) const throw()
  69906. {
  69907. int maxW = 0;
  69908. for (int i = tokens.size(); --i >= 0;)
  69909. {
  69910. const Token* const t = tokens.getUnchecked(i);
  69911. if (t->line == lineNumber && ! t->isWhitespace)
  69912. maxW = jmax (maxW, t->x + t->w);
  69913. }
  69914. return maxW;
  69915. }
  69916. int TextLayout::getWidth() const throw()
  69917. {
  69918. int maxW = 0;
  69919. for (int i = tokens.size(); --i >= 0;)
  69920. {
  69921. const Token* const t = tokens.getUnchecked(i);
  69922. if (! t->isWhitespace)
  69923. maxW = jmax (maxW, t->x + t->w);
  69924. }
  69925. return maxW;
  69926. }
  69927. int TextLayout::getHeight() const throw()
  69928. {
  69929. int maxH = 0;
  69930. for (int i = tokens.size(); --i >= 0;)
  69931. {
  69932. const Token* const t = tokens.getUnchecked(i);
  69933. if (! t->isWhitespace)
  69934. maxH = jmax (maxH, t->y + t->h);
  69935. }
  69936. return maxH;
  69937. }
  69938. void TextLayout::draw (Graphics& g,
  69939. const int xOffset,
  69940. const int yOffset) const throw()
  69941. {
  69942. for (int i = tokens.size(); --i >= 0;)
  69943. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  69944. }
  69945. void TextLayout::drawWithin (Graphics& g,
  69946. int x, int y, int w, int h,
  69947. const Justification& justification) const throw()
  69948. {
  69949. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  69950. x, y, w, h);
  69951. draw (g, x, y);
  69952. }
  69953. END_JUCE_NAMESPACE
  69954. /*** End of inlined file: juce_TextLayout.cpp ***/
  69955. /*** Start of inlined file: juce_Typeface.cpp ***/
  69956. BEGIN_JUCE_NAMESPACE
  69957. Typeface::Typeface (const String& name_) throw()
  69958. : name (name_)
  69959. {
  69960. }
  69961. Typeface::~Typeface()
  69962. {
  69963. }
  69964. class CustomTypeface::GlyphInfo
  69965. {
  69966. public:
  69967. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  69968. : character (character_), path (path_), width (width_)
  69969. {
  69970. }
  69971. ~GlyphInfo() throw()
  69972. {
  69973. }
  69974. struct KerningPair
  69975. {
  69976. juce_wchar character2;
  69977. float kerningAmount;
  69978. };
  69979. void addKerningPair (const juce_wchar subsequentCharacter,
  69980. const float extraKerningAmount) throw()
  69981. {
  69982. KerningPair kp;
  69983. kp.character2 = subsequentCharacter;
  69984. kp.kerningAmount = extraKerningAmount;
  69985. kerningPairs.add (kp);
  69986. }
  69987. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  69988. {
  69989. if (subsequentCharacter != 0)
  69990. {
  69991. for (int i = kerningPairs.size(); --i >= 0;)
  69992. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  69993. return width + kerningPairs.getReference(i).kerningAmount;
  69994. }
  69995. return width;
  69996. }
  69997. const juce_wchar character;
  69998. const Path path;
  69999. float width;
  70000. Array <KerningPair> kerningPairs;
  70001. juce_UseDebuggingNewOperator
  70002. private:
  70003. GlyphInfo (const GlyphInfo&);
  70004. GlyphInfo& operator= (const GlyphInfo&);
  70005. };
  70006. CustomTypeface::CustomTypeface()
  70007. : Typeface (String::empty)
  70008. {
  70009. clear();
  70010. }
  70011. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70012. : Typeface (String::empty)
  70013. {
  70014. clear();
  70015. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70016. BufferedInputStream in (&gzin, 32768, false);
  70017. name = in.readString();
  70018. isBold = in.readBool();
  70019. isItalic = in.readBool();
  70020. ascent = in.readFloat();
  70021. defaultCharacter = (juce_wchar) in.readShort();
  70022. int i, numChars = in.readInt();
  70023. for (i = 0; i < numChars; ++i)
  70024. {
  70025. const juce_wchar c = (juce_wchar) in.readShort();
  70026. const float width = in.readFloat();
  70027. Path p;
  70028. p.loadPathFromStream (in);
  70029. addGlyph (c, p, width);
  70030. }
  70031. const int numKerningPairs = in.readInt();
  70032. for (i = 0; i < numKerningPairs; ++i)
  70033. {
  70034. const juce_wchar char1 = (juce_wchar) in.readShort();
  70035. const juce_wchar char2 = (juce_wchar) in.readShort();
  70036. addKerningPair (char1, char2, in.readFloat());
  70037. }
  70038. }
  70039. CustomTypeface::~CustomTypeface()
  70040. {
  70041. }
  70042. void CustomTypeface::clear()
  70043. {
  70044. defaultCharacter = 0;
  70045. ascent = 1.0f;
  70046. isBold = isItalic = false;
  70047. zeromem (lookupTable, sizeof (lookupTable));
  70048. glyphs.clear();
  70049. }
  70050. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70051. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70052. {
  70053. name = name_;
  70054. defaultCharacter = defaultCharacter_;
  70055. ascent = ascent_;
  70056. isBold = isBold_;
  70057. isItalic = isItalic_;
  70058. }
  70059. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70060. {
  70061. // Check that you're not trying to add the same character twice..
  70062. jassert (findGlyph (character, false) == 0);
  70063. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70064. lookupTable [character] = (short) glyphs.size();
  70065. glyphs.add (new GlyphInfo (character, path, width));
  70066. }
  70067. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70068. {
  70069. if (extraAmount != 0)
  70070. {
  70071. GlyphInfo* const g = findGlyph (char1, true);
  70072. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70073. if (g != 0)
  70074. g->addKerningPair (char2, extraAmount);
  70075. }
  70076. }
  70077. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70078. {
  70079. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70080. return glyphs [(int) lookupTable [(int) character]];
  70081. for (int i = 0; i < glyphs.size(); ++i)
  70082. {
  70083. GlyphInfo* const g = glyphs.getUnchecked(i);
  70084. if (g->character == character)
  70085. return g;
  70086. }
  70087. if (loadIfNeeded && loadGlyphIfPossible (character))
  70088. return findGlyph (character, false);
  70089. return 0;
  70090. }
  70091. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70092. {
  70093. GlyphInfo* glyph = findGlyph (character, true);
  70094. if (glyph == 0)
  70095. {
  70096. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70097. glyph = findGlyph (L' ', true);
  70098. if (glyph == 0)
  70099. {
  70100. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70101. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70102. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70103. {
  70104. //xxx
  70105. }
  70106. if (glyph == 0)
  70107. glyph = findGlyph (defaultCharacter, true);
  70108. }
  70109. }
  70110. return glyph;
  70111. }
  70112. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70113. {
  70114. return false;
  70115. }
  70116. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70117. {
  70118. for (int i = 0; i < numCharacters; ++i)
  70119. {
  70120. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70121. Array <int> glyphIndexes;
  70122. Array <float> offsets;
  70123. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70124. const int glyphIndex = glyphIndexes.getFirst();
  70125. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70126. {
  70127. const float glyphWidth = offsets[1];
  70128. Path p;
  70129. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70130. addGlyph (c, p, glyphWidth);
  70131. for (int j = glyphs.size() - 1; --j >= 0;)
  70132. {
  70133. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70134. glyphIndexes.clearQuick();
  70135. offsets.clearQuick();
  70136. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70137. if (offsets.size() > 1)
  70138. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70139. }
  70140. }
  70141. }
  70142. }
  70143. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70144. {
  70145. GZIPCompressorOutputStream out (&outputStream);
  70146. out.writeString (name);
  70147. out.writeBool (isBold);
  70148. out.writeBool (isItalic);
  70149. out.writeFloat (ascent);
  70150. out.writeShort ((short) (unsigned short) defaultCharacter);
  70151. out.writeInt (glyphs.size());
  70152. int i, numKerningPairs = 0;
  70153. for (i = 0; i < glyphs.size(); ++i)
  70154. {
  70155. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70156. out.writeShort ((short) (unsigned short) g->character);
  70157. out.writeFloat (g->width);
  70158. g->path.writePathToStream (out);
  70159. numKerningPairs += g->kerningPairs.size();
  70160. }
  70161. out.writeInt (numKerningPairs);
  70162. for (i = 0; i < glyphs.size(); ++i)
  70163. {
  70164. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70165. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70166. {
  70167. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70168. out.writeShort ((short) (unsigned short) g->character);
  70169. out.writeShort ((short) (unsigned short) p.character2);
  70170. out.writeFloat (p.kerningAmount);
  70171. }
  70172. }
  70173. return true;
  70174. }
  70175. float CustomTypeface::getAscent() const
  70176. {
  70177. return ascent;
  70178. }
  70179. float CustomTypeface::getDescent() const
  70180. {
  70181. return 1.0f - ascent;
  70182. }
  70183. float CustomTypeface::getStringWidth (const String& text)
  70184. {
  70185. float x = 0;
  70186. const juce_wchar* t = (const juce_wchar*) text;
  70187. while (*t != 0)
  70188. {
  70189. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70190. if (glyph != 0)
  70191. x += glyph->getHorizontalSpacing (*t);
  70192. }
  70193. return x;
  70194. }
  70195. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70196. {
  70197. xOffsets.add (0);
  70198. float x = 0;
  70199. const juce_wchar* t = (const juce_wchar*) text;
  70200. while (*t != 0)
  70201. {
  70202. const juce_wchar c = *t++;
  70203. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70204. if (glyph != 0)
  70205. {
  70206. x += glyph->getHorizontalSpacing (*t);
  70207. resultGlyphs.add ((int) glyph->character);
  70208. xOffsets.add (x);
  70209. }
  70210. }
  70211. }
  70212. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70213. {
  70214. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70215. if (glyph != 0)
  70216. {
  70217. path = glyph->path;
  70218. return true;
  70219. }
  70220. return false;
  70221. }
  70222. END_JUCE_NAMESPACE
  70223. /*** End of inlined file: juce_Typeface.cpp ***/
  70224. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70225. BEGIN_JUCE_NAMESPACE
  70226. AffineTransform::AffineTransform() throw()
  70227. : mat00 (1.0f),
  70228. mat01 (0),
  70229. mat02 (0),
  70230. mat10 (0),
  70231. mat11 (1.0f),
  70232. mat12 (0)
  70233. {
  70234. }
  70235. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70236. : mat00 (other.mat00),
  70237. mat01 (other.mat01),
  70238. mat02 (other.mat02),
  70239. mat10 (other.mat10),
  70240. mat11 (other.mat11),
  70241. mat12 (other.mat12)
  70242. {
  70243. }
  70244. AffineTransform::AffineTransform (const float mat00_,
  70245. const float mat01_,
  70246. const float mat02_,
  70247. const float mat10_,
  70248. const float mat11_,
  70249. const float mat12_) throw()
  70250. : mat00 (mat00_),
  70251. mat01 (mat01_),
  70252. mat02 (mat02_),
  70253. mat10 (mat10_),
  70254. mat11 (mat11_),
  70255. mat12 (mat12_)
  70256. {
  70257. }
  70258. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70259. {
  70260. mat00 = other.mat00;
  70261. mat01 = other.mat01;
  70262. mat02 = other.mat02;
  70263. mat10 = other.mat10;
  70264. mat11 = other.mat11;
  70265. mat12 = other.mat12;
  70266. return *this;
  70267. }
  70268. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70269. {
  70270. return mat00 == other.mat00
  70271. && mat01 == other.mat01
  70272. && mat02 == other.mat02
  70273. && mat10 == other.mat10
  70274. && mat11 == other.mat11
  70275. && mat12 == other.mat12;
  70276. }
  70277. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70278. {
  70279. return ! operator== (other);
  70280. }
  70281. bool AffineTransform::isIdentity() const throw()
  70282. {
  70283. return (mat01 == 0)
  70284. && (mat02 == 0)
  70285. && (mat10 == 0)
  70286. && (mat12 == 0)
  70287. && (mat00 == 1.0f)
  70288. && (mat11 == 1.0f);
  70289. }
  70290. const AffineTransform AffineTransform::identity;
  70291. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70292. {
  70293. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70294. other.mat00 * mat01 + other.mat01 * mat11,
  70295. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70296. other.mat10 * mat00 + other.mat11 * mat10,
  70297. other.mat10 * mat01 + other.mat11 * mat11,
  70298. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70299. }
  70300. const AffineTransform AffineTransform::followedBy (const float omat00,
  70301. const float omat01,
  70302. const float omat02,
  70303. const float omat10,
  70304. const float omat11,
  70305. const float omat12) const throw()
  70306. {
  70307. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70308. omat00 * mat01 + omat01 * mat11,
  70309. omat00 * mat02 + omat01 * mat12 + omat02,
  70310. omat10 * mat00 + omat11 * mat10,
  70311. omat10 * mat01 + omat11 * mat11,
  70312. omat10 * mat02 + omat11 * mat12 + omat12);
  70313. }
  70314. const AffineTransform AffineTransform::translated (const float dx,
  70315. const float dy) const throw()
  70316. {
  70317. return AffineTransform (mat00, mat01, mat02 + dx,
  70318. mat10, mat11, mat12 + dy);
  70319. }
  70320. const AffineTransform AffineTransform::translation (const float dx,
  70321. const float dy) throw()
  70322. {
  70323. return AffineTransform (1.0f, 0, dx,
  70324. 0, 1.0f, dy);
  70325. }
  70326. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70327. {
  70328. const float cosRad = cosf (rad);
  70329. const float sinRad = sinf (rad);
  70330. return followedBy (cosRad, -sinRad, 0,
  70331. sinRad, cosRad, 0);
  70332. }
  70333. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70334. {
  70335. const float cosRad = cosf (rad);
  70336. const float sinRad = sinf (rad);
  70337. return AffineTransform (cosRad, -sinRad, 0,
  70338. sinRad, cosRad, 0);
  70339. }
  70340. const AffineTransform AffineTransform::rotated (const float angle,
  70341. const float pivotX,
  70342. const float pivotY) const throw()
  70343. {
  70344. return translated (-pivotX, -pivotY)
  70345. .rotated (angle)
  70346. .translated (pivotX, pivotY);
  70347. }
  70348. const AffineTransform AffineTransform::rotation (const float angle,
  70349. const float pivotX,
  70350. const float pivotY) throw()
  70351. {
  70352. return translation (-pivotX, -pivotY)
  70353. .rotated (angle)
  70354. .translated (pivotX, pivotY);
  70355. }
  70356. const AffineTransform AffineTransform::scaled (const float factorX,
  70357. const float factorY) const throw()
  70358. {
  70359. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70360. factorY * mat10, factorY * mat11, factorY * mat12);
  70361. }
  70362. const AffineTransform AffineTransform::scale (const float factorX,
  70363. const float factorY) throw()
  70364. {
  70365. return AffineTransform (factorX, 0, 0,
  70366. 0, factorY, 0);
  70367. }
  70368. const AffineTransform AffineTransform::sheared (const float shearX,
  70369. const float shearY) const throw()
  70370. {
  70371. return followedBy (1.0f, shearX, 0,
  70372. shearY, 1.0f, 0);
  70373. }
  70374. const AffineTransform AffineTransform::inverted() const throw()
  70375. {
  70376. double determinant = (mat00 * mat11 - mat10 * mat01);
  70377. if (determinant != 0.0)
  70378. {
  70379. determinant = 1.0 / determinant;
  70380. const float dst00 = (float) (mat11 * determinant);
  70381. const float dst10 = (float) (-mat10 * determinant);
  70382. const float dst01 = (float) (-mat01 * determinant);
  70383. const float dst11 = (float) (mat00 * determinant);
  70384. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70385. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70386. }
  70387. else
  70388. {
  70389. // singularity..
  70390. return *this;
  70391. }
  70392. }
  70393. bool AffineTransform::isSingularity() const throw()
  70394. {
  70395. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70396. }
  70397. bool AffineTransform::isOnlyTranslation() const throw()
  70398. {
  70399. return (mat01 == 0)
  70400. && (mat10 == 0)
  70401. && (mat00 == 1.0f)
  70402. && (mat11 == 1.0f);
  70403. }
  70404. void AffineTransform::transformPoint (float& x,
  70405. float& y) const throw()
  70406. {
  70407. const float oldX = x;
  70408. x = mat00 * oldX + mat01 * y + mat02;
  70409. y = mat10 * oldX + mat11 * y + mat12;
  70410. }
  70411. void AffineTransform::transformPoint (double& x,
  70412. double& y) const throw()
  70413. {
  70414. const double oldX = x;
  70415. x = mat00 * oldX + mat01 * y + mat02;
  70416. y = mat10 * oldX + mat11 * y + mat12;
  70417. }
  70418. END_JUCE_NAMESPACE
  70419. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70420. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70421. BEGIN_JUCE_NAMESPACE
  70422. BorderSize::BorderSize() throw()
  70423. : top (0),
  70424. left (0),
  70425. bottom (0),
  70426. right (0)
  70427. {
  70428. }
  70429. BorderSize::BorderSize (const BorderSize& other) throw()
  70430. : top (other.top),
  70431. left (other.left),
  70432. bottom (other.bottom),
  70433. right (other.right)
  70434. {
  70435. }
  70436. BorderSize::BorderSize (const int topGap,
  70437. const int leftGap,
  70438. const int bottomGap,
  70439. const int rightGap) throw()
  70440. : top (topGap),
  70441. left (leftGap),
  70442. bottom (bottomGap),
  70443. right (rightGap)
  70444. {
  70445. }
  70446. BorderSize::BorderSize (const int allGaps) throw()
  70447. : top (allGaps),
  70448. left (allGaps),
  70449. bottom (allGaps),
  70450. right (allGaps)
  70451. {
  70452. }
  70453. BorderSize::~BorderSize() throw()
  70454. {
  70455. }
  70456. void BorderSize::setTop (const int newTopGap) throw()
  70457. {
  70458. top = newTopGap;
  70459. }
  70460. void BorderSize::setLeft (const int newLeftGap) throw()
  70461. {
  70462. left = newLeftGap;
  70463. }
  70464. void BorderSize::setBottom (const int newBottomGap) throw()
  70465. {
  70466. bottom = newBottomGap;
  70467. }
  70468. void BorderSize::setRight (const int newRightGap) throw()
  70469. {
  70470. right = newRightGap;
  70471. }
  70472. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70473. {
  70474. return Rectangle<int> (r.getX() + left,
  70475. r.getY() + top,
  70476. r.getWidth() - (left + right),
  70477. r.getHeight() - (top + bottom));
  70478. }
  70479. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70480. {
  70481. r.setBounds (r.getX() + left,
  70482. r.getY() + top,
  70483. r.getWidth() - (left + right),
  70484. r.getHeight() - (top + bottom));
  70485. }
  70486. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70487. {
  70488. return Rectangle<int> (r.getX() - left,
  70489. r.getY() - top,
  70490. r.getWidth() + (left + right),
  70491. r.getHeight() + (top + bottom));
  70492. }
  70493. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70494. {
  70495. r.setBounds (r.getX() - left,
  70496. r.getY() - top,
  70497. r.getWidth() + (left + right),
  70498. r.getHeight() + (top + bottom));
  70499. }
  70500. bool BorderSize::operator== (const BorderSize& other) const throw()
  70501. {
  70502. return top == other.top
  70503. && left == other.left
  70504. && bottom == other.bottom
  70505. && right == other.right;
  70506. }
  70507. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70508. {
  70509. return ! operator== (other);
  70510. }
  70511. END_JUCE_NAMESPACE
  70512. /*** End of inlined file: juce_BorderSize.cpp ***/
  70513. /*** Start of inlined file: juce_Line.cpp ***/
  70514. BEGIN_JUCE_NAMESPACE
  70515. static bool juce_lineIntersection (const float x1, const float y1,
  70516. const float x2, const float y2,
  70517. const float x3, const float y3,
  70518. const float x4, const float y4,
  70519. float& intersectionX,
  70520. float& intersectionY) throw()
  70521. {
  70522. if (x2 != x3 || y2 != y3)
  70523. {
  70524. const float dx1 = x2 - x1;
  70525. const float dy1 = y2 - y1;
  70526. const float dx2 = x4 - x3;
  70527. const float dy2 = y4 - y3;
  70528. const float divisor = dx1 * dy2 - dx2 * dy1;
  70529. if (divisor == 0)
  70530. {
  70531. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70532. {
  70533. if (dy1 == 0 && dy2 != 0)
  70534. {
  70535. const float along = (y1 - y3) / dy2;
  70536. intersectionX = x3 + along * dx2;
  70537. intersectionY = y1;
  70538. return along >= 0 && along <= 1.0f;
  70539. }
  70540. else if (dy2 == 0 && dy1 != 0)
  70541. {
  70542. const float along = (y3 - y1) / dy1;
  70543. intersectionX = x1 + along * dx1;
  70544. intersectionY = y3;
  70545. return along >= 0 && along <= 1.0f;
  70546. }
  70547. else if (dx1 == 0 && dx2 != 0)
  70548. {
  70549. const float along = (x1 - x3) / dx2;
  70550. intersectionX = x1;
  70551. intersectionY = y3 + along * dy2;
  70552. return along >= 0 && along <= 1.0f;
  70553. }
  70554. else if (dx2 == 0 && dx1 != 0)
  70555. {
  70556. const float along = (x3 - x1) / dx1;
  70557. intersectionX = x3;
  70558. intersectionY = y1 + along * dy1;
  70559. return along >= 0 && along <= 1.0f;
  70560. }
  70561. }
  70562. intersectionX = 0.5f * (x2 + x3);
  70563. intersectionY = 0.5f * (y2 + y3);
  70564. return false;
  70565. }
  70566. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70567. intersectionX = x1 + along1 * dx1;
  70568. intersectionY = y1 + along1 * dy1;
  70569. if (along1 < 0 || along1 > 1.0f)
  70570. return false;
  70571. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70572. return along2 >= 0 && along2 <= 1.0f;
  70573. }
  70574. intersectionX = x2;
  70575. intersectionY = y2;
  70576. return true;
  70577. }
  70578. Line::Line() throw()
  70579. : startX (0.0f),
  70580. startY (0.0f),
  70581. endX (0.0f),
  70582. endY (0.0f)
  70583. {
  70584. }
  70585. Line::Line (const Line& other) throw()
  70586. : startX (other.startX),
  70587. startY (other.startY),
  70588. endX (other.endX),
  70589. endY (other.endY)
  70590. {
  70591. }
  70592. Line::Line (const float startX_, const float startY_,
  70593. const float endX_, const float endY_) throw()
  70594. : startX (startX_),
  70595. startY (startY_),
  70596. endX (endX_),
  70597. endY (endY_)
  70598. {
  70599. }
  70600. Line::Line (const Point<float>& start,
  70601. const Point<float>& end) throw()
  70602. : startX (start.getX()),
  70603. startY (start.getY()),
  70604. endX (end.getX()),
  70605. endY (end.getY())
  70606. {
  70607. }
  70608. Line& Line::operator= (const Line& other) throw()
  70609. {
  70610. startX = other.startX;
  70611. startY = other.startY;
  70612. endX = other.endX;
  70613. endY = other.endY;
  70614. return *this;
  70615. }
  70616. Line::~Line() throw()
  70617. {
  70618. }
  70619. const Point<float> Line::getStart() const throw()
  70620. {
  70621. return Point<float> (startX, startY);
  70622. }
  70623. const Point<float> Line::getEnd() const throw()
  70624. {
  70625. return Point<float> (endX, endY);
  70626. }
  70627. void Line::setStart (const float newStartX,
  70628. const float newStartY) throw()
  70629. {
  70630. startX = newStartX;
  70631. startY = newStartY;
  70632. }
  70633. void Line::setStart (const Point<float>& newStart) throw()
  70634. {
  70635. startX = newStart.getX();
  70636. startY = newStart.getY();
  70637. }
  70638. void Line::setEnd (const float newEndX,
  70639. const float newEndY) throw()
  70640. {
  70641. endX = newEndX;
  70642. endY = newEndY;
  70643. }
  70644. void Line::setEnd (const Point<float>& newEnd) throw()
  70645. {
  70646. endX = newEnd.getX();
  70647. endY = newEnd.getY();
  70648. }
  70649. bool Line::operator== (const Line& other) const throw()
  70650. {
  70651. return startX == other.startX
  70652. && startY == other.startY
  70653. && endX == other.endX
  70654. && endY == other.endY;
  70655. }
  70656. bool Line::operator!= (const Line& other) const throw()
  70657. {
  70658. return startX != other.startX
  70659. || startY != other.startY
  70660. || endX != other.endX
  70661. || endY != other.endY;
  70662. }
  70663. void Line::applyTransform (const AffineTransform& transform) throw()
  70664. {
  70665. transform.transformPoint (startX, startY);
  70666. transform.transformPoint (endX, endY);
  70667. }
  70668. float Line::getLength() const throw()
  70669. {
  70670. return (float) juce_hypot (startX - endX,
  70671. startY - endY);
  70672. }
  70673. float Line::getAngle() const throw()
  70674. {
  70675. return atan2f (endX - startX,
  70676. endY - startY);
  70677. }
  70678. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70679. {
  70680. const float alpha = distanceFromStart / getLength();
  70681. return Point<float> (startX + (endX - startX) * alpha,
  70682. startY + (endY - startY) * alpha);
  70683. }
  70684. const Point<float> Line::getPointAlongLine (const float offsetX,
  70685. const float offsetY) const throw()
  70686. {
  70687. const float dx = endX - startX;
  70688. const float dy = endY - startY;
  70689. const double length = juce_hypot (dx, dy);
  70690. if (length == 0)
  70691. return Point<float> (startX, startY);
  70692. else
  70693. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70694. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70695. }
  70696. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70697. {
  70698. return Point<float> (startX + (endX - startX) * alpha,
  70699. startY + (endY - startY) * alpha);
  70700. }
  70701. float Line::getDistanceFromLine (const float x,
  70702. const float y) const throw()
  70703. {
  70704. const double dx = endX - startX;
  70705. const double dy = endY - startY;
  70706. const double length = dx * dx + dy * dy;
  70707. if (length > 0)
  70708. {
  70709. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70710. if (prop >= 0.0f && prop < 1.0f)
  70711. {
  70712. return (float) juce_hypot (x - (startX + prop * dx),
  70713. y - (startY + prop * dy));
  70714. }
  70715. }
  70716. return (float) jmin (juce_hypot (x - startX, y - startY),
  70717. juce_hypot (x - endX, y - endY));
  70718. }
  70719. float Line::findNearestPointTo (const float x,
  70720. const float y) const throw()
  70721. {
  70722. const double dx = endX - startX;
  70723. const double dy = endY - startY;
  70724. const double length = dx * dx + dy * dy;
  70725. if (length <= 0.0)
  70726. return 0.0f;
  70727. return jlimit (0.0f, 1.0f,
  70728. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70729. }
  70730. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70731. {
  70732. const float length = getLength();
  70733. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70734. getEnd());
  70735. }
  70736. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70737. {
  70738. const float length = getLength();
  70739. return Line (getStart(),
  70740. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70741. }
  70742. bool Line::clipToPath (const Path& path,
  70743. const bool keepSectionOutsidePath) throw()
  70744. {
  70745. const bool startInside = path.contains (startX, startY);
  70746. const bool endInside = path.contains (endX, endY);
  70747. if (startInside == endInside)
  70748. {
  70749. if (keepSectionOutsidePath != startInside)
  70750. {
  70751. // entirely outside the path
  70752. return false;
  70753. }
  70754. else
  70755. {
  70756. // entirely inside the path
  70757. startX = 0.0f;
  70758. startY = 0.0f;
  70759. endX = 0.0f;
  70760. endY = 0.0f;
  70761. return true;
  70762. }
  70763. }
  70764. else
  70765. {
  70766. bool changed = false;
  70767. PathFlatteningIterator iter (path, AffineTransform::identity);
  70768. while (iter.next())
  70769. {
  70770. float ix, iy;
  70771. if (intersects (Line (iter.x1, iter.y1,
  70772. iter.x2, iter.y2),
  70773. ix, iy))
  70774. {
  70775. if ((startInside && keepSectionOutsidePath)
  70776. || (endInside && ! keepSectionOutsidePath))
  70777. {
  70778. setStart (ix, iy);
  70779. }
  70780. else
  70781. {
  70782. setEnd (ix, iy);
  70783. }
  70784. changed = true;
  70785. }
  70786. }
  70787. return changed;
  70788. }
  70789. }
  70790. bool Line::intersects (const Line& line,
  70791. float& intersectionX,
  70792. float& intersectionY) const throw()
  70793. {
  70794. return juce_lineIntersection (startX, startY,
  70795. endX, endY,
  70796. line.startX, line.startY,
  70797. line.endX, line.endY,
  70798. intersectionX,
  70799. intersectionY);
  70800. }
  70801. bool Line::isVertical() const throw()
  70802. {
  70803. return startX == endX;
  70804. }
  70805. bool Line::isHorizontal() const throw()
  70806. {
  70807. return startY == endY;
  70808. }
  70809. bool Line::isPointAbove (const float x, const float y) const throw()
  70810. {
  70811. return startX != endX
  70812. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70813. }
  70814. END_JUCE_NAMESPACE
  70815. /*** End of inlined file: juce_Line.cpp ***/
  70816. /*** Start of inlined file: juce_Path.cpp ***/
  70817. BEGIN_JUCE_NAMESPACE
  70818. // tests that some co-ords aren't NaNs
  70819. #define CHECK_COORDS_ARE_VALID(x, y) \
  70820. jassert (x == x && y == y);
  70821. const float Path::lineMarker = 100001.0f;
  70822. const float Path::moveMarker = 100002.0f;
  70823. const float Path::quadMarker = 100003.0f;
  70824. const float Path::cubicMarker = 100004.0f;
  70825. const float Path::closeSubPathMarker = 100005.0f;
  70826. static const int defaultGranularity = 32;
  70827. Path::Path() throw()
  70828. : numElements (0),
  70829. pathXMin (0),
  70830. pathXMax (0),
  70831. pathYMin (0),
  70832. pathYMax (0),
  70833. useNonZeroWinding (true)
  70834. {
  70835. }
  70836. Path::~Path() throw()
  70837. {
  70838. }
  70839. Path::Path (const Path& other) throw()
  70840. : numElements (other.numElements),
  70841. pathXMin (other.pathXMin),
  70842. pathXMax (other.pathXMax),
  70843. pathYMin (other.pathYMin),
  70844. pathYMax (other.pathYMax),
  70845. useNonZeroWinding (other.useNonZeroWinding)
  70846. {
  70847. if (numElements > 0)
  70848. {
  70849. data.setAllocatedSize (numElements);
  70850. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70851. }
  70852. }
  70853. Path& Path::operator= (const Path& other) throw()
  70854. {
  70855. if (this != &other)
  70856. {
  70857. data.ensureAllocatedSize (other.numElements);
  70858. numElements = other.numElements;
  70859. pathXMin = other.pathXMin;
  70860. pathXMax = other.pathXMax;
  70861. pathYMin = other.pathYMin;
  70862. pathYMax = other.pathYMax;
  70863. useNonZeroWinding = other.useNonZeroWinding;
  70864. if (numElements > 0)
  70865. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70866. }
  70867. return *this;
  70868. }
  70869. void Path::clear() throw()
  70870. {
  70871. numElements = 0;
  70872. pathXMin = 0;
  70873. pathYMin = 0;
  70874. pathYMax = 0;
  70875. pathXMax = 0;
  70876. }
  70877. void Path::swapWithPath (Path& other)
  70878. {
  70879. data.swapWith (other.data);
  70880. swapVariables <int> (numElements, other.numElements);
  70881. swapVariables <float> (pathXMin, other.pathXMin);
  70882. swapVariables <float> (pathXMax, other.pathXMax);
  70883. swapVariables <float> (pathYMin, other.pathYMin);
  70884. swapVariables <float> (pathYMax, other.pathYMax);
  70885. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70886. }
  70887. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70888. {
  70889. useNonZeroWinding = isNonZero;
  70890. }
  70891. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70892. const bool preserveProportions) throw()
  70893. {
  70894. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70895. }
  70896. bool Path::isEmpty() const throw()
  70897. {
  70898. int i = 0;
  70899. while (i < numElements)
  70900. {
  70901. const float type = data.elements [i++];
  70902. if (type == moveMarker)
  70903. {
  70904. i += 2;
  70905. }
  70906. else if (type == lineMarker
  70907. || type == quadMarker
  70908. || type == cubicMarker)
  70909. {
  70910. return false;
  70911. }
  70912. }
  70913. return true;
  70914. }
  70915. const Rectangle<float> Path::getBounds () const throw()
  70916. {
  70917. return Rectangle<float> (pathXMin, pathYMin,
  70918. pathXMax - pathXMin,
  70919. pathYMax - pathYMin);
  70920. }
  70921. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  70922. {
  70923. return getBounds().transformed (transform);
  70924. }
  70925. void Path::startNewSubPath (const float x,
  70926. const float y) throw()
  70927. {
  70928. CHECK_COORDS_ARE_VALID (x, y);
  70929. if (numElements == 0)
  70930. {
  70931. pathXMin = pathXMax = x;
  70932. pathYMin = pathYMax = y;
  70933. }
  70934. else
  70935. {
  70936. pathXMin = jmin (pathXMin, x);
  70937. pathXMax = jmax (pathXMax, x);
  70938. pathYMin = jmin (pathYMin, y);
  70939. pathYMax = jmax (pathYMax, y);
  70940. }
  70941. data.ensureAllocatedSize (numElements + 3);
  70942. data.elements [numElements++] = moveMarker;
  70943. data.elements [numElements++] = x;
  70944. data.elements [numElements++] = y;
  70945. }
  70946. void Path::lineTo (const float x, const float y) throw()
  70947. {
  70948. CHECK_COORDS_ARE_VALID (x, y);
  70949. if (numElements == 0)
  70950. startNewSubPath (0, 0);
  70951. data.ensureAllocatedSize (numElements + 3);
  70952. data.elements [numElements++] = lineMarker;
  70953. data.elements [numElements++] = x;
  70954. data.elements [numElements++] = y;
  70955. pathXMin = jmin (pathXMin, x);
  70956. pathXMax = jmax (pathXMax, x);
  70957. pathYMin = jmin (pathYMin, y);
  70958. pathYMax = jmax (pathYMax, y);
  70959. }
  70960. void Path::quadraticTo (const float x1, const float y1,
  70961. const float x2, const float y2) throw()
  70962. {
  70963. CHECK_COORDS_ARE_VALID (x1, y1);
  70964. CHECK_COORDS_ARE_VALID (x2, y2);
  70965. if (numElements == 0)
  70966. startNewSubPath (0, 0);
  70967. data.ensureAllocatedSize (numElements + 5);
  70968. data.elements [numElements++] = quadMarker;
  70969. data.elements [numElements++] = x1;
  70970. data.elements [numElements++] = y1;
  70971. data.elements [numElements++] = x2;
  70972. data.elements [numElements++] = y2;
  70973. pathXMin = jmin (pathXMin, x1, x2);
  70974. pathXMax = jmax (pathXMax, x1, x2);
  70975. pathYMin = jmin (pathYMin, y1, y2);
  70976. pathYMax = jmax (pathYMax, y1, y2);
  70977. }
  70978. void Path::cubicTo (const float x1, const float y1,
  70979. const float x2, const float y2,
  70980. const float x3, const float y3) throw()
  70981. {
  70982. CHECK_COORDS_ARE_VALID (x1, y1);
  70983. CHECK_COORDS_ARE_VALID (x2, y2);
  70984. CHECK_COORDS_ARE_VALID (x3, y3);
  70985. if (numElements == 0)
  70986. startNewSubPath (0, 0);
  70987. data.ensureAllocatedSize (numElements + 7);
  70988. data.elements [numElements++] = cubicMarker;
  70989. data.elements [numElements++] = x1;
  70990. data.elements [numElements++] = y1;
  70991. data.elements [numElements++] = x2;
  70992. data.elements [numElements++] = y2;
  70993. data.elements [numElements++] = x3;
  70994. data.elements [numElements++] = y3;
  70995. pathXMin = jmin (pathXMin, x1, x2, x3);
  70996. pathXMax = jmax (pathXMax, x1, x2, x3);
  70997. pathYMin = jmin (pathYMin, y1, y2, y3);
  70998. pathYMax = jmax (pathYMax, y1, y2, y3);
  70999. }
  71000. void Path::closeSubPath() throw()
  71001. {
  71002. if (numElements > 0
  71003. && data.elements [numElements - 1] != closeSubPathMarker)
  71004. {
  71005. data.ensureAllocatedSize (numElements + 1);
  71006. data.elements [numElements++] = closeSubPathMarker;
  71007. }
  71008. }
  71009. const Point<float> Path::getCurrentPosition() const
  71010. {
  71011. int i = numElements - 1;
  71012. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71013. {
  71014. while (i >= 0)
  71015. {
  71016. if (data.elements[i] == moveMarker)
  71017. {
  71018. i += 2;
  71019. break;
  71020. }
  71021. --i;
  71022. }
  71023. }
  71024. if (i > 0)
  71025. return Point<float> (data.elements [i - 1], data.elements [i]);
  71026. return Point<float>();
  71027. }
  71028. void Path::addRectangle (const float x, const float y,
  71029. const float w, const float h) throw()
  71030. {
  71031. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71032. if (w < 0)
  71033. swapVariables (x1, x2);
  71034. if (h < 0)
  71035. swapVariables (y1, y2);
  71036. data.ensureAllocatedSize (numElements + 13);
  71037. if (numElements == 0)
  71038. {
  71039. pathXMin = x1;
  71040. pathXMax = x2;
  71041. pathYMin = y1;
  71042. pathYMax = y2;
  71043. }
  71044. else
  71045. {
  71046. pathXMin = jmin (pathXMin, x1);
  71047. pathXMax = jmax (pathXMax, x2);
  71048. pathYMin = jmin (pathYMin, y1);
  71049. pathYMax = jmax (pathYMax, y2);
  71050. }
  71051. data.elements [numElements++] = moveMarker;
  71052. data.elements [numElements++] = x1;
  71053. data.elements [numElements++] = y2;
  71054. data.elements [numElements++] = lineMarker;
  71055. data.elements [numElements++] = x1;
  71056. data.elements [numElements++] = y1;
  71057. data.elements [numElements++] = lineMarker;
  71058. data.elements [numElements++] = x2;
  71059. data.elements [numElements++] = y1;
  71060. data.elements [numElements++] = lineMarker;
  71061. data.elements [numElements++] = x2;
  71062. data.elements [numElements++] = y2;
  71063. data.elements [numElements++] = closeSubPathMarker;
  71064. }
  71065. void Path::addRectangle (const Rectangle<int>& rectangle) throw()
  71066. {
  71067. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71068. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71069. }
  71070. void Path::addRoundedRectangle (const float x, const float y,
  71071. const float w, const float h,
  71072. float csx,
  71073. float csy) throw()
  71074. {
  71075. csx = jmin (csx, w * 0.5f);
  71076. csy = jmin (csy, h * 0.5f);
  71077. const float cs45x = csx * 0.45f;
  71078. const float cs45y = csy * 0.45f;
  71079. const float x2 = x + w;
  71080. const float y2 = y + h;
  71081. startNewSubPath (x + csx, y);
  71082. lineTo (x2 - csx, y);
  71083. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71084. lineTo (x2, y2 - csy);
  71085. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71086. lineTo (x + csx, y2);
  71087. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71088. lineTo (x, y + csy);
  71089. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71090. closeSubPath();
  71091. }
  71092. void Path::addRoundedRectangle (const float x, const float y,
  71093. const float w, const float h,
  71094. float cs) throw()
  71095. {
  71096. addRoundedRectangle (x, y, w, h, cs, cs);
  71097. }
  71098. void Path::addTriangle (const float x1, const float y1,
  71099. const float x2, const float y2,
  71100. const float x3, const float y3) throw()
  71101. {
  71102. startNewSubPath (x1, y1);
  71103. lineTo (x2, y2);
  71104. lineTo (x3, y3);
  71105. closeSubPath();
  71106. }
  71107. void Path::addQuadrilateral (const float x1, const float y1,
  71108. const float x2, const float y2,
  71109. const float x3, const float y3,
  71110. const float x4, const float y4) throw()
  71111. {
  71112. startNewSubPath (x1, y1);
  71113. lineTo (x2, y2);
  71114. lineTo (x3, y3);
  71115. lineTo (x4, y4);
  71116. closeSubPath();
  71117. }
  71118. void Path::addEllipse (const float x, const float y,
  71119. const float w, const float h) throw()
  71120. {
  71121. const float hw = w * 0.5f;
  71122. const float hw55 = hw * 0.55f;
  71123. const float hh = h * 0.5f;
  71124. const float hh45 = hh * 0.55f;
  71125. const float cx = x + hw;
  71126. const float cy = y + hh;
  71127. startNewSubPath (cx, cy - hh);
  71128. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71129. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71130. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71131. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71132. closeSubPath();
  71133. }
  71134. void Path::addArc (const float x, const float y,
  71135. const float w, const float h,
  71136. const float fromRadians,
  71137. const float toRadians,
  71138. const bool startAsNewSubPath) throw()
  71139. {
  71140. const float radiusX = w / 2.0f;
  71141. const float radiusY = h / 2.0f;
  71142. addCentredArc (x + radiusX,
  71143. y + radiusY,
  71144. radiusX, radiusY,
  71145. 0.0f,
  71146. fromRadians, toRadians,
  71147. startAsNewSubPath);
  71148. }
  71149. static const float ellipseAngularIncrement = 0.05f;
  71150. void Path::addCentredArc (const float centreX, const float centreY,
  71151. const float radiusX, const float radiusY,
  71152. const float rotationOfEllipse,
  71153. const float fromRadians,
  71154. const float toRadians,
  71155. const bool startAsNewSubPath) throw()
  71156. {
  71157. if (radiusX > 0.0f && radiusY > 0.0f)
  71158. {
  71159. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71160. float angle = fromRadians;
  71161. if (startAsNewSubPath)
  71162. {
  71163. float x = centreX + radiusX * sinf (angle);
  71164. float y = centreY - radiusY * cosf (angle);
  71165. if (rotationOfEllipse != 0)
  71166. rotation.transformPoint (x, y);
  71167. startNewSubPath (x, y);
  71168. }
  71169. if (fromRadians < toRadians)
  71170. {
  71171. if (startAsNewSubPath)
  71172. angle += ellipseAngularIncrement;
  71173. while (angle < toRadians)
  71174. {
  71175. float x = centreX + radiusX * sinf (angle);
  71176. float y = centreY - radiusY * cosf (angle);
  71177. if (rotationOfEllipse != 0)
  71178. rotation.transformPoint (x, y);
  71179. lineTo (x, y);
  71180. angle += ellipseAngularIncrement;
  71181. }
  71182. }
  71183. else
  71184. {
  71185. if (startAsNewSubPath)
  71186. angle -= ellipseAngularIncrement;
  71187. while (angle > toRadians)
  71188. {
  71189. float x = centreX + radiusX * sinf (angle);
  71190. float y = centreY - radiusY * cosf (angle);
  71191. if (rotationOfEllipse != 0)
  71192. rotation.transformPoint (x, y);
  71193. lineTo (x, y);
  71194. angle -= ellipseAngularIncrement;
  71195. }
  71196. }
  71197. float x = centreX + radiusX * sinf (toRadians);
  71198. float y = centreY - radiusY * cosf (toRadians);
  71199. if (rotationOfEllipse != 0)
  71200. rotation.transformPoint (x, y);
  71201. lineTo (x, y);
  71202. }
  71203. }
  71204. void Path::addPieSegment (const float x, const float y,
  71205. const float width, const float height,
  71206. const float fromRadians,
  71207. const float toRadians,
  71208. const float innerCircleProportionalSize)
  71209. {
  71210. float hw = width * 0.5f;
  71211. float hh = height * 0.5f;
  71212. const float centreX = x + hw;
  71213. const float centreY = y + hh;
  71214. startNewSubPath (centreX + hw * sinf (fromRadians),
  71215. centreY - hh * cosf (fromRadians));
  71216. addArc (x, y, width, height, fromRadians, toRadians);
  71217. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71218. {
  71219. closeSubPath();
  71220. if (innerCircleProportionalSize > 0)
  71221. {
  71222. hw *= innerCircleProportionalSize;
  71223. hh *= innerCircleProportionalSize;
  71224. startNewSubPath (centreX + hw * sinf (toRadians),
  71225. centreY - hh * cosf (toRadians));
  71226. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71227. toRadians, fromRadians);
  71228. }
  71229. }
  71230. else
  71231. {
  71232. if (innerCircleProportionalSize > 0)
  71233. {
  71234. hw *= innerCircleProportionalSize;
  71235. hh *= innerCircleProportionalSize;
  71236. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71237. toRadians, fromRadians);
  71238. }
  71239. else
  71240. {
  71241. lineTo (centreX, centreY);
  71242. }
  71243. }
  71244. closeSubPath();
  71245. }
  71246. static void perpendicularOffset (const float x1, const float y1,
  71247. const float x2, const float y2,
  71248. const float offsetX, const float offsetY,
  71249. float& resultX, float& resultY) throw()
  71250. {
  71251. const float dx = x2 - x1;
  71252. const float dy = y2 - y1;
  71253. const float len = juce_hypotf (dx, dy);
  71254. if (len == 0)
  71255. {
  71256. resultX = x1;
  71257. resultY = y1;
  71258. }
  71259. else
  71260. {
  71261. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71262. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71263. }
  71264. }
  71265. void Path::addLineSegment (const float startX, const float startY,
  71266. const float endX, const float endY,
  71267. float lineThickness) throw()
  71268. {
  71269. lineThickness *= 0.5f;
  71270. float x, y;
  71271. perpendicularOffset (startX, startY, endX, endY,
  71272. 0, lineThickness, x, y);
  71273. startNewSubPath (x, y);
  71274. perpendicularOffset (startX, startY, endX, endY,
  71275. 0, -lineThickness, x, y);
  71276. lineTo (x, y);
  71277. perpendicularOffset (endX, endY, startX, startY,
  71278. 0, lineThickness, x, y);
  71279. lineTo (x, y);
  71280. perpendicularOffset (endX, endY, startX, startY,
  71281. 0, -lineThickness, x, y);
  71282. lineTo (x, y);
  71283. closeSubPath();
  71284. }
  71285. void Path::addArrow (const float startX, const float startY,
  71286. const float endX, const float endY,
  71287. float lineThickness,
  71288. float arrowheadWidth,
  71289. float arrowheadLength) throw()
  71290. {
  71291. lineThickness *= 0.5f;
  71292. arrowheadWidth *= 0.5f;
  71293. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71294. startY - endY));
  71295. float x, y;
  71296. perpendicularOffset (startX, startY, endX, endY,
  71297. 0, lineThickness, x, y);
  71298. startNewSubPath (x, y);
  71299. perpendicularOffset (startX, startY, endX, endY,
  71300. 0, -lineThickness, x, y);
  71301. lineTo (x, y);
  71302. perpendicularOffset (endX, endY, startX, startY,
  71303. arrowheadLength, lineThickness, x, y);
  71304. lineTo (x, y);
  71305. perpendicularOffset (endX, endY, startX, startY,
  71306. arrowheadLength, arrowheadWidth, x, y);
  71307. lineTo (x, y);
  71308. perpendicularOffset (endX, endY, startX, startY,
  71309. 0, 0, x, y);
  71310. lineTo (x, y);
  71311. perpendicularOffset (endX, endY, startX, startY,
  71312. arrowheadLength, -arrowheadWidth, x, y);
  71313. lineTo (x, y);
  71314. perpendicularOffset (endX, endY, startX, startY,
  71315. arrowheadLength, -lineThickness, x, y);
  71316. lineTo (x, y);
  71317. closeSubPath();
  71318. }
  71319. void Path::addStar (const float centreX,
  71320. const float centreY,
  71321. const int numberOfPoints,
  71322. const float innerRadius,
  71323. const float outerRadius,
  71324. const float startAngle)
  71325. {
  71326. jassert (numberOfPoints > 1); // this would be silly.
  71327. if (numberOfPoints > 1)
  71328. {
  71329. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71330. for (int i = 0; i < numberOfPoints; ++i)
  71331. {
  71332. float angle = startAngle + i * angleBetweenPoints;
  71333. const float x = centreX + outerRadius * sinf (angle);
  71334. const float y = centreY - outerRadius * cosf (angle);
  71335. if (i == 0)
  71336. startNewSubPath (x, y);
  71337. else
  71338. lineTo (x, y);
  71339. angle += angleBetweenPoints * 0.5f;
  71340. lineTo (centreX + innerRadius * sinf (angle),
  71341. centreY - innerRadius * cosf (angle));
  71342. }
  71343. closeSubPath();
  71344. }
  71345. }
  71346. void Path::addBubble (float x, float y,
  71347. float w, float h,
  71348. float cs,
  71349. float tipX,
  71350. float tipY,
  71351. int whichSide,
  71352. float arrowPos,
  71353. float arrowWidth)
  71354. {
  71355. if (w > 1.0f && h > 1.0f)
  71356. {
  71357. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71358. const float cs2 = 2.0f * cs;
  71359. startNewSubPath (x + cs, y);
  71360. if (whichSide == 0)
  71361. {
  71362. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71363. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71364. lineTo (arrowX1, y);
  71365. lineTo (tipX, tipY);
  71366. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71367. }
  71368. lineTo (x + w - cs, y);
  71369. if (cs > 0.0f)
  71370. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71371. if (whichSide == 3)
  71372. {
  71373. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71374. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71375. lineTo (x + w, arrowY1);
  71376. lineTo (tipX, tipY);
  71377. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71378. }
  71379. lineTo (x + w, y + h - cs);
  71380. if (cs > 0.0f)
  71381. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71382. if (whichSide == 2)
  71383. {
  71384. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71385. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71386. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71387. lineTo (tipX, tipY);
  71388. lineTo (arrowX1, y + h);
  71389. }
  71390. lineTo (x + cs, y + h);
  71391. if (cs > 0.0f)
  71392. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71393. if (whichSide == 1)
  71394. {
  71395. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71396. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71397. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71398. lineTo (tipX, tipY);
  71399. lineTo (x, arrowY1);
  71400. }
  71401. lineTo (x, y + cs);
  71402. if (cs > 0.0f)
  71403. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71404. closeSubPath();
  71405. }
  71406. }
  71407. void Path::addPath (const Path& other) throw()
  71408. {
  71409. int i = 0;
  71410. while (i < other.numElements)
  71411. {
  71412. const float type = other.data.elements [i++];
  71413. if (type == moveMarker)
  71414. {
  71415. startNewSubPath (other.data.elements [i],
  71416. other.data.elements [i + 1]);
  71417. i += 2;
  71418. }
  71419. else if (type == lineMarker)
  71420. {
  71421. lineTo (other.data.elements [i],
  71422. other.data.elements [i + 1]);
  71423. i += 2;
  71424. }
  71425. else if (type == quadMarker)
  71426. {
  71427. quadraticTo (other.data.elements [i],
  71428. other.data.elements [i + 1],
  71429. other.data.elements [i + 2],
  71430. other.data.elements [i + 3]);
  71431. i += 4;
  71432. }
  71433. else if (type == cubicMarker)
  71434. {
  71435. cubicTo (other.data.elements [i],
  71436. other.data.elements [i + 1],
  71437. other.data.elements [i + 2],
  71438. other.data.elements [i + 3],
  71439. other.data.elements [i + 4],
  71440. other.data.elements [i + 5]);
  71441. i += 6;
  71442. }
  71443. else if (type == closeSubPathMarker)
  71444. {
  71445. closeSubPath();
  71446. }
  71447. else
  71448. {
  71449. // something's gone wrong with the element list!
  71450. jassertfalse
  71451. }
  71452. }
  71453. }
  71454. void Path::addPath (const Path& other,
  71455. const AffineTransform& transformToApply) throw()
  71456. {
  71457. int i = 0;
  71458. while (i < other.numElements)
  71459. {
  71460. const float type = other.data.elements [i++];
  71461. if (type == closeSubPathMarker)
  71462. {
  71463. closeSubPath();
  71464. }
  71465. else
  71466. {
  71467. float x = other.data.elements [i++];
  71468. float y = other.data.elements [i++];
  71469. transformToApply.transformPoint (x, y);
  71470. if (type == moveMarker)
  71471. {
  71472. startNewSubPath (x, y);
  71473. }
  71474. else if (type == lineMarker)
  71475. {
  71476. lineTo (x, y);
  71477. }
  71478. else if (type == quadMarker)
  71479. {
  71480. float x2 = other.data.elements [i++];
  71481. float y2 = other.data.elements [i++];
  71482. transformToApply.transformPoint (x2, y2);
  71483. quadraticTo (x, y, x2, y2);
  71484. }
  71485. else if (type == cubicMarker)
  71486. {
  71487. float x2 = other.data.elements [i++];
  71488. float y2 = other.data.elements [i++];
  71489. float x3 = other.data.elements [i++];
  71490. float y3 = other.data.elements [i++];
  71491. transformToApply.transformPoint (x2, y2);
  71492. transformToApply.transformPoint (x3, y3);
  71493. cubicTo (x, y, x2, y2, x3, y3);
  71494. }
  71495. else
  71496. {
  71497. // something's gone wrong with the element list!
  71498. jassertfalse
  71499. }
  71500. }
  71501. }
  71502. }
  71503. void Path::applyTransform (const AffineTransform& transform) throw()
  71504. {
  71505. int i = 0;
  71506. pathYMin = pathXMin = 0;
  71507. pathYMax = pathXMax = 0;
  71508. bool setMaxMin = false;
  71509. while (i < numElements)
  71510. {
  71511. const float type = data.elements [i++];
  71512. if (type == moveMarker)
  71513. {
  71514. transform.transformPoint (data.elements [i],
  71515. data.elements [i + 1]);
  71516. if (setMaxMin)
  71517. {
  71518. pathXMin = jmin (pathXMin, data.elements [i]);
  71519. pathXMax = jmax (pathXMax, data.elements [i]);
  71520. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71521. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71522. }
  71523. else
  71524. {
  71525. pathXMin = pathXMax = data.elements [i];
  71526. pathYMin = pathYMax = data.elements [i + 1];
  71527. setMaxMin = true;
  71528. }
  71529. i += 2;
  71530. }
  71531. else if (type == lineMarker)
  71532. {
  71533. transform.transformPoint (data.elements [i],
  71534. data.elements [i + 1]);
  71535. pathXMin = jmin (pathXMin, data.elements [i]);
  71536. pathXMax = jmax (pathXMax, data.elements [i]);
  71537. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71538. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71539. i += 2;
  71540. }
  71541. else if (type == quadMarker)
  71542. {
  71543. transform.transformPoint (data.elements [i],
  71544. data.elements [i + 1]);
  71545. transform.transformPoint (data.elements [i + 2],
  71546. data.elements [i + 3]);
  71547. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71548. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71549. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71550. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71551. i += 4;
  71552. }
  71553. else if (type == cubicMarker)
  71554. {
  71555. transform.transformPoint (data.elements [i],
  71556. data.elements [i + 1]);
  71557. transform.transformPoint (data.elements [i + 2],
  71558. data.elements [i + 3]);
  71559. transform.transformPoint (data.elements [i + 4],
  71560. data.elements [i + 5]);
  71561. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71562. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71563. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71564. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71565. i += 6;
  71566. }
  71567. }
  71568. }
  71569. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71570. const float w, const float h,
  71571. const bool preserveProportions,
  71572. const Justification& justification) const throw()
  71573. {
  71574. Rectangle<float> bounds (getBounds());
  71575. if (preserveProportions)
  71576. {
  71577. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71578. return AffineTransform::identity;
  71579. float newW, newH;
  71580. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71581. if (srcRatio > h / w)
  71582. {
  71583. newW = h / srcRatio;
  71584. newH = h;
  71585. }
  71586. else
  71587. {
  71588. newW = w;
  71589. newH = w * srcRatio;
  71590. }
  71591. float newXCentre = x;
  71592. float newYCentre = y;
  71593. if (justification.testFlags (Justification::left))
  71594. newXCentre += newW * 0.5f;
  71595. else if (justification.testFlags (Justification::right))
  71596. newXCentre += w - newW * 0.5f;
  71597. else
  71598. newXCentre += w * 0.5f;
  71599. if (justification.testFlags (Justification::top))
  71600. newYCentre += newH * 0.5f;
  71601. else if (justification.testFlags (Justification::bottom))
  71602. newYCentre += h - newH * 0.5f;
  71603. else
  71604. newYCentre += h * 0.5f;
  71605. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71606. bounds.getHeight() * -0.5f - bounds.getY())
  71607. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71608. .translated (newXCentre, newYCentre);
  71609. }
  71610. else
  71611. {
  71612. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71613. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71614. .translated (x, y);
  71615. }
  71616. }
  71617. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  71618. {
  71619. if (x <= pathXMin || x >= pathXMax
  71620. || y <= pathYMin || y >= pathYMax)
  71621. return false;
  71622. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71623. int positiveCrossings = 0;
  71624. int negativeCrossings = 0;
  71625. while (i.next())
  71626. {
  71627. if ((i.y1 <= y && i.y2 > y)
  71628. || (i.y2 <= y && i.y1 > y))
  71629. {
  71630. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71631. if (intersectX <= x)
  71632. {
  71633. if (i.y1 < i.y2)
  71634. ++positiveCrossings;
  71635. else
  71636. ++negativeCrossings;
  71637. }
  71638. }
  71639. }
  71640. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71641. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71642. }
  71643. bool Path::intersectsLine (const float x1, const float y1,
  71644. const float x2, const float y2,
  71645. const float tolerence) throw()
  71646. {
  71647. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71648. const Line line1 (x1, y1, x2, y2);
  71649. while (i.next())
  71650. {
  71651. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71652. float ix, iy;
  71653. if (line1.intersects (line2, ix, iy))
  71654. return true;
  71655. }
  71656. return false;
  71657. }
  71658. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  71659. {
  71660. if (cornerRadius <= 0.01f)
  71661. return *this;
  71662. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71663. int n = 0;
  71664. bool lastWasLine = false, firstWasLine = false;
  71665. Path p;
  71666. while (n < numElements)
  71667. {
  71668. const float type = data.elements [n++];
  71669. if (type == moveMarker)
  71670. {
  71671. indexOfPathStart = p.numElements;
  71672. indexOfPathStartThis = n - 1;
  71673. const float x = data.elements [n++];
  71674. const float y = data.elements [n++];
  71675. p.startNewSubPath (x, y);
  71676. lastWasLine = false;
  71677. firstWasLine = (data.elements [n] == lineMarker);
  71678. }
  71679. else if (type == lineMarker || type == closeSubPathMarker)
  71680. {
  71681. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71682. if (type == lineMarker)
  71683. {
  71684. endX = data.elements [n++];
  71685. endY = data.elements [n++];
  71686. if (n > 8)
  71687. {
  71688. startX = data.elements [n - 8];
  71689. startY = data.elements [n - 7];
  71690. joinX = data.elements [n - 5];
  71691. joinY = data.elements [n - 4];
  71692. }
  71693. }
  71694. else
  71695. {
  71696. endX = data.elements [indexOfPathStartThis + 1];
  71697. endY = data.elements [indexOfPathStartThis + 2];
  71698. if (n > 6)
  71699. {
  71700. startX = data.elements [n - 6];
  71701. startY = data.elements [n - 5];
  71702. joinX = data.elements [n - 3];
  71703. joinY = data.elements [n - 2];
  71704. }
  71705. }
  71706. if (lastWasLine)
  71707. {
  71708. const double len1 = juce_hypot (startX - joinX,
  71709. startY - joinY);
  71710. if (len1 > 0)
  71711. {
  71712. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71713. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71714. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71715. }
  71716. const double len2 = juce_hypot (endX - joinX,
  71717. endY - joinY);
  71718. if (len2 > 0)
  71719. {
  71720. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71721. p.quadraticTo (joinX, joinY,
  71722. (float) (joinX + (endX - joinX) * propNeeded),
  71723. (float) (joinY + (endY - joinY) * propNeeded));
  71724. }
  71725. p.lineTo (endX, endY);
  71726. }
  71727. else if (type == lineMarker)
  71728. {
  71729. p.lineTo (endX, endY);
  71730. lastWasLine = true;
  71731. }
  71732. if (type == closeSubPathMarker)
  71733. {
  71734. if (firstWasLine)
  71735. {
  71736. startX = data.elements [n - 3];
  71737. startY = data.elements [n - 2];
  71738. joinX = endX;
  71739. joinY = endY;
  71740. endX = data.elements [indexOfPathStartThis + 4];
  71741. endY = data.elements [indexOfPathStartThis + 5];
  71742. const double len1 = juce_hypot (startX - joinX,
  71743. startY - joinY);
  71744. if (len1 > 0)
  71745. {
  71746. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71747. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71748. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71749. }
  71750. const double len2 = juce_hypot (endX - joinX,
  71751. endY - joinY);
  71752. if (len2 > 0)
  71753. {
  71754. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71755. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71756. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71757. p.quadraticTo (joinX, joinY, endX, endY);
  71758. p.data.elements [indexOfPathStart + 1] = endX;
  71759. p.data.elements [indexOfPathStart + 2] = endY;
  71760. }
  71761. }
  71762. p.closeSubPath();
  71763. }
  71764. }
  71765. else if (type == quadMarker)
  71766. {
  71767. lastWasLine = false;
  71768. const float x1 = data.elements [n++];
  71769. const float y1 = data.elements [n++];
  71770. const float x2 = data.elements [n++];
  71771. const float y2 = data.elements [n++];
  71772. p.quadraticTo (x1, y1, x2, y2);
  71773. }
  71774. else if (type == cubicMarker)
  71775. {
  71776. lastWasLine = false;
  71777. const float x1 = data.elements [n++];
  71778. const float y1 = data.elements [n++];
  71779. const float x2 = data.elements [n++];
  71780. const float y2 = data.elements [n++];
  71781. const float x3 = data.elements [n++];
  71782. const float y3 = data.elements [n++];
  71783. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71784. }
  71785. }
  71786. return p;
  71787. }
  71788. void Path::loadPathFromStream (InputStream& source)
  71789. {
  71790. while (! source.isExhausted())
  71791. {
  71792. switch (source.readByte())
  71793. {
  71794. case 'm':
  71795. {
  71796. const float x = source.readFloat();
  71797. const float y = source.readFloat();
  71798. startNewSubPath (x, y);
  71799. break;
  71800. }
  71801. case 'l':
  71802. {
  71803. const float x = source.readFloat();
  71804. const float y = source.readFloat();
  71805. lineTo (x, y);
  71806. break;
  71807. }
  71808. case 'q':
  71809. {
  71810. const float x1 = source.readFloat();
  71811. const float y1 = source.readFloat();
  71812. const float x2 = source.readFloat();
  71813. const float y2 = source.readFloat();
  71814. quadraticTo (x1, y1, x2, y2);
  71815. break;
  71816. }
  71817. case 'b':
  71818. {
  71819. const float x1 = source.readFloat();
  71820. const float y1 = source.readFloat();
  71821. const float x2 = source.readFloat();
  71822. const float y2 = source.readFloat();
  71823. const float x3 = source.readFloat();
  71824. const float y3 = source.readFloat();
  71825. cubicTo (x1, y1, x2, y2, x3, y3);
  71826. break;
  71827. }
  71828. case 'c':
  71829. closeSubPath();
  71830. break;
  71831. case 'n':
  71832. useNonZeroWinding = true;
  71833. break;
  71834. case 'z':
  71835. useNonZeroWinding = false;
  71836. break;
  71837. case 'e':
  71838. return; // end of path marker
  71839. default:
  71840. jassertfalse // illegal char in the stream
  71841. break;
  71842. }
  71843. }
  71844. }
  71845. void Path::loadPathFromData (const unsigned char* const data,
  71846. const int numberOfBytes) throw()
  71847. {
  71848. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  71849. loadPathFromStream (in);
  71850. }
  71851. void Path::writePathToStream (OutputStream& dest) const
  71852. {
  71853. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  71854. int i = 0;
  71855. while (i < numElements)
  71856. {
  71857. const float type = data.elements [i++];
  71858. if (type == moveMarker)
  71859. {
  71860. dest.writeByte ('m');
  71861. dest.writeFloat (data.elements [i++]);
  71862. dest.writeFloat (data.elements [i++]);
  71863. }
  71864. else if (type == lineMarker)
  71865. {
  71866. dest.writeByte ('l');
  71867. dest.writeFloat (data.elements [i++]);
  71868. dest.writeFloat (data.elements [i++]);
  71869. }
  71870. else if (type == quadMarker)
  71871. {
  71872. dest.writeByte ('q');
  71873. dest.writeFloat (data.elements [i++]);
  71874. dest.writeFloat (data.elements [i++]);
  71875. dest.writeFloat (data.elements [i++]);
  71876. dest.writeFloat (data.elements [i++]);
  71877. }
  71878. else if (type == cubicMarker)
  71879. {
  71880. dest.writeByte ('b');
  71881. dest.writeFloat (data.elements [i++]);
  71882. dest.writeFloat (data.elements [i++]);
  71883. dest.writeFloat (data.elements [i++]);
  71884. dest.writeFloat (data.elements [i++]);
  71885. dest.writeFloat (data.elements [i++]);
  71886. dest.writeFloat (data.elements [i++]);
  71887. }
  71888. else if (type == closeSubPathMarker)
  71889. {
  71890. dest.writeByte ('c');
  71891. }
  71892. }
  71893. dest.writeByte ('e'); // marks the end-of-path
  71894. }
  71895. const String Path::toString() const
  71896. {
  71897. MemoryOutputStream s (2048, 2048);
  71898. if (! useNonZeroWinding)
  71899. s << "a ";
  71900. int i = 0;
  71901. float lastMarker = 0.0f;
  71902. while (i < numElements)
  71903. {
  71904. const float marker = data.elements [i++];
  71905. char markerChar = 0;
  71906. int numCoords = 0;
  71907. if (marker == moveMarker)
  71908. {
  71909. markerChar = 'm';
  71910. numCoords = 2;
  71911. }
  71912. else if (marker == lineMarker)
  71913. {
  71914. markerChar = 'l';
  71915. numCoords = 2;
  71916. }
  71917. else if (marker == quadMarker)
  71918. {
  71919. markerChar = 'q';
  71920. numCoords = 4;
  71921. }
  71922. else if (marker == cubicMarker)
  71923. {
  71924. markerChar = 'c';
  71925. numCoords = 6;
  71926. }
  71927. else
  71928. {
  71929. jassert (marker == closeSubPathMarker);
  71930. markerChar = 'z';
  71931. }
  71932. if (marker != lastMarker)
  71933. {
  71934. s << markerChar << ' ';
  71935. lastMarker = marker;
  71936. }
  71937. while (--numCoords >= 0 && i < numElements)
  71938. {
  71939. String n (data.elements [i++], 3);
  71940. if (n.endsWithChar (T('0')))
  71941. {
  71942. do
  71943. {
  71944. n = n.dropLastCharacters (1);
  71945. } while (n.endsWithChar (T('0')));
  71946. if (n.endsWithChar (T('.')))
  71947. n = n.dropLastCharacters (1);
  71948. }
  71949. s << n << ' ';
  71950. }
  71951. }
  71952. const char* const result = (const char*) s.getData();
  71953. size_t len = s.getDataSize();
  71954. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  71955. --len;
  71956. return String (result, len);
  71957. }
  71958. static const String nextToken (const tchar*& t)
  71959. {
  71960. while (CharacterFunctions::isWhitespace (*t))
  71961. ++t;
  71962. const tchar* const start = t;
  71963. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  71964. ++t;
  71965. const int length = (int) (t - start);
  71966. while (CharacterFunctions::isWhitespace (*t))
  71967. ++t;
  71968. return String (start, length);
  71969. }
  71970. void Path::restoreFromString (const String& stringVersion)
  71971. {
  71972. clear();
  71973. setUsingNonZeroWinding (true);
  71974. const tchar* t = stringVersion;
  71975. tchar marker = T('m');
  71976. int numValues = 2;
  71977. float values [6];
  71978. while (*t != 0)
  71979. {
  71980. const String token (nextToken (t));
  71981. const tchar firstChar = token[0];
  71982. int startNum = 0;
  71983. if (firstChar == T('m') || firstChar == T('l'))
  71984. {
  71985. marker = firstChar;
  71986. numValues = 2;
  71987. }
  71988. else if (firstChar == T('q'))
  71989. {
  71990. marker = firstChar;
  71991. numValues = 4;
  71992. }
  71993. else if (firstChar == T('c'))
  71994. {
  71995. marker = firstChar;
  71996. numValues = 6;
  71997. }
  71998. else if (firstChar == T('z'))
  71999. {
  72000. marker = firstChar;
  72001. numValues = 0;
  72002. }
  72003. else if (firstChar == T('a'))
  72004. {
  72005. setUsingNonZeroWinding (false);
  72006. continue;
  72007. }
  72008. else
  72009. {
  72010. ++startNum;
  72011. values [0] = token.getFloatValue();
  72012. }
  72013. for (int i = startNum; i < numValues; ++i)
  72014. values [i] = nextToken (t).getFloatValue();
  72015. switch (marker)
  72016. {
  72017. case T('m'):
  72018. startNewSubPath (values[0], values[1]);
  72019. break;
  72020. case T('l'):
  72021. lineTo (values[0], values[1]);
  72022. break;
  72023. case T('q'):
  72024. quadraticTo (values[0], values[1],
  72025. values[2], values[3]);
  72026. break;
  72027. case T('c'):
  72028. cubicTo (values[0], values[1],
  72029. values[2], values[3],
  72030. values[4], values[5]);
  72031. break;
  72032. case T('z'):
  72033. closeSubPath();
  72034. break;
  72035. default:
  72036. jassertfalse // illegal string format?
  72037. break;
  72038. }
  72039. }
  72040. }
  72041. Path::Iterator::Iterator (const Path& path_)
  72042. : path (path_),
  72043. index (0)
  72044. {
  72045. }
  72046. Path::Iterator::~Iterator()
  72047. {
  72048. }
  72049. bool Path::Iterator::next()
  72050. {
  72051. const float* const elements = path.data.elements;
  72052. if (index < path.numElements)
  72053. {
  72054. const float type = elements [index++];
  72055. if (type == moveMarker)
  72056. {
  72057. elementType = startNewSubPath;
  72058. x1 = elements [index++];
  72059. y1 = elements [index++];
  72060. }
  72061. else if (type == lineMarker)
  72062. {
  72063. elementType = lineTo;
  72064. x1 = elements [index++];
  72065. y1 = elements [index++];
  72066. }
  72067. else if (type == quadMarker)
  72068. {
  72069. elementType = quadraticTo;
  72070. x1 = elements [index++];
  72071. y1 = elements [index++];
  72072. x2 = elements [index++];
  72073. y2 = elements [index++];
  72074. }
  72075. else if (type == cubicMarker)
  72076. {
  72077. elementType = cubicTo;
  72078. x1 = elements [index++];
  72079. y1 = elements [index++];
  72080. x2 = elements [index++];
  72081. y2 = elements [index++];
  72082. x3 = elements [index++];
  72083. y3 = elements [index++];
  72084. }
  72085. else if (type == closeSubPathMarker)
  72086. {
  72087. elementType = closePath;
  72088. }
  72089. return true;
  72090. }
  72091. return false;
  72092. }
  72093. END_JUCE_NAMESPACE
  72094. /*** End of inlined file: juce_Path.cpp ***/
  72095. /*** Start of inlined file: juce_PathIterator.cpp ***/
  72096. BEGIN_JUCE_NAMESPACE
  72097. #if JUCE_MSVC
  72098. #pragma optimize ("t", on)
  72099. #endif
  72100. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72101. const AffineTransform& transform_,
  72102. float tolerence_) throw()
  72103. : x2 (0),
  72104. y2 (0),
  72105. closesSubPath (false),
  72106. subPathIndex (-1),
  72107. path (path_),
  72108. transform (transform_),
  72109. points (path_.data.elements),
  72110. tolerence (tolerence_ * tolerence_),
  72111. subPathCloseX (0),
  72112. subPathCloseY (0),
  72113. stackBase (32),
  72114. index (0),
  72115. stackSize (32)
  72116. {
  72117. isIdentityTransform = transform.isIdentity();
  72118. stackPos = stackBase;
  72119. }
  72120. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72121. {
  72122. }
  72123. bool PathFlatteningIterator::next() throw()
  72124. {
  72125. x1 = x2;
  72126. y1 = y2;
  72127. float x3 = 0;
  72128. float y3 = 0;
  72129. float x4 = 0;
  72130. float y4 = 0;
  72131. float type;
  72132. for (;;)
  72133. {
  72134. if (stackPos == stackBase)
  72135. {
  72136. if (index >= path.numElements)
  72137. {
  72138. return false;
  72139. }
  72140. else
  72141. {
  72142. type = points [index++];
  72143. if (type != Path::closeSubPathMarker)
  72144. {
  72145. x2 = points [index++];
  72146. y2 = points [index++];
  72147. if (! isIdentityTransform)
  72148. transform.transformPoint (x2, y2);
  72149. if (type == Path::quadMarker)
  72150. {
  72151. x3 = points [index++];
  72152. y3 = points [index++];
  72153. if (! isIdentityTransform)
  72154. transform.transformPoint (x3, y3);
  72155. }
  72156. else if (type == Path::cubicMarker)
  72157. {
  72158. x3 = points [index++];
  72159. y3 = points [index++];
  72160. x4 = points [index++];
  72161. y4 = points [index++];
  72162. if (! isIdentityTransform)
  72163. {
  72164. transform.transformPoint (x3, y3);
  72165. transform.transformPoint (x4, y4);
  72166. }
  72167. }
  72168. }
  72169. }
  72170. }
  72171. else
  72172. {
  72173. type = *--stackPos;
  72174. if (type != Path::closeSubPathMarker)
  72175. {
  72176. x2 = *--stackPos;
  72177. y2 = *--stackPos;
  72178. if (type == Path::quadMarker)
  72179. {
  72180. x3 = *--stackPos;
  72181. y3 = *--stackPos;
  72182. }
  72183. else if (type == Path::cubicMarker)
  72184. {
  72185. x3 = *--stackPos;
  72186. y3 = *--stackPos;
  72187. x4 = *--stackPos;
  72188. y4 = *--stackPos;
  72189. }
  72190. }
  72191. }
  72192. if (type == Path::lineMarker)
  72193. {
  72194. ++subPathIndex;
  72195. closesSubPath = (stackPos == stackBase)
  72196. && (index < path.numElements)
  72197. && (points [index] == Path::closeSubPathMarker)
  72198. && x2 == subPathCloseX
  72199. && y2 == subPathCloseY;
  72200. return true;
  72201. }
  72202. else if (type == Path::quadMarker)
  72203. {
  72204. const int offset = (int) (stackPos - stackBase);
  72205. if (offset >= stackSize - 10)
  72206. {
  72207. stackSize <<= 1;
  72208. stackBase.realloc (stackSize);
  72209. stackPos = stackBase + offset;
  72210. }
  72211. const float dx1 = x1 - x2;
  72212. const float dy1 = y1 - y2;
  72213. const float dx2 = x2 - x3;
  72214. const float dy2 = y2 - y3;
  72215. const float m1x = (x1 + x2) * 0.5f;
  72216. const float m1y = (y1 + y2) * 0.5f;
  72217. const float m2x = (x2 + x3) * 0.5f;
  72218. const float m2y = (y2 + y3) * 0.5f;
  72219. const float m3x = (m1x + m2x) * 0.5f;
  72220. const float m3y = (m1y + m2y) * 0.5f;
  72221. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72222. {
  72223. *stackPos++ = y3;
  72224. *stackPos++ = x3;
  72225. *stackPos++ = m2y;
  72226. *stackPos++ = m2x;
  72227. *stackPos++ = Path::quadMarker;
  72228. *stackPos++ = m3y;
  72229. *stackPos++ = m3x;
  72230. *stackPos++ = m1y;
  72231. *stackPos++ = m1x;
  72232. *stackPos++ = Path::quadMarker;
  72233. }
  72234. else
  72235. {
  72236. *stackPos++ = y3;
  72237. *stackPos++ = x3;
  72238. *stackPos++ = Path::lineMarker;
  72239. *stackPos++ = m3y;
  72240. *stackPos++ = m3x;
  72241. *stackPos++ = Path::lineMarker;
  72242. }
  72243. jassert (stackPos < stackBase + stackSize);
  72244. }
  72245. else if (type == Path::cubicMarker)
  72246. {
  72247. const int offset = (int) (stackPos - stackBase);
  72248. if (offset >= stackSize - 16)
  72249. {
  72250. stackSize <<= 1;
  72251. stackBase.realloc (stackSize);
  72252. stackPos = stackBase + offset;
  72253. }
  72254. const float dx1 = x1 - x2;
  72255. const float dy1 = y1 - y2;
  72256. const float dx2 = x2 - x3;
  72257. const float dy2 = y2 - y3;
  72258. const float dx3 = x3 - x4;
  72259. const float dy3 = y3 - y4;
  72260. const float m1x = (x1 + x2) * 0.5f;
  72261. const float m1y = (y1 + y2) * 0.5f;
  72262. const float m2x = (x3 + x2) * 0.5f;
  72263. const float m2y = (y3 + y2) * 0.5f;
  72264. const float m3x = (x3 + x4) * 0.5f;
  72265. const float m3y = (y3 + y4) * 0.5f;
  72266. const float m4x = (m1x + m2x) * 0.5f;
  72267. const float m4y = (m1y + m2y) * 0.5f;
  72268. const float m5x = (m3x + m2x) * 0.5f;
  72269. const float m5y = (m3y + m2y) * 0.5f;
  72270. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72271. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72272. {
  72273. *stackPos++ = y4;
  72274. *stackPos++ = x4;
  72275. *stackPos++ = m3y;
  72276. *stackPos++ = m3x;
  72277. *stackPos++ = m5y;
  72278. *stackPos++ = m5x;
  72279. *stackPos++ = Path::cubicMarker;
  72280. *stackPos++ = (m4y + m5y) * 0.5f;
  72281. *stackPos++ = (m4x + m5x) * 0.5f;
  72282. *stackPos++ = m4y;
  72283. *stackPos++ = m4x;
  72284. *stackPos++ = m1y;
  72285. *stackPos++ = m1x;
  72286. *stackPos++ = Path::cubicMarker;
  72287. }
  72288. else
  72289. {
  72290. *stackPos++ = y4;
  72291. *stackPos++ = x4;
  72292. *stackPos++ = Path::lineMarker;
  72293. *stackPos++ = m5y;
  72294. *stackPos++ = m5x;
  72295. *stackPos++ = Path::lineMarker;
  72296. *stackPos++ = m4y;
  72297. *stackPos++ = m4x;
  72298. *stackPos++ = Path::lineMarker;
  72299. }
  72300. }
  72301. else if (type == Path::closeSubPathMarker)
  72302. {
  72303. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72304. {
  72305. x1 = x2;
  72306. y1 = y2;
  72307. x2 = subPathCloseX;
  72308. y2 = subPathCloseY;
  72309. closesSubPath = true;
  72310. return true;
  72311. }
  72312. }
  72313. else
  72314. {
  72315. jassert (type == Path::moveMarker);
  72316. subPathIndex = -1;
  72317. subPathCloseX = x1 = x2;
  72318. subPathCloseY = y1 = y2;
  72319. }
  72320. }
  72321. }
  72322. END_JUCE_NAMESPACE
  72323. /*** End of inlined file: juce_PathIterator.cpp ***/
  72324. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72325. BEGIN_JUCE_NAMESPACE
  72326. PathStrokeType::PathStrokeType (const float strokeThickness,
  72327. const JointStyle jointStyle_,
  72328. const EndCapStyle endStyle_) throw()
  72329. : thickness (strokeThickness),
  72330. jointStyle (jointStyle_),
  72331. endStyle (endStyle_)
  72332. {
  72333. }
  72334. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72335. : thickness (other.thickness),
  72336. jointStyle (other.jointStyle),
  72337. endStyle (other.endStyle)
  72338. {
  72339. }
  72340. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72341. {
  72342. thickness = other.thickness;
  72343. jointStyle = other.jointStyle;
  72344. endStyle = other.endStyle;
  72345. return *this;
  72346. }
  72347. PathStrokeType::~PathStrokeType() throw()
  72348. {
  72349. }
  72350. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72351. {
  72352. return thickness == other.thickness
  72353. && jointStyle == other.jointStyle
  72354. && endStyle == other.endStyle;
  72355. }
  72356. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72357. {
  72358. return ! operator== (other);
  72359. }
  72360. static bool lineIntersection (const float x1, const float y1,
  72361. const float x2, const float y2,
  72362. const float x3, const float y3,
  72363. const float x4, const float y4,
  72364. float& intersectionX,
  72365. float& intersectionY,
  72366. float& distanceBeyondLine1EndSquared) throw()
  72367. {
  72368. if (x2 != x3 || y2 != y3)
  72369. {
  72370. const float dx1 = x2 - x1;
  72371. const float dy1 = y2 - y1;
  72372. const float dx2 = x4 - x3;
  72373. const float dy2 = y4 - y3;
  72374. const float divisor = dx1 * dy2 - dx2 * dy1;
  72375. if (divisor == 0)
  72376. {
  72377. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72378. {
  72379. if (dy1 == 0 && dy2 != 0)
  72380. {
  72381. const float along = (y1 - y3) / dy2;
  72382. intersectionX = x3 + along * dx2;
  72383. intersectionY = y1;
  72384. distanceBeyondLine1EndSquared = intersectionX - x2;
  72385. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72386. if ((x2 > x1) == (intersectionX < x2))
  72387. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72388. return along >= 0 && along <= 1.0f;
  72389. }
  72390. else if (dy2 == 0 && dy1 != 0)
  72391. {
  72392. const float along = (y3 - y1) / dy1;
  72393. intersectionX = x1 + along * dx1;
  72394. intersectionY = y3;
  72395. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72396. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72397. if (along < 1.0f)
  72398. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72399. return along >= 0 && along <= 1.0f;
  72400. }
  72401. else if (dx1 == 0 && dx2 != 0)
  72402. {
  72403. const float along = (x1 - x3) / dx2;
  72404. intersectionX = x1;
  72405. intersectionY = y3 + along * dy2;
  72406. distanceBeyondLine1EndSquared = intersectionY - y2;
  72407. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72408. if ((y2 > y1) == (intersectionY < y2))
  72409. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72410. return along >= 0 && along <= 1.0f;
  72411. }
  72412. else if (dx2 == 0 && dx1 != 0)
  72413. {
  72414. const float along = (x3 - x1) / dx1;
  72415. intersectionX = x3;
  72416. intersectionY = y1 + along * dy1;
  72417. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72418. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72419. if (along < 1.0f)
  72420. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72421. return along >= 0 && along <= 1.0f;
  72422. }
  72423. }
  72424. intersectionX = 0.5f * (x2 + x3);
  72425. intersectionY = 0.5f * (y2 + y3);
  72426. distanceBeyondLine1EndSquared = 0.0f;
  72427. return false;
  72428. }
  72429. else
  72430. {
  72431. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72432. intersectionX = x1 + along1 * dx1;
  72433. intersectionY = y1 + along1 * dy1;
  72434. if (along1 >= 0 && along1 <= 1.0f)
  72435. {
  72436. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72437. if (along2 >= 0 && along2 <= divisor)
  72438. {
  72439. distanceBeyondLine1EndSquared = 0.0f;
  72440. return true;
  72441. }
  72442. }
  72443. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72444. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72445. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72446. if (along1 < 1.0f)
  72447. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72448. return false;
  72449. }
  72450. }
  72451. intersectionX = x2;
  72452. intersectionY = y2;
  72453. distanceBeyondLine1EndSquared = 0.0f;
  72454. return true;
  72455. }
  72456. namespace PathFunctions
  72457. {
  72458. // part of stroke drawing stuff
  72459. static void addEdgeAndJoint (Path& destPath,
  72460. const PathStrokeType::JointStyle style,
  72461. const float maxMiterExtensionSquared, const float width,
  72462. const float x1, const float y1,
  72463. const float x2, const float y2,
  72464. const float x3, const float y3,
  72465. const float x4, const float y4,
  72466. const float midX, const float midY)
  72467. {
  72468. if (style == PathStrokeType::beveled
  72469. || (x3 == x4 && y3 == y4)
  72470. || (x1 == x2 && y1 == y2))
  72471. {
  72472. destPath.lineTo (x2, y2);
  72473. destPath.lineTo (x3, y3);
  72474. }
  72475. else
  72476. {
  72477. float jx, jy, distanceBeyondLine1EndSquared;
  72478. // if they intersect, use this point..
  72479. if (lineIntersection (x1, y1, x2, y2,
  72480. x3, y3, x4, y4,
  72481. jx, jy, distanceBeyondLine1EndSquared))
  72482. {
  72483. destPath.lineTo (jx, jy);
  72484. }
  72485. else
  72486. {
  72487. if (style == PathStrokeType::mitered)
  72488. {
  72489. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72490. && distanceBeyondLine1EndSquared > 0.0f)
  72491. {
  72492. destPath.lineTo (jx, jy);
  72493. }
  72494. else
  72495. {
  72496. // the end sticks out too far, so just use a blunt joint
  72497. destPath.lineTo (x2, y2);
  72498. destPath.lineTo (x3, y3);
  72499. }
  72500. }
  72501. else
  72502. {
  72503. // curved joints
  72504. float angle1 = atan2f (x2 - midX, y2 - midY);
  72505. float angle2 = atan2f (x3 - midX, y3 - midY);
  72506. const float angleIncrement = 0.1f;
  72507. destPath.lineTo (x2, y2);
  72508. if (fabs (angle1 - angle2) > angleIncrement)
  72509. {
  72510. if (angle2 > angle1 + float_Pi
  72511. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72512. {
  72513. if (angle2 > angle1)
  72514. angle2 -= float_Pi * 2.0f;
  72515. jassert (angle1 <= angle2 + float_Pi);
  72516. angle1 -= angleIncrement;
  72517. while (angle1 > angle2)
  72518. {
  72519. destPath.lineTo (midX + width * sinf (angle1),
  72520. midY + width * cosf (angle1));
  72521. angle1 -= angleIncrement;
  72522. }
  72523. }
  72524. else
  72525. {
  72526. if (angle1 > angle2)
  72527. angle1 -= float_Pi * 2.0f;
  72528. jassert (angle1 >= angle2 - float_Pi);
  72529. angle1 += angleIncrement;
  72530. while (angle1 < angle2)
  72531. {
  72532. destPath.lineTo (midX + width * sinf (angle1),
  72533. midY + width * cosf (angle1));
  72534. angle1 += angleIncrement;
  72535. }
  72536. }
  72537. }
  72538. destPath.lineTo (x3, y3);
  72539. }
  72540. }
  72541. }
  72542. }
  72543. static void addLineEnd (Path& destPath,
  72544. const PathStrokeType::EndCapStyle style,
  72545. const float x1, const float y1,
  72546. const float x2, const float y2,
  72547. const float width)
  72548. {
  72549. if (style == PathStrokeType::butt)
  72550. {
  72551. destPath.lineTo (x2, y2);
  72552. }
  72553. else
  72554. {
  72555. float offx1, offy1, offx2, offy2;
  72556. float dx = x2 - x1;
  72557. float dy = y2 - y1;
  72558. const float len = juce_hypotf (dx, dy);
  72559. if (len == 0)
  72560. {
  72561. offx1 = offx2 = x1;
  72562. offy1 = offy2 = y1;
  72563. }
  72564. else
  72565. {
  72566. const float offset = width / len;
  72567. dx *= offset;
  72568. dy *= offset;
  72569. offx1 = x1 + dy;
  72570. offy1 = y1 - dx;
  72571. offx2 = x2 + dy;
  72572. offy2 = y2 - dx;
  72573. }
  72574. if (style == PathStrokeType::square)
  72575. {
  72576. // sqaure ends
  72577. destPath.lineTo (offx1, offy1);
  72578. destPath.lineTo (offx2, offy2);
  72579. destPath.lineTo (x2, y2);
  72580. }
  72581. else
  72582. {
  72583. // rounded ends
  72584. const float midx = (offx1 + offx2) * 0.5f;
  72585. const float midy = (offy1 + offy2) * 0.5f;
  72586. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72587. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72588. midx, midy);
  72589. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72590. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72591. x2, y2);
  72592. }
  72593. }
  72594. }
  72595. struct LineSection
  72596. {
  72597. LineSection() {}
  72598. LineSection (int) {}
  72599. float x1, y1, x2, y2; // original line
  72600. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72601. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72602. };
  72603. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72604. const bool isClosed,
  72605. const float width, const float maxMiterExtensionSquared,
  72606. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72607. {
  72608. jassert (subPath.size() > 0);
  72609. const LineSection& firstLine = subPath.getReference (0);
  72610. float lastX1 = firstLine.lx1;
  72611. float lastY1 = firstLine.ly1;
  72612. float lastX2 = firstLine.lx2;
  72613. float lastY2 = firstLine.ly2;
  72614. if (isClosed)
  72615. {
  72616. destPath.startNewSubPath (lastX1, lastY1);
  72617. }
  72618. else
  72619. {
  72620. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72621. addLineEnd (destPath, endStyle,
  72622. firstLine.rx2, firstLine.ry2,
  72623. lastX1, lastY1,
  72624. width);
  72625. }
  72626. int i;
  72627. for (i = 1; i < subPath.size(); ++i)
  72628. {
  72629. const LineSection& l = subPath.getReference (i);
  72630. addEdgeAndJoint (destPath, jointStyle,
  72631. maxMiterExtensionSquared, width,
  72632. lastX1, lastY1, lastX2, lastY2,
  72633. l.lx1, l.ly1, l.lx2, l.ly2,
  72634. l.x1, l.y1);
  72635. lastX1 = l.lx1;
  72636. lastY1 = l.ly1;
  72637. lastX2 = l.lx2;
  72638. lastY2 = l.ly2;
  72639. }
  72640. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72641. if (isClosed)
  72642. {
  72643. const LineSection& l = subPath.getReference (0);
  72644. addEdgeAndJoint (destPath, jointStyle,
  72645. maxMiterExtensionSquared, width,
  72646. lastX1, lastY1, lastX2, lastY2,
  72647. l.lx1, l.ly1, l.lx2, l.ly2,
  72648. l.x1, l.y1);
  72649. destPath.closeSubPath();
  72650. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72651. }
  72652. else
  72653. {
  72654. destPath.lineTo (lastX2, lastY2);
  72655. addLineEnd (destPath, endStyle,
  72656. lastX2, lastY2,
  72657. lastLine.rx1, lastLine.ry1,
  72658. width);
  72659. }
  72660. lastX1 = lastLine.rx1;
  72661. lastY1 = lastLine.ry1;
  72662. lastX2 = lastLine.rx2;
  72663. lastY2 = lastLine.ry2;
  72664. for (i = subPath.size() - 1; --i >= 0;)
  72665. {
  72666. const LineSection& l = subPath.getReference (i);
  72667. addEdgeAndJoint (destPath, jointStyle,
  72668. maxMiterExtensionSquared, width,
  72669. lastX1, lastY1, lastX2, lastY2,
  72670. l.rx1, l.ry1, l.rx2, l.ry2,
  72671. l.x2, l.y2);
  72672. lastX1 = l.rx1;
  72673. lastY1 = l.ry1;
  72674. lastX2 = l.rx2;
  72675. lastY2 = l.ry2;
  72676. }
  72677. if (isClosed)
  72678. {
  72679. addEdgeAndJoint (destPath, jointStyle,
  72680. maxMiterExtensionSquared, width,
  72681. lastX1, lastY1, lastX2, lastY2,
  72682. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72683. lastLine.x2, lastLine.y2);
  72684. }
  72685. else
  72686. {
  72687. // do the last line
  72688. destPath.lineTo (lastX2, lastY2);
  72689. }
  72690. destPath.closeSubPath();
  72691. }
  72692. }
  72693. void PathStrokeType::createStrokedPath (Path& destPath,
  72694. const Path& source,
  72695. const AffineTransform& transform,
  72696. const float extraAccuracy) const
  72697. {
  72698. if (thickness <= 0)
  72699. {
  72700. destPath.clear();
  72701. return;
  72702. }
  72703. const Path* sourcePath = &source;
  72704. Path temp;
  72705. if (sourcePath == &destPath)
  72706. {
  72707. destPath.swapWithPath (temp);
  72708. sourcePath = &temp;
  72709. }
  72710. else
  72711. {
  72712. destPath.clear();
  72713. }
  72714. destPath.setUsingNonZeroWinding (true);
  72715. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72716. const float width = 0.5f * thickness;
  72717. // Iterate the path, creating a list of the
  72718. // left/right-hand lines along either side of it...
  72719. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72720. using namespace PathFunctions;
  72721. Array <LineSection> subPath;
  72722. LineSection l;
  72723. l.x1 = 0;
  72724. l.y1 = 0;
  72725. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72726. while (it.next())
  72727. {
  72728. if (it.subPathIndex == 0)
  72729. {
  72730. if (subPath.size() > 0)
  72731. {
  72732. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72733. subPath.clearQuick();
  72734. }
  72735. l.x1 = it.x1;
  72736. l.y1 = it.y1;
  72737. }
  72738. l.x2 = it.x2;
  72739. l.y2 = it.y2;
  72740. float dx = l.x2 - l.x1;
  72741. float dy = l.y2 - l.y1;
  72742. const float hypotSquared = dx*dx + dy*dy;
  72743. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72744. {
  72745. const float len = sqrtf (hypotSquared);
  72746. if (len == 0)
  72747. {
  72748. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72749. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72750. }
  72751. else
  72752. {
  72753. const float offset = width / len;
  72754. dx *= offset;
  72755. dy *= offset;
  72756. l.rx2 = l.x1 - dy;
  72757. l.ry2 = l.y1 + dx;
  72758. l.lx1 = l.x1 + dy;
  72759. l.ly1 = l.y1 - dx;
  72760. l.lx2 = l.x2 + dy;
  72761. l.ly2 = l.y2 - dx;
  72762. l.rx1 = l.x2 - dy;
  72763. l.ry1 = l.y2 + dx;
  72764. }
  72765. subPath.add (l);
  72766. if (it.closesSubPath)
  72767. {
  72768. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72769. subPath.clearQuick();
  72770. }
  72771. else
  72772. {
  72773. l.x1 = it.x2;
  72774. l.y1 = it.y2;
  72775. }
  72776. }
  72777. }
  72778. if (subPath.size() > 0)
  72779. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72780. }
  72781. void PathStrokeType::createDashedStroke (Path& destPath,
  72782. const Path& sourcePath,
  72783. const float* dashLengths,
  72784. int numDashLengths,
  72785. const AffineTransform& transform,
  72786. const float extraAccuracy) const
  72787. {
  72788. if (thickness <= 0)
  72789. return;
  72790. // this should really be an even number..
  72791. jassert ((numDashLengths & 1) == 0);
  72792. Path newDestPath;
  72793. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72794. bool first = true;
  72795. int dashNum = 0;
  72796. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72797. float dx = 0.0f, dy = 0.0f;
  72798. for (;;)
  72799. {
  72800. const bool isSolid = ((dashNum & 1) == 0);
  72801. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72802. jassert (dashLen > 0); // must be a positive increment!
  72803. if (dashLen <= 0)
  72804. break;
  72805. pos += dashLen;
  72806. while (pos > lineEndPos)
  72807. {
  72808. if (! it.next())
  72809. {
  72810. if (isSolid && ! first)
  72811. newDestPath.lineTo (it.x2, it.y2);
  72812. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72813. return;
  72814. }
  72815. if (isSolid && ! first)
  72816. newDestPath.lineTo (it.x1, it.y1);
  72817. else
  72818. newDestPath.startNewSubPath (it.x1, it.y1);
  72819. dx = it.x2 - it.x1;
  72820. dy = it.y2 - it.y1;
  72821. lineLen = juce_hypotf (dx, dy);
  72822. lineEndPos += lineLen;
  72823. first = it.closesSubPath;
  72824. }
  72825. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72826. if (isSolid)
  72827. newDestPath.lineTo (it.x1 + dx * alpha,
  72828. it.y1 + dy * alpha);
  72829. else
  72830. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72831. it.y1 + dy * alpha);
  72832. }
  72833. }
  72834. END_JUCE_NAMESPACE
  72835. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72836. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72837. BEGIN_JUCE_NAMESPACE
  72838. PositionedRectangle::PositionedRectangle() throw()
  72839. : x (0.0),
  72840. y (0.0),
  72841. w (0.0),
  72842. h (0.0),
  72843. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72844. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72845. wMode (absoluteSize),
  72846. hMode (absoluteSize)
  72847. {
  72848. }
  72849. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72850. : x (other.x),
  72851. y (other.y),
  72852. w (other.w),
  72853. h (other.h),
  72854. xMode (other.xMode),
  72855. yMode (other.yMode),
  72856. wMode (other.wMode),
  72857. hMode (other.hMode)
  72858. {
  72859. }
  72860. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72861. {
  72862. x = other.x;
  72863. y = other.y;
  72864. w = other.w;
  72865. h = other.h;
  72866. xMode = other.xMode;
  72867. yMode = other.yMode;
  72868. wMode = other.wMode;
  72869. hMode = other.hMode;
  72870. return *this;
  72871. }
  72872. PositionedRectangle::~PositionedRectangle() throw()
  72873. {
  72874. }
  72875. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72876. {
  72877. return x == other.x
  72878. && y == other.y
  72879. && w == other.w
  72880. && h == other.h
  72881. && xMode == other.xMode
  72882. && yMode == other.yMode
  72883. && wMode == other.wMode
  72884. && hMode == other.hMode;
  72885. }
  72886. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72887. {
  72888. return ! operator== (other);
  72889. }
  72890. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72891. {
  72892. StringArray tokens;
  72893. tokens.addTokens (stringVersion, false);
  72894. decodePosString (tokens [0], xMode, x);
  72895. decodePosString (tokens [1], yMode, y);
  72896. decodeSizeString (tokens [2], wMode, w);
  72897. decodeSizeString (tokens [3], hMode, h);
  72898. }
  72899. const String PositionedRectangle::toString() const throw()
  72900. {
  72901. String s;
  72902. s.preallocateStorage (12);
  72903. addPosDescription (s, xMode, x);
  72904. s << T(' ');
  72905. addPosDescription (s, yMode, y);
  72906. s << T(' ');
  72907. addSizeDescription (s, wMode, w);
  72908. s << T(' ');
  72909. addSizeDescription (s, hMode, h);
  72910. return s;
  72911. }
  72912. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72913. {
  72914. jassert (! target.isEmpty());
  72915. double x_, y_, w_, h_;
  72916. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72917. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72918. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  72919. roundToInt (w_), roundToInt (h_));
  72920. }
  72921. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  72922. double& x_, double& y_,
  72923. double& w_, double& h_) const throw()
  72924. {
  72925. jassert (! target.isEmpty());
  72926. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72927. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72928. }
  72929. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  72930. {
  72931. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  72932. }
  72933. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  72934. const Rectangle<int>& target) throw()
  72935. {
  72936. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  72937. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  72938. }
  72939. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  72940. const double newW, const double newH,
  72941. const Rectangle<int>& target) throw()
  72942. {
  72943. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  72944. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  72945. }
  72946. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  72947. {
  72948. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  72949. updateFrom (comp.getBounds(), Rectangle<int>());
  72950. else
  72951. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  72952. }
  72953. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  72954. {
  72955. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72956. }
  72957. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  72958. {
  72959. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  72960. | absoluteFromParentBottomRight
  72961. | absoluteFromParentCentre
  72962. | proportionOfParentSize));
  72963. }
  72964. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  72965. {
  72966. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72967. }
  72968. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  72969. {
  72970. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  72971. | absoluteFromParentBottomRight
  72972. | absoluteFromParentCentre
  72973. | proportionOfParentSize));
  72974. }
  72975. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  72976. {
  72977. return (SizeMode) wMode;
  72978. }
  72979. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  72980. {
  72981. return (SizeMode) hMode;
  72982. }
  72983. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  72984. const PositionMode xMode_,
  72985. const AnchorPoint yAnchor,
  72986. const PositionMode yMode_,
  72987. const SizeMode widthMode,
  72988. const SizeMode heightMode,
  72989. const Rectangle<int>& target) throw()
  72990. {
  72991. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  72992. {
  72993. double tx, tw;
  72994. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  72995. xMode = (uint8) (xAnchor | xMode_);
  72996. wMode = (uint8) widthMode;
  72997. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  72998. }
  72999. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  73000. {
  73001. double ty, th;
  73002. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  73003. yMode = (uint8) (yAnchor | yMode_);
  73004. hMode = (uint8) heightMode;
  73005. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73006. }
  73007. }
  73008. bool PositionedRectangle::isPositionAbsolute() const throw()
  73009. {
  73010. return xMode == absoluteFromParentTopLeft
  73011. && yMode == absoluteFromParentTopLeft
  73012. && wMode == absoluteSize
  73013. && hMode == absoluteSize;
  73014. }
  73015. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73016. {
  73017. if ((mode & proportionOfParentSize) != 0)
  73018. {
  73019. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73020. }
  73021. else
  73022. {
  73023. s << (roundToInt (value * 100.0) / 100.0);
  73024. if ((mode & absoluteFromParentBottomRight) != 0)
  73025. s << T('R');
  73026. else if ((mode & absoluteFromParentCentre) != 0)
  73027. s << T('C');
  73028. }
  73029. if ((mode & anchorAtRightOrBottom) != 0)
  73030. s << T('r');
  73031. else if ((mode & anchorAtCentre) != 0)
  73032. s << T('c');
  73033. }
  73034. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73035. {
  73036. if (mode == proportionalSize)
  73037. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73038. else if (mode == parentSizeMinusAbsolute)
  73039. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73040. else
  73041. s << (roundToInt (value * 100.0) / 100.0);
  73042. }
  73043. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73044. {
  73045. if (s.containsChar (T('r')))
  73046. mode = anchorAtRightOrBottom;
  73047. else if (s.containsChar (T('c')))
  73048. mode = anchorAtCentre;
  73049. else
  73050. mode = anchorAtLeftOrTop;
  73051. if (s.containsChar (T('%')))
  73052. {
  73053. mode |= proportionOfParentSize;
  73054. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73055. }
  73056. else
  73057. {
  73058. if (s.containsChar (T('R')))
  73059. mode |= absoluteFromParentBottomRight;
  73060. else if (s.containsChar (T('C')))
  73061. mode |= absoluteFromParentCentre;
  73062. else
  73063. mode |= absoluteFromParentTopLeft;
  73064. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73065. }
  73066. }
  73067. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73068. {
  73069. if (s.containsChar (T('%')))
  73070. {
  73071. mode = proportionalSize;
  73072. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73073. }
  73074. else if (s.containsChar (T('M')))
  73075. {
  73076. mode = parentSizeMinusAbsolute;
  73077. value = s.getDoubleValue();
  73078. }
  73079. else
  73080. {
  73081. mode = absoluteSize;
  73082. value = s.getDoubleValue();
  73083. }
  73084. }
  73085. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73086. const double x_, const double w_,
  73087. const uint8 xMode_, const uint8 wMode_,
  73088. const int parentPos,
  73089. const int parentSize) const throw()
  73090. {
  73091. if (wMode_ == proportionalSize)
  73092. wOut = roundToInt (w_ * parentSize);
  73093. else if (wMode_ == parentSizeMinusAbsolute)
  73094. wOut = jmax (0, parentSize - roundToInt (w_));
  73095. else
  73096. wOut = roundToInt (w_);
  73097. if ((xMode_ & proportionOfParentSize) != 0)
  73098. xOut = parentPos + x_ * parentSize;
  73099. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73100. xOut = (parentPos + parentSize) - x_;
  73101. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73102. xOut = x_ + (parentPos + parentSize / 2);
  73103. else
  73104. xOut = x_ + parentPos;
  73105. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73106. xOut -= wOut;
  73107. else if ((xMode_ & anchorAtCentre) != 0)
  73108. xOut -= wOut / 2;
  73109. }
  73110. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73111. double x_, const double w_,
  73112. const uint8 xMode_, const uint8 wMode_,
  73113. const int parentPos,
  73114. const int parentSize) const throw()
  73115. {
  73116. if (wMode_ == proportionalSize)
  73117. {
  73118. if (parentSize > 0)
  73119. wOut = w_ / parentSize;
  73120. }
  73121. else if (wMode_ == parentSizeMinusAbsolute)
  73122. wOut = parentSize - w_;
  73123. else
  73124. wOut = w_;
  73125. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73126. x_ += w_;
  73127. else if ((xMode_ & anchorAtCentre) != 0)
  73128. x_ += w_ / 2;
  73129. if ((xMode_ & proportionOfParentSize) != 0)
  73130. {
  73131. if (parentSize > 0)
  73132. xOut = (x_ - parentPos) / parentSize;
  73133. }
  73134. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73135. xOut = (parentPos + parentSize) - x_;
  73136. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73137. xOut = x_ - (parentPos + parentSize / 2);
  73138. else
  73139. xOut = x_ - parentPos;
  73140. }
  73141. END_JUCE_NAMESPACE
  73142. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73143. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73144. BEGIN_JUCE_NAMESPACE
  73145. RectangleList::RectangleList() throw()
  73146. {
  73147. }
  73148. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73149. {
  73150. if (! rect.isEmpty())
  73151. rects.add (rect);
  73152. }
  73153. RectangleList::RectangleList (const RectangleList& other) throw()
  73154. : rects (other.rects)
  73155. {
  73156. }
  73157. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73158. {
  73159. rects = other.rects;
  73160. return *this;
  73161. }
  73162. RectangleList::~RectangleList() throw()
  73163. {
  73164. }
  73165. void RectangleList::clear() throw()
  73166. {
  73167. rects.clearQuick();
  73168. }
  73169. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73170. {
  73171. if (((unsigned int) index) < (unsigned int) rects.size())
  73172. return rects.getReference (index);
  73173. return Rectangle<int>();
  73174. }
  73175. bool RectangleList::isEmpty() const throw()
  73176. {
  73177. return rects.size() == 0;
  73178. }
  73179. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73180. : current (0),
  73181. owner (list),
  73182. index (list.rects.size())
  73183. {
  73184. }
  73185. RectangleList::Iterator::~Iterator() throw()
  73186. {
  73187. }
  73188. bool RectangleList::Iterator::next() throw()
  73189. {
  73190. if (--index >= 0)
  73191. {
  73192. current = & (owner.rects.getReference (index));
  73193. return true;
  73194. }
  73195. return false;
  73196. }
  73197. void RectangleList::add (const Rectangle<int>& rect) throw()
  73198. {
  73199. if (! rect.isEmpty())
  73200. {
  73201. if (rects.size() == 0)
  73202. {
  73203. rects.add (rect);
  73204. }
  73205. else
  73206. {
  73207. bool anyOverlaps = false;
  73208. int i;
  73209. for (i = rects.size(); --i >= 0;)
  73210. {
  73211. Rectangle<int>& ourRect = rects.getReference (i);
  73212. if (rect.intersects (ourRect))
  73213. {
  73214. if (rect.contains (ourRect))
  73215. rects.remove (i);
  73216. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73217. anyOverlaps = true;
  73218. }
  73219. }
  73220. if (anyOverlaps && rects.size() > 0)
  73221. {
  73222. RectangleList r (rect);
  73223. for (i = rects.size(); --i >= 0;)
  73224. {
  73225. const Rectangle<int>& ourRect = rects.getReference (i);
  73226. if (rect.intersects (ourRect))
  73227. {
  73228. r.subtract (ourRect);
  73229. if (r.rects.size() == 0)
  73230. return;
  73231. }
  73232. }
  73233. for (i = r.getNumRectangles(); --i >= 0;)
  73234. rects.add (r.rects.getReference (i));
  73235. }
  73236. else
  73237. {
  73238. rects.add (rect);
  73239. }
  73240. }
  73241. }
  73242. }
  73243. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73244. {
  73245. rects.add (rect);
  73246. }
  73247. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73248. {
  73249. if (rects.size() == 0)
  73250. {
  73251. if (w > 0 && h > 0)
  73252. rects.add (Rectangle<int> (x, y, w, h));
  73253. }
  73254. else
  73255. {
  73256. add (Rectangle<int> (x, y, w, h));
  73257. }
  73258. }
  73259. void RectangleList::add (const RectangleList& other) throw()
  73260. {
  73261. for (int i = 0; i < other.rects.size(); ++i)
  73262. add (other.rects.getReference (i));
  73263. }
  73264. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73265. {
  73266. const int originalNumRects = rects.size();
  73267. if (originalNumRects > 0)
  73268. {
  73269. const int x1 = rect.x;
  73270. const int y1 = rect.y;
  73271. const int x2 = x1 + rect.w;
  73272. const int y2 = y1 + rect.h;
  73273. for (int i = getNumRectangles(); --i >= 0;)
  73274. {
  73275. Rectangle<int>& r = rects.getReference (i);
  73276. const int rx1 = r.x;
  73277. const int ry1 = r.y;
  73278. const int rx2 = rx1 + r.w;
  73279. const int ry2 = ry1 + r.h;
  73280. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73281. {
  73282. if (x1 > rx1 && x1 < rx2)
  73283. {
  73284. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73285. {
  73286. r.w = x1 - rx1;
  73287. }
  73288. else
  73289. {
  73290. r.x = x1;
  73291. r.w = rx2 - x1;
  73292. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73293. i += 2;
  73294. }
  73295. }
  73296. else if (x2 > rx1 && x2 < rx2)
  73297. {
  73298. r.x = x2;
  73299. r.w = rx2 - x2;
  73300. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73301. {
  73302. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73303. i += 2;
  73304. }
  73305. }
  73306. else if (y1 > ry1 && y1 < ry2)
  73307. {
  73308. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73309. {
  73310. r.h = y1 - ry1;
  73311. }
  73312. else
  73313. {
  73314. r.y = y1;
  73315. r.h = ry2 - y1;
  73316. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73317. i += 2;
  73318. }
  73319. }
  73320. else if (y2 > ry1 && y2 < ry2)
  73321. {
  73322. r.y = y2;
  73323. r.h = ry2 - y2;
  73324. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73325. {
  73326. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73327. i += 2;
  73328. }
  73329. }
  73330. else
  73331. {
  73332. rects.remove (i);
  73333. }
  73334. }
  73335. }
  73336. if (rects.size() > originalNumRects + 10)
  73337. consolidate();
  73338. }
  73339. }
  73340. void RectangleList::subtract (const RectangleList& otherList) throw()
  73341. {
  73342. for (int i = otherList.rects.size(); --i >= 0;)
  73343. subtract (otherList.rects.getReference (i));
  73344. }
  73345. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73346. {
  73347. bool notEmpty = false;
  73348. if (rect.isEmpty())
  73349. {
  73350. clear();
  73351. }
  73352. else
  73353. {
  73354. for (int i = rects.size(); --i >= 0;)
  73355. {
  73356. Rectangle<int>& r = rects.getReference (i);
  73357. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73358. rects.remove (i);
  73359. else
  73360. notEmpty = true;
  73361. }
  73362. }
  73363. return notEmpty;
  73364. }
  73365. bool RectangleList::clipTo (const RectangleList& other) throw()
  73366. {
  73367. if (rects.size() == 0)
  73368. return false;
  73369. RectangleList result;
  73370. for (int j = 0; j < rects.size(); ++j)
  73371. {
  73372. const Rectangle<int>& rect = rects.getReference (j);
  73373. for (int i = other.rects.size(); --i >= 0;)
  73374. {
  73375. Rectangle<int> r (other.rects.getReference (i));
  73376. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73377. result.rects.add (r);
  73378. }
  73379. }
  73380. swapWith (result);
  73381. return ! isEmpty();
  73382. }
  73383. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73384. {
  73385. destRegion.clear();
  73386. if (! rect.isEmpty())
  73387. {
  73388. for (int i = rects.size(); --i >= 0;)
  73389. {
  73390. Rectangle<int> r (rects.getReference (i));
  73391. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73392. destRegion.rects.add (r);
  73393. }
  73394. }
  73395. return destRegion.rects.size() > 0;
  73396. }
  73397. void RectangleList::swapWith (RectangleList& otherList) throw()
  73398. {
  73399. rects.swapWithArray (otherList.rects);
  73400. }
  73401. void RectangleList::consolidate() throw()
  73402. {
  73403. int i;
  73404. for (i = 0; i < getNumRectangles() - 1; ++i)
  73405. {
  73406. Rectangle<int>& r = rects.getReference (i);
  73407. const int rx1 = r.x;
  73408. const int ry1 = r.y;
  73409. const int rx2 = rx1 + r.w;
  73410. const int ry2 = ry1 + r.h;
  73411. for (int j = rects.size(); --j > i;)
  73412. {
  73413. Rectangle<int>& r2 = rects.getReference (j);
  73414. const int jrx1 = r2.x;
  73415. const int jry1 = r2.y;
  73416. const int jrx2 = jrx1 + r2.w;
  73417. const int jry2 = jry1 + r2.h;
  73418. // if the vertical edges of any blocks are touching and their horizontals don't
  73419. // line up, split them horizontally..
  73420. if (jrx1 == rx2 || jrx2 == rx1)
  73421. {
  73422. if (jry1 > ry1 && jry1 < ry2)
  73423. {
  73424. r.h = jry1 - ry1;
  73425. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73426. i = -1;
  73427. break;
  73428. }
  73429. if (jry2 > ry1 && jry2 < ry2)
  73430. {
  73431. r.h = jry2 - ry1;
  73432. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73433. i = -1;
  73434. break;
  73435. }
  73436. else if (ry1 > jry1 && ry1 < jry2)
  73437. {
  73438. r2.h = ry1 - jry1;
  73439. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73440. i = -1;
  73441. break;
  73442. }
  73443. else if (ry2 > jry1 && ry2 < jry2)
  73444. {
  73445. r2.h = ry2 - jry1;
  73446. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73447. i = -1;
  73448. break;
  73449. }
  73450. }
  73451. }
  73452. }
  73453. for (i = 0; i < rects.size() - 1; ++i)
  73454. {
  73455. Rectangle<int>& r = rects.getReference (i);
  73456. for (int j = rects.size(); --j > i;)
  73457. {
  73458. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73459. {
  73460. rects.remove (j);
  73461. i = -1;
  73462. break;
  73463. }
  73464. }
  73465. }
  73466. }
  73467. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73468. {
  73469. for (int i = getNumRectangles(); --i >= 0;)
  73470. if (rects.getReference (i).contains (x, y))
  73471. return true;
  73472. return false;
  73473. }
  73474. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73475. {
  73476. if (rects.size() > 1)
  73477. {
  73478. RectangleList r (rectangleToCheck);
  73479. for (int i = rects.size(); --i >= 0;)
  73480. {
  73481. r.subtract (rects.getReference (i));
  73482. if (r.rects.size() == 0)
  73483. return true;
  73484. }
  73485. }
  73486. else if (rects.size() > 0)
  73487. {
  73488. return rects.getReference (0).contains (rectangleToCheck);
  73489. }
  73490. return false;
  73491. }
  73492. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73493. {
  73494. for (int i = rects.size(); --i >= 0;)
  73495. if (rects.getReference (i).intersects (rectangleToCheck))
  73496. return true;
  73497. return false;
  73498. }
  73499. bool RectangleList::intersects (const RectangleList& other) const throw()
  73500. {
  73501. for (int i = rects.size(); --i >= 0;)
  73502. if (other.intersectsRectangle (rects.getReference (i)))
  73503. return true;
  73504. return false;
  73505. }
  73506. const Rectangle<int> RectangleList::getBounds() const throw()
  73507. {
  73508. if (rects.size() <= 1)
  73509. {
  73510. if (rects.size() == 0)
  73511. return Rectangle<int>();
  73512. else
  73513. return rects.getReference (0);
  73514. }
  73515. else
  73516. {
  73517. const Rectangle<int>& r = rects.getReference (0);
  73518. int minX = r.x;
  73519. int minY = r.y;
  73520. int maxX = minX + r.w;
  73521. int maxY = minY + r.h;
  73522. for (int i = rects.size(); --i > 0;)
  73523. {
  73524. const Rectangle<int>& r2 = rects.getReference (i);
  73525. minX = jmin (minX, r2.x);
  73526. minY = jmin (minY, r2.y);
  73527. maxX = jmax (maxX, r2.getRight());
  73528. maxY = jmax (maxY, r2.getBottom());
  73529. }
  73530. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73531. }
  73532. }
  73533. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73534. {
  73535. for (int i = rects.size(); --i >= 0;)
  73536. {
  73537. Rectangle<int>& r = rects.getReference (i);
  73538. r.x += dx;
  73539. r.y += dy;
  73540. }
  73541. }
  73542. const Path RectangleList::toPath() const throw()
  73543. {
  73544. Path p;
  73545. for (int i = rects.size(); --i >= 0;)
  73546. {
  73547. const Rectangle<int>& r = rects.getReference (i);
  73548. p.addRectangle ((float) r.x,
  73549. (float) r.y,
  73550. (float) r.w,
  73551. (float) r.h);
  73552. }
  73553. return p;
  73554. }
  73555. END_JUCE_NAMESPACE
  73556. /*** End of inlined file: juce_RectangleList.cpp ***/
  73557. /*** Start of inlined file: juce_Image.cpp ***/
  73558. BEGIN_JUCE_NAMESPACE
  73559. static const int fullAlphaThreshold = 253;
  73560. Image::Image (const PixelFormat format_,
  73561. const int imageWidth_,
  73562. const int imageHeight_)
  73563. : format (format_),
  73564. imageWidth (imageWidth_),
  73565. imageHeight (imageHeight_),
  73566. imageData (0)
  73567. {
  73568. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73569. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73570. // actual image will be at least 1x1.
  73571. }
  73572. Image::Image (const PixelFormat format_,
  73573. const int imageWidth_,
  73574. const int imageHeight_,
  73575. const bool clearImage)
  73576. : format (format_),
  73577. imageWidth (imageWidth_),
  73578. imageHeight (imageHeight_)
  73579. {
  73580. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73581. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73582. // actual image will be at least 1x1.
  73583. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73584. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73585. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73586. imageData = imageDataAllocated;
  73587. }
  73588. Image::Image (const Image& other)
  73589. : format (other.format),
  73590. imageWidth (other.imageWidth),
  73591. imageHeight (other.imageHeight)
  73592. {
  73593. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73594. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73595. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73596. imageData = imageDataAllocated;
  73597. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73598. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73599. }
  73600. Image::~Image()
  73601. {
  73602. }
  73603. LowLevelGraphicsContext* Image::createLowLevelContext()
  73604. {
  73605. return new LowLevelGraphicsSoftwareRenderer (*this);
  73606. }
  73607. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73608. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73609. lineStride (image.lineStride),
  73610. pixelStride (image.pixelStride),
  73611. width (w),
  73612. height (h)
  73613. {
  73614. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73615. }
  73616. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73617. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73618. lineStride (image.lineStride),
  73619. pixelStride (image.pixelStride),
  73620. width (w),
  73621. height (h)
  73622. {
  73623. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73624. }
  73625. Image::BitmapData::~BitmapData()
  73626. {
  73627. }
  73628. void Image::setPixelData (int x, int y, int w, int h,
  73629. const uint8* sourcePixelData, int sourceLineStride)
  73630. {
  73631. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73632. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73633. {
  73634. const BitmapData dest (*this, x, y, w, h, true);
  73635. for (int i = 0; i < h; ++i)
  73636. {
  73637. memcpy (dest.getLinePointer(i),
  73638. sourcePixelData + sourceLineStride * i,
  73639. w * dest.pixelStride);
  73640. }
  73641. }
  73642. }
  73643. void Image::clear (int dx, int dy, int dw, int dh,
  73644. const Colour& colourToClearTo)
  73645. {
  73646. const PixelARGB col (colourToClearTo.getPixelARGB());
  73647. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73648. uint8* dest = destData.data;
  73649. while (--dh >= 0)
  73650. {
  73651. uint8* line = dest;
  73652. dest += destData.lineStride;
  73653. if (isARGB())
  73654. {
  73655. for (int x = dw; --x >= 0;)
  73656. {
  73657. ((PixelARGB*) line)->set (col);
  73658. line += destData.pixelStride;
  73659. }
  73660. }
  73661. else if (isRGB())
  73662. {
  73663. for (int x = dw; --x >= 0;)
  73664. {
  73665. ((PixelRGB*) line)->set (col);
  73666. line += destData.pixelStride;
  73667. }
  73668. }
  73669. else
  73670. {
  73671. for (int x = dw; --x >= 0;)
  73672. {
  73673. *line = col.getAlpha();
  73674. line += destData.pixelStride;
  73675. }
  73676. }
  73677. }
  73678. }
  73679. Image* Image::createCopy (int newWidth, int newHeight,
  73680. const Graphics::ResamplingQuality quality) const
  73681. {
  73682. if (newWidth < 0)
  73683. newWidth = imageWidth;
  73684. if (newHeight < 0)
  73685. newHeight = imageHeight;
  73686. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73687. Graphics g (*newImage);
  73688. g.setImageResamplingQuality (quality);
  73689. g.drawImage (this,
  73690. 0, 0, newWidth, newHeight,
  73691. 0, 0, imageWidth, imageHeight,
  73692. false);
  73693. return newImage;
  73694. }
  73695. Image* Image::createCopyOfAlphaChannel() const
  73696. {
  73697. jassert (format != SingleChannel);
  73698. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73699. if (! hasAlphaChannel())
  73700. {
  73701. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73702. }
  73703. else
  73704. {
  73705. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73706. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73707. for (int y = 0; y < imageHeight; ++y)
  73708. {
  73709. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73710. uint8* dst = destData.getLinePointer (y);
  73711. for (int x = imageWidth; --x >= 0;)
  73712. {
  73713. *dst++ = src->getAlpha();
  73714. ++src;
  73715. }
  73716. }
  73717. }
  73718. return newImage;
  73719. }
  73720. const Colour Image::getPixelAt (const int x, const int y) const
  73721. {
  73722. Colour c;
  73723. if (((unsigned int) x) < (unsigned int) imageWidth
  73724. && ((unsigned int) y) < (unsigned int) imageHeight)
  73725. {
  73726. const BitmapData srcData (*this, x, y, 1, 1);
  73727. if (isARGB())
  73728. {
  73729. PixelARGB p (*(const PixelARGB*) srcData.data);
  73730. p.unpremultiply();
  73731. c = Colour (p.getARGB());
  73732. }
  73733. else if (isRGB())
  73734. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73735. else
  73736. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73737. }
  73738. return c;
  73739. }
  73740. void Image::setPixelAt (const int x, const int y,
  73741. const Colour& colour)
  73742. {
  73743. if (((unsigned int) x) < (unsigned int) imageWidth
  73744. && ((unsigned int) y) < (unsigned int) imageHeight)
  73745. {
  73746. const BitmapData destData (*this, x, y, 1, 1, true);
  73747. const PixelARGB col (colour.getPixelARGB());
  73748. if (isARGB())
  73749. ((PixelARGB*) destData.data)->set (col);
  73750. else if (isRGB())
  73751. ((PixelRGB*) destData.data)->set (col);
  73752. else
  73753. *(destData.data) = col.getAlpha();
  73754. }
  73755. }
  73756. void Image::multiplyAlphaAt (const int x, const int y,
  73757. const float multiplier)
  73758. {
  73759. if (((unsigned int) x) < (unsigned int) imageWidth
  73760. && ((unsigned int) y) < (unsigned int) imageHeight
  73761. && hasAlphaChannel())
  73762. {
  73763. const BitmapData destData (*this, x, y, 1, 1, true);
  73764. if (isARGB())
  73765. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73766. else
  73767. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73768. }
  73769. }
  73770. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73771. {
  73772. if (hasAlphaChannel())
  73773. {
  73774. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73775. if (isARGB())
  73776. {
  73777. for (int y = 0; y < imageHeight; ++y)
  73778. {
  73779. uint8* p = destData.getLinePointer (y);
  73780. for (int x = 0; x < imageWidth; ++x)
  73781. {
  73782. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73783. p += destData.pixelStride;
  73784. }
  73785. }
  73786. }
  73787. else
  73788. {
  73789. for (int y = 0; y < imageHeight; ++y)
  73790. {
  73791. uint8* p = destData.getLinePointer (y);
  73792. for (int x = 0; x < imageWidth; ++x)
  73793. {
  73794. *p = (uint8) (*p * amountToMultiplyBy);
  73795. p += destData.pixelStride;
  73796. }
  73797. }
  73798. }
  73799. }
  73800. else
  73801. {
  73802. jassertfalse // can't do this without an alpha-channel!
  73803. }
  73804. }
  73805. void Image::desaturate()
  73806. {
  73807. if (isARGB() || isRGB())
  73808. {
  73809. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73810. if (isARGB())
  73811. {
  73812. for (int y = 0; y < imageHeight; ++y)
  73813. {
  73814. uint8* p = destData.getLinePointer (y);
  73815. for (int x = 0; x < imageWidth; ++x)
  73816. {
  73817. ((PixelARGB*) p)->desaturate();
  73818. p += destData.pixelStride;
  73819. }
  73820. }
  73821. }
  73822. else
  73823. {
  73824. for (int y = 0; y < imageHeight; ++y)
  73825. {
  73826. uint8* p = destData.getLinePointer (y);
  73827. for (int x = 0; x < imageWidth; ++x)
  73828. {
  73829. ((PixelRGB*) p)->desaturate();
  73830. p += destData.pixelStride;
  73831. }
  73832. }
  73833. }
  73834. }
  73835. }
  73836. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73837. {
  73838. if (hasAlphaChannel())
  73839. {
  73840. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73841. SparseSet <int> pixelsOnRow;
  73842. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73843. for (int y = 0; y < imageHeight; ++y)
  73844. {
  73845. pixelsOnRow.clear();
  73846. const uint8* lineData = srcData.getLinePointer (y);
  73847. if (isARGB())
  73848. {
  73849. for (int x = 0; x < imageWidth; ++x)
  73850. {
  73851. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73852. pixelsOnRow.addRange (x, 1);
  73853. lineData += srcData.pixelStride;
  73854. }
  73855. }
  73856. else
  73857. {
  73858. for (int x = 0; x < imageWidth; ++x)
  73859. {
  73860. if (*lineData >= threshold)
  73861. pixelsOnRow.addRange (x, 1);
  73862. lineData += srcData.pixelStride;
  73863. }
  73864. }
  73865. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73866. {
  73867. int x, w;
  73868. if (pixelsOnRow.getRange (i, x, w))
  73869. result.add (Rectangle<int> (x, y, w, 1));
  73870. }
  73871. result.consolidate();
  73872. }
  73873. }
  73874. else
  73875. {
  73876. result.add (0, 0, imageWidth, imageHeight);
  73877. }
  73878. }
  73879. void Image::moveImageSection (int dx, int dy,
  73880. int sx, int sy,
  73881. int w, int h)
  73882. {
  73883. if (dx < 0)
  73884. {
  73885. w += dx;
  73886. sx -= dx;
  73887. dx = 0;
  73888. }
  73889. if (dy < 0)
  73890. {
  73891. h += dy;
  73892. sy -= dy;
  73893. dy = 0;
  73894. }
  73895. if (sx < 0)
  73896. {
  73897. w += sx;
  73898. dx -= sx;
  73899. sx = 0;
  73900. }
  73901. if (sy < 0)
  73902. {
  73903. h += sy;
  73904. dy -= sy;
  73905. sy = 0;
  73906. }
  73907. const int minX = jmin (dx, sx);
  73908. const int minY = jmin (dy, sy);
  73909. w = jmin (w, getWidth() - jmax (sx, dx));
  73910. h = jmin (h, getHeight() - jmax (sy, dy));
  73911. if (w > 0 && h > 0)
  73912. {
  73913. const int maxX = jmax (dx, sx) + w;
  73914. const int maxY = jmax (dy, sy) + h;
  73915. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73916. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73917. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  73918. const int lineSize = destData.pixelStride * w;
  73919. if (dy > sy)
  73920. {
  73921. while (--h >= 0)
  73922. {
  73923. const int offset = h * destData.lineStride;
  73924. memmove (dst + offset, src + offset, lineSize);
  73925. }
  73926. }
  73927. else if (dst != src)
  73928. {
  73929. while (--h >= 0)
  73930. {
  73931. memmove (dst, src, lineSize);
  73932. dst += destData.lineStride;
  73933. src += destData.lineStride;
  73934. }
  73935. }
  73936. }
  73937. }
  73938. END_JUCE_NAMESPACE
  73939. /*** End of inlined file: juce_Image.cpp ***/
  73940. /*** Start of inlined file: juce_ImageCache.cpp ***/
  73941. BEGIN_JUCE_NAMESPACE
  73942. struct ImageCacheItem
  73943. {
  73944. ScopedPointer <Image> image;
  73945. int64 hashCode;
  73946. int refCount;
  73947. uint32 releaseTime;
  73948. juce_UseDebuggingNewOperator
  73949. };
  73950. static ImageCache* instance = 0;
  73951. static int cacheTimeout = 5000;
  73952. ImageCache::ImageCache()
  73953. {
  73954. }
  73955. ImageCache::~ImageCache()
  73956. {
  73957. jassert (instance == this);
  73958. instance = 0;
  73959. }
  73960. Image* ImageCache::getFromHashCode (const int64 hashCode)
  73961. {
  73962. if (instance != 0)
  73963. {
  73964. const ScopedLock sl (instance->lock);
  73965. for (int i = instance->images.size(); --i >= 0;)
  73966. {
  73967. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  73968. if (ci->hashCode == hashCode)
  73969. {
  73970. ci->refCount++;
  73971. return ci->image;
  73972. }
  73973. }
  73974. }
  73975. return 0;
  73976. }
  73977. void ImageCache::addImageToCache (Image* const image,
  73978. const int64 hashCode)
  73979. {
  73980. if (image != 0)
  73981. {
  73982. if (instance == 0)
  73983. instance = new ImageCache();
  73984. ImageCacheItem* const newC = new ImageCacheItem();
  73985. newC->hashCode = hashCode;
  73986. newC->image = image;
  73987. newC->refCount = 1;
  73988. newC->releaseTime = 0;
  73989. const ScopedLock sl (instance->lock);
  73990. instance->images.add (newC);
  73991. }
  73992. }
  73993. void ImageCache::release (Image* const imageToRelease)
  73994. {
  73995. if (imageToRelease != 0 && instance != 0)
  73996. {
  73997. const ScopedLock sl (instance->lock);
  73998. for (int i = instance->images.size(); --i >= 0;)
  73999. {
  74000. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74001. if ((Image*) ci->image == imageToRelease)
  74002. {
  74003. if (--(ci->refCount) == 0)
  74004. ci->releaseTime = Time::getApproximateMillisecondCounter();
  74005. if (! instance->isTimerRunning())
  74006. instance->startTimer (999);
  74007. break;
  74008. }
  74009. }
  74010. }
  74011. }
  74012. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74013. {
  74014. if (isImageInCache (imageToRelease))
  74015. release (imageToRelease);
  74016. else
  74017. delete imageToRelease;
  74018. }
  74019. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74020. {
  74021. if (instance != 0)
  74022. {
  74023. const ScopedLock sl (instance->lock);
  74024. for (int i = instance->images.size(); --i >= 0;)
  74025. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74026. return true;
  74027. }
  74028. return false;
  74029. }
  74030. void ImageCache::incReferenceCount (Image* const image)
  74031. {
  74032. if (instance != 0)
  74033. {
  74034. const ScopedLock sl (instance->lock);
  74035. for (int i = instance->images.size(); --i >= 0;)
  74036. {
  74037. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74038. if ((Image*) ci->image == image)
  74039. {
  74040. ci->refCount++;
  74041. return;
  74042. }
  74043. }
  74044. }
  74045. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74046. }
  74047. void ImageCache::timerCallback()
  74048. {
  74049. int numberStillNeedingReleasing = 0;
  74050. const unsigned int now = Time::getApproximateMillisecondCounter();
  74051. const ScopedLock sl (lock);
  74052. for (int i = images.size(); --i >= 0;)
  74053. {
  74054. ImageCacheItem* const ci = images.getUnchecked(i);
  74055. if (ci->refCount <= 0)
  74056. {
  74057. if (now > ci->releaseTime + cacheTimeout
  74058. || now < ci->releaseTime - 1000)
  74059. {
  74060. images.remove (i);
  74061. }
  74062. else
  74063. {
  74064. ++numberStillNeedingReleasing;
  74065. }
  74066. }
  74067. }
  74068. if (numberStillNeedingReleasing == 0)
  74069. stopTimer();
  74070. }
  74071. Image* ImageCache::getFromFile (const File& file)
  74072. {
  74073. const int64 hashCode = file.hashCode64();
  74074. Image* image = getFromHashCode (hashCode);
  74075. if (image == 0)
  74076. {
  74077. image = ImageFileFormat::loadFrom (file);
  74078. addImageToCache (image, hashCode);
  74079. }
  74080. return image;
  74081. }
  74082. Image* ImageCache::getFromMemory (const void* imageData,
  74083. const int dataSize)
  74084. {
  74085. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74086. Image* image = getFromHashCode (hashCode);
  74087. if (image == 0)
  74088. {
  74089. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74090. addImageToCache (image, hashCode);
  74091. }
  74092. return image;
  74093. }
  74094. void ImageCache::setCacheTimeout (const int millisecs)
  74095. {
  74096. cacheTimeout = millisecs;
  74097. }
  74098. END_JUCE_NAMESPACE
  74099. /*** End of inlined file: juce_ImageCache.cpp ***/
  74100. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74101. BEGIN_JUCE_NAMESPACE
  74102. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74103. : values (size_ * size_),
  74104. size (size_)
  74105. {
  74106. clear();
  74107. }
  74108. ImageConvolutionKernel::~ImageConvolutionKernel()
  74109. {
  74110. }
  74111. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  74112. {
  74113. if (((unsigned int) x) < (unsigned int) size
  74114. && ((unsigned int) y) < (unsigned int) size)
  74115. {
  74116. return values [x + y * size];
  74117. }
  74118. else
  74119. {
  74120. jassertfalse;
  74121. return 0;
  74122. }
  74123. }
  74124. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  74125. {
  74126. if (((unsigned int) x) < (unsigned int) size
  74127. && ((unsigned int) y) < (unsigned int) size)
  74128. {
  74129. values [x + y * size] = value;
  74130. }
  74131. else
  74132. {
  74133. jassertfalse;
  74134. }
  74135. }
  74136. void ImageConvolutionKernel::clear()
  74137. {
  74138. for (int i = size * size; --i >= 0;)
  74139. values[i] = 0;
  74140. }
  74141. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74142. {
  74143. double currentTotal = 0.0;
  74144. for (int i = size * size; --i >= 0;)
  74145. currentTotal += values[i];
  74146. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74147. }
  74148. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74149. {
  74150. for (int i = size * size; --i >= 0;)
  74151. values[i] *= multiplier;
  74152. }
  74153. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74154. {
  74155. const double radiusFactor = -1.0 / (radius * radius * 2);
  74156. const int centre = size >> 1;
  74157. for (int y = size; --y >= 0;)
  74158. {
  74159. for (int x = size; --x >= 0;)
  74160. {
  74161. const int cx = x - centre;
  74162. const int cy = y - centre;
  74163. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74164. }
  74165. }
  74166. setOverallSum (1.0f);
  74167. }
  74168. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74169. const Image* sourceImage,
  74170. int dx,
  74171. int dy,
  74172. int dw,
  74173. int dh) const
  74174. {
  74175. ScopedPointer <Image> imageCreated;
  74176. if (sourceImage == 0)
  74177. {
  74178. sourceImage = imageCreated = destImage.createCopy();
  74179. }
  74180. else
  74181. {
  74182. jassert (sourceImage->getWidth() == destImage.getWidth()
  74183. && sourceImage->getHeight() == destImage.getHeight()
  74184. && sourceImage->getFormat() == destImage.getFormat());
  74185. if (sourceImage->getWidth() != destImage.getWidth()
  74186. || sourceImage->getHeight() != destImage.getHeight()
  74187. || sourceImage->getFormat() != destImage.getFormat())
  74188. return;
  74189. }
  74190. const int imageWidth = destImage.getWidth();
  74191. const int imageHeight = destImage.getHeight();
  74192. if (dx >= imageWidth || dy >= imageHeight)
  74193. return;
  74194. if (dx + dw > imageWidth)
  74195. dw = imageWidth - dx;
  74196. if (dy + dh > imageHeight)
  74197. dh = imageHeight - dy;
  74198. const int dx2 = dx + dw;
  74199. const int dy2 = dy + dh;
  74200. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74201. uint8* line = destData.data;
  74202. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74203. if (destData.pixelStride == 4)
  74204. {
  74205. for (int y = dy; y < dy2; ++y)
  74206. {
  74207. uint8* dest = line;
  74208. line += destData.lineStride;
  74209. for (int x = dx; x < dx2; ++x)
  74210. {
  74211. float c1 = 0;
  74212. float c2 = 0;
  74213. float c3 = 0;
  74214. float c4 = 0;
  74215. for (int yy = 0; yy < size; ++yy)
  74216. {
  74217. const int sy = y + yy - (size >> 1);
  74218. if (sy >= imageHeight)
  74219. break;
  74220. if (sy >= 0)
  74221. {
  74222. int sx = x - (size >> 1);
  74223. const uint8* src = srcData.getPixelPointer (sx, sy);
  74224. for (int xx = 0; xx < size; ++xx)
  74225. {
  74226. if (sx >= imageWidth)
  74227. break;
  74228. if (sx >= 0)
  74229. {
  74230. const float kernelMult = values [xx + yy * size];
  74231. c1 += kernelMult * *src++;
  74232. c2 += kernelMult * *src++;
  74233. c3 += kernelMult * *src++;
  74234. c4 += kernelMult * *src++;
  74235. }
  74236. else
  74237. {
  74238. src += 4;
  74239. }
  74240. ++sx;
  74241. }
  74242. }
  74243. }
  74244. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74245. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74246. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74247. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74248. }
  74249. }
  74250. }
  74251. else if (destData.pixelStride == 3)
  74252. {
  74253. for (int y = dy; y < dy2; ++y)
  74254. {
  74255. uint8* dest = line;
  74256. line += destData.lineStride;
  74257. for (int x = dx; x < dx2; ++x)
  74258. {
  74259. float c1 = 0;
  74260. float c2 = 0;
  74261. float c3 = 0;
  74262. for (int yy = 0; yy < size; ++yy)
  74263. {
  74264. const int sy = y + yy - (size >> 1);
  74265. if (sy >= imageHeight)
  74266. break;
  74267. if (sy >= 0)
  74268. {
  74269. int sx = x - (size >> 1);
  74270. const uint8* src = srcData.getPixelPointer (sx, sy);
  74271. for (int xx = 0; xx < size; ++xx)
  74272. {
  74273. if (sx >= imageWidth)
  74274. break;
  74275. if (sx >= 0)
  74276. {
  74277. const float kernelMult = values [xx + yy * size];
  74278. c1 += kernelMult * *src++;
  74279. c2 += kernelMult * *src++;
  74280. c3 += kernelMult * *src++;
  74281. }
  74282. else
  74283. {
  74284. src += 3;
  74285. }
  74286. ++sx;
  74287. }
  74288. }
  74289. }
  74290. *dest++ = (uint8) roundToInt (c1);
  74291. *dest++ = (uint8) roundToInt (c2);
  74292. *dest++ = (uint8) roundToInt (c3);
  74293. }
  74294. }
  74295. }
  74296. }
  74297. END_JUCE_NAMESPACE
  74298. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74299. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74300. BEGIN_JUCE_NAMESPACE
  74301. /*** Start of inlined file: juce_GIFLoader.h ***/
  74302. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74303. #define __JUCE_GIFLOADER_JUCEHEADER__
  74304. #ifndef DOXYGEN
  74305. class GIFLoader
  74306. {
  74307. public:
  74308. GIFLoader (InputStream& in);
  74309. ~GIFLoader();
  74310. Image* getImage() const { return image; }
  74311. private:
  74312. Image* image;
  74313. InputStream& input;
  74314. uint8 buffer [300];
  74315. uint8 palette [256][4];
  74316. bool dataBlockIsZero, fresh, finished;
  74317. int currentBit, lastBit, lastByteIndex;
  74318. int codeSize, setCodeSize;
  74319. int maxCode, maxCodeSize;
  74320. int firstcode, oldcode;
  74321. int clearCode, end_code;
  74322. enum { maxGifCode = 1 << 12 };
  74323. int table [2] [maxGifCode];
  74324. int stack [2 * maxGifCode];
  74325. int *sp;
  74326. bool getSizeFromHeader (int& width, int& height);
  74327. bool readPalette (const int numCols);
  74328. int readDataBlock (unsigned char* dest);
  74329. int processExtension (int type, int& transparent);
  74330. int readLZWByte (bool initialise, int input_code_size);
  74331. int getCode (int code_size, bool initialise);
  74332. bool readImage (int width, int height, int interlace, int transparent);
  74333. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74334. GIFLoader (const GIFLoader&);
  74335. GIFLoader& operator= (const GIFLoader&);
  74336. };
  74337. #endif // DOXYGEN
  74338. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74339. /*** End of inlined file: juce_GIFLoader.h ***/
  74340. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74341. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74342. PNGImageFormat::PNGImageFormat() {}
  74343. PNGImageFormat::~PNGImageFormat() {}
  74344. const String PNGImageFormat::getFormatName()
  74345. {
  74346. return T("PNG");
  74347. }
  74348. bool PNGImageFormat::canUnderstand (InputStream& in)
  74349. {
  74350. const int bytesNeeded = 4;
  74351. char header [bytesNeeded];
  74352. return in.read (header, bytesNeeded) == bytesNeeded
  74353. && header[1] == 'P'
  74354. && header[2] == 'N'
  74355. && header[3] == 'G';
  74356. }
  74357. Image* PNGImageFormat::decodeImage (InputStream& in)
  74358. {
  74359. return juce_loadPNGImageFromStream (in);
  74360. }
  74361. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74362. OutputStream& destStream)
  74363. {
  74364. return juce_writePNGImageToStream (sourceImage, destStream);
  74365. }
  74366. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74367. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74368. JPEGImageFormat::JPEGImageFormat()
  74369. : quality (-1.0f)
  74370. {
  74371. }
  74372. JPEGImageFormat::~JPEGImageFormat() {}
  74373. void JPEGImageFormat::setQuality (const float newQuality)
  74374. {
  74375. quality = newQuality;
  74376. }
  74377. const String JPEGImageFormat::getFormatName()
  74378. {
  74379. return T("JPEG");
  74380. }
  74381. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74382. {
  74383. const int bytesNeeded = 10;
  74384. uint8 header [bytesNeeded];
  74385. if (in.read (header, bytesNeeded) == bytesNeeded)
  74386. {
  74387. return header[0] == 0xff
  74388. && header[1] == 0xd8
  74389. && header[2] == 0xff
  74390. && (header[3] == 0xe0 || header[3] == 0xe1);
  74391. }
  74392. return false;
  74393. }
  74394. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74395. {
  74396. return juce_loadJPEGImageFromStream (in);
  74397. }
  74398. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74399. OutputStream& destStream)
  74400. {
  74401. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74402. }
  74403. class GIFImageFormat : public ImageFileFormat
  74404. {
  74405. public:
  74406. GIFImageFormat() {}
  74407. ~GIFImageFormat() {}
  74408. const String getFormatName()
  74409. {
  74410. return T("GIF");
  74411. }
  74412. bool canUnderstand (InputStream& in)
  74413. {
  74414. const int bytesNeeded = 4;
  74415. char header [bytesNeeded];
  74416. return (in.read (header, bytesNeeded) == bytesNeeded)
  74417. && header[0] == 'G'
  74418. && header[1] == 'I'
  74419. && header[2] == 'F';
  74420. }
  74421. Image* decodeImage (InputStream& in)
  74422. {
  74423. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74424. return loader->getImage();
  74425. }
  74426. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74427. {
  74428. return false;
  74429. }
  74430. };
  74431. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74432. {
  74433. static PNGImageFormat png;
  74434. static JPEGImageFormat jpg;
  74435. static GIFImageFormat gif;
  74436. ImageFileFormat* formats[4];
  74437. int numFormats = 0;
  74438. formats [numFormats++] = &png;
  74439. formats [numFormats++] = &jpg;
  74440. formats [numFormats++] = &gif;
  74441. const int64 streamPos = input.getPosition();
  74442. for (int i = 0; i < numFormats; ++i)
  74443. {
  74444. const bool found = formats[i]->canUnderstand (input);
  74445. input.setPosition (streamPos);
  74446. if (found)
  74447. return formats[i];
  74448. }
  74449. return 0;
  74450. }
  74451. Image* ImageFileFormat::loadFrom (InputStream& input)
  74452. {
  74453. ImageFileFormat* const format = findImageFormatForStream (input);
  74454. if (format != 0)
  74455. return format->decodeImage (input);
  74456. return 0;
  74457. }
  74458. Image* ImageFileFormat::loadFrom (const File& file)
  74459. {
  74460. InputStream* const in = file.createInputStream();
  74461. if (in != 0)
  74462. {
  74463. BufferedInputStream b (in, 8192, true);
  74464. return loadFrom (b);
  74465. }
  74466. return 0;
  74467. }
  74468. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74469. {
  74470. if (rawData != 0 && numBytes > 4)
  74471. {
  74472. MemoryInputStream stream (rawData, numBytes, false);
  74473. return loadFrom (stream);
  74474. }
  74475. return 0;
  74476. }
  74477. END_JUCE_NAMESPACE
  74478. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74479. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74480. BEGIN_JUCE_NAMESPACE
  74481. GIFLoader::GIFLoader (InputStream& in)
  74482. : image (0),
  74483. input (in),
  74484. dataBlockIsZero (false),
  74485. fresh (false),
  74486. finished (false)
  74487. {
  74488. currentBit = lastBit = lastByteIndex = 0;
  74489. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74490. firstcode = oldcode = 0;
  74491. clearCode = end_code = 0;
  74492. int imageWidth, imageHeight;
  74493. int transparent = -1;
  74494. if (! getSizeFromHeader (imageWidth, imageHeight))
  74495. return;
  74496. if ((imageWidth <= 0) || (imageHeight <= 0))
  74497. return;
  74498. unsigned char buf [16];
  74499. if (in.read (buf, 3) != 3)
  74500. return;
  74501. int numColours = 2 << (buf[0] & 7);
  74502. if ((buf[0] & 0x80) != 0)
  74503. readPalette (numColours);
  74504. for (;;)
  74505. {
  74506. if (input.read (buf, 1) != 1)
  74507. break;
  74508. if (buf[0] == ';')
  74509. break;
  74510. if (buf[0] == '!')
  74511. {
  74512. if (input.read (buf, 1) != 1)
  74513. break;
  74514. if (processExtension (buf[0], transparent) < 0)
  74515. break;
  74516. continue;
  74517. }
  74518. if (buf[0] != ',')
  74519. continue;
  74520. if (input.read (buf, 9) != 9)
  74521. break;
  74522. imageWidth = makeWord (buf[4], buf[5]);
  74523. imageHeight = makeWord (buf[6], buf[7]);
  74524. numColours = 2 << (buf[8] & 7);
  74525. if ((buf[8] & 0x80) != 0)
  74526. if (! readPalette (numColours))
  74527. break;
  74528. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74529. imageWidth, imageHeight, (transparent >= 0));
  74530. readImage (imageWidth, imageHeight,
  74531. (buf[8] & 0x40) != 0,
  74532. transparent);
  74533. break;
  74534. }
  74535. }
  74536. GIFLoader::~GIFLoader()
  74537. {
  74538. }
  74539. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74540. {
  74541. unsigned char b [8];
  74542. if (input.read (b, 6) == 6)
  74543. {
  74544. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74545. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74546. {
  74547. if (input.read (b, 4) == 4)
  74548. {
  74549. w = makeWord (b[0], b[1]);
  74550. h = makeWord (b[2], b[3]);
  74551. return true;
  74552. }
  74553. }
  74554. }
  74555. return false;
  74556. }
  74557. bool GIFLoader::readPalette (const int numCols)
  74558. {
  74559. unsigned char rgb[4];
  74560. for (int i = 0; i < numCols; ++i)
  74561. {
  74562. input.read (rgb, 3);
  74563. palette [i][0] = rgb[0];
  74564. palette [i][1] = rgb[1];
  74565. palette [i][2] = rgb[2];
  74566. palette [i][3] = 0xff;
  74567. }
  74568. return true;
  74569. }
  74570. int GIFLoader::readDataBlock (unsigned char* const dest)
  74571. {
  74572. unsigned char n;
  74573. if (input.read (&n, 1) == 1)
  74574. {
  74575. dataBlockIsZero = (n == 0);
  74576. if (dataBlockIsZero || (input.read (dest, n) == n))
  74577. return n;
  74578. }
  74579. return -1;
  74580. }
  74581. int GIFLoader::processExtension (const int type, int& transparent)
  74582. {
  74583. unsigned char b [300];
  74584. int n = 0;
  74585. if (type == 0xf9)
  74586. {
  74587. n = readDataBlock (b);
  74588. if (n < 0)
  74589. return 1;
  74590. if ((b[0] & 0x1) != 0)
  74591. transparent = b[3];
  74592. }
  74593. do
  74594. {
  74595. n = readDataBlock (b);
  74596. }
  74597. while (n > 0);
  74598. return n;
  74599. }
  74600. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74601. {
  74602. if (initialise)
  74603. {
  74604. currentBit = 0;
  74605. lastBit = 0;
  74606. finished = false;
  74607. return 0;
  74608. }
  74609. if ((currentBit + codeSize_) >= lastBit)
  74610. {
  74611. if (finished)
  74612. return -1;
  74613. buffer[0] = buffer [lastByteIndex - 2];
  74614. buffer[1] = buffer [lastByteIndex - 1];
  74615. const int n = readDataBlock (&buffer[2]);
  74616. if (n == 0)
  74617. finished = true;
  74618. lastByteIndex = 2 + n;
  74619. currentBit = (currentBit - lastBit) + 16;
  74620. lastBit = (2 + n) * 8 ;
  74621. }
  74622. int result = 0;
  74623. int i = currentBit;
  74624. for (int j = 0; j < codeSize_; ++j)
  74625. {
  74626. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74627. ++i;
  74628. }
  74629. currentBit += codeSize_;
  74630. return result;
  74631. }
  74632. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74633. {
  74634. int code, incode, i;
  74635. if (initialise)
  74636. {
  74637. setCodeSize = inputCodeSize;
  74638. codeSize = setCodeSize + 1;
  74639. clearCode = 1 << setCodeSize;
  74640. end_code = clearCode + 1;
  74641. maxCodeSize = 2 * clearCode;
  74642. maxCode = clearCode + 2;
  74643. getCode (0, true);
  74644. fresh = true;
  74645. for (i = 0; i < clearCode; ++i)
  74646. {
  74647. table[0][i] = 0;
  74648. table[1][i] = i;
  74649. }
  74650. for (; i < maxGifCode; ++i)
  74651. {
  74652. table[0][i] = 0;
  74653. table[1][i] = 0;
  74654. }
  74655. sp = stack;
  74656. return 0;
  74657. }
  74658. else if (fresh)
  74659. {
  74660. fresh = false;
  74661. do
  74662. {
  74663. firstcode = oldcode
  74664. = getCode (codeSize, false);
  74665. }
  74666. while (firstcode == clearCode);
  74667. return firstcode;
  74668. }
  74669. if (sp > stack)
  74670. return *--sp;
  74671. while ((code = getCode (codeSize, false)) >= 0)
  74672. {
  74673. if (code == clearCode)
  74674. {
  74675. for (i = 0; i < clearCode; ++i)
  74676. {
  74677. table[0][i] = 0;
  74678. table[1][i] = i;
  74679. }
  74680. for (; i < maxGifCode; ++i)
  74681. {
  74682. table[0][i] = 0;
  74683. table[1][i] = 0;
  74684. }
  74685. codeSize = setCodeSize + 1;
  74686. maxCodeSize = 2 * clearCode;
  74687. maxCode = clearCode + 2;
  74688. sp = stack;
  74689. firstcode = oldcode = getCode (codeSize, false);
  74690. return firstcode;
  74691. }
  74692. else if (code == end_code)
  74693. {
  74694. if (dataBlockIsZero)
  74695. return -2;
  74696. unsigned char buf [260];
  74697. int n;
  74698. while ((n = readDataBlock (buf)) > 0)
  74699. {}
  74700. if (n != 0)
  74701. return -2;
  74702. }
  74703. incode = code;
  74704. if (code >= maxCode)
  74705. {
  74706. *sp++ = firstcode;
  74707. code = oldcode;
  74708. }
  74709. while (code >= clearCode)
  74710. {
  74711. *sp++ = table[1][code];
  74712. if (code == table[0][code])
  74713. return -2;
  74714. code = table[0][code];
  74715. }
  74716. *sp++ = firstcode = table[1][code];
  74717. if ((code = maxCode) < maxGifCode)
  74718. {
  74719. table[0][code] = oldcode;
  74720. table[1][code] = firstcode;
  74721. ++maxCode;
  74722. if ((maxCode >= maxCodeSize)
  74723. && (maxCodeSize < maxGifCode))
  74724. {
  74725. maxCodeSize <<= 1;
  74726. ++codeSize;
  74727. }
  74728. }
  74729. oldcode = incode;
  74730. if (sp > stack)
  74731. return *--sp;
  74732. }
  74733. return code;
  74734. }
  74735. bool GIFLoader::readImage (const int width, const int height,
  74736. const int interlace, const int transparent)
  74737. {
  74738. unsigned char c;
  74739. if (input.read (&c, 1) != 1
  74740. || readLZWByte (true, c) < 0)
  74741. return false;
  74742. if (transparent >= 0)
  74743. {
  74744. palette [transparent][0] = 0;
  74745. palette [transparent][1] = 0;
  74746. palette [transparent][2] = 0;
  74747. palette [transparent][3] = 0;
  74748. }
  74749. int index;
  74750. int xpos = 0, ypos = 0, pass = 0;
  74751. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74752. uint8* p = destData.data;
  74753. const bool hasAlpha = image->hasAlphaChannel();
  74754. while ((index = readLZWByte (false, c)) >= 0)
  74755. {
  74756. const uint8* const paletteEntry = palette [index];
  74757. if (hasAlpha)
  74758. {
  74759. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74760. paletteEntry[0],
  74761. paletteEntry[1],
  74762. paletteEntry[2]);
  74763. ((PixelARGB*) p)->premultiply();
  74764. }
  74765. else
  74766. {
  74767. ((PixelRGB*) p)->setARGB (0,
  74768. paletteEntry[0],
  74769. paletteEntry[1],
  74770. paletteEntry[2]);
  74771. }
  74772. p += destData.pixelStride;
  74773. ++xpos;
  74774. if (xpos == width)
  74775. {
  74776. xpos = 0;
  74777. if (interlace)
  74778. {
  74779. switch (pass)
  74780. {
  74781. case 0:
  74782. case 1:
  74783. ypos += 8;
  74784. break;
  74785. case 2:
  74786. ypos += 4;
  74787. break;
  74788. case 3:
  74789. ypos += 2;
  74790. break;
  74791. }
  74792. while (ypos >= height)
  74793. {
  74794. ++pass;
  74795. switch (pass)
  74796. {
  74797. case 1:
  74798. ypos = 4;
  74799. break;
  74800. case 2:
  74801. ypos = 2;
  74802. break;
  74803. case 3:
  74804. ypos = 1;
  74805. break;
  74806. default:
  74807. return true;
  74808. }
  74809. }
  74810. }
  74811. else
  74812. {
  74813. ++ypos;
  74814. }
  74815. p = destData.getPixelPointer (xpos, ypos);
  74816. }
  74817. if (ypos >= height)
  74818. break;
  74819. }
  74820. return true;
  74821. }
  74822. END_JUCE_NAMESPACE
  74823. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74824. #endif
  74825. //==============================================================================
  74826. // some files include lots of library code, so leave them to the end to avoid cluttering
  74827. // up the build for the clean files.
  74828. #if JUCE_BUILD_CORE
  74829. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74830. namespace zlibNamespace
  74831. {
  74832. #if JUCE_INCLUDE_ZLIB_CODE
  74833. #undef OS_CODE
  74834. #undef fdopen
  74835. /*** Start of inlined file: zlib.h ***/
  74836. #ifndef ZLIB_H
  74837. #define ZLIB_H
  74838. /*** Start of inlined file: zconf.h ***/
  74839. #ifndef ZCONF_H
  74840. #define ZCONF_H
  74841. // *** Just a few hacks here to make it compile nicely with Juce..
  74842. #define Z_PREFIX 1
  74843. #undef __MACTYPES__
  74844. #ifdef _MSC_VER
  74845. #pragma warning (disable : 4131 4127 4244 4267)
  74846. #endif
  74847. #ifdef Z_PREFIX
  74848. # define deflateInit_ z_deflateInit_
  74849. # define deflate z_deflate
  74850. # define deflateEnd z_deflateEnd
  74851. # define inflateInit_ z_inflateInit_
  74852. # define inflate z_inflate
  74853. # define inflateEnd z_inflateEnd
  74854. # define deflateInit2_ z_deflateInit2_
  74855. # define deflateSetDictionary z_deflateSetDictionary
  74856. # define deflateCopy z_deflateCopy
  74857. # define deflateReset z_deflateReset
  74858. # define deflateParams z_deflateParams
  74859. # define deflateBound z_deflateBound
  74860. # define deflatePrime z_deflatePrime
  74861. # define inflateInit2_ z_inflateInit2_
  74862. # define inflateSetDictionary z_inflateSetDictionary
  74863. # define inflateSync z_inflateSync
  74864. # define inflateSyncPoint z_inflateSyncPoint
  74865. # define inflateCopy z_inflateCopy
  74866. # define inflateReset z_inflateReset
  74867. # define inflateBack z_inflateBack
  74868. # define inflateBackEnd z_inflateBackEnd
  74869. # define compress z_compress
  74870. # define compress2 z_compress2
  74871. # define compressBound z_compressBound
  74872. # define uncompress z_uncompress
  74873. # define adler32 z_adler32
  74874. # define crc32 z_crc32
  74875. # define get_crc_table z_get_crc_table
  74876. # define zError z_zError
  74877. # define alloc_func z_alloc_func
  74878. # define free_func z_free_func
  74879. # define in_func z_in_func
  74880. # define out_func z_out_func
  74881. # define Byte z_Byte
  74882. # define uInt z_uInt
  74883. # define uLong z_uLong
  74884. # define Bytef z_Bytef
  74885. # define charf z_charf
  74886. # define intf z_intf
  74887. # define uIntf z_uIntf
  74888. # define uLongf z_uLongf
  74889. # define voidpf z_voidpf
  74890. # define voidp z_voidp
  74891. #endif
  74892. #if defined(__MSDOS__) && !defined(MSDOS)
  74893. # define MSDOS
  74894. #endif
  74895. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74896. # define OS2
  74897. #endif
  74898. #if defined(_WINDOWS) && !defined(WINDOWS)
  74899. # define WINDOWS
  74900. #endif
  74901. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74902. # ifndef WIN32
  74903. # define WIN32
  74904. # endif
  74905. #endif
  74906. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74907. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74908. # ifndef SYS16BIT
  74909. # define SYS16BIT
  74910. # endif
  74911. # endif
  74912. #endif
  74913. #ifdef SYS16BIT
  74914. # define MAXSEG_64K
  74915. #endif
  74916. #ifdef MSDOS
  74917. # define UNALIGNED_OK
  74918. #endif
  74919. #ifdef __STDC_VERSION__
  74920. # ifndef STDC
  74921. # define STDC
  74922. # endif
  74923. # if __STDC_VERSION__ >= 199901L
  74924. # ifndef STDC99
  74925. # define STDC99
  74926. # endif
  74927. # endif
  74928. #endif
  74929. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  74930. # define STDC
  74931. #endif
  74932. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  74933. # define STDC
  74934. #endif
  74935. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  74936. # define STDC
  74937. #endif
  74938. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  74939. # define STDC
  74940. #endif
  74941. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  74942. # define STDC
  74943. #endif
  74944. #ifndef STDC
  74945. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  74946. # define const /* note: need a more gentle solution here */
  74947. # endif
  74948. #endif
  74949. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  74950. # define NO_DUMMY_DECL
  74951. #endif
  74952. #ifndef MAX_MEM_LEVEL
  74953. # ifdef MAXSEG_64K
  74954. # define MAX_MEM_LEVEL 8
  74955. # else
  74956. # define MAX_MEM_LEVEL 9
  74957. # endif
  74958. #endif
  74959. #ifndef MAX_WBITS
  74960. # define MAX_WBITS 15 /* 32K LZ77 window */
  74961. #endif
  74962. #ifndef OF /* function prototypes */
  74963. # ifdef STDC
  74964. # define OF(args) args
  74965. # else
  74966. # define OF(args) ()
  74967. # endif
  74968. #endif
  74969. #ifdef SYS16BIT
  74970. # if defined(M_I86SM) || defined(M_I86MM)
  74971. # define SMALL_MEDIUM
  74972. # ifdef _MSC_VER
  74973. # define FAR _far
  74974. # else
  74975. # define FAR far
  74976. # endif
  74977. # endif
  74978. # if (defined(__SMALL__) || defined(__MEDIUM__))
  74979. # define SMALL_MEDIUM
  74980. # ifdef __BORLANDC__
  74981. # define FAR _far
  74982. # else
  74983. # define FAR far
  74984. # endif
  74985. # endif
  74986. #endif
  74987. #if defined(WINDOWS) || defined(WIN32)
  74988. # ifdef ZLIB_DLL
  74989. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  74990. # ifdef ZLIB_INTERNAL
  74991. # define ZEXTERN extern __declspec(dllexport)
  74992. # else
  74993. # define ZEXTERN extern __declspec(dllimport)
  74994. # endif
  74995. # endif
  74996. # endif /* ZLIB_DLL */
  74997. # ifdef ZLIB_WINAPI
  74998. # ifdef FAR
  74999. # undef FAR
  75000. # endif
  75001. # include <windows.h>
  75002. # define ZEXPORT WINAPI
  75003. # ifdef WIN32
  75004. # define ZEXPORTVA WINAPIV
  75005. # else
  75006. # define ZEXPORTVA FAR CDECL
  75007. # endif
  75008. # endif
  75009. #endif
  75010. #if defined (__BEOS__)
  75011. # ifdef ZLIB_DLL
  75012. # ifdef ZLIB_INTERNAL
  75013. # define ZEXPORT __declspec(dllexport)
  75014. # define ZEXPORTVA __declspec(dllexport)
  75015. # else
  75016. # define ZEXPORT __declspec(dllimport)
  75017. # define ZEXPORTVA __declspec(dllimport)
  75018. # endif
  75019. # endif
  75020. #endif
  75021. #ifndef ZEXTERN
  75022. # define ZEXTERN extern
  75023. #endif
  75024. #ifndef ZEXPORT
  75025. # define ZEXPORT
  75026. #endif
  75027. #ifndef ZEXPORTVA
  75028. # define ZEXPORTVA
  75029. #endif
  75030. #ifndef FAR
  75031. # define FAR
  75032. #endif
  75033. #if !defined(__MACTYPES__)
  75034. typedef unsigned char Byte; /* 8 bits */
  75035. #endif
  75036. typedef unsigned int uInt; /* 16 bits or more */
  75037. typedef unsigned long uLong; /* 32 bits or more */
  75038. #ifdef SMALL_MEDIUM
  75039. # define Bytef Byte FAR
  75040. #else
  75041. typedef Byte FAR Bytef;
  75042. #endif
  75043. typedef char FAR charf;
  75044. typedef int FAR intf;
  75045. typedef uInt FAR uIntf;
  75046. typedef uLong FAR uLongf;
  75047. #ifdef STDC
  75048. typedef void const *voidpc;
  75049. typedef void FAR *voidpf;
  75050. typedef void *voidp;
  75051. #else
  75052. typedef Byte const *voidpc;
  75053. typedef Byte FAR *voidpf;
  75054. typedef Byte *voidp;
  75055. #endif
  75056. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75057. # include <sys/types.h> /* for off_t */
  75058. # include <unistd.h> /* for SEEK_* and off_t */
  75059. # ifdef VMS
  75060. # include <unixio.h> /* for off_t */
  75061. # endif
  75062. # define z_off_t off_t
  75063. #endif
  75064. #ifndef SEEK_SET
  75065. # define SEEK_SET 0 /* Seek from beginning of file. */
  75066. # define SEEK_CUR 1 /* Seek from current position. */
  75067. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75068. #endif
  75069. #ifndef z_off_t
  75070. # define z_off_t long
  75071. #endif
  75072. #if defined(__OS400__)
  75073. # define NO_vsnprintf
  75074. #endif
  75075. #if defined(__MVS__)
  75076. # define NO_vsnprintf
  75077. # ifdef FAR
  75078. # undef FAR
  75079. # endif
  75080. #endif
  75081. #if defined(__MVS__)
  75082. # pragma map(deflateInit_,"DEIN")
  75083. # pragma map(deflateInit2_,"DEIN2")
  75084. # pragma map(deflateEnd,"DEEND")
  75085. # pragma map(deflateBound,"DEBND")
  75086. # pragma map(inflateInit_,"ININ")
  75087. # pragma map(inflateInit2_,"ININ2")
  75088. # pragma map(inflateEnd,"INEND")
  75089. # pragma map(inflateSync,"INSY")
  75090. # pragma map(inflateSetDictionary,"INSEDI")
  75091. # pragma map(compressBound,"CMBND")
  75092. # pragma map(inflate_table,"INTABL")
  75093. # pragma map(inflate_fast,"INFA")
  75094. # pragma map(inflate_copyright,"INCOPY")
  75095. #endif
  75096. #endif /* ZCONF_H */
  75097. /*** End of inlined file: zconf.h ***/
  75098. #ifdef __cplusplus
  75099. extern "C" {
  75100. #endif
  75101. #define ZLIB_VERSION "1.2.3"
  75102. #define ZLIB_VERNUM 0x1230
  75103. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75104. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75105. struct internal_state;
  75106. typedef struct z_stream_s {
  75107. Bytef *next_in; /* next input byte */
  75108. uInt avail_in; /* number of bytes available at next_in */
  75109. uLong total_in; /* total nb of input bytes read so far */
  75110. Bytef *next_out; /* next output byte should be put there */
  75111. uInt avail_out; /* remaining free space at next_out */
  75112. uLong total_out; /* total nb of bytes output so far */
  75113. char *msg; /* last error message, NULL if no error */
  75114. struct internal_state FAR *state; /* not visible by applications */
  75115. alloc_func zalloc; /* used to allocate the internal state */
  75116. free_func zfree; /* used to free the internal state */
  75117. voidpf opaque; /* private data object passed to zalloc and zfree */
  75118. int data_type; /* best guess about the data type: binary or text */
  75119. uLong adler; /* adler32 value of the uncompressed data */
  75120. uLong reserved; /* reserved for future use */
  75121. } z_stream;
  75122. typedef z_stream FAR *z_streamp;
  75123. typedef struct gz_header_s {
  75124. int text; /* true if compressed data believed to be text */
  75125. uLong time; /* modification time */
  75126. int xflags; /* extra flags (not used when writing a gzip file) */
  75127. int os; /* operating system */
  75128. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75129. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75130. uInt extra_max; /* space at extra (only when reading header) */
  75131. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75132. uInt name_max; /* space at name (only when reading header) */
  75133. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75134. uInt comm_max; /* space at comment (only when reading header) */
  75135. int hcrc; /* true if there was or will be a header crc */
  75136. int done; /* true when done reading gzip header (not used
  75137. when writing a gzip file) */
  75138. } gz_header;
  75139. typedef gz_header FAR *gz_headerp;
  75140. #define Z_NO_FLUSH 0
  75141. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75142. #define Z_SYNC_FLUSH 2
  75143. #define Z_FULL_FLUSH 3
  75144. #define Z_FINISH 4
  75145. #define Z_BLOCK 5
  75146. #define Z_OK 0
  75147. #define Z_STREAM_END 1
  75148. #define Z_NEED_DICT 2
  75149. #define Z_ERRNO (-1)
  75150. #define Z_STREAM_ERROR (-2)
  75151. #define Z_DATA_ERROR (-3)
  75152. #define Z_MEM_ERROR (-4)
  75153. #define Z_BUF_ERROR (-5)
  75154. #define Z_VERSION_ERROR (-6)
  75155. #define Z_NO_COMPRESSION 0
  75156. #define Z_BEST_SPEED 1
  75157. #define Z_BEST_COMPRESSION 9
  75158. #define Z_DEFAULT_COMPRESSION (-1)
  75159. #define Z_FILTERED 1
  75160. #define Z_HUFFMAN_ONLY 2
  75161. #define Z_RLE 3
  75162. #define Z_FIXED 4
  75163. #define Z_DEFAULT_STRATEGY 0
  75164. #define Z_BINARY 0
  75165. #define Z_TEXT 1
  75166. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75167. #define Z_UNKNOWN 2
  75168. #define Z_DEFLATED 8
  75169. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75170. #define zlib_version zlibVersion()
  75171. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75172. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75173. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75174. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75175. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75176. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75177. const Bytef *dictionary,
  75178. uInt dictLength));
  75179. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75180. z_streamp source));
  75181. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75182. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75183. int level,
  75184. int strategy));
  75185. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75186. int good_length,
  75187. int max_lazy,
  75188. int nice_length,
  75189. int max_chain));
  75190. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75191. uLong sourceLen));
  75192. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75193. int bits,
  75194. int value));
  75195. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75196. gz_headerp head));
  75197. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75198. const Bytef *dictionary,
  75199. uInt dictLength));
  75200. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75201. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75202. z_streamp source));
  75203. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75204. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75205. int bits,
  75206. int value));
  75207. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75208. gz_headerp head));
  75209. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75210. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75211. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75212. in_func in, void FAR *in_desc,
  75213. out_func out, void FAR *out_desc));
  75214. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75215. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75216. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75217. const Bytef *source, uLong sourceLen));
  75218. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75219. const Bytef *source, uLong sourceLen,
  75220. int level));
  75221. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75222. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75223. const Bytef *source, uLong sourceLen));
  75224. typedef voidp gzFile;
  75225. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75226. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75227. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75228. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75229. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75230. voidpc buf, unsigned len));
  75231. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75232. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75233. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75234. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75235. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75236. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75237. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75238. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75239. z_off_t offset, int whence));
  75240. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75241. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75242. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75243. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75244. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75245. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75246. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75247. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75248. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75249. z_off_t len2));
  75250. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75251. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75252. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75253. const char *version, int stream_size));
  75254. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75255. const char *version, int stream_size));
  75256. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75257. int windowBits, int memLevel,
  75258. int strategy, const char *version,
  75259. int stream_size));
  75260. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75261. const char *version, int stream_size));
  75262. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75263. unsigned char FAR *window,
  75264. const char *version,
  75265. int stream_size));
  75266. #define deflateInit(strm, level) \
  75267. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75268. #define inflateInit(strm) \
  75269. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75270. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75271. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75272. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75273. #define inflateInit2(strm, windowBits) \
  75274. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75275. #define inflateBackInit(strm, windowBits, window) \
  75276. inflateBackInit_((strm), (windowBits), (window), \
  75277. ZLIB_VERSION, sizeof(z_stream))
  75278. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75279. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75280. #endif
  75281. ZEXTERN const char * ZEXPORT zError OF((int));
  75282. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75283. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75284. #ifdef __cplusplus
  75285. }
  75286. #endif
  75287. #endif /* ZLIB_H */
  75288. /*** End of inlined file: zlib.h ***/
  75289. #undef OS_CODE
  75290. #else
  75291. #include <zlib.h>
  75292. #endif
  75293. }
  75294. BEGIN_JUCE_NAMESPACE
  75295. // internal helper object that holds the zlib structures so they don't have to be
  75296. // included publicly.
  75297. class GZIPCompressorHelper
  75298. {
  75299. public:
  75300. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75301. : data (0),
  75302. dataSize (0),
  75303. compLevel (compressionLevel),
  75304. strategy (0),
  75305. setParams (true),
  75306. streamIsValid (false),
  75307. finished (false),
  75308. shouldFinish (false)
  75309. {
  75310. using namespace zlibNamespace;
  75311. zerostruct (stream);
  75312. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75313. nowrap ? -MAX_WBITS : MAX_WBITS,
  75314. 8, strategy) == Z_OK);
  75315. }
  75316. ~GZIPCompressorHelper()
  75317. {
  75318. using namespace zlibNamespace;
  75319. if (streamIsValid)
  75320. deflateEnd (&stream);
  75321. }
  75322. bool needsInput() const throw()
  75323. {
  75324. return dataSize <= 0;
  75325. }
  75326. void setInput (uint8* const newData, const int size) throw()
  75327. {
  75328. data = newData;
  75329. dataSize = size;
  75330. }
  75331. int doNextBlock (uint8* const dest, const int destSize) throw()
  75332. {
  75333. using namespace zlibNamespace;
  75334. if (streamIsValid)
  75335. {
  75336. stream.next_in = data;
  75337. stream.next_out = dest;
  75338. stream.avail_in = dataSize;
  75339. stream.avail_out = destSize;
  75340. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75341. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75342. setParams = false;
  75343. switch (result)
  75344. {
  75345. case Z_STREAM_END:
  75346. finished = true;
  75347. // Deliberate fall-through..
  75348. case Z_OK:
  75349. data += dataSize - stream.avail_in;
  75350. dataSize = stream.avail_in;
  75351. return destSize - stream.avail_out;
  75352. default:
  75353. break;
  75354. }
  75355. }
  75356. return 0;
  75357. }
  75358. private:
  75359. zlibNamespace::z_stream stream;
  75360. uint8* data;
  75361. int dataSize, compLevel, strategy;
  75362. bool setParams, streamIsValid;
  75363. public:
  75364. bool finished, shouldFinish;
  75365. };
  75366. const int gzipCompBufferSize = 32768;
  75367. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75368. int compressionLevel,
  75369. const bool deleteDestStream,
  75370. const bool noWrap)
  75371. : destStream (destStream_),
  75372. streamToDelete (deleteDestStream ? destStream_ : 0),
  75373. buffer (gzipCompBufferSize)
  75374. {
  75375. if (compressionLevel < 1 || compressionLevel > 9)
  75376. compressionLevel = -1;
  75377. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75378. }
  75379. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75380. {
  75381. flush();
  75382. }
  75383. void GZIPCompressorOutputStream::flush()
  75384. {
  75385. if (! helper->finished)
  75386. {
  75387. helper->shouldFinish = true;
  75388. while (! helper->finished)
  75389. doNextBlock();
  75390. }
  75391. destStream->flush();
  75392. }
  75393. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75394. {
  75395. if (! helper->finished)
  75396. {
  75397. helper->setInput ((uint8*) destBuffer, howMany);
  75398. while (! helper->needsInput())
  75399. {
  75400. if (! doNextBlock())
  75401. return false;
  75402. }
  75403. }
  75404. return true;
  75405. }
  75406. bool GZIPCompressorOutputStream::doNextBlock()
  75407. {
  75408. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75409. if (len > 0)
  75410. return destStream->write (buffer, len);
  75411. else
  75412. return true;
  75413. }
  75414. int64 GZIPCompressorOutputStream::getPosition()
  75415. {
  75416. return destStream->getPosition();
  75417. }
  75418. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75419. {
  75420. jassertfalse // can't do it!
  75421. return false;
  75422. }
  75423. END_JUCE_NAMESPACE
  75424. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75425. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75426. #if JUCE_MSVC
  75427. #pragma warning (push)
  75428. #pragma warning (disable: 4309 4305)
  75429. #endif
  75430. namespace zlibNamespace
  75431. {
  75432. #if JUCE_INCLUDE_ZLIB_CODE
  75433. extern "C"
  75434. {
  75435. #undef OS_CODE
  75436. #undef fdopen
  75437. #define ZLIB_INTERNAL
  75438. #define NO_DUMMY_DECL
  75439. /*** Start of inlined file: adler32.c ***/
  75440. #define ZLIB_INTERNAL
  75441. #define BASE 65521UL /* largest prime smaller than 65536 */
  75442. #define NMAX 5552
  75443. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75444. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75445. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75446. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75447. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75448. #ifdef NO_DIVIDE
  75449. # define MOD(a) \
  75450. do { \
  75451. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75452. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75453. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75454. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75455. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75456. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75457. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75458. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75459. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75460. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75461. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75462. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75463. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75464. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75465. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75466. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75467. if (a >= BASE) a -= BASE; \
  75468. } while (0)
  75469. # define MOD4(a) \
  75470. do { \
  75471. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75472. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75473. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75474. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75475. if (a >= BASE) a -= BASE; \
  75476. } while (0)
  75477. #else
  75478. # define MOD(a) a %= BASE
  75479. # define MOD4(a) a %= BASE
  75480. #endif
  75481. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75482. {
  75483. unsigned long sum2;
  75484. unsigned n;
  75485. sum2 = (adler >> 16) & 0xffff;
  75486. adler &= 0xffff;
  75487. if (len == 1) {
  75488. adler += buf[0];
  75489. if (adler >= BASE)
  75490. adler -= BASE;
  75491. sum2 += adler;
  75492. if (sum2 >= BASE)
  75493. sum2 -= BASE;
  75494. return adler | (sum2 << 16);
  75495. }
  75496. if (buf == Z_NULL)
  75497. return 1L;
  75498. if (len < 16) {
  75499. while (len--) {
  75500. adler += *buf++;
  75501. sum2 += adler;
  75502. }
  75503. if (adler >= BASE)
  75504. adler -= BASE;
  75505. MOD4(sum2); /* only added so many BASE's */
  75506. return adler | (sum2 << 16);
  75507. }
  75508. while (len >= NMAX) {
  75509. len -= NMAX;
  75510. n = NMAX / 16; /* NMAX is divisible by 16 */
  75511. do {
  75512. DO16(buf); /* 16 sums unrolled */
  75513. buf += 16;
  75514. } while (--n);
  75515. MOD(adler);
  75516. MOD(sum2);
  75517. }
  75518. if (len) { /* avoid modulos if none remaining */
  75519. while (len >= 16) {
  75520. len -= 16;
  75521. DO16(buf);
  75522. buf += 16;
  75523. }
  75524. while (len--) {
  75525. adler += *buf++;
  75526. sum2 += adler;
  75527. }
  75528. MOD(adler);
  75529. MOD(sum2);
  75530. }
  75531. return adler | (sum2 << 16);
  75532. }
  75533. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75534. {
  75535. unsigned long sum1;
  75536. unsigned long sum2;
  75537. unsigned rem;
  75538. rem = (unsigned)(len2 % BASE);
  75539. sum1 = adler1 & 0xffff;
  75540. sum2 = rem * sum1;
  75541. MOD(sum2);
  75542. sum1 += (adler2 & 0xffff) + BASE - 1;
  75543. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75544. if (sum1 > BASE) sum1 -= BASE;
  75545. if (sum1 > BASE) sum1 -= BASE;
  75546. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75547. if (sum2 > BASE) sum2 -= BASE;
  75548. return sum1 | (sum2 << 16);
  75549. }
  75550. /*** End of inlined file: adler32.c ***/
  75551. /*** Start of inlined file: compress.c ***/
  75552. #define ZLIB_INTERNAL
  75553. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75554. uLong sourceLen, int level)
  75555. {
  75556. z_stream stream;
  75557. int err;
  75558. stream.next_in = (Bytef*)source;
  75559. stream.avail_in = (uInt)sourceLen;
  75560. #ifdef MAXSEG_64K
  75561. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75562. #endif
  75563. stream.next_out = dest;
  75564. stream.avail_out = (uInt)*destLen;
  75565. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75566. stream.zalloc = (alloc_func)0;
  75567. stream.zfree = (free_func)0;
  75568. stream.opaque = (voidpf)0;
  75569. err = deflateInit(&stream, level);
  75570. if (err != Z_OK) return err;
  75571. err = deflate(&stream, Z_FINISH);
  75572. if (err != Z_STREAM_END) {
  75573. deflateEnd(&stream);
  75574. return err == Z_OK ? Z_BUF_ERROR : err;
  75575. }
  75576. *destLen = stream.total_out;
  75577. err = deflateEnd(&stream);
  75578. return err;
  75579. }
  75580. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75581. {
  75582. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75583. }
  75584. uLong ZEXPORT compressBound (uLong sourceLen)
  75585. {
  75586. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75587. }
  75588. /*** End of inlined file: compress.c ***/
  75589. #undef DO1
  75590. #undef DO8
  75591. /*** Start of inlined file: crc32.c ***/
  75592. #ifdef MAKECRCH
  75593. # include <stdio.h>
  75594. # ifndef DYNAMIC_CRC_TABLE
  75595. # define DYNAMIC_CRC_TABLE
  75596. # endif /* !DYNAMIC_CRC_TABLE */
  75597. #endif /* MAKECRCH */
  75598. /*** Start of inlined file: zutil.h ***/
  75599. #ifndef ZUTIL_H
  75600. #define ZUTIL_H
  75601. #define ZLIB_INTERNAL
  75602. #ifdef STDC
  75603. # ifndef _WIN32_WCE
  75604. # include <stddef.h>
  75605. # endif
  75606. # include <string.h>
  75607. # include <stdlib.h>
  75608. #endif
  75609. #ifdef NO_ERRNO_H
  75610. # ifdef _WIN32_WCE
  75611. # define errno z_errno
  75612. # endif
  75613. extern int errno;
  75614. #else
  75615. # ifndef _WIN32_WCE
  75616. # include <errno.h>
  75617. # endif
  75618. #endif
  75619. #ifndef local
  75620. # define local static
  75621. #endif
  75622. typedef unsigned char uch;
  75623. typedef uch FAR uchf;
  75624. typedef unsigned short ush;
  75625. typedef ush FAR ushf;
  75626. typedef unsigned long ulg;
  75627. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75628. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75629. #define ERR_RETURN(strm,err) \
  75630. return (strm->msg = (char*)ERR_MSG(err), (err))
  75631. #ifndef DEF_WBITS
  75632. # define DEF_WBITS MAX_WBITS
  75633. #endif
  75634. #if MAX_MEM_LEVEL >= 8
  75635. # define DEF_MEM_LEVEL 8
  75636. #else
  75637. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75638. #endif
  75639. #define STORED_BLOCK 0
  75640. #define STATIC_TREES 1
  75641. #define DYN_TREES 2
  75642. #define MIN_MATCH 3
  75643. #define MAX_MATCH 258
  75644. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75645. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75646. # define OS_CODE 0x00
  75647. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75648. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75649. void _Cdecl farfree( void *block );
  75650. void *_Cdecl farmalloc( unsigned long nbytes );
  75651. # else
  75652. # include <alloc.h>
  75653. # endif
  75654. # else /* MSC or DJGPP */
  75655. # include <malloc.h>
  75656. # endif
  75657. #endif
  75658. #ifdef AMIGA
  75659. # define OS_CODE 0x01
  75660. #endif
  75661. #if defined(VAXC) || defined(VMS)
  75662. # define OS_CODE 0x02
  75663. # define F_OPEN(name, mode) \
  75664. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75665. #endif
  75666. #if defined(ATARI) || defined(atarist)
  75667. # define OS_CODE 0x05
  75668. #endif
  75669. #ifdef OS2
  75670. # define OS_CODE 0x06
  75671. # ifdef M_I86
  75672. #include <malloc.h>
  75673. # endif
  75674. #endif
  75675. #if defined(MACOS) || TARGET_OS_MAC
  75676. # define OS_CODE 0x07
  75677. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75678. # include <unix.h> /* for fdopen */
  75679. # else
  75680. # ifndef fdopen
  75681. # define fdopen(fd,mode) NULL /* No fdopen() */
  75682. # endif
  75683. # endif
  75684. #endif
  75685. #ifdef TOPS20
  75686. # define OS_CODE 0x0a
  75687. #endif
  75688. #ifdef WIN32
  75689. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75690. # define OS_CODE 0x0b
  75691. # endif
  75692. #endif
  75693. #ifdef __50SERIES /* Prime/PRIMOS */
  75694. # define OS_CODE 0x0f
  75695. #endif
  75696. #if defined(_BEOS_) || defined(RISCOS)
  75697. # define fdopen(fd,mode) NULL /* No fdopen() */
  75698. #endif
  75699. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75700. # if defined(_WIN32_WCE)
  75701. # define fdopen(fd,mode) NULL /* No fdopen() */
  75702. # ifndef _PTRDIFF_T_DEFINED
  75703. typedef int ptrdiff_t;
  75704. # define _PTRDIFF_T_DEFINED
  75705. # endif
  75706. # else
  75707. # define fdopen(fd,type) _fdopen(fd,type)
  75708. # endif
  75709. #endif
  75710. #ifndef OS_CODE
  75711. # define OS_CODE 0x03 /* assume Unix */
  75712. #endif
  75713. #ifndef F_OPEN
  75714. # define F_OPEN(name, mode) fopen((name), (mode))
  75715. #endif
  75716. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75717. # ifndef HAVE_VSNPRINTF
  75718. # define HAVE_VSNPRINTF
  75719. # endif
  75720. #endif
  75721. #if defined(__CYGWIN__)
  75722. # ifndef HAVE_VSNPRINTF
  75723. # define HAVE_VSNPRINTF
  75724. # endif
  75725. #endif
  75726. #ifndef HAVE_VSNPRINTF
  75727. # ifdef MSDOS
  75728. # define NO_vsnprintf
  75729. # endif
  75730. # ifdef __TURBOC__
  75731. # define NO_vsnprintf
  75732. # endif
  75733. # ifdef WIN32
  75734. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75735. # define vsnprintf _vsnprintf
  75736. # endif
  75737. # endif
  75738. # ifdef __SASC
  75739. # define NO_vsnprintf
  75740. # endif
  75741. #endif
  75742. #ifdef VMS
  75743. # define NO_vsnprintf
  75744. #endif
  75745. #if defined(pyr)
  75746. # define NO_MEMCPY
  75747. #endif
  75748. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75749. # define NO_MEMCPY
  75750. #endif
  75751. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75752. # define HAVE_MEMCPY
  75753. #endif
  75754. #ifdef HAVE_MEMCPY
  75755. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75756. # define zmemcpy _fmemcpy
  75757. # define zmemcmp _fmemcmp
  75758. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75759. # else
  75760. # define zmemcpy memcpy
  75761. # define zmemcmp memcmp
  75762. # define zmemzero(dest, len) memset(dest, 0, len)
  75763. # endif
  75764. #else
  75765. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75766. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75767. extern void zmemzero OF((Bytef* dest, uInt len));
  75768. #endif
  75769. #ifdef DEBUG
  75770. # include <stdio.h>
  75771. extern int z_verbose;
  75772. extern void z_error OF((const char *m));
  75773. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75774. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75775. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75776. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75777. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75778. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75779. #else
  75780. # define Assert(cond,msg)
  75781. # define Trace(x)
  75782. # define Tracev(x)
  75783. # define Tracevv(x)
  75784. # define Tracec(c,x)
  75785. # define Tracecv(c,x)
  75786. #endif
  75787. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75788. void zcfree OF((voidpf opaque, voidpf ptr));
  75789. #define ZALLOC(strm, items, size) \
  75790. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75791. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75792. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75793. #endif /* ZUTIL_H */
  75794. /*** End of inlined file: zutil.h ***/
  75795. /* for STDC and FAR definitions */
  75796. #define local static
  75797. #ifndef NOBYFOUR
  75798. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75799. # include <limits.h>
  75800. # define BYFOUR
  75801. # if (UINT_MAX == 0xffffffffUL)
  75802. typedef unsigned int u4;
  75803. # else
  75804. # if (ULONG_MAX == 0xffffffffUL)
  75805. typedef unsigned long u4;
  75806. # else
  75807. # if (USHRT_MAX == 0xffffffffUL)
  75808. typedef unsigned short u4;
  75809. # else
  75810. # undef BYFOUR /* can't find a four-byte integer type! */
  75811. # endif
  75812. # endif
  75813. # endif
  75814. # endif /* STDC */
  75815. #endif /* !NOBYFOUR */
  75816. #ifdef BYFOUR
  75817. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75818. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75819. local unsigned long crc32_little OF((unsigned long,
  75820. const unsigned char FAR *, unsigned));
  75821. local unsigned long crc32_big OF((unsigned long,
  75822. const unsigned char FAR *, unsigned));
  75823. # define TBLS 8
  75824. #else
  75825. # define TBLS 1
  75826. #endif /* BYFOUR */
  75827. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75828. unsigned long vec));
  75829. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75830. #ifdef DYNAMIC_CRC_TABLE
  75831. local volatile int crc_table_empty = 1;
  75832. local unsigned long FAR crc_table[TBLS][256];
  75833. local void make_crc_table OF((void));
  75834. #ifdef MAKECRCH
  75835. local void write_table OF((FILE *, const unsigned long FAR *));
  75836. #endif /* MAKECRCH */
  75837. local void make_crc_table()
  75838. {
  75839. unsigned long c;
  75840. int n, k;
  75841. unsigned long poly; /* polynomial exclusive-or pattern */
  75842. static volatile int first = 1; /* flag to limit concurrent making */
  75843. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75844. if (first) {
  75845. first = 0;
  75846. poly = 0UL;
  75847. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75848. poly |= 1UL << (31 - p[n]);
  75849. for (n = 0; n < 256; n++) {
  75850. c = (unsigned long)n;
  75851. for (k = 0; k < 8; k++)
  75852. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75853. crc_table[0][n] = c;
  75854. }
  75855. #ifdef BYFOUR
  75856. for (n = 0; n < 256; n++) {
  75857. c = crc_table[0][n];
  75858. crc_table[4][n] = REV(c);
  75859. for (k = 1; k < 4; k++) {
  75860. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75861. crc_table[k][n] = c;
  75862. crc_table[k + 4][n] = REV(c);
  75863. }
  75864. }
  75865. #endif /* BYFOUR */
  75866. crc_table_empty = 0;
  75867. }
  75868. else { /* not first */
  75869. while (crc_table_empty)
  75870. ;
  75871. }
  75872. #ifdef MAKECRCH
  75873. {
  75874. FILE *out;
  75875. out = fopen("crc32.h", "w");
  75876. if (out == NULL) return;
  75877. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75878. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75879. fprintf(out, "local const unsigned long FAR ");
  75880. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75881. write_table(out, crc_table[0]);
  75882. # ifdef BYFOUR
  75883. fprintf(out, "#ifdef BYFOUR\n");
  75884. for (k = 1; k < 8; k++) {
  75885. fprintf(out, " },\n {\n");
  75886. write_table(out, crc_table[k]);
  75887. }
  75888. fprintf(out, "#endif\n");
  75889. # endif /* BYFOUR */
  75890. fprintf(out, " }\n};\n");
  75891. fclose(out);
  75892. }
  75893. #endif /* MAKECRCH */
  75894. }
  75895. #ifdef MAKECRCH
  75896. local void write_table(out, table)
  75897. FILE *out;
  75898. const unsigned long FAR *table;
  75899. {
  75900. int n;
  75901. for (n = 0; n < 256; n++)
  75902. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75903. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75904. }
  75905. #endif /* MAKECRCH */
  75906. #else /* !DYNAMIC_CRC_TABLE */
  75907. /*** Start of inlined file: crc32.h ***/
  75908. local const unsigned long FAR crc_table[TBLS][256] =
  75909. {
  75910. {
  75911. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75912. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75913. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75914. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75915. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75916. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75917. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75918. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75919. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  75920. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  75921. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  75922. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  75923. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  75924. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  75925. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  75926. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  75927. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  75928. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  75929. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  75930. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  75931. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  75932. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  75933. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  75934. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  75935. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  75936. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  75937. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  75938. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  75939. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  75940. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  75941. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  75942. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  75943. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  75944. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  75945. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  75946. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  75947. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  75948. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  75949. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  75950. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  75951. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  75952. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  75953. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  75954. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  75955. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  75956. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  75957. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  75958. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  75959. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  75960. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  75961. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  75962. 0x2d02ef8dUL
  75963. #ifdef BYFOUR
  75964. },
  75965. {
  75966. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  75967. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  75968. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  75969. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  75970. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  75971. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  75972. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  75973. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  75974. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  75975. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  75976. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  75977. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  75978. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  75979. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  75980. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  75981. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  75982. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  75983. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  75984. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  75985. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  75986. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  75987. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  75988. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  75989. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  75990. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  75991. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  75992. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  75993. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  75994. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  75995. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  75996. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  75997. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  75998. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  75999. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  76000. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  76001. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  76002. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  76003. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  76004. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  76005. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  76006. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  76007. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76008. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76009. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76010. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76011. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76012. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76013. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76014. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76015. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76016. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76017. 0x9324fd72UL
  76018. },
  76019. {
  76020. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76021. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76022. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76023. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76024. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76025. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76026. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76027. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76028. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76029. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76030. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76031. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76032. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76033. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76034. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76035. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76036. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76037. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76038. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76039. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76040. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76041. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76042. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76043. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76044. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76045. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76046. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76047. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76048. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76049. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76050. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76051. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76052. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76053. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76054. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76055. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76056. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76057. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76058. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76059. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76060. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76061. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76062. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76063. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76064. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76065. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76066. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76067. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76068. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76069. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76070. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76071. 0xbe9834edUL
  76072. },
  76073. {
  76074. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76075. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76076. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76077. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76078. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76079. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76080. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76081. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76082. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76083. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76084. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76085. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76086. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76087. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76088. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76089. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76090. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76091. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76092. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76093. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76094. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76095. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76096. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76097. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76098. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76099. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76100. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76101. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76102. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76103. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76104. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76105. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76106. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76107. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76108. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76109. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76110. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76111. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76112. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76113. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76114. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76115. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76116. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76117. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76118. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76119. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76120. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76121. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76122. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76123. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76124. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76125. 0xde0506f1UL
  76126. },
  76127. {
  76128. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76129. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76130. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76131. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76132. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76133. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76134. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76135. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76136. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76137. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76138. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76139. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76140. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76141. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76142. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76143. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76144. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76145. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76146. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76147. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76148. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76149. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76150. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76151. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76152. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76153. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76154. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76155. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76156. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76157. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76158. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76159. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76160. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76161. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76162. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76163. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76164. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76165. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76166. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76167. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76168. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76169. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76170. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76171. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76172. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76173. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76174. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76175. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76176. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76177. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76178. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76179. 0x8def022dUL
  76180. },
  76181. {
  76182. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76183. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76184. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76185. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76186. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76187. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76188. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76189. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76190. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76191. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76192. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76193. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76194. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76195. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76196. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76197. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76198. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76199. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76200. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76201. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76202. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76203. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76204. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76205. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76206. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76207. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76208. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76209. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76210. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76211. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76212. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76213. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76214. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76215. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76216. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76217. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76218. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76219. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76220. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76221. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76222. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76223. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76224. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76225. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76226. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76227. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76228. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76229. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76230. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76231. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76232. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76233. 0x72fd2493UL
  76234. },
  76235. {
  76236. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76237. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76238. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76239. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76240. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76241. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76242. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76243. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76244. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76245. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76246. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76247. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76248. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76249. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76250. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76251. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76252. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76253. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76254. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76255. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76256. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76257. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76258. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76259. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76260. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76261. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76262. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76263. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76264. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76265. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76266. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76267. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76268. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76269. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76270. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76271. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76272. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76273. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76274. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76275. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76276. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76277. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76278. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76279. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76280. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76281. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76282. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76283. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76284. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76285. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76286. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76287. 0xed3498beUL
  76288. },
  76289. {
  76290. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76291. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76292. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76293. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76294. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76295. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76296. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76297. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76298. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76299. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76300. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76301. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76302. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76303. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76304. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76305. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76306. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76307. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76308. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76309. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76310. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76311. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76312. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76313. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76314. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76315. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76316. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76317. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76318. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76319. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76320. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76321. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76322. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76323. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76324. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76325. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76326. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76327. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76328. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76329. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76330. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76331. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76332. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76333. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76334. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76335. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76336. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76337. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76338. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76339. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76340. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76341. 0xf10605deUL
  76342. #endif
  76343. }
  76344. };
  76345. /*** End of inlined file: crc32.h ***/
  76346. #endif /* DYNAMIC_CRC_TABLE */
  76347. const unsigned long FAR * ZEXPORT get_crc_table()
  76348. {
  76349. #ifdef DYNAMIC_CRC_TABLE
  76350. if (crc_table_empty)
  76351. make_crc_table();
  76352. #endif /* DYNAMIC_CRC_TABLE */
  76353. return (const unsigned long FAR *)crc_table;
  76354. }
  76355. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76356. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76357. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76358. {
  76359. if (buf == Z_NULL) return 0UL;
  76360. #ifdef DYNAMIC_CRC_TABLE
  76361. if (crc_table_empty)
  76362. make_crc_table();
  76363. #endif /* DYNAMIC_CRC_TABLE */
  76364. #ifdef BYFOUR
  76365. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76366. u4 endian;
  76367. endian = 1;
  76368. if (*((unsigned char *)(&endian)))
  76369. return crc32_little(crc, buf, len);
  76370. else
  76371. return crc32_big(crc, buf, len);
  76372. }
  76373. #endif /* BYFOUR */
  76374. crc = crc ^ 0xffffffffUL;
  76375. while (len >= 8) {
  76376. DO8;
  76377. len -= 8;
  76378. }
  76379. if (len) do {
  76380. DO1;
  76381. } while (--len);
  76382. return crc ^ 0xffffffffUL;
  76383. }
  76384. #ifdef BYFOUR
  76385. #define DOLIT4 c ^= *buf4++; \
  76386. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76387. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76388. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76389. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76390. {
  76391. register u4 c;
  76392. register const u4 FAR *buf4;
  76393. c = (u4)crc;
  76394. c = ~c;
  76395. while (len && ((ptrdiff_t)buf & 3)) {
  76396. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76397. len--;
  76398. }
  76399. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76400. while (len >= 32) {
  76401. DOLIT32;
  76402. len -= 32;
  76403. }
  76404. while (len >= 4) {
  76405. DOLIT4;
  76406. len -= 4;
  76407. }
  76408. buf = (const unsigned char FAR *)buf4;
  76409. if (len) do {
  76410. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76411. } while (--len);
  76412. c = ~c;
  76413. return (unsigned long)c;
  76414. }
  76415. #define DOBIG4 c ^= *++buf4; \
  76416. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76417. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76418. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76419. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76420. {
  76421. register u4 c;
  76422. register const u4 FAR *buf4;
  76423. c = REV((u4)crc);
  76424. c = ~c;
  76425. while (len && ((ptrdiff_t)buf & 3)) {
  76426. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76427. len--;
  76428. }
  76429. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76430. buf4--;
  76431. while (len >= 32) {
  76432. DOBIG32;
  76433. len -= 32;
  76434. }
  76435. while (len >= 4) {
  76436. DOBIG4;
  76437. len -= 4;
  76438. }
  76439. buf4++;
  76440. buf = (const unsigned char FAR *)buf4;
  76441. if (len) do {
  76442. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76443. } while (--len);
  76444. c = ~c;
  76445. return (unsigned long)(REV(c));
  76446. }
  76447. #endif /* BYFOUR */
  76448. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76449. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76450. {
  76451. unsigned long sum;
  76452. sum = 0;
  76453. while (vec) {
  76454. if (vec & 1)
  76455. sum ^= *mat;
  76456. vec >>= 1;
  76457. mat++;
  76458. }
  76459. return sum;
  76460. }
  76461. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76462. {
  76463. int n;
  76464. for (n = 0; n < GF2_DIM; n++)
  76465. square[n] = gf2_matrix_times(mat, mat[n]);
  76466. }
  76467. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76468. {
  76469. int n;
  76470. unsigned long row;
  76471. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76472. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76473. if (len2 == 0)
  76474. return crc1;
  76475. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76476. row = 1;
  76477. for (n = 1; n < GF2_DIM; n++) {
  76478. odd[n] = row;
  76479. row <<= 1;
  76480. }
  76481. gf2_matrix_square(even, odd);
  76482. gf2_matrix_square(odd, even);
  76483. do {
  76484. gf2_matrix_square(even, odd);
  76485. if (len2 & 1)
  76486. crc1 = gf2_matrix_times(even, crc1);
  76487. len2 >>= 1;
  76488. if (len2 == 0)
  76489. break;
  76490. gf2_matrix_square(odd, even);
  76491. if (len2 & 1)
  76492. crc1 = gf2_matrix_times(odd, crc1);
  76493. len2 >>= 1;
  76494. } while (len2 != 0);
  76495. crc1 ^= crc2;
  76496. return crc1;
  76497. }
  76498. /*** End of inlined file: crc32.c ***/
  76499. /*** Start of inlined file: deflate.c ***/
  76500. /*** Start of inlined file: deflate.h ***/
  76501. #ifndef DEFLATE_H
  76502. #define DEFLATE_H
  76503. #ifndef NO_GZIP
  76504. # define GZIP
  76505. #endif
  76506. #define NO_DUMMY_DECL
  76507. #define LENGTH_CODES 29
  76508. #define LITERALS 256
  76509. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76510. #define D_CODES 30
  76511. #define BL_CODES 19
  76512. #define HEAP_SIZE (2*L_CODES+1)
  76513. #define MAX_BITS 15
  76514. #define INIT_STATE 42
  76515. #define EXTRA_STATE 69
  76516. #define NAME_STATE 73
  76517. #define COMMENT_STATE 91
  76518. #define HCRC_STATE 103
  76519. #define BUSY_STATE 113
  76520. #define FINISH_STATE 666
  76521. typedef struct ct_data_s {
  76522. union {
  76523. ush freq; /* frequency count */
  76524. ush code; /* bit string */
  76525. } fc;
  76526. union {
  76527. ush dad; /* father node in Huffman tree */
  76528. ush len; /* length of bit string */
  76529. } dl;
  76530. } FAR ct_data;
  76531. #define Freq fc.freq
  76532. #define Code fc.code
  76533. #define Dad dl.dad
  76534. #define Len dl.len
  76535. typedef struct static_tree_desc_s static_tree_desc;
  76536. typedef struct tree_desc_s {
  76537. ct_data *dyn_tree; /* the dynamic tree */
  76538. int max_code; /* largest code with non zero frequency */
  76539. static_tree_desc *stat_desc; /* the corresponding static tree */
  76540. } FAR tree_desc;
  76541. typedef ush Pos;
  76542. typedef Pos FAR Posf;
  76543. typedef unsigned IPos;
  76544. typedef struct internal_state {
  76545. z_streamp strm; /* pointer back to this zlib stream */
  76546. int status; /* as the name implies */
  76547. Bytef *pending_buf; /* output still pending */
  76548. ulg pending_buf_size; /* size of pending_buf */
  76549. Bytef *pending_out; /* next pending byte to output to the stream */
  76550. uInt pending; /* nb of bytes in the pending buffer */
  76551. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76552. gz_headerp gzhead; /* gzip header information to write */
  76553. uInt gzindex; /* where in extra, name, or comment */
  76554. Byte method; /* STORED (for zip only) or DEFLATED */
  76555. int last_flush; /* value of flush param for previous deflate call */
  76556. uInt w_size; /* LZ77 window size (32K by default) */
  76557. uInt w_bits; /* log2(w_size) (8..16) */
  76558. uInt w_mask; /* w_size - 1 */
  76559. Bytef *window;
  76560. ulg window_size;
  76561. Posf *prev;
  76562. Posf *head; /* Heads of the hash chains or NIL. */
  76563. uInt ins_h; /* hash index of string to be inserted */
  76564. uInt hash_size; /* number of elements in hash table */
  76565. uInt hash_bits; /* log2(hash_size) */
  76566. uInt hash_mask; /* hash_size-1 */
  76567. uInt hash_shift;
  76568. long block_start;
  76569. uInt match_length; /* length of best match */
  76570. IPos prev_match; /* previous match */
  76571. int match_available; /* set if previous match exists */
  76572. uInt strstart; /* start of string to insert */
  76573. uInt match_start; /* start of matching string */
  76574. uInt lookahead; /* number of valid bytes ahead in window */
  76575. uInt prev_length;
  76576. uInt max_chain_length;
  76577. uInt max_lazy_match;
  76578. # define max_insert_length max_lazy_match
  76579. int level; /* compression level (1..9) */
  76580. int strategy; /* favor or force Huffman coding*/
  76581. uInt good_match;
  76582. int nice_match; /* Stop searching when current match exceeds this */
  76583. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76584. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76585. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76586. struct tree_desc_s l_desc; /* desc. for literal tree */
  76587. struct tree_desc_s d_desc; /* desc. for distance tree */
  76588. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76589. ush bl_count[MAX_BITS+1];
  76590. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76591. int heap_len; /* number of elements in the heap */
  76592. int heap_max; /* element of largest frequency */
  76593. uch depth[2*L_CODES+1];
  76594. uchf *l_buf; /* buffer for literals or lengths */
  76595. uInt lit_bufsize;
  76596. uInt last_lit; /* running index in l_buf */
  76597. ushf *d_buf;
  76598. ulg opt_len; /* bit length of current block with optimal trees */
  76599. ulg static_len; /* bit length of current block with static trees */
  76600. uInt matches; /* number of string matches in current block */
  76601. int last_eob_len; /* bit length of EOB code for last block */
  76602. #ifdef DEBUG
  76603. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76604. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76605. #endif
  76606. ush bi_buf;
  76607. int bi_valid;
  76608. } FAR deflate_state;
  76609. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76610. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76611. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76612. void _tr_init OF((deflate_state *s));
  76613. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76614. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76615. int eof));
  76616. void _tr_align OF((deflate_state *s));
  76617. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76618. int eof));
  76619. #define d_code(dist) \
  76620. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76621. #ifndef DEBUG
  76622. #if defined(GEN_TREES_H) || !defined(STDC)
  76623. extern uch _length_code[];
  76624. extern uch _dist_code[];
  76625. #else
  76626. extern const uch _length_code[];
  76627. extern const uch _dist_code[];
  76628. #endif
  76629. # define _tr_tally_lit(s, c, flush) \
  76630. { uch cc = (c); \
  76631. s->d_buf[s->last_lit] = 0; \
  76632. s->l_buf[s->last_lit++] = cc; \
  76633. s->dyn_ltree[cc].Freq++; \
  76634. flush = (s->last_lit == s->lit_bufsize-1); \
  76635. }
  76636. # define _tr_tally_dist(s, distance, length, flush) \
  76637. { uch len = (length); \
  76638. ush dist = (distance); \
  76639. s->d_buf[s->last_lit] = dist; \
  76640. s->l_buf[s->last_lit++] = len; \
  76641. dist--; \
  76642. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76643. s->dyn_dtree[d_code(dist)].Freq++; \
  76644. flush = (s->last_lit == s->lit_bufsize-1); \
  76645. }
  76646. #else
  76647. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76648. # define _tr_tally_dist(s, distance, length, flush) \
  76649. flush = _tr_tally(s, distance, length)
  76650. #endif
  76651. #endif /* DEFLATE_H */
  76652. /*** End of inlined file: deflate.h ***/
  76653. const char deflate_copyright[] =
  76654. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76655. typedef enum {
  76656. need_more, /* block not completed, need more input or more output */
  76657. block_done, /* block flush performed */
  76658. finish_started, /* finish started, need only more output at next deflate */
  76659. finish_done /* finish done, accept no more input or output */
  76660. } block_state;
  76661. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76662. local void fill_window OF((deflate_state *s));
  76663. local block_state deflate_stored OF((deflate_state *s, int flush));
  76664. local block_state deflate_fast OF((deflate_state *s, int flush));
  76665. #ifndef FASTEST
  76666. local block_state deflate_slow OF((deflate_state *s, int flush));
  76667. #endif
  76668. local void lm_init OF((deflate_state *s));
  76669. local void putShortMSB OF((deflate_state *s, uInt b));
  76670. local void flush_pending OF((z_streamp strm));
  76671. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76672. #ifndef FASTEST
  76673. #ifdef ASMV
  76674. void match_init OF((void)); /* asm code initialization */
  76675. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76676. #else
  76677. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76678. #endif
  76679. #endif
  76680. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76681. #ifdef DEBUG
  76682. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76683. int length));
  76684. #endif
  76685. #define NIL 0
  76686. #ifndef TOO_FAR
  76687. # define TOO_FAR 4096
  76688. #endif
  76689. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76690. typedef struct config_s {
  76691. ush good_length; /* reduce lazy search above this match length */
  76692. ush max_lazy; /* do not perform lazy search above this match length */
  76693. ush nice_length; /* quit search above this match length */
  76694. ush max_chain;
  76695. compress_func func;
  76696. } config;
  76697. #ifdef FASTEST
  76698. local const config configuration_table[2] = {
  76699. {0, 0, 0, 0, deflate_stored}, /* store only */
  76700. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76701. #else
  76702. local const config configuration_table[10] = {
  76703. {0, 0, 0, 0, deflate_stored}, /* store only */
  76704. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76705. {4, 5, 16, 8, deflate_fast},
  76706. {4, 6, 32, 32, deflate_fast},
  76707. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76708. {8, 16, 32, 32, deflate_slow},
  76709. {8, 16, 128, 128, deflate_slow},
  76710. {8, 32, 128, 256, deflate_slow},
  76711. {32, 128, 258, 1024, deflate_slow},
  76712. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76713. #endif
  76714. #define EQUAL 0
  76715. #ifndef NO_DUMMY_DECL
  76716. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76717. #endif
  76718. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76719. #ifdef FASTEST
  76720. #define INSERT_STRING(s, str, match_head) \
  76721. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76722. match_head = s->head[s->ins_h], \
  76723. s->head[s->ins_h] = (Pos)(str))
  76724. #else
  76725. #define INSERT_STRING(s, str, match_head) \
  76726. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76727. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76728. s->head[s->ins_h] = (Pos)(str))
  76729. #endif
  76730. #define CLEAR_HASH(s) \
  76731. s->head[s->hash_size-1] = NIL; \
  76732. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76733. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76734. {
  76735. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76736. Z_DEFAULT_STRATEGY, version, stream_size);
  76737. }
  76738. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76739. {
  76740. deflate_state *s;
  76741. int wrap = 1;
  76742. static const char my_version[] = ZLIB_VERSION;
  76743. ushf *overlay;
  76744. if (version == Z_NULL || version[0] != my_version[0] ||
  76745. stream_size != sizeof(z_stream)) {
  76746. return Z_VERSION_ERROR;
  76747. }
  76748. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76749. strm->msg = Z_NULL;
  76750. if (strm->zalloc == (alloc_func)0) {
  76751. strm->zalloc = zcalloc;
  76752. strm->opaque = (voidpf)0;
  76753. }
  76754. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76755. #ifdef FASTEST
  76756. if (level != 0) level = 1;
  76757. #else
  76758. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76759. #endif
  76760. if (windowBits < 0) { /* suppress zlib wrapper */
  76761. wrap = 0;
  76762. windowBits = -windowBits;
  76763. }
  76764. #ifdef GZIP
  76765. else if (windowBits > 15) {
  76766. wrap = 2; /* write gzip wrapper instead */
  76767. windowBits -= 16;
  76768. }
  76769. #endif
  76770. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76771. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76772. strategy < 0 || strategy > Z_FIXED) {
  76773. return Z_STREAM_ERROR;
  76774. }
  76775. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76776. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76777. if (s == Z_NULL) return Z_MEM_ERROR;
  76778. strm->state = (struct internal_state FAR *)s;
  76779. s->strm = strm;
  76780. s->wrap = wrap;
  76781. s->gzhead = Z_NULL;
  76782. s->w_bits = windowBits;
  76783. s->w_size = 1 << s->w_bits;
  76784. s->w_mask = s->w_size - 1;
  76785. s->hash_bits = memLevel + 7;
  76786. s->hash_size = 1 << s->hash_bits;
  76787. s->hash_mask = s->hash_size - 1;
  76788. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76789. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76790. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76791. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76792. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76793. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76794. s->pending_buf = (uchf *) overlay;
  76795. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76796. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76797. s->pending_buf == Z_NULL) {
  76798. s->status = FINISH_STATE;
  76799. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76800. deflateEnd (strm);
  76801. return Z_MEM_ERROR;
  76802. }
  76803. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76804. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76805. s->level = level;
  76806. s->strategy = strategy;
  76807. s->method = (Byte)method;
  76808. return deflateReset(strm);
  76809. }
  76810. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76811. {
  76812. deflate_state *s;
  76813. uInt length = dictLength;
  76814. uInt n;
  76815. IPos hash_head = 0;
  76816. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76817. strm->state->wrap == 2 ||
  76818. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76819. return Z_STREAM_ERROR;
  76820. s = strm->state;
  76821. if (s->wrap)
  76822. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76823. if (length < MIN_MATCH) return Z_OK;
  76824. if (length > MAX_DIST(s)) {
  76825. length = MAX_DIST(s);
  76826. dictionary += dictLength - length; /* use the tail of the dictionary */
  76827. }
  76828. zmemcpy(s->window, dictionary, length);
  76829. s->strstart = length;
  76830. s->block_start = (long)length;
  76831. s->ins_h = s->window[0];
  76832. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76833. for (n = 0; n <= length - MIN_MATCH; n++) {
  76834. INSERT_STRING(s, n, hash_head);
  76835. }
  76836. if (hash_head) hash_head = 0; /* to make compiler happy */
  76837. return Z_OK;
  76838. }
  76839. int ZEXPORT deflateReset (z_streamp strm)
  76840. {
  76841. deflate_state *s;
  76842. if (strm == Z_NULL || strm->state == Z_NULL ||
  76843. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76844. return Z_STREAM_ERROR;
  76845. }
  76846. strm->total_in = strm->total_out = 0;
  76847. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76848. strm->data_type = Z_UNKNOWN;
  76849. s = (deflate_state *)strm->state;
  76850. s->pending = 0;
  76851. s->pending_out = s->pending_buf;
  76852. if (s->wrap < 0) {
  76853. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76854. }
  76855. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76856. strm->adler =
  76857. #ifdef GZIP
  76858. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76859. #endif
  76860. adler32(0L, Z_NULL, 0);
  76861. s->last_flush = Z_NO_FLUSH;
  76862. _tr_init(s);
  76863. lm_init(s);
  76864. return Z_OK;
  76865. }
  76866. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76867. {
  76868. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76869. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76870. strm->state->gzhead = head;
  76871. return Z_OK;
  76872. }
  76873. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76874. {
  76875. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76876. strm->state->bi_valid = bits;
  76877. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76878. return Z_OK;
  76879. }
  76880. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76881. {
  76882. deflate_state *s;
  76883. compress_func func;
  76884. int err = Z_OK;
  76885. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76886. s = strm->state;
  76887. #ifdef FASTEST
  76888. if (level != 0) level = 1;
  76889. #else
  76890. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76891. #endif
  76892. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76893. return Z_STREAM_ERROR;
  76894. }
  76895. func = configuration_table[s->level].func;
  76896. if (func != configuration_table[level].func && strm->total_in != 0) {
  76897. err = deflate(strm, Z_PARTIAL_FLUSH);
  76898. }
  76899. if (s->level != level) {
  76900. s->level = level;
  76901. s->max_lazy_match = configuration_table[level].max_lazy;
  76902. s->good_match = configuration_table[level].good_length;
  76903. s->nice_match = configuration_table[level].nice_length;
  76904. s->max_chain_length = configuration_table[level].max_chain;
  76905. }
  76906. s->strategy = strategy;
  76907. return err;
  76908. }
  76909. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76910. {
  76911. deflate_state *s;
  76912. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76913. s = strm->state;
  76914. s->good_match = good_length;
  76915. s->max_lazy_match = max_lazy;
  76916. s->nice_match = nice_length;
  76917. s->max_chain_length = max_chain;
  76918. return Z_OK;
  76919. }
  76920. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  76921. {
  76922. deflate_state *s;
  76923. uLong destLen;
  76924. destLen = sourceLen +
  76925. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  76926. if (strm == Z_NULL || strm->state == Z_NULL)
  76927. return destLen;
  76928. s = strm->state;
  76929. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  76930. return destLen;
  76931. return compressBound(sourceLen);
  76932. }
  76933. local void putShortMSB (deflate_state *s, uInt b)
  76934. {
  76935. put_byte(s, (Byte)(b >> 8));
  76936. put_byte(s, (Byte)(b & 0xff));
  76937. }
  76938. local void flush_pending (z_streamp strm)
  76939. {
  76940. unsigned len = strm->state->pending;
  76941. if (len > strm->avail_out) len = strm->avail_out;
  76942. if (len == 0) return;
  76943. zmemcpy(strm->next_out, strm->state->pending_out, len);
  76944. strm->next_out += len;
  76945. strm->state->pending_out += len;
  76946. strm->total_out += len;
  76947. strm->avail_out -= len;
  76948. strm->state->pending -= len;
  76949. if (strm->state->pending == 0) {
  76950. strm->state->pending_out = strm->state->pending_buf;
  76951. }
  76952. }
  76953. int ZEXPORT deflate (z_streamp strm, int flush)
  76954. {
  76955. int old_flush; /* value of flush param for previous deflate call */
  76956. deflate_state *s;
  76957. if (strm == Z_NULL || strm->state == Z_NULL ||
  76958. flush > Z_FINISH || flush < 0) {
  76959. return Z_STREAM_ERROR;
  76960. }
  76961. s = strm->state;
  76962. if (strm->next_out == Z_NULL ||
  76963. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  76964. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  76965. ERR_RETURN(strm, Z_STREAM_ERROR);
  76966. }
  76967. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  76968. s->strm = strm; /* just in case */
  76969. old_flush = s->last_flush;
  76970. s->last_flush = flush;
  76971. if (s->status == INIT_STATE) {
  76972. #ifdef GZIP
  76973. if (s->wrap == 2) {
  76974. strm->adler = crc32(0L, Z_NULL, 0);
  76975. put_byte(s, 31);
  76976. put_byte(s, 139);
  76977. put_byte(s, 8);
  76978. if (s->gzhead == NULL) {
  76979. put_byte(s, 0);
  76980. put_byte(s, 0);
  76981. put_byte(s, 0);
  76982. put_byte(s, 0);
  76983. put_byte(s, 0);
  76984. put_byte(s, s->level == 9 ? 2 :
  76985. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76986. 4 : 0));
  76987. put_byte(s, OS_CODE);
  76988. s->status = BUSY_STATE;
  76989. }
  76990. else {
  76991. put_byte(s, (s->gzhead->text ? 1 : 0) +
  76992. (s->gzhead->hcrc ? 2 : 0) +
  76993. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  76994. (s->gzhead->name == Z_NULL ? 0 : 8) +
  76995. (s->gzhead->comment == Z_NULL ? 0 : 16)
  76996. );
  76997. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  76998. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  76999. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  77000. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  77001. put_byte(s, s->level == 9 ? 2 :
  77002. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77003. 4 : 0));
  77004. put_byte(s, s->gzhead->os & 0xff);
  77005. if (s->gzhead->extra != NULL) {
  77006. put_byte(s, s->gzhead->extra_len & 0xff);
  77007. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77008. }
  77009. if (s->gzhead->hcrc)
  77010. strm->adler = crc32(strm->adler, s->pending_buf,
  77011. s->pending);
  77012. s->gzindex = 0;
  77013. s->status = EXTRA_STATE;
  77014. }
  77015. }
  77016. else
  77017. #endif
  77018. {
  77019. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77020. uInt level_flags;
  77021. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77022. level_flags = 0;
  77023. else if (s->level < 6)
  77024. level_flags = 1;
  77025. else if (s->level == 6)
  77026. level_flags = 2;
  77027. else
  77028. level_flags = 3;
  77029. header |= (level_flags << 6);
  77030. if (s->strstart != 0) header |= PRESET_DICT;
  77031. header += 31 - (header % 31);
  77032. s->status = BUSY_STATE;
  77033. putShortMSB(s, header);
  77034. if (s->strstart != 0) {
  77035. putShortMSB(s, (uInt)(strm->adler >> 16));
  77036. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77037. }
  77038. strm->adler = adler32(0L, Z_NULL, 0);
  77039. }
  77040. }
  77041. #ifdef GZIP
  77042. if (s->status == EXTRA_STATE) {
  77043. if (s->gzhead->extra != NULL) {
  77044. uInt beg = s->pending; /* start of bytes to update crc */
  77045. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77046. if (s->pending == s->pending_buf_size) {
  77047. if (s->gzhead->hcrc && s->pending > beg)
  77048. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77049. s->pending - beg);
  77050. flush_pending(strm);
  77051. beg = s->pending;
  77052. if (s->pending == s->pending_buf_size)
  77053. break;
  77054. }
  77055. put_byte(s, s->gzhead->extra[s->gzindex]);
  77056. s->gzindex++;
  77057. }
  77058. if (s->gzhead->hcrc && s->pending > beg)
  77059. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77060. s->pending - beg);
  77061. if (s->gzindex == s->gzhead->extra_len) {
  77062. s->gzindex = 0;
  77063. s->status = NAME_STATE;
  77064. }
  77065. }
  77066. else
  77067. s->status = NAME_STATE;
  77068. }
  77069. if (s->status == NAME_STATE) {
  77070. if (s->gzhead->name != NULL) {
  77071. uInt beg = s->pending; /* start of bytes to update crc */
  77072. int val;
  77073. do {
  77074. if (s->pending == s->pending_buf_size) {
  77075. if (s->gzhead->hcrc && s->pending > beg)
  77076. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77077. s->pending - beg);
  77078. flush_pending(strm);
  77079. beg = s->pending;
  77080. if (s->pending == s->pending_buf_size) {
  77081. val = 1;
  77082. break;
  77083. }
  77084. }
  77085. val = s->gzhead->name[s->gzindex++];
  77086. put_byte(s, val);
  77087. } while (val != 0);
  77088. if (s->gzhead->hcrc && s->pending > beg)
  77089. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77090. s->pending - beg);
  77091. if (val == 0) {
  77092. s->gzindex = 0;
  77093. s->status = COMMENT_STATE;
  77094. }
  77095. }
  77096. else
  77097. s->status = COMMENT_STATE;
  77098. }
  77099. if (s->status == COMMENT_STATE) {
  77100. if (s->gzhead->comment != NULL) {
  77101. uInt beg = s->pending; /* start of bytes to update crc */
  77102. int val;
  77103. do {
  77104. if (s->pending == s->pending_buf_size) {
  77105. if (s->gzhead->hcrc && s->pending > beg)
  77106. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77107. s->pending - beg);
  77108. flush_pending(strm);
  77109. beg = s->pending;
  77110. if (s->pending == s->pending_buf_size) {
  77111. val = 1;
  77112. break;
  77113. }
  77114. }
  77115. val = s->gzhead->comment[s->gzindex++];
  77116. put_byte(s, val);
  77117. } while (val != 0);
  77118. if (s->gzhead->hcrc && s->pending > beg)
  77119. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77120. s->pending - beg);
  77121. if (val == 0)
  77122. s->status = HCRC_STATE;
  77123. }
  77124. else
  77125. s->status = HCRC_STATE;
  77126. }
  77127. if (s->status == HCRC_STATE) {
  77128. if (s->gzhead->hcrc) {
  77129. if (s->pending + 2 > s->pending_buf_size)
  77130. flush_pending(strm);
  77131. if (s->pending + 2 <= s->pending_buf_size) {
  77132. put_byte(s, (Byte)(strm->adler & 0xff));
  77133. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77134. strm->adler = crc32(0L, Z_NULL, 0);
  77135. s->status = BUSY_STATE;
  77136. }
  77137. }
  77138. else
  77139. s->status = BUSY_STATE;
  77140. }
  77141. #endif
  77142. if (s->pending != 0) {
  77143. flush_pending(strm);
  77144. if (strm->avail_out == 0) {
  77145. s->last_flush = -1;
  77146. return Z_OK;
  77147. }
  77148. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77149. flush != Z_FINISH) {
  77150. ERR_RETURN(strm, Z_BUF_ERROR);
  77151. }
  77152. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77153. ERR_RETURN(strm, Z_BUF_ERROR);
  77154. }
  77155. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77156. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77157. block_state bstate;
  77158. bstate = (*(configuration_table[s->level].func))(s, flush);
  77159. if (bstate == finish_started || bstate == finish_done) {
  77160. s->status = FINISH_STATE;
  77161. }
  77162. if (bstate == need_more || bstate == finish_started) {
  77163. if (strm->avail_out == 0) {
  77164. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77165. }
  77166. return Z_OK;
  77167. }
  77168. if (bstate == block_done) {
  77169. if (flush == Z_PARTIAL_FLUSH) {
  77170. _tr_align(s);
  77171. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77172. _tr_stored_block(s, (char*)0, 0L, 0);
  77173. if (flush == Z_FULL_FLUSH) {
  77174. CLEAR_HASH(s); /* forget history */
  77175. }
  77176. }
  77177. flush_pending(strm);
  77178. if (strm->avail_out == 0) {
  77179. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77180. return Z_OK;
  77181. }
  77182. }
  77183. }
  77184. Assert(strm->avail_out > 0, "bug2");
  77185. if (flush != Z_FINISH) return Z_OK;
  77186. if (s->wrap <= 0) return Z_STREAM_END;
  77187. #ifdef GZIP
  77188. if (s->wrap == 2) {
  77189. put_byte(s, (Byte)(strm->adler & 0xff));
  77190. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77191. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77192. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77193. put_byte(s, (Byte)(strm->total_in & 0xff));
  77194. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77195. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77196. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77197. }
  77198. else
  77199. #endif
  77200. {
  77201. putShortMSB(s, (uInt)(strm->adler >> 16));
  77202. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77203. }
  77204. flush_pending(strm);
  77205. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77206. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77207. }
  77208. int ZEXPORT deflateEnd (z_streamp strm)
  77209. {
  77210. int status;
  77211. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77212. status = strm->state->status;
  77213. if (status != INIT_STATE &&
  77214. status != EXTRA_STATE &&
  77215. status != NAME_STATE &&
  77216. status != COMMENT_STATE &&
  77217. status != HCRC_STATE &&
  77218. status != BUSY_STATE &&
  77219. status != FINISH_STATE) {
  77220. return Z_STREAM_ERROR;
  77221. }
  77222. TRY_FREE(strm, strm->state->pending_buf);
  77223. TRY_FREE(strm, strm->state->head);
  77224. TRY_FREE(strm, strm->state->prev);
  77225. TRY_FREE(strm, strm->state->window);
  77226. ZFREE(strm, strm->state);
  77227. strm->state = Z_NULL;
  77228. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77229. }
  77230. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77231. {
  77232. #ifdef MAXSEG_64K
  77233. return Z_STREAM_ERROR;
  77234. #else
  77235. deflate_state *ds;
  77236. deflate_state *ss;
  77237. ushf *overlay;
  77238. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77239. return Z_STREAM_ERROR;
  77240. }
  77241. ss = source->state;
  77242. zmemcpy(dest, source, sizeof(z_stream));
  77243. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77244. if (ds == Z_NULL) return Z_MEM_ERROR;
  77245. dest->state = (struct internal_state FAR *) ds;
  77246. zmemcpy(ds, ss, sizeof(deflate_state));
  77247. ds->strm = dest;
  77248. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77249. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77250. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77251. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77252. ds->pending_buf = (uchf *) overlay;
  77253. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77254. ds->pending_buf == Z_NULL) {
  77255. deflateEnd (dest);
  77256. return Z_MEM_ERROR;
  77257. }
  77258. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77259. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77260. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77261. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77262. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77263. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77264. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77265. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77266. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77267. ds->bl_desc.dyn_tree = ds->bl_tree;
  77268. return Z_OK;
  77269. #endif /* MAXSEG_64K */
  77270. }
  77271. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77272. {
  77273. unsigned len = strm->avail_in;
  77274. if (len > size) len = size;
  77275. if (len == 0) return 0;
  77276. strm->avail_in -= len;
  77277. if (strm->state->wrap == 1) {
  77278. strm->adler = adler32(strm->adler, strm->next_in, len);
  77279. }
  77280. #ifdef GZIP
  77281. else if (strm->state->wrap == 2) {
  77282. strm->adler = crc32(strm->adler, strm->next_in, len);
  77283. }
  77284. #endif
  77285. zmemcpy(buf, strm->next_in, len);
  77286. strm->next_in += len;
  77287. strm->total_in += len;
  77288. return (int)len;
  77289. }
  77290. local void lm_init (deflate_state *s)
  77291. {
  77292. s->window_size = (ulg)2L*s->w_size;
  77293. CLEAR_HASH(s);
  77294. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77295. s->good_match = configuration_table[s->level].good_length;
  77296. s->nice_match = configuration_table[s->level].nice_length;
  77297. s->max_chain_length = configuration_table[s->level].max_chain;
  77298. s->strstart = 0;
  77299. s->block_start = 0L;
  77300. s->lookahead = 0;
  77301. s->match_length = s->prev_length = MIN_MATCH-1;
  77302. s->match_available = 0;
  77303. s->ins_h = 0;
  77304. #ifndef FASTEST
  77305. #ifdef ASMV
  77306. match_init(); /* initialize the asm code */
  77307. #endif
  77308. #endif
  77309. }
  77310. #ifndef FASTEST
  77311. #ifndef ASMV
  77312. local uInt longest_match(deflate_state *s, IPos cur_match)
  77313. {
  77314. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77315. register Bytef *scan = s->window + s->strstart; /* current string */
  77316. register Bytef *match; /* matched string */
  77317. register int len; /* length of current match */
  77318. int best_len = s->prev_length; /* best match length so far */
  77319. int nice_match = s->nice_match; /* stop if match long enough */
  77320. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77321. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77322. Posf *prev = s->prev;
  77323. uInt wmask = s->w_mask;
  77324. #ifdef UNALIGNED_OK
  77325. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77326. register ush scan_start = *(ushf*)scan;
  77327. register ush scan_end = *(ushf*)(scan+best_len-1);
  77328. #else
  77329. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77330. register Byte scan_end1 = scan[best_len-1];
  77331. register Byte scan_end = scan[best_len];
  77332. #endif
  77333. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77334. if (s->prev_length >= s->good_match) {
  77335. chain_length >>= 2;
  77336. }
  77337. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77338. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77339. do {
  77340. Assert(cur_match < s->strstart, "no future");
  77341. match = s->window + cur_match;
  77342. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77343. if (*(ushf*)(match+best_len-1) != scan_end ||
  77344. *(ushf*)match != scan_start) continue;
  77345. Assert(scan[2] == match[2], "scan[2]?");
  77346. scan++, match++;
  77347. do {
  77348. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77349. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77350. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77351. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77352. scan < strend);
  77353. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77354. if (*scan == *match) scan++;
  77355. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77356. scan = strend - (MAX_MATCH-1);
  77357. #else /* UNALIGNED_OK */
  77358. if (match[best_len] != scan_end ||
  77359. match[best_len-1] != scan_end1 ||
  77360. *match != *scan ||
  77361. *++match != scan[1]) continue;
  77362. scan += 2, match++;
  77363. Assert(*scan == *match, "match[2]?");
  77364. do {
  77365. } while (*++scan == *++match && *++scan == *++match &&
  77366. *++scan == *++match && *++scan == *++match &&
  77367. *++scan == *++match && *++scan == *++match &&
  77368. *++scan == *++match && *++scan == *++match &&
  77369. scan < strend);
  77370. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77371. len = MAX_MATCH - (int)(strend - scan);
  77372. scan = strend - MAX_MATCH;
  77373. #endif /* UNALIGNED_OK */
  77374. if (len > best_len) {
  77375. s->match_start = cur_match;
  77376. best_len = len;
  77377. if (len >= nice_match) break;
  77378. #ifdef UNALIGNED_OK
  77379. scan_end = *(ushf*)(scan+best_len-1);
  77380. #else
  77381. scan_end1 = scan[best_len-1];
  77382. scan_end = scan[best_len];
  77383. #endif
  77384. }
  77385. } while ((cur_match = prev[cur_match & wmask]) > limit
  77386. && --chain_length != 0);
  77387. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77388. return s->lookahead;
  77389. }
  77390. #endif /* ASMV */
  77391. #endif /* FASTEST */
  77392. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77393. {
  77394. register Bytef *scan = s->window + s->strstart; /* current string */
  77395. register Bytef *match; /* matched string */
  77396. register int len; /* length of current match */
  77397. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77398. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77399. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77400. Assert(cur_match < s->strstart, "no future");
  77401. match = s->window + cur_match;
  77402. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77403. scan += 2, match += 2;
  77404. Assert(*scan == *match, "match[2]?");
  77405. do {
  77406. } while (*++scan == *++match && *++scan == *++match &&
  77407. *++scan == *++match && *++scan == *++match &&
  77408. *++scan == *++match && *++scan == *++match &&
  77409. *++scan == *++match && *++scan == *++match &&
  77410. scan < strend);
  77411. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77412. len = MAX_MATCH - (int)(strend - scan);
  77413. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77414. s->match_start = cur_match;
  77415. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77416. }
  77417. #ifdef DEBUG
  77418. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77419. {
  77420. if (zmemcmp(s->window + match,
  77421. s->window + start, length) != EQUAL) {
  77422. fprintf(stderr, " start %u, match %u, length %d\n",
  77423. start, match, length);
  77424. do {
  77425. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77426. } while (--length != 0);
  77427. z_error("invalid match");
  77428. }
  77429. if (z_verbose > 1) {
  77430. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77431. do { putc(s->window[start++], stderr); } while (--length != 0);
  77432. }
  77433. }
  77434. #else
  77435. # define check_match(s, start, match, length)
  77436. #endif /* DEBUG */
  77437. local void fill_window (deflate_state *s)
  77438. {
  77439. register unsigned n, m;
  77440. register Posf *p;
  77441. unsigned more; /* Amount of free space at the end of the window. */
  77442. uInt wsize = s->w_size;
  77443. do {
  77444. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77445. if (sizeof(int) <= 2) {
  77446. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77447. more = wsize;
  77448. } else if (more == (unsigned)(-1)) {
  77449. more--;
  77450. }
  77451. }
  77452. if (s->strstart >= wsize+MAX_DIST(s)) {
  77453. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77454. s->match_start -= wsize;
  77455. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77456. s->block_start -= (long) wsize;
  77457. n = s->hash_size;
  77458. p = &s->head[n];
  77459. do {
  77460. m = *--p;
  77461. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77462. } while (--n);
  77463. n = wsize;
  77464. #ifndef FASTEST
  77465. p = &s->prev[n];
  77466. do {
  77467. m = *--p;
  77468. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77469. } while (--n);
  77470. #endif
  77471. more += wsize;
  77472. }
  77473. if (s->strm->avail_in == 0) return;
  77474. Assert(more >= 2, "more < 2");
  77475. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77476. s->lookahead += n;
  77477. if (s->lookahead >= MIN_MATCH) {
  77478. s->ins_h = s->window[s->strstart];
  77479. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77480. #if MIN_MATCH != 3
  77481. Call UPDATE_HASH() MIN_MATCH-3 more times
  77482. #endif
  77483. }
  77484. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77485. }
  77486. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77487. _tr_flush_block(s, (s->block_start >= 0L ? \
  77488. (charf *)&s->window[(unsigned)s->block_start] : \
  77489. (charf *)Z_NULL), \
  77490. (ulg)((long)s->strstart - s->block_start), \
  77491. (eof)); \
  77492. s->block_start = s->strstart; \
  77493. flush_pending(s->strm); \
  77494. Tracev((stderr,"[FLUSH]")); \
  77495. }
  77496. #define FLUSH_BLOCK(s, eof) { \
  77497. FLUSH_BLOCK_ONLY(s, eof); \
  77498. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77499. }
  77500. local block_state deflate_stored(deflate_state *s, int flush)
  77501. {
  77502. ulg max_block_size = 0xffff;
  77503. ulg max_start;
  77504. if (max_block_size > s->pending_buf_size - 5) {
  77505. max_block_size = s->pending_buf_size - 5;
  77506. }
  77507. for (;;) {
  77508. if (s->lookahead <= 1) {
  77509. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77510. s->block_start >= (long)s->w_size, "slide too late");
  77511. fill_window(s);
  77512. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77513. if (s->lookahead == 0) break; /* flush the current block */
  77514. }
  77515. Assert(s->block_start >= 0L, "block gone");
  77516. s->strstart += s->lookahead;
  77517. s->lookahead = 0;
  77518. max_start = s->block_start + max_block_size;
  77519. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77520. s->lookahead = (uInt)(s->strstart - max_start);
  77521. s->strstart = (uInt)max_start;
  77522. FLUSH_BLOCK(s, 0);
  77523. }
  77524. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77525. FLUSH_BLOCK(s, 0);
  77526. }
  77527. }
  77528. FLUSH_BLOCK(s, flush == Z_FINISH);
  77529. return flush == Z_FINISH ? finish_done : block_done;
  77530. }
  77531. local block_state deflate_fast(deflate_state *s, int flush)
  77532. {
  77533. IPos hash_head = NIL; /* head of the hash chain */
  77534. int bflush; /* set if current block must be flushed */
  77535. for (;;) {
  77536. if (s->lookahead < MIN_LOOKAHEAD) {
  77537. fill_window(s);
  77538. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77539. return need_more;
  77540. }
  77541. if (s->lookahead == 0) break; /* flush the current block */
  77542. }
  77543. if (s->lookahead >= MIN_MATCH) {
  77544. INSERT_STRING(s, s->strstart, hash_head);
  77545. }
  77546. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77547. #ifdef FASTEST
  77548. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77549. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77550. s->match_length = longest_match_fast (s, hash_head);
  77551. }
  77552. #else
  77553. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77554. s->match_length = longest_match (s, hash_head);
  77555. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77556. s->match_length = longest_match_fast (s, hash_head);
  77557. }
  77558. #endif
  77559. }
  77560. if (s->match_length >= MIN_MATCH) {
  77561. check_match(s, s->strstart, s->match_start, s->match_length);
  77562. _tr_tally_dist(s, s->strstart - s->match_start,
  77563. s->match_length - MIN_MATCH, bflush);
  77564. s->lookahead -= s->match_length;
  77565. #ifndef FASTEST
  77566. if (s->match_length <= s->max_insert_length &&
  77567. s->lookahead >= MIN_MATCH) {
  77568. s->match_length--; /* string at strstart already in table */
  77569. do {
  77570. s->strstart++;
  77571. INSERT_STRING(s, s->strstart, hash_head);
  77572. } while (--s->match_length != 0);
  77573. s->strstart++;
  77574. } else
  77575. #endif
  77576. {
  77577. s->strstart += s->match_length;
  77578. s->match_length = 0;
  77579. s->ins_h = s->window[s->strstart];
  77580. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77581. #if MIN_MATCH != 3
  77582. Call UPDATE_HASH() MIN_MATCH-3 more times
  77583. #endif
  77584. }
  77585. } else {
  77586. Tracevv((stderr,"%c", s->window[s->strstart]));
  77587. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77588. s->lookahead--;
  77589. s->strstart++;
  77590. }
  77591. if (bflush) FLUSH_BLOCK(s, 0);
  77592. }
  77593. FLUSH_BLOCK(s, flush == Z_FINISH);
  77594. return flush == Z_FINISH ? finish_done : block_done;
  77595. }
  77596. #ifndef FASTEST
  77597. local block_state deflate_slow(deflate_state *s, int flush)
  77598. {
  77599. IPos hash_head = NIL; /* head of hash chain */
  77600. int bflush; /* set if current block must be flushed */
  77601. for (;;) {
  77602. if (s->lookahead < MIN_LOOKAHEAD) {
  77603. fill_window(s);
  77604. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77605. return need_more;
  77606. }
  77607. if (s->lookahead == 0) break; /* flush the current block */
  77608. }
  77609. if (s->lookahead >= MIN_MATCH) {
  77610. INSERT_STRING(s, s->strstart, hash_head);
  77611. }
  77612. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77613. s->match_length = MIN_MATCH-1;
  77614. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77615. s->strstart - hash_head <= MAX_DIST(s)) {
  77616. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77617. s->match_length = longest_match (s, hash_head);
  77618. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77619. s->match_length = longest_match_fast (s, hash_head);
  77620. }
  77621. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77622. #if TOO_FAR <= 32767
  77623. || (s->match_length == MIN_MATCH &&
  77624. s->strstart - s->match_start > TOO_FAR)
  77625. #endif
  77626. )) {
  77627. s->match_length = MIN_MATCH-1;
  77628. }
  77629. }
  77630. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77631. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77632. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77633. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77634. s->prev_length - MIN_MATCH, bflush);
  77635. s->lookahead -= s->prev_length-1;
  77636. s->prev_length -= 2;
  77637. do {
  77638. if (++s->strstart <= max_insert) {
  77639. INSERT_STRING(s, s->strstart, hash_head);
  77640. }
  77641. } while (--s->prev_length != 0);
  77642. s->match_available = 0;
  77643. s->match_length = MIN_MATCH-1;
  77644. s->strstart++;
  77645. if (bflush) FLUSH_BLOCK(s, 0);
  77646. } else if (s->match_available) {
  77647. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77648. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77649. if (bflush) {
  77650. FLUSH_BLOCK_ONLY(s, 0);
  77651. }
  77652. s->strstart++;
  77653. s->lookahead--;
  77654. if (s->strm->avail_out == 0) return need_more;
  77655. } else {
  77656. s->match_available = 1;
  77657. s->strstart++;
  77658. s->lookahead--;
  77659. }
  77660. }
  77661. Assert (flush != Z_NO_FLUSH, "no flush?");
  77662. if (s->match_available) {
  77663. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77664. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77665. s->match_available = 0;
  77666. }
  77667. FLUSH_BLOCK(s, flush == Z_FINISH);
  77668. return flush == Z_FINISH ? finish_done : block_done;
  77669. }
  77670. #endif /* FASTEST */
  77671. #if 0
  77672. local block_state deflate_rle(s, flush)
  77673. deflate_state *s;
  77674. int flush;
  77675. {
  77676. int bflush; /* set if current block must be flushed */
  77677. uInt run; /* length of run */
  77678. uInt max; /* maximum length of run */
  77679. uInt prev; /* byte at distance one to match */
  77680. Bytef *scan; /* scan for end of run */
  77681. for (;;) {
  77682. if (s->lookahead < MAX_MATCH) {
  77683. fill_window(s);
  77684. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77685. return need_more;
  77686. }
  77687. if (s->lookahead == 0) break; /* flush the current block */
  77688. }
  77689. run = 0;
  77690. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77691. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77692. scan = s->window + s->strstart - 1;
  77693. prev = *scan++;
  77694. do {
  77695. if (*scan++ != prev)
  77696. break;
  77697. } while (++run < max);
  77698. }
  77699. if (run >= MIN_MATCH) {
  77700. check_match(s, s->strstart, s->strstart - 1, run);
  77701. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77702. s->lookahead -= run;
  77703. s->strstart += run;
  77704. } else {
  77705. Tracevv((stderr,"%c", s->window[s->strstart]));
  77706. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77707. s->lookahead--;
  77708. s->strstart++;
  77709. }
  77710. if (bflush) FLUSH_BLOCK(s, 0);
  77711. }
  77712. FLUSH_BLOCK(s, flush == Z_FINISH);
  77713. return flush == Z_FINISH ? finish_done : block_done;
  77714. }
  77715. #endif
  77716. /*** End of inlined file: deflate.c ***/
  77717. /*** Start of inlined file: inffast.c ***/
  77718. /*** Start of inlined file: inftrees.h ***/
  77719. #ifndef _INFTREES_H_
  77720. #define _INFTREES_H_
  77721. typedef struct {
  77722. unsigned char op; /* operation, extra bits, table bits */
  77723. unsigned char bits; /* bits in this part of the code */
  77724. unsigned short val; /* offset in table or code value */
  77725. } code;
  77726. #define ENOUGH 2048
  77727. #define MAXD 592
  77728. typedef enum {
  77729. CODES,
  77730. LENS,
  77731. DISTS
  77732. } codetype;
  77733. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77734. unsigned codes, code FAR * FAR *table,
  77735. unsigned FAR *bits, unsigned short FAR *work));
  77736. #endif
  77737. /*** End of inlined file: inftrees.h ***/
  77738. /*** Start of inlined file: inflate.h ***/
  77739. #ifndef _INFLATE_H_
  77740. #define _INFLATE_H_
  77741. #ifndef NO_GZIP
  77742. # define GUNZIP
  77743. #endif
  77744. typedef enum {
  77745. HEAD, /* i: waiting for magic header */
  77746. FLAGS, /* i: waiting for method and flags (gzip) */
  77747. TIME, /* i: waiting for modification time (gzip) */
  77748. OS, /* i: waiting for extra flags and operating system (gzip) */
  77749. EXLEN, /* i: waiting for extra length (gzip) */
  77750. EXTRA, /* i: waiting for extra bytes (gzip) */
  77751. NAME, /* i: waiting for end of file name (gzip) */
  77752. COMMENT, /* i: waiting for end of comment (gzip) */
  77753. HCRC, /* i: waiting for header crc (gzip) */
  77754. DICTID, /* i: waiting for dictionary check value */
  77755. DICT, /* waiting for inflateSetDictionary() call */
  77756. TYPE, /* i: waiting for type bits, including last-flag bit */
  77757. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77758. STORED, /* i: waiting for stored size (length and complement) */
  77759. COPY, /* i/o: waiting for input or output to copy stored block */
  77760. TABLE, /* i: waiting for dynamic block table lengths */
  77761. LENLENS, /* i: waiting for code length code lengths */
  77762. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77763. LEN, /* i: waiting for length/lit code */
  77764. LENEXT, /* i: waiting for length extra bits */
  77765. DIST, /* i: waiting for distance code */
  77766. DISTEXT, /* i: waiting for distance extra bits */
  77767. MATCH, /* o: waiting for output space to copy string */
  77768. LIT, /* o: waiting for output space to write literal */
  77769. CHECK, /* i: waiting for 32-bit check value */
  77770. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77771. DONE, /* finished check, done -- remain here until reset */
  77772. BAD, /* got a data error -- remain here until reset */
  77773. MEM, /* got an inflate() memory error -- remain here until reset */
  77774. SYNC /* looking for synchronization bytes to restart inflate() */
  77775. } inflate_mode;
  77776. struct inflate_state {
  77777. inflate_mode mode; /* current inflate mode */
  77778. int last; /* true if processing last block */
  77779. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77780. int havedict; /* true if dictionary provided */
  77781. int flags; /* gzip header method and flags (0 if zlib) */
  77782. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77783. unsigned long check; /* protected copy of check value */
  77784. unsigned long total; /* protected copy of output count */
  77785. gz_headerp head; /* where to save gzip header information */
  77786. unsigned wbits; /* log base 2 of requested window size */
  77787. unsigned wsize; /* window size or zero if not using window */
  77788. unsigned whave; /* valid bytes in the window */
  77789. unsigned write; /* window write index */
  77790. unsigned char FAR *window; /* allocated sliding window, if needed */
  77791. unsigned long hold; /* input bit accumulator */
  77792. unsigned bits; /* number of bits in "in" */
  77793. unsigned length; /* literal or length of data to copy */
  77794. unsigned offset; /* distance back to copy string from */
  77795. unsigned extra; /* extra bits needed */
  77796. code const FAR *lencode; /* starting table for length/literal codes */
  77797. code const FAR *distcode; /* starting table for distance codes */
  77798. unsigned lenbits; /* index bits for lencode */
  77799. unsigned distbits; /* index bits for distcode */
  77800. unsigned ncode; /* number of code length code lengths */
  77801. unsigned nlen; /* number of length code lengths */
  77802. unsigned ndist; /* number of distance code lengths */
  77803. unsigned have; /* number of code lengths in lens[] */
  77804. code FAR *next; /* next available space in codes[] */
  77805. unsigned short lens[320]; /* temporary storage for code lengths */
  77806. unsigned short work[288]; /* work area for code table building */
  77807. code codes[ENOUGH]; /* space for code tables */
  77808. };
  77809. #endif
  77810. /*** End of inlined file: inflate.h ***/
  77811. /*** Start of inlined file: inffast.h ***/
  77812. void inflate_fast OF((z_streamp strm, unsigned start));
  77813. /*** End of inlined file: inffast.h ***/
  77814. #ifndef ASMINF
  77815. #ifdef POSTINC
  77816. # define OFF 0
  77817. # define PUP(a) *(a)++
  77818. #else
  77819. # define OFF 1
  77820. # define PUP(a) *++(a)
  77821. #endif
  77822. void inflate_fast (z_streamp strm, unsigned start)
  77823. {
  77824. struct inflate_state FAR *state;
  77825. unsigned char FAR *in; /* local strm->next_in */
  77826. unsigned char FAR *last; /* while in < last, enough input available */
  77827. unsigned char FAR *out; /* local strm->next_out */
  77828. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77829. unsigned char FAR *end; /* while out < end, enough space available */
  77830. #ifdef INFLATE_STRICT
  77831. unsigned dmax; /* maximum distance from zlib header */
  77832. #endif
  77833. unsigned wsize; /* window size or zero if not using window */
  77834. unsigned whave; /* valid bytes in the window */
  77835. unsigned write; /* window write index */
  77836. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77837. unsigned long hold; /* local strm->hold */
  77838. unsigned bits; /* local strm->bits */
  77839. code const FAR *lcode; /* local strm->lencode */
  77840. code const FAR *dcode; /* local strm->distcode */
  77841. unsigned lmask; /* mask for first level of length codes */
  77842. unsigned dmask; /* mask for first level of distance codes */
  77843. code thisx; /* retrieved table entry */
  77844. unsigned op; /* code bits, operation, extra bits, or */
  77845. unsigned len; /* match length, unused bytes */
  77846. unsigned dist; /* match distance */
  77847. unsigned char FAR *from; /* where to copy match from */
  77848. state = (struct inflate_state FAR *)strm->state;
  77849. in = strm->next_in - OFF;
  77850. last = in + (strm->avail_in - 5);
  77851. out = strm->next_out - OFF;
  77852. beg = out - (start - strm->avail_out);
  77853. end = out + (strm->avail_out - 257);
  77854. #ifdef INFLATE_STRICT
  77855. dmax = state->dmax;
  77856. #endif
  77857. wsize = state->wsize;
  77858. whave = state->whave;
  77859. write = state->write;
  77860. window = state->window;
  77861. hold = state->hold;
  77862. bits = state->bits;
  77863. lcode = state->lencode;
  77864. dcode = state->distcode;
  77865. lmask = (1U << state->lenbits) - 1;
  77866. dmask = (1U << state->distbits) - 1;
  77867. do {
  77868. if (bits < 15) {
  77869. hold += (unsigned long)(PUP(in)) << bits;
  77870. bits += 8;
  77871. hold += (unsigned long)(PUP(in)) << bits;
  77872. bits += 8;
  77873. }
  77874. thisx = lcode[hold & lmask];
  77875. dolen:
  77876. op = (unsigned)(thisx.bits);
  77877. hold >>= op;
  77878. bits -= op;
  77879. op = (unsigned)(thisx.op);
  77880. if (op == 0) { /* literal */
  77881. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77882. "inflate: literal '%c'\n" :
  77883. "inflate: literal 0x%02x\n", thisx.val));
  77884. PUP(out) = (unsigned char)(thisx.val);
  77885. }
  77886. else if (op & 16) { /* length base */
  77887. len = (unsigned)(thisx.val);
  77888. op &= 15; /* number of extra bits */
  77889. if (op) {
  77890. if (bits < op) {
  77891. hold += (unsigned long)(PUP(in)) << bits;
  77892. bits += 8;
  77893. }
  77894. len += (unsigned)hold & ((1U << op) - 1);
  77895. hold >>= op;
  77896. bits -= op;
  77897. }
  77898. Tracevv((stderr, "inflate: length %u\n", len));
  77899. if (bits < 15) {
  77900. hold += (unsigned long)(PUP(in)) << bits;
  77901. bits += 8;
  77902. hold += (unsigned long)(PUP(in)) << bits;
  77903. bits += 8;
  77904. }
  77905. thisx = dcode[hold & dmask];
  77906. dodist:
  77907. op = (unsigned)(thisx.bits);
  77908. hold >>= op;
  77909. bits -= op;
  77910. op = (unsigned)(thisx.op);
  77911. if (op & 16) { /* distance base */
  77912. dist = (unsigned)(thisx.val);
  77913. op &= 15; /* number of extra bits */
  77914. if (bits < op) {
  77915. hold += (unsigned long)(PUP(in)) << bits;
  77916. bits += 8;
  77917. if (bits < op) {
  77918. hold += (unsigned long)(PUP(in)) << bits;
  77919. bits += 8;
  77920. }
  77921. }
  77922. dist += (unsigned)hold & ((1U << op) - 1);
  77923. #ifdef INFLATE_STRICT
  77924. if (dist > dmax) {
  77925. strm->msg = (char *)"invalid distance too far back";
  77926. state->mode = BAD;
  77927. break;
  77928. }
  77929. #endif
  77930. hold >>= op;
  77931. bits -= op;
  77932. Tracevv((stderr, "inflate: distance %u\n", dist));
  77933. op = (unsigned)(out - beg); /* max distance in output */
  77934. if (dist > op) { /* see if copy from window */
  77935. op = dist - op; /* distance back in window */
  77936. if (op > whave) {
  77937. strm->msg = (char *)"invalid distance too far back";
  77938. state->mode = BAD;
  77939. break;
  77940. }
  77941. from = window - OFF;
  77942. if (write == 0) { /* very common case */
  77943. from += wsize - op;
  77944. if (op < len) { /* some from window */
  77945. len -= op;
  77946. do {
  77947. PUP(out) = PUP(from);
  77948. } while (--op);
  77949. from = out - dist; /* rest from output */
  77950. }
  77951. }
  77952. else if (write < op) { /* wrap around window */
  77953. from += wsize + write - op;
  77954. op -= write;
  77955. if (op < len) { /* some from end of window */
  77956. len -= op;
  77957. do {
  77958. PUP(out) = PUP(from);
  77959. } while (--op);
  77960. from = window - OFF;
  77961. if (write < len) { /* some from start of window */
  77962. op = write;
  77963. len -= op;
  77964. do {
  77965. PUP(out) = PUP(from);
  77966. } while (--op);
  77967. from = out - dist; /* rest from output */
  77968. }
  77969. }
  77970. }
  77971. else { /* contiguous in window */
  77972. from += write - op;
  77973. if (op < len) { /* some from window */
  77974. len -= op;
  77975. do {
  77976. PUP(out) = PUP(from);
  77977. } while (--op);
  77978. from = out - dist; /* rest from output */
  77979. }
  77980. }
  77981. while (len > 2) {
  77982. PUP(out) = PUP(from);
  77983. PUP(out) = PUP(from);
  77984. PUP(out) = PUP(from);
  77985. len -= 3;
  77986. }
  77987. if (len) {
  77988. PUP(out) = PUP(from);
  77989. if (len > 1)
  77990. PUP(out) = PUP(from);
  77991. }
  77992. }
  77993. else {
  77994. from = out - dist; /* copy direct from output */
  77995. do { /* minimum length is three */
  77996. PUP(out) = PUP(from);
  77997. PUP(out) = PUP(from);
  77998. PUP(out) = PUP(from);
  77999. len -= 3;
  78000. } while (len > 2);
  78001. if (len) {
  78002. PUP(out) = PUP(from);
  78003. if (len > 1)
  78004. PUP(out) = PUP(from);
  78005. }
  78006. }
  78007. }
  78008. else if ((op & 64) == 0) { /* 2nd level distance code */
  78009. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78010. goto dodist;
  78011. }
  78012. else {
  78013. strm->msg = (char *)"invalid distance code";
  78014. state->mode = BAD;
  78015. break;
  78016. }
  78017. }
  78018. else if ((op & 64) == 0) { /* 2nd level length code */
  78019. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78020. goto dolen;
  78021. }
  78022. else if (op & 32) { /* end-of-block */
  78023. Tracevv((stderr, "inflate: end of block\n"));
  78024. state->mode = TYPE;
  78025. break;
  78026. }
  78027. else {
  78028. strm->msg = (char *)"invalid literal/length code";
  78029. state->mode = BAD;
  78030. break;
  78031. }
  78032. } while (in < last && out < end);
  78033. len = bits >> 3;
  78034. in -= len;
  78035. bits -= len << 3;
  78036. hold &= (1U << bits) - 1;
  78037. strm->next_in = in + OFF;
  78038. strm->next_out = out + OFF;
  78039. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78040. strm->avail_out = (unsigned)(out < end ?
  78041. 257 + (end - out) : 257 - (out - end));
  78042. state->hold = hold;
  78043. state->bits = bits;
  78044. return;
  78045. }
  78046. #endif /* !ASMINF */
  78047. /*** End of inlined file: inffast.c ***/
  78048. #undef PULLBYTE
  78049. #undef LOAD
  78050. #undef RESTORE
  78051. #undef INITBITS
  78052. #undef NEEDBITS
  78053. #undef DROPBITS
  78054. #undef BYTEBITS
  78055. /*** Start of inlined file: inflate.c ***/
  78056. /*** Start of inlined file: inffast.h ***/
  78057. void inflate_fast OF((z_streamp strm, unsigned start));
  78058. /*** End of inlined file: inffast.h ***/
  78059. #ifdef MAKEFIXED
  78060. # ifndef BUILDFIXED
  78061. # define BUILDFIXED
  78062. # endif
  78063. #endif
  78064. local void fixedtables OF((struct inflate_state FAR *state));
  78065. local int updatewindow OF((z_streamp strm, unsigned out));
  78066. #ifdef BUILDFIXED
  78067. void makefixed OF((void));
  78068. #endif
  78069. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78070. unsigned len));
  78071. int ZEXPORT inflateReset (z_streamp strm)
  78072. {
  78073. struct inflate_state FAR *state;
  78074. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78075. state = (struct inflate_state FAR *)strm->state;
  78076. strm->total_in = strm->total_out = state->total = 0;
  78077. strm->msg = Z_NULL;
  78078. strm->adler = 1; /* to support ill-conceived Java test suite */
  78079. state->mode = HEAD;
  78080. state->last = 0;
  78081. state->havedict = 0;
  78082. state->dmax = 32768U;
  78083. state->head = Z_NULL;
  78084. state->wsize = 0;
  78085. state->whave = 0;
  78086. state->write = 0;
  78087. state->hold = 0;
  78088. state->bits = 0;
  78089. state->lencode = state->distcode = state->next = state->codes;
  78090. Tracev((stderr, "inflate: reset\n"));
  78091. return Z_OK;
  78092. }
  78093. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78094. {
  78095. struct inflate_state FAR *state;
  78096. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78097. state = (struct inflate_state FAR *)strm->state;
  78098. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78099. value &= (1L << bits) - 1;
  78100. state->hold += value << state->bits;
  78101. state->bits += bits;
  78102. return Z_OK;
  78103. }
  78104. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78105. {
  78106. struct inflate_state FAR *state;
  78107. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78108. stream_size != (int)(sizeof(z_stream)))
  78109. return Z_VERSION_ERROR;
  78110. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78111. strm->msg = Z_NULL; /* in case we return an error */
  78112. if (strm->zalloc == (alloc_func)0) {
  78113. strm->zalloc = zcalloc;
  78114. strm->opaque = (voidpf)0;
  78115. }
  78116. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78117. state = (struct inflate_state FAR *)
  78118. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78119. if (state == Z_NULL) return Z_MEM_ERROR;
  78120. Tracev((stderr, "inflate: allocated\n"));
  78121. strm->state = (struct internal_state FAR *)state;
  78122. if (windowBits < 0) {
  78123. state->wrap = 0;
  78124. windowBits = -windowBits;
  78125. }
  78126. else {
  78127. state->wrap = (windowBits >> 4) + 1;
  78128. #ifdef GUNZIP
  78129. if (windowBits < 48) windowBits &= 15;
  78130. #endif
  78131. }
  78132. if (windowBits < 8 || windowBits > 15) {
  78133. ZFREE(strm, state);
  78134. strm->state = Z_NULL;
  78135. return Z_STREAM_ERROR;
  78136. }
  78137. state->wbits = (unsigned)windowBits;
  78138. state->window = Z_NULL;
  78139. return inflateReset(strm);
  78140. }
  78141. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78142. {
  78143. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78144. }
  78145. local void fixedtables (struct inflate_state FAR *state)
  78146. {
  78147. #ifdef BUILDFIXED
  78148. static int virgin = 1;
  78149. static code *lenfix, *distfix;
  78150. static code fixed[544];
  78151. if (virgin) {
  78152. unsigned sym, bits;
  78153. static code *next;
  78154. sym = 0;
  78155. while (sym < 144) state->lens[sym++] = 8;
  78156. while (sym < 256) state->lens[sym++] = 9;
  78157. while (sym < 280) state->lens[sym++] = 7;
  78158. while (sym < 288) state->lens[sym++] = 8;
  78159. next = fixed;
  78160. lenfix = next;
  78161. bits = 9;
  78162. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78163. sym = 0;
  78164. while (sym < 32) state->lens[sym++] = 5;
  78165. distfix = next;
  78166. bits = 5;
  78167. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78168. virgin = 0;
  78169. }
  78170. #else /* !BUILDFIXED */
  78171. /*** Start of inlined file: inffixed.h ***/
  78172. static const code lenfix[512] = {
  78173. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78174. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78175. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78176. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78177. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78178. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78179. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78180. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78181. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78182. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78183. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78184. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78185. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78186. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78187. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78188. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78189. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78190. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78191. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78192. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78193. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78194. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78195. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78196. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78197. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78198. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78199. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78200. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78201. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78202. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78203. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78204. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78205. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78206. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78207. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78208. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78209. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78210. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78211. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78212. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78213. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78214. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78215. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78216. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78217. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78218. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78219. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78220. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78221. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78222. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78223. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78224. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78225. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78226. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78227. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78228. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78229. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78230. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78231. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78232. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78233. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78234. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78235. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78236. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78237. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78238. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78239. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78240. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78241. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78242. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78243. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78244. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78245. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78246. {0,9,255}
  78247. };
  78248. static const code distfix[32] = {
  78249. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78250. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78251. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78252. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78253. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78254. {22,5,193},{64,5,0}
  78255. };
  78256. /*** End of inlined file: inffixed.h ***/
  78257. #endif /* BUILDFIXED */
  78258. state->lencode = lenfix;
  78259. state->lenbits = 9;
  78260. state->distcode = distfix;
  78261. state->distbits = 5;
  78262. }
  78263. #ifdef MAKEFIXED
  78264. #include <stdio.h>
  78265. void makefixed()
  78266. {
  78267. unsigned low, size;
  78268. struct inflate_state state;
  78269. fixedtables(&state);
  78270. puts(" /* inffixed.h -- table for decoding fixed codes");
  78271. puts(" * Generated automatically by makefixed().");
  78272. puts(" */");
  78273. puts("");
  78274. puts(" /* WARNING: this file should *not* be used by applications.");
  78275. puts(" It is part of the implementation of this library and is");
  78276. puts(" subject to change. Applications should only use zlib.h.");
  78277. puts(" */");
  78278. puts("");
  78279. size = 1U << 9;
  78280. printf(" static const code lenfix[%u] = {", size);
  78281. low = 0;
  78282. for (;;) {
  78283. if ((low % 7) == 0) printf("\n ");
  78284. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78285. state.lencode[low].val);
  78286. if (++low == size) break;
  78287. putchar(',');
  78288. }
  78289. puts("\n };");
  78290. size = 1U << 5;
  78291. printf("\n static const code distfix[%u] = {", size);
  78292. low = 0;
  78293. for (;;) {
  78294. if ((low % 6) == 0) printf("\n ");
  78295. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78296. state.distcode[low].val);
  78297. if (++low == size) break;
  78298. putchar(',');
  78299. }
  78300. puts("\n };");
  78301. }
  78302. #endif /* MAKEFIXED */
  78303. local int updatewindow (z_streamp strm, unsigned out)
  78304. {
  78305. struct inflate_state FAR *state;
  78306. unsigned copy, dist;
  78307. state = (struct inflate_state FAR *)strm->state;
  78308. if (state->window == Z_NULL) {
  78309. state->window = (unsigned char FAR *)
  78310. ZALLOC(strm, 1U << state->wbits,
  78311. sizeof(unsigned char));
  78312. if (state->window == Z_NULL) return 1;
  78313. }
  78314. if (state->wsize == 0) {
  78315. state->wsize = 1U << state->wbits;
  78316. state->write = 0;
  78317. state->whave = 0;
  78318. }
  78319. copy = out - strm->avail_out;
  78320. if (copy >= state->wsize) {
  78321. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78322. state->write = 0;
  78323. state->whave = state->wsize;
  78324. }
  78325. else {
  78326. dist = state->wsize - state->write;
  78327. if (dist > copy) dist = copy;
  78328. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78329. copy -= dist;
  78330. if (copy) {
  78331. zmemcpy(state->window, strm->next_out - copy, copy);
  78332. state->write = copy;
  78333. state->whave = state->wsize;
  78334. }
  78335. else {
  78336. state->write += dist;
  78337. if (state->write == state->wsize) state->write = 0;
  78338. if (state->whave < state->wsize) state->whave += dist;
  78339. }
  78340. }
  78341. return 0;
  78342. }
  78343. #ifdef GUNZIP
  78344. # define UPDATE(check, buf, len) \
  78345. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78346. #else
  78347. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78348. #endif
  78349. #ifdef GUNZIP
  78350. # define CRC2(check, word) \
  78351. do { \
  78352. hbuf[0] = (unsigned char)(word); \
  78353. hbuf[1] = (unsigned char)((word) >> 8); \
  78354. check = crc32(check, hbuf, 2); \
  78355. } while (0)
  78356. # define CRC4(check, word) \
  78357. do { \
  78358. hbuf[0] = (unsigned char)(word); \
  78359. hbuf[1] = (unsigned char)((word) >> 8); \
  78360. hbuf[2] = (unsigned char)((word) >> 16); \
  78361. hbuf[3] = (unsigned char)((word) >> 24); \
  78362. check = crc32(check, hbuf, 4); \
  78363. } while (0)
  78364. #endif
  78365. #define LOAD() \
  78366. do { \
  78367. put = strm->next_out; \
  78368. left = strm->avail_out; \
  78369. next = strm->next_in; \
  78370. have = strm->avail_in; \
  78371. hold = state->hold; \
  78372. bits = state->bits; \
  78373. } while (0)
  78374. #define RESTORE() \
  78375. do { \
  78376. strm->next_out = put; \
  78377. strm->avail_out = left; \
  78378. strm->next_in = next; \
  78379. strm->avail_in = have; \
  78380. state->hold = hold; \
  78381. state->bits = bits; \
  78382. } while (0)
  78383. #define INITBITS() \
  78384. do { \
  78385. hold = 0; \
  78386. bits = 0; \
  78387. } while (0)
  78388. #define PULLBYTE() \
  78389. do { \
  78390. if (have == 0) goto inf_leave; \
  78391. have--; \
  78392. hold += (unsigned long)(*next++) << bits; \
  78393. bits += 8; \
  78394. } while (0)
  78395. #define NEEDBITS(n) \
  78396. do { \
  78397. while (bits < (unsigned)(n)) \
  78398. PULLBYTE(); \
  78399. } while (0)
  78400. #define BITS(n) \
  78401. ((unsigned)hold & ((1U << (n)) - 1))
  78402. #define DROPBITS(n) \
  78403. do { \
  78404. hold >>= (n); \
  78405. bits -= (unsigned)(n); \
  78406. } while (0)
  78407. #define BYTEBITS() \
  78408. do { \
  78409. hold >>= bits & 7; \
  78410. bits -= bits & 7; \
  78411. } while (0)
  78412. #define REVERSE(q) \
  78413. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78414. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78415. int ZEXPORT inflate (z_streamp strm, int flush)
  78416. {
  78417. struct inflate_state FAR *state;
  78418. unsigned char FAR *next; /* next input */
  78419. unsigned char FAR *put; /* next output */
  78420. unsigned have, left; /* available input and output */
  78421. unsigned long hold; /* bit buffer */
  78422. unsigned bits; /* bits in bit buffer */
  78423. unsigned in, out; /* save starting available input and output */
  78424. unsigned copy; /* number of stored or match bytes to copy */
  78425. unsigned char FAR *from; /* where to copy match bytes from */
  78426. code thisx; /* current decoding table entry */
  78427. code last; /* parent table entry */
  78428. unsigned len; /* length to copy for repeats, bits to drop */
  78429. int ret; /* return code */
  78430. #ifdef GUNZIP
  78431. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78432. #endif
  78433. static const unsigned short order[19] = /* permutation of code lengths */
  78434. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78435. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78436. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78437. return Z_STREAM_ERROR;
  78438. state = (struct inflate_state FAR *)strm->state;
  78439. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78440. LOAD();
  78441. in = have;
  78442. out = left;
  78443. ret = Z_OK;
  78444. for (;;)
  78445. switch (state->mode) {
  78446. case HEAD:
  78447. if (state->wrap == 0) {
  78448. state->mode = TYPEDO;
  78449. break;
  78450. }
  78451. NEEDBITS(16);
  78452. #ifdef GUNZIP
  78453. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78454. state->check = crc32(0L, Z_NULL, 0);
  78455. CRC2(state->check, hold);
  78456. INITBITS();
  78457. state->mode = FLAGS;
  78458. break;
  78459. }
  78460. state->flags = 0; /* expect zlib header */
  78461. if (state->head != Z_NULL)
  78462. state->head->done = -1;
  78463. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78464. #else
  78465. if (
  78466. #endif
  78467. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78468. strm->msg = (char *)"incorrect header check";
  78469. state->mode = BAD;
  78470. break;
  78471. }
  78472. if (BITS(4) != Z_DEFLATED) {
  78473. strm->msg = (char *)"unknown compression method";
  78474. state->mode = BAD;
  78475. break;
  78476. }
  78477. DROPBITS(4);
  78478. len = BITS(4) + 8;
  78479. if (len > state->wbits) {
  78480. strm->msg = (char *)"invalid window size";
  78481. state->mode = BAD;
  78482. break;
  78483. }
  78484. state->dmax = 1U << len;
  78485. Tracev((stderr, "inflate: zlib header ok\n"));
  78486. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78487. state->mode = hold & 0x200 ? DICTID : TYPE;
  78488. INITBITS();
  78489. break;
  78490. #ifdef GUNZIP
  78491. case FLAGS:
  78492. NEEDBITS(16);
  78493. state->flags = (int)(hold);
  78494. if ((state->flags & 0xff) != Z_DEFLATED) {
  78495. strm->msg = (char *)"unknown compression method";
  78496. state->mode = BAD;
  78497. break;
  78498. }
  78499. if (state->flags & 0xe000) {
  78500. strm->msg = (char *)"unknown header flags set";
  78501. state->mode = BAD;
  78502. break;
  78503. }
  78504. if (state->head != Z_NULL)
  78505. state->head->text = (int)((hold >> 8) & 1);
  78506. if (state->flags & 0x0200) CRC2(state->check, hold);
  78507. INITBITS();
  78508. state->mode = TIME;
  78509. case TIME:
  78510. NEEDBITS(32);
  78511. if (state->head != Z_NULL)
  78512. state->head->time = hold;
  78513. if (state->flags & 0x0200) CRC4(state->check, hold);
  78514. INITBITS();
  78515. state->mode = OS;
  78516. case OS:
  78517. NEEDBITS(16);
  78518. if (state->head != Z_NULL) {
  78519. state->head->xflags = (int)(hold & 0xff);
  78520. state->head->os = (int)(hold >> 8);
  78521. }
  78522. if (state->flags & 0x0200) CRC2(state->check, hold);
  78523. INITBITS();
  78524. state->mode = EXLEN;
  78525. case EXLEN:
  78526. if (state->flags & 0x0400) {
  78527. NEEDBITS(16);
  78528. state->length = (unsigned)(hold);
  78529. if (state->head != Z_NULL)
  78530. state->head->extra_len = (unsigned)hold;
  78531. if (state->flags & 0x0200) CRC2(state->check, hold);
  78532. INITBITS();
  78533. }
  78534. else if (state->head != Z_NULL)
  78535. state->head->extra = Z_NULL;
  78536. state->mode = EXTRA;
  78537. case EXTRA:
  78538. if (state->flags & 0x0400) {
  78539. copy = state->length;
  78540. if (copy > have) copy = have;
  78541. if (copy) {
  78542. if (state->head != Z_NULL &&
  78543. state->head->extra != Z_NULL) {
  78544. len = state->head->extra_len - state->length;
  78545. zmemcpy(state->head->extra + len, next,
  78546. len + copy > state->head->extra_max ?
  78547. state->head->extra_max - len : copy);
  78548. }
  78549. if (state->flags & 0x0200)
  78550. state->check = crc32(state->check, next, copy);
  78551. have -= copy;
  78552. next += copy;
  78553. state->length -= copy;
  78554. }
  78555. if (state->length) goto inf_leave;
  78556. }
  78557. state->length = 0;
  78558. state->mode = NAME;
  78559. case NAME:
  78560. if (state->flags & 0x0800) {
  78561. if (have == 0) goto inf_leave;
  78562. copy = 0;
  78563. do {
  78564. len = (unsigned)(next[copy++]);
  78565. if (state->head != Z_NULL &&
  78566. state->head->name != Z_NULL &&
  78567. state->length < state->head->name_max)
  78568. state->head->name[state->length++] = len;
  78569. } while (len && copy < have);
  78570. if (state->flags & 0x0200)
  78571. state->check = crc32(state->check, next, copy);
  78572. have -= copy;
  78573. next += copy;
  78574. if (len) goto inf_leave;
  78575. }
  78576. else if (state->head != Z_NULL)
  78577. state->head->name = Z_NULL;
  78578. state->length = 0;
  78579. state->mode = COMMENT;
  78580. case COMMENT:
  78581. if (state->flags & 0x1000) {
  78582. if (have == 0) goto inf_leave;
  78583. copy = 0;
  78584. do {
  78585. len = (unsigned)(next[copy++]);
  78586. if (state->head != Z_NULL &&
  78587. state->head->comment != Z_NULL &&
  78588. state->length < state->head->comm_max)
  78589. state->head->comment[state->length++] = len;
  78590. } while (len && copy < have);
  78591. if (state->flags & 0x0200)
  78592. state->check = crc32(state->check, next, copy);
  78593. have -= copy;
  78594. next += copy;
  78595. if (len) goto inf_leave;
  78596. }
  78597. else if (state->head != Z_NULL)
  78598. state->head->comment = Z_NULL;
  78599. state->mode = HCRC;
  78600. case HCRC:
  78601. if (state->flags & 0x0200) {
  78602. NEEDBITS(16);
  78603. if (hold != (state->check & 0xffff)) {
  78604. strm->msg = (char *)"header crc mismatch";
  78605. state->mode = BAD;
  78606. break;
  78607. }
  78608. INITBITS();
  78609. }
  78610. if (state->head != Z_NULL) {
  78611. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78612. state->head->done = 1;
  78613. }
  78614. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78615. state->mode = TYPE;
  78616. break;
  78617. #endif
  78618. case DICTID:
  78619. NEEDBITS(32);
  78620. strm->adler = state->check = REVERSE(hold);
  78621. INITBITS();
  78622. state->mode = DICT;
  78623. case DICT:
  78624. if (state->havedict == 0) {
  78625. RESTORE();
  78626. return Z_NEED_DICT;
  78627. }
  78628. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78629. state->mode = TYPE;
  78630. case TYPE:
  78631. if (flush == Z_BLOCK) goto inf_leave;
  78632. case TYPEDO:
  78633. if (state->last) {
  78634. BYTEBITS();
  78635. state->mode = CHECK;
  78636. break;
  78637. }
  78638. NEEDBITS(3);
  78639. state->last = BITS(1);
  78640. DROPBITS(1);
  78641. switch (BITS(2)) {
  78642. case 0: /* stored block */
  78643. Tracev((stderr, "inflate: stored block%s\n",
  78644. state->last ? " (last)" : ""));
  78645. state->mode = STORED;
  78646. break;
  78647. case 1: /* fixed block */
  78648. fixedtables(state);
  78649. Tracev((stderr, "inflate: fixed codes block%s\n",
  78650. state->last ? " (last)" : ""));
  78651. state->mode = LEN; /* decode codes */
  78652. break;
  78653. case 2: /* dynamic block */
  78654. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78655. state->last ? " (last)" : ""));
  78656. state->mode = TABLE;
  78657. break;
  78658. case 3:
  78659. strm->msg = (char *)"invalid block type";
  78660. state->mode = BAD;
  78661. }
  78662. DROPBITS(2);
  78663. break;
  78664. case STORED:
  78665. BYTEBITS(); /* go to byte boundary */
  78666. NEEDBITS(32);
  78667. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78668. strm->msg = (char *)"invalid stored block lengths";
  78669. state->mode = BAD;
  78670. break;
  78671. }
  78672. state->length = (unsigned)hold & 0xffff;
  78673. Tracev((stderr, "inflate: stored length %u\n",
  78674. state->length));
  78675. INITBITS();
  78676. state->mode = COPY;
  78677. case COPY:
  78678. copy = state->length;
  78679. if (copy) {
  78680. if (copy > have) copy = have;
  78681. if (copy > left) copy = left;
  78682. if (copy == 0) goto inf_leave;
  78683. zmemcpy(put, next, copy);
  78684. have -= copy;
  78685. next += copy;
  78686. left -= copy;
  78687. put += copy;
  78688. state->length -= copy;
  78689. break;
  78690. }
  78691. Tracev((stderr, "inflate: stored end\n"));
  78692. state->mode = TYPE;
  78693. break;
  78694. case TABLE:
  78695. NEEDBITS(14);
  78696. state->nlen = BITS(5) + 257;
  78697. DROPBITS(5);
  78698. state->ndist = BITS(5) + 1;
  78699. DROPBITS(5);
  78700. state->ncode = BITS(4) + 4;
  78701. DROPBITS(4);
  78702. #ifndef PKZIP_BUG_WORKAROUND
  78703. if (state->nlen > 286 || state->ndist > 30) {
  78704. strm->msg = (char *)"too many length or distance symbols";
  78705. state->mode = BAD;
  78706. break;
  78707. }
  78708. #endif
  78709. Tracev((stderr, "inflate: table sizes ok\n"));
  78710. state->have = 0;
  78711. state->mode = LENLENS;
  78712. case LENLENS:
  78713. while (state->have < state->ncode) {
  78714. NEEDBITS(3);
  78715. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78716. DROPBITS(3);
  78717. }
  78718. while (state->have < 19)
  78719. state->lens[order[state->have++]] = 0;
  78720. state->next = state->codes;
  78721. state->lencode = (code const FAR *)(state->next);
  78722. state->lenbits = 7;
  78723. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78724. &(state->lenbits), state->work);
  78725. if (ret) {
  78726. strm->msg = (char *)"invalid code lengths set";
  78727. state->mode = BAD;
  78728. break;
  78729. }
  78730. Tracev((stderr, "inflate: code lengths ok\n"));
  78731. state->have = 0;
  78732. state->mode = CODELENS;
  78733. case CODELENS:
  78734. while (state->have < state->nlen + state->ndist) {
  78735. for (;;) {
  78736. thisx = state->lencode[BITS(state->lenbits)];
  78737. if ((unsigned)(thisx.bits) <= bits) break;
  78738. PULLBYTE();
  78739. }
  78740. if (thisx.val < 16) {
  78741. NEEDBITS(thisx.bits);
  78742. DROPBITS(thisx.bits);
  78743. state->lens[state->have++] = thisx.val;
  78744. }
  78745. else {
  78746. if (thisx.val == 16) {
  78747. NEEDBITS(thisx.bits + 2);
  78748. DROPBITS(thisx.bits);
  78749. if (state->have == 0) {
  78750. strm->msg = (char *)"invalid bit length repeat";
  78751. state->mode = BAD;
  78752. break;
  78753. }
  78754. len = state->lens[state->have - 1];
  78755. copy = 3 + BITS(2);
  78756. DROPBITS(2);
  78757. }
  78758. else if (thisx.val == 17) {
  78759. NEEDBITS(thisx.bits + 3);
  78760. DROPBITS(thisx.bits);
  78761. len = 0;
  78762. copy = 3 + BITS(3);
  78763. DROPBITS(3);
  78764. }
  78765. else {
  78766. NEEDBITS(thisx.bits + 7);
  78767. DROPBITS(thisx.bits);
  78768. len = 0;
  78769. copy = 11 + BITS(7);
  78770. DROPBITS(7);
  78771. }
  78772. if (state->have + copy > state->nlen + state->ndist) {
  78773. strm->msg = (char *)"invalid bit length repeat";
  78774. state->mode = BAD;
  78775. break;
  78776. }
  78777. while (copy--)
  78778. state->lens[state->have++] = (unsigned short)len;
  78779. }
  78780. }
  78781. if (state->mode == BAD) break;
  78782. state->next = state->codes;
  78783. state->lencode = (code const FAR *)(state->next);
  78784. state->lenbits = 9;
  78785. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78786. &(state->lenbits), state->work);
  78787. if (ret) {
  78788. strm->msg = (char *)"invalid literal/lengths set";
  78789. state->mode = BAD;
  78790. break;
  78791. }
  78792. state->distcode = (code const FAR *)(state->next);
  78793. state->distbits = 6;
  78794. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78795. &(state->next), &(state->distbits), state->work);
  78796. if (ret) {
  78797. strm->msg = (char *)"invalid distances set";
  78798. state->mode = BAD;
  78799. break;
  78800. }
  78801. Tracev((stderr, "inflate: codes ok\n"));
  78802. state->mode = LEN;
  78803. case LEN:
  78804. if (have >= 6 && left >= 258) {
  78805. RESTORE();
  78806. inflate_fast(strm, out);
  78807. LOAD();
  78808. break;
  78809. }
  78810. for (;;) {
  78811. thisx = state->lencode[BITS(state->lenbits)];
  78812. if ((unsigned)(thisx.bits) <= bits) break;
  78813. PULLBYTE();
  78814. }
  78815. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78816. last = thisx;
  78817. for (;;) {
  78818. thisx = state->lencode[last.val +
  78819. (BITS(last.bits + last.op) >> last.bits)];
  78820. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78821. PULLBYTE();
  78822. }
  78823. DROPBITS(last.bits);
  78824. }
  78825. DROPBITS(thisx.bits);
  78826. state->length = (unsigned)thisx.val;
  78827. if ((int)(thisx.op) == 0) {
  78828. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78829. "inflate: literal '%c'\n" :
  78830. "inflate: literal 0x%02x\n", thisx.val));
  78831. state->mode = LIT;
  78832. break;
  78833. }
  78834. if (thisx.op & 32) {
  78835. Tracevv((stderr, "inflate: end of block\n"));
  78836. state->mode = TYPE;
  78837. break;
  78838. }
  78839. if (thisx.op & 64) {
  78840. strm->msg = (char *)"invalid literal/length code";
  78841. state->mode = BAD;
  78842. break;
  78843. }
  78844. state->extra = (unsigned)(thisx.op) & 15;
  78845. state->mode = LENEXT;
  78846. case LENEXT:
  78847. if (state->extra) {
  78848. NEEDBITS(state->extra);
  78849. state->length += BITS(state->extra);
  78850. DROPBITS(state->extra);
  78851. }
  78852. Tracevv((stderr, "inflate: length %u\n", state->length));
  78853. state->mode = DIST;
  78854. case DIST:
  78855. for (;;) {
  78856. thisx = state->distcode[BITS(state->distbits)];
  78857. if ((unsigned)(thisx.bits) <= bits) break;
  78858. PULLBYTE();
  78859. }
  78860. if ((thisx.op & 0xf0) == 0) {
  78861. last = thisx;
  78862. for (;;) {
  78863. thisx = state->distcode[last.val +
  78864. (BITS(last.bits + last.op) >> last.bits)];
  78865. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78866. PULLBYTE();
  78867. }
  78868. DROPBITS(last.bits);
  78869. }
  78870. DROPBITS(thisx.bits);
  78871. if (thisx.op & 64) {
  78872. strm->msg = (char *)"invalid distance code";
  78873. state->mode = BAD;
  78874. break;
  78875. }
  78876. state->offset = (unsigned)thisx.val;
  78877. state->extra = (unsigned)(thisx.op) & 15;
  78878. state->mode = DISTEXT;
  78879. case DISTEXT:
  78880. if (state->extra) {
  78881. NEEDBITS(state->extra);
  78882. state->offset += BITS(state->extra);
  78883. DROPBITS(state->extra);
  78884. }
  78885. #ifdef INFLATE_STRICT
  78886. if (state->offset > state->dmax) {
  78887. strm->msg = (char *)"invalid distance too far back";
  78888. state->mode = BAD;
  78889. break;
  78890. }
  78891. #endif
  78892. if (state->offset > state->whave + out - left) {
  78893. strm->msg = (char *)"invalid distance too far back";
  78894. state->mode = BAD;
  78895. break;
  78896. }
  78897. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78898. state->mode = MATCH;
  78899. case MATCH:
  78900. if (left == 0) goto inf_leave;
  78901. copy = out - left;
  78902. if (state->offset > copy) { /* copy from window */
  78903. copy = state->offset - copy;
  78904. if (copy > state->write) {
  78905. copy -= state->write;
  78906. from = state->window + (state->wsize - copy);
  78907. }
  78908. else
  78909. from = state->window + (state->write - copy);
  78910. if (copy > state->length) copy = state->length;
  78911. }
  78912. else { /* copy from output */
  78913. from = put - state->offset;
  78914. copy = state->length;
  78915. }
  78916. if (copy > left) copy = left;
  78917. left -= copy;
  78918. state->length -= copy;
  78919. do {
  78920. *put++ = *from++;
  78921. } while (--copy);
  78922. if (state->length == 0) state->mode = LEN;
  78923. break;
  78924. case LIT:
  78925. if (left == 0) goto inf_leave;
  78926. *put++ = (unsigned char)(state->length);
  78927. left--;
  78928. state->mode = LEN;
  78929. break;
  78930. case CHECK:
  78931. if (state->wrap) {
  78932. NEEDBITS(32);
  78933. out -= left;
  78934. strm->total_out += out;
  78935. state->total += out;
  78936. if (out)
  78937. strm->adler = state->check =
  78938. UPDATE(state->check, put - out, out);
  78939. out = left;
  78940. if ((
  78941. #ifdef GUNZIP
  78942. state->flags ? hold :
  78943. #endif
  78944. REVERSE(hold)) != state->check) {
  78945. strm->msg = (char *)"incorrect data check";
  78946. state->mode = BAD;
  78947. break;
  78948. }
  78949. INITBITS();
  78950. Tracev((stderr, "inflate: check matches trailer\n"));
  78951. }
  78952. #ifdef GUNZIP
  78953. state->mode = LENGTH;
  78954. case LENGTH:
  78955. if (state->wrap && state->flags) {
  78956. NEEDBITS(32);
  78957. if (hold != (state->total & 0xffffffffUL)) {
  78958. strm->msg = (char *)"incorrect length check";
  78959. state->mode = BAD;
  78960. break;
  78961. }
  78962. INITBITS();
  78963. Tracev((stderr, "inflate: length matches trailer\n"));
  78964. }
  78965. #endif
  78966. state->mode = DONE;
  78967. case DONE:
  78968. ret = Z_STREAM_END;
  78969. goto inf_leave;
  78970. case BAD:
  78971. ret = Z_DATA_ERROR;
  78972. goto inf_leave;
  78973. case MEM:
  78974. return Z_MEM_ERROR;
  78975. case SYNC:
  78976. default:
  78977. return Z_STREAM_ERROR;
  78978. }
  78979. inf_leave:
  78980. RESTORE();
  78981. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  78982. if (updatewindow(strm, out)) {
  78983. state->mode = MEM;
  78984. return Z_MEM_ERROR;
  78985. }
  78986. in -= strm->avail_in;
  78987. out -= strm->avail_out;
  78988. strm->total_in += in;
  78989. strm->total_out += out;
  78990. state->total += out;
  78991. if (state->wrap && out)
  78992. strm->adler = state->check =
  78993. UPDATE(state->check, strm->next_out - out, out);
  78994. strm->data_type = state->bits + (state->last ? 64 : 0) +
  78995. (state->mode == TYPE ? 128 : 0);
  78996. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  78997. ret = Z_BUF_ERROR;
  78998. return ret;
  78999. }
  79000. int ZEXPORT inflateEnd (z_streamp strm)
  79001. {
  79002. struct inflate_state FAR *state;
  79003. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  79004. return Z_STREAM_ERROR;
  79005. state = (struct inflate_state FAR *)strm->state;
  79006. if (state->window != Z_NULL) ZFREE(strm, state->window);
  79007. ZFREE(strm, strm->state);
  79008. strm->state = Z_NULL;
  79009. Tracev((stderr, "inflate: end\n"));
  79010. return Z_OK;
  79011. }
  79012. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79013. {
  79014. struct inflate_state FAR *state;
  79015. unsigned long id_;
  79016. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79017. state = (struct inflate_state FAR *)strm->state;
  79018. if (state->wrap != 0 && state->mode != DICT)
  79019. return Z_STREAM_ERROR;
  79020. if (state->mode == DICT) {
  79021. id_ = adler32(0L, Z_NULL, 0);
  79022. id_ = adler32(id_, dictionary, dictLength);
  79023. if (id_ != state->check)
  79024. return Z_DATA_ERROR;
  79025. }
  79026. if (updatewindow(strm, strm->avail_out)) {
  79027. state->mode = MEM;
  79028. return Z_MEM_ERROR;
  79029. }
  79030. if (dictLength > state->wsize) {
  79031. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79032. state->wsize);
  79033. state->whave = state->wsize;
  79034. }
  79035. else {
  79036. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79037. dictLength);
  79038. state->whave = dictLength;
  79039. }
  79040. state->havedict = 1;
  79041. Tracev((stderr, "inflate: dictionary set\n"));
  79042. return Z_OK;
  79043. }
  79044. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79045. {
  79046. struct inflate_state FAR *state;
  79047. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79048. state = (struct inflate_state FAR *)strm->state;
  79049. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79050. state->head = head;
  79051. head->done = 0;
  79052. return Z_OK;
  79053. }
  79054. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79055. {
  79056. unsigned got;
  79057. unsigned next;
  79058. got = *have;
  79059. next = 0;
  79060. while (next < len && got < 4) {
  79061. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79062. got++;
  79063. else if (buf[next])
  79064. got = 0;
  79065. else
  79066. got = 4 - got;
  79067. next++;
  79068. }
  79069. *have = got;
  79070. return next;
  79071. }
  79072. int ZEXPORT inflateSync (z_streamp strm)
  79073. {
  79074. unsigned len; /* number of bytes to look at or looked at */
  79075. unsigned long in, out; /* temporary to save total_in and total_out */
  79076. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79077. struct inflate_state FAR *state;
  79078. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79079. state = (struct inflate_state FAR *)strm->state;
  79080. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79081. if (state->mode != SYNC) {
  79082. state->mode = SYNC;
  79083. state->hold <<= state->bits & 7;
  79084. state->bits -= state->bits & 7;
  79085. len = 0;
  79086. while (state->bits >= 8) {
  79087. buf[len++] = (unsigned char)(state->hold);
  79088. state->hold >>= 8;
  79089. state->bits -= 8;
  79090. }
  79091. state->have = 0;
  79092. syncsearch(&(state->have), buf, len);
  79093. }
  79094. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79095. strm->avail_in -= len;
  79096. strm->next_in += len;
  79097. strm->total_in += len;
  79098. if (state->have != 4) return Z_DATA_ERROR;
  79099. in = strm->total_in; out = strm->total_out;
  79100. inflateReset(strm);
  79101. strm->total_in = in; strm->total_out = out;
  79102. state->mode = TYPE;
  79103. return Z_OK;
  79104. }
  79105. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79106. {
  79107. struct inflate_state FAR *state;
  79108. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79109. state = (struct inflate_state FAR *)strm->state;
  79110. return state->mode == STORED && state->bits == 0;
  79111. }
  79112. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79113. {
  79114. struct inflate_state FAR *state;
  79115. struct inflate_state FAR *copy;
  79116. unsigned char FAR *window;
  79117. unsigned wsize;
  79118. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79119. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79120. return Z_STREAM_ERROR;
  79121. state = (struct inflate_state FAR *)source->state;
  79122. copy = (struct inflate_state FAR *)
  79123. ZALLOC(source, 1, sizeof(struct inflate_state));
  79124. if (copy == Z_NULL) return Z_MEM_ERROR;
  79125. window = Z_NULL;
  79126. if (state->window != Z_NULL) {
  79127. window = (unsigned char FAR *)
  79128. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79129. if (window == Z_NULL) {
  79130. ZFREE(source, copy);
  79131. return Z_MEM_ERROR;
  79132. }
  79133. }
  79134. zmemcpy(dest, source, sizeof(z_stream));
  79135. zmemcpy(copy, state, sizeof(struct inflate_state));
  79136. if (state->lencode >= state->codes &&
  79137. state->lencode <= state->codes + ENOUGH - 1) {
  79138. copy->lencode = copy->codes + (state->lencode - state->codes);
  79139. copy->distcode = copy->codes + (state->distcode - state->codes);
  79140. }
  79141. copy->next = copy->codes + (state->next - state->codes);
  79142. if (window != Z_NULL) {
  79143. wsize = 1U << state->wbits;
  79144. zmemcpy(window, state->window, wsize);
  79145. }
  79146. copy->window = window;
  79147. dest->state = (struct internal_state FAR *)copy;
  79148. return Z_OK;
  79149. }
  79150. /*** End of inlined file: inflate.c ***/
  79151. /*** Start of inlined file: inftrees.c ***/
  79152. #define MAXBITS 15
  79153. const char inflate_copyright[] =
  79154. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79155. int inflate_table (codetype type,
  79156. unsigned short FAR *lens,
  79157. unsigned codes,
  79158. code FAR * FAR *table,
  79159. unsigned FAR *bits,
  79160. unsigned short FAR *work)
  79161. {
  79162. unsigned len; /* a code's length in bits */
  79163. unsigned sym; /* index of code symbols */
  79164. unsigned min, max; /* minimum and maximum code lengths */
  79165. unsigned root; /* number of index bits for root table */
  79166. unsigned curr; /* number of index bits for current table */
  79167. unsigned drop; /* code bits to drop for sub-table */
  79168. int left; /* number of prefix codes available */
  79169. unsigned used; /* code entries in table used */
  79170. unsigned huff; /* Huffman code */
  79171. unsigned incr; /* for incrementing code, index */
  79172. unsigned fill; /* index for replicating entries */
  79173. unsigned low; /* low bits for current root entry */
  79174. unsigned mask; /* mask for low root bits */
  79175. code thisx; /* table entry for duplication */
  79176. code FAR *next; /* next available space in table */
  79177. const unsigned short FAR *base; /* base value table to use */
  79178. const unsigned short FAR *extra; /* extra bits table to use */
  79179. int end; /* use base and extra for symbol > end */
  79180. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79181. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79182. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79183. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79184. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79185. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79186. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79187. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79188. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79189. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79190. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79191. 8193, 12289, 16385, 24577, 0, 0};
  79192. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79193. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79194. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79195. 28, 28, 29, 29, 64, 64};
  79196. for (len = 0; len <= MAXBITS; len++)
  79197. count[len] = 0;
  79198. for (sym = 0; sym < codes; sym++)
  79199. count[lens[sym]]++;
  79200. root = *bits;
  79201. for (max = MAXBITS; max >= 1; max--)
  79202. if (count[max] != 0) break;
  79203. if (root > max) root = max;
  79204. if (max == 0) { /* no symbols to code at all */
  79205. thisx.op = (unsigned char)64; /* invalid code marker */
  79206. thisx.bits = (unsigned char)1;
  79207. thisx.val = (unsigned short)0;
  79208. *(*table)++ = thisx; /* make a table to force an error */
  79209. *(*table)++ = thisx;
  79210. *bits = 1;
  79211. return 0; /* no symbols, but wait for decoding to report error */
  79212. }
  79213. for (min = 1; min <= MAXBITS; min++)
  79214. if (count[min] != 0) break;
  79215. if (root < min) root = min;
  79216. left = 1;
  79217. for (len = 1; len <= MAXBITS; len++) {
  79218. left <<= 1;
  79219. left -= count[len];
  79220. if (left < 0) return -1; /* over-subscribed */
  79221. }
  79222. if (left > 0 && (type == CODES || max != 1))
  79223. return -1; /* incomplete set */
  79224. offs[1] = 0;
  79225. for (len = 1; len < MAXBITS; len++)
  79226. offs[len + 1] = offs[len] + count[len];
  79227. for (sym = 0; sym < codes; sym++)
  79228. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79229. switch (type) {
  79230. case CODES:
  79231. base = extra = work; /* dummy value--not used */
  79232. end = 19;
  79233. break;
  79234. case LENS:
  79235. base = lbase;
  79236. base -= 257;
  79237. extra = lext;
  79238. extra -= 257;
  79239. end = 256;
  79240. break;
  79241. default: /* DISTS */
  79242. base = dbase;
  79243. extra = dext;
  79244. end = -1;
  79245. }
  79246. huff = 0; /* starting code */
  79247. sym = 0; /* starting code symbol */
  79248. len = min; /* starting code length */
  79249. next = *table; /* current table to fill in */
  79250. curr = root; /* current table index bits */
  79251. drop = 0; /* current bits to drop from code for index */
  79252. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79253. used = 1U << root; /* use root table entries */
  79254. mask = used - 1; /* mask for comparing low */
  79255. if (type == LENS && used >= ENOUGH - MAXD)
  79256. return 1;
  79257. for (;;) {
  79258. thisx.bits = (unsigned char)(len - drop);
  79259. if ((int)(work[sym]) < end) {
  79260. thisx.op = (unsigned char)0;
  79261. thisx.val = work[sym];
  79262. }
  79263. else if ((int)(work[sym]) > end) {
  79264. thisx.op = (unsigned char)(extra[work[sym]]);
  79265. thisx.val = base[work[sym]];
  79266. }
  79267. else {
  79268. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79269. thisx.val = 0;
  79270. }
  79271. incr = 1U << (len - drop);
  79272. fill = 1U << curr;
  79273. min = fill; /* save offset to next table */
  79274. do {
  79275. fill -= incr;
  79276. next[(huff >> drop) + fill] = thisx;
  79277. } while (fill != 0);
  79278. incr = 1U << (len - 1);
  79279. while (huff & incr)
  79280. incr >>= 1;
  79281. if (incr != 0) {
  79282. huff &= incr - 1;
  79283. huff += incr;
  79284. }
  79285. else
  79286. huff = 0;
  79287. sym++;
  79288. if (--(count[len]) == 0) {
  79289. if (len == max) break;
  79290. len = lens[work[sym]];
  79291. }
  79292. if (len > root && (huff & mask) != low) {
  79293. if (drop == 0)
  79294. drop = root;
  79295. next += min; /* here min is 1 << curr */
  79296. curr = len - drop;
  79297. left = (int)(1 << curr);
  79298. while (curr + drop < max) {
  79299. left -= count[curr + drop];
  79300. if (left <= 0) break;
  79301. curr++;
  79302. left <<= 1;
  79303. }
  79304. used += 1U << curr;
  79305. if (type == LENS && used >= ENOUGH - MAXD)
  79306. return 1;
  79307. low = huff & mask;
  79308. (*table)[low].op = (unsigned char)curr;
  79309. (*table)[low].bits = (unsigned char)root;
  79310. (*table)[low].val = (unsigned short)(next - *table);
  79311. }
  79312. }
  79313. thisx.op = (unsigned char)64; /* invalid code marker */
  79314. thisx.bits = (unsigned char)(len - drop);
  79315. thisx.val = (unsigned short)0;
  79316. while (huff != 0) {
  79317. if (drop != 0 && (huff & mask) != low) {
  79318. drop = 0;
  79319. len = root;
  79320. next = *table;
  79321. thisx.bits = (unsigned char)len;
  79322. }
  79323. next[huff >> drop] = thisx;
  79324. incr = 1U << (len - 1);
  79325. while (huff & incr)
  79326. incr >>= 1;
  79327. if (incr != 0) {
  79328. huff &= incr - 1;
  79329. huff += incr;
  79330. }
  79331. else
  79332. huff = 0;
  79333. }
  79334. *table += used;
  79335. *bits = root;
  79336. return 0;
  79337. }
  79338. /*** End of inlined file: inftrees.c ***/
  79339. /*** Start of inlined file: trees.c ***/
  79340. #ifdef DEBUG
  79341. # include <ctype.h>
  79342. #endif
  79343. #define MAX_BL_BITS 7
  79344. #define END_BLOCK 256
  79345. #define REP_3_6 16
  79346. #define REPZ_3_10 17
  79347. #define REPZ_11_138 18
  79348. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79349. = {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};
  79350. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79351. = {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};
  79352. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79353. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79354. local const uch bl_order[BL_CODES]
  79355. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79356. #define Buf_size (8 * 2*sizeof(char))
  79357. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79358. #if defined(GEN_TREES_H) || !defined(STDC)
  79359. local ct_data static_ltree[L_CODES+2];
  79360. local ct_data static_dtree[D_CODES];
  79361. uch _dist_code[DIST_CODE_LEN];
  79362. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79363. local int base_length[LENGTH_CODES];
  79364. local int base_dist[D_CODES];
  79365. #else
  79366. /*** Start of inlined file: trees.h ***/
  79367. local const ct_data static_ltree[L_CODES+2] = {
  79368. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79369. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79370. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79371. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79372. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79373. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79374. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79375. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79376. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79377. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79378. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79379. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79380. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79381. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79382. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79383. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79384. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79385. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79386. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79387. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79388. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79389. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79390. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79391. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79392. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79393. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79394. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79395. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79396. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79397. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79398. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79399. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79400. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79401. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79402. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79403. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79404. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79405. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79406. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79407. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79408. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79409. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79410. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79411. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79412. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79413. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79414. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79415. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79416. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79417. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79418. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79419. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79420. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79421. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79422. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79423. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79424. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79425. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79426. };
  79427. local const ct_data static_dtree[D_CODES] = {
  79428. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79429. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79430. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79431. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79432. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79433. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79434. };
  79435. const uch _dist_code[DIST_CODE_LEN] = {
  79436. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79437. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79438. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79439. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79440. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79441. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79442. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79443. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79444. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79445. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79446. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79447. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79448. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79449. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79450. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79451. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79452. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79453. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79454. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79455. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79456. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79457. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79458. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79459. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79460. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79461. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79462. };
  79463. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79464. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79465. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79466. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79467. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79468. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79469. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79470. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79471. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79472. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79473. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79474. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79475. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79476. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79477. };
  79478. local const int base_length[LENGTH_CODES] = {
  79479. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79480. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79481. };
  79482. local const int base_dist[D_CODES] = {
  79483. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79484. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79485. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79486. };
  79487. /*** End of inlined file: trees.h ***/
  79488. #endif /* GEN_TREES_H */
  79489. struct static_tree_desc_s {
  79490. const ct_data *static_tree; /* static tree or NULL */
  79491. const intf *extra_bits; /* extra bits for each code or NULL */
  79492. int extra_base; /* base index for extra_bits */
  79493. int elems; /* max number of elements in the tree */
  79494. int max_length; /* max bit length for the codes */
  79495. };
  79496. local static_tree_desc static_l_desc =
  79497. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79498. local static_tree_desc static_d_desc =
  79499. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79500. local static_tree_desc static_bl_desc =
  79501. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79502. local void tr_static_init OF((void));
  79503. local void init_block OF((deflate_state *s));
  79504. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79505. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79506. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79507. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79508. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79509. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79510. local int build_bl_tree OF((deflate_state *s));
  79511. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79512. int blcodes));
  79513. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79514. ct_data *dtree));
  79515. local void set_data_type OF((deflate_state *s));
  79516. local unsigned bi_reverse OF((unsigned value, int length));
  79517. local void bi_windup OF((deflate_state *s));
  79518. local void bi_flush OF((deflate_state *s));
  79519. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79520. int header));
  79521. #ifdef GEN_TREES_H
  79522. local void gen_trees_header OF((void));
  79523. #endif
  79524. #ifndef DEBUG
  79525. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79526. #else /* DEBUG */
  79527. # define send_code(s, c, tree) \
  79528. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79529. send_bits(s, tree[c].Code, tree[c].Len); }
  79530. #endif
  79531. #define put_short(s, w) { \
  79532. put_byte(s, (uch)((w) & 0xff)); \
  79533. put_byte(s, (uch)((ush)(w) >> 8)); \
  79534. }
  79535. #ifdef DEBUG
  79536. local void send_bits OF((deflate_state *s, int value, int length));
  79537. local void send_bits (deflate_state *s, int value, int length)
  79538. {
  79539. Tracevv((stderr," l %2d v %4x ", length, value));
  79540. Assert(length > 0 && length <= 15, "invalid length");
  79541. s->bits_sent += (ulg)length;
  79542. if (s->bi_valid > (int)Buf_size - length) {
  79543. s->bi_buf |= (value << s->bi_valid);
  79544. put_short(s, s->bi_buf);
  79545. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79546. s->bi_valid += length - Buf_size;
  79547. } else {
  79548. s->bi_buf |= value << s->bi_valid;
  79549. s->bi_valid += length;
  79550. }
  79551. }
  79552. #else /* !DEBUG */
  79553. #define send_bits(s, value, length) \
  79554. { int len = length;\
  79555. if (s->bi_valid > (int)Buf_size - len) {\
  79556. int val = value;\
  79557. s->bi_buf |= (val << s->bi_valid);\
  79558. put_short(s, s->bi_buf);\
  79559. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79560. s->bi_valid += len - Buf_size;\
  79561. } else {\
  79562. s->bi_buf |= (value) << s->bi_valid;\
  79563. s->bi_valid += len;\
  79564. }\
  79565. }
  79566. #endif /* DEBUG */
  79567. local void tr_static_init()
  79568. {
  79569. #if defined(GEN_TREES_H) || !defined(STDC)
  79570. static int static_init_done = 0;
  79571. int n; /* iterates over tree elements */
  79572. int bits; /* bit counter */
  79573. int length; /* length value */
  79574. int code; /* code value */
  79575. int dist; /* distance index */
  79576. ush bl_count[MAX_BITS+1];
  79577. if (static_init_done) return;
  79578. static_l_desc.static_tree = static_ltree;
  79579. static_l_desc.extra_bits = extra_lbits;
  79580. static_d_desc.static_tree = static_dtree;
  79581. static_d_desc.extra_bits = extra_dbits;
  79582. static_bl_desc.extra_bits = extra_blbits;
  79583. length = 0;
  79584. for (code = 0; code < LENGTH_CODES-1; code++) {
  79585. base_length[code] = length;
  79586. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79587. _length_code[length++] = (uch)code;
  79588. }
  79589. }
  79590. Assert (length == 256, "tr_static_init: length != 256");
  79591. _length_code[length-1] = (uch)code;
  79592. dist = 0;
  79593. for (code = 0 ; code < 16; code++) {
  79594. base_dist[code] = dist;
  79595. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79596. _dist_code[dist++] = (uch)code;
  79597. }
  79598. }
  79599. Assert (dist == 256, "tr_static_init: dist != 256");
  79600. dist >>= 7; /* from now on, all distances are divided by 128 */
  79601. for ( ; code < D_CODES; code++) {
  79602. base_dist[code] = dist << 7;
  79603. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79604. _dist_code[256 + dist++] = (uch)code;
  79605. }
  79606. }
  79607. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79608. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79609. n = 0;
  79610. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79611. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79612. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79613. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79614. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79615. for (n = 0; n < D_CODES; n++) {
  79616. static_dtree[n].Len = 5;
  79617. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79618. }
  79619. static_init_done = 1;
  79620. # ifdef GEN_TREES_H
  79621. gen_trees_header();
  79622. # endif
  79623. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79624. }
  79625. #ifdef GEN_TREES_H
  79626. # ifndef DEBUG
  79627. # include <stdio.h>
  79628. # endif
  79629. # define SEPARATOR(i, last, width) \
  79630. ((i) == (last)? "\n};\n\n" : \
  79631. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79632. void gen_trees_header()
  79633. {
  79634. FILE *header = fopen("trees.h", "w");
  79635. int i;
  79636. Assert (header != NULL, "Can't open trees.h");
  79637. fprintf(header,
  79638. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79639. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79640. for (i = 0; i < L_CODES+2; i++) {
  79641. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79642. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79643. }
  79644. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79645. for (i = 0; i < D_CODES; i++) {
  79646. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79647. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79648. }
  79649. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79650. for (i = 0; i < DIST_CODE_LEN; i++) {
  79651. fprintf(header, "%2u%s", _dist_code[i],
  79652. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79653. }
  79654. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79655. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79656. fprintf(header, "%2u%s", _length_code[i],
  79657. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79658. }
  79659. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79660. for (i = 0; i < LENGTH_CODES; i++) {
  79661. fprintf(header, "%1u%s", base_length[i],
  79662. SEPARATOR(i, LENGTH_CODES-1, 20));
  79663. }
  79664. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79665. for (i = 0; i < D_CODES; i++) {
  79666. fprintf(header, "%5u%s", base_dist[i],
  79667. SEPARATOR(i, D_CODES-1, 10));
  79668. }
  79669. fclose(header);
  79670. }
  79671. #endif /* GEN_TREES_H */
  79672. void _tr_init(deflate_state *s)
  79673. {
  79674. tr_static_init();
  79675. s->l_desc.dyn_tree = s->dyn_ltree;
  79676. s->l_desc.stat_desc = &static_l_desc;
  79677. s->d_desc.dyn_tree = s->dyn_dtree;
  79678. s->d_desc.stat_desc = &static_d_desc;
  79679. s->bl_desc.dyn_tree = s->bl_tree;
  79680. s->bl_desc.stat_desc = &static_bl_desc;
  79681. s->bi_buf = 0;
  79682. s->bi_valid = 0;
  79683. s->last_eob_len = 8; /* enough lookahead for inflate */
  79684. #ifdef DEBUG
  79685. s->compressed_len = 0L;
  79686. s->bits_sent = 0L;
  79687. #endif
  79688. init_block(s);
  79689. }
  79690. local void init_block (deflate_state *s)
  79691. {
  79692. int n; /* iterates over tree elements */
  79693. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79694. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79695. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79696. s->dyn_ltree[END_BLOCK].Freq = 1;
  79697. s->opt_len = s->static_len = 0L;
  79698. s->last_lit = s->matches = 0;
  79699. }
  79700. #define SMALLEST 1
  79701. #define pqremove(s, tree, top) \
  79702. {\
  79703. top = s->heap[SMALLEST]; \
  79704. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79705. pqdownheap(s, tree, SMALLEST); \
  79706. }
  79707. #define smaller(tree, n, m, depth) \
  79708. (tree[n].Freq < tree[m].Freq || \
  79709. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79710. local void pqdownheap (deflate_state *s,
  79711. ct_data *tree, /* the tree to restore */
  79712. int k) /* node to move down */
  79713. {
  79714. int v = s->heap[k];
  79715. int j = k << 1; /* left son of k */
  79716. while (j <= s->heap_len) {
  79717. if (j < s->heap_len &&
  79718. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79719. j++;
  79720. }
  79721. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79722. s->heap[k] = s->heap[j]; k = j;
  79723. j <<= 1;
  79724. }
  79725. s->heap[k] = v;
  79726. }
  79727. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79728. {
  79729. ct_data *tree = desc->dyn_tree;
  79730. int max_code = desc->max_code;
  79731. const ct_data *stree = desc->stat_desc->static_tree;
  79732. const intf *extra = desc->stat_desc->extra_bits;
  79733. int base = desc->stat_desc->extra_base;
  79734. int max_length = desc->stat_desc->max_length;
  79735. int h; /* heap index */
  79736. int n, m; /* iterate over the tree elements */
  79737. int bits; /* bit length */
  79738. int xbits; /* extra bits */
  79739. ush f; /* frequency */
  79740. int overflow = 0; /* number of elements with bit length too large */
  79741. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79742. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79743. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79744. n = s->heap[h];
  79745. bits = tree[tree[n].Dad].Len + 1;
  79746. if (bits > max_length) bits = max_length, overflow++;
  79747. tree[n].Len = (ush)bits;
  79748. if (n > max_code) continue; /* not a leaf node */
  79749. s->bl_count[bits]++;
  79750. xbits = 0;
  79751. if (n >= base) xbits = extra[n-base];
  79752. f = tree[n].Freq;
  79753. s->opt_len += (ulg)f * (bits + xbits);
  79754. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79755. }
  79756. if (overflow == 0) return;
  79757. Trace((stderr,"\nbit length overflow\n"));
  79758. do {
  79759. bits = max_length-1;
  79760. while (s->bl_count[bits] == 0) bits--;
  79761. s->bl_count[bits]--; /* move one leaf down the tree */
  79762. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79763. s->bl_count[max_length]--;
  79764. overflow -= 2;
  79765. } while (overflow > 0);
  79766. for (bits = max_length; bits != 0; bits--) {
  79767. n = s->bl_count[bits];
  79768. while (n != 0) {
  79769. m = s->heap[--h];
  79770. if (m > max_code) continue;
  79771. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79772. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79773. s->opt_len += ((long)bits - (long)tree[m].Len)
  79774. *(long)tree[m].Freq;
  79775. tree[m].Len = (ush)bits;
  79776. }
  79777. n--;
  79778. }
  79779. }
  79780. }
  79781. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79782. int max_code, /* largest code with non zero frequency */
  79783. ushf *bl_count) /* number of codes at each bit length */
  79784. {
  79785. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79786. ush code = 0; /* running code value */
  79787. int bits; /* bit index */
  79788. int n; /* code index */
  79789. for (bits = 1; bits <= MAX_BITS; bits++) {
  79790. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79791. }
  79792. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79793. "inconsistent bit counts");
  79794. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79795. for (n = 0; n <= max_code; n++) {
  79796. int len = tree[n].Len;
  79797. if (len == 0) continue;
  79798. tree[n].Code = bi_reverse(next_code[len]++, len);
  79799. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79800. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79801. }
  79802. }
  79803. local void build_tree (deflate_state *s,
  79804. tree_desc *desc) /* the tree descriptor */
  79805. {
  79806. ct_data *tree = desc->dyn_tree;
  79807. const ct_data *stree = desc->stat_desc->static_tree;
  79808. int elems = desc->stat_desc->elems;
  79809. int n, m; /* iterate over heap elements */
  79810. int max_code = -1; /* largest code with non zero frequency */
  79811. int node; /* new node being created */
  79812. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79813. for (n = 0; n < elems; n++) {
  79814. if (tree[n].Freq != 0) {
  79815. s->heap[++(s->heap_len)] = max_code = n;
  79816. s->depth[n] = 0;
  79817. } else {
  79818. tree[n].Len = 0;
  79819. }
  79820. }
  79821. while (s->heap_len < 2) {
  79822. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79823. tree[node].Freq = 1;
  79824. s->depth[node] = 0;
  79825. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79826. }
  79827. desc->max_code = max_code;
  79828. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79829. node = elems; /* next internal node of the tree */
  79830. do {
  79831. pqremove(s, tree, n); /* n = node of least frequency */
  79832. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79833. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79834. s->heap[--(s->heap_max)] = m;
  79835. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79836. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79837. s->depth[n] : s->depth[m]) + 1);
  79838. tree[n].Dad = tree[m].Dad = (ush)node;
  79839. #ifdef DUMP_BL_TREE
  79840. if (tree == s->bl_tree) {
  79841. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79842. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79843. }
  79844. #endif
  79845. s->heap[SMALLEST] = node++;
  79846. pqdownheap(s, tree, SMALLEST);
  79847. } while (s->heap_len >= 2);
  79848. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79849. gen_bitlen(s, (tree_desc *)desc);
  79850. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79851. }
  79852. local void scan_tree (deflate_state *s,
  79853. ct_data *tree, /* the tree to be scanned */
  79854. int max_code) /* and its largest code of non zero frequency */
  79855. {
  79856. int n; /* iterates over all tree elements */
  79857. int prevlen = -1; /* last emitted length */
  79858. int curlen; /* length of current code */
  79859. int nextlen = tree[0].Len; /* length of next code */
  79860. int count = 0; /* repeat count of the current code */
  79861. int max_count = 7; /* max repeat count */
  79862. int min_count = 4; /* min repeat count */
  79863. if (nextlen == 0) max_count = 138, min_count = 3;
  79864. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79865. for (n = 0; n <= max_code; n++) {
  79866. curlen = nextlen; nextlen = tree[n+1].Len;
  79867. if (++count < max_count && curlen == nextlen) {
  79868. continue;
  79869. } else if (count < min_count) {
  79870. s->bl_tree[curlen].Freq += count;
  79871. } else if (curlen != 0) {
  79872. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79873. s->bl_tree[REP_3_6].Freq++;
  79874. } else if (count <= 10) {
  79875. s->bl_tree[REPZ_3_10].Freq++;
  79876. } else {
  79877. s->bl_tree[REPZ_11_138].Freq++;
  79878. }
  79879. count = 0; prevlen = curlen;
  79880. if (nextlen == 0) {
  79881. max_count = 138, min_count = 3;
  79882. } else if (curlen == nextlen) {
  79883. max_count = 6, min_count = 3;
  79884. } else {
  79885. max_count = 7, min_count = 4;
  79886. }
  79887. }
  79888. }
  79889. local void send_tree (deflate_state *s,
  79890. ct_data *tree, /* the tree to be scanned */
  79891. int max_code) /* and its largest code of non zero frequency */
  79892. {
  79893. int n; /* iterates over all tree elements */
  79894. int prevlen = -1; /* last emitted length */
  79895. int curlen; /* length of current code */
  79896. int nextlen = tree[0].Len; /* length of next code */
  79897. int count = 0; /* repeat count of the current code */
  79898. int max_count = 7; /* max repeat count */
  79899. int min_count = 4; /* min repeat count */
  79900. /* guard already set */
  79901. if (nextlen == 0) max_count = 138, min_count = 3;
  79902. for (n = 0; n <= max_code; n++) {
  79903. curlen = nextlen; nextlen = tree[n+1].Len;
  79904. if (++count < max_count && curlen == nextlen) {
  79905. continue;
  79906. } else if (count < min_count) {
  79907. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79908. } else if (curlen != 0) {
  79909. if (curlen != prevlen) {
  79910. send_code(s, curlen, s->bl_tree); count--;
  79911. }
  79912. Assert(count >= 3 && count <= 6, " 3_6?");
  79913. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79914. } else if (count <= 10) {
  79915. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79916. } else {
  79917. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79918. }
  79919. count = 0; prevlen = curlen;
  79920. if (nextlen == 0) {
  79921. max_count = 138, min_count = 3;
  79922. } else if (curlen == nextlen) {
  79923. max_count = 6, min_count = 3;
  79924. } else {
  79925. max_count = 7, min_count = 4;
  79926. }
  79927. }
  79928. }
  79929. local int build_bl_tree (deflate_state *s)
  79930. {
  79931. int max_blindex; /* index of last bit length code of non zero freq */
  79932. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  79933. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  79934. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  79935. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  79936. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  79937. }
  79938. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  79939. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  79940. s->opt_len, s->static_len));
  79941. return max_blindex;
  79942. }
  79943. local void send_all_trees (deflate_state *s,
  79944. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  79945. {
  79946. int rank; /* index in bl_order */
  79947. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  79948. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  79949. "too many codes");
  79950. Tracev((stderr, "\nbl counts: "));
  79951. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  79952. send_bits(s, dcodes-1, 5);
  79953. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  79954. for (rank = 0; rank < blcodes; rank++) {
  79955. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  79956. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  79957. }
  79958. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  79959. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  79960. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  79961. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  79962. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  79963. }
  79964. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  79965. {
  79966. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  79967. #ifdef DEBUG
  79968. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  79969. s->compressed_len += (stored_len + 4) << 3;
  79970. #endif
  79971. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  79972. }
  79973. void _tr_align (deflate_state *s)
  79974. {
  79975. send_bits(s, STATIC_TREES<<1, 3);
  79976. send_code(s, END_BLOCK, static_ltree);
  79977. #ifdef DEBUG
  79978. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  79979. #endif
  79980. bi_flush(s);
  79981. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  79982. send_bits(s, STATIC_TREES<<1, 3);
  79983. send_code(s, END_BLOCK, static_ltree);
  79984. #ifdef DEBUG
  79985. s->compressed_len += 10L;
  79986. #endif
  79987. bi_flush(s);
  79988. }
  79989. s->last_eob_len = 7;
  79990. }
  79991. void _tr_flush_block (deflate_state *s,
  79992. charf *buf, /* input block, or NULL if too old */
  79993. ulg stored_len, /* length of input block */
  79994. int eof) /* true if this is the last block for a file */
  79995. {
  79996. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  79997. int max_blindex = 0; /* index of last bit length code of non zero freq */
  79998. if (s->level > 0) {
  79999. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  80000. set_data_type(s);
  80001. build_tree(s, (tree_desc *)(&(s->l_desc)));
  80002. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  80003. s->static_len));
  80004. build_tree(s, (tree_desc *)(&(s->d_desc)));
  80005. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  80006. s->static_len));
  80007. max_blindex = build_bl_tree(s);
  80008. opt_lenb = (s->opt_len+3+7)>>3;
  80009. static_lenb = (s->static_len+3+7)>>3;
  80010. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80011. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80012. s->last_lit));
  80013. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80014. } else {
  80015. Assert(buf != (char*)0, "lost buf");
  80016. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80017. }
  80018. #ifdef FORCE_STORED
  80019. if (buf != (char*)0) { /* force stored block */
  80020. #else
  80021. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80022. #endif
  80023. _tr_stored_block(s, buf, stored_len, eof);
  80024. #ifdef FORCE_STATIC
  80025. } else if (static_lenb >= 0) { /* force static trees */
  80026. #else
  80027. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80028. #endif
  80029. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80030. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80031. #ifdef DEBUG
  80032. s->compressed_len += 3 + s->static_len;
  80033. #endif
  80034. } else {
  80035. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80036. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80037. max_blindex+1);
  80038. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80039. #ifdef DEBUG
  80040. s->compressed_len += 3 + s->opt_len;
  80041. #endif
  80042. }
  80043. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80044. init_block(s);
  80045. if (eof) {
  80046. bi_windup(s);
  80047. #ifdef DEBUG
  80048. s->compressed_len += 7; /* align on byte boundary */
  80049. #endif
  80050. }
  80051. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80052. s->compressed_len-7*eof));
  80053. }
  80054. int _tr_tally (deflate_state *s,
  80055. unsigned dist, /* distance of matched string */
  80056. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80057. {
  80058. s->d_buf[s->last_lit] = (ush)dist;
  80059. s->l_buf[s->last_lit++] = (uch)lc;
  80060. if (dist == 0) {
  80061. s->dyn_ltree[lc].Freq++;
  80062. } else {
  80063. s->matches++;
  80064. dist--; /* dist = match distance - 1 */
  80065. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80066. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80067. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80068. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80069. s->dyn_dtree[d_code(dist)].Freq++;
  80070. }
  80071. #ifdef TRUNCATE_BLOCK
  80072. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80073. ulg out_length = (ulg)s->last_lit*8L;
  80074. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80075. int dcode;
  80076. for (dcode = 0; dcode < D_CODES; dcode++) {
  80077. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80078. (5L+extra_dbits[dcode]);
  80079. }
  80080. out_length >>= 3;
  80081. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80082. s->last_lit, in_length, out_length,
  80083. 100L - out_length*100L/in_length));
  80084. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80085. }
  80086. #endif
  80087. return (s->last_lit == s->lit_bufsize-1);
  80088. }
  80089. local void compress_block (deflate_state *s,
  80090. ct_data *ltree, /* literal tree */
  80091. ct_data *dtree) /* distance tree */
  80092. {
  80093. unsigned dist; /* distance of matched string */
  80094. int lc; /* match length or unmatched char (if dist == 0) */
  80095. unsigned lx = 0; /* running index in l_buf */
  80096. unsigned code; /* the code to send */
  80097. int extra; /* number of extra bits to send */
  80098. if (s->last_lit != 0) do {
  80099. dist = s->d_buf[lx];
  80100. lc = s->l_buf[lx++];
  80101. if (dist == 0) {
  80102. send_code(s, lc, ltree); /* send a literal byte */
  80103. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80104. } else {
  80105. code = _length_code[lc];
  80106. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80107. extra = extra_lbits[code];
  80108. if (extra != 0) {
  80109. lc -= base_length[code];
  80110. send_bits(s, lc, extra); /* send the extra length bits */
  80111. }
  80112. dist--; /* dist is now the match distance - 1 */
  80113. code = d_code(dist);
  80114. Assert (code < D_CODES, "bad d_code");
  80115. send_code(s, code, dtree); /* send the distance code */
  80116. extra = extra_dbits[code];
  80117. if (extra != 0) {
  80118. dist -= base_dist[code];
  80119. send_bits(s, dist, extra); /* send the extra distance bits */
  80120. }
  80121. } /* literal or match pair ? */
  80122. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80123. "pendingBuf overflow");
  80124. } while (lx < s->last_lit);
  80125. send_code(s, END_BLOCK, ltree);
  80126. s->last_eob_len = ltree[END_BLOCK].Len;
  80127. }
  80128. local void set_data_type (deflate_state *s)
  80129. {
  80130. int n;
  80131. for (n = 0; n < 9; n++)
  80132. if (s->dyn_ltree[n].Freq != 0)
  80133. break;
  80134. if (n == 9)
  80135. for (n = 14; n < 32; n++)
  80136. if (s->dyn_ltree[n].Freq != 0)
  80137. break;
  80138. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80139. }
  80140. local unsigned bi_reverse (unsigned code, int len)
  80141. {
  80142. register unsigned res = 0;
  80143. do {
  80144. res |= code & 1;
  80145. code >>= 1, res <<= 1;
  80146. } while (--len > 0);
  80147. return res >> 1;
  80148. }
  80149. local void bi_flush (deflate_state *s)
  80150. {
  80151. if (s->bi_valid == 16) {
  80152. put_short(s, s->bi_buf);
  80153. s->bi_buf = 0;
  80154. s->bi_valid = 0;
  80155. } else if (s->bi_valid >= 8) {
  80156. put_byte(s, (Byte)s->bi_buf);
  80157. s->bi_buf >>= 8;
  80158. s->bi_valid -= 8;
  80159. }
  80160. }
  80161. local void bi_windup (deflate_state *s)
  80162. {
  80163. if (s->bi_valid > 8) {
  80164. put_short(s, s->bi_buf);
  80165. } else if (s->bi_valid > 0) {
  80166. put_byte(s, (Byte)s->bi_buf);
  80167. }
  80168. s->bi_buf = 0;
  80169. s->bi_valid = 0;
  80170. #ifdef DEBUG
  80171. s->bits_sent = (s->bits_sent+7) & ~7;
  80172. #endif
  80173. }
  80174. local void copy_block(deflate_state *s,
  80175. charf *buf, /* the input data */
  80176. unsigned len, /* its length */
  80177. int header) /* true if block header must be written */
  80178. {
  80179. bi_windup(s); /* align on byte boundary */
  80180. s->last_eob_len = 8; /* enough lookahead for inflate */
  80181. if (header) {
  80182. put_short(s, (ush)len);
  80183. put_short(s, (ush)~len);
  80184. #ifdef DEBUG
  80185. s->bits_sent += 2*16;
  80186. #endif
  80187. }
  80188. #ifdef DEBUG
  80189. s->bits_sent += (ulg)len<<3;
  80190. #endif
  80191. while (len--) {
  80192. put_byte(s, *buf++);
  80193. }
  80194. }
  80195. /*** End of inlined file: trees.c ***/
  80196. /*** Start of inlined file: zutil.c ***/
  80197. #ifndef NO_DUMMY_DECL
  80198. struct internal_state {int dummy;}; /* for buggy compilers */
  80199. #endif
  80200. const char * const z_errmsg[10] = {
  80201. "need dictionary", /* Z_NEED_DICT 2 */
  80202. "stream end", /* Z_STREAM_END 1 */
  80203. "", /* Z_OK 0 */
  80204. "file error", /* Z_ERRNO (-1) */
  80205. "stream error", /* Z_STREAM_ERROR (-2) */
  80206. "data error", /* Z_DATA_ERROR (-3) */
  80207. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80208. "buffer error", /* Z_BUF_ERROR (-5) */
  80209. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80210. ""};
  80211. #ifdef DEBUG
  80212. # ifndef verbose
  80213. # define verbose 0
  80214. # endif
  80215. int z_verbose = verbose;
  80216. void z_error (const char *m)
  80217. {
  80218. fprintf(stderr, "%s\n", m);
  80219. exit(1);
  80220. }
  80221. #endif
  80222. const char * ZEXPORT zError(int err)
  80223. {
  80224. return ERR_MSG(err);
  80225. }
  80226. #if defined(_WIN32_WCE)
  80227. int errno = 0;
  80228. #endif
  80229. #ifndef HAVE_MEMCPY
  80230. void zmemcpy(dest, source, len)
  80231. Bytef* dest;
  80232. const Bytef* source;
  80233. uInt len;
  80234. {
  80235. if (len == 0) return;
  80236. do {
  80237. *dest++ = *source++; /* ??? to be unrolled */
  80238. } while (--len != 0);
  80239. }
  80240. int zmemcmp(s1, s2, len)
  80241. const Bytef* s1;
  80242. const Bytef* s2;
  80243. uInt len;
  80244. {
  80245. uInt j;
  80246. for (j = 0; j < len; j++) {
  80247. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80248. }
  80249. return 0;
  80250. }
  80251. void zmemzero(dest, len)
  80252. Bytef* dest;
  80253. uInt len;
  80254. {
  80255. if (len == 0) return;
  80256. do {
  80257. *dest++ = 0; /* ??? to be unrolled */
  80258. } while (--len != 0);
  80259. }
  80260. #endif
  80261. #ifdef SYS16BIT
  80262. #ifdef __TURBOC__
  80263. # define MY_ZCALLOC
  80264. #define MAX_PTR 10
  80265. local int next_ptr = 0;
  80266. typedef struct ptr_table_s {
  80267. voidpf org_ptr;
  80268. voidpf new_ptr;
  80269. } ptr_table;
  80270. local ptr_table table[MAX_PTR];
  80271. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80272. {
  80273. voidpf buf = opaque; /* just to make some compilers happy */
  80274. ulg bsize = (ulg)items*size;
  80275. if (bsize < 65520L) {
  80276. buf = farmalloc(bsize);
  80277. if (*(ush*)&buf != 0) return buf;
  80278. } else {
  80279. buf = farmalloc(bsize + 16L);
  80280. }
  80281. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80282. table[next_ptr].org_ptr = buf;
  80283. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80284. *(ush*)&buf = 0;
  80285. table[next_ptr++].new_ptr = buf;
  80286. return buf;
  80287. }
  80288. void zcfree (voidpf opaque, voidpf ptr)
  80289. {
  80290. int n;
  80291. if (*(ush*)&ptr != 0) { /* object < 64K */
  80292. farfree(ptr);
  80293. return;
  80294. }
  80295. for (n = 0; n < next_ptr; n++) {
  80296. if (ptr != table[n].new_ptr) continue;
  80297. farfree(table[n].org_ptr);
  80298. while (++n < next_ptr) {
  80299. table[n-1] = table[n];
  80300. }
  80301. next_ptr--;
  80302. return;
  80303. }
  80304. ptr = opaque; /* just to make some compilers happy */
  80305. Assert(0, "zcfree: ptr not found");
  80306. }
  80307. #endif /* __TURBOC__ */
  80308. #ifdef M_I86
  80309. # define MY_ZCALLOC
  80310. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80311. # define _halloc halloc
  80312. # define _hfree hfree
  80313. #endif
  80314. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80315. {
  80316. if (opaque) opaque = 0; /* to make compiler happy */
  80317. return _halloc((long)items, size);
  80318. }
  80319. void zcfree (voidpf opaque, voidpf ptr)
  80320. {
  80321. if (opaque) opaque = 0; /* to make compiler happy */
  80322. _hfree(ptr);
  80323. }
  80324. #endif /* M_I86 */
  80325. #endif /* SYS16BIT */
  80326. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80327. #ifndef STDC
  80328. extern voidp malloc OF((uInt size));
  80329. extern voidp calloc OF((uInt items, uInt size));
  80330. extern void free OF((voidpf ptr));
  80331. #endif
  80332. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80333. {
  80334. if (opaque) items += size - size; /* make compiler happy */
  80335. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80336. (voidpf)calloc(items, size);
  80337. }
  80338. void zcfree (voidpf opaque, voidpf ptr)
  80339. {
  80340. free(ptr);
  80341. if (opaque) return; /* make compiler happy */
  80342. }
  80343. #endif /* MY_ZCALLOC */
  80344. /*** End of inlined file: zutil.c ***/
  80345. #undef Byte
  80346. }
  80347. #else
  80348. #include <zlib.h>
  80349. #endif
  80350. }
  80351. #if JUCE_MSVC
  80352. #pragma warning (pop)
  80353. #endif
  80354. BEGIN_JUCE_NAMESPACE
  80355. // internal helper object that holds the zlib structures so they don't have to be
  80356. // included publicly.
  80357. class GZIPDecompressHelper
  80358. {
  80359. public:
  80360. GZIPDecompressHelper (const bool noWrap)
  80361. : finished (true),
  80362. needsDictionary (false),
  80363. error (true),
  80364. streamIsValid (false),
  80365. data (0),
  80366. dataSize (0)
  80367. {
  80368. using namespace zlibNamespace;
  80369. zerostruct (stream);
  80370. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80371. finished = error = ! streamIsValid;
  80372. }
  80373. ~GZIPDecompressHelper()
  80374. {
  80375. using namespace zlibNamespace;
  80376. if (streamIsValid)
  80377. inflateEnd (&stream);
  80378. }
  80379. bool needsInput() const throw() { return dataSize <= 0; }
  80380. void setInput (uint8* const data_, const int size) throw()
  80381. {
  80382. data = data_;
  80383. dataSize = size;
  80384. }
  80385. int doNextBlock (uint8* const dest, const int destSize)
  80386. {
  80387. using namespace zlibNamespace;
  80388. if (streamIsValid && data != 0 && ! finished)
  80389. {
  80390. stream.next_in = data;
  80391. stream.next_out = dest;
  80392. stream.avail_in = dataSize;
  80393. stream.avail_out = destSize;
  80394. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80395. {
  80396. case Z_STREAM_END:
  80397. finished = true;
  80398. // deliberate fall-through
  80399. case Z_OK:
  80400. data += dataSize - stream.avail_in;
  80401. dataSize = stream.avail_in;
  80402. return destSize - stream.avail_out;
  80403. case Z_NEED_DICT:
  80404. needsDictionary = true;
  80405. data += dataSize - stream.avail_in;
  80406. dataSize = stream.avail_in;
  80407. break;
  80408. case Z_DATA_ERROR:
  80409. case Z_MEM_ERROR:
  80410. error = true;
  80411. default:
  80412. break;
  80413. }
  80414. }
  80415. return 0;
  80416. }
  80417. bool finished, needsDictionary, error, streamIsValid;
  80418. private:
  80419. zlibNamespace::z_stream stream;
  80420. uint8* data;
  80421. int dataSize;
  80422. GZIPDecompressHelper (const GZIPDecompressHelper&);
  80423. GZIPDecompressHelper& operator= (const GZIPDecompressHelper&);
  80424. };
  80425. const int gzipDecompBufferSize = 32768;
  80426. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80427. const bool deleteSourceWhenDestroyed,
  80428. const bool noWrap_,
  80429. const int64 uncompressedStreamLength_)
  80430. : sourceStream (sourceStream_),
  80431. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80432. uncompressedStreamLength (uncompressedStreamLength_),
  80433. noWrap (noWrap_),
  80434. isEof (false),
  80435. activeBufferSize (0),
  80436. originalSourcePos (sourceStream_->getPosition()),
  80437. currentPos (0),
  80438. buffer (gzipDecompBufferSize),
  80439. helper (new GZIPDecompressHelper (noWrap_))
  80440. {
  80441. }
  80442. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80443. {
  80444. }
  80445. int64 GZIPDecompressorInputStream::getTotalLength()
  80446. {
  80447. return uncompressedStreamLength;
  80448. }
  80449. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80450. {
  80451. if ((howMany > 0) && ! isEof)
  80452. {
  80453. jassert (destBuffer != 0);
  80454. if (destBuffer != 0)
  80455. {
  80456. int numRead = 0;
  80457. uint8* d = (uint8*) destBuffer;
  80458. while (! helper->error)
  80459. {
  80460. const int n = helper->doNextBlock (d, howMany);
  80461. currentPos += n;
  80462. if (n == 0)
  80463. {
  80464. if (helper->finished || helper->needsDictionary)
  80465. {
  80466. isEof = true;
  80467. return numRead;
  80468. }
  80469. if (helper->needsInput())
  80470. {
  80471. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80472. if (activeBufferSize > 0)
  80473. {
  80474. helper->setInput ((uint8*) buffer, activeBufferSize);
  80475. }
  80476. else
  80477. {
  80478. isEof = true;
  80479. return numRead;
  80480. }
  80481. }
  80482. }
  80483. else
  80484. {
  80485. numRead += n;
  80486. howMany -= n;
  80487. d += n;
  80488. if (howMany <= 0)
  80489. return numRead;
  80490. }
  80491. }
  80492. }
  80493. }
  80494. return 0;
  80495. }
  80496. bool GZIPDecompressorInputStream::isExhausted()
  80497. {
  80498. return helper->error || isEof;
  80499. }
  80500. int64 GZIPDecompressorInputStream::getPosition()
  80501. {
  80502. return currentPos;
  80503. }
  80504. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80505. {
  80506. if (newPos < currentPos)
  80507. {
  80508. // to go backwards, reset the stream and start again..
  80509. isEof = false;
  80510. activeBufferSize = 0;
  80511. currentPos = 0;
  80512. helper = new GZIPDecompressHelper (noWrap);
  80513. sourceStream->setPosition (originalSourcePos);
  80514. }
  80515. skipNextBytes (newPos - currentPos);
  80516. return true;
  80517. }
  80518. END_JUCE_NAMESPACE
  80519. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80520. #endif
  80521. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80522. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80523. #if JUCE_USE_FLAC
  80524. #if JUCE_WINDOWS
  80525. #include <windows.h>
  80526. #endif
  80527. #ifdef _MSC_VER
  80528. #pragma warning (disable : 4505)
  80529. #pragma warning (push)
  80530. #endif
  80531. namespace FlacNamespace
  80532. {
  80533. #if JUCE_INCLUDE_FLAC_CODE
  80534. #define FLAC__NO_DLL 1
  80535. #if ! defined (SIZE_MAX)
  80536. #define SIZE_MAX 0xffffffff
  80537. #endif
  80538. #define __STDC_LIMIT_MACROS 1
  80539. /*** Start of inlined file: all.h ***/
  80540. #ifndef FLAC__ALL_H
  80541. #define FLAC__ALL_H
  80542. /*** Start of inlined file: export.h ***/
  80543. #ifndef FLAC__EXPORT_H
  80544. #define FLAC__EXPORT_H
  80545. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80546. #define FLAC_API
  80547. #else
  80548. #ifdef FLAC_API_EXPORTS
  80549. #define FLAC_API _declspec(dllexport)
  80550. #else
  80551. #define FLAC_API _declspec(dllimport)
  80552. #endif
  80553. #endif
  80554. #define FLAC_API_VERSION_CURRENT 10
  80555. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80556. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80557. #ifdef __cplusplus
  80558. extern "C" {
  80559. #endif
  80560. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80561. #ifdef __cplusplus
  80562. }
  80563. #endif
  80564. #endif
  80565. /*** End of inlined file: export.h ***/
  80566. /*** Start of inlined file: assert.h ***/
  80567. #ifndef FLAC__ASSERT_H
  80568. #define FLAC__ASSERT_H
  80569. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80570. #ifdef DEBUG
  80571. #include <assert.h>
  80572. #define FLAC__ASSERT(x) assert(x)
  80573. #define FLAC__ASSERT_DECLARATION(x) x
  80574. #else
  80575. #define FLAC__ASSERT(x)
  80576. #define FLAC__ASSERT_DECLARATION(x)
  80577. #endif
  80578. #endif
  80579. /*** End of inlined file: assert.h ***/
  80580. /*** Start of inlined file: callback.h ***/
  80581. #ifndef FLAC__CALLBACK_H
  80582. #define FLAC__CALLBACK_H
  80583. /*** Start of inlined file: ordinals.h ***/
  80584. #ifndef FLAC__ORDINALS_H
  80585. #define FLAC__ORDINALS_H
  80586. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80587. #include <inttypes.h>
  80588. #endif
  80589. typedef signed char FLAC__int8;
  80590. typedef unsigned char FLAC__uint8;
  80591. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80592. typedef __int16 FLAC__int16;
  80593. typedef __int32 FLAC__int32;
  80594. typedef __int64 FLAC__int64;
  80595. typedef unsigned __int16 FLAC__uint16;
  80596. typedef unsigned __int32 FLAC__uint32;
  80597. typedef unsigned __int64 FLAC__uint64;
  80598. #elif defined(__EMX__)
  80599. typedef short FLAC__int16;
  80600. typedef long FLAC__int32;
  80601. typedef long long FLAC__int64;
  80602. typedef unsigned short FLAC__uint16;
  80603. typedef unsigned long FLAC__uint32;
  80604. typedef unsigned long long FLAC__uint64;
  80605. #else
  80606. typedef int16_t FLAC__int16;
  80607. typedef int32_t FLAC__int32;
  80608. typedef int64_t FLAC__int64;
  80609. typedef uint16_t FLAC__uint16;
  80610. typedef uint32_t FLAC__uint32;
  80611. typedef uint64_t FLAC__uint64;
  80612. #endif
  80613. typedef int FLAC__bool;
  80614. typedef FLAC__uint8 FLAC__byte;
  80615. #ifdef true
  80616. #undef true
  80617. #endif
  80618. #ifdef false
  80619. #undef false
  80620. #endif
  80621. #ifndef __cplusplus
  80622. #define true 1
  80623. #define false 0
  80624. #endif
  80625. #endif
  80626. /*** End of inlined file: ordinals.h ***/
  80627. #include <stdlib.h> /* for size_t */
  80628. #ifdef __cplusplus
  80629. extern "C" {
  80630. #endif
  80631. typedef void* FLAC__IOHandle;
  80632. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80633. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80634. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80635. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80636. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80637. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80638. typedef struct {
  80639. FLAC__IOCallback_Read read;
  80640. FLAC__IOCallback_Write write;
  80641. FLAC__IOCallback_Seek seek;
  80642. FLAC__IOCallback_Tell tell;
  80643. FLAC__IOCallback_Eof eof;
  80644. FLAC__IOCallback_Close close;
  80645. } FLAC__IOCallbacks;
  80646. #ifdef __cplusplus
  80647. }
  80648. #endif
  80649. #endif
  80650. /*** End of inlined file: callback.h ***/
  80651. /*** Start of inlined file: format.h ***/
  80652. #ifndef FLAC__FORMAT_H
  80653. #define FLAC__FORMAT_H
  80654. #ifdef __cplusplus
  80655. extern "C" {
  80656. #endif
  80657. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80658. #define FLAC__MIN_BLOCK_SIZE (16u)
  80659. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80660. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80661. #define FLAC__MAX_CHANNELS (8u)
  80662. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80663. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80664. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80665. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80666. #define FLAC__MAX_LPC_ORDER (32u)
  80667. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80668. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80669. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80670. #define FLAC__MAX_FIXED_ORDER (4u)
  80671. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80672. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80673. extern FLAC_API const char *FLAC__VERSION_STRING;
  80674. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80675. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80676. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80677. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80678. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80679. typedef enum {
  80680. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80681. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80682. } FLAC__EntropyCodingMethodType;
  80683. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80684. typedef struct {
  80685. unsigned *parameters;
  80686. unsigned *raw_bits;
  80687. unsigned capacity_by_order;
  80688. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80689. typedef struct {
  80690. unsigned order;
  80691. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80692. } FLAC__EntropyCodingMethod_PartitionedRice;
  80693. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80694. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80695. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80696. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80697. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80698. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80699. typedef struct {
  80700. FLAC__EntropyCodingMethodType type;
  80701. union {
  80702. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80703. } data;
  80704. } FLAC__EntropyCodingMethod;
  80705. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80706. typedef enum {
  80707. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80708. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80709. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80710. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80711. } FLAC__SubframeType;
  80712. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80713. typedef struct {
  80714. FLAC__int32 value; /**< The constant signal value. */
  80715. } FLAC__Subframe_Constant;
  80716. typedef struct {
  80717. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80718. } FLAC__Subframe_Verbatim;
  80719. typedef struct {
  80720. FLAC__EntropyCodingMethod entropy_coding_method;
  80721. unsigned order;
  80722. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80723. const FLAC__int32 *residual;
  80724. } FLAC__Subframe_Fixed;
  80725. typedef struct {
  80726. FLAC__EntropyCodingMethod entropy_coding_method;
  80727. unsigned order;
  80728. unsigned qlp_coeff_precision;
  80729. int quantization_level;
  80730. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80731. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80732. const FLAC__int32 *residual;
  80733. } FLAC__Subframe_LPC;
  80734. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80735. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80736. typedef struct {
  80737. FLAC__SubframeType type;
  80738. union {
  80739. FLAC__Subframe_Constant constant;
  80740. FLAC__Subframe_Fixed fixed;
  80741. FLAC__Subframe_LPC lpc;
  80742. FLAC__Subframe_Verbatim verbatim;
  80743. } data;
  80744. unsigned wasted_bits;
  80745. } FLAC__Subframe;
  80746. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80747. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80748. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80749. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80750. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80751. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80752. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80753. typedef enum {
  80754. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80755. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80756. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80757. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80758. } FLAC__ChannelAssignment;
  80759. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80760. typedef enum {
  80761. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80762. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80763. } FLAC__FrameNumberType;
  80764. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80765. typedef struct {
  80766. unsigned blocksize;
  80767. unsigned sample_rate;
  80768. unsigned channels;
  80769. FLAC__ChannelAssignment channel_assignment;
  80770. unsigned bits_per_sample;
  80771. FLAC__FrameNumberType number_type;
  80772. union {
  80773. FLAC__uint32 frame_number;
  80774. FLAC__uint64 sample_number;
  80775. } number;
  80776. FLAC__uint8 crc;
  80777. } FLAC__FrameHeader;
  80778. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80779. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80780. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80781. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80782. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80783. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80784. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80785. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80786. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80787. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80788. typedef struct {
  80789. FLAC__uint16 crc;
  80790. } FLAC__FrameFooter;
  80791. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80792. typedef struct {
  80793. FLAC__FrameHeader header;
  80794. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80795. FLAC__FrameFooter footer;
  80796. } FLAC__Frame;
  80797. typedef enum {
  80798. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80799. FLAC__METADATA_TYPE_PADDING = 1,
  80800. FLAC__METADATA_TYPE_APPLICATION = 2,
  80801. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80802. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80803. FLAC__METADATA_TYPE_CUESHEET = 5,
  80804. FLAC__METADATA_TYPE_PICTURE = 6,
  80805. FLAC__METADATA_TYPE_UNDEFINED = 7
  80806. } FLAC__MetadataType;
  80807. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80808. typedef struct {
  80809. unsigned min_blocksize, max_blocksize;
  80810. unsigned min_framesize, max_framesize;
  80811. unsigned sample_rate;
  80812. unsigned channels;
  80813. unsigned bits_per_sample;
  80814. FLAC__uint64 total_samples;
  80815. FLAC__byte md5sum[16];
  80816. } FLAC__StreamMetadata_StreamInfo;
  80817. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80818. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80819. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80820. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80821. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80822. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80823. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80824. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80825. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80826. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80827. typedef struct {
  80828. int dummy;
  80829. } FLAC__StreamMetadata_Padding;
  80830. typedef struct {
  80831. FLAC__byte id[4];
  80832. FLAC__byte *data;
  80833. } FLAC__StreamMetadata_Application;
  80834. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80835. typedef struct {
  80836. FLAC__uint64 sample_number;
  80837. FLAC__uint64 stream_offset;
  80838. unsigned frame_samples;
  80839. } FLAC__StreamMetadata_SeekPoint;
  80840. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80841. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80842. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80843. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80844. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80845. typedef struct {
  80846. unsigned num_points;
  80847. FLAC__StreamMetadata_SeekPoint *points;
  80848. } FLAC__StreamMetadata_SeekTable;
  80849. typedef struct {
  80850. FLAC__uint32 length;
  80851. FLAC__byte *entry;
  80852. } FLAC__StreamMetadata_VorbisComment_Entry;
  80853. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80854. typedef struct {
  80855. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80856. FLAC__uint32 num_comments;
  80857. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80858. } FLAC__StreamMetadata_VorbisComment;
  80859. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80860. typedef struct {
  80861. FLAC__uint64 offset;
  80862. FLAC__byte number;
  80863. } FLAC__StreamMetadata_CueSheet_Index;
  80864. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80865. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80866. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80867. typedef struct {
  80868. FLAC__uint64 offset;
  80869. FLAC__byte number;
  80870. char isrc[13];
  80871. unsigned type:1;
  80872. unsigned pre_emphasis:1;
  80873. FLAC__byte num_indices;
  80874. FLAC__StreamMetadata_CueSheet_Index *indices;
  80875. } FLAC__StreamMetadata_CueSheet_Track;
  80876. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80877. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80878. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80879. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80880. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80881. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80882. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80883. typedef struct {
  80884. char media_catalog_number[129];
  80885. FLAC__uint64 lead_in;
  80886. FLAC__bool is_cd;
  80887. unsigned num_tracks;
  80888. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80889. } FLAC__StreamMetadata_CueSheet;
  80890. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80891. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80892. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80893. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80894. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80895. typedef enum {
  80896. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80897. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80898. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80899. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80900. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80901. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80902. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80903. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80904. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80905. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80906. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80907. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80908. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80909. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80910. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80911. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80912. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80913. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80914. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80915. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80916. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80917. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80918. } FLAC__StreamMetadata_Picture_Type;
  80919. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80920. typedef struct {
  80921. FLAC__StreamMetadata_Picture_Type type;
  80922. char *mime_type;
  80923. FLAC__byte *description;
  80924. FLAC__uint32 width;
  80925. FLAC__uint32 height;
  80926. FLAC__uint32 depth;
  80927. FLAC__uint32 colors;
  80928. FLAC__uint32 data_length;
  80929. FLAC__byte *data;
  80930. } FLAC__StreamMetadata_Picture;
  80931. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  80932. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  80933. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  80934. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  80935. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  80936. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  80937. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  80938. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  80939. typedef struct {
  80940. FLAC__byte *data;
  80941. } FLAC__StreamMetadata_Unknown;
  80942. typedef struct {
  80943. FLAC__MetadataType type;
  80944. FLAC__bool is_last;
  80945. unsigned length;
  80946. union {
  80947. FLAC__StreamMetadata_StreamInfo stream_info;
  80948. FLAC__StreamMetadata_Padding padding;
  80949. FLAC__StreamMetadata_Application application;
  80950. FLAC__StreamMetadata_SeekTable seek_table;
  80951. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  80952. FLAC__StreamMetadata_CueSheet cue_sheet;
  80953. FLAC__StreamMetadata_Picture picture;
  80954. FLAC__StreamMetadata_Unknown unknown;
  80955. } data;
  80956. } FLAC__StreamMetadata;
  80957. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  80958. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  80959. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  80960. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  80961. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  80962. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  80963. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  80964. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  80965. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  80966. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  80967. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  80968. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  80969. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  80970. #ifdef __cplusplus
  80971. }
  80972. #endif
  80973. #endif
  80974. /*** End of inlined file: format.h ***/
  80975. /*** Start of inlined file: metadata.h ***/
  80976. #ifndef FLAC__METADATA_H
  80977. #define FLAC__METADATA_H
  80978. #include <sys/types.h> /* for off_t */
  80979. #ifdef __cplusplus
  80980. extern "C" {
  80981. #endif
  80982. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  80983. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  80984. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  80985. 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);
  80986. struct FLAC__Metadata_SimpleIterator;
  80987. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  80988. typedef enum {
  80989. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  80990. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  80991. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  80992. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  80993. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  80994. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  80995. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  80996. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  80997. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  80998. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  80999. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  81000. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  81001. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  81002. } FLAC__Metadata_SimpleIteratorStatus;
  81003. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  81004. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  81005. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  81006. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  81007. 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);
  81008. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  81009. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  81010. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81011. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81012. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81013. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81014. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81015. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81016. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81017. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81018. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81019. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81020. struct FLAC__Metadata_Chain;
  81021. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81022. struct FLAC__Metadata_Iterator;
  81023. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81024. typedef enum {
  81025. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81026. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81027. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81028. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81029. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81030. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81031. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81032. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81033. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81034. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81035. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81036. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81037. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81038. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81039. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81040. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81041. } FLAC__Metadata_ChainStatus;
  81042. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81043. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81044. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81045. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81046. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81047. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81048. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81049. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81050. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81051. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81052. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81053. 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);
  81054. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81055. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81056. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81057. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81058. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81059. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81060. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81061. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81062. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81063. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81064. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81065. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81066. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81067. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81068. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81069. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81070. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81071. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81072. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81073. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81074. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81075. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81076. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81077. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81078. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81079. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81080. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81081. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81082. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81083. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81084. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81085. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81086. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81087. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81088. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81089. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81090. 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);
  81091. 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);
  81092. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81093. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81094. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81095. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81096. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81097. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81098. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81099. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81100. 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);
  81101. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81102. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81103. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81104. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81105. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81106. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81107. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81108. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81109. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81110. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81111. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81112. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81113. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81114. #ifdef __cplusplus
  81115. }
  81116. #endif
  81117. #endif
  81118. /*** End of inlined file: metadata.h ***/
  81119. /*** Start of inlined file: stream_decoder.h ***/
  81120. #ifndef FLAC__STREAM_DECODER_H
  81121. #define FLAC__STREAM_DECODER_H
  81122. #include <stdio.h> /* for FILE */
  81123. #ifdef __cplusplus
  81124. extern "C" {
  81125. #endif
  81126. typedef enum {
  81127. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81128. FLAC__STREAM_DECODER_READ_METADATA,
  81129. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81130. FLAC__STREAM_DECODER_READ_FRAME,
  81131. FLAC__STREAM_DECODER_END_OF_STREAM,
  81132. FLAC__STREAM_DECODER_OGG_ERROR,
  81133. FLAC__STREAM_DECODER_SEEK_ERROR,
  81134. FLAC__STREAM_DECODER_ABORTED,
  81135. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81136. FLAC__STREAM_DECODER_UNINITIALIZED
  81137. } FLAC__StreamDecoderState;
  81138. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81139. typedef enum {
  81140. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81141. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81142. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81143. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81144. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81145. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81146. } FLAC__StreamDecoderInitStatus;
  81147. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81148. typedef enum {
  81149. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81150. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81151. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81152. } FLAC__StreamDecoderReadStatus;
  81153. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81154. typedef enum {
  81155. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81156. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81157. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81158. } FLAC__StreamDecoderSeekStatus;
  81159. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81160. typedef enum {
  81161. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81162. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81163. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81164. } FLAC__StreamDecoderTellStatus;
  81165. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81166. typedef enum {
  81167. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81168. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81169. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81170. } FLAC__StreamDecoderLengthStatus;
  81171. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81172. typedef enum {
  81173. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81174. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81175. } FLAC__StreamDecoderWriteStatus;
  81176. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81177. typedef enum {
  81178. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81179. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81180. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81181. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81182. } FLAC__StreamDecoderErrorStatus;
  81183. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81184. struct FLAC__StreamDecoderProtected;
  81185. struct FLAC__StreamDecoderPrivate;
  81186. typedef struct {
  81187. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81188. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81189. } FLAC__StreamDecoder;
  81190. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81191. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81192. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81193. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81194. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81195. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81196. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81197. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81198. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81199. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81200. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81201. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81202. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81203. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81204. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81205. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81206. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81207. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81208. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81209. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81210. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81211. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81212. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81213. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81214. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81215. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81216. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81217. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81218. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81219. FLAC__StreamDecoder *decoder,
  81220. FLAC__StreamDecoderReadCallback read_callback,
  81221. FLAC__StreamDecoderSeekCallback seek_callback,
  81222. FLAC__StreamDecoderTellCallback tell_callback,
  81223. FLAC__StreamDecoderLengthCallback length_callback,
  81224. FLAC__StreamDecoderEofCallback eof_callback,
  81225. FLAC__StreamDecoderWriteCallback write_callback,
  81226. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81227. FLAC__StreamDecoderErrorCallback error_callback,
  81228. void *client_data
  81229. );
  81230. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81231. FLAC__StreamDecoder *decoder,
  81232. FLAC__StreamDecoderReadCallback read_callback,
  81233. FLAC__StreamDecoderSeekCallback seek_callback,
  81234. FLAC__StreamDecoderTellCallback tell_callback,
  81235. FLAC__StreamDecoderLengthCallback length_callback,
  81236. FLAC__StreamDecoderEofCallback eof_callback,
  81237. FLAC__StreamDecoderWriteCallback write_callback,
  81238. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81239. FLAC__StreamDecoderErrorCallback error_callback,
  81240. void *client_data
  81241. );
  81242. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81243. FLAC__StreamDecoder *decoder,
  81244. FILE *file,
  81245. FLAC__StreamDecoderWriteCallback write_callback,
  81246. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81247. FLAC__StreamDecoderErrorCallback error_callback,
  81248. void *client_data
  81249. );
  81250. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81251. FLAC__StreamDecoder *decoder,
  81252. FILE *file,
  81253. FLAC__StreamDecoderWriteCallback write_callback,
  81254. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81255. FLAC__StreamDecoderErrorCallback error_callback,
  81256. void *client_data
  81257. );
  81258. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81259. FLAC__StreamDecoder *decoder,
  81260. const char *filename,
  81261. FLAC__StreamDecoderWriteCallback write_callback,
  81262. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81263. FLAC__StreamDecoderErrorCallback error_callback,
  81264. void *client_data
  81265. );
  81266. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81267. FLAC__StreamDecoder *decoder,
  81268. const char *filename,
  81269. FLAC__StreamDecoderWriteCallback write_callback,
  81270. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81271. FLAC__StreamDecoderErrorCallback error_callback,
  81272. void *client_data
  81273. );
  81274. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81275. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81276. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81277. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81278. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81279. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81280. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81281. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81282. #ifdef __cplusplus
  81283. }
  81284. #endif
  81285. #endif
  81286. /*** End of inlined file: stream_decoder.h ***/
  81287. /*** Start of inlined file: stream_encoder.h ***/
  81288. #ifndef FLAC__STREAM_ENCODER_H
  81289. #define FLAC__STREAM_ENCODER_H
  81290. #include <stdio.h> /* for FILE */
  81291. #ifdef __cplusplus
  81292. extern "C" {
  81293. #endif
  81294. typedef enum {
  81295. FLAC__STREAM_ENCODER_OK = 0,
  81296. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81297. FLAC__STREAM_ENCODER_OGG_ERROR,
  81298. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81299. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81300. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81301. FLAC__STREAM_ENCODER_IO_ERROR,
  81302. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81303. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81304. } FLAC__StreamEncoderState;
  81305. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81306. typedef enum {
  81307. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81308. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81309. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81310. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81311. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81312. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81313. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81314. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81315. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81316. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81317. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81318. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81319. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81320. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81321. } FLAC__StreamEncoderInitStatus;
  81322. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81323. typedef enum {
  81324. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81325. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81326. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81327. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81328. } FLAC__StreamEncoderReadStatus;
  81329. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81330. typedef enum {
  81331. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81332. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81333. } FLAC__StreamEncoderWriteStatus;
  81334. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81335. typedef enum {
  81336. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81337. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81338. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81339. } FLAC__StreamEncoderSeekStatus;
  81340. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81341. typedef enum {
  81342. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81343. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81344. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81345. } FLAC__StreamEncoderTellStatus;
  81346. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81347. struct FLAC__StreamEncoderProtected;
  81348. struct FLAC__StreamEncoderPrivate;
  81349. typedef struct {
  81350. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81351. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81352. } FLAC__StreamEncoder;
  81353. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81354. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81355. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81356. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81357. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81358. 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);
  81359. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81360. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81361. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81362. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81363. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81364. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81365. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81366. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81367. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81368. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81369. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81370. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81371. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81372. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81373. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81374. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81375. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81376. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81377. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81378. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81379. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81380. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81381. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81382. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81383. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81384. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81385. 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);
  81386. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81387. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81388. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81389. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81390. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81391. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81392. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81393. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81394. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81395. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81396. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81397. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81398. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81399. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81400. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81401. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81402. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81403. 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);
  81404. 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);
  81405. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81406. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81407. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81408. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81409. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81410. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81411. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81412. #ifdef __cplusplus
  81413. }
  81414. #endif
  81415. #endif
  81416. /*** End of inlined file: stream_encoder.h ***/
  81417. #ifdef _MSC_VER
  81418. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81419. {
  81420. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81421. return (x>>16) | (x<<16);
  81422. }
  81423. #endif
  81424. #if defined(_MSC_VER) && defined(_X86_)
  81425. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81426. {
  81427. __asm {
  81428. mov edx, start
  81429. mov ecx, len
  81430. test ecx, ecx
  81431. loop1:
  81432. jz done1
  81433. mov eax, [edx]
  81434. bswap eax
  81435. mov [edx], eax
  81436. add edx, 4
  81437. dec ecx
  81438. jmp short loop1
  81439. done1:
  81440. }
  81441. }
  81442. #endif
  81443. #endif
  81444. /*** End of inlined file: all.h ***/
  81445. /*** Start of inlined file: bitmath.c ***/
  81446. /*** Start of inlined file: juce_FlacHeader.h ***/
  81447. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81448. // tasks..
  81449. #define VERSION "1.2.1"
  81450. #define FLAC__NO_DLL 1
  81451. #if JUCE_MSVC
  81452. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81453. #endif
  81454. #if JUCE_MAC
  81455. #define FLAC__SYS_DARWIN 1
  81456. #endif
  81457. /*** End of inlined file: juce_FlacHeader.h ***/
  81458. #if JUCE_USE_FLAC
  81459. #if HAVE_CONFIG_H
  81460. # include <config.h>
  81461. #endif
  81462. /*** Start of inlined file: bitmath.h ***/
  81463. #ifndef FLAC__PRIVATE__BITMATH_H
  81464. #define FLAC__PRIVATE__BITMATH_H
  81465. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81466. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81467. unsigned FLAC__bitmath_silog2(int v);
  81468. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81469. #endif
  81470. /*** End of inlined file: bitmath.h ***/
  81471. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81472. {
  81473. unsigned l = 0;
  81474. FLAC__ASSERT(v > 0);
  81475. while(v >>= 1)
  81476. l++;
  81477. return l;
  81478. }
  81479. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81480. {
  81481. unsigned l = 0;
  81482. FLAC__ASSERT(v > 0);
  81483. while(v >>= 1)
  81484. l++;
  81485. return l;
  81486. }
  81487. unsigned FLAC__bitmath_silog2(int v)
  81488. {
  81489. while(1) {
  81490. if(v == 0) {
  81491. return 0;
  81492. }
  81493. else if(v > 0) {
  81494. unsigned l = 0;
  81495. while(v) {
  81496. l++;
  81497. v >>= 1;
  81498. }
  81499. return l+1;
  81500. }
  81501. else if(v == -1) {
  81502. return 2;
  81503. }
  81504. else {
  81505. v++;
  81506. v = -v;
  81507. }
  81508. }
  81509. }
  81510. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81511. {
  81512. while(1) {
  81513. if(v == 0) {
  81514. return 0;
  81515. }
  81516. else if(v > 0) {
  81517. unsigned l = 0;
  81518. while(v) {
  81519. l++;
  81520. v >>= 1;
  81521. }
  81522. return l+1;
  81523. }
  81524. else if(v == -1) {
  81525. return 2;
  81526. }
  81527. else {
  81528. v++;
  81529. v = -v;
  81530. }
  81531. }
  81532. }
  81533. #endif
  81534. /*** End of inlined file: bitmath.c ***/
  81535. /*** Start of inlined file: bitreader.c ***/
  81536. /*** Start of inlined file: juce_FlacHeader.h ***/
  81537. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81538. // tasks..
  81539. #define VERSION "1.2.1"
  81540. #define FLAC__NO_DLL 1
  81541. #if JUCE_MSVC
  81542. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81543. #endif
  81544. #if JUCE_MAC
  81545. #define FLAC__SYS_DARWIN 1
  81546. #endif
  81547. /*** End of inlined file: juce_FlacHeader.h ***/
  81548. #if JUCE_USE_FLAC
  81549. #if HAVE_CONFIG_H
  81550. # include <config.h>
  81551. #endif
  81552. #include <stdlib.h> /* for malloc() */
  81553. #include <string.h> /* for memcpy(), memset() */
  81554. #ifdef _MSC_VER
  81555. #include <winsock.h> /* for ntohl() */
  81556. #elif defined FLAC__SYS_DARWIN
  81557. #include <machine/endian.h> /* for ntohl() */
  81558. #elif defined __MINGW32__
  81559. #include <winsock.h> /* for ntohl() */
  81560. #else
  81561. #include <netinet/in.h> /* for ntohl() */
  81562. #endif
  81563. /*** Start of inlined file: bitreader.h ***/
  81564. #ifndef FLAC__PRIVATE__BITREADER_H
  81565. #define FLAC__PRIVATE__BITREADER_H
  81566. #include <stdio.h> /* for FILE */
  81567. /*** Start of inlined file: cpu.h ***/
  81568. #ifndef FLAC__PRIVATE__CPU_H
  81569. #define FLAC__PRIVATE__CPU_H
  81570. #ifdef HAVE_CONFIG_H
  81571. #include <config.h>
  81572. #endif
  81573. typedef enum {
  81574. FLAC__CPUINFO_TYPE_IA32,
  81575. FLAC__CPUINFO_TYPE_PPC,
  81576. FLAC__CPUINFO_TYPE_UNKNOWN
  81577. } FLAC__CPUInfo_Type;
  81578. typedef struct {
  81579. FLAC__bool cpuid;
  81580. FLAC__bool bswap;
  81581. FLAC__bool cmov;
  81582. FLAC__bool mmx;
  81583. FLAC__bool fxsr;
  81584. FLAC__bool sse;
  81585. FLAC__bool sse2;
  81586. FLAC__bool sse3;
  81587. FLAC__bool ssse3;
  81588. FLAC__bool _3dnow;
  81589. FLAC__bool ext3dnow;
  81590. FLAC__bool extmmx;
  81591. } FLAC__CPUInfo_IA32;
  81592. typedef struct {
  81593. FLAC__bool altivec;
  81594. FLAC__bool ppc64;
  81595. } FLAC__CPUInfo_PPC;
  81596. typedef struct {
  81597. FLAC__bool use_asm;
  81598. FLAC__CPUInfo_Type type;
  81599. union {
  81600. FLAC__CPUInfo_IA32 ia32;
  81601. FLAC__CPUInfo_PPC ppc;
  81602. } data;
  81603. } FLAC__CPUInfo;
  81604. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81605. #ifndef FLAC__NO_ASM
  81606. #ifdef FLAC__CPU_IA32
  81607. #ifdef FLAC__HAS_NASM
  81608. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81609. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81610. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81611. #endif
  81612. #endif
  81613. #endif
  81614. #endif
  81615. /*** End of inlined file: cpu.h ***/
  81616. struct FLAC__BitReader;
  81617. typedef struct FLAC__BitReader FLAC__BitReader;
  81618. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81619. FLAC__BitReader *FLAC__bitreader_new(void);
  81620. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81621. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81622. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81623. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81624. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81625. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81626. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81627. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81628. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81629. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81630. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81631. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81632. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81633. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81634. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81635. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81636. 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! */
  81637. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81638. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81639. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81640. #ifndef FLAC__NO_ASM
  81641. # ifdef FLAC__CPU_IA32
  81642. # ifdef FLAC__HAS_NASM
  81643. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81644. # endif
  81645. # endif
  81646. #endif
  81647. #if 0 /* UNUSED */
  81648. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81649. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81650. #endif
  81651. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81652. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81653. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81654. #endif
  81655. /*** End of inlined file: bitreader.h ***/
  81656. /*** Start of inlined file: crc.h ***/
  81657. #ifndef FLAC__PRIVATE__CRC_H
  81658. #define FLAC__PRIVATE__CRC_H
  81659. extern FLAC__byte const FLAC__crc8_table[256];
  81660. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81661. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81662. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81663. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81664. extern unsigned FLAC__crc16_table[256];
  81665. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81666. #if 0
  81667. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81668. #endif
  81669. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81670. #endif
  81671. /*** End of inlined file: crc.h ***/
  81672. typedef FLAC__uint32 brword;
  81673. #define FLAC__BYTES_PER_WORD 4
  81674. #define FLAC__BITS_PER_WORD 32
  81675. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81676. #if WORDS_BIGENDIAN
  81677. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81678. #else
  81679. #if defined (_MSC_VER) && defined (_X86_)
  81680. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81681. #else
  81682. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81683. #endif
  81684. #endif
  81685. #define COUNT_ZERO_MSBS(word) ( \
  81686. (word) <= 0xffff ? \
  81687. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81688. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81689. )
  81690. #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])) )
  81691. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81692. static const unsigned char byte_to_unary_table[] = {
  81693. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81694. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81695. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81696. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81697. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81698. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81699. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81700. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81709. };
  81710. #ifdef min
  81711. #undef min
  81712. #endif
  81713. #define min(x,y) ((x)<(y)?(x):(y))
  81714. #ifdef max
  81715. #undef max
  81716. #endif
  81717. #define max(x,y) ((x)>(y)?(x):(y))
  81718. #ifdef _MSC_VER
  81719. #define FLAC__U64L(x) x
  81720. #else
  81721. #define FLAC__U64L(x) x##LLU
  81722. #endif
  81723. #ifndef FLaC__INLINE
  81724. #define FLaC__INLINE
  81725. #endif
  81726. struct FLAC__BitReader {
  81727. brword *buffer;
  81728. unsigned capacity; /* in words */
  81729. unsigned words; /* # of completed words in buffer */
  81730. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81731. unsigned consumed_words; /* #words ... */
  81732. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81733. unsigned read_crc16; /* the running frame CRC */
  81734. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81735. FLAC__BitReaderReadCallback read_callback;
  81736. void *client_data;
  81737. FLAC__CPUInfo cpu_info;
  81738. };
  81739. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81740. {
  81741. register unsigned crc = br->read_crc16;
  81742. #if FLAC__BYTES_PER_WORD == 4
  81743. switch(br->crc16_align) {
  81744. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81745. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81746. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81747. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81748. }
  81749. #elif FLAC__BYTES_PER_WORD == 8
  81750. switch(br->crc16_align) {
  81751. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81752. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81753. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81754. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81755. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81756. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81757. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81758. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81759. }
  81760. #else
  81761. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81762. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81763. br->read_crc16 = crc;
  81764. #endif
  81765. br->crc16_align = 0;
  81766. }
  81767. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81768. {
  81769. unsigned start, end;
  81770. size_t bytes;
  81771. FLAC__byte *target;
  81772. if(br->consumed_words > 0) {
  81773. start = br->consumed_words;
  81774. end = br->words + (br->bytes? 1:0);
  81775. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81776. br->words -= start;
  81777. br->consumed_words = 0;
  81778. }
  81779. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81780. if(bytes == 0)
  81781. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81782. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81783. #if WORDS_BIGENDIAN
  81784. #else
  81785. if(br->bytes)
  81786. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81787. #endif
  81788. if(!br->read_callback(target, &bytes, br->client_data))
  81789. return false;
  81790. #if WORDS_BIGENDIAN
  81791. #else
  81792. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81793. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81794. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81795. start = br->words;
  81796. local_swap32_block_(br->buffer + start, end - start);
  81797. }
  81798. else
  81799. # endif
  81800. for(start = br->words; start < end; start++)
  81801. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81802. #endif
  81803. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81804. br->words = end / FLAC__BYTES_PER_WORD;
  81805. br->bytes = end % FLAC__BYTES_PER_WORD;
  81806. return true;
  81807. }
  81808. FLAC__BitReader *FLAC__bitreader_new(void)
  81809. {
  81810. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81811. return br;
  81812. }
  81813. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81814. {
  81815. FLAC__ASSERT(0 != br);
  81816. FLAC__bitreader_free(br);
  81817. free(br);
  81818. }
  81819. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81820. {
  81821. FLAC__ASSERT(0 != br);
  81822. br->words = br->bytes = 0;
  81823. br->consumed_words = br->consumed_bits = 0;
  81824. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81825. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81826. if(br->buffer == 0)
  81827. return false;
  81828. br->read_callback = rcb;
  81829. br->client_data = cd;
  81830. br->cpu_info = cpu;
  81831. return true;
  81832. }
  81833. void FLAC__bitreader_free(FLAC__BitReader *br)
  81834. {
  81835. FLAC__ASSERT(0 != br);
  81836. if(0 != br->buffer)
  81837. free(br->buffer);
  81838. br->buffer = 0;
  81839. br->capacity = 0;
  81840. br->words = br->bytes = 0;
  81841. br->consumed_words = br->consumed_bits = 0;
  81842. br->read_callback = 0;
  81843. br->client_data = 0;
  81844. }
  81845. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81846. {
  81847. br->words = br->bytes = 0;
  81848. br->consumed_words = br->consumed_bits = 0;
  81849. return true;
  81850. }
  81851. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81852. {
  81853. unsigned i, j;
  81854. if(br == 0) {
  81855. fprintf(out, "bitreader is NULL\n");
  81856. }
  81857. else {
  81858. 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);
  81859. for(i = 0; i < br->words; i++) {
  81860. fprintf(out, "%08X: ", i);
  81861. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81862. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81863. fprintf(out, ".");
  81864. else
  81865. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81866. fprintf(out, "\n");
  81867. }
  81868. if(br->bytes > 0) {
  81869. fprintf(out, "%08X: ", i);
  81870. for(j = 0; j < br->bytes*8; j++)
  81871. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81872. fprintf(out, ".");
  81873. else
  81874. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81875. fprintf(out, "\n");
  81876. }
  81877. }
  81878. }
  81879. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81880. {
  81881. FLAC__ASSERT(0 != br);
  81882. FLAC__ASSERT(0 != br->buffer);
  81883. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81884. br->read_crc16 = (unsigned)seed;
  81885. br->crc16_align = br->consumed_bits;
  81886. }
  81887. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81888. {
  81889. FLAC__ASSERT(0 != br);
  81890. FLAC__ASSERT(0 != br->buffer);
  81891. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81892. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81893. if(br->consumed_bits) {
  81894. const brword tail = br->buffer[br->consumed_words];
  81895. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81896. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81897. }
  81898. return br->read_crc16;
  81899. }
  81900. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81901. {
  81902. return ((br->consumed_bits & 7) == 0);
  81903. }
  81904. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81905. {
  81906. return 8 - (br->consumed_bits & 7);
  81907. }
  81908. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81909. {
  81910. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81911. }
  81912. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81913. {
  81914. FLAC__ASSERT(0 != br);
  81915. FLAC__ASSERT(0 != br->buffer);
  81916. FLAC__ASSERT(bits <= 32);
  81917. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81918. FLAC__ASSERT(br->consumed_words <= br->words);
  81919. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81920. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81921. *val = 0;
  81922. return true;
  81923. }
  81924. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  81925. if(!bitreader_read_from_client_(br))
  81926. return false;
  81927. }
  81928. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81929. if(br->consumed_bits) {
  81930. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  81931. const brword word = br->buffer[br->consumed_words];
  81932. if(bits < n) {
  81933. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  81934. br->consumed_bits += bits;
  81935. return true;
  81936. }
  81937. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  81938. bits -= n;
  81939. crc16_update_word_(br, word);
  81940. br->consumed_words++;
  81941. br->consumed_bits = 0;
  81942. 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 */
  81943. *val <<= bits;
  81944. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  81945. br->consumed_bits = bits;
  81946. }
  81947. return true;
  81948. }
  81949. else {
  81950. const brword word = br->buffer[br->consumed_words];
  81951. if(bits < FLAC__BITS_PER_WORD) {
  81952. *val = word >> (FLAC__BITS_PER_WORD-bits);
  81953. br->consumed_bits = bits;
  81954. return true;
  81955. }
  81956. *val = word;
  81957. crc16_update_word_(br, word);
  81958. br->consumed_words++;
  81959. return true;
  81960. }
  81961. }
  81962. else {
  81963. if(br->consumed_bits) {
  81964. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  81965. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  81966. br->consumed_bits += bits;
  81967. return true;
  81968. }
  81969. else {
  81970. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  81971. br->consumed_bits += bits;
  81972. return true;
  81973. }
  81974. }
  81975. }
  81976. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  81977. {
  81978. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  81979. return false;
  81980. *val <<= (32-bits);
  81981. *val >>= (32-bits);
  81982. return true;
  81983. }
  81984. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  81985. {
  81986. FLAC__uint32 hi, lo;
  81987. if(bits > 32) {
  81988. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  81989. return false;
  81990. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  81991. return false;
  81992. *val = hi;
  81993. *val <<= 32;
  81994. *val |= lo;
  81995. }
  81996. else {
  81997. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  81998. return false;
  81999. *val = lo;
  82000. }
  82001. return true;
  82002. }
  82003. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  82004. {
  82005. FLAC__uint32 x8, x32 = 0;
  82006. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  82007. return false;
  82008. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82009. return false;
  82010. x32 |= (x8 << 8);
  82011. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82012. return false;
  82013. x32 |= (x8 << 16);
  82014. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82015. return false;
  82016. x32 |= (x8 << 24);
  82017. *val = x32;
  82018. return true;
  82019. }
  82020. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82021. {
  82022. FLAC__ASSERT(0 != br);
  82023. FLAC__ASSERT(0 != br->buffer);
  82024. if(bits > 0) {
  82025. const unsigned n = br->consumed_bits & 7;
  82026. unsigned m;
  82027. FLAC__uint32 x;
  82028. if(n != 0) {
  82029. m = min(8-n, bits);
  82030. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82031. return false;
  82032. bits -= m;
  82033. }
  82034. m = bits / 8;
  82035. if(m > 0) {
  82036. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82037. return false;
  82038. bits %= 8;
  82039. }
  82040. if(bits > 0) {
  82041. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82042. return false;
  82043. }
  82044. }
  82045. return true;
  82046. }
  82047. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82048. {
  82049. FLAC__uint32 x;
  82050. FLAC__ASSERT(0 != br);
  82051. FLAC__ASSERT(0 != br->buffer);
  82052. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82053. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82054. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82055. return false;
  82056. nvals--;
  82057. }
  82058. if(0 == nvals)
  82059. return true;
  82060. while(nvals >= FLAC__BYTES_PER_WORD) {
  82061. if(br->consumed_words < br->words) {
  82062. br->consumed_words++;
  82063. nvals -= FLAC__BYTES_PER_WORD;
  82064. }
  82065. else if(!bitreader_read_from_client_(br))
  82066. return false;
  82067. }
  82068. while(nvals) {
  82069. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82070. return false;
  82071. nvals--;
  82072. }
  82073. return true;
  82074. }
  82075. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82076. {
  82077. FLAC__uint32 x;
  82078. FLAC__ASSERT(0 != br);
  82079. FLAC__ASSERT(0 != br->buffer);
  82080. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82081. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82082. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82083. return false;
  82084. *val++ = (FLAC__byte)x;
  82085. nvals--;
  82086. }
  82087. if(0 == nvals)
  82088. return true;
  82089. while(nvals >= FLAC__BYTES_PER_WORD) {
  82090. if(br->consumed_words < br->words) {
  82091. const brword word = br->buffer[br->consumed_words++];
  82092. #if FLAC__BYTES_PER_WORD == 4
  82093. val[0] = (FLAC__byte)(word >> 24);
  82094. val[1] = (FLAC__byte)(word >> 16);
  82095. val[2] = (FLAC__byte)(word >> 8);
  82096. val[3] = (FLAC__byte)word;
  82097. #elif FLAC__BYTES_PER_WORD == 8
  82098. val[0] = (FLAC__byte)(word >> 56);
  82099. val[1] = (FLAC__byte)(word >> 48);
  82100. val[2] = (FLAC__byte)(word >> 40);
  82101. val[3] = (FLAC__byte)(word >> 32);
  82102. val[4] = (FLAC__byte)(word >> 24);
  82103. val[5] = (FLAC__byte)(word >> 16);
  82104. val[6] = (FLAC__byte)(word >> 8);
  82105. val[7] = (FLAC__byte)word;
  82106. #else
  82107. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82108. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82109. #endif
  82110. val += FLAC__BYTES_PER_WORD;
  82111. nvals -= FLAC__BYTES_PER_WORD;
  82112. }
  82113. else if(!bitreader_read_from_client_(br))
  82114. return false;
  82115. }
  82116. while(nvals) {
  82117. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82118. return false;
  82119. *val++ = (FLAC__byte)x;
  82120. nvals--;
  82121. }
  82122. return true;
  82123. }
  82124. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82125. #if 0 /* slow but readable version */
  82126. {
  82127. unsigned bit;
  82128. FLAC__ASSERT(0 != br);
  82129. FLAC__ASSERT(0 != br->buffer);
  82130. *val = 0;
  82131. while(1) {
  82132. if(!FLAC__bitreader_read_bit(br, &bit))
  82133. return false;
  82134. if(bit)
  82135. break;
  82136. else
  82137. *val++;
  82138. }
  82139. return true;
  82140. }
  82141. #else
  82142. {
  82143. unsigned i;
  82144. FLAC__ASSERT(0 != br);
  82145. FLAC__ASSERT(0 != br->buffer);
  82146. *val = 0;
  82147. while(1) {
  82148. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82149. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82150. if(b) {
  82151. i = COUNT_ZERO_MSBS(b);
  82152. *val += i;
  82153. i++;
  82154. br->consumed_bits += i;
  82155. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82156. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82157. br->consumed_words++;
  82158. br->consumed_bits = 0;
  82159. }
  82160. return true;
  82161. }
  82162. else {
  82163. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82164. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82165. br->consumed_words++;
  82166. br->consumed_bits = 0;
  82167. }
  82168. }
  82169. if(br->bytes) {
  82170. const unsigned end = br->bytes * 8;
  82171. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82172. if(b) {
  82173. i = COUNT_ZERO_MSBS(b);
  82174. *val += i;
  82175. i++;
  82176. br->consumed_bits += i;
  82177. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82178. return true;
  82179. }
  82180. else {
  82181. *val += end - br->consumed_bits;
  82182. br->consumed_bits += end;
  82183. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82184. }
  82185. }
  82186. if(!bitreader_read_from_client_(br))
  82187. return false;
  82188. }
  82189. }
  82190. #endif
  82191. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82192. {
  82193. FLAC__uint32 lsbs = 0, msbs = 0;
  82194. unsigned uval;
  82195. FLAC__ASSERT(0 != br);
  82196. FLAC__ASSERT(0 != br->buffer);
  82197. FLAC__ASSERT(parameter <= 31);
  82198. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82199. return false;
  82200. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82201. return false;
  82202. uval = (msbs << parameter) | lsbs;
  82203. if(uval & 1)
  82204. *val = -((int)(uval >> 1)) - 1;
  82205. else
  82206. *val = (int)(uval >> 1);
  82207. return true;
  82208. }
  82209. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82210. #ifdef _MSC_VER
  82211. {
  82212. unsigned i;
  82213. unsigned uval = 0;
  82214. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82215. register unsigned cwords;
  82216. register unsigned cbits;
  82217. FLAC__ASSERT(0 != br);
  82218. FLAC__ASSERT(0 != br->buffer);
  82219. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82220. FLAC__ASSERT(parameter < 32);
  82221. if(nvals == 0)
  82222. return true;
  82223. cbits = br->consumed_bits;
  82224. cwords = br->consumed_words;
  82225. while(1) {
  82226. while(1) {
  82227. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82228. brword b = br->buffer[cwords] << cbits;
  82229. if(b) {
  82230. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82231. __asm {
  82232. bsr eax, b
  82233. not eax
  82234. and eax, 31
  82235. mov i, eax
  82236. }
  82237. #else
  82238. i = COUNT_ZERO_MSBS(b);
  82239. #endif
  82240. uval += i;
  82241. bits = parameter;
  82242. i++;
  82243. cbits += i;
  82244. if(cbits == FLAC__BITS_PER_WORD) {
  82245. crc16_update_word_(br, br->buffer[cwords]);
  82246. cwords++;
  82247. cbits = 0;
  82248. }
  82249. goto break1;
  82250. }
  82251. else {
  82252. uval += FLAC__BITS_PER_WORD - cbits;
  82253. crc16_update_word_(br, br->buffer[cwords]);
  82254. cwords++;
  82255. cbits = 0;
  82256. }
  82257. }
  82258. if(br->bytes) {
  82259. const unsigned end = br->bytes * 8;
  82260. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82261. if(b) {
  82262. i = COUNT_ZERO_MSBS(b);
  82263. uval += i;
  82264. bits = parameter;
  82265. i++;
  82266. cbits += i;
  82267. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82268. goto break1;
  82269. }
  82270. else {
  82271. uval += end - cbits;
  82272. cbits += end;
  82273. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82274. }
  82275. }
  82276. br->consumed_bits = cbits;
  82277. br->consumed_words = cwords;
  82278. if(!bitreader_read_from_client_(br))
  82279. return false;
  82280. cwords = br->consumed_words;
  82281. }
  82282. break1:
  82283. FLAC__ASSERT(cwords <= br->words);
  82284. if(bits) {
  82285. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82286. br->consumed_bits = cbits;
  82287. br->consumed_words = cwords;
  82288. if(!bitreader_read_from_client_(br))
  82289. return false;
  82290. cwords = br->consumed_words;
  82291. }
  82292. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82293. if(cbits) {
  82294. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82295. const brword word = br->buffer[cwords];
  82296. if(bits < n) {
  82297. uval <<= bits;
  82298. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82299. cbits += bits;
  82300. goto break2;
  82301. }
  82302. uval <<= n;
  82303. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82304. bits -= n;
  82305. crc16_update_word_(br, word);
  82306. cwords++;
  82307. cbits = 0;
  82308. 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 */
  82309. uval <<= bits;
  82310. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82311. cbits = bits;
  82312. }
  82313. goto break2;
  82314. }
  82315. else {
  82316. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82317. uval <<= bits;
  82318. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82319. cbits = bits;
  82320. goto break2;
  82321. }
  82322. }
  82323. else {
  82324. uval <<= bits;
  82325. if(cbits) {
  82326. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82327. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82328. cbits += bits;
  82329. goto break2;
  82330. }
  82331. else {
  82332. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82333. cbits += bits;
  82334. goto break2;
  82335. }
  82336. }
  82337. }
  82338. break2:
  82339. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82340. --nvals;
  82341. if(nvals == 0) {
  82342. br->consumed_bits = cbits;
  82343. br->consumed_words = cwords;
  82344. return true;
  82345. }
  82346. uval = 0;
  82347. ++vals;
  82348. }
  82349. }
  82350. #else
  82351. {
  82352. unsigned i;
  82353. unsigned uval = 0;
  82354. register unsigned cwords;
  82355. register unsigned cbits;
  82356. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82357. FLAC__ASSERT(0 != br);
  82358. FLAC__ASSERT(0 != br->buffer);
  82359. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82360. FLAC__ASSERT(parameter < 32);
  82361. if(nvals == 0)
  82362. return true;
  82363. cbits = br->consumed_bits;
  82364. cwords = br->consumed_words;
  82365. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82366. while(1) {
  82367. while(1) {
  82368. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82369. brword b = br->buffer[cwords] << cbits;
  82370. if(b) {
  82371. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82372. asm volatile (
  82373. "bsrl %1, %0;"
  82374. "notl %0;"
  82375. "andl $31, %0;"
  82376. : "=r"(i)
  82377. : "r"(b)
  82378. );
  82379. #else
  82380. i = COUNT_ZERO_MSBS(b);
  82381. #endif
  82382. uval += i;
  82383. cbits += i;
  82384. cbits++; /* skip over stop bit */
  82385. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82386. crc16_update_word_(br, br->buffer[cwords]);
  82387. cwords++;
  82388. cbits = 0;
  82389. }
  82390. goto break1;
  82391. }
  82392. else {
  82393. uval += FLAC__BITS_PER_WORD - cbits;
  82394. crc16_update_word_(br, br->buffer[cwords]);
  82395. cwords++;
  82396. cbits = 0;
  82397. }
  82398. }
  82399. if(br->bytes) {
  82400. const unsigned end = br->bytes * 8;
  82401. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82402. if(b) {
  82403. i = COUNT_ZERO_MSBS(b);
  82404. uval += i;
  82405. cbits += i;
  82406. cbits++; /* skip over stop bit */
  82407. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82408. goto break1;
  82409. }
  82410. else {
  82411. uval += end - cbits;
  82412. cbits += end;
  82413. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82414. }
  82415. }
  82416. br->consumed_bits = cbits;
  82417. br->consumed_words = cwords;
  82418. if(!bitreader_read_from_client_(br))
  82419. return false;
  82420. cwords = br->consumed_words;
  82421. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82422. }
  82423. break1:
  82424. ucbits -= uval;
  82425. ucbits--; /* account for stop bit */
  82426. FLAC__ASSERT(cwords <= br->words);
  82427. if(parameter) {
  82428. while(ucbits < parameter) {
  82429. br->consumed_bits = cbits;
  82430. br->consumed_words = cwords;
  82431. if(!bitreader_read_from_client_(br))
  82432. return false;
  82433. cwords = br->consumed_words;
  82434. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82435. }
  82436. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82437. if(cbits) {
  82438. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82439. const brword word = br->buffer[cwords];
  82440. if(parameter < n) {
  82441. uval <<= parameter;
  82442. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82443. cbits += parameter;
  82444. }
  82445. else {
  82446. uval <<= n;
  82447. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82448. crc16_update_word_(br, word);
  82449. cwords++;
  82450. cbits = parameter - n;
  82451. 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 */
  82452. uval <<= cbits;
  82453. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82454. }
  82455. }
  82456. }
  82457. else {
  82458. cbits = parameter;
  82459. uval <<= parameter;
  82460. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82461. }
  82462. }
  82463. else {
  82464. uval <<= parameter;
  82465. if(cbits) {
  82466. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82467. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82468. cbits += parameter;
  82469. }
  82470. else {
  82471. cbits = parameter;
  82472. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82473. }
  82474. }
  82475. }
  82476. ucbits -= parameter;
  82477. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82478. --nvals;
  82479. if(nvals == 0) {
  82480. br->consumed_bits = cbits;
  82481. br->consumed_words = cwords;
  82482. return true;
  82483. }
  82484. uval = 0;
  82485. ++vals;
  82486. }
  82487. }
  82488. #endif
  82489. #if 0 /* UNUSED */
  82490. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82491. {
  82492. FLAC__uint32 lsbs = 0, msbs = 0;
  82493. unsigned bit, uval, k;
  82494. FLAC__ASSERT(0 != br);
  82495. FLAC__ASSERT(0 != br->buffer);
  82496. k = FLAC__bitmath_ilog2(parameter);
  82497. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82498. return false;
  82499. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82500. return false;
  82501. if(parameter == 1u<<k) {
  82502. uval = (msbs << k) | lsbs;
  82503. }
  82504. else {
  82505. unsigned d = (1 << (k+1)) - parameter;
  82506. if(lsbs >= d) {
  82507. if(!FLAC__bitreader_read_bit(br, &bit))
  82508. return false;
  82509. lsbs <<= 1;
  82510. lsbs |= bit;
  82511. lsbs -= d;
  82512. }
  82513. uval = msbs * parameter + lsbs;
  82514. }
  82515. if(uval & 1)
  82516. *val = -((int)(uval >> 1)) - 1;
  82517. else
  82518. *val = (int)(uval >> 1);
  82519. return true;
  82520. }
  82521. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82522. {
  82523. FLAC__uint32 lsbs, msbs = 0;
  82524. unsigned bit, k;
  82525. FLAC__ASSERT(0 != br);
  82526. FLAC__ASSERT(0 != br->buffer);
  82527. k = FLAC__bitmath_ilog2(parameter);
  82528. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82529. return false;
  82530. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82531. return false;
  82532. if(parameter == 1u<<k) {
  82533. *val = (msbs << k) | lsbs;
  82534. }
  82535. else {
  82536. unsigned d = (1 << (k+1)) - parameter;
  82537. if(lsbs >= d) {
  82538. if(!FLAC__bitreader_read_bit(br, &bit))
  82539. return false;
  82540. lsbs <<= 1;
  82541. lsbs |= bit;
  82542. lsbs -= d;
  82543. }
  82544. *val = msbs * parameter + lsbs;
  82545. }
  82546. return true;
  82547. }
  82548. #endif /* UNUSED */
  82549. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82550. {
  82551. FLAC__uint32 v = 0;
  82552. FLAC__uint32 x;
  82553. unsigned i;
  82554. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82555. return false;
  82556. if(raw)
  82557. raw[(*rawlen)++] = (FLAC__byte)x;
  82558. if(!(x & 0x80)) { /* 0xxxxxxx */
  82559. v = x;
  82560. i = 0;
  82561. }
  82562. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82563. v = x & 0x1F;
  82564. i = 1;
  82565. }
  82566. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82567. v = x & 0x0F;
  82568. i = 2;
  82569. }
  82570. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82571. v = x & 0x07;
  82572. i = 3;
  82573. }
  82574. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82575. v = x & 0x03;
  82576. i = 4;
  82577. }
  82578. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82579. v = x & 0x01;
  82580. i = 5;
  82581. }
  82582. else {
  82583. *val = 0xffffffff;
  82584. return true;
  82585. }
  82586. for( ; i; i--) {
  82587. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82588. return false;
  82589. if(raw)
  82590. raw[(*rawlen)++] = (FLAC__byte)x;
  82591. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82592. *val = 0xffffffff;
  82593. return true;
  82594. }
  82595. v <<= 6;
  82596. v |= (x & 0x3F);
  82597. }
  82598. *val = v;
  82599. return true;
  82600. }
  82601. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82602. {
  82603. FLAC__uint64 v = 0;
  82604. FLAC__uint32 x;
  82605. unsigned i;
  82606. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82607. return false;
  82608. if(raw)
  82609. raw[(*rawlen)++] = (FLAC__byte)x;
  82610. if(!(x & 0x80)) { /* 0xxxxxxx */
  82611. v = x;
  82612. i = 0;
  82613. }
  82614. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82615. v = x & 0x1F;
  82616. i = 1;
  82617. }
  82618. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82619. v = x & 0x0F;
  82620. i = 2;
  82621. }
  82622. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82623. v = x & 0x07;
  82624. i = 3;
  82625. }
  82626. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82627. v = x & 0x03;
  82628. i = 4;
  82629. }
  82630. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82631. v = x & 0x01;
  82632. i = 5;
  82633. }
  82634. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82635. v = 0;
  82636. i = 6;
  82637. }
  82638. else {
  82639. *val = FLAC__U64L(0xffffffffffffffff);
  82640. return true;
  82641. }
  82642. for( ; i; i--) {
  82643. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82644. return false;
  82645. if(raw)
  82646. raw[(*rawlen)++] = (FLAC__byte)x;
  82647. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82648. *val = FLAC__U64L(0xffffffffffffffff);
  82649. return true;
  82650. }
  82651. v <<= 6;
  82652. v |= (x & 0x3F);
  82653. }
  82654. *val = v;
  82655. return true;
  82656. }
  82657. #endif
  82658. /*** End of inlined file: bitreader.c ***/
  82659. /*** Start of inlined file: bitwriter.c ***/
  82660. /*** Start of inlined file: juce_FlacHeader.h ***/
  82661. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82662. // tasks..
  82663. #define VERSION "1.2.1"
  82664. #define FLAC__NO_DLL 1
  82665. #if JUCE_MSVC
  82666. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82667. #endif
  82668. #if JUCE_MAC
  82669. #define FLAC__SYS_DARWIN 1
  82670. #endif
  82671. /*** End of inlined file: juce_FlacHeader.h ***/
  82672. #if JUCE_USE_FLAC
  82673. #if HAVE_CONFIG_H
  82674. # include <config.h>
  82675. #endif
  82676. #include <stdlib.h> /* for malloc() */
  82677. #include <string.h> /* for memcpy(), memset() */
  82678. #ifdef _MSC_VER
  82679. #include <winsock.h> /* for ntohl() */
  82680. #elif defined FLAC__SYS_DARWIN
  82681. #include <machine/endian.h> /* for ntohl() */
  82682. #elif defined __MINGW32__
  82683. #include <winsock.h> /* for ntohl() */
  82684. #else
  82685. #include <netinet/in.h> /* for ntohl() */
  82686. #endif
  82687. #if 0 /* UNUSED */
  82688. #endif
  82689. /*** Start of inlined file: bitwriter.h ***/
  82690. #ifndef FLAC__PRIVATE__BITWRITER_H
  82691. #define FLAC__PRIVATE__BITWRITER_H
  82692. #include <stdio.h> /* for FILE */
  82693. struct FLAC__BitWriter;
  82694. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82695. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82696. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82697. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82698. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82699. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82700. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82701. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82702. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82703. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82704. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82705. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82706. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82707. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82708. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82709. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82710. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82711. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82712. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82713. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82714. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82715. #if 0 /* UNUSED */
  82716. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82717. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82718. #endif
  82719. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82720. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82721. #if 0 /* UNUSED */
  82722. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82723. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82724. #endif
  82725. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82726. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82727. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82728. #endif
  82729. /*** End of inlined file: bitwriter.h ***/
  82730. /*** Start of inlined file: alloc.h ***/
  82731. #ifndef FLAC__SHARE__ALLOC_H
  82732. #define FLAC__SHARE__ALLOC_H
  82733. #if HAVE_CONFIG_H
  82734. # include <config.h>
  82735. #endif
  82736. #include <limits.h> /* for SIZE_MAX */
  82737. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82738. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82739. #endif
  82740. #include <stdlib.h> /* for size_t, malloc(), etc */
  82741. #ifndef SIZE_MAX
  82742. # ifndef SIZE_T_MAX
  82743. # ifdef _MSC_VER
  82744. # define SIZE_T_MAX UINT_MAX
  82745. # else
  82746. # error
  82747. # endif
  82748. # endif
  82749. # define SIZE_MAX SIZE_T_MAX
  82750. #endif
  82751. #ifndef FLaC__INLINE
  82752. #define FLaC__INLINE
  82753. #endif
  82754. static FLaC__INLINE void *safe_malloc_(size_t size)
  82755. {
  82756. if(!size)
  82757. size++;
  82758. return malloc(size);
  82759. }
  82760. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82761. {
  82762. if(!nmemb || !size)
  82763. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82764. return calloc(nmemb, size);
  82765. }
  82766. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82767. {
  82768. size2 += size1;
  82769. if(size2 < size1)
  82770. return 0;
  82771. return safe_malloc_(size2);
  82772. }
  82773. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82774. {
  82775. size2 += size1;
  82776. if(size2 < size1)
  82777. return 0;
  82778. size3 += size2;
  82779. if(size3 < size2)
  82780. return 0;
  82781. return safe_malloc_(size3);
  82782. }
  82783. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82784. {
  82785. size2 += size1;
  82786. if(size2 < size1)
  82787. return 0;
  82788. size3 += size2;
  82789. if(size3 < size2)
  82790. return 0;
  82791. size4 += size3;
  82792. if(size4 < size3)
  82793. return 0;
  82794. return safe_malloc_(size4);
  82795. }
  82796. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82797. #if 0
  82798. needs support for cases where sizeof(size_t) != 4
  82799. {
  82800. if(sizeof(size_t) == 4) {
  82801. if ((double)size1 * (double)size2 < 4294967296.0)
  82802. return malloc(size1*size2);
  82803. }
  82804. return 0;
  82805. }
  82806. #else
  82807. {
  82808. if(!size1 || !size2)
  82809. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82810. if(size1 > SIZE_MAX / size2)
  82811. return 0;
  82812. return malloc(size1*size2);
  82813. }
  82814. #endif
  82815. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82816. {
  82817. if(!size1 || !size2 || !size3)
  82818. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82819. if(size1 > SIZE_MAX / size2)
  82820. return 0;
  82821. size1 *= size2;
  82822. if(size1 > SIZE_MAX / size3)
  82823. return 0;
  82824. return malloc(size1*size3);
  82825. }
  82826. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82827. {
  82828. if(!size1 || !size2)
  82829. return safe_malloc_(size3);
  82830. if(size1 > SIZE_MAX / size2)
  82831. return 0;
  82832. return safe_malloc_add_2op_(size1*size2, size3);
  82833. }
  82834. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82835. {
  82836. if(!size1 || (!size2 && !size3))
  82837. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82838. size2 += size3;
  82839. if(size2 < size3)
  82840. return 0;
  82841. return safe_malloc_mul_2op_(size1, size2);
  82842. }
  82843. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82844. {
  82845. size2 += size1;
  82846. if(size2 < size1)
  82847. return 0;
  82848. return realloc(ptr, size2);
  82849. }
  82850. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, 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 realloc(ptr, size3);
  82859. }
  82860. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, 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 realloc(ptr, size4);
  82872. }
  82873. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82874. {
  82875. if(!size1 || !size2)
  82876. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82877. if(size1 > SIZE_MAX / size2)
  82878. return 0;
  82879. return realloc(ptr, size1*size2);
  82880. }
  82881. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82882. {
  82883. if(!size1 || (!size2 && !size3))
  82884. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82885. size2 += size3;
  82886. if(size2 < size3)
  82887. return 0;
  82888. return safe_realloc_mul_2op_(ptr, size1, size2);
  82889. }
  82890. #endif
  82891. /*** End of inlined file: alloc.h ***/
  82892. typedef FLAC__uint32 bwword;
  82893. #define FLAC__BYTES_PER_WORD 4
  82894. #define FLAC__BITS_PER_WORD 32
  82895. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82896. #if WORDS_BIGENDIAN
  82897. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82898. #else
  82899. #ifdef _MSC_VER
  82900. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82901. #else
  82902. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82903. #endif
  82904. #endif
  82905. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82906. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82907. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82908. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82909. #ifdef min
  82910. #undef min
  82911. #endif
  82912. #define min(x,y) ((x)<(y)?(x):(y))
  82913. #ifdef _MSC_VER
  82914. #define FLAC__U64L(x) x
  82915. #else
  82916. #define FLAC__U64L(x) x##LLU
  82917. #endif
  82918. #ifndef FLaC__INLINE
  82919. #define FLaC__INLINE
  82920. #endif
  82921. struct FLAC__BitWriter {
  82922. bwword *buffer;
  82923. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  82924. unsigned capacity; /* capacity of buffer in words */
  82925. unsigned words; /* # of complete words in buffer */
  82926. unsigned bits; /* # of used bits in accum */
  82927. };
  82928. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  82929. {
  82930. unsigned new_capacity;
  82931. bwword *new_buffer;
  82932. FLAC__ASSERT(0 != bw);
  82933. FLAC__ASSERT(0 != bw->buffer);
  82934. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  82935. if(bw->capacity >= new_capacity)
  82936. return true;
  82937. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  82938. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82939. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82940. FLAC__ASSERT(new_capacity > bw->capacity);
  82941. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  82942. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  82943. if(new_buffer == 0)
  82944. return false;
  82945. bw->buffer = new_buffer;
  82946. bw->capacity = new_capacity;
  82947. return true;
  82948. }
  82949. FLAC__BitWriter *FLAC__bitwriter_new(void)
  82950. {
  82951. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  82952. return bw;
  82953. }
  82954. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  82955. {
  82956. FLAC__ASSERT(0 != bw);
  82957. FLAC__bitwriter_free(bw);
  82958. free(bw);
  82959. }
  82960. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  82961. {
  82962. FLAC__ASSERT(0 != bw);
  82963. bw->words = bw->bits = 0;
  82964. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  82965. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  82966. if(bw->buffer == 0)
  82967. return false;
  82968. return true;
  82969. }
  82970. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  82971. {
  82972. FLAC__ASSERT(0 != bw);
  82973. if(0 != bw->buffer)
  82974. free(bw->buffer);
  82975. bw->buffer = 0;
  82976. bw->capacity = 0;
  82977. bw->words = bw->bits = 0;
  82978. }
  82979. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  82980. {
  82981. bw->words = bw->bits = 0;
  82982. }
  82983. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  82984. {
  82985. unsigned i, j;
  82986. if(bw == 0) {
  82987. fprintf(out, "bitwriter is NULL\n");
  82988. }
  82989. else {
  82990. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  82991. for(i = 0; i < bw->words; i++) {
  82992. fprintf(out, "%08X: ", i);
  82993. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82994. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82995. fprintf(out, "\n");
  82996. }
  82997. if(bw->bits > 0) {
  82998. fprintf(out, "%08X: ", i);
  82999. for(j = 0; j < bw->bits; j++)
  83000. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  83001. fprintf(out, "\n");
  83002. }
  83003. }
  83004. }
  83005. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  83006. {
  83007. const FLAC__byte *buffer;
  83008. size_t bytes;
  83009. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83010. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83011. return false;
  83012. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83013. FLAC__bitwriter_release_buffer(bw);
  83014. return true;
  83015. }
  83016. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  83017. {
  83018. const FLAC__byte *buffer;
  83019. size_t bytes;
  83020. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83021. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83022. return false;
  83023. *crc = FLAC__crc8(buffer, bytes);
  83024. FLAC__bitwriter_release_buffer(bw);
  83025. return true;
  83026. }
  83027. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83028. {
  83029. return ((bw->bits & 7) == 0);
  83030. }
  83031. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83032. {
  83033. return FLAC__TOTAL_BITS(bw);
  83034. }
  83035. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83036. {
  83037. FLAC__ASSERT((bw->bits & 7) == 0);
  83038. if(bw->bits & 7)
  83039. return false;
  83040. if(bw->bits) {
  83041. FLAC__ASSERT(bw->words <= bw->capacity);
  83042. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83043. return false;
  83044. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83045. }
  83046. *buffer = (FLAC__byte*)bw->buffer;
  83047. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83048. return true;
  83049. }
  83050. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83051. {
  83052. (void)bw;
  83053. }
  83054. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83055. {
  83056. unsigned n;
  83057. FLAC__ASSERT(0 != bw);
  83058. FLAC__ASSERT(0 != bw->buffer);
  83059. if(bits == 0)
  83060. return true;
  83061. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83062. return false;
  83063. if(bw->bits) {
  83064. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83065. bw->accum <<= n;
  83066. bits -= n;
  83067. bw->bits += n;
  83068. if(bw->bits == FLAC__BITS_PER_WORD) {
  83069. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83070. bw->bits = 0;
  83071. }
  83072. else
  83073. return true;
  83074. }
  83075. while(bits >= FLAC__BITS_PER_WORD) {
  83076. bw->buffer[bw->words++] = 0;
  83077. bits -= FLAC__BITS_PER_WORD;
  83078. }
  83079. if(bits > 0) {
  83080. bw->accum = 0;
  83081. bw->bits = bits;
  83082. }
  83083. return true;
  83084. }
  83085. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83086. {
  83087. register unsigned left;
  83088. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83089. FLAC__ASSERT(0 != bw);
  83090. FLAC__ASSERT(0 != bw->buffer);
  83091. FLAC__ASSERT(bits <= 32);
  83092. if(bits == 0)
  83093. return true;
  83094. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83095. return false;
  83096. left = FLAC__BITS_PER_WORD - bw->bits;
  83097. if(bits < left) {
  83098. bw->accum <<= bits;
  83099. bw->accum |= val;
  83100. bw->bits += bits;
  83101. }
  83102. 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 */
  83103. bw->accum <<= left;
  83104. bw->accum |= val >> (bw->bits = bits - left);
  83105. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83106. bw->accum = val;
  83107. }
  83108. else {
  83109. bw->accum = val;
  83110. bw->bits = 0;
  83111. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83112. }
  83113. return true;
  83114. }
  83115. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83116. {
  83117. if(bits < 32)
  83118. val &= (~(0xffffffff << bits));
  83119. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83120. }
  83121. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83122. {
  83123. if(bits > 32) {
  83124. return
  83125. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83126. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83127. }
  83128. else
  83129. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83130. }
  83131. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83132. {
  83133. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83134. return false;
  83135. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83136. return false;
  83137. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83138. return false;
  83139. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83140. return false;
  83141. return true;
  83142. }
  83143. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83144. {
  83145. unsigned i;
  83146. for(i = 0; i < nvals; i++) {
  83147. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83148. return false;
  83149. }
  83150. return true;
  83151. }
  83152. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83153. {
  83154. if(val < 32)
  83155. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83156. else
  83157. return
  83158. FLAC__bitwriter_write_zeroes(bw, val) &&
  83159. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83160. }
  83161. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83162. {
  83163. FLAC__uint32 uval;
  83164. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83165. uval = (val<<1) ^ (val>>31);
  83166. return 1 + parameter + (uval >> parameter);
  83167. }
  83168. #if 0 /* UNUSED */
  83169. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83170. {
  83171. unsigned bits, msbs, uval;
  83172. unsigned k;
  83173. FLAC__ASSERT(parameter > 0);
  83174. if(val < 0)
  83175. uval = (unsigned)(((-(++val)) << 1) + 1);
  83176. else
  83177. uval = (unsigned)(val << 1);
  83178. k = FLAC__bitmath_ilog2(parameter);
  83179. if(parameter == 1u<<k) {
  83180. FLAC__ASSERT(k <= 30);
  83181. msbs = uval >> k;
  83182. bits = 1 + k + msbs;
  83183. }
  83184. else {
  83185. unsigned q, r, d;
  83186. d = (1 << (k+1)) - parameter;
  83187. q = uval / parameter;
  83188. r = uval - (q * parameter);
  83189. bits = 1 + q + k;
  83190. if(r >= d)
  83191. bits++;
  83192. }
  83193. return bits;
  83194. }
  83195. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83196. {
  83197. unsigned bits, msbs;
  83198. unsigned k;
  83199. FLAC__ASSERT(parameter > 0);
  83200. k = FLAC__bitmath_ilog2(parameter);
  83201. if(parameter == 1u<<k) {
  83202. FLAC__ASSERT(k <= 30);
  83203. msbs = uval >> k;
  83204. bits = 1 + k + msbs;
  83205. }
  83206. else {
  83207. unsigned q, r, d;
  83208. d = (1 << (k+1)) - parameter;
  83209. q = uval / parameter;
  83210. r = uval - (q * parameter);
  83211. bits = 1 + q + k;
  83212. if(r >= d)
  83213. bits++;
  83214. }
  83215. return bits;
  83216. }
  83217. #endif /* UNUSED */
  83218. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83219. {
  83220. unsigned total_bits, interesting_bits, msbs;
  83221. FLAC__uint32 uval, pattern;
  83222. FLAC__ASSERT(0 != bw);
  83223. FLAC__ASSERT(0 != bw->buffer);
  83224. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83225. uval = (val<<1) ^ (val>>31);
  83226. msbs = uval >> parameter;
  83227. interesting_bits = 1 + parameter;
  83228. total_bits = interesting_bits + msbs;
  83229. pattern = 1 << parameter; /* the unary end bit */
  83230. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83231. if(total_bits <= 32)
  83232. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83233. else
  83234. return
  83235. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83236. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83237. }
  83238. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83239. {
  83240. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83241. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83242. FLAC__uint32 uval;
  83243. unsigned left;
  83244. const unsigned lsbits = 1 + parameter;
  83245. unsigned msbits;
  83246. FLAC__ASSERT(0 != bw);
  83247. FLAC__ASSERT(0 != bw->buffer);
  83248. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83249. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83250. while(nvals) {
  83251. uval = (*vals<<1) ^ (*vals>>31);
  83252. msbits = uval >> parameter;
  83253. #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) */
  83254. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83255. bw->bits = bw->bits + msbits + lsbits;
  83256. uval |= mask1; /* set stop bit */
  83257. uval &= mask2; /* mask off unused top bits */
  83258. bw->accum <<= msbits;
  83259. bw->accum <<= lsbits;
  83260. bw->accum |= uval;
  83261. if(bw->bits == FLAC__BITS_PER_WORD) {
  83262. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83263. bw->bits = 0;
  83264. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83265. FLAC__ASSERT(bw->capacity == bw->words);
  83266. return false;
  83267. }
  83268. }
  83269. }
  83270. else {
  83271. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83272. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83273. bw->bits = bw->bits + msbits + lsbits;
  83274. uval |= mask1; /* set stop bit */
  83275. uval &= mask2; /* mask off unused top bits */
  83276. bw->accum <<= msbits + lsbits;
  83277. bw->accum |= uval;
  83278. }
  83279. else {
  83280. #endif
  83281. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83282. return false;
  83283. if(msbits) {
  83284. if(bw->bits) {
  83285. left = FLAC__BITS_PER_WORD - bw->bits;
  83286. if(msbits < left) {
  83287. bw->accum <<= msbits;
  83288. bw->bits += msbits;
  83289. goto break1;
  83290. }
  83291. else {
  83292. bw->accum <<= left;
  83293. msbits -= left;
  83294. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83295. bw->bits = 0;
  83296. }
  83297. }
  83298. while(msbits >= FLAC__BITS_PER_WORD) {
  83299. bw->buffer[bw->words++] = 0;
  83300. msbits -= FLAC__BITS_PER_WORD;
  83301. }
  83302. if(msbits > 0) {
  83303. bw->accum = 0;
  83304. bw->bits = msbits;
  83305. }
  83306. }
  83307. break1:
  83308. uval |= mask1; /* set stop bit */
  83309. uval &= mask2; /* mask off unused top bits */
  83310. left = FLAC__BITS_PER_WORD - bw->bits;
  83311. if(lsbits < left) {
  83312. bw->accum <<= lsbits;
  83313. bw->accum |= uval;
  83314. bw->bits += lsbits;
  83315. }
  83316. else {
  83317. FLAC__ASSERT(bw->bits);
  83318. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83319. bw->accum <<= left;
  83320. bw->accum |= uval >> (bw->bits = lsbits - left);
  83321. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83322. bw->accum = uval;
  83323. }
  83324. #if 1
  83325. }
  83326. #endif
  83327. vals++;
  83328. nvals--;
  83329. }
  83330. return true;
  83331. }
  83332. #if 0 /* UNUSED */
  83333. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83334. {
  83335. unsigned total_bits, msbs, uval;
  83336. unsigned k;
  83337. FLAC__ASSERT(0 != bw);
  83338. FLAC__ASSERT(0 != bw->buffer);
  83339. FLAC__ASSERT(parameter > 0);
  83340. if(val < 0)
  83341. uval = (unsigned)(((-(++val)) << 1) + 1);
  83342. else
  83343. uval = (unsigned)(val << 1);
  83344. k = FLAC__bitmath_ilog2(parameter);
  83345. if(parameter == 1u<<k) {
  83346. unsigned pattern;
  83347. FLAC__ASSERT(k <= 30);
  83348. msbs = uval >> k;
  83349. total_bits = 1 + k + msbs;
  83350. pattern = 1 << k; /* the unary end bit */
  83351. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83352. if(total_bits <= 32) {
  83353. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83354. return false;
  83355. }
  83356. else {
  83357. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83358. return false;
  83359. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83360. return false;
  83361. }
  83362. }
  83363. else {
  83364. unsigned q, r, d;
  83365. d = (1 << (k+1)) - parameter;
  83366. q = uval / parameter;
  83367. r = uval - (q * parameter);
  83368. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83369. return false;
  83370. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83371. return false;
  83372. if(r >= d) {
  83373. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83374. return false;
  83375. }
  83376. else {
  83377. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83378. return false;
  83379. }
  83380. }
  83381. return true;
  83382. }
  83383. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83384. {
  83385. unsigned total_bits, msbs;
  83386. unsigned k;
  83387. FLAC__ASSERT(0 != bw);
  83388. FLAC__ASSERT(0 != bw->buffer);
  83389. FLAC__ASSERT(parameter > 0);
  83390. k = FLAC__bitmath_ilog2(parameter);
  83391. if(parameter == 1u<<k) {
  83392. unsigned pattern;
  83393. FLAC__ASSERT(k <= 30);
  83394. msbs = uval >> k;
  83395. total_bits = 1 + k + msbs;
  83396. pattern = 1 << k; /* the unary end bit */
  83397. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83398. if(total_bits <= 32) {
  83399. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83400. return false;
  83401. }
  83402. else {
  83403. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83404. return false;
  83405. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83406. return false;
  83407. }
  83408. }
  83409. else {
  83410. unsigned q, r, d;
  83411. d = (1 << (k+1)) - parameter;
  83412. q = uval / parameter;
  83413. r = uval - (q * parameter);
  83414. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83415. return false;
  83416. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83417. return false;
  83418. if(r >= d) {
  83419. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83420. return false;
  83421. }
  83422. else {
  83423. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83424. return false;
  83425. }
  83426. }
  83427. return true;
  83428. }
  83429. #endif /* UNUSED */
  83430. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83431. {
  83432. FLAC__bool ok = 1;
  83433. FLAC__ASSERT(0 != bw);
  83434. FLAC__ASSERT(0 != bw->buffer);
  83435. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83436. if(val < 0x80) {
  83437. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83438. }
  83439. else if(val < 0x800) {
  83440. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83441. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83442. }
  83443. else if(val < 0x10000) {
  83444. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83445. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83446. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83447. }
  83448. else if(val < 0x200000) {
  83449. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83450. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83451. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83452. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83453. }
  83454. else if(val < 0x4000000) {
  83455. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83456. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83457. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83458. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83459. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83460. }
  83461. else {
  83462. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83463. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83464. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83465. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83466. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83467. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83468. }
  83469. return ok;
  83470. }
  83471. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83472. {
  83473. FLAC__bool ok = 1;
  83474. FLAC__ASSERT(0 != bw);
  83475. FLAC__ASSERT(0 != bw->buffer);
  83476. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83477. if(val < 0x80) {
  83478. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83479. }
  83480. else if(val < 0x800) {
  83481. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83482. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83483. }
  83484. else if(val < 0x10000) {
  83485. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83486. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83487. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83488. }
  83489. else if(val < 0x200000) {
  83490. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83491. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83492. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83493. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83494. }
  83495. else if(val < 0x4000000) {
  83496. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83497. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83498. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83499. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83500. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83501. }
  83502. else if(val < 0x80000000) {
  83503. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83504. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83505. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83506. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83507. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83508. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83509. }
  83510. else {
  83511. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83512. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83513. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83514. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83515. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83516. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83517. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83518. }
  83519. return ok;
  83520. }
  83521. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83522. {
  83523. if(bw->bits & 7u)
  83524. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83525. else
  83526. return true;
  83527. }
  83528. #endif
  83529. /*** End of inlined file: bitwriter.c ***/
  83530. /*** Start of inlined file: cpu.c ***/
  83531. /*** Start of inlined file: juce_FlacHeader.h ***/
  83532. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83533. // tasks..
  83534. #define VERSION "1.2.1"
  83535. #define FLAC__NO_DLL 1
  83536. #if JUCE_MSVC
  83537. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83538. #endif
  83539. #if JUCE_MAC
  83540. #define FLAC__SYS_DARWIN 1
  83541. #endif
  83542. /*** End of inlined file: juce_FlacHeader.h ***/
  83543. #if JUCE_USE_FLAC
  83544. #if HAVE_CONFIG_H
  83545. # include <config.h>
  83546. #endif
  83547. #include <stdlib.h>
  83548. #include <stdio.h>
  83549. #if defined FLAC__CPU_IA32
  83550. # include <signal.h>
  83551. #elif defined FLAC__CPU_PPC
  83552. # if !defined FLAC__NO_ASM
  83553. # if defined FLAC__SYS_DARWIN
  83554. # include <sys/sysctl.h>
  83555. # include <mach/mach.h>
  83556. # include <mach/mach_host.h>
  83557. # include <mach/host_info.h>
  83558. # include <mach/machine.h>
  83559. # ifndef CPU_SUBTYPE_POWERPC_970
  83560. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83561. # endif
  83562. # else /* FLAC__SYS_DARWIN */
  83563. # include <signal.h>
  83564. # include <setjmp.h>
  83565. static sigjmp_buf jmpbuf;
  83566. static volatile sig_atomic_t canjump = 0;
  83567. static void sigill_handler (int sig)
  83568. {
  83569. if (!canjump) {
  83570. signal (sig, SIG_DFL);
  83571. raise (sig);
  83572. }
  83573. canjump = 0;
  83574. siglongjmp (jmpbuf, 1);
  83575. }
  83576. # endif /* FLAC__SYS_DARWIN */
  83577. # endif /* FLAC__NO_ASM */
  83578. #endif /* FLAC__CPU_PPC */
  83579. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83580. #include <sys/param.h>
  83581. #include <sys/sysctl.h>
  83582. #include <machine/cpu.h>
  83583. #endif
  83584. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83585. #include <sys/types.h>
  83586. #include <sys/sysctl.h>
  83587. #endif
  83588. #if defined(__APPLE__)
  83589. #endif
  83590. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83591. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83592. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83593. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83594. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83595. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83596. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83597. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83598. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83599. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83600. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83601. # if defined(__linux__)
  83602. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83603. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83604. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83605. {
  83606. (void)signal;
  83607. sc.eip += 3 + 3 + 6;
  83608. }
  83609. # else
  83610. # include <sys/ucontext.h>
  83611. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83612. {
  83613. (void)signal, (void)si;
  83614. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83615. }
  83616. # endif
  83617. # elif defined(_MSC_VER)
  83618. # include <windows.h>
  83619. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83620. # ifdef USE_TRY_CATCH_FLAVOR
  83621. # else
  83622. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83623. {
  83624. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83625. ep->ContextRecord->Eip += 3 + 3 + 6;
  83626. return EXCEPTION_CONTINUE_EXECUTION;
  83627. }
  83628. return EXCEPTION_CONTINUE_SEARCH;
  83629. }
  83630. # endif
  83631. # endif
  83632. #endif
  83633. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83634. {
  83635. #ifdef FLAC__CPU_IA32
  83636. info->type = FLAC__CPUINFO_TYPE_IA32;
  83637. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83638. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83639. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83640. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83641. info->data.ia32.cmov = false;
  83642. info->data.ia32.mmx = false;
  83643. info->data.ia32.fxsr = false;
  83644. info->data.ia32.sse = false;
  83645. info->data.ia32.sse2 = false;
  83646. info->data.ia32.sse3 = false;
  83647. info->data.ia32.ssse3 = false;
  83648. info->data.ia32._3dnow = false;
  83649. info->data.ia32.ext3dnow = false;
  83650. info->data.ia32.extmmx = false;
  83651. if(info->data.ia32.cpuid) {
  83652. FLAC__uint32 flags_edx, flags_ecx;
  83653. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83654. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83655. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83656. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83657. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83658. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83659. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83660. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83661. #ifdef FLAC__USE_3DNOW
  83662. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83663. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83664. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83665. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83666. #else
  83667. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83668. #endif
  83669. #ifdef DEBUG
  83670. fprintf(stderr, "CPU info (IA-32):\n");
  83671. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83672. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83673. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83674. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83675. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83676. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83677. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83678. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83679. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83680. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83681. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83682. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83683. #endif
  83684. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83685. #if defined FLAC__NO_SSE_OS
  83686. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83687. #elif defined FLAC__SSE_OS
  83688. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83689. int sse = 0;
  83690. size_t len;
  83691. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83692. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83693. if(!sse)
  83694. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83695. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83696. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83697. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83698. size_t len = sizeof(val);
  83699. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83700. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83701. else { /* double-check SSE2 */
  83702. mib[1] = CPU_SSE2;
  83703. len = sizeof(val);
  83704. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83705. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83706. }
  83707. # else
  83708. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83709. # endif
  83710. #elif defined(__linux__)
  83711. int sse = 0;
  83712. struct sigaction sigill_save;
  83713. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83714. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83715. #else
  83716. struct sigaction sigill_sse;
  83717. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83718. __sigemptyset(&sigill_sse.sa_mask);
  83719. 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 */
  83720. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83721. #endif
  83722. {
  83723. asm volatile (
  83724. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83725. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83726. "incl %0\n\t" /* SIGILL handler will jump over this */
  83727. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83728. "nop\n\t"
  83729. "nop\n\t"
  83730. "nop\n\t"
  83731. "nop\n\t"
  83732. "nop\n\t"
  83733. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83734. "nop\n\t"
  83735. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83736. : "=r"(sse)
  83737. : "r"(sse)
  83738. );
  83739. sigaction(SIGILL, &sigill_save, NULL);
  83740. }
  83741. if(!sse)
  83742. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83743. #elif defined(_MSC_VER)
  83744. # ifdef USE_TRY_CATCH_FLAVOR
  83745. _try {
  83746. __asm {
  83747. # if _MSC_VER <= 1200
  83748. _emit 0x0F
  83749. _emit 0x57
  83750. _emit 0xC0
  83751. # else
  83752. xorps xmm0,xmm0
  83753. # endif
  83754. }
  83755. }
  83756. _except(EXCEPTION_EXECUTE_HANDLER) {
  83757. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83758. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83759. }
  83760. # else
  83761. int sse = 0;
  83762. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83763. __asm {
  83764. # if _MSC_VER <= 1200
  83765. _emit 0x0F
  83766. _emit 0x57
  83767. _emit 0xC0
  83768. # else
  83769. xorps xmm0,xmm0
  83770. # endif
  83771. inc sse
  83772. nop
  83773. nop
  83774. nop
  83775. nop
  83776. nop
  83777. nop
  83778. nop
  83779. nop
  83780. nop
  83781. }
  83782. SetUnhandledExceptionFilter(save);
  83783. if(!sse)
  83784. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83785. # endif
  83786. #else
  83787. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83788. #endif
  83789. #ifdef DEBUG
  83790. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83791. #endif
  83792. }
  83793. }
  83794. #else
  83795. info->use_asm = false;
  83796. #endif
  83797. #elif defined FLAC__CPU_PPC
  83798. info->type = FLAC__CPUINFO_TYPE_PPC;
  83799. # if !defined FLAC__NO_ASM
  83800. info->use_asm = true;
  83801. # ifdef FLAC__USE_ALTIVEC
  83802. # if defined FLAC__SYS_DARWIN
  83803. {
  83804. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83805. size_t len = sizeof(val);
  83806. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83807. }
  83808. {
  83809. host_basic_info_data_t hostInfo;
  83810. mach_msg_type_number_t infoCount;
  83811. infoCount = HOST_BASIC_INFO_COUNT;
  83812. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83813. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83814. }
  83815. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83816. {
  83817. info->data.ppc.altivec = 0;
  83818. info->data.ppc.ppc64 = 0;
  83819. signal (SIGILL, sigill_handler);
  83820. canjump = 0;
  83821. if (!sigsetjmp (jmpbuf, 1)) {
  83822. canjump = 1;
  83823. asm volatile (
  83824. "mtspr 256, %0\n\t"
  83825. "vand %%v0, %%v0, %%v0"
  83826. :
  83827. : "r" (-1)
  83828. );
  83829. info->data.ppc.altivec = 1;
  83830. }
  83831. canjump = 0;
  83832. if (!sigsetjmp (jmpbuf, 1)) {
  83833. int x = 0;
  83834. canjump = 1;
  83835. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83836. info->data.ppc.ppc64 = 1;
  83837. }
  83838. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83839. }
  83840. # endif
  83841. # else /* !FLAC__USE_ALTIVEC */
  83842. info->data.ppc.altivec = 0;
  83843. info->data.ppc.ppc64 = 0;
  83844. # endif
  83845. # else
  83846. info->use_asm = false;
  83847. # endif
  83848. #else
  83849. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83850. info->use_asm = false;
  83851. #endif
  83852. }
  83853. #endif
  83854. /*** End of inlined file: cpu.c ***/
  83855. /*** Start of inlined file: crc.c ***/
  83856. /*** Start of inlined file: juce_FlacHeader.h ***/
  83857. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83858. // tasks..
  83859. #define VERSION "1.2.1"
  83860. #define FLAC__NO_DLL 1
  83861. #if JUCE_MSVC
  83862. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83863. #endif
  83864. #if JUCE_MAC
  83865. #define FLAC__SYS_DARWIN 1
  83866. #endif
  83867. /*** End of inlined file: juce_FlacHeader.h ***/
  83868. #if JUCE_USE_FLAC
  83869. #if HAVE_CONFIG_H
  83870. # include <config.h>
  83871. #endif
  83872. FLAC__byte const FLAC__crc8_table[256] = {
  83873. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83874. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83875. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83876. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83877. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83878. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83879. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83880. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83881. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83882. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83883. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83884. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83885. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83886. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83887. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83888. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83889. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83890. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83891. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83892. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83893. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83894. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83895. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83896. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83897. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83898. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83899. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83900. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83901. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83902. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83903. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83904. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83905. };
  83906. unsigned FLAC__crc16_table[256] = {
  83907. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83908. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83909. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83910. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83911. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83912. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83913. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83914. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83915. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83916. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83917. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83918. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83919. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83920. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83921. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83922. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  83923. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  83924. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  83925. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  83926. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  83927. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  83928. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  83929. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  83930. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  83931. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  83932. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  83933. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  83934. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  83935. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  83936. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  83937. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  83938. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  83939. };
  83940. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  83941. {
  83942. *crc = FLAC__crc8_table[*crc ^ data];
  83943. }
  83944. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  83945. {
  83946. while(len--)
  83947. *crc = FLAC__crc8_table[*crc ^ *data++];
  83948. }
  83949. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  83950. {
  83951. FLAC__uint8 crc = 0;
  83952. while(len--)
  83953. crc = FLAC__crc8_table[crc ^ *data++];
  83954. return crc;
  83955. }
  83956. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  83957. {
  83958. unsigned crc = 0;
  83959. while(len--)
  83960. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  83961. return crc;
  83962. }
  83963. #endif
  83964. /*** End of inlined file: crc.c ***/
  83965. /*** Start of inlined file: fixed.c ***/
  83966. /*** Start of inlined file: juce_FlacHeader.h ***/
  83967. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83968. // tasks..
  83969. #define VERSION "1.2.1"
  83970. #define FLAC__NO_DLL 1
  83971. #if JUCE_MSVC
  83972. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83973. #endif
  83974. #if JUCE_MAC
  83975. #define FLAC__SYS_DARWIN 1
  83976. #endif
  83977. /*** End of inlined file: juce_FlacHeader.h ***/
  83978. #if JUCE_USE_FLAC
  83979. #if HAVE_CONFIG_H
  83980. # include <config.h>
  83981. #endif
  83982. #include <math.h>
  83983. #include <string.h>
  83984. /*** Start of inlined file: fixed.h ***/
  83985. #ifndef FLAC__PRIVATE__FIXED_H
  83986. #define FLAC__PRIVATE__FIXED_H
  83987. #ifdef HAVE_CONFIG_H
  83988. #include <config.h>
  83989. #endif
  83990. /*** Start of inlined file: float.h ***/
  83991. #ifndef FLAC__PRIVATE__FLOAT_H
  83992. #define FLAC__PRIVATE__FLOAT_H
  83993. #ifdef HAVE_CONFIG_H
  83994. #include <config.h>
  83995. #endif
  83996. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83997. typedef double FLAC__double;
  83998. typedef float FLAC__float;
  83999. typedef float FLAC__real;
  84000. #else
  84001. typedef FLAC__int32 FLAC__fixedpoint;
  84002. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  84003. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  84004. extern const FLAC__fixedpoint FLAC__FP_ONE;
  84005. extern const FLAC__fixedpoint FLAC__FP_LN2;
  84006. extern const FLAC__fixedpoint FLAC__FP_E;
  84007. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  84008. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  84009. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  84010. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84011. #endif
  84012. #endif
  84013. /*** End of inlined file: float.h ***/
  84014. /*** Start of inlined file: format.h ***/
  84015. #ifndef FLAC__PRIVATE__FORMAT_H
  84016. #define FLAC__PRIVATE__FORMAT_H
  84017. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84018. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84019. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84020. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84021. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84022. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84023. #endif
  84024. /*** End of inlined file: format.h ***/
  84025. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84026. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84027. # ifndef FLAC__NO_ASM
  84028. # ifdef FLAC__CPU_IA32
  84029. # ifdef FLAC__HAS_NASM
  84030. 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]);
  84031. # endif
  84032. # endif
  84033. # endif
  84034. 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]);
  84035. #else
  84036. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84037. 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]);
  84038. #endif
  84039. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84040. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84041. #endif
  84042. /*** End of inlined file: fixed.h ***/
  84043. #ifndef M_LN2
  84044. #define M_LN2 0.69314718055994530942
  84045. #endif
  84046. #ifdef min
  84047. #undef min
  84048. #endif
  84049. #define min(x,y) ((x) < (y)? (x) : (y))
  84050. #ifdef local_abs
  84051. #undef local_abs
  84052. #endif
  84053. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84054. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84055. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84056. {
  84057. FLAC__uint32 rbps;
  84058. unsigned bits; /* the number of bits required to represent a number */
  84059. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84060. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84061. FLAC__ASSERT(err > 0);
  84062. FLAC__ASSERT(n > 0);
  84063. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84064. if(err <= n)
  84065. return 0;
  84066. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84067. err <<= fracbits;
  84068. err /= n;
  84069. FLAC__ASSERT(err > 0);
  84070. bits = FLAC__bitmath_ilog2(err)+1;
  84071. if(bits > 16) {
  84072. err >>= (bits-16);
  84073. fracbits -= (bits-16);
  84074. }
  84075. rbps = (FLAC__uint32)err;
  84076. rbps *= FLAC__FP_LN2;
  84077. fracbits += 16;
  84078. FLAC__ASSERT(fracbits >= 0);
  84079. {
  84080. const int f = fracbits & 3;
  84081. if(f) {
  84082. rbps >>= f;
  84083. fracbits -= f;
  84084. }
  84085. }
  84086. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84087. if(rbps == 0)
  84088. return 0;
  84089. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84090. FLAC__ASSERT(fracbits >= -3);
  84091. if(fracbits < 16)
  84092. return rbps << (16-fracbits);
  84093. else if(fracbits > 16)
  84094. return rbps >> (fracbits-16);
  84095. else
  84096. return rbps;
  84097. }
  84098. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84099. {
  84100. FLAC__uint32 rbps;
  84101. unsigned bits; /* the number of bits required to represent a number */
  84102. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84103. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84104. FLAC__ASSERT(err > 0);
  84105. FLAC__ASSERT(n > 0);
  84106. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84107. if(err <= n)
  84108. return 0;
  84109. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84110. err <<= fracbits;
  84111. err /= n;
  84112. FLAC__ASSERT(err > 0);
  84113. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84114. if(bits > 16) {
  84115. err >>= (bits-16);
  84116. fracbits -= (bits-16);
  84117. }
  84118. rbps = (FLAC__uint32)err;
  84119. rbps *= FLAC__FP_LN2;
  84120. fracbits += 16;
  84121. FLAC__ASSERT(fracbits >= 0);
  84122. {
  84123. const int f = fracbits & 3;
  84124. if(f) {
  84125. rbps >>= f;
  84126. fracbits -= f;
  84127. }
  84128. }
  84129. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84130. if(rbps == 0)
  84131. return 0;
  84132. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84133. FLAC__ASSERT(fracbits >= -3);
  84134. if(fracbits < 16)
  84135. return rbps << (16-fracbits);
  84136. else if(fracbits > 16)
  84137. return rbps >> (fracbits-16);
  84138. else
  84139. return rbps;
  84140. }
  84141. #endif
  84142. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84143. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84144. #else
  84145. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84146. #endif
  84147. {
  84148. FLAC__int32 last_error_0 = data[-1];
  84149. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84150. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84151. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84152. FLAC__int32 error, save;
  84153. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84154. unsigned i, order;
  84155. for(i = 0; i < data_len; i++) {
  84156. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84157. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84158. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84159. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84160. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84161. }
  84162. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84163. order = 0;
  84164. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84165. order = 1;
  84166. else if(total_error_2 < min(total_error_3, total_error_4))
  84167. order = 2;
  84168. else if(total_error_3 < total_error_4)
  84169. order = 3;
  84170. else
  84171. order = 4;
  84172. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84173. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84174. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84175. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84176. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84177. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84178. 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);
  84179. 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);
  84180. 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);
  84181. 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);
  84182. 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);
  84183. #else
  84184. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84185. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84186. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84187. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84188. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84189. #endif
  84190. return order;
  84191. }
  84192. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84193. 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])
  84194. #else
  84195. 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])
  84196. #endif
  84197. {
  84198. FLAC__int32 last_error_0 = data[-1];
  84199. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84200. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84201. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84202. FLAC__int32 error, save;
  84203. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84204. unsigned i, order;
  84205. for(i = 0; i < data_len; i++) {
  84206. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84207. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84208. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84209. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84210. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84211. }
  84212. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84213. order = 0;
  84214. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84215. order = 1;
  84216. else if(total_error_2 < min(total_error_3, total_error_4))
  84217. order = 2;
  84218. else if(total_error_3 < total_error_4)
  84219. order = 3;
  84220. else
  84221. order = 4;
  84222. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84223. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84224. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84225. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84226. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84227. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84228. #if defined _MSC_VER || defined __MINGW32__
  84229. 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);
  84230. 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);
  84231. 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);
  84232. 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);
  84233. 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);
  84234. #else
  84235. 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);
  84236. 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);
  84237. 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);
  84238. 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);
  84239. 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);
  84240. #endif
  84241. #else
  84242. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84243. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84244. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84245. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84246. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84247. #endif
  84248. return order;
  84249. }
  84250. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84251. {
  84252. const int idata_len = (int)data_len;
  84253. int i;
  84254. switch(order) {
  84255. case 0:
  84256. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84257. memcpy(residual, data, sizeof(residual[0])*data_len);
  84258. break;
  84259. case 1:
  84260. for(i = 0; i < idata_len; i++)
  84261. residual[i] = data[i] - data[i-1];
  84262. break;
  84263. case 2:
  84264. for(i = 0; i < idata_len; i++)
  84265. #if 1 /* OPT: may be faster with some compilers on some systems */
  84266. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84267. #else
  84268. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84269. #endif
  84270. break;
  84271. case 3:
  84272. for(i = 0; i < idata_len; i++)
  84273. #if 1 /* OPT: may be faster with some compilers on some systems */
  84274. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84275. #else
  84276. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84277. #endif
  84278. break;
  84279. case 4:
  84280. for(i = 0; i < idata_len; i++)
  84281. #if 1 /* OPT: may be faster with some compilers on some systems */
  84282. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84283. #else
  84284. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84285. #endif
  84286. break;
  84287. default:
  84288. FLAC__ASSERT(0);
  84289. }
  84290. }
  84291. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84292. {
  84293. int i, idata_len = (int)data_len;
  84294. switch(order) {
  84295. case 0:
  84296. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84297. memcpy(data, residual, sizeof(residual[0])*data_len);
  84298. break;
  84299. case 1:
  84300. for(i = 0; i < idata_len; i++)
  84301. data[i] = residual[i] + data[i-1];
  84302. break;
  84303. case 2:
  84304. for(i = 0; i < idata_len; i++)
  84305. #if 1 /* OPT: may be faster with some compilers on some systems */
  84306. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84307. #else
  84308. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84309. #endif
  84310. break;
  84311. case 3:
  84312. for(i = 0; i < idata_len; i++)
  84313. #if 1 /* OPT: may be faster with some compilers on some systems */
  84314. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84315. #else
  84316. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84317. #endif
  84318. break;
  84319. case 4:
  84320. for(i = 0; i < idata_len; i++)
  84321. #if 1 /* OPT: may be faster with some compilers on some systems */
  84322. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84323. #else
  84324. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84325. #endif
  84326. break;
  84327. default:
  84328. FLAC__ASSERT(0);
  84329. }
  84330. }
  84331. #endif
  84332. /*** End of inlined file: fixed.c ***/
  84333. /*** Start of inlined file: float.c ***/
  84334. /*** Start of inlined file: juce_FlacHeader.h ***/
  84335. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84336. // tasks..
  84337. #define VERSION "1.2.1"
  84338. #define FLAC__NO_DLL 1
  84339. #if JUCE_MSVC
  84340. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84341. #endif
  84342. #if JUCE_MAC
  84343. #define FLAC__SYS_DARWIN 1
  84344. #endif
  84345. /*** End of inlined file: juce_FlacHeader.h ***/
  84346. #if JUCE_USE_FLAC
  84347. #if HAVE_CONFIG_H
  84348. # include <config.h>
  84349. #endif
  84350. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84351. #ifdef _MSC_VER
  84352. #define FLAC__U64L(x) x
  84353. #else
  84354. #define FLAC__U64L(x) x##LLU
  84355. #endif
  84356. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84357. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84358. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84359. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84360. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84361. #define LOG2_LOOKUP_PRECISION 16
  84362. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84363. {
  84364. 0x00000000,
  84365. 0x00000001,
  84366. 0x00000000,
  84367. 0x00000000,
  84368. 0x00000000,
  84369. 0x00000000,
  84370. 0x00000000,
  84371. 0x00000000,
  84372. 0x00000000,
  84373. 0x00000000,
  84374. 0x00000000,
  84375. 0x00000000,
  84376. 0x00000000,
  84377. 0x00000000,
  84378. 0x00000000,
  84379. 0x00000000
  84380. },
  84381. {
  84382. 0x00000000,
  84383. 0x00000010,
  84384. 0x00000007,
  84385. 0x00000003,
  84386. 0x00000001,
  84387. 0x00000001,
  84388. 0x00000000,
  84389. 0x00000000,
  84390. 0x00000000,
  84391. 0x00000000,
  84392. 0x00000000,
  84393. 0x00000000,
  84394. 0x00000000,
  84395. 0x00000000,
  84396. 0x00000000,
  84397. 0x00000000
  84398. },
  84399. {
  84400. 0x00000000,
  84401. 0x00000100,
  84402. 0x0000006a,
  84403. 0x00000031,
  84404. 0x00000018,
  84405. 0x0000000c,
  84406. 0x00000006,
  84407. 0x00000003,
  84408. 0x00000001,
  84409. 0x00000001,
  84410. 0x00000000,
  84411. 0x00000000,
  84412. 0x00000000,
  84413. 0x00000000,
  84414. 0x00000000,
  84415. 0x00000000
  84416. },
  84417. {
  84418. 0x00000000,
  84419. 0x00001000,
  84420. 0x000006a4,
  84421. 0x00000315,
  84422. 0x0000017d,
  84423. 0x000000bc,
  84424. 0x0000005d,
  84425. 0x0000002e,
  84426. 0x00000017,
  84427. 0x0000000c,
  84428. 0x00000006,
  84429. 0x00000003,
  84430. 0x00000001,
  84431. 0x00000001,
  84432. 0x00000000,
  84433. 0x00000000
  84434. },
  84435. {
  84436. 0x00000000,
  84437. 0x00010000,
  84438. 0x00006a40,
  84439. 0x00003151,
  84440. 0x000017d6,
  84441. 0x00000bba,
  84442. 0x000005d1,
  84443. 0x000002e6,
  84444. 0x00000172,
  84445. 0x000000b9,
  84446. 0x0000005c,
  84447. 0x0000002e,
  84448. 0x00000017,
  84449. 0x0000000c,
  84450. 0x00000006,
  84451. 0x00000003
  84452. },
  84453. {
  84454. 0x00000000,
  84455. 0x00100000,
  84456. 0x0006a3fe,
  84457. 0x00031513,
  84458. 0x00017d60,
  84459. 0x0000bb9d,
  84460. 0x00005d10,
  84461. 0x00002e59,
  84462. 0x00001721,
  84463. 0x00000b8e,
  84464. 0x000005c6,
  84465. 0x000002e3,
  84466. 0x00000171,
  84467. 0x000000b9,
  84468. 0x0000005c,
  84469. 0x0000002e
  84470. },
  84471. {
  84472. 0x00000000,
  84473. 0x01000000,
  84474. 0x006a3fe6,
  84475. 0x00315130,
  84476. 0x0017d605,
  84477. 0x000bb9ca,
  84478. 0x0005d0fc,
  84479. 0x0002e58f,
  84480. 0x0001720e,
  84481. 0x0000b8d8,
  84482. 0x00005c61,
  84483. 0x00002e2d,
  84484. 0x00001716,
  84485. 0x00000b8b,
  84486. 0x000005c5,
  84487. 0x000002e3
  84488. },
  84489. {
  84490. 0x00000000,
  84491. 0x10000000,
  84492. 0x06a3fe5c,
  84493. 0x03151301,
  84494. 0x017d6049,
  84495. 0x00bb9ca6,
  84496. 0x005d0fba,
  84497. 0x002e58f7,
  84498. 0x001720da,
  84499. 0x000b8d87,
  84500. 0x0005c60b,
  84501. 0x0002e2d7,
  84502. 0x00017160,
  84503. 0x0000b8ad,
  84504. 0x00005c56,
  84505. 0x00002e2b
  84506. }
  84507. };
  84508. #if 0
  84509. static const FLAC__uint64 log2_lookup_wide[] = {
  84510. {
  84511. 0x00000000,
  84512. FLAC__U64L(0x100000000),
  84513. FLAC__U64L(0x6a3fe5c6),
  84514. FLAC__U64L(0x31513015),
  84515. FLAC__U64L(0x17d60497),
  84516. FLAC__U64L(0x0bb9ca65),
  84517. FLAC__U64L(0x05d0fba2),
  84518. FLAC__U64L(0x02e58f74),
  84519. FLAC__U64L(0x01720d9c),
  84520. FLAC__U64L(0x00b8d875),
  84521. FLAC__U64L(0x005c60aa),
  84522. FLAC__U64L(0x002e2d72),
  84523. FLAC__U64L(0x00171600),
  84524. FLAC__U64L(0x000b8ad2),
  84525. FLAC__U64L(0x0005c55d),
  84526. FLAC__U64L(0x0002e2ac)
  84527. },
  84528. {
  84529. 0x00000000,
  84530. FLAC__U64L(0x1000000000000),
  84531. FLAC__U64L(0x6a3fe5c60429),
  84532. FLAC__U64L(0x315130157f7a),
  84533. FLAC__U64L(0x17d60496cfbb),
  84534. FLAC__U64L(0xbb9ca64ecac),
  84535. FLAC__U64L(0x5d0fba187cd),
  84536. FLAC__U64L(0x2e58f7441ee),
  84537. FLAC__U64L(0x1720d9c06a8),
  84538. FLAC__U64L(0xb8d8752173),
  84539. FLAC__U64L(0x5c60aa252e),
  84540. FLAC__U64L(0x2e2d71b0d8),
  84541. FLAC__U64L(0x1716001719),
  84542. FLAC__U64L(0xb8ad1de1b),
  84543. FLAC__U64L(0x5c55d640d),
  84544. FLAC__U64L(0x2e2abcf52)
  84545. }
  84546. };
  84547. #endif
  84548. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84549. {
  84550. const FLAC__uint32 ONE = (1u << fracbits);
  84551. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84552. FLAC__ASSERT(fracbits < 32);
  84553. FLAC__ASSERT((fracbits & 0x3) == 0);
  84554. if(x < ONE)
  84555. return 0;
  84556. if(precision > LOG2_LOOKUP_PRECISION)
  84557. precision = LOG2_LOOKUP_PRECISION;
  84558. {
  84559. FLAC__uint32 y = 0;
  84560. FLAC__uint32 z = x >> 1, k = 1;
  84561. while (x > ONE && k < precision) {
  84562. if (x - z >= ONE) {
  84563. x -= z;
  84564. z = x >> k;
  84565. y += table[k];
  84566. }
  84567. else {
  84568. z >>= 1;
  84569. k++;
  84570. }
  84571. }
  84572. return y;
  84573. }
  84574. }
  84575. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84576. #endif
  84577. /*** End of inlined file: float.c ***/
  84578. /*** Start of inlined file: format.c ***/
  84579. /*** Start of inlined file: juce_FlacHeader.h ***/
  84580. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84581. // tasks..
  84582. #define VERSION "1.2.1"
  84583. #define FLAC__NO_DLL 1
  84584. #if JUCE_MSVC
  84585. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84586. #endif
  84587. #if JUCE_MAC
  84588. #define FLAC__SYS_DARWIN 1
  84589. #endif
  84590. /*** End of inlined file: juce_FlacHeader.h ***/
  84591. #if JUCE_USE_FLAC
  84592. #if HAVE_CONFIG_H
  84593. # include <config.h>
  84594. #endif
  84595. #include <stdio.h>
  84596. #include <stdlib.h> /* for qsort() */
  84597. #include <string.h> /* for memset() */
  84598. #ifndef FLaC__INLINE
  84599. #define FLaC__INLINE
  84600. #endif
  84601. #ifdef min
  84602. #undef min
  84603. #endif
  84604. #define min(a,b) ((a)<(b)?(a):(b))
  84605. #ifdef _MSC_VER
  84606. #define FLAC__U64L(x) x
  84607. #else
  84608. #define FLAC__U64L(x) x##LLU
  84609. #endif
  84610. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84611. ;
  84612. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84613. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84614. #else
  84615. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84616. #endif
  84617. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84618. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84619. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84620. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84621. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84622. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84623. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84624. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84625. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84626. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84627. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84628. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84629. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84630. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84631. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84632. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84633. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84634. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84635. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84636. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84637. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84638. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84639. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84640. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84641. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84642. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84643. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84644. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84645. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84646. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84647. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84648. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84649. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84650. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84651. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84652. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84653. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84654. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84655. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84656. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84657. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84658. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84659. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84660. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84661. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84662. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84663. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84664. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84665. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84666. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84667. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84668. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84669. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84670. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84671. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84672. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84673. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84674. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84675. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84676. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84677. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84678. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84679. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84680. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84681. "PARTITIONED_RICE",
  84682. "PARTITIONED_RICE2"
  84683. };
  84684. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84685. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84686. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84687. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84688. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84689. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84690. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84691. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84692. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84693. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84694. "CONSTANT",
  84695. "VERBATIM",
  84696. "FIXED",
  84697. "LPC"
  84698. };
  84699. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84700. "INDEPENDENT",
  84701. "LEFT_SIDE",
  84702. "RIGHT_SIDE",
  84703. "MID_SIDE"
  84704. };
  84705. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84706. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84707. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84708. };
  84709. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84710. "STREAMINFO",
  84711. "PADDING",
  84712. "APPLICATION",
  84713. "SEEKTABLE",
  84714. "VORBIS_COMMENT",
  84715. "CUESHEET",
  84716. "PICTURE"
  84717. };
  84718. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84719. "Other",
  84720. "32x32 pixels 'file icon' (PNG only)",
  84721. "Other file icon",
  84722. "Cover (front)",
  84723. "Cover (back)",
  84724. "Leaflet page",
  84725. "Media (e.g. label side of CD)",
  84726. "Lead artist/lead performer/soloist",
  84727. "Artist/performer",
  84728. "Conductor",
  84729. "Band/Orchestra",
  84730. "Composer",
  84731. "Lyricist/text writer",
  84732. "Recording Location",
  84733. "During recording",
  84734. "During performance",
  84735. "Movie/video screen capture",
  84736. "A bright coloured fish",
  84737. "Illustration",
  84738. "Band/artist logotype",
  84739. "Publisher/Studio logotype"
  84740. };
  84741. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84742. {
  84743. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84744. return false;
  84745. }
  84746. else
  84747. return true;
  84748. }
  84749. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84750. {
  84751. if(
  84752. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84753. (
  84754. sample_rate >= (1u << 16) &&
  84755. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84756. )
  84757. ) {
  84758. return false;
  84759. }
  84760. else
  84761. return true;
  84762. }
  84763. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84764. {
  84765. unsigned i;
  84766. FLAC__uint64 prev_sample_number = 0;
  84767. FLAC__bool got_prev = false;
  84768. FLAC__ASSERT(0 != seek_table);
  84769. for(i = 0; i < seek_table->num_points; i++) {
  84770. if(got_prev) {
  84771. if(
  84772. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84773. seek_table->points[i].sample_number <= prev_sample_number
  84774. )
  84775. return false;
  84776. }
  84777. prev_sample_number = seek_table->points[i].sample_number;
  84778. got_prev = true;
  84779. }
  84780. return true;
  84781. }
  84782. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84783. {
  84784. if(l->sample_number == r->sample_number)
  84785. return 0;
  84786. else if(l->sample_number < r->sample_number)
  84787. return -1;
  84788. else
  84789. return 1;
  84790. }
  84791. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84792. {
  84793. unsigned i, j;
  84794. FLAC__bool first;
  84795. FLAC__ASSERT(0 != seek_table);
  84796. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84797. first = true;
  84798. for(i = j = 0; i < seek_table->num_points; i++) {
  84799. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84800. if(!first) {
  84801. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84802. continue;
  84803. }
  84804. }
  84805. first = false;
  84806. seek_table->points[j++] = seek_table->points[i];
  84807. }
  84808. for(i = j; i < seek_table->num_points; i++) {
  84809. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84810. seek_table->points[i].stream_offset = 0;
  84811. seek_table->points[i].frame_samples = 0;
  84812. }
  84813. return j;
  84814. }
  84815. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84816. {
  84817. FLAC__ASSERT(0 != utf8);
  84818. if ((utf8[0] & 0x80) == 0) {
  84819. return 1;
  84820. }
  84821. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84822. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84823. return 0;
  84824. return 2;
  84825. }
  84826. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84827. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84828. return 0;
  84829. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84830. return 0;
  84831. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84832. return 0;
  84833. return 3;
  84834. }
  84835. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84836. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84837. return 0;
  84838. return 4;
  84839. }
  84840. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84841. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84842. return 0;
  84843. return 5;
  84844. }
  84845. 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) {
  84846. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84847. return 0;
  84848. return 6;
  84849. }
  84850. else {
  84851. return 0;
  84852. }
  84853. }
  84854. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84855. {
  84856. char c;
  84857. for(c = *name; c; c = *(++name))
  84858. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84859. return false;
  84860. return true;
  84861. }
  84862. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84863. {
  84864. if(length == (unsigned)(-1)) {
  84865. while(*value) {
  84866. unsigned n = utf8len_(value);
  84867. if(n == 0)
  84868. return false;
  84869. value += n;
  84870. }
  84871. }
  84872. else {
  84873. const FLAC__byte *end = value + length;
  84874. while(value < end) {
  84875. unsigned n = utf8len_(value);
  84876. if(n == 0)
  84877. return false;
  84878. value += n;
  84879. }
  84880. if(value != end)
  84881. return false;
  84882. }
  84883. return true;
  84884. }
  84885. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84886. {
  84887. const FLAC__byte *s, *end;
  84888. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84889. if(*s < 0x20 || *s > 0x7D)
  84890. return false;
  84891. }
  84892. if(s == end)
  84893. return false;
  84894. s++; /* skip '=' */
  84895. while(s < end) {
  84896. unsigned n = utf8len_(s);
  84897. if(n == 0)
  84898. return false;
  84899. s += n;
  84900. }
  84901. if(s != end)
  84902. return false;
  84903. return true;
  84904. }
  84905. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84906. {
  84907. unsigned i, j;
  84908. if(check_cd_da_subset) {
  84909. if(cue_sheet->lead_in < 2 * 44100) {
  84910. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84911. return false;
  84912. }
  84913. if(cue_sheet->lead_in % 588 != 0) {
  84914. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84915. return false;
  84916. }
  84917. }
  84918. if(cue_sheet->num_tracks == 0) {
  84919. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84920. return false;
  84921. }
  84922. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  84923. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  84924. return false;
  84925. }
  84926. for(i = 0; i < cue_sheet->num_tracks; i++) {
  84927. if(cue_sheet->tracks[i].number == 0) {
  84928. if(violation) *violation = "cue sheet may not have a track number 0";
  84929. return false;
  84930. }
  84931. if(check_cd_da_subset) {
  84932. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  84933. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  84934. return false;
  84935. }
  84936. }
  84937. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  84938. if(violation) {
  84939. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  84940. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  84941. else
  84942. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  84943. }
  84944. return false;
  84945. }
  84946. if(i < cue_sheet->num_tracks - 1) {
  84947. if(cue_sheet->tracks[i].num_indices == 0) {
  84948. if(violation) *violation = "cue sheet track must have at least one index point";
  84949. return false;
  84950. }
  84951. if(cue_sheet->tracks[i].indices[0].number > 1) {
  84952. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  84953. return false;
  84954. }
  84955. }
  84956. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  84957. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  84958. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  84959. return false;
  84960. }
  84961. if(j > 0) {
  84962. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  84963. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  84964. return false;
  84965. }
  84966. }
  84967. }
  84968. }
  84969. return true;
  84970. }
  84971. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  84972. {
  84973. char *p;
  84974. FLAC__byte *b;
  84975. for(p = picture->mime_type; *p; p++) {
  84976. if(*p < 0x20 || *p > 0x7e) {
  84977. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  84978. return false;
  84979. }
  84980. }
  84981. for(b = picture->description; *b; ) {
  84982. unsigned n = utf8len_(b);
  84983. if(n == 0) {
  84984. if(violation) *violation = "description string must be valid UTF-8";
  84985. return false;
  84986. }
  84987. b += n;
  84988. }
  84989. return true;
  84990. }
  84991. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  84992. {
  84993. return
  84994. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  84995. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  84996. blocksize,
  84997. predictor_order
  84998. );
  84999. }
  85000. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  85001. {
  85002. unsigned max_rice_partition_order = 0;
  85003. while(!(blocksize & 1)) {
  85004. max_rice_partition_order++;
  85005. blocksize >>= 1;
  85006. }
  85007. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  85008. }
  85009. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  85010. {
  85011. unsigned max_rice_partition_order = limit;
  85012. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85013. max_rice_partition_order--;
  85014. FLAC__ASSERT(
  85015. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85016. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85017. );
  85018. return max_rice_partition_order;
  85019. }
  85020. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85021. {
  85022. FLAC__ASSERT(0 != object);
  85023. object->parameters = 0;
  85024. object->raw_bits = 0;
  85025. object->capacity_by_order = 0;
  85026. }
  85027. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85028. {
  85029. FLAC__ASSERT(0 != object);
  85030. if(0 != object->parameters)
  85031. free(object->parameters);
  85032. if(0 != object->raw_bits)
  85033. free(object->raw_bits);
  85034. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85035. }
  85036. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85037. {
  85038. FLAC__ASSERT(0 != object);
  85039. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85040. if(object->capacity_by_order < max_partition_order) {
  85041. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85042. return false;
  85043. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85044. return false;
  85045. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85046. object->capacity_by_order = max_partition_order;
  85047. }
  85048. return true;
  85049. }
  85050. #endif
  85051. /*** End of inlined file: format.c ***/
  85052. /*** Start of inlined file: lpc_flac.c ***/
  85053. /*** Start of inlined file: juce_FlacHeader.h ***/
  85054. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85055. // tasks..
  85056. #define VERSION "1.2.1"
  85057. #define FLAC__NO_DLL 1
  85058. #if JUCE_MSVC
  85059. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85060. #endif
  85061. #if JUCE_MAC
  85062. #define FLAC__SYS_DARWIN 1
  85063. #endif
  85064. /*** End of inlined file: juce_FlacHeader.h ***/
  85065. #if JUCE_USE_FLAC
  85066. #if HAVE_CONFIG_H
  85067. # include <config.h>
  85068. #endif
  85069. #include <math.h>
  85070. /*** Start of inlined file: lpc.h ***/
  85071. #ifndef FLAC__PRIVATE__LPC_H
  85072. #define FLAC__PRIVATE__LPC_H
  85073. #ifdef HAVE_CONFIG_H
  85074. #include <config.h>
  85075. #endif
  85076. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85077. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85078. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85079. #ifndef FLAC__NO_ASM
  85080. # ifdef FLAC__CPU_IA32
  85081. # ifdef FLAC__HAS_NASM
  85082. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85083. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85084. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85085. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85086. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85087. # endif
  85088. # endif
  85089. #endif
  85090. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85091. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85092. 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[]);
  85093. 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[]);
  85094. #ifndef FLAC__NO_ASM
  85095. # ifdef FLAC__CPU_IA32
  85096. # ifdef FLAC__HAS_NASM
  85097. 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[]);
  85098. 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[]);
  85099. # endif
  85100. # endif
  85101. #endif
  85102. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85103. 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[]);
  85104. 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[]);
  85105. #ifndef FLAC__NO_ASM
  85106. # ifdef FLAC__CPU_IA32
  85107. # ifdef FLAC__HAS_NASM
  85108. 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[]);
  85109. 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[]);
  85110. # endif /* FLAC__HAS_NASM */
  85111. # elif defined FLAC__CPU_PPC
  85112. 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[]);
  85113. 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[]);
  85114. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85115. #endif /* FLAC__NO_ASM */
  85116. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85117. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85118. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85119. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85120. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85121. #endif
  85122. /*** End of inlined file: lpc.h ***/
  85123. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85124. #include <stdio.h>
  85125. #endif
  85126. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85127. #ifndef M_LN2
  85128. #define M_LN2 0.69314718055994530942
  85129. #endif
  85130. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85131. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85132. {
  85133. unsigned i;
  85134. for(i = 0; i < data_len; i++)
  85135. out[i] = in[i] * window[i];
  85136. }
  85137. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85138. {
  85139. #if 0
  85140. FLAC__real d;
  85141. unsigned i;
  85142. FLAC__ASSERT(lag > 0);
  85143. FLAC__ASSERT(lag <= data_len);
  85144. while(lag--) {
  85145. for(i = lag, d = 0.0; i < data_len; i++)
  85146. d += data[i] * data[i - lag];
  85147. autoc[lag] = d;
  85148. }
  85149. #endif
  85150. FLAC__real d;
  85151. unsigned sample, coeff;
  85152. const unsigned limit = data_len - lag;
  85153. FLAC__ASSERT(lag > 0);
  85154. FLAC__ASSERT(lag <= data_len);
  85155. for(coeff = 0; coeff < lag; coeff++)
  85156. autoc[coeff] = 0.0;
  85157. for(sample = 0; sample <= limit; sample++) {
  85158. d = data[sample];
  85159. for(coeff = 0; coeff < lag; coeff++)
  85160. autoc[coeff] += d * data[sample+coeff];
  85161. }
  85162. for(; sample < data_len; sample++) {
  85163. d = data[sample];
  85164. for(coeff = 0; coeff < data_len - sample; coeff++)
  85165. autoc[coeff] += d * data[sample+coeff];
  85166. }
  85167. }
  85168. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85169. {
  85170. unsigned i, j;
  85171. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85172. FLAC__ASSERT(0 != max_order);
  85173. FLAC__ASSERT(0 < *max_order);
  85174. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85175. FLAC__ASSERT(autoc[0] != 0.0);
  85176. err = autoc[0];
  85177. for(i = 0; i < *max_order; i++) {
  85178. r = -autoc[i+1];
  85179. for(j = 0; j < i; j++)
  85180. r -= lpc[j] * autoc[i-j];
  85181. ref[i] = (r/=err);
  85182. lpc[i]=r;
  85183. for(j = 0; j < (i>>1); j++) {
  85184. FLAC__double tmp = lpc[j];
  85185. lpc[j] += r * lpc[i-1-j];
  85186. lpc[i-1-j] += r * tmp;
  85187. }
  85188. if(i & 1)
  85189. lpc[j] += lpc[j] * r;
  85190. err *= (1.0 - r * r);
  85191. for(j = 0; j <= i; j++)
  85192. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85193. error[i] = err;
  85194. if(err == 0.0) {
  85195. *max_order = i+1;
  85196. return;
  85197. }
  85198. }
  85199. }
  85200. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85201. {
  85202. unsigned i;
  85203. FLAC__double cmax;
  85204. FLAC__int32 qmax, qmin;
  85205. FLAC__ASSERT(precision > 0);
  85206. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85207. precision--;
  85208. qmax = 1 << precision;
  85209. qmin = -qmax;
  85210. qmax--;
  85211. cmax = 0.0;
  85212. for(i = 0; i < order; i++) {
  85213. const FLAC__double d = fabs(lp_coeff[i]);
  85214. if(d > cmax)
  85215. cmax = d;
  85216. }
  85217. if(cmax <= 0.0) {
  85218. return 2;
  85219. }
  85220. else {
  85221. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85222. const int min_shiftlimit = -max_shiftlimit - 1;
  85223. int log2cmax;
  85224. (void)frexp(cmax, &log2cmax);
  85225. log2cmax--;
  85226. *shift = (int)precision - log2cmax - 1;
  85227. if(*shift > max_shiftlimit)
  85228. *shift = max_shiftlimit;
  85229. else if(*shift < min_shiftlimit)
  85230. return 1;
  85231. }
  85232. if(*shift >= 0) {
  85233. FLAC__double error = 0.0;
  85234. FLAC__int32 q;
  85235. for(i = 0; i < order; i++) {
  85236. error += lp_coeff[i] * (1 << *shift);
  85237. #if 1 /* unfortunately lround() is C99 */
  85238. if(error >= 0.0)
  85239. q = (FLAC__int32)(error + 0.5);
  85240. else
  85241. q = (FLAC__int32)(error - 0.5);
  85242. #else
  85243. q = lround(error);
  85244. #endif
  85245. #ifdef FLAC__OVERFLOW_DETECT
  85246. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85247. 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]);
  85248. else if(q < qmin)
  85249. 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]);
  85250. #endif
  85251. if(q > qmax)
  85252. q = qmax;
  85253. else if(q < qmin)
  85254. q = qmin;
  85255. error -= q;
  85256. qlp_coeff[i] = q;
  85257. }
  85258. }
  85259. else {
  85260. const int nshift = -(*shift);
  85261. FLAC__double error = 0.0;
  85262. FLAC__int32 q;
  85263. #ifdef DEBUG
  85264. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85265. #endif
  85266. for(i = 0; i < order; i++) {
  85267. error += lp_coeff[i] / (1 << nshift);
  85268. #if 1 /* unfortunately lround() is C99 */
  85269. if(error >= 0.0)
  85270. q = (FLAC__int32)(error + 0.5);
  85271. else
  85272. q = (FLAC__int32)(error - 0.5);
  85273. #else
  85274. q = lround(error);
  85275. #endif
  85276. #ifdef FLAC__OVERFLOW_DETECT
  85277. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85278. 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]);
  85279. else if(q < qmin)
  85280. 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]);
  85281. #endif
  85282. if(q > qmax)
  85283. q = qmax;
  85284. else if(q < qmin)
  85285. q = qmin;
  85286. error -= q;
  85287. qlp_coeff[i] = q;
  85288. }
  85289. *shift = 0;
  85290. }
  85291. return 0;
  85292. }
  85293. 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[])
  85294. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85295. {
  85296. FLAC__int64 sumo;
  85297. unsigned i, j;
  85298. FLAC__int32 sum;
  85299. const FLAC__int32 *history;
  85300. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85301. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85302. for(i=0;i<order;i++)
  85303. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85304. fprintf(stderr,"\n");
  85305. #endif
  85306. FLAC__ASSERT(order > 0);
  85307. for(i = 0; i < data_len; i++) {
  85308. sumo = 0;
  85309. sum = 0;
  85310. history = data;
  85311. for(j = 0; j < order; j++) {
  85312. sum += qlp_coeff[j] * (*(--history));
  85313. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85314. #if defined _MSC_VER
  85315. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85316. 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);
  85317. #else
  85318. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85319. 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);
  85320. #endif
  85321. }
  85322. *(residual++) = *(data++) - (sum >> lp_quantization);
  85323. }
  85324. }
  85325. #else /* fully unrolled version for normal use */
  85326. {
  85327. int i;
  85328. FLAC__int32 sum;
  85329. FLAC__ASSERT(order > 0);
  85330. FLAC__ASSERT(order <= 32);
  85331. if(order <= 12) {
  85332. if(order > 8) {
  85333. if(order > 10) {
  85334. if(order == 12) {
  85335. for(i = 0; i < (int)data_len; i++) {
  85336. sum = 0;
  85337. sum += qlp_coeff[11] * data[i-12];
  85338. sum += qlp_coeff[10] * data[i-11];
  85339. sum += qlp_coeff[9] * data[i-10];
  85340. sum += qlp_coeff[8] * data[i-9];
  85341. sum += qlp_coeff[7] * data[i-8];
  85342. sum += qlp_coeff[6] * data[i-7];
  85343. sum += qlp_coeff[5] * data[i-6];
  85344. sum += qlp_coeff[4] * data[i-5];
  85345. sum += qlp_coeff[3] * data[i-4];
  85346. sum += qlp_coeff[2] * data[i-3];
  85347. sum += qlp_coeff[1] * data[i-2];
  85348. sum += qlp_coeff[0] * data[i-1];
  85349. residual[i] = data[i] - (sum >> lp_quantization);
  85350. }
  85351. }
  85352. else { /* order == 11 */
  85353. for(i = 0; i < (int)data_len; i++) {
  85354. sum = 0;
  85355. sum += qlp_coeff[10] * data[i-11];
  85356. sum += qlp_coeff[9] * data[i-10];
  85357. sum += qlp_coeff[8] * data[i-9];
  85358. sum += qlp_coeff[7] * data[i-8];
  85359. sum += qlp_coeff[6] * data[i-7];
  85360. sum += qlp_coeff[5] * data[i-6];
  85361. sum += qlp_coeff[4] * data[i-5];
  85362. sum += qlp_coeff[3] * data[i-4];
  85363. sum += qlp_coeff[2] * data[i-3];
  85364. sum += qlp_coeff[1] * data[i-2];
  85365. sum += qlp_coeff[0] * data[i-1];
  85366. residual[i] = data[i] - (sum >> lp_quantization);
  85367. }
  85368. }
  85369. }
  85370. else {
  85371. if(order == 10) {
  85372. for(i = 0; i < (int)data_len; i++) {
  85373. sum = 0;
  85374. sum += qlp_coeff[9] * data[i-10];
  85375. sum += qlp_coeff[8] * data[i-9];
  85376. sum += qlp_coeff[7] * data[i-8];
  85377. sum += qlp_coeff[6] * data[i-7];
  85378. sum += qlp_coeff[5] * data[i-6];
  85379. sum += qlp_coeff[4] * data[i-5];
  85380. sum += qlp_coeff[3] * data[i-4];
  85381. sum += qlp_coeff[2] * data[i-3];
  85382. sum += qlp_coeff[1] * data[i-2];
  85383. sum += qlp_coeff[0] * data[i-1];
  85384. residual[i] = data[i] - (sum >> lp_quantization);
  85385. }
  85386. }
  85387. else { /* order == 9 */
  85388. for(i = 0; i < (int)data_len; i++) {
  85389. sum = 0;
  85390. sum += qlp_coeff[8] * data[i-9];
  85391. sum += qlp_coeff[7] * data[i-8];
  85392. sum += qlp_coeff[6] * data[i-7];
  85393. sum += qlp_coeff[5] * data[i-6];
  85394. sum += qlp_coeff[4] * data[i-5];
  85395. sum += qlp_coeff[3] * data[i-4];
  85396. sum += qlp_coeff[2] * data[i-3];
  85397. sum += qlp_coeff[1] * data[i-2];
  85398. sum += qlp_coeff[0] * data[i-1];
  85399. residual[i] = data[i] - (sum >> lp_quantization);
  85400. }
  85401. }
  85402. }
  85403. }
  85404. else if(order > 4) {
  85405. if(order > 6) {
  85406. if(order == 8) {
  85407. for(i = 0; i < (int)data_len; i++) {
  85408. sum = 0;
  85409. sum += qlp_coeff[7] * data[i-8];
  85410. sum += qlp_coeff[6] * data[i-7];
  85411. sum += qlp_coeff[5] * data[i-6];
  85412. sum += qlp_coeff[4] * data[i-5];
  85413. sum += qlp_coeff[3] * data[i-4];
  85414. sum += qlp_coeff[2] * data[i-3];
  85415. sum += qlp_coeff[1] * data[i-2];
  85416. sum += qlp_coeff[0] * data[i-1];
  85417. residual[i] = data[i] - (sum >> lp_quantization);
  85418. }
  85419. }
  85420. else { /* order == 7 */
  85421. for(i = 0; i < (int)data_len; i++) {
  85422. sum = 0;
  85423. sum += qlp_coeff[6] * data[i-7];
  85424. sum += qlp_coeff[5] * data[i-6];
  85425. sum += qlp_coeff[4] * data[i-5];
  85426. sum += qlp_coeff[3] * data[i-4];
  85427. sum += qlp_coeff[2] * data[i-3];
  85428. sum += qlp_coeff[1] * data[i-2];
  85429. sum += qlp_coeff[0] * data[i-1];
  85430. residual[i] = data[i] - (sum >> lp_quantization);
  85431. }
  85432. }
  85433. }
  85434. else {
  85435. if(order == 6) {
  85436. for(i = 0; i < (int)data_len; i++) {
  85437. sum = 0;
  85438. sum += qlp_coeff[5] * data[i-6];
  85439. sum += qlp_coeff[4] * data[i-5];
  85440. sum += qlp_coeff[3] * data[i-4];
  85441. sum += qlp_coeff[2] * data[i-3];
  85442. sum += qlp_coeff[1] * data[i-2];
  85443. sum += qlp_coeff[0] * data[i-1];
  85444. residual[i] = data[i] - (sum >> lp_quantization);
  85445. }
  85446. }
  85447. else { /* order == 5 */
  85448. for(i = 0; i < (int)data_len; i++) {
  85449. sum = 0;
  85450. sum += qlp_coeff[4] * data[i-5];
  85451. sum += qlp_coeff[3] * data[i-4];
  85452. sum += qlp_coeff[2] * data[i-3];
  85453. sum += qlp_coeff[1] * data[i-2];
  85454. sum += qlp_coeff[0] * data[i-1];
  85455. residual[i] = data[i] - (sum >> lp_quantization);
  85456. }
  85457. }
  85458. }
  85459. }
  85460. else {
  85461. if(order > 2) {
  85462. if(order == 4) {
  85463. for(i = 0; i < (int)data_len; i++) {
  85464. sum = 0;
  85465. sum += qlp_coeff[3] * data[i-4];
  85466. sum += qlp_coeff[2] * data[i-3];
  85467. sum += qlp_coeff[1] * data[i-2];
  85468. sum += qlp_coeff[0] * data[i-1];
  85469. residual[i] = data[i] - (sum >> lp_quantization);
  85470. }
  85471. }
  85472. else { /* order == 3 */
  85473. for(i = 0; i < (int)data_len; i++) {
  85474. sum = 0;
  85475. sum += qlp_coeff[2] * data[i-3];
  85476. sum += qlp_coeff[1] * data[i-2];
  85477. sum += qlp_coeff[0] * data[i-1];
  85478. residual[i] = data[i] - (sum >> lp_quantization);
  85479. }
  85480. }
  85481. }
  85482. else {
  85483. if(order == 2) {
  85484. for(i = 0; i < (int)data_len; i++) {
  85485. sum = 0;
  85486. sum += qlp_coeff[1] * data[i-2];
  85487. sum += qlp_coeff[0] * data[i-1];
  85488. residual[i] = data[i] - (sum >> lp_quantization);
  85489. }
  85490. }
  85491. else { /* order == 1 */
  85492. for(i = 0; i < (int)data_len; i++)
  85493. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85494. }
  85495. }
  85496. }
  85497. }
  85498. else { /* order > 12 */
  85499. for(i = 0; i < (int)data_len; i++) {
  85500. sum = 0;
  85501. switch(order) {
  85502. case 32: sum += qlp_coeff[31] * data[i-32];
  85503. case 31: sum += qlp_coeff[30] * data[i-31];
  85504. case 30: sum += qlp_coeff[29] * data[i-30];
  85505. case 29: sum += qlp_coeff[28] * data[i-29];
  85506. case 28: sum += qlp_coeff[27] * data[i-28];
  85507. case 27: sum += qlp_coeff[26] * data[i-27];
  85508. case 26: sum += qlp_coeff[25] * data[i-26];
  85509. case 25: sum += qlp_coeff[24] * data[i-25];
  85510. case 24: sum += qlp_coeff[23] * data[i-24];
  85511. case 23: sum += qlp_coeff[22] * data[i-23];
  85512. case 22: sum += qlp_coeff[21] * data[i-22];
  85513. case 21: sum += qlp_coeff[20] * data[i-21];
  85514. case 20: sum += qlp_coeff[19] * data[i-20];
  85515. case 19: sum += qlp_coeff[18] * data[i-19];
  85516. case 18: sum += qlp_coeff[17] * data[i-18];
  85517. case 17: sum += qlp_coeff[16] * data[i-17];
  85518. case 16: sum += qlp_coeff[15] * data[i-16];
  85519. case 15: sum += qlp_coeff[14] * data[i-15];
  85520. case 14: sum += qlp_coeff[13] * data[i-14];
  85521. case 13: sum += qlp_coeff[12] * data[i-13];
  85522. sum += qlp_coeff[11] * data[i-12];
  85523. sum += qlp_coeff[10] * data[i-11];
  85524. sum += qlp_coeff[ 9] * data[i-10];
  85525. sum += qlp_coeff[ 8] * data[i- 9];
  85526. sum += qlp_coeff[ 7] * data[i- 8];
  85527. sum += qlp_coeff[ 6] * data[i- 7];
  85528. sum += qlp_coeff[ 5] * data[i- 6];
  85529. sum += qlp_coeff[ 4] * data[i- 5];
  85530. sum += qlp_coeff[ 3] * data[i- 4];
  85531. sum += qlp_coeff[ 2] * data[i- 3];
  85532. sum += qlp_coeff[ 1] * data[i- 2];
  85533. sum += qlp_coeff[ 0] * data[i- 1];
  85534. }
  85535. residual[i] = data[i] - (sum >> lp_quantization);
  85536. }
  85537. }
  85538. }
  85539. #endif
  85540. 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[])
  85541. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85542. {
  85543. unsigned i, j;
  85544. FLAC__int64 sum;
  85545. const FLAC__int32 *history;
  85546. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85547. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85548. for(i=0;i<order;i++)
  85549. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85550. fprintf(stderr,"\n");
  85551. #endif
  85552. FLAC__ASSERT(order > 0);
  85553. for(i = 0; i < data_len; i++) {
  85554. sum = 0;
  85555. history = data;
  85556. for(j = 0; j < order; j++)
  85557. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85558. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85559. #if defined _MSC_VER
  85560. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85561. #else
  85562. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85563. #endif
  85564. break;
  85565. }
  85566. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85567. #if defined _MSC_VER
  85568. 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));
  85569. #else
  85570. 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)));
  85571. #endif
  85572. break;
  85573. }
  85574. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85575. }
  85576. }
  85577. #else /* fully unrolled version for normal use */
  85578. {
  85579. int i;
  85580. FLAC__int64 sum;
  85581. FLAC__ASSERT(order > 0);
  85582. FLAC__ASSERT(order <= 32);
  85583. if(order <= 12) {
  85584. if(order > 8) {
  85585. if(order > 10) {
  85586. if(order == 12) {
  85587. for(i = 0; i < (int)data_len; i++) {
  85588. sum = 0;
  85589. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85590. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85591. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85592. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85593. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85594. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85595. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85596. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85597. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85598. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85599. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85600. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85601. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85602. }
  85603. }
  85604. else { /* order == 11 */
  85605. for(i = 0; i < (int)data_len; i++) {
  85606. sum = 0;
  85607. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85608. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85609. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85610. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85611. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85612. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85613. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85614. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85615. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85616. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85617. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85618. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85619. }
  85620. }
  85621. }
  85622. else {
  85623. if(order == 10) {
  85624. for(i = 0; i < (int)data_len; i++) {
  85625. sum = 0;
  85626. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85627. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85628. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85629. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85630. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85631. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85632. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85633. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85634. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85635. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85636. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85637. }
  85638. }
  85639. else { /* order == 9 */
  85640. for(i = 0; i < (int)data_len; i++) {
  85641. sum = 0;
  85642. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85643. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85644. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85645. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85646. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85647. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85648. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85649. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85650. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85651. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85652. }
  85653. }
  85654. }
  85655. }
  85656. else if(order > 4) {
  85657. if(order > 6) {
  85658. if(order == 8) {
  85659. for(i = 0; i < (int)data_len; i++) {
  85660. sum = 0;
  85661. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85662. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85663. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85664. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85665. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85666. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85667. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85668. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85669. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85670. }
  85671. }
  85672. else { /* order == 7 */
  85673. for(i = 0; i < (int)data_len; i++) {
  85674. sum = 0;
  85675. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85676. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85677. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85678. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85679. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85680. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85681. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85682. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85683. }
  85684. }
  85685. }
  85686. else {
  85687. if(order == 6) {
  85688. for(i = 0; i < (int)data_len; i++) {
  85689. sum = 0;
  85690. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85691. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85692. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85693. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85694. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85695. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85696. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85697. }
  85698. }
  85699. else { /* order == 5 */
  85700. for(i = 0; i < (int)data_len; i++) {
  85701. sum = 0;
  85702. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85703. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85704. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85705. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85706. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85707. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85708. }
  85709. }
  85710. }
  85711. }
  85712. else {
  85713. if(order > 2) {
  85714. if(order == 4) {
  85715. for(i = 0; i < (int)data_len; i++) {
  85716. sum = 0;
  85717. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85718. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85719. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85720. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85721. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85722. }
  85723. }
  85724. else { /* order == 3 */
  85725. for(i = 0; i < (int)data_len; i++) {
  85726. sum = 0;
  85727. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85728. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85729. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85730. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85731. }
  85732. }
  85733. }
  85734. else {
  85735. if(order == 2) {
  85736. for(i = 0; i < (int)data_len; i++) {
  85737. sum = 0;
  85738. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85739. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85740. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85741. }
  85742. }
  85743. else { /* order == 1 */
  85744. for(i = 0; i < (int)data_len; i++)
  85745. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85746. }
  85747. }
  85748. }
  85749. }
  85750. else { /* order > 12 */
  85751. for(i = 0; i < (int)data_len; i++) {
  85752. sum = 0;
  85753. switch(order) {
  85754. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85755. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85756. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85757. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85758. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85759. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85760. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85761. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85762. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85763. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85764. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85765. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85766. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85767. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85768. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85769. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85770. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85771. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85772. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85773. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85774. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85775. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85776. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85777. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85778. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85779. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85780. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85781. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85782. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85783. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85784. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85785. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85786. }
  85787. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85788. }
  85789. }
  85790. }
  85791. #endif
  85792. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85793. 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[])
  85794. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85795. {
  85796. FLAC__int64 sumo;
  85797. unsigned i, j;
  85798. FLAC__int32 sum;
  85799. const FLAC__int32 *r = residual, *history;
  85800. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85801. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85802. for(i=0;i<order;i++)
  85803. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85804. fprintf(stderr,"\n");
  85805. #endif
  85806. FLAC__ASSERT(order > 0);
  85807. for(i = 0; i < data_len; i++) {
  85808. sumo = 0;
  85809. sum = 0;
  85810. history = data;
  85811. for(j = 0; j < order; j++) {
  85812. sum += qlp_coeff[j] * (*(--history));
  85813. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85814. #if defined _MSC_VER
  85815. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85816. 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);
  85817. #else
  85818. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85819. 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);
  85820. #endif
  85821. }
  85822. *(data++) = *(r++) + (sum >> lp_quantization);
  85823. }
  85824. }
  85825. #else /* fully unrolled version for normal use */
  85826. {
  85827. int i;
  85828. FLAC__int32 sum;
  85829. FLAC__ASSERT(order > 0);
  85830. FLAC__ASSERT(order <= 32);
  85831. if(order <= 12) {
  85832. if(order > 8) {
  85833. if(order > 10) {
  85834. if(order == 12) {
  85835. for(i = 0; i < (int)data_len; i++) {
  85836. sum = 0;
  85837. sum += qlp_coeff[11] * data[i-12];
  85838. sum += qlp_coeff[10] * data[i-11];
  85839. sum += qlp_coeff[9] * data[i-10];
  85840. sum += qlp_coeff[8] * data[i-9];
  85841. sum += qlp_coeff[7] * data[i-8];
  85842. sum += qlp_coeff[6] * data[i-7];
  85843. sum += qlp_coeff[5] * data[i-6];
  85844. sum += qlp_coeff[4] * data[i-5];
  85845. sum += qlp_coeff[3] * data[i-4];
  85846. sum += qlp_coeff[2] * data[i-3];
  85847. sum += qlp_coeff[1] * data[i-2];
  85848. sum += qlp_coeff[0] * data[i-1];
  85849. data[i] = residual[i] + (sum >> lp_quantization);
  85850. }
  85851. }
  85852. else { /* order == 11 */
  85853. for(i = 0; i < (int)data_len; i++) {
  85854. sum = 0;
  85855. sum += qlp_coeff[10] * data[i-11];
  85856. sum += qlp_coeff[9] * data[i-10];
  85857. sum += qlp_coeff[8] * data[i-9];
  85858. sum += qlp_coeff[7] * data[i-8];
  85859. sum += qlp_coeff[6] * data[i-7];
  85860. sum += qlp_coeff[5] * data[i-6];
  85861. sum += qlp_coeff[4] * data[i-5];
  85862. sum += qlp_coeff[3] * data[i-4];
  85863. sum += qlp_coeff[2] * data[i-3];
  85864. sum += qlp_coeff[1] * data[i-2];
  85865. sum += qlp_coeff[0] * data[i-1];
  85866. data[i] = residual[i] + (sum >> lp_quantization);
  85867. }
  85868. }
  85869. }
  85870. else {
  85871. if(order == 10) {
  85872. for(i = 0; i < (int)data_len; i++) {
  85873. sum = 0;
  85874. sum += qlp_coeff[9] * data[i-10];
  85875. sum += qlp_coeff[8] * data[i-9];
  85876. sum += qlp_coeff[7] * data[i-8];
  85877. sum += qlp_coeff[6] * data[i-7];
  85878. sum += qlp_coeff[5] * data[i-6];
  85879. sum += qlp_coeff[4] * data[i-5];
  85880. sum += qlp_coeff[3] * data[i-4];
  85881. sum += qlp_coeff[2] * data[i-3];
  85882. sum += qlp_coeff[1] * data[i-2];
  85883. sum += qlp_coeff[0] * data[i-1];
  85884. data[i] = residual[i] + (sum >> lp_quantization);
  85885. }
  85886. }
  85887. else { /* order == 9 */
  85888. for(i = 0; i < (int)data_len; i++) {
  85889. sum = 0;
  85890. sum += qlp_coeff[8] * data[i-9];
  85891. sum += qlp_coeff[7] * data[i-8];
  85892. sum += qlp_coeff[6] * data[i-7];
  85893. sum += qlp_coeff[5] * data[i-6];
  85894. sum += qlp_coeff[4] * data[i-5];
  85895. sum += qlp_coeff[3] * data[i-4];
  85896. sum += qlp_coeff[2] * data[i-3];
  85897. sum += qlp_coeff[1] * data[i-2];
  85898. sum += qlp_coeff[0] * data[i-1];
  85899. data[i] = residual[i] + (sum >> lp_quantization);
  85900. }
  85901. }
  85902. }
  85903. }
  85904. else if(order > 4) {
  85905. if(order > 6) {
  85906. if(order == 8) {
  85907. for(i = 0; i < (int)data_len; i++) {
  85908. sum = 0;
  85909. sum += qlp_coeff[7] * data[i-8];
  85910. sum += qlp_coeff[6] * data[i-7];
  85911. sum += qlp_coeff[5] * data[i-6];
  85912. sum += qlp_coeff[4] * data[i-5];
  85913. sum += qlp_coeff[3] * data[i-4];
  85914. sum += qlp_coeff[2] * data[i-3];
  85915. sum += qlp_coeff[1] * data[i-2];
  85916. sum += qlp_coeff[0] * data[i-1];
  85917. data[i] = residual[i] + (sum >> lp_quantization);
  85918. }
  85919. }
  85920. else { /* order == 7 */
  85921. for(i = 0; i < (int)data_len; i++) {
  85922. sum = 0;
  85923. sum += qlp_coeff[6] * data[i-7];
  85924. sum += qlp_coeff[5] * data[i-6];
  85925. sum += qlp_coeff[4] * data[i-5];
  85926. sum += qlp_coeff[3] * data[i-4];
  85927. sum += qlp_coeff[2] * data[i-3];
  85928. sum += qlp_coeff[1] * data[i-2];
  85929. sum += qlp_coeff[0] * data[i-1];
  85930. data[i] = residual[i] + (sum >> lp_quantization);
  85931. }
  85932. }
  85933. }
  85934. else {
  85935. if(order == 6) {
  85936. for(i = 0; i < (int)data_len; i++) {
  85937. sum = 0;
  85938. sum += qlp_coeff[5] * data[i-6];
  85939. sum += qlp_coeff[4] * data[i-5];
  85940. sum += qlp_coeff[3] * data[i-4];
  85941. sum += qlp_coeff[2] * data[i-3];
  85942. sum += qlp_coeff[1] * data[i-2];
  85943. sum += qlp_coeff[0] * data[i-1];
  85944. data[i] = residual[i] + (sum >> lp_quantization);
  85945. }
  85946. }
  85947. else { /* order == 5 */
  85948. for(i = 0; i < (int)data_len; i++) {
  85949. sum = 0;
  85950. sum += qlp_coeff[4] * data[i-5];
  85951. sum += qlp_coeff[3] * data[i-4];
  85952. sum += qlp_coeff[2] * data[i-3];
  85953. sum += qlp_coeff[1] * data[i-2];
  85954. sum += qlp_coeff[0] * data[i-1];
  85955. data[i] = residual[i] + (sum >> lp_quantization);
  85956. }
  85957. }
  85958. }
  85959. }
  85960. else {
  85961. if(order > 2) {
  85962. if(order == 4) {
  85963. for(i = 0; i < (int)data_len; i++) {
  85964. sum = 0;
  85965. sum += qlp_coeff[3] * data[i-4];
  85966. sum += qlp_coeff[2] * data[i-3];
  85967. sum += qlp_coeff[1] * data[i-2];
  85968. sum += qlp_coeff[0] * data[i-1];
  85969. data[i] = residual[i] + (sum >> lp_quantization);
  85970. }
  85971. }
  85972. else { /* order == 3 */
  85973. for(i = 0; i < (int)data_len; i++) {
  85974. sum = 0;
  85975. sum += qlp_coeff[2] * data[i-3];
  85976. sum += qlp_coeff[1] * data[i-2];
  85977. sum += qlp_coeff[0] * data[i-1];
  85978. data[i] = residual[i] + (sum >> lp_quantization);
  85979. }
  85980. }
  85981. }
  85982. else {
  85983. if(order == 2) {
  85984. for(i = 0; i < (int)data_len; i++) {
  85985. sum = 0;
  85986. sum += qlp_coeff[1] * data[i-2];
  85987. sum += qlp_coeff[0] * data[i-1];
  85988. data[i] = residual[i] + (sum >> lp_quantization);
  85989. }
  85990. }
  85991. else { /* order == 1 */
  85992. for(i = 0; i < (int)data_len; i++)
  85993. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85994. }
  85995. }
  85996. }
  85997. }
  85998. else { /* order > 12 */
  85999. for(i = 0; i < (int)data_len; i++) {
  86000. sum = 0;
  86001. switch(order) {
  86002. case 32: sum += qlp_coeff[31] * data[i-32];
  86003. case 31: sum += qlp_coeff[30] * data[i-31];
  86004. case 30: sum += qlp_coeff[29] * data[i-30];
  86005. case 29: sum += qlp_coeff[28] * data[i-29];
  86006. case 28: sum += qlp_coeff[27] * data[i-28];
  86007. case 27: sum += qlp_coeff[26] * data[i-27];
  86008. case 26: sum += qlp_coeff[25] * data[i-26];
  86009. case 25: sum += qlp_coeff[24] * data[i-25];
  86010. case 24: sum += qlp_coeff[23] * data[i-24];
  86011. case 23: sum += qlp_coeff[22] * data[i-23];
  86012. case 22: sum += qlp_coeff[21] * data[i-22];
  86013. case 21: sum += qlp_coeff[20] * data[i-21];
  86014. case 20: sum += qlp_coeff[19] * data[i-20];
  86015. case 19: sum += qlp_coeff[18] * data[i-19];
  86016. case 18: sum += qlp_coeff[17] * data[i-18];
  86017. case 17: sum += qlp_coeff[16] * data[i-17];
  86018. case 16: sum += qlp_coeff[15] * data[i-16];
  86019. case 15: sum += qlp_coeff[14] * data[i-15];
  86020. case 14: sum += qlp_coeff[13] * data[i-14];
  86021. case 13: sum += qlp_coeff[12] * data[i-13];
  86022. sum += qlp_coeff[11] * data[i-12];
  86023. sum += qlp_coeff[10] * data[i-11];
  86024. sum += qlp_coeff[ 9] * data[i-10];
  86025. sum += qlp_coeff[ 8] * data[i- 9];
  86026. sum += qlp_coeff[ 7] * data[i- 8];
  86027. sum += qlp_coeff[ 6] * data[i- 7];
  86028. sum += qlp_coeff[ 5] * data[i- 6];
  86029. sum += qlp_coeff[ 4] * data[i- 5];
  86030. sum += qlp_coeff[ 3] * data[i- 4];
  86031. sum += qlp_coeff[ 2] * data[i- 3];
  86032. sum += qlp_coeff[ 1] * data[i- 2];
  86033. sum += qlp_coeff[ 0] * data[i- 1];
  86034. }
  86035. data[i] = residual[i] + (sum >> lp_quantization);
  86036. }
  86037. }
  86038. }
  86039. #endif
  86040. 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[])
  86041. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86042. {
  86043. unsigned i, j;
  86044. FLAC__int64 sum;
  86045. const FLAC__int32 *r = residual, *history;
  86046. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86047. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86048. for(i=0;i<order;i++)
  86049. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86050. fprintf(stderr,"\n");
  86051. #endif
  86052. FLAC__ASSERT(order > 0);
  86053. for(i = 0; i < data_len; i++) {
  86054. sum = 0;
  86055. history = data;
  86056. for(j = 0; j < order; j++)
  86057. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86058. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86059. #ifdef _MSC_VER
  86060. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86061. #else
  86062. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86063. #endif
  86064. break;
  86065. }
  86066. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86067. #ifdef _MSC_VER
  86068. 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));
  86069. #else
  86070. 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)));
  86071. #endif
  86072. break;
  86073. }
  86074. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86075. }
  86076. }
  86077. #else /* fully unrolled version for normal use */
  86078. {
  86079. int i;
  86080. FLAC__int64 sum;
  86081. FLAC__ASSERT(order > 0);
  86082. FLAC__ASSERT(order <= 32);
  86083. if(order <= 12) {
  86084. if(order > 8) {
  86085. if(order > 10) {
  86086. if(order == 12) {
  86087. for(i = 0; i < (int)data_len; i++) {
  86088. sum = 0;
  86089. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86090. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86091. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86092. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86093. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86094. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86095. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86096. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86097. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86098. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86099. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86100. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86101. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86102. }
  86103. }
  86104. else { /* order == 11 */
  86105. for(i = 0; i < (int)data_len; i++) {
  86106. sum = 0;
  86107. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86108. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86109. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86110. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86111. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86112. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86113. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86114. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86115. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86116. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86117. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86118. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86119. }
  86120. }
  86121. }
  86122. else {
  86123. if(order == 10) {
  86124. for(i = 0; i < (int)data_len; i++) {
  86125. sum = 0;
  86126. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86127. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86128. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86129. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86130. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86131. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86132. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86133. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86134. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86135. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86136. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86137. }
  86138. }
  86139. else { /* order == 9 */
  86140. for(i = 0; i < (int)data_len; i++) {
  86141. sum = 0;
  86142. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86143. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86144. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86145. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86146. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86147. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86148. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86149. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86150. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86151. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86152. }
  86153. }
  86154. }
  86155. }
  86156. else if(order > 4) {
  86157. if(order > 6) {
  86158. if(order == 8) {
  86159. for(i = 0; i < (int)data_len; i++) {
  86160. sum = 0;
  86161. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86162. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86163. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86164. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86165. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86166. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86167. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86168. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86169. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86170. }
  86171. }
  86172. else { /* order == 7 */
  86173. for(i = 0; i < (int)data_len; i++) {
  86174. sum = 0;
  86175. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86176. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86177. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86178. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86179. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86180. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86181. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86182. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86183. }
  86184. }
  86185. }
  86186. else {
  86187. if(order == 6) {
  86188. for(i = 0; i < (int)data_len; i++) {
  86189. sum = 0;
  86190. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86191. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86192. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86193. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86194. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86195. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86196. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86197. }
  86198. }
  86199. else { /* order == 5 */
  86200. for(i = 0; i < (int)data_len; i++) {
  86201. sum = 0;
  86202. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86203. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86204. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86205. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86206. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86207. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86208. }
  86209. }
  86210. }
  86211. }
  86212. else {
  86213. if(order > 2) {
  86214. if(order == 4) {
  86215. for(i = 0; i < (int)data_len; i++) {
  86216. sum = 0;
  86217. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86218. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86219. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86220. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86221. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86222. }
  86223. }
  86224. else { /* order == 3 */
  86225. for(i = 0; i < (int)data_len; i++) {
  86226. sum = 0;
  86227. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86228. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86229. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86230. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86231. }
  86232. }
  86233. }
  86234. else {
  86235. if(order == 2) {
  86236. for(i = 0; i < (int)data_len; i++) {
  86237. sum = 0;
  86238. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86239. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86240. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86241. }
  86242. }
  86243. else { /* order == 1 */
  86244. for(i = 0; i < (int)data_len; i++)
  86245. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86246. }
  86247. }
  86248. }
  86249. }
  86250. else { /* order > 12 */
  86251. for(i = 0; i < (int)data_len; i++) {
  86252. sum = 0;
  86253. switch(order) {
  86254. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86255. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86256. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86257. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86258. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86259. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86260. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86261. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86262. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86263. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86264. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86265. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86266. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86267. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86268. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86269. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86270. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86271. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86272. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86273. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86274. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86275. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86276. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86277. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86278. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86279. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86280. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86281. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86282. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86283. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86284. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86285. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86286. }
  86287. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86288. }
  86289. }
  86290. }
  86291. #endif
  86292. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86293. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86294. {
  86295. FLAC__double error_scale;
  86296. FLAC__ASSERT(total_samples > 0);
  86297. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86298. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86299. }
  86300. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86301. {
  86302. if(lpc_error > 0.0) {
  86303. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86304. if(bps >= 0.0)
  86305. return bps;
  86306. else
  86307. return 0.0;
  86308. }
  86309. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86310. return 1e32;
  86311. }
  86312. else {
  86313. return 0.0;
  86314. }
  86315. }
  86316. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86317. {
  86318. 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 */
  86319. FLAC__double bits, best_bits, error_scale;
  86320. FLAC__ASSERT(max_order > 0);
  86321. FLAC__ASSERT(total_samples > 0);
  86322. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86323. best_index = 0;
  86324. best_bits = (unsigned)(-1);
  86325. for(index = 0, order = 1; index < max_order; index++, order++) {
  86326. 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);
  86327. if(bits < best_bits) {
  86328. best_index = index;
  86329. best_bits = bits;
  86330. }
  86331. }
  86332. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86333. }
  86334. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86335. #endif
  86336. /*** End of inlined file: lpc_flac.c ***/
  86337. /*** Start of inlined file: md5.c ***/
  86338. /*** Start of inlined file: juce_FlacHeader.h ***/
  86339. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86340. // tasks..
  86341. #define VERSION "1.2.1"
  86342. #define FLAC__NO_DLL 1
  86343. #if JUCE_MSVC
  86344. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86345. #endif
  86346. #if JUCE_MAC
  86347. #define FLAC__SYS_DARWIN 1
  86348. #endif
  86349. /*** End of inlined file: juce_FlacHeader.h ***/
  86350. #if JUCE_USE_FLAC
  86351. #if HAVE_CONFIG_H
  86352. # include <config.h>
  86353. #endif
  86354. #include <stdlib.h> /* for malloc() */
  86355. #include <string.h> /* for memcpy() */
  86356. /*** Start of inlined file: md5.h ***/
  86357. #ifndef FLAC__PRIVATE__MD5_H
  86358. #define FLAC__PRIVATE__MD5_H
  86359. typedef struct {
  86360. FLAC__uint32 in[16];
  86361. FLAC__uint32 buf[4];
  86362. FLAC__uint32 bytes[2];
  86363. FLAC__byte *internal_buf;
  86364. size_t capacity;
  86365. } FLAC__MD5Context;
  86366. void FLAC__MD5Init(FLAC__MD5Context *context);
  86367. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86368. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86369. #endif
  86370. /*** End of inlined file: md5.h ***/
  86371. #ifndef FLaC__INLINE
  86372. #define FLaC__INLINE
  86373. #endif
  86374. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86375. #define F2(x, y, z) F1(z, x, y)
  86376. #define F3(x, y, z) (x ^ y ^ z)
  86377. #define F4(x, y, z) (y ^ (x | ~z))
  86378. #define MD5STEP(f,w,x,y,z,in,s) \
  86379. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86380. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86381. {
  86382. register FLAC__uint32 a, b, c, d;
  86383. a = buf[0];
  86384. b = buf[1];
  86385. c = buf[2];
  86386. d = buf[3];
  86387. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86388. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86389. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86390. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86391. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86392. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86393. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86394. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86395. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86396. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86397. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86398. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86399. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86400. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86401. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86402. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86403. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86404. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86405. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86406. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86407. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86408. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86409. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86410. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86411. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86412. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86413. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86414. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86415. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86416. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86417. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86418. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86419. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86420. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86421. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86422. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86423. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86424. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86425. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86426. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86427. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86428. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86429. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86430. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86431. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86432. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86433. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86434. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86435. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86436. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86437. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86438. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86439. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86440. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86441. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86442. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86443. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86444. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86445. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86446. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86447. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86448. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86449. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86450. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86451. buf[0] += a;
  86452. buf[1] += b;
  86453. buf[2] += c;
  86454. buf[3] += d;
  86455. }
  86456. #if WORDS_BIGENDIAN
  86457. //@@@@@@ OPT: use bswap/intrinsics
  86458. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86459. {
  86460. register FLAC__uint32 x;
  86461. do {
  86462. x = *buf;
  86463. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86464. *buf++ = (x >> 16) | (x << 16);
  86465. } while (--words);
  86466. }
  86467. static void byteSwapX16(FLAC__uint32 *buf)
  86468. {
  86469. register FLAC__uint32 x;
  86470. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86471. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86472. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86473. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86474. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86475. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86476. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86477. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86478. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86479. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86480. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86481. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86482. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86483. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86484. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86485. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86486. }
  86487. #else
  86488. #define byteSwap(buf, words)
  86489. #define byteSwapX16(buf)
  86490. #endif
  86491. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86492. {
  86493. FLAC__uint32 t;
  86494. t = ctx->bytes[0];
  86495. if ((ctx->bytes[0] = t + len) < t)
  86496. ctx->bytes[1]++; /* Carry from low to high */
  86497. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86498. if (t > len) {
  86499. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86500. return;
  86501. }
  86502. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86503. byteSwapX16(ctx->in);
  86504. FLAC__MD5Transform(ctx->buf, ctx->in);
  86505. buf += t;
  86506. len -= t;
  86507. while (len >= 64) {
  86508. memcpy(ctx->in, buf, 64);
  86509. byteSwapX16(ctx->in);
  86510. FLAC__MD5Transform(ctx->buf, ctx->in);
  86511. buf += 64;
  86512. len -= 64;
  86513. }
  86514. memcpy(ctx->in, buf, len);
  86515. }
  86516. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86517. {
  86518. ctx->buf[0] = 0x67452301;
  86519. ctx->buf[1] = 0xefcdab89;
  86520. ctx->buf[2] = 0x98badcfe;
  86521. ctx->buf[3] = 0x10325476;
  86522. ctx->bytes[0] = 0;
  86523. ctx->bytes[1] = 0;
  86524. ctx->internal_buf = 0;
  86525. ctx->capacity = 0;
  86526. }
  86527. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86528. {
  86529. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86530. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86531. *p++ = 0x80;
  86532. count = 56 - 1 - count;
  86533. if (count < 0) { /* Padding forces an extra block */
  86534. memset(p, 0, count + 8);
  86535. byteSwapX16(ctx->in);
  86536. FLAC__MD5Transform(ctx->buf, ctx->in);
  86537. p = (FLAC__byte *)ctx->in;
  86538. count = 56;
  86539. }
  86540. memset(p, 0, count);
  86541. byteSwap(ctx->in, 14);
  86542. ctx->in[14] = ctx->bytes[0] << 3;
  86543. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86544. FLAC__MD5Transform(ctx->buf, ctx->in);
  86545. byteSwap(ctx->buf, 4);
  86546. memcpy(digest, ctx->buf, 16);
  86547. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86548. if(0 != ctx->internal_buf) {
  86549. free(ctx->internal_buf);
  86550. ctx->internal_buf = 0;
  86551. ctx->capacity = 0;
  86552. }
  86553. }
  86554. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86555. {
  86556. unsigned channel, sample;
  86557. register FLAC__int32 a_word;
  86558. register FLAC__byte *buf_ = buf;
  86559. #if WORDS_BIGENDIAN
  86560. #else
  86561. if(channels == 2 && bytes_per_sample == 2) {
  86562. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86563. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86564. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86565. *buf1_ = (FLAC__int16)signal[1][sample];
  86566. }
  86567. else if(channels == 1 && bytes_per_sample == 2) {
  86568. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86569. for(sample = 0; sample < samples; sample++)
  86570. *buf1_++ = (FLAC__int16)signal[0][sample];
  86571. }
  86572. else
  86573. #endif
  86574. if(bytes_per_sample == 2) {
  86575. if(channels == 2) {
  86576. for(sample = 0; sample < samples; sample++) {
  86577. a_word = signal[0][sample];
  86578. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86579. *buf_++ = (FLAC__byte)a_word;
  86580. a_word = signal[1][sample];
  86581. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86582. *buf_++ = (FLAC__byte)a_word;
  86583. }
  86584. }
  86585. else if(channels == 1) {
  86586. for(sample = 0; sample < samples; sample++) {
  86587. a_word = signal[0][sample];
  86588. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86589. *buf_++ = (FLAC__byte)a_word;
  86590. }
  86591. }
  86592. else {
  86593. for(sample = 0; sample < samples; sample++) {
  86594. for(channel = 0; channel < channels; channel++) {
  86595. a_word = signal[channel][sample];
  86596. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86597. *buf_++ = (FLAC__byte)a_word;
  86598. }
  86599. }
  86600. }
  86601. }
  86602. else if(bytes_per_sample == 3) {
  86603. if(channels == 2) {
  86604. for(sample = 0; sample < samples; sample++) {
  86605. a_word = signal[0][sample];
  86606. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86607. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86608. *buf_++ = (FLAC__byte)a_word;
  86609. a_word = signal[1][sample];
  86610. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86611. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86612. *buf_++ = (FLAC__byte)a_word;
  86613. }
  86614. }
  86615. else if(channels == 1) {
  86616. for(sample = 0; sample < samples; sample++) {
  86617. a_word = signal[0][sample];
  86618. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86619. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86620. *buf_++ = (FLAC__byte)a_word;
  86621. }
  86622. }
  86623. else {
  86624. for(sample = 0; sample < samples; sample++) {
  86625. for(channel = 0; channel < channels; channel++) {
  86626. a_word = signal[channel][sample];
  86627. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86628. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86629. *buf_++ = (FLAC__byte)a_word;
  86630. }
  86631. }
  86632. }
  86633. }
  86634. else if(bytes_per_sample == 1) {
  86635. if(channels == 2) {
  86636. for(sample = 0; sample < samples; sample++) {
  86637. a_word = signal[0][sample];
  86638. *buf_++ = (FLAC__byte)a_word;
  86639. a_word = signal[1][sample];
  86640. *buf_++ = (FLAC__byte)a_word;
  86641. }
  86642. }
  86643. else if(channels == 1) {
  86644. for(sample = 0; sample < samples; sample++) {
  86645. a_word = signal[0][sample];
  86646. *buf_++ = (FLAC__byte)a_word;
  86647. }
  86648. }
  86649. else {
  86650. for(sample = 0; sample < samples; sample++) {
  86651. for(channel = 0; channel < channels; channel++) {
  86652. a_word = signal[channel][sample];
  86653. *buf_++ = (FLAC__byte)a_word;
  86654. }
  86655. }
  86656. }
  86657. }
  86658. else { /* bytes_per_sample == 4, maybe optimize more later */
  86659. for(sample = 0; sample < samples; sample++) {
  86660. for(channel = 0; channel < channels; channel++) {
  86661. a_word = signal[channel][sample];
  86662. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86663. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86664. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86665. *buf_++ = (FLAC__byte)a_word;
  86666. }
  86667. }
  86668. }
  86669. }
  86670. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86671. {
  86672. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86673. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86674. return false;
  86675. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86676. return false;
  86677. if(ctx->capacity < bytes_needed) {
  86678. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86679. if(0 == tmp) {
  86680. free(ctx->internal_buf);
  86681. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86682. return false;
  86683. }
  86684. ctx->internal_buf = tmp;
  86685. ctx->capacity = bytes_needed;
  86686. }
  86687. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86688. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86689. return true;
  86690. }
  86691. #endif
  86692. /*** End of inlined file: md5.c ***/
  86693. /*** Start of inlined file: memory.c ***/
  86694. /*** Start of inlined file: juce_FlacHeader.h ***/
  86695. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86696. // tasks..
  86697. #define VERSION "1.2.1"
  86698. #define FLAC__NO_DLL 1
  86699. #if JUCE_MSVC
  86700. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86701. #endif
  86702. #if JUCE_MAC
  86703. #define FLAC__SYS_DARWIN 1
  86704. #endif
  86705. /*** End of inlined file: juce_FlacHeader.h ***/
  86706. #if JUCE_USE_FLAC
  86707. #if HAVE_CONFIG_H
  86708. # include <config.h>
  86709. #endif
  86710. /*** Start of inlined file: memory.h ***/
  86711. #ifndef FLAC__PRIVATE__MEMORY_H
  86712. #define FLAC__PRIVATE__MEMORY_H
  86713. #ifdef HAVE_CONFIG_H
  86714. #include <config.h>
  86715. #endif
  86716. #include <stdlib.h> /* for size_t */
  86717. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86718. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86719. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86720. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86721. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86722. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86723. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86724. #endif
  86725. #endif
  86726. /*** End of inlined file: memory.h ***/
  86727. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86728. {
  86729. void *x;
  86730. FLAC__ASSERT(0 != aligned_address);
  86731. #ifdef FLAC__ALIGN_MALLOC_DATA
  86732. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86733. #ifdef SIZEOF_VOIDP
  86734. #if SIZEOF_VOIDP == 4
  86735. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86736. #elif SIZEOF_VOIDP == 8
  86737. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86738. #else
  86739. # error Unsupported sizeof(void*)
  86740. #endif
  86741. #else
  86742. if(sizeof(void*) == sizeof(unsigned))
  86743. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86744. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86745. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86746. else
  86747. return 0;
  86748. #endif
  86749. #else
  86750. x = safe_malloc_(bytes);
  86751. *aligned_address = x;
  86752. #endif
  86753. return x;
  86754. }
  86755. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86756. {
  86757. FLAC__int32 *pu; /* unaligned pointer */
  86758. union { /* union needed to comply with C99 pointer aliasing rules */
  86759. FLAC__int32 *pa; /* aligned pointer */
  86760. void *pv; /* aligned pointer alias */
  86761. } u;
  86762. FLAC__ASSERT(elements > 0);
  86763. FLAC__ASSERT(0 != unaligned_pointer);
  86764. FLAC__ASSERT(0 != aligned_pointer);
  86765. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86766. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86767. if(0 == pu) {
  86768. return false;
  86769. }
  86770. else {
  86771. if(*unaligned_pointer != 0)
  86772. free(*unaligned_pointer);
  86773. *unaligned_pointer = pu;
  86774. *aligned_pointer = u.pa;
  86775. return true;
  86776. }
  86777. }
  86778. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86779. {
  86780. FLAC__uint32 *pu; /* unaligned pointer */
  86781. union { /* union needed to comply with C99 pointer aliasing rules */
  86782. FLAC__uint32 *pa; /* aligned pointer */
  86783. void *pv; /* aligned pointer alias */
  86784. } u;
  86785. FLAC__ASSERT(elements > 0);
  86786. FLAC__ASSERT(0 != unaligned_pointer);
  86787. FLAC__ASSERT(0 != aligned_pointer);
  86788. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86789. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86790. if(0 == pu) {
  86791. return false;
  86792. }
  86793. else {
  86794. if(*unaligned_pointer != 0)
  86795. free(*unaligned_pointer);
  86796. *unaligned_pointer = pu;
  86797. *aligned_pointer = u.pa;
  86798. return true;
  86799. }
  86800. }
  86801. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86802. {
  86803. FLAC__uint64 *pu; /* unaligned pointer */
  86804. union { /* union needed to comply with C99 pointer aliasing rules */
  86805. FLAC__uint64 *pa; /* aligned pointer */
  86806. void *pv; /* aligned pointer alias */
  86807. } u;
  86808. FLAC__ASSERT(elements > 0);
  86809. FLAC__ASSERT(0 != unaligned_pointer);
  86810. FLAC__ASSERT(0 != aligned_pointer);
  86811. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86812. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86813. if(0 == pu) {
  86814. return false;
  86815. }
  86816. else {
  86817. if(*unaligned_pointer != 0)
  86818. free(*unaligned_pointer);
  86819. *unaligned_pointer = pu;
  86820. *aligned_pointer = u.pa;
  86821. return true;
  86822. }
  86823. }
  86824. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86825. {
  86826. unsigned *pu; /* unaligned pointer */
  86827. union { /* union needed to comply with C99 pointer aliasing rules */
  86828. unsigned *pa; /* aligned pointer */
  86829. void *pv; /* aligned pointer alias */
  86830. } u;
  86831. FLAC__ASSERT(elements > 0);
  86832. FLAC__ASSERT(0 != unaligned_pointer);
  86833. FLAC__ASSERT(0 != aligned_pointer);
  86834. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86835. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86836. if(0 == pu) {
  86837. return false;
  86838. }
  86839. else {
  86840. if(*unaligned_pointer != 0)
  86841. free(*unaligned_pointer);
  86842. *unaligned_pointer = pu;
  86843. *aligned_pointer = u.pa;
  86844. return true;
  86845. }
  86846. }
  86847. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86848. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86849. {
  86850. FLAC__real *pu; /* unaligned pointer */
  86851. union { /* union needed to comply with C99 pointer aliasing rules */
  86852. FLAC__real *pa; /* aligned pointer */
  86853. void *pv; /* aligned pointer alias */
  86854. } u;
  86855. FLAC__ASSERT(elements > 0);
  86856. FLAC__ASSERT(0 != unaligned_pointer);
  86857. FLAC__ASSERT(0 != aligned_pointer);
  86858. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86859. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86860. if(0 == pu) {
  86861. return false;
  86862. }
  86863. else {
  86864. if(*unaligned_pointer != 0)
  86865. free(*unaligned_pointer);
  86866. *unaligned_pointer = pu;
  86867. *aligned_pointer = u.pa;
  86868. return true;
  86869. }
  86870. }
  86871. #endif
  86872. #endif
  86873. /*** End of inlined file: memory.c ***/
  86874. /*** Start of inlined file: stream_decoder.c ***/
  86875. /*** Start of inlined file: juce_FlacHeader.h ***/
  86876. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86877. // tasks..
  86878. #define VERSION "1.2.1"
  86879. #define FLAC__NO_DLL 1
  86880. #if JUCE_MSVC
  86881. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86882. #endif
  86883. #if JUCE_MAC
  86884. #define FLAC__SYS_DARWIN 1
  86885. #endif
  86886. /*** End of inlined file: juce_FlacHeader.h ***/
  86887. #if JUCE_USE_FLAC
  86888. #if HAVE_CONFIG_H
  86889. # include <config.h>
  86890. #endif
  86891. #if defined _MSC_VER || defined __MINGW32__
  86892. #include <io.h> /* for _setmode() */
  86893. #include <fcntl.h> /* for _O_BINARY */
  86894. #endif
  86895. #if defined __CYGWIN__ || defined __EMX__
  86896. #include <io.h> /* for setmode(), O_BINARY */
  86897. #include <fcntl.h> /* for _O_BINARY */
  86898. #endif
  86899. #include <stdio.h>
  86900. #include <stdlib.h> /* for malloc() */
  86901. #include <string.h> /* for memset/memcpy() */
  86902. #include <sys/stat.h> /* for stat() */
  86903. #include <sys/types.h> /* for off_t */
  86904. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86905. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86906. #define fseeko fseek
  86907. #define ftello ftell
  86908. #endif
  86909. #endif
  86910. /*** Start of inlined file: stream_decoder.h ***/
  86911. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86912. #define FLAC__PROTECTED__STREAM_DECODER_H
  86913. #if FLAC__HAS_OGG
  86914. #include "include/private/ogg_decoder_aspect.h"
  86915. #endif
  86916. typedef struct FLAC__StreamDecoderProtected {
  86917. FLAC__StreamDecoderState state;
  86918. unsigned channels;
  86919. FLAC__ChannelAssignment channel_assignment;
  86920. unsigned bits_per_sample;
  86921. unsigned sample_rate; /* in Hz */
  86922. unsigned blocksize; /* in samples (per channel) */
  86923. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  86924. #if FLAC__HAS_OGG
  86925. FLAC__OggDecoderAspect ogg_decoder_aspect;
  86926. #endif
  86927. } FLAC__StreamDecoderProtected;
  86928. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  86929. #endif
  86930. /*** End of inlined file: stream_decoder.h ***/
  86931. #ifdef max
  86932. #undef max
  86933. #endif
  86934. #define max(a,b) ((a)>(b)?(a):(b))
  86935. #ifdef _MSC_VER
  86936. #define FLAC__U64L(x) x
  86937. #else
  86938. #define FLAC__U64L(x) x##LLU
  86939. #endif
  86940. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  86941. #if FLAC__HAS_OGG
  86942. 1
  86943. #else
  86944. 0
  86945. #endif
  86946. ;
  86947. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  86948. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  86949. static FILE *get_binary_stdin_(void);
  86950. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  86951. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  86952. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  86953. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  86954. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86955. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86956. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  86957. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  86958. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  86959. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  86960. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  86961. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  86962. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  86963. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86964. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86965. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86966. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86967. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86968. 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);
  86969. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  86970. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  86971. #if FLAC__HAS_OGG
  86972. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  86973. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86974. #endif
  86975. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  86976. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  86977. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86978. #if FLAC__HAS_OGG
  86979. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86980. #endif
  86981. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86982. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  86983. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  86984. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  86985. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  86986. typedef struct FLAC__StreamDecoderPrivate {
  86987. #if FLAC__HAS_OGG
  86988. FLAC__bool is_ogg;
  86989. #endif
  86990. FLAC__StreamDecoderReadCallback read_callback;
  86991. FLAC__StreamDecoderSeekCallback seek_callback;
  86992. FLAC__StreamDecoderTellCallback tell_callback;
  86993. FLAC__StreamDecoderLengthCallback length_callback;
  86994. FLAC__StreamDecoderEofCallback eof_callback;
  86995. FLAC__StreamDecoderWriteCallback write_callback;
  86996. FLAC__StreamDecoderMetadataCallback metadata_callback;
  86997. FLAC__StreamDecoderErrorCallback error_callback;
  86998. 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[]);
  86999. 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[]);
  87000. 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[]);
  87001. 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[]);
  87002. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  87003. void *client_data;
  87004. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  87005. FLAC__BitReader *input;
  87006. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  87007. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  87008. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  87009. unsigned output_capacity, output_channels;
  87010. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87011. FLAC__uint64 samples_decoded;
  87012. FLAC__bool has_stream_info, has_seek_table;
  87013. FLAC__StreamMetadata stream_info;
  87014. FLAC__StreamMetadata seek_table;
  87015. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87016. FLAC__byte *metadata_filter_ids;
  87017. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87018. FLAC__Frame frame;
  87019. FLAC__bool cached; /* true if there is a byte in lookahead */
  87020. FLAC__CPUInfo cpuinfo;
  87021. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87022. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87023. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87024. 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 */
  87025. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87026. FLAC__bool is_seeking;
  87027. FLAC__MD5Context md5context;
  87028. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87029. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87030. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87031. FLAC__uint64 target_sample;
  87032. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87033. #if FLAC__HAS_OGG
  87034. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87035. #endif
  87036. } FLAC__StreamDecoderPrivate;
  87037. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87038. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87039. "FLAC__STREAM_DECODER_READ_METADATA",
  87040. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87041. "FLAC__STREAM_DECODER_READ_FRAME",
  87042. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87043. "FLAC__STREAM_DECODER_OGG_ERROR",
  87044. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87045. "FLAC__STREAM_DECODER_ABORTED",
  87046. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87047. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87048. };
  87049. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87050. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87051. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87052. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87053. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87054. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87055. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87056. };
  87057. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87058. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87059. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87060. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87061. };
  87062. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87063. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87064. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87065. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87066. };
  87067. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87068. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87069. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87070. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87071. };
  87072. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87073. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87074. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87075. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87076. };
  87077. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87078. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87079. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87080. };
  87081. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87082. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87083. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87084. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87085. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87086. };
  87087. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87088. {
  87089. FLAC__StreamDecoder *decoder;
  87090. unsigned i;
  87091. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87092. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87093. if(decoder == 0) {
  87094. return 0;
  87095. }
  87096. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87097. if(decoder->protected_ == 0) {
  87098. free(decoder);
  87099. return 0;
  87100. }
  87101. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87102. if(decoder->private_ == 0) {
  87103. free(decoder->protected_);
  87104. free(decoder);
  87105. return 0;
  87106. }
  87107. decoder->private_->input = FLAC__bitreader_new();
  87108. if(decoder->private_->input == 0) {
  87109. free(decoder->private_);
  87110. free(decoder->protected_);
  87111. free(decoder);
  87112. return 0;
  87113. }
  87114. decoder->private_->metadata_filter_ids_capacity = 16;
  87115. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87116. FLAC__bitreader_delete(decoder->private_->input);
  87117. free(decoder->private_);
  87118. free(decoder->protected_);
  87119. free(decoder);
  87120. return 0;
  87121. }
  87122. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87123. decoder->private_->output[i] = 0;
  87124. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87125. }
  87126. decoder->private_->output_capacity = 0;
  87127. decoder->private_->output_channels = 0;
  87128. decoder->private_->has_seek_table = false;
  87129. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87130. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87131. decoder->private_->file = 0;
  87132. set_defaults_dec(decoder);
  87133. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87134. return decoder;
  87135. }
  87136. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87137. {
  87138. unsigned i;
  87139. FLAC__ASSERT(0 != decoder);
  87140. FLAC__ASSERT(0 != decoder->protected_);
  87141. FLAC__ASSERT(0 != decoder->private_);
  87142. FLAC__ASSERT(0 != decoder->private_->input);
  87143. (void)FLAC__stream_decoder_finish(decoder);
  87144. if(0 != decoder->private_->metadata_filter_ids)
  87145. free(decoder->private_->metadata_filter_ids);
  87146. FLAC__bitreader_delete(decoder->private_->input);
  87147. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87148. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87149. free(decoder->private_);
  87150. free(decoder->protected_);
  87151. free(decoder);
  87152. }
  87153. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87154. FLAC__StreamDecoder *decoder,
  87155. FLAC__StreamDecoderReadCallback read_callback,
  87156. FLAC__StreamDecoderSeekCallback seek_callback,
  87157. FLAC__StreamDecoderTellCallback tell_callback,
  87158. FLAC__StreamDecoderLengthCallback length_callback,
  87159. FLAC__StreamDecoderEofCallback eof_callback,
  87160. FLAC__StreamDecoderWriteCallback write_callback,
  87161. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87162. FLAC__StreamDecoderErrorCallback error_callback,
  87163. void *client_data,
  87164. FLAC__bool is_ogg
  87165. )
  87166. {
  87167. FLAC__ASSERT(0 != decoder);
  87168. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87169. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87170. #if !FLAC__HAS_OGG
  87171. if(is_ogg)
  87172. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87173. #endif
  87174. if(
  87175. 0 == read_callback ||
  87176. 0 == write_callback ||
  87177. 0 == error_callback ||
  87178. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87179. )
  87180. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87181. #if FLAC__HAS_OGG
  87182. decoder->private_->is_ogg = is_ogg;
  87183. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87184. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87185. #endif
  87186. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87187. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87188. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87189. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87190. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87191. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87192. #ifndef FLAC__NO_ASM
  87193. if(decoder->private_->cpuinfo.use_asm) {
  87194. #ifdef FLAC__CPU_IA32
  87195. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87196. #ifdef FLAC__HAS_NASM
  87197. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87198. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87199. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87200. #endif
  87201. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87202. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87203. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87204. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87205. }
  87206. else {
  87207. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87208. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87209. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87210. }
  87211. #endif
  87212. #elif defined FLAC__CPU_PPC
  87213. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87214. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87215. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87216. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87217. }
  87218. #endif
  87219. }
  87220. #endif
  87221. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87222. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87223. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87224. }
  87225. decoder->private_->read_callback = read_callback;
  87226. decoder->private_->seek_callback = seek_callback;
  87227. decoder->private_->tell_callback = tell_callback;
  87228. decoder->private_->length_callback = length_callback;
  87229. decoder->private_->eof_callback = eof_callback;
  87230. decoder->private_->write_callback = write_callback;
  87231. decoder->private_->metadata_callback = metadata_callback;
  87232. decoder->private_->error_callback = error_callback;
  87233. decoder->private_->client_data = client_data;
  87234. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87235. decoder->private_->samples_decoded = 0;
  87236. decoder->private_->has_stream_info = false;
  87237. decoder->private_->cached = false;
  87238. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87239. decoder->private_->is_seeking = false;
  87240. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87241. if(!FLAC__stream_decoder_reset(decoder)) {
  87242. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87243. }
  87244. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87245. }
  87246. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87247. FLAC__StreamDecoder *decoder,
  87248. FLAC__StreamDecoderReadCallback read_callback,
  87249. FLAC__StreamDecoderSeekCallback seek_callback,
  87250. FLAC__StreamDecoderTellCallback tell_callback,
  87251. FLAC__StreamDecoderLengthCallback length_callback,
  87252. FLAC__StreamDecoderEofCallback eof_callback,
  87253. FLAC__StreamDecoderWriteCallback write_callback,
  87254. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87255. FLAC__StreamDecoderErrorCallback error_callback,
  87256. void *client_data
  87257. )
  87258. {
  87259. return init_stream_internal_dec(
  87260. decoder,
  87261. read_callback,
  87262. seek_callback,
  87263. tell_callback,
  87264. length_callback,
  87265. eof_callback,
  87266. write_callback,
  87267. metadata_callback,
  87268. error_callback,
  87269. client_data,
  87270. false
  87271. );
  87272. }
  87273. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87274. FLAC__StreamDecoder *decoder,
  87275. FLAC__StreamDecoderReadCallback read_callback,
  87276. FLAC__StreamDecoderSeekCallback seek_callback,
  87277. FLAC__StreamDecoderTellCallback tell_callback,
  87278. FLAC__StreamDecoderLengthCallback length_callback,
  87279. FLAC__StreamDecoderEofCallback eof_callback,
  87280. FLAC__StreamDecoderWriteCallback write_callback,
  87281. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87282. FLAC__StreamDecoderErrorCallback error_callback,
  87283. void *client_data
  87284. )
  87285. {
  87286. return init_stream_internal_dec(
  87287. decoder,
  87288. read_callback,
  87289. seek_callback,
  87290. tell_callback,
  87291. length_callback,
  87292. eof_callback,
  87293. write_callback,
  87294. metadata_callback,
  87295. error_callback,
  87296. client_data,
  87297. true
  87298. );
  87299. }
  87300. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87301. FLAC__StreamDecoder *decoder,
  87302. FILE *file,
  87303. FLAC__StreamDecoderWriteCallback write_callback,
  87304. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87305. FLAC__StreamDecoderErrorCallback error_callback,
  87306. void *client_data,
  87307. FLAC__bool is_ogg
  87308. )
  87309. {
  87310. FLAC__ASSERT(0 != decoder);
  87311. FLAC__ASSERT(0 != file);
  87312. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87313. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87314. if(0 == write_callback || 0 == error_callback)
  87315. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87316. if(file == stdin)
  87317. file = get_binary_stdin_(); /* just to be safe */
  87318. decoder->private_->file = file;
  87319. return init_stream_internal_dec(
  87320. decoder,
  87321. file_read_callback_dec,
  87322. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87323. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87324. decoder->private_->file == stdin? 0: file_length_callback_,
  87325. file_eof_callback_,
  87326. write_callback,
  87327. metadata_callback,
  87328. error_callback,
  87329. client_data,
  87330. is_ogg
  87331. );
  87332. }
  87333. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87334. FLAC__StreamDecoder *decoder,
  87335. FILE *file,
  87336. FLAC__StreamDecoderWriteCallback write_callback,
  87337. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87338. FLAC__StreamDecoderErrorCallback error_callback,
  87339. void *client_data
  87340. )
  87341. {
  87342. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87343. }
  87344. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87345. FLAC__StreamDecoder *decoder,
  87346. FILE *file,
  87347. FLAC__StreamDecoderWriteCallback write_callback,
  87348. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87349. FLAC__StreamDecoderErrorCallback error_callback,
  87350. void *client_data
  87351. )
  87352. {
  87353. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87354. }
  87355. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87356. FLAC__StreamDecoder *decoder,
  87357. const char *filename,
  87358. FLAC__StreamDecoderWriteCallback write_callback,
  87359. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87360. FLAC__StreamDecoderErrorCallback error_callback,
  87361. void *client_data,
  87362. FLAC__bool is_ogg
  87363. )
  87364. {
  87365. FILE *file;
  87366. FLAC__ASSERT(0 != decoder);
  87367. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87368. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87369. if(0 == write_callback || 0 == error_callback)
  87370. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87371. file = filename? fopen(filename, "rb") : stdin;
  87372. if(0 == file)
  87373. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87374. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87375. }
  87376. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87377. FLAC__StreamDecoder *decoder,
  87378. const char *filename,
  87379. FLAC__StreamDecoderWriteCallback write_callback,
  87380. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87381. FLAC__StreamDecoderErrorCallback error_callback,
  87382. void *client_data
  87383. )
  87384. {
  87385. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87386. }
  87387. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87388. FLAC__StreamDecoder *decoder,
  87389. const char *filename,
  87390. FLAC__StreamDecoderWriteCallback write_callback,
  87391. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87392. FLAC__StreamDecoderErrorCallback error_callback,
  87393. void *client_data
  87394. )
  87395. {
  87396. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87397. }
  87398. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87399. {
  87400. FLAC__bool md5_failed = false;
  87401. unsigned i;
  87402. FLAC__ASSERT(0 != decoder);
  87403. FLAC__ASSERT(0 != decoder->private_);
  87404. FLAC__ASSERT(0 != decoder->protected_);
  87405. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87406. return true;
  87407. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87408. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87409. free(decoder->private_->seek_table.data.seek_table.points);
  87410. decoder->private_->seek_table.data.seek_table.points = 0;
  87411. decoder->private_->has_seek_table = false;
  87412. }
  87413. FLAC__bitreader_free(decoder->private_->input);
  87414. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87415. if(0 != decoder->private_->output[i]) {
  87416. free(decoder->private_->output[i]-4);
  87417. decoder->private_->output[i] = 0;
  87418. }
  87419. if(0 != decoder->private_->residual_unaligned[i]) {
  87420. free(decoder->private_->residual_unaligned[i]);
  87421. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87422. }
  87423. }
  87424. decoder->private_->output_capacity = 0;
  87425. decoder->private_->output_channels = 0;
  87426. #if FLAC__HAS_OGG
  87427. if(decoder->private_->is_ogg)
  87428. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87429. #endif
  87430. if(0 != decoder->private_->file) {
  87431. if(decoder->private_->file != stdin)
  87432. fclose(decoder->private_->file);
  87433. decoder->private_->file = 0;
  87434. }
  87435. if(decoder->private_->do_md5_checking) {
  87436. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87437. md5_failed = true;
  87438. }
  87439. decoder->private_->is_seeking = false;
  87440. set_defaults_dec(decoder);
  87441. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87442. return !md5_failed;
  87443. }
  87444. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87445. {
  87446. FLAC__ASSERT(0 != decoder);
  87447. FLAC__ASSERT(0 != decoder->private_);
  87448. FLAC__ASSERT(0 != decoder->protected_);
  87449. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87450. return false;
  87451. #if FLAC__HAS_OGG
  87452. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87453. return true;
  87454. #else
  87455. (void)value;
  87456. return false;
  87457. #endif
  87458. }
  87459. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87460. {
  87461. FLAC__ASSERT(0 != decoder);
  87462. FLAC__ASSERT(0 != decoder->protected_);
  87463. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87464. return false;
  87465. decoder->protected_->md5_checking = value;
  87466. return true;
  87467. }
  87468. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87469. {
  87470. FLAC__ASSERT(0 != decoder);
  87471. FLAC__ASSERT(0 != decoder->private_);
  87472. FLAC__ASSERT(0 != decoder->protected_);
  87473. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87474. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87475. return false;
  87476. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87477. return false;
  87478. decoder->private_->metadata_filter[type] = true;
  87479. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87480. decoder->private_->metadata_filter_ids_count = 0;
  87481. return true;
  87482. }
  87483. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87484. {
  87485. FLAC__ASSERT(0 != decoder);
  87486. FLAC__ASSERT(0 != decoder->private_);
  87487. FLAC__ASSERT(0 != decoder->protected_);
  87488. FLAC__ASSERT(0 != id);
  87489. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87490. return false;
  87491. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87492. return true;
  87493. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87494. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87495. 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))) {
  87496. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87497. return false;
  87498. }
  87499. decoder->private_->metadata_filter_ids_capacity *= 2;
  87500. }
  87501. 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));
  87502. decoder->private_->metadata_filter_ids_count++;
  87503. return true;
  87504. }
  87505. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87506. {
  87507. unsigned i;
  87508. FLAC__ASSERT(0 != decoder);
  87509. FLAC__ASSERT(0 != decoder->private_);
  87510. FLAC__ASSERT(0 != decoder->protected_);
  87511. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87512. return false;
  87513. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87514. decoder->private_->metadata_filter[i] = true;
  87515. decoder->private_->metadata_filter_ids_count = 0;
  87516. return true;
  87517. }
  87518. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87519. {
  87520. FLAC__ASSERT(0 != decoder);
  87521. FLAC__ASSERT(0 != decoder->private_);
  87522. FLAC__ASSERT(0 != decoder->protected_);
  87523. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87524. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87525. return false;
  87526. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87527. return false;
  87528. decoder->private_->metadata_filter[type] = false;
  87529. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87530. decoder->private_->metadata_filter_ids_count = 0;
  87531. return true;
  87532. }
  87533. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87534. {
  87535. FLAC__ASSERT(0 != decoder);
  87536. FLAC__ASSERT(0 != decoder->private_);
  87537. FLAC__ASSERT(0 != decoder->protected_);
  87538. FLAC__ASSERT(0 != id);
  87539. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87540. return false;
  87541. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87542. return true;
  87543. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87544. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87545. 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))) {
  87546. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87547. return false;
  87548. }
  87549. decoder->private_->metadata_filter_ids_capacity *= 2;
  87550. }
  87551. 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));
  87552. decoder->private_->metadata_filter_ids_count++;
  87553. return true;
  87554. }
  87555. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87556. {
  87557. FLAC__ASSERT(0 != decoder);
  87558. FLAC__ASSERT(0 != decoder->private_);
  87559. FLAC__ASSERT(0 != decoder->protected_);
  87560. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87561. return false;
  87562. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87563. decoder->private_->metadata_filter_ids_count = 0;
  87564. return true;
  87565. }
  87566. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87567. {
  87568. FLAC__ASSERT(0 != decoder);
  87569. FLAC__ASSERT(0 != decoder->protected_);
  87570. return decoder->protected_->state;
  87571. }
  87572. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87573. {
  87574. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87575. }
  87576. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87577. {
  87578. FLAC__ASSERT(0 != decoder);
  87579. FLAC__ASSERT(0 != decoder->protected_);
  87580. return decoder->protected_->md5_checking;
  87581. }
  87582. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87583. {
  87584. FLAC__ASSERT(0 != decoder);
  87585. FLAC__ASSERT(0 != decoder->protected_);
  87586. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87587. }
  87588. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87589. {
  87590. FLAC__ASSERT(0 != decoder);
  87591. FLAC__ASSERT(0 != decoder->protected_);
  87592. return decoder->protected_->channels;
  87593. }
  87594. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87595. {
  87596. FLAC__ASSERT(0 != decoder);
  87597. FLAC__ASSERT(0 != decoder->protected_);
  87598. return decoder->protected_->channel_assignment;
  87599. }
  87600. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87601. {
  87602. FLAC__ASSERT(0 != decoder);
  87603. FLAC__ASSERT(0 != decoder->protected_);
  87604. return decoder->protected_->bits_per_sample;
  87605. }
  87606. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87607. {
  87608. FLAC__ASSERT(0 != decoder);
  87609. FLAC__ASSERT(0 != decoder->protected_);
  87610. return decoder->protected_->sample_rate;
  87611. }
  87612. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87613. {
  87614. FLAC__ASSERT(0 != decoder);
  87615. FLAC__ASSERT(0 != decoder->protected_);
  87616. return decoder->protected_->blocksize;
  87617. }
  87618. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87619. {
  87620. FLAC__ASSERT(0 != decoder);
  87621. FLAC__ASSERT(0 != decoder->private_);
  87622. FLAC__ASSERT(0 != position);
  87623. #if FLAC__HAS_OGG
  87624. if(decoder->private_->is_ogg)
  87625. return false;
  87626. #endif
  87627. if(0 == decoder->private_->tell_callback)
  87628. return false;
  87629. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87630. return false;
  87631. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87632. return false;
  87633. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87634. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87635. return true;
  87636. }
  87637. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87638. {
  87639. FLAC__ASSERT(0 != decoder);
  87640. FLAC__ASSERT(0 != decoder->private_);
  87641. FLAC__ASSERT(0 != decoder->protected_);
  87642. decoder->private_->samples_decoded = 0;
  87643. decoder->private_->do_md5_checking = false;
  87644. #if FLAC__HAS_OGG
  87645. if(decoder->private_->is_ogg)
  87646. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87647. #endif
  87648. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87649. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87650. return false;
  87651. }
  87652. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87653. return true;
  87654. }
  87655. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87656. {
  87657. FLAC__ASSERT(0 != decoder);
  87658. FLAC__ASSERT(0 != decoder->private_);
  87659. FLAC__ASSERT(0 != decoder->protected_);
  87660. if(!FLAC__stream_decoder_flush(decoder)) {
  87661. return false;
  87662. }
  87663. #if FLAC__HAS_OGG
  87664. if(decoder->private_->is_ogg)
  87665. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87666. #endif
  87667. if(!decoder->private_->internal_reset_hack) {
  87668. if(decoder->private_->file == stdin)
  87669. return false; /* can't rewind stdin, reset fails */
  87670. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87671. return false; /* seekable and seek fails, reset fails */
  87672. }
  87673. else
  87674. decoder->private_->internal_reset_hack = false;
  87675. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87676. decoder->private_->has_stream_info = false;
  87677. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87678. free(decoder->private_->seek_table.data.seek_table.points);
  87679. decoder->private_->seek_table.data.seek_table.points = 0;
  87680. decoder->private_->has_seek_table = false;
  87681. }
  87682. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87683. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87684. FLAC__MD5Init(&decoder->private_->md5context);
  87685. decoder->private_->first_frame_offset = 0;
  87686. decoder->private_->unparseable_frame_count = 0;
  87687. return true;
  87688. }
  87689. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87690. {
  87691. FLAC__bool got_a_frame;
  87692. FLAC__ASSERT(0 != decoder);
  87693. FLAC__ASSERT(0 != decoder->protected_);
  87694. while(1) {
  87695. switch(decoder->protected_->state) {
  87696. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87697. if(!find_metadata_(decoder))
  87698. return false; /* above function sets the status for us */
  87699. break;
  87700. case FLAC__STREAM_DECODER_READ_METADATA:
  87701. if(!read_metadata_(decoder))
  87702. return false; /* above function sets the status for us */
  87703. else
  87704. return true;
  87705. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87706. if(!frame_sync_(decoder))
  87707. return true; /* above function sets the status for us */
  87708. break;
  87709. case FLAC__STREAM_DECODER_READ_FRAME:
  87710. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87711. return false; /* above function sets the status for us */
  87712. if(got_a_frame)
  87713. return true; /* above function sets the status for us */
  87714. break;
  87715. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87716. case FLAC__STREAM_DECODER_ABORTED:
  87717. return true;
  87718. default:
  87719. FLAC__ASSERT(0);
  87720. return false;
  87721. }
  87722. }
  87723. }
  87724. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87725. {
  87726. FLAC__ASSERT(0 != decoder);
  87727. FLAC__ASSERT(0 != decoder->protected_);
  87728. while(1) {
  87729. switch(decoder->protected_->state) {
  87730. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87731. if(!find_metadata_(decoder))
  87732. return false; /* above function sets the status for us */
  87733. break;
  87734. case FLAC__STREAM_DECODER_READ_METADATA:
  87735. if(!read_metadata_(decoder))
  87736. return false; /* above function sets the status for us */
  87737. break;
  87738. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87739. case FLAC__STREAM_DECODER_READ_FRAME:
  87740. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87741. case FLAC__STREAM_DECODER_ABORTED:
  87742. return true;
  87743. default:
  87744. FLAC__ASSERT(0);
  87745. return false;
  87746. }
  87747. }
  87748. }
  87749. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87750. {
  87751. FLAC__bool dummy;
  87752. FLAC__ASSERT(0 != decoder);
  87753. FLAC__ASSERT(0 != decoder->protected_);
  87754. while(1) {
  87755. switch(decoder->protected_->state) {
  87756. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87757. if(!find_metadata_(decoder))
  87758. return false; /* above function sets the status for us */
  87759. break;
  87760. case FLAC__STREAM_DECODER_READ_METADATA:
  87761. if(!read_metadata_(decoder))
  87762. return false; /* above function sets the status for us */
  87763. break;
  87764. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87765. if(!frame_sync_(decoder))
  87766. return true; /* above function sets the status for us */
  87767. break;
  87768. case FLAC__STREAM_DECODER_READ_FRAME:
  87769. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87770. return false; /* above function sets the status for us */
  87771. break;
  87772. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87773. case FLAC__STREAM_DECODER_ABORTED:
  87774. return true;
  87775. default:
  87776. FLAC__ASSERT(0);
  87777. return false;
  87778. }
  87779. }
  87780. }
  87781. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87782. {
  87783. FLAC__bool got_a_frame;
  87784. FLAC__ASSERT(0 != decoder);
  87785. FLAC__ASSERT(0 != decoder->protected_);
  87786. while(1) {
  87787. switch(decoder->protected_->state) {
  87788. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87789. case FLAC__STREAM_DECODER_READ_METADATA:
  87790. return false; /* above function sets the status for us */
  87791. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87792. if(!frame_sync_(decoder))
  87793. return true; /* above function sets the status for us */
  87794. break;
  87795. case FLAC__STREAM_DECODER_READ_FRAME:
  87796. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87797. return false; /* above function sets the status for us */
  87798. if(got_a_frame)
  87799. return true; /* above function sets the status for us */
  87800. break;
  87801. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87802. case FLAC__STREAM_DECODER_ABORTED:
  87803. return true;
  87804. default:
  87805. FLAC__ASSERT(0);
  87806. return false;
  87807. }
  87808. }
  87809. }
  87810. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87811. {
  87812. FLAC__uint64 length;
  87813. FLAC__ASSERT(0 != decoder);
  87814. if(
  87815. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87816. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87817. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87818. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87819. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87820. )
  87821. return false;
  87822. if(0 == decoder->private_->seek_callback)
  87823. return false;
  87824. FLAC__ASSERT(decoder->private_->seek_callback);
  87825. FLAC__ASSERT(decoder->private_->tell_callback);
  87826. FLAC__ASSERT(decoder->private_->length_callback);
  87827. FLAC__ASSERT(decoder->private_->eof_callback);
  87828. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87829. return false;
  87830. decoder->private_->is_seeking = true;
  87831. decoder->private_->do_md5_checking = false;
  87832. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87833. decoder->private_->is_seeking = false;
  87834. return false;
  87835. }
  87836. if(
  87837. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87838. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87839. ) {
  87840. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87841. decoder->private_->is_seeking = false;
  87842. return false;
  87843. }
  87844. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87845. decoder->private_->is_seeking = false;
  87846. return false;
  87847. }
  87848. }
  87849. {
  87850. const FLAC__bool ok =
  87851. #if FLAC__HAS_OGG
  87852. decoder->private_->is_ogg?
  87853. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87854. #endif
  87855. seek_to_absolute_sample_(decoder, length, sample)
  87856. ;
  87857. decoder->private_->is_seeking = false;
  87858. return ok;
  87859. }
  87860. }
  87861. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87862. {
  87863. FLAC__ASSERT(0 != decoder);
  87864. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87865. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87866. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87867. }
  87868. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87869. {
  87870. #if FLAC__HAS_OGG
  87871. decoder->private_->is_ogg = false;
  87872. #endif
  87873. decoder->private_->read_callback = 0;
  87874. decoder->private_->seek_callback = 0;
  87875. decoder->private_->tell_callback = 0;
  87876. decoder->private_->length_callback = 0;
  87877. decoder->private_->eof_callback = 0;
  87878. decoder->private_->write_callback = 0;
  87879. decoder->private_->metadata_callback = 0;
  87880. decoder->private_->error_callback = 0;
  87881. decoder->private_->client_data = 0;
  87882. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87883. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87884. decoder->private_->metadata_filter_ids_count = 0;
  87885. decoder->protected_->md5_checking = false;
  87886. #if FLAC__HAS_OGG
  87887. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87888. #endif
  87889. }
  87890. FILE *get_binary_stdin_(void)
  87891. {
  87892. #if defined _MSC_VER || defined __MINGW32__
  87893. _setmode(_fileno(stdin), _O_BINARY);
  87894. #elif defined __CYGWIN__
  87895. setmode(_fileno(stdin), _O_BINARY);
  87896. #elif defined __EMX__
  87897. setmode(fileno(stdin), O_BINARY);
  87898. #endif
  87899. return stdin;
  87900. }
  87901. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87902. {
  87903. unsigned i;
  87904. FLAC__int32 *tmp;
  87905. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87906. return true;
  87907. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87908. if(0 != decoder->private_->output[i]) {
  87909. free(decoder->private_->output[i]-4);
  87910. decoder->private_->output[i] = 0;
  87911. }
  87912. if(0 != decoder->private_->residual_unaligned[i]) {
  87913. free(decoder->private_->residual_unaligned[i]);
  87914. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87915. }
  87916. }
  87917. for(i = 0; i < channels; i++) {
  87918. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87919. if(tmp == 0) {
  87920. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87921. return false;
  87922. }
  87923. memset(tmp, 0, sizeof(FLAC__int32)*4);
  87924. decoder->private_->output[i] = tmp + 4;
  87925. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  87926. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87927. return false;
  87928. }
  87929. }
  87930. decoder->private_->output_capacity = size;
  87931. decoder->private_->output_channels = channels;
  87932. return true;
  87933. }
  87934. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  87935. {
  87936. size_t i;
  87937. FLAC__ASSERT(0 != decoder);
  87938. FLAC__ASSERT(0 != decoder->private_);
  87939. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  87940. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  87941. return true;
  87942. return false;
  87943. }
  87944. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  87945. {
  87946. FLAC__uint32 x;
  87947. unsigned i, id_;
  87948. FLAC__bool first = true;
  87949. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87950. for(i = id_ = 0; i < 4; ) {
  87951. if(decoder->private_->cached) {
  87952. x = (FLAC__uint32)decoder->private_->lookahead;
  87953. decoder->private_->cached = false;
  87954. }
  87955. else {
  87956. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87957. return false; /* read_callback_ sets the state for us */
  87958. }
  87959. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  87960. first = true;
  87961. i++;
  87962. id_ = 0;
  87963. continue;
  87964. }
  87965. if(x == ID3V2_TAG_[id_]) {
  87966. id_++;
  87967. i = 0;
  87968. if(id_ == 3) {
  87969. if(!skip_id3v2_tag_(decoder))
  87970. return false; /* skip_id3v2_tag_ sets the state for us */
  87971. }
  87972. continue;
  87973. }
  87974. id_ = 0;
  87975. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87976. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  87977. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87978. return false; /* read_callback_ sets the state for us */
  87979. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87980. decoder->private_->lookahead = (FLAC__byte)x;
  87981. decoder->private_->cached = true;
  87982. }
  87983. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  87984. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  87985. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  87986. return true;
  87987. }
  87988. }
  87989. i = 0;
  87990. if(first) {
  87991. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  87992. first = false;
  87993. }
  87994. }
  87995. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  87996. return true;
  87997. }
  87998. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  87999. {
  88000. FLAC__bool is_last;
  88001. FLAC__uint32 i, x, type, length;
  88002. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88003. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  88004. return false; /* read_callback_ sets the state for us */
  88005. is_last = x? true : false;
  88006. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  88007. return false; /* read_callback_ sets the state for us */
  88008. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  88009. return false; /* read_callback_ sets the state for us */
  88010. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88011. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88012. return false;
  88013. decoder->private_->has_stream_info = true;
  88014. 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))
  88015. decoder->private_->do_md5_checking = false;
  88016. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88017. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88018. }
  88019. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88020. if(!read_metadata_seektable_(decoder, is_last, length))
  88021. return false;
  88022. decoder->private_->has_seek_table = true;
  88023. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88024. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88025. }
  88026. else {
  88027. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88028. unsigned real_length = length;
  88029. FLAC__StreamMetadata block;
  88030. block.is_last = is_last;
  88031. block.type = (FLAC__MetadataType)type;
  88032. block.length = length;
  88033. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88034. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88035. return false; /* read_callback_ sets the state for us */
  88036. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88037. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88038. return false;
  88039. }
  88040. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88041. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88042. skip_it = !skip_it;
  88043. }
  88044. if(skip_it) {
  88045. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88046. return false; /* read_callback_ sets the state for us */
  88047. }
  88048. else {
  88049. switch(type) {
  88050. case FLAC__METADATA_TYPE_PADDING:
  88051. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88052. return false; /* read_callback_ sets the state for us */
  88053. break;
  88054. case FLAC__METADATA_TYPE_APPLICATION:
  88055. if(real_length > 0) {
  88056. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88057. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88058. return false;
  88059. }
  88060. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88061. return false; /* read_callback_ sets the state for us */
  88062. }
  88063. else
  88064. block.data.application.data = 0;
  88065. break;
  88066. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88067. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88068. return false;
  88069. break;
  88070. case FLAC__METADATA_TYPE_CUESHEET:
  88071. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88072. return false;
  88073. break;
  88074. case FLAC__METADATA_TYPE_PICTURE:
  88075. if(!read_metadata_picture_(decoder, &block.data.picture))
  88076. return false;
  88077. break;
  88078. case FLAC__METADATA_TYPE_STREAMINFO:
  88079. case FLAC__METADATA_TYPE_SEEKTABLE:
  88080. FLAC__ASSERT(0);
  88081. break;
  88082. default:
  88083. if(real_length > 0) {
  88084. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88085. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88086. return false;
  88087. }
  88088. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88089. return false; /* read_callback_ sets the state for us */
  88090. }
  88091. else
  88092. block.data.unknown.data = 0;
  88093. break;
  88094. }
  88095. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88096. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88097. switch(type) {
  88098. case FLAC__METADATA_TYPE_PADDING:
  88099. break;
  88100. case FLAC__METADATA_TYPE_APPLICATION:
  88101. if(0 != block.data.application.data)
  88102. free(block.data.application.data);
  88103. break;
  88104. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88105. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88106. free(block.data.vorbis_comment.vendor_string.entry);
  88107. if(block.data.vorbis_comment.num_comments > 0)
  88108. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88109. if(0 != block.data.vorbis_comment.comments[i].entry)
  88110. free(block.data.vorbis_comment.comments[i].entry);
  88111. if(0 != block.data.vorbis_comment.comments)
  88112. free(block.data.vorbis_comment.comments);
  88113. break;
  88114. case FLAC__METADATA_TYPE_CUESHEET:
  88115. if(block.data.cue_sheet.num_tracks > 0)
  88116. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88117. if(0 != block.data.cue_sheet.tracks[i].indices)
  88118. free(block.data.cue_sheet.tracks[i].indices);
  88119. if(0 != block.data.cue_sheet.tracks)
  88120. free(block.data.cue_sheet.tracks);
  88121. break;
  88122. case FLAC__METADATA_TYPE_PICTURE:
  88123. if(0 != block.data.picture.mime_type)
  88124. free(block.data.picture.mime_type);
  88125. if(0 != block.data.picture.description)
  88126. free(block.data.picture.description);
  88127. if(0 != block.data.picture.data)
  88128. free(block.data.picture.data);
  88129. break;
  88130. case FLAC__METADATA_TYPE_STREAMINFO:
  88131. case FLAC__METADATA_TYPE_SEEKTABLE:
  88132. FLAC__ASSERT(0);
  88133. default:
  88134. if(0 != block.data.unknown.data)
  88135. free(block.data.unknown.data);
  88136. break;
  88137. }
  88138. }
  88139. }
  88140. if(is_last) {
  88141. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88142. decoder->private_->first_frame_offset = 0;
  88143. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88144. }
  88145. return true;
  88146. }
  88147. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88148. {
  88149. FLAC__uint32 x;
  88150. unsigned bits, used_bits = 0;
  88151. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88152. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88153. decoder->private_->stream_info.is_last = is_last;
  88154. decoder->private_->stream_info.length = length;
  88155. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88156. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88157. return false; /* read_callback_ sets the state for us */
  88158. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88159. used_bits += bits;
  88160. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88161. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88162. return false; /* read_callback_ sets the state for us */
  88163. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88164. used_bits += bits;
  88165. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88166. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88167. return false; /* read_callback_ sets the state for us */
  88168. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88169. used_bits += bits;
  88170. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88171. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88172. return false; /* read_callback_ sets the state for us */
  88173. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88174. used_bits += bits;
  88175. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88176. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88177. return false; /* read_callback_ sets the state for us */
  88178. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88179. used_bits += bits;
  88180. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88181. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88182. return false; /* read_callback_ sets the state for us */
  88183. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88184. used_bits += bits;
  88185. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88186. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88187. return false; /* read_callback_ sets the state for us */
  88188. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88189. used_bits += bits;
  88190. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88191. 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))
  88192. return false; /* read_callback_ sets the state for us */
  88193. used_bits += bits;
  88194. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88195. return false; /* read_callback_ sets the state for us */
  88196. used_bits += 16*8;
  88197. FLAC__ASSERT(used_bits % 8 == 0);
  88198. length -= (used_bits / 8);
  88199. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88200. return false; /* read_callback_ sets the state for us */
  88201. return true;
  88202. }
  88203. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88204. {
  88205. FLAC__uint32 i, x;
  88206. FLAC__uint64 xx;
  88207. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88208. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88209. decoder->private_->seek_table.is_last = is_last;
  88210. decoder->private_->seek_table.length = length;
  88211. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88212. 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)))) {
  88213. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88214. return false;
  88215. }
  88216. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88217. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88218. return false; /* read_callback_ sets the state for us */
  88219. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88220. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88221. return false; /* read_callback_ sets the state for us */
  88222. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88223. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88224. return false; /* read_callback_ sets the state for us */
  88225. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88226. }
  88227. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88228. if(length > 0) {
  88229. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88230. return false; /* read_callback_ sets the state for us */
  88231. }
  88232. return true;
  88233. }
  88234. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88235. {
  88236. FLAC__uint32 i;
  88237. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88238. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88239. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88240. return false; /* read_callback_ sets the state for us */
  88241. if(obj->vendor_string.length > 0) {
  88242. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88243. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88244. return false;
  88245. }
  88246. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88247. return false; /* read_callback_ sets the state for us */
  88248. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88249. }
  88250. else
  88251. obj->vendor_string.entry = 0;
  88252. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88253. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88254. return false; /* read_callback_ sets the state for us */
  88255. if(obj->num_comments > 0) {
  88256. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88257. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88258. return false;
  88259. }
  88260. for(i = 0; i < obj->num_comments; i++) {
  88261. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88262. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88263. return false; /* read_callback_ sets the state for us */
  88264. if(obj->comments[i].length > 0) {
  88265. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88266. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88267. return false;
  88268. }
  88269. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88270. return false; /* read_callback_ sets the state for us */
  88271. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88272. }
  88273. else
  88274. obj->comments[i].entry = 0;
  88275. }
  88276. }
  88277. else {
  88278. obj->comments = 0;
  88279. }
  88280. return true;
  88281. }
  88282. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88283. {
  88284. FLAC__uint32 i, j, x;
  88285. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88286. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88287. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88288. 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))
  88289. return false; /* read_callback_ sets the state for us */
  88290. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88291. return false; /* read_callback_ sets the state for us */
  88292. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88293. return false; /* read_callback_ sets the state for us */
  88294. obj->is_cd = x? true : false;
  88295. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88296. return false; /* read_callback_ sets the state for us */
  88297. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88298. return false; /* read_callback_ sets the state for us */
  88299. obj->num_tracks = x;
  88300. if(obj->num_tracks > 0) {
  88301. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88302. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88303. return false;
  88304. }
  88305. for(i = 0; i < obj->num_tracks; i++) {
  88306. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88307. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88308. return false; /* read_callback_ sets the state for us */
  88309. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88310. return false; /* read_callback_ sets the state for us */
  88311. track->number = (FLAC__byte)x;
  88312. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88313. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88314. return false; /* read_callback_ sets the state for us */
  88315. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88316. return false; /* read_callback_ sets the state for us */
  88317. track->type = x;
  88318. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88319. return false; /* read_callback_ sets the state for us */
  88320. track->pre_emphasis = x;
  88321. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88322. return false; /* read_callback_ sets the state for us */
  88323. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88324. return false; /* read_callback_ sets the state for us */
  88325. track->num_indices = (FLAC__byte)x;
  88326. if(track->num_indices > 0) {
  88327. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88328. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88329. return false;
  88330. }
  88331. for(j = 0; j < track->num_indices; j++) {
  88332. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88333. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88334. return false; /* read_callback_ sets the state for us */
  88335. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88336. return false; /* read_callback_ sets the state for us */
  88337. index->number = (FLAC__byte)x;
  88338. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88339. return false; /* read_callback_ sets the state for us */
  88340. }
  88341. }
  88342. }
  88343. }
  88344. return true;
  88345. }
  88346. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88347. {
  88348. FLAC__uint32 x;
  88349. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88350. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88351. return false; /* read_callback_ sets the state for us */
  88352. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88353. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88354. return false; /* read_callback_ sets the state for us */
  88355. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88356. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88357. return false;
  88358. }
  88359. if(x > 0) {
  88360. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88361. return false; /* read_callback_ sets the state for us */
  88362. }
  88363. obj->mime_type[x] = '\0';
  88364. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88365. return false; /* read_callback_ sets the state for us */
  88366. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88367. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88368. return false;
  88369. }
  88370. if(x > 0) {
  88371. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88372. return false; /* read_callback_ sets the state for us */
  88373. }
  88374. obj->description[x] = '\0';
  88375. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88376. return false; /* read_callback_ sets the state for us */
  88377. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88378. return false; /* read_callback_ sets the state for us */
  88379. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88380. return false; /* read_callback_ sets the state for us */
  88381. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88382. return false; /* read_callback_ sets the state for us */
  88383. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88384. return false; /* read_callback_ sets the state for us */
  88385. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88386. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88387. return false;
  88388. }
  88389. if(obj->data_length > 0) {
  88390. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88391. return false; /* read_callback_ sets the state for us */
  88392. }
  88393. return true;
  88394. }
  88395. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88396. {
  88397. FLAC__uint32 x;
  88398. unsigned i, skip;
  88399. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88400. return false; /* read_callback_ sets the state for us */
  88401. skip = 0;
  88402. for(i = 0; i < 4; i++) {
  88403. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88404. return false; /* read_callback_ sets the state for us */
  88405. skip <<= 7;
  88406. skip |= (x & 0x7f);
  88407. }
  88408. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88409. return false; /* read_callback_ sets the state for us */
  88410. return true;
  88411. }
  88412. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88413. {
  88414. FLAC__uint32 x;
  88415. FLAC__bool first = true;
  88416. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88417. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88418. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88419. return true;
  88420. }
  88421. }
  88422. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88423. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88424. return false; /* read_callback_ sets the state for us */
  88425. }
  88426. while(1) {
  88427. if(decoder->private_->cached) {
  88428. x = (FLAC__uint32)decoder->private_->lookahead;
  88429. decoder->private_->cached = false;
  88430. }
  88431. else {
  88432. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88433. return false; /* read_callback_ sets the state for us */
  88434. }
  88435. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88436. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88437. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88438. return false; /* read_callback_ sets the state for us */
  88439. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88440. decoder->private_->lookahead = (FLAC__byte)x;
  88441. decoder->private_->cached = true;
  88442. }
  88443. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88444. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88445. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88446. return true;
  88447. }
  88448. }
  88449. if(first) {
  88450. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88451. first = false;
  88452. }
  88453. }
  88454. return true;
  88455. }
  88456. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88457. {
  88458. unsigned channel;
  88459. unsigned i;
  88460. FLAC__int32 mid, side;
  88461. unsigned frame_crc; /* the one we calculate from the input stream */
  88462. FLAC__uint32 x;
  88463. *got_a_frame = false;
  88464. frame_crc = 0;
  88465. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88466. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88467. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88468. if(!read_frame_header_(decoder))
  88469. return false;
  88470. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88471. return true;
  88472. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88473. return false;
  88474. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88475. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88476. switch(decoder->private_->frame.header.channel_assignment) {
  88477. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88478. break;
  88479. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88480. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88481. if(channel == 1)
  88482. bps++;
  88483. break;
  88484. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88485. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88486. if(channel == 0)
  88487. bps++;
  88488. break;
  88489. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88490. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88491. if(channel == 1)
  88492. bps++;
  88493. break;
  88494. default:
  88495. FLAC__ASSERT(0);
  88496. }
  88497. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88498. return false;
  88499. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88500. return true;
  88501. }
  88502. if(!read_zero_padding_(decoder))
  88503. return false;
  88504. 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) */
  88505. return true;
  88506. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88507. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88508. return false; /* read_callback_ sets the state for us */
  88509. if(frame_crc == x) {
  88510. if(do_full_decode) {
  88511. switch(decoder->private_->frame.header.channel_assignment) {
  88512. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88513. break;
  88514. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88515. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88516. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88517. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88518. break;
  88519. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88520. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88521. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88522. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88523. break;
  88524. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88525. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88526. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88527. #if 1
  88528. mid = decoder->private_->output[0][i];
  88529. side = decoder->private_->output[1][i];
  88530. mid <<= 1;
  88531. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88532. decoder->private_->output[0][i] = (mid + side) >> 1;
  88533. decoder->private_->output[1][i] = (mid - side) >> 1;
  88534. #else
  88535. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88536. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88537. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88538. #endif
  88539. }
  88540. break;
  88541. default:
  88542. FLAC__ASSERT(0);
  88543. break;
  88544. }
  88545. }
  88546. }
  88547. else {
  88548. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88549. if(do_full_decode) {
  88550. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88551. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88552. }
  88553. }
  88554. }
  88555. *got_a_frame = true;
  88556. if(decoder->private_->next_fixed_block_size)
  88557. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88558. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88559. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88560. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88561. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88562. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88563. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88564. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88565. if(do_full_decode) {
  88566. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88567. return false;
  88568. }
  88569. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88570. return true;
  88571. }
  88572. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88573. {
  88574. FLAC__uint32 x;
  88575. FLAC__uint64 xx;
  88576. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88577. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88578. unsigned raw_header_len;
  88579. FLAC__bool is_unparseable = false;
  88580. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88581. raw_header[0] = decoder->private_->header_warmup[0];
  88582. raw_header[1] = decoder->private_->header_warmup[1];
  88583. raw_header_len = 2;
  88584. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88585. is_unparseable = true;
  88586. for(i = 0; i < 2; i++) {
  88587. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88588. return false; /* read_callback_ sets the state for us */
  88589. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88590. decoder->private_->lookahead = (FLAC__byte)x;
  88591. decoder->private_->cached = true;
  88592. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88593. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88594. return true;
  88595. }
  88596. raw_header[raw_header_len++] = (FLAC__byte)x;
  88597. }
  88598. switch(x = raw_header[2] >> 4) {
  88599. case 0:
  88600. is_unparseable = true;
  88601. break;
  88602. case 1:
  88603. decoder->private_->frame.header.blocksize = 192;
  88604. break;
  88605. case 2:
  88606. case 3:
  88607. case 4:
  88608. case 5:
  88609. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88610. break;
  88611. case 6:
  88612. case 7:
  88613. blocksize_hint = x;
  88614. break;
  88615. case 8:
  88616. case 9:
  88617. case 10:
  88618. case 11:
  88619. case 12:
  88620. case 13:
  88621. case 14:
  88622. case 15:
  88623. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88624. break;
  88625. default:
  88626. FLAC__ASSERT(0);
  88627. break;
  88628. }
  88629. switch(x = raw_header[2] & 0x0f) {
  88630. case 0:
  88631. if(decoder->private_->has_stream_info)
  88632. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88633. else
  88634. is_unparseable = true;
  88635. break;
  88636. case 1:
  88637. decoder->private_->frame.header.sample_rate = 88200;
  88638. break;
  88639. case 2:
  88640. decoder->private_->frame.header.sample_rate = 176400;
  88641. break;
  88642. case 3:
  88643. decoder->private_->frame.header.sample_rate = 192000;
  88644. break;
  88645. case 4:
  88646. decoder->private_->frame.header.sample_rate = 8000;
  88647. break;
  88648. case 5:
  88649. decoder->private_->frame.header.sample_rate = 16000;
  88650. break;
  88651. case 6:
  88652. decoder->private_->frame.header.sample_rate = 22050;
  88653. break;
  88654. case 7:
  88655. decoder->private_->frame.header.sample_rate = 24000;
  88656. break;
  88657. case 8:
  88658. decoder->private_->frame.header.sample_rate = 32000;
  88659. break;
  88660. case 9:
  88661. decoder->private_->frame.header.sample_rate = 44100;
  88662. break;
  88663. case 10:
  88664. decoder->private_->frame.header.sample_rate = 48000;
  88665. break;
  88666. case 11:
  88667. decoder->private_->frame.header.sample_rate = 96000;
  88668. break;
  88669. case 12:
  88670. case 13:
  88671. case 14:
  88672. sample_rate_hint = x;
  88673. break;
  88674. case 15:
  88675. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88676. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88677. return true;
  88678. default:
  88679. FLAC__ASSERT(0);
  88680. }
  88681. x = (unsigned)(raw_header[3] >> 4);
  88682. if(x & 8) {
  88683. decoder->private_->frame.header.channels = 2;
  88684. switch(x & 7) {
  88685. case 0:
  88686. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88687. break;
  88688. case 1:
  88689. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88690. break;
  88691. case 2:
  88692. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88693. break;
  88694. default:
  88695. is_unparseable = true;
  88696. break;
  88697. }
  88698. }
  88699. else {
  88700. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88701. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88702. }
  88703. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88704. case 0:
  88705. if(decoder->private_->has_stream_info)
  88706. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88707. else
  88708. is_unparseable = true;
  88709. break;
  88710. case 1:
  88711. decoder->private_->frame.header.bits_per_sample = 8;
  88712. break;
  88713. case 2:
  88714. decoder->private_->frame.header.bits_per_sample = 12;
  88715. break;
  88716. case 4:
  88717. decoder->private_->frame.header.bits_per_sample = 16;
  88718. break;
  88719. case 5:
  88720. decoder->private_->frame.header.bits_per_sample = 20;
  88721. break;
  88722. case 6:
  88723. decoder->private_->frame.header.bits_per_sample = 24;
  88724. break;
  88725. case 3:
  88726. case 7:
  88727. is_unparseable = true;
  88728. break;
  88729. default:
  88730. FLAC__ASSERT(0);
  88731. break;
  88732. }
  88733. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88734. is_unparseable = true;
  88735. if(
  88736. raw_header[1] & 0x01 ||
  88737. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88738. ) { /* variable blocksize */
  88739. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88740. return false; /* read_callback_ sets the state for us */
  88741. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88742. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88743. decoder->private_->cached = true;
  88744. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88745. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88746. return true;
  88747. }
  88748. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88749. decoder->private_->frame.header.number.sample_number = xx;
  88750. }
  88751. else { /* fixed blocksize */
  88752. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88753. return false; /* read_callback_ sets the state for us */
  88754. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88755. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88756. decoder->private_->cached = true;
  88757. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88758. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88759. return true;
  88760. }
  88761. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88762. decoder->private_->frame.header.number.frame_number = x;
  88763. }
  88764. if(blocksize_hint) {
  88765. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88766. return false; /* read_callback_ sets the state for us */
  88767. raw_header[raw_header_len++] = (FLAC__byte)x;
  88768. if(blocksize_hint == 7) {
  88769. FLAC__uint32 _x;
  88770. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88771. return false; /* read_callback_ sets the state for us */
  88772. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88773. x = (x << 8) | _x;
  88774. }
  88775. decoder->private_->frame.header.blocksize = x+1;
  88776. }
  88777. if(sample_rate_hint) {
  88778. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88779. return false; /* read_callback_ sets the state for us */
  88780. raw_header[raw_header_len++] = (FLAC__byte)x;
  88781. if(sample_rate_hint != 12) {
  88782. FLAC__uint32 _x;
  88783. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88784. return false; /* read_callback_ sets the state for us */
  88785. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88786. x = (x << 8) | _x;
  88787. }
  88788. if(sample_rate_hint == 12)
  88789. decoder->private_->frame.header.sample_rate = x*1000;
  88790. else if(sample_rate_hint == 13)
  88791. decoder->private_->frame.header.sample_rate = x;
  88792. else
  88793. decoder->private_->frame.header.sample_rate = x*10;
  88794. }
  88795. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88796. return false; /* read_callback_ sets the state for us */
  88797. crc8 = (FLAC__byte)x;
  88798. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88799. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88800. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88801. return true;
  88802. }
  88803. decoder->private_->next_fixed_block_size = 0;
  88804. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88805. x = decoder->private_->frame.header.number.frame_number;
  88806. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88807. if(decoder->private_->fixed_block_size)
  88808. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88809. else if(decoder->private_->has_stream_info) {
  88810. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88811. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88812. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88813. }
  88814. else
  88815. is_unparseable = true;
  88816. }
  88817. else if(x == 0) {
  88818. decoder->private_->frame.header.number.sample_number = 0;
  88819. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88820. }
  88821. else {
  88822. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88823. }
  88824. }
  88825. if(is_unparseable) {
  88826. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88827. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88828. return true;
  88829. }
  88830. return true;
  88831. }
  88832. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88833. {
  88834. FLAC__uint32 x;
  88835. FLAC__bool wasted_bits;
  88836. unsigned i;
  88837. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88838. return false; /* read_callback_ sets the state for us */
  88839. wasted_bits = (x & 1);
  88840. x &= 0xfe;
  88841. if(wasted_bits) {
  88842. unsigned u;
  88843. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88844. return false; /* read_callback_ sets the state for us */
  88845. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88846. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88847. }
  88848. else
  88849. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88850. if(x & 0x80) {
  88851. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88852. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88853. return true;
  88854. }
  88855. else if(x == 0) {
  88856. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88857. return false;
  88858. }
  88859. else if(x == 2) {
  88860. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88861. return false;
  88862. }
  88863. else if(x < 16) {
  88864. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88865. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88866. return true;
  88867. }
  88868. else if(x <= 24) {
  88869. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88870. return false;
  88871. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88872. return true;
  88873. }
  88874. else if(x < 64) {
  88875. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88876. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88877. return true;
  88878. }
  88879. else {
  88880. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  88881. return false;
  88882. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88883. return true;
  88884. }
  88885. if(wasted_bits && do_full_decode) {
  88886. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88887. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88888. decoder->private_->output[channel][i] <<= x;
  88889. }
  88890. return true;
  88891. }
  88892. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88893. {
  88894. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88895. FLAC__int32 x;
  88896. unsigned i;
  88897. FLAC__int32 *output = decoder->private_->output[channel];
  88898. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88899. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88900. return false; /* read_callback_ sets the state for us */
  88901. subframe->value = x;
  88902. if(do_full_decode) {
  88903. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88904. output[i] = x;
  88905. }
  88906. return true;
  88907. }
  88908. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88909. {
  88910. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88911. FLAC__int32 i32;
  88912. FLAC__uint32 u32;
  88913. unsigned u;
  88914. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88915. subframe->residual = decoder->private_->residual[channel];
  88916. subframe->order = order;
  88917. for(u = 0; u < order; u++) {
  88918. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88919. return false; /* read_callback_ sets the state for us */
  88920. subframe->warmup[u] = i32;
  88921. }
  88922. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88923. return false; /* read_callback_ sets the state for us */
  88924. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88925. switch(subframe->entropy_coding_method.type) {
  88926. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88927. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88928. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88929. return false; /* read_callback_ sets the state for us */
  88930. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88931. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88932. break;
  88933. default:
  88934. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88935. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88936. return true;
  88937. }
  88938. switch(subframe->entropy_coding_method.type) {
  88939. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88940. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88941. 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))
  88942. return false;
  88943. break;
  88944. default:
  88945. FLAC__ASSERT(0);
  88946. }
  88947. if(do_full_decode) {
  88948. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88949. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  88950. }
  88951. return true;
  88952. }
  88953. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88954. {
  88955. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  88956. FLAC__int32 i32;
  88957. FLAC__uint32 u32;
  88958. unsigned u;
  88959. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  88960. subframe->residual = decoder->private_->residual[channel];
  88961. subframe->order = order;
  88962. for(u = 0; u < order; u++) {
  88963. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88964. return false; /* read_callback_ sets the state for us */
  88965. subframe->warmup[u] = i32;
  88966. }
  88967. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  88968. return false; /* read_callback_ sets the state for us */
  88969. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  88970. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88971. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88972. return true;
  88973. }
  88974. subframe->qlp_coeff_precision = u32+1;
  88975. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  88976. return false; /* read_callback_ sets the state for us */
  88977. subframe->quantization_level = i32;
  88978. for(u = 0; u < order; u++) {
  88979. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  88980. return false; /* read_callback_ sets the state for us */
  88981. subframe->qlp_coeff[u] = i32;
  88982. }
  88983. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88984. return false; /* read_callback_ sets the state for us */
  88985. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88986. switch(subframe->entropy_coding_method.type) {
  88987. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88988. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88989. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88990. return false; /* read_callback_ sets the state for us */
  88991. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88992. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88993. break;
  88994. default:
  88995. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88996. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88997. return true;
  88998. }
  88999. switch(subframe->entropy_coding_method.type) {
  89000. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89001. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89002. 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))
  89003. return false;
  89004. break;
  89005. default:
  89006. FLAC__ASSERT(0);
  89007. }
  89008. if(do_full_decode) {
  89009. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89010. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89011. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89012. if(order <= 8)
  89013. 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);
  89014. else
  89015. 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);
  89016. }
  89017. else
  89018. 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);
  89019. else
  89020. 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);
  89021. }
  89022. return true;
  89023. }
  89024. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89025. {
  89026. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89027. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89028. unsigned i;
  89029. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89030. subframe->data = residual;
  89031. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89032. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89033. return false; /* read_callback_ sets the state for us */
  89034. residual[i] = x;
  89035. }
  89036. if(do_full_decode)
  89037. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89038. return true;
  89039. }
  89040. 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)
  89041. {
  89042. FLAC__uint32 rice_parameter;
  89043. int i;
  89044. unsigned partition, sample, u;
  89045. const unsigned partitions = 1u << partition_order;
  89046. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89047. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89048. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89049. if(partition_order == 0) {
  89050. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89051. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89052. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89053. return true;
  89054. }
  89055. }
  89056. else {
  89057. if(partition_samples < predictor_order) {
  89058. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89059. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89060. return true;
  89061. }
  89062. }
  89063. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89064. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89065. return false;
  89066. }
  89067. sample = 0;
  89068. for(partition = 0; partition < partitions; partition++) {
  89069. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89070. return false; /* read_callback_ sets the state for us */
  89071. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89072. if(rice_parameter < pesc) {
  89073. partitioned_rice_contents->raw_bits[partition] = 0;
  89074. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89075. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89076. return false; /* read_callback_ sets the state for us */
  89077. sample += u;
  89078. }
  89079. else {
  89080. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89081. return false; /* read_callback_ sets the state for us */
  89082. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89083. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89084. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89085. return false; /* read_callback_ sets the state for us */
  89086. residual[sample] = i;
  89087. }
  89088. }
  89089. }
  89090. return true;
  89091. }
  89092. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89093. {
  89094. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89095. FLAC__uint32 zero = 0;
  89096. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89097. return false; /* read_callback_ sets the state for us */
  89098. if(zero != 0) {
  89099. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89100. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89101. }
  89102. }
  89103. return true;
  89104. }
  89105. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89106. {
  89107. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89108. if(
  89109. #if FLAC__HAS_OGG
  89110. !decoder->private_->is_ogg &&
  89111. #endif
  89112. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89113. ) {
  89114. *bytes = 0;
  89115. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89116. return false;
  89117. }
  89118. else if(*bytes > 0) {
  89119. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89120. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89121. return false;
  89122. }
  89123. else {
  89124. const FLAC__StreamDecoderReadStatus status =
  89125. #if FLAC__HAS_OGG
  89126. decoder->private_->is_ogg?
  89127. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89128. #endif
  89129. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89130. ;
  89131. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89132. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89133. return false;
  89134. }
  89135. else if(*bytes == 0) {
  89136. if(
  89137. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89138. (
  89139. #if FLAC__HAS_OGG
  89140. !decoder->private_->is_ogg &&
  89141. #endif
  89142. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89143. )
  89144. ) {
  89145. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89146. return false;
  89147. }
  89148. else
  89149. return true;
  89150. }
  89151. else
  89152. return true;
  89153. }
  89154. }
  89155. else {
  89156. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89157. return false;
  89158. }
  89159. }
  89160. #if FLAC__HAS_OGG
  89161. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89162. {
  89163. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89164. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89165. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89166. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89167. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89168. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89169. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89170. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89171. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89172. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89173. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89174. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89175. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89176. default:
  89177. FLAC__ASSERT(0);
  89178. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89179. }
  89180. }
  89181. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89182. {
  89183. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89184. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89185. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89186. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89187. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89188. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89189. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89190. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89191. default:
  89192. FLAC__ASSERT(0);
  89193. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89194. }
  89195. }
  89196. #endif
  89197. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89198. {
  89199. if(decoder->private_->is_seeking) {
  89200. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89201. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89202. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89203. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89204. #if FLAC__HAS_OGG
  89205. decoder->private_->got_a_frame = true;
  89206. #endif
  89207. decoder->private_->last_frame = *frame; /* save the frame */
  89208. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89209. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89210. decoder->private_->is_seeking = false;
  89211. if(delta > 0) {
  89212. unsigned channel;
  89213. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89214. for(channel = 0; channel < frame->header.channels; channel++)
  89215. newbuffer[channel] = buffer[channel] + delta;
  89216. decoder->private_->last_frame.header.blocksize -= delta;
  89217. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89218. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89219. }
  89220. else {
  89221. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89222. }
  89223. }
  89224. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89225. }
  89226. if(!decoder->private_->has_stream_info)
  89227. decoder->private_->do_md5_checking = false;
  89228. if(decoder->private_->do_md5_checking) {
  89229. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89230. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89231. }
  89232. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89233. }
  89234. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89235. {
  89236. if(!decoder->private_->is_seeking)
  89237. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89238. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89239. decoder->private_->unparseable_frame_count++;
  89240. }
  89241. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89242. {
  89243. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89244. FLAC__int64 pos = -1;
  89245. int i;
  89246. unsigned approx_bytes_per_frame;
  89247. FLAC__bool first_seek = true;
  89248. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89249. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89250. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89251. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89252. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89253. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89254. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89255. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89256. if(channels == 0)
  89257. channels = decoder->private_->stream_info.data.stream_info.channels;
  89258. if(bps == 0)
  89259. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89260. if(max_framesize > 0)
  89261. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89262. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89263. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89264. }
  89265. else
  89266. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89267. lower_bound = first_frame_offset;
  89268. lower_bound_sample = 0;
  89269. upper_bound = stream_length;
  89270. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89271. if(seek_table) {
  89272. FLAC__uint64 new_lower_bound = lower_bound;
  89273. FLAC__uint64 new_upper_bound = upper_bound;
  89274. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89275. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89276. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89277. if(
  89278. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89279. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89280. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89281. seek_table->points[i].sample_number <= target_sample
  89282. )
  89283. break;
  89284. }
  89285. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89286. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89287. new_lower_bound_sample = seek_table->points[i].sample_number;
  89288. }
  89289. for(i = 0; i < (int)seek_table->num_points; i++) {
  89290. if(
  89291. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89292. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89293. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89294. seek_table->points[i].sample_number > target_sample
  89295. )
  89296. break;
  89297. }
  89298. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89299. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89300. new_upper_bound_sample = seek_table->points[i].sample_number;
  89301. }
  89302. if(new_upper_bound >= new_lower_bound) {
  89303. lower_bound = new_lower_bound;
  89304. upper_bound = new_upper_bound;
  89305. lower_bound_sample = new_lower_bound_sample;
  89306. upper_bound_sample = new_upper_bound_sample;
  89307. }
  89308. }
  89309. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89310. if(upper_bound_sample == lower_bound_sample)
  89311. upper_bound_sample++;
  89312. decoder->private_->target_sample = target_sample;
  89313. while(1) {
  89314. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89315. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89316. return false;
  89317. }
  89318. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89319. #if defined _MSC_VER || defined __MINGW32__
  89320. 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;
  89321. #else
  89322. 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;
  89323. #endif
  89324. #else
  89325. if(upper_bound - lower_bound < 0xffffffff)
  89326. 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;
  89327. else /* @@@ WATCHOUT, ~2TB limit */
  89328. 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;
  89329. #endif
  89330. if(pos >= (FLAC__int64)upper_bound)
  89331. pos = (FLAC__int64)upper_bound - 1;
  89332. if(pos < (FLAC__int64)lower_bound)
  89333. pos = (FLAC__int64)lower_bound;
  89334. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89335. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89336. return false;
  89337. }
  89338. if(!FLAC__stream_decoder_flush(decoder)) {
  89339. return false;
  89340. }
  89341. decoder->private_->unparseable_frame_count = 0;
  89342. if(!FLAC__stream_decoder_process_single(decoder)) {
  89343. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89344. return false;
  89345. }
  89346. #if 0
  89347. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89348. break;
  89349. #endif
  89350. if(!decoder->private_->is_seeking)
  89351. break;
  89352. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89353. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89354. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89355. if (pos == (FLAC__int64)lower_bound) {
  89356. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89357. return false;
  89358. }
  89359. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89360. continue;
  89361. }
  89362. first_seek = false;
  89363. if (this_frame_sample < lower_bound_sample) {
  89364. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89365. return false;
  89366. }
  89367. if(target_sample < this_frame_sample) {
  89368. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89369. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89370. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89371. return false;
  89372. }
  89373. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89374. }
  89375. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89376. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89377. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89378. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89379. return false;
  89380. }
  89381. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89382. }
  89383. }
  89384. return true;
  89385. }
  89386. #if FLAC__HAS_OGG
  89387. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89388. {
  89389. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89390. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89391. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89392. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89393. FLAC__bool did_a_seek;
  89394. unsigned iteration = 0;
  89395. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89396. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89397. if(right_sample == 0) {
  89398. right_sample = (FLAC__uint64)(-1);
  89399. BINARY_SEARCH_AFTER_ITERATION = 0;
  89400. }
  89401. decoder->private_->target_sample = target_sample;
  89402. for( ; ; iteration++) {
  89403. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89404. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89405. pos = (right_pos + left_pos) / 2;
  89406. }
  89407. else {
  89408. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89409. #if defined _MSC_VER || defined __MINGW32__
  89410. 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));
  89411. #else
  89412. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89413. #endif
  89414. #else
  89415. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89416. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89417. else /* @@@ WATCHOUT, ~2TB limit */
  89418. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89419. #endif
  89420. }
  89421. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89422. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89423. return false;
  89424. }
  89425. if(!FLAC__stream_decoder_flush(decoder)) {
  89426. return false;
  89427. }
  89428. did_a_seek = true;
  89429. }
  89430. else
  89431. did_a_seek = false;
  89432. decoder->private_->got_a_frame = false;
  89433. if(!FLAC__stream_decoder_process_single(decoder)) {
  89434. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89435. return false;
  89436. }
  89437. if(!decoder->private_->got_a_frame) {
  89438. if(did_a_seek) {
  89439. right_pos = pos;
  89440. BINARY_SEARCH_AFTER_ITERATION = 0;
  89441. }
  89442. else {
  89443. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89444. return false;
  89445. }
  89446. }
  89447. else if(!decoder->private_->is_seeking) {
  89448. break;
  89449. }
  89450. else {
  89451. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89452. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89453. if (did_a_seek) {
  89454. if (this_frame_sample <= target_sample) {
  89455. FLAC__ASSERT(this_frame_sample != target_sample);
  89456. left_sample = this_frame_sample;
  89457. if (left_pos == pos) {
  89458. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89459. return false;
  89460. }
  89461. left_pos = pos;
  89462. }
  89463. else if(this_frame_sample > target_sample) {
  89464. right_sample = this_frame_sample;
  89465. if (right_pos == pos) {
  89466. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89467. return false;
  89468. }
  89469. right_pos = pos;
  89470. }
  89471. }
  89472. }
  89473. }
  89474. return true;
  89475. }
  89476. #endif
  89477. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89478. {
  89479. (void)client_data;
  89480. if(*bytes > 0) {
  89481. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89482. if(ferror(decoder->private_->file))
  89483. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89484. else if(*bytes == 0)
  89485. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89486. else
  89487. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89488. }
  89489. else
  89490. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89491. }
  89492. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89493. {
  89494. (void)client_data;
  89495. if(decoder->private_->file == stdin)
  89496. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89497. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89498. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89499. else
  89500. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89501. }
  89502. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89503. {
  89504. off_t pos;
  89505. (void)client_data;
  89506. if(decoder->private_->file == stdin)
  89507. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89508. else if((pos = ftello(decoder->private_->file)) < 0)
  89509. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89510. else {
  89511. *absolute_byte_offset = (FLAC__uint64)pos;
  89512. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89513. }
  89514. }
  89515. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89516. {
  89517. struct stat filestats;
  89518. (void)client_data;
  89519. if(decoder->private_->file == stdin)
  89520. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89521. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89522. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89523. else {
  89524. *stream_length = (FLAC__uint64)filestats.st_size;
  89525. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89526. }
  89527. }
  89528. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89529. {
  89530. (void)client_data;
  89531. return feof(decoder->private_->file)? true : false;
  89532. }
  89533. #endif
  89534. /*** End of inlined file: stream_decoder.c ***/
  89535. /*** Start of inlined file: stream_encoder.c ***/
  89536. /*** Start of inlined file: juce_FlacHeader.h ***/
  89537. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89538. // tasks..
  89539. #define VERSION "1.2.1"
  89540. #define FLAC__NO_DLL 1
  89541. #if JUCE_MSVC
  89542. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89543. #endif
  89544. #if JUCE_MAC
  89545. #define FLAC__SYS_DARWIN 1
  89546. #endif
  89547. /*** End of inlined file: juce_FlacHeader.h ***/
  89548. #if JUCE_USE_FLAC
  89549. #if HAVE_CONFIG_H
  89550. # include <config.h>
  89551. #endif
  89552. #if defined _MSC_VER || defined __MINGW32__
  89553. #include <io.h> /* for _setmode() */
  89554. #include <fcntl.h> /* for _O_BINARY */
  89555. #endif
  89556. #if defined __CYGWIN__ || defined __EMX__
  89557. #include <io.h> /* for setmode(), O_BINARY */
  89558. #include <fcntl.h> /* for _O_BINARY */
  89559. #endif
  89560. #include <limits.h>
  89561. #include <stdio.h>
  89562. #include <stdlib.h> /* for malloc() */
  89563. #include <string.h> /* for memcpy() */
  89564. #include <sys/types.h> /* for off_t */
  89565. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89566. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89567. #define fseeko fseek
  89568. #define ftello ftell
  89569. #endif
  89570. #endif
  89571. /*** Start of inlined file: stream_encoder.h ***/
  89572. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89573. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89574. #if FLAC__HAS_OGG
  89575. #include "private/ogg_encoder_aspect.h"
  89576. #endif
  89577. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89578. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89579. typedef enum {
  89580. FLAC__APODIZATION_BARTLETT,
  89581. FLAC__APODIZATION_BARTLETT_HANN,
  89582. FLAC__APODIZATION_BLACKMAN,
  89583. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89584. FLAC__APODIZATION_CONNES,
  89585. FLAC__APODIZATION_FLATTOP,
  89586. FLAC__APODIZATION_GAUSS,
  89587. FLAC__APODIZATION_HAMMING,
  89588. FLAC__APODIZATION_HANN,
  89589. FLAC__APODIZATION_KAISER_BESSEL,
  89590. FLAC__APODIZATION_NUTTALL,
  89591. FLAC__APODIZATION_RECTANGLE,
  89592. FLAC__APODIZATION_TRIANGLE,
  89593. FLAC__APODIZATION_TUKEY,
  89594. FLAC__APODIZATION_WELCH
  89595. } FLAC__ApodizationFunction;
  89596. typedef struct {
  89597. FLAC__ApodizationFunction type;
  89598. union {
  89599. struct {
  89600. FLAC__real stddev;
  89601. } gauss;
  89602. struct {
  89603. FLAC__real p;
  89604. } tukey;
  89605. } parameters;
  89606. } FLAC__ApodizationSpecification;
  89607. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89608. typedef struct FLAC__StreamEncoderProtected {
  89609. FLAC__StreamEncoderState state;
  89610. FLAC__bool verify;
  89611. FLAC__bool streamable_subset;
  89612. FLAC__bool do_md5;
  89613. FLAC__bool do_mid_side_stereo;
  89614. FLAC__bool loose_mid_side_stereo;
  89615. unsigned channels;
  89616. unsigned bits_per_sample;
  89617. unsigned sample_rate;
  89618. unsigned blocksize;
  89619. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89620. unsigned num_apodizations;
  89621. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89622. #endif
  89623. unsigned max_lpc_order;
  89624. unsigned qlp_coeff_precision;
  89625. FLAC__bool do_qlp_coeff_prec_search;
  89626. FLAC__bool do_exhaustive_model_search;
  89627. FLAC__bool do_escape_coding;
  89628. unsigned min_residual_partition_order;
  89629. unsigned max_residual_partition_order;
  89630. unsigned rice_parameter_search_dist;
  89631. FLAC__uint64 total_samples_estimate;
  89632. FLAC__StreamMetadata **metadata;
  89633. unsigned num_metadata_blocks;
  89634. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89635. #if FLAC__HAS_OGG
  89636. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89637. #endif
  89638. } FLAC__StreamEncoderProtected;
  89639. #endif
  89640. /*** End of inlined file: stream_encoder.h ***/
  89641. #if FLAC__HAS_OGG
  89642. #include "include/private/ogg_helper.h"
  89643. #include "include/private/ogg_mapping.h"
  89644. #endif
  89645. /*** Start of inlined file: stream_encoder_framing.h ***/
  89646. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89647. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89648. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89649. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89650. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89651. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89652. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89653. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89654. #endif
  89655. /*** End of inlined file: stream_encoder_framing.h ***/
  89656. /*** Start of inlined file: window.h ***/
  89657. #ifndef FLAC__PRIVATE__WINDOW_H
  89658. #define FLAC__PRIVATE__WINDOW_H
  89659. #ifdef HAVE_CONFIG_H
  89660. #include <config.h>
  89661. #endif
  89662. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89663. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89664. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89665. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89666. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89667. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89668. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89669. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89670. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89671. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89672. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89673. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89674. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89675. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89676. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89677. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89678. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89679. #endif
  89680. /*** End of inlined file: window.h ***/
  89681. #ifndef FLaC__INLINE
  89682. #define FLaC__INLINE
  89683. #endif
  89684. #ifdef min
  89685. #undef min
  89686. #endif
  89687. #define min(x,y) ((x)<(y)?(x):(y))
  89688. #ifdef max
  89689. #undef max
  89690. #endif
  89691. #define max(x,y) ((x)>(y)?(x):(y))
  89692. #undef EXACT_RICE_BITS_CALCULATION
  89693. #undef ENABLE_RICE_PARAMETER_SEARCH
  89694. typedef struct {
  89695. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89696. unsigned size; /* of each data[] in samples */
  89697. unsigned tail;
  89698. } verify_input_fifo;
  89699. typedef struct {
  89700. const FLAC__byte *data;
  89701. unsigned capacity;
  89702. unsigned bytes;
  89703. } verify_output;
  89704. typedef enum {
  89705. ENCODER_IN_MAGIC = 0,
  89706. ENCODER_IN_METADATA = 1,
  89707. ENCODER_IN_AUDIO = 2
  89708. } EncoderStateHint;
  89709. static struct CompressionLevels {
  89710. FLAC__bool do_mid_side_stereo;
  89711. FLAC__bool loose_mid_side_stereo;
  89712. unsigned max_lpc_order;
  89713. unsigned qlp_coeff_precision;
  89714. FLAC__bool do_qlp_coeff_prec_search;
  89715. FLAC__bool do_escape_coding;
  89716. FLAC__bool do_exhaustive_model_search;
  89717. unsigned min_residual_partition_order;
  89718. unsigned max_residual_partition_order;
  89719. unsigned rice_parameter_search_dist;
  89720. } compression_levels_[] = {
  89721. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89722. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89723. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89724. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89725. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89726. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89727. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89728. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89729. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89730. };
  89731. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89732. static void free_(FLAC__StreamEncoder *encoder);
  89733. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89734. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89735. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89736. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89737. #if FLAC__HAS_OGG
  89738. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89739. #endif
  89740. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89741. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89742. static FLAC__bool process_subframe_(
  89743. FLAC__StreamEncoder *encoder,
  89744. unsigned min_partition_order,
  89745. unsigned max_partition_order,
  89746. const FLAC__FrameHeader *frame_header,
  89747. unsigned subframe_bps,
  89748. const FLAC__int32 integer_signal[],
  89749. FLAC__Subframe *subframe[2],
  89750. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89751. FLAC__int32 *residual[2],
  89752. unsigned *best_subframe,
  89753. unsigned *best_bits
  89754. );
  89755. static FLAC__bool add_subframe_(
  89756. FLAC__StreamEncoder *encoder,
  89757. unsigned blocksize,
  89758. unsigned subframe_bps,
  89759. const FLAC__Subframe *subframe,
  89760. FLAC__BitWriter *frame
  89761. );
  89762. static unsigned evaluate_constant_subframe_(
  89763. FLAC__StreamEncoder *encoder,
  89764. const FLAC__int32 signal,
  89765. unsigned blocksize,
  89766. unsigned subframe_bps,
  89767. FLAC__Subframe *subframe
  89768. );
  89769. static unsigned evaluate_fixed_subframe_(
  89770. FLAC__StreamEncoder *encoder,
  89771. const FLAC__int32 signal[],
  89772. FLAC__int32 residual[],
  89773. FLAC__uint64 abs_residual_partition_sums[],
  89774. unsigned raw_bits_per_partition[],
  89775. unsigned blocksize,
  89776. unsigned subframe_bps,
  89777. unsigned order,
  89778. unsigned rice_parameter,
  89779. unsigned rice_parameter_limit,
  89780. unsigned min_partition_order,
  89781. unsigned max_partition_order,
  89782. FLAC__bool do_escape_coding,
  89783. unsigned rice_parameter_search_dist,
  89784. FLAC__Subframe *subframe,
  89785. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89786. );
  89787. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89788. static unsigned evaluate_lpc_subframe_(
  89789. FLAC__StreamEncoder *encoder,
  89790. const FLAC__int32 signal[],
  89791. FLAC__int32 residual[],
  89792. FLAC__uint64 abs_residual_partition_sums[],
  89793. unsigned raw_bits_per_partition[],
  89794. const FLAC__real lp_coeff[],
  89795. unsigned blocksize,
  89796. unsigned subframe_bps,
  89797. unsigned order,
  89798. unsigned qlp_coeff_precision,
  89799. unsigned rice_parameter,
  89800. unsigned rice_parameter_limit,
  89801. unsigned min_partition_order,
  89802. unsigned max_partition_order,
  89803. FLAC__bool do_escape_coding,
  89804. unsigned rice_parameter_search_dist,
  89805. FLAC__Subframe *subframe,
  89806. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89807. );
  89808. #endif
  89809. static unsigned evaluate_verbatim_subframe_(
  89810. FLAC__StreamEncoder *encoder,
  89811. const FLAC__int32 signal[],
  89812. unsigned blocksize,
  89813. unsigned subframe_bps,
  89814. FLAC__Subframe *subframe
  89815. );
  89816. static unsigned find_best_partition_order_(
  89817. struct FLAC__StreamEncoderPrivate *private_,
  89818. const FLAC__int32 residual[],
  89819. FLAC__uint64 abs_residual_partition_sums[],
  89820. unsigned raw_bits_per_partition[],
  89821. unsigned residual_samples,
  89822. unsigned predictor_order,
  89823. unsigned rice_parameter,
  89824. unsigned rice_parameter_limit,
  89825. unsigned min_partition_order,
  89826. unsigned max_partition_order,
  89827. unsigned bps,
  89828. FLAC__bool do_escape_coding,
  89829. unsigned rice_parameter_search_dist,
  89830. FLAC__EntropyCodingMethod *best_ecm
  89831. );
  89832. static void precompute_partition_info_sums_(
  89833. const FLAC__int32 residual[],
  89834. FLAC__uint64 abs_residual_partition_sums[],
  89835. unsigned residual_samples,
  89836. unsigned predictor_order,
  89837. unsigned min_partition_order,
  89838. unsigned max_partition_order,
  89839. unsigned bps
  89840. );
  89841. static void precompute_partition_info_escapes_(
  89842. const FLAC__int32 residual[],
  89843. unsigned raw_bits_per_partition[],
  89844. unsigned residual_samples,
  89845. unsigned predictor_order,
  89846. unsigned min_partition_order,
  89847. unsigned max_partition_order
  89848. );
  89849. static FLAC__bool set_partitioned_rice_(
  89850. #ifdef EXACT_RICE_BITS_CALCULATION
  89851. const FLAC__int32 residual[],
  89852. #endif
  89853. const FLAC__uint64 abs_residual_partition_sums[],
  89854. const unsigned raw_bits_per_partition[],
  89855. const unsigned residual_samples,
  89856. const unsigned predictor_order,
  89857. const unsigned suggested_rice_parameter,
  89858. const unsigned rice_parameter_limit,
  89859. const unsigned rice_parameter_search_dist,
  89860. const unsigned partition_order,
  89861. const FLAC__bool search_for_escapes,
  89862. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89863. unsigned *bits
  89864. );
  89865. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89866. static void append_to_verify_fifo_(
  89867. verify_input_fifo *fifo,
  89868. const FLAC__int32 * const input[],
  89869. unsigned input_offset,
  89870. unsigned channels,
  89871. unsigned wide_samples
  89872. );
  89873. static void append_to_verify_fifo_interleaved_(
  89874. verify_input_fifo *fifo,
  89875. const FLAC__int32 input[],
  89876. unsigned input_offset,
  89877. unsigned channels,
  89878. unsigned wide_samples
  89879. );
  89880. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89881. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89882. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89883. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89884. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89885. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89886. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89887. 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);
  89888. static FILE *get_binary_stdout_(void);
  89889. typedef struct FLAC__StreamEncoderPrivate {
  89890. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89891. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89892. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89893. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89894. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89895. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89896. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89897. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89898. #endif
  89899. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89900. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89901. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89902. FLAC__int32 *residual_workspace_mid_side[2][2];
  89903. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89904. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89905. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89906. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89907. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89908. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89909. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89910. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89911. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89912. unsigned best_subframe_mid_side[2];
  89913. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89914. unsigned best_subframe_bits_mid_side[2];
  89915. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89916. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89917. FLAC__BitWriter *frame; /* the current frame being worked on */
  89918. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89919. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89920. FLAC__ChannelAssignment last_channel_assignment;
  89921. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89922. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  89923. unsigned current_sample_number;
  89924. unsigned current_frame_number;
  89925. FLAC__MD5Context md5context;
  89926. FLAC__CPUInfo cpuinfo;
  89927. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89928. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89929. #else
  89930. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89931. #endif
  89932. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89933. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  89934. 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[]);
  89935. 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[]);
  89936. 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[]);
  89937. #endif
  89938. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  89939. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  89940. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  89941. FLAC__bool disable_constant_subframes;
  89942. FLAC__bool disable_fixed_subframes;
  89943. FLAC__bool disable_verbatim_subframes;
  89944. #if FLAC__HAS_OGG
  89945. FLAC__bool is_ogg;
  89946. #endif
  89947. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  89948. FLAC__StreamEncoderSeekCallback seek_callback;
  89949. FLAC__StreamEncoderTellCallback tell_callback;
  89950. FLAC__StreamEncoderWriteCallback write_callback;
  89951. FLAC__StreamEncoderMetadataCallback metadata_callback;
  89952. FLAC__StreamEncoderProgressCallback progress_callback;
  89953. void *client_data;
  89954. unsigned first_seekpoint_to_check;
  89955. FILE *file; /* only used when encoding to a file */
  89956. FLAC__uint64 bytes_written;
  89957. FLAC__uint64 samples_written;
  89958. unsigned frames_written;
  89959. unsigned total_frames_estimate;
  89960. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  89961. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  89962. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89963. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  89964. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  89965. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  89966. FLAC__real *windowed_signal_unaligned;
  89967. #endif
  89968. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  89969. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  89970. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  89971. unsigned *raw_bits_per_partition_unaligned;
  89972. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89973. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  89974. #endif
  89975. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  89976. struct {
  89977. FLAC__StreamDecoder *decoder;
  89978. EncoderStateHint state_hint;
  89979. FLAC__bool needs_magic_hack;
  89980. verify_input_fifo input_fifo;
  89981. verify_output output;
  89982. struct {
  89983. FLAC__uint64 absolute_sample;
  89984. unsigned frame_number;
  89985. unsigned channel;
  89986. unsigned sample;
  89987. FLAC__int32 expected;
  89988. FLAC__int32 got;
  89989. } error_stats;
  89990. } verify;
  89991. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  89992. } FLAC__StreamEncoderPrivate;
  89993. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  89994. "FLAC__STREAM_ENCODER_OK",
  89995. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  89996. "FLAC__STREAM_ENCODER_OGG_ERROR",
  89997. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  89998. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  89999. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  90000. "FLAC__STREAM_ENCODER_IO_ERROR",
  90001. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  90002. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  90003. };
  90004. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  90005. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  90006. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  90007. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  90008. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  90009. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  90010. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90011. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90012. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90013. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90014. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90015. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90016. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90017. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90018. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90019. };
  90020. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90021. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90022. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90023. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90024. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90025. };
  90026. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90027. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90028. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90029. };
  90030. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90031. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90032. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90033. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90034. };
  90035. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90036. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90037. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90038. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90039. };
  90040. static const unsigned OVERREAD_ = 1;
  90041. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90042. {
  90043. FLAC__StreamEncoder *encoder;
  90044. unsigned i;
  90045. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90046. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90047. if(encoder == 0) {
  90048. return 0;
  90049. }
  90050. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90051. if(encoder->protected_ == 0) {
  90052. free(encoder);
  90053. return 0;
  90054. }
  90055. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90056. if(encoder->private_ == 0) {
  90057. free(encoder->protected_);
  90058. free(encoder);
  90059. return 0;
  90060. }
  90061. encoder->private_->frame = FLAC__bitwriter_new();
  90062. if(encoder->private_->frame == 0) {
  90063. free(encoder->private_);
  90064. free(encoder->protected_);
  90065. free(encoder);
  90066. return 0;
  90067. }
  90068. encoder->private_->file = 0;
  90069. set_defaults_enc(encoder);
  90070. encoder->private_->is_being_deleted = false;
  90071. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90072. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90073. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90074. }
  90075. for(i = 0; i < 2; i++) {
  90076. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90077. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90078. }
  90079. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90080. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90081. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90082. }
  90083. for(i = 0; i < 2; i++) {
  90084. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90085. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90086. }
  90087. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90088. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90089. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90090. }
  90091. for(i = 0; i < 2; i++) {
  90092. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90093. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90094. }
  90095. for(i = 0; i < 2; i++)
  90096. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90097. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90098. return encoder;
  90099. }
  90100. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90101. {
  90102. unsigned i;
  90103. FLAC__ASSERT(0 != encoder);
  90104. FLAC__ASSERT(0 != encoder->protected_);
  90105. FLAC__ASSERT(0 != encoder->private_);
  90106. FLAC__ASSERT(0 != encoder->private_->frame);
  90107. encoder->private_->is_being_deleted = true;
  90108. (void)FLAC__stream_encoder_finish(encoder);
  90109. if(0 != encoder->private_->verify.decoder)
  90110. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90111. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90112. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90113. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90114. }
  90115. for(i = 0; i < 2; i++) {
  90116. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90117. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90118. }
  90119. for(i = 0; i < 2; i++)
  90120. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90121. FLAC__bitwriter_delete(encoder->private_->frame);
  90122. free(encoder->private_);
  90123. free(encoder->protected_);
  90124. free(encoder);
  90125. }
  90126. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90127. FLAC__StreamEncoder *encoder,
  90128. FLAC__StreamEncoderReadCallback read_callback,
  90129. FLAC__StreamEncoderWriteCallback write_callback,
  90130. FLAC__StreamEncoderSeekCallback seek_callback,
  90131. FLAC__StreamEncoderTellCallback tell_callback,
  90132. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90133. void *client_data,
  90134. FLAC__bool is_ogg
  90135. )
  90136. {
  90137. unsigned i;
  90138. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90139. FLAC__ASSERT(0 != encoder);
  90140. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90141. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90142. #if !FLAC__HAS_OGG
  90143. if(is_ogg)
  90144. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90145. #endif
  90146. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90147. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90148. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90149. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90150. if(encoder->protected_->channels != 2) {
  90151. encoder->protected_->do_mid_side_stereo = false;
  90152. encoder->protected_->loose_mid_side_stereo = false;
  90153. }
  90154. else if(!encoder->protected_->do_mid_side_stereo)
  90155. encoder->protected_->loose_mid_side_stereo = false;
  90156. if(encoder->protected_->bits_per_sample >= 32)
  90157. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90158. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90159. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90160. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90161. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90162. if(encoder->protected_->blocksize == 0) {
  90163. if(encoder->protected_->max_lpc_order == 0)
  90164. encoder->protected_->blocksize = 1152;
  90165. else
  90166. encoder->protected_->blocksize = 4096;
  90167. }
  90168. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90169. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90170. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90171. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90172. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90173. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90174. if(encoder->protected_->qlp_coeff_precision == 0) {
  90175. if(encoder->protected_->bits_per_sample < 16) {
  90176. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90177. }
  90178. else if(encoder->protected_->bits_per_sample == 16) {
  90179. if(encoder->protected_->blocksize <= 192)
  90180. encoder->protected_->qlp_coeff_precision = 7;
  90181. else if(encoder->protected_->blocksize <= 384)
  90182. encoder->protected_->qlp_coeff_precision = 8;
  90183. else if(encoder->protected_->blocksize <= 576)
  90184. encoder->protected_->qlp_coeff_precision = 9;
  90185. else if(encoder->protected_->blocksize <= 1152)
  90186. encoder->protected_->qlp_coeff_precision = 10;
  90187. else if(encoder->protected_->blocksize <= 2304)
  90188. encoder->protected_->qlp_coeff_precision = 11;
  90189. else if(encoder->protected_->blocksize <= 4608)
  90190. encoder->protected_->qlp_coeff_precision = 12;
  90191. else
  90192. encoder->protected_->qlp_coeff_precision = 13;
  90193. }
  90194. else {
  90195. if(encoder->protected_->blocksize <= 384)
  90196. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90197. else if(encoder->protected_->blocksize <= 1152)
  90198. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90199. else
  90200. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90201. }
  90202. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90203. }
  90204. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90205. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90206. if(encoder->protected_->streamable_subset) {
  90207. if(
  90208. encoder->protected_->blocksize != 192 &&
  90209. encoder->protected_->blocksize != 576 &&
  90210. encoder->protected_->blocksize != 1152 &&
  90211. encoder->protected_->blocksize != 2304 &&
  90212. encoder->protected_->blocksize != 4608 &&
  90213. encoder->protected_->blocksize != 256 &&
  90214. encoder->protected_->blocksize != 512 &&
  90215. encoder->protected_->blocksize != 1024 &&
  90216. encoder->protected_->blocksize != 2048 &&
  90217. encoder->protected_->blocksize != 4096 &&
  90218. encoder->protected_->blocksize != 8192 &&
  90219. encoder->protected_->blocksize != 16384
  90220. )
  90221. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90222. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90223. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90224. if(
  90225. encoder->protected_->bits_per_sample != 8 &&
  90226. encoder->protected_->bits_per_sample != 12 &&
  90227. encoder->protected_->bits_per_sample != 16 &&
  90228. encoder->protected_->bits_per_sample != 20 &&
  90229. encoder->protected_->bits_per_sample != 24
  90230. )
  90231. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90232. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90233. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90234. if(
  90235. encoder->protected_->sample_rate <= 48000 &&
  90236. (
  90237. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90238. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90239. )
  90240. ) {
  90241. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90242. }
  90243. }
  90244. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90245. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90246. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90247. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90248. #if FLAC__HAS_OGG
  90249. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90250. unsigned i;
  90251. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90252. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90253. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90254. for( ; i > 0; i--)
  90255. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90256. encoder->protected_->metadata[0] = vc;
  90257. break;
  90258. }
  90259. }
  90260. }
  90261. #endif
  90262. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90263. unsigned i;
  90264. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90265. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90266. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90267. break; /* take only the first one */
  90268. }
  90269. }
  90270. }
  90271. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90272. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90273. metadata_has_seektable = false;
  90274. metadata_has_vorbis_comment = false;
  90275. metadata_picture_has_type1 = false;
  90276. metadata_picture_has_type2 = false;
  90277. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90278. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90279. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90280. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90281. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90282. if(metadata_has_seektable) /* only one is allowed */
  90283. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90284. metadata_has_seektable = true;
  90285. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90286. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90287. }
  90288. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90289. if(metadata_has_vorbis_comment) /* only one is allowed */
  90290. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90291. metadata_has_vorbis_comment = true;
  90292. }
  90293. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90294. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90295. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90296. }
  90297. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90298. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90299. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90300. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90301. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90302. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90303. metadata_picture_has_type1 = true;
  90304. if(
  90305. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90306. (
  90307. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90308. m->data.picture.width != 32 ||
  90309. m->data.picture.height != 32
  90310. )
  90311. )
  90312. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90313. }
  90314. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90315. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90316. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90317. metadata_picture_has_type2 = true;
  90318. }
  90319. }
  90320. }
  90321. encoder->private_->input_capacity = 0;
  90322. for(i = 0; i < encoder->protected_->channels; i++) {
  90323. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90324. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90325. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90326. #endif
  90327. }
  90328. for(i = 0; i < 2; i++) {
  90329. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90330. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90331. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90332. #endif
  90333. }
  90334. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90335. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90336. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90337. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90338. #endif
  90339. for(i = 0; i < encoder->protected_->channels; i++) {
  90340. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90341. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90342. encoder->private_->best_subframe[i] = 0;
  90343. }
  90344. for(i = 0; i < 2; i++) {
  90345. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90346. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90347. encoder->private_->best_subframe_mid_side[i] = 0;
  90348. }
  90349. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90350. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90351. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90352. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90353. #else
  90354. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90355. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90356. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90357. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90358. 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);
  90359. #endif
  90360. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90361. encoder->private_->loose_mid_side_stereo_frames = 1;
  90362. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90363. encoder->private_->current_sample_number = 0;
  90364. encoder->private_->current_frame_number = 0;
  90365. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90366. 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? */
  90367. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90368. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90369. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90370. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90371. #endif
  90372. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90373. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90374. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90375. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90376. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90377. #endif
  90378. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90379. # ifndef FLAC__NO_ASM
  90380. if(encoder->private_->cpuinfo.use_asm) {
  90381. # ifdef FLAC__CPU_IA32
  90382. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90383. # ifdef FLAC__HAS_NASM
  90384. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90385. if(encoder->protected_->max_lpc_order < 4)
  90386. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90387. else if(encoder->protected_->max_lpc_order < 8)
  90388. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90389. else if(encoder->protected_->max_lpc_order < 12)
  90390. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90391. else
  90392. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90393. }
  90394. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90395. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90396. else
  90397. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90398. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90399. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90400. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90401. }
  90402. else {
  90403. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90404. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90405. }
  90406. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90407. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90408. # endif /* FLAC__HAS_NASM */
  90409. # endif /* FLAC__CPU_IA32 */
  90410. }
  90411. # endif /* !FLAC__NO_ASM */
  90412. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90413. if(encoder->private_->use_wide_by_block) {
  90414. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90415. }
  90416. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90417. #if FLAC__HAS_OGG
  90418. encoder->private_->is_ogg = is_ogg;
  90419. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90420. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90421. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90422. }
  90423. #endif
  90424. encoder->private_->read_callback = read_callback;
  90425. encoder->private_->write_callback = write_callback;
  90426. encoder->private_->seek_callback = seek_callback;
  90427. encoder->private_->tell_callback = tell_callback;
  90428. encoder->private_->metadata_callback = metadata_callback;
  90429. encoder->private_->client_data = client_data;
  90430. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90431. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90432. }
  90433. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90434. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90435. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90436. }
  90437. if(encoder->protected_->verify) {
  90438. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90439. for(i = 0; i < encoder->protected_->channels; i++) {
  90440. 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))) {
  90441. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90442. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90443. }
  90444. }
  90445. encoder->private_->verify.input_fifo.tail = 0;
  90446. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90447. if(0 == encoder->private_->verify.decoder) {
  90448. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90449. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90450. }
  90451. 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) {
  90452. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90453. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90454. }
  90455. }
  90456. encoder->private_->verify.error_stats.absolute_sample = 0;
  90457. encoder->private_->verify.error_stats.frame_number = 0;
  90458. encoder->private_->verify.error_stats.channel = 0;
  90459. encoder->private_->verify.error_stats.sample = 0;
  90460. encoder->private_->verify.error_stats.expected = 0;
  90461. encoder->private_->verify.error_stats.got = 0;
  90462. encoder->private_->first_seekpoint_to_check = 0;
  90463. encoder->private_->samples_written = 0;
  90464. encoder->protected_->streaminfo_offset = 0;
  90465. encoder->protected_->seektable_offset = 0;
  90466. encoder->protected_->audio_offset = 0;
  90467. if(encoder->protected_->verify)
  90468. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90469. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90470. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90471. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90472. }
  90473. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90474. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90475. }
  90476. if(encoder->protected_->verify)
  90477. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90478. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90479. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90480. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90481. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90482. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90483. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90484. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90485. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90486. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90487. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90488. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90489. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90490. if(encoder->protected_->do_md5)
  90491. FLAC__MD5Init(&encoder->private_->md5context);
  90492. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90493. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90494. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90495. }
  90496. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90497. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90498. }
  90499. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90500. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90501. if(!metadata_has_vorbis_comment) {
  90502. FLAC__StreamMetadata vorbis_comment;
  90503. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90504. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90505. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90506. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90507. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90508. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90509. vorbis_comment.data.vorbis_comment.comments = 0;
  90510. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90511. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90512. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90513. }
  90514. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90515. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90516. }
  90517. }
  90518. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90519. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90520. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90521. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90522. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90523. }
  90524. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90525. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90526. }
  90527. }
  90528. 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 */
  90529. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90530. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90531. }
  90532. if(encoder->protected_->verify)
  90533. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90534. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90535. }
  90536. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90537. FLAC__StreamEncoder *encoder,
  90538. FLAC__StreamEncoderWriteCallback write_callback,
  90539. FLAC__StreamEncoderSeekCallback seek_callback,
  90540. FLAC__StreamEncoderTellCallback tell_callback,
  90541. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90542. void *client_data
  90543. )
  90544. {
  90545. return init_stream_internal_enc(
  90546. encoder,
  90547. 0,
  90548. write_callback,
  90549. seek_callback,
  90550. tell_callback,
  90551. metadata_callback,
  90552. client_data,
  90553. false
  90554. );
  90555. }
  90556. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90557. FLAC__StreamEncoder *encoder,
  90558. FLAC__StreamEncoderReadCallback read_callback,
  90559. FLAC__StreamEncoderWriteCallback write_callback,
  90560. FLAC__StreamEncoderSeekCallback seek_callback,
  90561. FLAC__StreamEncoderTellCallback tell_callback,
  90562. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90563. void *client_data
  90564. )
  90565. {
  90566. return init_stream_internal_enc(
  90567. encoder,
  90568. read_callback,
  90569. write_callback,
  90570. seek_callback,
  90571. tell_callback,
  90572. metadata_callback,
  90573. client_data,
  90574. true
  90575. );
  90576. }
  90577. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90578. FLAC__StreamEncoder *encoder,
  90579. FILE *file,
  90580. FLAC__StreamEncoderProgressCallback progress_callback,
  90581. void *client_data,
  90582. FLAC__bool is_ogg
  90583. )
  90584. {
  90585. FLAC__StreamEncoderInitStatus init_status;
  90586. FLAC__ASSERT(0 != encoder);
  90587. FLAC__ASSERT(0 != file);
  90588. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90589. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90590. if(file == 0) {
  90591. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90592. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90593. }
  90594. if(file == stdout)
  90595. file = get_binary_stdout_(); /* just to be safe */
  90596. encoder->private_->file = file;
  90597. encoder->private_->progress_callback = progress_callback;
  90598. encoder->private_->bytes_written = 0;
  90599. encoder->private_->samples_written = 0;
  90600. encoder->private_->frames_written = 0;
  90601. init_status = init_stream_internal_enc(
  90602. encoder,
  90603. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90604. file_write_callback_,
  90605. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90606. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90607. 0,
  90608. client_data,
  90609. is_ogg
  90610. );
  90611. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90612. return init_status;
  90613. }
  90614. {
  90615. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90616. FLAC__ASSERT(blocksize != 0);
  90617. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90618. }
  90619. return init_status;
  90620. }
  90621. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90622. FLAC__StreamEncoder *encoder,
  90623. FILE *file,
  90624. FLAC__StreamEncoderProgressCallback progress_callback,
  90625. void *client_data
  90626. )
  90627. {
  90628. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90629. }
  90630. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90631. FLAC__StreamEncoder *encoder,
  90632. FILE *file,
  90633. FLAC__StreamEncoderProgressCallback progress_callback,
  90634. void *client_data
  90635. )
  90636. {
  90637. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90638. }
  90639. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90640. FLAC__StreamEncoder *encoder,
  90641. const char *filename,
  90642. FLAC__StreamEncoderProgressCallback progress_callback,
  90643. void *client_data,
  90644. FLAC__bool is_ogg
  90645. )
  90646. {
  90647. FILE *file;
  90648. FLAC__ASSERT(0 != encoder);
  90649. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90650. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90651. file = filename? fopen(filename, "w+b") : stdout;
  90652. if(file == 0) {
  90653. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90654. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90655. }
  90656. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90657. }
  90658. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90659. FLAC__StreamEncoder *encoder,
  90660. const char *filename,
  90661. FLAC__StreamEncoderProgressCallback progress_callback,
  90662. void *client_data
  90663. )
  90664. {
  90665. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90666. }
  90667. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90668. FLAC__StreamEncoder *encoder,
  90669. const char *filename,
  90670. FLAC__StreamEncoderProgressCallback progress_callback,
  90671. void *client_data
  90672. )
  90673. {
  90674. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90675. }
  90676. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90677. {
  90678. FLAC__bool error = false;
  90679. FLAC__ASSERT(0 != encoder);
  90680. FLAC__ASSERT(0 != encoder->private_);
  90681. FLAC__ASSERT(0 != encoder->protected_);
  90682. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90683. return true;
  90684. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90685. if(encoder->private_->current_sample_number != 0) {
  90686. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90687. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90688. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90689. error = true;
  90690. }
  90691. }
  90692. if(encoder->protected_->do_md5)
  90693. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90694. if(!encoder->private_->is_being_deleted) {
  90695. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90696. if(encoder->private_->seek_callback) {
  90697. #if FLAC__HAS_OGG
  90698. if(encoder->private_->is_ogg)
  90699. update_ogg_metadata_(encoder);
  90700. else
  90701. #endif
  90702. update_metadata_(encoder);
  90703. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90704. error = true;
  90705. }
  90706. if(encoder->private_->metadata_callback)
  90707. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90708. }
  90709. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90710. if(!error)
  90711. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90712. error = true;
  90713. }
  90714. }
  90715. if(0 != encoder->private_->file) {
  90716. if(encoder->private_->file != stdout)
  90717. fclose(encoder->private_->file);
  90718. encoder->private_->file = 0;
  90719. }
  90720. #if FLAC__HAS_OGG
  90721. if(encoder->private_->is_ogg)
  90722. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90723. #endif
  90724. free_(encoder);
  90725. set_defaults_enc(encoder);
  90726. if(!error)
  90727. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90728. return !error;
  90729. }
  90730. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90731. {
  90732. FLAC__ASSERT(0 != encoder);
  90733. FLAC__ASSERT(0 != encoder->private_);
  90734. FLAC__ASSERT(0 != encoder->protected_);
  90735. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90736. return false;
  90737. #if FLAC__HAS_OGG
  90738. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90739. return true;
  90740. #else
  90741. (void)value;
  90742. return false;
  90743. #endif
  90744. }
  90745. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90746. {
  90747. FLAC__ASSERT(0 != encoder);
  90748. FLAC__ASSERT(0 != encoder->private_);
  90749. FLAC__ASSERT(0 != encoder->protected_);
  90750. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90751. return false;
  90752. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90753. encoder->protected_->verify = value;
  90754. #endif
  90755. return true;
  90756. }
  90757. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90758. {
  90759. FLAC__ASSERT(0 != encoder);
  90760. FLAC__ASSERT(0 != encoder->private_);
  90761. FLAC__ASSERT(0 != encoder->protected_);
  90762. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90763. return false;
  90764. encoder->protected_->streamable_subset = value;
  90765. return true;
  90766. }
  90767. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90768. {
  90769. FLAC__ASSERT(0 != encoder);
  90770. FLAC__ASSERT(0 != encoder->private_);
  90771. FLAC__ASSERT(0 != encoder->protected_);
  90772. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90773. return false;
  90774. encoder->protected_->do_md5 = value;
  90775. return true;
  90776. }
  90777. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90778. {
  90779. FLAC__ASSERT(0 != encoder);
  90780. FLAC__ASSERT(0 != encoder->private_);
  90781. FLAC__ASSERT(0 != encoder->protected_);
  90782. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90783. return false;
  90784. encoder->protected_->channels = value;
  90785. return true;
  90786. }
  90787. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90788. {
  90789. FLAC__ASSERT(0 != encoder);
  90790. FLAC__ASSERT(0 != encoder->private_);
  90791. FLAC__ASSERT(0 != encoder->protected_);
  90792. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90793. return false;
  90794. encoder->protected_->bits_per_sample = value;
  90795. return true;
  90796. }
  90797. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90798. {
  90799. FLAC__ASSERT(0 != encoder);
  90800. FLAC__ASSERT(0 != encoder->private_);
  90801. FLAC__ASSERT(0 != encoder->protected_);
  90802. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90803. return false;
  90804. encoder->protected_->sample_rate = value;
  90805. return true;
  90806. }
  90807. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90808. {
  90809. FLAC__bool ok = true;
  90810. FLAC__ASSERT(0 != encoder);
  90811. FLAC__ASSERT(0 != encoder->private_);
  90812. FLAC__ASSERT(0 != encoder->protected_);
  90813. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90814. return false;
  90815. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90816. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90817. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90818. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90819. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90820. #if 0
  90821. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90822. #else
  90823. encoder->protected_->num_apodizations = 1;
  90824. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90825. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90826. #endif
  90827. #endif
  90828. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90829. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90830. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90831. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90832. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90833. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90834. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90835. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90836. return ok;
  90837. }
  90838. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90839. {
  90840. FLAC__ASSERT(0 != encoder);
  90841. FLAC__ASSERT(0 != encoder->private_);
  90842. FLAC__ASSERT(0 != encoder->protected_);
  90843. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90844. return false;
  90845. encoder->protected_->blocksize = value;
  90846. return true;
  90847. }
  90848. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90849. {
  90850. FLAC__ASSERT(0 != encoder);
  90851. FLAC__ASSERT(0 != encoder->private_);
  90852. FLAC__ASSERT(0 != encoder->protected_);
  90853. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90854. return false;
  90855. encoder->protected_->do_mid_side_stereo = value;
  90856. return true;
  90857. }
  90858. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90859. {
  90860. FLAC__ASSERT(0 != encoder);
  90861. FLAC__ASSERT(0 != encoder->private_);
  90862. FLAC__ASSERT(0 != encoder->protected_);
  90863. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90864. return false;
  90865. encoder->protected_->loose_mid_side_stereo = value;
  90866. return true;
  90867. }
  90868. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90869. {
  90870. FLAC__ASSERT(0 != encoder);
  90871. FLAC__ASSERT(0 != encoder->private_);
  90872. FLAC__ASSERT(0 != encoder->protected_);
  90873. FLAC__ASSERT(0 != specification);
  90874. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90875. return false;
  90876. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90877. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90878. #else
  90879. encoder->protected_->num_apodizations = 0;
  90880. while(1) {
  90881. const char *s = strchr(specification, ';');
  90882. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90883. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90884. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90885. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90886. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90887. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90888. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90889. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90890. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90891. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90892. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90893. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90894. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90895. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90896. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90897. if (stddev > 0.0 && stddev <= 0.5) {
  90898. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90899. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90900. }
  90901. }
  90902. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90903. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90904. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90905. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90906. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90907. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90908. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90909. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90910. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90911. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90912. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90913. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90914. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90915. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90916. if (p >= 0.0 && p <= 1.0) {
  90917. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90918. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90919. }
  90920. }
  90921. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90922. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  90923. if (encoder->protected_->num_apodizations == 32)
  90924. break;
  90925. if (s)
  90926. specification = s+1;
  90927. else
  90928. break;
  90929. }
  90930. if(encoder->protected_->num_apodizations == 0) {
  90931. encoder->protected_->num_apodizations = 1;
  90932. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90933. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90934. }
  90935. #endif
  90936. return true;
  90937. }
  90938. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  90939. {
  90940. FLAC__ASSERT(0 != encoder);
  90941. FLAC__ASSERT(0 != encoder->private_);
  90942. FLAC__ASSERT(0 != encoder->protected_);
  90943. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90944. return false;
  90945. encoder->protected_->max_lpc_order = value;
  90946. return true;
  90947. }
  90948. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  90949. {
  90950. FLAC__ASSERT(0 != encoder);
  90951. FLAC__ASSERT(0 != encoder->private_);
  90952. FLAC__ASSERT(0 != encoder->protected_);
  90953. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90954. return false;
  90955. encoder->protected_->qlp_coeff_precision = value;
  90956. return true;
  90957. }
  90958. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90959. {
  90960. FLAC__ASSERT(0 != encoder);
  90961. FLAC__ASSERT(0 != encoder->private_);
  90962. FLAC__ASSERT(0 != encoder->protected_);
  90963. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90964. return false;
  90965. encoder->protected_->do_qlp_coeff_prec_search = value;
  90966. return true;
  90967. }
  90968. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90969. {
  90970. FLAC__ASSERT(0 != encoder);
  90971. FLAC__ASSERT(0 != encoder->private_);
  90972. FLAC__ASSERT(0 != encoder->protected_);
  90973. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90974. return false;
  90975. #if 0
  90976. encoder->protected_->do_escape_coding = value;
  90977. #else
  90978. (void)value;
  90979. #endif
  90980. return true;
  90981. }
  90982. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90983. {
  90984. FLAC__ASSERT(0 != encoder);
  90985. FLAC__ASSERT(0 != encoder->private_);
  90986. FLAC__ASSERT(0 != encoder->protected_);
  90987. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90988. return false;
  90989. encoder->protected_->do_exhaustive_model_search = value;
  90990. return true;
  90991. }
  90992. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90993. {
  90994. FLAC__ASSERT(0 != encoder);
  90995. FLAC__ASSERT(0 != encoder->private_);
  90996. FLAC__ASSERT(0 != encoder->protected_);
  90997. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90998. return false;
  90999. encoder->protected_->min_residual_partition_order = value;
  91000. return true;
  91001. }
  91002. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91003. {
  91004. FLAC__ASSERT(0 != encoder);
  91005. FLAC__ASSERT(0 != encoder->private_);
  91006. FLAC__ASSERT(0 != encoder->protected_);
  91007. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91008. return false;
  91009. encoder->protected_->max_residual_partition_order = value;
  91010. return true;
  91011. }
  91012. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  91013. {
  91014. FLAC__ASSERT(0 != encoder);
  91015. FLAC__ASSERT(0 != encoder->private_);
  91016. FLAC__ASSERT(0 != encoder->protected_);
  91017. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91018. return false;
  91019. #if 0
  91020. encoder->protected_->rice_parameter_search_dist = value;
  91021. #else
  91022. (void)value;
  91023. #endif
  91024. return true;
  91025. }
  91026. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91027. {
  91028. FLAC__ASSERT(0 != encoder);
  91029. FLAC__ASSERT(0 != encoder->private_);
  91030. FLAC__ASSERT(0 != encoder->protected_);
  91031. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91032. return false;
  91033. encoder->protected_->total_samples_estimate = value;
  91034. return true;
  91035. }
  91036. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  91037. {
  91038. FLAC__ASSERT(0 != encoder);
  91039. FLAC__ASSERT(0 != encoder->private_);
  91040. FLAC__ASSERT(0 != encoder->protected_);
  91041. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91042. return false;
  91043. if(0 == metadata)
  91044. num_blocks = 0;
  91045. if(0 == num_blocks)
  91046. metadata = 0;
  91047. if(encoder->protected_->metadata) {
  91048. free(encoder->protected_->metadata);
  91049. encoder->protected_->metadata = 0;
  91050. encoder->protected_->num_metadata_blocks = 0;
  91051. }
  91052. if(num_blocks) {
  91053. FLAC__StreamMetadata **m;
  91054. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91055. return false;
  91056. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91057. encoder->protected_->metadata = m;
  91058. encoder->protected_->num_metadata_blocks = num_blocks;
  91059. }
  91060. #if FLAC__HAS_OGG
  91061. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91062. return false;
  91063. #endif
  91064. return true;
  91065. }
  91066. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91067. {
  91068. FLAC__ASSERT(0 != encoder);
  91069. FLAC__ASSERT(0 != encoder->private_);
  91070. FLAC__ASSERT(0 != encoder->protected_);
  91071. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91072. return false;
  91073. encoder->private_->disable_constant_subframes = value;
  91074. return true;
  91075. }
  91076. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91077. {
  91078. FLAC__ASSERT(0 != encoder);
  91079. FLAC__ASSERT(0 != encoder->private_);
  91080. FLAC__ASSERT(0 != encoder->protected_);
  91081. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91082. return false;
  91083. encoder->private_->disable_fixed_subframes = value;
  91084. return true;
  91085. }
  91086. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91087. {
  91088. FLAC__ASSERT(0 != encoder);
  91089. FLAC__ASSERT(0 != encoder->private_);
  91090. FLAC__ASSERT(0 != encoder->protected_);
  91091. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91092. return false;
  91093. encoder->private_->disable_verbatim_subframes = value;
  91094. return true;
  91095. }
  91096. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91097. {
  91098. FLAC__ASSERT(0 != encoder);
  91099. FLAC__ASSERT(0 != encoder->private_);
  91100. FLAC__ASSERT(0 != encoder->protected_);
  91101. return encoder->protected_->state;
  91102. }
  91103. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91104. {
  91105. FLAC__ASSERT(0 != encoder);
  91106. FLAC__ASSERT(0 != encoder->private_);
  91107. FLAC__ASSERT(0 != encoder->protected_);
  91108. if(encoder->protected_->verify)
  91109. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91110. else
  91111. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91112. }
  91113. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  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_VERIFY_DECODER_ERROR)
  91119. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91120. else
  91121. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91122. }
  91123. 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)
  91124. {
  91125. FLAC__ASSERT(0 != encoder);
  91126. FLAC__ASSERT(0 != encoder->private_);
  91127. FLAC__ASSERT(0 != encoder->protected_);
  91128. if(0 != absolute_sample)
  91129. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91130. if(0 != frame_number)
  91131. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91132. if(0 != channel)
  91133. *channel = encoder->private_->verify.error_stats.channel;
  91134. if(0 != sample)
  91135. *sample = encoder->private_->verify.error_stats.sample;
  91136. if(0 != expected)
  91137. *expected = encoder->private_->verify.error_stats.expected;
  91138. if(0 != got)
  91139. *got = encoder->private_->verify.error_stats.got;
  91140. }
  91141. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91142. {
  91143. FLAC__ASSERT(0 != encoder);
  91144. FLAC__ASSERT(0 != encoder->private_);
  91145. FLAC__ASSERT(0 != encoder->protected_);
  91146. return encoder->protected_->verify;
  91147. }
  91148. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91149. {
  91150. FLAC__ASSERT(0 != encoder);
  91151. FLAC__ASSERT(0 != encoder->private_);
  91152. FLAC__ASSERT(0 != encoder->protected_);
  91153. return encoder->protected_->streamable_subset;
  91154. }
  91155. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91156. {
  91157. FLAC__ASSERT(0 != encoder);
  91158. FLAC__ASSERT(0 != encoder->private_);
  91159. FLAC__ASSERT(0 != encoder->protected_);
  91160. return encoder->protected_->do_md5;
  91161. }
  91162. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91163. {
  91164. FLAC__ASSERT(0 != encoder);
  91165. FLAC__ASSERT(0 != encoder->private_);
  91166. FLAC__ASSERT(0 != encoder->protected_);
  91167. return encoder->protected_->channels;
  91168. }
  91169. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91170. {
  91171. FLAC__ASSERT(0 != encoder);
  91172. FLAC__ASSERT(0 != encoder->private_);
  91173. FLAC__ASSERT(0 != encoder->protected_);
  91174. return encoder->protected_->bits_per_sample;
  91175. }
  91176. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91177. {
  91178. FLAC__ASSERT(0 != encoder);
  91179. FLAC__ASSERT(0 != encoder->private_);
  91180. FLAC__ASSERT(0 != encoder->protected_);
  91181. return encoder->protected_->sample_rate;
  91182. }
  91183. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91184. {
  91185. FLAC__ASSERT(0 != encoder);
  91186. FLAC__ASSERT(0 != encoder->private_);
  91187. FLAC__ASSERT(0 != encoder->protected_);
  91188. return encoder->protected_->blocksize;
  91189. }
  91190. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91191. {
  91192. FLAC__ASSERT(0 != encoder);
  91193. FLAC__ASSERT(0 != encoder->private_);
  91194. FLAC__ASSERT(0 != encoder->protected_);
  91195. return encoder->protected_->do_mid_side_stereo;
  91196. }
  91197. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91198. {
  91199. FLAC__ASSERT(0 != encoder);
  91200. FLAC__ASSERT(0 != encoder->private_);
  91201. FLAC__ASSERT(0 != encoder->protected_);
  91202. return encoder->protected_->loose_mid_side_stereo;
  91203. }
  91204. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91205. {
  91206. FLAC__ASSERT(0 != encoder);
  91207. FLAC__ASSERT(0 != encoder->private_);
  91208. FLAC__ASSERT(0 != encoder->protected_);
  91209. return encoder->protected_->max_lpc_order;
  91210. }
  91211. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91212. {
  91213. FLAC__ASSERT(0 != encoder);
  91214. FLAC__ASSERT(0 != encoder->private_);
  91215. FLAC__ASSERT(0 != encoder->protected_);
  91216. return encoder->protected_->qlp_coeff_precision;
  91217. }
  91218. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(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_->do_qlp_coeff_prec_search;
  91224. }
  91225. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(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_->do_escape_coding;
  91231. }
  91232. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(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_exhaustive_model_search;
  91238. }
  91239. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(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_->min_residual_partition_order;
  91245. }
  91246. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(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_->max_residual_partition_order;
  91252. }
  91253. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(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_->rice_parameter_search_dist;
  91259. }
  91260. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(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_->total_samples_estimate;
  91266. }
  91267. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91268. {
  91269. unsigned i, j = 0, channel;
  91270. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91271. FLAC__ASSERT(0 != encoder);
  91272. FLAC__ASSERT(0 != encoder->private_);
  91273. FLAC__ASSERT(0 != encoder->protected_);
  91274. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91275. do {
  91276. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91277. if(encoder->protected_->verify)
  91278. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91279. for(channel = 0; channel < channels; channel++)
  91280. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91281. if(encoder->protected_->do_mid_side_stereo) {
  91282. FLAC__ASSERT(channels == 2);
  91283. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91284. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91285. 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' ! */
  91286. }
  91287. }
  91288. else
  91289. j += n;
  91290. encoder->private_->current_sample_number += n;
  91291. if(encoder->private_->current_sample_number > blocksize) {
  91292. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91293. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91294. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91295. return false;
  91296. for(channel = 0; channel < channels; channel++)
  91297. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91298. if(encoder->protected_->do_mid_side_stereo) {
  91299. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91300. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91301. }
  91302. encoder->private_->current_sample_number = 1;
  91303. }
  91304. } while(j < samples);
  91305. return true;
  91306. }
  91307. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91308. {
  91309. unsigned i, j, k, channel;
  91310. FLAC__int32 x, mid, side;
  91311. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91312. FLAC__ASSERT(0 != encoder);
  91313. FLAC__ASSERT(0 != encoder->private_);
  91314. FLAC__ASSERT(0 != encoder->protected_);
  91315. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91316. j = k = 0;
  91317. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91318. do {
  91319. if(encoder->protected_->verify)
  91320. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91321. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91322. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91323. x = buffer[k++];
  91324. encoder->private_->integer_signal[1][i] = x;
  91325. mid += x;
  91326. side -= x;
  91327. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91328. encoder->private_->integer_signal_mid_side[1][i] = side;
  91329. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91330. }
  91331. encoder->private_->current_sample_number = i;
  91332. if(i > blocksize) {
  91333. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91334. return false;
  91335. /* move unprocessed overread samples to beginnings of arrays */
  91336. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91337. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91338. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91339. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91340. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91341. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91342. encoder->private_->current_sample_number = 1;
  91343. }
  91344. } while(j < samples);
  91345. }
  91346. else {
  91347. do {
  91348. if(encoder->protected_->verify)
  91349. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91350. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91351. for(channel = 0; channel < channels; channel++)
  91352. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91353. }
  91354. encoder->private_->current_sample_number = i;
  91355. if(i > blocksize) {
  91356. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91357. return false;
  91358. /* move unprocessed overread samples to beginnings of arrays */
  91359. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91360. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91361. for(channel = 0; channel < channels; channel++)
  91362. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91363. encoder->private_->current_sample_number = 1;
  91364. }
  91365. } while(j < samples);
  91366. }
  91367. return true;
  91368. }
  91369. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91370. {
  91371. FLAC__ASSERT(0 != encoder);
  91372. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91373. encoder->protected_->verify = true;
  91374. #else
  91375. encoder->protected_->verify = false;
  91376. #endif
  91377. encoder->protected_->streamable_subset = true;
  91378. encoder->protected_->do_md5 = true;
  91379. encoder->protected_->do_mid_side_stereo = false;
  91380. encoder->protected_->loose_mid_side_stereo = false;
  91381. encoder->protected_->channels = 2;
  91382. encoder->protected_->bits_per_sample = 16;
  91383. encoder->protected_->sample_rate = 44100;
  91384. encoder->protected_->blocksize = 0;
  91385. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91386. encoder->protected_->num_apodizations = 1;
  91387. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91388. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91389. #endif
  91390. encoder->protected_->max_lpc_order = 0;
  91391. encoder->protected_->qlp_coeff_precision = 0;
  91392. encoder->protected_->do_qlp_coeff_prec_search = false;
  91393. encoder->protected_->do_exhaustive_model_search = false;
  91394. encoder->protected_->do_escape_coding = false;
  91395. encoder->protected_->min_residual_partition_order = 0;
  91396. encoder->protected_->max_residual_partition_order = 0;
  91397. encoder->protected_->rice_parameter_search_dist = 0;
  91398. encoder->protected_->total_samples_estimate = 0;
  91399. encoder->protected_->metadata = 0;
  91400. encoder->protected_->num_metadata_blocks = 0;
  91401. encoder->private_->seek_table = 0;
  91402. encoder->private_->disable_constant_subframes = false;
  91403. encoder->private_->disable_fixed_subframes = false;
  91404. encoder->private_->disable_verbatim_subframes = false;
  91405. #if FLAC__HAS_OGG
  91406. encoder->private_->is_ogg = false;
  91407. #endif
  91408. encoder->private_->read_callback = 0;
  91409. encoder->private_->write_callback = 0;
  91410. encoder->private_->seek_callback = 0;
  91411. encoder->private_->tell_callback = 0;
  91412. encoder->private_->metadata_callback = 0;
  91413. encoder->private_->progress_callback = 0;
  91414. encoder->private_->client_data = 0;
  91415. #if FLAC__HAS_OGG
  91416. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91417. #endif
  91418. }
  91419. void free_(FLAC__StreamEncoder *encoder)
  91420. {
  91421. unsigned i, channel;
  91422. FLAC__ASSERT(0 != encoder);
  91423. if(encoder->protected_->metadata) {
  91424. free(encoder->protected_->metadata);
  91425. encoder->protected_->metadata = 0;
  91426. encoder->protected_->num_metadata_blocks = 0;
  91427. }
  91428. for(i = 0; i < encoder->protected_->channels; i++) {
  91429. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91430. free(encoder->private_->integer_signal_unaligned[i]);
  91431. encoder->private_->integer_signal_unaligned[i] = 0;
  91432. }
  91433. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91434. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91435. free(encoder->private_->real_signal_unaligned[i]);
  91436. encoder->private_->real_signal_unaligned[i] = 0;
  91437. }
  91438. #endif
  91439. }
  91440. for(i = 0; i < 2; i++) {
  91441. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91442. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91443. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91444. }
  91445. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91446. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91447. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91448. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91449. }
  91450. #endif
  91451. }
  91452. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91453. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91454. if(0 != encoder->private_->window_unaligned[i]) {
  91455. free(encoder->private_->window_unaligned[i]);
  91456. encoder->private_->window_unaligned[i] = 0;
  91457. }
  91458. }
  91459. if(0 != encoder->private_->windowed_signal_unaligned) {
  91460. free(encoder->private_->windowed_signal_unaligned);
  91461. encoder->private_->windowed_signal_unaligned = 0;
  91462. }
  91463. #endif
  91464. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91465. for(i = 0; i < 2; i++) {
  91466. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91467. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91468. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91469. }
  91470. }
  91471. }
  91472. for(channel = 0; channel < 2; channel++) {
  91473. for(i = 0; i < 2; i++) {
  91474. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91475. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91476. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91477. }
  91478. }
  91479. }
  91480. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91481. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91482. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91483. }
  91484. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91485. free(encoder->private_->raw_bits_per_partition_unaligned);
  91486. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91487. }
  91488. if(encoder->protected_->verify) {
  91489. for(i = 0; i < encoder->protected_->channels; i++) {
  91490. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91491. free(encoder->private_->verify.input_fifo.data[i]);
  91492. encoder->private_->verify.input_fifo.data[i] = 0;
  91493. }
  91494. }
  91495. }
  91496. FLAC__bitwriter_free(encoder->private_->frame);
  91497. }
  91498. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91499. {
  91500. FLAC__bool ok;
  91501. unsigned i, channel;
  91502. FLAC__ASSERT(new_blocksize > 0);
  91503. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91504. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91505. if(new_blocksize <= encoder->private_->input_capacity)
  91506. return true;
  91507. ok = true;
  91508. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91509. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91510. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91511. encoder->private_->integer_signal[i] += 4;
  91512. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91513. #if 0 /* @@@ currently unused */
  91514. if(encoder->protected_->max_lpc_order > 0)
  91515. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91516. #endif
  91517. #endif
  91518. }
  91519. for(i = 0; ok && i < 2; i++) {
  91520. 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]);
  91521. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91522. encoder->private_->integer_signal_mid_side[i] += 4;
  91523. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91524. #if 0 /* @@@ currently unused */
  91525. if(encoder->protected_->max_lpc_order > 0)
  91526. 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]);
  91527. #endif
  91528. #endif
  91529. }
  91530. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91531. if(ok && encoder->protected_->max_lpc_order > 0) {
  91532. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91533. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91534. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91535. }
  91536. #endif
  91537. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91538. for(i = 0; ok && i < 2; i++) {
  91539. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91540. }
  91541. }
  91542. for(channel = 0; ok && channel < 2; channel++) {
  91543. for(i = 0; ok && i < 2; i++) {
  91544. 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]);
  91545. }
  91546. }
  91547. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91548. if(encoder->protected_->do_escape_coding)
  91549. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91550. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91551. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91552. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91553. switch(encoder->protected_->apodizations[i].type) {
  91554. case FLAC__APODIZATION_BARTLETT:
  91555. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91556. break;
  91557. case FLAC__APODIZATION_BARTLETT_HANN:
  91558. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91559. break;
  91560. case FLAC__APODIZATION_BLACKMAN:
  91561. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91562. break;
  91563. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91564. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91565. break;
  91566. case FLAC__APODIZATION_CONNES:
  91567. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91568. break;
  91569. case FLAC__APODIZATION_FLATTOP:
  91570. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91571. break;
  91572. case FLAC__APODIZATION_GAUSS:
  91573. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91574. break;
  91575. case FLAC__APODIZATION_HAMMING:
  91576. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91577. break;
  91578. case FLAC__APODIZATION_HANN:
  91579. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91580. break;
  91581. case FLAC__APODIZATION_KAISER_BESSEL:
  91582. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91583. break;
  91584. case FLAC__APODIZATION_NUTTALL:
  91585. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91586. break;
  91587. case FLAC__APODIZATION_RECTANGLE:
  91588. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91589. break;
  91590. case FLAC__APODIZATION_TRIANGLE:
  91591. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91592. break;
  91593. case FLAC__APODIZATION_TUKEY:
  91594. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91595. break;
  91596. case FLAC__APODIZATION_WELCH:
  91597. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91598. break;
  91599. default:
  91600. FLAC__ASSERT(0);
  91601. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91602. break;
  91603. }
  91604. }
  91605. }
  91606. #endif
  91607. if(ok)
  91608. encoder->private_->input_capacity = new_blocksize;
  91609. else
  91610. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91611. return ok;
  91612. }
  91613. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91614. {
  91615. const FLAC__byte *buffer;
  91616. size_t bytes;
  91617. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91618. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91619. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91620. return false;
  91621. }
  91622. if(encoder->protected_->verify) {
  91623. encoder->private_->verify.output.data = buffer;
  91624. encoder->private_->verify.output.bytes = bytes;
  91625. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91626. encoder->private_->verify.needs_magic_hack = true;
  91627. }
  91628. else {
  91629. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91630. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91631. FLAC__bitwriter_clear(encoder->private_->frame);
  91632. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91633. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91634. return false;
  91635. }
  91636. }
  91637. }
  91638. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91639. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91640. FLAC__bitwriter_clear(encoder->private_->frame);
  91641. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91642. return false;
  91643. }
  91644. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91645. FLAC__bitwriter_clear(encoder->private_->frame);
  91646. if(samples > 0) {
  91647. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91648. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91649. }
  91650. return true;
  91651. }
  91652. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91653. {
  91654. FLAC__StreamEncoderWriteStatus status;
  91655. FLAC__uint64 output_position = 0;
  91656. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91657. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91658. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91659. }
  91660. if(samples == 0) {
  91661. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91662. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91663. encoder->protected_->streaminfo_offset = output_position;
  91664. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91665. encoder->protected_->seektable_offset = output_position;
  91666. }
  91667. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91668. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91669. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91670. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91671. FLAC__uint64 test_sample;
  91672. unsigned i;
  91673. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91674. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91675. if(test_sample > frame_last_sample) {
  91676. break;
  91677. }
  91678. else if(test_sample >= frame_first_sample) {
  91679. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91680. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91681. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91682. encoder->private_->first_seekpoint_to_check++;
  91683. }
  91684. else {
  91685. encoder->private_->first_seekpoint_to_check++;
  91686. }
  91687. }
  91688. }
  91689. #if FLAC__HAS_OGG
  91690. if(encoder->private_->is_ogg) {
  91691. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91692. &encoder->protected_->ogg_encoder_aspect,
  91693. buffer,
  91694. bytes,
  91695. samples,
  91696. encoder->private_->current_frame_number,
  91697. is_last_block,
  91698. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91699. encoder,
  91700. encoder->private_->client_data
  91701. );
  91702. }
  91703. else
  91704. #endif
  91705. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91706. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91707. encoder->private_->bytes_written += bytes;
  91708. encoder->private_->samples_written += samples;
  91709. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91710. }
  91711. else
  91712. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91713. return status;
  91714. }
  91715. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91716. {
  91717. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91718. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91719. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91720. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91721. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91722. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91723. FLAC__StreamEncoderSeekStatus seek_status;
  91724. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91725. {
  91726. const unsigned md5_offset =
  91727. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91728. (
  91729. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91730. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91731. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91732. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91733. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91734. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91735. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91736. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91737. ) / 8;
  91738. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91739. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91740. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91741. return;
  91742. }
  91743. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91744. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91745. return;
  91746. }
  91747. }
  91748. {
  91749. const unsigned total_samples_byte_offset =
  91750. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91751. (
  91752. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91753. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91754. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91755. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91756. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91757. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91758. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91759. - 4
  91760. ) / 8;
  91761. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91762. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91763. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91764. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91765. b[4] = (FLAC__byte)(samples & 0xFF);
  91766. 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) {
  91767. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91768. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91769. return;
  91770. }
  91771. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91772. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91773. return;
  91774. }
  91775. }
  91776. {
  91777. const unsigned min_framesize_offset =
  91778. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91779. (
  91780. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91781. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91782. ) / 8;
  91783. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91784. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91785. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91786. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91787. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91788. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91789. 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) {
  91790. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91791. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91792. return;
  91793. }
  91794. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91795. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91796. return;
  91797. }
  91798. }
  91799. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91800. unsigned i;
  91801. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91802. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91803. 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) {
  91804. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91805. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91806. return;
  91807. }
  91808. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91809. FLAC__uint64 xx;
  91810. unsigned x;
  91811. xx = encoder->private_->seek_table->points[i].sample_number;
  91812. b[7] = (FLAC__byte)xx; xx >>= 8;
  91813. b[6] = (FLAC__byte)xx; xx >>= 8;
  91814. b[5] = (FLAC__byte)xx; xx >>= 8;
  91815. b[4] = (FLAC__byte)xx; xx >>= 8;
  91816. b[3] = (FLAC__byte)xx; xx >>= 8;
  91817. b[2] = (FLAC__byte)xx; xx >>= 8;
  91818. b[1] = (FLAC__byte)xx; xx >>= 8;
  91819. b[0] = (FLAC__byte)xx; xx >>= 8;
  91820. xx = encoder->private_->seek_table->points[i].stream_offset;
  91821. b[15] = (FLAC__byte)xx; xx >>= 8;
  91822. b[14] = (FLAC__byte)xx; xx >>= 8;
  91823. b[13] = (FLAC__byte)xx; xx >>= 8;
  91824. b[12] = (FLAC__byte)xx; xx >>= 8;
  91825. b[11] = (FLAC__byte)xx; xx >>= 8;
  91826. b[10] = (FLAC__byte)xx; xx >>= 8;
  91827. b[9] = (FLAC__byte)xx; xx >>= 8;
  91828. b[8] = (FLAC__byte)xx; xx >>= 8;
  91829. x = encoder->private_->seek_table->points[i].frame_samples;
  91830. b[17] = (FLAC__byte)x; x >>= 8;
  91831. b[16] = (FLAC__byte)x; x >>= 8;
  91832. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91833. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91834. return;
  91835. }
  91836. }
  91837. }
  91838. }
  91839. #if FLAC__HAS_OGG
  91840. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91841. {
  91842. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91843. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91844. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91845. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91846. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91847. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91848. FLAC__STREAM_SYNC_LENGTH
  91849. ;
  91850. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91851. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91852. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91853. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91854. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91855. ogg_page page;
  91856. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91857. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91858. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91859. return;
  91860. simple_ogg_page__init(&page);
  91861. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91862. simple_ogg_page__clear(&page);
  91863. return; /* state already set */
  91864. }
  91865. {
  91866. const unsigned md5_offset =
  91867. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91868. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91869. (
  91870. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91871. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91872. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91873. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91874. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91875. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91876. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91877. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91878. ) / 8;
  91879. if(md5_offset + 16 > (unsigned)page.body_len) {
  91880. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91881. simple_ogg_page__clear(&page);
  91882. return;
  91883. }
  91884. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91885. }
  91886. {
  91887. const unsigned total_samples_byte_offset =
  91888. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91889. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91890. (
  91891. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91892. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91893. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91894. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91895. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91896. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91897. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91898. - 4
  91899. ) / 8;
  91900. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91901. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91902. simple_ogg_page__clear(&page);
  91903. return;
  91904. }
  91905. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91906. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91907. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91908. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91909. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91910. b[4] = (FLAC__byte)(samples & 0xFF);
  91911. memcpy(page.body + total_samples_byte_offset, b, 5);
  91912. }
  91913. {
  91914. const unsigned min_framesize_offset =
  91915. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91916. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91917. (
  91918. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91919. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91920. ) / 8;
  91921. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91922. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91923. simple_ogg_page__clear(&page);
  91924. return;
  91925. }
  91926. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91927. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91928. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91929. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91930. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91931. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91932. memcpy(page.body + min_framesize_offset, b, 6);
  91933. }
  91934. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91935. simple_ogg_page__clear(&page);
  91936. return; /* state already set */
  91937. }
  91938. simple_ogg_page__clear(&page);
  91939. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91940. unsigned i;
  91941. FLAC__byte *p;
  91942. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91943. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91944. simple_ogg_page__init(&page);
  91945. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91946. simple_ogg_page__clear(&page);
  91947. return; /* state already set */
  91948. }
  91949. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  91950. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91951. simple_ogg_page__clear(&page);
  91952. return;
  91953. }
  91954. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  91955. FLAC__uint64 xx;
  91956. unsigned x;
  91957. xx = encoder->private_->seek_table->points[i].sample_number;
  91958. b[7] = (FLAC__byte)xx; xx >>= 8;
  91959. b[6] = (FLAC__byte)xx; xx >>= 8;
  91960. b[5] = (FLAC__byte)xx; xx >>= 8;
  91961. b[4] = (FLAC__byte)xx; xx >>= 8;
  91962. b[3] = (FLAC__byte)xx; xx >>= 8;
  91963. b[2] = (FLAC__byte)xx; xx >>= 8;
  91964. b[1] = (FLAC__byte)xx; xx >>= 8;
  91965. b[0] = (FLAC__byte)xx; xx >>= 8;
  91966. xx = encoder->private_->seek_table->points[i].stream_offset;
  91967. b[15] = (FLAC__byte)xx; xx >>= 8;
  91968. b[14] = (FLAC__byte)xx; xx >>= 8;
  91969. b[13] = (FLAC__byte)xx; xx >>= 8;
  91970. b[12] = (FLAC__byte)xx; xx >>= 8;
  91971. b[11] = (FLAC__byte)xx; xx >>= 8;
  91972. b[10] = (FLAC__byte)xx; xx >>= 8;
  91973. b[9] = (FLAC__byte)xx; xx >>= 8;
  91974. b[8] = (FLAC__byte)xx; xx >>= 8;
  91975. x = encoder->private_->seek_table->points[i].frame_samples;
  91976. b[17] = (FLAC__byte)x; x >>= 8;
  91977. b[16] = (FLAC__byte)x; x >>= 8;
  91978. memcpy(p, b, 18);
  91979. }
  91980. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91981. simple_ogg_page__clear(&page);
  91982. return; /* state already set */
  91983. }
  91984. simple_ogg_page__clear(&page);
  91985. }
  91986. }
  91987. #endif
  91988. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  91989. {
  91990. FLAC__uint16 crc;
  91991. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91992. 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)) {
  91993. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91994. return false;
  91995. }
  91996. if(!process_subframes_(encoder, is_fractional_block)) {
  91997. return false;
  91998. }
  91999. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  92000. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92001. return false;
  92002. }
  92003. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92004. if(
  92005. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  92006. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  92007. ) {
  92008. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92009. return false;
  92010. }
  92011. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92012. return false;
  92013. }
  92014. encoder->private_->current_sample_number = 0;
  92015. encoder->private_->current_frame_number++;
  92016. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92017. return true;
  92018. }
  92019. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92020. {
  92021. FLAC__FrameHeader frame_header;
  92022. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92023. FLAC__bool do_independent, do_mid_side;
  92024. if(is_fractional_block) {
  92025. max_partition_order = 0;
  92026. }
  92027. else {
  92028. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92029. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92030. }
  92031. min_partition_order = min(min_partition_order, max_partition_order);
  92032. frame_header.blocksize = encoder->protected_->blocksize;
  92033. frame_header.sample_rate = encoder->protected_->sample_rate;
  92034. frame_header.channels = encoder->protected_->channels;
  92035. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92036. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92037. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92038. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92039. if(encoder->protected_->do_mid_side_stereo) {
  92040. if(encoder->protected_->loose_mid_side_stereo) {
  92041. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92042. do_independent = true;
  92043. do_mid_side = true;
  92044. }
  92045. else {
  92046. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92047. do_mid_side = !do_independent;
  92048. }
  92049. }
  92050. else {
  92051. do_independent = true;
  92052. do_mid_side = true;
  92053. }
  92054. }
  92055. else {
  92056. do_independent = true;
  92057. do_mid_side = false;
  92058. }
  92059. FLAC__ASSERT(do_independent || do_mid_side);
  92060. if(do_independent) {
  92061. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92062. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92063. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92064. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92065. }
  92066. }
  92067. if(do_mid_side) {
  92068. FLAC__ASSERT(encoder->protected_->channels == 2);
  92069. for(channel = 0; channel < 2; channel++) {
  92070. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92071. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92072. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92073. }
  92074. }
  92075. if(do_independent) {
  92076. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92077. if(!
  92078. process_subframe_(
  92079. encoder,
  92080. min_partition_order,
  92081. max_partition_order,
  92082. &frame_header,
  92083. encoder->private_->subframe_bps[channel],
  92084. encoder->private_->integer_signal[channel],
  92085. encoder->private_->subframe_workspace_ptr[channel],
  92086. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92087. encoder->private_->residual_workspace[channel],
  92088. encoder->private_->best_subframe+channel,
  92089. encoder->private_->best_subframe_bits+channel
  92090. )
  92091. )
  92092. return false;
  92093. }
  92094. }
  92095. if(do_mid_side) {
  92096. FLAC__ASSERT(encoder->protected_->channels == 2);
  92097. for(channel = 0; channel < 2; channel++) {
  92098. if(!
  92099. process_subframe_(
  92100. encoder,
  92101. min_partition_order,
  92102. max_partition_order,
  92103. &frame_header,
  92104. encoder->private_->subframe_bps_mid_side[channel],
  92105. encoder->private_->integer_signal_mid_side[channel],
  92106. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92107. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92108. encoder->private_->residual_workspace_mid_side[channel],
  92109. encoder->private_->best_subframe_mid_side+channel,
  92110. encoder->private_->best_subframe_bits_mid_side+channel
  92111. )
  92112. )
  92113. return false;
  92114. }
  92115. }
  92116. if(do_mid_side) {
  92117. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92118. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92119. FLAC__ChannelAssignment channel_assignment;
  92120. FLAC__ASSERT(encoder->protected_->channels == 2);
  92121. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92122. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92123. }
  92124. else {
  92125. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92126. unsigned min_bits;
  92127. int ca;
  92128. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92129. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92130. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92131. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92132. FLAC__ASSERT(do_independent && do_mid_side);
  92133. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92134. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92135. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92136. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92137. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92138. min_bits = bits[channel_assignment];
  92139. for(ca = 1; ca <= 3; ca++) {
  92140. if(bits[ca] < min_bits) {
  92141. min_bits = bits[ca];
  92142. channel_assignment = (FLAC__ChannelAssignment)ca;
  92143. }
  92144. }
  92145. }
  92146. frame_header.channel_assignment = channel_assignment;
  92147. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92148. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92149. return false;
  92150. }
  92151. switch(channel_assignment) {
  92152. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92153. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92154. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92155. break;
  92156. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92157. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92158. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92159. break;
  92160. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92161. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92162. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92163. break;
  92164. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92165. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92166. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92167. break;
  92168. default:
  92169. FLAC__ASSERT(0);
  92170. }
  92171. switch(channel_assignment) {
  92172. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92173. left_bps = encoder->private_->subframe_bps [0];
  92174. right_bps = encoder->private_->subframe_bps [1];
  92175. break;
  92176. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92177. left_bps = encoder->private_->subframe_bps [0];
  92178. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92179. break;
  92180. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92181. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92182. right_bps = encoder->private_->subframe_bps [1];
  92183. break;
  92184. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92185. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92186. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92187. break;
  92188. default:
  92189. FLAC__ASSERT(0);
  92190. }
  92191. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92192. return false;
  92193. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92194. return false;
  92195. }
  92196. else {
  92197. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92198. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92199. return false;
  92200. }
  92201. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92202. 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)) {
  92203. return false;
  92204. }
  92205. }
  92206. }
  92207. if(encoder->protected_->loose_mid_side_stereo) {
  92208. encoder->private_->loose_mid_side_stereo_frame_count++;
  92209. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92210. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92211. }
  92212. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92213. return true;
  92214. }
  92215. FLAC__bool process_subframe_(
  92216. FLAC__StreamEncoder *encoder,
  92217. unsigned min_partition_order,
  92218. unsigned max_partition_order,
  92219. const FLAC__FrameHeader *frame_header,
  92220. unsigned subframe_bps,
  92221. const FLAC__int32 integer_signal[],
  92222. FLAC__Subframe *subframe[2],
  92223. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92224. FLAC__int32 *residual[2],
  92225. unsigned *best_subframe,
  92226. unsigned *best_bits
  92227. )
  92228. {
  92229. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92230. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92231. #else
  92232. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92233. #endif
  92234. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92235. FLAC__double lpc_residual_bits_per_sample;
  92236. 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 */
  92237. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92238. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92239. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92240. #endif
  92241. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92242. unsigned rice_parameter;
  92243. unsigned _candidate_bits, _best_bits;
  92244. unsigned _best_subframe;
  92245. 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;
  92246. FLAC__ASSERT(frame_header->blocksize > 0);
  92247. _best_subframe = 0;
  92248. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92249. _best_bits = UINT_MAX;
  92250. else
  92251. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92252. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92253. unsigned signal_is_constant = false;
  92254. 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);
  92255. if(
  92256. !encoder->private_->disable_constant_subframes &&
  92257. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92258. fixed_residual_bits_per_sample[1] == 0.0
  92259. #else
  92260. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92261. #endif
  92262. ) {
  92263. unsigned i;
  92264. signal_is_constant = true;
  92265. for(i = 1; i < frame_header->blocksize; i++) {
  92266. if(integer_signal[0] != integer_signal[i]) {
  92267. signal_is_constant = false;
  92268. break;
  92269. }
  92270. }
  92271. }
  92272. if(signal_is_constant) {
  92273. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92274. if(_candidate_bits < _best_bits) {
  92275. _best_subframe = !_best_subframe;
  92276. _best_bits = _candidate_bits;
  92277. }
  92278. }
  92279. else {
  92280. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92281. if(encoder->protected_->do_exhaustive_model_search) {
  92282. min_fixed_order = 0;
  92283. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92284. }
  92285. else {
  92286. min_fixed_order = max_fixed_order = guess_fixed_order;
  92287. }
  92288. if(max_fixed_order >= frame_header->blocksize)
  92289. max_fixed_order = frame_header->blocksize - 1;
  92290. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92291. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92292. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92293. continue; /* don't even try */
  92294. 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 */
  92295. #else
  92296. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92297. continue; /* don't even try */
  92298. 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 */
  92299. #endif
  92300. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92301. if(rice_parameter >= rice_parameter_limit) {
  92302. #ifdef DEBUG_VERBOSE
  92303. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92304. #endif
  92305. rice_parameter = rice_parameter_limit - 1;
  92306. }
  92307. _candidate_bits =
  92308. evaluate_fixed_subframe_(
  92309. encoder,
  92310. integer_signal,
  92311. residual[!_best_subframe],
  92312. encoder->private_->abs_residual_partition_sums,
  92313. encoder->private_->raw_bits_per_partition,
  92314. frame_header->blocksize,
  92315. subframe_bps,
  92316. fixed_order,
  92317. rice_parameter,
  92318. rice_parameter_limit,
  92319. min_partition_order,
  92320. max_partition_order,
  92321. encoder->protected_->do_escape_coding,
  92322. encoder->protected_->rice_parameter_search_dist,
  92323. subframe[!_best_subframe],
  92324. partitioned_rice_contents[!_best_subframe]
  92325. );
  92326. if(_candidate_bits < _best_bits) {
  92327. _best_subframe = !_best_subframe;
  92328. _best_bits = _candidate_bits;
  92329. }
  92330. }
  92331. }
  92332. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92333. if(encoder->protected_->max_lpc_order > 0) {
  92334. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92335. max_lpc_order = frame_header->blocksize-1;
  92336. else
  92337. max_lpc_order = encoder->protected_->max_lpc_order;
  92338. if(max_lpc_order > 0) {
  92339. unsigned a;
  92340. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92341. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92342. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92343. if(autoc[0] != 0.0) {
  92344. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92345. if(encoder->protected_->do_exhaustive_model_search) {
  92346. min_lpc_order = 1;
  92347. }
  92348. else {
  92349. const unsigned guess_lpc_order =
  92350. FLAC__lpc_compute_best_order(
  92351. lpc_error,
  92352. max_lpc_order,
  92353. frame_header->blocksize,
  92354. subframe_bps + (
  92355. encoder->protected_->do_qlp_coeff_prec_search?
  92356. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92357. encoder->protected_->qlp_coeff_precision
  92358. )
  92359. );
  92360. min_lpc_order = max_lpc_order = guess_lpc_order;
  92361. }
  92362. if(max_lpc_order >= frame_header->blocksize)
  92363. max_lpc_order = frame_header->blocksize - 1;
  92364. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92365. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92366. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92367. continue; /* don't even try */
  92368. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92369. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92370. if(rice_parameter >= rice_parameter_limit) {
  92371. #ifdef DEBUG_VERBOSE
  92372. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92373. #endif
  92374. rice_parameter = rice_parameter_limit - 1;
  92375. }
  92376. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92377. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92378. if(subframe_bps <= 17) {
  92379. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92380. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92381. }
  92382. else
  92383. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92384. }
  92385. else {
  92386. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92387. }
  92388. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92389. _candidate_bits =
  92390. evaluate_lpc_subframe_(
  92391. encoder,
  92392. integer_signal,
  92393. residual[!_best_subframe],
  92394. encoder->private_->abs_residual_partition_sums,
  92395. encoder->private_->raw_bits_per_partition,
  92396. encoder->private_->lp_coeff[lpc_order-1],
  92397. frame_header->blocksize,
  92398. subframe_bps,
  92399. lpc_order,
  92400. qlp_coeff_precision,
  92401. rice_parameter,
  92402. rice_parameter_limit,
  92403. min_partition_order,
  92404. max_partition_order,
  92405. encoder->protected_->do_escape_coding,
  92406. encoder->protected_->rice_parameter_search_dist,
  92407. subframe[!_best_subframe],
  92408. partitioned_rice_contents[!_best_subframe]
  92409. );
  92410. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92411. if(_candidate_bits < _best_bits) {
  92412. _best_subframe = !_best_subframe;
  92413. _best_bits = _candidate_bits;
  92414. }
  92415. }
  92416. }
  92417. }
  92418. }
  92419. }
  92420. }
  92421. }
  92422. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92423. }
  92424. }
  92425. if(_best_bits == UINT_MAX) {
  92426. FLAC__ASSERT(_best_subframe == 0);
  92427. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92428. }
  92429. *best_subframe = _best_subframe;
  92430. *best_bits = _best_bits;
  92431. return true;
  92432. }
  92433. FLAC__bool add_subframe_(
  92434. FLAC__StreamEncoder *encoder,
  92435. unsigned blocksize,
  92436. unsigned subframe_bps,
  92437. const FLAC__Subframe *subframe,
  92438. FLAC__BitWriter *frame
  92439. )
  92440. {
  92441. switch(subframe->type) {
  92442. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92443. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92444. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92445. return false;
  92446. }
  92447. break;
  92448. case FLAC__SUBFRAME_TYPE_FIXED:
  92449. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92450. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92451. return false;
  92452. }
  92453. break;
  92454. case FLAC__SUBFRAME_TYPE_LPC:
  92455. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92456. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92457. return false;
  92458. }
  92459. break;
  92460. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92461. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92462. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92463. return false;
  92464. }
  92465. break;
  92466. default:
  92467. FLAC__ASSERT(0);
  92468. }
  92469. return true;
  92470. }
  92471. #define SPOTCHECK_ESTIMATE 0
  92472. #if SPOTCHECK_ESTIMATE
  92473. static void spotcheck_subframe_estimate_(
  92474. FLAC__StreamEncoder *encoder,
  92475. unsigned blocksize,
  92476. unsigned subframe_bps,
  92477. const FLAC__Subframe *subframe,
  92478. unsigned estimate
  92479. )
  92480. {
  92481. FLAC__bool ret;
  92482. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92483. if(frame == 0) {
  92484. fprintf(stderr, "EST: can't allocate frame\n");
  92485. return;
  92486. }
  92487. if(!FLAC__bitwriter_init(frame)) {
  92488. fprintf(stderr, "EST: can't init frame\n");
  92489. return;
  92490. }
  92491. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92492. FLAC__ASSERT(ret);
  92493. {
  92494. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92495. if(estimate != actual)
  92496. 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);
  92497. }
  92498. FLAC__bitwriter_delete(frame);
  92499. }
  92500. #endif
  92501. unsigned evaluate_constant_subframe_(
  92502. FLAC__StreamEncoder *encoder,
  92503. const FLAC__int32 signal,
  92504. unsigned blocksize,
  92505. unsigned subframe_bps,
  92506. FLAC__Subframe *subframe
  92507. )
  92508. {
  92509. unsigned estimate;
  92510. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92511. subframe->data.constant.value = signal;
  92512. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92513. #if SPOTCHECK_ESTIMATE
  92514. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92515. #else
  92516. (void)encoder, (void)blocksize;
  92517. #endif
  92518. return estimate;
  92519. }
  92520. unsigned evaluate_fixed_subframe_(
  92521. FLAC__StreamEncoder *encoder,
  92522. const FLAC__int32 signal[],
  92523. FLAC__int32 residual[],
  92524. FLAC__uint64 abs_residual_partition_sums[],
  92525. unsigned raw_bits_per_partition[],
  92526. unsigned blocksize,
  92527. unsigned subframe_bps,
  92528. unsigned order,
  92529. unsigned rice_parameter,
  92530. unsigned rice_parameter_limit,
  92531. unsigned min_partition_order,
  92532. unsigned max_partition_order,
  92533. FLAC__bool do_escape_coding,
  92534. unsigned rice_parameter_search_dist,
  92535. FLAC__Subframe *subframe,
  92536. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92537. )
  92538. {
  92539. unsigned i, residual_bits, estimate;
  92540. const unsigned residual_samples = blocksize - order;
  92541. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92542. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92543. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92544. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92545. subframe->data.fixed.residual = residual;
  92546. residual_bits =
  92547. find_best_partition_order_(
  92548. encoder->private_,
  92549. residual,
  92550. abs_residual_partition_sums,
  92551. raw_bits_per_partition,
  92552. residual_samples,
  92553. order,
  92554. rice_parameter,
  92555. rice_parameter_limit,
  92556. min_partition_order,
  92557. max_partition_order,
  92558. subframe_bps,
  92559. do_escape_coding,
  92560. rice_parameter_search_dist,
  92561. &subframe->data.fixed.entropy_coding_method
  92562. );
  92563. subframe->data.fixed.order = order;
  92564. for(i = 0; i < order; i++)
  92565. subframe->data.fixed.warmup[i] = signal[i];
  92566. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92567. #if SPOTCHECK_ESTIMATE
  92568. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92569. #endif
  92570. return estimate;
  92571. }
  92572. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92573. unsigned evaluate_lpc_subframe_(
  92574. FLAC__StreamEncoder *encoder,
  92575. const FLAC__int32 signal[],
  92576. FLAC__int32 residual[],
  92577. FLAC__uint64 abs_residual_partition_sums[],
  92578. unsigned raw_bits_per_partition[],
  92579. const FLAC__real lp_coeff[],
  92580. unsigned blocksize,
  92581. unsigned subframe_bps,
  92582. unsigned order,
  92583. unsigned qlp_coeff_precision,
  92584. unsigned rice_parameter,
  92585. unsigned rice_parameter_limit,
  92586. unsigned min_partition_order,
  92587. unsigned max_partition_order,
  92588. FLAC__bool do_escape_coding,
  92589. unsigned rice_parameter_search_dist,
  92590. FLAC__Subframe *subframe,
  92591. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92592. )
  92593. {
  92594. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92595. unsigned i, residual_bits, estimate;
  92596. int quantization, ret;
  92597. const unsigned residual_samples = blocksize - order;
  92598. if(subframe_bps <= 16) {
  92599. FLAC__ASSERT(order > 0);
  92600. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92601. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92602. }
  92603. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92604. if(ret != 0)
  92605. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92606. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92607. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92608. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92609. else
  92610. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92611. else
  92612. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92613. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92614. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92615. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92616. subframe->data.lpc.residual = residual;
  92617. residual_bits =
  92618. find_best_partition_order_(
  92619. encoder->private_,
  92620. residual,
  92621. abs_residual_partition_sums,
  92622. raw_bits_per_partition,
  92623. residual_samples,
  92624. order,
  92625. rice_parameter,
  92626. rice_parameter_limit,
  92627. min_partition_order,
  92628. max_partition_order,
  92629. subframe_bps,
  92630. do_escape_coding,
  92631. rice_parameter_search_dist,
  92632. &subframe->data.lpc.entropy_coding_method
  92633. );
  92634. subframe->data.lpc.order = order;
  92635. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92636. subframe->data.lpc.quantization_level = quantization;
  92637. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92638. for(i = 0; i < order; i++)
  92639. subframe->data.lpc.warmup[i] = signal[i];
  92640. 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;
  92641. #if SPOTCHECK_ESTIMATE
  92642. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92643. #endif
  92644. return estimate;
  92645. }
  92646. #endif
  92647. unsigned evaluate_verbatim_subframe_(
  92648. FLAC__StreamEncoder *encoder,
  92649. const FLAC__int32 signal[],
  92650. unsigned blocksize,
  92651. unsigned subframe_bps,
  92652. FLAC__Subframe *subframe
  92653. )
  92654. {
  92655. unsigned estimate;
  92656. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92657. subframe->data.verbatim.data = signal;
  92658. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92659. #if SPOTCHECK_ESTIMATE
  92660. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92661. #else
  92662. (void)encoder;
  92663. #endif
  92664. return estimate;
  92665. }
  92666. unsigned find_best_partition_order_(
  92667. FLAC__StreamEncoderPrivate *private_,
  92668. const FLAC__int32 residual[],
  92669. FLAC__uint64 abs_residual_partition_sums[],
  92670. unsigned raw_bits_per_partition[],
  92671. unsigned residual_samples,
  92672. unsigned predictor_order,
  92673. unsigned rice_parameter,
  92674. unsigned rice_parameter_limit,
  92675. unsigned min_partition_order,
  92676. unsigned max_partition_order,
  92677. unsigned bps,
  92678. FLAC__bool do_escape_coding,
  92679. unsigned rice_parameter_search_dist,
  92680. FLAC__EntropyCodingMethod *best_ecm
  92681. )
  92682. {
  92683. unsigned residual_bits, best_residual_bits = 0;
  92684. unsigned best_parameters_index = 0;
  92685. unsigned best_partition_order = 0;
  92686. const unsigned blocksize = residual_samples + predictor_order;
  92687. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92688. min_partition_order = min(min_partition_order, max_partition_order);
  92689. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92690. if(do_escape_coding)
  92691. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92692. {
  92693. int partition_order;
  92694. unsigned sum;
  92695. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92696. if(!
  92697. set_partitioned_rice_(
  92698. #ifdef EXACT_RICE_BITS_CALCULATION
  92699. residual,
  92700. #endif
  92701. abs_residual_partition_sums+sum,
  92702. raw_bits_per_partition+sum,
  92703. residual_samples,
  92704. predictor_order,
  92705. rice_parameter,
  92706. rice_parameter_limit,
  92707. rice_parameter_search_dist,
  92708. (unsigned)partition_order,
  92709. do_escape_coding,
  92710. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92711. &residual_bits
  92712. )
  92713. )
  92714. {
  92715. FLAC__ASSERT(best_residual_bits != 0);
  92716. break;
  92717. }
  92718. sum += 1u << partition_order;
  92719. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92720. best_residual_bits = residual_bits;
  92721. best_parameters_index = !best_parameters_index;
  92722. best_partition_order = partition_order;
  92723. }
  92724. }
  92725. }
  92726. best_ecm->data.partitioned_rice.order = best_partition_order;
  92727. {
  92728. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92729. unsigned partition;
  92730. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92731. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92732. if(do_escape_coding)
  92733. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92734. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92735. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92736. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92737. break;
  92738. }
  92739. }
  92740. }
  92741. return best_residual_bits;
  92742. }
  92743. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92744. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92745. const FLAC__int32 residual[],
  92746. FLAC__uint64 abs_residual_partition_sums[],
  92747. unsigned blocksize,
  92748. unsigned predictor_order,
  92749. unsigned min_partition_order,
  92750. unsigned max_partition_order
  92751. );
  92752. #endif
  92753. void precompute_partition_info_sums_(
  92754. const FLAC__int32 residual[],
  92755. FLAC__uint64 abs_residual_partition_sums[],
  92756. unsigned residual_samples,
  92757. unsigned predictor_order,
  92758. unsigned min_partition_order,
  92759. unsigned max_partition_order,
  92760. unsigned bps
  92761. )
  92762. {
  92763. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92764. unsigned partitions = 1u << max_partition_order;
  92765. FLAC__ASSERT(default_partition_samples > predictor_order);
  92766. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92767. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92768. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92769. return;
  92770. }
  92771. #endif
  92772. {
  92773. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92774. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92775. FLAC__uint32 abs_residual_partition_sum;
  92776. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92777. end += default_partition_samples;
  92778. abs_residual_partition_sum = 0;
  92779. for( ; residual_sample < end; residual_sample++)
  92780. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92781. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92782. }
  92783. }
  92784. else { /* have to pessimistically use 64 bits for accumulator */
  92785. FLAC__uint64 abs_residual_partition_sum;
  92786. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92787. end += default_partition_samples;
  92788. abs_residual_partition_sum = 0;
  92789. for( ; residual_sample < end; residual_sample++)
  92790. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92791. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92792. }
  92793. }
  92794. }
  92795. {
  92796. unsigned from_partition = 0, to_partition = partitions;
  92797. int partition_order;
  92798. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92799. unsigned i;
  92800. partitions >>= 1;
  92801. for(i = 0; i < partitions; i++) {
  92802. abs_residual_partition_sums[to_partition++] =
  92803. abs_residual_partition_sums[from_partition ] +
  92804. abs_residual_partition_sums[from_partition+1];
  92805. from_partition += 2;
  92806. }
  92807. }
  92808. }
  92809. }
  92810. void precompute_partition_info_escapes_(
  92811. const FLAC__int32 residual[],
  92812. unsigned raw_bits_per_partition[],
  92813. unsigned residual_samples,
  92814. unsigned predictor_order,
  92815. unsigned min_partition_order,
  92816. unsigned max_partition_order
  92817. )
  92818. {
  92819. int partition_order;
  92820. unsigned from_partition, to_partition = 0;
  92821. const unsigned blocksize = residual_samples + predictor_order;
  92822. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92823. FLAC__int32 r;
  92824. FLAC__uint32 rmax;
  92825. unsigned partition, partition_sample, partition_samples, residual_sample;
  92826. const unsigned partitions = 1u << partition_order;
  92827. const unsigned default_partition_samples = blocksize >> partition_order;
  92828. FLAC__ASSERT(default_partition_samples > predictor_order);
  92829. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92830. partition_samples = default_partition_samples;
  92831. if(partition == 0)
  92832. partition_samples -= predictor_order;
  92833. rmax = 0;
  92834. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92835. r = residual[residual_sample++];
  92836. if(r < 0)
  92837. rmax |= ~r;
  92838. else
  92839. rmax |= r;
  92840. }
  92841. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92842. }
  92843. to_partition = partitions;
  92844. break; /*@@@ yuck, should remove the 'for' loop instead */
  92845. }
  92846. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92847. unsigned m;
  92848. unsigned i;
  92849. const unsigned partitions = 1u << partition_order;
  92850. for(i = 0; i < partitions; i++) {
  92851. m = raw_bits_per_partition[from_partition];
  92852. from_partition++;
  92853. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92854. from_partition++;
  92855. to_partition++;
  92856. }
  92857. }
  92858. }
  92859. #ifdef EXACT_RICE_BITS_CALCULATION
  92860. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92861. const unsigned rice_parameter,
  92862. const unsigned partition_samples,
  92863. const FLAC__int32 *residual
  92864. )
  92865. {
  92866. unsigned i, partition_bits =
  92867. 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 */
  92868. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92869. ;
  92870. for(i = 0; i < partition_samples; i++)
  92871. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92872. return partition_bits;
  92873. }
  92874. #else
  92875. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92876. const unsigned rice_parameter,
  92877. const unsigned partition_samples,
  92878. const FLAC__uint64 abs_residual_partition_sum
  92879. )
  92880. {
  92881. return
  92882. 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 */
  92883. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92884. (
  92885. rice_parameter?
  92886. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92887. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92888. )
  92889. - (partition_samples >> 1)
  92890. ;
  92891. }
  92892. #endif
  92893. FLAC__bool set_partitioned_rice_(
  92894. #ifdef EXACT_RICE_BITS_CALCULATION
  92895. const FLAC__int32 residual[],
  92896. #endif
  92897. const FLAC__uint64 abs_residual_partition_sums[],
  92898. const unsigned raw_bits_per_partition[],
  92899. const unsigned residual_samples,
  92900. const unsigned predictor_order,
  92901. const unsigned suggested_rice_parameter,
  92902. const unsigned rice_parameter_limit,
  92903. const unsigned rice_parameter_search_dist,
  92904. const unsigned partition_order,
  92905. const FLAC__bool search_for_escapes,
  92906. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92907. unsigned *bits
  92908. )
  92909. {
  92910. unsigned rice_parameter, partition_bits;
  92911. unsigned best_partition_bits, best_rice_parameter = 0;
  92912. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92913. unsigned *parameters, *raw_bits;
  92914. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92915. unsigned min_rice_parameter, max_rice_parameter;
  92916. #else
  92917. (void)rice_parameter_search_dist;
  92918. #endif
  92919. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92920. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92921. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92922. parameters = partitioned_rice_contents->parameters;
  92923. raw_bits = partitioned_rice_contents->raw_bits;
  92924. if(partition_order == 0) {
  92925. best_partition_bits = (unsigned)(-1);
  92926. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92927. if(rice_parameter_search_dist) {
  92928. if(suggested_rice_parameter < rice_parameter_search_dist)
  92929. min_rice_parameter = 0;
  92930. else
  92931. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  92932. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  92933. if(max_rice_parameter >= rice_parameter_limit) {
  92934. #ifdef DEBUG_VERBOSE
  92935. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  92936. #endif
  92937. max_rice_parameter = rice_parameter_limit - 1;
  92938. }
  92939. }
  92940. else
  92941. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  92942. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92943. #else
  92944. rice_parameter = suggested_rice_parameter;
  92945. #endif
  92946. #ifdef EXACT_RICE_BITS_CALCULATION
  92947. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  92948. #else
  92949. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  92950. #endif
  92951. if(partition_bits < best_partition_bits) {
  92952. best_rice_parameter = rice_parameter;
  92953. best_partition_bits = partition_bits;
  92954. }
  92955. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92956. }
  92957. #endif
  92958. if(search_for_escapes) {
  92959. 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;
  92960. if(partition_bits <= best_partition_bits) {
  92961. raw_bits[0] = raw_bits_per_partition[0];
  92962. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92963. best_partition_bits = partition_bits;
  92964. }
  92965. else
  92966. raw_bits[0] = 0;
  92967. }
  92968. parameters[0] = best_rice_parameter;
  92969. bits_ += best_partition_bits;
  92970. }
  92971. else {
  92972. unsigned partition, residual_sample;
  92973. unsigned partition_samples;
  92974. FLAC__uint64 mean, k;
  92975. const unsigned partitions = 1u << partition_order;
  92976. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92977. partition_samples = (residual_samples+predictor_order) >> partition_order;
  92978. if(partition == 0) {
  92979. if(partition_samples <= predictor_order)
  92980. return false;
  92981. else
  92982. partition_samples -= predictor_order;
  92983. }
  92984. mean = abs_residual_partition_sums[partition];
  92985. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  92986. ;
  92987. if(rice_parameter >= rice_parameter_limit) {
  92988. #ifdef DEBUG_VERBOSE
  92989. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  92990. #endif
  92991. rice_parameter = rice_parameter_limit - 1;
  92992. }
  92993. best_partition_bits = (unsigned)(-1);
  92994. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92995. if(rice_parameter_search_dist) {
  92996. if(rice_parameter < rice_parameter_search_dist)
  92997. min_rice_parameter = 0;
  92998. else
  92999. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  93000. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  93001. if(max_rice_parameter >= rice_parameter_limit) {
  93002. #ifdef DEBUG_VERBOSE
  93003. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  93004. #endif
  93005. max_rice_parameter = rice_parameter_limit - 1;
  93006. }
  93007. }
  93008. else
  93009. min_rice_parameter = max_rice_parameter = rice_parameter;
  93010. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93011. #endif
  93012. #ifdef EXACT_RICE_BITS_CALCULATION
  93013. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93014. #else
  93015. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93016. #endif
  93017. if(partition_bits < best_partition_bits) {
  93018. best_rice_parameter = rice_parameter;
  93019. best_partition_bits = partition_bits;
  93020. }
  93021. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93022. }
  93023. #endif
  93024. if(search_for_escapes) {
  93025. 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;
  93026. if(partition_bits <= best_partition_bits) {
  93027. raw_bits[partition] = raw_bits_per_partition[partition];
  93028. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93029. best_partition_bits = partition_bits;
  93030. }
  93031. else
  93032. raw_bits[partition] = 0;
  93033. }
  93034. parameters[partition] = best_rice_parameter;
  93035. bits_ += best_partition_bits;
  93036. residual_sample += partition_samples;
  93037. }
  93038. }
  93039. *bits = bits_;
  93040. return true;
  93041. }
  93042. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93043. {
  93044. unsigned i, shift;
  93045. FLAC__int32 x = 0;
  93046. for(i = 0; i < samples && !(x&1); i++)
  93047. x |= signal[i];
  93048. if(x == 0) {
  93049. shift = 0;
  93050. }
  93051. else {
  93052. for(shift = 0; !(x&1); shift++)
  93053. x >>= 1;
  93054. }
  93055. if(shift > 0) {
  93056. for(i = 0; i < samples; i++)
  93057. signal[i] >>= shift;
  93058. }
  93059. return shift;
  93060. }
  93061. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93062. {
  93063. unsigned channel;
  93064. for(channel = 0; channel < channels; channel++)
  93065. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93066. fifo->tail += wide_samples;
  93067. FLAC__ASSERT(fifo->tail <= fifo->size);
  93068. }
  93069. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93070. {
  93071. unsigned channel;
  93072. unsigned sample, wide_sample;
  93073. unsigned tail = fifo->tail;
  93074. sample = input_offset * channels;
  93075. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93076. for(channel = 0; channel < channels; channel++)
  93077. fifo->data[channel][tail] = input[sample++];
  93078. tail++;
  93079. }
  93080. fifo->tail = tail;
  93081. FLAC__ASSERT(fifo->tail <= fifo->size);
  93082. }
  93083. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93084. {
  93085. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93086. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93087. (void)decoder;
  93088. if(encoder->private_->verify.needs_magic_hack) {
  93089. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93090. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93091. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93092. encoder->private_->verify.needs_magic_hack = false;
  93093. }
  93094. else {
  93095. if(encoded_bytes == 0) {
  93096. FLAC__ASSERT(0);
  93097. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93098. }
  93099. else if(encoded_bytes < *bytes)
  93100. *bytes = encoded_bytes;
  93101. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93102. encoder->private_->verify.output.data += *bytes;
  93103. encoder->private_->verify.output.bytes -= *bytes;
  93104. }
  93105. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93106. }
  93107. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93108. {
  93109. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93110. unsigned channel;
  93111. const unsigned channels = frame->header.channels;
  93112. const unsigned blocksize = frame->header.blocksize;
  93113. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93114. (void)decoder;
  93115. for(channel = 0; channel < channels; channel++) {
  93116. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93117. unsigned i, sample = 0;
  93118. FLAC__int32 expect = 0, got = 0;
  93119. for(i = 0; i < blocksize; i++) {
  93120. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93121. sample = i;
  93122. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93123. got = (FLAC__int32)buffer[channel][i];
  93124. break;
  93125. }
  93126. }
  93127. FLAC__ASSERT(i < blocksize);
  93128. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93129. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93130. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93131. encoder->private_->verify.error_stats.channel = channel;
  93132. encoder->private_->verify.error_stats.sample = sample;
  93133. encoder->private_->verify.error_stats.expected = expect;
  93134. encoder->private_->verify.error_stats.got = got;
  93135. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93136. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93137. }
  93138. }
  93139. encoder->private_->verify.input_fifo.tail -= blocksize;
  93140. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93141. for(channel = 0; channel < channels; channel++)
  93142. 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]));
  93143. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93144. }
  93145. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93146. {
  93147. (void)decoder, (void)metadata, (void)client_data;
  93148. }
  93149. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93150. {
  93151. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93152. (void)decoder, (void)status;
  93153. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93154. }
  93155. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93156. {
  93157. (void)client_data;
  93158. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93159. if (*bytes == 0) {
  93160. if (feof(encoder->private_->file))
  93161. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93162. else if (ferror(encoder->private_->file))
  93163. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93164. }
  93165. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93166. }
  93167. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93168. {
  93169. (void)client_data;
  93170. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93171. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93172. else
  93173. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93174. }
  93175. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93176. {
  93177. off_t offset;
  93178. (void)client_data;
  93179. offset = ftello(encoder->private_->file);
  93180. if(offset < 0) {
  93181. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93182. }
  93183. else {
  93184. *absolute_byte_offset = (FLAC__uint64)offset;
  93185. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93186. }
  93187. }
  93188. #ifdef FLAC__VALGRIND_TESTING
  93189. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93190. {
  93191. size_t ret = fwrite(ptr, size, nmemb, stream);
  93192. if(!ferror(stream))
  93193. fflush(stream);
  93194. return ret;
  93195. }
  93196. #else
  93197. #define local__fwrite fwrite
  93198. #endif
  93199. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93200. {
  93201. (void)client_data, (void)current_frame;
  93202. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93203. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93204. #if FLAC__HAS_OGG
  93205. encoder->private_->is_ogg? true :
  93206. #endif
  93207. samples > 0
  93208. );
  93209. if(call_it) {
  93210. 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);
  93211. }
  93212. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93213. }
  93214. else
  93215. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93216. }
  93217. FILE *get_binary_stdout_(void)
  93218. {
  93219. #if defined _MSC_VER || defined __MINGW32__
  93220. _setmode(_fileno(stdout), _O_BINARY);
  93221. #elif defined __CYGWIN__
  93222. setmode(_fileno(stdout), _O_BINARY);
  93223. #elif defined __EMX__
  93224. setmode(fileno(stdout), O_BINARY);
  93225. #endif
  93226. return stdout;
  93227. }
  93228. #endif
  93229. /*** End of inlined file: stream_encoder.c ***/
  93230. /*** Start of inlined file: stream_encoder_framing.c ***/
  93231. /*** Start of inlined file: juce_FlacHeader.h ***/
  93232. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93233. // tasks..
  93234. #define VERSION "1.2.1"
  93235. #define FLAC__NO_DLL 1
  93236. #if JUCE_MSVC
  93237. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93238. #endif
  93239. #if JUCE_MAC
  93240. #define FLAC__SYS_DARWIN 1
  93241. #endif
  93242. /*** End of inlined file: juce_FlacHeader.h ***/
  93243. #if JUCE_USE_FLAC
  93244. #if HAVE_CONFIG_H
  93245. # include <config.h>
  93246. #endif
  93247. #include <stdio.h>
  93248. #include <string.h> /* for strlen() */
  93249. #ifdef max
  93250. #undef max
  93251. #endif
  93252. #define max(x,y) ((x)>(y)?(x):(y))
  93253. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93254. 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);
  93255. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93256. {
  93257. unsigned i, j;
  93258. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93259. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93260. return false;
  93261. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93262. return false;
  93263. i = metadata->length;
  93264. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93265. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93266. i -= metadata->data.vorbis_comment.vendor_string.length;
  93267. i += vendor_string_length;
  93268. }
  93269. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93270. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93271. return false;
  93272. switch(metadata->type) {
  93273. case FLAC__METADATA_TYPE_STREAMINFO:
  93274. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93275. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93276. return false;
  93277. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93278. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93279. return false;
  93280. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93281. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93282. return false;
  93283. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93284. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93285. return false;
  93286. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93287. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93288. return false;
  93289. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93290. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93291. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93292. return false;
  93293. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93294. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93295. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93296. return false;
  93297. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93298. return false;
  93299. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93300. return false;
  93301. break;
  93302. case FLAC__METADATA_TYPE_PADDING:
  93303. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93304. return false;
  93305. break;
  93306. case FLAC__METADATA_TYPE_APPLICATION:
  93307. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93308. return false;
  93309. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93310. return false;
  93311. break;
  93312. case FLAC__METADATA_TYPE_SEEKTABLE:
  93313. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93314. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93315. return false;
  93316. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93317. return false;
  93318. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93319. return false;
  93320. }
  93321. break;
  93322. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93323. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93324. return false;
  93325. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93326. return false;
  93327. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93328. return false;
  93329. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93330. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93331. return false;
  93332. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93333. return false;
  93334. }
  93335. break;
  93336. case FLAC__METADATA_TYPE_CUESHEET:
  93337. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93338. 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))
  93339. return false;
  93340. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93341. return false;
  93342. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93343. return false;
  93344. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93345. return false;
  93346. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93347. return false;
  93348. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93349. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93350. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93351. return false;
  93352. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93353. return false;
  93354. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93355. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93356. return false;
  93357. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93358. return false;
  93359. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93360. return false;
  93361. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93362. return false;
  93363. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93364. return false;
  93365. for(j = 0; j < track->num_indices; j++) {
  93366. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93367. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93368. return false;
  93369. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93370. return false;
  93371. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93372. return false;
  93373. }
  93374. }
  93375. break;
  93376. case FLAC__METADATA_TYPE_PICTURE:
  93377. {
  93378. size_t len;
  93379. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93380. return false;
  93381. len = strlen(metadata->data.picture.mime_type);
  93382. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93383. return false;
  93384. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93385. return false;
  93386. len = strlen((const char *)metadata->data.picture.description);
  93387. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93388. return false;
  93389. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93390. return false;
  93391. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93392. return false;
  93393. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93394. return false;
  93395. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93396. return false;
  93397. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93398. return false;
  93399. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93400. return false;
  93401. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93402. return false;
  93403. }
  93404. break;
  93405. default:
  93406. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93407. return false;
  93408. break;
  93409. }
  93410. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93411. return true;
  93412. }
  93413. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93414. {
  93415. unsigned u, blocksize_hint, sample_rate_hint;
  93416. FLAC__byte crc;
  93417. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93418. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93419. return false;
  93420. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93421. return false;
  93422. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93423. return false;
  93424. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93425. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93426. blocksize_hint = 0;
  93427. switch(header->blocksize) {
  93428. case 192: u = 1; break;
  93429. case 576: u = 2; break;
  93430. case 1152: u = 3; break;
  93431. case 2304: u = 4; break;
  93432. case 4608: u = 5; break;
  93433. case 256: u = 8; break;
  93434. case 512: u = 9; break;
  93435. case 1024: u = 10; break;
  93436. case 2048: u = 11; break;
  93437. case 4096: u = 12; break;
  93438. case 8192: u = 13; break;
  93439. case 16384: u = 14; break;
  93440. case 32768: u = 15; break;
  93441. default:
  93442. if(header->blocksize <= 0x100)
  93443. blocksize_hint = u = 6;
  93444. else
  93445. blocksize_hint = u = 7;
  93446. break;
  93447. }
  93448. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93449. return false;
  93450. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93451. sample_rate_hint = 0;
  93452. switch(header->sample_rate) {
  93453. case 88200: u = 1; break;
  93454. case 176400: u = 2; break;
  93455. case 192000: u = 3; break;
  93456. case 8000: u = 4; break;
  93457. case 16000: u = 5; break;
  93458. case 22050: u = 6; break;
  93459. case 24000: u = 7; break;
  93460. case 32000: u = 8; break;
  93461. case 44100: u = 9; break;
  93462. case 48000: u = 10; break;
  93463. case 96000: u = 11; break;
  93464. default:
  93465. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93466. sample_rate_hint = u = 12;
  93467. else if(header->sample_rate % 10 == 0)
  93468. sample_rate_hint = u = 14;
  93469. else if(header->sample_rate <= 0xffff)
  93470. sample_rate_hint = u = 13;
  93471. else
  93472. u = 0;
  93473. break;
  93474. }
  93475. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93476. return false;
  93477. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93478. switch(header->channel_assignment) {
  93479. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93480. u = header->channels - 1;
  93481. break;
  93482. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93483. FLAC__ASSERT(header->channels == 2);
  93484. u = 8;
  93485. break;
  93486. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93487. FLAC__ASSERT(header->channels == 2);
  93488. u = 9;
  93489. break;
  93490. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93491. FLAC__ASSERT(header->channels == 2);
  93492. u = 10;
  93493. break;
  93494. default:
  93495. FLAC__ASSERT(0);
  93496. }
  93497. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93498. return false;
  93499. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93500. switch(header->bits_per_sample) {
  93501. case 8 : u = 1; break;
  93502. case 12: u = 2; break;
  93503. case 16: u = 4; break;
  93504. case 20: u = 5; break;
  93505. case 24: u = 6; break;
  93506. default: u = 0; break;
  93507. }
  93508. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93509. return false;
  93510. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93511. return false;
  93512. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93513. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93514. return false;
  93515. }
  93516. else {
  93517. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93518. return false;
  93519. }
  93520. if(blocksize_hint)
  93521. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93522. return false;
  93523. switch(sample_rate_hint) {
  93524. case 12:
  93525. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93526. return false;
  93527. break;
  93528. case 13:
  93529. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93530. return false;
  93531. break;
  93532. case 14:
  93533. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93534. return false;
  93535. break;
  93536. }
  93537. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93538. return false;
  93539. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93540. return false;
  93541. return true;
  93542. }
  93543. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93544. {
  93545. FLAC__bool ok;
  93546. ok =
  93547. 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) &&
  93548. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93549. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93550. ;
  93551. return ok;
  93552. }
  93553. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93554. {
  93555. unsigned i;
  93556. 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))
  93557. return false;
  93558. if(wasted_bits)
  93559. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93560. return false;
  93561. for(i = 0; i < subframe->order; i++)
  93562. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93563. return false;
  93564. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93565. return false;
  93566. switch(subframe->entropy_coding_method.type) {
  93567. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93568. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93569. if(!add_residual_partitioned_rice_(
  93570. bw,
  93571. subframe->residual,
  93572. residual_samples,
  93573. subframe->order,
  93574. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93575. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93576. subframe->entropy_coding_method.data.partitioned_rice.order,
  93577. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93578. ))
  93579. return false;
  93580. break;
  93581. default:
  93582. FLAC__ASSERT(0);
  93583. }
  93584. return true;
  93585. }
  93586. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93587. {
  93588. unsigned i;
  93589. 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))
  93590. return false;
  93591. if(wasted_bits)
  93592. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93593. return false;
  93594. for(i = 0; i < subframe->order; i++)
  93595. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93596. return false;
  93597. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93598. return false;
  93599. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93600. return false;
  93601. for(i = 0; i < subframe->order; i++)
  93602. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93603. return false;
  93604. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93605. return false;
  93606. switch(subframe->entropy_coding_method.type) {
  93607. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93608. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93609. if(!add_residual_partitioned_rice_(
  93610. bw,
  93611. subframe->residual,
  93612. residual_samples,
  93613. subframe->order,
  93614. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93615. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93616. subframe->entropy_coding_method.data.partitioned_rice.order,
  93617. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93618. ))
  93619. return false;
  93620. break;
  93621. default:
  93622. FLAC__ASSERT(0);
  93623. }
  93624. return true;
  93625. }
  93626. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93627. {
  93628. unsigned i;
  93629. const FLAC__int32 *signal = subframe->data;
  93630. 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))
  93631. return false;
  93632. if(wasted_bits)
  93633. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93634. return false;
  93635. for(i = 0; i < samples; i++)
  93636. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93637. return false;
  93638. return true;
  93639. }
  93640. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93641. {
  93642. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93643. return false;
  93644. switch(method->type) {
  93645. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93646. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93647. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93648. return false;
  93649. break;
  93650. default:
  93651. FLAC__ASSERT(0);
  93652. }
  93653. return true;
  93654. }
  93655. 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)
  93656. {
  93657. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93658. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93659. if(partition_order == 0) {
  93660. unsigned i;
  93661. if(raw_bits[0] == 0) {
  93662. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93663. return false;
  93664. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93665. return false;
  93666. }
  93667. else {
  93668. FLAC__ASSERT(rice_parameters[0] == 0);
  93669. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93670. return false;
  93671. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93672. return false;
  93673. for(i = 0; i < residual_samples; i++) {
  93674. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93675. return false;
  93676. }
  93677. }
  93678. return true;
  93679. }
  93680. else {
  93681. unsigned i, j, k = 0, k_last = 0;
  93682. unsigned partition_samples;
  93683. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93684. for(i = 0; i < (1u<<partition_order); i++) {
  93685. partition_samples = default_partition_samples;
  93686. if(i == 0)
  93687. partition_samples -= predictor_order;
  93688. k += partition_samples;
  93689. if(raw_bits[i] == 0) {
  93690. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93691. return false;
  93692. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93693. return false;
  93694. }
  93695. else {
  93696. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93697. return false;
  93698. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93699. return false;
  93700. for(j = k_last; j < k; j++) {
  93701. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93702. return false;
  93703. }
  93704. }
  93705. k_last = k;
  93706. }
  93707. return true;
  93708. }
  93709. }
  93710. #endif
  93711. /*** End of inlined file: stream_encoder_framing.c ***/
  93712. /*** Start of inlined file: window_flac.c ***/
  93713. /*** Start of inlined file: juce_FlacHeader.h ***/
  93714. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93715. // tasks..
  93716. #define VERSION "1.2.1"
  93717. #define FLAC__NO_DLL 1
  93718. #if JUCE_MSVC
  93719. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93720. #endif
  93721. #if JUCE_MAC
  93722. #define FLAC__SYS_DARWIN 1
  93723. #endif
  93724. /*** End of inlined file: juce_FlacHeader.h ***/
  93725. #if JUCE_USE_FLAC
  93726. #if HAVE_CONFIG_H
  93727. # include <config.h>
  93728. #endif
  93729. #include <math.h>
  93730. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93731. #ifndef M_PI
  93732. #define M_PI 3.14159265358979323846
  93733. #endif
  93734. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93735. {
  93736. const FLAC__int32 N = L - 1;
  93737. FLAC__int32 n;
  93738. if (L & 1) {
  93739. for (n = 0; n <= N/2; n++)
  93740. window[n] = 2.0f * n / (float)N;
  93741. for (; n <= N; n++)
  93742. window[n] = 2.0f - 2.0f * n / (float)N;
  93743. }
  93744. else {
  93745. for (n = 0; n <= L/2-1; n++)
  93746. window[n] = 2.0f * n / (float)N;
  93747. for (; n <= N; n++)
  93748. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93749. }
  93750. }
  93751. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93752. {
  93753. const FLAC__int32 N = L - 1;
  93754. FLAC__int32 n;
  93755. for (n = 0; n < L; n++)
  93756. 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)));
  93757. }
  93758. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93759. {
  93760. const FLAC__int32 N = L - 1;
  93761. FLAC__int32 n;
  93762. for (n = 0; n < L; n++)
  93763. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93764. }
  93765. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93766. {
  93767. const FLAC__int32 N = L - 1;
  93768. FLAC__int32 n;
  93769. for (n = 0; n <= N; n++)
  93770. 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));
  93771. }
  93772. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93773. {
  93774. const FLAC__int32 N = L - 1;
  93775. const double N2 = (double)N / 2.;
  93776. FLAC__int32 n;
  93777. for (n = 0; n <= N; n++) {
  93778. double k = ((double)n - N2) / N2;
  93779. k = 1.0f - k * k;
  93780. window[n] = (FLAC__real)(k * k);
  93781. }
  93782. }
  93783. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  93784. {
  93785. const FLAC__int32 N = L - 1;
  93786. FLAC__int32 n;
  93787. for (n = 0; n < L; n++)
  93788. 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));
  93789. }
  93790. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93791. {
  93792. const FLAC__int32 N = L - 1;
  93793. const double N2 = (double)N / 2.;
  93794. FLAC__int32 n;
  93795. for (n = 0; n <= N; n++) {
  93796. const double k = ((double)n - N2) / (stddev * N2);
  93797. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93798. }
  93799. }
  93800. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93801. {
  93802. const FLAC__int32 N = L - 1;
  93803. FLAC__int32 n;
  93804. for (n = 0; n < L; n++)
  93805. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93806. }
  93807. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93808. {
  93809. const FLAC__int32 N = L - 1;
  93810. FLAC__int32 n;
  93811. for (n = 0; n < L; n++)
  93812. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93813. }
  93814. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93815. {
  93816. const FLAC__int32 N = L - 1;
  93817. FLAC__int32 n;
  93818. for (n = 0; n < L; n++)
  93819. 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));
  93820. }
  93821. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93822. {
  93823. const FLAC__int32 N = L - 1;
  93824. FLAC__int32 n;
  93825. for (n = 0; n < L; n++)
  93826. 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));
  93827. }
  93828. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93829. {
  93830. FLAC__int32 n;
  93831. for (n = 0; n < L; n++)
  93832. window[n] = 1.0f;
  93833. }
  93834. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93835. {
  93836. FLAC__int32 n;
  93837. if (L & 1) {
  93838. for (n = 1; n <= L+1/2; n++)
  93839. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93840. for (; n <= L; n++)
  93841. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93842. }
  93843. else {
  93844. for (n = 1; n <= L/2; n++)
  93845. window[n-1] = 2.0f * n / (float)L;
  93846. for (; n <= L; n++)
  93847. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93848. }
  93849. }
  93850. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93851. {
  93852. if (p <= 0.0)
  93853. FLAC__window_rectangle(window, L);
  93854. else if (p >= 1.0)
  93855. FLAC__window_hann(window, L);
  93856. else {
  93857. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93858. FLAC__int32 n;
  93859. FLAC__window_rectangle(window, L);
  93860. if (Np > 0) {
  93861. for (n = 0; n <= Np; n++) {
  93862. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93863. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93864. }
  93865. }
  93866. }
  93867. }
  93868. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93869. {
  93870. const FLAC__int32 N = L - 1;
  93871. const double N2 = (double)N / 2.;
  93872. FLAC__int32 n;
  93873. for (n = 0; n <= N; n++) {
  93874. const double k = ((double)n - N2) / N2;
  93875. window[n] = (FLAC__real)(1.0f - k * k);
  93876. }
  93877. }
  93878. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93879. #endif
  93880. /*** End of inlined file: window_flac.c ***/
  93881. #else
  93882. #include <FLAC/all.h>
  93883. #endif
  93884. }
  93885. #ifdef _MSC_VER
  93886. #pragma warning (pop)
  93887. #endif
  93888. BEGIN_JUCE_NAMESPACE
  93889. static const char* const flacFormatName = "FLAC file";
  93890. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  93891. class FlacReader : public AudioFormatReader
  93892. {
  93893. public:
  93894. FlacReader (InputStream* const in)
  93895. : AudioFormatReader (in, TRANS (flacFormatName)),
  93896. reservoir (2, 0),
  93897. reservoirStart (0),
  93898. samplesInReservoir (0),
  93899. scanningForLength (false)
  93900. {
  93901. using namespace FlacNamespace;
  93902. lengthInSamples = 0;
  93903. decoder = FLAC__stream_decoder_new();
  93904. ok = FLAC__stream_decoder_init_stream (decoder,
  93905. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93906. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93907. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93908. if (ok)
  93909. {
  93910. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93911. if (lengthInSamples == 0 && sampleRate > 0)
  93912. {
  93913. // the length hasn't been stored in the metadata, so we'll need to
  93914. // work it out the length the hard way, by scanning the whole file..
  93915. scanningForLength = true;
  93916. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93917. scanningForLength = false;
  93918. const int64 tempLength = lengthInSamples;
  93919. FLAC__stream_decoder_reset (decoder);
  93920. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93921. lengthInSamples = tempLength;
  93922. }
  93923. }
  93924. }
  93925. ~FlacReader()
  93926. {
  93927. FlacNamespace::FLAC__stream_decoder_delete (decoder);
  93928. }
  93929. void useMetadata (const FlacNamespace::FLAC__StreamMetadata_StreamInfo& info)
  93930. {
  93931. sampleRate = info.sample_rate;
  93932. bitsPerSample = info.bits_per_sample;
  93933. lengthInSamples = (unsigned int) info.total_samples;
  93934. numChannels = info.channels;
  93935. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  93936. }
  93937. // returns the number of samples read
  93938. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  93939. int64 startSampleInFile, int numSamples)
  93940. {
  93941. using namespace FlacNamespace;
  93942. if (! ok)
  93943. return false;
  93944. while (numSamples > 0)
  93945. {
  93946. if (startSampleInFile >= reservoirStart
  93947. && startSampleInFile < reservoirStart + samplesInReservoir)
  93948. {
  93949. const int num = (int) jmin ((int64) numSamples,
  93950. reservoirStart + samplesInReservoir - startSampleInFile);
  93951. jassert (num > 0);
  93952. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  93953. if (destSamples[i] != 0)
  93954. memcpy (destSamples[i] + startOffsetInDestBuffer,
  93955. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  93956. sizeof (int) * num);
  93957. startOffsetInDestBuffer += num;
  93958. startSampleInFile += num;
  93959. numSamples -= num;
  93960. }
  93961. else
  93962. {
  93963. if (startSampleInFile >= (int) lengthInSamples)
  93964. {
  93965. samplesInReservoir = 0;
  93966. }
  93967. else if (startSampleInFile < reservoirStart
  93968. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  93969. {
  93970. // had some problems with flac crashing if the read pos is aligned more
  93971. // accurately than this. Probably fixed in newer versions of the library, though.
  93972. reservoirStart = (int) (startSampleInFile & ~511);
  93973. samplesInReservoir = 0;
  93974. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  93975. }
  93976. else
  93977. {
  93978. reservoirStart += samplesInReservoir;
  93979. samplesInReservoir = 0;
  93980. FLAC__stream_decoder_process_single (decoder);
  93981. }
  93982. if (samplesInReservoir == 0)
  93983. break;
  93984. }
  93985. }
  93986. if (numSamples > 0)
  93987. {
  93988. for (int i = numDestChannels; --i >= 0;)
  93989. if (destSamples[i] != 0)
  93990. zeromem (destSamples[i] + startOffsetInDestBuffer,
  93991. sizeof (int) * numSamples);
  93992. }
  93993. return true;
  93994. }
  93995. void useSamples (const FlacNamespace::FLAC__int32* const buffer[], int numSamples)
  93996. {
  93997. if (scanningForLength)
  93998. {
  93999. lengthInSamples += numSamples;
  94000. }
  94001. else
  94002. {
  94003. if (numSamples > reservoir.getNumSamples())
  94004. reservoir.setSize (numChannels, numSamples, false, false, true);
  94005. const int bitsToShift = 32 - bitsPerSample;
  94006. for (int i = 0; i < (int) numChannels; ++i)
  94007. {
  94008. const FlacNamespace::FLAC__int32* src = buffer[i];
  94009. int n = i;
  94010. while (src == 0 && n > 0)
  94011. src = buffer [--n];
  94012. if (src != 0)
  94013. {
  94014. int* dest = (int*) reservoir.getSampleData(i);
  94015. for (int j = 0; j < numSamples; ++j)
  94016. dest[j] = src[j] << bitsToShift;
  94017. }
  94018. }
  94019. samplesInReservoir = numSamples;
  94020. }
  94021. }
  94022. static FlacNamespace::FLAC__StreamDecoderReadStatus readCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__byte buffer[], size_t* bytes, void* client_data)
  94023. {
  94024. using namespace FlacNamespace;
  94025. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94026. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94027. }
  94028. static FlacNamespace::FLAC__StreamDecoderSeekStatus seekCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64 absolute_byte_offset, void* client_data)
  94029. {
  94030. using namespace FlacNamespace;
  94031. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94032. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94033. }
  94034. static FlacNamespace::FLAC__StreamDecoderTellStatus tellCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  94035. {
  94036. using namespace FlacNamespace;
  94037. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94038. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94039. }
  94040. static FlacNamespace::FLAC__StreamDecoderLengthStatus lengthCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* stream_length, void* client_data)
  94041. {
  94042. using namespace FlacNamespace;
  94043. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94044. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94045. }
  94046. static FlacNamespace::FLAC__bool eofCallback_ (const FlacNamespace::FLAC__StreamDecoder*, void* client_data)
  94047. {
  94048. return ((const FlacReader*) client_data)->input->isExhausted();
  94049. }
  94050. static FlacNamespace::FLAC__StreamDecoderWriteStatus writeCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  94051. const FlacNamespace::FLAC__Frame* frame,
  94052. const FlacNamespace::FLAC__int32* const buffer[],
  94053. void* client_data)
  94054. {
  94055. using namespace FlacNamespace;
  94056. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94057. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94058. }
  94059. static void metadataCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  94060. const FlacNamespace::FLAC__StreamMetadata* metadata,
  94061. void* client_data)
  94062. {
  94063. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94064. }
  94065. static void errorCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__StreamDecoderErrorStatus, void*)
  94066. {
  94067. }
  94068. juce_UseDebuggingNewOperator
  94069. private:
  94070. FlacNamespace::FLAC__StreamDecoder* decoder;
  94071. AudioSampleBuffer reservoir;
  94072. int reservoirStart, samplesInReservoir;
  94073. bool ok, scanningForLength;
  94074. FlacReader (const FlacReader&);
  94075. FlacReader& operator= (const FlacReader&);
  94076. };
  94077. class FlacWriter : public AudioFormatWriter
  94078. {
  94079. public:
  94080. FlacWriter (OutputStream* const out,
  94081. const double sampleRate_,
  94082. const int numChannels_,
  94083. const int bitsPerSample_)
  94084. : AudioFormatWriter (out, TRANS (flacFormatName),
  94085. sampleRate_,
  94086. numChannels_,
  94087. bitsPerSample_)
  94088. {
  94089. using namespace FlacNamespace;
  94090. encoder = FLAC__stream_encoder_new();
  94091. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94092. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94093. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94094. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94095. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94096. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94097. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94098. ok = FLAC__stream_encoder_init_stream (encoder,
  94099. encodeWriteCallback, encodeSeekCallback,
  94100. encodeTellCallback, encodeMetadataCallback,
  94101. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94102. }
  94103. ~FlacWriter()
  94104. {
  94105. if (ok)
  94106. {
  94107. FLAC__stream_encoder_finish (encoder);
  94108. output->flush();
  94109. }
  94110. else
  94111. {
  94112. output = 0; // to stop the base class deleting this, as it needs to be returned
  94113. // to the caller of createWriter()
  94114. }
  94115. FLAC__stream_encoder_delete (encoder);
  94116. }
  94117. bool write (const int** samplesToWrite, int numSamples)
  94118. {
  94119. using namespace FlacNamespace;
  94120. if (! ok)
  94121. return false;
  94122. int* buf[3];
  94123. const int bitsToShift = 32 - bitsPerSample;
  94124. if (bitsToShift > 0)
  94125. {
  94126. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94127. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94128. buf[0] = (int*) temp.getData();
  94129. buf[1] = buf[0] + numSamples;
  94130. buf[2] = 0;
  94131. for (int i = numChannelsToWrite; --i >= 0;)
  94132. {
  94133. if (samplesToWrite[i] != 0)
  94134. {
  94135. for (int j = 0; j < numSamples; ++j)
  94136. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94137. }
  94138. }
  94139. samplesToWrite = (const int**) buf;
  94140. }
  94141. return FLAC__stream_encoder_process (encoder,
  94142. (const FLAC__int32**) samplesToWrite,
  94143. numSamples) != 0;
  94144. }
  94145. bool writeData (const void* const data, const int size) const
  94146. {
  94147. return output->write (data, size);
  94148. }
  94149. static void packUint32 (FlacNamespace::FLAC__uint32 val, FlacNamespace::FLAC__byte* b, const int bytes)
  94150. {
  94151. using namespace FlacNamespace;
  94152. b += bytes;
  94153. for (int i = 0; i < bytes; ++i)
  94154. {
  94155. *(--b) = (FLAC__byte) (val & 0xff);
  94156. val >>= 8;
  94157. }
  94158. }
  94159. void writeMetaData (const FlacNamespace::FLAC__StreamMetadata* metadata)
  94160. {
  94161. using namespace FlacNamespace;
  94162. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94163. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94164. const unsigned int channelsMinus1 = info.channels - 1;
  94165. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94166. packUint32 (info.min_blocksize, buffer, 2);
  94167. packUint32 (info.max_blocksize, buffer + 2, 2);
  94168. packUint32 (info.min_framesize, buffer + 4, 3);
  94169. packUint32 (info.max_framesize, buffer + 7, 3);
  94170. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94171. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94172. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94173. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94174. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94175. memcpy (buffer + 18, info.md5sum, 16);
  94176. const bool seekOk = output->setPosition (4);
  94177. (void) seekOk;
  94178. // if this fails, you've given it an output stream that can't seek! It needs
  94179. // to be able to seek back to write the header
  94180. jassert (seekOk);
  94181. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94182. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94183. }
  94184. static FlacNamespace::FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FlacNamespace::FLAC__StreamEncoder*,
  94185. const FlacNamespace::FLAC__byte buffer[],
  94186. size_t bytes,
  94187. unsigned int /*samples*/,
  94188. unsigned int /*current_frame*/,
  94189. void* client_data)
  94190. {
  94191. using namespace FlacNamespace;
  94192. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94193. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94194. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94195. }
  94196. static FlacNamespace::FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64, void*)
  94197. {
  94198. using namespace FlacNamespace;
  94199. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94200. }
  94201. static FlacNamespace::FLAC__StreamEncoderTellStatus encodeTellCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  94202. {
  94203. using namespace FlacNamespace;
  94204. if (client_data == 0)
  94205. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94206. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94207. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94208. }
  94209. static void encodeMetadataCallback (const FlacNamespace::FLAC__StreamEncoder*,
  94210. const FlacNamespace::FLAC__StreamMetadata* metadata,
  94211. void* client_data)
  94212. {
  94213. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94214. }
  94215. juce_UseDebuggingNewOperator
  94216. bool ok;
  94217. private:
  94218. FlacNamespace::FLAC__StreamEncoder* encoder;
  94219. MemoryBlock temp;
  94220. FlacWriter (const FlacWriter&);
  94221. FlacWriter& operator= (const FlacWriter&);
  94222. };
  94223. FlacAudioFormat::FlacAudioFormat()
  94224. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94225. {
  94226. }
  94227. FlacAudioFormat::~FlacAudioFormat()
  94228. {
  94229. }
  94230. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94231. {
  94232. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94233. return Array <int> (rates);
  94234. }
  94235. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94236. {
  94237. const int depths[] = { 16, 24, 0 };
  94238. return Array <int> (depths);
  94239. }
  94240. bool FlacAudioFormat::canDoStereo()
  94241. {
  94242. return true;
  94243. }
  94244. bool FlacAudioFormat::canDoMono()
  94245. {
  94246. return true;
  94247. }
  94248. bool FlacAudioFormat::isCompressed()
  94249. {
  94250. return true;
  94251. }
  94252. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94253. const bool deleteStreamIfOpeningFails)
  94254. {
  94255. ScopedPointer <FlacReader> r (new FlacReader (in));
  94256. if (r->sampleRate != 0)
  94257. return r.release();
  94258. if (! deleteStreamIfOpeningFails)
  94259. r->input = 0;
  94260. return 0;
  94261. }
  94262. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94263. double sampleRate,
  94264. unsigned int numberOfChannels,
  94265. int bitsPerSample,
  94266. const StringPairArray& /*metadataValues*/,
  94267. int /*qualityOptionIndex*/)
  94268. {
  94269. if (getPossibleBitDepths().contains (bitsPerSample))
  94270. {
  94271. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94272. sampleRate,
  94273. numberOfChannels,
  94274. bitsPerSample));
  94275. if (w->ok)
  94276. return w.release();
  94277. }
  94278. return 0;
  94279. }
  94280. END_JUCE_NAMESPACE
  94281. #endif
  94282. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94283. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94284. #if JUCE_USE_OGGVORBIS
  94285. #if JUCE_MAC
  94286. #define __MACOSX__ 1
  94287. #endif
  94288. namespace OggVorbisNamespace
  94289. {
  94290. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94291. /*** Start of inlined file: vorbisenc.h ***/
  94292. #ifndef _OV_ENC_H_
  94293. #define _OV_ENC_H_
  94294. #ifdef __cplusplus
  94295. extern "C"
  94296. {
  94297. #endif /* __cplusplus */
  94298. /*** Start of inlined file: codec.h ***/
  94299. #ifndef _vorbis_codec_h_
  94300. #define _vorbis_codec_h_
  94301. #ifdef __cplusplus
  94302. extern "C"
  94303. {
  94304. #endif /* __cplusplus */
  94305. /*** Start of inlined file: ogg.h ***/
  94306. #ifndef _OGG_H
  94307. #define _OGG_H
  94308. #ifdef __cplusplus
  94309. extern "C" {
  94310. #endif
  94311. /*** Start of inlined file: os_types.h ***/
  94312. #ifndef _OS_TYPES_H
  94313. #define _OS_TYPES_H
  94314. #define _ogg_malloc malloc
  94315. #define _ogg_calloc calloc
  94316. #define _ogg_realloc realloc
  94317. #define _ogg_free free
  94318. #if defined(_WIN32)
  94319. # if defined(__CYGWIN__)
  94320. # include <_G_config.h>
  94321. typedef _G_int64_t ogg_int64_t;
  94322. typedef _G_int32_t ogg_int32_t;
  94323. typedef _G_uint32_t ogg_uint32_t;
  94324. typedef _G_int16_t ogg_int16_t;
  94325. typedef _G_uint16_t ogg_uint16_t;
  94326. # elif defined(__MINGW32__)
  94327. typedef short ogg_int16_t;
  94328. typedef unsigned short ogg_uint16_t;
  94329. typedef int ogg_int32_t;
  94330. typedef unsigned int ogg_uint32_t;
  94331. typedef long long ogg_int64_t;
  94332. typedef unsigned long long ogg_uint64_t;
  94333. # elif defined(__MWERKS__)
  94334. typedef long long ogg_int64_t;
  94335. typedef int ogg_int32_t;
  94336. typedef unsigned int ogg_uint32_t;
  94337. typedef short ogg_int16_t;
  94338. typedef unsigned short ogg_uint16_t;
  94339. # else
  94340. typedef __int64 ogg_int64_t;
  94341. typedef __int32 ogg_int32_t;
  94342. typedef unsigned __int32 ogg_uint32_t;
  94343. typedef __int16 ogg_int16_t;
  94344. typedef unsigned __int16 ogg_uint16_t;
  94345. # endif
  94346. #elif defined(__MACOS__)
  94347. # include <sys/types.h>
  94348. typedef SInt16 ogg_int16_t;
  94349. typedef UInt16 ogg_uint16_t;
  94350. typedef SInt32 ogg_int32_t;
  94351. typedef UInt32 ogg_uint32_t;
  94352. typedef SInt64 ogg_int64_t;
  94353. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94354. # include <sys/types.h>
  94355. typedef int16_t ogg_int16_t;
  94356. typedef u_int16_t ogg_uint16_t;
  94357. typedef int32_t ogg_int32_t;
  94358. typedef u_int32_t ogg_uint32_t;
  94359. typedef int64_t ogg_int64_t;
  94360. #elif defined(__BEOS__)
  94361. # include <inttypes.h>
  94362. typedef int16_t ogg_int16_t;
  94363. typedef u_int16_t ogg_uint16_t;
  94364. typedef int32_t ogg_int32_t;
  94365. typedef u_int32_t ogg_uint32_t;
  94366. typedef int64_t ogg_int64_t;
  94367. #elif defined (__EMX__)
  94368. typedef short ogg_int16_t;
  94369. typedef unsigned short ogg_uint16_t;
  94370. typedef int ogg_int32_t;
  94371. typedef unsigned int ogg_uint32_t;
  94372. typedef long long ogg_int64_t;
  94373. #elif defined (DJGPP)
  94374. typedef short ogg_int16_t;
  94375. typedef int ogg_int32_t;
  94376. typedef unsigned int ogg_uint32_t;
  94377. typedef long long ogg_int64_t;
  94378. #elif defined(R5900)
  94379. typedef long ogg_int64_t;
  94380. typedef int ogg_int32_t;
  94381. typedef unsigned ogg_uint32_t;
  94382. typedef short ogg_int16_t;
  94383. #elif defined(__SYMBIAN32__)
  94384. typedef signed short ogg_int16_t;
  94385. typedef unsigned short ogg_uint16_t;
  94386. typedef signed int ogg_int32_t;
  94387. typedef unsigned int ogg_uint32_t;
  94388. typedef long long int ogg_int64_t;
  94389. #else
  94390. # include <sys/types.h>
  94391. /*** Start of inlined file: config_types.h ***/
  94392. #ifndef __CONFIG_TYPES_H__
  94393. #define __CONFIG_TYPES_H__
  94394. typedef int16_t ogg_int16_t;
  94395. typedef unsigned short ogg_uint16_t;
  94396. typedef int32_t ogg_int32_t;
  94397. typedef unsigned int ogg_uint32_t;
  94398. typedef int64_t ogg_int64_t;
  94399. #endif
  94400. /*** End of inlined file: config_types.h ***/
  94401. #endif
  94402. #endif /* _OS_TYPES_H */
  94403. /*** End of inlined file: os_types.h ***/
  94404. typedef struct {
  94405. long endbyte;
  94406. int endbit;
  94407. unsigned char *buffer;
  94408. unsigned char *ptr;
  94409. long storage;
  94410. } oggpack_buffer;
  94411. typedef struct {
  94412. unsigned char *header;
  94413. long header_len;
  94414. unsigned char *body;
  94415. long body_len;
  94416. } ogg_page;
  94417. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94418. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94419. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94420. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94421. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94422. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94423. }
  94424. typedef struct {
  94425. unsigned char *body_data; /* bytes from packet bodies */
  94426. long body_storage; /* storage elements allocated */
  94427. long body_fill; /* elements stored; fill mark */
  94428. long body_returned; /* elements of fill returned */
  94429. int *lacing_vals; /* The values that will go to the segment table */
  94430. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94431. this way, but it is simple coupled to the
  94432. lacing fifo */
  94433. long lacing_storage;
  94434. long lacing_fill;
  94435. long lacing_packet;
  94436. long lacing_returned;
  94437. unsigned char header[282]; /* working space for header encode */
  94438. int header_fill;
  94439. int e_o_s; /* set when we have buffered the last packet in the
  94440. logical bitstream */
  94441. int b_o_s; /* set after we've written the initial page
  94442. of a logical bitstream */
  94443. long serialno;
  94444. long pageno;
  94445. ogg_int64_t packetno; /* sequence number for decode; the framing
  94446. knows where there's a hole in the data,
  94447. but we need coupling so that the codec
  94448. (which is in a seperate abstraction
  94449. layer) also knows about the gap */
  94450. ogg_int64_t granulepos;
  94451. } ogg_stream_state;
  94452. typedef struct {
  94453. unsigned char *packet;
  94454. long bytes;
  94455. long b_o_s;
  94456. long e_o_s;
  94457. ogg_int64_t granulepos;
  94458. ogg_int64_t packetno; /* sequence number for decode; the framing
  94459. knows where there's a hole in the data,
  94460. but we need coupling so that the codec
  94461. (which is in a seperate abstraction
  94462. layer) also knows about the gap */
  94463. } ogg_packet;
  94464. typedef struct {
  94465. unsigned char *data;
  94466. int storage;
  94467. int fill;
  94468. int returned;
  94469. int unsynced;
  94470. int headerbytes;
  94471. int bodybytes;
  94472. } ogg_sync_state;
  94473. extern void oggpack_writeinit(oggpack_buffer *b);
  94474. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94475. extern void oggpack_writealign(oggpack_buffer *b);
  94476. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94477. extern void oggpack_reset(oggpack_buffer *b);
  94478. extern void oggpack_writeclear(oggpack_buffer *b);
  94479. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94480. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94481. extern long oggpack_look(oggpack_buffer *b,int bits);
  94482. extern long oggpack_look1(oggpack_buffer *b);
  94483. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94484. extern void oggpack_adv1(oggpack_buffer *b);
  94485. extern long oggpack_read(oggpack_buffer *b,int bits);
  94486. extern long oggpack_read1(oggpack_buffer *b);
  94487. extern long oggpack_bytes(oggpack_buffer *b);
  94488. extern long oggpack_bits(oggpack_buffer *b);
  94489. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94490. extern void oggpackB_writeinit(oggpack_buffer *b);
  94491. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94492. extern void oggpackB_writealign(oggpack_buffer *b);
  94493. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94494. extern void oggpackB_reset(oggpack_buffer *b);
  94495. extern void oggpackB_writeclear(oggpack_buffer *b);
  94496. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94497. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94498. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94499. extern long oggpackB_look1(oggpack_buffer *b);
  94500. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94501. extern void oggpackB_adv1(oggpack_buffer *b);
  94502. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94503. extern long oggpackB_read1(oggpack_buffer *b);
  94504. extern long oggpackB_bytes(oggpack_buffer *b);
  94505. extern long oggpackB_bits(oggpack_buffer *b);
  94506. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94507. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94508. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94509. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94510. extern int ogg_sync_init(ogg_sync_state *oy);
  94511. extern int ogg_sync_clear(ogg_sync_state *oy);
  94512. extern int ogg_sync_reset(ogg_sync_state *oy);
  94513. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94514. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94515. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94516. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94517. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94518. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94519. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94520. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94521. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94522. extern int ogg_stream_clear(ogg_stream_state *os);
  94523. extern int ogg_stream_reset(ogg_stream_state *os);
  94524. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94525. extern int ogg_stream_destroy(ogg_stream_state *os);
  94526. extern int ogg_stream_eos(ogg_stream_state *os);
  94527. extern void ogg_page_checksum_set(ogg_page *og);
  94528. extern int ogg_page_version(ogg_page *og);
  94529. extern int ogg_page_continued(ogg_page *og);
  94530. extern int ogg_page_bos(ogg_page *og);
  94531. extern int ogg_page_eos(ogg_page *og);
  94532. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94533. extern int ogg_page_serialno(ogg_page *og);
  94534. extern long ogg_page_pageno(ogg_page *og);
  94535. extern int ogg_page_packets(ogg_page *og);
  94536. extern void ogg_packet_clear(ogg_packet *op);
  94537. #ifdef __cplusplus
  94538. }
  94539. #endif
  94540. #endif /* _OGG_H */
  94541. /*** End of inlined file: ogg.h ***/
  94542. typedef struct vorbis_info{
  94543. int version;
  94544. int channels;
  94545. long rate;
  94546. long bitrate_upper;
  94547. long bitrate_nominal;
  94548. long bitrate_lower;
  94549. long bitrate_window;
  94550. void *codec_setup;
  94551. } vorbis_info;
  94552. typedef struct vorbis_dsp_state{
  94553. int analysisp;
  94554. vorbis_info *vi;
  94555. float **pcm;
  94556. float **pcmret;
  94557. int pcm_storage;
  94558. int pcm_current;
  94559. int pcm_returned;
  94560. int preextrapolate;
  94561. int eofflag;
  94562. long lW;
  94563. long W;
  94564. long nW;
  94565. long centerW;
  94566. ogg_int64_t granulepos;
  94567. ogg_int64_t sequence;
  94568. ogg_int64_t glue_bits;
  94569. ogg_int64_t time_bits;
  94570. ogg_int64_t floor_bits;
  94571. ogg_int64_t res_bits;
  94572. void *backend_state;
  94573. } vorbis_dsp_state;
  94574. typedef struct vorbis_block{
  94575. float **pcm; /* this is a pointer into local storage */
  94576. oggpack_buffer opb;
  94577. long lW;
  94578. long W;
  94579. long nW;
  94580. int pcmend;
  94581. int mode;
  94582. int eofflag;
  94583. ogg_int64_t granulepos;
  94584. ogg_int64_t sequence;
  94585. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94586. void *localstore;
  94587. long localtop;
  94588. long localalloc;
  94589. long totaluse;
  94590. struct alloc_chain *reap;
  94591. long glue_bits;
  94592. long time_bits;
  94593. long floor_bits;
  94594. long res_bits;
  94595. void *internal;
  94596. } vorbis_block;
  94597. struct alloc_chain{
  94598. void *ptr;
  94599. struct alloc_chain *next;
  94600. };
  94601. typedef struct vorbis_comment{
  94602. char **user_comments;
  94603. int *comment_lengths;
  94604. int comments;
  94605. char *vendor;
  94606. } vorbis_comment;
  94607. extern void vorbis_info_init(vorbis_info *vi);
  94608. extern void vorbis_info_clear(vorbis_info *vi);
  94609. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94610. extern void vorbis_comment_init(vorbis_comment *vc);
  94611. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94612. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94613. const char *tag, char *contents);
  94614. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94615. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94616. extern void vorbis_comment_clear(vorbis_comment *vc);
  94617. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94618. extern int vorbis_block_clear(vorbis_block *vb);
  94619. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94620. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94621. ogg_int64_t granulepos);
  94622. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94623. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94624. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94625. vorbis_comment *vc,
  94626. ogg_packet *op,
  94627. ogg_packet *op_comm,
  94628. ogg_packet *op_code);
  94629. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94630. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94631. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94632. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94633. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94634. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94635. ogg_packet *op);
  94636. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94637. ogg_packet *op);
  94638. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94639. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94640. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94641. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94642. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94643. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94644. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94645. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94646. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94647. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94648. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94649. #define OV_FALSE -1
  94650. #define OV_EOF -2
  94651. #define OV_HOLE -3
  94652. #define OV_EREAD -128
  94653. #define OV_EFAULT -129
  94654. #define OV_EIMPL -130
  94655. #define OV_EINVAL -131
  94656. #define OV_ENOTVORBIS -132
  94657. #define OV_EBADHEADER -133
  94658. #define OV_EVERSION -134
  94659. #define OV_ENOTAUDIO -135
  94660. #define OV_EBADPACKET -136
  94661. #define OV_EBADLINK -137
  94662. #define OV_ENOSEEK -138
  94663. #ifdef __cplusplus
  94664. }
  94665. #endif /* __cplusplus */
  94666. #endif
  94667. /*** End of inlined file: codec.h ***/
  94668. extern int vorbis_encode_init(vorbis_info *vi,
  94669. long channels,
  94670. long rate,
  94671. long max_bitrate,
  94672. long nominal_bitrate,
  94673. long min_bitrate);
  94674. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94675. long channels,
  94676. long rate,
  94677. long max_bitrate,
  94678. long nominal_bitrate,
  94679. long min_bitrate);
  94680. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94681. long channels,
  94682. long rate,
  94683. float quality /* quality level from 0. (lo) to 1. (hi) */
  94684. );
  94685. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94686. long channels,
  94687. long rate,
  94688. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94689. );
  94690. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94691. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94692. #define OV_ECTL_RATEMANAGE_GET 0x10
  94693. #define OV_ECTL_RATEMANAGE_SET 0x11
  94694. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94695. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94696. struct ovectl_ratemanage_arg {
  94697. int management_active;
  94698. long bitrate_hard_min;
  94699. long bitrate_hard_max;
  94700. double bitrate_hard_window;
  94701. long bitrate_av_lo;
  94702. long bitrate_av_hi;
  94703. double bitrate_av_window;
  94704. double bitrate_av_window_center;
  94705. };
  94706. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94707. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94708. struct ovectl_ratemanage2_arg {
  94709. int management_active;
  94710. long bitrate_limit_min_kbps;
  94711. long bitrate_limit_max_kbps;
  94712. long bitrate_limit_reservoir_bits;
  94713. double bitrate_limit_reservoir_bias;
  94714. long bitrate_average_kbps;
  94715. double bitrate_average_damping;
  94716. };
  94717. #define OV_ECTL_LOWPASS_GET 0x20
  94718. #define OV_ECTL_LOWPASS_SET 0x21
  94719. #define OV_ECTL_IBLOCK_GET 0x30
  94720. #define OV_ECTL_IBLOCK_SET 0x31
  94721. #ifdef __cplusplus
  94722. }
  94723. #endif /* __cplusplus */
  94724. #endif
  94725. /*** End of inlined file: vorbisenc.h ***/
  94726. /*** Start of inlined file: vorbisfile.h ***/
  94727. #ifndef _OV_FILE_H_
  94728. #define _OV_FILE_H_
  94729. #ifdef __cplusplus
  94730. extern "C"
  94731. {
  94732. #endif /* __cplusplus */
  94733. #include <stdio.h>
  94734. typedef struct {
  94735. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94736. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94737. int (*close_func) (void *datasource);
  94738. long (*tell_func) (void *datasource);
  94739. } ov_callbacks;
  94740. #define NOTOPEN 0
  94741. #define PARTOPEN 1
  94742. #define OPENED 2
  94743. #define STREAMSET 3
  94744. #define INITSET 4
  94745. typedef struct OggVorbis_File {
  94746. void *datasource; /* Pointer to a FILE *, etc. */
  94747. int seekable;
  94748. ogg_int64_t offset;
  94749. ogg_int64_t end;
  94750. ogg_sync_state oy;
  94751. int links;
  94752. ogg_int64_t *offsets;
  94753. ogg_int64_t *dataoffsets;
  94754. long *serialnos;
  94755. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94756. compatability; x2 size, stores both
  94757. beginning and end values */
  94758. vorbis_info *vi;
  94759. vorbis_comment *vc;
  94760. ogg_int64_t pcm_offset;
  94761. int ready_state;
  94762. long current_serialno;
  94763. int current_link;
  94764. double bittrack;
  94765. double samptrack;
  94766. ogg_stream_state os; /* take physical pages, weld into a logical
  94767. stream of packets */
  94768. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94769. vorbis_block vb; /* local working space for packet->PCM decode */
  94770. ov_callbacks callbacks;
  94771. } OggVorbis_File;
  94772. extern int ov_clear(OggVorbis_File *vf);
  94773. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94774. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94775. char *initial, long ibytes, ov_callbacks callbacks);
  94776. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94777. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94778. char *initial, long ibytes, ov_callbacks callbacks);
  94779. extern int ov_test_open(OggVorbis_File *vf);
  94780. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94781. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94782. extern long ov_streams(OggVorbis_File *vf);
  94783. extern long ov_seekable(OggVorbis_File *vf);
  94784. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94785. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94786. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94787. extern double ov_time_total(OggVorbis_File *vf,int i);
  94788. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94789. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94790. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94791. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94792. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94793. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94794. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94795. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94796. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94797. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94798. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94799. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94800. extern double ov_time_tell(OggVorbis_File *vf);
  94801. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94802. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94803. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94804. int *bitstream);
  94805. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94806. int bigendianp,int word,int sgned,int *bitstream);
  94807. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94808. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94809. extern int ov_halfrate_p(OggVorbis_File *vf);
  94810. #ifdef __cplusplus
  94811. }
  94812. #endif /* __cplusplus */
  94813. #endif
  94814. /*** End of inlined file: vorbisfile.h ***/
  94815. /*** Start of inlined file: bitwise.c ***/
  94816. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94817. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94818. // tasks..
  94819. #if JUCE_MSVC
  94820. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94821. #endif
  94822. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94823. #if JUCE_USE_OGGVORBIS
  94824. #include <string.h>
  94825. #include <stdlib.h>
  94826. #define BUFFER_INCREMENT 256
  94827. static const unsigned long mask[]=
  94828. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94829. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94830. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94831. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94832. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94833. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94834. 0x3fffffff,0x7fffffff,0xffffffff };
  94835. static const unsigned int mask8B[]=
  94836. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94837. void oggpack_writeinit(oggpack_buffer *b){
  94838. memset(b,0,sizeof(*b));
  94839. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94840. b->buffer[0]='\0';
  94841. b->storage=BUFFER_INCREMENT;
  94842. }
  94843. void oggpackB_writeinit(oggpack_buffer *b){
  94844. oggpack_writeinit(b);
  94845. }
  94846. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94847. long bytes=bits>>3;
  94848. bits-=bytes*8;
  94849. b->ptr=b->buffer+bytes;
  94850. b->endbit=bits;
  94851. b->endbyte=bytes;
  94852. *b->ptr&=mask[bits];
  94853. }
  94854. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94855. long bytes=bits>>3;
  94856. bits-=bytes*8;
  94857. b->ptr=b->buffer+bytes;
  94858. b->endbit=bits;
  94859. b->endbyte=bytes;
  94860. *b->ptr&=mask8B[bits];
  94861. }
  94862. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94863. if(b->endbyte+4>=b->storage){
  94864. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94865. b->storage+=BUFFER_INCREMENT;
  94866. b->ptr=b->buffer+b->endbyte;
  94867. }
  94868. value&=mask[bits];
  94869. bits+=b->endbit;
  94870. b->ptr[0]|=value<<b->endbit;
  94871. if(bits>=8){
  94872. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94873. if(bits>=16){
  94874. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94875. if(bits>=24){
  94876. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94877. if(bits>=32){
  94878. if(b->endbit)
  94879. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94880. else
  94881. b->ptr[4]=0;
  94882. }
  94883. }
  94884. }
  94885. }
  94886. b->endbyte+=bits/8;
  94887. b->ptr+=bits/8;
  94888. b->endbit=bits&7;
  94889. }
  94890. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94891. if(b->endbyte+4>=b->storage){
  94892. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94893. b->storage+=BUFFER_INCREMENT;
  94894. b->ptr=b->buffer+b->endbyte;
  94895. }
  94896. value=(value&mask[bits])<<(32-bits);
  94897. bits+=b->endbit;
  94898. b->ptr[0]|=value>>(24+b->endbit);
  94899. if(bits>=8){
  94900. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94901. if(bits>=16){
  94902. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94903. if(bits>=24){
  94904. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94905. if(bits>=32){
  94906. if(b->endbit)
  94907. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94908. else
  94909. b->ptr[4]=0;
  94910. }
  94911. }
  94912. }
  94913. }
  94914. b->endbyte+=bits/8;
  94915. b->ptr+=bits/8;
  94916. b->endbit=bits&7;
  94917. }
  94918. void oggpack_writealign(oggpack_buffer *b){
  94919. int bits=8-b->endbit;
  94920. if(bits<8)
  94921. oggpack_write(b,0,bits);
  94922. }
  94923. void oggpackB_writealign(oggpack_buffer *b){
  94924. int bits=8-b->endbit;
  94925. if(bits<8)
  94926. oggpackB_write(b,0,bits);
  94927. }
  94928. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94929. void *source,
  94930. long bits,
  94931. void (*w)(oggpack_buffer *,
  94932. unsigned long,
  94933. int),
  94934. int msb){
  94935. unsigned char *ptr=(unsigned char *)source;
  94936. long bytes=bits/8;
  94937. bits-=bytes*8;
  94938. if(b->endbit){
  94939. int i;
  94940. for(i=0;i<bytes;i++)
  94941. w(b,(unsigned long)(ptr[i]),8);
  94942. }else{
  94943. if(b->endbyte+bytes+1>=b->storage){
  94944. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  94945. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  94946. b->ptr=b->buffer+b->endbyte;
  94947. }
  94948. memmove(b->ptr,source,bytes);
  94949. b->ptr+=bytes;
  94950. b->endbyte+=bytes;
  94951. *b->ptr=0;
  94952. }
  94953. if(bits){
  94954. if(msb)
  94955. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  94956. else
  94957. w(b,(unsigned long)(ptr[bytes]),bits);
  94958. }
  94959. }
  94960. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  94961. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  94962. }
  94963. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  94964. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  94965. }
  94966. void oggpack_reset(oggpack_buffer *b){
  94967. b->ptr=b->buffer;
  94968. b->buffer[0]=0;
  94969. b->endbit=b->endbyte=0;
  94970. }
  94971. void oggpackB_reset(oggpack_buffer *b){
  94972. oggpack_reset(b);
  94973. }
  94974. void oggpack_writeclear(oggpack_buffer *b){
  94975. _ogg_free(b->buffer);
  94976. memset(b,0,sizeof(*b));
  94977. }
  94978. void oggpackB_writeclear(oggpack_buffer *b){
  94979. oggpack_writeclear(b);
  94980. }
  94981. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94982. memset(b,0,sizeof(*b));
  94983. b->buffer=b->ptr=buf;
  94984. b->storage=bytes;
  94985. }
  94986. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94987. oggpack_readinit(b,buf,bytes);
  94988. }
  94989. long oggpack_look(oggpack_buffer *b,int bits){
  94990. unsigned long ret;
  94991. unsigned long m=mask[bits];
  94992. bits+=b->endbit;
  94993. if(b->endbyte+4>=b->storage){
  94994. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94995. }
  94996. ret=b->ptr[0]>>b->endbit;
  94997. if(bits>8){
  94998. ret|=b->ptr[1]<<(8-b->endbit);
  94999. if(bits>16){
  95000. ret|=b->ptr[2]<<(16-b->endbit);
  95001. if(bits>24){
  95002. ret|=b->ptr[3]<<(24-b->endbit);
  95003. if(bits>32 && b->endbit)
  95004. ret|=b->ptr[4]<<(32-b->endbit);
  95005. }
  95006. }
  95007. }
  95008. return(m&ret);
  95009. }
  95010. long oggpackB_look(oggpack_buffer *b,int bits){
  95011. unsigned long ret;
  95012. int m=32-bits;
  95013. bits+=b->endbit;
  95014. if(b->endbyte+4>=b->storage){
  95015. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95016. }
  95017. ret=b->ptr[0]<<(24+b->endbit);
  95018. if(bits>8){
  95019. ret|=b->ptr[1]<<(16+b->endbit);
  95020. if(bits>16){
  95021. ret|=b->ptr[2]<<(8+b->endbit);
  95022. if(bits>24){
  95023. ret|=b->ptr[3]<<(b->endbit);
  95024. if(bits>32 && b->endbit)
  95025. ret|=b->ptr[4]>>(8-b->endbit);
  95026. }
  95027. }
  95028. }
  95029. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95030. }
  95031. long oggpack_look1(oggpack_buffer *b){
  95032. if(b->endbyte>=b->storage)return(-1);
  95033. return((b->ptr[0]>>b->endbit)&1);
  95034. }
  95035. long oggpackB_look1(oggpack_buffer *b){
  95036. if(b->endbyte>=b->storage)return(-1);
  95037. return((b->ptr[0]>>(7-b->endbit))&1);
  95038. }
  95039. void oggpack_adv(oggpack_buffer *b,int bits){
  95040. bits+=b->endbit;
  95041. b->ptr+=bits/8;
  95042. b->endbyte+=bits/8;
  95043. b->endbit=bits&7;
  95044. }
  95045. void oggpackB_adv(oggpack_buffer *b,int bits){
  95046. oggpack_adv(b,bits);
  95047. }
  95048. void oggpack_adv1(oggpack_buffer *b){
  95049. if(++(b->endbit)>7){
  95050. b->endbit=0;
  95051. b->ptr++;
  95052. b->endbyte++;
  95053. }
  95054. }
  95055. void oggpackB_adv1(oggpack_buffer *b){
  95056. oggpack_adv1(b);
  95057. }
  95058. long oggpack_read(oggpack_buffer *b,int bits){
  95059. long ret;
  95060. unsigned long m=mask[bits];
  95061. bits+=b->endbit;
  95062. if(b->endbyte+4>=b->storage){
  95063. ret=-1L;
  95064. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95065. }
  95066. ret=b->ptr[0]>>b->endbit;
  95067. if(bits>8){
  95068. ret|=b->ptr[1]<<(8-b->endbit);
  95069. if(bits>16){
  95070. ret|=b->ptr[2]<<(16-b->endbit);
  95071. if(bits>24){
  95072. ret|=b->ptr[3]<<(24-b->endbit);
  95073. if(bits>32 && b->endbit){
  95074. ret|=b->ptr[4]<<(32-b->endbit);
  95075. }
  95076. }
  95077. }
  95078. }
  95079. ret&=m;
  95080. overflow:
  95081. b->ptr+=bits/8;
  95082. b->endbyte+=bits/8;
  95083. b->endbit=bits&7;
  95084. return(ret);
  95085. }
  95086. long oggpackB_read(oggpack_buffer *b,int bits){
  95087. long ret;
  95088. long m=32-bits;
  95089. bits+=b->endbit;
  95090. if(b->endbyte+4>=b->storage){
  95091. ret=-1L;
  95092. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95093. }
  95094. ret=b->ptr[0]<<(24+b->endbit);
  95095. if(bits>8){
  95096. ret|=b->ptr[1]<<(16+b->endbit);
  95097. if(bits>16){
  95098. ret|=b->ptr[2]<<(8+b->endbit);
  95099. if(bits>24){
  95100. ret|=b->ptr[3]<<(b->endbit);
  95101. if(bits>32 && b->endbit)
  95102. ret|=b->ptr[4]>>(8-b->endbit);
  95103. }
  95104. }
  95105. }
  95106. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95107. overflow:
  95108. b->ptr+=bits/8;
  95109. b->endbyte+=bits/8;
  95110. b->endbit=bits&7;
  95111. return(ret);
  95112. }
  95113. long oggpack_read1(oggpack_buffer *b){
  95114. long ret;
  95115. if(b->endbyte>=b->storage){
  95116. ret=-1L;
  95117. goto overflow;
  95118. }
  95119. ret=(b->ptr[0]>>b->endbit)&1;
  95120. overflow:
  95121. b->endbit++;
  95122. if(b->endbit>7){
  95123. b->endbit=0;
  95124. b->ptr++;
  95125. b->endbyte++;
  95126. }
  95127. return(ret);
  95128. }
  95129. long oggpackB_read1(oggpack_buffer *b){
  95130. long ret;
  95131. if(b->endbyte>=b->storage){
  95132. ret=-1L;
  95133. goto overflow;
  95134. }
  95135. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95136. overflow:
  95137. b->endbit++;
  95138. if(b->endbit>7){
  95139. b->endbit=0;
  95140. b->ptr++;
  95141. b->endbyte++;
  95142. }
  95143. return(ret);
  95144. }
  95145. long oggpack_bytes(oggpack_buffer *b){
  95146. return(b->endbyte+(b->endbit+7)/8);
  95147. }
  95148. long oggpack_bits(oggpack_buffer *b){
  95149. return(b->endbyte*8+b->endbit);
  95150. }
  95151. long oggpackB_bytes(oggpack_buffer *b){
  95152. return oggpack_bytes(b);
  95153. }
  95154. long oggpackB_bits(oggpack_buffer *b){
  95155. return oggpack_bits(b);
  95156. }
  95157. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95158. return(b->buffer);
  95159. }
  95160. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95161. return oggpack_get_buffer(b);
  95162. }
  95163. #ifdef _V_SELFTEST
  95164. #include <stdio.h>
  95165. static int ilog(unsigned int v){
  95166. int ret=0;
  95167. while(v){
  95168. ret++;
  95169. v>>=1;
  95170. }
  95171. return(ret);
  95172. }
  95173. oggpack_buffer o;
  95174. oggpack_buffer r;
  95175. void report(char *in){
  95176. fprintf(stderr,"%s",in);
  95177. exit(1);
  95178. }
  95179. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95180. long bytes,i;
  95181. unsigned char *buffer;
  95182. oggpack_reset(&o);
  95183. for(i=0;i<vals;i++)
  95184. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95185. buffer=oggpack_get_buffer(&o);
  95186. bytes=oggpack_bytes(&o);
  95187. if(bytes!=compsize)report("wrong number of bytes!\n");
  95188. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95189. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95190. report("wrote incorrect value!\n");
  95191. }
  95192. oggpack_readinit(&r,buffer,bytes);
  95193. for(i=0;i<vals;i++){
  95194. int tbit=bits?bits:ilog(b[i]);
  95195. if(oggpack_look(&r,tbit)==-1)
  95196. report("out of data!\n");
  95197. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95198. report("looked at incorrect value!\n");
  95199. if(tbit==1)
  95200. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95201. report("looked at single bit incorrect value!\n");
  95202. if(tbit==1){
  95203. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95204. report("read incorrect single bit value!\n");
  95205. }else{
  95206. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95207. report("read incorrect value!\n");
  95208. }
  95209. }
  95210. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95211. }
  95212. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95213. long bytes,i;
  95214. unsigned char *buffer;
  95215. oggpackB_reset(&o);
  95216. for(i=0;i<vals;i++)
  95217. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95218. buffer=oggpackB_get_buffer(&o);
  95219. bytes=oggpackB_bytes(&o);
  95220. if(bytes!=compsize)report("wrong number of bytes!\n");
  95221. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95222. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95223. report("wrote incorrect value!\n");
  95224. }
  95225. oggpackB_readinit(&r,buffer,bytes);
  95226. for(i=0;i<vals;i++){
  95227. int tbit=bits?bits:ilog(b[i]);
  95228. if(oggpackB_look(&r,tbit)==-1)
  95229. report("out of data!\n");
  95230. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95231. report("looked at incorrect value!\n");
  95232. if(tbit==1)
  95233. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95234. report("looked at single bit incorrect value!\n");
  95235. if(tbit==1){
  95236. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95237. report("read incorrect single bit value!\n");
  95238. }else{
  95239. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95240. report("read incorrect value!\n");
  95241. }
  95242. }
  95243. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95244. }
  95245. int main(void){
  95246. unsigned char *buffer;
  95247. long bytes,i;
  95248. static unsigned long testbuffer1[]=
  95249. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95250. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95251. int test1size=43;
  95252. static unsigned long testbuffer2[]=
  95253. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95254. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95255. 85525151,0,12321,1,349528352};
  95256. int test2size=21;
  95257. static unsigned long testbuffer3[]=
  95258. {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,
  95259. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95260. int test3size=56;
  95261. static unsigned long large[]=
  95262. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95263. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95264. 85525151,0,12321,1,2146528352};
  95265. int onesize=33;
  95266. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95267. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95268. 223,4};
  95269. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95270. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95271. 245,251,128};
  95272. int twosize=6;
  95273. static int two[6]={61,255,255,251,231,29};
  95274. static int twoB[6]={247,63,255,253,249,120};
  95275. int threesize=54;
  95276. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95277. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95278. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95279. 100,52,4,14,18,86,77,1};
  95280. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95281. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95282. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95283. 200,20,254,4,58,106,176,144,0};
  95284. int foursize=38;
  95285. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95286. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95287. 28,2,133,0,1};
  95288. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95289. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95290. 129,10,4,32};
  95291. int fivesize=45;
  95292. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95293. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95294. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95295. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95296. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95297. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95298. int sixsize=7;
  95299. static int six[7]={17,177,170,242,169,19,148};
  95300. static int sixB[7]={136,141,85,79,149,200,41};
  95301. oggpack_writeinit(&o);
  95302. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95303. cliptest(testbuffer1,test1size,0,one,onesize);
  95304. fprintf(stderr,"ok.");
  95305. fprintf(stderr,"\nNull bit call (LSb): ");
  95306. cliptest(testbuffer3,test3size,0,two,twosize);
  95307. fprintf(stderr,"ok.");
  95308. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95309. cliptest(testbuffer2,test2size,0,three,threesize);
  95310. fprintf(stderr,"ok.");
  95311. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95312. oggpack_reset(&o);
  95313. for(i=0;i<test2size;i++)
  95314. oggpack_write(&o,large[i],32);
  95315. buffer=oggpack_get_buffer(&o);
  95316. bytes=oggpack_bytes(&o);
  95317. oggpack_readinit(&r,buffer,bytes);
  95318. for(i=0;i<test2size;i++){
  95319. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95320. if(oggpack_look(&r,32)!=large[i]){
  95321. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95322. oggpack_look(&r,32),large[i]);
  95323. report("read incorrect value!\n");
  95324. }
  95325. oggpack_adv(&r,32);
  95326. }
  95327. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95328. fprintf(stderr,"ok.");
  95329. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95330. cliptest(testbuffer1,test1size,7,four,foursize);
  95331. fprintf(stderr,"ok.");
  95332. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95333. cliptest(testbuffer2,test2size,17,five,fivesize);
  95334. fprintf(stderr,"ok.");
  95335. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95336. cliptest(testbuffer3,test3size,1,six,sixsize);
  95337. fprintf(stderr,"ok.");
  95338. fprintf(stderr,"\nTesting read past end (LSb): ");
  95339. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95340. for(i=0;i<64;i++){
  95341. if(oggpack_read(&r,1)!=0){
  95342. fprintf(stderr,"failed; got -1 prematurely.\n");
  95343. exit(1);
  95344. }
  95345. }
  95346. if(oggpack_look(&r,1)!=-1 ||
  95347. oggpack_read(&r,1)!=-1){
  95348. fprintf(stderr,"failed; read past end without -1.\n");
  95349. exit(1);
  95350. }
  95351. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95352. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95353. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95354. exit(1);
  95355. }
  95356. if(oggpack_look(&r,18)!=0 ||
  95357. oggpack_look(&r,18)!=0){
  95358. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95359. exit(1);
  95360. }
  95361. if(oggpack_look(&r,19)!=-1 ||
  95362. oggpack_look(&r,19)!=-1){
  95363. fprintf(stderr,"failed; read past end without -1.\n");
  95364. exit(1);
  95365. }
  95366. if(oggpack_look(&r,32)!=-1 ||
  95367. oggpack_look(&r,32)!=-1){
  95368. fprintf(stderr,"failed; read past end without -1.\n");
  95369. exit(1);
  95370. }
  95371. oggpack_writeclear(&o);
  95372. fprintf(stderr,"ok.\n");
  95373. oggpackB_writeinit(&o);
  95374. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95375. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95376. fprintf(stderr,"ok.");
  95377. fprintf(stderr,"\nNull bit call (MSb): ");
  95378. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95379. fprintf(stderr,"ok.");
  95380. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95381. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95382. fprintf(stderr,"ok.");
  95383. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95384. oggpackB_reset(&o);
  95385. for(i=0;i<test2size;i++)
  95386. oggpackB_write(&o,large[i],32);
  95387. buffer=oggpackB_get_buffer(&o);
  95388. bytes=oggpackB_bytes(&o);
  95389. oggpackB_readinit(&r,buffer,bytes);
  95390. for(i=0;i<test2size;i++){
  95391. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95392. if(oggpackB_look(&r,32)!=large[i]){
  95393. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95394. oggpackB_look(&r,32),large[i]);
  95395. report("read incorrect value!\n");
  95396. }
  95397. oggpackB_adv(&r,32);
  95398. }
  95399. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95400. fprintf(stderr,"ok.");
  95401. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95402. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95403. fprintf(stderr,"ok.");
  95404. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95405. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95406. fprintf(stderr,"ok.");
  95407. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95408. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95409. fprintf(stderr,"ok.");
  95410. fprintf(stderr,"\nTesting read past end (MSb): ");
  95411. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95412. for(i=0;i<64;i++){
  95413. if(oggpackB_read(&r,1)!=0){
  95414. fprintf(stderr,"failed; got -1 prematurely.\n");
  95415. exit(1);
  95416. }
  95417. }
  95418. if(oggpackB_look(&r,1)!=-1 ||
  95419. oggpackB_read(&r,1)!=-1){
  95420. fprintf(stderr,"failed; read past end without -1.\n");
  95421. exit(1);
  95422. }
  95423. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95424. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95425. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95426. exit(1);
  95427. }
  95428. if(oggpackB_look(&r,18)!=0 ||
  95429. oggpackB_look(&r,18)!=0){
  95430. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95431. exit(1);
  95432. }
  95433. if(oggpackB_look(&r,19)!=-1 ||
  95434. oggpackB_look(&r,19)!=-1){
  95435. fprintf(stderr,"failed; read past end without -1.\n");
  95436. exit(1);
  95437. }
  95438. if(oggpackB_look(&r,32)!=-1 ||
  95439. oggpackB_look(&r,32)!=-1){
  95440. fprintf(stderr,"failed; read past end without -1.\n");
  95441. exit(1);
  95442. }
  95443. oggpackB_writeclear(&o);
  95444. fprintf(stderr,"ok.\n\n");
  95445. return(0);
  95446. }
  95447. #endif /* _V_SELFTEST */
  95448. #undef BUFFER_INCREMENT
  95449. #endif
  95450. /*** End of inlined file: bitwise.c ***/
  95451. /*** Start of inlined file: framing.c ***/
  95452. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95453. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95454. // tasks..
  95455. #if JUCE_MSVC
  95456. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95457. #endif
  95458. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95459. #if JUCE_USE_OGGVORBIS
  95460. #include <stdlib.h>
  95461. #include <string.h>
  95462. int ogg_page_version(ogg_page *og){
  95463. return((int)(og->header[4]));
  95464. }
  95465. int ogg_page_continued(ogg_page *og){
  95466. return((int)(og->header[5]&0x01));
  95467. }
  95468. int ogg_page_bos(ogg_page *og){
  95469. return((int)(og->header[5]&0x02));
  95470. }
  95471. int ogg_page_eos(ogg_page *og){
  95472. return((int)(og->header[5]&0x04));
  95473. }
  95474. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95475. unsigned char *page=og->header;
  95476. ogg_int64_t granulepos=page[13]&(0xff);
  95477. granulepos= (granulepos<<8)|(page[12]&0xff);
  95478. granulepos= (granulepos<<8)|(page[11]&0xff);
  95479. granulepos= (granulepos<<8)|(page[10]&0xff);
  95480. granulepos= (granulepos<<8)|(page[9]&0xff);
  95481. granulepos= (granulepos<<8)|(page[8]&0xff);
  95482. granulepos= (granulepos<<8)|(page[7]&0xff);
  95483. granulepos= (granulepos<<8)|(page[6]&0xff);
  95484. return(granulepos);
  95485. }
  95486. int ogg_page_serialno(ogg_page *og){
  95487. return(og->header[14] |
  95488. (og->header[15]<<8) |
  95489. (og->header[16]<<16) |
  95490. (og->header[17]<<24));
  95491. }
  95492. long ogg_page_pageno(ogg_page *og){
  95493. return(og->header[18] |
  95494. (og->header[19]<<8) |
  95495. (og->header[20]<<16) |
  95496. (og->header[21]<<24));
  95497. }
  95498. int ogg_page_packets(ogg_page *og){
  95499. int i,n=og->header[26],count=0;
  95500. for(i=0;i<n;i++)
  95501. if(og->header[27+i]<255)count++;
  95502. return(count);
  95503. }
  95504. #if 0
  95505. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95506. int i;
  95507. unsigned long r;
  95508. r = index << 24;
  95509. for (i=0; i<8; i++)
  95510. if (r & 0x80000000UL)
  95511. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95512. polynomial, although we use an
  95513. unreflected alg and an init/final
  95514. of 0, not 0xffffffff */
  95515. else
  95516. r<<=1;
  95517. return (r & 0xffffffffUL);
  95518. }
  95519. #endif
  95520. static const ogg_uint32_t crc_lookup[256]={
  95521. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95522. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95523. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95524. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95525. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95526. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95527. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95528. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95529. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95530. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95531. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95532. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95533. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95534. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95535. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95536. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95537. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95538. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95539. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95540. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95541. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95542. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95543. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95544. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95545. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95546. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95547. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95548. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95549. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95550. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95551. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95552. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95553. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95554. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95555. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95556. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95557. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95558. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95559. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95560. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95561. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95562. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95563. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95564. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95565. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95566. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95567. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95568. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95569. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95570. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95571. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95572. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95573. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95574. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95575. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95576. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95577. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95578. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95579. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95580. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95581. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95582. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95583. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95584. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95585. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95586. if(os){
  95587. memset(os,0,sizeof(*os));
  95588. os->body_storage=16*1024;
  95589. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95590. os->lacing_storage=1024;
  95591. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95592. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95593. os->serialno=serialno;
  95594. return(0);
  95595. }
  95596. return(-1);
  95597. }
  95598. int ogg_stream_clear(ogg_stream_state *os){
  95599. if(os){
  95600. if(os->body_data)_ogg_free(os->body_data);
  95601. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95602. if(os->granule_vals)_ogg_free(os->granule_vals);
  95603. memset(os,0,sizeof(*os));
  95604. }
  95605. return(0);
  95606. }
  95607. int ogg_stream_destroy(ogg_stream_state *os){
  95608. if(os){
  95609. ogg_stream_clear(os);
  95610. _ogg_free(os);
  95611. }
  95612. return(0);
  95613. }
  95614. static void _os_body_expand(ogg_stream_state *os,int needed){
  95615. if(os->body_storage<=os->body_fill+needed){
  95616. os->body_storage+=(needed+1024);
  95617. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95618. }
  95619. }
  95620. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95621. if(os->lacing_storage<=os->lacing_fill+needed){
  95622. os->lacing_storage+=(needed+32);
  95623. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95624. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95625. }
  95626. }
  95627. void ogg_page_checksum_set(ogg_page *og){
  95628. if(og){
  95629. ogg_uint32_t crc_reg=0;
  95630. int i;
  95631. og->header[22]=0;
  95632. og->header[23]=0;
  95633. og->header[24]=0;
  95634. og->header[25]=0;
  95635. for(i=0;i<og->header_len;i++)
  95636. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95637. for(i=0;i<og->body_len;i++)
  95638. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95639. og->header[22]=(unsigned char)(crc_reg&0xff);
  95640. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95641. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95642. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95643. }
  95644. }
  95645. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95646. int lacing_vals=op->bytes/255+1,i;
  95647. if(os->body_returned){
  95648. os->body_fill-=os->body_returned;
  95649. if(os->body_fill)
  95650. memmove(os->body_data,os->body_data+os->body_returned,
  95651. os->body_fill);
  95652. os->body_returned=0;
  95653. }
  95654. _os_body_expand(os,op->bytes);
  95655. _os_lacing_expand(os,lacing_vals);
  95656. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95657. os->body_fill+=op->bytes;
  95658. for(i=0;i<lacing_vals-1;i++){
  95659. os->lacing_vals[os->lacing_fill+i]=255;
  95660. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95661. }
  95662. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95663. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95664. os->lacing_vals[os->lacing_fill]|= 0x100;
  95665. os->lacing_fill+=lacing_vals;
  95666. os->packetno++;
  95667. if(op->e_o_s)os->e_o_s=1;
  95668. return(0);
  95669. }
  95670. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95671. int i;
  95672. int vals=0;
  95673. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95674. int bytes=0;
  95675. long acc=0;
  95676. ogg_int64_t granule_pos=-1;
  95677. if(maxvals==0)return(0);
  95678. if(os->b_o_s==0){ /* 'initial header page' case */
  95679. granule_pos=0;
  95680. for(vals=0;vals<maxvals;vals++){
  95681. if((os->lacing_vals[vals]&0x0ff)<255){
  95682. vals++;
  95683. break;
  95684. }
  95685. }
  95686. }else{
  95687. for(vals=0;vals<maxvals;vals++){
  95688. if(acc>4096)break;
  95689. acc+=os->lacing_vals[vals]&0x0ff;
  95690. if((os->lacing_vals[vals]&0xff)<255)
  95691. granule_pos=os->granule_vals[vals];
  95692. }
  95693. }
  95694. memcpy(os->header,"OggS",4);
  95695. os->header[4]=0x00;
  95696. os->header[5]=0x00;
  95697. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95698. if(os->b_o_s==0)os->header[5]|=0x02;
  95699. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95700. os->b_o_s=1;
  95701. for(i=6;i<14;i++){
  95702. os->header[i]=(unsigned char)(granule_pos&0xff);
  95703. granule_pos>>=8;
  95704. }
  95705. {
  95706. long serialno=os->serialno;
  95707. for(i=14;i<18;i++){
  95708. os->header[i]=(unsigned char)(serialno&0xff);
  95709. serialno>>=8;
  95710. }
  95711. }
  95712. if(os->pageno==-1)os->pageno=0; /* because someone called
  95713. stream_reset; this would be a
  95714. strange thing to do in an
  95715. encode stream, but it has
  95716. plausible uses */
  95717. {
  95718. long pageno=os->pageno++;
  95719. for(i=18;i<22;i++){
  95720. os->header[i]=(unsigned char)(pageno&0xff);
  95721. pageno>>=8;
  95722. }
  95723. }
  95724. os->header[22]=0;
  95725. os->header[23]=0;
  95726. os->header[24]=0;
  95727. os->header[25]=0;
  95728. os->header[26]=(unsigned char)(vals&0xff);
  95729. for(i=0;i<vals;i++)
  95730. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95731. og->header=os->header;
  95732. og->header_len=os->header_fill=vals+27;
  95733. og->body=os->body_data+os->body_returned;
  95734. og->body_len=bytes;
  95735. os->lacing_fill-=vals;
  95736. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95737. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95738. os->body_returned+=bytes;
  95739. ogg_page_checksum_set(og);
  95740. return(1);
  95741. }
  95742. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95743. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95744. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95745. os->lacing_fill>=255 || /* 'segment table full' case */
  95746. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95747. return(ogg_stream_flush(os,og));
  95748. }
  95749. return(0);
  95750. }
  95751. int ogg_stream_eos(ogg_stream_state *os){
  95752. return os->e_o_s;
  95753. }
  95754. int ogg_sync_init(ogg_sync_state *oy){
  95755. if(oy){
  95756. memset(oy,0,sizeof(*oy));
  95757. }
  95758. return(0);
  95759. }
  95760. int ogg_sync_clear(ogg_sync_state *oy){
  95761. if(oy){
  95762. if(oy->data)_ogg_free(oy->data);
  95763. ogg_sync_init(oy);
  95764. }
  95765. return(0);
  95766. }
  95767. int ogg_sync_destroy(ogg_sync_state *oy){
  95768. if(oy){
  95769. ogg_sync_clear(oy);
  95770. _ogg_free(oy);
  95771. }
  95772. return(0);
  95773. }
  95774. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95775. if(oy->returned){
  95776. oy->fill-=oy->returned;
  95777. if(oy->fill>0)
  95778. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95779. oy->returned=0;
  95780. }
  95781. if(size>oy->storage-oy->fill){
  95782. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95783. if(oy->data)
  95784. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95785. else
  95786. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95787. oy->storage=newsize;
  95788. }
  95789. return((char *)oy->data+oy->fill);
  95790. }
  95791. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95792. if(oy->fill+bytes>oy->storage)return(-1);
  95793. oy->fill+=bytes;
  95794. return(0);
  95795. }
  95796. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95797. unsigned char *page=oy->data+oy->returned;
  95798. unsigned char *next;
  95799. long bytes=oy->fill-oy->returned;
  95800. if(oy->headerbytes==0){
  95801. int headerbytes,i;
  95802. if(bytes<27)return(0); /* not enough for a header */
  95803. if(memcmp(page,"OggS",4))goto sync_fail;
  95804. headerbytes=page[26]+27;
  95805. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95806. for(i=0;i<page[26];i++)
  95807. oy->bodybytes+=page[27+i];
  95808. oy->headerbytes=headerbytes;
  95809. }
  95810. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95811. {
  95812. char chksum[4];
  95813. ogg_page log;
  95814. memcpy(chksum,page+22,4);
  95815. memset(page+22,0,4);
  95816. log.header=page;
  95817. log.header_len=oy->headerbytes;
  95818. log.body=page+oy->headerbytes;
  95819. log.body_len=oy->bodybytes;
  95820. ogg_page_checksum_set(&log);
  95821. if(memcmp(chksum,page+22,4)){
  95822. memcpy(page+22,chksum,4);
  95823. goto sync_fail;
  95824. }
  95825. }
  95826. {
  95827. unsigned char *page=oy->data+oy->returned;
  95828. long bytes;
  95829. if(og){
  95830. og->header=page;
  95831. og->header_len=oy->headerbytes;
  95832. og->body=page+oy->headerbytes;
  95833. og->body_len=oy->bodybytes;
  95834. }
  95835. oy->unsynced=0;
  95836. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95837. oy->headerbytes=0;
  95838. oy->bodybytes=0;
  95839. return(bytes);
  95840. }
  95841. sync_fail:
  95842. oy->headerbytes=0;
  95843. oy->bodybytes=0;
  95844. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95845. if(!next)
  95846. next=oy->data+oy->fill;
  95847. oy->returned=next-oy->data;
  95848. return(-(next-page));
  95849. }
  95850. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95851. for(;;){
  95852. long ret=ogg_sync_pageseek(oy,og);
  95853. if(ret>0){
  95854. return(1);
  95855. }
  95856. if(ret==0){
  95857. return(0);
  95858. }
  95859. if(!oy->unsynced){
  95860. oy->unsynced=1;
  95861. return(-1);
  95862. }
  95863. }
  95864. }
  95865. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95866. unsigned char *header=og->header;
  95867. unsigned char *body=og->body;
  95868. long bodysize=og->body_len;
  95869. int segptr=0;
  95870. int version=ogg_page_version(og);
  95871. int continued=ogg_page_continued(og);
  95872. int bos=ogg_page_bos(og);
  95873. int eos=ogg_page_eos(og);
  95874. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95875. int serialno=ogg_page_serialno(og);
  95876. long pageno=ogg_page_pageno(og);
  95877. int segments=header[26];
  95878. {
  95879. long lr=os->lacing_returned;
  95880. long br=os->body_returned;
  95881. if(br){
  95882. os->body_fill-=br;
  95883. if(os->body_fill)
  95884. memmove(os->body_data,os->body_data+br,os->body_fill);
  95885. os->body_returned=0;
  95886. }
  95887. if(lr){
  95888. if(os->lacing_fill-lr){
  95889. memmove(os->lacing_vals,os->lacing_vals+lr,
  95890. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95891. memmove(os->granule_vals,os->granule_vals+lr,
  95892. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95893. }
  95894. os->lacing_fill-=lr;
  95895. os->lacing_packet-=lr;
  95896. os->lacing_returned=0;
  95897. }
  95898. }
  95899. if(serialno!=os->serialno)return(-1);
  95900. if(version>0)return(-1);
  95901. _os_lacing_expand(os,segments+1);
  95902. if(pageno!=os->pageno){
  95903. int i;
  95904. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95905. os->body_fill-=os->lacing_vals[i]&0xff;
  95906. os->lacing_fill=os->lacing_packet;
  95907. if(os->pageno!=-1){
  95908. os->lacing_vals[os->lacing_fill++]=0x400;
  95909. os->lacing_packet++;
  95910. }
  95911. }
  95912. if(continued){
  95913. if(os->lacing_fill<1 ||
  95914. os->lacing_vals[os->lacing_fill-1]==0x400){
  95915. bos=0;
  95916. for(;segptr<segments;segptr++){
  95917. int val=header[27+segptr];
  95918. body+=val;
  95919. bodysize-=val;
  95920. if(val<255){
  95921. segptr++;
  95922. break;
  95923. }
  95924. }
  95925. }
  95926. }
  95927. if(bodysize){
  95928. _os_body_expand(os,bodysize);
  95929. memcpy(os->body_data+os->body_fill,body,bodysize);
  95930. os->body_fill+=bodysize;
  95931. }
  95932. {
  95933. int saved=-1;
  95934. while(segptr<segments){
  95935. int val=header[27+segptr];
  95936. os->lacing_vals[os->lacing_fill]=val;
  95937. os->granule_vals[os->lacing_fill]=-1;
  95938. if(bos){
  95939. os->lacing_vals[os->lacing_fill]|=0x100;
  95940. bos=0;
  95941. }
  95942. if(val<255)saved=os->lacing_fill;
  95943. os->lacing_fill++;
  95944. segptr++;
  95945. if(val<255)os->lacing_packet=os->lacing_fill;
  95946. }
  95947. if(saved!=-1){
  95948. os->granule_vals[saved]=granulepos;
  95949. }
  95950. }
  95951. if(eos){
  95952. os->e_o_s=1;
  95953. if(os->lacing_fill>0)
  95954. os->lacing_vals[os->lacing_fill-1]|=0x200;
  95955. }
  95956. os->pageno=pageno+1;
  95957. return(0);
  95958. }
  95959. int ogg_sync_reset(ogg_sync_state *oy){
  95960. oy->fill=0;
  95961. oy->returned=0;
  95962. oy->unsynced=0;
  95963. oy->headerbytes=0;
  95964. oy->bodybytes=0;
  95965. return(0);
  95966. }
  95967. int ogg_stream_reset(ogg_stream_state *os){
  95968. os->body_fill=0;
  95969. os->body_returned=0;
  95970. os->lacing_fill=0;
  95971. os->lacing_packet=0;
  95972. os->lacing_returned=0;
  95973. os->header_fill=0;
  95974. os->e_o_s=0;
  95975. os->b_o_s=0;
  95976. os->pageno=-1;
  95977. os->packetno=0;
  95978. os->granulepos=0;
  95979. return(0);
  95980. }
  95981. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  95982. ogg_stream_reset(os);
  95983. os->serialno=serialno;
  95984. return(0);
  95985. }
  95986. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  95987. int ptr=os->lacing_returned;
  95988. if(os->lacing_packet<=ptr)return(0);
  95989. if(os->lacing_vals[ptr]&0x400){
  95990. os->lacing_returned++;
  95991. os->packetno++;
  95992. return(-1);
  95993. }
  95994. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  95995. to ask if there's a whole packet
  95996. waiting */
  95997. {
  95998. int size=os->lacing_vals[ptr]&0xff;
  95999. int bytes=size;
  96000. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  96001. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  96002. while(size==255){
  96003. int val=os->lacing_vals[++ptr];
  96004. size=val&0xff;
  96005. if(val&0x200)eos=0x200;
  96006. bytes+=size;
  96007. }
  96008. if(op){
  96009. op->e_o_s=eos;
  96010. op->b_o_s=bos;
  96011. op->packet=os->body_data+os->body_returned;
  96012. op->packetno=os->packetno;
  96013. op->granulepos=os->granule_vals[ptr];
  96014. op->bytes=bytes;
  96015. }
  96016. if(adv){
  96017. os->body_returned+=bytes;
  96018. os->lacing_returned=ptr+1;
  96019. os->packetno++;
  96020. }
  96021. }
  96022. return(1);
  96023. }
  96024. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96025. return _packetout(os,op,1);
  96026. }
  96027. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96028. return _packetout(os,op,0);
  96029. }
  96030. void ogg_packet_clear(ogg_packet *op) {
  96031. _ogg_free(op->packet);
  96032. memset(op, 0, sizeof(*op));
  96033. }
  96034. #ifdef _V_SELFTEST
  96035. #include <stdio.h>
  96036. ogg_stream_state os_en, os_de;
  96037. ogg_sync_state oy;
  96038. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96039. long j;
  96040. static int sequence=0;
  96041. static int lastno=0;
  96042. if(op->bytes!=len){
  96043. fprintf(stderr,"incorrect packet length!\n");
  96044. exit(1);
  96045. }
  96046. if(op->granulepos!=pos){
  96047. fprintf(stderr,"incorrect packet position!\n");
  96048. exit(1);
  96049. }
  96050. if(no==0){
  96051. sequence=0;
  96052. }else{
  96053. sequence++;
  96054. if(no>lastno+1)
  96055. sequence++;
  96056. }
  96057. lastno=no;
  96058. if(op->packetno!=sequence){
  96059. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96060. (long)(op->packetno),sequence);
  96061. exit(1);
  96062. }
  96063. for(j=0;j<op->bytes;j++)
  96064. if(op->packet[j]!=((j+no)&0xff)){
  96065. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96066. j,op->packet[j],(j+no)&0xff);
  96067. exit(1);
  96068. }
  96069. }
  96070. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96071. long j;
  96072. for(j=0;j<og->body_len;j++)
  96073. if(og->body[j]!=data[j]){
  96074. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96075. j,data[j],og->body[j]);
  96076. exit(1);
  96077. }
  96078. for(j=0;j<og->header_len;j++){
  96079. if(og->header[j]!=header[j]){
  96080. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96081. for(j=0;j<header[26]+27;j++)
  96082. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96083. fprintf(stderr,"\n");
  96084. exit(1);
  96085. }
  96086. }
  96087. if(og->header_len!=header[26]+27){
  96088. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96089. og->header_len,header[26]+27);
  96090. exit(1);
  96091. }
  96092. }
  96093. void print_header(ogg_page *og){
  96094. int j;
  96095. fprintf(stderr,"\nHEADER:\n");
  96096. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96097. og->header[0],og->header[1],og->header[2],og->header[3],
  96098. (int)og->header[4],(int)og->header[5]);
  96099. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96100. (og->header[9]<<24)|(og->header[8]<<16)|
  96101. (og->header[7]<<8)|og->header[6],
  96102. (og->header[17]<<24)|(og->header[16]<<16)|
  96103. (og->header[15]<<8)|og->header[14],
  96104. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96105. (og->header[19]<<8)|og->header[18]);
  96106. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96107. (int)og->header[22],(int)og->header[23],
  96108. (int)og->header[24],(int)og->header[25],
  96109. (int)og->header[26]);
  96110. for(j=27;j<og->header_len;j++)
  96111. fprintf(stderr,"%d ",(int)og->header[j]);
  96112. fprintf(stderr,")\n\n");
  96113. }
  96114. void copy_page(ogg_page *og){
  96115. unsigned char *temp=_ogg_malloc(og->header_len);
  96116. memcpy(temp,og->header,og->header_len);
  96117. og->header=temp;
  96118. temp=_ogg_malloc(og->body_len);
  96119. memcpy(temp,og->body,og->body_len);
  96120. og->body=temp;
  96121. }
  96122. void free_page(ogg_page *og){
  96123. _ogg_free (og->header);
  96124. _ogg_free (og->body);
  96125. }
  96126. void error(void){
  96127. fprintf(stderr,"error!\n");
  96128. exit(1);
  96129. }
  96130. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96131. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96132. 0x01,0x02,0x03,0x04,0,0,0,0,
  96133. 0x15,0xed,0xec,0x91,
  96134. 1,
  96135. 17};
  96136. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96137. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96138. 0x01,0x02,0x03,0x04,0,0,0,0,
  96139. 0x59,0x10,0x6c,0x2c,
  96140. 1,
  96141. 17};
  96142. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96143. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96144. 0x01,0x02,0x03,0x04,1,0,0,0,
  96145. 0x89,0x33,0x85,0xce,
  96146. 13,
  96147. 254,255,0,255,1,255,245,255,255,0,
  96148. 255,255,90};
  96149. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96150. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96151. 0x01,0x02,0x03,0x04,0,0,0,0,
  96152. 0xff,0x7b,0x23,0x17,
  96153. 1,
  96154. 0};
  96155. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96156. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96157. 0x01,0x02,0x03,0x04,1,0,0,0,
  96158. 0x5c,0x3f,0x66,0xcb,
  96159. 17,
  96160. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96161. 255,255,90,0};
  96162. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96163. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96164. 0x01,0x02,0x03,0x04,0,0,0,0,
  96165. 0x01,0x27,0x31,0xaa,
  96166. 18,
  96167. 255,255,255,255,255,255,255,255,
  96168. 255,255,255,255,255,255,255,255,255,10};
  96169. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96170. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96171. 0x01,0x02,0x03,0x04,1,0,0,0,
  96172. 0x7f,0x4e,0x8a,0xd2,
  96173. 4,
  96174. 255,4,255,0};
  96175. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96176. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96177. 0x01,0x02,0x03,0x04,0,0,0,0,
  96178. 0xff,0x7b,0x23,0x17,
  96179. 1,
  96180. 0};
  96181. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96182. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96183. 0x01,0x02,0x03,0x04,1,0,0,0,
  96184. 0x54,0x05,0x51,0xc8,
  96185. 17,
  96186. 255,255,255,255,255,255,255,255,
  96187. 255,255,255,255,255,255,255,255,255};
  96188. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96189. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96190. 0x01,0x02,0x03,0x04,2,0,0,0,
  96191. 0xc8,0xc3,0xcb,0xed,
  96192. 5,
  96193. 10,255,4,255,0};
  96194. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96195. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96196. 0x01,0x02,0x03,0x04,0,0,0,0,
  96197. 0xff,0x7b,0x23,0x17,
  96198. 1,
  96199. 0};
  96200. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96201. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96202. 0x01,0x02,0x03,0x04,1,0,0,0,
  96203. 0xed,0x2a,0x2e,0xa7,
  96204. 255,
  96205. 10,10,10,10,10,10,10,10,
  96206. 10,10,10,10,10,10,10,10,
  96207. 10,10,10,10,10,10,10,10,
  96208. 10,10,10,10,10,10,10,10,
  96209. 10,10,10,10,10,10,10,10,
  96210. 10,10,10,10,10,10,10,10,
  96211. 10,10,10,10,10,10,10,10,
  96212. 10,10,10,10,10,10,10,10,
  96213. 10,10,10,10,10,10,10,10,
  96214. 10,10,10,10,10,10,10,10,
  96215. 10,10,10,10,10,10,10,10,
  96216. 10,10,10,10,10,10,10,10,
  96217. 10,10,10,10,10,10,10,10,
  96218. 10,10,10,10,10,10,10,10,
  96219. 10,10,10,10,10,10,10,10,
  96220. 10,10,10,10,10,10,10,10,
  96221. 10,10,10,10,10,10,10,10,
  96222. 10,10,10,10,10,10,10,10,
  96223. 10,10,10,10,10,10,10,10,
  96224. 10,10,10,10,10,10,10,10,
  96225. 10,10,10,10,10,10,10,10,
  96226. 10,10,10,10,10,10,10,10,
  96227. 10,10,10,10,10,10,10,10,
  96228. 10,10,10,10,10,10,10,10,
  96229. 10,10,10,10,10,10,10,10,
  96230. 10,10,10,10,10,10,10,10,
  96231. 10,10,10,10,10,10,10,10,
  96232. 10,10,10,10,10,10,10,10,
  96233. 10,10,10,10,10,10,10,10,
  96234. 10,10,10,10,10,10,10,10,
  96235. 10,10,10,10,10,10,10,10,
  96236. 10,10,10,10,10,10,10};
  96237. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96238. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96239. 0x01,0x02,0x03,0x04,2,0,0,0,
  96240. 0x6c,0x3b,0x82,0x3d,
  96241. 1,
  96242. 50};
  96243. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96244. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96245. 0x01,0x02,0x03,0x04,0,0,0,0,
  96246. 0xff,0x7b,0x23,0x17,
  96247. 1,
  96248. 0};
  96249. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96250. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96251. 0x01,0x02,0x03,0x04,1,0,0,0,
  96252. 0x3c,0xd9,0x4d,0x3f,
  96253. 17,
  96254. 100,255,255,255,255,255,255,255,255,
  96255. 255,255,255,255,255,255,255,255};
  96256. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96257. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96258. 0x01,0x02,0x03,0x04,2,0,0,0,
  96259. 0x01,0xd2,0xe5,0xe5,
  96260. 17,
  96261. 255,255,255,255,255,255,255,255,
  96262. 255,255,255,255,255,255,255,255,255};
  96263. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96264. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96265. 0x01,0x02,0x03,0x04,3,0,0,0,
  96266. 0xef,0xdd,0x88,0xde,
  96267. 7,
  96268. 255,255,75,255,4,255,0};
  96269. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96270. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96271. 0x01,0x02,0x03,0x04,0,0,0,0,
  96272. 0xff,0x7b,0x23,0x17,
  96273. 1,
  96274. 0};
  96275. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96276. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96277. 0x01,0x02,0x03,0x04,1,0,0,0,
  96278. 0x3c,0xd9,0x4d,0x3f,
  96279. 17,
  96280. 100,255,255,255,255,255,255,255,255,
  96281. 255,255,255,255,255,255,255,255};
  96282. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96283. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96284. 0x01,0x02,0x03,0x04,2,0,0,0,
  96285. 0xd4,0xe0,0x60,0xe5,
  96286. 1,0};
  96287. void test_pack(const int *pl, const int **headers, int byteskip,
  96288. int pageskip, int packetskip){
  96289. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96290. long inptr=0;
  96291. long outptr=0;
  96292. long deptr=0;
  96293. long depacket=0;
  96294. long granule_pos=7,pageno=0;
  96295. int i,j,packets,pageout=pageskip;
  96296. int eosflag=0;
  96297. int bosflag=0;
  96298. int byteskipcount=0;
  96299. ogg_stream_reset(&os_en);
  96300. ogg_stream_reset(&os_de);
  96301. ogg_sync_reset(&oy);
  96302. for(packets=0;packets<packetskip;packets++)
  96303. depacket+=pl[packets];
  96304. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96305. for(i=0;i<packets;i++){
  96306. ogg_packet op;
  96307. int len=pl[i];
  96308. op.packet=data+inptr;
  96309. op.bytes=len;
  96310. op.e_o_s=(pl[i+1]<0?1:0);
  96311. op.granulepos=granule_pos;
  96312. granule_pos+=1024;
  96313. for(j=0;j<len;j++)data[inptr++]=i+j;
  96314. ogg_stream_packetin(&os_en,&op);
  96315. {
  96316. ogg_page og;
  96317. while(ogg_stream_pageout(&os_en,&og)){
  96318. fprintf(stderr,"%ld, ",pageno);
  96319. if(headers[pageno]==NULL){
  96320. fprintf(stderr,"coded too many pages!\n");
  96321. exit(1);
  96322. }
  96323. check_page(data+outptr,headers[pageno],&og);
  96324. outptr+=og.body_len;
  96325. pageno++;
  96326. if(pageskip){
  96327. bosflag=1;
  96328. pageskip--;
  96329. deptr+=og.body_len;
  96330. }
  96331. {
  96332. ogg_page og_de;
  96333. ogg_packet op_de,op_de2;
  96334. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96335. char *next=buf;
  96336. byteskipcount+=og.header_len;
  96337. if(byteskipcount>byteskip){
  96338. memcpy(next,og.header,byteskipcount-byteskip);
  96339. next+=byteskipcount-byteskip;
  96340. byteskipcount=byteskip;
  96341. }
  96342. byteskipcount+=og.body_len;
  96343. if(byteskipcount>byteskip){
  96344. memcpy(next,og.body,byteskipcount-byteskip);
  96345. next+=byteskipcount-byteskip;
  96346. byteskipcount=byteskip;
  96347. }
  96348. ogg_sync_wrote(&oy,next-buf);
  96349. while(1){
  96350. int ret=ogg_sync_pageout(&oy,&og_de);
  96351. if(ret==0)break;
  96352. if(ret<0)continue;
  96353. fprintf(stderr,"(%ld), ",pageout);
  96354. check_page(data+deptr,headers[pageout],&og_de);
  96355. deptr+=og_de.body_len;
  96356. pageout++;
  96357. ogg_stream_pagein(&os_de,&og_de);
  96358. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96359. ogg_stream_packetpeek(&os_de,NULL);
  96360. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96361. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96362. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96363. depacket);
  96364. exit(1);
  96365. }
  96366. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96367. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96368. depacket);
  96369. exit(1);
  96370. }
  96371. if(bosflag==0 && op_de.b_o_s==0){
  96372. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96373. exit(1);
  96374. }
  96375. if(bosflag && op_de.b_o_s){
  96376. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96377. exit(1);
  96378. }
  96379. bosflag=1;
  96380. depacket+=op_de.bytes;
  96381. if(eosflag){
  96382. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96383. exit(1);
  96384. }
  96385. if(op_de.e_o_s)eosflag=1;
  96386. if(op_de.granulepos!=-1){
  96387. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96388. }
  96389. }
  96390. }
  96391. }
  96392. }
  96393. }
  96394. }
  96395. _ogg_free(data);
  96396. if(headers[pageno]!=NULL){
  96397. fprintf(stderr,"did not write last page!\n");
  96398. exit(1);
  96399. }
  96400. if(headers[pageout]!=NULL){
  96401. fprintf(stderr,"did not decode last page!\n");
  96402. exit(1);
  96403. }
  96404. if(inptr!=outptr){
  96405. fprintf(stderr,"encoded page data incomplete!\n");
  96406. exit(1);
  96407. }
  96408. if(inptr!=deptr){
  96409. fprintf(stderr,"decoded page data incomplete!\n");
  96410. exit(1);
  96411. }
  96412. if(inptr!=depacket){
  96413. fprintf(stderr,"decoded packet data incomplete!\n");
  96414. exit(1);
  96415. }
  96416. if(!eosflag){
  96417. fprintf(stderr,"Never got a packet with EOS set!\n");
  96418. exit(1);
  96419. }
  96420. fprintf(stderr,"ok.\n");
  96421. }
  96422. int main(void){
  96423. ogg_stream_init(&os_en,0x04030201);
  96424. ogg_stream_init(&os_de,0x04030201);
  96425. ogg_sync_init(&oy);
  96426. {
  96427. const int packets[]={17, -1};
  96428. const int *headret[]={head1_0,NULL};
  96429. fprintf(stderr,"testing single page encoding... ");
  96430. test_pack(packets,headret,0,0,0);
  96431. }
  96432. {
  96433. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96434. const int *headret[]={head1_1,head2_1,NULL};
  96435. fprintf(stderr,"testing basic page encoding... ");
  96436. test_pack(packets,headret,0,0,0);
  96437. }
  96438. {
  96439. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96440. const int *headret[]={head1_2,head2_2,NULL};
  96441. fprintf(stderr,"testing basic nil packets... ");
  96442. test_pack(packets,headret,0,0,0);
  96443. }
  96444. {
  96445. const int packets[]={4345,259,255,-1};
  96446. const int *headret[]={head1_3,head2_3,NULL};
  96447. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96448. test_pack(packets,headret,0,0,0);
  96449. }
  96450. {
  96451. const int packets[]={0,4345,259,255,-1};
  96452. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96453. fprintf(stderr,"testing single packet page span... ");
  96454. test_pack(packets,headret,0,0,0);
  96455. }
  96456. {
  96457. const int packets[]={0,10,10,10,10,10,10,10,10,
  96458. 10,10,10,10,10,10,10,10,
  96459. 10,10,10,10,10,10,10,10,
  96460. 10,10,10,10,10,10,10,10,
  96461. 10,10,10,10,10,10,10,10,
  96462. 10,10,10,10,10,10,10,10,
  96463. 10,10,10,10,10,10,10,10,
  96464. 10,10,10,10,10,10,10,10,
  96465. 10,10,10,10,10,10,10,10,
  96466. 10,10,10,10,10,10,10,10,
  96467. 10,10,10,10,10,10,10,10,
  96468. 10,10,10,10,10,10,10,10,
  96469. 10,10,10,10,10,10,10,10,
  96470. 10,10,10,10,10,10,10,10,
  96471. 10,10,10,10,10,10,10,10,
  96472. 10,10,10,10,10,10,10,10,
  96473. 10,10,10,10,10,10,10,10,
  96474. 10,10,10,10,10,10,10,10,
  96475. 10,10,10,10,10,10,10,10,
  96476. 10,10,10,10,10,10,10,10,
  96477. 10,10,10,10,10,10,10,10,
  96478. 10,10,10,10,10,10,10,10,
  96479. 10,10,10,10,10,10,10,10,
  96480. 10,10,10,10,10,10,10,10,
  96481. 10,10,10,10,10,10,10,10,
  96482. 10,10,10,10,10,10,10,10,
  96483. 10,10,10,10,10,10,10,10,
  96484. 10,10,10,10,10,10,10,10,
  96485. 10,10,10,10,10,10,10,10,
  96486. 10,10,10,10,10,10,10,10,
  96487. 10,10,10,10,10,10,10,10,
  96488. 10,10,10,10,10,10,10,50,-1};
  96489. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96490. fprintf(stderr,"testing max packet segments... ");
  96491. test_pack(packets,headret,0,0,0);
  96492. }
  96493. {
  96494. const int packets[]={0,100,9000,259,255,-1};
  96495. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96496. fprintf(stderr,"testing very large packets... ");
  96497. test_pack(packets,headret,0,0,0);
  96498. }
  96499. {
  96500. const int packets[]={0,100,9000,259,255,-1};
  96501. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96502. fprintf(stderr,"testing continuation resync in very large packets... ");
  96503. test_pack(packets,headret,100,2,3);
  96504. }
  96505. {
  96506. const int packets[]={0,100,4080,-1};
  96507. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96508. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96509. test_pack(packets,headret,0,0,0);
  96510. }
  96511. {
  96512. unsigned char *data=_ogg_malloc(1024*1024);
  96513. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96514. int inptr=0,i,j;
  96515. ogg_page og[5];
  96516. ogg_stream_reset(&os_en);
  96517. for(i=0;pl[i]!=-1;i++){
  96518. ogg_packet op;
  96519. int len=pl[i];
  96520. op.packet=data+inptr;
  96521. op.bytes=len;
  96522. op.e_o_s=(pl[i+1]<0?1:0);
  96523. op.granulepos=(i+1)*1000;
  96524. for(j=0;j<len;j++)data[inptr++]=i+j;
  96525. ogg_stream_packetin(&os_en,&op);
  96526. }
  96527. _ogg_free(data);
  96528. for(i=0;i<5;i++){
  96529. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96530. fprintf(stderr,"Too few pages output building sync tests!\n");
  96531. exit(1);
  96532. }
  96533. copy_page(&og[i]);
  96534. }
  96535. {
  96536. ogg_page temp;
  96537. ogg_packet test;
  96538. fprintf(stderr,"Testing loss of pages... ");
  96539. ogg_sync_reset(&oy);
  96540. ogg_stream_reset(&os_de);
  96541. for(i=0;i<5;i++){
  96542. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96543. og[i].header_len);
  96544. ogg_sync_wrote(&oy,og[i].header_len);
  96545. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96546. ogg_sync_wrote(&oy,og[i].body_len);
  96547. }
  96548. ogg_sync_pageout(&oy,&temp);
  96549. ogg_stream_pagein(&os_de,&temp);
  96550. ogg_sync_pageout(&oy,&temp);
  96551. ogg_stream_pagein(&os_de,&temp);
  96552. ogg_sync_pageout(&oy,&temp);
  96553. ogg_sync_pageout(&oy,&temp);
  96554. ogg_stream_pagein(&os_de,&temp);
  96555. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96556. checkpacket(&test,0,0,0);
  96557. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96558. checkpacket(&test,100,1,-1);
  96559. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96560. checkpacket(&test,4079,2,3000);
  96561. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96562. fprintf(stderr,"Error: loss of page did not return error\n");
  96563. exit(1);
  96564. }
  96565. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96566. checkpacket(&test,76,5,-1);
  96567. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96568. checkpacket(&test,34,6,-1);
  96569. fprintf(stderr,"ok.\n");
  96570. }
  96571. {
  96572. ogg_page temp;
  96573. ogg_packet test;
  96574. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96575. ogg_sync_reset(&oy);
  96576. ogg_stream_reset(&os_de);
  96577. for(i=0;i<5;i++){
  96578. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96579. og[i].header_len);
  96580. ogg_sync_wrote(&oy,og[i].header_len);
  96581. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96582. ogg_sync_wrote(&oy,og[i].body_len);
  96583. }
  96584. ogg_sync_pageout(&oy,&temp);
  96585. ogg_stream_pagein(&os_de,&temp);
  96586. ogg_sync_pageout(&oy,&temp);
  96587. ogg_stream_pagein(&os_de,&temp);
  96588. ogg_sync_pageout(&oy,&temp);
  96589. ogg_stream_pagein(&os_de,&temp);
  96590. ogg_sync_pageout(&oy,&temp);
  96591. ogg_sync_pageout(&oy,&temp);
  96592. ogg_stream_pagein(&os_de,&temp);
  96593. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96594. checkpacket(&test,0,0,0);
  96595. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96596. checkpacket(&test,100,1,-1);
  96597. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96598. checkpacket(&test,4079,2,3000);
  96599. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96600. checkpacket(&test,2956,3,4000);
  96601. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96602. fprintf(stderr,"Error: loss of page did not return error\n");
  96603. exit(1);
  96604. }
  96605. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96606. checkpacket(&test,300,13,14000);
  96607. fprintf(stderr,"ok.\n");
  96608. }
  96609. {
  96610. ogg_page og_de;
  96611. fprintf(stderr,"Testing sync on partial inputs... ");
  96612. ogg_sync_reset(&oy);
  96613. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96614. 3);
  96615. ogg_sync_wrote(&oy,3);
  96616. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96617. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96618. 20);
  96619. ogg_sync_wrote(&oy,20);
  96620. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96621. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96622. 5);
  96623. ogg_sync_wrote(&oy,5);
  96624. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96625. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96626. og[1].header_len-28);
  96627. ogg_sync_wrote(&oy,og[1].header_len-28);
  96628. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96629. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96630. ogg_sync_wrote(&oy,1000);
  96631. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96632. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96633. og[1].body_len-1000);
  96634. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96635. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96636. fprintf(stderr,"ok.\n");
  96637. }
  96638. {
  96639. ogg_page og_de;
  96640. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96641. ogg_sync_reset(&oy);
  96642. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96643. og[1].header_len);
  96644. ogg_sync_wrote(&oy,og[1].header_len);
  96645. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96646. og[1].body_len);
  96647. ogg_sync_wrote(&oy,og[1].body_len);
  96648. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96649. 20);
  96650. ogg_sync_wrote(&oy,20);
  96651. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96652. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96653. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96654. og[1].header_len-20);
  96655. ogg_sync_wrote(&oy,og[1].header_len-20);
  96656. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96657. og[1].body_len);
  96658. ogg_sync_wrote(&oy,og[1].body_len);
  96659. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96660. fprintf(stderr,"ok.\n");
  96661. }
  96662. {
  96663. ogg_page og_de;
  96664. fprintf(stderr,"Testing search for capture... ");
  96665. ogg_sync_reset(&oy);
  96666. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96667. og[1].body_len);
  96668. ogg_sync_wrote(&oy,og[1].body_len);
  96669. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96670. og[1].header_len);
  96671. ogg_sync_wrote(&oy,og[1].header_len);
  96672. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96673. og[1].body_len);
  96674. ogg_sync_wrote(&oy,og[1].body_len);
  96675. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96676. 20);
  96677. ogg_sync_wrote(&oy,20);
  96678. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96679. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96680. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96681. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96682. og[2].header_len-20);
  96683. ogg_sync_wrote(&oy,og[2].header_len-20);
  96684. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96685. og[2].body_len);
  96686. ogg_sync_wrote(&oy,og[2].body_len);
  96687. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96688. fprintf(stderr,"ok.\n");
  96689. }
  96690. {
  96691. ogg_page og_de;
  96692. fprintf(stderr,"Testing recapture... ");
  96693. ogg_sync_reset(&oy);
  96694. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96695. og[1].header_len);
  96696. ogg_sync_wrote(&oy,og[1].header_len);
  96697. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96698. og[1].body_len);
  96699. ogg_sync_wrote(&oy,og[1].body_len);
  96700. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96701. og[2].header_len);
  96702. ogg_sync_wrote(&oy,og[2].header_len);
  96703. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96704. og[2].header_len);
  96705. ogg_sync_wrote(&oy,og[2].header_len);
  96706. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96707. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96708. og[2].body_len-5);
  96709. ogg_sync_wrote(&oy,og[2].body_len-5);
  96710. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96711. og[3].header_len);
  96712. ogg_sync_wrote(&oy,og[3].header_len);
  96713. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96714. og[3].body_len);
  96715. ogg_sync_wrote(&oy,og[3].body_len);
  96716. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96717. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96718. fprintf(stderr,"ok.\n");
  96719. }
  96720. {
  96721. for(i=0;i<5;i++){
  96722. free_page(&og[i]);
  96723. }
  96724. }
  96725. }
  96726. return(0);
  96727. }
  96728. #endif
  96729. #endif
  96730. /*** End of inlined file: framing.c ***/
  96731. /*** Start of inlined file: analysis.c ***/
  96732. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96733. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96734. // tasks..
  96735. #if JUCE_MSVC
  96736. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96737. #endif
  96738. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96739. #if JUCE_USE_OGGVORBIS
  96740. #include <stdio.h>
  96741. #include <string.h>
  96742. #include <math.h>
  96743. /*** Start of inlined file: codec_internal.h ***/
  96744. #ifndef _V_CODECI_H_
  96745. #define _V_CODECI_H_
  96746. /*** Start of inlined file: envelope.h ***/
  96747. #ifndef _V_ENVELOPE_
  96748. #define _V_ENVELOPE_
  96749. /*** Start of inlined file: mdct.h ***/
  96750. #ifndef _OGG_mdct_H_
  96751. #define _OGG_mdct_H_
  96752. #ifdef MDCT_INTEGERIZED
  96753. #define DATA_TYPE int
  96754. #define REG_TYPE register int
  96755. #define TRIGBITS 14
  96756. #define cPI3_8 6270
  96757. #define cPI2_8 11585
  96758. #define cPI1_8 15137
  96759. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96760. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96761. #define HALVE(x) ((x)>>1)
  96762. #else
  96763. #define DATA_TYPE float
  96764. #define REG_TYPE float
  96765. #define cPI3_8 .38268343236508977175F
  96766. #define cPI2_8 .70710678118654752441F
  96767. #define cPI1_8 .92387953251128675613F
  96768. #define FLOAT_CONV(x) (x)
  96769. #define MULT_NORM(x) (x)
  96770. #define HALVE(x) ((x)*.5f)
  96771. #endif
  96772. typedef struct {
  96773. int n;
  96774. int log2n;
  96775. DATA_TYPE *trig;
  96776. int *bitrev;
  96777. DATA_TYPE scale;
  96778. } mdct_lookup;
  96779. extern void mdct_init(mdct_lookup *lookup,int n);
  96780. extern void mdct_clear(mdct_lookup *l);
  96781. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96782. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96783. #endif
  96784. /*** End of inlined file: mdct.h ***/
  96785. #define VE_PRE 16
  96786. #define VE_WIN 4
  96787. #define VE_POST 2
  96788. #define VE_AMP (VE_PRE+VE_POST-1)
  96789. #define VE_BANDS 7
  96790. #define VE_NEARDC 15
  96791. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96792. #define VE_MAXSTRETCH 12 /* one-third full block */
  96793. typedef struct {
  96794. float ampbuf[VE_AMP];
  96795. int ampptr;
  96796. float nearDC[VE_NEARDC];
  96797. float nearDC_acc;
  96798. float nearDC_partialacc;
  96799. int nearptr;
  96800. } envelope_filter_state;
  96801. typedef struct {
  96802. int begin;
  96803. int end;
  96804. float *window;
  96805. float total;
  96806. } envelope_band;
  96807. typedef struct {
  96808. int ch;
  96809. int winlength;
  96810. int searchstep;
  96811. float minenergy;
  96812. mdct_lookup mdct;
  96813. float *mdct_win;
  96814. envelope_band band[VE_BANDS];
  96815. envelope_filter_state *filter;
  96816. int stretch;
  96817. int *mark;
  96818. long storage;
  96819. long current;
  96820. long curmark;
  96821. long cursor;
  96822. } envelope_lookup;
  96823. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96824. extern void _ve_envelope_clear(envelope_lookup *e);
  96825. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96826. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96827. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96828. #endif
  96829. /*** End of inlined file: envelope.h ***/
  96830. /*** Start of inlined file: codebook.h ***/
  96831. #ifndef _V_CODEBOOK_H_
  96832. #define _V_CODEBOOK_H_
  96833. typedef struct static_codebook{
  96834. long dim; /* codebook dimensions (elements per vector) */
  96835. long entries; /* codebook entries */
  96836. long *lengthlist; /* codeword lengths in bits */
  96837. int maptype; /* 0=none
  96838. 1=implicitly populated values from map column
  96839. 2=listed arbitrary values */
  96840. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96841. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96842. int q_quant; /* bits: 0 < quant <= 16 */
  96843. int q_sequencep; /* bitflag */
  96844. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96845. map == 2: list of dim*entries quantized entry vals
  96846. */
  96847. struct encode_aux_nearestmatch *nearest_tree;
  96848. struct encode_aux_threshmatch *thresh_tree;
  96849. struct encode_aux_pigeonhole *pigeon_tree;
  96850. int allocedp;
  96851. } static_codebook;
  96852. typedef struct encode_aux_nearestmatch{
  96853. long *ptr0;
  96854. long *ptr1;
  96855. long *p; /* decision points (each is an entry) */
  96856. long *q; /* decision points (each is an entry) */
  96857. long aux; /* number of tree entries */
  96858. long alloc;
  96859. } encode_aux_nearestmatch;
  96860. typedef struct encode_aux_threshmatch{
  96861. float *quantthresh;
  96862. long *quantmap;
  96863. int quantvals;
  96864. int threshvals;
  96865. } encode_aux_threshmatch;
  96866. typedef struct encode_aux_pigeonhole{
  96867. float min;
  96868. float del;
  96869. int mapentries;
  96870. int quantvals;
  96871. long *pigeonmap;
  96872. long fittotal;
  96873. long *fitlist;
  96874. long *fitmap;
  96875. long *fitlength;
  96876. } encode_aux_pigeonhole;
  96877. typedef struct codebook{
  96878. long dim; /* codebook dimensions (elements per vector) */
  96879. long entries; /* codebook entries */
  96880. long used_entries; /* populated codebook entries */
  96881. const static_codebook *c;
  96882. float *valuelist; /* list of dim*entries actual entry values */
  96883. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96884. int *dec_index; /* only used if sparseness collapsed */
  96885. char *dec_codelengths;
  96886. ogg_uint32_t *dec_firsttable;
  96887. int dec_firsttablen;
  96888. int dec_maxlength;
  96889. } codebook;
  96890. extern void vorbis_staticbook_clear(static_codebook *b);
  96891. extern void vorbis_staticbook_destroy(static_codebook *b);
  96892. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96893. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96894. extern void vorbis_book_clear(codebook *b);
  96895. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96896. extern float *_book_logdist(const static_codebook *b,float *vals);
  96897. extern float _float32_unpack(long val);
  96898. extern long _float32_pack(float val);
  96899. extern int _best(codebook *book, float *a, int step);
  96900. extern int _ilog(unsigned int v);
  96901. extern long _book_maptype1_quantvals(const static_codebook *b);
  96902. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96903. extern long vorbis_book_codeword(codebook *book,int entry);
  96904. extern long vorbis_book_codelen(codebook *book,int entry);
  96905. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96906. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96907. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96908. extern int vorbis_book_errorv(codebook *book, float *a);
  96909. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96910. oggpack_buffer *b);
  96911. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96912. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96913. oggpack_buffer *b,int n);
  96914. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96915. oggpack_buffer *b,int n);
  96916. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96917. oggpack_buffer *b,int n);
  96918. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96919. long off,int ch,
  96920. oggpack_buffer *b,int n);
  96921. #endif
  96922. /*** End of inlined file: codebook.h ***/
  96923. #define BLOCKTYPE_IMPULSE 0
  96924. #define BLOCKTYPE_PADDING 1
  96925. #define BLOCKTYPE_TRANSITION 0
  96926. #define BLOCKTYPE_LONG 1
  96927. #define PACKETBLOBS 15
  96928. typedef struct vorbis_block_internal{
  96929. float **pcmdelay; /* this is a pointer into local storage */
  96930. float ampmax;
  96931. int blocktype;
  96932. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96933. blob [PACKETBLOBS/2] points to
  96934. the oggpack_buffer in the
  96935. main vorbis_block */
  96936. } vorbis_block_internal;
  96937. typedef void vorbis_look_floor;
  96938. typedef void vorbis_look_residue;
  96939. typedef void vorbis_look_transform;
  96940. typedef struct {
  96941. int blockflag;
  96942. int windowtype;
  96943. int transformtype;
  96944. int mapping;
  96945. } vorbis_info_mode;
  96946. typedef void vorbis_info_floor;
  96947. typedef void vorbis_info_residue;
  96948. typedef void vorbis_info_mapping;
  96949. /*** Start of inlined file: psy.h ***/
  96950. #ifndef _V_PSY_H_
  96951. #define _V_PSY_H_
  96952. /*** Start of inlined file: smallft.h ***/
  96953. #ifndef _V_SMFT_H_
  96954. #define _V_SMFT_H_
  96955. typedef struct {
  96956. int n;
  96957. float *trigcache;
  96958. int *splitcache;
  96959. } drft_lookup;
  96960. extern void drft_forward(drft_lookup *l,float *data);
  96961. extern void drft_backward(drft_lookup *l,float *data);
  96962. extern void drft_init(drft_lookup *l,int n);
  96963. extern void drft_clear(drft_lookup *l);
  96964. #endif
  96965. /*** End of inlined file: smallft.h ***/
  96966. /*** Start of inlined file: backends.h ***/
  96967. #ifndef _vorbis_backend_h_
  96968. #define _vorbis_backend_h_
  96969. typedef struct{
  96970. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  96971. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  96972. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  96973. void (*free_info) (vorbis_info_floor *);
  96974. void (*free_look) (vorbis_look_floor *);
  96975. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  96976. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  96977. void *buffer,float *);
  96978. } vorbis_func_floor;
  96979. typedef struct{
  96980. int order;
  96981. long rate;
  96982. long barkmap;
  96983. int ampbits;
  96984. int ampdB;
  96985. int numbooks; /* <= 16 */
  96986. int books[16];
  96987. float lessthan; /* encode-only config setting hacks for libvorbis */
  96988. float greaterthan; /* encode-only config setting hacks for libvorbis */
  96989. } vorbis_info_floor0;
  96990. #define VIF_POSIT 63
  96991. #define VIF_CLASS 16
  96992. #define VIF_PARTS 31
  96993. typedef struct{
  96994. int partitions; /* 0 to 31 */
  96995. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  96996. int class_dim[VIF_CLASS]; /* 1 to 8 */
  96997. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  96998. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  96999. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  97000. int mult; /* 1 2 3 or 4 */
  97001. int postlist[VIF_POSIT+2]; /* first two implicit */
  97002. float maxover;
  97003. float maxunder;
  97004. float maxerr;
  97005. float twofitweight;
  97006. float twofitatten;
  97007. int n;
  97008. } vorbis_info_floor1;
  97009. typedef struct{
  97010. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  97011. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  97012. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  97013. vorbis_info_residue *);
  97014. void (*free_info) (vorbis_info_residue *);
  97015. void (*free_look) (vorbis_look_residue *);
  97016. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  97017. float **,int *,int);
  97018. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  97019. vorbis_look_residue *,
  97020. float **,float **,int *,int,long **);
  97021. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  97022. float **,int *,int);
  97023. } vorbis_func_residue;
  97024. typedef struct vorbis_info_residue0{
  97025. long begin;
  97026. long end;
  97027. int grouping; /* group n vectors per partition */
  97028. int partitions; /* possible codebooks for a partition */
  97029. int groupbook; /* huffbook for partitioning */
  97030. int secondstages[64]; /* expanded out to pointers in lookup */
  97031. int booklist[256]; /* list of second stage books */
  97032. float classmetric1[64];
  97033. float classmetric2[64];
  97034. } vorbis_info_residue0;
  97035. typedef struct{
  97036. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97037. oggpack_buffer *);
  97038. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97039. void (*free_info) (vorbis_info_mapping *);
  97040. int (*forward) (struct vorbis_block *vb);
  97041. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97042. } vorbis_func_mapping;
  97043. typedef struct vorbis_info_mapping0{
  97044. int submaps; /* <= 16 */
  97045. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97046. int floorsubmap[16]; /* [mux] submap to floors */
  97047. int residuesubmap[16]; /* [mux] submap to residue */
  97048. int coupling_steps;
  97049. int coupling_mag[256];
  97050. int coupling_ang[256];
  97051. } vorbis_info_mapping0;
  97052. #endif
  97053. /*** End of inlined file: backends.h ***/
  97054. #ifndef EHMER_MAX
  97055. #define EHMER_MAX 56
  97056. #endif
  97057. #define P_BANDS 17 /* 62Hz to 16kHz */
  97058. #define P_LEVELS 8 /* 30dB to 100dB */
  97059. #define P_LEVEL_0 30. /* 30 dB */
  97060. #define P_NOISECURVES 3
  97061. #define NOISE_COMPAND_LEVELS 40
  97062. typedef struct vorbis_info_psy{
  97063. int blockflag;
  97064. float ath_adjatt;
  97065. float ath_maxatt;
  97066. float tone_masteratt[P_NOISECURVES];
  97067. float tone_centerboost;
  97068. float tone_decay;
  97069. float tone_abs_limit;
  97070. float toneatt[P_BANDS];
  97071. int noisemaskp;
  97072. float noisemaxsupp;
  97073. float noisewindowlo;
  97074. float noisewindowhi;
  97075. int noisewindowlomin;
  97076. int noisewindowhimin;
  97077. int noisewindowfixed;
  97078. float noiseoff[P_NOISECURVES][P_BANDS];
  97079. float noisecompand[NOISE_COMPAND_LEVELS];
  97080. float max_curve_dB;
  97081. int normal_channel_p;
  97082. int normal_point_p;
  97083. int normal_start;
  97084. int normal_partition;
  97085. double normal_thresh;
  97086. } vorbis_info_psy;
  97087. typedef struct{
  97088. int eighth_octave_lines;
  97089. float preecho_thresh[VE_BANDS];
  97090. float postecho_thresh[VE_BANDS];
  97091. float stretch_penalty;
  97092. float preecho_minenergy;
  97093. float ampmax_att_per_sec;
  97094. int coupling_pkHz[PACKETBLOBS];
  97095. int coupling_pointlimit[2][PACKETBLOBS];
  97096. int coupling_prepointamp[PACKETBLOBS];
  97097. int coupling_postpointamp[PACKETBLOBS];
  97098. int sliding_lowpass[2][PACKETBLOBS];
  97099. } vorbis_info_psy_global;
  97100. typedef struct {
  97101. float ampmax;
  97102. int channels;
  97103. vorbis_info_psy_global *gi;
  97104. int coupling_pointlimit[2][P_NOISECURVES];
  97105. } vorbis_look_psy_global;
  97106. typedef struct {
  97107. int n;
  97108. struct vorbis_info_psy *vi;
  97109. float ***tonecurves;
  97110. float **noiseoffset;
  97111. float *ath;
  97112. long *octave; /* in n.ocshift format */
  97113. long *bark;
  97114. long firstoc;
  97115. long shiftoc;
  97116. int eighth_octave_lines; /* power of two, please */
  97117. int total_octave_lines;
  97118. long rate; /* cache it */
  97119. float m_val; /* Masking compensation value */
  97120. } vorbis_look_psy;
  97121. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97122. vorbis_info_psy_global *gi,int n,long rate);
  97123. extern void _vp_psy_clear(vorbis_look_psy *p);
  97124. extern void *_vi_psy_dup(void *source);
  97125. extern void _vi_psy_free(vorbis_info_psy *i);
  97126. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97127. extern void _vp_remove_floor(vorbis_look_psy *p,
  97128. float *mdct,
  97129. int *icodedflr,
  97130. float *residue,
  97131. int sliding_lowpass);
  97132. extern void _vp_noisemask(vorbis_look_psy *p,
  97133. float *logmdct,
  97134. float *logmask);
  97135. extern void _vp_tonemask(vorbis_look_psy *p,
  97136. float *logfft,
  97137. float *logmask,
  97138. float global_specmax,
  97139. float local_specmax);
  97140. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97141. float *noise,
  97142. float *tone,
  97143. int offset_select,
  97144. float *logmask,
  97145. float *mdct,
  97146. float *logmdct);
  97147. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97148. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97149. vorbis_info_psy_global *g,
  97150. vorbis_look_psy *p,
  97151. vorbis_info_mapping0 *vi,
  97152. float **mdct);
  97153. extern void _vp_couple(int blobno,
  97154. vorbis_info_psy_global *g,
  97155. vorbis_look_psy *p,
  97156. vorbis_info_mapping0 *vi,
  97157. float **res,
  97158. float **mag_memo,
  97159. int **mag_sort,
  97160. int **ifloor,
  97161. int *nonzero,
  97162. int sliding_lowpass);
  97163. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97164. float *in,float *out,int *sortedindex);
  97165. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97166. float *magnitudes,int *sortedindex);
  97167. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97168. vorbis_look_psy *p,
  97169. vorbis_info_mapping0 *vi,
  97170. float **mags);
  97171. extern void hf_reduction(vorbis_info_psy_global *g,
  97172. vorbis_look_psy *p,
  97173. vorbis_info_mapping0 *vi,
  97174. float **mdct);
  97175. #endif
  97176. /*** End of inlined file: psy.h ***/
  97177. /*** Start of inlined file: bitrate.h ***/
  97178. #ifndef _V_BITRATE_H_
  97179. #define _V_BITRATE_H_
  97180. /*** Start of inlined file: os.h ***/
  97181. #ifndef _OS_H
  97182. #define _OS_H
  97183. #ifdef HAVE_CONFIG_H
  97184. #include "config.h"
  97185. #endif
  97186. #include <math.h>
  97187. /*** Start of inlined file: misc.h ***/
  97188. #ifndef _V_RANDOM_H_
  97189. #define _V_RANDOM_H_
  97190. extern int analysis_noisy;
  97191. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97192. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97193. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97194. ogg_int64_t off);
  97195. #ifdef DEBUG_MALLOC
  97196. #define _VDBG_GRAPHFILE "malloc.m"
  97197. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97198. extern void _VDBG_free(void *ptr,char *file,long line);
  97199. #ifndef MISC_C
  97200. #undef _ogg_malloc
  97201. #undef _ogg_calloc
  97202. #undef _ogg_realloc
  97203. #undef _ogg_free
  97204. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97205. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97206. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97207. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97208. #endif
  97209. #endif
  97210. #endif
  97211. /*** End of inlined file: misc.h ***/
  97212. #ifndef _V_IFDEFJAIL_H_
  97213. # define _V_IFDEFJAIL_H_
  97214. # ifdef __GNUC__
  97215. # define STIN static __inline__
  97216. # elif _WIN32
  97217. # define STIN static __inline
  97218. # else
  97219. # define STIN static
  97220. # endif
  97221. #ifdef DJGPP
  97222. # define rint(x) (floor((x)+0.5f))
  97223. #endif
  97224. #ifndef M_PI
  97225. # define M_PI (3.1415926536f)
  97226. #endif
  97227. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97228. # include <malloc.h>
  97229. # define rint(x) (floor((x)+0.5f))
  97230. # define NO_FLOAT_MATH_LIB
  97231. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97232. #endif
  97233. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97234. void *_alloca(size_t size);
  97235. # define alloca _alloca
  97236. #endif
  97237. #ifndef FAST_HYPOT
  97238. # define FAST_HYPOT hypot
  97239. #endif
  97240. #endif
  97241. #ifdef HAVE_ALLOCA_H
  97242. # include <alloca.h>
  97243. #endif
  97244. #ifdef USE_MEMORY_H
  97245. # include <memory.h>
  97246. #endif
  97247. #ifndef min
  97248. # define min(x,y) ((x)>(y)?(y):(x))
  97249. #endif
  97250. #ifndef max
  97251. # define max(x,y) ((x)<(y)?(y):(x))
  97252. #endif
  97253. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97254. # define VORBIS_FPU_CONTROL
  97255. typedef ogg_int16_t vorbis_fpu_control;
  97256. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97257. ogg_int16_t ret;
  97258. ogg_int16_t temp;
  97259. __asm__ __volatile__("fnstcw %0\n\t"
  97260. "movw %0,%%dx\n\t"
  97261. "orw $62463,%%dx\n\t"
  97262. "movw %%dx,%1\n\t"
  97263. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97264. *fpu=ret;
  97265. }
  97266. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97267. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97268. }
  97269. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97270. we get extra fst/fld to
  97271. truncate precision */
  97272. int i;
  97273. __asm__("fistl %0": "=m"(i) : "t"(f));
  97274. return(i);
  97275. }
  97276. #endif
  97277. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97278. # define VORBIS_FPU_CONTROL
  97279. typedef ogg_int16_t vorbis_fpu_control;
  97280. static __inline int vorbis_ftoi(double f){
  97281. int i;
  97282. __asm{
  97283. fld f
  97284. fistp i
  97285. }
  97286. return i;
  97287. }
  97288. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97289. }
  97290. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97291. }
  97292. #endif
  97293. #ifndef VORBIS_FPU_CONTROL
  97294. typedef int vorbis_fpu_control;
  97295. static int vorbis_ftoi(double f){
  97296. return (int)(f+.5);
  97297. }
  97298. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97299. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97300. #endif
  97301. #endif /* _OS_H */
  97302. /*** End of inlined file: os.h ***/
  97303. typedef struct bitrate_manager_state {
  97304. int managed;
  97305. long avg_reservoir;
  97306. long minmax_reservoir;
  97307. long avg_bitsper;
  97308. long min_bitsper;
  97309. long max_bitsper;
  97310. long short_per_long;
  97311. double avgfloat;
  97312. vorbis_block *vb;
  97313. int choice;
  97314. } bitrate_manager_state;
  97315. typedef struct bitrate_manager_info{
  97316. long avg_rate;
  97317. long min_rate;
  97318. long max_rate;
  97319. long reservoir_bits;
  97320. double reservoir_bias;
  97321. double slew_damp;
  97322. } bitrate_manager_info;
  97323. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97324. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97325. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97326. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97327. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97328. #endif
  97329. /*** End of inlined file: bitrate.h ***/
  97330. static int ilog(unsigned int v){
  97331. int ret=0;
  97332. while(v){
  97333. ret++;
  97334. v>>=1;
  97335. }
  97336. return(ret);
  97337. }
  97338. static int ilog2(unsigned int v){
  97339. int ret=0;
  97340. if(v)--v;
  97341. while(v){
  97342. ret++;
  97343. v>>=1;
  97344. }
  97345. return(ret);
  97346. }
  97347. typedef struct private_state {
  97348. envelope_lookup *ve; /* envelope lookup */
  97349. int window[2];
  97350. vorbis_look_transform **transform[2]; /* block, type */
  97351. drft_lookup fft_look[2];
  97352. int modebits;
  97353. vorbis_look_floor **flr;
  97354. vorbis_look_residue **residue;
  97355. vorbis_look_psy *psy;
  97356. vorbis_look_psy_global *psy_g_look;
  97357. unsigned char *header;
  97358. unsigned char *header1;
  97359. unsigned char *header2;
  97360. bitrate_manager_state bms;
  97361. ogg_int64_t sample_count;
  97362. } private_state;
  97363. /*** Start of inlined file: highlevel.h ***/
  97364. typedef struct highlevel_byblocktype {
  97365. double tone_mask_setting;
  97366. double tone_peaklimit_setting;
  97367. double noise_bias_setting;
  97368. double noise_compand_setting;
  97369. } highlevel_byblocktype;
  97370. typedef struct highlevel_encode_setup {
  97371. void *setup;
  97372. int set_in_stone;
  97373. double base_setting;
  97374. double long_setting;
  97375. double short_setting;
  97376. double impulse_noisetune;
  97377. int managed;
  97378. long bitrate_min;
  97379. long bitrate_av;
  97380. double bitrate_av_damp;
  97381. long bitrate_max;
  97382. long bitrate_reservoir;
  97383. double bitrate_reservoir_bias;
  97384. int impulse_block_p;
  97385. int noise_normalize_p;
  97386. double stereo_point_setting;
  97387. double lowpass_kHz;
  97388. double ath_floating_dB;
  97389. double ath_absolute_dB;
  97390. double amplitude_track_dBpersec;
  97391. double trigger_setting;
  97392. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97393. } highlevel_encode_setup;
  97394. /*** End of inlined file: highlevel.h ***/
  97395. typedef struct codec_setup_info {
  97396. long blocksizes[2];
  97397. int modes;
  97398. int maps;
  97399. int floors;
  97400. int residues;
  97401. int books;
  97402. int psys; /* encode only */
  97403. vorbis_info_mode *mode_param[64];
  97404. int map_type[64];
  97405. vorbis_info_mapping *map_param[64];
  97406. int floor_type[64];
  97407. vorbis_info_floor *floor_param[64];
  97408. int residue_type[64];
  97409. vorbis_info_residue *residue_param[64];
  97410. static_codebook *book_param[256];
  97411. codebook *fullbooks;
  97412. vorbis_info_psy *psy_param[4]; /* encode only */
  97413. vorbis_info_psy_global psy_g_param;
  97414. bitrate_manager_info bi;
  97415. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97416. highly redundant structure, but
  97417. improves clarity of program flow. */
  97418. int halfrate_flag; /* painless downsample for decode */
  97419. } codec_setup_info;
  97420. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97421. extern void _vp_global_free(vorbis_look_psy_global *look);
  97422. #endif
  97423. /*** End of inlined file: codec_internal.h ***/
  97424. /*** Start of inlined file: registry.h ***/
  97425. #ifndef _V_REG_H_
  97426. #define _V_REG_H_
  97427. #define VI_TRANSFORMB 1
  97428. #define VI_WINDOWB 1
  97429. #define VI_TIMEB 1
  97430. #define VI_FLOORB 2
  97431. #define VI_RESB 3
  97432. #define VI_MAPB 1
  97433. extern vorbis_func_floor *_floor_P[];
  97434. extern vorbis_func_residue *_residue_P[];
  97435. extern vorbis_func_mapping *_mapping_P[];
  97436. #endif
  97437. /*** End of inlined file: registry.h ***/
  97438. /*** Start of inlined file: scales.h ***/
  97439. #ifndef _V_SCALES_H_
  97440. #define _V_SCALES_H_
  97441. #include <math.h>
  97442. #define VORBIS_IEEE_FLOAT32 1
  97443. #ifdef VORBIS_IEEE_FLOAT32
  97444. static float unitnorm(float x){
  97445. union {
  97446. ogg_uint32_t i;
  97447. float f;
  97448. } ix;
  97449. ix.f = x;
  97450. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97451. return ix.f;
  97452. }
  97453. static float todB(const float *x){
  97454. union {
  97455. ogg_uint32_t i;
  97456. float f;
  97457. } ix;
  97458. ix.f = *x;
  97459. ix.i = ix.i&0x7fffffff;
  97460. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97461. }
  97462. #define todB_nn(x) todB(x)
  97463. #else
  97464. static float unitnorm(float x){
  97465. if(x<0)return(-1.f);
  97466. return(1.f);
  97467. }
  97468. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97469. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97470. #endif
  97471. #define fromdB(x) (exp((x)*.11512925f))
  97472. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97473. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97474. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97475. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97476. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97477. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97478. #endif
  97479. /*** End of inlined file: scales.h ***/
  97480. int analysis_noisy=1;
  97481. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97482. int ret,i;
  97483. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97484. vb->glue_bits=0;
  97485. vb->time_bits=0;
  97486. vb->floor_bits=0;
  97487. vb->res_bits=0;
  97488. for(i=0;i<PACKETBLOBS;i++)
  97489. oggpack_reset(vbi->packetblob[i]);
  97490. if((ret=_mapping_P[0]->forward(vb)))
  97491. return(ret);
  97492. if(op){
  97493. if(vorbis_bitrate_managed(vb))
  97494. return(OV_EINVAL);
  97495. op->packet=oggpack_get_buffer(&vb->opb);
  97496. op->bytes=oggpack_bytes(&vb->opb);
  97497. op->b_o_s=0;
  97498. op->e_o_s=vb->eofflag;
  97499. op->granulepos=vb->granulepos;
  97500. op->packetno=vb->sequence; /* for sake of completeness */
  97501. }
  97502. return(0);
  97503. }
  97504. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97505. int j;
  97506. FILE *of;
  97507. char buffer[80];
  97508. sprintf(buffer,"%s_%d.m",base,i);
  97509. of=fopen(buffer,"w");
  97510. if(!of)perror("failed to open data dump file");
  97511. for(j=0;j<n;j++){
  97512. if(bark){
  97513. float b=toBARK((4000.f*j/n)+.25);
  97514. fprintf(of,"%f ",b);
  97515. }else
  97516. if(off!=0)
  97517. fprintf(of,"%f ",(double)(j+off)/8000.);
  97518. else
  97519. fprintf(of,"%f ",(double)j);
  97520. if(dB){
  97521. float val;
  97522. if(v[j]==0.)
  97523. val=-140.;
  97524. else
  97525. val=todB(v+j);
  97526. fprintf(of,"%f\n",val);
  97527. }else{
  97528. fprintf(of,"%f\n",v[j]);
  97529. }
  97530. }
  97531. fclose(of);
  97532. }
  97533. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97534. ogg_int64_t off){
  97535. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97536. }
  97537. #endif
  97538. /*** End of inlined file: analysis.c ***/
  97539. /*** Start of inlined file: bitrate.c ***/
  97540. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97541. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97542. // tasks..
  97543. #if JUCE_MSVC
  97544. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97545. #endif
  97546. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97547. #if JUCE_USE_OGGVORBIS
  97548. #include <stdlib.h>
  97549. #include <string.h>
  97550. #include <math.h>
  97551. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97552. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97553. bitrate_manager_info *bi=&ci->bi;
  97554. memset(bm,0,sizeof(*bm));
  97555. if(bi && (bi->reservoir_bits>0)){
  97556. long ratesamples=vi->rate;
  97557. int halfsamples=ci->blocksizes[0]>>1;
  97558. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97559. bm->managed=1;
  97560. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97561. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97562. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97563. bm->avgfloat=PACKETBLOBS/2;
  97564. {
  97565. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97566. bm->minmax_reservoir=desired_fill;
  97567. bm->avg_reservoir=desired_fill;
  97568. }
  97569. }
  97570. }
  97571. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97572. memset(bm,0,sizeof(*bm));
  97573. return;
  97574. }
  97575. int vorbis_bitrate_managed(vorbis_block *vb){
  97576. vorbis_dsp_state *vd=vb->vd;
  97577. private_state *b=(private_state*)vd->backend_state;
  97578. bitrate_manager_state *bm=&b->bms;
  97579. if(bm && bm->managed)return(1);
  97580. return(0);
  97581. }
  97582. int vorbis_bitrate_addblock(vorbis_block *vb){
  97583. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97584. vorbis_dsp_state *vd=vb->vd;
  97585. private_state *b=(private_state*)vd->backend_state;
  97586. bitrate_manager_state *bm=&b->bms;
  97587. vorbis_info *vi=vd->vi;
  97588. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97589. bitrate_manager_info *bi=&ci->bi;
  97590. int choice=rint(bm->avgfloat);
  97591. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97592. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97593. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97594. int samples=ci->blocksizes[vb->W]>>1;
  97595. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97596. if(!bm->managed){
  97597. if(bm->vb)return(-1); /* one has been submitted without
  97598. being claimed */
  97599. bm->vb=vb;
  97600. return(0);
  97601. }
  97602. bm->vb=vb;
  97603. if(bm->avg_bitsper>0){
  97604. double slew=0.;
  97605. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97606. double slewlimit= 15./bi->slew_damp;
  97607. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97608. while(choice>0 && this_bits>avg_target_bits &&
  97609. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97610. choice--;
  97611. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97612. }
  97613. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97614. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97615. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97616. choice++;
  97617. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97618. }
  97619. }
  97620. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97621. if(slew<-slewlimit)slew=-slewlimit;
  97622. if(slew>slewlimit)slew=slewlimit;
  97623. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97624. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97625. }
  97626. if(bm->min_bitsper>0){
  97627. if(this_bits<min_target_bits){
  97628. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97629. choice++;
  97630. if(choice>=PACKETBLOBS)break;
  97631. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97632. }
  97633. }
  97634. }
  97635. if(bm->max_bitsper>0){
  97636. if(this_bits>max_target_bits){
  97637. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97638. choice--;
  97639. if(choice<0)break;
  97640. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97641. }
  97642. }
  97643. }
  97644. if(choice<0){
  97645. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97646. bm->choice=choice=0;
  97647. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97648. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97649. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97650. }
  97651. }else{
  97652. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97653. if(choice>=PACKETBLOBS)
  97654. choice=PACKETBLOBS-1;
  97655. bm->choice=choice;
  97656. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97657. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97658. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97659. }
  97660. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97661. if(max_target_bits>0 && this_bits>max_target_bits){
  97662. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97663. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97664. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97665. }else{
  97666. if(bm->minmax_reservoir>desired_fill){
  97667. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97668. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97669. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97670. }else{
  97671. bm->minmax_reservoir=desired_fill;
  97672. }
  97673. }else{
  97674. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97675. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97676. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97677. }else{
  97678. bm->minmax_reservoir=desired_fill;
  97679. }
  97680. }
  97681. }
  97682. }
  97683. if(bm->avg_bitsper>0){
  97684. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97685. bm->avg_reservoir+=this_bits-avg_target_bits;
  97686. }
  97687. return(0);
  97688. }
  97689. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97690. private_state *b=(private_state*)vd->backend_state;
  97691. bitrate_manager_state *bm=&b->bms;
  97692. vorbis_block *vb=bm->vb;
  97693. int choice=PACKETBLOBS/2;
  97694. if(!vb)return 0;
  97695. if(op){
  97696. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97697. if(vorbis_bitrate_managed(vb))
  97698. choice=bm->choice;
  97699. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97700. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97701. op->b_o_s=0;
  97702. op->e_o_s=vb->eofflag;
  97703. op->granulepos=vb->granulepos;
  97704. op->packetno=vb->sequence; /* for sake of completeness */
  97705. }
  97706. bm->vb=0;
  97707. return(1);
  97708. }
  97709. #endif
  97710. /*** End of inlined file: bitrate.c ***/
  97711. /*** Start of inlined file: block.c ***/
  97712. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97713. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97714. // tasks..
  97715. #if JUCE_MSVC
  97716. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97717. #endif
  97718. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97719. #if JUCE_USE_OGGVORBIS
  97720. #include <stdio.h>
  97721. #include <stdlib.h>
  97722. #include <string.h>
  97723. /*** Start of inlined file: window.h ***/
  97724. #ifndef _V_WINDOW_
  97725. #define _V_WINDOW_
  97726. extern float *_vorbis_window_get(int n);
  97727. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97728. int lW,int W,int nW);
  97729. #endif
  97730. /*** End of inlined file: window.h ***/
  97731. /*** Start of inlined file: lpc.h ***/
  97732. #ifndef _V_LPC_H_
  97733. #define _V_LPC_H_
  97734. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97735. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97736. float *data,long n);
  97737. #endif
  97738. /*** End of inlined file: lpc.h ***/
  97739. #ifndef WORD_ALIGN
  97740. #define WORD_ALIGN 8
  97741. #endif
  97742. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97743. int i;
  97744. memset(vb,0,sizeof(*vb));
  97745. vb->vd=v;
  97746. vb->localalloc=0;
  97747. vb->localstore=NULL;
  97748. if(v->analysisp){
  97749. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97750. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97751. vbi->ampmax=-9999;
  97752. for(i=0;i<PACKETBLOBS;i++){
  97753. if(i==PACKETBLOBS/2){
  97754. vbi->packetblob[i]=&vb->opb;
  97755. }else{
  97756. vbi->packetblob[i]=
  97757. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97758. }
  97759. oggpack_writeinit(vbi->packetblob[i]);
  97760. }
  97761. }
  97762. return(0);
  97763. }
  97764. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97765. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97766. if(bytes+vb->localtop>vb->localalloc){
  97767. if(vb->localstore){
  97768. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97769. vb->totaluse+=vb->localtop;
  97770. link->next=vb->reap;
  97771. link->ptr=vb->localstore;
  97772. vb->reap=link;
  97773. }
  97774. vb->localalloc=bytes;
  97775. vb->localstore=_ogg_malloc(vb->localalloc);
  97776. vb->localtop=0;
  97777. }
  97778. {
  97779. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97780. vb->localtop+=bytes;
  97781. return ret;
  97782. }
  97783. }
  97784. void _vorbis_block_ripcord(vorbis_block *vb){
  97785. struct alloc_chain *reap=vb->reap;
  97786. while(reap){
  97787. struct alloc_chain *next=reap->next;
  97788. _ogg_free(reap->ptr);
  97789. memset(reap,0,sizeof(*reap));
  97790. _ogg_free(reap);
  97791. reap=next;
  97792. }
  97793. if(vb->totaluse){
  97794. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97795. vb->localalloc+=vb->totaluse;
  97796. vb->totaluse=0;
  97797. }
  97798. vb->localtop=0;
  97799. vb->reap=NULL;
  97800. }
  97801. int vorbis_block_clear(vorbis_block *vb){
  97802. int i;
  97803. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97804. _vorbis_block_ripcord(vb);
  97805. if(vb->localstore)_ogg_free(vb->localstore);
  97806. if(vbi){
  97807. for(i=0;i<PACKETBLOBS;i++){
  97808. oggpack_writeclear(vbi->packetblob[i]);
  97809. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97810. }
  97811. _ogg_free(vbi);
  97812. }
  97813. memset(vb,0,sizeof(*vb));
  97814. return(0);
  97815. }
  97816. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97817. int i;
  97818. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97819. private_state *b=NULL;
  97820. int hs;
  97821. if(ci==NULL) return 1;
  97822. hs=ci->halfrate_flag;
  97823. memset(v,0,sizeof(*v));
  97824. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97825. v->vi=vi;
  97826. b->modebits=ilog2(ci->modes);
  97827. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97828. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97829. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97830. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97831. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97832. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97833. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97834. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97835. if(encp){ /* encode/decode differ here */
  97836. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97837. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97838. if(!ci->fullbooks){
  97839. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97840. for(i=0;i<ci->books;i++)
  97841. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97842. }
  97843. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97844. for(i=0;i<ci->psys;i++){
  97845. _vp_psy_init(b->psy+i,
  97846. ci->psy_param[i],
  97847. &ci->psy_g_param,
  97848. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97849. vi->rate);
  97850. }
  97851. v->analysisp=1;
  97852. }else{
  97853. if(!ci->fullbooks){
  97854. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97855. for(i=0;i<ci->books;i++){
  97856. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97857. vorbis_staticbook_destroy(ci->book_param[i]);
  97858. ci->book_param[i]=NULL;
  97859. }
  97860. }
  97861. }
  97862. v->pcm_storage=ci->blocksizes[1];
  97863. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97864. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97865. {
  97866. int i;
  97867. for(i=0;i<vi->channels;i++)
  97868. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97869. }
  97870. v->lW=0; /* previous window size */
  97871. v->W=0; /* current window size */
  97872. v->centerW=ci->blocksizes[1]/2;
  97873. v->pcm_current=v->centerW;
  97874. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97875. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97876. for(i=0;i<ci->floors;i++)
  97877. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97878. look(v,ci->floor_param[i]);
  97879. for(i=0;i<ci->residues;i++)
  97880. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97881. look(v,ci->residue_param[i]);
  97882. return 0;
  97883. }
  97884. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97885. private_state *b=NULL;
  97886. if(_vds_shared_init(v,vi,1))return 1;
  97887. b=(private_state*)v->backend_state;
  97888. b->psy_g_look=_vp_global_look(vi);
  97889. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97890. _ve_envelope_init(b->ve,vi);
  97891. vorbis_bitrate_init(vi,&b->bms);
  97892. v->sequence=3;
  97893. return(0);
  97894. }
  97895. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97896. int i;
  97897. if(v){
  97898. vorbis_info *vi=v->vi;
  97899. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97900. private_state *b=(private_state*)v->backend_state;
  97901. if(b){
  97902. if(b->ve){
  97903. _ve_envelope_clear(b->ve);
  97904. _ogg_free(b->ve);
  97905. }
  97906. if(b->transform[0]){
  97907. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97908. _ogg_free(b->transform[0][0]);
  97909. _ogg_free(b->transform[0]);
  97910. }
  97911. if(b->transform[1]){
  97912. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97913. _ogg_free(b->transform[1][0]);
  97914. _ogg_free(b->transform[1]);
  97915. }
  97916. if(b->flr){
  97917. for(i=0;i<ci->floors;i++)
  97918. _floor_P[ci->floor_type[i]]->
  97919. free_look(b->flr[i]);
  97920. _ogg_free(b->flr);
  97921. }
  97922. if(b->residue){
  97923. for(i=0;i<ci->residues;i++)
  97924. _residue_P[ci->residue_type[i]]->
  97925. free_look(b->residue[i]);
  97926. _ogg_free(b->residue);
  97927. }
  97928. if(b->psy){
  97929. for(i=0;i<ci->psys;i++)
  97930. _vp_psy_clear(b->psy+i);
  97931. _ogg_free(b->psy);
  97932. }
  97933. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97934. vorbis_bitrate_clear(&b->bms);
  97935. drft_clear(&b->fft_look[0]);
  97936. drft_clear(&b->fft_look[1]);
  97937. }
  97938. if(v->pcm){
  97939. for(i=0;i<vi->channels;i++)
  97940. if(v->pcm[i])_ogg_free(v->pcm[i]);
  97941. _ogg_free(v->pcm);
  97942. if(v->pcmret)_ogg_free(v->pcmret);
  97943. }
  97944. if(b){
  97945. if(b->header)_ogg_free(b->header);
  97946. if(b->header1)_ogg_free(b->header1);
  97947. if(b->header2)_ogg_free(b->header2);
  97948. _ogg_free(b);
  97949. }
  97950. memset(v,0,sizeof(*v));
  97951. }
  97952. }
  97953. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  97954. int i;
  97955. vorbis_info *vi=v->vi;
  97956. private_state *b=(private_state*)v->backend_state;
  97957. if(b->header)_ogg_free(b->header);b->header=NULL;
  97958. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  97959. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  97960. if(v->pcm_current+vals>=v->pcm_storage){
  97961. v->pcm_storage=v->pcm_current+vals*2;
  97962. for(i=0;i<vi->channels;i++){
  97963. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  97964. }
  97965. }
  97966. for(i=0;i<vi->channels;i++)
  97967. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  97968. return(v->pcmret);
  97969. }
  97970. static void _preextrapolate_helper(vorbis_dsp_state *v){
  97971. int i;
  97972. int order=32;
  97973. float *lpc=(float*)alloca(order*sizeof(*lpc));
  97974. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  97975. long j;
  97976. v->preextrapolate=1;
  97977. if(v->pcm_current-v->centerW>order*2){ /* safety */
  97978. for(i=0;i<v->vi->channels;i++){
  97979. for(j=0;j<v->pcm_current;j++)
  97980. work[j]=v->pcm[i][v->pcm_current-j-1];
  97981. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  97982. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  97983. order,
  97984. work+v->pcm_current-v->centerW,
  97985. v->centerW);
  97986. for(j=0;j<v->pcm_current;j++)
  97987. v->pcm[i][v->pcm_current-j-1]=work[j];
  97988. }
  97989. }
  97990. }
  97991. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  97992. vorbis_info *vi=v->vi;
  97993. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97994. if(vals<=0){
  97995. int order=32;
  97996. int i;
  97997. float *lpc=(float*) alloca(order*sizeof(*lpc));
  97998. if(!v->preextrapolate)
  97999. _preextrapolate_helper(v);
  98000. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  98001. v->eofflag=v->pcm_current;
  98002. v->pcm_current+=ci->blocksizes[1]*3;
  98003. for(i=0;i<vi->channels;i++){
  98004. if(v->eofflag>order*2){
  98005. long n;
  98006. n=v->eofflag;
  98007. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  98008. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  98009. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  98010. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  98011. }else{
  98012. memset(v->pcm[i]+v->eofflag,0,
  98013. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  98014. }
  98015. }
  98016. }else{
  98017. if(v->pcm_current+vals>v->pcm_storage)
  98018. return(OV_EINVAL);
  98019. v->pcm_current+=vals;
  98020. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  98021. _preextrapolate_helper(v);
  98022. }
  98023. return(0);
  98024. }
  98025. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98026. int i;
  98027. vorbis_info *vi=v->vi;
  98028. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98029. private_state *b=(private_state*)v->backend_state;
  98030. vorbis_look_psy_global *g=b->psy_g_look;
  98031. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98032. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98033. if(!v->preextrapolate)return(0);
  98034. if(v->eofflag==-1)return(0);
  98035. {
  98036. long bp=_ve_envelope_search(v);
  98037. if(bp==-1){
  98038. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98039. full long block */
  98040. v->nW=0;
  98041. }else{
  98042. if(ci->blocksizes[0]==ci->blocksizes[1])
  98043. v->nW=0;
  98044. else
  98045. v->nW=bp;
  98046. }
  98047. }
  98048. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98049. {
  98050. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98051. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98052. although this check is
  98053. less strict that the
  98054. _ve_envelope_search,
  98055. the search is not run
  98056. if we only use one
  98057. block size */
  98058. }
  98059. _vorbis_block_ripcord(vb);
  98060. vb->lW=v->lW;
  98061. vb->W=v->W;
  98062. vb->nW=v->nW;
  98063. if(v->W){
  98064. if(!v->lW || !v->nW){
  98065. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98066. }else{
  98067. vbi->blocktype=BLOCKTYPE_LONG;
  98068. }
  98069. }else{
  98070. if(_ve_envelope_mark(v)){
  98071. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98072. }else{
  98073. vbi->blocktype=BLOCKTYPE_PADDING;
  98074. }
  98075. }
  98076. vb->vd=v;
  98077. vb->sequence=v->sequence++;
  98078. vb->granulepos=v->granulepos;
  98079. vb->pcmend=ci->blocksizes[v->W];
  98080. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98081. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98082. vbi->ampmax=g->ampmax;
  98083. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98084. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98085. for(i=0;i<vi->channels;i++){
  98086. vbi->pcmdelay[i]=
  98087. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98088. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98089. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98090. }
  98091. if(v->eofflag){
  98092. if(v->centerW>=v->eofflag){
  98093. v->eofflag=-1;
  98094. vb->eofflag=1;
  98095. return(1);
  98096. }
  98097. }
  98098. {
  98099. int new_centerNext=ci->blocksizes[1]/2;
  98100. int movementW=centerNext-new_centerNext;
  98101. if(movementW>0){
  98102. _ve_envelope_shift(b->ve,movementW);
  98103. v->pcm_current-=movementW;
  98104. for(i=0;i<vi->channels;i++)
  98105. memmove(v->pcm[i],v->pcm[i]+movementW,
  98106. v->pcm_current*sizeof(*v->pcm[i]));
  98107. v->lW=v->W;
  98108. v->W=v->nW;
  98109. v->centerW=new_centerNext;
  98110. if(v->eofflag){
  98111. v->eofflag-=movementW;
  98112. if(v->eofflag<=0)v->eofflag=-1;
  98113. if(v->centerW>=v->eofflag){
  98114. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98115. }else{
  98116. v->granulepos+=movementW;
  98117. }
  98118. }else{
  98119. v->granulepos+=movementW;
  98120. }
  98121. }
  98122. }
  98123. return(1);
  98124. }
  98125. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98126. vorbis_info *vi=v->vi;
  98127. codec_setup_info *ci;
  98128. int hs;
  98129. if(!v->backend_state)return -1;
  98130. if(!vi)return -1;
  98131. ci=(codec_setup_info*) vi->codec_setup;
  98132. if(!ci)return -1;
  98133. hs=ci->halfrate_flag;
  98134. v->centerW=ci->blocksizes[1]>>(hs+1);
  98135. v->pcm_current=v->centerW>>hs;
  98136. v->pcm_returned=-1;
  98137. v->granulepos=-1;
  98138. v->sequence=-1;
  98139. v->eofflag=0;
  98140. ((private_state *)(v->backend_state))->sample_count=-1;
  98141. return(0);
  98142. }
  98143. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98144. if(_vds_shared_init(v,vi,0)) return 1;
  98145. vorbis_synthesis_restart(v);
  98146. return 0;
  98147. }
  98148. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98149. vorbis_info *vi=v->vi;
  98150. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98151. private_state *b=(private_state*)v->backend_state;
  98152. int hs=ci->halfrate_flag;
  98153. int i,j;
  98154. if(!vb)return(OV_EINVAL);
  98155. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98156. v->lW=v->W;
  98157. v->W=vb->W;
  98158. v->nW=-1;
  98159. if((v->sequence==-1)||
  98160. (v->sequence+1 != vb->sequence)){
  98161. v->granulepos=-1; /* out of sequence; lose count */
  98162. b->sample_count=-1;
  98163. }
  98164. v->sequence=vb->sequence;
  98165. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98166. was called on block */
  98167. int n=ci->blocksizes[v->W]>>(hs+1);
  98168. int n0=ci->blocksizes[0]>>(hs+1);
  98169. int n1=ci->blocksizes[1]>>(hs+1);
  98170. int thisCenter;
  98171. int prevCenter;
  98172. v->glue_bits+=vb->glue_bits;
  98173. v->time_bits+=vb->time_bits;
  98174. v->floor_bits+=vb->floor_bits;
  98175. v->res_bits+=vb->res_bits;
  98176. if(v->centerW){
  98177. thisCenter=n1;
  98178. prevCenter=0;
  98179. }else{
  98180. thisCenter=0;
  98181. prevCenter=n1;
  98182. }
  98183. for(j=0;j<vi->channels;j++){
  98184. if(v->lW){
  98185. if(v->W){
  98186. float *w=_vorbis_window_get(b->window[1]-hs);
  98187. float *pcm=v->pcm[j]+prevCenter;
  98188. float *p=vb->pcm[j];
  98189. for(i=0;i<n1;i++)
  98190. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98191. }else{
  98192. float *w=_vorbis_window_get(b->window[0]-hs);
  98193. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98194. float *p=vb->pcm[j];
  98195. for(i=0;i<n0;i++)
  98196. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98197. }
  98198. }else{
  98199. if(v->W){
  98200. float *w=_vorbis_window_get(b->window[0]-hs);
  98201. float *pcm=v->pcm[j]+prevCenter;
  98202. float *p=vb->pcm[j]+n1/2-n0/2;
  98203. for(i=0;i<n0;i++)
  98204. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98205. for(;i<n1/2+n0/2;i++)
  98206. pcm[i]=p[i];
  98207. }else{
  98208. float *w=_vorbis_window_get(b->window[0]-hs);
  98209. float *pcm=v->pcm[j]+prevCenter;
  98210. float *p=vb->pcm[j];
  98211. for(i=0;i<n0;i++)
  98212. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98213. }
  98214. }
  98215. {
  98216. float *pcm=v->pcm[j]+thisCenter;
  98217. float *p=vb->pcm[j]+n;
  98218. for(i=0;i<n;i++)
  98219. pcm[i]=p[i];
  98220. }
  98221. }
  98222. if(v->centerW)
  98223. v->centerW=0;
  98224. else
  98225. v->centerW=n1;
  98226. if(v->pcm_returned==-1){
  98227. v->pcm_returned=thisCenter;
  98228. v->pcm_current=thisCenter;
  98229. }else{
  98230. v->pcm_returned=prevCenter;
  98231. v->pcm_current=prevCenter+
  98232. ((ci->blocksizes[v->lW]/4+
  98233. ci->blocksizes[v->W]/4)>>hs);
  98234. }
  98235. }
  98236. if(b->sample_count==-1){
  98237. b->sample_count=0;
  98238. }else{
  98239. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98240. }
  98241. if(v->granulepos==-1){
  98242. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98243. v->granulepos=vb->granulepos;
  98244. if(b->sample_count>v->granulepos){
  98245. if(vb->eofflag){
  98246. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98247. }else{
  98248. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98249. if(v->pcm_returned>v->pcm_current)
  98250. v->pcm_returned=v->pcm_current;
  98251. }
  98252. }
  98253. }
  98254. }else{
  98255. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98256. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98257. if(v->granulepos>vb->granulepos){
  98258. long extra=v->granulepos-vb->granulepos;
  98259. if(extra)
  98260. if(vb->eofflag){
  98261. v->pcm_current-=extra>>hs;
  98262. } /* else {Shouldn't happen *unless* the bitstream is out of
  98263. spec. Either way, believe the bitstream } */
  98264. } /* else {Shouldn't happen *unless* the bitstream is out of
  98265. spec. Either way, believe the bitstream } */
  98266. v->granulepos=vb->granulepos;
  98267. }
  98268. }
  98269. if(vb->eofflag)v->eofflag=1;
  98270. return(0);
  98271. }
  98272. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98273. vorbis_info *vi=v->vi;
  98274. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98275. if(pcm){
  98276. int i;
  98277. for(i=0;i<vi->channels;i++)
  98278. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98279. *pcm=v->pcmret;
  98280. }
  98281. return(v->pcm_current-v->pcm_returned);
  98282. }
  98283. return(0);
  98284. }
  98285. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98286. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98287. v->pcm_returned+=n;
  98288. return(0);
  98289. }
  98290. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98291. vorbis_info *vi=v->vi;
  98292. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98293. int hs=ci->halfrate_flag;
  98294. int n=ci->blocksizes[v->W]>>(hs+1);
  98295. int n0=ci->blocksizes[0]>>(hs+1);
  98296. int n1=ci->blocksizes[1]>>(hs+1);
  98297. int i,j;
  98298. if(v->pcm_returned<0)return 0;
  98299. if(v->centerW==n1){
  98300. for(j=0;j<vi->channels;j++){
  98301. float *p=v->pcm[j];
  98302. for(i=0;i<n1;i++){
  98303. float temp=p[i];
  98304. p[i]=p[i+n1];
  98305. p[i+n1]=temp;
  98306. }
  98307. }
  98308. v->pcm_current-=n1;
  98309. v->pcm_returned-=n1;
  98310. v->centerW=0;
  98311. }
  98312. if((v->lW^v->W)==1){
  98313. for(j=0;j<vi->channels;j++){
  98314. float *s=v->pcm[j];
  98315. float *d=v->pcm[j]+(n1-n0)/2;
  98316. for(i=(n1+n0)/2-1;i>=0;--i)
  98317. d[i]=s[i];
  98318. }
  98319. v->pcm_returned+=(n1-n0)/2;
  98320. v->pcm_current+=(n1-n0)/2;
  98321. }else{
  98322. if(v->lW==0){
  98323. for(j=0;j<vi->channels;j++){
  98324. float *s=v->pcm[j];
  98325. float *d=v->pcm[j]+n1-n0;
  98326. for(i=n0-1;i>=0;--i)
  98327. d[i]=s[i];
  98328. }
  98329. v->pcm_returned+=n1-n0;
  98330. v->pcm_current+=n1-n0;
  98331. }
  98332. }
  98333. if(pcm){
  98334. int i;
  98335. for(i=0;i<vi->channels;i++)
  98336. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98337. *pcm=v->pcmret;
  98338. }
  98339. return(n1+n-v->pcm_returned);
  98340. }
  98341. float *vorbis_window(vorbis_dsp_state *v,int W){
  98342. vorbis_info *vi=v->vi;
  98343. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98344. int hs=ci->halfrate_flag;
  98345. private_state *b=(private_state*)v->backend_state;
  98346. if(b->window[W]-1<0)return NULL;
  98347. return _vorbis_window_get(b->window[W]-hs);
  98348. }
  98349. #endif
  98350. /*** End of inlined file: block.c ***/
  98351. /*** Start of inlined file: codebook.c ***/
  98352. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98353. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98354. // tasks..
  98355. #if JUCE_MSVC
  98356. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98357. #endif
  98358. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98359. #if JUCE_USE_OGGVORBIS
  98360. #include <stdlib.h>
  98361. #include <string.h>
  98362. #include <math.h>
  98363. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98364. long i,j;
  98365. int ordered=0;
  98366. oggpack_write(opb,0x564342,24);
  98367. oggpack_write(opb,c->dim,16);
  98368. oggpack_write(opb,c->entries,24);
  98369. for(i=1;i<c->entries;i++)
  98370. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98371. if(i==c->entries)ordered=1;
  98372. if(ordered){
  98373. long count=0;
  98374. oggpack_write(opb,1,1); /* ordered */
  98375. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98376. for(i=1;i<c->entries;i++){
  98377. long thisx=c->lengthlist[i];
  98378. long last=c->lengthlist[i-1];
  98379. if(thisx>last){
  98380. for(j=last;j<thisx;j++){
  98381. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98382. count=i;
  98383. }
  98384. }
  98385. }
  98386. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98387. }else{
  98388. oggpack_write(opb,0,1); /* unordered */
  98389. for(i=0;i<c->entries;i++)
  98390. if(c->lengthlist[i]==0)break;
  98391. if(i==c->entries){
  98392. oggpack_write(opb,0,1); /* no unused entries */
  98393. for(i=0;i<c->entries;i++)
  98394. oggpack_write(opb,c->lengthlist[i]-1,5);
  98395. }else{
  98396. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98397. for(i=0;i<c->entries;i++){
  98398. if(c->lengthlist[i]==0){
  98399. oggpack_write(opb,0,1);
  98400. }else{
  98401. oggpack_write(opb,1,1);
  98402. oggpack_write(opb,c->lengthlist[i]-1,5);
  98403. }
  98404. }
  98405. }
  98406. }
  98407. oggpack_write(opb,c->maptype,4);
  98408. switch(c->maptype){
  98409. case 0:
  98410. break;
  98411. case 1:case 2:
  98412. if(!c->quantlist){
  98413. return(-1);
  98414. }
  98415. oggpack_write(opb,c->q_min,32);
  98416. oggpack_write(opb,c->q_delta,32);
  98417. oggpack_write(opb,c->q_quant-1,4);
  98418. oggpack_write(opb,c->q_sequencep,1);
  98419. {
  98420. int quantvals;
  98421. switch(c->maptype){
  98422. case 1:
  98423. quantvals=_book_maptype1_quantvals(c);
  98424. break;
  98425. case 2:
  98426. quantvals=c->entries*c->dim;
  98427. break;
  98428. default: /* NOT_REACHABLE */
  98429. quantvals=-1;
  98430. }
  98431. for(i=0;i<quantvals;i++)
  98432. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98433. }
  98434. break;
  98435. default:
  98436. return(-1);
  98437. }
  98438. return(0);
  98439. }
  98440. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98441. long i,j;
  98442. memset(s,0,sizeof(*s));
  98443. s->allocedp=1;
  98444. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98445. s->dim=oggpack_read(opb,16);
  98446. s->entries=oggpack_read(opb,24);
  98447. if(s->entries==-1)goto _eofout;
  98448. switch((int)oggpack_read(opb,1)){
  98449. case 0:
  98450. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98451. if(oggpack_read(opb,1)){
  98452. for(i=0;i<s->entries;i++){
  98453. if(oggpack_read(opb,1)){
  98454. long num=oggpack_read(opb,5);
  98455. if(num==-1)goto _eofout;
  98456. s->lengthlist[i]=num+1;
  98457. }else
  98458. s->lengthlist[i]=0;
  98459. }
  98460. }else{
  98461. for(i=0;i<s->entries;i++){
  98462. long num=oggpack_read(opb,5);
  98463. if(num==-1)goto _eofout;
  98464. s->lengthlist[i]=num+1;
  98465. }
  98466. }
  98467. break;
  98468. case 1:
  98469. {
  98470. long length=oggpack_read(opb,5)+1;
  98471. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98472. for(i=0;i<s->entries;){
  98473. long num=oggpack_read(opb,_ilog(s->entries-i));
  98474. if(num==-1)goto _eofout;
  98475. for(j=0;j<num && i<s->entries;j++,i++)
  98476. s->lengthlist[i]=length;
  98477. length++;
  98478. }
  98479. }
  98480. break;
  98481. default:
  98482. return(-1);
  98483. }
  98484. switch((s->maptype=oggpack_read(opb,4))){
  98485. case 0:
  98486. break;
  98487. case 1: case 2:
  98488. s->q_min=oggpack_read(opb,32);
  98489. s->q_delta=oggpack_read(opb,32);
  98490. s->q_quant=oggpack_read(opb,4)+1;
  98491. s->q_sequencep=oggpack_read(opb,1);
  98492. {
  98493. int quantvals=0;
  98494. switch(s->maptype){
  98495. case 1:
  98496. quantvals=_book_maptype1_quantvals(s);
  98497. break;
  98498. case 2:
  98499. quantvals=s->entries*s->dim;
  98500. break;
  98501. }
  98502. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98503. for(i=0;i<quantvals;i++)
  98504. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98505. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98506. }
  98507. break;
  98508. default:
  98509. goto _errout;
  98510. }
  98511. return(0);
  98512. _errout:
  98513. _eofout:
  98514. vorbis_staticbook_clear(s);
  98515. return(-1);
  98516. }
  98517. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98518. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98519. return(book->c->lengthlist[a]);
  98520. }
  98521. int vorbis_book_errorv(codebook *book,float *a){
  98522. int dim=book->dim,k;
  98523. int best=_best(book,a,1);
  98524. for(k=0;k<dim;k++)
  98525. a[k]=(book->valuelist+best*dim)[k];
  98526. return(best);
  98527. }
  98528. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98529. int k,dim=book->dim;
  98530. for(k=0;k<dim;k++)
  98531. a[k]=(book->valuelist+best*dim)[k];
  98532. return(vorbis_book_encode(book,best,b));
  98533. }
  98534. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98535. int read=book->dec_maxlength;
  98536. long lo,hi;
  98537. long lok = oggpack_look(b,book->dec_firsttablen);
  98538. if (lok >= 0) {
  98539. long entry = book->dec_firsttable[lok];
  98540. if(entry&0x80000000UL){
  98541. lo=(entry>>15)&0x7fff;
  98542. hi=book->used_entries-(entry&0x7fff);
  98543. }else{
  98544. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98545. return(entry-1);
  98546. }
  98547. }else{
  98548. lo=0;
  98549. hi=book->used_entries;
  98550. }
  98551. lok = oggpack_look(b, read);
  98552. while(lok<0 && read>1)
  98553. lok = oggpack_look(b, --read);
  98554. if(lok<0)return -1;
  98555. {
  98556. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98557. while(hi-lo>1){
  98558. long p=(hi-lo)>>1;
  98559. long test=book->codelist[lo+p]>testword;
  98560. lo+=p&(test-1);
  98561. hi-=p&(-test);
  98562. }
  98563. if(book->dec_codelengths[lo]<=read){
  98564. oggpack_adv(b, book->dec_codelengths[lo]);
  98565. return(lo);
  98566. }
  98567. }
  98568. oggpack_adv(b, read);
  98569. return(-1);
  98570. }
  98571. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98572. long packed_entry=decode_packed_entry_number(book,b);
  98573. if(packed_entry>=0)
  98574. return(book->dec_index[packed_entry]);
  98575. return(packed_entry);
  98576. }
  98577. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98578. int step=n/book->dim;
  98579. long *entry = (long*)alloca(sizeof(*entry)*step);
  98580. float **t = (float**)alloca(sizeof(*t)*step);
  98581. int i,j,o;
  98582. for (i = 0; i < step; i++) {
  98583. entry[i]=decode_packed_entry_number(book,b);
  98584. if(entry[i]==-1)return(-1);
  98585. t[i] = book->valuelist+entry[i]*book->dim;
  98586. }
  98587. for(i=0,o=0;i<book->dim;i++,o+=step)
  98588. for (j=0;j<step;j++)
  98589. a[o+j]+=t[j][i];
  98590. return(0);
  98591. }
  98592. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98593. int i,j,entry;
  98594. float *t;
  98595. if(book->dim>8){
  98596. for(i=0;i<n;){
  98597. entry = decode_packed_entry_number(book,b);
  98598. if(entry==-1)return(-1);
  98599. t = book->valuelist+entry*book->dim;
  98600. for (j=0;j<book->dim;)
  98601. a[i++]+=t[j++];
  98602. }
  98603. }else{
  98604. for(i=0;i<n;){
  98605. entry = decode_packed_entry_number(book,b);
  98606. if(entry==-1)return(-1);
  98607. t = book->valuelist+entry*book->dim;
  98608. j=0;
  98609. switch((int)book->dim){
  98610. case 8:
  98611. a[i++]+=t[j++];
  98612. case 7:
  98613. a[i++]+=t[j++];
  98614. case 6:
  98615. a[i++]+=t[j++];
  98616. case 5:
  98617. a[i++]+=t[j++];
  98618. case 4:
  98619. a[i++]+=t[j++];
  98620. case 3:
  98621. a[i++]+=t[j++];
  98622. case 2:
  98623. a[i++]+=t[j++];
  98624. case 1:
  98625. a[i++]+=t[j++];
  98626. case 0:
  98627. break;
  98628. }
  98629. }
  98630. }
  98631. return(0);
  98632. }
  98633. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98634. int i,j,entry;
  98635. float *t;
  98636. for(i=0;i<n;){
  98637. entry = decode_packed_entry_number(book,b);
  98638. if(entry==-1)return(-1);
  98639. t = book->valuelist+entry*book->dim;
  98640. for (j=0;j<book->dim;)
  98641. a[i++]=t[j++];
  98642. }
  98643. return(0);
  98644. }
  98645. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98646. oggpack_buffer *b,int n){
  98647. long i,j,entry;
  98648. int chptr=0;
  98649. for(i=offset/ch;i<(offset+n)/ch;){
  98650. entry = decode_packed_entry_number(book,b);
  98651. if(entry==-1)return(-1);
  98652. {
  98653. const float *t = book->valuelist+entry*book->dim;
  98654. for (j=0;j<book->dim;j++){
  98655. a[chptr++][i]+=t[j];
  98656. if(chptr==ch){
  98657. chptr=0;
  98658. i++;
  98659. }
  98660. }
  98661. }
  98662. }
  98663. return(0);
  98664. }
  98665. #ifdef _V_SELFTEST
  98666. #include <stdio.h>
  98667. #include "vorbis/book/lsp20_0.vqh"
  98668. #include "vorbis/book/res0a_13.vqh"
  98669. #define TESTSIZE 40
  98670. float test1[TESTSIZE]={
  98671. 0.105939f,
  98672. 0.215373f,
  98673. 0.429117f,
  98674. 0.587974f,
  98675. 0.181173f,
  98676. 0.296583f,
  98677. 0.515707f,
  98678. 0.715261f,
  98679. 0.162327f,
  98680. 0.263834f,
  98681. 0.342876f,
  98682. 0.406025f,
  98683. 0.103571f,
  98684. 0.223561f,
  98685. 0.368513f,
  98686. 0.540313f,
  98687. 0.136672f,
  98688. 0.395882f,
  98689. 0.587183f,
  98690. 0.652476f,
  98691. 0.114338f,
  98692. 0.417300f,
  98693. 0.525486f,
  98694. 0.698679f,
  98695. 0.147492f,
  98696. 0.324481f,
  98697. 0.643089f,
  98698. 0.757582f,
  98699. 0.139556f,
  98700. 0.215795f,
  98701. 0.324559f,
  98702. 0.399387f,
  98703. 0.120236f,
  98704. 0.267420f,
  98705. 0.446940f,
  98706. 0.608760f,
  98707. 0.115587f,
  98708. 0.287234f,
  98709. 0.571081f,
  98710. 0.708603f,
  98711. };
  98712. float test3[TESTSIZE]={
  98713. 0,1,-2,3,4,-5,6,7,8,9,
  98714. 8,-2,7,-1,4,6,8,3,1,-9,
  98715. 10,11,12,13,14,15,26,17,18,19,
  98716. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98717. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98718. &_vq_book_res0a_13,NULL};
  98719. float *testvec[]={test1,test3};
  98720. int main(){
  98721. oggpack_buffer write;
  98722. oggpack_buffer read;
  98723. long ptr=0,i;
  98724. oggpack_writeinit(&write);
  98725. fprintf(stderr,"Testing codebook abstraction...:\n");
  98726. while(testlist[ptr]){
  98727. codebook c;
  98728. static_codebook s;
  98729. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98730. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98731. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98732. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98733. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98734. oggpack_reset(&write);
  98735. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98736. we can write */
  98737. vorbis_staticbook_pack(testlist[ptr],&write);
  98738. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98739. for(i=0;i<TESTSIZE;i+=c.dim){
  98740. int best=_best(&c,qv+i,1);
  98741. vorbis_book_encodev(&c,best,qv+i,&write);
  98742. }
  98743. vorbis_book_clear(&c);
  98744. fprintf(stderr,"OK.\n");
  98745. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98746. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98747. if(vorbis_staticbook_unpack(&read,&s)){
  98748. fprintf(stderr,"Error unpacking codebook.\n");
  98749. exit(1);
  98750. }
  98751. if(vorbis_book_init_decode(&c,&s)){
  98752. fprintf(stderr,"Error initializing codebook.\n");
  98753. exit(1);
  98754. }
  98755. for(i=0;i<TESTSIZE;i+=c.dim)
  98756. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98757. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98758. exit(1);
  98759. }
  98760. for(i=0;i<TESTSIZE;i++)
  98761. if(fabs(qv[i]-iv[i])>.000001){
  98762. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98763. iv[i],qv[i],i);
  98764. exit(1);
  98765. }
  98766. fprintf(stderr,"OK\n");
  98767. ptr++;
  98768. }
  98769. exit(0);
  98770. }
  98771. #endif
  98772. #endif
  98773. /*** End of inlined file: codebook.c ***/
  98774. /*** Start of inlined file: envelope.c ***/
  98775. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98776. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98777. // tasks..
  98778. #if JUCE_MSVC
  98779. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98780. #endif
  98781. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98782. #if JUCE_USE_OGGVORBIS
  98783. #include <stdlib.h>
  98784. #include <string.h>
  98785. #include <stdio.h>
  98786. #include <math.h>
  98787. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98788. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98789. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98790. int ch=vi->channels;
  98791. int i,j;
  98792. int n=e->winlength=128;
  98793. e->searchstep=64; /* not random */
  98794. e->minenergy=gi->preecho_minenergy;
  98795. e->ch=ch;
  98796. e->storage=128;
  98797. e->cursor=ci->blocksizes[1]/2;
  98798. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98799. mdct_init(&e->mdct,n);
  98800. for(i=0;i<n;i++){
  98801. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98802. e->mdct_win[i]*=e->mdct_win[i];
  98803. }
  98804. e->band[0].begin=2; e->band[0].end=4;
  98805. e->band[1].begin=4; e->band[1].end=5;
  98806. e->band[2].begin=6; e->band[2].end=6;
  98807. e->band[3].begin=9; e->band[3].end=8;
  98808. e->band[4].begin=13; e->band[4].end=8;
  98809. e->band[5].begin=17; e->band[5].end=8;
  98810. e->band[6].begin=22; e->band[6].end=8;
  98811. for(j=0;j<VE_BANDS;j++){
  98812. n=e->band[j].end;
  98813. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98814. for(i=0;i<n;i++){
  98815. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98816. e->band[j].total+=e->band[j].window[i];
  98817. }
  98818. e->band[j].total=1./e->band[j].total;
  98819. }
  98820. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98821. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98822. }
  98823. void _ve_envelope_clear(envelope_lookup *e){
  98824. int i;
  98825. mdct_clear(&e->mdct);
  98826. for(i=0;i<VE_BANDS;i++)
  98827. _ogg_free(e->band[i].window);
  98828. _ogg_free(e->mdct_win);
  98829. _ogg_free(e->filter);
  98830. _ogg_free(e->mark);
  98831. memset(e,0,sizeof(*e));
  98832. }
  98833. static int _ve_amp(envelope_lookup *ve,
  98834. vorbis_info_psy_global *gi,
  98835. float *data,
  98836. envelope_band *bands,
  98837. envelope_filter_state *filters,
  98838. long pos){
  98839. long n=ve->winlength;
  98840. int ret=0;
  98841. long i,j;
  98842. float decay;
  98843. float minV=ve->minenergy;
  98844. float *vec=(float*) alloca(n*sizeof(*vec));
  98845. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98846. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98847. if(penalty<0.f)penalty=0.f;
  98848. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98849. for(i=0;i<n;i++)
  98850. vec[i]=data[i]*ve->mdct_win[i];
  98851. mdct_forward(&ve->mdct,vec,vec);
  98852. {
  98853. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98854. int ptr=filters->nearptr;
  98855. if(ptr==0){
  98856. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98857. filters->nearDC_partialacc=temp;
  98858. }else{
  98859. decay=filters->nearDC_acc+=temp;
  98860. filters->nearDC_partialacc+=temp;
  98861. }
  98862. filters->nearDC_acc-=filters->nearDC[ptr];
  98863. filters->nearDC[ptr]=temp;
  98864. decay*=(1./(VE_NEARDC+1));
  98865. filters->nearptr++;
  98866. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98867. decay=todB(&decay)*.5-15.f;
  98868. }
  98869. for(i=0;i<n/2;i+=2){
  98870. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98871. val=todB(&val)*.5f;
  98872. if(val<decay)val=decay;
  98873. if(val<minV)val=minV;
  98874. vec[i>>1]=val;
  98875. decay-=8.;
  98876. }
  98877. for(j=0;j<VE_BANDS;j++){
  98878. float acc=0.;
  98879. float valmax,valmin;
  98880. for(i=0;i<bands[j].end;i++)
  98881. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98882. acc*=bands[j].total;
  98883. {
  98884. int p,thisx=filters[j].ampptr;
  98885. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98886. p=thisx;
  98887. p--;
  98888. if(p<0)p+=VE_AMP;
  98889. postmax=max(acc,filters[j].ampbuf[p]);
  98890. postmin=min(acc,filters[j].ampbuf[p]);
  98891. for(i=0;i<stretch;i++){
  98892. p--;
  98893. if(p<0)p+=VE_AMP;
  98894. premax=max(premax,filters[j].ampbuf[p]);
  98895. premin=min(premin,filters[j].ampbuf[p]);
  98896. }
  98897. valmin=postmin-premin;
  98898. valmax=postmax-premax;
  98899. filters[j].ampbuf[thisx]=acc;
  98900. filters[j].ampptr++;
  98901. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98902. }
  98903. if(valmax>gi->preecho_thresh[j]+penalty){
  98904. ret|=1;
  98905. ret|=4;
  98906. }
  98907. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98908. }
  98909. return(ret);
  98910. }
  98911. #if 0
  98912. static int seq=0;
  98913. static ogg_int64_t totalshift=-1024;
  98914. #endif
  98915. long _ve_envelope_search(vorbis_dsp_state *v){
  98916. vorbis_info *vi=v->vi;
  98917. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98918. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98919. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98920. long i,j;
  98921. int first=ve->current/ve->searchstep;
  98922. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98923. if(first<0)first=0;
  98924. if(last+VE_WIN+VE_POST>ve->storage){
  98925. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98926. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98927. }
  98928. for(j=first;j<last;j++){
  98929. int ret=0;
  98930. ve->stretch++;
  98931. if(ve->stretch>VE_MAXSTRETCH*2)
  98932. ve->stretch=VE_MAXSTRETCH*2;
  98933. for(i=0;i<ve->ch;i++){
  98934. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98935. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98936. }
  98937. ve->mark[j+VE_POST]=0;
  98938. if(ret&1){
  98939. ve->mark[j]=1;
  98940. ve->mark[j+1]=1;
  98941. }
  98942. if(ret&2){
  98943. ve->mark[j]=1;
  98944. if(j>0)ve->mark[j-1]=1;
  98945. }
  98946. if(ret&4)ve->stretch=-1;
  98947. }
  98948. ve->current=last*ve->searchstep;
  98949. {
  98950. long centerW=v->centerW;
  98951. long testW=
  98952. centerW+
  98953. ci->blocksizes[v->W]/4+
  98954. ci->blocksizes[1]/2+
  98955. ci->blocksizes[0]/4;
  98956. j=ve->cursor;
  98957. while(j<ve->current-(ve->searchstep)){/* account for postecho
  98958. working back one window */
  98959. if(j>=testW)return(1);
  98960. ve->cursor=j;
  98961. if(ve->mark[j/ve->searchstep]){
  98962. if(j>centerW){
  98963. #if 0
  98964. if(j>ve->curmark){
  98965. float *marker=alloca(v->pcm_current*sizeof(*marker));
  98966. int l,m;
  98967. memset(marker,0,sizeof(*marker)*v->pcm_current);
  98968. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  98969. seq,
  98970. (totalshift+ve->cursor)/44100.,
  98971. (totalshift+j)/44100.);
  98972. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  98973. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  98974. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  98975. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  98976. for(m=0;m<VE_BANDS;m++){
  98977. char buf[80];
  98978. sprintf(buf,"delL%d",m);
  98979. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  98980. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98981. }
  98982. for(m=0;m<VE_BANDS;m++){
  98983. char buf[80];
  98984. sprintf(buf,"delR%d",m);
  98985. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  98986. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98987. }
  98988. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  98989. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  98990. seq++;
  98991. }
  98992. #endif
  98993. ve->curmark=j;
  98994. if(j>=testW)return(1);
  98995. return(0);
  98996. }
  98997. }
  98998. j+=ve->searchstep;
  98999. }
  99000. }
  99001. return(-1);
  99002. }
  99003. int _ve_envelope_mark(vorbis_dsp_state *v){
  99004. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99005. vorbis_info *vi=v->vi;
  99006. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99007. long centerW=v->centerW;
  99008. long beginW=centerW-ci->blocksizes[v->W]/4;
  99009. long endW=centerW+ci->blocksizes[v->W]/4;
  99010. if(v->W){
  99011. beginW-=ci->blocksizes[v->lW]/4;
  99012. endW+=ci->blocksizes[v->nW]/4;
  99013. }else{
  99014. beginW-=ci->blocksizes[0]/4;
  99015. endW+=ci->blocksizes[0]/4;
  99016. }
  99017. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  99018. {
  99019. long first=beginW/ve->searchstep;
  99020. long last=endW/ve->searchstep;
  99021. long i;
  99022. for(i=first;i<last;i++)
  99023. if(ve->mark[i])return(1);
  99024. }
  99025. return(0);
  99026. }
  99027. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99028. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99029. ahead of ve->current */
  99030. int smallshift=shift/e->searchstep;
  99031. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99032. #if 0
  99033. for(i=0;i<VE_BANDS*e->ch;i++)
  99034. memmove(e->filter[i].markers,
  99035. e->filter[i].markers+smallshift,
  99036. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99037. totalshift+=shift;
  99038. #endif
  99039. e->current-=shift;
  99040. if(e->curmark>=0)
  99041. e->curmark-=shift;
  99042. e->cursor-=shift;
  99043. }
  99044. #endif
  99045. /*** End of inlined file: envelope.c ***/
  99046. /*** Start of inlined file: floor0.c ***/
  99047. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99048. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99049. // tasks..
  99050. #if JUCE_MSVC
  99051. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99052. #endif
  99053. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99054. #if JUCE_USE_OGGVORBIS
  99055. #include <stdlib.h>
  99056. #include <string.h>
  99057. #include <math.h>
  99058. /*** Start of inlined file: lsp.h ***/
  99059. #ifndef _V_LSP_H_
  99060. #define _V_LSP_H_
  99061. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99062. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99063. float *lsp,int m,
  99064. float amp,float ampoffset);
  99065. #endif
  99066. /*** End of inlined file: lsp.h ***/
  99067. #include <stdio.h>
  99068. typedef struct {
  99069. int ln;
  99070. int m;
  99071. int **linearmap;
  99072. int n[2];
  99073. vorbis_info_floor0 *vi;
  99074. long bits;
  99075. long frames;
  99076. } vorbis_look_floor0;
  99077. static void floor0_free_info(vorbis_info_floor *i){
  99078. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99079. if(info){
  99080. memset(info,0,sizeof(*info));
  99081. _ogg_free(info);
  99082. }
  99083. }
  99084. static void floor0_free_look(vorbis_look_floor *i){
  99085. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99086. if(look){
  99087. if(look->linearmap){
  99088. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99089. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99090. _ogg_free(look->linearmap);
  99091. }
  99092. memset(look,0,sizeof(*look));
  99093. _ogg_free(look);
  99094. }
  99095. }
  99096. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99097. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99098. int j;
  99099. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99100. info->order=oggpack_read(opb,8);
  99101. info->rate=oggpack_read(opb,16);
  99102. info->barkmap=oggpack_read(opb,16);
  99103. info->ampbits=oggpack_read(opb,6);
  99104. info->ampdB=oggpack_read(opb,8);
  99105. info->numbooks=oggpack_read(opb,4)+1;
  99106. if(info->order<1)goto err_out;
  99107. if(info->rate<1)goto err_out;
  99108. if(info->barkmap<1)goto err_out;
  99109. if(info->numbooks<1)goto err_out;
  99110. for(j=0;j<info->numbooks;j++){
  99111. info->books[j]=oggpack_read(opb,8);
  99112. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99113. }
  99114. return(info);
  99115. err_out:
  99116. floor0_free_info(info);
  99117. return(NULL);
  99118. }
  99119. static void floor0_map_lazy_init(vorbis_block *vb,
  99120. vorbis_info_floor *infoX,
  99121. vorbis_look_floor0 *look){
  99122. if(!look->linearmap[vb->W]){
  99123. vorbis_dsp_state *vd=vb->vd;
  99124. vorbis_info *vi=vd->vi;
  99125. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99126. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99127. int W=vb->W;
  99128. int n=ci->blocksizes[W]/2,j;
  99129. float scale=look->ln/toBARK(info->rate/2.f);
  99130. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99131. for(j=0;j<n;j++){
  99132. int val=floor( toBARK((info->rate/2.f)/n*j)
  99133. *scale); /* bark numbers represent band edges */
  99134. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99135. look->linearmap[W][j]=val;
  99136. }
  99137. look->linearmap[W][j]=-1;
  99138. look->n[W]=n;
  99139. }
  99140. }
  99141. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99142. vorbis_info_floor *i){
  99143. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99144. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99145. look->m=info->order;
  99146. look->ln=info->barkmap;
  99147. look->vi=info;
  99148. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99149. return look;
  99150. }
  99151. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99152. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99153. vorbis_info_floor0 *info=look->vi;
  99154. int j,k;
  99155. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99156. if(ampraw>0){ /* also handles the -1 out of data case */
  99157. long maxval=(1<<info->ampbits)-1;
  99158. float amp=(float)ampraw/maxval*info->ampdB;
  99159. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99160. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99161. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99162. codebook *b=ci->fullbooks+info->books[booknum];
  99163. float last=0.f;
  99164. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99165. for(j=0;j<look->m;j+=b->dim)
  99166. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99167. for(j=0;j<look->m;){
  99168. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99169. last=lsp[j-1];
  99170. }
  99171. lsp[look->m]=amp;
  99172. return(lsp);
  99173. }
  99174. }
  99175. eop:
  99176. return(NULL);
  99177. }
  99178. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99179. void *memo,float *out){
  99180. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99181. vorbis_info_floor0 *info=look->vi;
  99182. floor0_map_lazy_init(vb,info,look);
  99183. if(memo){
  99184. float *lsp=(float *)memo;
  99185. float amp=lsp[look->m];
  99186. vorbis_lsp_to_curve(out,
  99187. look->linearmap[vb->W],
  99188. look->n[vb->W],
  99189. look->ln,
  99190. lsp,look->m,amp,(float)info->ampdB);
  99191. return(1);
  99192. }
  99193. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99194. return(0);
  99195. }
  99196. vorbis_func_floor floor0_exportbundle={
  99197. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99198. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99199. };
  99200. #endif
  99201. /*** End of inlined file: floor0.c ***/
  99202. /*** Start of inlined file: floor1.c ***/
  99203. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99204. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99205. // tasks..
  99206. #if JUCE_MSVC
  99207. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99208. #endif
  99209. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99210. #if JUCE_USE_OGGVORBIS
  99211. #include <stdlib.h>
  99212. #include <string.h>
  99213. #include <math.h>
  99214. #include <stdio.h>
  99215. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99216. typedef struct {
  99217. int sorted_index[VIF_POSIT+2];
  99218. int forward_index[VIF_POSIT+2];
  99219. int reverse_index[VIF_POSIT+2];
  99220. int hineighbor[VIF_POSIT];
  99221. int loneighbor[VIF_POSIT];
  99222. int posts;
  99223. int n;
  99224. int quant_q;
  99225. vorbis_info_floor1 *vi;
  99226. long phrasebits;
  99227. long postbits;
  99228. long frames;
  99229. } vorbis_look_floor1;
  99230. typedef struct lsfit_acc{
  99231. long x0;
  99232. long x1;
  99233. long xa;
  99234. long ya;
  99235. long x2a;
  99236. long y2a;
  99237. long xya;
  99238. long an;
  99239. } lsfit_acc;
  99240. static void floor1_free_info(vorbis_info_floor *i){
  99241. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99242. if(info){
  99243. memset(info,0,sizeof(*info));
  99244. _ogg_free(info);
  99245. }
  99246. }
  99247. static void floor1_free_look(vorbis_look_floor *i){
  99248. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99249. if(look){
  99250. memset(look,0,sizeof(*look));
  99251. _ogg_free(look);
  99252. }
  99253. }
  99254. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99255. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99256. int j,k;
  99257. int count=0;
  99258. int rangebits;
  99259. int maxposit=info->postlist[1];
  99260. int maxclass=-1;
  99261. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99262. for(j=0;j<info->partitions;j++){
  99263. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99264. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99265. }
  99266. for(j=0;j<maxclass+1;j++){
  99267. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99268. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99269. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99270. for(k=0;k<(1<<info->class_subs[j]);k++)
  99271. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99272. }
  99273. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99274. oggpack_write(opb,ilog2(maxposit),4);
  99275. rangebits=ilog2(maxposit);
  99276. for(j=0,k=0;j<info->partitions;j++){
  99277. count+=info->class_dim[info->partitionclass[j]];
  99278. for(;k<count;k++)
  99279. oggpack_write(opb,info->postlist[k+2],rangebits);
  99280. }
  99281. }
  99282. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99283. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99284. int j,k,count=0,maxclass=-1,rangebits;
  99285. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99286. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99287. for(j=0;j<info->partitions;j++){
  99288. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99289. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99290. }
  99291. for(j=0;j<maxclass+1;j++){
  99292. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99293. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99294. if(info->class_subs[j]<0)
  99295. goto err_out;
  99296. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99297. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99298. goto err_out;
  99299. for(k=0;k<(1<<info->class_subs[j]);k++){
  99300. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99301. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99302. goto err_out;
  99303. }
  99304. }
  99305. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99306. rangebits=oggpack_read(opb,4);
  99307. for(j=0,k=0;j<info->partitions;j++){
  99308. count+=info->class_dim[info->partitionclass[j]];
  99309. for(;k<count;k++){
  99310. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99311. if(t<0 || t>=(1<<rangebits))
  99312. goto err_out;
  99313. }
  99314. }
  99315. info->postlist[0]=0;
  99316. info->postlist[1]=1<<rangebits;
  99317. return(info);
  99318. err_out:
  99319. floor1_free_info(info);
  99320. return(NULL);
  99321. }
  99322. static int icomp(const void *a,const void *b){
  99323. return(**(int **)a-**(int **)b);
  99324. }
  99325. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99326. vorbis_info_floor *in){
  99327. int *sortpointer[VIF_POSIT+2];
  99328. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99329. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99330. int i,j,n=0;
  99331. look->vi=info;
  99332. look->n=info->postlist[1];
  99333. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99334. n+=2;
  99335. look->posts=n;
  99336. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99337. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99338. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99339. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99340. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99341. switch(info->mult){
  99342. case 1: /* 1024 -> 256 */
  99343. look->quant_q=256;
  99344. break;
  99345. case 2: /* 1024 -> 128 */
  99346. look->quant_q=128;
  99347. break;
  99348. case 3: /* 1024 -> 86 */
  99349. look->quant_q=86;
  99350. break;
  99351. case 4: /* 1024 -> 64 */
  99352. look->quant_q=64;
  99353. break;
  99354. }
  99355. for(i=0;i<n-2;i++){
  99356. int lo=0;
  99357. int hi=1;
  99358. int lx=0;
  99359. int hx=look->n;
  99360. int currentx=info->postlist[i+2];
  99361. for(j=0;j<i+2;j++){
  99362. int x=info->postlist[j];
  99363. if(x>lx && x<currentx){
  99364. lo=j;
  99365. lx=x;
  99366. }
  99367. if(x<hx && x>currentx){
  99368. hi=j;
  99369. hx=x;
  99370. }
  99371. }
  99372. look->loneighbor[i]=lo;
  99373. look->hineighbor[i]=hi;
  99374. }
  99375. return(look);
  99376. }
  99377. static int render_point(int x0,int x1,int y0,int y1,int x){
  99378. y0&=0x7fff; /* mask off flag */
  99379. y1&=0x7fff;
  99380. {
  99381. int dy=y1-y0;
  99382. int adx=x1-x0;
  99383. int ady=abs(dy);
  99384. int err=ady*(x-x0);
  99385. int off=err/adx;
  99386. if(dy<0)return(y0-off);
  99387. return(y0+off);
  99388. }
  99389. }
  99390. static int vorbis_dBquant(const float *x){
  99391. int i= *x*7.3142857f+1023.5f;
  99392. if(i>1023)return(1023);
  99393. if(i<0)return(0);
  99394. return i;
  99395. }
  99396. static float FLOOR1_fromdB_LOOKUP[256]={
  99397. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99398. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99399. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99400. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99401. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99402. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99403. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99404. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99405. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99406. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99407. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99408. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99409. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99410. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99411. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99412. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99413. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99414. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99415. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99416. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99417. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99418. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99419. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99420. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99421. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99422. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99423. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99424. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99425. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99426. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99427. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99428. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99429. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99430. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99431. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99432. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99433. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99434. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99435. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99436. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99437. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99438. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99439. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99440. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99441. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99442. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99443. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99444. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99445. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99446. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99447. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99448. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99449. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99450. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99451. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99452. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99453. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99454. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99455. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99456. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99457. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99458. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99459. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99460. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99461. };
  99462. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99463. int dy=y1-y0;
  99464. int adx=x1-x0;
  99465. int ady=abs(dy);
  99466. int base=dy/adx;
  99467. int sy=(dy<0?base-1:base+1);
  99468. int x=x0;
  99469. int y=y0;
  99470. int err=0;
  99471. ady-=abs(base*adx);
  99472. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99473. while(++x<x1){
  99474. err=err+ady;
  99475. if(err>=adx){
  99476. err-=adx;
  99477. y+=sy;
  99478. }else{
  99479. y+=base;
  99480. }
  99481. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99482. }
  99483. }
  99484. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99485. int dy=y1-y0;
  99486. int adx=x1-x0;
  99487. int ady=abs(dy);
  99488. int base=dy/adx;
  99489. int sy=(dy<0?base-1:base+1);
  99490. int x=x0;
  99491. int y=y0;
  99492. int err=0;
  99493. ady-=abs(base*adx);
  99494. d[x]=y;
  99495. while(++x<x1){
  99496. err=err+ady;
  99497. if(err>=adx){
  99498. err-=adx;
  99499. y+=sy;
  99500. }else{
  99501. y+=base;
  99502. }
  99503. d[x]=y;
  99504. }
  99505. }
  99506. static int accumulate_fit(const float *flr,const float *mdct,
  99507. int x0, int x1,lsfit_acc *a,
  99508. int n,vorbis_info_floor1 *info){
  99509. long i;
  99510. 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;
  99511. memset(a,0,sizeof(*a));
  99512. a->x0=x0;
  99513. a->x1=x1;
  99514. if(x1>=n)x1=n-1;
  99515. for(i=x0;i<=x1;i++){
  99516. int quantized=vorbis_dBquant(flr+i);
  99517. if(quantized){
  99518. if(mdct[i]+info->twofitatten>=flr[i]){
  99519. xa += i;
  99520. ya += quantized;
  99521. x2a += i*i;
  99522. y2a += quantized*quantized;
  99523. xya += i*quantized;
  99524. na++;
  99525. }else{
  99526. xb += i;
  99527. yb += quantized;
  99528. x2b += i*i;
  99529. y2b += quantized*quantized;
  99530. xyb += i*quantized;
  99531. nb++;
  99532. }
  99533. }
  99534. }
  99535. xb+=xa;
  99536. yb+=ya;
  99537. x2b+=x2a;
  99538. y2b+=y2a;
  99539. xyb+=xya;
  99540. nb+=na;
  99541. {
  99542. int weight=nb*info->twofitweight/(na+1);
  99543. a->xa=xa*weight+xb;
  99544. a->ya=ya*weight+yb;
  99545. a->x2a=x2a*weight+x2b;
  99546. a->y2a=y2a*weight+y2b;
  99547. a->xya=xya*weight+xyb;
  99548. a->an=na*weight+nb;
  99549. }
  99550. return(na);
  99551. }
  99552. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99553. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99554. long x0=a[0].x0;
  99555. long x1=a[fits-1].x1;
  99556. for(i=0;i<fits;i++){
  99557. x+=a[i].xa;
  99558. y+=a[i].ya;
  99559. x2+=a[i].x2a;
  99560. y2+=a[i].y2a;
  99561. xy+=a[i].xya;
  99562. an+=a[i].an;
  99563. }
  99564. if(*y0>=0){
  99565. x+= x0;
  99566. y+= *y0;
  99567. x2+= x0 * x0;
  99568. y2+= *y0 * *y0;
  99569. xy+= *y0 * x0;
  99570. an++;
  99571. }
  99572. if(*y1>=0){
  99573. x+= x1;
  99574. y+= *y1;
  99575. x2+= x1 * x1;
  99576. y2+= *y1 * *y1;
  99577. xy+= *y1 * x1;
  99578. an++;
  99579. }
  99580. if(an){
  99581. double fx=x;
  99582. double fy=y;
  99583. double fx2=x2;
  99584. double fxy=xy;
  99585. double denom=1./(an*fx2-fx*fx);
  99586. double a=(fy*fx2-fxy*fx)*denom;
  99587. double b=(an*fxy-fx*fy)*denom;
  99588. *y0=rint(a+b*x0);
  99589. *y1=rint(a+b*x1);
  99590. if(*y0>1023)*y0=1023;
  99591. if(*y1>1023)*y1=1023;
  99592. if(*y0<0)*y0=0;
  99593. if(*y1<0)*y1=0;
  99594. }else{
  99595. *y0=0;
  99596. *y1=0;
  99597. }
  99598. }
  99599. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99600. const float *mdct,
  99601. vorbis_info_floor1 *info){
  99602. int dy=y1-y0;
  99603. int adx=x1-x0;
  99604. int ady=abs(dy);
  99605. int base=dy/adx;
  99606. int sy=(dy<0?base-1:base+1);
  99607. int x=x0;
  99608. int y=y0;
  99609. int err=0;
  99610. int val=vorbis_dBquant(mask+x);
  99611. int mse=0;
  99612. int n=0;
  99613. ady-=abs(base*adx);
  99614. mse=(y-val);
  99615. mse*=mse;
  99616. n++;
  99617. if(mdct[x]+info->twofitatten>=mask[x]){
  99618. if(y+info->maxover<val)return(1);
  99619. if(y-info->maxunder>val)return(1);
  99620. }
  99621. while(++x<x1){
  99622. err=err+ady;
  99623. if(err>=adx){
  99624. err-=adx;
  99625. y+=sy;
  99626. }else{
  99627. y+=base;
  99628. }
  99629. val=vorbis_dBquant(mask+x);
  99630. mse+=((y-val)*(y-val));
  99631. n++;
  99632. if(mdct[x]+info->twofitatten>=mask[x]){
  99633. if(val){
  99634. if(y+info->maxover<val)return(1);
  99635. if(y-info->maxunder>val)return(1);
  99636. }
  99637. }
  99638. }
  99639. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99640. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99641. if(mse/n>info->maxerr)return(1);
  99642. return(0);
  99643. }
  99644. static int post_Y(int *A,int *B,int pos){
  99645. if(A[pos]<0)
  99646. return B[pos];
  99647. if(B[pos]<0)
  99648. return A[pos];
  99649. return (A[pos]+B[pos])>>1;
  99650. }
  99651. int *floor1_fit(vorbis_block *vb,void *look_,
  99652. const float *logmdct, /* in */
  99653. const float *logmask){
  99654. long i,j;
  99655. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99656. vorbis_info_floor1 *info=look->vi;
  99657. long n=look->n;
  99658. long posts=look->posts;
  99659. long nonzero=0;
  99660. lsfit_acc fits[VIF_POSIT+1];
  99661. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99662. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99663. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99664. int hineighbor[VIF_POSIT+2];
  99665. int *output=NULL;
  99666. int memo[VIF_POSIT+2];
  99667. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99668. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99669. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99670. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99671. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99672. if(posts==0){
  99673. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99674. }else{
  99675. for(i=0;i<posts-1;i++)
  99676. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99677. look->sorted_index[i+1],fits+i,
  99678. n,info);
  99679. }
  99680. if(nonzero){
  99681. int y0=-200;
  99682. int y1=-200;
  99683. fit_line(fits,posts-1,&y0,&y1);
  99684. fit_valueA[0]=y0;
  99685. fit_valueB[0]=y0;
  99686. fit_valueB[1]=y1;
  99687. fit_valueA[1]=y1;
  99688. for(i=2;i<posts;i++){
  99689. int sortpos=look->reverse_index[i];
  99690. int ln=loneighbor[sortpos];
  99691. int hn=hineighbor[sortpos];
  99692. if(memo[ln]!=hn){
  99693. int lsortpos=look->reverse_index[ln];
  99694. int hsortpos=look->reverse_index[hn];
  99695. memo[ln]=hn;
  99696. {
  99697. int lx=info->postlist[ln];
  99698. int hx=info->postlist[hn];
  99699. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99700. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99701. if(ly==-1 || hy==-1){
  99702. exit(1);
  99703. }
  99704. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99705. int ly0=-200;
  99706. int ly1=-200;
  99707. int hy0=-200;
  99708. int hy1=-200;
  99709. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99710. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99711. fit_valueB[ln]=ly0;
  99712. if(ln==0)fit_valueA[ln]=ly0;
  99713. fit_valueA[i]=ly1;
  99714. fit_valueB[i]=hy0;
  99715. fit_valueA[hn]=hy1;
  99716. if(hn==1)fit_valueB[hn]=hy1;
  99717. if(ly1>=0 || hy0>=0){
  99718. for(j=sortpos-1;j>=0;j--)
  99719. if(hineighbor[j]==hn)
  99720. hineighbor[j]=i;
  99721. else
  99722. break;
  99723. for(j=sortpos+1;j<posts;j++)
  99724. if(loneighbor[j]==ln)
  99725. loneighbor[j]=i;
  99726. else
  99727. break;
  99728. }
  99729. }else{
  99730. fit_valueA[i]=-200;
  99731. fit_valueB[i]=-200;
  99732. }
  99733. }
  99734. }
  99735. }
  99736. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99737. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99738. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99739. for(i=2;i<posts;i++){
  99740. int ln=look->loneighbor[i-2];
  99741. int hn=look->hineighbor[i-2];
  99742. int x0=info->postlist[ln];
  99743. int x1=info->postlist[hn];
  99744. int y0=output[ln];
  99745. int y1=output[hn];
  99746. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99747. int vx=post_Y(fit_valueA,fit_valueB,i);
  99748. if(vx>=0 && predicted!=vx){
  99749. output[i]=vx;
  99750. }else{
  99751. output[i]= predicted|0x8000;
  99752. }
  99753. }
  99754. }
  99755. return(output);
  99756. }
  99757. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99758. int *A,int *B,
  99759. int del){
  99760. long i;
  99761. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99762. long posts=look->posts;
  99763. int *output=NULL;
  99764. if(A && B){
  99765. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99766. for(i=0;i<posts;i++){
  99767. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99768. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99769. }
  99770. }
  99771. return(output);
  99772. }
  99773. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99774. void*look_,
  99775. int *post,int *ilogmask){
  99776. long i,j;
  99777. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99778. vorbis_info_floor1 *info=look->vi;
  99779. long posts=look->posts;
  99780. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99781. int out[VIF_POSIT+2];
  99782. static_codebook **sbooks=ci->book_param;
  99783. codebook *books=ci->fullbooks;
  99784. static long seq=0;
  99785. if(post){
  99786. for(i=0;i<posts;i++){
  99787. int val=post[i]&0x7fff;
  99788. switch(info->mult){
  99789. case 1: /* 1024 -> 256 */
  99790. val>>=2;
  99791. break;
  99792. case 2: /* 1024 -> 128 */
  99793. val>>=3;
  99794. break;
  99795. case 3: /* 1024 -> 86 */
  99796. val/=12;
  99797. break;
  99798. case 4: /* 1024 -> 64 */
  99799. val>>=4;
  99800. break;
  99801. }
  99802. post[i]=val | (post[i]&0x8000);
  99803. }
  99804. out[0]=post[0];
  99805. out[1]=post[1];
  99806. for(i=2;i<posts;i++){
  99807. int ln=look->loneighbor[i-2];
  99808. int hn=look->hineighbor[i-2];
  99809. int x0=info->postlist[ln];
  99810. int x1=info->postlist[hn];
  99811. int y0=post[ln];
  99812. int y1=post[hn];
  99813. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99814. if((post[i]&0x8000) || (predicted==post[i])){
  99815. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99816. in interpolation */
  99817. out[i]=0;
  99818. }else{
  99819. int headroom=(look->quant_q-predicted<predicted?
  99820. look->quant_q-predicted:predicted);
  99821. int val=post[i]-predicted;
  99822. if(val<0)
  99823. if(val<-headroom)
  99824. val=headroom-val-1;
  99825. else
  99826. val=-1-(val<<1);
  99827. else
  99828. if(val>=headroom)
  99829. val= val+headroom;
  99830. else
  99831. val<<=1;
  99832. out[i]=val;
  99833. post[ln]&=0x7fff;
  99834. post[hn]&=0x7fff;
  99835. }
  99836. }
  99837. oggpack_write(opb,1,1);
  99838. look->frames++;
  99839. look->postbits+=ilog(look->quant_q-1)*2;
  99840. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99841. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99842. for(i=0,j=2;i<info->partitions;i++){
  99843. int classx=info->partitionclass[i];
  99844. int cdim=info->class_dim[classx];
  99845. int csubbits=info->class_subs[classx];
  99846. int csub=1<<csubbits;
  99847. int bookas[8]={0,0,0,0,0,0,0,0};
  99848. int cval=0;
  99849. int cshift=0;
  99850. int k,l;
  99851. if(csubbits){
  99852. int maxval[8];
  99853. for(k=0;k<csub;k++){
  99854. int booknum=info->class_subbook[classx][k];
  99855. if(booknum<0){
  99856. maxval[k]=1;
  99857. }else{
  99858. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99859. }
  99860. }
  99861. for(k=0;k<cdim;k++){
  99862. for(l=0;l<csub;l++){
  99863. int val=out[j+k];
  99864. if(val<maxval[l]){
  99865. bookas[k]=l;
  99866. break;
  99867. }
  99868. }
  99869. cval|= bookas[k]<<cshift;
  99870. cshift+=csubbits;
  99871. }
  99872. look->phrasebits+=
  99873. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99874. #ifdef TRAIN_FLOOR1
  99875. {
  99876. FILE *of;
  99877. char buffer[80];
  99878. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99879. vb->pcmend/2,posts-2,class);
  99880. of=fopen(buffer,"a");
  99881. fprintf(of,"%d\n",cval);
  99882. fclose(of);
  99883. }
  99884. #endif
  99885. }
  99886. for(k=0;k<cdim;k++){
  99887. int book=info->class_subbook[classx][bookas[k]];
  99888. if(book>=0){
  99889. if(out[j+k]<(books+book)->entries)
  99890. look->postbits+=vorbis_book_encode(books+book,
  99891. out[j+k],opb);
  99892. #ifdef TRAIN_FLOOR1
  99893. {
  99894. FILE *of;
  99895. char buffer[80];
  99896. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99897. vb->pcmend/2,posts-2,class,bookas[k]);
  99898. of=fopen(buffer,"a");
  99899. fprintf(of,"%d\n",out[j+k]);
  99900. fclose(of);
  99901. }
  99902. #endif
  99903. }
  99904. }
  99905. j+=cdim;
  99906. }
  99907. {
  99908. int hx=0;
  99909. int lx=0;
  99910. int ly=post[0]*info->mult;
  99911. for(j=1;j<look->posts;j++){
  99912. int current=look->forward_index[j];
  99913. int hy=post[current]&0x7fff;
  99914. if(hy==post[current]){
  99915. hy*=info->mult;
  99916. hx=info->postlist[current];
  99917. render_line0(lx,hx,ly,hy,ilogmask);
  99918. lx=hx;
  99919. ly=hy;
  99920. }
  99921. }
  99922. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99923. seq++;
  99924. return(1);
  99925. }
  99926. }else{
  99927. oggpack_write(opb,0,1);
  99928. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99929. seq++;
  99930. return(0);
  99931. }
  99932. }
  99933. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99934. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99935. vorbis_info_floor1 *info=look->vi;
  99936. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99937. int i,j,k;
  99938. codebook *books=ci->fullbooks;
  99939. if(oggpack_read(&vb->opb,1)==1){
  99940. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  99941. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99942. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99943. for(i=0,j=2;i<info->partitions;i++){
  99944. int classx=info->partitionclass[i];
  99945. int cdim=info->class_dim[classx];
  99946. int csubbits=info->class_subs[classx];
  99947. int csub=1<<csubbits;
  99948. int cval=0;
  99949. if(csubbits){
  99950. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  99951. if(cval==-1)goto eop;
  99952. }
  99953. for(k=0;k<cdim;k++){
  99954. int book=info->class_subbook[classx][cval&(csub-1)];
  99955. cval>>=csubbits;
  99956. if(book>=0){
  99957. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  99958. goto eop;
  99959. }else{
  99960. fit_value[j+k]=0;
  99961. }
  99962. }
  99963. j+=cdim;
  99964. }
  99965. for(i=2;i<look->posts;i++){
  99966. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  99967. info->postlist[look->hineighbor[i-2]],
  99968. fit_value[look->loneighbor[i-2]],
  99969. fit_value[look->hineighbor[i-2]],
  99970. info->postlist[i]);
  99971. int hiroom=look->quant_q-predicted;
  99972. int loroom=predicted;
  99973. int room=(hiroom<loroom?hiroom:loroom)<<1;
  99974. int val=fit_value[i];
  99975. if(val){
  99976. if(val>=room){
  99977. if(hiroom>loroom){
  99978. val = val-loroom;
  99979. }else{
  99980. val = -1-(val-hiroom);
  99981. }
  99982. }else{
  99983. if(val&1){
  99984. val= -((val+1)>>1);
  99985. }else{
  99986. val>>=1;
  99987. }
  99988. }
  99989. fit_value[i]=val+predicted;
  99990. fit_value[look->loneighbor[i-2]]&=0x7fff;
  99991. fit_value[look->hineighbor[i-2]]&=0x7fff;
  99992. }else{
  99993. fit_value[i]=predicted|0x8000;
  99994. }
  99995. }
  99996. return(fit_value);
  99997. }
  99998. eop:
  99999. return(NULL);
  100000. }
  100001. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  100002. float *out){
  100003. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100004. vorbis_info_floor1 *info=look->vi;
  100005. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100006. int n=ci->blocksizes[vb->W]/2;
  100007. int j;
  100008. if(memo){
  100009. int *fit_value=(int *)memo;
  100010. int hx=0;
  100011. int lx=0;
  100012. int ly=fit_value[0]*info->mult;
  100013. for(j=1;j<look->posts;j++){
  100014. int current=look->forward_index[j];
  100015. int hy=fit_value[current]&0x7fff;
  100016. if(hy==fit_value[current]){
  100017. hy*=info->mult;
  100018. hx=info->postlist[current];
  100019. render_line(lx,hx,ly,hy,out);
  100020. lx=hx;
  100021. ly=hy;
  100022. }
  100023. }
  100024. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100025. return(1);
  100026. }
  100027. memset(out,0,sizeof(*out)*n);
  100028. return(0);
  100029. }
  100030. vorbis_func_floor floor1_exportbundle={
  100031. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100032. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100033. };
  100034. #endif
  100035. /*** End of inlined file: floor1.c ***/
  100036. /*** Start of inlined file: info.c ***/
  100037. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100038. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100039. // tasks..
  100040. #if JUCE_MSVC
  100041. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100042. #endif
  100043. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100044. #if JUCE_USE_OGGVORBIS
  100045. #include <stdlib.h>
  100046. #include <string.h>
  100047. #include <ctype.h>
  100048. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100049. while(bytes--){
  100050. oggpack_write(o,*s++,8);
  100051. }
  100052. }
  100053. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100054. while(bytes--){
  100055. *buf++=oggpack_read(o,8);
  100056. }
  100057. }
  100058. void vorbis_comment_init(vorbis_comment *vc){
  100059. memset(vc,0,sizeof(*vc));
  100060. }
  100061. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100062. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100063. (vc->comments+2)*sizeof(*vc->user_comments));
  100064. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100065. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100066. vc->comment_lengths[vc->comments]=strlen(comment);
  100067. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100068. strcpy(vc->user_comments[vc->comments], comment);
  100069. vc->comments++;
  100070. vc->user_comments[vc->comments]=NULL;
  100071. }
  100072. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100073. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100074. strcpy(comment, tag);
  100075. strcat(comment, "=");
  100076. strcat(comment, contents);
  100077. vorbis_comment_add(vc, comment);
  100078. }
  100079. static int tagcompare(const char *s1, const char *s2, int n){
  100080. int c=0;
  100081. while(c < n){
  100082. if(toupper(s1[c]) != toupper(s2[c]))
  100083. return !0;
  100084. c++;
  100085. }
  100086. return 0;
  100087. }
  100088. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100089. long i;
  100090. int found = 0;
  100091. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100092. char *fulltag = (char*)alloca(taglen+ 1);
  100093. strcpy(fulltag, tag);
  100094. strcat(fulltag, "=");
  100095. for(i=0;i<vc->comments;i++){
  100096. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100097. if(count == found)
  100098. return vc->user_comments[i] + taglen;
  100099. else
  100100. found++;
  100101. }
  100102. }
  100103. return NULL; /* didn't find anything */
  100104. }
  100105. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100106. int i,count=0;
  100107. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100108. char *fulltag = (char*)alloca(taglen+1);
  100109. strcpy(fulltag,tag);
  100110. strcat(fulltag, "=");
  100111. for(i=0;i<vc->comments;i++){
  100112. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100113. count++;
  100114. }
  100115. return count;
  100116. }
  100117. void vorbis_comment_clear(vorbis_comment *vc){
  100118. if(vc){
  100119. long i;
  100120. for(i=0;i<vc->comments;i++)
  100121. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100122. if(vc->user_comments)_ogg_free(vc->user_comments);
  100123. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100124. if(vc->vendor)_ogg_free(vc->vendor);
  100125. }
  100126. memset(vc,0,sizeof(*vc));
  100127. }
  100128. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100129. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100130. return ci ? ci->blocksizes[zo] : -1;
  100131. }
  100132. void vorbis_info_init(vorbis_info *vi){
  100133. memset(vi,0,sizeof(*vi));
  100134. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100135. }
  100136. void vorbis_info_clear(vorbis_info *vi){
  100137. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100138. int i;
  100139. if(ci){
  100140. for(i=0;i<ci->modes;i++)
  100141. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100142. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100143. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100144. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100145. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100146. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100147. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100148. for(i=0;i<ci->books;i++){
  100149. if(ci->book_param[i]){
  100150. vorbis_staticbook_destroy(ci->book_param[i]);
  100151. }
  100152. if(ci->fullbooks)
  100153. vorbis_book_clear(ci->fullbooks+i);
  100154. }
  100155. if(ci->fullbooks)
  100156. _ogg_free(ci->fullbooks);
  100157. for(i=0;i<ci->psys;i++)
  100158. _vi_psy_free(ci->psy_param[i]);
  100159. _ogg_free(ci);
  100160. }
  100161. memset(vi,0,sizeof(*vi));
  100162. }
  100163. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100164. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100165. if(!ci)return(OV_EFAULT);
  100166. vi->version=oggpack_read(opb,32);
  100167. if(vi->version!=0)return(OV_EVERSION);
  100168. vi->channels=oggpack_read(opb,8);
  100169. vi->rate=oggpack_read(opb,32);
  100170. vi->bitrate_upper=oggpack_read(opb,32);
  100171. vi->bitrate_nominal=oggpack_read(opb,32);
  100172. vi->bitrate_lower=oggpack_read(opb,32);
  100173. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100174. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100175. if(vi->rate<1)goto err_out;
  100176. if(vi->channels<1)goto err_out;
  100177. if(ci->blocksizes[0]<8)goto err_out;
  100178. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100179. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100180. return(0);
  100181. err_out:
  100182. vorbis_info_clear(vi);
  100183. return(OV_EBADHEADER);
  100184. }
  100185. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100186. int i;
  100187. int vendorlen=oggpack_read(opb,32);
  100188. if(vendorlen<0)goto err_out;
  100189. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100190. _v_readstring(opb,vc->vendor,vendorlen);
  100191. vc->comments=oggpack_read(opb,32);
  100192. if(vc->comments<0)goto err_out;
  100193. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100194. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100195. for(i=0;i<vc->comments;i++){
  100196. int len=oggpack_read(opb,32);
  100197. if(len<0)goto err_out;
  100198. vc->comment_lengths[i]=len;
  100199. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100200. _v_readstring(opb,vc->user_comments[i],len);
  100201. }
  100202. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100203. return(0);
  100204. err_out:
  100205. vorbis_comment_clear(vc);
  100206. return(OV_EBADHEADER);
  100207. }
  100208. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100209. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100210. int i;
  100211. if(!ci)return(OV_EFAULT);
  100212. ci->books=oggpack_read(opb,8)+1;
  100213. for(i=0;i<ci->books;i++){
  100214. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100215. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100216. }
  100217. {
  100218. int times=oggpack_read(opb,6)+1;
  100219. for(i=0;i<times;i++){
  100220. int test=oggpack_read(opb,16);
  100221. if(test<0 || test>=VI_TIMEB)goto err_out;
  100222. }
  100223. }
  100224. ci->floors=oggpack_read(opb,6)+1;
  100225. for(i=0;i<ci->floors;i++){
  100226. ci->floor_type[i]=oggpack_read(opb,16);
  100227. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100228. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100229. if(!ci->floor_param[i])goto err_out;
  100230. }
  100231. ci->residues=oggpack_read(opb,6)+1;
  100232. for(i=0;i<ci->residues;i++){
  100233. ci->residue_type[i]=oggpack_read(opb,16);
  100234. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100235. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100236. if(!ci->residue_param[i])goto err_out;
  100237. }
  100238. ci->maps=oggpack_read(opb,6)+1;
  100239. for(i=0;i<ci->maps;i++){
  100240. ci->map_type[i]=oggpack_read(opb,16);
  100241. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100242. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100243. if(!ci->map_param[i])goto err_out;
  100244. }
  100245. ci->modes=oggpack_read(opb,6)+1;
  100246. for(i=0;i<ci->modes;i++){
  100247. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100248. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100249. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100250. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100251. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100252. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100253. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100254. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100255. }
  100256. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100257. return(0);
  100258. err_out:
  100259. vorbis_info_clear(vi);
  100260. return(OV_EBADHEADER);
  100261. }
  100262. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100263. oggpack_buffer opb;
  100264. if(op){
  100265. oggpack_readinit(&opb,op->packet,op->bytes);
  100266. {
  100267. char buffer[6];
  100268. int packtype=oggpack_read(&opb,8);
  100269. memset(buffer,0,6);
  100270. _v_readstring(&opb,buffer,6);
  100271. if(memcmp(buffer,"vorbis",6)){
  100272. return(OV_ENOTVORBIS);
  100273. }
  100274. switch(packtype){
  100275. case 0x01: /* least significant *bit* is read first */
  100276. if(!op->b_o_s){
  100277. return(OV_EBADHEADER);
  100278. }
  100279. if(vi->rate!=0){
  100280. return(OV_EBADHEADER);
  100281. }
  100282. return(_vorbis_unpack_info(vi,&opb));
  100283. case 0x03: /* least significant *bit* is read first */
  100284. if(vi->rate==0){
  100285. return(OV_EBADHEADER);
  100286. }
  100287. return(_vorbis_unpack_comment(vc,&opb));
  100288. case 0x05: /* least significant *bit* is read first */
  100289. if(vi->rate==0 || vc->vendor==NULL){
  100290. return(OV_EBADHEADER);
  100291. }
  100292. return(_vorbis_unpack_books(vi,&opb));
  100293. default:
  100294. return(OV_EBADHEADER);
  100295. break;
  100296. }
  100297. }
  100298. }
  100299. return(OV_EBADHEADER);
  100300. }
  100301. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100302. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100303. if(!ci)return(OV_EFAULT);
  100304. oggpack_write(opb,0x01,8);
  100305. _v_writestring(opb,"vorbis", 6);
  100306. oggpack_write(opb,0x00,32);
  100307. oggpack_write(opb,vi->channels,8);
  100308. oggpack_write(opb,vi->rate,32);
  100309. oggpack_write(opb,vi->bitrate_upper,32);
  100310. oggpack_write(opb,vi->bitrate_nominal,32);
  100311. oggpack_write(opb,vi->bitrate_lower,32);
  100312. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100313. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100314. oggpack_write(opb,1,1);
  100315. return(0);
  100316. }
  100317. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100318. char temp[]="Xiph.Org libVorbis I 20050304";
  100319. int bytes = strlen(temp);
  100320. oggpack_write(opb,0x03,8);
  100321. _v_writestring(opb,"vorbis", 6);
  100322. oggpack_write(opb,bytes,32);
  100323. _v_writestring(opb,temp, bytes);
  100324. oggpack_write(opb,vc->comments,32);
  100325. if(vc->comments){
  100326. int i;
  100327. for(i=0;i<vc->comments;i++){
  100328. if(vc->user_comments[i]){
  100329. oggpack_write(opb,vc->comment_lengths[i],32);
  100330. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100331. }else{
  100332. oggpack_write(opb,0,32);
  100333. }
  100334. }
  100335. }
  100336. oggpack_write(opb,1,1);
  100337. return(0);
  100338. }
  100339. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100340. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100341. int i;
  100342. if(!ci)return(OV_EFAULT);
  100343. oggpack_write(opb,0x05,8);
  100344. _v_writestring(opb,"vorbis", 6);
  100345. oggpack_write(opb,ci->books-1,8);
  100346. for(i=0;i<ci->books;i++)
  100347. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100348. oggpack_write(opb,0,6);
  100349. oggpack_write(opb,0,16);
  100350. oggpack_write(opb,ci->floors-1,6);
  100351. for(i=0;i<ci->floors;i++){
  100352. oggpack_write(opb,ci->floor_type[i],16);
  100353. if(_floor_P[ci->floor_type[i]]->pack)
  100354. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100355. else
  100356. goto err_out;
  100357. }
  100358. oggpack_write(opb,ci->residues-1,6);
  100359. for(i=0;i<ci->residues;i++){
  100360. oggpack_write(opb,ci->residue_type[i],16);
  100361. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100362. }
  100363. oggpack_write(opb,ci->maps-1,6);
  100364. for(i=0;i<ci->maps;i++){
  100365. oggpack_write(opb,ci->map_type[i],16);
  100366. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100367. }
  100368. oggpack_write(opb,ci->modes-1,6);
  100369. for(i=0;i<ci->modes;i++){
  100370. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100371. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100372. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100373. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100374. }
  100375. oggpack_write(opb,1,1);
  100376. return(0);
  100377. err_out:
  100378. return(-1);
  100379. }
  100380. int vorbis_commentheader_out(vorbis_comment *vc,
  100381. ogg_packet *op){
  100382. oggpack_buffer opb;
  100383. oggpack_writeinit(&opb);
  100384. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100385. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100386. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100387. op->bytes=oggpack_bytes(&opb);
  100388. op->b_o_s=0;
  100389. op->e_o_s=0;
  100390. op->granulepos=0;
  100391. op->packetno=1;
  100392. return 0;
  100393. }
  100394. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100395. vorbis_comment *vc,
  100396. ogg_packet *op,
  100397. ogg_packet *op_comm,
  100398. ogg_packet *op_code){
  100399. int ret=OV_EIMPL;
  100400. vorbis_info *vi=v->vi;
  100401. oggpack_buffer opb;
  100402. private_state *b=(private_state*)v->backend_state;
  100403. if(!b){
  100404. ret=OV_EFAULT;
  100405. goto err_out;
  100406. }
  100407. oggpack_writeinit(&opb);
  100408. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100409. if(b->header)_ogg_free(b->header);
  100410. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100411. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100412. op->packet=b->header;
  100413. op->bytes=oggpack_bytes(&opb);
  100414. op->b_o_s=1;
  100415. op->e_o_s=0;
  100416. op->granulepos=0;
  100417. op->packetno=0;
  100418. oggpack_reset(&opb);
  100419. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100420. if(b->header1)_ogg_free(b->header1);
  100421. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100422. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100423. op_comm->packet=b->header1;
  100424. op_comm->bytes=oggpack_bytes(&opb);
  100425. op_comm->b_o_s=0;
  100426. op_comm->e_o_s=0;
  100427. op_comm->granulepos=0;
  100428. op_comm->packetno=1;
  100429. oggpack_reset(&opb);
  100430. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100431. if(b->header2)_ogg_free(b->header2);
  100432. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100433. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100434. op_code->packet=b->header2;
  100435. op_code->bytes=oggpack_bytes(&opb);
  100436. op_code->b_o_s=0;
  100437. op_code->e_o_s=0;
  100438. op_code->granulepos=0;
  100439. op_code->packetno=2;
  100440. oggpack_writeclear(&opb);
  100441. return(0);
  100442. err_out:
  100443. oggpack_writeclear(&opb);
  100444. memset(op,0,sizeof(*op));
  100445. memset(op_comm,0,sizeof(*op_comm));
  100446. memset(op_code,0,sizeof(*op_code));
  100447. if(b->header)_ogg_free(b->header);
  100448. if(b->header1)_ogg_free(b->header1);
  100449. if(b->header2)_ogg_free(b->header2);
  100450. b->header=NULL;
  100451. b->header1=NULL;
  100452. b->header2=NULL;
  100453. return(ret);
  100454. }
  100455. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100456. if(granulepos>=0)
  100457. return((double)granulepos/v->vi->rate);
  100458. return(-1);
  100459. }
  100460. #endif
  100461. /*** End of inlined file: info.c ***/
  100462. /*** Start of inlined file: lpc.c ***/
  100463. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100464. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100465. // tasks..
  100466. #if JUCE_MSVC
  100467. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100468. #endif
  100469. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100470. #if JUCE_USE_OGGVORBIS
  100471. #include <stdlib.h>
  100472. #include <string.h>
  100473. #include <math.h>
  100474. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100475. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100476. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100477. double error;
  100478. int i,j;
  100479. j=m+1;
  100480. while(j--){
  100481. double d=0; /* double needed for accumulator depth */
  100482. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100483. aut[j]=d;
  100484. }
  100485. error=aut[0];
  100486. for(i=0;i<m;i++){
  100487. double r= -aut[i+1];
  100488. if(error==0){
  100489. memset(lpci,0,m*sizeof(*lpci));
  100490. return 0;
  100491. }
  100492. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100493. r/=error;
  100494. lpc[i]=r;
  100495. for(j=0;j<i/2;j++){
  100496. double tmp=lpc[j];
  100497. lpc[j]+=r*lpc[i-1-j];
  100498. lpc[i-1-j]+=r*tmp;
  100499. }
  100500. if(i%2)lpc[j]+=lpc[j]*r;
  100501. error*=1.f-r*r;
  100502. }
  100503. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100504. return error;
  100505. }
  100506. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100507. float *data,long n){
  100508. long i,j,o,p;
  100509. float y;
  100510. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100511. if(!prime)
  100512. for(i=0;i<m;i++)
  100513. work[i]=0.f;
  100514. else
  100515. for(i=0;i<m;i++)
  100516. work[i]=prime[i];
  100517. for(i=0;i<n;i++){
  100518. y=0;
  100519. o=i;
  100520. p=m;
  100521. for(j=0;j<m;j++)
  100522. y-=work[o++]*coeff[--p];
  100523. data[i]=work[o]=y;
  100524. }
  100525. }
  100526. #endif
  100527. /*** End of inlined file: lpc.c ***/
  100528. /*** Start of inlined file: lsp.c ***/
  100529. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100530. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100531. // tasks..
  100532. #if JUCE_MSVC
  100533. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100534. #endif
  100535. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100536. #if JUCE_USE_OGGVORBIS
  100537. #include <math.h>
  100538. #include <string.h>
  100539. #include <stdlib.h>
  100540. /*** Start of inlined file: lookup.h ***/
  100541. #ifndef _V_LOOKUP_H_
  100542. #ifdef FLOAT_LOOKUP
  100543. extern float vorbis_coslook(float a);
  100544. extern float vorbis_invsqlook(float a);
  100545. extern float vorbis_invsq2explook(int a);
  100546. extern float vorbis_fromdBlook(float a);
  100547. #endif
  100548. #ifdef INT_LOOKUP
  100549. extern long vorbis_invsqlook_i(long a,long e);
  100550. extern long vorbis_coslook_i(long a);
  100551. extern float vorbis_fromdBlook_i(long a);
  100552. #endif
  100553. #endif
  100554. /*** End of inlined file: lookup.h ***/
  100555. #define FLOAT_LOOKUP
  100556. #undef INT_LOOKUP
  100557. #ifdef FLOAT_LOOKUP
  100558. /*** Start of inlined file: lookup.c ***/
  100559. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100560. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100561. // tasks..
  100562. #if JUCE_MSVC
  100563. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100564. #endif
  100565. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100566. #if JUCE_USE_OGGVORBIS
  100567. #include <math.h>
  100568. /*** Start of inlined file: lookup.h ***/
  100569. #ifndef _V_LOOKUP_H_
  100570. #ifdef FLOAT_LOOKUP
  100571. extern float vorbis_coslook(float a);
  100572. extern float vorbis_invsqlook(float a);
  100573. extern float vorbis_invsq2explook(int a);
  100574. extern float vorbis_fromdBlook(float a);
  100575. #endif
  100576. #ifdef INT_LOOKUP
  100577. extern long vorbis_invsqlook_i(long a,long e);
  100578. extern long vorbis_coslook_i(long a);
  100579. extern float vorbis_fromdBlook_i(long a);
  100580. #endif
  100581. #endif
  100582. /*** End of inlined file: lookup.h ***/
  100583. /*** Start of inlined file: lookup_data.h ***/
  100584. #ifndef _V_LOOKUP_DATA_H_
  100585. #ifdef FLOAT_LOOKUP
  100586. #define COS_LOOKUP_SZ 128
  100587. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100588. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100589. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100590. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100591. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100592. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100593. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100594. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100595. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100596. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100597. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100598. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100599. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100600. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100601. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100602. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100603. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100604. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100605. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100606. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100607. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100608. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100609. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100610. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100611. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100612. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100613. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100614. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100615. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100616. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100617. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100618. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100619. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100620. -1.0000000000000f,
  100621. };
  100622. #define INVSQ_LOOKUP_SZ 32
  100623. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100624. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100625. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100626. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100627. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100628. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100629. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100630. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100631. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100632. 1.000000000000f,
  100633. };
  100634. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100635. #define INVSQ2EXP_LOOKUP_MAX 32
  100636. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100637. INVSQ2EXP_LOOKUP_MIN+1]={
  100638. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100639. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100640. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100641. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100642. 256.f, 181.019336f, 128.f, 90.50966799f,
  100643. 64.f, 45.254834f, 32.f, 22.627417f,
  100644. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100645. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100646. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100647. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100648. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100649. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100650. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100651. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100652. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100653. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100654. 1.525878906e-05f,
  100655. };
  100656. #endif
  100657. #define FROMdB_LOOKUP_SZ 35
  100658. #define FROMdB2_LOOKUP_SZ 32
  100659. #define FROMdB_SHIFT 5
  100660. #define FROMdB2_SHIFT 3
  100661. #define FROMdB2_MASK 31
  100662. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100663. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100664. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100665. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100666. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100667. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100668. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100669. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100670. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100671. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100672. };
  100673. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100674. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100675. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100676. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100677. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100678. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100679. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100680. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100681. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100682. };
  100683. #ifdef INT_LOOKUP
  100684. #define INVSQ_LOOKUP_I_SHIFT 10
  100685. #define INVSQ_LOOKUP_I_MASK 1023
  100686. static long INVSQ_LOOKUP_I[64+1]={
  100687. 92682l, 91966l, 91267l, 90583l,
  100688. 89915l, 89261l, 88621l, 87995l,
  100689. 87381l, 86781l, 86192l, 85616l,
  100690. 85051l, 84497l, 83953l, 83420l,
  100691. 82897l, 82384l, 81880l, 81385l,
  100692. 80899l, 80422l, 79953l, 79492l,
  100693. 79039l, 78594l, 78156l, 77726l,
  100694. 77302l, 76885l, 76475l, 76072l,
  100695. 75674l, 75283l, 74898l, 74519l,
  100696. 74146l, 73778l, 73415l, 73058l,
  100697. 72706l, 72359l, 72016l, 71679l,
  100698. 71347l, 71019l, 70695l, 70376l,
  100699. 70061l, 69750l, 69444l, 69141l,
  100700. 68842l, 68548l, 68256l, 67969l,
  100701. 67685l, 67405l, 67128l, 66855l,
  100702. 66585l, 66318l, 66054l, 65794l,
  100703. 65536l,
  100704. };
  100705. #define COS_LOOKUP_I_SHIFT 9
  100706. #define COS_LOOKUP_I_MASK 511
  100707. #define COS_LOOKUP_I_SZ 128
  100708. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100709. 16384l, 16379l, 16364l, 16340l,
  100710. 16305l, 16261l, 16207l, 16143l,
  100711. 16069l, 15986l, 15893l, 15791l,
  100712. 15679l, 15557l, 15426l, 15286l,
  100713. 15137l, 14978l, 14811l, 14635l,
  100714. 14449l, 14256l, 14053l, 13842l,
  100715. 13623l, 13395l, 13160l, 12916l,
  100716. 12665l, 12406l, 12140l, 11866l,
  100717. 11585l, 11297l, 11003l, 10702l,
  100718. 10394l, 10080l, 9760l, 9434l,
  100719. 9102l, 8765l, 8423l, 8076l,
  100720. 7723l, 7366l, 7005l, 6639l,
  100721. 6270l, 5897l, 5520l, 5139l,
  100722. 4756l, 4370l, 3981l, 3590l,
  100723. 3196l, 2801l, 2404l, 2006l,
  100724. 1606l, 1205l, 804l, 402l,
  100725. 0l, -401l, -803l, -1204l,
  100726. -1605l, -2005l, -2403l, -2800l,
  100727. -3195l, -3589l, -3980l, -4369l,
  100728. -4755l, -5138l, -5519l, -5896l,
  100729. -6269l, -6638l, -7004l, -7365l,
  100730. -7722l, -8075l, -8422l, -8764l,
  100731. -9101l, -9433l, -9759l, -10079l,
  100732. -10393l, -10701l, -11002l, -11296l,
  100733. -11584l, -11865l, -12139l, -12405l,
  100734. -12664l, -12915l, -13159l, -13394l,
  100735. -13622l, -13841l, -14052l, -14255l,
  100736. -14448l, -14634l, -14810l, -14977l,
  100737. -15136l, -15285l, -15425l, -15556l,
  100738. -15678l, -15790l, -15892l, -15985l,
  100739. -16068l, -16142l, -16206l, -16260l,
  100740. -16304l, -16339l, -16363l, -16378l,
  100741. -16383l,
  100742. };
  100743. #endif
  100744. #endif
  100745. /*** End of inlined file: lookup_data.h ***/
  100746. #ifdef FLOAT_LOOKUP
  100747. float vorbis_coslook(float a){
  100748. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100749. int i=vorbis_ftoi(d-.5);
  100750. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100751. }
  100752. float vorbis_invsqlook(float a){
  100753. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100754. int i=vorbis_ftoi(d-.5f);
  100755. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100756. }
  100757. float vorbis_invsq2explook(int a){
  100758. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100759. }
  100760. #include <stdio.h>
  100761. float vorbis_fromdBlook(float a){
  100762. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100763. return (i<0)?1.f:
  100764. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100765. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100766. }
  100767. #endif
  100768. #ifdef INT_LOOKUP
  100769. long vorbis_invsqlook_i(long a,long e){
  100770. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100771. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100772. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100773. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100774. d)>>16); /* result 1.16 */
  100775. e+=32;
  100776. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100777. e=(e>>1)-8;
  100778. return(val>>e);
  100779. }
  100780. float vorbis_fromdBlook_i(long a){
  100781. int i=(-a)>>(12-FROMdB2_SHIFT);
  100782. return (i<0)?1.f:
  100783. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100784. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100785. }
  100786. long vorbis_coslook_i(long a){
  100787. int i=a>>COS_LOOKUP_I_SHIFT;
  100788. int d=a&COS_LOOKUP_I_MASK;
  100789. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100790. COS_LOOKUP_I_SHIFT);
  100791. }
  100792. #endif
  100793. #endif
  100794. /*** End of inlined file: lookup.c ***/
  100795. /* catch this in the build system; we #include for
  100796. compilers (like gcc) that can't inline across
  100797. modules */
  100798. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100799. float amp,float ampoffset){
  100800. int i;
  100801. float wdel=M_PI/ln;
  100802. vorbis_fpu_control fpu;
  100803. (void) fpu; // to avoid an unused variable warning
  100804. vorbis_fpu_setround(&fpu);
  100805. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100806. i=0;
  100807. while(i<n){
  100808. int k=map[i];
  100809. int qexp;
  100810. float p=.7071067812f;
  100811. float q=.7071067812f;
  100812. float w=vorbis_coslook(wdel*k);
  100813. float *ftmp=lsp;
  100814. int c=m>>1;
  100815. do{
  100816. q*=ftmp[0]-w;
  100817. p*=ftmp[1]-w;
  100818. ftmp+=2;
  100819. }while(--c);
  100820. if(m&1){
  100821. q*=ftmp[0]-w;
  100822. q*=q;
  100823. p*=p*(1.f-w*w);
  100824. }else{
  100825. q*=q*(1.f+w);
  100826. p*=p*(1.f-w);
  100827. }
  100828. q=frexp(p+q,&qexp);
  100829. q=vorbis_fromdBlook(amp*
  100830. vorbis_invsqlook(q)*
  100831. vorbis_invsq2explook(qexp+m)-
  100832. ampoffset);
  100833. do{
  100834. curve[i++]*=q;
  100835. }while(map[i]==k);
  100836. }
  100837. vorbis_fpu_restore(fpu);
  100838. }
  100839. #else
  100840. #ifdef INT_LOOKUP
  100841. /*** Start of inlined file: lookup.c ***/
  100842. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100843. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100844. // tasks..
  100845. #if JUCE_MSVC
  100846. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100847. #endif
  100848. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100849. #if JUCE_USE_OGGVORBIS
  100850. #include <math.h>
  100851. /*** Start of inlined file: lookup.h ***/
  100852. #ifndef _V_LOOKUP_H_
  100853. #ifdef FLOAT_LOOKUP
  100854. extern float vorbis_coslook(float a);
  100855. extern float vorbis_invsqlook(float a);
  100856. extern float vorbis_invsq2explook(int a);
  100857. extern float vorbis_fromdBlook(float a);
  100858. #endif
  100859. #ifdef INT_LOOKUP
  100860. extern long vorbis_invsqlook_i(long a,long e);
  100861. extern long vorbis_coslook_i(long a);
  100862. extern float vorbis_fromdBlook_i(long a);
  100863. #endif
  100864. #endif
  100865. /*** End of inlined file: lookup.h ***/
  100866. /*** Start of inlined file: lookup_data.h ***/
  100867. #ifndef _V_LOOKUP_DATA_H_
  100868. #ifdef FLOAT_LOOKUP
  100869. #define COS_LOOKUP_SZ 128
  100870. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100871. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100872. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100873. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100874. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100875. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100876. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100877. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100878. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100879. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100880. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100881. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100882. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100883. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100884. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100885. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100886. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100887. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100888. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100889. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100890. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100891. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100892. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100893. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100894. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100895. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100896. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100897. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100898. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100899. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100900. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100901. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100902. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100903. -1.0000000000000f,
  100904. };
  100905. #define INVSQ_LOOKUP_SZ 32
  100906. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100907. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100908. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100909. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100910. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100911. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100912. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100913. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100914. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100915. 1.000000000000f,
  100916. };
  100917. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100918. #define INVSQ2EXP_LOOKUP_MAX 32
  100919. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100920. INVSQ2EXP_LOOKUP_MIN+1]={
  100921. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100922. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100923. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100924. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100925. 256.f, 181.019336f, 128.f, 90.50966799f,
  100926. 64.f, 45.254834f, 32.f, 22.627417f,
  100927. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100928. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100929. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100930. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100931. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100932. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100933. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100934. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100935. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100936. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100937. 1.525878906e-05f,
  100938. };
  100939. #endif
  100940. #define FROMdB_LOOKUP_SZ 35
  100941. #define FROMdB2_LOOKUP_SZ 32
  100942. #define FROMdB_SHIFT 5
  100943. #define FROMdB2_SHIFT 3
  100944. #define FROMdB2_MASK 31
  100945. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100946. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100947. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100948. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100949. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100950. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100951. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100952. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100953. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100954. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100955. };
  100956. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100957. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100958. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100959. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100960. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100961. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100962. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100963. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100964. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100965. };
  100966. #ifdef INT_LOOKUP
  100967. #define INVSQ_LOOKUP_I_SHIFT 10
  100968. #define INVSQ_LOOKUP_I_MASK 1023
  100969. static long INVSQ_LOOKUP_I[64+1]={
  100970. 92682l, 91966l, 91267l, 90583l,
  100971. 89915l, 89261l, 88621l, 87995l,
  100972. 87381l, 86781l, 86192l, 85616l,
  100973. 85051l, 84497l, 83953l, 83420l,
  100974. 82897l, 82384l, 81880l, 81385l,
  100975. 80899l, 80422l, 79953l, 79492l,
  100976. 79039l, 78594l, 78156l, 77726l,
  100977. 77302l, 76885l, 76475l, 76072l,
  100978. 75674l, 75283l, 74898l, 74519l,
  100979. 74146l, 73778l, 73415l, 73058l,
  100980. 72706l, 72359l, 72016l, 71679l,
  100981. 71347l, 71019l, 70695l, 70376l,
  100982. 70061l, 69750l, 69444l, 69141l,
  100983. 68842l, 68548l, 68256l, 67969l,
  100984. 67685l, 67405l, 67128l, 66855l,
  100985. 66585l, 66318l, 66054l, 65794l,
  100986. 65536l,
  100987. };
  100988. #define COS_LOOKUP_I_SHIFT 9
  100989. #define COS_LOOKUP_I_MASK 511
  100990. #define COS_LOOKUP_I_SZ 128
  100991. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100992. 16384l, 16379l, 16364l, 16340l,
  100993. 16305l, 16261l, 16207l, 16143l,
  100994. 16069l, 15986l, 15893l, 15791l,
  100995. 15679l, 15557l, 15426l, 15286l,
  100996. 15137l, 14978l, 14811l, 14635l,
  100997. 14449l, 14256l, 14053l, 13842l,
  100998. 13623l, 13395l, 13160l, 12916l,
  100999. 12665l, 12406l, 12140l, 11866l,
  101000. 11585l, 11297l, 11003l, 10702l,
  101001. 10394l, 10080l, 9760l, 9434l,
  101002. 9102l, 8765l, 8423l, 8076l,
  101003. 7723l, 7366l, 7005l, 6639l,
  101004. 6270l, 5897l, 5520l, 5139l,
  101005. 4756l, 4370l, 3981l, 3590l,
  101006. 3196l, 2801l, 2404l, 2006l,
  101007. 1606l, 1205l, 804l, 402l,
  101008. 0l, -401l, -803l, -1204l,
  101009. -1605l, -2005l, -2403l, -2800l,
  101010. -3195l, -3589l, -3980l, -4369l,
  101011. -4755l, -5138l, -5519l, -5896l,
  101012. -6269l, -6638l, -7004l, -7365l,
  101013. -7722l, -8075l, -8422l, -8764l,
  101014. -9101l, -9433l, -9759l, -10079l,
  101015. -10393l, -10701l, -11002l, -11296l,
  101016. -11584l, -11865l, -12139l, -12405l,
  101017. -12664l, -12915l, -13159l, -13394l,
  101018. -13622l, -13841l, -14052l, -14255l,
  101019. -14448l, -14634l, -14810l, -14977l,
  101020. -15136l, -15285l, -15425l, -15556l,
  101021. -15678l, -15790l, -15892l, -15985l,
  101022. -16068l, -16142l, -16206l, -16260l,
  101023. -16304l, -16339l, -16363l, -16378l,
  101024. -16383l,
  101025. };
  101026. #endif
  101027. #endif
  101028. /*** End of inlined file: lookup_data.h ***/
  101029. #ifdef FLOAT_LOOKUP
  101030. float vorbis_coslook(float a){
  101031. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101032. int i=vorbis_ftoi(d-.5);
  101033. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101034. }
  101035. float vorbis_invsqlook(float a){
  101036. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101037. int i=vorbis_ftoi(d-.5f);
  101038. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101039. }
  101040. float vorbis_invsq2explook(int a){
  101041. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101042. }
  101043. #include <stdio.h>
  101044. float vorbis_fromdBlook(float a){
  101045. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101046. return (i<0)?1.f:
  101047. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101048. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101049. }
  101050. #endif
  101051. #ifdef INT_LOOKUP
  101052. long vorbis_invsqlook_i(long a,long e){
  101053. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101054. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101055. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101056. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101057. d)>>16); /* result 1.16 */
  101058. e+=32;
  101059. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101060. e=(e>>1)-8;
  101061. return(val>>e);
  101062. }
  101063. float vorbis_fromdBlook_i(long a){
  101064. int i=(-a)>>(12-FROMdB2_SHIFT);
  101065. return (i<0)?1.f:
  101066. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101067. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101068. }
  101069. long vorbis_coslook_i(long a){
  101070. int i=a>>COS_LOOKUP_I_SHIFT;
  101071. int d=a&COS_LOOKUP_I_MASK;
  101072. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101073. COS_LOOKUP_I_SHIFT);
  101074. }
  101075. #endif
  101076. #endif
  101077. /*** End of inlined file: lookup.c ***/
  101078. /* catch this in the build system; we #include for
  101079. compilers (like gcc) that can't inline across
  101080. modules */
  101081. static int MLOOP_1[64]={
  101082. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101083. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101084. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101085. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101086. };
  101087. static int MLOOP_2[64]={
  101088. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101089. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101090. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101091. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101092. };
  101093. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101094. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101095. float amp,float ampoffset){
  101096. int i;
  101097. int ampoffseti=rint(ampoffset*4096.f);
  101098. int ampi=rint(amp*16.f);
  101099. long *ilsp=alloca(m*sizeof(*ilsp));
  101100. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101101. i=0;
  101102. while(i<n){
  101103. int j,k=map[i];
  101104. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101105. unsigned long qi=46341;
  101106. int qexp=0,shift;
  101107. long wi=vorbis_coslook_i(k*65536/ln);
  101108. qi*=labs(ilsp[0]-wi);
  101109. pi*=labs(ilsp[1]-wi);
  101110. for(j=3;j<m;j+=2){
  101111. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101112. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101113. shift=MLOOP_3[(pi|qi)>>16];
  101114. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101115. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101116. qexp+=shift;
  101117. }
  101118. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101119. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101120. shift=MLOOP_3[(pi|qi)>>16];
  101121. if(m&1){
  101122. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101123. pi=(pi>>shift)<<14;
  101124. qexp+=shift;
  101125. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101126. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101127. shift=MLOOP_3[(pi|qi)>>16];
  101128. pi>>=shift;
  101129. qi>>=shift;
  101130. qexp+=shift-14*((m+1)>>1);
  101131. pi=((pi*pi)>>16);
  101132. qi=((qi*qi)>>16);
  101133. qexp=qexp*2+m;
  101134. pi*=(1<<14)-((wi*wi)>>14);
  101135. qi+=pi>>14;
  101136. }else{
  101137. pi>>=shift;
  101138. qi>>=shift;
  101139. qexp+=shift-7*m;
  101140. pi=((pi*pi)>>16);
  101141. qi=((qi*qi)>>16);
  101142. qexp=qexp*2+m;
  101143. pi*=(1<<14)-wi;
  101144. qi*=(1<<14)+wi;
  101145. qi=(qi+pi)>>14;
  101146. }
  101147. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101148. qi>>=1; qexp++;
  101149. }else
  101150. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101151. qi<<=1; qexp--;
  101152. }
  101153. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101154. vorbis_invsqlook_i(qi,qexp)-
  101155. ampoffseti); /* 8.12[0] */
  101156. curve[i]*=amp;
  101157. while(map[++i]==k)curve[i]*=amp;
  101158. }
  101159. }
  101160. #else
  101161. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101162. float amp,float ampoffset){
  101163. int i;
  101164. float wdel=M_PI/ln;
  101165. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101166. i=0;
  101167. while(i<n){
  101168. int j,k=map[i];
  101169. float p=.5f;
  101170. float q=.5f;
  101171. float w=2.f*cos(wdel*k);
  101172. for(j=1;j<m;j+=2){
  101173. q *= w-lsp[j-1];
  101174. p *= w-lsp[j];
  101175. }
  101176. if(j==m){
  101177. q*=w-lsp[j-1];
  101178. p*=p*(4.f-w*w);
  101179. q*=q;
  101180. }else{
  101181. p*=p*(2.f-w);
  101182. q*=q*(2.f+w);
  101183. }
  101184. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101185. curve[i]*=q;
  101186. while(map[++i]==k)curve[i]*=q;
  101187. }
  101188. }
  101189. #endif
  101190. #endif
  101191. static void cheby(float *g, int ord) {
  101192. int i, j;
  101193. g[0] *= .5f;
  101194. for(i=2; i<= ord; i++) {
  101195. for(j=ord; j >= i; j--) {
  101196. g[j-2] -= g[j];
  101197. g[j] += g[j];
  101198. }
  101199. }
  101200. }
  101201. static int comp(const void *a,const void *b){
  101202. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101203. }
  101204. #define EPSILON 10e-7
  101205. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101206. int i,m;
  101207. double lastdelta=0.f;
  101208. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101209. for(i=0;i<=ord;i++)defl[i]=a[i];
  101210. for(m=ord;m>0;m--){
  101211. double newx=0.f,delta;
  101212. while(1){
  101213. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101214. for(i=m;i>0;i--){
  101215. ppp = newx*ppp + pp;
  101216. pp = newx*pp + p;
  101217. p = newx*p + defl[i-1];
  101218. }
  101219. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101220. if(denom<0)
  101221. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101222. if(pp>0){
  101223. denom = pp + sqrt(denom);
  101224. if(denom<EPSILON)denom=EPSILON;
  101225. }else{
  101226. denom = pp - sqrt(denom);
  101227. if(denom>-(EPSILON))denom=-(EPSILON);
  101228. }
  101229. delta = m*p/denom;
  101230. newx -= delta;
  101231. if(delta<0.f)delta*=-1;
  101232. if(fabs(delta/newx)<10e-12)break;
  101233. lastdelta=delta;
  101234. }
  101235. r[m-1]=newx;
  101236. for(i=m;i>0;i--)
  101237. defl[i-1]+=newx*defl[i];
  101238. defl++;
  101239. }
  101240. return(0);
  101241. }
  101242. static int Newton_Raphson(float *a,int ord,float *r){
  101243. int i, k, count=0;
  101244. double error=1.f;
  101245. double *root=(double*)alloca(ord*sizeof(*root));
  101246. for(i=0; i<ord;i++) root[i] = r[i];
  101247. while(error>1e-20){
  101248. error=0;
  101249. for(i=0; i<ord; i++) { /* Update each point. */
  101250. double pp=0.,delta;
  101251. double rooti=root[i];
  101252. double p=a[ord];
  101253. for(k=ord-1; k>= 0; k--) {
  101254. pp= pp* rooti + p;
  101255. p = p * rooti + a[k];
  101256. }
  101257. delta = p/pp;
  101258. root[i] -= delta;
  101259. error+= delta*delta;
  101260. }
  101261. if(count>40)return(-1);
  101262. count++;
  101263. }
  101264. for(i=0; i<ord;i++) r[i] = root[i];
  101265. return(0);
  101266. }
  101267. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101268. int order2=(m+1)>>1;
  101269. int g1_order,g2_order;
  101270. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101271. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101272. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101273. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101274. int i;
  101275. g1_order=(m+1)>>1;
  101276. g2_order=(m) >>1;
  101277. g1[g1_order] = 1.f;
  101278. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101279. g2[g2_order] = 1.f;
  101280. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101281. if(g1_order>g2_order){
  101282. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101283. }else{
  101284. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101285. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101286. }
  101287. cheby(g1,g1_order);
  101288. cheby(g2,g2_order);
  101289. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101290. Laguerre_With_Deflation(g2,g2_order,g2r))
  101291. return(-1);
  101292. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101293. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101294. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101295. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101296. for(i=0;i<g1_order;i++)
  101297. lsp[i*2] = acos(g1r[i]);
  101298. for(i=0;i<g2_order;i++)
  101299. lsp[i*2+1] = acos(g2r[i]);
  101300. return(0);
  101301. }
  101302. #endif
  101303. /*** End of inlined file: lsp.c ***/
  101304. /*** Start of inlined file: mapping0.c ***/
  101305. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101306. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101307. // tasks..
  101308. #if JUCE_MSVC
  101309. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101310. #endif
  101311. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101312. #if JUCE_USE_OGGVORBIS
  101313. #include <stdlib.h>
  101314. #include <stdio.h>
  101315. #include <string.h>
  101316. #include <math.h>
  101317. static void mapping0_free_info(vorbis_info_mapping *i){
  101318. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101319. if(info){
  101320. memset(info,0,sizeof(*info));
  101321. _ogg_free(info);
  101322. }
  101323. }
  101324. static int ilog3(unsigned int v){
  101325. int ret=0;
  101326. if(v)--v;
  101327. while(v){
  101328. ret++;
  101329. v>>=1;
  101330. }
  101331. return(ret);
  101332. }
  101333. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101334. oggpack_buffer *opb){
  101335. int i;
  101336. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101337. if(info->submaps>1){
  101338. oggpack_write(opb,1,1);
  101339. oggpack_write(opb,info->submaps-1,4);
  101340. }else
  101341. oggpack_write(opb,0,1);
  101342. if(info->coupling_steps>0){
  101343. oggpack_write(opb,1,1);
  101344. oggpack_write(opb,info->coupling_steps-1,8);
  101345. for(i=0;i<info->coupling_steps;i++){
  101346. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101347. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101348. }
  101349. }else
  101350. oggpack_write(opb,0,1);
  101351. oggpack_write(opb,0,2); /* 2,3:reserved */
  101352. if(info->submaps>1){
  101353. for(i=0;i<vi->channels;i++)
  101354. oggpack_write(opb,info->chmuxlist[i],4);
  101355. }
  101356. for(i=0;i<info->submaps;i++){
  101357. oggpack_write(opb,0,8); /* time submap unused */
  101358. oggpack_write(opb,info->floorsubmap[i],8);
  101359. oggpack_write(opb,info->residuesubmap[i],8);
  101360. }
  101361. }
  101362. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101363. int i;
  101364. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101365. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101366. memset(info,0,sizeof(*info));
  101367. if(oggpack_read(opb,1))
  101368. info->submaps=oggpack_read(opb,4)+1;
  101369. else
  101370. info->submaps=1;
  101371. if(oggpack_read(opb,1)){
  101372. info->coupling_steps=oggpack_read(opb,8)+1;
  101373. for(i=0;i<info->coupling_steps;i++){
  101374. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101375. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101376. if(testM<0 ||
  101377. testA<0 ||
  101378. testM==testA ||
  101379. testM>=vi->channels ||
  101380. testA>=vi->channels) goto err_out;
  101381. }
  101382. }
  101383. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101384. if(info->submaps>1){
  101385. for(i=0;i<vi->channels;i++){
  101386. info->chmuxlist[i]=oggpack_read(opb,4);
  101387. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101388. }
  101389. }
  101390. for(i=0;i<info->submaps;i++){
  101391. oggpack_read(opb,8); /* time submap unused */
  101392. info->floorsubmap[i]=oggpack_read(opb,8);
  101393. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101394. info->residuesubmap[i]=oggpack_read(opb,8);
  101395. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101396. }
  101397. return info;
  101398. err_out:
  101399. mapping0_free_info(info);
  101400. return(NULL);
  101401. }
  101402. #if 0
  101403. static long seq=0;
  101404. static ogg_int64_t total=0;
  101405. static float FLOOR1_fromdB_LOOKUP[256]={
  101406. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101407. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101408. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101409. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101410. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101411. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101412. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101413. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101414. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101415. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101416. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101417. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101418. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101419. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101420. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101421. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101422. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101423. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101424. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101425. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101426. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101427. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101428. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101429. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101430. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101431. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101432. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101433. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101434. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101435. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101436. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101437. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101438. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101439. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101440. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101441. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101442. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101443. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101444. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101445. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101446. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101447. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101448. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101449. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101450. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101451. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101452. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101453. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101454. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101455. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101456. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101457. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101458. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101459. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101460. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101461. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101462. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101463. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101464. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101465. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101466. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101467. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101468. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101469. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101470. };
  101471. #endif
  101472. extern int *floor1_fit(vorbis_block *vb,void *look,
  101473. const float *logmdct, /* in */
  101474. const float *logmask);
  101475. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101476. int *A,int *B,
  101477. int del);
  101478. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101479. void*look,
  101480. int *post,int *ilogmask);
  101481. static int mapping0_forward(vorbis_block *vb){
  101482. vorbis_dsp_state *vd=vb->vd;
  101483. vorbis_info *vi=vd->vi;
  101484. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101485. private_state *b=(private_state*)vb->vd->backend_state;
  101486. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101487. int n=vb->pcmend;
  101488. int i,j,k;
  101489. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101490. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101491. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101492. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101493. float global_ampmax=vbi->ampmax;
  101494. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101495. int blocktype=vbi->blocktype;
  101496. int modenumber=vb->W;
  101497. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101498. vorbis_look_psy *psy_look=
  101499. b->psy+blocktype+(vb->W?2:0);
  101500. vb->mode=modenumber;
  101501. for(i=0;i<vi->channels;i++){
  101502. float scale=4.f/n;
  101503. float scale_dB;
  101504. float *pcm =vb->pcm[i];
  101505. float *logfft =pcm;
  101506. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101507. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101508. todB estimation used on IEEE 754
  101509. compliant machines had a bug that
  101510. returned dB values about a third
  101511. of a decibel too high. The bug
  101512. was harmless because tunings
  101513. implicitly took that into
  101514. account. However, fixing the bug
  101515. in the estimator requires
  101516. changing all the tunings as well.
  101517. For now, it's easier to sync
  101518. things back up here, and
  101519. recalibrate the tunings in the
  101520. next major model upgrade. */
  101521. #if 0
  101522. if(vi->channels==2)
  101523. if(i==0)
  101524. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101525. else
  101526. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101527. #endif
  101528. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101529. #if 0
  101530. if(vi->channels==2)
  101531. if(i==0)
  101532. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101533. else
  101534. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101535. #endif
  101536. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101537. drft_forward(&b->fft_look[vb->W],pcm);
  101538. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101539. original todB estimation used on
  101540. IEEE 754 compliant machines had a
  101541. bug that returned dB values about
  101542. a third of a decibel too high.
  101543. The bug was harmless because
  101544. tunings implicitly took that into
  101545. account. However, fixing the bug
  101546. in the estimator requires
  101547. changing all the tunings as well.
  101548. For now, it's easier to sync
  101549. things back up here, and
  101550. recalibrate the tunings in the
  101551. next major model upgrade. */
  101552. local_ampmax[i]=logfft[0];
  101553. for(j=1;j<n-1;j+=2){
  101554. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101555. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101556. .345 is a hack; the original todB
  101557. estimation used on IEEE 754
  101558. compliant machines had a bug that
  101559. returned dB values about a third
  101560. of a decibel too high. The bug
  101561. was harmless because tunings
  101562. implicitly took that into
  101563. account. However, fixing the bug
  101564. in the estimator requires
  101565. changing all the tunings as well.
  101566. For now, it's easier to sync
  101567. things back up here, and
  101568. recalibrate the tunings in the
  101569. next major model upgrade. */
  101570. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101571. }
  101572. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101573. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101574. #if 0
  101575. if(vi->channels==2){
  101576. if(i==0){
  101577. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101578. }else{
  101579. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101580. }
  101581. }
  101582. #endif
  101583. }
  101584. {
  101585. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101586. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101587. for(i=0;i<vi->channels;i++){
  101588. int submap=info->chmuxlist[i];
  101589. float *mdct =gmdct[i];
  101590. float *logfft =vb->pcm[i];
  101591. float *logmdct =logfft+n/2;
  101592. float *logmask =logfft;
  101593. vb->mode=modenumber;
  101594. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101595. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101596. for(j=0;j<n/2;j++)
  101597. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101598. todB estimation used on IEEE 754
  101599. compliant machines had a bug that
  101600. returned dB values about a third
  101601. of a decibel too high. The bug
  101602. was harmless because tunings
  101603. implicitly took that into
  101604. account. However, fixing the bug
  101605. in the estimator requires
  101606. changing all the tunings as well.
  101607. For now, it's easier to sync
  101608. things back up here, and
  101609. recalibrate the tunings in the
  101610. next major model upgrade. */
  101611. #if 0
  101612. if(vi->channels==2){
  101613. if(i==0)
  101614. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101615. else
  101616. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101617. }else{
  101618. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101619. }
  101620. #endif
  101621. _vp_noisemask(psy_look,
  101622. logmdct,
  101623. noise); /* noise does not have by-frequency offset
  101624. bias applied yet */
  101625. #if 0
  101626. if(vi->channels==2){
  101627. if(i==0)
  101628. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101629. else
  101630. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101631. }
  101632. #endif
  101633. _vp_tonemask(psy_look,
  101634. logfft,
  101635. tone,
  101636. global_ampmax,
  101637. local_ampmax[i]);
  101638. #if 0
  101639. if(vi->channels==2){
  101640. if(i==0)
  101641. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101642. else
  101643. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101644. }
  101645. #endif
  101646. #if 0
  101647. {
  101648. float aotuv[psy_look->n];
  101649. #endif
  101650. _vp_offset_and_mix(psy_look,
  101651. noise,
  101652. tone,
  101653. 1,
  101654. logmask,
  101655. mdct,
  101656. logmdct);
  101657. #if 0
  101658. if(vi->channels==2){
  101659. if(i==0)
  101660. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101661. else
  101662. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101663. }
  101664. }
  101665. #endif
  101666. #if 0
  101667. if(vi->channels==2){
  101668. if(i==0)
  101669. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101670. else
  101671. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101672. }
  101673. #endif
  101674. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101675. floor_posts[i][PACKETBLOBS/2]=
  101676. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101677. logmdct,
  101678. logmask);
  101679. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101680. _vp_offset_and_mix(psy_look,
  101681. noise,
  101682. tone,
  101683. 2,
  101684. logmask,
  101685. mdct,
  101686. logmdct);
  101687. #if 0
  101688. if(vi->channels==2){
  101689. if(i==0)
  101690. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101691. else
  101692. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101693. }
  101694. #endif
  101695. floor_posts[i][PACKETBLOBS-1]=
  101696. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101697. logmdct,
  101698. logmask);
  101699. _vp_offset_and_mix(psy_look,
  101700. noise,
  101701. tone,
  101702. 0,
  101703. logmask,
  101704. mdct,
  101705. logmdct);
  101706. #if 0
  101707. if(vi->channels==2)
  101708. if(i==0)
  101709. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101710. else
  101711. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101712. #endif
  101713. floor_posts[i][0]=
  101714. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101715. logmdct,
  101716. logmask);
  101717. for(k=1;k<PACKETBLOBS/2;k++)
  101718. floor_posts[i][k]=
  101719. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101720. floor_posts[i][0],
  101721. floor_posts[i][PACKETBLOBS/2],
  101722. k*65536/(PACKETBLOBS/2));
  101723. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101724. floor_posts[i][k]=
  101725. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101726. floor_posts[i][PACKETBLOBS/2],
  101727. floor_posts[i][PACKETBLOBS-1],
  101728. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101729. }
  101730. }
  101731. }
  101732. vbi->ampmax=global_ampmax;
  101733. {
  101734. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101735. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101736. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101737. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101738. float **mag_memo;
  101739. int **mag_sort;
  101740. if(info->coupling_steps){
  101741. mag_memo=_vp_quantize_couple_memo(vb,
  101742. &ci->psy_g_param,
  101743. psy_look,
  101744. info,
  101745. gmdct);
  101746. mag_sort=_vp_quantize_couple_sort(vb,
  101747. psy_look,
  101748. info,
  101749. mag_memo);
  101750. hf_reduction(&ci->psy_g_param,
  101751. psy_look,
  101752. info,
  101753. mag_memo);
  101754. }
  101755. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101756. if(psy_look->vi->normal_channel_p){
  101757. for(i=0;i<vi->channels;i++){
  101758. float *mdct =gmdct[i];
  101759. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101760. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101761. }
  101762. }
  101763. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101764. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101765. k++){
  101766. oggpack_buffer *opb=vbi->packetblob[k];
  101767. oggpack_write(opb,0,1);
  101768. oggpack_write(opb,modenumber,b->modebits);
  101769. if(vb->W){
  101770. oggpack_write(opb,vb->lW,1);
  101771. oggpack_write(opb,vb->nW,1);
  101772. }
  101773. for(i=0;i<vi->channels;i++){
  101774. int submap=info->chmuxlist[i];
  101775. float *mdct =gmdct[i];
  101776. float *res =vb->pcm[i];
  101777. int *ilogmask=ilogmaskch[i]=
  101778. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101779. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101780. floor_posts[i][k],
  101781. ilogmask);
  101782. #if 0
  101783. {
  101784. char buf[80];
  101785. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101786. float work[n/2];
  101787. for(j=0;j<n/2;j++)
  101788. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101789. _analysis_output(buf,seq,work,n/2,1,1,0);
  101790. }
  101791. #endif
  101792. _vp_remove_floor(psy_look,
  101793. mdct,
  101794. ilogmask,
  101795. res,
  101796. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101797. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101798. #if 0
  101799. {
  101800. char buf[80];
  101801. float work[n/2];
  101802. for(j=0;j<n/2;j++)
  101803. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101804. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101805. _analysis_output(buf,seq,work,n/2,1,1,0);
  101806. }
  101807. #endif
  101808. }
  101809. if(info->coupling_steps){
  101810. _vp_couple(k,
  101811. &ci->psy_g_param,
  101812. psy_look,
  101813. info,
  101814. vb->pcm,
  101815. mag_memo,
  101816. mag_sort,
  101817. ilogmaskch,
  101818. nonzero,
  101819. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101820. }
  101821. for(i=0;i<info->submaps;i++){
  101822. int ch_in_bundle=0;
  101823. long **classifications;
  101824. int resnum=info->residuesubmap[i];
  101825. for(j=0;j<vi->channels;j++){
  101826. if(info->chmuxlist[j]==i){
  101827. zerobundle[ch_in_bundle]=0;
  101828. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101829. res_bundle[ch_in_bundle]=vb->pcm[j];
  101830. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101831. }
  101832. }
  101833. classifications=_residue_P[ci->residue_type[resnum]]->
  101834. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101835. _residue_P[ci->residue_type[resnum]]->
  101836. forward(opb,vb,b->residue[resnum],
  101837. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101838. }
  101839. }
  101840. }
  101841. #if 0
  101842. seq++;
  101843. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101844. #endif
  101845. return(0);
  101846. }
  101847. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101848. vorbis_dsp_state *vd=vb->vd;
  101849. vorbis_info *vi=vd->vi;
  101850. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101851. private_state *b=(private_state*)vd->backend_state;
  101852. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101853. int i,j;
  101854. long n=vb->pcmend=ci->blocksizes[vb->W];
  101855. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101856. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101857. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101858. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101859. for(i=0;i<vi->channels;i++){
  101860. int submap=info->chmuxlist[i];
  101861. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101862. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101863. if(floormemo[i])
  101864. nonzero[i]=1;
  101865. else
  101866. nonzero[i]=0;
  101867. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101868. }
  101869. for(i=0;i<info->coupling_steps;i++){
  101870. if(nonzero[info->coupling_mag[i]] ||
  101871. nonzero[info->coupling_ang[i]]){
  101872. nonzero[info->coupling_mag[i]]=1;
  101873. nonzero[info->coupling_ang[i]]=1;
  101874. }
  101875. }
  101876. for(i=0;i<info->submaps;i++){
  101877. int ch_in_bundle=0;
  101878. for(j=0;j<vi->channels;j++){
  101879. if(info->chmuxlist[j]==i){
  101880. if(nonzero[j])
  101881. zerobundle[ch_in_bundle]=1;
  101882. else
  101883. zerobundle[ch_in_bundle]=0;
  101884. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101885. }
  101886. }
  101887. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101888. inverse(vb,b->residue[info->residuesubmap[i]],
  101889. pcmbundle,zerobundle,ch_in_bundle);
  101890. }
  101891. for(i=info->coupling_steps-1;i>=0;i--){
  101892. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101893. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101894. for(j=0;j<n/2;j++){
  101895. float mag=pcmM[j];
  101896. float ang=pcmA[j];
  101897. if(mag>0)
  101898. if(ang>0){
  101899. pcmM[j]=mag;
  101900. pcmA[j]=mag-ang;
  101901. }else{
  101902. pcmA[j]=mag;
  101903. pcmM[j]=mag+ang;
  101904. }
  101905. else
  101906. if(ang>0){
  101907. pcmM[j]=mag;
  101908. pcmA[j]=mag+ang;
  101909. }else{
  101910. pcmA[j]=mag;
  101911. pcmM[j]=mag-ang;
  101912. }
  101913. }
  101914. }
  101915. for(i=0;i<vi->channels;i++){
  101916. float *pcm=vb->pcm[i];
  101917. int submap=info->chmuxlist[i];
  101918. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101919. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101920. floormemo[i],pcm);
  101921. }
  101922. for(i=0;i<vi->channels;i++){
  101923. float *pcm=vb->pcm[i];
  101924. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101925. }
  101926. return(0);
  101927. }
  101928. vorbis_func_mapping mapping0_exportbundle={
  101929. &mapping0_pack,
  101930. &mapping0_unpack,
  101931. &mapping0_free_info,
  101932. &mapping0_forward,
  101933. &mapping0_inverse
  101934. };
  101935. #endif
  101936. /*** End of inlined file: mapping0.c ***/
  101937. /*** Start of inlined file: mdct.c ***/
  101938. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101939. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101940. // tasks..
  101941. #if JUCE_MSVC
  101942. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101943. #endif
  101944. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101945. #if JUCE_USE_OGGVORBIS
  101946. #include <stdio.h>
  101947. #include <stdlib.h>
  101948. #include <string.h>
  101949. #include <math.h>
  101950. void mdct_init(mdct_lookup *lookup,int n){
  101951. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  101952. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  101953. int i;
  101954. int n2=n>>1;
  101955. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  101956. lookup->n=n;
  101957. lookup->trig=T;
  101958. lookup->bitrev=bitrev;
  101959. for(i=0;i<n/4;i++){
  101960. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  101961. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  101962. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  101963. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  101964. }
  101965. for(i=0;i<n/8;i++){
  101966. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  101967. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  101968. }
  101969. {
  101970. int mask=(1<<(log2n-1))-1,i,j;
  101971. int msb=1<<(log2n-2);
  101972. for(i=0;i<n/8;i++){
  101973. int acc=0;
  101974. for(j=0;msb>>j;j++)
  101975. if((msb>>j)&i)acc|=1<<j;
  101976. bitrev[i*2]=((~acc)&mask)-1;
  101977. bitrev[i*2+1]=acc;
  101978. }
  101979. }
  101980. lookup->scale=FLOAT_CONV(4.f/n);
  101981. }
  101982. STIN void mdct_butterfly_8(DATA_TYPE *x){
  101983. REG_TYPE r0 = x[6] + x[2];
  101984. REG_TYPE r1 = x[6] - x[2];
  101985. REG_TYPE r2 = x[4] + x[0];
  101986. REG_TYPE r3 = x[4] - x[0];
  101987. x[6] = r0 + r2;
  101988. x[4] = r0 - r2;
  101989. r0 = x[5] - x[1];
  101990. r2 = x[7] - x[3];
  101991. x[0] = r1 + r0;
  101992. x[2] = r1 - r0;
  101993. r0 = x[5] + x[1];
  101994. r1 = x[7] + x[3];
  101995. x[3] = r2 + r3;
  101996. x[1] = r2 - r3;
  101997. x[7] = r1 + r0;
  101998. x[5] = r1 - r0;
  101999. }
  102000. STIN void mdct_butterfly_16(DATA_TYPE *x){
  102001. REG_TYPE r0 = x[1] - x[9];
  102002. REG_TYPE r1 = x[0] - x[8];
  102003. x[8] += x[0];
  102004. x[9] += x[1];
  102005. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  102006. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  102007. r0 = x[3] - x[11];
  102008. r1 = x[10] - x[2];
  102009. x[10] += x[2];
  102010. x[11] += x[3];
  102011. x[2] = r0;
  102012. x[3] = r1;
  102013. r0 = x[12] - x[4];
  102014. r1 = x[13] - x[5];
  102015. x[12] += x[4];
  102016. x[13] += x[5];
  102017. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  102018. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  102019. r0 = x[14] - x[6];
  102020. r1 = x[15] - x[7];
  102021. x[14] += x[6];
  102022. x[15] += x[7];
  102023. x[6] = r0;
  102024. x[7] = r1;
  102025. mdct_butterfly_8(x);
  102026. mdct_butterfly_8(x+8);
  102027. }
  102028. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102029. REG_TYPE r0 = x[30] - x[14];
  102030. REG_TYPE r1 = x[31] - x[15];
  102031. x[30] += x[14];
  102032. x[31] += x[15];
  102033. x[14] = r0;
  102034. x[15] = r1;
  102035. r0 = x[28] - x[12];
  102036. r1 = x[29] - x[13];
  102037. x[28] += x[12];
  102038. x[29] += x[13];
  102039. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102040. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102041. r0 = x[26] - x[10];
  102042. r1 = x[27] - x[11];
  102043. x[26] += x[10];
  102044. x[27] += x[11];
  102045. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102046. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102047. r0 = x[24] - x[8];
  102048. r1 = x[25] - x[9];
  102049. x[24] += x[8];
  102050. x[25] += x[9];
  102051. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102052. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102053. r0 = x[22] - x[6];
  102054. r1 = x[7] - x[23];
  102055. x[22] += x[6];
  102056. x[23] += x[7];
  102057. x[6] = r1;
  102058. x[7] = r0;
  102059. r0 = x[4] - x[20];
  102060. r1 = x[5] - x[21];
  102061. x[20] += x[4];
  102062. x[21] += x[5];
  102063. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102064. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102065. r0 = x[2] - x[18];
  102066. r1 = x[3] - x[19];
  102067. x[18] += x[2];
  102068. x[19] += x[3];
  102069. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102070. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102071. r0 = x[0] - x[16];
  102072. r1 = x[1] - x[17];
  102073. x[16] += x[0];
  102074. x[17] += x[1];
  102075. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102076. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102077. mdct_butterfly_16(x);
  102078. mdct_butterfly_16(x+16);
  102079. }
  102080. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102081. DATA_TYPE *x,
  102082. int points){
  102083. DATA_TYPE *x1 = x + points - 8;
  102084. DATA_TYPE *x2 = x + (points>>1) - 8;
  102085. REG_TYPE r0;
  102086. REG_TYPE r1;
  102087. do{
  102088. r0 = x1[6] - x2[6];
  102089. r1 = x1[7] - x2[7];
  102090. x1[6] += x2[6];
  102091. x1[7] += x2[7];
  102092. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102093. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102094. r0 = x1[4] - x2[4];
  102095. r1 = x1[5] - x2[5];
  102096. x1[4] += x2[4];
  102097. x1[5] += x2[5];
  102098. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102099. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102100. r0 = x1[2] - x2[2];
  102101. r1 = x1[3] - x2[3];
  102102. x1[2] += x2[2];
  102103. x1[3] += x2[3];
  102104. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102105. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102106. r0 = x1[0] - x2[0];
  102107. r1 = x1[1] - x2[1];
  102108. x1[0] += x2[0];
  102109. x1[1] += x2[1];
  102110. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102111. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102112. x1-=8;
  102113. x2-=8;
  102114. T+=16;
  102115. }while(x2>=x);
  102116. }
  102117. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102118. DATA_TYPE *x,
  102119. int points,
  102120. int trigint){
  102121. DATA_TYPE *x1 = x + points - 8;
  102122. DATA_TYPE *x2 = x + (points>>1) - 8;
  102123. REG_TYPE r0;
  102124. REG_TYPE r1;
  102125. do{
  102126. r0 = x1[6] - x2[6];
  102127. r1 = x1[7] - x2[7];
  102128. x1[6] += x2[6];
  102129. x1[7] += x2[7];
  102130. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102131. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102132. T+=trigint;
  102133. r0 = x1[4] - x2[4];
  102134. r1 = x1[5] - x2[5];
  102135. x1[4] += x2[4];
  102136. x1[5] += x2[5];
  102137. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102138. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102139. T+=trigint;
  102140. r0 = x1[2] - x2[2];
  102141. r1 = x1[3] - x2[3];
  102142. x1[2] += x2[2];
  102143. x1[3] += x2[3];
  102144. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102145. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102146. T+=trigint;
  102147. r0 = x1[0] - x2[0];
  102148. r1 = x1[1] - x2[1];
  102149. x1[0] += x2[0];
  102150. x1[1] += x2[1];
  102151. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102152. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102153. T+=trigint;
  102154. x1-=8;
  102155. x2-=8;
  102156. }while(x2>=x);
  102157. }
  102158. STIN void mdct_butterflies(mdct_lookup *init,
  102159. DATA_TYPE *x,
  102160. int points){
  102161. DATA_TYPE *T=init->trig;
  102162. int stages=init->log2n-5;
  102163. int i,j;
  102164. if(--stages>0){
  102165. mdct_butterfly_first(T,x,points);
  102166. }
  102167. for(i=1;--stages>0;i++){
  102168. for(j=0;j<(1<<i);j++)
  102169. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102170. }
  102171. for(j=0;j<points;j+=32)
  102172. mdct_butterfly_32(x+j);
  102173. }
  102174. void mdct_clear(mdct_lookup *l){
  102175. if(l){
  102176. if(l->trig)_ogg_free(l->trig);
  102177. if(l->bitrev)_ogg_free(l->bitrev);
  102178. memset(l,0,sizeof(*l));
  102179. }
  102180. }
  102181. STIN void mdct_bitreverse(mdct_lookup *init,
  102182. DATA_TYPE *x){
  102183. int n = init->n;
  102184. int *bit = init->bitrev;
  102185. DATA_TYPE *w0 = x;
  102186. DATA_TYPE *w1 = x = w0+(n>>1);
  102187. DATA_TYPE *T = init->trig+n;
  102188. do{
  102189. DATA_TYPE *x0 = x+bit[0];
  102190. DATA_TYPE *x1 = x+bit[1];
  102191. REG_TYPE r0 = x0[1] - x1[1];
  102192. REG_TYPE r1 = x0[0] + x1[0];
  102193. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102194. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102195. w1 -= 4;
  102196. r0 = HALVE(x0[1] + x1[1]);
  102197. r1 = HALVE(x0[0] - x1[0]);
  102198. w0[0] = r0 + r2;
  102199. w1[2] = r0 - r2;
  102200. w0[1] = r1 + r3;
  102201. w1[3] = r3 - r1;
  102202. x0 = x+bit[2];
  102203. x1 = x+bit[3];
  102204. r0 = x0[1] - x1[1];
  102205. r1 = x0[0] + x1[0];
  102206. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102207. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102208. r0 = HALVE(x0[1] + x1[1]);
  102209. r1 = HALVE(x0[0] - x1[0]);
  102210. w0[2] = r0 + r2;
  102211. w1[0] = r0 - r2;
  102212. w0[3] = r1 + r3;
  102213. w1[1] = r3 - r1;
  102214. T += 4;
  102215. bit += 4;
  102216. w0 += 4;
  102217. }while(w0<w1);
  102218. }
  102219. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102220. int n=init->n;
  102221. int n2=n>>1;
  102222. int n4=n>>2;
  102223. DATA_TYPE *iX = in+n2-7;
  102224. DATA_TYPE *oX = out+n2+n4;
  102225. DATA_TYPE *T = init->trig+n4;
  102226. do{
  102227. oX -= 4;
  102228. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102229. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102230. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102231. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102232. iX -= 8;
  102233. T += 4;
  102234. }while(iX>=in);
  102235. iX = in+n2-8;
  102236. oX = out+n2+n4;
  102237. T = init->trig+n4;
  102238. do{
  102239. T -= 4;
  102240. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102241. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102242. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102243. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102244. iX -= 8;
  102245. oX += 4;
  102246. }while(iX>=in);
  102247. mdct_butterflies(init,out+n2,n2);
  102248. mdct_bitreverse(init,out);
  102249. {
  102250. DATA_TYPE *oX1=out+n2+n4;
  102251. DATA_TYPE *oX2=out+n2+n4;
  102252. DATA_TYPE *iX =out;
  102253. T =init->trig+n2;
  102254. do{
  102255. oX1-=4;
  102256. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102257. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102258. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102259. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102260. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102261. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102262. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102263. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102264. oX2+=4;
  102265. iX += 8;
  102266. T += 8;
  102267. }while(iX<oX1);
  102268. iX=out+n2+n4;
  102269. oX1=out+n4;
  102270. oX2=oX1;
  102271. do{
  102272. oX1-=4;
  102273. iX-=4;
  102274. oX2[0] = -(oX1[3] = iX[3]);
  102275. oX2[1] = -(oX1[2] = iX[2]);
  102276. oX2[2] = -(oX1[1] = iX[1]);
  102277. oX2[3] = -(oX1[0] = iX[0]);
  102278. oX2+=4;
  102279. }while(oX2<iX);
  102280. iX=out+n2+n4;
  102281. oX1=out+n2+n4;
  102282. oX2=out+n2;
  102283. do{
  102284. oX1-=4;
  102285. oX1[0]= iX[3];
  102286. oX1[1]= iX[2];
  102287. oX1[2]= iX[1];
  102288. oX1[3]= iX[0];
  102289. iX+=4;
  102290. }while(oX1>oX2);
  102291. }
  102292. }
  102293. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102294. int n=init->n;
  102295. int n2=n>>1;
  102296. int n4=n>>2;
  102297. int n8=n>>3;
  102298. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102299. DATA_TYPE *w2=w+n2;
  102300. REG_TYPE r0;
  102301. REG_TYPE r1;
  102302. DATA_TYPE *x0=in+n2+n4;
  102303. DATA_TYPE *x1=x0+1;
  102304. DATA_TYPE *T=init->trig+n2;
  102305. int i=0;
  102306. for(i=0;i<n8;i+=2){
  102307. x0 -=4;
  102308. T-=2;
  102309. r0= x0[2] + x1[0];
  102310. r1= x0[0] + x1[2];
  102311. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102312. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102313. x1 +=4;
  102314. }
  102315. x1=in+1;
  102316. for(;i<n2-n8;i+=2){
  102317. T-=2;
  102318. x0 -=4;
  102319. r0= x0[2] - x1[0];
  102320. r1= x0[0] - x1[2];
  102321. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102322. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102323. x1 +=4;
  102324. }
  102325. x0=in+n;
  102326. for(;i<n2;i+=2){
  102327. T-=2;
  102328. x0 -=4;
  102329. r0= -x0[2] - x1[0];
  102330. r1= -x0[0] - x1[2];
  102331. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102332. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102333. x1 +=4;
  102334. }
  102335. mdct_butterflies(init,w+n2,n2);
  102336. mdct_bitreverse(init,w);
  102337. T=init->trig+n2;
  102338. x0=out+n2;
  102339. for(i=0;i<n4;i++){
  102340. x0--;
  102341. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102342. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102343. w+=2;
  102344. T+=2;
  102345. }
  102346. }
  102347. #endif
  102348. /*** End of inlined file: mdct.c ***/
  102349. /*** Start of inlined file: psy.c ***/
  102350. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102351. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102352. // tasks..
  102353. #if JUCE_MSVC
  102354. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102355. #endif
  102356. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102357. #if JUCE_USE_OGGVORBIS
  102358. #include <stdlib.h>
  102359. #include <math.h>
  102360. #include <string.h>
  102361. /*** Start of inlined file: masking.h ***/
  102362. #ifndef _V_MASKING_H_
  102363. #define _V_MASKING_H_
  102364. #define MAX_ATH 88
  102365. static float ATH[]={
  102366. -51, -52, -53, -54, -55, -56, -57, -58,
  102367. -59, -60, -61, -62, -63, -64, -65, -66,
  102368. -67, -68, -69, -70, -71, -72, -73, -74,
  102369. -75, -76, -77, -78, -80, -81, -82, -83,
  102370. -84, -85, -86, -87, -88, -88, -89, -89,
  102371. -90, -91, -91, -92, -93, -94, -95, -96,
  102372. -96, -97, -98, -98, -99, -99,-100,-100,
  102373. -101,-102,-103,-104,-106,-107,-107,-107,
  102374. -107,-105,-103,-102,-101, -99, -98, -96,
  102375. -95, -95, -96, -97, -96, -95, -93, -90,
  102376. -80, -70, -50, -40, -30, -30, -30, -30
  102377. };
  102378. #define EHMER_OFFSET 16
  102379. #define EHMER_MAX 56
  102380. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102381. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102382. -60, -60, -60, -60, -62, -62, -65, -73,
  102383. -69, -68, -68, -67, -70, -70, -72, -74,
  102384. -75, -79, -79, -80, -83, -88, -93, -100,
  102385. -110, -999, -999, -999, -999, -999, -999, -999,
  102386. -999, -999, -999, -999, -999, -999, -999, -999,
  102387. -999, -999, -999, -999, -999, -999, -999, -999},
  102388. { -48, -48, -48, -48, -48, -48, -48, -48,
  102389. -48, -48, -48, -48, -48, -53, -61, -66,
  102390. -66, -68, -67, -70, -76, -76, -72, -73,
  102391. -75, -76, -78, -79, -83, -88, -93, -100,
  102392. -110, -999, -999, -999, -999, -999, -999, -999,
  102393. -999, -999, -999, -999, -999, -999, -999, -999,
  102394. -999, -999, -999, -999, -999, -999, -999, -999},
  102395. { -37, -37, -37, -37, -37, -37, -37, -37,
  102396. -38, -40, -42, -46, -48, -53, -55, -62,
  102397. -65, -58, -56, -56, -61, -60, -65, -67,
  102398. -69, -71, -77, -77, -78, -80, -82, -84,
  102399. -88, -93, -98, -106, -112, -999, -999, -999,
  102400. -999, -999, -999, -999, -999, -999, -999, -999,
  102401. -999, -999, -999, -999, -999, -999, -999, -999},
  102402. { -25, -25, -25, -25, -25, -25, -25, -25,
  102403. -25, -26, -27, -29, -32, -38, -48, -52,
  102404. -52, -50, -48, -48, -51, -52, -54, -60,
  102405. -67, -67, -66, -68, -69, -73, -73, -76,
  102406. -80, -81, -81, -85, -85, -86, -88, -93,
  102407. -100, -110, -999, -999, -999, -999, -999, -999,
  102408. -999, -999, -999, -999, -999, -999, -999, -999},
  102409. { -16, -16, -16, -16, -16, -16, -16, -16,
  102410. -17, -19, -20, -22, -26, -28, -31, -40,
  102411. -47, -39, -39, -40, -42, -43, -47, -51,
  102412. -57, -52, -55, -55, -60, -58, -62, -63,
  102413. -70, -67, -69, -72, -73, -77, -80, -82,
  102414. -83, -87, -90, -94, -98, -104, -115, -999,
  102415. -999, -999, -999, -999, -999, -999, -999, -999},
  102416. { -8, -8, -8, -8, -8, -8, -8, -8,
  102417. -8, -8, -10, -11, -15, -19, -25, -30,
  102418. -34, -31, -30, -31, -29, -32, -35, -42,
  102419. -48, -42, -44, -46, -50, -50, -51, -52,
  102420. -59, -54, -55, -55, -58, -62, -63, -66,
  102421. -72, -73, -76, -75, -78, -80, -80, -81,
  102422. -84, -88, -90, -94, -98, -101, -106, -110}},
  102423. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102424. -66, -66, -66, -66, -66, -67, -67, -67,
  102425. -76, -72, -71, -74, -76, -76, -75, -78,
  102426. -79, -79, -81, -83, -86, -89, -93, -97,
  102427. -100, -105, -110, -999, -999, -999, -999, -999,
  102428. -999, -999, -999, -999, -999, -999, -999, -999,
  102429. -999, -999, -999, -999, -999, -999, -999, -999},
  102430. { -47, -47, -47, -47, -47, -47, -47, -47,
  102431. -47, -47, -47, -48, -51, -55, -59, -66,
  102432. -66, -66, -67, -66, -68, -69, -70, -74,
  102433. -79, -77, -77, -78, -80, -81, -82, -84,
  102434. -86, -88, -91, -95, -100, -108, -116, -999,
  102435. -999, -999, -999, -999, -999, -999, -999, -999,
  102436. -999, -999, -999, -999, -999, -999, -999, -999},
  102437. { -36, -36, -36, -36, -36, -36, -36, -36,
  102438. -36, -37, -37, -41, -44, -48, -51, -58,
  102439. -62, -60, -57, -59, -59, -60, -63, -65,
  102440. -72, -71, -70, -72, -74, -77, -76, -78,
  102441. -81, -81, -80, -83, -86, -91, -96, -100,
  102442. -105, -110, -999, -999, -999, -999, -999, -999,
  102443. -999, -999, -999, -999, -999, -999, -999, -999},
  102444. { -28, -28, -28, -28, -28, -28, -28, -28,
  102445. -28, -30, -32, -32, -33, -35, -41, -49,
  102446. -50, -49, -47, -48, -48, -52, -51, -57,
  102447. -65, -61, -59, -61, -64, -69, -70, -74,
  102448. -77, -77, -78, -81, -84, -85, -87, -90,
  102449. -92, -96, -100, -107, -112, -999, -999, -999,
  102450. -999, -999, -999, -999, -999, -999, -999, -999},
  102451. { -19, -19, -19, -19, -19, -19, -19, -19,
  102452. -20, -21, -23, -27, -30, -35, -36, -41,
  102453. -46, -44, -42, -40, -41, -41, -43, -48,
  102454. -55, -53, -52, -53, -56, -59, -58, -60,
  102455. -67, -66, -69, -71, -72, -75, -79, -81,
  102456. -84, -87, -90, -93, -97, -101, -107, -114,
  102457. -999, -999, -999, -999, -999, -999, -999, -999},
  102458. { -9, -9, -9, -9, -9, -9, -9, -9,
  102459. -11, -12, -12, -15, -16, -20, -23, -30,
  102460. -37, -34, -33, -34, -31, -32, -32, -38,
  102461. -47, -44, -41, -40, -47, -49, -46, -46,
  102462. -58, -50, -50, -54, -58, -62, -64, -67,
  102463. -67, -70, -72, -76, -79, -83, -87, -91,
  102464. -96, -100, -104, -110, -999, -999, -999, -999}},
  102465. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102466. -62, -62, -63, -64, -66, -67, -66, -68,
  102467. -75, -72, -76, -75, -76, -78, -79, -82,
  102468. -84, -85, -90, -94, -101, -110, -999, -999,
  102469. -999, -999, -999, -999, -999, -999, -999, -999,
  102470. -999, -999, -999, -999, -999, -999, -999, -999,
  102471. -999, -999, -999, -999, -999, -999, -999, -999},
  102472. { -59, -59, -59, -59, -59, -59, -59, -59,
  102473. -59, -59, -59, -60, -60, -61, -63, -66,
  102474. -71, -68, -70, -70, -71, -72, -72, -75,
  102475. -81, -78, -79, -82, -83, -86, -90, -97,
  102476. -103, -113, -999, -999, -999, -999, -999, -999,
  102477. -999, -999, -999, -999, -999, -999, -999, -999,
  102478. -999, -999, -999, -999, -999, -999, -999, -999},
  102479. { -53, -53, -53, -53, -53, -53, -53, -53,
  102480. -53, -54, -55, -57, -56, -57, -55, -61,
  102481. -65, -60, -60, -62, -63, -63, -66, -68,
  102482. -74, -73, -75, -75, -78, -80, -80, -82,
  102483. -85, -90, -96, -101, -108, -999, -999, -999,
  102484. -999, -999, -999, -999, -999, -999, -999, -999,
  102485. -999, -999, -999, -999, -999, -999, -999, -999},
  102486. { -46, -46, -46, -46, -46, -46, -46, -46,
  102487. -46, -46, -47, -47, -47, -47, -48, -51,
  102488. -57, -51, -49, -50, -51, -53, -54, -59,
  102489. -66, -60, -62, -67, -67, -70, -72, -75,
  102490. -76, -78, -81, -85, -88, -94, -97, -104,
  102491. -112, -999, -999, -999, -999, -999, -999, -999,
  102492. -999, -999, -999, -999, -999, -999, -999, -999},
  102493. { -36, -36, -36, -36, -36, -36, -36, -36,
  102494. -39, -41, -42, -42, -39, -38, -41, -43,
  102495. -52, -44, -40, -39, -37, -37, -40, -47,
  102496. -54, -50, -48, -50, -55, -61, -59, -62,
  102497. -66, -66, -66, -69, -69, -73, -74, -74,
  102498. -75, -77, -79, -82, -87, -91, -95, -100,
  102499. -108, -115, -999, -999, -999, -999, -999, -999},
  102500. { -28, -26, -24, -22, -20, -20, -23, -29,
  102501. -30, -31, -28, -27, -28, -28, -28, -35,
  102502. -40, -33, -32, -29, -30, -30, -30, -37,
  102503. -45, -41, -37, -38, -45, -47, -47, -48,
  102504. -53, -49, -48, -50, -49, -49, -51, -52,
  102505. -58, -56, -57, -56, -60, -61, -62, -70,
  102506. -72, -74, -78, -83, -88, -93, -100, -106}},
  102507. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102508. -999, -110, -105, -100, -95, -91, -87, -83,
  102509. -80, -78, -76, -78, -78, -81, -83, -85,
  102510. -86, -85, -86, -87, -90, -97, -107, -999,
  102511. -999, -999, -999, -999, -999, -999, -999, -999,
  102512. -999, -999, -999, -999, -999, -999, -999, -999,
  102513. -999, -999, -999, -999, -999, -999, -999, -999},
  102514. {-999, -999, -999, -110, -105, -100, -95, -90,
  102515. -85, -81, -77, -73, -70, -67, -67, -68,
  102516. -75, -73, -70, -69, -70, -72, -75, -79,
  102517. -84, -83, -84, -86, -88, -89, -89, -93,
  102518. -98, -105, -112, -999, -999, -999, -999, -999,
  102519. -999, -999, -999, -999, -999, -999, -999, -999,
  102520. -999, -999, -999, -999, -999, -999, -999, -999},
  102521. {-105, -100, -95, -90, -85, -80, -76, -71,
  102522. -68, -68, -65, -63, -63, -62, -62, -64,
  102523. -65, -64, -61, -62, -63, -64, -66, -68,
  102524. -73, -73, -74, -75, -76, -81, -83, -85,
  102525. -88, -89, -92, -95, -100, -108, -999, -999,
  102526. -999, -999, -999, -999, -999, -999, -999, -999,
  102527. -999, -999, -999, -999, -999, -999, -999, -999},
  102528. { -80, -75, -71, -68, -65, -63, -62, -61,
  102529. -61, -61, -61, -59, -56, -57, -53, -50,
  102530. -58, -52, -50, -50, -52, -53, -54, -58,
  102531. -67, -63, -67, -68, -72, -75, -78, -80,
  102532. -81, -81, -82, -85, -89, -90, -93, -97,
  102533. -101, -107, -114, -999, -999, -999, -999, -999,
  102534. -999, -999, -999, -999, -999, -999, -999, -999},
  102535. { -65, -61, -59, -57, -56, -55, -55, -56,
  102536. -56, -57, -55, -53, -52, -47, -44, -44,
  102537. -50, -44, -41, -39, -39, -42, -40, -46,
  102538. -51, -49, -50, -53, -54, -63, -60, -61,
  102539. -62, -66, -66, -66, -70, -73, -74, -75,
  102540. -76, -75, -79, -85, -89, -91, -96, -102,
  102541. -110, -999, -999, -999, -999, -999, -999, -999},
  102542. { -52, -50, -49, -49, -48, -48, -48, -49,
  102543. -50, -50, -49, -46, -43, -39, -35, -33,
  102544. -38, -36, -32, -29, -32, -32, -32, -35,
  102545. -44, -39, -38, -38, -46, -50, -45, -46,
  102546. -53, -50, -50, -50, -54, -54, -53, -53,
  102547. -56, -57, -59, -66, -70, -72, -74, -79,
  102548. -83, -85, -90, -97, -114, -999, -999, -999}},
  102549. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102550. -100, -95, -90, -86, -80, -75, -75, -79,
  102551. -80, -79, -80, -81, -82, -88, -95, -103,
  102552. -110, -999, -999, -999, -999, -999, -999, -999,
  102553. -999, -999, -999, -999, -999, -999, -999, -999,
  102554. -999, -999, -999, -999, -999, -999, -999, -999,
  102555. -999, -999, -999, -999, -999, -999, -999, -999},
  102556. {-999, -999, -999, -999, -108, -103, -98, -93,
  102557. -88, -83, -79, -78, -75, -71, -67, -68,
  102558. -73, -73, -72, -73, -75, -77, -80, -82,
  102559. -88, -93, -100, -107, -114, -999, -999, -999,
  102560. -999, -999, -999, -999, -999, -999, -999, -999,
  102561. -999, -999, -999, -999, -999, -999, -999, -999,
  102562. -999, -999, -999, -999, -999, -999, -999, -999},
  102563. {-999, -999, -999, -110, -105, -101, -96, -90,
  102564. -86, -81, -77, -73, -69, -66, -61, -62,
  102565. -66, -64, -62, -65, -66, -70, -72, -76,
  102566. -81, -80, -84, -90, -95, -102, -110, -999,
  102567. -999, -999, -999, -999, -999, -999, -999, -999,
  102568. -999, -999, -999, -999, -999, -999, -999, -999,
  102569. -999, -999, -999, -999, -999, -999, -999, -999},
  102570. {-999, -999, -999, -107, -103, -97, -92, -88,
  102571. -83, -79, -74, -70, -66, -59, -53, -58,
  102572. -62, -55, -54, -54, -54, -58, -61, -62,
  102573. -72, -70, -72, -75, -78, -80, -81, -80,
  102574. -83, -83, -88, -93, -100, -107, -115, -999,
  102575. -999, -999, -999, -999, -999, -999, -999, -999,
  102576. -999, -999, -999, -999, -999, -999, -999, -999},
  102577. {-999, -999, -999, -105, -100, -95, -90, -85,
  102578. -80, -75, -70, -66, -62, -56, -48, -44,
  102579. -48, -46, -46, -43, -46, -48, -48, -51,
  102580. -58, -58, -59, -60, -62, -62, -61, -61,
  102581. -65, -64, -65, -68, -70, -74, -75, -78,
  102582. -81, -86, -95, -110, -999, -999, -999, -999,
  102583. -999, -999, -999, -999, -999, -999, -999, -999},
  102584. {-999, -999, -105, -100, -95, -90, -85, -80,
  102585. -75, -70, -65, -61, -55, -49, -39, -33,
  102586. -40, -35, -32, -38, -40, -33, -35, -37,
  102587. -46, -41, -45, -44, -46, -42, -45, -46,
  102588. -52, -50, -50, -50, -54, -54, -55, -57,
  102589. -62, -64, -66, -68, -70, -76, -81, -90,
  102590. -100, -110, -999, -999, -999, -999, -999, -999}},
  102591. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102592. -105, -98, -90, -85, -82, -83, -80, -78,
  102593. -84, -79, -80, -83, -87, -89, -91, -93,
  102594. -99, -106, -117, -999, -999, -999, -999, -999,
  102595. -999, -999, -999, -999, -999, -999, -999, -999,
  102596. -999, -999, -999, -999, -999, -999, -999, -999,
  102597. -999, -999, -999, -999, -999, -999, -999, -999},
  102598. {-999, -999, -999, -999, -999, -999, -999, -999,
  102599. -105, -98, -90, -85, -80, -75, -70, -68,
  102600. -74, -72, -74, -77, -80, -82, -85, -87,
  102601. -92, -89, -91, -95, -100, -106, -112, -999,
  102602. -999, -999, -999, -999, -999, -999, -999, -999,
  102603. -999, -999, -999, -999, -999, -999, -999, -999,
  102604. -999, -999, -999, -999, -999, -999, -999, -999},
  102605. {-999, -999, -999, -999, -999, -999, -999, -999,
  102606. -105, -98, -90, -83, -75, -71, -63, -64,
  102607. -67, -62, -64, -67, -70, -73, -77, -81,
  102608. -84, -83, -85, -89, -90, -93, -98, -104,
  102609. -109, -114, -999, -999, -999, -999, -999, -999,
  102610. -999, -999, -999, -999, -999, -999, -999, -999,
  102611. -999, -999, -999, -999, -999, -999, -999, -999},
  102612. {-999, -999, -999, -999, -999, -999, -999, -999,
  102613. -103, -96, -88, -81, -75, -68, -58, -54,
  102614. -56, -54, -56, -56, -58, -60, -63, -66,
  102615. -74, -69, -72, -72, -75, -74, -77, -81,
  102616. -81, -82, -84, -87, -93, -96, -99, -104,
  102617. -110, -999, -999, -999, -999, -999, -999, -999,
  102618. -999, -999, -999, -999, -999, -999, -999, -999},
  102619. {-999, -999, -999, -999, -999, -108, -102, -96,
  102620. -91, -85, -80, -74, -68, -60, -51, -46,
  102621. -48, -46, -43, -45, -47, -47, -49, -48,
  102622. -56, -53, -55, -58, -57, -63, -58, -60,
  102623. -66, -64, -67, -70, -70, -74, -77, -84,
  102624. -86, -89, -91, -93, -94, -101, -109, -118,
  102625. -999, -999, -999, -999, -999, -999, -999, -999},
  102626. {-999, -999, -999, -108, -103, -98, -93, -88,
  102627. -83, -78, -73, -68, -60, -53, -44, -35,
  102628. -38, -38, -34, -34, -36, -40, -41, -44,
  102629. -51, -45, -46, -47, -46, -54, -50, -49,
  102630. -50, -50, -50, -51, -54, -57, -58, -60,
  102631. -66, -66, -66, -64, -65, -68, -77, -82,
  102632. -87, -95, -110, -999, -999, -999, -999, -999}},
  102633. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102634. -107, -102, -97, -92, -87, -83, -78, -75,
  102635. -82, -79, -83, -85, -89, -92, -95, -98,
  102636. -101, -105, -109, -113, -999, -999, -999, -999,
  102637. -999, -999, -999, -999, -999, -999, -999, -999,
  102638. -999, -999, -999, -999, -999, -999, -999, -999,
  102639. -999, -999, -999, -999, -999, -999, -999, -999},
  102640. {-999, -999, -999, -999, -999, -999, -999, -106,
  102641. -100, -95, -90, -86, -81, -78, -74, -69,
  102642. -74, -74, -76, -79, -83, -84, -86, -89,
  102643. -92, -97, -93, -100, -103, -107, -110, -999,
  102644. -999, -999, -999, -999, -999, -999, -999, -999,
  102645. -999, -999, -999, -999, -999, -999, -999, -999,
  102646. -999, -999, -999, -999, -999, -999, -999, -999},
  102647. {-999, -999, -999, -999, -999, -999, -106, -100,
  102648. -95, -90, -87, -83, -80, -75, -69, -60,
  102649. -66, -66, -68, -70, -74, -78, -79, -81,
  102650. -81, -83, -84, -87, -93, -96, -99, -103,
  102651. -107, -110, -999, -999, -999, -999, -999, -999,
  102652. -999, -999, -999, -999, -999, -999, -999, -999,
  102653. -999, -999, -999, -999, -999, -999, -999, -999},
  102654. {-999, -999, -999, -999, -999, -108, -103, -98,
  102655. -93, -89, -85, -82, -78, -71, -62, -55,
  102656. -58, -58, -54, -54, -55, -59, -61, -62,
  102657. -70, -66, -66, -67, -70, -72, -75, -78,
  102658. -84, -84, -84, -88, -91, -90, -95, -98,
  102659. -102, -103, -106, -110, -999, -999, -999, -999,
  102660. -999, -999, -999, -999, -999, -999, -999, -999},
  102661. {-999, -999, -999, -999, -108, -103, -98, -94,
  102662. -90, -87, -82, -79, -73, -67, -58, -47,
  102663. -50, -45, -41, -45, -48, -44, -44, -49,
  102664. -54, -51, -48, -47, -49, -50, -51, -57,
  102665. -58, -60, -63, -69, -70, -69, -71, -74,
  102666. -78, -82, -90, -95, -101, -105, -110, -999,
  102667. -999, -999, -999, -999, -999, -999, -999, -999},
  102668. {-999, -999, -999, -105, -101, -97, -93, -90,
  102669. -85, -80, -77, -72, -65, -56, -48, -37,
  102670. -40, -36, -34, -40, -50, -47, -38, -41,
  102671. -47, -38, -35, -39, -38, -43, -40, -45,
  102672. -50, -45, -44, -47, -50, -55, -48, -48,
  102673. -52, -66, -70, -76, -82, -90, -97, -105,
  102674. -110, -999, -999, -999, -999, -999, -999, -999}},
  102675. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102676. -999, -108, -103, -98, -93, -86, -79, -76,
  102677. -83, -81, -85, -87, -89, -93, -98, -102,
  102678. -107, -112, -999, -999, -999, -999, -999, -999,
  102679. -999, -999, -999, -999, -999, -999, -999, -999,
  102680. -999, -999, -999, -999, -999, -999, -999, -999,
  102681. -999, -999, -999, -999, -999, -999, -999, -999},
  102682. {-999, -999, -999, -999, -999, -999, -999, -999,
  102683. -999, -108, -103, -98, -93, -86, -79, -71,
  102684. -77, -74, -77, -79, -81, -84, -85, -90,
  102685. -92, -93, -92, -98, -101, -108, -112, -999,
  102686. -999, -999, -999, -999, -999, -999, -999, -999,
  102687. -999, -999, -999, -999, -999, -999, -999, -999,
  102688. -999, -999, -999, -999, -999, -999, -999, -999},
  102689. {-999, -999, -999, -999, -999, -999, -999, -999,
  102690. -108, -103, -98, -93, -87, -78, -68, -65,
  102691. -66, -62, -65, -67, -70, -73, -75, -78,
  102692. -82, -82, -83, -84, -91, -93, -98, -102,
  102693. -106, -110, -999, -999, -999, -999, -999, -999,
  102694. -999, -999, -999, -999, -999, -999, -999, -999,
  102695. -999, -999, -999, -999, -999, -999, -999, -999},
  102696. {-999, -999, -999, -999, -999, -999, -999, -999,
  102697. -105, -100, -95, -90, -82, -74, -62, -57,
  102698. -58, -56, -51, -52, -52, -54, -54, -58,
  102699. -66, -59, -60, -63, -66, -69, -73, -79,
  102700. -83, -84, -80, -81, -81, -82, -88, -92,
  102701. -98, -105, -113, -999, -999, -999, -999, -999,
  102702. -999, -999, -999, -999, -999, -999, -999, -999},
  102703. {-999, -999, -999, -999, -999, -999, -999, -107,
  102704. -102, -97, -92, -84, -79, -69, -57, -47,
  102705. -52, -47, -44, -45, -50, -52, -42, -42,
  102706. -53, -43, -43, -48, -51, -56, -55, -52,
  102707. -57, -59, -61, -62, -67, -71, -78, -83,
  102708. -86, -94, -98, -103, -110, -999, -999, -999,
  102709. -999, -999, -999, -999, -999, -999, -999, -999},
  102710. {-999, -999, -999, -999, -999, -999, -105, -100,
  102711. -95, -90, -84, -78, -70, -61, -51, -41,
  102712. -40, -38, -40, -46, -52, -51, -41, -40,
  102713. -46, -40, -38, -38, -41, -46, -41, -46,
  102714. -47, -43, -43, -45, -41, -45, -56, -67,
  102715. -68, -83, -87, -90, -95, -102, -107, -113,
  102716. -999, -999, -999, -999, -999, -999, -999, -999}},
  102717. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102718. -999, -109, -105, -101, -96, -91, -84, -77,
  102719. -82, -82, -85, -89, -94, -100, -106, -110,
  102720. -999, -999, -999, -999, -999, -999, -999, -999,
  102721. -999, -999, -999, -999, -999, -999, -999, -999,
  102722. -999, -999, -999, -999, -999, -999, -999, -999,
  102723. -999, -999, -999, -999, -999, -999, -999, -999},
  102724. {-999, -999, -999, -999, -999, -999, -999, -999,
  102725. -999, -106, -103, -98, -92, -85, -80, -71,
  102726. -75, -72, -76, -80, -84, -86, -89, -93,
  102727. -100, -107, -113, -999, -999, -999, -999, -999,
  102728. -999, -999, -999, -999, -999, -999, -999, -999,
  102729. -999, -999, -999, -999, -999, -999, -999, -999,
  102730. -999, -999, -999, -999, -999, -999, -999, -999},
  102731. {-999, -999, -999, -999, -999, -999, -999, -107,
  102732. -104, -101, -97, -92, -88, -84, -80, -64,
  102733. -66, -63, -64, -66, -69, -73, -77, -83,
  102734. -83, -86, -91, -98, -104, -111, -999, -999,
  102735. -999, -999, -999, -999, -999, -999, -999, -999,
  102736. -999, -999, -999, -999, -999, -999, -999, -999,
  102737. -999, -999, -999, -999, -999, -999, -999, -999},
  102738. {-999, -999, -999, -999, -999, -999, -999, -107,
  102739. -104, -101, -97, -92, -90, -84, -74, -57,
  102740. -58, -52, -55, -54, -50, -52, -50, -52,
  102741. -63, -62, -69, -76, -77, -78, -78, -79,
  102742. -82, -88, -94, -100, -106, -111, -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, -106, -102,
  102746. -98, -95, -90, -85, -83, -78, -70, -50,
  102747. -50, -41, -44, -49, -47, -50, -50, -44,
  102748. -55, -46, -47, -48, -48, -54, -49, -49,
  102749. -58, -62, -71, -81, -87, -92, -97, -102,
  102750. -108, -114, -999, -999, -999, -999, -999, -999,
  102751. -999, -999, -999, -999, -999, -999, -999, -999},
  102752. {-999, -999, -999, -999, -999, -999, -106, -102,
  102753. -98, -95, -90, -85, -83, -78, -70, -45,
  102754. -43, -41, -47, -50, -51, -50, -49, -45,
  102755. -47, -41, -44, -41, -39, -43, -38, -37,
  102756. -40, -41, -44, -50, -58, -65, -73, -79,
  102757. -85, -92, -97, -101, -105, -109, -113, -999,
  102758. -999, -999, -999, -999, -999, -999, -999, -999}},
  102759. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102760. -999, -999, -999, -107, -100, -95, -87, -81,
  102761. -85, -83, -88, -93, -100, -107, -114, -999,
  102762. -999, -999, -999, -999, -999, -999, -999, -999,
  102763. -999, -999, -999, -999, -999, -999, -999, -999,
  102764. -999, -999, -999, -999, -999, -999, -999, -999,
  102765. -999, -999, -999, -999, -999, -999, -999, -999},
  102766. {-999, -999, -999, -999, -999, -999, -999, -999,
  102767. -999, -999, -107, -101, -95, -88, -83, -76,
  102768. -73, -72, -79, -84, -90, -95, -100, -105,
  102769. -110, -115, -999, -999, -999, -999, -999, -999,
  102770. -999, -999, -999, -999, -999, -999, -999, -999,
  102771. -999, -999, -999, -999, -999, -999, -999, -999,
  102772. -999, -999, -999, -999, -999, -999, -999, -999},
  102773. {-999, -999, -999, -999, -999, -999, -999, -999,
  102774. -999, -999, -104, -98, -92, -87, -81, -70,
  102775. -65, -62, -67, -71, -74, -80, -85, -91,
  102776. -95, -99, -103, -108, -111, -114, -999, -999,
  102777. -999, -999, -999, -999, -999, -999, -999, -999,
  102778. -999, -999, -999, -999, -999, -999, -999, -999,
  102779. -999, -999, -999, -999, -999, -999, -999, -999},
  102780. {-999, -999, -999, -999, -999, -999, -999, -999,
  102781. -999, -999, -103, -97, -90, -85, -76, -60,
  102782. -56, -54, -60, -62, -61, -56, -63, -65,
  102783. -73, -74, -77, -75, -78, -81, -86, -87,
  102784. -88, -91, -94, -98, -103, -110, -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, -105,
  102788. -100, -97, -92, -86, -81, -79, -70, -57,
  102789. -51, -47, -51, -58, -60, -56, -53, -50,
  102790. -58, -52, -50, -50, -53, -55, -64, -69,
  102791. -71, -85, -82, -78, -81, -85, -95, -102,
  102792. -112, -999, -999, -999, -999, -999, -999, -999,
  102793. -999, -999, -999, -999, -999, -999, -999, -999},
  102794. {-999, -999, -999, -999, -999, -999, -999, -105,
  102795. -100, -97, -92, -85, -83, -79, -72, -49,
  102796. -40, -43, -43, -54, -56, -51, -50, -40,
  102797. -43, -38, -36, -35, -37, -38, -37, -44,
  102798. -54, -60, -57, -60, -70, -75, -84, -92,
  102799. -103, -112, -999, -999, -999, -999, -999, -999,
  102800. -999, -999, -999, -999, -999, -999, -999, -999}},
  102801. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102802. -999, -999, -999, -110, -102, -95, -89, -82,
  102803. -83, -84, -90, -92, -99, -107, -113, -999,
  102804. -999, -999, -999, -999, -999, -999, -999, -999,
  102805. -999, -999, -999, -999, -999, -999, -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, -999, -999,
  102809. -999, -999, -107, -101, -95, -89, -83, -72,
  102810. -74, -78, -85, -88, -88, -90, -92, -98,
  102811. -105, -111, -999, -999, -999, -999, -999, -999,
  102812. -999, -999, -999, -999, -999, -999, -999, -999,
  102813. -999, -999, -999, -999, -999, -999, -999, -999,
  102814. -999, -999, -999, -999, -999, -999, -999, -999},
  102815. {-999, -999, -999, -999, -999, -999, -999, -999,
  102816. -999, -109, -103, -97, -93, -87, -81, -70,
  102817. -70, -67, -75, -73, -76, -79, -81, -83,
  102818. -88, -89, -97, -103, -110, -999, -999, -999,
  102819. -999, -999, -999, -999, -999, -999, -999, -999,
  102820. -999, -999, -999, -999, -999, -999, -999, -999,
  102821. -999, -999, -999, -999, -999, -999, -999, -999},
  102822. {-999, -999, -999, -999, -999, -999, -999, -999,
  102823. -999, -107, -100, -94, -88, -83, -75, -63,
  102824. -59, -59, -63, -66, -60, -62, -67, -67,
  102825. -77, -76, -81, -88, -86, -92, -96, -102,
  102826. -109, -116, -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, -105, -98, -92, -86, -81, -73, -56,
  102831. -52, -47, -55, -60, -58, -52, -51, -45,
  102832. -49, -50, -53, -54, -61, -71, -70, -69,
  102833. -78, -79, -87, -90, -96, -104, -112, -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, -103, -96, -90, -86, -78, -70, -51,
  102838. -42, -47, -48, -55, -54, -54, -53, -42,
  102839. -35, -28, -33, -38, -37, -44, -47, -49,
  102840. -54, -63, -68, -78, -82, -89, -94, -99,
  102841. -104, -109, -114, -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, -999, -999, -110, -100, -90, -79,
  102845. -85, -81, -82, -82, -89, -94, -99, -103,
  102846. -109, -115, -999, -999, -999, -999, -999, -999,
  102847. -999, -999, -999, -999, -999, -999, -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, -999,
  102851. -999, -999, -999, -999, -105, -97, -85, -72,
  102852. -74, -70, -70, -70, -76, -85, -91, -93,
  102853. -97, -103, -109, -115, -999, -999, -999, -999,
  102854. -999, -999, -999, -999, -999, -999, -999, -999,
  102855. -999, -999, -999, -999, -999, -999, -999, -999,
  102856. -999, -999, -999, -999, -999, -999, -999, -999},
  102857. {-999, -999, -999, -999, -999, -999, -999, -999,
  102858. -999, -999, -999, -999, -112, -93, -81, -68,
  102859. -62, -60, -60, -57, -63, -70, -77, -82,
  102860. -90, -93, -98, -104, -109, -113, -999, -999,
  102861. -999, -999, -999, -999, -999, -999, -999, -999,
  102862. -999, -999, -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, -113, -100, -93, -84, -63,
  102866. -58, -48, -53, -54, -52, -52, -57, -64,
  102867. -66, -76, -83, -81, -85, -85, -90, -95,
  102868. -98, -101, -103, -106, -108, -111, -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, -999, -105, -95, -86, -74, -53,
  102873. -50, -38, -43, -49, -43, -42, -39, -39,
  102874. -46, -52, -57, -56, -72, -69, -74, -81,
  102875. -87, -92, -94, -97, -99, -102, -105, -108,
  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, -999, -108, -99, -90, -76, -66, -45,
  102880. -43, -41, -44, -47, -43, -47, -40, -30,
  102881. -31, -31, -39, -33, -40, -41, -43, -53,
  102882. -59, -70, -73, -77, -79, -82, -84, -87,
  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, -999, -999, -999, -999, -110, -91, -76,
  102887. -75, -85, -93, -98, -104, -110, -999, -999,
  102888. -999, -999, -999, -999, -999, -999, -999, -999,
  102889. -999, -999, -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, -999, -999, -999, -999, -110, -91, -70,
  102894. -70, -75, -86, -89, -94, -98, -101, -106,
  102895. -110, -999, -999, -999, -999, -999, -999, -999,
  102896. -999, -999, -999, -999, -999, -999, -999, -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, -999, -999, -999, -110, -95, -80, -60,
  102901. -65, -64, -74, -83, -88, -91, -95, -99,
  102902. -103, -107, -110, -999, -999, -999, -999, -999,
  102903. -999, -999, -999, -999, -999, -999, -999, -999,
  102904. -999, -999, -999, -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, -95, -80, -58,
  102908. -55, -49, -66, -68, -71, -78, -78, -80,
  102909. -88, -85, -89, -97, -100, -105, -110, -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, -110, -95, -80, -53,
  102915. -52, -41, -59, -59, -49, -58, -56, -63,
  102916. -86, -79, -90, -93, -98, -103, -107, -112,
  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, -110, -97, -91, -73, -45,
  102922. -40, -33, -53, -61, -49, -54, -50, -50,
  102923. -60, -52, -67, -74, -81, -92, -96, -100,
  102924. -105, -110, -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, -106, -99, -92, -77,
  102929. -80, -88, -97, -106, -115, -999, -999, -999,
  102930. -999, -999, -999, -999, -999, -999, -999, -999,
  102931. -999, -999, -999, -999, -999, -999, -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, -116, -109, -102, -95, -89, -74,
  102936. -72, -88, -87, -95, -102, -109, -116, -999,
  102937. -999, -999, -999, -999, -999, -999, -999, -999,
  102938. -999, -999, -999, -999, -999, -999, -999, -999,
  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, -116, -109, -102, -95, -89, -75,
  102943. -66, -74, -77, -78, -86, -87, -90, -96,
  102944. -105, -115, -999, -999, -999, -999, -999, -999,
  102945. -999, -999, -999, -999, -999, -999, -999, -999,
  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, -115, -108, -101, -94, -88, -66,
  102950. -56, -61, -70, -65, -78, -72, -83, -84,
  102951. -93, -98, -105, -110, -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, -110, -105, -95, -89, -82, -57,
  102957. -52, -52, -59, -56, -59, -58, -69, -67,
  102958. -88, -82, -82, -89, -94, -100, -108, -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, -110, -101, -96, -90, -83, -77, -54,
  102964. -43, -38, -50, -48, -52, -48, -42, -42,
  102965. -51, -52, -53, -59, -65, -71, -78, -85,
  102966. -95, -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, -120, -105, -86, -68,
  102971. -78, -79, -90, -100, -110, -999, -999, -999,
  102972. -999, -999, -999, -999, -999, -999, -999, -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, -120, -105, -86, -66,
  102978. -73, -77, -88, -96, -105, -115, -999, -999,
  102979. -999, -999, -999, -999, -999, -999, -999, -999,
  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, -120, -105, -92, -80, -61,
  102985. -64, -68, -80, -87, -92, -100, -110, -999,
  102986. -999, -999, -999, -999, -999, -999, -999, -999,
  102987. -999, -999, -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, -120, -104, -91, -79, -52,
  102992. -60, -54, -64, -69, -77, -80, -82, -84,
  102993. -85, -87, -88, -90, -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, -999, -118, -100, -87, -77, -49,
  102999. -50, -44, -58, -61, -61, -67, -65, -62,
  103000. -62, -62, -65, -68, -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, -999, -115, -98, -84, -62, -49,
  103006. -44, -38, -46, -49, -49, -46, -39, -37,
  103007. -39, -40, -42, -43, -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, -999, -999, -999, -110, -88, -74,
  103013. -77, -82, -82, -85, -90, -94, -99, -104,
  103014. -999, -999, -999, -999, -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, -999, -999, -999, -110, -88, -66,
  103020. -70, -81, -80, -81, -84, -88, -91, -93,
  103021. -999, -999, -999, -999, -999, -999, -999, -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, -999, -999, -999, -999, -110, -88, -61,
  103027. -63, -70, -71, -74, -77, -80, -83, -85,
  103028. -999, -999, -999, -999, -999, -999, -999, -999,
  103029. -999, -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, -999, -110, -86, -62,
  103034. -63, -62, -62, -58, -52, -50, -50, -52,
  103035. -54, -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, -118, -108, -84, -53,
  103041. -50, -50, -50, -55, -47, -45, -40, -40,
  103042. -40, -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, -999, -118, -100, -73, -43,
  103048. -37, -42, -43, -53, -38, -37, -35, -35,
  103049. -38, -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, -110, -100, -91, -84, -74,
  103055. -80, -80, -80, -80, -80, -999, -999, -999,
  103056. -999, -999, -999, -999, -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, -110, -100, -91, -84, -74,
  103062. -68, -68, -68, -68, -68, -999, -999, -999,
  103063. -999, -999, -999, -999, -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, -110, -100, -86, -78, -70,
  103069. -60, -45, -30, -21, -999, -999, -999, -999,
  103070. -999, -999, -999, -999, -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, -110, -100, -87, -78, -67,
  103076. -48, -38, -29, -21, -999, -999, -999, -999,
  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, -110, -100, -86, -69, -56,
  103083. -45, -35, -33, -29, -999, -999, -999, -999,
  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, -110, -100, -83, -71, -48,
  103090. -27, -38, -37, -34, -999, -999, -999, -999,
  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. };
  103096. #endif
  103097. /*** End of inlined file: masking.h ***/
  103098. #define NEGINF -9999.f
  103099. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103100. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103101. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103102. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103103. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103104. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103105. look->channels=vi->channels;
  103106. look->ampmax=-9999.;
  103107. look->gi=gi;
  103108. return(look);
  103109. }
  103110. void _vp_global_free(vorbis_look_psy_global *look){
  103111. if(look){
  103112. memset(look,0,sizeof(*look));
  103113. _ogg_free(look);
  103114. }
  103115. }
  103116. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103117. if(i){
  103118. memset(i,0,sizeof(*i));
  103119. _ogg_free(i);
  103120. }
  103121. }
  103122. void _vi_psy_free(vorbis_info_psy *i){
  103123. if(i){
  103124. memset(i,0,sizeof(*i));
  103125. _ogg_free(i);
  103126. }
  103127. }
  103128. static void min_curve(float *c,
  103129. float *c2){
  103130. int i;
  103131. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103132. }
  103133. static void max_curve(float *c,
  103134. float *c2){
  103135. int i;
  103136. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103137. }
  103138. static void attenuate_curve(float *c,float att){
  103139. int i;
  103140. for(i=0;i<EHMER_MAX;i++)
  103141. c[i]+=att;
  103142. }
  103143. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103144. float center_boost, float center_decay_rate){
  103145. int i,j,k,m;
  103146. float ath[EHMER_MAX];
  103147. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103148. float athc[P_LEVELS][EHMER_MAX];
  103149. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103150. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103151. memset(workc,0,sizeof(workc));
  103152. for(i=0;i<P_BANDS;i++){
  103153. int ath_offset=i*4;
  103154. for(j=0;j<EHMER_MAX;j++){
  103155. float min=999.;
  103156. for(k=0;k<4;k++)
  103157. if(j+k+ath_offset<MAX_ATH){
  103158. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103159. }else{
  103160. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103161. }
  103162. ath[j]=min;
  103163. }
  103164. for(j=0;j<6;j++)
  103165. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103166. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103167. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103168. for(j=0;j<P_LEVELS;j++){
  103169. for(k=0;k<EHMER_MAX;k++){
  103170. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103171. if(adj<0. && center_boost>0)adj=0.;
  103172. if(adj>0. && center_boost<0)adj=0.;
  103173. workc[i][j][k]+=adj;
  103174. }
  103175. }
  103176. for(j=0;j<P_LEVELS;j++){
  103177. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103178. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103179. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103180. max_curve(athc[j],workc[i][j]);
  103181. }
  103182. for(j=1;j<P_LEVELS;j++){
  103183. min_curve(athc[j],athc[j-1]);
  103184. min_curve(workc[i][j],athc[j]);
  103185. }
  103186. }
  103187. for(i=0;i<P_BANDS;i++){
  103188. int hi_curve,lo_curve,bin;
  103189. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103190. bin=floor(fromOC(i*.5)/binHz);
  103191. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103192. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103193. if(lo_curve>i)lo_curve=i;
  103194. if(lo_curve<0)lo_curve=0;
  103195. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103196. for(m=0;m<P_LEVELS;m++){
  103197. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103198. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103199. for(k=lo_curve;k<=hi_curve;k++){
  103200. int l=0;
  103201. for(j=0;j<EHMER_MAX;j++){
  103202. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103203. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103204. if(lo_bin<0)lo_bin=0;
  103205. if(lo_bin>n)lo_bin=n;
  103206. if(lo_bin<l)l=lo_bin;
  103207. if(hi_bin<0)hi_bin=0;
  103208. if(hi_bin>n)hi_bin=n;
  103209. for(;l<hi_bin && l<n;l++)
  103210. if(brute_buffer[l]>workc[k][m][j])
  103211. brute_buffer[l]=workc[k][m][j];
  103212. }
  103213. for(;l<n;l++)
  103214. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103215. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103216. }
  103217. if(i+1<P_BANDS){
  103218. int l=0;
  103219. k=i+1;
  103220. for(j=0;j<EHMER_MAX;j++){
  103221. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103222. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103223. if(lo_bin<0)lo_bin=0;
  103224. if(lo_bin>n)lo_bin=n;
  103225. if(lo_bin<l)l=lo_bin;
  103226. if(hi_bin<0)hi_bin=0;
  103227. if(hi_bin>n)hi_bin=n;
  103228. for(;l<hi_bin && l<n;l++)
  103229. if(brute_buffer[l]>workc[k][m][j])
  103230. brute_buffer[l]=workc[k][m][j];
  103231. }
  103232. for(;l<n;l++)
  103233. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103234. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103235. }
  103236. for(j=0;j<EHMER_MAX;j++){
  103237. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103238. if(bin<0){
  103239. ret[i][m][j+2]=-999.;
  103240. }else{
  103241. if(bin>=n){
  103242. ret[i][m][j+2]=-999.;
  103243. }else{
  103244. ret[i][m][j+2]=brute_buffer[bin];
  103245. }
  103246. }
  103247. }
  103248. for(j=0;j<EHMER_OFFSET;j++)
  103249. if(ret[i][m][j+2]>-200.f)break;
  103250. ret[i][m][0]=j;
  103251. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103252. if(ret[i][m][j+2]>-200.f)
  103253. break;
  103254. ret[i][m][1]=j;
  103255. }
  103256. }
  103257. return(ret);
  103258. }
  103259. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103260. vorbis_info_psy_global *gi,int n,long rate){
  103261. long i,j,lo=-99,hi=1;
  103262. long maxoc;
  103263. memset(p,0,sizeof(*p));
  103264. p->eighth_octave_lines=gi->eighth_octave_lines;
  103265. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103266. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103267. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103268. p->total_octave_lines=maxoc-p->firstoc+1;
  103269. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103270. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103271. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103272. p->vi=vi;
  103273. p->n=n;
  103274. p->rate=rate;
  103275. p->m_val = 1.;
  103276. if(rate < 26000) p->m_val = 0;
  103277. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103278. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103279. for(i=0,j=0;i<MAX_ATH-1;i++){
  103280. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103281. float base=ATH[i];
  103282. if(j<endpos){
  103283. float delta=(ATH[i+1]-base)/(endpos-j);
  103284. for(;j<endpos && j<n;j++){
  103285. p->ath[j]=base+100.;
  103286. base+=delta;
  103287. }
  103288. }
  103289. }
  103290. for(i=0;i<n;i++){
  103291. float bark=toBARK(rate/(2*n)*i);
  103292. for(;lo+vi->noisewindowlomin<i &&
  103293. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103294. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103295. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103296. p->bark[i]=((lo-1)<<16)+(hi-1);
  103297. }
  103298. for(i=0;i<n;i++)
  103299. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103300. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103301. vi->tone_centerboost,vi->tone_decay);
  103302. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103303. for(i=0;i<P_NOISECURVES;i++)
  103304. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103305. for(i=0;i<n;i++){
  103306. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103307. int inthalfoc;
  103308. float del;
  103309. if(halfoc<0)halfoc=0;
  103310. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103311. inthalfoc=(int)halfoc;
  103312. del=halfoc-inthalfoc;
  103313. for(j=0;j<P_NOISECURVES;j++)
  103314. p->noiseoffset[j][i]=
  103315. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103316. p->vi->noiseoff[j][inthalfoc+1]*del;
  103317. }
  103318. #if 0
  103319. {
  103320. static int ls=0;
  103321. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103322. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103323. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103324. }
  103325. #endif
  103326. }
  103327. void _vp_psy_clear(vorbis_look_psy *p){
  103328. int i,j;
  103329. if(p){
  103330. if(p->ath)_ogg_free(p->ath);
  103331. if(p->octave)_ogg_free(p->octave);
  103332. if(p->bark)_ogg_free(p->bark);
  103333. if(p->tonecurves){
  103334. for(i=0;i<P_BANDS;i++){
  103335. for(j=0;j<P_LEVELS;j++){
  103336. _ogg_free(p->tonecurves[i][j]);
  103337. }
  103338. _ogg_free(p->tonecurves[i]);
  103339. }
  103340. _ogg_free(p->tonecurves);
  103341. }
  103342. if(p->noiseoffset){
  103343. for(i=0;i<P_NOISECURVES;i++){
  103344. _ogg_free(p->noiseoffset[i]);
  103345. }
  103346. _ogg_free(p->noiseoffset);
  103347. }
  103348. memset(p,0,sizeof(*p));
  103349. }
  103350. }
  103351. static void seed_curve(float *seed,
  103352. const float **curves,
  103353. float amp,
  103354. int oc, int n,
  103355. int linesper,float dBoffset){
  103356. int i,post1;
  103357. int seedptr;
  103358. const float *posts,*curve;
  103359. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103360. choice=max(choice,0);
  103361. choice=min(choice,P_LEVELS-1);
  103362. posts=curves[choice];
  103363. curve=posts+2;
  103364. post1=(int)posts[1];
  103365. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103366. for(i=posts[0];i<post1;i++){
  103367. if(seedptr>0){
  103368. float lin=amp+curve[i];
  103369. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103370. }
  103371. seedptr+=linesper;
  103372. if(seedptr>=n)break;
  103373. }
  103374. }
  103375. static void seed_loop(vorbis_look_psy *p,
  103376. const float ***curves,
  103377. const float *f,
  103378. const float *flr,
  103379. float *seed,
  103380. float specmax){
  103381. vorbis_info_psy *vi=p->vi;
  103382. long n=p->n,i;
  103383. float dBoffset=vi->max_curve_dB-specmax;
  103384. for(i=0;i<n;i++){
  103385. float max=f[i];
  103386. long oc=p->octave[i];
  103387. while(i+1<n && p->octave[i+1]==oc){
  103388. i++;
  103389. if(f[i]>max)max=f[i];
  103390. }
  103391. if(max+6.f>flr[i]){
  103392. oc=oc>>p->shiftoc;
  103393. if(oc>=P_BANDS)oc=P_BANDS-1;
  103394. if(oc<0)oc=0;
  103395. seed_curve(seed,
  103396. curves[oc],
  103397. max,
  103398. p->octave[i]-p->firstoc,
  103399. p->total_octave_lines,
  103400. p->eighth_octave_lines,
  103401. dBoffset);
  103402. }
  103403. }
  103404. }
  103405. static void seed_chase(float *seeds, int linesper, long n){
  103406. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103407. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103408. long stack=0;
  103409. long pos=0;
  103410. long i;
  103411. for(i=0;i<n;i++){
  103412. if(stack<2){
  103413. posstack[stack]=i;
  103414. ampstack[stack++]=seeds[i];
  103415. }else{
  103416. while(1){
  103417. if(seeds[i]<ampstack[stack-1]){
  103418. posstack[stack]=i;
  103419. ampstack[stack++]=seeds[i];
  103420. break;
  103421. }else{
  103422. if(i<posstack[stack-1]+linesper){
  103423. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103424. i<posstack[stack-2]+linesper){
  103425. stack--;
  103426. continue;
  103427. }
  103428. }
  103429. posstack[stack]=i;
  103430. ampstack[stack++]=seeds[i];
  103431. break;
  103432. }
  103433. }
  103434. }
  103435. }
  103436. for(i=0;i<stack;i++){
  103437. long endpos;
  103438. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103439. endpos=posstack[i+1];
  103440. }else{
  103441. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103442. discarded in short frames */
  103443. }
  103444. if(endpos>n)endpos=n;
  103445. for(;pos<endpos;pos++)
  103446. seeds[pos]=ampstack[i];
  103447. }
  103448. }
  103449. #include<stdio.h>
  103450. static void max_seeds(vorbis_look_psy *p,
  103451. float *seed,
  103452. float *flr){
  103453. long n=p->total_octave_lines;
  103454. int linesper=p->eighth_octave_lines;
  103455. long linpos=0;
  103456. long pos;
  103457. seed_chase(seed,linesper,n); /* for masking */
  103458. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103459. while(linpos+1<p->n){
  103460. float minV=seed[pos];
  103461. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103462. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103463. while(pos+1<=end){
  103464. pos++;
  103465. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103466. minV=seed[pos];
  103467. }
  103468. end=pos+p->firstoc;
  103469. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103470. if(flr[linpos]<minV)flr[linpos]=minV;
  103471. }
  103472. {
  103473. float minV=seed[p->total_octave_lines-1];
  103474. for(;linpos<p->n;linpos++)
  103475. if(flr[linpos]<minV)flr[linpos]=minV;
  103476. }
  103477. }
  103478. static void bark_noise_hybridmp(int n,const long *b,
  103479. const float *f,
  103480. float *noise,
  103481. const float offset,
  103482. const int fixed){
  103483. float *N=(float*) alloca(n*sizeof(*N));
  103484. float *X=(float*) alloca(n*sizeof(*N));
  103485. float *XX=(float*) alloca(n*sizeof(*N));
  103486. float *Y=(float*) alloca(n*sizeof(*N));
  103487. float *XY=(float*) alloca(n*sizeof(*N));
  103488. float tN, tX, tXX, tY, tXY;
  103489. int i;
  103490. int lo, hi;
  103491. float R, A, B, D;
  103492. float w, x, y;
  103493. tN = tX = tXX = tY = tXY = 0.f;
  103494. y = f[0] + offset;
  103495. if (y < 1.f) y = 1.f;
  103496. w = y * y * .5;
  103497. tN += w;
  103498. tX += w;
  103499. tY += w * y;
  103500. N[0] = tN;
  103501. X[0] = tX;
  103502. XX[0] = tXX;
  103503. Y[0] = tY;
  103504. XY[0] = tXY;
  103505. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103506. y = f[i] + offset;
  103507. if (y < 1.f) y = 1.f;
  103508. w = y * y;
  103509. tN += w;
  103510. tX += w * x;
  103511. tXX += w * x * x;
  103512. tY += w * y;
  103513. tXY += w * x * y;
  103514. N[i] = tN;
  103515. X[i] = tX;
  103516. XX[i] = tXX;
  103517. Y[i] = tY;
  103518. XY[i] = tXY;
  103519. }
  103520. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103521. lo = b[i] >> 16;
  103522. if( lo>=0 ) break;
  103523. hi = b[i] & 0xffff;
  103524. tN = N[hi] + N[-lo];
  103525. tX = X[hi] - X[-lo];
  103526. tXX = XX[hi] + XX[-lo];
  103527. tY = Y[hi] + Y[-lo];
  103528. tXY = XY[hi] - XY[-lo];
  103529. A = tY * tXX - tX * tXY;
  103530. B = tN * tXY - tX * tY;
  103531. D = tN * tXX - tX * tX;
  103532. R = (A + x * B) / D;
  103533. if (R < 0.f)
  103534. R = 0.f;
  103535. noise[i] = R - offset;
  103536. }
  103537. for ( ;; i++, x += 1.f) {
  103538. lo = b[i] >> 16;
  103539. hi = b[i] & 0xffff;
  103540. if(hi>=n)break;
  103541. tN = N[hi] - N[lo];
  103542. tX = X[hi] - X[lo];
  103543. tXX = XX[hi] - XX[lo];
  103544. tY = Y[hi] - Y[lo];
  103545. tXY = XY[hi] - XY[lo];
  103546. A = tY * tXX - tX * tXY;
  103547. B = tN * tXY - tX * tY;
  103548. D = tN * tXX - tX * tX;
  103549. R = (A + x * B) / D;
  103550. if (R < 0.f) R = 0.f;
  103551. noise[i] = R - offset;
  103552. }
  103553. for ( ; i < n; i++, x += 1.f) {
  103554. R = (A + x * B) / D;
  103555. if (R < 0.f) R = 0.f;
  103556. noise[i] = R - offset;
  103557. }
  103558. if (fixed <= 0) return;
  103559. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103560. hi = i + fixed / 2;
  103561. lo = hi - fixed;
  103562. if(lo>=0)break;
  103563. tN = N[hi] + N[-lo];
  103564. tX = X[hi] - X[-lo];
  103565. tXX = XX[hi] + XX[-lo];
  103566. tY = Y[hi] + Y[-lo];
  103567. tXY = XY[hi] - XY[-lo];
  103568. A = tY * tXX - tX * tXY;
  103569. B = tN * tXY - tX * tY;
  103570. D = tN * tXX - tX * tX;
  103571. R = (A + x * B) / D;
  103572. if (R - offset < noise[i]) noise[i] = R - offset;
  103573. }
  103574. for ( ;; i++, x += 1.f) {
  103575. hi = i + fixed / 2;
  103576. lo = hi - fixed;
  103577. if(hi>=n)break;
  103578. tN = N[hi] - N[lo];
  103579. tX = X[hi] - X[lo];
  103580. tXX = XX[hi] - XX[lo];
  103581. tY = Y[hi] - Y[lo];
  103582. tXY = XY[hi] - XY[lo];
  103583. A = tY * tXX - tX * tXY;
  103584. B = tN * tXY - tX * tY;
  103585. D = tN * tXX - tX * tX;
  103586. R = (A + x * B) / D;
  103587. if (R - offset < noise[i]) noise[i] = R - offset;
  103588. }
  103589. for ( ; i < n; i++, x += 1.f) {
  103590. R = (A + x * B) / D;
  103591. if (R - offset < noise[i]) noise[i] = R - offset;
  103592. }
  103593. }
  103594. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103595. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103596. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103597. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103598. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103599. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103600. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103601. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103602. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103603. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103604. 973377.F, 913981.F, 858210.F, 805842.F,
  103605. 756669.F, 710497.F, 667142.F, 626433.F,
  103606. 588208.F, 552316.F, 518613.F, 486967.F,
  103607. 457252.F, 429351.F, 403152.F, 378551.F,
  103608. 355452.F, 333762.F, 313396.F, 294273.F,
  103609. 276316.F, 259455.F, 243623.F, 228757.F,
  103610. 214798.F, 201691.F, 189384.F, 177828.F,
  103611. 166977.F, 156788.F, 147221.F, 138237.F,
  103612. 129802.F, 121881.F, 114444.F, 107461.F,
  103613. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103614. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103615. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103616. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103617. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103618. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103619. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103620. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103621. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103622. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103623. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103624. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103625. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103626. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103627. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103628. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103629. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103630. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103631. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103632. 842.910F, 791.475F, 743.179F, 697.830F,
  103633. 655.249F, 615.265F, 577.722F, 542.469F,
  103634. 509.367F, 478.286F, 449.101F, 421.696F,
  103635. 395.964F, 371.803F, 349.115F, 327.812F,
  103636. 307.809F, 289.026F, 271.390F, 254.830F,
  103637. 239.280F, 224.679F, 210.969F, 198.096F,
  103638. 186.008F, 174.658F, 164.000F, 153.993F,
  103639. 144.596F, 135.773F, 127.488F, 119.708F,
  103640. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103641. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103642. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103643. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103644. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103645. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103646. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103647. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103648. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103649. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103650. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103651. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103652. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103653. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103654. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103655. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103656. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103657. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103658. 1.20790F, 1.13419F, 1.06499F, 1.F
  103659. };
  103660. void _vp_remove_floor(vorbis_look_psy *p,
  103661. float *mdct,
  103662. int *codedflr,
  103663. float *residue,
  103664. int sliding_lowpass){
  103665. int i,n=p->n;
  103666. if(sliding_lowpass>n)sliding_lowpass=n;
  103667. for(i=0;i<sliding_lowpass;i++){
  103668. residue[i]=
  103669. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103670. }
  103671. for(;i<n;i++)
  103672. residue[i]=0.;
  103673. }
  103674. void _vp_noisemask(vorbis_look_psy *p,
  103675. float *logmdct,
  103676. float *logmask){
  103677. int i,n=p->n;
  103678. float *work=(float*) alloca(n*sizeof(*work));
  103679. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103680. 140.,-1);
  103681. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103682. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103683. p->vi->noisewindowfixed);
  103684. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103685. #if 0
  103686. {
  103687. static int seq=0;
  103688. float work2[n];
  103689. for(i=0;i<n;i++){
  103690. work2[i]=logmask[i]+work[i];
  103691. }
  103692. if(seq&1)
  103693. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103694. else
  103695. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103696. if(seq&1)
  103697. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103698. else
  103699. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103700. seq++;
  103701. }
  103702. #endif
  103703. for(i=0;i<n;i++){
  103704. int dB=logmask[i]+.5;
  103705. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103706. if(dB<0)dB=0;
  103707. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103708. }
  103709. }
  103710. void _vp_tonemask(vorbis_look_psy *p,
  103711. float *logfft,
  103712. float *logmask,
  103713. float global_specmax,
  103714. float local_specmax){
  103715. int i,n=p->n;
  103716. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103717. float att=local_specmax+p->vi->ath_adjatt;
  103718. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103719. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103720. for(i=0;i<n;i++)
  103721. logmask[i]=p->ath[i]+att;
  103722. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103723. max_seeds(p,seed,logmask);
  103724. }
  103725. void _vp_offset_and_mix(vorbis_look_psy *p,
  103726. float *noise,
  103727. float *tone,
  103728. int offset_select,
  103729. float *logmask,
  103730. float *mdct,
  103731. float *logmdct){
  103732. int i,n=p->n;
  103733. float de, coeffi, cx;/* AoTuV */
  103734. float toneatt=p->vi->tone_masteratt[offset_select];
  103735. cx = p->m_val;
  103736. for(i=0;i<n;i++){
  103737. float val= noise[i]+p->noiseoffset[offset_select][i];
  103738. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103739. logmask[i]=max(val,tone[i]+toneatt);
  103740. if(offset_select == 1) {
  103741. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103742. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103743. if(val > coeffi){
  103744. de = 1.0-((val-coeffi)*0.005*cx);
  103745. if(de < 0) de = 0.0001;
  103746. }else
  103747. de = 1.0-((val-coeffi)*0.0003*cx);
  103748. mdct[i] *= de;
  103749. }
  103750. }
  103751. }
  103752. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103753. vorbis_info *vi=vd->vi;
  103754. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103755. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103756. int n=ci->blocksizes[vd->W]/2;
  103757. float secs=(float)n/vi->rate;
  103758. amp+=secs*gi->ampmax_att_per_sec;
  103759. if(amp<-9999)amp=-9999;
  103760. return(amp);
  103761. }
  103762. static void couple_lossless(float A, float B,
  103763. float *qA, float *qB){
  103764. int test1=fabs(*qA)>fabs(*qB);
  103765. test1-= fabs(*qA)<fabs(*qB);
  103766. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103767. if(test1==1){
  103768. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103769. }else{
  103770. float temp=*qB;
  103771. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103772. *qA=temp;
  103773. }
  103774. if(*qB>fabs(*qA)*1.9999f){
  103775. *qB= -fabs(*qA)*2.f;
  103776. *qA= -*qA;
  103777. }
  103778. }
  103779. static float hypot_lookup[32]={
  103780. -0.009935, -0.011245, -0.012726, -0.014397,
  103781. -0.016282, -0.018407, -0.020800, -0.023494,
  103782. -0.026522, -0.029923, -0.033737, -0.038010,
  103783. -0.042787, -0.048121, -0.054064, -0.060671,
  103784. -0.068000, -0.076109, -0.085054, -0.094892,
  103785. -0.105675, -0.117451, -0.130260, -0.144134,
  103786. -0.159093, -0.175146, -0.192286, -0.210490,
  103787. -0.229718, -0.249913, -0.271001, -0.292893};
  103788. static void precomputed_couple_point(float premag,
  103789. int floorA,int floorB,
  103790. float *mag, float *ang){
  103791. int test=(floorA>floorB)-1;
  103792. int offset=31-abs(floorA-floorB);
  103793. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103794. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103795. *mag=premag*floormag;
  103796. *ang=0.f;
  103797. }
  103798. static float dipole_hypot(float a, float b){
  103799. if(a>0.){
  103800. if(b>0.)return sqrt(a*a+b*b);
  103801. if(a>-b)return sqrt(a*a-b*b);
  103802. return -sqrt(b*b-a*a);
  103803. }
  103804. if(b<0.)return -sqrt(a*a+b*b);
  103805. if(-a>b)return -sqrt(a*a-b*b);
  103806. return sqrt(b*b-a*a);
  103807. }
  103808. static float round_hypot(float a, float b){
  103809. if(a>0.){
  103810. if(b>0.)return sqrt(a*a+b*b);
  103811. if(a>-b)return sqrt(a*a+b*b);
  103812. return -sqrt(b*b+a*a);
  103813. }
  103814. if(b<0.)return -sqrt(a*a+b*b);
  103815. if(-a>b)return -sqrt(a*a+b*b);
  103816. return sqrt(b*b+a*a);
  103817. }
  103818. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103819. vorbis_info_psy_global *g,
  103820. vorbis_look_psy *p,
  103821. vorbis_info_mapping0 *vi,
  103822. float **mdct){
  103823. int i,j,n=p->n;
  103824. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103825. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103826. for(i=0;i<vi->coupling_steps;i++){
  103827. float *mdctM=mdct[vi->coupling_mag[i]];
  103828. float *mdctA=mdct[vi->coupling_ang[i]];
  103829. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103830. for(j=0;j<limit;j++)
  103831. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103832. for(;j<n;j++)
  103833. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103834. }
  103835. return(ret);
  103836. }
  103837. static int apsort(const void *a, const void *b){
  103838. float f1=fabs(**(float**)a);
  103839. float f2=fabs(**(float**)b);
  103840. return (f1<f2)-(f1>f2);
  103841. }
  103842. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103843. vorbis_look_psy *p,
  103844. vorbis_info_mapping0 *vi,
  103845. float **mags){
  103846. if(p->vi->normal_point_p){
  103847. int i,j,k,n=p->n;
  103848. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103849. int partition=p->vi->normal_partition;
  103850. float **work=(float**) alloca(sizeof(*work)*partition);
  103851. for(i=0;i<vi->coupling_steps;i++){
  103852. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103853. for(j=0;j<n;j+=partition){
  103854. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103855. qsort(work,partition,sizeof(*work),apsort);
  103856. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103857. }
  103858. }
  103859. return(ret);
  103860. }
  103861. return(NULL);
  103862. }
  103863. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103864. float *magnitudes,int *sortedindex){
  103865. int i,j,n=p->n;
  103866. vorbis_info_psy *vi=p->vi;
  103867. int partition=vi->normal_partition;
  103868. float **work=(float**) alloca(sizeof(*work)*partition);
  103869. int start=vi->normal_start;
  103870. for(j=start;j<n;j+=partition){
  103871. if(j+partition>n)partition=n-j;
  103872. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103873. qsort(work,partition,sizeof(*work),apsort);
  103874. for(i=0;i<partition;i++){
  103875. sortedindex[i+j-start]=work[i]-magnitudes;
  103876. }
  103877. }
  103878. }
  103879. void _vp_noise_normalize(vorbis_look_psy *p,
  103880. float *in,float *out,int *sortedindex){
  103881. int flag=0,i,j=0,n=p->n;
  103882. vorbis_info_psy *vi=p->vi;
  103883. int partition=vi->normal_partition;
  103884. int start=vi->normal_start;
  103885. if(start>n)start=n;
  103886. if(vi->normal_channel_p){
  103887. for(;j<start;j++)
  103888. out[j]=rint(in[j]);
  103889. for(;j+partition<=n;j+=partition){
  103890. float acc=0.;
  103891. int k;
  103892. for(i=j;i<j+partition;i++)
  103893. acc+=in[i]*in[i];
  103894. for(i=0;i<partition;i++){
  103895. k=sortedindex[i+j-start];
  103896. if(in[k]*in[k]>=.25f){
  103897. out[k]=rint(in[k]);
  103898. acc-=in[k]*in[k];
  103899. flag=1;
  103900. }else{
  103901. if(acc<vi->normal_thresh)break;
  103902. out[k]=unitnorm(in[k]);
  103903. acc-=1.;
  103904. }
  103905. }
  103906. for(;i<partition;i++){
  103907. k=sortedindex[i+j-start];
  103908. out[k]=0.;
  103909. }
  103910. }
  103911. }
  103912. for(;j<n;j++)
  103913. out[j]=rint(in[j]);
  103914. }
  103915. void _vp_couple(int blobno,
  103916. vorbis_info_psy_global *g,
  103917. vorbis_look_psy *p,
  103918. vorbis_info_mapping0 *vi,
  103919. float **res,
  103920. float **mag_memo,
  103921. int **mag_sort,
  103922. int **ifloor,
  103923. int *nonzero,
  103924. int sliding_lowpass){
  103925. int i,j,k,n=p->n;
  103926. for(i=0;i<vi->coupling_steps;i++){
  103927. if(nonzero[vi->coupling_mag[i]] ||
  103928. nonzero[vi->coupling_ang[i]]){
  103929. float *rM=res[vi->coupling_mag[i]];
  103930. float *rA=res[vi->coupling_ang[i]];
  103931. float *qM=rM+n;
  103932. float *qA=rA+n;
  103933. int *floorM=ifloor[vi->coupling_mag[i]];
  103934. int *floorA=ifloor[vi->coupling_ang[i]];
  103935. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103936. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  103937. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  103938. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  103939. int pointlimit=limit;
  103940. nonzero[vi->coupling_mag[i]]=1;
  103941. nonzero[vi->coupling_ang[i]]=1;
  103942. if(n > 1000)
  103943. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  103944. for(j=0;j<p->n;j+=partition){
  103945. float acc=0.f;
  103946. for(k=0;k<partition;k++){
  103947. int l=k+j;
  103948. if(l<sliding_lowpass){
  103949. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  103950. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  103951. precomputed_couple_point(mag_memo[i][l],
  103952. floorM[l],floorA[l],
  103953. qM+l,qA+l);
  103954. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  103955. }else{
  103956. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  103957. }
  103958. }else{
  103959. qM[l]=0.;
  103960. qA[l]=0.;
  103961. }
  103962. }
  103963. if(p->vi->normal_point_p){
  103964. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  103965. int l=mag_sort[i][j+k];
  103966. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  103967. qM[l]=unitnorm(qM[l]);
  103968. acc-=1.f;
  103969. }
  103970. }
  103971. }
  103972. }
  103973. }
  103974. }
  103975. }
  103976. void hf_reduction(vorbis_info_psy_global *g,
  103977. vorbis_look_psy *p,
  103978. vorbis_info_mapping0 *vi,
  103979. float **mdct){
  103980. int i,j,n=p->n, de=0.3*p->m_val;
  103981. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103982. for(i=0; i<vi->coupling_steps; i++){
  103983. for(j=limit; j<n; j++)
  103984. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  103985. }
  103986. }
  103987. #endif
  103988. /*** End of inlined file: psy.c ***/
  103989. /*** Start of inlined file: registry.c ***/
  103990. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103991. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103992. // tasks..
  103993. #if JUCE_MSVC
  103994. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103995. #endif
  103996. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103997. #if JUCE_USE_OGGVORBIS
  103998. extern vorbis_func_floor floor0_exportbundle;
  103999. extern vorbis_func_floor floor1_exportbundle;
  104000. extern vorbis_func_residue residue0_exportbundle;
  104001. extern vorbis_func_residue residue1_exportbundle;
  104002. extern vorbis_func_residue residue2_exportbundle;
  104003. extern vorbis_func_mapping mapping0_exportbundle;
  104004. vorbis_func_floor *_floor_P[]={
  104005. &floor0_exportbundle,
  104006. &floor1_exportbundle,
  104007. };
  104008. vorbis_func_residue *_residue_P[]={
  104009. &residue0_exportbundle,
  104010. &residue1_exportbundle,
  104011. &residue2_exportbundle,
  104012. };
  104013. vorbis_func_mapping *_mapping_P[]={
  104014. &mapping0_exportbundle,
  104015. };
  104016. #endif
  104017. /*** End of inlined file: registry.c ***/
  104018. /*** Start of inlined file: res0.c ***/
  104019. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104020. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104021. // tasks..
  104022. #if JUCE_MSVC
  104023. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104024. #endif
  104025. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104026. #if JUCE_USE_OGGVORBIS
  104027. #include <stdlib.h>
  104028. #include <string.h>
  104029. #include <math.h>
  104030. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104031. #include <stdio.h>
  104032. #endif
  104033. typedef struct {
  104034. vorbis_info_residue0 *info;
  104035. int parts;
  104036. int stages;
  104037. codebook *fullbooks;
  104038. codebook *phrasebook;
  104039. codebook ***partbooks;
  104040. int partvals;
  104041. int **decodemap;
  104042. long postbits;
  104043. long phrasebits;
  104044. long frames;
  104045. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104046. int train_seq;
  104047. long *training_data[8][64];
  104048. float training_max[8][64];
  104049. float training_min[8][64];
  104050. float tmin;
  104051. float tmax;
  104052. #endif
  104053. } vorbis_look_residue0;
  104054. void res0_free_info(vorbis_info_residue *i){
  104055. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104056. if(info){
  104057. memset(info,0,sizeof(*info));
  104058. _ogg_free(info);
  104059. }
  104060. }
  104061. void res0_free_look(vorbis_look_residue *i){
  104062. int j;
  104063. if(i){
  104064. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104065. #ifdef TRAIN_RES
  104066. {
  104067. int j,k,l;
  104068. for(j=0;j<look->parts;j++){
  104069. for(k=0;k<8;k++)
  104070. if(look->training_data[k][j]){
  104071. char buffer[80];
  104072. FILE *of;
  104073. codebook *statebook=look->partbooks[j][k];
  104074. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104075. of=fopen(buffer,"a");
  104076. for(l=0;l<statebook->entries;l++)
  104077. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104078. fclose(of);
  104079. _ogg_free(look->training_data[k][j]);
  104080. look->training_data[k][j]=NULL;
  104081. }
  104082. }
  104083. }
  104084. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104085. #endif
  104086. for(j=0;j<look->parts;j++)
  104087. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104088. _ogg_free(look->partbooks);
  104089. for(j=0;j<look->partvals;j++)
  104090. _ogg_free(look->decodemap[j]);
  104091. _ogg_free(look->decodemap);
  104092. memset(look,0,sizeof(*look));
  104093. _ogg_free(look);
  104094. }
  104095. }
  104096. static int icount(unsigned int v){
  104097. int ret=0;
  104098. while(v){
  104099. ret+=v&1;
  104100. v>>=1;
  104101. }
  104102. return(ret);
  104103. }
  104104. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104105. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104106. int j,acc=0;
  104107. oggpack_write(opb,info->begin,24);
  104108. oggpack_write(opb,info->end,24);
  104109. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104110. code with a partitioned book */
  104111. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104112. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104113. for(j=0;j<info->partitions;j++){
  104114. if(ilog(info->secondstages[j])>3){
  104115. oggpack_write(opb,info->secondstages[j],3);
  104116. oggpack_write(opb,1,1);
  104117. oggpack_write(opb,info->secondstages[j]>>3,5);
  104118. }else
  104119. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104120. acc+=icount(info->secondstages[j]);
  104121. }
  104122. for(j=0;j<acc;j++)
  104123. oggpack_write(opb,info->booklist[j],8);
  104124. }
  104125. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104126. int j,acc=0;
  104127. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104128. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104129. info->begin=oggpack_read(opb,24);
  104130. info->end=oggpack_read(opb,24);
  104131. info->grouping=oggpack_read(opb,24)+1;
  104132. info->partitions=oggpack_read(opb,6)+1;
  104133. info->groupbook=oggpack_read(opb,8);
  104134. for(j=0;j<info->partitions;j++){
  104135. int cascade=oggpack_read(opb,3);
  104136. if(oggpack_read(opb,1))
  104137. cascade|=(oggpack_read(opb,5)<<3);
  104138. info->secondstages[j]=cascade;
  104139. acc+=icount(cascade);
  104140. }
  104141. for(j=0;j<acc;j++)
  104142. info->booklist[j]=oggpack_read(opb,8);
  104143. if(info->groupbook>=ci->books)goto errout;
  104144. for(j=0;j<acc;j++)
  104145. if(info->booklist[j]>=ci->books)goto errout;
  104146. return(info);
  104147. errout:
  104148. res0_free_info(info);
  104149. return(NULL);
  104150. }
  104151. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104152. vorbis_info_residue *vr){
  104153. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104154. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104155. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104156. int j,k,acc=0;
  104157. int dim;
  104158. int maxstage=0;
  104159. look->info=info;
  104160. look->parts=info->partitions;
  104161. look->fullbooks=ci->fullbooks;
  104162. look->phrasebook=ci->fullbooks+info->groupbook;
  104163. dim=look->phrasebook->dim;
  104164. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104165. for(j=0;j<look->parts;j++){
  104166. int stages=ilog(info->secondstages[j]);
  104167. if(stages){
  104168. if(stages>maxstage)maxstage=stages;
  104169. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104170. for(k=0;k<stages;k++)
  104171. if(info->secondstages[j]&(1<<k)){
  104172. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104173. #ifdef TRAIN_RES
  104174. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104175. sizeof(***look->training_data));
  104176. #endif
  104177. }
  104178. }
  104179. }
  104180. look->partvals=rint(pow((float)look->parts,(float)dim));
  104181. look->stages=maxstage;
  104182. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104183. for(j=0;j<look->partvals;j++){
  104184. long val=j;
  104185. long mult=look->partvals/look->parts;
  104186. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104187. for(k=0;k<dim;k++){
  104188. long deco=val/mult;
  104189. val-=deco*mult;
  104190. mult/=look->parts;
  104191. look->decodemap[j][k]=deco;
  104192. }
  104193. }
  104194. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104195. {
  104196. static int train_seq=0;
  104197. look->train_seq=train_seq++;
  104198. }
  104199. #endif
  104200. return(look);
  104201. }
  104202. static int local_book_besterror(codebook *book,float *a){
  104203. int dim=book->dim,i,k,o;
  104204. int best=0;
  104205. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104206. for(k=0,o=dim;k<dim;++k){
  104207. float val=a[--o];
  104208. i=tt->threshvals>>1;
  104209. if(val<tt->quantthresh[i]){
  104210. if(val<tt->quantthresh[i-1]){
  104211. for(--i;i>0;--i)
  104212. if(val>=tt->quantthresh[i-1])
  104213. break;
  104214. }
  104215. }else{
  104216. for(++i;i<tt->threshvals-1;++i)
  104217. if(val<tt->quantthresh[i])break;
  104218. }
  104219. best=(best*tt->quantvals)+tt->quantmap[i];
  104220. }
  104221. if(book->c->lengthlist[best]<=0){
  104222. const static_codebook *c=book->c;
  104223. int i,j;
  104224. float bestf=0.f;
  104225. float *e=book->valuelist;
  104226. best=-1;
  104227. for(i=0;i<book->entries;i++){
  104228. if(c->lengthlist[i]>0){
  104229. float thisx=0.f;
  104230. for(j=0;j<dim;j++){
  104231. float val=(e[j]-a[j]);
  104232. thisx+=val*val;
  104233. }
  104234. if(best==-1 || thisx<bestf){
  104235. bestf=thisx;
  104236. best=i;
  104237. }
  104238. }
  104239. e+=dim;
  104240. }
  104241. }
  104242. {
  104243. float *ptr=book->valuelist+best*dim;
  104244. for(i=0;i<dim;i++)
  104245. *a++ -= *ptr++;
  104246. }
  104247. return(best);
  104248. }
  104249. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104250. codebook *book,long *acc){
  104251. int i,bits=0;
  104252. int dim=book->dim;
  104253. int step=n/dim;
  104254. for(i=0;i<step;i++){
  104255. int entry=local_book_besterror(book,vec+i*dim);
  104256. #ifdef TRAIN_RES
  104257. acc[entry]++;
  104258. #endif
  104259. bits+=vorbis_book_encode(book,entry,opb);
  104260. }
  104261. return(bits);
  104262. }
  104263. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104264. float **in,int ch){
  104265. long i,j,k;
  104266. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104267. vorbis_info_residue0 *info=look->info;
  104268. int samples_per_partition=info->grouping;
  104269. int possible_partitions=info->partitions;
  104270. int n=info->end-info->begin;
  104271. int partvals=n/samples_per_partition;
  104272. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104273. float scale=100./samples_per_partition;
  104274. for(i=0;i<ch;i++){
  104275. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104276. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104277. }
  104278. for(i=0;i<partvals;i++){
  104279. int offset=i*samples_per_partition+info->begin;
  104280. for(j=0;j<ch;j++){
  104281. float max=0.;
  104282. float ent=0.;
  104283. for(k=0;k<samples_per_partition;k++){
  104284. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104285. ent+=fabs(rint(in[j][offset+k]));
  104286. }
  104287. ent*=scale;
  104288. for(k=0;k<possible_partitions-1;k++)
  104289. if(max<=info->classmetric1[k] &&
  104290. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104291. break;
  104292. partword[j][i]=k;
  104293. }
  104294. }
  104295. #ifdef TRAIN_RESAUX
  104296. {
  104297. FILE *of;
  104298. char buffer[80];
  104299. for(i=0;i<ch;i++){
  104300. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104301. of=fopen(buffer,"a");
  104302. for(j=0;j<partvals;j++)
  104303. fprintf(of,"%ld, ",partword[i][j]);
  104304. fprintf(of,"\n");
  104305. fclose(of);
  104306. }
  104307. }
  104308. #endif
  104309. look->frames++;
  104310. return(partword);
  104311. }
  104312. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104313. int ch){
  104314. long i,j,k,l;
  104315. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104316. vorbis_info_residue0 *info=look->info;
  104317. int samples_per_partition=info->grouping;
  104318. int possible_partitions=info->partitions;
  104319. int n=info->end-info->begin;
  104320. int partvals=n/samples_per_partition;
  104321. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104322. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104323. FILE *of;
  104324. char buffer[80];
  104325. #endif
  104326. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104327. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104328. for(i=0,l=info->begin/ch;i<partvals;i++){
  104329. float magmax=0.f;
  104330. float angmax=0.f;
  104331. for(j=0;j<samples_per_partition;j+=ch){
  104332. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104333. for(k=1;k<ch;k++)
  104334. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104335. l++;
  104336. }
  104337. for(j=0;j<possible_partitions-1;j++)
  104338. if(magmax<=info->classmetric1[j] &&
  104339. angmax<=info->classmetric2[j])
  104340. break;
  104341. partword[0][i]=j;
  104342. }
  104343. #ifdef TRAIN_RESAUX
  104344. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104345. of=fopen(buffer,"a");
  104346. for(i=0;i<partvals;i++)
  104347. fprintf(of,"%ld, ",partword[0][i]);
  104348. fprintf(of,"\n");
  104349. fclose(of);
  104350. #endif
  104351. look->frames++;
  104352. return(partword);
  104353. }
  104354. static int _01forward(oggpack_buffer *opb,
  104355. vorbis_block *vb,vorbis_look_residue *vl,
  104356. float **in,int ch,
  104357. long **partword,
  104358. int (*encode)(oggpack_buffer *,float *,int,
  104359. codebook *,long *)){
  104360. long i,j,k,s;
  104361. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104362. vorbis_info_residue0 *info=look->info;
  104363. int samples_per_partition=info->grouping;
  104364. int possible_partitions=info->partitions;
  104365. int partitions_per_word=look->phrasebook->dim;
  104366. int n=info->end-info->begin;
  104367. int partvals=n/samples_per_partition;
  104368. long resbits[128];
  104369. long resvals[128];
  104370. #ifdef TRAIN_RES
  104371. for(i=0;i<ch;i++)
  104372. for(j=info->begin;j<info->end;j++){
  104373. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104374. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104375. }
  104376. #endif
  104377. memset(resbits,0,sizeof(resbits));
  104378. memset(resvals,0,sizeof(resvals));
  104379. for(s=0;s<look->stages;s++){
  104380. for(i=0;i<partvals;){
  104381. if(s==0){
  104382. for(j=0;j<ch;j++){
  104383. long val=partword[j][i];
  104384. for(k=1;k<partitions_per_word;k++){
  104385. val*=possible_partitions;
  104386. if(i+k<partvals)
  104387. val+=partword[j][i+k];
  104388. }
  104389. if(val<look->phrasebook->entries)
  104390. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104391. #if 0 /*def TRAIN_RES*/
  104392. else
  104393. fprintf(stderr,"!");
  104394. #endif
  104395. }
  104396. }
  104397. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104398. long offset=i*samples_per_partition+info->begin;
  104399. for(j=0;j<ch;j++){
  104400. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104401. if(info->secondstages[partword[j][i]]&(1<<s)){
  104402. codebook *statebook=look->partbooks[partword[j][i]][s];
  104403. if(statebook){
  104404. int ret;
  104405. long *accumulator=NULL;
  104406. #ifdef TRAIN_RES
  104407. accumulator=look->training_data[s][partword[j][i]];
  104408. {
  104409. int l;
  104410. float *samples=in[j]+offset;
  104411. for(l=0;l<samples_per_partition;l++){
  104412. if(samples[l]<look->training_min[s][partword[j][i]])
  104413. look->training_min[s][partword[j][i]]=samples[l];
  104414. if(samples[l]>look->training_max[s][partword[j][i]])
  104415. look->training_max[s][partword[j][i]]=samples[l];
  104416. }
  104417. }
  104418. #endif
  104419. ret=encode(opb,in[j]+offset,samples_per_partition,
  104420. statebook,accumulator);
  104421. look->postbits+=ret;
  104422. resbits[partword[j][i]]+=ret;
  104423. }
  104424. }
  104425. }
  104426. }
  104427. }
  104428. }
  104429. return(0);
  104430. }
  104431. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104432. float **in,int ch,
  104433. long (*decodepart)(codebook *, float *,
  104434. oggpack_buffer *,int)){
  104435. long i,j,k,l,s;
  104436. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104437. vorbis_info_residue0 *info=look->info;
  104438. int samples_per_partition=info->grouping;
  104439. int partitions_per_word=look->phrasebook->dim;
  104440. int n=info->end-info->begin;
  104441. int partvals=n/samples_per_partition;
  104442. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104443. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104444. for(j=0;j<ch;j++)
  104445. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104446. for(s=0;s<look->stages;s++){
  104447. for(i=0,l=0;i<partvals;l++){
  104448. if(s==0){
  104449. for(j=0;j<ch;j++){
  104450. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104451. if(temp==-1)goto eopbreak;
  104452. partword[j][l]=look->decodemap[temp];
  104453. if(partword[j][l]==NULL)goto errout;
  104454. }
  104455. }
  104456. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104457. for(j=0;j<ch;j++){
  104458. long offset=info->begin+i*samples_per_partition;
  104459. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104460. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104461. if(stagebook){
  104462. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104463. samples_per_partition)==-1)goto eopbreak;
  104464. }
  104465. }
  104466. }
  104467. }
  104468. }
  104469. errout:
  104470. eopbreak:
  104471. return(0);
  104472. }
  104473. #if 0
  104474. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104475. float **in,int *nonzero,int ch){
  104476. int i,used=0;
  104477. for(i=0;i<ch;i++)
  104478. if(nonzero[i])
  104479. in[used++]=in[i];
  104480. if(used)
  104481. return(_01class(vb,vl,in,used));
  104482. else
  104483. return(0);
  104484. }
  104485. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104486. float **in,float **out,int *nonzero,int ch,
  104487. long **partword){
  104488. int i,j,used=0,n=vb->pcmend/2;
  104489. for(i=0;i<ch;i++)
  104490. if(nonzero[i]){
  104491. if(out)
  104492. for(j=0;j<n;j++)
  104493. out[i][j]+=in[i][j];
  104494. in[used++]=in[i];
  104495. }
  104496. if(used){
  104497. int ret=_01forward(vb,vl,in,used,partword,
  104498. _interleaved_encodepart);
  104499. if(out){
  104500. used=0;
  104501. for(i=0;i<ch;i++)
  104502. if(nonzero[i]){
  104503. for(j=0;j<n;j++)
  104504. out[i][j]-=in[used][j];
  104505. used++;
  104506. }
  104507. }
  104508. return(ret);
  104509. }else{
  104510. return(0);
  104511. }
  104512. }
  104513. #endif
  104514. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104515. float **in,int *nonzero,int ch){
  104516. int i,used=0;
  104517. for(i=0;i<ch;i++)
  104518. if(nonzero[i])
  104519. in[used++]=in[i];
  104520. if(used)
  104521. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104522. else
  104523. return(0);
  104524. }
  104525. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104526. float **in,float **out,int *nonzero,int ch,
  104527. long **partword){
  104528. int i,j,used=0,n=vb->pcmend/2;
  104529. for(i=0;i<ch;i++)
  104530. if(nonzero[i]){
  104531. if(out)
  104532. for(j=0;j<n;j++)
  104533. out[i][j]+=in[i][j];
  104534. in[used++]=in[i];
  104535. }
  104536. if(used){
  104537. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104538. if(out){
  104539. used=0;
  104540. for(i=0;i<ch;i++)
  104541. if(nonzero[i]){
  104542. for(j=0;j<n;j++)
  104543. out[i][j]-=in[used][j];
  104544. used++;
  104545. }
  104546. }
  104547. return(ret);
  104548. }else{
  104549. return(0);
  104550. }
  104551. }
  104552. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104553. float **in,int *nonzero,int ch){
  104554. int i,used=0;
  104555. for(i=0;i<ch;i++)
  104556. if(nonzero[i])
  104557. in[used++]=in[i];
  104558. if(used)
  104559. return(_01class(vb,vl,in,used));
  104560. else
  104561. return(0);
  104562. }
  104563. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104564. float **in,int *nonzero,int ch){
  104565. int i,used=0;
  104566. for(i=0;i<ch;i++)
  104567. if(nonzero[i])
  104568. in[used++]=in[i];
  104569. if(used)
  104570. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104571. else
  104572. return(0);
  104573. }
  104574. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104575. float **in,int *nonzero,int ch){
  104576. int i,used=0;
  104577. for(i=0;i<ch;i++)
  104578. if(nonzero[i])used++;
  104579. if(used)
  104580. return(_2class(vb,vl,in,ch));
  104581. else
  104582. return(0);
  104583. }
  104584. int res2_forward(oggpack_buffer *opb,
  104585. vorbis_block *vb,vorbis_look_residue *vl,
  104586. float **in,float **out,int *nonzero,int ch,
  104587. long **partword){
  104588. long i,j,k,n=vb->pcmend/2,used=0;
  104589. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104590. for(i=0;i<ch;i++){
  104591. float *pcm=in[i];
  104592. if(nonzero[i])used++;
  104593. for(j=0,k=i;j<n;j++,k+=ch)
  104594. work[k]=pcm[j];
  104595. }
  104596. if(used){
  104597. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104598. if(out){
  104599. for(i=0;i<ch;i++){
  104600. float *pcm=in[i];
  104601. float *sofar=out[i];
  104602. for(j=0,k=i;j<n;j++,k+=ch)
  104603. sofar[j]+=pcm[j]-work[k];
  104604. }
  104605. }
  104606. return(ret);
  104607. }else{
  104608. return(0);
  104609. }
  104610. }
  104611. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104612. float **in,int *nonzero,int ch){
  104613. long i,k,l,s;
  104614. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104615. vorbis_info_residue0 *info=look->info;
  104616. int samples_per_partition=info->grouping;
  104617. int partitions_per_word=look->phrasebook->dim;
  104618. int n=info->end-info->begin;
  104619. int partvals=n/samples_per_partition;
  104620. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104621. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104622. for(i=0;i<ch;i++)if(nonzero[i])break;
  104623. if(i==ch)return(0); /* no nonzero vectors */
  104624. for(s=0;s<look->stages;s++){
  104625. for(i=0,l=0;i<partvals;l++){
  104626. if(s==0){
  104627. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104628. if(temp==-1)goto eopbreak;
  104629. partword[l]=look->decodemap[temp];
  104630. if(partword[l]==NULL)goto errout;
  104631. }
  104632. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104633. if(info->secondstages[partword[l][k]]&(1<<s)){
  104634. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104635. if(stagebook){
  104636. if(vorbis_book_decodevv_add(stagebook,in,
  104637. i*samples_per_partition+info->begin,ch,
  104638. &vb->opb,samples_per_partition)==-1)
  104639. goto eopbreak;
  104640. }
  104641. }
  104642. }
  104643. }
  104644. errout:
  104645. eopbreak:
  104646. return(0);
  104647. }
  104648. vorbis_func_residue residue0_exportbundle={
  104649. NULL,
  104650. &res0_unpack,
  104651. &res0_look,
  104652. &res0_free_info,
  104653. &res0_free_look,
  104654. NULL,
  104655. NULL,
  104656. &res0_inverse
  104657. };
  104658. vorbis_func_residue residue1_exportbundle={
  104659. &res0_pack,
  104660. &res0_unpack,
  104661. &res0_look,
  104662. &res0_free_info,
  104663. &res0_free_look,
  104664. &res1_class,
  104665. &res1_forward,
  104666. &res1_inverse
  104667. };
  104668. vorbis_func_residue residue2_exportbundle={
  104669. &res0_pack,
  104670. &res0_unpack,
  104671. &res0_look,
  104672. &res0_free_info,
  104673. &res0_free_look,
  104674. &res2_class,
  104675. &res2_forward,
  104676. &res2_inverse
  104677. };
  104678. #endif
  104679. /*** End of inlined file: res0.c ***/
  104680. /*** Start of inlined file: sharedbook.c ***/
  104681. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104682. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104683. // tasks..
  104684. #if JUCE_MSVC
  104685. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104686. #endif
  104687. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104688. #if JUCE_USE_OGGVORBIS
  104689. #include <stdlib.h>
  104690. #include <math.h>
  104691. #include <string.h>
  104692. int _ilog(unsigned int v){
  104693. int ret=0;
  104694. while(v){
  104695. ret++;
  104696. v>>=1;
  104697. }
  104698. return(ret);
  104699. }
  104700. #define VQ_FEXP 10
  104701. #define VQ_FMAN 21
  104702. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104703. long _float32_pack(float val){
  104704. int sign=0;
  104705. long exp;
  104706. long mant;
  104707. if(val<0){
  104708. sign=0x80000000;
  104709. val= -val;
  104710. }
  104711. exp= floor(log(val)/log(2.f));
  104712. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104713. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104714. return(sign|exp|mant);
  104715. }
  104716. float _float32_unpack(long val){
  104717. double mant=val&0x1fffff;
  104718. int sign=val&0x80000000;
  104719. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104720. if(sign)mant= -mant;
  104721. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104722. }
  104723. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104724. long i,j,count=0;
  104725. ogg_uint32_t marker[33];
  104726. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104727. memset(marker,0,sizeof(marker));
  104728. for(i=0;i<n;i++){
  104729. long length=l[i];
  104730. if(length>0){
  104731. ogg_uint32_t entry=marker[length];
  104732. if(length<32 && (entry>>length)){
  104733. _ogg_free(r);
  104734. return(NULL);
  104735. }
  104736. r[count++]=entry;
  104737. {
  104738. for(j=length;j>0;j--){
  104739. if(marker[j]&1){
  104740. if(j==1)
  104741. marker[1]++;
  104742. else
  104743. marker[j]=marker[j-1]<<1;
  104744. break; /* invariant says next upper marker would already
  104745. have been moved if it was on the same path */
  104746. }
  104747. marker[j]++;
  104748. }
  104749. }
  104750. for(j=length+1;j<33;j++)
  104751. if((marker[j]>>1) == entry){
  104752. entry=marker[j];
  104753. marker[j]=marker[j-1]<<1;
  104754. }else
  104755. break;
  104756. }else
  104757. if(sparsecount==0)count++;
  104758. }
  104759. for(i=0,count=0;i<n;i++){
  104760. ogg_uint32_t temp=0;
  104761. for(j=0;j<l[i];j++){
  104762. temp<<=1;
  104763. temp|=(r[count]>>j)&1;
  104764. }
  104765. if(sparsecount){
  104766. if(l[i])
  104767. r[count++]=temp;
  104768. }else
  104769. r[count++]=temp;
  104770. }
  104771. return(r);
  104772. }
  104773. long _book_maptype1_quantvals(const static_codebook *b){
  104774. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104775. while(1){
  104776. long acc=1;
  104777. long acc1=1;
  104778. int i;
  104779. for(i=0;i<b->dim;i++){
  104780. acc*=vals;
  104781. acc1*=vals+1;
  104782. }
  104783. if(acc<=b->entries && acc1>b->entries){
  104784. return(vals);
  104785. }else{
  104786. if(acc>b->entries){
  104787. vals--;
  104788. }else{
  104789. vals++;
  104790. }
  104791. }
  104792. }
  104793. }
  104794. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104795. long j,k,count=0;
  104796. if(b->maptype==1 || b->maptype==2){
  104797. int quantvals;
  104798. float mindel=_float32_unpack(b->q_min);
  104799. float delta=_float32_unpack(b->q_delta);
  104800. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104801. switch(b->maptype){
  104802. case 1:
  104803. quantvals=_book_maptype1_quantvals(b);
  104804. for(j=0;j<b->entries;j++){
  104805. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104806. float last=0.f;
  104807. int indexdiv=1;
  104808. for(k=0;k<b->dim;k++){
  104809. int index= (j/indexdiv)%quantvals;
  104810. float val=b->quantlist[index];
  104811. val=fabs(val)*delta+mindel+last;
  104812. if(b->q_sequencep)last=val;
  104813. if(sparsemap)
  104814. r[sparsemap[count]*b->dim+k]=val;
  104815. else
  104816. r[count*b->dim+k]=val;
  104817. indexdiv*=quantvals;
  104818. }
  104819. count++;
  104820. }
  104821. }
  104822. break;
  104823. case 2:
  104824. for(j=0;j<b->entries;j++){
  104825. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104826. float last=0.f;
  104827. for(k=0;k<b->dim;k++){
  104828. float val=b->quantlist[j*b->dim+k];
  104829. val=fabs(val)*delta+mindel+last;
  104830. if(b->q_sequencep)last=val;
  104831. if(sparsemap)
  104832. r[sparsemap[count]*b->dim+k]=val;
  104833. else
  104834. r[count*b->dim+k]=val;
  104835. }
  104836. count++;
  104837. }
  104838. }
  104839. break;
  104840. }
  104841. return(r);
  104842. }
  104843. return(NULL);
  104844. }
  104845. void vorbis_staticbook_clear(static_codebook *b){
  104846. if(b->allocedp){
  104847. if(b->quantlist)_ogg_free(b->quantlist);
  104848. if(b->lengthlist)_ogg_free(b->lengthlist);
  104849. if(b->nearest_tree){
  104850. _ogg_free(b->nearest_tree->ptr0);
  104851. _ogg_free(b->nearest_tree->ptr1);
  104852. _ogg_free(b->nearest_tree->p);
  104853. _ogg_free(b->nearest_tree->q);
  104854. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104855. _ogg_free(b->nearest_tree);
  104856. }
  104857. if(b->thresh_tree){
  104858. _ogg_free(b->thresh_tree->quantthresh);
  104859. _ogg_free(b->thresh_tree->quantmap);
  104860. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104861. _ogg_free(b->thresh_tree);
  104862. }
  104863. memset(b,0,sizeof(*b));
  104864. }
  104865. }
  104866. void vorbis_staticbook_destroy(static_codebook *b){
  104867. if(b->allocedp){
  104868. vorbis_staticbook_clear(b);
  104869. _ogg_free(b);
  104870. }
  104871. }
  104872. void vorbis_book_clear(codebook *b){
  104873. if(b->valuelist)_ogg_free(b->valuelist);
  104874. if(b->codelist)_ogg_free(b->codelist);
  104875. if(b->dec_index)_ogg_free(b->dec_index);
  104876. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104877. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104878. memset(b,0,sizeof(*b));
  104879. }
  104880. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104881. memset(c,0,sizeof(*c));
  104882. c->c=s;
  104883. c->entries=s->entries;
  104884. c->used_entries=s->entries;
  104885. c->dim=s->dim;
  104886. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104887. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104888. return(0);
  104889. }
  104890. static int sort32a(const void *a,const void *b){
  104891. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104892. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104893. }
  104894. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104895. int i,j,n=0,tabn;
  104896. int *sortindex;
  104897. memset(c,0,sizeof(*c));
  104898. for(i=0;i<s->entries;i++)
  104899. if(s->lengthlist[i]>0)
  104900. n++;
  104901. c->entries=s->entries;
  104902. c->used_entries=n;
  104903. c->dim=s->dim;
  104904. {
  104905. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104906. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104907. if(codes==NULL)goto err_out;
  104908. for(i=0;i<n;i++){
  104909. codes[i]=ogg_bitreverse(codes[i]);
  104910. codep[i]=codes+i;
  104911. }
  104912. qsort(codep,n,sizeof(*codep),sort32a);
  104913. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104914. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104915. for(i=0;i<n;i++){
  104916. int position=codep[i]-codes;
  104917. sortindex[position]=i;
  104918. }
  104919. for(i=0;i<n;i++)
  104920. c->codelist[sortindex[i]]=codes[i];
  104921. _ogg_free(codes);
  104922. }
  104923. c->valuelist=_book_unquantize(s,n,sortindex);
  104924. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104925. for(n=0,i=0;i<s->entries;i++)
  104926. if(s->lengthlist[i]>0)
  104927. c->dec_index[sortindex[n++]]=i;
  104928. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104929. for(n=0,i=0;i<s->entries;i++)
  104930. if(s->lengthlist[i]>0)
  104931. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104932. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104933. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104934. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104935. tabn=1<<c->dec_firsttablen;
  104936. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  104937. c->dec_maxlength=0;
  104938. for(i=0;i<n;i++){
  104939. if(c->dec_maxlength<c->dec_codelengths[i])
  104940. c->dec_maxlength=c->dec_codelengths[i];
  104941. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  104942. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  104943. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  104944. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  104945. }
  104946. }
  104947. {
  104948. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  104949. long lo=0,hi=0;
  104950. for(i=0;i<tabn;i++){
  104951. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  104952. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  104953. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  104954. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  104955. {
  104956. unsigned long loval=lo;
  104957. unsigned long hival=n-hi;
  104958. if(loval>0x7fff)loval=0x7fff;
  104959. if(hival>0x7fff)hival=0x7fff;
  104960. c->dec_firsttable[ogg_bitreverse(word)]=
  104961. 0x80000000UL | (loval<<15) | hival;
  104962. }
  104963. }
  104964. }
  104965. }
  104966. return(0);
  104967. err_out:
  104968. vorbis_book_clear(c);
  104969. return(-1);
  104970. }
  104971. static float _dist(int el,float *ref, float *b,int step){
  104972. int i;
  104973. float acc=0.f;
  104974. for(i=0;i<el;i++){
  104975. float val=(ref[i]-b[i*step]);
  104976. acc+=val*val;
  104977. }
  104978. return(acc);
  104979. }
  104980. int _best(codebook *book, float *a, int step){
  104981. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104982. #if 0
  104983. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  104984. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  104985. #endif
  104986. int dim=book->dim;
  104987. int k,o;
  104988. if(tt){
  104989. int index=0,i;
  104990. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104991. i=tt->threshvals>>1;
  104992. if(a[o]<tt->quantthresh[i]){
  104993. for(;i>0;i--)
  104994. if(a[o]>=tt->quantthresh[i-1])
  104995. break;
  104996. }else{
  104997. for(i++;i<tt->threshvals-1;i++)
  104998. if(a[o]<tt->quantthresh[i])break;
  104999. }
  105000. index=(index*tt->quantvals)+tt->quantmap[i];
  105001. }
  105002. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  105003. use a decision tree after all
  105004. and fall through*/
  105005. return(index);
  105006. }
  105007. #if 0
  105008. if(pt){
  105009. const static_codebook *c=book->c;
  105010. int i,besti=-1;
  105011. float best=0.f;
  105012. int entry=0;
  105013. if(c->q_sequencep){
  105014. int pv;
  105015. long mul=1;
  105016. float qlast=0;
  105017. for(k=0,o=0;k<dim;k++,o+=step){
  105018. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  105019. if(pv<0 || pv>=pt->mapentries)break;
  105020. entry+=pt->pigeonmap[pv]*mul;
  105021. mul*=pt->quantvals;
  105022. qlast+=pv*pt->del+pt->min;
  105023. }
  105024. }else{
  105025. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105026. int pv=(int)((a[o]-pt->min)/pt->del);
  105027. if(pv<0 || pv>=pt->mapentries)break;
  105028. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105029. }
  105030. }
  105031. if(k==dim && pt->fitlength[entry]){
  105032. long *list=pt->fitlist+pt->fitmap[entry];
  105033. for(i=0;i<pt->fitlength[entry];i++){
  105034. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105035. if(besti==-1 || this<best){
  105036. best=this;
  105037. besti=list[i];
  105038. }
  105039. }
  105040. return(besti);
  105041. }
  105042. }
  105043. if(nt){
  105044. while(1){
  105045. float c=0.f;
  105046. float *p=book->valuelist+nt->p[ptr];
  105047. float *q=book->valuelist+nt->q[ptr];
  105048. for(k=0,o=0;k<dim;k++,o+=step)
  105049. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105050. if(c>0.f) /* in A */
  105051. ptr= -nt->ptr0[ptr];
  105052. else /* in B */
  105053. ptr= -nt->ptr1[ptr];
  105054. if(ptr<=0)break;
  105055. }
  105056. return(-ptr);
  105057. }
  105058. #endif
  105059. {
  105060. const static_codebook *c=book->c;
  105061. int i,besti=-1;
  105062. float best=0.f;
  105063. float *e=book->valuelist;
  105064. for(i=0;i<book->entries;i++){
  105065. if(c->lengthlist[i]>0){
  105066. float thisx=_dist(dim,e,a,step);
  105067. if(besti==-1 || thisx<best){
  105068. best=thisx;
  105069. besti=i;
  105070. }
  105071. }
  105072. e+=dim;
  105073. }
  105074. return(besti);
  105075. }
  105076. }
  105077. long vorbis_book_codeword(codebook *book,int entry){
  105078. if(book->c) /* only use with encode; decode optimizations are
  105079. allowed to break this */
  105080. return book->codelist[entry];
  105081. return -1;
  105082. }
  105083. long vorbis_book_codelen(codebook *book,int entry){
  105084. if(book->c) /* only use with encode; decode optimizations are
  105085. allowed to break this */
  105086. return book->c->lengthlist[entry];
  105087. return -1;
  105088. }
  105089. #ifdef _V_SELFTEST
  105090. #include <stdio.h>
  105091. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105092. static long partial_quantlist1[]={0,7,2};
  105093. static_codebook test1={
  105094. 4,16,
  105095. NULL,
  105096. 0,
  105097. 0,0,0,0,
  105098. NULL,
  105099. NULL,NULL
  105100. };
  105101. static float *test1_result=NULL;
  105102. static_codebook test2={
  105103. 4,3,
  105104. NULL,
  105105. 2,
  105106. -533200896,1611661312,4,0,
  105107. full_quantlist1,
  105108. NULL,NULL
  105109. };
  105110. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105111. static_codebook test3={
  105112. 4,3,
  105113. NULL,
  105114. 2,
  105115. -533200896,1611661312,4,1,
  105116. full_quantlist1,
  105117. NULL,NULL
  105118. };
  105119. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105120. static_codebook test4={
  105121. 3,27,
  105122. NULL,
  105123. 1,
  105124. -533200896,1611661312,4,0,
  105125. partial_quantlist1,
  105126. NULL,NULL
  105127. };
  105128. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105129. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105130. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105131. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105132. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105133. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105134. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105135. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105136. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105137. static_codebook test5={
  105138. 3,27,
  105139. NULL,
  105140. 1,
  105141. -533200896,1611661312,4,1,
  105142. partial_quantlist1,
  105143. NULL,NULL
  105144. };
  105145. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105146. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105147. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105148. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105149. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105150. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105151. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105152. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105153. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105154. void run_test(static_codebook *b,float *comp){
  105155. float *out=_book_unquantize(b,b->entries,NULL);
  105156. int i;
  105157. if(comp){
  105158. if(!out){
  105159. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105160. exit(1);
  105161. }
  105162. for(i=0;i<b->entries*b->dim;i++)
  105163. if(fabs(out[i]-comp[i])>.0001){
  105164. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105165. "position %d, %g != %g\n",i,out[i],comp[i]);
  105166. exit(1);
  105167. }
  105168. }else{
  105169. if(out){
  105170. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105171. " correct result should have been NULL\n");
  105172. exit(1);
  105173. }
  105174. }
  105175. }
  105176. int main(){
  105177. fprintf(stderr,"Dequant test 1... ");
  105178. run_test(&test1,test1_result);
  105179. fprintf(stderr,"OK\nDequant test 2... ");
  105180. run_test(&test2,test2_result);
  105181. fprintf(stderr,"OK\nDequant test 3... ");
  105182. run_test(&test3,test3_result);
  105183. fprintf(stderr,"OK\nDequant test 4... ");
  105184. run_test(&test4,test4_result);
  105185. fprintf(stderr,"OK\nDequant test 5... ");
  105186. run_test(&test5,test5_result);
  105187. fprintf(stderr,"OK\n\n");
  105188. return(0);
  105189. }
  105190. #endif
  105191. #endif
  105192. /*** End of inlined file: sharedbook.c ***/
  105193. /*** Start of inlined file: smallft.c ***/
  105194. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105195. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105196. // tasks..
  105197. #if JUCE_MSVC
  105198. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105199. #endif
  105200. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105201. #if JUCE_USE_OGGVORBIS
  105202. #include <stdlib.h>
  105203. #include <string.h>
  105204. #include <math.h>
  105205. static void drfti1(int n, float *wa, int *ifac){
  105206. static int ntryh[4] = { 4,2,3,5 };
  105207. static float tpi = 6.28318530717958648f;
  105208. float arg,argh,argld,fi;
  105209. int ntry=0,i,j=-1;
  105210. int k1, l1, l2, ib;
  105211. int ld, ii, ip, is, nq, nr;
  105212. int ido, ipm, nfm1;
  105213. int nl=n;
  105214. int nf=0;
  105215. L101:
  105216. j++;
  105217. if (j < 4)
  105218. ntry=ntryh[j];
  105219. else
  105220. ntry+=2;
  105221. L104:
  105222. nq=nl/ntry;
  105223. nr=nl-ntry*nq;
  105224. if (nr!=0) goto L101;
  105225. nf++;
  105226. ifac[nf+1]=ntry;
  105227. nl=nq;
  105228. if(ntry!=2)goto L107;
  105229. if(nf==1)goto L107;
  105230. for (i=1;i<nf;i++){
  105231. ib=nf-i+1;
  105232. ifac[ib+1]=ifac[ib];
  105233. }
  105234. ifac[2] = 2;
  105235. L107:
  105236. if(nl!=1)goto L104;
  105237. ifac[0]=n;
  105238. ifac[1]=nf;
  105239. argh=tpi/n;
  105240. is=0;
  105241. nfm1=nf-1;
  105242. l1=1;
  105243. if(nfm1==0)return;
  105244. for (k1=0;k1<nfm1;k1++){
  105245. ip=ifac[k1+2];
  105246. ld=0;
  105247. l2=l1*ip;
  105248. ido=n/l2;
  105249. ipm=ip-1;
  105250. for (j=0;j<ipm;j++){
  105251. ld+=l1;
  105252. i=is;
  105253. argld=(float)ld*argh;
  105254. fi=0.f;
  105255. for (ii=2;ii<ido;ii+=2){
  105256. fi+=1.f;
  105257. arg=fi*argld;
  105258. wa[i++]=cos(arg);
  105259. wa[i++]=sin(arg);
  105260. }
  105261. is+=ido;
  105262. }
  105263. l1=l2;
  105264. }
  105265. }
  105266. static void fdrffti(int n, float *wsave, int *ifac){
  105267. if (n == 1) return;
  105268. drfti1(n, wsave+n, ifac);
  105269. }
  105270. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105271. int i,k;
  105272. float ti2,tr2;
  105273. int t0,t1,t2,t3,t4,t5,t6;
  105274. t1=0;
  105275. t0=(t2=l1*ido);
  105276. t3=ido<<1;
  105277. for(k=0;k<l1;k++){
  105278. ch[t1<<1]=cc[t1]+cc[t2];
  105279. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105280. t1+=ido;
  105281. t2+=ido;
  105282. }
  105283. if(ido<2)return;
  105284. if(ido==2)goto L105;
  105285. t1=0;
  105286. t2=t0;
  105287. for(k=0;k<l1;k++){
  105288. t3=t2;
  105289. t4=(t1<<1)+(ido<<1);
  105290. t5=t1;
  105291. t6=t1+t1;
  105292. for(i=2;i<ido;i+=2){
  105293. t3+=2;
  105294. t4-=2;
  105295. t5+=2;
  105296. t6+=2;
  105297. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105298. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105299. ch[t6]=cc[t5]+ti2;
  105300. ch[t4]=ti2-cc[t5];
  105301. ch[t6-1]=cc[t5-1]+tr2;
  105302. ch[t4-1]=cc[t5-1]-tr2;
  105303. }
  105304. t1+=ido;
  105305. t2+=ido;
  105306. }
  105307. if(ido%2==1)return;
  105308. L105:
  105309. t3=(t2=(t1=ido)-1);
  105310. t2+=t0;
  105311. for(k=0;k<l1;k++){
  105312. ch[t1]=-cc[t2];
  105313. ch[t1-1]=cc[t3];
  105314. t1+=ido<<1;
  105315. t2+=ido;
  105316. t3+=ido;
  105317. }
  105318. }
  105319. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105320. float *wa2,float *wa3){
  105321. static float hsqt2 = .70710678118654752f;
  105322. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105323. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105324. t0=l1*ido;
  105325. t1=t0;
  105326. t4=t1<<1;
  105327. t2=t1+(t1<<1);
  105328. t3=0;
  105329. for(k=0;k<l1;k++){
  105330. tr1=cc[t1]+cc[t2];
  105331. tr2=cc[t3]+cc[t4];
  105332. ch[t5=t3<<2]=tr1+tr2;
  105333. ch[(ido<<2)+t5-1]=tr2-tr1;
  105334. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105335. ch[t5]=cc[t2]-cc[t1];
  105336. t1+=ido;
  105337. t2+=ido;
  105338. t3+=ido;
  105339. t4+=ido;
  105340. }
  105341. if(ido<2)return;
  105342. if(ido==2)goto L105;
  105343. t1=0;
  105344. for(k=0;k<l1;k++){
  105345. t2=t1;
  105346. t4=t1<<2;
  105347. t5=(t6=ido<<1)+t4;
  105348. for(i=2;i<ido;i+=2){
  105349. t3=(t2+=2);
  105350. t4+=2;
  105351. t5-=2;
  105352. t3+=t0;
  105353. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105354. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105355. t3+=t0;
  105356. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105357. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105358. t3+=t0;
  105359. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105360. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105361. tr1=cr2+cr4;
  105362. tr4=cr4-cr2;
  105363. ti1=ci2+ci4;
  105364. ti4=ci2-ci4;
  105365. ti2=cc[t2]+ci3;
  105366. ti3=cc[t2]-ci3;
  105367. tr2=cc[t2-1]+cr3;
  105368. tr3=cc[t2-1]-cr3;
  105369. ch[t4-1]=tr1+tr2;
  105370. ch[t4]=ti1+ti2;
  105371. ch[t5-1]=tr3-ti4;
  105372. ch[t5]=tr4-ti3;
  105373. ch[t4+t6-1]=ti4+tr3;
  105374. ch[t4+t6]=tr4+ti3;
  105375. ch[t5+t6-1]=tr2-tr1;
  105376. ch[t5+t6]=ti1-ti2;
  105377. }
  105378. t1+=ido;
  105379. }
  105380. if(ido&1)return;
  105381. L105:
  105382. t2=(t1=t0+ido-1)+(t0<<1);
  105383. t3=ido<<2;
  105384. t4=ido;
  105385. t5=ido<<1;
  105386. t6=ido;
  105387. for(k=0;k<l1;k++){
  105388. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105389. tr1=hsqt2*(cc[t1]-cc[t2]);
  105390. ch[t4-1]=tr1+cc[t6-1];
  105391. ch[t4+t5-1]=cc[t6-1]-tr1;
  105392. ch[t4]=ti1-cc[t1+t0];
  105393. ch[t4+t5]=ti1+cc[t1+t0];
  105394. t1+=ido;
  105395. t2+=ido;
  105396. t4+=t3;
  105397. t6+=ido;
  105398. }
  105399. }
  105400. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105401. float *c2,float *ch,float *ch2,float *wa){
  105402. static float tpi=6.283185307179586f;
  105403. int idij,ipph,i,j,k,l,ic,ik,is;
  105404. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105405. float dc2,ai1,ai2,ar1,ar2,ds2;
  105406. int nbd;
  105407. float dcp,arg,dsp,ar1h,ar2h;
  105408. int idp2,ipp2;
  105409. arg=tpi/(float)ip;
  105410. dcp=cos(arg);
  105411. dsp=sin(arg);
  105412. ipph=(ip+1)>>1;
  105413. ipp2=ip;
  105414. idp2=ido;
  105415. nbd=(ido-1)>>1;
  105416. t0=l1*ido;
  105417. t10=ip*ido;
  105418. if(ido==1)goto L119;
  105419. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105420. t1=0;
  105421. for(j=1;j<ip;j++){
  105422. t1+=t0;
  105423. t2=t1;
  105424. for(k=0;k<l1;k++){
  105425. ch[t2]=c1[t2];
  105426. t2+=ido;
  105427. }
  105428. }
  105429. is=-ido;
  105430. t1=0;
  105431. if(nbd>l1){
  105432. for(j=1;j<ip;j++){
  105433. t1+=t0;
  105434. is+=ido;
  105435. t2= -ido+t1;
  105436. for(k=0;k<l1;k++){
  105437. idij=is-1;
  105438. t2+=ido;
  105439. t3=t2;
  105440. for(i=2;i<ido;i+=2){
  105441. idij+=2;
  105442. t3+=2;
  105443. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105444. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105445. }
  105446. }
  105447. }
  105448. }else{
  105449. for(j=1;j<ip;j++){
  105450. is+=ido;
  105451. idij=is-1;
  105452. t1+=t0;
  105453. t2=t1;
  105454. for(i=2;i<ido;i+=2){
  105455. idij+=2;
  105456. t2+=2;
  105457. t3=t2;
  105458. for(k=0;k<l1;k++){
  105459. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105460. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105461. t3+=ido;
  105462. }
  105463. }
  105464. }
  105465. }
  105466. t1=0;
  105467. t2=ipp2*t0;
  105468. if(nbd<l1){
  105469. for(j=1;j<ipph;j++){
  105470. t1+=t0;
  105471. t2-=t0;
  105472. t3=t1;
  105473. t4=t2;
  105474. for(i=2;i<ido;i+=2){
  105475. t3+=2;
  105476. t4+=2;
  105477. t5=t3-ido;
  105478. t6=t4-ido;
  105479. for(k=0;k<l1;k++){
  105480. t5+=ido;
  105481. t6+=ido;
  105482. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105483. c1[t6-1]=ch[t5]-ch[t6];
  105484. c1[t5]=ch[t5]+ch[t6];
  105485. c1[t6]=ch[t6-1]-ch[t5-1];
  105486. }
  105487. }
  105488. }
  105489. }else{
  105490. for(j=1;j<ipph;j++){
  105491. t1+=t0;
  105492. t2-=t0;
  105493. t3=t1;
  105494. t4=t2;
  105495. for(k=0;k<l1;k++){
  105496. t5=t3;
  105497. t6=t4;
  105498. for(i=2;i<ido;i+=2){
  105499. t5+=2;
  105500. t6+=2;
  105501. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105502. c1[t6-1]=ch[t5]-ch[t6];
  105503. c1[t5]=ch[t5]+ch[t6];
  105504. c1[t6]=ch[t6-1]-ch[t5-1];
  105505. }
  105506. t3+=ido;
  105507. t4+=ido;
  105508. }
  105509. }
  105510. }
  105511. L119:
  105512. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105513. t1=0;
  105514. t2=ipp2*idl1;
  105515. for(j=1;j<ipph;j++){
  105516. t1+=t0;
  105517. t2-=t0;
  105518. t3=t1-ido;
  105519. t4=t2-ido;
  105520. for(k=0;k<l1;k++){
  105521. t3+=ido;
  105522. t4+=ido;
  105523. c1[t3]=ch[t3]+ch[t4];
  105524. c1[t4]=ch[t4]-ch[t3];
  105525. }
  105526. }
  105527. ar1=1.f;
  105528. ai1=0.f;
  105529. t1=0;
  105530. t2=ipp2*idl1;
  105531. t3=(ip-1)*idl1;
  105532. for(l=1;l<ipph;l++){
  105533. t1+=idl1;
  105534. t2-=idl1;
  105535. ar1h=dcp*ar1-dsp*ai1;
  105536. ai1=dcp*ai1+dsp*ar1;
  105537. ar1=ar1h;
  105538. t4=t1;
  105539. t5=t2;
  105540. t6=t3;
  105541. t7=idl1;
  105542. for(ik=0;ik<idl1;ik++){
  105543. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105544. ch2[t5++]=ai1*c2[t6++];
  105545. }
  105546. dc2=ar1;
  105547. ds2=ai1;
  105548. ar2=ar1;
  105549. ai2=ai1;
  105550. t4=idl1;
  105551. t5=(ipp2-1)*idl1;
  105552. for(j=2;j<ipph;j++){
  105553. t4+=idl1;
  105554. t5-=idl1;
  105555. ar2h=dc2*ar2-ds2*ai2;
  105556. ai2=dc2*ai2+ds2*ar2;
  105557. ar2=ar2h;
  105558. t6=t1;
  105559. t7=t2;
  105560. t8=t4;
  105561. t9=t5;
  105562. for(ik=0;ik<idl1;ik++){
  105563. ch2[t6++]+=ar2*c2[t8++];
  105564. ch2[t7++]+=ai2*c2[t9++];
  105565. }
  105566. }
  105567. }
  105568. t1=0;
  105569. for(j=1;j<ipph;j++){
  105570. t1+=idl1;
  105571. t2=t1;
  105572. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105573. }
  105574. if(ido<l1)goto L132;
  105575. t1=0;
  105576. t2=0;
  105577. for(k=0;k<l1;k++){
  105578. t3=t1;
  105579. t4=t2;
  105580. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105581. t1+=ido;
  105582. t2+=t10;
  105583. }
  105584. goto L135;
  105585. L132:
  105586. for(i=0;i<ido;i++){
  105587. t1=i;
  105588. t2=i;
  105589. for(k=0;k<l1;k++){
  105590. cc[t2]=ch[t1];
  105591. t1+=ido;
  105592. t2+=t10;
  105593. }
  105594. }
  105595. L135:
  105596. t1=0;
  105597. t2=ido<<1;
  105598. t3=0;
  105599. t4=ipp2*t0;
  105600. for(j=1;j<ipph;j++){
  105601. t1+=t2;
  105602. t3+=t0;
  105603. t4-=t0;
  105604. t5=t1;
  105605. t6=t3;
  105606. t7=t4;
  105607. for(k=0;k<l1;k++){
  105608. cc[t5-1]=ch[t6];
  105609. cc[t5]=ch[t7];
  105610. t5+=t10;
  105611. t6+=ido;
  105612. t7+=ido;
  105613. }
  105614. }
  105615. if(ido==1)return;
  105616. if(nbd<l1)goto L141;
  105617. t1=-ido;
  105618. t3=0;
  105619. t4=0;
  105620. t5=ipp2*t0;
  105621. for(j=1;j<ipph;j++){
  105622. t1+=t2;
  105623. t3+=t2;
  105624. t4+=t0;
  105625. t5-=t0;
  105626. t6=t1;
  105627. t7=t3;
  105628. t8=t4;
  105629. t9=t5;
  105630. for(k=0;k<l1;k++){
  105631. for(i=2;i<ido;i+=2){
  105632. ic=idp2-i;
  105633. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105634. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105635. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105636. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105637. }
  105638. t6+=t10;
  105639. t7+=t10;
  105640. t8+=ido;
  105641. t9+=ido;
  105642. }
  105643. }
  105644. return;
  105645. L141:
  105646. t1=-ido;
  105647. t3=0;
  105648. t4=0;
  105649. t5=ipp2*t0;
  105650. for(j=1;j<ipph;j++){
  105651. t1+=t2;
  105652. t3+=t2;
  105653. t4+=t0;
  105654. t5-=t0;
  105655. for(i=2;i<ido;i+=2){
  105656. t6=idp2+t1-i;
  105657. t7=i+t3;
  105658. t8=i+t4;
  105659. t9=i+t5;
  105660. for(k=0;k<l1;k++){
  105661. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105662. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105663. cc[t7]=ch[t8]+ch[t9];
  105664. cc[t6]=ch[t9]-ch[t8];
  105665. t6+=t10;
  105666. t7+=t10;
  105667. t8+=ido;
  105668. t9+=ido;
  105669. }
  105670. }
  105671. }
  105672. }
  105673. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105674. int i,k1,l1,l2;
  105675. int na,kh,nf;
  105676. int ip,iw,ido,idl1,ix2,ix3;
  105677. nf=ifac[1];
  105678. na=1;
  105679. l2=n;
  105680. iw=n;
  105681. for(k1=0;k1<nf;k1++){
  105682. kh=nf-k1;
  105683. ip=ifac[kh+1];
  105684. l1=l2/ip;
  105685. ido=n/l2;
  105686. idl1=ido*l1;
  105687. iw-=(ip-1)*ido;
  105688. na=1-na;
  105689. if(ip!=4)goto L102;
  105690. ix2=iw+ido;
  105691. ix3=ix2+ido;
  105692. if(na!=0)
  105693. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105694. else
  105695. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105696. goto L110;
  105697. L102:
  105698. if(ip!=2)goto L104;
  105699. if(na!=0)goto L103;
  105700. dradf2(ido,l1,c,ch,wa+iw-1);
  105701. goto L110;
  105702. L103:
  105703. dradf2(ido,l1,ch,c,wa+iw-1);
  105704. goto L110;
  105705. L104:
  105706. if(ido==1)na=1-na;
  105707. if(na!=0)goto L109;
  105708. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105709. na=1;
  105710. goto L110;
  105711. L109:
  105712. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105713. na=0;
  105714. L110:
  105715. l2=l1;
  105716. }
  105717. if(na==1)return;
  105718. for(i=0;i<n;i++)c[i]=ch[i];
  105719. }
  105720. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105721. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105722. float ti2,tr2;
  105723. t0=l1*ido;
  105724. t1=0;
  105725. t2=0;
  105726. t3=(ido<<1)-1;
  105727. for(k=0;k<l1;k++){
  105728. ch[t1]=cc[t2]+cc[t3+t2];
  105729. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105730. t2=(t1+=ido)<<1;
  105731. }
  105732. if(ido<2)return;
  105733. if(ido==2)goto L105;
  105734. t1=0;
  105735. t2=0;
  105736. for(k=0;k<l1;k++){
  105737. t3=t1;
  105738. t5=(t4=t2)+(ido<<1);
  105739. t6=t0+t1;
  105740. for(i=2;i<ido;i+=2){
  105741. t3+=2;
  105742. t4+=2;
  105743. t5-=2;
  105744. t6+=2;
  105745. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105746. tr2=cc[t4-1]-cc[t5-1];
  105747. ch[t3]=cc[t4]-cc[t5];
  105748. ti2=cc[t4]+cc[t5];
  105749. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105750. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105751. }
  105752. t2=(t1+=ido)<<1;
  105753. }
  105754. if(ido%2==1)return;
  105755. L105:
  105756. t1=ido-1;
  105757. t2=ido-1;
  105758. for(k=0;k<l1;k++){
  105759. ch[t1]=cc[t2]+cc[t2];
  105760. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105761. t1+=ido;
  105762. t2+=ido<<1;
  105763. }
  105764. }
  105765. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105766. float *wa2){
  105767. static float taur = -.5f;
  105768. static float taui = .8660254037844386f;
  105769. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105770. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105771. t0=l1*ido;
  105772. t1=0;
  105773. t2=t0<<1;
  105774. t3=ido<<1;
  105775. t4=ido+(ido<<1);
  105776. t5=0;
  105777. for(k=0;k<l1;k++){
  105778. tr2=cc[t3-1]+cc[t3-1];
  105779. cr2=cc[t5]+(taur*tr2);
  105780. ch[t1]=cc[t5]+tr2;
  105781. ci3=taui*(cc[t3]+cc[t3]);
  105782. ch[t1+t0]=cr2-ci3;
  105783. ch[t1+t2]=cr2+ci3;
  105784. t1+=ido;
  105785. t3+=t4;
  105786. t5+=t4;
  105787. }
  105788. if(ido==1)return;
  105789. t1=0;
  105790. t3=ido<<1;
  105791. for(k=0;k<l1;k++){
  105792. t7=t1+(t1<<1);
  105793. t6=(t5=t7+t3);
  105794. t8=t1;
  105795. t10=(t9=t1+t0)+t0;
  105796. for(i=2;i<ido;i+=2){
  105797. t5+=2;
  105798. t6-=2;
  105799. t7+=2;
  105800. t8+=2;
  105801. t9+=2;
  105802. t10+=2;
  105803. tr2=cc[t5-1]+cc[t6-1];
  105804. cr2=cc[t7-1]+(taur*tr2);
  105805. ch[t8-1]=cc[t7-1]+tr2;
  105806. ti2=cc[t5]-cc[t6];
  105807. ci2=cc[t7]+(taur*ti2);
  105808. ch[t8]=cc[t7]+ti2;
  105809. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105810. ci3=taui*(cc[t5]+cc[t6]);
  105811. dr2=cr2-ci3;
  105812. dr3=cr2+ci3;
  105813. di2=ci2+cr3;
  105814. di3=ci2-cr3;
  105815. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105816. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105817. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105818. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105819. }
  105820. t1+=ido;
  105821. }
  105822. }
  105823. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105824. float *wa2,float *wa3){
  105825. static float sqrt2=1.414213562373095f;
  105826. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105827. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105828. t0=l1*ido;
  105829. t1=0;
  105830. t2=ido<<2;
  105831. t3=0;
  105832. t6=ido<<1;
  105833. for(k=0;k<l1;k++){
  105834. t4=t3+t6;
  105835. t5=t1;
  105836. tr3=cc[t4-1]+cc[t4-1];
  105837. tr4=cc[t4]+cc[t4];
  105838. tr1=cc[t3]-cc[(t4+=t6)-1];
  105839. tr2=cc[t3]+cc[t4-1];
  105840. ch[t5]=tr2+tr3;
  105841. ch[t5+=t0]=tr1-tr4;
  105842. ch[t5+=t0]=tr2-tr3;
  105843. ch[t5+=t0]=tr1+tr4;
  105844. t1+=ido;
  105845. t3+=t2;
  105846. }
  105847. if(ido<2)return;
  105848. if(ido==2)goto L105;
  105849. t1=0;
  105850. for(k=0;k<l1;k++){
  105851. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105852. t7=t1;
  105853. for(i=2;i<ido;i+=2){
  105854. t2+=2;
  105855. t3+=2;
  105856. t4-=2;
  105857. t5-=2;
  105858. t7+=2;
  105859. ti1=cc[t2]+cc[t5];
  105860. ti2=cc[t2]-cc[t5];
  105861. ti3=cc[t3]-cc[t4];
  105862. tr4=cc[t3]+cc[t4];
  105863. tr1=cc[t2-1]-cc[t5-1];
  105864. tr2=cc[t2-1]+cc[t5-1];
  105865. ti4=cc[t3-1]-cc[t4-1];
  105866. tr3=cc[t3-1]+cc[t4-1];
  105867. ch[t7-1]=tr2+tr3;
  105868. cr3=tr2-tr3;
  105869. ch[t7]=ti2+ti3;
  105870. ci3=ti2-ti3;
  105871. cr2=tr1-tr4;
  105872. cr4=tr1+tr4;
  105873. ci2=ti1+ti4;
  105874. ci4=ti1-ti4;
  105875. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105876. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105877. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105878. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105879. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105880. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105881. }
  105882. t1+=ido;
  105883. }
  105884. if(ido%2 == 1)return;
  105885. L105:
  105886. t1=ido;
  105887. t2=ido<<2;
  105888. t3=ido-1;
  105889. t4=ido+(ido<<1);
  105890. for(k=0;k<l1;k++){
  105891. t5=t3;
  105892. ti1=cc[t1]+cc[t4];
  105893. ti2=cc[t4]-cc[t1];
  105894. tr1=cc[t1-1]-cc[t4-1];
  105895. tr2=cc[t1-1]+cc[t4-1];
  105896. ch[t5]=tr2+tr2;
  105897. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105898. ch[t5+=t0]=ti2+ti2;
  105899. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105900. t3+=ido;
  105901. t1+=t2;
  105902. t4+=t2;
  105903. }
  105904. }
  105905. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105906. float *c2,float *ch,float *ch2,float *wa){
  105907. static float tpi=6.283185307179586f;
  105908. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105909. t11,t12;
  105910. float dc2,ai1,ai2,ar1,ar2,ds2;
  105911. int nbd;
  105912. float dcp,arg,dsp,ar1h,ar2h;
  105913. int ipp2;
  105914. t10=ip*ido;
  105915. t0=l1*ido;
  105916. arg=tpi/(float)ip;
  105917. dcp=cos(arg);
  105918. dsp=sin(arg);
  105919. nbd=(ido-1)>>1;
  105920. ipp2=ip;
  105921. ipph=(ip+1)>>1;
  105922. if(ido<l1)goto L103;
  105923. t1=0;
  105924. t2=0;
  105925. for(k=0;k<l1;k++){
  105926. t3=t1;
  105927. t4=t2;
  105928. for(i=0;i<ido;i++){
  105929. ch[t3]=cc[t4];
  105930. t3++;
  105931. t4++;
  105932. }
  105933. t1+=ido;
  105934. t2+=t10;
  105935. }
  105936. goto L106;
  105937. L103:
  105938. t1=0;
  105939. for(i=0;i<ido;i++){
  105940. t2=t1;
  105941. t3=t1;
  105942. for(k=0;k<l1;k++){
  105943. ch[t2]=cc[t3];
  105944. t2+=ido;
  105945. t3+=t10;
  105946. }
  105947. t1++;
  105948. }
  105949. L106:
  105950. t1=0;
  105951. t2=ipp2*t0;
  105952. t7=(t5=ido<<1);
  105953. for(j=1;j<ipph;j++){
  105954. t1+=t0;
  105955. t2-=t0;
  105956. t3=t1;
  105957. t4=t2;
  105958. t6=t5;
  105959. for(k=0;k<l1;k++){
  105960. ch[t3]=cc[t6-1]+cc[t6-1];
  105961. ch[t4]=cc[t6]+cc[t6];
  105962. t3+=ido;
  105963. t4+=ido;
  105964. t6+=t10;
  105965. }
  105966. t5+=t7;
  105967. }
  105968. if (ido == 1)goto L116;
  105969. if(nbd<l1)goto L112;
  105970. t1=0;
  105971. t2=ipp2*t0;
  105972. t7=0;
  105973. for(j=1;j<ipph;j++){
  105974. t1+=t0;
  105975. t2-=t0;
  105976. t3=t1;
  105977. t4=t2;
  105978. t7+=(ido<<1);
  105979. t8=t7;
  105980. for(k=0;k<l1;k++){
  105981. t5=t3;
  105982. t6=t4;
  105983. t9=t8;
  105984. t11=t8;
  105985. for(i=2;i<ido;i+=2){
  105986. t5+=2;
  105987. t6+=2;
  105988. t9+=2;
  105989. t11-=2;
  105990. ch[t5-1]=cc[t9-1]+cc[t11-1];
  105991. ch[t6-1]=cc[t9-1]-cc[t11-1];
  105992. ch[t5]=cc[t9]-cc[t11];
  105993. ch[t6]=cc[t9]+cc[t11];
  105994. }
  105995. t3+=ido;
  105996. t4+=ido;
  105997. t8+=t10;
  105998. }
  105999. }
  106000. goto L116;
  106001. L112:
  106002. t1=0;
  106003. t2=ipp2*t0;
  106004. t7=0;
  106005. for(j=1;j<ipph;j++){
  106006. t1+=t0;
  106007. t2-=t0;
  106008. t3=t1;
  106009. t4=t2;
  106010. t7+=(ido<<1);
  106011. t8=t7;
  106012. t9=t7;
  106013. for(i=2;i<ido;i+=2){
  106014. t3+=2;
  106015. t4+=2;
  106016. t8+=2;
  106017. t9-=2;
  106018. t5=t3;
  106019. t6=t4;
  106020. t11=t8;
  106021. t12=t9;
  106022. for(k=0;k<l1;k++){
  106023. ch[t5-1]=cc[t11-1]+cc[t12-1];
  106024. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106025. ch[t5]=cc[t11]-cc[t12];
  106026. ch[t6]=cc[t11]+cc[t12];
  106027. t5+=ido;
  106028. t6+=ido;
  106029. t11+=t10;
  106030. t12+=t10;
  106031. }
  106032. }
  106033. }
  106034. L116:
  106035. ar1=1.f;
  106036. ai1=0.f;
  106037. t1=0;
  106038. t9=(t2=ipp2*idl1);
  106039. t3=(ip-1)*idl1;
  106040. for(l=1;l<ipph;l++){
  106041. t1+=idl1;
  106042. t2-=idl1;
  106043. ar1h=dcp*ar1-dsp*ai1;
  106044. ai1=dcp*ai1+dsp*ar1;
  106045. ar1=ar1h;
  106046. t4=t1;
  106047. t5=t2;
  106048. t6=0;
  106049. t7=idl1;
  106050. t8=t3;
  106051. for(ik=0;ik<idl1;ik++){
  106052. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106053. c2[t5++]=ai1*ch2[t8++];
  106054. }
  106055. dc2=ar1;
  106056. ds2=ai1;
  106057. ar2=ar1;
  106058. ai2=ai1;
  106059. t6=idl1;
  106060. t7=t9-idl1;
  106061. for(j=2;j<ipph;j++){
  106062. t6+=idl1;
  106063. t7-=idl1;
  106064. ar2h=dc2*ar2-ds2*ai2;
  106065. ai2=dc2*ai2+ds2*ar2;
  106066. ar2=ar2h;
  106067. t4=t1;
  106068. t5=t2;
  106069. t11=t6;
  106070. t12=t7;
  106071. for(ik=0;ik<idl1;ik++){
  106072. c2[t4++]+=ar2*ch2[t11++];
  106073. c2[t5++]+=ai2*ch2[t12++];
  106074. }
  106075. }
  106076. }
  106077. t1=0;
  106078. for(j=1;j<ipph;j++){
  106079. t1+=idl1;
  106080. t2=t1;
  106081. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106082. }
  106083. t1=0;
  106084. t2=ipp2*t0;
  106085. for(j=1;j<ipph;j++){
  106086. t1+=t0;
  106087. t2-=t0;
  106088. t3=t1;
  106089. t4=t2;
  106090. for(k=0;k<l1;k++){
  106091. ch[t3]=c1[t3]-c1[t4];
  106092. ch[t4]=c1[t3]+c1[t4];
  106093. t3+=ido;
  106094. t4+=ido;
  106095. }
  106096. }
  106097. if(ido==1)goto L132;
  106098. if(nbd<l1)goto L128;
  106099. t1=0;
  106100. t2=ipp2*t0;
  106101. for(j=1;j<ipph;j++){
  106102. t1+=t0;
  106103. t2-=t0;
  106104. t3=t1;
  106105. t4=t2;
  106106. for(k=0;k<l1;k++){
  106107. t5=t3;
  106108. t6=t4;
  106109. for(i=2;i<ido;i+=2){
  106110. t5+=2;
  106111. t6+=2;
  106112. ch[t5-1]=c1[t5-1]-c1[t6];
  106113. ch[t6-1]=c1[t5-1]+c1[t6];
  106114. ch[t5]=c1[t5]+c1[t6-1];
  106115. ch[t6]=c1[t5]-c1[t6-1];
  106116. }
  106117. t3+=ido;
  106118. t4+=ido;
  106119. }
  106120. }
  106121. goto L132;
  106122. L128:
  106123. t1=0;
  106124. t2=ipp2*t0;
  106125. for(j=1;j<ipph;j++){
  106126. t1+=t0;
  106127. t2-=t0;
  106128. t3=t1;
  106129. t4=t2;
  106130. for(i=2;i<ido;i+=2){
  106131. t3+=2;
  106132. t4+=2;
  106133. t5=t3;
  106134. t6=t4;
  106135. for(k=0;k<l1;k++){
  106136. ch[t5-1]=c1[t5-1]-c1[t6];
  106137. ch[t6-1]=c1[t5-1]+c1[t6];
  106138. ch[t5]=c1[t5]+c1[t6-1];
  106139. ch[t6]=c1[t5]-c1[t6-1];
  106140. t5+=ido;
  106141. t6+=ido;
  106142. }
  106143. }
  106144. }
  106145. L132:
  106146. if(ido==1)return;
  106147. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106148. t1=0;
  106149. for(j=1;j<ip;j++){
  106150. t2=(t1+=t0);
  106151. for(k=0;k<l1;k++){
  106152. c1[t2]=ch[t2];
  106153. t2+=ido;
  106154. }
  106155. }
  106156. if(nbd>l1)goto L139;
  106157. is= -ido-1;
  106158. t1=0;
  106159. for(j=1;j<ip;j++){
  106160. is+=ido;
  106161. t1+=t0;
  106162. idij=is;
  106163. t2=t1;
  106164. for(i=2;i<ido;i+=2){
  106165. t2+=2;
  106166. idij+=2;
  106167. t3=t2;
  106168. for(k=0;k<l1;k++){
  106169. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106170. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106171. t3+=ido;
  106172. }
  106173. }
  106174. }
  106175. return;
  106176. L139:
  106177. is= -ido-1;
  106178. t1=0;
  106179. for(j=1;j<ip;j++){
  106180. is+=ido;
  106181. t1+=t0;
  106182. t2=t1;
  106183. for(k=0;k<l1;k++){
  106184. idij=is;
  106185. t3=t2;
  106186. for(i=2;i<ido;i+=2){
  106187. idij+=2;
  106188. t3+=2;
  106189. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106190. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106191. }
  106192. t2+=ido;
  106193. }
  106194. }
  106195. }
  106196. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106197. int i,k1,l1,l2;
  106198. int na;
  106199. int nf,ip,iw,ix2,ix3,ido,idl1;
  106200. nf=ifac[1];
  106201. na=0;
  106202. l1=1;
  106203. iw=1;
  106204. for(k1=0;k1<nf;k1++){
  106205. ip=ifac[k1 + 2];
  106206. l2=ip*l1;
  106207. ido=n/l2;
  106208. idl1=ido*l1;
  106209. if(ip!=4)goto L103;
  106210. ix2=iw+ido;
  106211. ix3=ix2+ido;
  106212. if(na!=0)
  106213. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106214. else
  106215. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106216. na=1-na;
  106217. goto L115;
  106218. L103:
  106219. if(ip!=2)goto L106;
  106220. if(na!=0)
  106221. dradb2(ido,l1,ch,c,wa+iw-1);
  106222. else
  106223. dradb2(ido,l1,c,ch,wa+iw-1);
  106224. na=1-na;
  106225. goto L115;
  106226. L106:
  106227. if(ip!=3)goto L109;
  106228. ix2=iw+ido;
  106229. if(na!=0)
  106230. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106231. else
  106232. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106233. na=1-na;
  106234. goto L115;
  106235. L109:
  106236. if(na!=0)
  106237. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106238. else
  106239. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106240. if(ido==1)na=1-na;
  106241. L115:
  106242. l1=l2;
  106243. iw+=(ip-1)*ido;
  106244. }
  106245. if(na==0)return;
  106246. for(i=0;i<n;i++)c[i]=ch[i];
  106247. }
  106248. void drft_forward(drft_lookup *l,float *data){
  106249. if(l->n==1)return;
  106250. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106251. }
  106252. void drft_backward(drft_lookup *l,float *data){
  106253. if (l->n==1)return;
  106254. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106255. }
  106256. void drft_init(drft_lookup *l,int n){
  106257. l->n=n;
  106258. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106259. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106260. fdrffti(n, l->trigcache, l->splitcache);
  106261. }
  106262. void drft_clear(drft_lookup *l){
  106263. if(l){
  106264. if(l->trigcache)_ogg_free(l->trigcache);
  106265. if(l->splitcache)_ogg_free(l->splitcache);
  106266. memset(l,0,sizeof(*l));
  106267. }
  106268. }
  106269. #endif
  106270. /*** End of inlined file: smallft.c ***/
  106271. /*** Start of inlined file: synthesis.c ***/
  106272. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106273. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106274. // tasks..
  106275. #if JUCE_MSVC
  106276. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106277. #endif
  106278. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106279. #if JUCE_USE_OGGVORBIS
  106280. #include <stdio.h>
  106281. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106282. vorbis_dsp_state *vd=vb->vd;
  106283. private_state *b=(private_state*)vd->backend_state;
  106284. vorbis_info *vi=vd->vi;
  106285. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106286. oggpack_buffer *opb=&vb->opb;
  106287. int type,mode,i;
  106288. _vorbis_block_ripcord(vb);
  106289. oggpack_readinit(opb,op->packet,op->bytes);
  106290. if(oggpack_read(opb,1)!=0){
  106291. return(OV_ENOTAUDIO);
  106292. }
  106293. mode=oggpack_read(opb,b->modebits);
  106294. if(mode==-1)return(OV_EBADPACKET);
  106295. vb->mode=mode;
  106296. vb->W=ci->mode_param[mode]->blockflag;
  106297. if(vb->W){
  106298. vb->lW=oggpack_read(opb,1);
  106299. vb->nW=oggpack_read(opb,1);
  106300. if(vb->nW==-1) return(OV_EBADPACKET);
  106301. }else{
  106302. vb->lW=0;
  106303. vb->nW=0;
  106304. }
  106305. vb->granulepos=op->granulepos;
  106306. vb->sequence=op->packetno;
  106307. vb->eofflag=op->e_o_s;
  106308. vb->pcmend=ci->blocksizes[vb->W];
  106309. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106310. for(i=0;i<vi->channels;i++)
  106311. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106312. type=ci->map_type[ci->mode_param[mode]->mapping];
  106313. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106314. mapping]));
  106315. }
  106316. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106317. vorbis_dsp_state *vd=vb->vd;
  106318. private_state *b=(private_state*)vd->backend_state;
  106319. vorbis_info *vi=vd->vi;
  106320. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106321. oggpack_buffer *opb=&vb->opb;
  106322. int mode;
  106323. _vorbis_block_ripcord(vb);
  106324. oggpack_readinit(opb,op->packet,op->bytes);
  106325. if(oggpack_read(opb,1)!=0){
  106326. return(OV_ENOTAUDIO);
  106327. }
  106328. mode=oggpack_read(opb,b->modebits);
  106329. if(mode==-1)return(OV_EBADPACKET);
  106330. vb->mode=mode;
  106331. vb->W=ci->mode_param[mode]->blockflag;
  106332. if(vb->W){
  106333. vb->lW=oggpack_read(opb,1);
  106334. vb->nW=oggpack_read(opb,1);
  106335. if(vb->nW==-1) return(OV_EBADPACKET);
  106336. }else{
  106337. vb->lW=0;
  106338. vb->nW=0;
  106339. }
  106340. vb->granulepos=op->granulepos;
  106341. vb->sequence=op->packetno;
  106342. vb->eofflag=op->e_o_s;
  106343. vb->pcmend=0;
  106344. vb->pcm=NULL;
  106345. return(0);
  106346. }
  106347. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106348. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106349. oggpack_buffer opb;
  106350. int mode;
  106351. oggpack_readinit(&opb,op->packet,op->bytes);
  106352. if(oggpack_read(&opb,1)!=0){
  106353. return(OV_ENOTAUDIO);
  106354. }
  106355. {
  106356. int modebits=0;
  106357. int v=ci->modes;
  106358. while(v>1){
  106359. modebits++;
  106360. v>>=1;
  106361. }
  106362. mode=oggpack_read(&opb,modebits);
  106363. }
  106364. if(mode==-1)return(OV_EBADPACKET);
  106365. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106366. }
  106367. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106368. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106369. if(ci->blocksizes[0]<=64 && flag)return -1;
  106370. ci->halfrate_flag=(flag?1:0);
  106371. return 0;
  106372. }
  106373. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106374. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106375. return ci->halfrate_flag;
  106376. }
  106377. #endif
  106378. /*** End of inlined file: synthesis.c ***/
  106379. /*** Start of inlined file: vorbisenc.c ***/
  106380. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106381. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106382. // tasks..
  106383. #if JUCE_MSVC
  106384. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106385. #endif
  106386. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106387. #if JUCE_USE_OGGVORBIS
  106388. #include <stdlib.h>
  106389. #include <string.h>
  106390. #include <math.h>
  106391. typedef struct {
  106392. static_codebook *books[12][3];
  106393. } static_bookblock;
  106394. typedef struct {
  106395. int res_type;
  106396. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106397. vorbis_info_residue0 *res;
  106398. static_codebook *book_aux;
  106399. static_codebook *book_aux_managed;
  106400. static_bookblock *books_base;
  106401. static_bookblock *books_base_managed;
  106402. } vorbis_residue_template;
  106403. typedef struct {
  106404. vorbis_info_mapping0 *map;
  106405. vorbis_residue_template *res;
  106406. } vorbis_mapping_template;
  106407. typedef struct vp_adjblock{
  106408. int block[P_BANDS];
  106409. } vp_adjblock;
  106410. typedef struct {
  106411. int data[NOISE_COMPAND_LEVELS];
  106412. } compandblock;
  106413. typedef struct {
  106414. int att[P_NOISECURVES];
  106415. float boost;
  106416. float decay;
  106417. } att3;
  106418. typedef struct { int data[P_NOISECURVES]; } adj3;
  106419. typedef struct {
  106420. int pre[PACKETBLOBS];
  106421. int post[PACKETBLOBS];
  106422. float kHz[PACKETBLOBS];
  106423. float lowpasskHz[PACKETBLOBS];
  106424. } adj_stereo;
  106425. typedef struct {
  106426. int lo;
  106427. int hi;
  106428. int fixed;
  106429. } noiseguard;
  106430. typedef struct {
  106431. int data[P_NOISECURVES][17];
  106432. } noise3;
  106433. typedef struct {
  106434. int mappings;
  106435. double *rate_mapping;
  106436. double *quality_mapping;
  106437. int coupling_restriction;
  106438. long samplerate_min_restriction;
  106439. long samplerate_max_restriction;
  106440. int *blocksize_short;
  106441. int *blocksize_long;
  106442. att3 *psy_tone_masteratt;
  106443. int *psy_tone_0dB;
  106444. int *psy_tone_dBsuppress;
  106445. vp_adjblock *psy_tone_adj_impulse;
  106446. vp_adjblock *psy_tone_adj_long;
  106447. vp_adjblock *psy_tone_adj_other;
  106448. noiseguard *psy_noiseguards;
  106449. noise3 *psy_noise_bias_impulse;
  106450. noise3 *psy_noise_bias_padding;
  106451. noise3 *psy_noise_bias_trans;
  106452. noise3 *psy_noise_bias_long;
  106453. int *psy_noise_dBsuppress;
  106454. compandblock *psy_noise_compand;
  106455. double *psy_noise_compand_short_mapping;
  106456. double *psy_noise_compand_long_mapping;
  106457. int *psy_noise_normal_start[2];
  106458. int *psy_noise_normal_partition[2];
  106459. double *psy_noise_normal_thresh;
  106460. int *psy_ath_float;
  106461. int *psy_ath_abs;
  106462. double *psy_lowpass;
  106463. vorbis_info_psy_global *global_params;
  106464. double *global_mapping;
  106465. adj_stereo *stereo_modes;
  106466. static_codebook ***floor_books;
  106467. vorbis_info_floor1 *floor_params;
  106468. int *floor_short_mapping;
  106469. int *floor_long_mapping;
  106470. vorbis_mapping_template *maps;
  106471. } ve_setup_data_template;
  106472. static vorbis_info_mode _mode_template[2]={
  106473. {0,0,0,0},
  106474. {1,0,0,1}
  106475. };
  106476. static vorbis_info_mapping0 _map_nominal[2]={
  106477. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106478. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106479. };
  106480. /*** Start of inlined file: setup_44.h ***/
  106481. /*** Start of inlined file: floor_all.h ***/
  106482. /*** Start of inlined file: floor_books.h ***/
  106483. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106484. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106485. };
  106486. static static_codebook _huff_book_line_256x7_0sub1 = {
  106487. 1, 9,
  106488. _huff_lengthlist_line_256x7_0sub1,
  106489. 0, 0, 0, 0, 0,
  106490. NULL,
  106491. NULL,
  106492. NULL,
  106493. NULL,
  106494. 0
  106495. };
  106496. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106498. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106499. };
  106500. static static_codebook _huff_book_line_256x7_0sub2 = {
  106501. 1, 25,
  106502. _huff_lengthlist_line_256x7_0sub2,
  106503. 0, 0, 0, 0, 0,
  106504. NULL,
  106505. NULL,
  106506. NULL,
  106507. NULL,
  106508. 0
  106509. };
  106510. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106513. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106514. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106515. };
  106516. static static_codebook _huff_book_line_256x7_0sub3 = {
  106517. 1, 64,
  106518. _huff_lengthlist_line_256x7_0sub3,
  106519. 0, 0, 0, 0, 0,
  106520. NULL,
  106521. NULL,
  106522. NULL,
  106523. NULL,
  106524. 0
  106525. };
  106526. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106527. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106528. };
  106529. static static_codebook _huff_book_line_256x7_1sub1 = {
  106530. 1, 9,
  106531. _huff_lengthlist_line_256x7_1sub1,
  106532. 0, 0, 0, 0, 0,
  106533. NULL,
  106534. NULL,
  106535. NULL,
  106536. NULL,
  106537. 0
  106538. };
  106539. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106541. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106542. };
  106543. static static_codebook _huff_book_line_256x7_1sub2 = {
  106544. 1, 25,
  106545. _huff_lengthlist_line_256x7_1sub2,
  106546. 0, 0, 0, 0, 0,
  106547. NULL,
  106548. NULL,
  106549. NULL,
  106550. NULL,
  106551. 0
  106552. };
  106553. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106556. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106557. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106558. };
  106559. static static_codebook _huff_book_line_256x7_1sub3 = {
  106560. 1, 64,
  106561. _huff_lengthlist_line_256x7_1sub3,
  106562. 0, 0, 0, 0, 0,
  106563. NULL,
  106564. NULL,
  106565. NULL,
  106566. NULL,
  106567. 0
  106568. };
  106569. static long _huff_lengthlist_line_256x7_class0[] = {
  106570. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106571. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106572. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106573. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106574. };
  106575. static static_codebook _huff_book_line_256x7_class0 = {
  106576. 1, 64,
  106577. _huff_lengthlist_line_256x7_class0,
  106578. 0, 0, 0, 0, 0,
  106579. NULL,
  106580. NULL,
  106581. NULL,
  106582. NULL,
  106583. 0
  106584. };
  106585. static long _huff_lengthlist_line_256x7_class1[] = {
  106586. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106587. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106588. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106589. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106590. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106591. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106592. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106593. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106594. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106595. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106596. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106597. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106598. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106599. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106600. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106601. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106602. };
  106603. static static_codebook _huff_book_line_256x7_class1 = {
  106604. 1, 256,
  106605. _huff_lengthlist_line_256x7_class1,
  106606. 0, 0, 0, 0, 0,
  106607. NULL,
  106608. NULL,
  106609. NULL,
  106610. NULL,
  106611. 0
  106612. };
  106613. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106614. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106615. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106616. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106617. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106618. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106619. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106620. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106621. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106622. };
  106623. static static_codebook _huff_book_line_512x17_0sub0 = {
  106624. 1, 128,
  106625. _huff_lengthlist_line_512x17_0sub0,
  106626. 0, 0, 0, 0, 0,
  106627. NULL,
  106628. NULL,
  106629. NULL,
  106630. NULL,
  106631. 0
  106632. };
  106633. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106634. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106635. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106636. };
  106637. static static_codebook _huff_book_line_512x17_1sub0 = {
  106638. 1, 32,
  106639. _huff_lengthlist_line_512x17_1sub0,
  106640. 0, 0, 0, 0, 0,
  106641. NULL,
  106642. NULL,
  106643. NULL,
  106644. NULL,
  106645. 0
  106646. };
  106647. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106650. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106651. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106652. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106653. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106654. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106655. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106656. };
  106657. static static_codebook _huff_book_line_512x17_1sub1 = {
  106658. 1, 128,
  106659. _huff_lengthlist_line_512x17_1sub1,
  106660. 0, 0, 0, 0, 0,
  106661. NULL,
  106662. NULL,
  106663. NULL,
  106664. NULL,
  106665. 0
  106666. };
  106667. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106668. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106669. 5, 3,
  106670. };
  106671. static static_codebook _huff_book_line_512x17_2sub1 = {
  106672. 1, 18,
  106673. _huff_lengthlist_line_512x17_2sub1,
  106674. 0, 0, 0, 0, 0,
  106675. NULL,
  106676. NULL,
  106677. NULL,
  106678. NULL,
  106679. 0
  106680. };
  106681. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106683. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106684. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106685. 9, 8,
  106686. };
  106687. static static_codebook _huff_book_line_512x17_2sub2 = {
  106688. 1, 50,
  106689. _huff_lengthlist_line_512x17_2sub2,
  106690. 0, 0, 0, 0, 0,
  106691. NULL,
  106692. NULL,
  106693. NULL,
  106694. NULL,
  106695. 0
  106696. };
  106697. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106701. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106702. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106703. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106704. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106705. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106706. };
  106707. static static_codebook _huff_book_line_512x17_2sub3 = {
  106708. 1, 128,
  106709. _huff_lengthlist_line_512x17_2sub3,
  106710. 0, 0, 0, 0, 0,
  106711. NULL,
  106712. NULL,
  106713. NULL,
  106714. NULL,
  106715. 0
  106716. };
  106717. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106718. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106719. 5, 5,
  106720. };
  106721. static static_codebook _huff_book_line_512x17_3sub1 = {
  106722. 1, 18,
  106723. _huff_lengthlist_line_512x17_3sub1,
  106724. 0, 0, 0, 0, 0,
  106725. NULL,
  106726. NULL,
  106727. NULL,
  106728. NULL,
  106729. 0
  106730. };
  106731. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106733. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106734. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106735. 11,14,
  106736. };
  106737. static static_codebook _huff_book_line_512x17_3sub2 = {
  106738. 1, 50,
  106739. _huff_lengthlist_line_512x17_3sub2,
  106740. 0, 0, 0, 0, 0,
  106741. NULL,
  106742. NULL,
  106743. NULL,
  106744. NULL,
  106745. 0
  106746. };
  106747. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106751. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106752. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106753. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106754. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106755. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106756. };
  106757. static static_codebook _huff_book_line_512x17_3sub3 = {
  106758. 1, 128,
  106759. _huff_lengthlist_line_512x17_3sub3,
  106760. 0, 0, 0, 0, 0,
  106761. NULL,
  106762. NULL,
  106763. NULL,
  106764. NULL,
  106765. 0
  106766. };
  106767. static long _huff_lengthlist_line_512x17_class1[] = {
  106768. 1, 2, 3, 6, 5, 4, 7, 7,
  106769. };
  106770. static static_codebook _huff_book_line_512x17_class1 = {
  106771. 1, 8,
  106772. _huff_lengthlist_line_512x17_class1,
  106773. 0, 0, 0, 0, 0,
  106774. NULL,
  106775. NULL,
  106776. NULL,
  106777. NULL,
  106778. 0
  106779. };
  106780. static long _huff_lengthlist_line_512x17_class2[] = {
  106781. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106782. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106783. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106784. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106785. };
  106786. static static_codebook _huff_book_line_512x17_class2 = {
  106787. 1, 64,
  106788. _huff_lengthlist_line_512x17_class2,
  106789. 0, 0, 0, 0, 0,
  106790. NULL,
  106791. NULL,
  106792. NULL,
  106793. NULL,
  106794. 0
  106795. };
  106796. static long _huff_lengthlist_line_512x17_class3[] = {
  106797. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106798. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106799. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106800. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106801. };
  106802. static static_codebook _huff_book_line_512x17_class3 = {
  106803. 1, 64,
  106804. _huff_lengthlist_line_512x17_class3,
  106805. 0, 0, 0, 0, 0,
  106806. NULL,
  106807. NULL,
  106808. NULL,
  106809. NULL,
  106810. 0
  106811. };
  106812. static long _huff_lengthlist_line_128x4_class0[] = {
  106813. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106814. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106815. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106816. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106817. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106818. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106819. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106820. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106821. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106822. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106823. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106824. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106825. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106826. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106827. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106828. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106829. };
  106830. static static_codebook _huff_book_line_128x4_class0 = {
  106831. 1, 256,
  106832. _huff_lengthlist_line_128x4_class0,
  106833. 0, 0, 0, 0, 0,
  106834. NULL,
  106835. NULL,
  106836. NULL,
  106837. NULL,
  106838. 0
  106839. };
  106840. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106841. 2, 2, 2, 2,
  106842. };
  106843. static static_codebook _huff_book_line_128x4_0sub0 = {
  106844. 1, 4,
  106845. _huff_lengthlist_line_128x4_0sub0,
  106846. 0, 0, 0, 0, 0,
  106847. NULL,
  106848. NULL,
  106849. NULL,
  106850. NULL,
  106851. 0
  106852. };
  106853. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106854. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106855. };
  106856. static static_codebook _huff_book_line_128x4_0sub1 = {
  106857. 1, 10,
  106858. _huff_lengthlist_line_128x4_0sub1,
  106859. 0, 0, 0, 0, 0,
  106860. NULL,
  106861. NULL,
  106862. NULL,
  106863. NULL,
  106864. 0
  106865. };
  106866. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106868. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106869. };
  106870. static static_codebook _huff_book_line_128x4_0sub2 = {
  106871. 1, 25,
  106872. _huff_lengthlist_line_128x4_0sub2,
  106873. 0, 0, 0, 0, 0,
  106874. NULL,
  106875. NULL,
  106876. NULL,
  106877. NULL,
  106878. 0
  106879. };
  106880. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106883. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106884. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106885. };
  106886. static static_codebook _huff_book_line_128x4_0sub3 = {
  106887. 1, 64,
  106888. _huff_lengthlist_line_128x4_0sub3,
  106889. 0, 0, 0, 0, 0,
  106890. NULL,
  106891. NULL,
  106892. NULL,
  106893. NULL,
  106894. 0
  106895. };
  106896. static long _huff_lengthlist_line_256x4_class0[] = {
  106897. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106898. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106899. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106900. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106901. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106902. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106903. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106904. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106905. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106906. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106907. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106908. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106909. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106910. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106911. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106912. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106913. };
  106914. static static_codebook _huff_book_line_256x4_class0 = {
  106915. 1, 256,
  106916. _huff_lengthlist_line_256x4_class0,
  106917. 0, 0, 0, 0, 0,
  106918. NULL,
  106919. NULL,
  106920. NULL,
  106921. NULL,
  106922. 0
  106923. };
  106924. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106925. 2, 2, 2, 2,
  106926. };
  106927. static static_codebook _huff_book_line_256x4_0sub0 = {
  106928. 1, 4,
  106929. _huff_lengthlist_line_256x4_0sub0,
  106930. 0, 0, 0, 0, 0,
  106931. NULL,
  106932. NULL,
  106933. NULL,
  106934. NULL,
  106935. 0
  106936. };
  106937. static long _huff_lengthlist_line_256x4_0sub1[] = {
  106938. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  106939. };
  106940. static static_codebook _huff_book_line_256x4_0sub1 = {
  106941. 1, 10,
  106942. _huff_lengthlist_line_256x4_0sub1,
  106943. 0, 0, 0, 0, 0,
  106944. NULL,
  106945. NULL,
  106946. NULL,
  106947. NULL,
  106948. 0
  106949. };
  106950. static long _huff_lengthlist_line_256x4_0sub2[] = {
  106951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  106952. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  106953. };
  106954. static static_codebook _huff_book_line_256x4_0sub2 = {
  106955. 1, 25,
  106956. _huff_lengthlist_line_256x4_0sub2,
  106957. 0, 0, 0, 0, 0,
  106958. NULL,
  106959. NULL,
  106960. NULL,
  106961. NULL,
  106962. 0
  106963. };
  106964. static long _huff_lengthlist_line_256x4_0sub3[] = {
  106965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106967. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  106968. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  106969. };
  106970. static static_codebook _huff_book_line_256x4_0sub3 = {
  106971. 1, 64,
  106972. _huff_lengthlist_line_256x4_0sub3,
  106973. 0, 0, 0, 0, 0,
  106974. NULL,
  106975. NULL,
  106976. NULL,
  106977. NULL,
  106978. 0
  106979. };
  106980. static long _huff_lengthlist_line_128x7_class0[] = {
  106981. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  106982. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  106983. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  106984. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  106985. };
  106986. static static_codebook _huff_book_line_128x7_class0 = {
  106987. 1, 64,
  106988. _huff_lengthlist_line_128x7_class0,
  106989. 0, 0, 0, 0, 0,
  106990. NULL,
  106991. NULL,
  106992. NULL,
  106993. NULL,
  106994. 0
  106995. };
  106996. static long _huff_lengthlist_line_128x7_class1[] = {
  106997. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  106998. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  106999. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  107000. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107001. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  107002. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  107003. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  107004. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  107005. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  107006. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  107007. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  107008. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  107009. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  107010. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  107011. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  107012. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  107013. };
  107014. static static_codebook _huff_book_line_128x7_class1 = {
  107015. 1, 256,
  107016. _huff_lengthlist_line_128x7_class1,
  107017. 0, 0, 0, 0, 0,
  107018. NULL,
  107019. NULL,
  107020. NULL,
  107021. NULL,
  107022. 0
  107023. };
  107024. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107025. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107026. };
  107027. static static_codebook _huff_book_line_128x7_0sub1 = {
  107028. 1, 9,
  107029. _huff_lengthlist_line_128x7_0sub1,
  107030. 0, 0, 0, 0, 0,
  107031. NULL,
  107032. NULL,
  107033. NULL,
  107034. NULL,
  107035. 0
  107036. };
  107037. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107039. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107040. };
  107041. static static_codebook _huff_book_line_128x7_0sub2 = {
  107042. 1, 25,
  107043. _huff_lengthlist_line_128x7_0sub2,
  107044. 0, 0, 0, 0, 0,
  107045. NULL,
  107046. NULL,
  107047. NULL,
  107048. NULL,
  107049. 0
  107050. };
  107051. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107054. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107055. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107056. };
  107057. static static_codebook _huff_book_line_128x7_0sub3 = {
  107058. 1, 64,
  107059. _huff_lengthlist_line_128x7_0sub3,
  107060. 0, 0, 0, 0, 0,
  107061. NULL,
  107062. NULL,
  107063. NULL,
  107064. NULL,
  107065. 0
  107066. };
  107067. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107068. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107069. };
  107070. static static_codebook _huff_book_line_128x7_1sub1 = {
  107071. 1, 9,
  107072. _huff_lengthlist_line_128x7_1sub1,
  107073. 0, 0, 0, 0, 0,
  107074. NULL,
  107075. NULL,
  107076. NULL,
  107077. NULL,
  107078. 0
  107079. };
  107080. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107082. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107083. };
  107084. static static_codebook _huff_book_line_128x7_1sub2 = {
  107085. 1, 25,
  107086. _huff_lengthlist_line_128x7_1sub2,
  107087. 0, 0, 0, 0, 0,
  107088. NULL,
  107089. NULL,
  107090. NULL,
  107091. NULL,
  107092. 0
  107093. };
  107094. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107097. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107098. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107099. };
  107100. static static_codebook _huff_book_line_128x7_1sub3 = {
  107101. 1, 64,
  107102. _huff_lengthlist_line_128x7_1sub3,
  107103. 0, 0, 0, 0, 0,
  107104. NULL,
  107105. NULL,
  107106. NULL,
  107107. NULL,
  107108. 0
  107109. };
  107110. static long _huff_lengthlist_line_128x11_class1[] = {
  107111. 1, 6, 3, 7, 2, 4, 5, 7,
  107112. };
  107113. static static_codebook _huff_book_line_128x11_class1 = {
  107114. 1, 8,
  107115. _huff_lengthlist_line_128x11_class1,
  107116. 0, 0, 0, 0, 0,
  107117. NULL,
  107118. NULL,
  107119. NULL,
  107120. NULL,
  107121. 0
  107122. };
  107123. static long _huff_lengthlist_line_128x11_class2[] = {
  107124. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107125. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107126. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107127. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107128. };
  107129. static static_codebook _huff_book_line_128x11_class2 = {
  107130. 1, 64,
  107131. _huff_lengthlist_line_128x11_class2,
  107132. 0, 0, 0, 0, 0,
  107133. NULL,
  107134. NULL,
  107135. NULL,
  107136. NULL,
  107137. 0
  107138. };
  107139. static long _huff_lengthlist_line_128x11_class3[] = {
  107140. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107141. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107142. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107143. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107144. };
  107145. static static_codebook _huff_book_line_128x11_class3 = {
  107146. 1, 64,
  107147. _huff_lengthlist_line_128x11_class3,
  107148. 0, 0, 0, 0, 0,
  107149. NULL,
  107150. NULL,
  107151. NULL,
  107152. NULL,
  107153. 0
  107154. };
  107155. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107156. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107157. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107158. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107159. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107160. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107161. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107162. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107163. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107164. };
  107165. static static_codebook _huff_book_line_128x11_0sub0 = {
  107166. 1, 128,
  107167. _huff_lengthlist_line_128x11_0sub0,
  107168. 0, 0, 0, 0, 0,
  107169. NULL,
  107170. NULL,
  107171. NULL,
  107172. NULL,
  107173. 0
  107174. };
  107175. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107176. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107177. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107178. };
  107179. static static_codebook _huff_book_line_128x11_1sub0 = {
  107180. 1, 32,
  107181. _huff_lengthlist_line_128x11_1sub0,
  107182. 0, 0, 0, 0, 0,
  107183. NULL,
  107184. NULL,
  107185. NULL,
  107186. NULL,
  107187. 0
  107188. };
  107189. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107192. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107193. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107194. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107195. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107196. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107197. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107198. };
  107199. static static_codebook _huff_book_line_128x11_1sub1 = {
  107200. 1, 128,
  107201. _huff_lengthlist_line_128x11_1sub1,
  107202. 0, 0, 0, 0, 0,
  107203. NULL,
  107204. NULL,
  107205. NULL,
  107206. NULL,
  107207. 0
  107208. };
  107209. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107210. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107211. 5, 5,
  107212. };
  107213. static static_codebook _huff_book_line_128x11_2sub1 = {
  107214. 1, 18,
  107215. _huff_lengthlist_line_128x11_2sub1,
  107216. 0, 0, 0, 0, 0,
  107217. NULL,
  107218. NULL,
  107219. NULL,
  107220. NULL,
  107221. 0
  107222. };
  107223. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107225. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107226. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107227. 8,11,
  107228. };
  107229. static static_codebook _huff_book_line_128x11_2sub2 = {
  107230. 1, 50,
  107231. _huff_lengthlist_line_128x11_2sub2,
  107232. 0, 0, 0, 0, 0,
  107233. NULL,
  107234. NULL,
  107235. NULL,
  107236. NULL,
  107237. 0
  107238. };
  107239. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107243. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107244. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107245. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107246. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107247. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107248. };
  107249. static static_codebook _huff_book_line_128x11_2sub3 = {
  107250. 1, 128,
  107251. _huff_lengthlist_line_128x11_2sub3,
  107252. 0, 0, 0, 0, 0,
  107253. NULL,
  107254. NULL,
  107255. NULL,
  107256. NULL,
  107257. 0
  107258. };
  107259. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107260. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107261. 5, 4,
  107262. };
  107263. static static_codebook _huff_book_line_128x11_3sub1 = {
  107264. 1, 18,
  107265. _huff_lengthlist_line_128x11_3sub1,
  107266. 0, 0, 0, 0, 0,
  107267. NULL,
  107268. NULL,
  107269. NULL,
  107270. NULL,
  107271. 0
  107272. };
  107273. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107275. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107276. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107277. 12, 6,
  107278. };
  107279. static static_codebook _huff_book_line_128x11_3sub2 = {
  107280. 1, 50,
  107281. _huff_lengthlist_line_128x11_3sub2,
  107282. 0, 0, 0, 0, 0,
  107283. NULL,
  107284. NULL,
  107285. NULL,
  107286. NULL,
  107287. 0
  107288. };
  107289. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107293. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107294. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107295. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107296. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107297. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107298. };
  107299. static static_codebook _huff_book_line_128x11_3sub3 = {
  107300. 1, 128,
  107301. _huff_lengthlist_line_128x11_3sub3,
  107302. 0, 0, 0, 0, 0,
  107303. NULL,
  107304. NULL,
  107305. NULL,
  107306. NULL,
  107307. 0
  107308. };
  107309. static long _huff_lengthlist_line_128x17_class1[] = {
  107310. 1, 3, 4, 7, 2, 5, 6, 7,
  107311. };
  107312. static static_codebook _huff_book_line_128x17_class1 = {
  107313. 1, 8,
  107314. _huff_lengthlist_line_128x17_class1,
  107315. 0, 0, 0, 0, 0,
  107316. NULL,
  107317. NULL,
  107318. NULL,
  107319. NULL,
  107320. 0
  107321. };
  107322. static long _huff_lengthlist_line_128x17_class2[] = {
  107323. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107324. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107325. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107326. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107327. };
  107328. static static_codebook _huff_book_line_128x17_class2 = {
  107329. 1, 64,
  107330. _huff_lengthlist_line_128x17_class2,
  107331. 0, 0, 0, 0, 0,
  107332. NULL,
  107333. NULL,
  107334. NULL,
  107335. NULL,
  107336. 0
  107337. };
  107338. static long _huff_lengthlist_line_128x17_class3[] = {
  107339. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107340. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107341. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107342. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107343. };
  107344. static static_codebook _huff_book_line_128x17_class3 = {
  107345. 1, 64,
  107346. _huff_lengthlist_line_128x17_class3,
  107347. 0, 0, 0, 0, 0,
  107348. NULL,
  107349. NULL,
  107350. NULL,
  107351. NULL,
  107352. 0
  107353. };
  107354. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107355. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107356. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107357. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107358. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107359. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107360. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107361. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107362. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107363. };
  107364. static static_codebook _huff_book_line_128x17_0sub0 = {
  107365. 1, 128,
  107366. _huff_lengthlist_line_128x17_0sub0,
  107367. 0, 0, 0, 0, 0,
  107368. NULL,
  107369. NULL,
  107370. NULL,
  107371. NULL,
  107372. 0
  107373. };
  107374. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107375. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107376. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107377. };
  107378. static static_codebook _huff_book_line_128x17_1sub0 = {
  107379. 1, 32,
  107380. _huff_lengthlist_line_128x17_1sub0,
  107381. 0, 0, 0, 0, 0,
  107382. NULL,
  107383. NULL,
  107384. NULL,
  107385. NULL,
  107386. 0
  107387. };
  107388. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107391. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107392. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107393. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107394. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107395. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107396. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107397. };
  107398. static static_codebook _huff_book_line_128x17_1sub1 = {
  107399. 1, 128,
  107400. _huff_lengthlist_line_128x17_1sub1,
  107401. 0, 0, 0, 0, 0,
  107402. NULL,
  107403. NULL,
  107404. NULL,
  107405. NULL,
  107406. 0
  107407. };
  107408. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107409. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107410. 9, 4,
  107411. };
  107412. static static_codebook _huff_book_line_128x17_2sub1 = {
  107413. 1, 18,
  107414. _huff_lengthlist_line_128x17_2sub1,
  107415. 0, 0, 0, 0, 0,
  107416. NULL,
  107417. NULL,
  107418. NULL,
  107419. NULL,
  107420. 0
  107421. };
  107422. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107424. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107425. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107426. 13,13,
  107427. };
  107428. static static_codebook _huff_book_line_128x17_2sub2 = {
  107429. 1, 50,
  107430. _huff_lengthlist_line_128x17_2sub2,
  107431. 0, 0, 0, 0, 0,
  107432. NULL,
  107433. NULL,
  107434. NULL,
  107435. NULL,
  107436. 0
  107437. };
  107438. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107442. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107443. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107444. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107445. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107446. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107447. };
  107448. static static_codebook _huff_book_line_128x17_2sub3 = {
  107449. 1, 128,
  107450. _huff_lengthlist_line_128x17_2sub3,
  107451. 0, 0, 0, 0, 0,
  107452. NULL,
  107453. NULL,
  107454. NULL,
  107455. NULL,
  107456. 0
  107457. };
  107458. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107459. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107460. 6, 4,
  107461. };
  107462. static static_codebook _huff_book_line_128x17_3sub1 = {
  107463. 1, 18,
  107464. _huff_lengthlist_line_128x17_3sub1,
  107465. 0, 0, 0, 0, 0,
  107466. NULL,
  107467. NULL,
  107468. NULL,
  107469. NULL,
  107470. 0
  107471. };
  107472. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107474. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107475. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107476. 10, 8,
  107477. };
  107478. static static_codebook _huff_book_line_128x17_3sub2 = {
  107479. 1, 50,
  107480. _huff_lengthlist_line_128x17_3sub2,
  107481. 0, 0, 0, 0, 0,
  107482. NULL,
  107483. NULL,
  107484. NULL,
  107485. NULL,
  107486. 0
  107487. };
  107488. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107492. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107493. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107494. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107495. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107496. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107497. };
  107498. static static_codebook _huff_book_line_128x17_3sub3 = {
  107499. 1, 128,
  107500. _huff_lengthlist_line_128x17_3sub3,
  107501. 0, 0, 0, 0, 0,
  107502. NULL,
  107503. NULL,
  107504. NULL,
  107505. NULL,
  107506. 0
  107507. };
  107508. static long _huff_lengthlist_line_1024x27_class1[] = {
  107509. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107510. };
  107511. static static_codebook _huff_book_line_1024x27_class1 = {
  107512. 1, 16,
  107513. _huff_lengthlist_line_1024x27_class1,
  107514. 0, 0, 0, 0, 0,
  107515. NULL,
  107516. NULL,
  107517. NULL,
  107518. NULL,
  107519. 0
  107520. };
  107521. static long _huff_lengthlist_line_1024x27_class2[] = {
  107522. 1, 4, 2, 6, 3, 7, 5, 7,
  107523. };
  107524. static static_codebook _huff_book_line_1024x27_class2 = {
  107525. 1, 8,
  107526. _huff_lengthlist_line_1024x27_class2,
  107527. 0, 0, 0, 0, 0,
  107528. NULL,
  107529. NULL,
  107530. NULL,
  107531. NULL,
  107532. 0
  107533. };
  107534. static long _huff_lengthlist_line_1024x27_class3[] = {
  107535. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107536. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107537. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107538. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107539. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107540. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107541. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107542. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107543. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107544. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107545. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107546. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107547. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107548. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107549. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107550. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107551. };
  107552. static static_codebook _huff_book_line_1024x27_class3 = {
  107553. 1, 256,
  107554. _huff_lengthlist_line_1024x27_class3,
  107555. 0, 0, 0, 0, 0,
  107556. NULL,
  107557. NULL,
  107558. NULL,
  107559. NULL,
  107560. 0
  107561. };
  107562. static long _huff_lengthlist_line_1024x27_class4[] = {
  107563. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107564. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107565. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107566. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107567. };
  107568. static static_codebook _huff_book_line_1024x27_class4 = {
  107569. 1, 64,
  107570. _huff_lengthlist_line_1024x27_class4,
  107571. 0, 0, 0, 0, 0,
  107572. NULL,
  107573. NULL,
  107574. NULL,
  107575. NULL,
  107576. 0
  107577. };
  107578. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107579. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107580. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107581. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107582. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107583. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107584. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107585. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107586. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107587. };
  107588. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107589. 1, 128,
  107590. _huff_lengthlist_line_1024x27_0sub0,
  107591. 0, 0, 0, 0, 0,
  107592. NULL,
  107593. NULL,
  107594. NULL,
  107595. NULL,
  107596. 0
  107597. };
  107598. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107599. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107600. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107601. };
  107602. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107603. 1, 32,
  107604. _huff_lengthlist_line_1024x27_1sub0,
  107605. 0, 0, 0, 0, 0,
  107606. NULL,
  107607. NULL,
  107608. NULL,
  107609. NULL,
  107610. 0
  107611. };
  107612. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107615. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107616. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107617. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107618. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107619. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107620. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107621. };
  107622. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107623. 1, 128,
  107624. _huff_lengthlist_line_1024x27_1sub1,
  107625. 0, 0, 0, 0, 0,
  107626. NULL,
  107627. NULL,
  107628. NULL,
  107629. NULL,
  107630. 0
  107631. };
  107632. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107633. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107634. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107635. };
  107636. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107637. 1, 32,
  107638. _huff_lengthlist_line_1024x27_2sub0,
  107639. 0, 0, 0, 0, 0,
  107640. NULL,
  107641. NULL,
  107642. NULL,
  107643. NULL,
  107644. 0
  107645. };
  107646. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107649. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107650. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107651. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107652. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107653. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107654. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107655. };
  107656. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107657. 1, 128,
  107658. _huff_lengthlist_line_1024x27_2sub1,
  107659. 0, 0, 0, 0, 0,
  107660. NULL,
  107661. NULL,
  107662. NULL,
  107663. NULL,
  107664. 0
  107665. };
  107666. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107667. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107668. 5, 5,
  107669. };
  107670. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107671. 1, 18,
  107672. _huff_lengthlist_line_1024x27_3sub1,
  107673. 0, 0, 0, 0, 0,
  107674. NULL,
  107675. NULL,
  107676. NULL,
  107677. NULL,
  107678. 0
  107679. };
  107680. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107682. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107683. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107684. 9,11,
  107685. };
  107686. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107687. 1, 50,
  107688. _huff_lengthlist_line_1024x27_3sub2,
  107689. 0, 0, 0, 0, 0,
  107690. NULL,
  107691. NULL,
  107692. NULL,
  107693. NULL,
  107694. 0
  107695. };
  107696. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107700. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107701. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107702. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107703. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107704. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107705. };
  107706. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107707. 1, 128,
  107708. _huff_lengthlist_line_1024x27_3sub3,
  107709. 0, 0, 0, 0, 0,
  107710. NULL,
  107711. NULL,
  107712. NULL,
  107713. NULL,
  107714. 0
  107715. };
  107716. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107717. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107718. 5, 4,
  107719. };
  107720. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107721. 1, 18,
  107722. _huff_lengthlist_line_1024x27_4sub1,
  107723. 0, 0, 0, 0, 0,
  107724. NULL,
  107725. NULL,
  107726. NULL,
  107727. NULL,
  107728. 0
  107729. };
  107730. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107732. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107733. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107734. 9,12,
  107735. };
  107736. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107737. 1, 50,
  107738. _huff_lengthlist_line_1024x27_4sub2,
  107739. 0, 0, 0, 0, 0,
  107740. NULL,
  107741. NULL,
  107742. NULL,
  107743. NULL,
  107744. 0
  107745. };
  107746. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107750. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107751. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107752. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107753. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107754. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107755. };
  107756. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107757. 1, 128,
  107758. _huff_lengthlist_line_1024x27_4sub3,
  107759. 0, 0, 0, 0, 0,
  107760. NULL,
  107761. NULL,
  107762. NULL,
  107763. NULL,
  107764. 0
  107765. };
  107766. static long _huff_lengthlist_line_2048x27_class1[] = {
  107767. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107768. };
  107769. static static_codebook _huff_book_line_2048x27_class1 = {
  107770. 1, 16,
  107771. _huff_lengthlist_line_2048x27_class1,
  107772. 0, 0, 0, 0, 0,
  107773. NULL,
  107774. NULL,
  107775. NULL,
  107776. NULL,
  107777. 0
  107778. };
  107779. static long _huff_lengthlist_line_2048x27_class2[] = {
  107780. 1, 2, 3, 6, 4, 7, 5, 7,
  107781. };
  107782. static static_codebook _huff_book_line_2048x27_class2 = {
  107783. 1, 8,
  107784. _huff_lengthlist_line_2048x27_class2,
  107785. 0, 0, 0, 0, 0,
  107786. NULL,
  107787. NULL,
  107788. NULL,
  107789. NULL,
  107790. 0
  107791. };
  107792. static long _huff_lengthlist_line_2048x27_class3[] = {
  107793. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107794. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107795. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107796. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107797. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107798. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107799. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107800. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107801. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107802. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107803. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107804. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107805. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107806. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107807. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107808. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107809. };
  107810. static static_codebook _huff_book_line_2048x27_class3 = {
  107811. 1, 256,
  107812. _huff_lengthlist_line_2048x27_class3,
  107813. 0, 0, 0, 0, 0,
  107814. NULL,
  107815. NULL,
  107816. NULL,
  107817. NULL,
  107818. 0
  107819. };
  107820. static long _huff_lengthlist_line_2048x27_class4[] = {
  107821. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107822. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107823. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107824. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107825. };
  107826. static static_codebook _huff_book_line_2048x27_class4 = {
  107827. 1, 64,
  107828. _huff_lengthlist_line_2048x27_class4,
  107829. 0, 0, 0, 0, 0,
  107830. NULL,
  107831. NULL,
  107832. NULL,
  107833. NULL,
  107834. 0
  107835. };
  107836. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107837. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107838. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107839. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107840. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107841. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107842. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107843. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107844. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107845. };
  107846. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107847. 1, 128,
  107848. _huff_lengthlist_line_2048x27_0sub0,
  107849. 0, 0, 0, 0, 0,
  107850. NULL,
  107851. NULL,
  107852. NULL,
  107853. NULL,
  107854. 0
  107855. };
  107856. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107857. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107858. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107859. };
  107860. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107861. 1, 32,
  107862. _huff_lengthlist_line_2048x27_1sub0,
  107863. 0, 0, 0, 0, 0,
  107864. NULL,
  107865. NULL,
  107866. NULL,
  107867. NULL,
  107868. 0
  107869. };
  107870. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107873. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107874. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107875. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107876. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107877. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107878. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107879. };
  107880. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107881. 1, 128,
  107882. _huff_lengthlist_line_2048x27_1sub1,
  107883. 0, 0, 0, 0, 0,
  107884. NULL,
  107885. NULL,
  107886. NULL,
  107887. NULL,
  107888. 0
  107889. };
  107890. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107891. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107892. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107893. };
  107894. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107895. 1, 32,
  107896. _huff_lengthlist_line_2048x27_2sub0,
  107897. 0, 0, 0, 0, 0,
  107898. NULL,
  107899. NULL,
  107900. NULL,
  107901. NULL,
  107902. 0
  107903. };
  107904. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107907. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107908. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107909. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107910. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107911. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107912. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107913. };
  107914. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107915. 1, 128,
  107916. _huff_lengthlist_line_2048x27_2sub1,
  107917. 0, 0, 0, 0, 0,
  107918. NULL,
  107919. NULL,
  107920. NULL,
  107921. NULL,
  107922. 0
  107923. };
  107924. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107925. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107926. 5, 5,
  107927. };
  107928. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107929. 1, 18,
  107930. _huff_lengthlist_line_2048x27_3sub1,
  107931. 0, 0, 0, 0, 0,
  107932. NULL,
  107933. NULL,
  107934. NULL,
  107935. NULL,
  107936. 0
  107937. };
  107938. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  107939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107940. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  107941. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  107942. 10,12,
  107943. };
  107944. static static_codebook _huff_book_line_2048x27_3sub2 = {
  107945. 1, 50,
  107946. _huff_lengthlist_line_2048x27_3sub2,
  107947. 0, 0, 0, 0, 0,
  107948. NULL,
  107949. NULL,
  107950. NULL,
  107951. NULL,
  107952. 0
  107953. };
  107954. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  107955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107958. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  107959. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107960. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107961. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107962. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107963. };
  107964. static static_codebook _huff_book_line_2048x27_3sub3 = {
  107965. 1, 128,
  107966. _huff_lengthlist_line_2048x27_3sub3,
  107967. 0, 0, 0, 0, 0,
  107968. NULL,
  107969. NULL,
  107970. NULL,
  107971. NULL,
  107972. 0
  107973. };
  107974. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  107975. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  107976. 4, 5,
  107977. };
  107978. static static_codebook _huff_book_line_2048x27_4sub1 = {
  107979. 1, 18,
  107980. _huff_lengthlist_line_2048x27_4sub1,
  107981. 0, 0, 0, 0, 0,
  107982. NULL,
  107983. NULL,
  107984. NULL,
  107985. NULL,
  107986. 0
  107987. };
  107988. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  107989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107990. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  107991. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  107992. 10,10,
  107993. };
  107994. static static_codebook _huff_book_line_2048x27_4sub2 = {
  107995. 1, 50,
  107996. _huff_lengthlist_line_2048x27_4sub2,
  107997. 0, 0, 0, 0, 0,
  107998. NULL,
  107999. NULL,
  108000. NULL,
  108001. NULL,
  108002. 0
  108003. };
  108004. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  108005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108008. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  108009. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  108010. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108011. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108012. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108013. };
  108014. static static_codebook _huff_book_line_2048x27_4sub3 = {
  108015. 1, 128,
  108016. _huff_lengthlist_line_2048x27_4sub3,
  108017. 0, 0, 0, 0, 0,
  108018. NULL,
  108019. NULL,
  108020. NULL,
  108021. NULL,
  108022. 0
  108023. };
  108024. static long _huff_lengthlist_line_256x4low_class0[] = {
  108025. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108026. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108027. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108028. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108029. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108030. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108031. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108032. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108033. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108034. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108035. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108036. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108037. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108038. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108039. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108040. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108041. };
  108042. static static_codebook _huff_book_line_256x4low_class0 = {
  108043. 1, 256,
  108044. _huff_lengthlist_line_256x4low_class0,
  108045. 0, 0, 0, 0, 0,
  108046. NULL,
  108047. NULL,
  108048. NULL,
  108049. NULL,
  108050. 0
  108051. };
  108052. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108053. 1, 3, 2, 3,
  108054. };
  108055. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108056. 1, 4,
  108057. _huff_lengthlist_line_256x4low_0sub0,
  108058. 0, 0, 0, 0, 0,
  108059. NULL,
  108060. NULL,
  108061. NULL,
  108062. NULL,
  108063. 0
  108064. };
  108065. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108066. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108067. };
  108068. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108069. 1, 10,
  108070. _huff_lengthlist_line_256x4low_0sub1,
  108071. 0, 0, 0, 0, 0,
  108072. NULL,
  108073. NULL,
  108074. NULL,
  108075. NULL,
  108076. 0
  108077. };
  108078. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108080. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108081. };
  108082. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108083. 1, 25,
  108084. _huff_lengthlist_line_256x4low_0sub2,
  108085. 0, 0, 0, 0, 0,
  108086. NULL,
  108087. NULL,
  108088. NULL,
  108089. NULL,
  108090. 0
  108091. };
  108092. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  108093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  108095. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108096. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108097. };
  108098. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108099. 1, 64,
  108100. _huff_lengthlist_line_256x4low_0sub3,
  108101. 0, 0, 0, 0, 0,
  108102. NULL,
  108103. NULL,
  108104. NULL,
  108105. NULL,
  108106. 0
  108107. };
  108108. /*** End of inlined file: floor_books.h ***/
  108109. static static_codebook *_floor_128x4_books[]={
  108110. &_huff_book_line_128x4_class0,
  108111. &_huff_book_line_128x4_0sub0,
  108112. &_huff_book_line_128x4_0sub1,
  108113. &_huff_book_line_128x4_0sub2,
  108114. &_huff_book_line_128x4_0sub3,
  108115. };
  108116. static static_codebook *_floor_256x4_books[]={
  108117. &_huff_book_line_256x4_class0,
  108118. &_huff_book_line_256x4_0sub0,
  108119. &_huff_book_line_256x4_0sub1,
  108120. &_huff_book_line_256x4_0sub2,
  108121. &_huff_book_line_256x4_0sub3,
  108122. };
  108123. static static_codebook *_floor_128x7_books[]={
  108124. &_huff_book_line_128x7_class0,
  108125. &_huff_book_line_128x7_class1,
  108126. &_huff_book_line_128x7_0sub1,
  108127. &_huff_book_line_128x7_0sub2,
  108128. &_huff_book_line_128x7_0sub3,
  108129. &_huff_book_line_128x7_1sub1,
  108130. &_huff_book_line_128x7_1sub2,
  108131. &_huff_book_line_128x7_1sub3,
  108132. };
  108133. static static_codebook *_floor_256x7_books[]={
  108134. &_huff_book_line_256x7_class0,
  108135. &_huff_book_line_256x7_class1,
  108136. &_huff_book_line_256x7_0sub1,
  108137. &_huff_book_line_256x7_0sub2,
  108138. &_huff_book_line_256x7_0sub3,
  108139. &_huff_book_line_256x7_1sub1,
  108140. &_huff_book_line_256x7_1sub2,
  108141. &_huff_book_line_256x7_1sub3,
  108142. };
  108143. static static_codebook *_floor_128x11_books[]={
  108144. &_huff_book_line_128x11_class1,
  108145. &_huff_book_line_128x11_class2,
  108146. &_huff_book_line_128x11_class3,
  108147. &_huff_book_line_128x11_0sub0,
  108148. &_huff_book_line_128x11_1sub0,
  108149. &_huff_book_line_128x11_1sub1,
  108150. &_huff_book_line_128x11_2sub1,
  108151. &_huff_book_line_128x11_2sub2,
  108152. &_huff_book_line_128x11_2sub3,
  108153. &_huff_book_line_128x11_3sub1,
  108154. &_huff_book_line_128x11_3sub2,
  108155. &_huff_book_line_128x11_3sub3,
  108156. };
  108157. static static_codebook *_floor_128x17_books[]={
  108158. &_huff_book_line_128x17_class1,
  108159. &_huff_book_line_128x17_class2,
  108160. &_huff_book_line_128x17_class3,
  108161. &_huff_book_line_128x17_0sub0,
  108162. &_huff_book_line_128x17_1sub0,
  108163. &_huff_book_line_128x17_1sub1,
  108164. &_huff_book_line_128x17_2sub1,
  108165. &_huff_book_line_128x17_2sub2,
  108166. &_huff_book_line_128x17_2sub3,
  108167. &_huff_book_line_128x17_3sub1,
  108168. &_huff_book_line_128x17_3sub2,
  108169. &_huff_book_line_128x17_3sub3,
  108170. };
  108171. static static_codebook *_floor_256x4low_books[]={
  108172. &_huff_book_line_256x4low_class0,
  108173. &_huff_book_line_256x4low_0sub0,
  108174. &_huff_book_line_256x4low_0sub1,
  108175. &_huff_book_line_256x4low_0sub2,
  108176. &_huff_book_line_256x4low_0sub3,
  108177. };
  108178. static static_codebook *_floor_1024x27_books[]={
  108179. &_huff_book_line_1024x27_class1,
  108180. &_huff_book_line_1024x27_class2,
  108181. &_huff_book_line_1024x27_class3,
  108182. &_huff_book_line_1024x27_class4,
  108183. &_huff_book_line_1024x27_0sub0,
  108184. &_huff_book_line_1024x27_1sub0,
  108185. &_huff_book_line_1024x27_1sub1,
  108186. &_huff_book_line_1024x27_2sub0,
  108187. &_huff_book_line_1024x27_2sub1,
  108188. &_huff_book_line_1024x27_3sub1,
  108189. &_huff_book_line_1024x27_3sub2,
  108190. &_huff_book_line_1024x27_3sub3,
  108191. &_huff_book_line_1024x27_4sub1,
  108192. &_huff_book_line_1024x27_4sub2,
  108193. &_huff_book_line_1024x27_4sub3,
  108194. };
  108195. static static_codebook *_floor_2048x27_books[]={
  108196. &_huff_book_line_2048x27_class1,
  108197. &_huff_book_line_2048x27_class2,
  108198. &_huff_book_line_2048x27_class3,
  108199. &_huff_book_line_2048x27_class4,
  108200. &_huff_book_line_2048x27_0sub0,
  108201. &_huff_book_line_2048x27_1sub0,
  108202. &_huff_book_line_2048x27_1sub1,
  108203. &_huff_book_line_2048x27_2sub0,
  108204. &_huff_book_line_2048x27_2sub1,
  108205. &_huff_book_line_2048x27_3sub1,
  108206. &_huff_book_line_2048x27_3sub2,
  108207. &_huff_book_line_2048x27_3sub3,
  108208. &_huff_book_line_2048x27_4sub1,
  108209. &_huff_book_line_2048x27_4sub2,
  108210. &_huff_book_line_2048x27_4sub3,
  108211. };
  108212. static static_codebook *_floor_512x17_books[]={
  108213. &_huff_book_line_512x17_class1,
  108214. &_huff_book_line_512x17_class2,
  108215. &_huff_book_line_512x17_class3,
  108216. &_huff_book_line_512x17_0sub0,
  108217. &_huff_book_line_512x17_1sub0,
  108218. &_huff_book_line_512x17_1sub1,
  108219. &_huff_book_line_512x17_2sub1,
  108220. &_huff_book_line_512x17_2sub2,
  108221. &_huff_book_line_512x17_2sub3,
  108222. &_huff_book_line_512x17_3sub1,
  108223. &_huff_book_line_512x17_3sub2,
  108224. &_huff_book_line_512x17_3sub3,
  108225. };
  108226. static static_codebook **_floor_books[10]={
  108227. _floor_128x4_books,
  108228. _floor_256x4_books,
  108229. _floor_128x7_books,
  108230. _floor_256x7_books,
  108231. _floor_128x11_books,
  108232. _floor_128x17_books,
  108233. _floor_256x4low_books,
  108234. _floor_1024x27_books,
  108235. _floor_2048x27_books,
  108236. _floor_512x17_books,
  108237. };
  108238. static vorbis_info_floor1 _floor[10]={
  108239. {
  108240. 1,{0},{4},{2},{0},
  108241. {{1,2,3,4}},
  108242. 4,{0,128, 33,8,16,70},
  108243. 60,30,500, 1.,18., -1
  108244. },
  108245. {
  108246. 1,{0},{4},{2},{0},
  108247. {{1,2,3,4}},
  108248. 4,{0,256, 66,16,32,140},
  108249. 60,30,500, 1.,18., -1
  108250. },
  108251. {
  108252. 2,{0,1},{3,4},{2,2},{0,1},
  108253. {{-1,2,3,4},{-1,5,6,7}},
  108254. 4,{0,128, 14,4,58, 2,8,28,90},
  108255. 60,30,500, 1.,18., -1
  108256. },
  108257. {
  108258. 2,{0,1},{3,4},{2,2},{0,1},
  108259. {{-1,2,3,4},{-1,5,6,7}},
  108260. 4,{0,256, 28,8,116, 4,16,56,180},
  108261. 60,30,500, 1.,18., -1
  108262. },
  108263. {
  108264. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108265. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108266. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108267. 60,30,500, 1,18., -1
  108268. },
  108269. {
  108270. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108271. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108272. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108273. 60,30,500, 1,18., -1
  108274. },
  108275. {
  108276. 1,{0},{4},{2},{0},
  108277. {{1,2,3,4}},
  108278. 4,{0,256, 66,16,32,140},
  108279. 60,30,500, 1.,18., -1
  108280. },
  108281. {
  108282. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108283. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108284. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108285. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108286. 60,30,500, 3,18., -1 /* lowpass */
  108287. },
  108288. {
  108289. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108290. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108291. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108292. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108293. 60,30,500, 3,18., -1 /* lowpass */
  108294. },
  108295. {
  108296. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108297. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108298. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108299. 7,23,39, 55,79,110, 156,232,360},
  108300. 60,30,500, 1,18., -1 /* lowpass! */
  108301. },
  108302. };
  108303. /*** End of inlined file: floor_all.h ***/
  108304. /*** Start of inlined file: residue_44.h ***/
  108305. /*** Start of inlined file: res_books_stereo.h ***/
  108306. static long _vq_quantlist__16c0_s_p1_0[] = {
  108307. 1,
  108308. 0,
  108309. 2,
  108310. };
  108311. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108312. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108313. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108317. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108318. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108322. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108323. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108358. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  108363. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  108368. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108403. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108404. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108409. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108414. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108620. 0, 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,
  108723. };
  108724. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108725. -0.5, 0.5,
  108726. };
  108727. static long _vq_quantmap__16c0_s_p1_0[] = {
  108728. 1, 0, 2,
  108729. };
  108730. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108731. _vq_quantthresh__16c0_s_p1_0,
  108732. _vq_quantmap__16c0_s_p1_0,
  108733. 3,
  108734. 3
  108735. };
  108736. static static_codebook _16c0_s_p1_0 = {
  108737. 8, 6561,
  108738. _vq_lengthlist__16c0_s_p1_0,
  108739. 1, -535822336, 1611661312, 2, 0,
  108740. _vq_quantlist__16c0_s_p1_0,
  108741. NULL,
  108742. &_vq_auxt__16c0_s_p1_0,
  108743. NULL,
  108744. 0
  108745. };
  108746. static long _vq_quantlist__16c0_s_p2_0[] = {
  108747. 2,
  108748. 1,
  108749. 3,
  108750. 0,
  108751. 4,
  108752. };
  108753. static long _vq_lengthlist__16c0_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108793. 0,
  108794. };
  108795. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108796. -1.5, -0.5, 0.5, 1.5,
  108797. };
  108798. static long _vq_quantmap__16c0_s_p2_0[] = {
  108799. 3, 1, 0, 2, 4,
  108800. };
  108801. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108802. _vq_quantthresh__16c0_s_p2_0,
  108803. _vq_quantmap__16c0_s_p2_0,
  108804. 5,
  108805. 5
  108806. };
  108807. static static_codebook _16c0_s_p2_0 = {
  108808. 4, 625,
  108809. _vq_lengthlist__16c0_s_p2_0,
  108810. 1, -533725184, 1611661312, 3, 0,
  108811. _vq_quantlist__16c0_s_p2_0,
  108812. NULL,
  108813. &_vq_auxt__16c0_s_p2_0,
  108814. NULL,
  108815. 0
  108816. };
  108817. static long _vq_quantlist__16c0_s_p3_0[] = {
  108818. 2,
  108819. 1,
  108820. 3,
  108821. 0,
  108822. 4,
  108823. };
  108824. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108825. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108828. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108831. 0, 0, 0, 0, 6, 6, 6, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108864. 0,
  108865. };
  108866. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108867. -1.5, -0.5, 0.5, 1.5,
  108868. };
  108869. static long _vq_quantmap__16c0_s_p3_0[] = {
  108870. 3, 1, 0, 2, 4,
  108871. };
  108872. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108873. _vq_quantthresh__16c0_s_p3_0,
  108874. _vq_quantmap__16c0_s_p3_0,
  108875. 5,
  108876. 5
  108877. };
  108878. static static_codebook _16c0_s_p3_0 = {
  108879. 4, 625,
  108880. _vq_lengthlist__16c0_s_p3_0,
  108881. 1, -533725184, 1611661312, 3, 0,
  108882. _vq_quantlist__16c0_s_p3_0,
  108883. NULL,
  108884. &_vq_auxt__16c0_s_p3_0,
  108885. NULL,
  108886. 0
  108887. };
  108888. static long _vq_quantlist__16c0_s_p4_0[] = {
  108889. 4,
  108890. 3,
  108891. 5,
  108892. 2,
  108893. 6,
  108894. 1,
  108895. 7,
  108896. 0,
  108897. 8,
  108898. };
  108899. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108900. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108901. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108902. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108903. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108904. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108905. 0,
  108906. };
  108907. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108908. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108909. };
  108910. static long _vq_quantmap__16c0_s_p4_0[] = {
  108911. 7, 5, 3, 1, 0, 2, 4, 6,
  108912. 8,
  108913. };
  108914. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108915. _vq_quantthresh__16c0_s_p4_0,
  108916. _vq_quantmap__16c0_s_p4_0,
  108917. 9,
  108918. 9
  108919. };
  108920. static static_codebook _16c0_s_p4_0 = {
  108921. 2, 81,
  108922. _vq_lengthlist__16c0_s_p4_0,
  108923. 1, -531628032, 1611661312, 4, 0,
  108924. _vq_quantlist__16c0_s_p4_0,
  108925. NULL,
  108926. &_vq_auxt__16c0_s_p4_0,
  108927. NULL,
  108928. 0
  108929. };
  108930. static long _vq_quantlist__16c0_s_p5_0[] = {
  108931. 4,
  108932. 3,
  108933. 5,
  108934. 2,
  108935. 6,
  108936. 1,
  108937. 7,
  108938. 0,
  108939. 8,
  108940. };
  108941. static long _vq_lengthlist__16c0_s_p5_0[] = {
  108942. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  108943. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  108944. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  108945. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  108946. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  108947. 10,
  108948. };
  108949. static float _vq_quantthresh__16c0_s_p5_0[] = {
  108950. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108951. };
  108952. static long _vq_quantmap__16c0_s_p5_0[] = {
  108953. 7, 5, 3, 1, 0, 2, 4, 6,
  108954. 8,
  108955. };
  108956. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  108957. _vq_quantthresh__16c0_s_p5_0,
  108958. _vq_quantmap__16c0_s_p5_0,
  108959. 9,
  108960. 9
  108961. };
  108962. static static_codebook _16c0_s_p5_0 = {
  108963. 2, 81,
  108964. _vq_lengthlist__16c0_s_p5_0,
  108965. 1, -531628032, 1611661312, 4, 0,
  108966. _vq_quantlist__16c0_s_p5_0,
  108967. NULL,
  108968. &_vq_auxt__16c0_s_p5_0,
  108969. NULL,
  108970. 0
  108971. };
  108972. static long _vq_quantlist__16c0_s_p6_0[] = {
  108973. 8,
  108974. 7,
  108975. 9,
  108976. 6,
  108977. 10,
  108978. 5,
  108979. 11,
  108980. 4,
  108981. 12,
  108982. 3,
  108983. 13,
  108984. 2,
  108985. 14,
  108986. 1,
  108987. 15,
  108988. 0,
  108989. 16,
  108990. };
  108991. static long _vq_lengthlist__16c0_s_p6_0[] = {
  108992. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  108993. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  108994. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  108995. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  108996. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  108997. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  108998. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  108999. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109000. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  109001. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109002. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  109003. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  109004. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  109005. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  109006. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  109007. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  109008. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  109009. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  109010. 14,
  109011. };
  109012. static float _vq_quantthresh__16c0_s_p6_0[] = {
  109013. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109014. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109015. };
  109016. static long _vq_quantmap__16c0_s_p6_0[] = {
  109017. 15, 13, 11, 9, 7, 5, 3, 1,
  109018. 0, 2, 4, 6, 8, 10, 12, 14,
  109019. 16,
  109020. };
  109021. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  109022. _vq_quantthresh__16c0_s_p6_0,
  109023. _vq_quantmap__16c0_s_p6_0,
  109024. 17,
  109025. 17
  109026. };
  109027. static static_codebook _16c0_s_p6_0 = {
  109028. 2, 289,
  109029. _vq_lengthlist__16c0_s_p6_0,
  109030. 1, -529530880, 1611661312, 5, 0,
  109031. _vq_quantlist__16c0_s_p6_0,
  109032. NULL,
  109033. &_vq_auxt__16c0_s_p6_0,
  109034. NULL,
  109035. 0
  109036. };
  109037. static long _vq_quantlist__16c0_s_p7_0[] = {
  109038. 1,
  109039. 0,
  109040. 2,
  109041. };
  109042. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109043. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109044. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109045. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109046. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109047. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109048. 13,
  109049. };
  109050. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109051. -5.5, 5.5,
  109052. };
  109053. static long _vq_quantmap__16c0_s_p7_0[] = {
  109054. 1, 0, 2,
  109055. };
  109056. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109057. _vq_quantthresh__16c0_s_p7_0,
  109058. _vq_quantmap__16c0_s_p7_0,
  109059. 3,
  109060. 3
  109061. };
  109062. static static_codebook _16c0_s_p7_0 = {
  109063. 4, 81,
  109064. _vq_lengthlist__16c0_s_p7_0,
  109065. 1, -529137664, 1618345984, 2, 0,
  109066. _vq_quantlist__16c0_s_p7_0,
  109067. NULL,
  109068. &_vq_auxt__16c0_s_p7_0,
  109069. NULL,
  109070. 0
  109071. };
  109072. static long _vq_quantlist__16c0_s_p7_1[] = {
  109073. 5,
  109074. 4,
  109075. 6,
  109076. 3,
  109077. 7,
  109078. 2,
  109079. 8,
  109080. 1,
  109081. 9,
  109082. 0,
  109083. 10,
  109084. };
  109085. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109086. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109087. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109088. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109089. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109090. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109091. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109092. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109093. 11,11,11, 9, 9, 9, 9,10,10,
  109094. };
  109095. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109096. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109097. 3.5, 4.5,
  109098. };
  109099. static long _vq_quantmap__16c0_s_p7_1[] = {
  109100. 9, 7, 5, 3, 1, 0, 2, 4,
  109101. 6, 8, 10,
  109102. };
  109103. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109104. _vq_quantthresh__16c0_s_p7_1,
  109105. _vq_quantmap__16c0_s_p7_1,
  109106. 11,
  109107. 11
  109108. };
  109109. static static_codebook _16c0_s_p7_1 = {
  109110. 2, 121,
  109111. _vq_lengthlist__16c0_s_p7_1,
  109112. 1, -531365888, 1611661312, 4, 0,
  109113. _vq_quantlist__16c0_s_p7_1,
  109114. NULL,
  109115. &_vq_auxt__16c0_s_p7_1,
  109116. NULL,
  109117. 0
  109118. };
  109119. static long _vq_quantlist__16c0_s_p8_0[] = {
  109120. 6,
  109121. 5,
  109122. 7,
  109123. 4,
  109124. 8,
  109125. 3,
  109126. 9,
  109127. 2,
  109128. 10,
  109129. 1,
  109130. 11,
  109131. 0,
  109132. 12,
  109133. };
  109134. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109135. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109136. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109137. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109138. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109139. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109140. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109141. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109142. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109143. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109144. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109145. 0,12,13,13,12,13,14,14,14,
  109146. };
  109147. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109148. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109149. 12.5, 17.5, 22.5, 27.5,
  109150. };
  109151. static long _vq_quantmap__16c0_s_p8_0[] = {
  109152. 11, 9, 7, 5, 3, 1, 0, 2,
  109153. 4, 6, 8, 10, 12,
  109154. };
  109155. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109156. _vq_quantthresh__16c0_s_p8_0,
  109157. _vq_quantmap__16c0_s_p8_0,
  109158. 13,
  109159. 13
  109160. };
  109161. static static_codebook _16c0_s_p8_0 = {
  109162. 2, 169,
  109163. _vq_lengthlist__16c0_s_p8_0,
  109164. 1, -526516224, 1616117760, 4, 0,
  109165. _vq_quantlist__16c0_s_p8_0,
  109166. NULL,
  109167. &_vq_auxt__16c0_s_p8_0,
  109168. NULL,
  109169. 0
  109170. };
  109171. static long _vq_quantlist__16c0_s_p8_1[] = {
  109172. 2,
  109173. 1,
  109174. 3,
  109175. 0,
  109176. 4,
  109177. };
  109178. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109179. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109180. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109181. };
  109182. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109183. -1.5, -0.5, 0.5, 1.5,
  109184. };
  109185. static long _vq_quantmap__16c0_s_p8_1[] = {
  109186. 3, 1, 0, 2, 4,
  109187. };
  109188. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109189. _vq_quantthresh__16c0_s_p8_1,
  109190. _vq_quantmap__16c0_s_p8_1,
  109191. 5,
  109192. 5
  109193. };
  109194. static static_codebook _16c0_s_p8_1 = {
  109195. 2, 25,
  109196. _vq_lengthlist__16c0_s_p8_1,
  109197. 1, -533725184, 1611661312, 3, 0,
  109198. _vq_quantlist__16c0_s_p8_1,
  109199. NULL,
  109200. &_vq_auxt__16c0_s_p8_1,
  109201. NULL,
  109202. 0
  109203. };
  109204. static long _vq_quantlist__16c0_s_p9_0[] = {
  109205. 1,
  109206. 0,
  109207. 2,
  109208. };
  109209. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109210. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109211. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109212. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109213. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109214. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109215. 7,
  109216. };
  109217. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109218. -157.5, 157.5,
  109219. };
  109220. static long _vq_quantmap__16c0_s_p9_0[] = {
  109221. 1, 0, 2,
  109222. };
  109223. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109224. _vq_quantthresh__16c0_s_p9_0,
  109225. _vq_quantmap__16c0_s_p9_0,
  109226. 3,
  109227. 3
  109228. };
  109229. static static_codebook _16c0_s_p9_0 = {
  109230. 4, 81,
  109231. _vq_lengthlist__16c0_s_p9_0,
  109232. 1, -518803456, 1628680192, 2, 0,
  109233. _vq_quantlist__16c0_s_p9_0,
  109234. NULL,
  109235. &_vq_auxt__16c0_s_p9_0,
  109236. NULL,
  109237. 0
  109238. };
  109239. static long _vq_quantlist__16c0_s_p9_1[] = {
  109240. 7,
  109241. 6,
  109242. 8,
  109243. 5,
  109244. 9,
  109245. 4,
  109246. 10,
  109247. 3,
  109248. 11,
  109249. 2,
  109250. 12,
  109251. 1,
  109252. 13,
  109253. 0,
  109254. 14,
  109255. };
  109256. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109257. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109258. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109259. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109260. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109261. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109262. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109263. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109264. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109265. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109266. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109267. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109268. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109269. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109270. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109271. 10,
  109272. };
  109273. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109274. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109275. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109276. };
  109277. static long _vq_quantmap__16c0_s_p9_1[] = {
  109278. 13, 11, 9, 7, 5, 3, 1, 0,
  109279. 2, 4, 6, 8, 10, 12, 14,
  109280. };
  109281. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109282. _vq_quantthresh__16c0_s_p9_1,
  109283. _vq_quantmap__16c0_s_p9_1,
  109284. 15,
  109285. 15
  109286. };
  109287. static static_codebook _16c0_s_p9_1 = {
  109288. 2, 225,
  109289. _vq_lengthlist__16c0_s_p9_1,
  109290. 1, -520986624, 1620377600, 4, 0,
  109291. _vq_quantlist__16c0_s_p9_1,
  109292. NULL,
  109293. &_vq_auxt__16c0_s_p9_1,
  109294. NULL,
  109295. 0
  109296. };
  109297. static long _vq_quantlist__16c0_s_p9_2[] = {
  109298. 10,
  109299. 9,
  109300. 11,
  109301. 8,
  109302. 12,
  109303. 7,
  109304. 13,
  109305. 6,
  109306. 14,
  109307. 5,
  109308. 15,
  109309. 4,
  109310. 16,
  109311. 3,
  109312. 17,
  109313. 2,
  109314. 18,
  109315. 1,
  109316. 19,
  109317. 0,
  109318. 20,
  109319. };
  109320. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109321. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109322. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109323. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109324. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109325. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109326. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109327. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109328. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109329. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109330. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109331. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109332. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109333. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109334. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109335. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109336. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109337. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109338. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109339. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109340. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109341. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109342. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109343. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109344. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109345. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109346. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109347. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109348. 10,11,10,10,11, 9,10,10,10,
  109349. };
  109350. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109351. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109352. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109353. 6.5, 7.5, 8.5, 9.5,
  109354. };
  109355. static long _vq_quantmap__16c0_s_p9_2[] = {
  109356. 19, 17, 15, 13, 11, 9, 7, 5,
  109357. 3, 1, 0, 2, 4, 6, 8, 10,
  109358. 12, 14, 16, 18, 20,
  109359. };
  109360. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109361. _vq_quantthresh__16c0_s_p9_2,
  109362. _vq_quantmap__16c0_s_p9_2,
  109363. 21,
  109364. 21
  109365. };
  109366. static static_codebook _16c0_s_p9_2 = {
  109367. 2, 441,
  109368. _vq_lengthlist__16c0_s_p9_2,
  109369. 1, -529268736, 1611661312, 5, 0,
  109370. _vq_quantlist__16c0_s_p9_2,
  109371. NULL,
  109372. &_vq_auxt__16c0_s_p9_2,
  109373. NULL,
  109374. 0
  109375. };
  109376. static long _huff_lengthlist__16c0_s_single[] = {
  109377. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109378. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109379. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109380. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109381. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109382. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109383. 16,16,18,18,
  109384. };
  109385. static static_codebook _huff_book__16c0_s_single = {
  109386. 2, 100,
  109387. _huff_lengthlist__16c0_s_single,
  109388. 0, 0, 0, 0, 0,
  109389. NULL,
  109390. NULL,
  109391. NULL,
  109392. NULL,
  109393. 0
  109394. };
  109395. static long _huff_lengthlist__16c1_s_long[] = {
  109396. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109397. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109398. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109399. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109400. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109401. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109402. 12,11,11,13,
  109403. };
  109404. static static_codebook _huff_book__16c1_s_long = {
  109405. 2, 100,
  109406. _huff_lengthlist__16c1_s_long,
  109407. 0, 0, 0, 0, 0,
  109408. NULL,
  109409. NULL,
  109410. NULL,
  109411. NULL,
  109412. 0
  109413. };
  109414. static long _vq_quantlist__16c1_s_p1_0[] = {
  109415. 1,
  109416. 0,
  109417. 2,
  109418. };
  109419. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109420. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109421. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109425. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109426. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109430. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109431. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109466. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109471. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109476. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109511. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109512. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109517. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109522. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109728. 0, 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,
  109831. };
  109832. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109833. -0.5, 0.5,
  109834. };
  109835. static long _vq_quantmap__16c1_s_p1_0[] = {
  109836. 1, 0, 2,
  109837. };
  109838. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109839. _vq_quantthresh__16c1_s_p1_0,
  109840. _vq_quantmap__16c1_s_p1_0,
  109841. 3,
  109842. 3
  109843. };
  109844. static static_codebook _16c1_s_p1_0 = {
  109845. 8, 6561,
  109846. _vq_lengthlist__16c1_s_p1_0,
  109847. 1, -535822336, 1611661312, 2, 0,
  109848. _vq_quantlist__16c1_s_p1_0,
  109849. NULL,
  109850. &_vq_auxt__16c1_s_p1_0,
  109851. NULL,
  109852. 0
  109853. };
  109854. static long _vq_quantlist__16c1_s_p2_0[] = {
  109855. 2,
  109856. 1,
  109857. 3,
  109858. 0,
  109859. 4,
  109860. };
  109861. static long _vq_lengthlist__16c1_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109901. 0,
  109902. };
  109903. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109904. -1.5, -0.5, 0.5, 1.5,
  109905. };
  109906. static long _vq_quantmap__16c1_s_p2_0[] = {
  109907. 3, 1, 0, 2, 4,
  109908. };
  109909. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109910. _vq_quantthresh__16c1_s_p2_0,
  109911. _vq_quantmap__16c1_s_p2_0,
  109912. 5,
  109913. 5
  109914. };
  109915. static static_codebook _16c1_s_p2_0 = {
  109916. 4, 625,
  109917. _vq_lengthlist__16c1_s_p2_0,
  109918. 1, -533725184, 1611661312, 3, 0,
  109919. _vq_quantlist__16c1_s_p2_0,
  109920. NULL,
  109921. &_vq_auxt__16c1_s_p2_0,
  109922. NULL,
  109923. 0
  109924. };
  109925. static long _vq_quantlist__16c1_s_p3_0[] = {
  109926. 2,
  109927. 1,
  109928. 3,
  109929. 0,
  109930. 4,
  109931. };
  109932. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109933. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109936. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  109938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109939. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109972. 0,
  109973. };
  109974. static float _vq_quantthresh__16c1_s_p3_0[] = {
  109975. -1.5, -0.5, 0.5, 1.5,
  109976. };
  109977. static long _vq_quantmap__16c1_s_p3_0[] = {
  109978. 3, 1, 0, 2, 4,
  109979. };
  109980. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  109981. _vq_quantthresh__16c1_s_p3_0,
  109982. _vq_quantmap__16c1_s_p3_0,
  109983. 5,
  109984. 5
  109985. };
  109986. static static_codebook _16c1_s_p3_0 = {
  109987. 4, 625,
  109988. _vq_lengthlist__16c1_s_p3_0,
  109989. 1, -533725184, 1611661312, 3, 0,
  109990. _vq_quantlist__16c1_s_p3_0,
  109991. NULL,
  109992. &_vq_auxt__16c1_s_p3_0,
  109993. NULL,
  109994. 0
  109995. };
  109996. static long _vq_quantlist__16c1_s_p4_0[] = {
  109997. 4,
  109998. 3,
  109999. 5,
  110000. 2,
  110001. 6,
  110002. 1,
  110003. 7,
  110004. 0,
  110005. 8,
  110006. };
  110007. static long _vq_lengthlist__16c1_s_p4_0[] = {
  110008. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  110009. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  110010. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  110011. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  110012. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110013. 0,
  110014. };
  110015. static float _vq_quantthresh__16c1_s_p4_0[] = {
  110016. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110017. };
  110018. static long _vq_quantmap__16c1_s_p4_0[] = {
  110019. 7, 5, 3, 1, 0, 2, 4, 6,
  110020. 8,
  110021. };
  110022. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  110023. _vq_quantthresh__16c1_s_p4_0,
  110024. _vq_quantmap__16c1_s_p4_0,
  110025. 9,
  110026. 9
  110027. };
  110028. static static_codebook _16c1_s_p4_0 = {
  110029. 2, 81,
  110030. _vq_lengthlist__16c1_s_p4_0,
  110031. 1, -531628032, 1611661312, 4, 0,
  110032. _vq_quantlist__16c1_s_p4_0,
  110033. NULL,
  110034. &_vq_auxt__16c1_s_p4_0,
  110035. NULL,
  110036. 0
  110037. };
  110038. static long _vq_quantlist__16c1_s_p5_0[] = {
  110039. 4,
  110040. 3,
  110041. 5,
  110042. 2,
  110043. 6,
  110044. 1,
  110045. 7,
  110046. 0,
  110047. 8,
  110048. };
  110049. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110050. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110051. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110052. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110053. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110054. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110055. 10,
  110056. };
  110057. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110058. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110059. };
  110060. static long _vq_quantmap__16c1_s_p5_0[] = {
  110061. 7, 5, 3, 1, 0, 2, 4, 6,
  110062. 8,
  110063. };
  110064. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110065. _vq_quantthresh__16c1_s_p5_0,
  110066. _vq_quantmap__16c1_s_p5_0,
  110067. 9,
  110068. 9
  110069. };
  110070. static static_codebook _16c1_s_p5_0 = {
  110071. 2, 81,
  110072. _vq_lengthlist__16c1_s_p5_0,
  110073. 1, -531628032, 1611661312, 4, 0,
  110074. _vq_quantlist__16c1_s_p5_0,
  110075. NULL,
  110076. &_vq_auxt__16c1_s_p5_0,
  110077. NULL,
  110078. 0
  110079. };
  110080. static long _vq_quantlist__16c1_s_p6_0[] = {
  110081. 8,
  110082. 7,
  110083. 9,
  110084. 6,
  110085. 10,
  110086. 5,
  110087. 11,
  110088. 4,
  110089. 12,
  110090. 3,
  110091. 13,
  110092. 2,
  110093. 14,
  110094. 1,
  110095. 15,
  110096. 0,
  110097. 16,
  110098. };
  110099. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110100. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110101. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110102. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110103. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110104. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110105. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110106. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110107. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110108. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110109. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110110. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110111. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110112. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110113. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110114. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110115. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110116. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110117. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110118. 14,
  110119. };
  110120. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110121. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110122. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110123. };
  110124. static long _vq_quantmap__16c1_s_p6_0[] = {
  110125. 15, 13, 11, 9, 7, 5, 3, 1,
  110126. 0, 2, 4, 6, 8, 10, 12, 14,
  110127. 16,
  110128. };
  110129. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110130. _vq_quantthresh__16c1_s_p6_0,
  110131. _vq_quantmap__16c1_s_p6_0,
  110132. 17,
  110133. 17
  110134. };
  110135. static static_codebook _16c1_s_p6_0 = {
  110136. 2, 289,
  110137. _vq_lengthlist__16c1_s_p6_0,
  110138. 1, -529530880, 1611661312, 5, 0,
  110139. _vq_quantlist__16c1_s_p6_0,
  110140. NULL,
  110141. &_vq_auxt__16c1_s_p6_0,
  110142. NULL,
  110143. 0
  110144. };
  110145. static long _vq_quantlist__16c1_s_p7_0[] = {
  110146. 1,
  110147. 0,
  110148. 2,
  110149. };
  110150. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110151. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110152. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110153. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110154. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110155. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110156. 11,
  110157. };
  110158. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110159. -5.5, 5.5,
  110160. };
  110161. static long _vq_quantmap__16c1_s_p7_0[] = {
  110162. 1, 0, 2,
  110163. };
  110164. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110165. _vq_quantthresh__16c1_s_p7_0,
  110166. _vq_quantmap__16c1_s_p7_0,
  110167. 3,
  110168. 3
  110169. };
  110170. static static_codebook _16c1_s_p7_0 = {
  110171. 4, 81,
  110172. _vq_lengthlist__16c1_s_p7_0,
  110173. 1, -529137664, 1618345984, 2, 0,
  110174. _vq_quantlist__16c1_s_p7_0,
  110175. NULL,
  110176. &_vq_auxt__16c1_s_p7_0,
  110177. NULL,
  110178. 0
  110179. };
  110180. static long _vq_quantlist__16c1_s_p7_1[] = {
  110181. 5,
  110182. 4,
  110183. 6,
  110184. 3,
  110185. 7,
  110186. 2,
  110187. 8,
  110188. 1,
  110189. 9,
  110190. 0,
  110191. 10,
  110192. };
  110193. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110194. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110195. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110196. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110197. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110198. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110199. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110200. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110201. 10,10,10, 8, 8, 8, 8, 9, 9,
  110202. };
  110203. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110204. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110205. 3.5, 4.5,
  110206. };
  110207. static long _vq_quantmap__16c1_s_p7_1[] = {
  110208. 9, 7, 5, 3, 1, 0, 2, 4,
  110209. 6, 8, 10,
  110210. };
  110211. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110212. _vq_quantthresh__16c1_s_p7_1,
  110213. _vq_quantmap__16c1_s_p7_1,
  110214. 11,
  110215. 11
  110216. };
  110217. static static_codebook _16c1_s_p7_1 = {
  110218. 2, 121,
  110219. _vq_lengthlist__16c1_s_p7_1,
  110220. 1, -531365888, 1611661312, 4, 0,
  110221. _vq_quantlist__16c1_s_p7_1,
  110222. NULL,
  110223. &_vq_auxt__16c1_s_p7_1,
  110224. NULL,
  110225. 0
  110226. };
  110227. static long _vq_quantlist__16c1_s_p8_0[] = {
  110228. 6,
  110229. 5,
  110230. 7,
  110231. 4,
  110232. 8,
  110233. 3,
  110234. 9,
  110235. 2,
  110236. 10,
  110237. 1,
  110238. 11,
  110239. 0,
  110240. 12,
  110241. };
  110242. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110243. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110244. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110245. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110246. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110247. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110248. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110249. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110250. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110251. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110252. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110253. 0,12,12,12,12,13,13,14,15,
  110254. };
  110255. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110256. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110257. 12.5, 17.5, 22.5, 27.5,
  110258. };
  110259. static long _vq_quantmap__16c1_s_p8_0[] = {
  110260. 11, 9, 7, 5, 3, 1, 0, 2,
  110261. 4, 6, 8, 10, 12,
  110262. };
  110263. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110264. _vq_quantthresh__16c1_s_p8_0,
  110265. _vq_quantmap__16c1_s_p8_0,
  110266. 13,
  110267. 13
  110268. };
  110269. static static_codebook _16c1_s_p8_0 = {
  110270. 2, 169,
  110271. _vq_lengthlist__16c1_s_p8_0,
  110272. 1, -526516224, 1616117760, 4, 0,
  110273. _vq_quantlist__16c1_s_p8_0,
  110274. NULL,
  110275. &_vq_auxt__16c1_s_p8_0,
  110276. NULL,
  110277. 0
  110278. };
  110279. static long _vq_quantlist__16c1_s_p8_1[] = {
  110280. 2,
  110281. 1,
  110282. 3,
  110283. 0,
  110284. 4,
  110285. };
  110286. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110287. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110288. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110289. };
  110290. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110291. -1.5, -0.5, 0.5, 1.5,
  110292. };
  110293. static long _vq_quantmap__16c1_s_p8_1[] = {
  110294. 3, 1, 0, 2, 4,
  110295. };
  110296. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110297. _vq_quantthresh__16c1_s_p8_1,
  110298. _vq_quantmap__16c1_s_p8_1,
  110299. 5,
  110300. 5
  110301. };
  110302. static static_codebook _16c1_s_p8_1 = {
  110303. 2, 25,
  110304. _vq_lengthlist__16c1_s_p8_1,
  110305. 1, -533725184, 1611661312, 3, 0,
  110306. _vq_quantlist__16c1_s_p8_1,
  110307. NULL,
  110308. &_vq_auxt__16c1_s_p8_1,
  110309. NULL,
  110310. 0
  110311. };
  110312. static long _vq_quantlist__16c1_s_p9_0[] = {
  110313. 6,
  110314. 5,
  110315. 7,
  110316. 4,
  110317. 8,
  110318. 3,
  110319. 9,
  110320. 2,
  110321. 10,
  110322. 1,
  110323. 11,
  110324. 0,
  110325. 12,
  110326. };
  110327. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110328. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110329. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110330. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110331. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110332. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110333. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110334. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110335. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110336. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110337. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110338. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110339. };
  110340. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110341. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110342. 787.5, 1102.5, 1417.5, 1732.5,
  110343. };
  110344. static long _vq_quantmap__16c1_s_p9_0[] = {
  110345. 11, 9, 7, 5, 3, 1, 0, 2,
  110346. 4, 6, 8, 10, 12,
  110347. };
  110348. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110349. _vq_quantthresh__16c1_s_p9_0,
  110350. _vq_quantmap__16c1_s_p9_0,
  110351. 13,
  110352. 13
  110353. };
  110354. static static_codebook _16c1_s_p9_0 = {
  110355. 2, 169,
  110356. _vq_lengthlist__16c1_s_p9_0,
  110357. 1, -513964032, 1628680192, 4, 0,
  110358. _vq_quantlist__16c1_s_p9_0,
  110359. NULL,
  110360. &_vq_auxt__16c1_s_p9_0,
  110361. NULL,
  110362. 0
  110363. };
  110364. static long _vq_quantlist__16c1_s_p9_1[] = {
  110365. 7,
  110366. 6,
  110367. 8,
  110368. 5,
  110369. 9,
  110370. 4,
  110371. 10,
  110372. 3,
  110373. 11,
  110374. 2,
  110375. 12,
  110376. 1,
  110377. 13,
  110378. 0,
  110379. 14,
  110380. };
  110381. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110382. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110383. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110384. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110385. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110386. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110387. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110388. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110389. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110390. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110391. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110392. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110393. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110394. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110395. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110396. 13,
  110397. };
  110398. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110399. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110400. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110401. };
  110402. static long _vq_quantmap__16c1_s_p9_1[] = {
  110403. 13, 11, 9, 7, 5, 3, 1, 0,
  110404. 2, 4, 6, 8, 10, 12, 14,
  110405. };
  110406. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110407. _vq_quantthresh__16c1_s_p9_1,
  110408. _vq_quantmap__16c1_s_p9_1,
  110409. 15,
  110410. 15
  110411. };
  110412. static static_codebook _16c1_s_p9_1 = {
  110413. 2, 225,
  110414. _vq_lengthlist__16c1_s_p9_1,
  110415. 1, -520986624, 1620377600, 4, 0,
  110416. _vq_quantlist__16c1_s_p9_1,
  110417. NULL,
  110418. &_vq_auxt__16c1_s_p9_1,
  110419. NULL,
  110420. 0
  110421. };
  110422. static long _vq_quantlist__16c1_s_p9_2[] = {
  110423. 10,
  110424. 9,
  110425. 11,
  110426. 8,
  110427. 12,
  110428. 7,
  110429. 13,
  110430. 6,
  110431. 14,
  110432. 5,
  110433. 15,
  110434. 4,
  110435. 16,
  110436. 3,
  110437. 17,
  110438. 2,
  110439. 18,
  110440. 1,
  110441. 19,
  110442. 0,
  110443. 20,
  110444. };
  110445. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110446. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110447. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110448. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110449. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110450. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110451. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110452. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110453. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110454. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110455. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110456. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110457. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110458. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110459. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110460. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110461. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110462. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110463. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110464. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110465. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110466. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110467. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110468. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110469. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110470. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110471. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110472. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110473. 11,11,11,11,12,11,11,12,11,
  110474. };
  110475. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110476. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110477. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110478. 6.5, 7.5, 8.5, 9.5,
  110479. };
  110480. static long _vq_quantmap__16c1_s_p9_2[] = {
  110481. 19, 17, 15, 13, 11, 9, 7, 5,
  110482. 3, 1, 0, 2, 4, 6, 8, 10,
  110483. 12, 14, 16, 18, 20,
  110484. };
  110485. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110486. _vq_quantthresh__16c1_s_p9_2,
  110487. _vq_quantmap__16c1_s_p9_2,
  110488. 21,
  110489. 21
  110490. };
  110491. static static_codebook _16c1_s_p9_2 = {
  110492. 2, 441,
  110493. _vq_lengthlist__16c1_s_p9_2,
  110494. 1, -529268736, 1611661312, 5, 0,
  110495. _vq_quantlist__16c1_s_p9_2,
  110496. NULL,
  110497. &_vq_auxt__16c1_s_p9_2,
  110498. NULL,
  110499. 0
  110500. };
  110501. static long _huff_lengthlist__16c1_s_short[] = {
  110502. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110503. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110504. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110505. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110506. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110507. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110508. 9, 9,10,13,
  110509. };
  110510. static static_codebook _huff_book__16c1_s_short = {
  110511. 2, 100,
  110512. _huff_lengthlist__16c1_s_short,
  110513. 0, 0, 0, 0, 0,
  110514. NULL,
  110515. NULL,
  110516. NULL,
  110517. NULL,
  110518. 0
  110519. };
  110520. static long _huff_lengthlist__16c2_s_long[] = {
  110521. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110522. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110523. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110524. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110525. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110526. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110527. 14,14,16,18,
  110528. };
  110529. static static_codebook _huff_book__16c2_s_long = {
  110530. 2, 100,
  110531. _huff_lengthlist__16c2_s_long,
  110532. 0, 0, 0, 0, 0,
  110533. NULL,
  110534. NULL,
  110535. NULL,
  110536. NULL,
  110537. 0
  110538. };
  110539. static long _vq_quantlist__16c2_s_p1_0[] = {
  110540. 1,
  110541. 0,
  110542. 2,
  110543. };
  110544. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110545. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110546. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110550. 0,
  110551. };
  110552. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110553. -0.5, 0.5,
  110554. };
  110555. static long _vq_quantmap__16c2_s_p1_0[] = {
  110556. 1, 0, 2,
  110557. };
  110558. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110559. _vq_quantthresh__16c2_s_p1_0,
  110560. _vq_quantmap__16c2_s_p1_0,
  110561. 3,
  110562. 3
  110563. };
  110564. static static_codebook _16c2_s_p1_0 = {
  110565. 4, 81,
  110566. _vq_lengthlist__16c2_s_p1_0,
  110567. 1, -535822336, 1611661312, 2, 0,
  110568. _vq_quantlist__16c2_s_p1_0,
  110569. NULL,
  110570. &_vq_auxt__16c2_s_p1_0,
  110571. NULL,
  110572. 0
  110573. };
  110574. static long _vq_quantlist__16c2_s_p2_0[] = {
  110575. 2,
  110576. 1,
  110577. 3,
  110578. 0,
  110579. 4,
  110580. };
  110581. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110582. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110583. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110584. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110585. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110586. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110587. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110588. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110589. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110594. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110595. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110596. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110597. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110602. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110603. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110604. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110605. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110610. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110611. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110612. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110613. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110618. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110619. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110620. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110621. 13,
  110622. };
  110623. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110624. -1.5, -0.5, 0.5, 1.5,
  110625. };
  110626. static long _vq_quantmap__16c2_s_p2_0[] = {
  110627. 3, 1, 0, 2, 4,
  110628. };
  110629. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110630. _vq_quantthresh__16c2_s_p2_0,
  110631. _vq_quantmap__16c2_s_p2_0,
  110632. 5,
  110633. 5
  110634. };
  110635. static static_codebook _16c2_s_p2_0 = {
  110636. 4, 625,
  110637. _vq_lengthlist__16c2_s_p2_0,
  110638. 1, -533725184, 1611661312, 3, 0,
  110639. _vq_quantlist__16c2_s_p2_0,
  110640. NULL,
  110641. &_vq_auxt__16c2_s_p2_0,
  110642. NULL,
  110643. 0
  110644. };
  110645. static long _vq_quantlist__16c2_s_p3_0[] = {
  110646. 4,
  110647. 3,
  110648. 5,
  110649. 2,
  110650. 6,
  110651. 1,
  110652. 7,
  110653. 0,
  110654. 8,
  110655. };
  110656. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110657. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110658. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110659. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110660. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110662. 0,
  110663. };
  110664. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110665. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110666. };
  110667. static long _vq_quantmap__16c2_s_p3_0[] = {
  110668. 7, 5, 3, 1, 0, 2, 4, 6,
  110669. 8,
  110670. };
  110671. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110672. _vq_quantthresh__16c2_s_p3_0,
  110673. _vq_quantmap__16c2_s_p3_0,
  110674. 9,
  110675. 9
  110676. };
  110677. static static_codebook _16c2_s_p3_0 = {
  110678. 2, 81,
  110679. _vq_lengthlist__16c2_s_p3_0,
  110680. 1, -531628032, 1611661312, 4, 0,
  110681. _vq_quantlist__16c2_s_p3_0,
  110682. NULL,
  110683. &_vq_auxt__16c2_s_p3_0,
  110684. NULL,
  110685. 0
  110686. };
  110687. static long _vq_quantlist__16c2_s_p4_0[] = {
  110688. 8,
  110689. 7,
  110690. 9,
  110691. 6,
  110692. 10,
  110693. 5,
  110694. 11,
  110695. 4,
  110696. 12,
  110697. 3,
  110698. 13,
  110699. 2,
  110700. 14,
  110701. 1,
  110702. 15,
  110703. 0,
  110704. 16,
  110705. };
  110706. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110707. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110708. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110709. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110710. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110711. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110712. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110713. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110714. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110715. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110716. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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_p4_0[] = {
  110728. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110729. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110730. };
  110731. static long _vq_quantmap__16c2_s_p4_0[] = {
  110732. 15, 13, 11, 9, 7, 5, 3, 1,
  110733. 0, 2, 4, 6, 8, 10, 12, 14,
  110734. 16,
  110735. };
  110736. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110737. _vq_quantthresh__16c2_s_p4_0,
  110738. _vq_quantmap__16c2_s_p4_0,
  110739. 17,
  110740. 17
  110741. };
  110742. static static_codebook _16c2_s_p4_0 = {
  110743. 2, 289,
  110744. _vq_lengthlist__16c2_s_p4_0,
  110745. 1, -529530880, 1611661312, 5, 0,
  110746. _vq_quantlist__16c2_s_p4_0,
  110747. NULL,
  110748. &_vq_auxt__16c2_s_p4_0,
  110749. NULL,
  110750. 0
  110751. };
  110752. static long _vq_quantlist__16c2_s_p5_0[] = {
  110753. 1,
  110754. 0,
  110755. 2,
  110756. };
  110757. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110758. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110759. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110760. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110761. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110762. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110763. 12,
  110764. };
  110765. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110766. -5.5, 5.5,
  110767. };
  110768. static long _vq_quantmap__16c2_s_p5_0[] = {
  110769. 1, 0, 2,
  110770. };
  110771. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110772. _vq_quantthresh__16c2_s_p5_0,
  110773. _vq_quantmap__16c2_s_p5_0,
  110774. 3,
  110775. 3
  110776. };
  110777. static static_codebook _16c2_s_p5_0 = {
  110778. 4, 81,
  110779. _vq_lengthlist__16c2_s_p5_0,
  110780. 1, -529137664, 1618345984, 2, 0,
  110781. _vq_quantlist__16c2_s_p5_0,
  110782. NULL,
  110783. &_vq_auxt__16c2_s_p5_0,
  110784. NULL,
  110785. 0
  110786. };
  110787. static long _vq_quantlist__16c2_s_p5_1[] = {
  110788. 5,
  110789. 4,
  110790. 6,
  110791. 3,
  110792. 7,
  110793. 2,
  110794. 8,
  110795. 1,
  110796. 9,
  110797. 0,
  110798. 10,
  110799. };
  110800. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110801. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110802. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110803. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110804. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110805. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110806. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110807. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110808. 11,11,11, 7, 7, 8, 8, 8, 8,
  110809. };
  110810. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110811. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110812. 3.5, 4.5,
  110813. };
  110814. static long _vq_quantmap__16c2_s_p5_1[] = {
  110815. 9, 7, 5, 3, 1, 0, 2, 4,
  110816. 6, 8, 10,
  110817. };
  110818. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110819. _vq_quantthresh__16c2_s_p5_1,
  110820. _vq_quantmap__16c2_s_p5_1,
  110821. 11,
  110822. 11
  110823. };
  110824. static static_codebook _16c2_s_p5_1 = {
  110825. 2, 121,
  110826. _vq_lengthlist__16c2_s_p5_1,
  110827. 1, -531365888, 1611661312, 4, 0,
  110828. _vq_quantlist__16c2_s_p5_1,
  110829. NULL,
  110830. &_vq_auxt__16c2_s_p5_1,
  110831. NULL,
  110832. 0
  110833. };
  110834. static long _vq_quantlist__16c2_s_p6_0[] = {
  110835. 6,
  110836. 5,
  110837. 7,
  110838. 4,
  110839. 8,
  110840. 3,
  110841. 9,
  110842. 2,
  110843. 10,
  110844. 1,
  110845. 11,
  110846. 0,
  110847. 12,
  110848. };
  110849. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110850. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110851. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110852. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110853. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110854. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110855. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110860. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110861. };
  110862. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110863. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110864. 12.5, 17.5, 22.5, 27.5,
  110865. };
  110866. static long _vq_quantmap__16c2_s_p6_0[] = {
  110867. 11, 9, 7, 5, 3, 1, 0, 2,
  110868. 4, 6, 8, 10, 12,
  110869. };
  110870. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110871. _vq_quantthresh__16c2_s_p6_0,
  110872. _vq_quantmap__16c2_s_p6_0,
  110873. 13,
  110874. 13
  110875. };
  110876. static static_codebook _16c2_s_p6_0 = {
  110877. 2, 169,
  110878. _vq_lengthlist__16c2_s_p6_0,
  110879. 1, -526516224, 1616117760, 4, 0,
  110880. _vq_quantlist__16c2_s_p6_0,
  110881. NULL,
  110882. &_vq_auxt__16c2_s_p6_0,
  110883. NULL,
  110884. 0
  110885. };
  110886. static long _vq_quantlist__16c2_s_p6_1[] = {
  110887. 2,
  110888. 1,
  110889. 3,
  110890. 0,
  110891. 4,
  110892. };
  110893. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110894. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110895. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110896. };
  110897. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110898. -1.5, -0.5, 0.5, 1.5,
  110899. };
  110900. static long _vq_quantmap__16c2_s_p6_1[] = {
  110901. 3, 1, 0, 2, 4,
  110902. };
  110903. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110904. _vq_quantthresh__16c2_s_p6_1,
  110905. _vq_quantmap__16c2_s_p6_1,
  110906. 5,
  110907. 5
  110908. };
  110909. static static_codebook _16c2_s_p6_1 = {
  110910. 2, 25,
  110911. _vq_lengthlist__16c2_s_p6_1,
  110912. 1, -533725184, 1611661312, 3, 0,
  110913. _vq_quantlist__16c2_s_p6_1,
  110914. NULL,
  110915. &_vq_auxt__16c2_s_p6_1,
  110916. NULL,
  110917. 0
  110918. };
  110919. static long _vq_quantlist__16c2_s_p7_0[] = {
  110920. 6,
  110921. 5,
  110922. 7,
  110923. 4,
  110924. 8,
  110925. 3,
  110926. 9,
  110927. 2,
  110928. 10,
  110929. 1,
  110930. 11,
  110931. 0,
  110932. 12,
  110933. };
  110934. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110935. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110936. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  110937. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  110938. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  110939. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  110940. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  110941. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  110942. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  110943. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  110944. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  110945. 18,13,14,13,13,14,13,15,14,
  110946. };
  110947. static float _vq_quantthresh__16c2_s_p7_0[] = {
  110948. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  110949. 27.5, 38.5, 49.5, 60.5,
  110950. };
  110951. static long _vq_quantmap__16c2_s_p7_0[] = {
  110952. 11, 9, 7, 5, 3, 1, 0, 2,
  110953. 4, 6, 8, 10, 12,
  110954. };
  110955. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  110956. _vq_quantthresh__16c2_s_p7_0,
  110957. _vq_quantmap__16c2_s_p7_0,
  110958. 13,
  110959. 13
  110960. };
  110961. static static_codebook _16c2_s_p7_0 = {
  110962. 2, 169,
  110963. _vq_lengthlist__16c2_s_p7_0,
  110964. 1, -523206656, 1618345984, 4, 0,
  110965. _vq_quantlist__16c2_s_p7_0,
  110966. NULL,
  110967. &_vq_auxt__16c2_s_p7_0,
  110968. NULL,
  110969. 0
  110970. };
  110971. static long _vq_quantlist__16c2_s_p7_1[] = {
  110972. 5,
  110973. 4,
  110974. 6,
  110975. 3,
  110976. 7,
  110977. 2,
  110978. 8,
  110979. 1,
  110980. 9,
  110981. 0,
  110982. 10,
  110983. };
  110984. static long _vq_lengthlist__16c2_s_p7_1[] = {
  110985. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  110986. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  110987. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  110988. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110989. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  110990. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  110991. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  110992. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110993. };
  110994. static float _vq_quantthresh__16c2_s_p7_1[] = {
  110995. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110996. 3.5, 4.5,
  110997. };
  110998. static long _vq_quantmap__16c2_s_p7_1[] = {
  110999. 9, 7, 5, 3, 1, 0, 2, 4,
  111000. 6, 8, 10,
  111001. };
  111002. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  111003. _vq_quantthresh__16c2_s_p7_1,
  111004. _vq_quantmap__16c2_s_p7_1,
  111005. 11,
  111006. 11
  111007. };
  111008. static static_codebook _16c2_s_p7_1 = {
  111009. 2, 121,
  111010. _vq_lengthlist__16c2_s_p7_1,
  111011. 1, -531365888, 1611661312, 4, 0,
  111012. _vq_quantlist__16c2_s_p7_1,
  111013. NULL,
  111014. &_vq_auxt__16c2_s_p7_1,
  111015. NULL,
  111016. 0
  111017. };
  111018. static long _vq_quantlist__16c2_s_p8_0[] = {
  111019. 7,
  111020. 6,
  111021. 8,
  111022. 5,
  111023. 9,
  111024. 4,
  111025. 10,
  111026. 3,
  111027. 11,
  111028. 2,
  111029. 12,
  111030. 1,
  111031. 13,
  111032. 0,
  111033. 14,
  111034. };
  111035. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111036. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111037. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111038. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111039. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111040. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111041. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111042. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111043. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111044. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111045. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111046. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111047. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111048. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111049. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111050. 13,
  111051. };
  111052. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111053. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111054. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111055. };
  111056. static long _vq_quantmap__16c2_s_p8_0[] = {
  111057. 13, 11, 9, 7, 5, 3, 1, 0,
  111058. 2, 4, 6, 8, 10, 12, 14,
  111059. };
  111060. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111061. _vq_quantthresh__16c2_s_p8_0,
  111062. _vq_quantmap__16c2_s_p8_0,
  111063. 15,
  111064. 15
  111065. };
  111066. static static_codebook _16c2_s_p8_0 = {
  111067. 2, 225,
  111068. _vq_lengthlist__16c2_s_p8_0,
  111069. 1, -520986624, 1620377600, 4, 0,
  111070. _vq_quantlist__16c2_s_p8_0,
  111071. NULL,
  111072. &_vq_auxt__16c2_s_p8_0,
  111073. NULL,
  111074. 0
  111075. };
  111076. static long _vq_quantlist__16c2_s_p8_1[] = {
  111077. 10,
  111078. 9,
  111079. 11,
  111080. 8,
  111081. 12,
  111082. 7,
  111083. 13,
  111084. 6,
  111085. 14,
  111086. 5,
  111087. 15,
  111088. 4,
  111089. 16,
  111090. 3,
  111091. 17,
  111092. 2,
  111093. 18,
  111094. 1,
  111095. 19,
  111096. 0,
  111097. 20,
  111098. };
  111099. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111100. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111101. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111102. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111103. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111104. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111105. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111106. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111107. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111108. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111109. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111110. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111111. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111112. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111113. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111114. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111115. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111116. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111117. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111118. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111119. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111120. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111121. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111122. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111123. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111124. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111125. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111126. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111127. 10,11,10,10,10,10,10,10,10,
  111128. };
  111129. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111130. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111131. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111132. 6.5, 7.5, 8.5, 9.5,
  111133. };
  111134. static long _vq_quantmap__16c2_s_p8_1[] = {
  111135. 19, 17, 15, 13, 11, 9, 7, 5,
  111136. 3, 1, 0, 2, 4, 6, 8, 10,
  111137. 12, 14, 16, 18, 20,
  111138. };
  111139. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111140. _vq_quantthresh__16c2_s_p8_1,
  111141. _vq_quantmap__16c2_s_p8_1,
  111142. 21,
  111143. 21
  111144. };
  111145. static static_codebook _16c2_s_p8_1 = {
  111146. 2, 441,
  111147. _vq_lengthlist__16c2_s_p8_1,
  111148. 1, -529268736, 1611661312, 5, 0,
  111149. _vq_quantlist__16c2_s_p8_1,
  111150. NULL,
  111151. &_vq_auxt__16c2_s_p8_1,
  111152. NULL,
  111153. 0
  111154. };
  111155. static long _vq_quantlist__16c2_s_p9_0[] = {
  111156. 6,
  111157. 5,
  111158. 7,
  111159. 4,
  111160. 8,
  111161. 3,
  111162. 9,
  111163. 2,
  111164. 10,
  111165. 1,
  111166. 11,
  111167. 0,
  111168. 12,
  111169. };
  111170. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111171. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111172. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111173. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111174. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111175. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111176. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111177. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111178. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111179. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111180. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111181. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111182. };
  111183. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111184. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111185. 2327.5, 3258.5, 4189.5, 5120.5,
  111186. };
  111187. static long _vq_quantmap__16c2_s_p9_0[] = {
  111188. 11, 9, 7, 5, 3, 1, 0, 2,
  111189. 4, 6, 8, 10, 12,
  111190. };
  111191. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111192. _vq_quantthresh__16c2_s_p9_0,
  111193. _vq_quantmap__16c2_s_p9_0,
  111194. 13,
  111195. 13
  111196. };
  111197. static static_codebook _16c2_s_p9_0 = {
  111198. 2, 169,
  111199. _vq_lengthlist__16c2_s_p9_0,
  111200. 1, -510275072, 1631393792, 4, 0,
  111201. _vq_quantlist__16c2_s_p9_0,
  111202. NULL,
  111203. &_vq_auxt__16c2_s_p9_0,
  111204. NULL,
  111205. 0
  111206. };
  111207. static long _vq_quantlist__16c2_s_p9_1[] = {
  111208. 8,
  111209. 7,
  111210. 9,
  111211. 6,
  111212. 10,
  111213. 5,
  111214. 11,
  111215. 4,
  111216. 12,
  111217. 3,
  111218. 13,
  111219. 2,
  111220. 14,
  111221. 1,
  111222. 15,
  111223. 0,
  111224. 16,
  111225. };
  111226. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111227. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111228. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111229. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111230. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111231. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111232. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111233. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111234. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111235. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111236. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111237. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111238. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111239. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111240. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111241. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111242. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111243. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111244. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111245. 10,
  111246. };
  111247. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111248. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111249. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111250. };
  111251. static long _vq_quantmap__16c2_s_p9_1[] = {
  111252. 15, 13, 11, 9, 7, 5, 3, 1,
  111253. 0, 2, 4, 6, 8, 10, 12, 14,
  111254. 16,
  111255. };
  111256. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111257. _vq_quantthresh__16c2_s_p9_1,
  111258. _vq_quantmap__16c2_s_p9_1,
  111259. 17,
  111260. 17
  111261. };
  111262. static static_codebook _16c2_s_p9_1 = {
  111263. 2, 289,
  111264. _vq_lengthlist__16c2_s_p9_1,
  111265. 1, -518488064, 1622704128, 5, 0,
  111266. _vq_quantlist__16c2_s_p9_1,
  111267. NULL,
  111268. &_vq_auxt__16c2_s_p9_1,
  111269. NULL,
  111270. 0
  111271. };
  111272. static long _vq_quantlist__16c2_s_p9_2[] = {
  111273. 13,
  111274. 12,
  111275. 14,
  111276. 11,
  111277. 15,
  111278. 10,
  111279. 16,
  111280. 9,
  111281. 17,
  111282. 8,
  111283. 18,
  111284. 7,
  111285. 19,
  111286. 6,
  111287. 20,
  111288. 5,
  111289. 21,
  111290. 4,
  111291. 22,
  111292. 3,
  111293. 23,
  111294. 2,
  111295. 24,
  111296. 1,
  111297. 25,
  111298. 0,
  111299. 26,
  111300. };
  111301. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111302. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111303. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111304. };
  111305. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111306. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111307. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111308. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111309. 11.5, 12.5,
  111310. };
  111311. static long _vq_quantmap__16c2_s_p9_2[] = {
  111312. 25, 23, 21, 19, 17, 15, 13, 11,
  111313. 9, 7, 5, 3, 1, 0, 2, 4,
  111314. 6, 8, 10, 12, 14, 16, 18, 20,
  111315. 22, 24, 26,
  111316. };
  111317. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111318. _vq_quantthresh__16c2_s_p9_2,
  111319. _vq_quantmap__16c2_s_p9_2,
  111320. 27,
  111321. 27
  111322. };
  111323. static static_codebook _16c2_s_p9_2 = {
  111324. 1, 27,
  111325. _vq_lengthlist__16c2_s_p9_2,
  111326. 1, -528875520, 1611661312, 5, 0,
  111327. _vq_quantlist__16c2_s_p9_2,
  111328. NULL,
  111329. &_vq_auxt__16c2_s_p9_2,
  111330. NULL,
  111331. 0
  111332. };
  111333. static long _huff_lengthlist__16c2_s_short[] = {
  111334. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111335. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111336. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111337. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111338. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111339. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111340. 15,12,14,14,
  111341. };
  111342. static static_codebook _huff_book__16c2_s_short = {
  111343. 2, 100,
  111344. _huff_lengthlist__16c2_s_short,
  111345. 0, 0, 0, 0, 0,
  111346. NULL,
  111347. NULL,
  111348. NULL,
  111349. NULL,
  111350. 0
  111351. };
  111352. static long _vq_quantlist__8c0_s_p1_0[] = {
  111353. 1,
  111354. 0,
  111355. 2,
  111356. };
  111357. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111358. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111359. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111363. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111364. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111368. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111369. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111404. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  111409. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9,10, 0, 0,
  111414. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111449. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111450. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111455. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111460. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111666. 0, 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,
  111769. };
  111770. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111771. -0.5, 0.5,
  111772. };
  111773. static long _vq_quantmap__8c0_s_p1_0[] = {
  111774. 1, 0, 2,
  111775. };
  111776. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111777. _vq_quantthresh__8c0_s_p1_0,
  111778. _vq_quantmap__8c0_s_p1_0,
  111779. 3,
  111780. 3
  111781. };
  111782. static static_codebook _8c0_s_p1_0 = {
  111783. 8, 6561,
  111784. _vq_lengthlist__8c0_s_p1_0,
  111785. 1, -535822336, 1611661312, 2, 0,
  111786. _vq_quantlist__8c0_s_p1_0,
  111787. NULL,
  111788. &_vq_auxt__8c0_s_p1_0,
  111789. NULL,
  111790. 0
  111791. };
  111792. static long _vq_quantlist__8c0_s_p2_0[] = {
  111793. 2,
  111794. 1,
  111795. 3,
  111796. 0,
  111797. 4,
  111798. };
  111799. static long _vq_lengthlist__8c0_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111839. 0,
  111840. };
  111841. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111842. -1.5, -0.5, 0.5, 1.5,
  111843. };
  111844. static long _vq_quantmap__8c0_s_p2_0[] = {
  111845. 3, 1, 0, 2, 4,
  111846. };
  111847. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111848. _vq_quantthresh__8c0_s_p2_0,
  111849. _vq_quantmap__8c0_s_p2_0,
  111850. 5,
  111851. 5
  111852. };
  111853. static static_codebook _8c0_s_p2_0 = {
  111854. 4, 625,
  111855. _vq_lengthlist__8c0_s_p2_0,
  111856. 1, -533725184, 1611661312, 3, 0,
  111857. _vq_quantlist__8c0_s_p2_0,
  111858. NULL,
  111859. &_vq_auxt__8c0_s_p2_0,
  111860. NULL,
  111861. 0
  111862. };
  111863. static long _vq_quantlist__8c0_s_p3_0[] = {
  111864. 2,
  111865. 1,
  111866. 3,
  111867. 0,
  111868. 4,
  111869. };
  111870. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111871. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111874. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111877. 0, 0, 0, 0, 6, 7, 7, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111910. 0,
  111911. };
  111912. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111913. -1.5, -0.5, 0.5, 1.5,
  111914. };
  111915. static long _vq_quantmap__8c0_s_p3_0[] = {
  111916. 3, 1, 0, 2, 4,
  111917. };
  111918. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111919. _vq_quantthresh__8c0_s_p3_0,
  111920. _vq_quantmap__8c0_s_p3_0,
  111921. 5,
  111922. 5
  111923. };
  111924. static static_codebook _8c0_s_p3_0 = {
  111925. 4, 625,
  111926. _vq_lengthlist__8c0_s_p3_0,
  111927. 1, -533725184, 1611661312, 3, 0,
  111928. _vq_quantlist__8c0_s_p3_0,
  111929. NULL,
  111930. &_vq_auxt__8c0_s_p3_0,
  111931. NULL,
  111932. 0
  111933. };
  111934. static long _vq_quantlist__8c0_s_p4_0[] = {
  111935. 4,
  111936. 3,
  111937. 5,
  111938. 2,
  111939. 6,
  111940. 1,
  111941. 7,
  111942. 0,
  111943. 8,
  111944. };
  111945. static long _vq_lengthlist__8c0_s_p4_0[] = {
  111946. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  111947. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  111948. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  111949. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  111950. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111951. 0,
  111952. };
  111953. static float _vq_quantthresh__8c0_s_p4_0[] = {
  111954. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111955. };
  111956. static long _vq_quantmap__8c0_s_p4_0[] = {
  111957. 7, 5, 3, 1, 0, 2, 4, 6,
  111958. 8,
  111959. };
  111960. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  111961. _vq_quantthresh__8c0_s_p4_0,
  111962. _vq_quantmap__8c0_s_p4_0,
  111963. 9,
  111964. 9
  111965. };
  111966. static static_codebook _8c0_s_p4_0 = {
  111967. 2, 81,
  111968. _vq_lengthlist__8c0_s_p4_0,
  111969. 1, -531628032, 1611661312, 4, 0,
  111970. _vq_quantlist__8c0_s_p4_0,
  111971. NULL,
  111972. &_vq_auxt__8c0_s_p4_0,
  111973. NULL,
  111974. 0
  111975. };
  111976. static long _vq_quantlist__8c0_s_p5_0[] = {
  111977. 4,
  111978. 3,
  111979. 5,
  111980. 2,
  111981. 6,
  111982. 1,
  111983. 7,
  111984. 0,
  111985. 8,
  111986. };
  111987. static long _vq_lengthlist__8c0_s_p5_0[] = {
  111988. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  111989. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  111990. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  111991. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  111992. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  111993. 10,
  111994. };
  111995. static float _vq_quantthresh__8c0_s_p5_0[] = {
  111996. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111997. };
  111998. static long _vq_quantmap__8c0_s_p5_0[] = {
  111999. 7, 5, 3, 1, 0, 2, 4, 6,
  112000. 8,
  112001. };
  112002. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  112003. _vq_quantthresh__8c0_s_p5_0,
  112004. _vq_quantmap__8c0_s_p5_0,
  112005. 9,
  112006. 9
  112007. };
  112008. static static_codebook _8c0_s_p5_0 = {
  112009. 2, 81,
  112010. _vq_lengthlist__8c0_s_p5_0,
  112011. 1, -531628032, 1611661312, 4, 0,
  112012. _vq_quantlist__8c0_s_p5_0,
  112013. NULL,
  112014. &_vq_auxt__8c0_s_p5_0,
  112015. NULL,
  112016. 0
  112017. };
  112018. static long _vq_quantlist__8c0_s_p6_0[] = {
  112019. 8,
  112020. 7,
  112021. 9,
  112022. 6,
  112023. 10,
  112024. 5,
  112025. 11,
  112026. 4,
  112027. 12,
  112028. 3,
  112029. 13,
  112030. 2,
  112031. 14,
  112032. 1,
  112033. 15,
  112034. 0,
  112035. 16,
  112036. };
  112037. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112038. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112039. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112040. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112041. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112042. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112043. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112044. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112045. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112046. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112047. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112048. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112049. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112050. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112051. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112052. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112053. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112054. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112055. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112056. 14,
  112057. };
  112058. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112059. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112060. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112061. };
  112062. static long _vq_quantmap__8c0_s_p6_0[] = {
  112063. 15, 13, 11, 9, 7, 5, 3, 1,
  112064. 0, 2, 4, 6, 8, 10, 12, 14,
  112065. 16,
  112066. };
  112067. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112068. _vq_quantthresh__8c0_s_p6_0,
  112069. _vq_quantmap__8c0_s_p6_0,
  112070. 17,
  112071. 17
  112072. };
  112073. static static_codebook _8c0_s_p6_0 = {
  112074. 2, 289,
  112075. _vq_lengthlist__8c0_s_p6_0,
  112076. 1, -529530880, 1611661312, 5, 0,
  112077. _vq_quantlist__8c0_s_p6_0,
  112078. NULL,
  112079. &_vq_auxt__8c0_s_p6_0,
  112080. NULL,
  112081. 0
  112082. };
  112083. static long _vq_quantlist__8c0_s_p7_0[] = {
  112084. 1,
  112085. 0,
  112086. 2,
  112087. };
  112088. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112089. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112090. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112091. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112092. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112093. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112094. 10,
  112095. };
  112096. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112097. -5.5, 5.5,
  112098. };
  112099. static long _vq_quantmap__8c0_s_p7_0[] = {
  112100. 1, 0, 2,
  112101. };
  112102. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112103. _vq_quantthresh__8c0_s_p7_0,
  112104. _vq_quantmap__8c0_s_p7_0,
  112105. 3,
  112106. 3
  112107. };
  112108. static static_codebook _8c0_s_p7_0 = {
  112109. 4, 81,
  112110. _vq_lengthlist__8c0_s_p7_0,
  112111. 1, -529137664, 1618345984, 2, 0,
  112112. _vq_quantlist__8c0_s_p7_0,
  112113. NULL,
  112114. &_vq_auxt__8c0_s_p7_0,
  112115. NULL,
  112116. 0
  112117. };
  112118. static long _vq_quantlist__8c0_s_p7_1[] = {
  112119. 5,
  112120. 4,
  112121. 6,
  112122. 3,
  112123. 7,
  112124. 2,
  112125. 8,
  112126. 1,
  112127. 9,
  112128. 0,
  112129. 10,
  112130. };
  112131. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112132. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112133. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112134. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112135. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112136. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112137. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112138. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112139. 10,10,10, 9, 9, 9,10,10,10,
  112140. };
  112141. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112142. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112143. 3.5, 4.5,
  112144. };
  112145. static long _vq_quantmap__8c0_s_p7_1[] = {
  112146. 9, 7, 5, 3, 1, 0, 2, 4,
  112147. 6, 8, 10,
  112148. };
  112149. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112150. _vq_quantthresh__8c0_s_p7_1,
  112151. _vq_quantmap__8c0_s_p7_1,
  112152. 11,
  112153. 11
  112154. };
  112155. static static_codebook _8c0_s_p7_1 = {
  112156. 2, 121,
  112157. _vq_lengthlist__8c0_s_p7_1,
  112158. 1, -531365888, 1611661312, 4, 0,
  112159. _vq_quantlist__8c0_s_p7_1,
  112160. NULL,
  112161. &_vq_auxt__8c0_s_p7_1,
  112162. NULL,
  112163. 0
  112164. };
  112165. static long _vq_quantlist__8c0_s_p8_0[] = {
  112166. 6,
  112167. 5,
  112168. 7,
  112169. 4,
  112170. 8,
  112171. 3,
  112172. 9,
  112173. 2,
  112174. 10,
  112175. 1,
  112176. 11,
  112177. 0,
  112178. 12,
  112179. };
  112180. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112181. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112182. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112183. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112184. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112185. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112186. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112187. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112188. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112189. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112190. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112191. 0, 0,13,13,11,13,13,11,12,
  112192. };
  112193. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112194. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112195. 12.5, 17.5, 22.5, 27.5,
  112196. };
  112197. static long _vq_quantmap__8c0_s_p8_0[] = {
  112198. 11, 9, 7, 5, 3, 1, 0, 2,
  112199. 4, 6, 8, 10, 12,
  112200. };
  112201. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112202. _vq_quantthresh__8c0_s_p8_0,
  112203. _vq_quantmap__8c0_s_p8_0,
  112204. 13,
  112205. 13
  112206. };
  112207. static static_codebook _8c0_s_p8_0 = {
  112208. 2, 169,
  112209. _vq_lengthlist__8c0_s_p8_0,
  112210. 1, -526516224, 1616117760, 4, 0,
  112211. _vq_quantlist__8c0_s_p8_0,
  112212. NULL,
  112213. &_vq_auxt__8c0_s_p8_0,
  112214. NULL,
  112215. 0
  112216. };
  112217. static long _vq_quantlist__8c0_s_p8_1[] = {
  112218. 2,
  112219. 1,
  112220. 3,
  112221. 0,
  112222. 4,
  112223. };
  112224. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112225. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112226. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112227. };
  112228. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112229. -1.5, -0.5, 0.5, 1.5,
  112230. };
  112231. static long _vq_quantmap__8c0_s_p8_1[] = {
  112232. 3, 1, 0, 2, 4,
  112233. };
  112234. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112235. _vq_quantthresh__8c0_s_p8_1,
  112236. _vq_quantmap__8c0_s_p8_1,
  112237. 5,
  112238. 5
  112239. };
  112240. static static_codebook _8c0_s_p8_1 = {
  112241. 2, 25,
  112242. _vq_lengthlist__8c0_s_p8_1,
  112243. 1, -533725184, 1611661312, 3, 0,
  112244. _vq_quantlist__8c0_s_p8_1,
  112245. NULL,
  112246. &_vq_auxt__8c0_s_p8_1,
  112247. NULL,
  112248. 0
  112249. };
  112250. static long _vq_quantlist__8c0_s_p9_0[] = {
  112251. 1,
  112252. 0,
  112253. 2,
  112254. };
  112255. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112256. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112257. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112258. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112259. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112260. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112261. 7,
  112262. };
  112263. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112264. -157.5, 157.5,
  112265. };
  112266. static long _vq_quantmap__8c0_s_p9_0[] = {
  112267. 1, 0, 2,
  112268. };
  112269. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112270. _vq_quantthresh__8c0_s_p9_0,
  112271. _vq_quantmap__8c0_s_p9_0,
  112272. 3,
  112273. 3
  112274. };
  112275. static static_codebook _8c0_s_p9_0 = {
  112276. 4, 81,
  112277. _vq_lengthlist__8c0_s_p9_0,
  112278. 1, -518803456, 1628680192, 2, 0,
  112279. _vq_quantlist__8c0_s_p9_0,
  112280. NULL,
  112281. &_vq_auxt__8c0_s_p9_0,
  112282. NULL,
  112283. 0
  112284. };
  112285. static long _vq_quantlist__8c0_s_p9_1[] = {
  112286. 7,
  112287. 6,
  112288. 8,
  112289. 5,
  112290. 9,
  112291. 4,
  112292. 10,
  112293. 3,
  112294. 11,
  112295. 2,
  112296. 12,
  112297. 1,
  112298. 13,
  112299. 0,
  112300. 14,
  112301. };
  112302. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112303. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112304. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112305. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112306. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112307. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112308. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112309. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112310. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112311. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112312. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112313. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112314. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112315. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112316. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112317. 11,
  112318. };
  112319. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112320. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112321. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112322. };
  112323. static long _vq_quantmap__8c0_s_p9_1[] = {
  112324. 13, 11, 9, 7, 5, 3, 1, 0,
  112325. 2, 4, 6, 8, 10, 12, 14,
  112326. };
  112327. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112328. _vq_quantthresh__8c0_s_p9_1,
  112329. _vq_quantmap__8c0_s_p9_1,
  112330. 15,
  112331. 15
  112332. };
  112333. static static_codebook _8c0_s_p9_1 = {
  112334. 2, 225,
  112335. _vq_lengthlist__8c0_s_p9_1,
  112336. 1, -520986624, 1620377600, 4, 0,
  112337. _vq_quantlist__8c0_s_p9_1,
  112338. NULL,
  112339. &_vq_auxt__8c0_s_p9_1,
  112340. NULL,
  112341. 0
  112342. };
  112343. static long _vq_quantlist__8c0_s_p9_2[] = {
  112344. 10,
  112345. 9,
  112346. 11,
  112347. 8,
  112348. 12,
  112349. 7,
  112350. 13,
  112351. 6,
  112352. 14,
  112353. 5,
  112354. 15,
  112355. 4,
  112356. 16,
  112357. 3,
  112358. 17,
  112359. 2,
  112360. 18,
  112361. 1,
  112362. 19,
  112363. 0,
  112364. 20,
  112365. };
  112366. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112367. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112368. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112369. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112370. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112371. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112372. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112373. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112374. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112375. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112376. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112377. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112378. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112379. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112380. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112381. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112382. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112383. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112384. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112385. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112386. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112387. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112388. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112389. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112390. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112391. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112392. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112393. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112394. 10,11, 9,11,10, 9,10, 9,10,
  112395. };
  112396. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112397. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112398. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112399. 6.5, 7.5, 8.5, 9.5,
  112400. };
  112401. static long _vq_quantmap__8c0_s_p9_2[] = {
  112402. 19, 17, 15, 13, 11, 9, 7, 5,
  112403. 3, 1, 0, 2, 4, 6, 8, 10,
  112404. 12, 14, 16, 18, 20,
  112405. };
  112406. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112407. _vq_quantthresh__8c0_s_p9_2,
  112408. _vq_quantmap__8c0_s_p9_2,
  112409. 21,
  112410. 21
  112411. };
  112412. static static_codebook _8c0_s_p9_2 = {
  112413. 2, 441,
  112414. _vq_lengthlist__8c0_s_p9_2,
  112415. 1, -529268736, 1611661312, 5, 0,
  112416. _vq_quantlist__8c0_s_p9_2,
  112417. NULL,
  112418. &_vq_auxt__8c0_s_p9_2,
  112419. NULL,
  112420. 0
  112421. };
  112422. static long _huff_lengthlist__8c0_s_single[] = {
  112423. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112424. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112425. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112426. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112427. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112428. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112429. 17,16,17,17,
  112430. };
  112431. static static_codebook _huff_book__8c0_s_single = {
  112432. 2, 100,
  112433. _huff_lengthlist__8c0_s_single,
  112434. 0, 0, 0, 0, 0,
  112435. NULL,
  112436. NULL,
  112437. NULL,
  112438. NULL,
  112439. 0
  112440. };
  112441. static long _vq_quantlist__8c1_s_p1_0[] = {
  112442. 1,
  112443. 0,
  112444. 2,
  112445. };
  112446. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112447. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112448. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112452. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112453. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112457. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112458. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112493. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  112498. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112503. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112538. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112539. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112544. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112549. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112755. 0, 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,
  112858. };
  112859. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112860. -0.5, 0.5,
  112861. };
  112862. static long _vq_quantmap__8c1_s_p1_0[] = {
  112863. 1, 0, 2,
  112864. };
  112865. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112866. _vq_quantthresh__8c1_s_p1_0,
  112867. _vq_quantmap__8c1_s_p1_0,
  112868. 3,
  112869. 3
  112870. };
  112871. static static_codebook _8c1_s_p1_0 = {
  112872. 8, 6561,
  112873. _vq_lengthlist__8c1_s_p1_0,
  112874. 1, -535822336, 1611661312, 2, 0,
  112875. _vq_quantlist__8c1_s_p1_0,
  112876. NULL,
  112877. &_vq_auxt__8c1_s_p1_0,
  112878. NULL,
  112879. 0
  112880. };
  112881. static long _vq_quantlist__8c1_s_p2_0[] = {
  112882. 2,
  112883. 1,
  112884. 3,
  112885. 0,
  112886. 4,
  112887. };
  112888. static long _vq_lengthlist__8c1_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112928. 0,
  112929. };
  112930. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112931. -1.5, -0.5, 0.5, 1.5,
  112932. };
  112933. static long _vq_quantmap__8c1_s_p2_0[] = {
  112934. 3, 1, 0, 2, 4,
  112935. };
  112936. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  112937. _vq_quantthresh__8c1_s_p2_0,
  112938. _vq_quantmap__8c1_s_p2_0,
  112939. 5,
  112940. 5
  112941. };
  112942. static static_codebook _8c1_s_p2_0 = {
  112943. 4, 625,
  112944. _vq_lengthlist__8c1_s_p2_0,
  112945. 1, -533725184, 1611661312, 3, 0,
  112946. _vq_quantlist__8c1_s_p2_0,
  112947. NULL,
  112948. &_vq_auxt__8c1_s_p2_0,
  112949. NULL,
  112950. 0
  112951. };
  112952. static long _vq_quantlist__8c1_s_p3_0[] = {
  112953. 2,
  112954. 1,
  112955. 3,
  112956. 0,
  112957. 4,
  112958. };
  112959. static long _vq_lengthlist__8c1_s_p3_0[] = {
  112960. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  112962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112963. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  112965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112966. 0, 0, 0, 0, 6, 6, 6, 7, 7, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112999. 0,
  113000. };
  113001. static float _vq_quantthresh__8c1_s_p3_0[] = {
  113002. -1.5, -0.5, 0.5, 1.5,
  113003. };
  113004. static long _vq_quantmap__8c1_s_p3_0[] = {
  113005. 3, 1, 0, 2, 4,
  113006. };
  113007. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  113008. _vq_quantthresh__8c1_s_p3_0,
  113009. _vq_quantmap__8c1_s_p3_0,
  113010. 5,
  113011. 5
  113012. };
  113013. static static_codebook _8c1_s_p3_0 = {
  113014. 4, 625,
  113015. _vq_lengthlist__8c1_s_p3_0,
  113016. 1, -533725184, 1611661312, 3, 0,
  113017. _vq_quantlist__8c1_s_p3_0,
  113018. NULL,
  113019. &_vq_auxt__8c1_s_p3_0,
  113020. NULL,
  113021. 0
  113022. };
  113023. static long _vq_quantlist__8c1_s_p4_0[] = {
  113024. 4,
  113025. 3,
  113026. 5,
  113027. 2,
  113028. 6,
  113029. 1,
  113030. 7,
  113031. 0,
  113032. 8,
  113033. };
  113034. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113035. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113036. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113037. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113038. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113039. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113040. 0,
  113041. };
  113042. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113043. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113044. };
  113045. static long _vq_quantmap__8c1_s_p4_0[] = {
  113046. 7, 5, 3, 1, 0, 2, 4, 6,
  113047. 8,
  113048. };
  113049. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113050. _vq_quantthresh__8c1_s_p4_0,
  113051. _vq_quantmap__8c1_s_p4_0,
  113052. 9,
  113053. 9
  113054. };
  113055. static static_codebook _8c1_s_p4_0 = {
  113056. 2, 81,
  113057. _vq_lengthlist__8c1_s_p4_0,
  113058. 1, -531628032, 1611661312, 4, 0,
  113059. _vq_quantlist__8c1_s_p4_0,
  113060. NULL,
  113061. &_vq_auxt__8c1_s_p4_0,
  113062. NULL,
  113063. 0
  113064. };
  113065. static long _vq_quantlist__8c1_s_p5_0[] = {
  113066. 4,
  113067. 3,
  113068. 5,
  113069. 2,
  113070. 6,
  113071. 1,
  113072. 7,
  113073. 0,
  113074. 8,
  113075. };
  113076. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113077. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113078. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113079. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113080. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113081. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113082. 10,
  113083. };
  113084. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113085. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113086. };
  113087. static long _vq_quantmap__8c1_s_p5_0[] = {
  113088. 7, 5, 3, 1, 0, 2, 4, 6,
  113089. 8,
  113090. };
  113091. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113092. _vq_quantthresh__8c1_s_p5_0,
  113093. _vq_quantmap__8c1_s_p5_0,
  113094. 9,
  113095. 9
  113096. };
  113097. static static_codebook _8c1_s_p5_0 = {
  113098. 2, 81,
  113099. _vq_lengthlist__8c1_s_p5_0,
  113100. 1, -531628032, 1611661312, 4, 0,
  113101. _vq_quantlist__8c1_s_p5_0,
  113102. NULL,
  113103. &_vq_auxt__8c1_s_p5_0,
  113104. NULL,
  113105. 0
  113106. };
  113107. static long _vq_quantlist__8c1_s_p6_0[] = {
  113108. 8,
  113109. 7,
  113110. 9,
  113111. 6,
  113112. 10,
  113113. 5,
  113114. 11,
  113115. 4,
  113116. 12,
  113117. 3,
  113118. 13,
  113119. 2,
  113120. 14,
  113121. 1,
  113122. 15,
  113123. 0,
  113124. 16,
  113125. };
  113126. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113127. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113128. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113129. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113130. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113131. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113132. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113133. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113134. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113135. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113136. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113137. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113138. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113139. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113140. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113141. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113142. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113143. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113144. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113145. 14,
  113146. };
  113147. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113148. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113149. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113150. };
  113151. static long _vq_quantmap__8c1_s_p6_0[] = {
  113152. 15, 13, 11, 9, 7, 5, 3, 1,
  113153. 0, 2, 4, 6, 8, 10, 12, 14,
  113154. 16,
  113155. };
  113156. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113157. _vq_quantthresh__8c1_s_p6_0,
  113158. _vq_quantmap__8c1_s_p6_0,
  113159. 17,
  113160. 17
  113161. };
  113162. static static_codebook _8c1_s_p6_0 = {
  113163. 2, 289,
  113164. _vq_lengthlist__8c1_s_p6_0,
  113165. 1, -529530880, 1611661312, 5, 0,
  113166. _vq_quantlist__8c1_s_p6_0,
  113167. NULL,
  113168. &_vq_auxt__8c1_s_p6_0,
  113169. NULL,
  113170. 0
  113171. };
  113172. static long _vq_quantlist__8c1_s_p7_0[] = {
  113173. 1,
  113174. 0,
  113175. 2,
  113176. };
  113177. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113178. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113179. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113180. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113181. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113182. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113183. 9,
  113184. };
  113185. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113186. -5.5, 5.5,
  113187. };
  113188. static long _vq_quantmap__8c1_s_p7_0[] = {
  113189. 1, 0, 2,
  113190. };
  113191. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113192. _vq_quantthresh__8c1_s_p7_0,
  113193. _vq_quantmap__8c1_s_p7_0,
  113194. 3,
  113195. 3
  113196. };
  113197. static static_codebook _8c1_s_p7_0 = {
  113198. 4, 81,
  113199. _vq_lengthlist__8c1_s_p7_0,
  113200. 1, -529137664, 1618345984, 2, 0,
  113201. _vq_quantlist__8c1_s_p7_0,
  113202. NULL,
  113203. &_vq_auxt__8c1_s_p7_0,
  113204. NULL,
  113205. 0
  113206. };
  113207. static long _vq_quantlist__8c1_s_p7_1[] = {
  113208. 5,
  113209. 4,
  113210. 6,
  113211. 3,
  113212. 7,
  113213. 2,
  113214. 8,
  113215. 1,
  113216. 9,
  113217. 0,
  113218. 10,
  113219. };
  113220. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113221. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113222. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113223. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113224. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113225. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113226. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113227. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113228. 10,10,10, 8, 8, 8, 8, 8, 8,
  113229. };
  113230. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113231. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113232. 3.5, 4.5,
  113233. };
  113234. static long _vq_quantmap__8c1_s_p7_1[] = {
  113235. 9, 7, 5, 3, 1, 0, 2, 4,
  113236. 6, 8, 10,
  113237. };
  113238. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113239. _vq_quantthresh__8c1_s_p7_1,
  113240. _vq_quantmap__8c1_s_p7_1,
  113241. 11,
  113242. 11
  113243. };
  113244. static static_codebook _8c1_s_p7_1 = {
  113245. 2, 121,
  113246. _vq_lengthlist__8c1_s_p7_1,
  113247. 1, -531365888, 1611661312, 4, 0,
  113248. _vq_quantlist__8c1_s_p7_1,
  113249. NULL,
  113250. &_vq_auxt__8c1_s_p7_1,
  113251. NULL,
  113252. 0
  113253. };
  113254. static long _vq_quantlist__8c1_s_p8_0[] = {
  113255. 6,
  113256. 5,
  113257. 7,
  113258. 4,
  113259. 8,
  113260. 3,
  113261. 9,
  113262. 2,
  113263. 10,
  113264. 1,
  113265. 11,
  113266. 0,
  113267. 12,
  113268. };
  113269. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113270. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113271. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113272. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113273. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113274. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113275. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113276. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113277. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113278. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113279. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113280. 0,12,12,11,10,12,11,13,12,
  113281. };
  113282. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113283. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113284. 12.5, 17.5, 22.5, 27.5,
  113285. };
  113286. static long _vq_quantmap__8c1_s_p8_0[] = {
  113287. 11, 9, 7, 5, 3, 1, 0, 2,
  113288. 4, 6, 8, 10, 12,
  113289. };
  113290. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113291. _vq_quantthresh__8c1_s_p8_0,
  113292. _vq_quantmap__8c1_s_p8_0,
  113293. 13,
  113294. 13
  113295. };
  113296. static static_codebook _8c1_s_p8_0 = {
  113297. 2, 169,
  113298. _vq_lengthlist__8c1_s_p8_0,
  113299. 1, -526516224, 1616117760, 4, 0,
  113300. _vq_quantlist__8c1_s_p8_0,
  113301. NULL,
  113302. &_vq_auxt__8c1_s_p8_0,
  113303. NULL,
  113304. 0
  113305. };
  113306. static long _vq_quantlist__8c1_s_p8_1[] = {
  113307. 2,
  113308. 1,
  113309. 3,
  113310. 0,
  113311. 4,
  113312. };
  113313. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113314. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113315. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113316. };
  113317. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113318. -1.5, -0.5, 0.5, 1.5,
  113319. };
  113320. static long _vq_quantmap__8c1_s_p8_1[] = {
  113321. 3, 1, 0, 2, 4,
  113322. };
  113323. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113324. _vq_quantthresh__8c1_s_p8_1,
  113325. _vq_quantmap__8c1_s_p8_1,
  113326. 5,
  113327. 5
  113328. };
  113329. static static_codebook _8c1_s_p8_1 = {
  113330. 2, 25,
  113331. _vq_lengthlist__8c1_s_p8_1,
  113332. 1, -533725184, 1611661312, 3, 0,
  113333. _vq_quantlist__8c1_s_p8_1,
  113334. NULL,
  113335. &_vq_auxt__8c1_s_p8_1,
  113336. NULL,
  113337. 0
  113338. };
  113339. static long _vq_quantlist__8c1_s_p9_0[] = {
  113340. 6,
  113341. 5,
  113342. 7,
  113343. 4,
  113344. 8,
  113345. 3,
  113346. 9,
  113347. 2,
  113348. 10,
  113349. 1,
  113350. 11,
  113351. 0,
  113352. 12,
  113353. };
  113354. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113355. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113356. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113357. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113358. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113359. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113360. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113361. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113362. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113363. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113364. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113365. 10,10,10,10,10, 9, 9, 9, 9,
  113366. };
  113367. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113368. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113369. 787.5, 1102.5, 1417.5, 1732.5,
  113370. };
  113371. static long _vq_quantmap__8c1_s_p9_0[] = {
  113372. 11, 9, 7, 5, 3, 1, 0, 2,
  113373. 4, 6, 8, 10, 12,
  113374. };
  113375. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113376. _vq_quantthresh__8c1_s_p9_0,
  113377. _vq_quantmap__8c1_s_p9_0,
  113378. 13,
  113379. 13
  113380. };
  113381. static static_codebook _8c1_s_p9_0 = {
  113382. 2, 169,
  113383. _vq_lengthlist__8c1_s_p9_0,
  113384. 1, -513964032, 1628680192, 4, 0,
  113385. _vq_quantlist__8c1_s_p9_0,
  113386. NULL,
  113387. &_vq_auxt__8c1_s_p9_0,
  113388. NULL,
  113389. 0
  113390. };
  113391. static long _vq_quantlist__8c1_s_p9_1[] = {
  113392. 7,
  113393. 6,
  113394. 8,
  113395. 5,
  113396. 9,
  113397. 4,
  113398. 10,
  113399. 3,
  113400. 11,
  113401. 2,
  113402. 12,
  113403. 1,
  113404. 13,
  113405. 0,
  113406. 14,
  113407. };
  113408. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113409. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113410. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113411. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113412. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113413. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113414. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113415. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113416. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113417. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113418. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113419. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113420. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113421. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113422. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113423. 15,
  113424. };
  113425. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113426. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113427. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113428. };
  113429. static long _vq_quantmap__8c1_s_p9_1[] = {
  113430. 13, 11, 9, 7, 5, 3, 1, 0,
  113431. 2, 4, 6, 8, 10, 12, 14,
  113432. };
  113433. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113434. _vq_quantthresh__8c1_s_p9_1,
  113435. _vq_quantmap__8c1_s_p9_1,
  113436. 15,
  113437. 15
  113438. };
  113439. static static_codebook _8c1_s_p9_1 = {
  113440. 2, 225,
  113441. _vq_lengthlist__8c1_s_p9_1,
  113442. 1, -520986624, 1620377600, 4, 0,
  113443. _vq_quantlist__8c1_s_p9_1,
  113444. NULL,
  113445. &_vq_auxt__8c1_s_p9_1,
  113446. NULL,
  113447. 0
  113448. };
  113449. static long _vq_quantlist__8c1_s_p9_2[] = {
  113450. 10,
  113451. 9,
  113452. 11,
  113453. 8,
  113454. 12,
  113455. 7,
  113456. 13,
  113457. 6,
  113458. 14,
  113459. 5,
  113460. 15,
  113461. 4,
  113462. 16,
  113463. 3,
  113464. 17,
  113465. 2,
  113466. 18,
  113467. 1,
  113468. 19,
  113469. 0,
  113470. 20,
  113471. };
  113472. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113473. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113474. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113475. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113476. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113477. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113478. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113479. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113480. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113481. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113482. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113483. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113484. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113485. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113486. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113487. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113488. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113489. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113490. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113491. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113492. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113493. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113494. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113495. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113496. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113497. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113498. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113499. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113500. 10,10,10,10,10,10,10,10,10,
  113501. };
  113502. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113503. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113504. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113505. 6.5, 7.5, 8.5, 9.5,
  113506. };
  113507. static long _vq_quantmap__8c1_s_p9_2[] = {
  113508. 19, 17, 15, 13, 11, 9, 7, 5,
  113509. 3, 1, 0, 2, 4, 6, 8, 10,
  113510. 12, 14, 16, 18, 20,
  113511. };
  113512. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113513. _vq_quantthresh__8c1_s_p9_2,
  113514. _vq_quantmap__8c1_s_p9_2,
  113515. 21,
  113516. 21
  113517. };
  113518. static static_codebook _8c1_s_p9_2 = {
  113519. 2, 441,
  113520. _vq_lengthlist__8c1_s_p9_2,
  113521. 1, -529268736, 1611661312, 5, 0,
  113522. _vq_quantlist__8c1_s_p9_2,
  113523. NULL,
  113524. &_vq_auxt__8c1_s_p9_2,
  113525. NULL,
  113526. 0
  113527. };
  113528. static long _huff_lengthlist__8c1_s_single[] = {
  113529. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113530. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113531. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113532. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113533. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113534. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113535. 9, 7, 7, 8,
  113536. };
  113537. static static_codebook _huff_book__8c1_s_single = {
  113538. 2, 100,
  113539. _huff_lengthlist__8c1_s_single,
  113540. 0, 0, 0, 0, 0,
  113541. NULL,
  113542. NULL,
  113543. NULL,
  113544. NULL,
  113545. 0
  113546. };
  113547. static long _huff_lengthlist__44c2_s_long[] = {
  113548. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113549. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113550. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113551. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113552. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113553. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113554. 10, 8, 8, 9,
  113555. };
  113556. static static_codebook _huff_book__44c2_s_long = {
  113557. 2, 100,
  113558. _huff_lengthlist__44c2_s_long,
  113559. 0, 0, 0, 0, 0,
  113560. NULL,
  113561. NULL,
  113562. NULL,
  113563. NULL,
  113564. 0
  113565. };
  113566. static long _vq_quantlist__44c2_s_p1_0[] = {
  113567. 1,
  113568. 0,
  113569. 2,
  113570. };
  113571. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113572. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113573. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113577. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113578. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113582. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113583. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113618. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113623. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  113628. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113663. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113664. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113669. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113674. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113880. 0, 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,
  113983. };
  113984. static float _vq_quantthresh__44c2_s_p1_0[] = {
  113985. -0.5, 0.5,
  113986. };
  113987. static long _vq_quantmap__44c2_s_p1_0[] = {
  113988. 1, 0, 2,
  113989. };
  113990. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  113991. _vq_quantthresh__44c2_s_p1_0,
  113992. _vq_quantmap__44c2_s_p1_0,
  113993. 3,
  113994. 3
  113995. };
  113996. static static_codebook _44c2_s_p1_0 = {
  113997. 8, 6561,
  113998. _vq_lengthlist__44c2_s_p1_0,
  113999. 1, -535822336, 1611661312, 2, 0,
  114000. _vq_quantlist__44c2_s_p1_0,
  114001. NULL,
  114002. &_vq_auxt__44c2_s_p1_0,
  114003. NULL,
  114004. 0
  114005. };
  114006. static long _vq_quantlist__44c2_s_p2_0[] = {
  114007. 2,
  114008. 1,
  114009. 3,
  114010. 0,
  114011. 4,
  114012. };
  114013. static long _vq_lengthlist__44c2_s_p2_0[] = {
  114014. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  114015. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  114016. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  114017. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  114018. 0, 0, 9, 9, 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, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  114024. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114025. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114026. 12, 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, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114032. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114033. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 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. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114040. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114041. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114053. 0,
  114054. };
  114055. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114056. -1.5, -0.5, 0.5, 1.5,
  114057. };
  114058. static long _vq_quantmap__44c2_s_p2_0[] = {
  114059. 3, 1, 0, 2, 4,
  114060. };
  114061. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114062. _vq_quantthresh__44c2_s_p2_0,
  114063. _vq_quantmap__44c2_s_p2_0,
  114064. 5,
  114065. 5
  114066. };
  114067. static static_codebook _44c2_s_p2_0 = {
  114068. 4, 625,
  114069. _vq_lengthlist__44c2_s_p2_0,
  114070. 1, -533725184, 1611661312, 3, 0,
  114071. _vq_quantlist__44c2_s_p2_0,
  114072. NULL,
  114073. &_vq_auxt__44c2_s_p2_0,
  114074. NULL,
  114075. 0
  114076. };
  114077. static long _vq_quantlist__44c2_s_p3_0[] = {
  114078. 2,
  114079. 1,
  114080. 3,
  114081. 0,
  114082. 4,
  114083. };
  114084. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114085. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114088. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114091. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114124. 0,
  114125. };
  114126. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114127. -1.5, -0.5, 0.5, 1.5,
  114128. };
  114129. static long _vq_quantmap__44c2_s_p3_0[] = {
  114130. 3, 1, 0, 2, 4,
  114131. };
  114132. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114133. _vq_quantthresh__44c2_s_p3_0,
  114134. _vq_quantmap__44c2_s_p3_0,
  114135. 5,
  114136. 5
  114137. };
  114138. static static_codebook _44c2_s_p3_0 = {
  114139. 4, 625,
  114140. _vq_lengthlist__44c2_s_p3_0,
  114141. 1, -533725184, 1611661312, 3, 0,
  114142. _vq_quantlist__44c2_s_p3_0,
  114143. NULL,
  114144. &_vq_auxt__44c2_s_p3_0,
  114145. NULL,
  114146. 0
  114147. };
  114148. static long _vq_quantlist__44c2_s_p4_0[] = {
  114149. 4,
  114150. 3,
  114151. 5,
  114152. 2,
  114153. 6,
  114154. 1,
  114155. 7,
  114156. 0,
  114157. 8,
  114158. };
  114159. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114160. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114161. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114162. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114163. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114164. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114165. 0,
  114166. };
  114167. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114168. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114169. };
  114170. static long _vq_quantmap__44c2_s_p4_0[] = {
  114171. 7, 5, 3, 1, 0, 2, 4, 6,
  114172. 8,
  114173. };
  114174. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114175. _vq_quantthresh__44c2_s_p4_0,
  114176. _vq_quantmap__44c2_s_p4_0,
  114177. 9,
  114178. 9
  114179. };
  114180. static static_codebook _44c2_s_p4_0 = {
  114181. 2, 81,
  114182. _vq_lengthlist__44c2_s_p4_0,
  114183. 1, -531628032, 1611661312, 4, 0,
  114184. _vq_quantlist__44c2_s_p4_0,
  114185. NULL,
  114186. &_vq_auxt__44c2_s_p4_0,
  114187. NULL,
  114188. 0
  114189. };
  114190. static long _vq_quantlist__44c2_s_p5_0[] = {
  114191. 4,
  114192. 3,
  114193. 5,
  114194. 2,
  114195. 6,
  114196. 1,
  114197. 7,
  114198. 0,
  114199. 8,
  114200. };
  114201. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114202. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114203. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114204. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114205. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114206. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114207. 11,
  114208. };
  114209. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114210. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114211. };
  114212. static long _vq_quantmap__44c2_s_p5_0[] = {
  114213. 7, 5, 3, 1, 0, 2, 4, 6,
  114214. 8,
  114215. };
  114216. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114217. _vq_quantthresh__44c2_s_p5_0,
  114218. _vq_quantmap__44c2_s_p5_0,
  114219. 9,
  114220. 9
  114221. };
  114222. static static_codebook _44c2_s_p5_0 = {
  114223. 2, 81,
  114224. _vq_lengthlist__44c2_s_p5_0,
  114225. 1, -531628032, 1611661312, 4, 0,
  114226. _vq_quantlist__44c2_s_p5_0,
  114227. NULL,
  114228. &_vq_auxt__44c2_s_p5_0,
  114229. NULL,
  114230. 0
  114231. };
  114232. static long _vq_quantlist__44c2_s_p6_0[] = {
  114233. 8,
  114234. 7,
  114235. 9,
  114236. 6,
  114237. 10,
  114238. 5,
  114239. 11,
  114240. 4,
  114241. 12,
  114242. 3,
  114243. 13,
  114244. 2,
  114245. 14,
  114246. 1,
  114247. 15,
  114248. 0,
  114249. 16,
  114250. };
  114251. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114252. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114253. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114254. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114255. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114256. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114257. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114258. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114259. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114260. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114261. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114262. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114263. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114264. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114265. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114266. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114267. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114268. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114269. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114270. 14,
  114271. };
  114272. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114273. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114274. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114275. };
  114276. static long _vq_quantmap__44c2_s_p6_0[] = {
  114277. 15, 13, 11, 9, 7, 5, 3, 1,
  114278. 0, 2, 4, 6, 8, 10, 12, 14,
  114279. 16,
  114280. };
  114281. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114282. _vq_quantthresh__44c2_s_p6_0,
  114283. _vq_quantmap__44c2_s_p6_0,
  114284. 17,
  114285. 17
  114286. };
  114287. static static_codebook _44c2_s_p6_0 = {
  114288. 2, 289,
  114289. _vq_lengthlist__44c2_s_p6_0,
  114290. 1, -529530880, 1611661312, 5, 0,
  114291. _vq_quantlist__44c2_s_p6_0,
  114292. NULL,
  114293. &_vq_auxt__44c2_s_p6_0,
  114294. NULL,
  114295. 0
  114296. };
  114297. static long _vq_quantlist__44c2_s_p7_0[] = {
  114298. 1,
  114299. 0,
  114300. 2,
  114301. };
  114302. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114303. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114304. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114305. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114306. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114307. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114308. 11,
  114309. };
  114310. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114311. -5.5, 5.5,
  114312. };
  114313. static long _vq_quantmap__44c2_s_p7_0[] = {
  114314. 1, 0, 2,
  114315. };
  114316. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114317. _vq_quantthresh__44c2_s_p7_0,
  114318. _vq_quantmap__44c2_s_p7_0,
  114319. 3,
  114320. 3
  114321. };
  114322. static static_codebook _44c2_s_p7_0 = {
  114323. 4, 81,
  114324. _vq_lengthlist__44c2_s_p7_0,
  114325. 1, -529137664, 1618345984, 2, 0,
  114326. _vq_quantlist__44c2_s_p7_0,
  114327. NULL,
  114328. &_vq_auxt__44c2_s_p7_0,
  114329. NULL,
  114330. 0
  114331. };
  114332. static long _vq_quantlist__44c2_s_p7_1[] = {
  114333. 5,
  114334. 4,
  114335. 6,
  114336. 3,
  114337. 7,
  114338. 2,
  114339. 8,
  114340. 1,
  114341. 9,
  114342. 0,
  114343. 10,
  114344. };
  114345. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114346. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114347. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114348. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114349. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114350. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114351. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114352. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114353. 10,10,10, 8, 8, 8, 8, 8, 8,
  114354. };
  114355. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114356. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114357. 3.5, 4.5,
  114358. };
  114359. static long _vq_quantmap__44c2_s_p7_1[] = {
  114360. 9, 7, 5, 3, 1, 0, 2, 4,
  114361. 6, 8, 10,
  114362. };
  114363. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114364. _vq_quantthresh__44c2_s_p7_1,
  114365. _vq_quantmap__44c2_s_p7_1,
  114366. 11,
  114367. 11
  114368. };
  114369. static static_codebook _44c2_s_p7_1 = {
  114370. 2, 121,
  114371. _vq_lengthlist__44c2_s_p7_1,
  114372. 1, -531365888, 1611661312, 4, 0,
  114373. _vq_quantlist__44c2_s_p7_1,
  114374. NULL,
  114375. &_vq_auxt__44c2_s_p7_1,
  114376. NULL,
  114377. 0
  114378. };
  114379. static long _vq_quantlist__44c2_s_p8_0[] = {
  114380. 6,
  114381. 5,
  114382. 7,
  114383. 4,
  114384. 8,
  114385. 3,
  114386. 9,
  114387. 2,
  114388. 10,
  114389. 1,
  114390. 11,
  114391. 0,
  114392. 12,
  114393. };
  114394. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114395. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114396. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114397. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114398. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114399. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114400. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114401. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114402. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114403. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114404. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114405. 0,12,12,12,12,13,12,14,14,
  114406. };
  114407. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114408. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114409. 12.5, 17.5, 22.5, 27.5,
  114410. };
  114411. static long _vq_quantmap__44c2_s_p8_0[] = {
  114412. 11, 9, 7, 5, 3, 1, 0, 2,
  114413. 4, 6, 8, 10, 12,
  114414. };
  114415. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114416. _vq_quantthresh__44c2_s_p8_0,
  114417. _vq_quantmap__44c2_s_p8_0,
  114418. 13,
  114419. 13
  114420. };
  114421. static static_codebook _44c2_s_p8_0 = {
  114422. 2, 169,
  114423. _vq_lengthlist__44c2_s_p8_0,
  114424. 1, -526516224, 1616117760, 4, 0,
  114425. _vq_quantlist__44c2_s_p8_0,
  114426. NULL,
  114427. &_vq_auxt__44c2_s_p8_0,
  114428. NULL,
  114429. 0
  114430. };
  114431. static long _vq_quantlist__44c2_s_p8_1[] = {
  114432. 2,
  114433. 1,
  114434. 3,
  114435. 0,
  114436. 4,
  114437. };
  114438. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114439. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114440. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114441. };
  114442. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114443. -1.5, -0.5, 0.5, 1.5,
  114444. };
  114445. static long _vq_quantmap__44c2_s_p8_1[] = {
  114446. 3, 1, 0, 2, 4,
  114447. };
  114448. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114449. _vq_quantthresh__44c2_s_p8_1,
  114450. _vq_quantmap__44c2_s_p8_1,
  114451. 5,
  114452. 5
  114453. };
  114454. static static_codebook _44c2_s_p8_1 = {
  114455. 2, 25,
  114456. _vq_lengthlist__44c2_s_p8_1,
  114457. 1, -533725184, 1611661312, 3, 0,
  114458. _vq_quantlist__44c2_s_p8_1,
  114459. NULL,
  114460. &_vq_auxt__44c2_s_p8_1,
  114461. NULL,
  114462. 0
  114463. };
  114464. static long _vq_quantlist__44c2_s_p9_0[] = {
  114465. 6,
  114466. 5,
  114467. 7,
  114468. 4,
  114469. 8,
  114470. 3,
  114471. 9,
  114472. 2,
  114473. 10,
  114474. 1,
  114475. 11,
  114476. 0,
  114477. 12,
  114478. };
  114479. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114480. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114481. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114482. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114483. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114484. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114485. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114486. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114487. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114488. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114489. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114490. 11,11,11,11,11,11,11,11,11,
  114491. };
  114492. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114493. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114494. 552.5, 773.5, 994.5, 1215.5,
  114495. };
  114496. static long _vq_quantmap__44c2_s_p9_0[] = {
  114497. 11, 9, 7, 5, 3, 1, 0, 2,
  114498. 4, 6, 8, 10, 12,
  114499. };
  114500. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114501. _vq_quantthresh__44c2_s_p9_0,
  114502. _vq_quantmap__44c2_s_p9_0,
  114503. 13,
  114504. 13
  114505. };
  114506. static static_codebook _44c2_s_p9_0 = {
  114507. 2, 169,
  114508. _vq_lengthlist__44c2_s_p9_0,
  114509. 1, -514541568, 1627103232, 4, 0,
  114510. _vq_quantlist__44c2_s_p9_0,
  114511. NULL,
  114512. &_vq_auxt__44c2_s_p9_0,
  114513. NULL,
  114514. 0
  114515. };
  114516. static long _vq_quantlist__44c2_s_p9_1[] = {
  114517. 6,
  114518. 5,
  114519. 7,
  114520. 4,
  114521. 8,
  114522. 3,
  114523. 9,
  114524. 2,
  114525. 10,
  114526. 1,
  114527. 11,
  114528. 0,
  114529. 12,
  114530. };
  114531. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114532. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114533. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114534. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114535. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114536. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114537. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114538. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114539. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114540. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114541. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114542. 17,13,12,12,10,13,11,14,14,
  114543. };
  114544. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114545. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114546. 42.5, 59.5, 76.5, 93.5,
  114547. };
  114548. static long _vq_quantmap__44c2_s_p9_1[] = {
  114549. 11, 9, 7, 5, 3, 1, 0, 2,
  114550. 4, 6, 8, 10, 12,
  114551. };
  114552. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114553. _vq_quantthresh__44c2_s_p9_1,
  114554. _vq_quantmap__44c2_s_p9_1,
  114555. 13,
  114556. 13
  114557. };
  114558. static static_codebook _44c2_s_p9_1 = {
  114559. 2, 169,
  114560. _vq_lengthlist__44c2_s_p9_1,
  114561. 1, -522616832, 1620115456, 4, 0,
  114562. _vq_quantlist__44c2_s_p9_1,
  114563. NULL,
  114564. &_vq_auxt__44c2_s_p9_1,
  114565. NULL,
  114566. 0
  114567. };
  114568. static long _vq_quantlist__44c2_s_p9_2[] = {
  114569. 8,
  114570. 7,
  114571. 9,
  114572. 6,
  114573. 10,
  114574. 5,
  114575. 11,
  114576. 4,
  114577. 12,
  114578. 3,
  114579. 13,
  114580. 2,
  114581. 14,
  114582. 1,
  114583. 15,
  114584. 0,
  114585. 16,
  114586. };
  114587. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114588. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114589. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114590. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114591. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114592. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114593. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114594. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114595. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114596. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114597. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114598. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114599. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114600. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114601. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114602. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114603. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114604. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114605. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114606. 10,
  114607. };
  114608. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114609. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114610. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114611. };
  114612. static long _vq_quantmap__44c2_s_p9_2[] = {
  114613. 15, 13, 11, 9, 7, 5, 3, 1,
  114614. 0, 2, 4, 6, 8, 10, 12, 14,
  114615. 16,
  114616. };
  114617. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114618. _vq_quantthresh__44c2_s_p9_2,
  114619. _vq_quantmap__44c2_s_p9_2,
  114620. 17,
  114621. 17
  114622. };
  114623. static static_codebook _44c2_s_p9_2 = {
  114624. 2, 289,
  114625. _vq_lengthlist__44c2_s_p9_2,
  114626. 1, -529530880, 1611661312, 5, 0,
  114627. _vq_quantlist__44c2_s_p9_2,
  114628. NULL,
  114629. &_vq_auxt__44c2_s_p9_2,
  114630. NULL,
  114631. 0
  114632. };
  114633. static long _huff_lengthlist__44c2_s_short[] = {
  114634. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114635. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114636. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114637. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114638. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114639. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114640. 6, 8, 9,12,
  114641. };
  114642. static static_codebook _huff_book__44c2_s_short = {
  114643. 2, 100,
  114644. _huff_lengthlist__44c2_s_short,
  114645. 0, 0, 0, 0, 0,
  114646. NULL,
  114647. NULL,
  114648. NULL,
  114649. NULL,
  114650. 0
  114651. };
  114652. static long _huff_lengthlist__44c3_s_long[] = {
  114653. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114654. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114655. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114656. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114657. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114658. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114659. 9, 8, 8, 8,
  114660. };
  114661. static static_codebook _huff_book__44c3_s_long = {
  114662. 2, 100,
  114663. _huff_lengthlist__44c3_s_long,
  114664. 0, 0, 0, 0, 0,
  114665. NULL,
  114666. NULL,
  114667. NULL,
  114668. NULL,
  114669. 0
  114670. };
  114671. static long _vq_quantlist__44c3_s_p1_0[] = {
  114672. 1,
  114673. 0,
  114674. 2,
  114675. };
  114676. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114677. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114678. 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114682. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114683. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114687. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114688. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  114723. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114728. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  114733. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114768. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114769. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114774. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114779. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  114780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114985. 0, 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,
  115088. };
  115089. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115090. -0.5, 0.5,
  115091. };
  115092. static long _vq_quantmap__44c3_s_p1_0[] = {
  115093. 1, 0, 2,
  115094. };
  115095. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115096. _vq_quantthresh__44c3_s_p1_0,
  115097. _vq_quantmap__44c3_s_p1_0,
  115098. 3,
  115099. 3
  115100. };
  115101. static static_codebook _44c3_s_p1_0 = {
  115102. 8, 6561,
  115103. _vq_lengthlist__44c3_s_p1_0,
  115104. 1, -535822336, 1611661312, 2, 0,
  115105. _vq_quantlist__44c3_s_p1_0,
  115106. NULL,
  115107. &_vq_auxt__44c3_s_p1_0,
  115108. NULL,
  115109. 0
  115110. };
  115111. static long _vq_quantlist__44c3_s_p2_0[] = {
  115112. 2,
  115113. 1,
  115114. 3,
  115115. 0,
  115116. 4,
  115117. };
  115118. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115119. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115120. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115121. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115122. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115123. 0, 0,10,10, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115129. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115130. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115131. 9, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115137. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115138. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 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. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115145. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115146. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115158. 0,
  115159. };
  115160. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115161. -1.5, -0.5, 0.5, 1.5,
  115162. };
  115163. static long _vq_quantmap__44c3_s_p2_0[] = {
  115164. 3, 1, 0, 2, 4,
  115165. };
  115166. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115167. _vq_quantthresh__44c3_s_p2_0,
  115168. _vq_quantmap__44c3_s_p2_0,
  115169. 5,
  115170. 5
  115171. };
  115172. static static_codebook _44c3_s_p2_0 = {
  115173. 4, 625,
  115174. _vq_lengthlist__44c3_s_p2_0,
  115175. 1, -533725184, 1611661312, 3, 0,
  115176. _vq_quantlist__44c3_s_p2_0,
  115177. NULL,
  115178. &_vq_auxt__44c3_s_p2_0,
  115179. NULL,
  115180. 0
  115181. };
  115182. static long _vq_quantlist__44c3_s_p3_0[] = {
  115183. 2,
  115184. 1,
  115185. 3,
  115186. 0,
  115187. 4,
  115188. };
  115189. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115190. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115193. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115196. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115229. 0,
  115230. };
  115231. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115232. -1.5, -0.5, 0.5, 1.5,
  115233. };
  115234. static long _vq_quantmap__44c3_s_p3_0[] = {
  115235. 3, 1, 0, 2, 4,
  115236. };
  115237. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115238. _vq_quantthresh__44c3_s_p3_0,
  115239. _vq_quantmap__44c3_s_p3_0,
  115240. 5,
  115241. 5
  115242. };
  115243. static static_codebook _44c3_s_p3_0 = {
  115244. 4, 625,
  115245. _vq_lengthlist__44c3_s_p3_0,
  115246. 1, -533725184, 1611661312, 3, 0,
  115247. _vq_quantlist__44c3_s_p3_0,
  115248. NULL,
  115249. &_vq_auxt__44c3_s_p3_0,
  115250. NULL,
  115251. 0
  115252. };
  115253. static long _vq_quantlist__44c3_s_p4_0[] = {
  115254. 4,
  115255. 3,
  115256. 5,
  115257. 2,
  115258. 6,
  115259. 1,
  115260. 7,
  115261. 0,
  115262. 8,
  115263. };
  115264. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115265. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115266. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115267. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115268. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115269. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115270. 0,
  115271. };
  115272. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115273. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115274. };
  115275. static long _vq_quantmap__44c3_s_p4_0[] = {
  115276. 7, 5, 3, 1, 0, 2, 4, 6,
  115277. 8,
  115278. };
  115279. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115280. _vq_quantthresh__44c3_s_p4_0,
  115281. _vq_quantmap__44c3_s_p4_0,
  115282. 9,
  115283. 9
  115284. };
  115285. static static_codebook _44c3_s_p4_0 = {
  115286. 2, 81,
  115287. _vq_lengthlist__44c3_s_p4_0,
  115288. 1, -531628032, 1611661312, 4, 0,
  115289. _vq_quantlist__44c3_s_p4_0,
  115290. NULL,
  115291. &_vq_auxt__44c3_s_p4_0,
  115292. NULL,
  115293. 0
  115294. };
  115295. static long _vq_quantlist__44c3_s_p5_0[] = {
  115296. 4,
  115297. 3,
  115298. 5,
  115299. 2,
  115300. 6,
  115301. 1,
  115302. 7,
  115303. 0,
  115304. 8,
  115305. };
  115306. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115307. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115308. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115309. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115310. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115311. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115312. 11,
  115313. };
  115314. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115315. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115316. };
  115317. static long _vq_quantmap__44c3_s_p5_0[] = {
  115318. 7, 5, 3, 1, 0, 2, 4, 6,
  115319. 8,
  115320. };
  115321. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115322. _vq_quantthresh__44c3_s_p5_0,
  115323. _vq_quantmap__44c3_s_p5_0,
  115324. 9,
  115325. 9
  115326. };
  115327. static static_codebook _44c3_s_p5_0 = {
  115328. 2, 81,
  115329. _vq_lengthlist__44c3_s_p5_0,
  115330. 1, -531628032, 1611661312, 4, 0,
  115331. _vq_quantlist__44c3_s_p5_0,
  115332. NULL,
  115333. &_vq_auxt__44c3_s_p5_0,
  115334. NULL,
  115335. 0
  115336. };
  115337. static long _vq_quantlist__44c3_s_p6_0[] = {
  115338. 8,
  115339. 7,
  115340. 9,
  115341. 6,
  115342. 10,
  115343. 5,
  115344. 11,
  115345. 4,
  115346. 12,
  115347. 3,
  115348. 13,
  115349. 2,
  115350. 14,
  115351. 1,
  115352. 15,
  115353. 0,
  115354. 16,
  115355. };
  115356. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115357. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115358. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115359. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115360. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115361. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115362. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115363. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115364. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115365. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115366. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115367. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115368. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115369. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115370. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115371. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115372. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115373. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115374. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115375. 13,
  115376. };
  115377. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115378. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115379. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115380. };
  115381. static long _vq_quantmap__44c3_s_p6_0[] = {
  115382. 15, 13, 11, 9, 7, 5, 3, 1,
  115383. 0, 2, 4, 6, 8, 10, 12, 14,
  115384. 16,
  115385. };
  115386. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115387. _vq_quantthresh__44c3_s_p6_0,
  115388. _vq_quantmap__44c3_s_p6_0,
  115389. 17,
  115390. 17
  115391. };
  115392. static static_codebook _44c3_s_p6_0 = {
  115393. 2, 289,
  115394. _vq_lengthlist__44c3_s_p6_0,
  115395. 1, -529530880, 1611661312, 5, 0,
  115396. _vq_quantlist__44c3_s_p6_0,
  115397. NULL,
  115398. &_vq_auxt__44c3_s_p6_0,
  115399. NULL,
  115400. 0
  115401. };
  115402. static long _vq_quantlist__44c3_s_p7_0[] = {
  115403. 1,
  115404. 0,
  115405. 2,
  115406. };
  115407. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115408. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115409. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115410. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115411. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115412. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115413. 10,
  115414. };
  115415. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115416. -5.5, 5.5,
  115417. };
  115418. static long _vq_quantmap__44c3_s_p7_0[] = {
  115419. 1, 0, 2,
  115420. };
  115421. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115422. _vq_quantthresh__44c3_s_p7_0,
  115423. _vq_quantmap__44c3_s_p7_0,
  115424. 3,
  115425. 3
  115426. };
  115427. static static_codebook _44c3_s_p7_0 = {
  115428. 4, 81,
  115429. _vq_lengthlist__44c3_s_p7_0,
  115430. 1, -529137664, 1618345984, 2, 0,
  115431. _vq_quantlist__44c3_s_p7_0,
  115432. NULL,
  115433. &_vq_auxt__44c3_s_p7_0,
  115434. NULL,
  115435. 0
  115436. };
  115437. static long _vq_quantlist__44c3_s_p7_1[] = {
  115438. 5,
  115439. 4,
  115440. 6,
  115441. 3,
  115442. 7,
  115443. 2,
  115444. 8,
  115445. 1,
  115446. 9,
  115447. 0,
  115448. 10,
  115449. };
  115450. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115451. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115452. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115453. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115454. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115455. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115456. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115457. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115458. 10,10,10, 8, 8, 8, 8, 8, 8,
  115459. };
  115460. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115461. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115462. 3.5, 4.5,
  115463. };
  115464. static long _vq_quantmap__44c3_s_p7_1[] = {
  115465. 9, 7, 5, 3, 1, 0, 2, 4,
  115466. 6, 8, 10,
  115467. };
  115468. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115469. _vq_quantthresh__44c3_s_p7_1,
  115470. _vq_quantmap__44c3_s_p7_1,
  115471. 11,
  115472. 11
  115473. };
  115474. static static_codebook _44c3_s_p7_1 = {
  115475. 2, 121,
  115476. _vq_lengthlist__44c3_s_p7_1,
  115477. 1, -531365888, 1611661312, 4, 0,
  115478. _vq_quantlist__44c3_s_p7_1,
  115479. NULL,
  115480. &_vq_auxt__44c3_s_p7_1,
  115481. NULL,
  115482. 0
  115483. };
  115484. static long _vq_quantlist__44c3_s_p8_0[] = {
  115485. 6,
  115486. 5,
  115487. 7,
  115488. 4,
  115489. 8,
  115490. 3,
  115491. 9,
  115492. 2,
  115493. 10,
  115494. 1,
  115495. 11,
  115496. 0,
  115497. 12,
  115498. };
  115499. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115500. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115501. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115502. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115503. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115504. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115505. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115506. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115507. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115508. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115509. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115510. 0,13,13,12,12,13,12,14,13,
  115511. };
  115512. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115513. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115514. 12.5, 17.5, 22.5, 27.5,
  115515. };
  115516. static long _vq_quantmap__44c3_s_p8_0[] = {
  115517. 11, 9, 7, 5, 3, 1, 0, 2,
  115518. 4, 6, 8, 10, 12,
  115519. };
  115520. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115521. _vq_quantthresh__44c3_s_p8_0,
  115522. _vq_quantmap__44c3_s_p8_0,
  115523. 13,
  115524. 13
  115525. };
  115526. static static_codebook _44c3_s_p8_0 = {
  115527. 2, 169,
  115528. _vq_lengthlist__44c3_s_p8_0,
  115529. 1, -526516224, 1616117760, 4, 0,
  115530. _vq_quantlist__44c3_s_p8_0,
  115531. NULL,
  115532. &_vq_auxt__44c3_s_p8_0,
  115533. NULL,
  115534. 0
  115535. };
  115536. static long _vq_quantlist__44c3_s_p8_1[] = {
  115537. 2,
  115538. 1,
  115539. 3,
  115540. 0,
  115541. 4,
  115542. };
  115543. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115544. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115545. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115546. };
  115547. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115548. -1.5, -0.5, 0.5, 1.5,
  115549. };
  115550. static long _vq_quantmap__44c3_s_p8_1[] = {
  115551. 3, 1, 0, 2, 4,
  115552. };
  115553. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115554. _vq_quantthresh__44c3_s_p8_1,
  115555. _vq_quantmap__44c3_s_p8_1,
  115556. 5,
  115557. 5
  115558. };
  115559. static static_codebook _44c3_s_p8_1 = {
  115560. 2, 25,
  115561. _vq_lengthlist__44c3_s_p8_1,
  115562. 1, -533725184, 1611661312, 3, 0,
  115563. _vq_quantlist__44c3_s_p8_1,
  115564. NULL,
  115565. &_vq_auxt__44c3_s_p8_1,
  115566. NULL,
  115567. 0
  115568. };
  115569. static long _vq_quantlist__44c3_s_p9_0[] = {
  115570. 6,
  115571. 5,
  115572. 7,
  115573. 4,
  115574. 8,
  115575. 3,
  115576. 9,
  115577. 2,
  115578. 10,
  115579. 1,
  115580. 11,
  115581. 0,
  115582. 12,
  115583. };
  115584. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115585. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115586. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115587. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115588. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115589. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115590. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115591. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115592. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115593. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115594. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115595. 11,11,11,11,11,11,11,11,11,
  115596. };
  115597. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115598. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115599. 637.5, 892.5, 1147.5, 1402.5,
  115600. };
  115601. static long _vq_quantmap__44c3_s_p9_0[] = {
  115602. 11, 9, 7, 5, 3, 1, 0, 2,
  115603. 4, 6, 8, 10, 12,
  115604. };
  115605. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115606. _vq_quantthresh__44c3_s_p9_0,
  115607. _vq_quantmap__44c3_s_p9_0,
  115608. 13,
  115609. 13
  115610. };
  115611. static static_codebook _44c3_s_p9_0 = {
  115612. 2, 169,
  115613. _vq_lengthlist__44c3_s_p9_0,
  115614. 1, -514332672, 1627381760, 4, 0,
  115615. _vq_quantlist__44c3_s_p9_0,
  115616. NULL,
  115617. &_vq_auxt__44c3_s_p9_0,
  115618. NULL,
  115619. 0
  115620. };
  115621. static long _vq_quantlist__44c3_s_p9_1[] = {
  115622. 7,
  115623. 6,
  115624. 8,
  115625. 5,
  115626. 9,
  115627. 4,
  115628. 10,
  115629. 3,
  115630. 11,
  115631. 2,
  115632. 12,
  115633. 1,
  115634. 13,
  115635. 0,
  115636. 14,
  115637. };
  115638. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115639. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115640. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115641. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115642. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115643. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115644. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115645. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115646. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115647. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115648. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115649. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115650. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115651. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115652. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115653. 15,
  115654. };
  115655. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115656. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115657. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115658. };
  115659. static long _vq_quantmap__44c3_s_p9_1[] = {
  115660. 13, 11, 9, 7, 5, 3, 1, 0,
  115661. 2, 4, 6, 8, 10, 12, 14,
  115662. };
  115663. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115664. _vq_quantthresh__44c3_s_p9_1,
  115665. _vq_quantmap__44c3_s_p9_1,
  115666. 15,
  115667. 15
  115668. };
  115669. static static_codebook _44c3_s_p9_1 = {
  115670. 2, 225,
  115671. _vq_lengthlist__44c3_s_p9_1,
  115672. 1, -522338304, 1620115456, 4, 0,
  115673. _vq_quantlist__44c3_s_p9_1,
  115674. NULL,
  115675. &_vq_auxt__44c3_s_p9_1,
  115676. NULL,
  115677. 0
  115678. };
  115679. static long _vq_quantlist__44c3_s_p9_2[] = {
  115680. 8,
  115681. 7,
  115682. 9,
  115683. 6,
  115684. 10,
  115685. 5,
  115686. 11,
  115687. 4,
  115688. 12,
  115689. 3,
  115690. 13,
  115691. 2,
  115692. 14,
  115693. 1,
  115694. 15,
  115695. 0,
  115696. 16,
  115697. };
  115698. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115699. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115700. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115701. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115702. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115703. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115704. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115705. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115706. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115707. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115708. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115709. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115710. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115711. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115712. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115713. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115714. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115715. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115716. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115717. 10,
  115718. };
  115719. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115720. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115721. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115722. };
  115723. static long _vq_quantmap__44c3_s_p9_2[] = {
  115724. 15, 13, 11, 9, 7, 5, 3, 1,
  115725. 0, 2, 4, 6, 8, 10, 12, 14,
  115726. 16,
  115727. };
  115728. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115729. _vq_quantthresh__44c3_s_p9_2,
  115730. _vq_quantmap__44c3_s_p9_2,
  115731. 17,
  115732. 17
  115733. };
  115734. static static_codebook _44c3_s_p9_2 = {
  115735. 2, 289,
  115736. _vq_lengthlist__44c3_s_p9_2,
  115737. 1, -529530880, 1611661312, 5, 0,
  115738. _vq_quantlist__44c3_s_p9_2,
  115739. NULL,
  115740. &_vq_auxt__44c3_s_p9_2,
  115741. NULL,
  115742. 0
  115743. };
  115744. static long _huff_lengthlist__44c3_s_short[] = {
  115745. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115746. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115747. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115748. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115749. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115750. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115751. 6, 8, 9,11,
  115752. };
  115753. static static_codebook _huff_book__44c3_s_short = {
  115754. 2, 100,
  115755. _huff_lengthlist__44c3_s_short,
  115756. 0, 0, 0, 0, 0,
  115757. NULL,
  115758. NULL,
  115759. NULL,
  115760. NULL,
  115761. 0
  115762. };
  115763. static long _huff_lengthlist__44c4_s_long[] = {
  115764. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115765. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115766. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115767. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115768. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115769. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115770. 9, 8, 7, 7,
  115771. };
  115772. static static_codebook _huff_book__44c4_s_long = {
  115773. 2, 100,
  115774. _huff_lengthlist__44c4_s_long,
  115775. 0, 0, 0, 0, 0,
  115776. NULL,
  115777. NULL,
  115778. NULL,
  115779. NULL,
  115780. 0
  115781. };
  115782. static long _vq_quantlist__44c4_s_p1_0[] = {
  115783. 1,
  115784. 0,
  115785. 2,
  115786. };
  115787. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115788. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115789. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115793. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115794. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115798. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115799. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115834. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115839. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  115844. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115879. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115880. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115885. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115890. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116096. 0, 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,
  116199. };
  116200. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116201. -0.5, 0.5,
  116202. };
  116203. static long _vq_quantmap__44c4_s_p1_0[] = {
  116204. 1, 0, 2,
  116205. };
  116206. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116207. _vq_quantthresh__44c4_s_p1_0,
  116208. _vq_quantmap__44c4_s_p1_0,
  116209. 3,
  116210. 3
  116211. };
  116212. static static_codebook _44c4_s_p1_0 = {
  116213. 8, 6561,
  116214. _vq_lengthlist__44c4_s_p1_0,
  116215. 1, -535822336, 1611661312, 2, 0,
  116216. _vq_quantlist__44c4_s_p1_0,
  116217. NULL,
  116218. &_vq_auxt__44c4_s_p1_0,
  116219. NULL,
  116220. 0
  116221. };
  116222. static long _vq_quantlist__44c4_s_p2_0[] = {
  116223. 2,
  116224. 1,
  116225. 3,
  116226. 0,
  116227. 4,
  116228. };
  116229. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116230. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116231. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116232. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116233. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116234. 0, 0,10,10, 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, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116240. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116241. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116242. 9, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116248. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116249. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 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. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116256. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116257. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116269. 0,
  116270. };
  116271. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116272. -1.5, -0.5, 0.5, 1.5,
  116273. };
  116274. static long _vq_quantmap__44c4_s_p2_0[] = {
  116275. 3, 1, 0, 2, 4,
  116276. };
  116277. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116278. _vq_quantthresh__44c4_s_p2_0,
  116279. _vq_quantmap__44c4_s_p2_0,
  116280. 5,
  116281. 5
  116282. };
  116283. static static_codebook _44c4_s_p2_0 = {
  116284. 4, 625,
  116285. _vq_lengthlist__44c4_s_p2_0,
  116286. 1, -533725184, 1611661312, 3, 0,
  116287. _vq_quantlist__44c4_s_p2_0,
  116288. NULL,
  116289. &_vq_auxt__44c4_s_p2_0,
  116290. NULL,
  116291. 0
  116292. };
  116293. static long _vq_quantlist__44c4_s_p3_0[] = {
  116294. 2,
  116295. 1,
  116296. 3,
  116297. 0,
  116298. 4,
  116299. };
  116300. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116301. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116304. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116307. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116340. 0,
  116341. };
  116342. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116343. -1.5, -0.5, 0.5, 1.5,
  116344. };
  116345. static long _vq_quantmap__44c4_s_p3_0[] = {
  116346. 3, 1, 0, 2, 4,
  116347. };
  116348. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116349. _vq_quantthresh__44c4_s_p3_0,
  116350. _vq_quantmap__44c4_s_p3_0,
  116351. 5,
  116352. 5
  116353. };
  116354. static static_codebook _44c4_s_p3_0 = {
  116355. 4, 625,
  116356. _vq_lengthlist__44c4_s_p3_0,
  116357. 1, -533725184, 1611661312, 3, 0,
  116358. _vq_quantlist__44c4_s_p3_0,
  116359. NULL,
  116360. &_vq_auxt__44c4_s_p3_0,
  116361. NULL,
  116362. 0
  116363. };
  116364. static long _vq_quantlist__44c4_s_p4_0[] = {
  116365. 4,
  116366. 3,
  116367. 5,
  116368. 2,
  116369. 6,
  116370. 1,
  116371. 7,
  116372. 0,
  116373. 8,
  116374. };
  116375. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116376. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116377. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116378. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116379. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116380. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116381. 0,
  116382. };
  116383. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116384. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116385. };
  116386. static long _vq_quantmap__44c4_s_p4_0[] = {
  116387. 7, 5, 3, 1, 0, 2, 4, 6,
  116388. 8,
  116389. };
  116390. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116391. _vq_quantthresh__44c4_s_p4_0,
  116392. _vq_quantmap__44c4_s_p4_0,
  116393. 9,
  116394. 9
  116395. };
  116396. static static_codebook _44c4_s_p4_0 = {
  116397. 2, 81,
  116398. _vq_lengthlist__44c4_s_p4_0,
  116399. 1, -531628032, 1611661312, 4, 0,
  116400. _vq_quantlist__44c4_s_p4_0,
  116401. NULL,
  116402. &_vq_auxt__44c4_s_p4_0,
  116403. NULL,
  116404. 0
  116405. };
  116406. static long _vq_quantlist__44c4_s_p5_0[] = {
  116407. 4,
  116408. 3,
  116409. 5,
  116410. 2,
  116411. 6,
  116412. 1,
  116413. 7,
  116414. 0,
  116415. 8,
  116416. };
  116417. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116418. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116419. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116420. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116421. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116422. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116423. 10,
  116424. };
  116425. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116426. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116427. };
  116428. static long _vq_quantmap__44c4_s_p5_0[] = {
  116429. 7, 5, 3, 1, 0, 2, 4, 6,
  116430. 8,
  116431. };
  116432. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116433. _vq_quantthresh__44c4_s_p5_0,
  116434. _vq_quantmap__44c4_s_p5_0,
  116435. 9,
  116436. 9
  116437. };
  116438. static static_codebook _44c4_s_p5_0 = {
  116439. 2, 81,
  116440. _vq_lengthlist__44c4_s_p5_0,
  116441. 1, -531628032, 1611661312, 4, 0,
  116442. _vq_quantlist__44c4_s_p5_0,
  116443. NULL,
  116444. &_vq_auxt__44c4_s_p5_0,
  116445. NULL,
  116446. 0
  116447. };
  116448. static long _vq_quantlist__44c4_s_p6_0[] = {
  116449. 8,
  116450. 7,
  116451. 9,
  116452. 6,
  116453. 10,
  116454. 5,
  116455. 11,
  116456. 4,
  116457. 12,
  116458. 3,
  116459. 13,
  116460. 2,
  116461. 14,
  116462. 1,
  116463. 15,
  116464. 0,
  116465. 16,
  116466. };
  116467. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116468. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116469. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116470. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116471. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116472. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116473. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116474. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116475. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116476. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116477. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116478. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116479. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116480. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116481. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116482. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116483. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116484. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116485. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116486. 13,
  116487. };
  116488. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116489. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116490. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116491. };
  116492. static long _vq_quantmap__44c4_s_p6_0[] = {
  116493. 15, 13, 11, 9, 7, 5, 3, 1,
  116494. 0, 2, 4, 6, 8, 10, 12, 14,
  116495. 16,
  116496. };
  116497. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116498. _vq_quantthresh__44c4_s_p6_0,
  116499. _vq_quantmap__44c4_s_p6_0,
  116500. 17,
  116501. 17
  116502. };
  116503. static static_codebook _44c4_s_p6_0 = {
  116504. 2, 289,
  116505. _vq_lengthlist__44c4_s_p6_0,
  116506. 1, -529530880, 1611661312, 5, 0,
  116507. _vq_quantlist__44c4_s_p6_0,
  116508. NULL,
  116509. &_vq_auxt__44c4_s_p6_0,
  116510. NULL,
  116511. 0
  116512. };
  116513. static long _vq_quantlist__44c4_s_p7_0[] = {
  116514. 1,
  116515. 0,
  116516. 2,
  116517. };
  116518. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116519. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116520. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116521. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116522. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116523. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116524. 10,
  116525. };
  116526. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116527. -5.5, 5.5,
  116528. };
  116529. static long _vq_quantmap__44c4_s_p7_0[] = {
  116530. 1, 0, 2,
  116531. };
  116532. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116533. _vq_quantthresh__44c4_s_p7_0,
  116534. _vq_quantmap__44c4_s_p7_0,
  116535. 3,
  116536. 3
  116537. };
  116538. static static_codebook _44c4_s_p7_0 = {
  116539. 4, 81,
  116540. _vq_lengthlist__44c4_s_p7_0,
  116541. 1, -529137664, 1618345984, 2, 0,
  116542. _vq_quantlist__44c4_s_p7_0,
  116543. NULL,
  116544. &_vq_auxt__44c4_s_p7_0,
  116545. NULL,
  116546. 0
  116547. };
  116548. static long _vq_quantlist__44c4_s_p7_1[] = {
  116549. 5,
  116550. 4,
  116551. 6,
  116552. 3,
  116553. 7,
  116554. 2,
  116555. 8,
  116556. 1,
  116557. 9,
  116558. 0,
  116559. 10,
  116560. };
  116561. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116562. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116563. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116564. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116565. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116566. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116567. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116568. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116569. 10,10,10, 8, 8, 8, 8, 9, 9,
  116570. };
  116571. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116572. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116573. 3.5, 4.5,
  116574. };
  116575. static long _vq_quantmap__44c4_s_p7_1[] = {
  116576. 9, 7, 5, 3, 1, 0, 2, 4,
  116577. 6, 8, 10,
  116578. };
  116579. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116580. _vq_quantthresh__44c4_s_p7_1,
  116581. _vq_quantmap__44c4_s_p7_1,
  116582. 11,
  116583. 11
  116584. };
  116585. static static_codebook _44c4_s_p7_1 = {
  116586. 2, 121,
  116587. _vq_lengthlist__44c4_s_p7_1,
  116588. 1, -531365888, 1611661312, 4, 0,
  116589. _vq_quantlist__44c4_s_p7_1,
  116590. NULL,
  116591. &_vq_auxt__44c4_s_p7_1,
  116592. NULL,
  116593. 0
  116594. };
  116595. static long _vq_quantlist__44c4_s_p8_0[] = {
  116596. 6,
  116597. 5,
  116598. 7,
  116599. 4,
  116600. 8,
  116601. 3,
  116602. 9,
  116603. 2,
  116604. 10,
  116605. 1,
  116606. 11,
  116607. 0,
  116608. 12,
  116609. };
  116610. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116611. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116612. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116613. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116614. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116615. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116616. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116617. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116618. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116619. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116620. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116621. 0,13,12,12,12,12,12,13,13,
  116622. };
  116623. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116624. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116625. 12.5, 17.5, 22.5, 27.5,
  116626. };
  116627. static long _vq_quantmap__44c4_s_p8_0[] = {
  116628. 11, 9, 7, 5, 3, 1, 0, 2,
  116629. 4, 6, 8, 10, 12,
  116630. };
  116631. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116632. _vq_quantthresh__44c4_s_p8_0,
  116633. _vq_quantmap__44c4_s_p8_0,
  116634. 13,
  116635. 13
  116636. };
  116637. static static_codebook _44c4_s_p8_0 = {
  116638. 2, 169,
  116639. _vq_lengthlist__44c4_s_p8_0,
  116640. 1, -526516224, 1616117760, 4, 0,
  116641. _vq_quantlist__44c4_s_p8_0,
  116642. NULL,
  116643. &_vq_auxt__44c4_s_p8_0,
  116644. NULL,
  116645. 0
  116646. };
  116647. static long _vq_quantlist__44c4_s_p8_1[] = {
  116648. 2,
  116649. 1,
  116650. 3,
  116651. 0,
  116652. 4,
  116653. };
  116654. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116655. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116656. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116657. };
  116658. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116659. -1.5, -0.5, 0.5, 1.5,
  116660. };
  116661. static long _vq_quantmap__44c4_s_p8_1[] = {
  116662. 3, 1, 0, 2, 4,
  116663. };
  116664. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116665. _vq_quantthresh__44c4_s_p8_1,
  116666. _vq_quantmap__44c4_s_p8_1,
  116667. 5,
  116668. 5
  116669. };
  116670. static static_codebook _44c4_s_p8_1 = {
  116671. 2, 25,
  116672. _vq_lengthlist__44c4_s_p8_1,
  116673. 1, -533725184, 1611661312, 3, 0,
  116674. _vq_quantlist__44c4_s_p8_1,
  116675. NULL,
  116676. &_vq_auxt__44c4_s_p8_1,
  116677. NULL,
  116678. 0
  116679. };
  116680. static long _vq_quantlist__44c4_s_p9_0[] = {
  116681. 6,
  116682. 5,
  116683. 7,
  116684. 4,
  116685. 8,
  116686. 3,
  116687. 9,
  116688. 2,
  116689. 10,
  116690. 1,
  116691. 11,
  116692. 0,
  116693. 12,
  116694. };
  116695. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116696. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116697. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116698. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116699. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116700. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116701. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116702. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116703. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116704. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116705. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116706. 12,12,12,12,12,12,12,12,12,
  116707. };
  116708. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116709. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116710. 787.5, 1102.5, 1417.5, 1732.5,
  116711. };
  116712. static long _vq_quantmap__44c4_s_p9_0[] = {
  116713. 11, 9, 7, 5, 3, 1, 0, 2,
  116714. 4, 6, 8, 10, 12,
  116715. };
  116716. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116717. _vq_quantthresh__44c4_s_p9_0,
  116718. _vq_quantmap__44c4_s_p9_0,
  116719. 13,
  116720. 13
  116721. };
  116722. static static_codebook _44c4_s_p9_0 = {
  116723. 2, 169,
  116724. _vq_lengthlist__44c4_s_p9_0,
  116725. 1, -513964032, 1628680192, 4, 0,
  116726. _vq_quantlist__44c4_s_p9_0,
  116727. NULL,
  116728. &_vq_auxt__44c4_s_p9_0,
  116729. NULL,
  116730. 0
  116731. };
  116732. static long _vq_quantlist__44c4_s_p9_1[] = {
  116733. 7,
  116734. 6,
  116735. 8,
  116736. 5,
  116737. 9,
  116738. 4,
  116739. 10,
  116740. 3,
  116741. 11,
  116742. 2,
  116743. 12,
  116744. 1,
  116745. 13,
  116746. 0,
  116747. 14,
  116748. };
  116749. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116750. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116751. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116752. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116753. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116754. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116755. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116756. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116757. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116758. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116759. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116760. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116761. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116762. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116763. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116764. 15,
  116765. };
  116766. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116767. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116768. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116769. };
  116770. static long _vq_quantmap__44c4_s_p9_1[] = {
  116771. 13, 11, 9, 7, 5, 3, 1, 0,
  116772. 2, 4, 6, 8, 10, 12, 14,
  116773. };
  116774. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116775. _vq_quantthresh__44c4_s_p9_1,
  116776. _vq_quantmap__44c4_s_p9_1,
  116777. 15,
  116778. 15
  116779. };
  116780. static static_codebook _44c4_s_p9_1 = {
  116781. 2, 225,
  116782. _vq_lengthlist__44c4_s_p9_1,
  116783. 1, -520986624, 1620377600, 4, 0,
  116784. _vq_quantlist__44c4_s_p9_1,
  116785. NULL,
  116786. &_vq_auxt__44c4_s_p9_1,
  116787. NULL,
  116788. 0
  116789. };
  116790. static long _vq_quantlist__44c4_s_p9_2[] = {
  116791. 10,
  116792. 9,
  116793. 11,
  116794. 8,
  116795. 12,
  116796. 7,
  116797. 13,
  116798. 6,
  116799. 14,
  116800. 5,
  116801. 15,
  116802. 4,
  116803. 16,
  116804. 3,
  116805. 17,
  116806. 2,
  116807. 18,
  116808. 1,
  116809. 19,
  116810. 0,
  116811. 20,
  116812. };
  116813. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116814. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116815. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116816. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116817. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116818. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116819. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116820. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116821. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116822. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116823. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116824. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116825. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116826. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116827. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116828. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116829. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116830. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116831. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116832. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116833. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116834. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116835. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116836. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116837. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116838. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116839. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116840. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116841. 10,10,10,10,10,10,10,10,10,
  116842. };
  116843. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116844. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116845. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116846. 6.5, 7.5, 8.5, 9.5,
  116847. };
  116848. static long _vq_quantmap__44c4_s_p9_2[] = {
  116849. 19, 17, 15, 13, 11, 9, 7, 5,
  116850. 3, 1, 0, 2, 4, 6, 8, 10,
  116851. 12, 14, 16, 18, 20,
  116852. };
  116853. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116854. _vq_quantthresh__44c4_s_p9_2,
  116855. _vq_quantmap__44c4_s_p9_2,
  116856. 21,
  116857. 21
  116858. };
  116859. static static_codebook _44c4_s_p9_2 = {
  116860. 2, 441,
  116861. _vq_lengthlist__44c4_s_p9_2,
  116862. 1, -529268736, 1611661312, 5, 0,
  116863. _vq_quantlist__44c4_s_p9_2,
  116864. NULL,
  116865. &_vq_auxt__44c4_s_p9_2,
  116866. NULL,
  116867. 0
  116868. };
  116869. static long _huff_lengthlist__44c4_s_short[] = {
  116870. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116871. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116872. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116873. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116874. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116875. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116876. 7, 9,12,17,
  116877. };
  116878. static static_codebook _huff_book__44c4_s_short = {
  116879. 2, 100,
  116880. _huff_lengthlist__44c4_s_short,
  116881. 0, 0, 0, 0, 0,
  116882. NULL,
  116883. NULL,
  116884. NULL,
  116885. NULL,
  116886. 0
  116887. };
  116888. static long _huff_lengthlist__44c5_s_long[] = {
  116889. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116890. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116891. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116892. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116893. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116894. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116895. 9, 8, 7, 7,
  116896. };
  116897. static static_codebook _huff_book__44c5_s_long = {
  116898. 2, 100,
  116899. _huff_lengthlist__44c5_s_long,
  116900. 0, 0, 0, 0, 0,
  116901. NULL,
  116902. NULL,
  116903. NULL,
  116904. NULL,
  116905. 0
  116906. };
  116907. static long _vq_quantlist__44c5_s_p1_0[] = {
  116908. 1,
  116909. 0,
  116910. 2,
  116911. };
  116912. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116913. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116914. 0, 0, 4, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116918. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116919. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116923. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116924. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116959. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116964. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  116965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116969. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  116970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117004. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117005. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  117010. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  117015. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  117016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117221. 0, 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,
  117324. };
  117325. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117326. -0.5, 0.5,
  117327. };
  117328. static long _vq_quantmap__44c5_s_p1_0[] = {
  117329. 1, 0, 2,
  117330. };
  117331. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117332. _vq_quantthresh__44c5_s_p1_0,
  117333. _vq_quantmap__44c5_s_p1_0,
  117334. 3,
  117335. 3
  117336. };
  117337. static static_codebook _44c5_s_p1_0 = {
  117338. 8, 6561,
  117339. _vq_lengthlist__44c5_s_p1_0,
  117340. 1, -535822336, 1611661312, 2, 0,
  117341. _vq_quantlist__44c5_s_p1_0,
  117342. NULL,
  117343. &_vq_auxt__44c5_s_p1_0,
  117344. NULL,
  117345. 0
  117346. };
  117347. static long _vq_quantlist__44c5_s_p2_0[] = {
  117348. 2,
  117349. 1,
  117350. 3,
  117351. 0,
  117352. 4,
  117353. };
  117354. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117355. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117356. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117357. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117358. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117359. 0, 0,10,10, 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, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117365. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117366. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117367. 10, 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, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117373. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117374. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 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. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117381. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117382. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117394. 0,
  117395. };
  117396. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117397. -1.5, -0.5, 0.5, 1.5,
  117398. };
  117399. static long _vq_quantmap__44c5_s_p2_0[] = {
  117400. 3, 1, 0, 2, 4,
  117401. };
  117402. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117403. _vq_quantthresh__44c5_s_p2_0,
  117404. _vq_quantmap__44c5_s_p2_0,
  117405. 5,
  117406. 5
  117407. };
  117408. static static_codebook _44c5_s_p2_0 = {
  117409. 4, 625,
  117410. _vq_lengthlist__44c5_s_p2_0,
  117411. 1, -533725184, 1611661312, 3, 0,
  117412. _vq_quantlist__44c5_s_p2_0,
  117413. NULL,
  117414. &_vq_auxt__44c5_s_p2_0,
  117415. NULL,
  117416. 0
  117417. };
  117418. static long _vq_quantlist__44c5_s_p3_0[] = {
  117419. 2,
  117420. 1,
  117421. 3,
  117422. 0,
  117423. 4,
  117424. };
  117425. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117426. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117429. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117432. 0, 0, 0, 0, 5, 6, 6, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117465. 0,
  117466. };
  117467. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117468. -1.5, -0.5, 0.5, 1.5,
  117469. };
  117470. static long _vq_quantmap__44c5_s_p3_0[] = {
  117471. 3, 1, 0, 2, 4,
  117472. };
  117473. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117474. _vq_quantthresh__44c5_s_p3_0,
  117475. _vq_quantmap__44c5_s_p3_0,
  117476. 5,
  117477. 5
  117478. };
  117479. static static_codebook _44c5_s_p3_0 = {
  117480. 4, 625,
  117481. _vq_lengthlist__44c5_s_p3_0,
  117482. 1, -533725184, 1611661312, 3, 0,
  117483. _vq_quantlist__44c5_s_p3_0,
  117484. NULL,
  117485. &_vq_auxt__44c5_s_p3_0,
  117486. NULL,
  117487. 0
  117488. };
  117489. static long _vq_quantlist__44c5_s_p4_0[] = {
  117490. 4,
  117491. 3,
  117492. 5,
  117493. 2,
  117494. 6,
  117495. 1,
  117496. 7,
  117497. 0,
  117498. 8,
  117499. };
  117500. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117501. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117502. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117503. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117504. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117505. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117506. 0,
  117507. };
  117508. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117509. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117510. };
  117511. static long _vq_quantmap__44c5_s_p4_0[] = {
  117512. 7, 5, 3, 1, 0, 2, 4, 6,
  117513. 8,
  117514. };
  117515. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117516. _vq_quantthresh__44c5_s_p4_0,
  117517. _vq_quantmap__44c5_s_p4_0,
  117518. 9,
  117519. 9
  117520. };
  117521. static static_codebook _44c5_s_p4_0 = {
  117522. 2, 81,
  117523. _vq_lengthlist__44c5_s_p4_0,
  117524. 1, -531628032, 1611661312, 4, 0,
  117525. _vq_quantlist__44c5_s_p4_0,
  117526. NULL,
  117527. &_vq_auxt__44c5_s_p4_0,
  117528. NULL,
  117529. 0
  117530. };
  117531. static long _vq_quantlist__44c5_s_p5_0[] = {
  117532. 4,
  117533. 3,
  117534. 5,
  117535. 2,
  117536. 6,
  117537. 1,
  117538. 7,
  117539. 0,
  117540. 8,
  117541. };
  117542. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117543. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117544. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117545. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117546. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117547. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117548. 10,
  117549. };
  117550. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117551. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117552. };
  117553. static long _vq_quantmap__44c5_s_p5_0[] = {
  117554. 7, 5, 3, 1, 0, 2, 4, 6,
  117555. 8,
  117556. };
  117557. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117558. _vq_quantthresh__44c5_s_p5_0,
  117559. _vq_quantmap__44c5_s_p5_0,
  117560. 9,
  117561. 9
  117562. };
  117563. static static_codebook _44c5_s_p5_0 = {
  117564. 2, 81,
  117565. _vq_lengthlist__44c5_s_p5_0,
  117566. 1, -531628032, 1611661312, 4, 0,
  117567. _vq_quantlist__44c5_s_p5_0,
  117568. NULL,
  117569. &_vq_auxt__44c5_s_p5_0,
  117570. NULL,
  117571. 0
  117572. };
  117573. static long _vq_quantlist__44c5_s_p6_0[] = {
  117574. 8,
  117575. 7,
  117576. 9,
  117577. 6,
  117578. 10,
  117579. 5,
  117580. 11,
  117581. 4,
  117582. 12,
  117583. 3,
  117584. 13,
  117585. 2,
  117586. 14,
  117587. 1,
  117588. 15,
  117589. 0,
  117590. 16,
  117591. };
  117592. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117593. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117594. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117595. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117596. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117597. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117598. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117599. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117600. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117601. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117602. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117603. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117604. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117605. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117606. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117607. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117608. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117609. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117610. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117611. 13,
  117612. };
  117613. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117614. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117615. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117616. };
  117617. static long _vq_quantmap__44c5_s_p6_0[] = {
  117618. 15, 13, 11, 9, 7, 5, 3, 1,
  117619. 0, 2, 4, 6, 8, 10, 12, 14,
  117620. 16,
  117621. };
  117622. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117623. _vq_quantthresh__44c5_s_p6_0,
  117624. _vq_quantmap__44c5_s_p6_0,
  117625. 17,
  117626. 17
  117627. };
  117628. static static_codebook _44c5_s_p6_0 = {
  117629. 2, 289,
  117630. _vq_lengthlist__44c5_s_p6_0,
  117631. 1, -529530880, 1611661312, 5, 0,
  117632. _vq_quantlist__44c5_s_p6_0,
  117633. NULL,
  117634. &_vq_auxt__44c5_s_p6_0,
  117635. NULL,
  117636. 0
  117637. };
  117638. static long _vq_quantlist__44c5_s_p7_0[] = {
  117639. 1,
  117640. 0,
  117641. 2,
  117642. };
  117643. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117644. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117645. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117646. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117647. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117648. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117649. 10,
  117650. };
  117651. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117652. -5.5, 5.5,
  117653. };
  117654. static long _vq_quantmap__44c5_s_p7_0[] = {
  117655. 1, 0, 2,
  117656. };
  117657. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117658. _vq_quantthresh__44c5_s_p7_0,
  117659. _vq_quantmap__44c5_s_p7_0,
  117660. 3,
  117661. 3
  117662. };
  117663. static static_codebook _44c5_s_p7_0 = {
  117664. 4, 81,
  117665. _vq_lengthlist__44c5_s_p7_0,
  117666. 1, -529137664, 1618345984, 2, 0,
  117667. _vq_quantlist__44c5_s_p7_0,
  117668. NULL,
  117669. &_vq_auxt__44c5_s_p7_0,
  117670. NULL,
  117671. 0
  117672. };
  117673. static long _vq_quantlist__44c5_s_p7_1[] = {
  117674. 5,
  117675. 4,
  117676. 6,
  117677. 3,
  117678. 7,
  117679. 2,
  117680. 8,
  117681. 1,
  117682. 9,
  117683. 0,
  117684. 10,
  117685. };
  117686. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117687. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117688. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117689. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117690. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117691. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117692. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117693. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117694. 10,10,10, 8, 8, 8, 8, 8, 8,
  117695. };
  117696. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117697. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117698. 3.5, 4.5,
  117699. };
  117700. static long _vq_quantmap__44c5_s_p7_1[] = {
  117701. 9, 7, 5, 3, 1, 0, 2, 4,
  117702. 6, 8, 10,
  117703. };
  117704. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117705. _vq_quantthresh__44c5_s_p7_1,
  117706. _vq_quantmap__44c5_s_p7_1,
  117707. 11,
  117708. 11
  117709. };
  117710. static static_codebook _44c5_s_p7_1 = {
  117711. 2, 121,
  117712. _vq_lengthlist__44c5_s_p7_1,
  117713. 1, -531365888, 1611661312, 4, 0,
  117714. _vq_quantlist__44c5_s_p7_1,
  117715. NULL,
  117716. &_vq_auxt__44c5_s_p7_1,
  117717. NULL,
  117718. 0
  117719. };
  117720. static long _vq_quantlist__44c5_s_p8_0[] = {
  117721. 6,
  117722. 5,
  117723. 7,
  117724. 4,
  117725. 8,
  117726. 3,
  117727. 9,
  117728. 2,
  117729. 10,
  117730. 1,
  117731. 11,
  117732. 0,
  117733. 12,
  117734. };
  117735. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117736. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117737. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117738. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117739. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117740. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117741. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117742. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117743. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117744. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117745. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117746. 0,12,12,12,12,12,12,13,13,
  117747. };
  117748. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117749. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117750. 12.5, 17.5, 22.5, 27.5,
  117751. };
  117752. static long _vq_quantmap__44c5_s_p8_0[] = {
  117753. 11, 9, 7, 5, 3, 1, 0, 2,
  117754. 4, 6, 8, 10, 12,
  117755. };
  117756. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117757. _vq_quantthresh__44c5_s_p8_0,
  117758. _vq_quantmap__44c5_s_p8_0,
  117759. 13,
  117760. 13
  117761. };
  117762. static static_codebook _44c5_s_p8_0 = {
  117763. 2, 169,
  117764. _vq_lengthlist__44c5_s_p8_0,
  117765. 1, -526516224, 1616117760, 4, 0,
  117766. _vq_quantlist__44c5_s_p8_0,
  117767. NULL,
  117768. &_vq_auxt__44c5_s_p8_0,
  117769. NULL,
  117770. 0
  117771. };
  117772. static long _vq_quantlist__44c5_s_p8_1[] = {
  117773. 2,
  117774. 1,
  117775. 3,
  117776. 0,
  117777. 4,
  117778. };
  117779. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117780. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117781. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117782. };
  117783. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117784. -1.5, -0.5, 0.5, 1.5,
  117785. };
  117786. static long _vq_quantmap__44c5_s_p8_1[] = {
  117787. 3, 1, 0, 2, 4,
  117788. };
  117789. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117790. _vq_quantthresh__44c5_s_p8_1,
  117791. _vq_quantmap__44c5_s_p8_1,
  117792. 5,
  117793. 5
  117794. };
  117795. static static_codebook _44c5_s_p8_1 = {
  117796. 2, 25,
  117797. _vq_lengthlist__44c5_s_p8_1,
  117798. 1, -533725184, 1611661312, 3, 0,
  117799. _vq_quantlist__44c5_s_p8_1,
  117800. NULL,
  117801. &_vq_auxt__44c5_s_p8_1,
  117802. NULL,
  117803. 0
  117804. };
  117805. static long _vq_quantlist__44c5_s_p9_0[] = {
  117806. 7,
  117807. 6,
  117808. 8,
  117809. 5,
  117810. 9,
  117811. 4,
  117812. 10,
  117813. 3,
  117814. 11,
  117815. 2,
  117816. 12,
  117817. 1,
  117818. 13,
  117819. 0,
  117820. 14,
  117821. };
  117822. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117823. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117824. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117825. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117826. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117827. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117828. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117829. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117830. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117831. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117832. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117833. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117834. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117835. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117836. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117837. 12,
  117838. };
  117839. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117840. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117841. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117842. };
  117843. static long _vq_quantmap__44c5_s_p9_0[] = {
  117844. 13, 11, 9, 7, 5, 3, 1, 0,
  117845. 2, 4, 6, 8, 10, 12, 14,
  117846. };
  117847. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117848. _vq_quantthresh__44c5_s_p9_0,
  117849. _vq_quantmap__44c5_s_p9_0,
  117850. 15,
  117851. 15
  117852. };
  117853. static static_codebook _44c5_s_p9_0 = {
  117854. 2, 225,
  117855. _vq_lengthlist__44c5_s_p9_0,
  117856. 1, -512522752, 1628852224, 4, 0,
  117857. _vq_quantlist__44c5_s_p9_0,
  117858. NULL,
  117859. &_vq_auxt__44c5_s_p9_0,
  117860. NULL,
  117861. 0
  117862. };
  117863. static long _vq_quantlist__44c5_s_p9_1[] = {
  117864. 8,
  117865. 7,
  117866. 9,
  117867. 6,
  117868. 10,
  117869. 5,
  117870. 11,
  117871. 4,
  117872. 12,
  117873. 3,
  117874. 13,
  117875. 2,
  117876. 14,
  117877. 1,
  117878. 15,
  117879. 0,
  117880. 16,
  117881. };
  117882. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117883. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117884. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117885. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117886. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117887. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117888. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117889. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117890. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117891. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117892. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117893. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117894. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117895. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117896. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117897. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117898. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117899. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117900. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117901. 15,
  117902. };
  117903. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117904. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117905. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117906. };
  117907. static long _vq_quantmap__44c5_s_p9_1[] = {
  117908. 15, 13, 11, 9, 7, 5, 3, 1,
  117909. 0, 2, 4, 6, 8, 10, 12, 14,
  117910. 16,
  117911. };
  117912. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117913. _vq_quantthresh__44c5_s_p9_1,
  117914. _vq_quantmap__44c5_s_p9_1,
  117915. 17,
  117916. 17
  117917. };
  117918. static static_codebook _44c5_s_p9_1 = {
  117919. 2, 289,
  117920. _vq_lengthlist__44c5_s_p9_1,
  117921. 1, -520814592, 1620377600, 5, 0,
  117922. _vq_quantlist__44c5_s_p9_1,
  117923. NULL,
  117924. &_vq_auxt__44c5_s_p9_1,
  117925. NULL,
  117926. 0
  117927. };
  117928. static long _vq_quantlist__44c5_s_p9_2[] = {
  117929. 10,
  117930. 9,
  117931. 11,
  117932. 8,
  117933. 12,
  117934. 7,
  117935. 13,
  117936. 6,
  117937. 14,
  117938. 5,
  117939. 15,
  117940. 4,
  117941. 16,
  117942. 3,
  117943. 17,
  117944. 2,
  117945. 18,
  117946. 1,
  117947. 19,
  117948. 0,
  117949. 20,
  117950. };
  117951. static long _vq_lengthlist__44c5_s_p9_2[] = {
  117952. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117953. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  117954. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  117955. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  117956. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  117957. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  117958. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  117959. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  117960. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  117961. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  117962. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117963. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  117964. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  117965. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  117966. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  117967. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  117968. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117969. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117970. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  117971. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  117972. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117973. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117974. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  117975. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  117976. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  117977. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117978. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  117979. 10,10,10,10,10,10,10,10,10,
  117980. };
  117981. static float _vq_quantthresh__44c5_s_p9_2[] = {
  117982. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117983. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117984. 6.5, 7.5, 8.5, 9.5,
  117985. };
  117986. static long _vq_quantmap__44c5_s_p9_2[] = {
  117987. 19, 17, 15, 13, 11, 9, 7, 5,
  117988. 3, 1, 0, 2, 4, 6, 8, 10,
  117989. 12, 14, 16, 18, 20,
  117990. };
  117991. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  117992. _vq_quantthresh__44c5_s_p9_2,
  117993. _vq_quantmap__44c5_s_p9_2,
  117994. 21,
  117995. 21
  117996. };
  117997. static static_codebook _44c5_s_p9_2 = {
  117998. 2, 441,
  117999. _vq_lengthlist__44c5_s_p9_2,
  118000. 1, -529268736, 1611661312, 5, 0,
  118001. _vq_quantlist__44c5_s_p9_2,
  118002. NULL,
  118003. &_vq_auxt__44c5_s_p9_2,
  118004. NULL,
  118005. 0
  118006. };
  118007. static long _huff_lengthlist__44c5_s_short[] = {
  118008. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  118009. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  118010. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  118011. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  118012. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  118013. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  118014. 6, 8,11,16,
  118015. };
  118016. static static_codebook _huff_book__44c5_s_short = {
  118017. 2, 100,
  118018. _huff_lengthlist__44c5_s_short,
  118019. 0, 0, 0, 0, 0,
  118020. NULL,
  118021. NULL,
  118022. NULL,
  118023. NULL,
  118024. 0
  118025. };
  118026. static long _huff_lengthlist__44c6_s_long[] = {
  118027. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118028. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118029. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118030. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118031. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118032. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118033. 11,10,10,12,
  118034. };
  118035. static static_codebook _huff_book__44c6_s_long = {
  118036. 2, 100,
  118037. _huff_lengthlist__44c6_s_long,
  118038. 0, 0, 0, 0, 0,
  118039. NULL,
  118040. NULL,
  118041. NULL,
  118042. NULL,
  118043. 0
  118044. };
  118045. static long _vq_quantlist__44c6_s_p1_0[] = {
  118046. 1,
  118047. 0,
  118048. 2,
  118049. };
  118050. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118051. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118052. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118053. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118054. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118055. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118056. 8,
  118057. };
  118058. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118059. -0.5, 0.5,
  118060. };
  118061. static long _vq_quantmap__44c6_s_p1_0[] = {
  118062. 1, 0, 2,
  118063. };
  118064. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118065. _vq_quantthresh__44c6_s_p1_0,
  118066. _vq_quantmap__44c6_s_p1_0,
  118067. 3,
  118068. 3
  118069. };
  118070. static static_codebook _44c6_s_p1_0 = {
  118071. 4, 81,
  118072. _vq_lengthlist__44c6_s_p1_0,
  118073. 1, -535822336, 1611661312, 2, 0,
  118074. _vq_quantlist__44c6_s_p1_0,
  118075. NULL,
  118076. &_vq_auxt__44c6_s_p1_0,
  118077. NULL,
  118078. 0
  118079. };
  118080. static long _vq_quantlist__44c6_s_p2_0[] = {
  118081. 2,
  118082. 1,
  118083. 3,
  118084. 0,
  118085. 4,
  118086. };
  118087. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118088. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118089. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118090. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118091. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118092. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118093. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118094. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118095. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118097. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118098. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118099. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118100. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118101. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118102. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118103. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118105. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118106. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118107. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118108. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118109. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118110. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118111. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118113. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118114. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118115. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118116. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118117. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118118. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118119. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118124. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118125. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118126. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118127. 13,
  118128. };
  118129. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118130. -1.5, -0.5, 0.5, 1.5,
  118131. };
  118132. static long _vq_quantmap__44c6_s_p2_0[] = {
  118133. 3, 1, 0, 2, 4,
  118134. };
  118135. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118136. _vq_quantthresh__44c6_s_p2_0,
  118137. _vq_quantmap__44c6_s_p2_0,
  118138. 5,
  118139. 5
  118140. };
  118141. static static_codebook _44c6_s_p2_0 = {
  118142. 4, 625,
  118143. _vq_lengthlist__44c6_s_p2_0,
  118144. 1, -533725184, 1611661312, 3, 0,
  118145. _vq_quantlist__44c6_s_p2_0,
  118146. NULL,
  118147. &_vq_auxt__44c6_s_p2_0,
  118148. NULL,
  118149. 0
  118150. };
  118151. static long _vq_quantlist__44c6_s_p3_0[] = {
  118152. 4,
  118153. 3,
  118154. 5,
  118155. 2,
  118156. 6,
  118157. 1,
  118158. 7,
  118159. 0,
  118160. 8,
  118161. };
  118162. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118163. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118164. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118165. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118166. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118168. 0,
  118169. };
  118170. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118171. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118172. };
  118173. static long _vq_quantmap__44c6_s_p3_0[] = {
  118174. 7, 5, 3, 1, 0, 2, 4, 6,
  118175. 8,
  118176. };
  118177. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118178. _vq_quantthresh__44c6_s_p3_0,
  118179. _vq_quantmap__44c6_s_p3_0,
  118180. 9,
  118181. 9
  118182. };
  118183. static static_codebook _44c6_s_p3_0 = {
  118184. 2, 81,
  118185. _vq_lengthlist__44c6_s_p3_0,
  118186. 1, -531628032, 1611661312, 4, 0,
  118187. _vq_quantlist__44c6_s_p3_0,
  118188. NULL,
  118189. &_vq_auxt__44c6_s_p3_0,
  118190. NULL,
  118191. 0
  118192. };
  118193. static long _vq_quantlist__44c6_s_p4_0[] = {
  118194. 8,
  118195. 7,
  118196. 9,
  118197. 6,
  118198. 10,
  118199. 5,
  118200. 11,
  118201. 4,
  118202. 12,
  118203. 3,
  118204. 13,
  118205. 2,
  118206. 14,
  118207. 1,
  118208. 15,
  118209. 0,
  118210. 16,
  118211. };
  118212. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118213. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118214. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118215. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118216. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118217. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118218. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118219. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118220. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118221. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118222. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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_p4_0[] = {
  118234. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118235. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118236. };
  118237. static long _vq_quantmap__44c6_s_p4_0[] = {
  118238. 15, 13, 11, 9, 7, 5, 3, 1,
  118239. 0, 2, 4, 6, 8, 10, 12, 14,
  118240. 16,
  118241. };
  118242. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118243. _vq_quantthresh__44c6_s_p4_0,
  118244. _vq_quantmap__44c6_s_p4_0,
  118245. 17,
  118246. 17
  118247. };
  118248. static static_codebook _44c6_s_p4_0 = {
  118249. 2, 289,
  118250. _vq_lengthlist__44c6_s_p4_0,
  118251. 1, -529530880, 1611661312, 5, 0,
  118252. _vq_quantlist__44c6_s_p4_0,
  118253. NULL,
  118254. &_vq_auxt__44c6_s_p4_0,
  118255. NULL,
  118256. 0
  118257. };
  118258. static long _vq_quantlist__44c6_s_p5_0[] = {
  118259. 1,
  118260. 0,
  118261. 2,
  118262. };
  118263. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118264. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118265. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118266. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118267. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118268. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118269. 12,
  118270. };
  118271. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118272. -5.5, 5.5,
  118273. };
  118274. static long _vq_quantmap__44c6_s_p5_0[] = {
  118275. 1, 0, 2,
  118276. };
  118277. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118278. _vq_quantthresh__44c6_s_p5_0,
  118279. _vq_quantmap__44c6_s_p5_0,
  118280. 3,
  118281. 3
  118282. };
  118283. static static_codebook _44c6_s_p5_0 = {
  118284. 4, 81,
  118285. _vq_lengthlist__44c6_s_p5_0,
  118286. 1, -529137664, 1618345984, 2, 0,
  118287. _vq_quantlist__44c6_s_p5_0,
  118288. NULL,
  118289. &_vq_auxt__44c6_s_p5_0,
  118290. NULL,
  118291. 0
  118292. };
  118293. static long _vq_quantlist__44c6_s_p5_1[] = {
  118294. 5,
  118295. 4,
  118296. 6,
  118297. 3,
  118298. 7,
  118299. 2,
  118300. 8,
  118301. 1,
  118302. 9,
  118303. 0,
  118304. 10,
  118305. };
  118306. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118307. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118308. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118309. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118310. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118311. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118312. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118313. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118314. 11,10,10, 7, 7, 8, 8, 8, 8,
  118315. };
  118316. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118317. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118318. 3.5, 4.5,
  118319. };
  118320. static long _vq_quantmap__44c6_s_p5_1[] = {
  118321. 9, 7, 5, 3, 1, 0, 2, 4,
  118322. 6, 8, 10,
  118323. };
  118324. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118325. _vq_quantthresh__44c6_s_p5_1,
  118326. _vq_quantmap__44c6_s_p5_1,
  118327. 11,
  118328. 11
  118329. };
  118330. static static_codebook _44c6_s_p5_1 = {
  118331. 2, 121,
  118332. _vq_lengthlist__44c6_s_p5_1,
  118333. 1, -531365888, 1611661312, 4, 0,
  118334. _vq_quantlist__44c6_s_p5_1,
  118335. NULL,
  118336. &_vq_auxt__44c6_s_p5_1,
  118337. NULL,
  118338. 0
  118339. };
  118340. static long _vq_quantlist__44c6_s_p6_0[] = {
  118341. 6,
  118342. 5,
  118343. 7,
  118344. 4,
  118345. 8,
  118346. 3,
  118347. 9,
  118348. 2,
  118349. 10,
  118350. 1,
  118351. 11,
  118352. 0,
  118353. 12,
  118354. };
  118355. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118356. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118357. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118358. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118359. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118360. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118361. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118366. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118367. };
  118368. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118369. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118370. 12.5, 17.5, 22.5, 27.5,
  118371. };
  118372. static long _vq_quantmap__44c6_s_p6_0[] = {
  118373. 11, 9, 7, 5, 3, 1, 0, 2,
  118374. 4, 6, 8, 10, 12,
  118375. };
  118376. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118377. _vq_quantthresh__44c6_s_p6_0,
  118378. _vq_quantmap__44c6_s_p6_0,
  118379. 13,
  118380. 13
  118381. };
  118382. static static_codebook _44c6_s_p6_0 = {
  118383. 2, 169,
  118384. _vq_lengthlist__44c6_s_p6_0,
  118385. 1, -526516224, 1616117760, 4, 0,
  118386. _vq_quantlist__44c6_s_p6_0,
  118387. NULL,
  118388. &_vq_auxt__44c6_s_p6_0,
  118389. NULL,
  118390. 0
  118391. };
  118392. static long _vq_quantlist__44c6_s_p6_1[] = {
  118393. 2,
  118394. 1,
  118395. 3,
  118396. 0,
  118397. 4,
  118398. };
  118399. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118400. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118401. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118402. };
  118403. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118404. -1.5, -0.5, 0.5, 1.5,
  118405. };
  118406. static long _vq_quantmap__44c6_s_p6_1[] = {
  118407. 3, 1, 0, 2, 4,
  118408. };
  118409. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118410. _vq_quantthresh__44c6_s_p6_1,
  118411. _vq_quantmap__44c6_s_p6_1,
  118412. 5,
  118413. 5
  118414. };
  118415. static static_codebook _44c6_s_p6_1 = {
  118416. 2, 25,
  118417. _vq_lengthlist__44c6_s_p6_1,
  118418. 1, -533725184, 1611661312, 3, 0,
  118419. _vq_quantlist__44c6_s_p6_1,
  118420. NULL,
  118421. &_vq_auxt__44c6_s_p6_1,
  118422. NULL,
  118423. 0
  118424. };
  118425. static long _vq_quantlist__44c6_s_p7_0[] = {
  118426. 6,
  118427. 5,
  118428. 7,
  118429. 4,
  118430. 8,
  118431. 3,
  118432. 9,
  118433. 2,
  118434. 10,
  118435. 1,
  118436. 11,
  118437. 0,
  118438. 12,
  118439. };
  118440. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118441. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118442. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118443. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118444. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118445. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118446. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118447. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118448. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118449. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118450. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118451. 20,13,13,13,13,13,13,14,14,
  118452. };
  118453. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118454. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118455. 27.5, 38.5, 49.5, 60.5,
  118456. };
  118457. static long _vq_quantmap__44c6_s_p7_0[] = {
  118458. 11, 9, 7, 5, 3, 1, 0, 2,
  118459. 4, 6, 8, 10, 12,
  118460. };
  118461. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118462. _vq_quantthresh__44c6_s_p7_0,
  118463. _vq_quantmap__44c6_s_p7_0,
  118464. 13,
  118465. 13
  118466. };
  118467. static static_codebook _44c6_s_p7_0 = {
  118468. 2, 169,
  118469. _vq_lengthlist__44c6_s_p7_0,
  118470. 1, -523206656, 1618345984, 4, 0,
  118471. _vq_quantlist__44c6_s_p7_0,
  118472. NULL,
  118473. &_vq_auxt__44c6_s_p7_0,
  118474. NULL,
  118475. 0
  118476. };
  118477. static long _vq_quantlist__44c6_s_p7_1[] = {
  118478. 5,
  118479. 4,
  118480. 6,
  118481. 3,
  118482. 7,
  118483. 2,
  118484. 8,
  118485. 1,
  118486. 9,
  118487. 0,
  118488. 10,
  118489. };
  118490. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118491. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118492. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118493. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118494. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118495. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118496. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118497. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118498. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118499. };
  118500. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118501. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118502. 3.5, 4.5,
  118503. };
  118504. static long _vq_quantmap__44c6_s_p7_1[] = {
  118505. 9, 7, 5, 3, 1, 0, 2, 4,
  118506. 6, 8, 10,
  118507. };
  118508. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118509. _vq_quantthresh__44c6_s_p7_1,
  118510. _vq_quantmap__44c6_s_p7_1,
  118511. 11,
  118512. 11
  118513. };
  118514. static static_codebook _44c6_s_p7_1 = {
  118515. 2, 121,
  118516. _vq_lengthlist__44c6_s_p7_1,
  118517. 1, -531365888, 1611661312, 4, 0,
  118518. _vq_quantlist__44c6_s_p7_1,
  118519. NULL,
  118520. &_vq_auxt__44c6_s_p7_1,
  118521. NULL,
  118522. 0
  118523. };
  118524. static long _vq_quantlist__44c6_s_p8_0[] = {
  118525. 7,
  118526. 6,
  118527. 8,
  118528. 5,
  118529. 9,
  118530. 4,
  118531. 10,
  118532. 3,
  118533. 11,
  118534. 2,
  118535. 12,
  118536. 1,
  118537. 13,
  118538. 0,
  118539. 14,
  118540. };
  118541. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118542. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118543. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118544. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118545. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118546. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118547. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118548. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118549. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118550. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118551. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118552. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118553. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118554. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118555. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118556. 14,
  118557. };
  118558. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118559. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118560. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118561. };
  118562. static long _vq_quantmap__44c6_s_p8_0[] = {
  118563. 13, 11, 9, 7, 5, 3, 1, 0,
  118564. 2, 4, 6, 8, 10, 12, 14,
  118565. };
  118566. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118567. _vq_quantthresh__44c6_s_p8_0,
  118568. _vq_quantmap__44c6_s_p8_0,
  118569. 15,
  118570. 15
  118571. };
  118572. static static_codebook _44c6_s_p8_0 = {
  118573. 2, 225,
  118574. _vq_lengthlist__44c6_s_p8_0,
  118575. 1, -520986624, 1620377600, 4, 0,
  118576. _vq_quantlist__44c6_s_p8_0,
  118577. NULL,
  118578. &_vq_auxt__44c6_s_p8_0,
  118579. NULL,
  118580. 0
  118581. };
  118582. static long _vq_quantlist__44c6_s_p8_1[] = {
  118583. 10,
  118584. 9,
  118585. 11,
  118586. 8,
  118587. 12,
  118588. 7,
  118589. 13,
  118590. 6,
  118591. 14,
  118592. 5,
  118593. 15,
  118594. 4,
  118595. 16,
  118596. 3,
  118597. 17,
  118598. 2,
  118599. 18,
  118600. 1,
  118601. 19,
  118602. 0,
  118603. 20,
  118604. };
  118605. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118606. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118607. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118608. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118609. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118610. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118611. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118612. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118613. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118614. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118615. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118616. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118617. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118618. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118619. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118620. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118621. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118622. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118623. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118624. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118625. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118626. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118627. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118628. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118629. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118630. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118631. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118632. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118633. 10,10,10,10,10,10,10,10,10,
  118634. };
  118635. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118636. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118637. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118638. 6.5, 7.5, 8.5, 9.5,
  118639. };
  118640. static long _vq_quantmap__44c6_s_p8_1[] = {
  118641. 19, 17, 15, 13, 11, 9, 7, 5,
  118642. 3, 1, 0, 2, 4, 6, 8, 10,
  118643. 12, 14, 16, 18, 20,
  118644. };
  118645. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118646. _vq_quantthresh__44c6_s_p8_1,
  118647. _vq_quantmap__44c6_s_p8_1,
  118648. 21,
  118649. 21
  118650. };
  118651. static static_codebook _44c6_s_p8_1 = {
  118652. 2, 441,
  118653. _vq_lengthlist__44c6_s_p8_1,
  118654. 1, -529268736, 1611661312, 5, 0,
  118655. _vq_quantlist__44c6_s_p8_1,
  118656. NULL,
  118657. &_vq_auxt__44c6_s_p8_1,
  118658. NULL,
  118659. 0
  118660. };
  118661. static long _vq_quantlist__44c6_s_p9_0[] = {
  118662. 6,
  118663. 5,
  118664. 7,
  118665. 4,
  118666. 8,
  118667. 3,
  118668. 9,
  118669. 2,
  118670. 10,
  118671. 1,
  118672. 11,
  118673. 0,
  118674. 12,
  118675. };
  118676. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118677. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118678. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118679. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118680. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118681. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118682. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118683. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118684. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118685. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118686. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118687. 10,10,10,10,10,10,10,10,10,
  118688. };
  118689. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118690. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118691. 1592.5, 2229.5, 2866.5, 3503.5,
  118692. };
  118693. static long _vq_quantmap__44c6_s_p9_0[] = {
  118694. 11, 9, 7, 5, 3, 1, 0, 2,
  118695. 4, 6, 8, 10, 12,
  118696. };
  118697. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118698. _vq_quantthresh__44c6_s_p9_0,
  118699. _vq_quantmap__44c6_s_p9_0,
  118700. 13,
  118701. 13
  118702. };
  118703. static static_codebook _44c6_s_p9_0 = {
  118704. 2, 169,
  118705. _vq_lengthlist__44c6_s_p9_0,
  118706. 1, -511845376, 1630791680, 4, 0,
  118707. _vq_quantlist__44c6_s_p9_0,
  118708. NULL,
  118709. &_vq_auxt__44c6_s_p9_0,
  118710. NULL,
  118711. 0
  118712. };
  118713. static long _vq_quantlist__44c6_s_p9_1[] = {
  118714. 6,
  118715. 5,
  118716. 7,
  118717. 4,
  118718. 8,
  118719. 3,
  118720. 9,
  118721. 2,
  118722. 10,
  118723. 1,
  118724. 11,
  118725. 0,
  118726. 12,
  118727. };
  118728. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118729. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118730. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118731. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118732. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118733. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118734. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118735. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118736. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118737. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118738. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118739. 15,12,10,11,11,13,11,12,13,
  118740. };
  118741. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118742. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118743. 122.5, 171.5, 220.5, 269.5,
  118744. };
  118745. static long _vq_quantmap__44c6_s_p9_1[] = {
  118746. 11, 9, 7, 5, 3, 1, 0, 2,
  118747. 4, 6, 8, 10, 12,
  118748. };
  118749. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118750. _vq_quantthresh__44c6_s_p9_1,
  118751. _vq_quantmap__44c6_s_p9_1,
  118752. 13,
  118753. 13
  118754. };
  118755. static static_codebook _44c6_s_p9_1 = {
  118756. 2, 169,
  118757. _vq_lengthlist__44c6_s_p9_1,
  118758. 1, -518889472, 1622704128, 4, 0,
  118759. _vq_quantlist__44c6_s_p9_1,
  118760. NULL,
  118761. &_vq_auxt__44c6_s_p9_1,
  118762. NULL,
  118763. 0
  118764. };
  118765. static long _vq_quantlist__44c6_s_p9_2[] = {
  118766. 24,
  118767. 23,
  118768. 25,
  118769. 22,
  118770. 26,
  118771. 21,
  118772. 27,
  118773. 20,
  118774. 28,
  118775. 19,
  118776. 29,
  118777. 18,
  118778. 30,
  118779. 17,
  118780. 31,
  118781. 16,
  118782. 32,
  118783. 15,
  118784. 33,
  118785. 14,
  118786. 34,
  118787. 13,
  118788. 35,
  118789. 12,
  118790. 36,
  118791. 11,
  118792. 37,
  118793. 10,
  118794. 38,
  118795. 9,
  118796. 39,
  118797. 8,
  118798. 40,
  118799. 7,
  118800. 41,
  118801. 6,
  118802. 42,
  118803. 5,
  118804. 43,
  118805. 4,
  118806. 44,
  118807. 3,
  118808. 45,
  118809. 2,
  118810. 46,
  118811. 1,
  118812. 47,
  118813. 0,
  118814. 48,
  118815. };
  118816. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118817. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118818. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118819. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118820. 7,
  118821. };
  118822. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118823. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118824. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118825. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118826. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118827. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118828. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118829. };
  118830. static long _vq_quantmap__44c6_s_p9_2[] = {
  118831. 47, 45, 43, 41, 39, 37, 35, 33,
  118832. 31, 29, 27, 25, 23, 21, 19, 17,
  118833. 15, 13, 11, 9, 7, 5, 3, 1,
  118834. 0, 2, 4, 6, 8, 10, 12, 14,
  118835. 16, 18, 20, 22, 24, 26, 28, 30,
  118836. 32, 34, 36, 38, 40, 42, 44, 46,
  118837. 48,
  118838. };
  118839. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118840. _vq_quantthresh__44c6_s_p9_2,
  118841. _vq_quantmap__44c6_s_p9_2,
  118842. 49,
  118843. 49
  118844. };
  118845. static static_codebook _44c6_s_p9_2 = {
  118846. 1, 49,
  118847. _vq_lengthlist__44c6_s_p9_2,
  118848. 1, -526909440, 1611661312, 6, 0,
  118849. _vq_quantlist__44c6_s_p9_2,
  118850. NULL,
  118851. &_vq_auxt__44c6_s_p9_2,
  118852. NULL,
  118853. 0
  118854. };
  118855. static long _huff_lengthlist__44c6_s_short[] = {
  118856. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118857. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118858. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118859. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118860. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118861. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118862. 9,10,17,18,
  118863. };
  118864. static static_codebook _huff_book__44c6_s_short = {
  118865. 2, 100,
  118866. _huff_lengthlist__44c6_s_short,
  118867. 0, 0, 0, 0, 0,
  118868. NULL,
  118869. NULL,
  118870. NULL,
  118871. NULL,
  118872. 0
  118873. };
  118874. static long _huff_lengthlist__44c7_s_long[] = {
  118875. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118876. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118877. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118878. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118879. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118880. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118881. 11,10,10,12,
  118882. };
  118883. static static_codebook _huff_book__44c7_s_long = {
  118884. 2, 100,
  118885. _huff_lengthlist__44c7_s_long,
  118886. 0, 0, 0, 0, 0,
  118887. NULL,
  118888. NULL,
  118889. NULL,
  118890. NULL,
  118891. 0
  118892. };
  118893. static long _vq_quantlist__44c7_s_p1_0[] = {
  118894. 1,
  118895. 0,
  118896. 2,
  118897. };
  118898. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118899. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118900. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118901. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118902. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118903. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118904. 8,
  118905. };
  118906. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118907. -0.5, 0.5,
  118908. };
  118909. static long _vq_quantmap__44c7_s_p1_0[] = {
  118910. 1, 0, 2,
  118911. };
  118912. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118913. _vq_quantthresh__44c7_s_p1_0,
  118914. _vq_quantmap__44c7_s_p1_0,
  118915. 3,
  118916. 3
  118917. };
  118918. static static_codebook _44c7_s_p1_0 = {
  118919. 4, 81,
  118920. _vq_lengthlist__44c7_s_p1_0,
  118921. 1, -535822336, 1611661312, 2, 0,
  118922. _vq_quantlist__44c7_s_p1_0,
  118923. NULL,
  118924. &_vq_auxt__44c7_s_p1_0,
  118925. NULL,
  118926. 0
  118927. };
  118928. static long _vq_quantlist__44c7_s_p2_0[] = {
  118929. 2,
  118930. 1,
  118931. 3,
  118932. 0,
  118933. 4,
  118934. };
  118935. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118936. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118937. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118938. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118939. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118940. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  118941. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118942. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  118943. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118945. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118946. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118947. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118948. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118949. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118950. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  118951. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118953. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118954. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  118955. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  118956. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  118957. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  118958. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118959. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118961. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  118962. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118963. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118964. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  118965. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118966. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  118967. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118972. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  118973. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  118974. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118975. 13,
  118976. };
  118977. static float _vq_quantthresh__44c7_s_p2_0[] = {
  118978. -1.5, -0.5, 0.5, 1.5,
  118979. };
  118980. static long _vq_quantmap__44c7_s_p2_0[] = {
  118981. 3, 1, 0, 2, 4,
  118982. };
  118983. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  118984. _vq_quantthresh__44c7_s_p2_0,
  118985. _vq_quantmap__44c7_s_p2_0,
  118986. 5,
  118987. 5
  118988. };
  118989. static static_codebook _44c7_s_p2_0 = {
  118990. 4, 625,
  118991. _vq_lengthlist__44c7_s_p2_0,
  118992. 1, -533725184, 1611661312, 3, 0,
  118993. _vq_quantlist__44c7_s_p2_0,
  118994. NULL,
  118995. &_vq_auxt__44c7_s_p2_0,
  118996. NULL,
  118997. 0
  118998. };
  118999. static long _vq_quantlist__44c7_s_p3_0[] = {
  119000. 4,
  119001. 3,
  119002. 5,
  119003. 2,
  119004. 6,
  119005. 1,
  119006. 7,
  119007. 0,
  119008. 8,
  119009. };
  119010. static long _vq_lengthlist__44c7_s_p3_0[] = {
  119011. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119012. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119013. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119014. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119016. 0,
  119017. };
  119018. static float _vq_quantthresh__44c7_s_p3_0[] = {
  119019. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119020. };
  119021. static long _vq_quantmap__44c7_s_p3_0[] = {
  119022. 7, 5, 3, 1, 0, 2, 4, 6,
  119023. 8,
  119024. };
  119025. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119026. _vq_quantthresh__44c7_s_p3_0,
  119027. _vq_quantmap__44c7_s_p3_0,
  119028. 9,
  119029. 9
  119030. };
  119031. static static_codebook _44c7_s_p3_0 = {
  119032. 2, 81,
  119033. _vq_lengthlist__44c7_s_p3_0,
  119034. 1, -531628032, 1611661312, 4, 0,
  119035. _vq_quantlist__44c7_s_p3_0,
  119036. NULL,
  119037. &_vq_auxt__44c7_s_p3_0,
  119038. NULL,
  119039. 0
  119040. };
  119041. static long _vq_quantlist__44c7_s_p4_0[] = {
  119042. 8,
  119043. 7,
  119044. 9,
  119045. 6,
  119046. 10,
  119047. 5,
  119048. 11,
  119049. 4,
  119050. 12,
  119051. 3,
  119052. 13,
  119053. 2,
  119054. 14,
  119055. 1,
  119056. 15,
  119057. 0,
  119058. 16,
  119059. };
  119060. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119061. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119062. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119063. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119064. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119065. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119066. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119067. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119068. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119069. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119070. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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_p4_0[] = {
  119082. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119083. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119084. };
  119085. static long _vq_quantmap__44c7_s_p4_0[] = {
  119086. 15, 13, 11, 9, 7, 5, 3, 1,
  119087. 0, 2, 4, 6, 8, 10, 12, 14,
  119088. 16,
  119089. };
  119090. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119091. _vq_quantthresh__44c7_s_p4_0,
  119092. _vq_quantmap__44c7_s_p4_0,
  119093. 17,
  119094. 17
  119095. };
  119096. static static_codebook _44c7_s_p4_0 = {
  119097. 2, 289,
  119098. _vq_lengthlist__44c7_s_p4_0,
  119099. 1, -529530880, 1611661312, 5, 0,
  119100. _vq_quantlist__44c7_s_p4_0,
  119101. NULL,
  119102. &_vq_auxt__44c7_s_p4_0,
  119103. NULL,
  119104. 0
  119105. };
  119106. static long _vq_quantlist__44c7_s_p5_0[] = {
  119107. 1,
  119108. 0,
  119109. 2,
  119110. };
  119111. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119112. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119113. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119114. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119115. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119116. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119117. 12,
  119118. };
  119119. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119120. -5.5, 5.5,
  119121. };
  119122. static long _vq_quantmap__44c7_s_p5_0[] = {
  119123. 1, 0, 2,
  119124. };
  119125. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119126. _vq_quantthresh__44c7_s_p5_0,
  119127. _vq_quantmap__44c7_s_p5_0,
  119128. 3,
  119129. 3
  119130. };
  119131. static static_codebook _44c7_s_p5_0 = {
  119132. 4, 81,
  119133. _vq_lengthlist__44c7_s_p5_0,
  119134. 1, -529137664, 1618345984, 2, 0,
  119135. _vq_quantlist__44c7_s_p5_0,
  119136. NULL,
  119137. &_vq_auxt__44c7_s_p5_0,
  119138. NULL,
  119139. 0
  119140. };
  119141. static long _vq_quantlist__44c7_s_p5_1[] = {
  119142. 5,
  119143. 4,
  119144. 6,
  119145. 3,
  119146. 7,
  119147. 2,
  119148. 8,
  119149. 1,
  119150. 9,
  119151. 0,
  119152. 10,
  119153. };
  119154. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119155. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119156. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119157. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119158. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119159. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119160. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119161. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119162. 11,11,11, 7, 7, 8, 8, 8, 8,
  119163. };
  119164. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119165. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119166. 3.5, 4.5,
  119167. };
  119168. static long _vq_quantmap__44c7_s_p5_1[] = {
  119169. 9, 7, 5, 3, 1, 0, 2, 4,
  119170. 6, 8, 10,
  119171. };
  119172. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119173. _vq_quantthresh__44c7_s_p5_1,
  119174. _vq_quantmap__44c7_s_p5_1,
  119175. 11,
  119176. 11
  119177. };
  119178. static static_codebook _44c7_s_p5_1 = {
  119179. 2, 121,
  119180. _vq_lengthlist__44c7_s_p5_1,
  119181. 1, -531365888, 1611661312, 4, 0,
  119182. _vq_quantlist__44c7_s_p5_1,
  119183. NULL,
  119184. &_vq_auxt__44c7_s_p5_1,
  119185. NULL,
  119186. 0
  119187. };
  119188. static long _vq_quantlist__44c7_s_p6_0[] = {
  119189. 6,
  119190. 5,
  119191. 7,
  119192. 4,
  119193. 8,
  119194. 3,
  119195. 9,
  119196. 2,
  119197. 10,
  119198. 1,
  119199. 11,
  119200. 0,
  119201. 12,
  119202. };
  119203. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119204. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119205. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119206. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119207. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119208. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119209. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119214. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119215. };
  119216. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119217. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119218. 12.5, 17.5, 22.5, 27.5,
  119219. };
  119220. static long _vq_quantmap__44c7_s_p6_0[] = {
  119221. 11, 9, 7, 5, 3, 1, 0, 2,
  119222. 4, 6, 8, 10, 12,
  119223. };
  119224. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119225. _vq_quantthresh__44c7_s_p6_0,
  119226. _vq_quantmap__44c7_s_p6_0,
  119227. 13,
  119228. 13
  119229. };
  119230. static static_codebook _44c7_s_p6_0 = {
  119231. 2, 169,
  119232. _vq_lengthlist__44c7_s_p6_0,
  119233. 1, -526516224, 1616117760, 4, 0,
  119234. _vq_quantlist__44c7_s_p6_0,
  119235. NULL,
  119236. &_vq_auxt__44c7_s_p6_0,
  119237. NULL,
  119238. 0
  119239. };
  119240. static long _vq_quantlist__44c7_s_p6_1[] = {
  119241. 2,
  119242. 1,
  119243. 3,
  119244. 0,
  119245. 4,
  119246. };
  119247. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119248. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119249. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119250. };
  119251. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119252. -1.5, -0.5, 0.5, 1.5,
  119253. };
  119254. static long _vq_quantmap__44c7_s_p6_1[] = {
  119255. 3, 1, 0, 2, 4,
  119256. };
  119257. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119258. _vq_quantthresh__44c7_s_p6_1,
  119259. _vq_quantmap__44c7_s_p6_1,
  119260. 5,
  119261. 5
  119262. };
  119263. static static_codebook _44c7_s_p6_1 = {
  119264. 2, 25,
  119265. _vq_lengthlist__44c7_s_p6_1,
  119266. 1, -533725184, 1611661312, 3, 0,
  119267. _vq_quantlist__44c7_s_p6_1,
  119268. NULL,
  119269. &_vq_auxt__44c7_s_p6_1,
  119270. NULL,
  119271. 0
  119272. };
  119273. static long _vq_quantlist__44c7_s_p7_0[] = {
  119274. 6,
  119275. 5,
  119276. 7,
  119277. 4,
  119278. 8,
  119279. 3,
  119280. 9,
  119281. 2,
  119282. 10,
  119283. 1,
  119284. 11,
  119285. 0,
  119286. 12,
  119287. };
  119288. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119289. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119290. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119291. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119292. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119293. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119294. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119295. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119296. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119297. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119298. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119299. 19,13,13,13,13,14,14,15,15,
  119300. };
  119301. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119302. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119303. 27.5, 38.5, 49.5, 60.5,
  119304. };
  119305. static long _vq_quantmap__44c7_s_p7_0[] = {
  119306. 11, 9, 7, 5, 3, 1, 0, 2,
  119307. 4, 6, 8, 10, 12,
  119308. };
  119309. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119310. _vq_quantthresh__44c7_s_p7_0,
  119311. _vq_quantmap__44c7_s_p7_0,
  119312. 13,
  119313. 13
  119314. };
  119315. static static_codebook _44c7_s_p7_0 = {
  119316. 2, 169,
  119317. _vq_lengthlist__44c7_s_p7_0,
  119318. 1, -523206656, 1618345984, 4, 0,
  119319. _vq_quantlist__44c7_s_p7_0,
  119320. NULL,
  119321. &_vq_auxt__44c7_s_p7_0,
  119322. NULL,
  119323. 0
  119324. };
  119325. static long _vq_quantlist__44c7_s_p7_1[] = {
  119326. 5,
  119327. 4,
  119328. 6,
  119329. 3,
  119330. 7,
  119331. 2,
  119332. 8,
  119333. 1,
  119334. 9,
  119335. 0,
  119336. 10,
  119337. };
  119338. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119339. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119340. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119341. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119342. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119343. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119344. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119345. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119346. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119347. };
  119348. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119349. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119350. 3.5, 4.5,
  119351. };
  119352. static long _vq_quantmap__44c7_s_p7_1[] = {
  119353. 9, 7, 5, 3, 1, 0, 2, 4,
  119354. 6, 8, 10,
  119355. };
  119356. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119357. _vq_quantthresh__44c7_s_p7_1,
  119358. _vq_quantmap__44c7_s_p7_1,
  119359. 11,
  119360. 11
  119361. };
  119362. static static_codebook _44c7_s_p7_1 = {
  119363. 2, 121,
  119364. _vq_lengthlist__44c7_s_p7_1,
  119365. 1, -531365888, 1611661312, 4, 0,
  119366. _vq_quantlist__44c7_s_p7_1,
  119367. NULL,
  119368. &_vq_auxt__44c7_s_p7_1,
  119369. NULL,
  119370. 0
  119371. };
  119372. static long _vq_quantlist__44c7_s_p8_0[] = {
  119373. 7,
  119374. 6,
  119375. 8,
  119376. 5,
  119377. 9,
  119378. 4,
  119379. 10,
  119380. 3,
  119381. 11,
  119382. 2,
  119383. 12,
  119384. 1,
  119385. 13,
  119386. 0,
  119387. 14,
  119388. };
  119389. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119390. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119391. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119392. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119393. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119394. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119395. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119396. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119397. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119398. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119399. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119400. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119401. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119402. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119403. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119404. 14,
  119405. };
  119406. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119407. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119408. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119409. };
  119410. static long _vq_quantmap__44c7_s_p8_0[] = {
  119411. 13, 11, 9, 7, 5, 3, 1, 0,
  119412. 2, 4, 6, 8, 10, 12, 14,
  119413. };
  119414. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119415. _vq_quantthresh__44c7_s_p8_0,
  119416. _vq_quantmap__44c7_s_p8_0,
  119417. 15,
  119418. 15
  119419. };
  119420. static static_codebook _44c7_s_p8_0 = {
  119421. 2, 225,
  119422. _vq_lengthlist__44c7_s_p8_0,
  119423. 1, -520986624, 1620377600, 4, 0,
  119424. _vq_quantlist__44c7_s_p8_0,
  119425. NULL,
  119426. &_vq_auxt__44c7_s_p8_0,
  119427. NULL,
  119428. 0
  119429. };
  119430. static long _vq_quantlist__44c7_s_p8_1[] = {
  119431. 10,
  119432. 9,
  119433. 11,
  119434. 8,
  119435. 12,
  119436. 7,
  119437. 13,
  119438. 6,
  119439. 14,
  119440. 5,
  119441. 15,
  119442. 4,
  119443. 16,
  119444. 3,
  119445. 17,
  119446. 2,
  119447. 18,
  119448. 1,
  119449. 19,
  119450. 0,
  119451. 20,
  119452. };
  119453. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119454. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119455. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119456. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119457. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119458. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119459. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119460. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119461. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119462. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119463. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119464. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119465. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119466. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119467. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119468. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119469. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119470. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119471. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119472. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119473. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119474. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119475. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119476. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119477. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119478. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119479. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119480. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119481. 10,10,10,10,10,10,10,10,10,
  119482. };
  119483. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119484. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119485. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119486. 6.5, 7.5, 8.5, 9.5,
  119487. };
  119488. static long _vq_quantmap__44c7_s_p8_1[] = {
  119489. 19, 17, 15, 13, 11, 9, 7, 5,
  119490. 3, 1, 0, 2, 4, 6, 8, 10,
  119491. 12, 14, 16, 18, 20,
  119492. };
  119493. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119494. _vq_quantthresh__44c7_s_p8_1,
  119495. _vq_quantmap__44c7_s_p8_1,
  119496. 21,
  119497. 21
  119498. };
  119499. static static_codebook _44c7_s_p8_1 = {
  119500. 2, 441,
  119501. _vq_lengthlist__44c7_s_p8_1,
  119502. 1, -529268736, 1611661312, 5, 0,
  119503. _vq_quantlist__44c7_s_p8_1,
  119504. NULL,
  119505. &_vq_auxt__44c7_s_p8_1,
  119506. NULL,
  119507. 0
  119508. };
  119509. static long _vq_quantlist__44c7_s_p9_0[] = {
  119510. 6,
  119511. 5,
  119512. 7,
  119513. 4,
  119514. 8,
  119515. 3,
  119516. 9,
  119517. 2,
  119518. 10,
  119519. 1,
  119520. 11,
  119521. 0,
  119522. 12,
  119523. };
  119524. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119525. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119526. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119527. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119528. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119529. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119530. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119531. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119532. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119533. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119534. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119535. 11,11,11,11,11,11,11,11,11,
  119536. };
  119537. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119538. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119539. 1592.5, 2229.5, 2866.5, 3503.5,
  119540. };
  119541. static long _vq_quantmap__44c7_s_p9_0[] = {
  119542. 11, 9, 7, 5, 3, 1, 0, 2,
  119543. 4, 6, 8, 10, 12,
  119544. };
  119545. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119546. _vq_quantthresh__44c7_s_p9_0,
  119547. _vq_quantmap__44c7_s_p9_0,
  119548. 13,
  119549. 13
  119550. };
  119551. static static_codebook _44c7_s_p9_0 = {
  119552. 2, 169,
  119553. _vq_lengthlist__44c7_s_p9_0,
  119554. 1, -511845376, 1630791680, 4, 0,
  119555. _vq_quantlist__44c7_s_p9_0,
  119556. NULL,
  119557. &_vq_auxt__44c7_s_p9_0,
  119558. NULL,
  119559. 0
  119560. };
  119561. static long _vq_quantlist__44c7_s_p9_1[] = {
  119562. 6,
  119563. 5,
  119564. 7,
  119565. 4,
  119566. 8,
  119567. 3,
  119568. 9,
  119569. 2,
  119570. 10,
  119571. 1,
  119572. 11,
  119573. 0,
  119574. 12,
  119575. };
  119576. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119577. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119578. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119579. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119580. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119581. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119582. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119583. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119584. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119585. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119586. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119587. 15,11,11,10,10,12,12,12,12,
  119588. };
  119589. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119590. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119591. 122.5, 171.5, 220.5, 269.5,
  119592. };
  119593. static long _vq_quantmap__44c7_s_p9_1[] = {
  119594. 11, 9, 7, 5, 3, 1, 0, 2,
  119595. 4, 6, 8, 10, 12,
  119596. };
  119597. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119598. _vq_quantthresh__44c7_s_p9_1,
  119599. _vq_quantmap__44c7_s_p9_1,
  119600. 13,
  119601. 13
  119602. };
  119603. static static_codebook _44c7_s_p9_1 = {
  119604. 2, 169,
  119605. _vq_lengthlist__44c7_s_p9_1,
  119606. 1, -518889472, 1622704128, 4, 0,
  119607. _vq_quantlist__44c7_s_p9_1,
  119608. NULL,
  119609. &_vq_auxt__44c7_s_p9_1,
  119610. NULL,
  119611. 0
  119612. };
  119613. static long _vq_quantlist__44c7_s_p9_2[] = {
  119614. 24,
  119615. 23,
  119616. 25,
  119617. 22,
  119618. 26,
  119619. 21,
  119620. 27,
  119621. 20,
  119622. 28,
  119623. 19,
  119624. 29,
  119625. 18,
  119626. 30,
  119627. 17,
  119628. 31,
  119629. 16,
  119630. 32,
  119631. 15,
  119632. 33,
  119633. 14,
  119634. 34,
  119635. 13,
  119636. 35,
  119637. 12,
  119638. 36,
  119639. 11,
  119640. 37,
  119641. 10,
  119642. 38,
  119643. 9,
  119644. 39,
  119645. 8,
  119646. 40,
  119647. 7,
  119648. 41,
  119649. 6,
  119650. 42,
  119651. 5,
  119652. 43,
  119653. 4,
  119654. 44,
  119655. 3,
  119656. 45,
  119657. 2,
  119658. 46,
  119659. 1,
  119660. 47,
  119661. 0,
  119662. 48,
  119663. };
  119664. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119665. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119666. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119667. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119668. 7,
  119669. };
  119670. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119671. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119672. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119673. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119674. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119675. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119676. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119677. };
  119678. static long _vq_quantmap__44c7_s_p9_2[] = {
  119679. 47, 45, 43, 41, 39, 37, 35, 33,
  119680. 31, 29, 27, 25, 23, 21, 19, 17,
  119681. 15, 13, 11, 9, 7, 5, 3, 1,
  119682. 0, 2, 4, 6, 8, 10, 12, 14,
  119683. 16, 18, 20, 22, 24, 26, 28, 30,
  119684. 32, 34, 36, 38, 40, 42, 44, 46,
  119685. 48,
  119686. };
  119687. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119688. _vq_quantthresh__44c7_s_p9_2,
  119689. _vq_quantmap__44c7_s_p9_2,
  119690. 49,
  119691. 49
  119692. };
  119693. static static_codebook _44c7_s_p9_2 = {
  119694. 1, 49,
  119695. _vq_lengthlist__44c7_s_p9_2,
  119696. 1, -526909440, 1611661312, 6, 0,
  119697. _vq_quantlist__44c7_s_p9_2,
  119698. NULL,
  119699. &_vq_auxt__44c7_s_p9_2,
  119700. NULL,
  119701. 0
  119702. };
  119703. static long _huff_lengthlist__44c7_s_short[] = {
  119704. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119705. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119706. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119707. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119708. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119709. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119710. 10, 9,11,14,
  119711. };
  119712. static static_codebook _huff_book__44c7_s_short = {
  119713. 2, 100,
  119714. _huff_lengthlist__44c7_s_short,
  119715. 0, 0, 0, 0, 0,
  119716. NULL,
  119717. NULL,
  119718. NULL,
  119719. NULL,
  119720. 0
  119721. };
  119722. static long _huff_lengthlist__44c8_s_long[] = {
  119723. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119724. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119725. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119726. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119727. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119728. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119729. 11, 9, 9,10,
  119730. };
  119731. static static_codebook _huff_book__44c8_s_long = {
  119732. 2, 100,
  119733. _huff_lengthlist__44c8_s_long,
  119734. 0, 0, 0, 0, 0,
  119735. NULL,
  119736. NULL,
  119737. NULL,
  119738. NULL,
  119739. 0
  119740. };
  119741. static long _vq_quantlist__44c8_s_p1_0[] = {
  119742. 1,
  119743. 0,
  119744. 2,
  119745. };
  119746. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119747. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119748. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119749. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119750. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119751. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119752. 8,
  119753. };
  119754. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119755. -0.5, 0.5,
  119756. };
  119757. static long _vq_quantmap__44c8_s_p1_0[] = {
  119758. 1, 0, 2,
  119759. };
  119760. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119761. _vq_quantthresh__44c8_s_p1_0,
  119762. _vq_quantmap__44c8_s_p1_0,
  119763. 3,
  119764. 3
  119765. };
  119766. static static_codebook _44c8_s_p1_0 = {
  119767. 4, 81,
  119768. _vq_lengthlist__44c8_s_p1_0,
  119769. 1, -535822336, 1611661312, 2, 0,
  119770. _vq_quantlist__44c8_s_p1_0,
  119771. NULL,
  119772. &_vq_auxt__44c8_s_p1_0,
  119773. NULL,
  119774. 0
  119775. };
  119776. static long _vq_quantlist__44c8_s_p2_0[] = {
  119777. 2,
  119778. 1,
  119779. 3,
  119780. 0,
  119781. 4,
  119782. };
  119783. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119784. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119785. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119786. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119787. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119788. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119789. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119790. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119791. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119793. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119794. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119795. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119796. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119797. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119798. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119799. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119801. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119802. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119803. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119804. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119805. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119806. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119807. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119809. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119810. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119811. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119812. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119813. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119814. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119815. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119820. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119821. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119822. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119823. 13,
  119824. };
  119825. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119826. -1.5, -0.5, 0.5, 1.5,
  119827. };
  119828. static long _vq_quantmap__44c8_s_p2_0[] = {
  119829. 3, 1, 0, 2, 4,
  119830. };
  119831. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119832. _vq_quantthresh__44c8_s_p2_0,
  119833. _vq_quantmap__44c8_s_p2_0,
  119834. 5,
  119835. 5
  119836. };
  119837. static static_codebook _44c8_s_p2_0 = {
  119838. 4, 625,
  119839. _vq_lengthlist__44c8_s_p2_0,
  119840. 1, -533725184, 1611661312, 3, 0,
  119841. _vq_quantlist__44c8_s_p2_0,
  119842. NULL,
  119843. &_vq_auxt__44c8_s_p2_0,
  119844. NULL,
  119845. 0
  119846. };
  119847. static long _vq_quantlist__44c8_s_p3_0[] = {
  119848. 4,
  119849. 3,
  119850. 5,
  119851. 2,
  119852. 6,
  119853. 1,
  119854. 7,
  119855. 0,
  119856. 8,
  119857. };
  119858. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119859. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119860. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119861. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119862. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119864. 0,
  119865. };
  119866. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119867. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119868. };
  119869. static long _vq_quantmap__44c8_s_p3_0[] = {
  119870. 7, 5, 3, 1, 0, 2, 4, 6,
  119871. 8,
  119872. };
  119873. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119874. _vq_quantthresh__44c8_s_p3_0,
  119875. _vq_quantmap__44c8_s_p3_0,
  119876. 9,
  119877. 9
  119878. };
  119879. static static_codebook _44c8_s_p3_0 = {
  119880. 2, 81,
  119881. _vq_lengthlist__44c8_s_p3_0,
  119882. 1, -531628032, 1611661312, 4, 0,
  119883. _vq_quantlist__44c8_s_p3_0,
  119884. NULL,
  119885. &_vq_auxt__44c8_s_p3_0,
  119886. NULL,
  119887. 0
  119888. };
  119889. static long _vq_quantlist__44c8_s_p4_0[] = {
  119890. 8,
  119891. 7,
  119892. 9,
  119893. 6,
  119894. 10,
  119895. 5,
  119896. 11,
  119897. 4,
  119898. 12,
  119899. 3,
  119900. 13,
  119901. 2,
  119902. 14,
  119903. 1,
  119904. 15,
  119905. 0,
  119906. 16,
  119907. };
  119908. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119909. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119910. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119911. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119912. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119913. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119914. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119915. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119916. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119917. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119918. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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_p4_0[] = {
  119930. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119931. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119932. };
  119933. static long _vq_quantmap__44c8_s_p4_0[] = {
  119934. 15, 13, 11, 9, 7, 5, 3, 1,
  119935. 0, 2, 4, 6, 8, 10, 12, 14,
  119936. 16,
  119937. };
  119938. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  119939. _vq_quantthresh__44c8_s_p4_0,
  119940. _vq_quantmap__44c8_s_p4_0,
  119941. 17,
  119942. 17
  119943. };
  119944. static static_codebook _44c8_s_p4_0 = {
  119945. 2, 289,
  119946. _vq_lengthlist__44c8_s_p4_0,
  119947. 1, -529530880, 1611661312, 5, 0,
  119948. _vq_quantlist__44c8_s_p4_0,
  119949. NULL,
  119950. &_vq_auxt__44c8_s_p4_0,
  119951. NULL,
  119952. 0
  119953. };
  119954. static long _vq_quantlist__44c8_s_p5_0[] = {
  119955. 1,
  119956. 0,
  119957. 2,
  119958. };
  119959. static long _vq_lengthlist__44c8_s_p5_0[] = {
  119960. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  119961. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119962. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119963. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  119964. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  119965. 12,
  119966. };
  119967. static float _vq_quantthresh__44c8_s_p5_0[] = {
  119968. -5.5, 5.5,
  119969. };
  119970. static long _vq_quantmap__44c8_s_p5_0[] = {
  119971. 1, 0, 2,
  119972. };
  119973. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  119974. _vq_quantthresh__44c8_s_p5_0,
  119975. _vq_quantmap__44c8_s_p5_0,
  119976. 3,
  119977. 3
  119978. };
  119979. static static_codebook _44c8_s_p5_0 = {
  119980. 4, 81,
  119981. _vq_lengthlist__44c8_s_p5_0,
  119982. 1, -529137664, 1618345984, 2, 0,
  119983. _vq_quantlist__44c8_s_p5_0,
  119984. NULL,
  119985. &_vq_auxt__44c8_s_p5_0,
  119986. NULL,
  119987. 0
  119988. };
  119989. static long _vq_quantlist__44c8_s_p5_1[] = {
  119990. 5,
  119991. 4,
  119992. 6,
  119993. 3,
  119994. 7,
  119995. 2,
  119996. 8,
  119997. 1,
  119998. 9,
  119999. 0,
  120000. 10,
  120001. };
  120002. static long _vq_lengthlist__44c8_s_p5_1[] = {
  120003. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  120004. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  120005. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  120006. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  120007. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  120008. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  120009. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  120010. 11,11,11, 7, 7, 7, 7, 8, 8,
  120011. };
  120012. static float _vq_quantthresh__44c8_s_p5_1[] = {
  120013. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120014. 3.5, 4.5,
  120015. };
  120016. static long _vq_quantmap__44c8_s_p5_1[] = {
  120017. 9, 7, 5, 3, 1, 0, 2, 4,
  120018. 6, 8, 10,
  120019. };
  120020. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  120021. _vq_quantthresh__44c8_s_p5_1,
  120022. _vq_quantmap__44c8_s_p5_1,
  120023. 11,
  120024. 11
  120025. };
  120026. static static_codebook _44c8_s_p5_1 = {
  120027. 2, 121,
  120028. _vq_lengthlist__44c8_s_p5_1,
  120029. 1, -531365888, 1611661312, 4, 0,
  120030. _vq_quantlist__44c8_s_p5_1,
  120031. NULL,
  120032. &_vq_auxt__44c8_s_p5_1,
  120033. NULL,
  120034. 0
  120035. };
  120036. static long _vq_quantlist__44c8_s_p6_0[] = {
  120037. 6,
  120038. 5,
  120039. 7,
  120040. 4,
  120041. 8,
  120042. 3,
  120043. 9,
  120044. 2,
  120045. 10,
  120046. 1,
  120047. 11,
  120048. 0,
  120049. 12,
  120050. };
  120051. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120052. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120053. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120054. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120055. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120056. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120057. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120062. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120063. };
  120064. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120065. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120066. 12.5, 17.5, 22.5, 27.5,
  120067. };
  120068. static long _vq_quantmap__44c8_s_p6_0[] = {
  120069. 11, 9, 7, 5, 3, 1, 0, 2,
  120070. 4, 6, 8, 10, 12,
  120071. };
  120072. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120073. _vq_quantthresh__44c8_s_p6_0,
  120074. _vq_quantmap__44c8_s_p6_0,
  120075. 13,
  120076. 13
  120077. };
  120078. static static_codebook _44c8_s_p6_0 = {
  120079. 2, 169,
  120080. _vq_lengthlist__44c8_s_p6_0,
  120081. 1, -526516224, 1616117760, 4, 0,
  120082. _vq_quantlist__44c8_s_p6_0,
  120083. NULL,
  120084. &_vq_auxt__44c8_s_p6_0,
  120085. NULL,
  120086. 0
  120087. };
  120088. static long _vq_quantlist__44c8_s_p6_1[] = {
  120089. 2,
  120090. 1,
  120091. 3,
  120092. 0,
  120093. 4,
  120094. };
  120095. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120096. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120097. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120098. };
  120099. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120100. -1.5, -0.5, 0.5, 1.5,
  120101. };
  120102. static long _vq_quantmap__44c8_s_p6_1[] = {
  120103. 3, 1, 0, 2, 4,
  120104. };
  120105. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120106. _vq_quantthresh__44c8_s_p6_1,
  120107. _vq_quantmap__44c8_s_p6_1,
  120108. 5,
  120109. 5
  120110. };
  120111. static static_codebook _44c8_s_p6_1 = {
  120112. 2, 25,
  120113. _vq_lengthlist__44c8_s_p6_1,
  120114. 1, -533725184, 1611661312, 3, 0,
  120115. _vq_quantlist__44c8_s_p6_1,
  120116. NULL,
  120117. &_vq_auxt__44c8_s_p6_1,
  120118. NULL,
  120119. 0
  120120. };
  120121. static long _vq_quantlist__44c8_s_p7_0[] = {
  120122. 6,
  120123. 5,
  120124. 7,
  120125. 4,
  120126. 8,
  120127. 3,
  120128. 9,
  120129. 2,
  120130. 10,
  120131. 1,
  120132. 11,
  120133. 0,
  120134. 12,
  120135. };
  120136. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120137. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120138. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120139. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120140. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120141. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120142. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120143. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120144. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120145. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120146. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120147. 20,13,13,13,13,14,13,15,15,
  120148. };
  120149. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120150. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120151. 27.5, 38.5, 49.5, 60.5,
  120152. };
  120153. static long _vq_quantmap__44c8_s_p7_0[] = {
  120154. 11, 9, 7, 5, 3, 1, 0, 2,
  120155. 4, 6, 8, 10, 12,
  120156. };
  120157. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120158. _vq_quantthresh__44c8_s_p7_0,
  120159. _vq_quantmap__44c8_s_p7_0,
  120160. 13,
  120161. 13
  120162. };
  120163. static static_codebook _44c8_s_p7_0 = {
  120164. 2, 169,
  120165. _vq_lengthlist__44c8_s_p7_0,
  120166. 1, -523206656, 1618345984, 4, 0,
  120167. _vq_quantlist__44c8_s_p7_0,
  120168. NULL,
  120169. &_vq_auxt__44c8_s_p7_0,
  120170. NULL,
  120171. 0
  120172. };
  120173. static long _vq_quantlist__44c8_s_p7_1[] = {
  120174. 5,
  120175. 4,
  120176. 6,
  120177. 3,
  120178. 7,
  120179. 2,
  120180. 8,
  120181. 1,
  120182. 9,
  120183. 0,
  120184. 10,
  120185. };
  120186. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120187. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120188. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120189. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120190. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120191. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120192. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120193. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120194. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120195. };
  120196. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120197. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120198. 3.5, 4.5,
  120199. };
  120200. static long _vq_quantmap__44c8_s_p7_1[] = {
  120201. 9, 7, 5, 3, 1, 0, 2, 4,
  120202. 6, 8, 10,
  120203. };
  120204. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120205. _vq_quantthresh__44c8_s_p7_1,
  120206. _vq_quantmap__44c8_s_p7_1,
  120207. 11,
  120208. 11
  120209. };
  120210. static static_codebook _44c8_s_p7_1 = {
  120211. 2, 121,
  120212. _vq_lengthlist__44c8_s_p7_1,
  120213. 1, -531365888, 1611661312, 4, 0,
  120214. _vq_quantlist__44c8_s_p7_1,
  120215. NULL,
  120216. &_vq_auxt__44c8_s_p7_1,
  120217. NULL,
  120218. 0
  120219. };
  120220. static long _vq_quantlist__44c8_s_p8_0[] = {
  120221. 7,
  120222. 6,
  120223. 8,
  120224. 5,
  120225. 9,
  120226. 4,
  120227. 10,
  120228. 3,
  120229. 11,
  120230. 2,
  120231. 12,
  120232. 1,
  120233. 13,
  120234. 0,
  120235. 14,
  120236. };
  120237. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120238. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120239. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120240. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120241. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120242. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120243. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120244. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120245. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120246. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120247. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120248. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120249. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120250. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120251. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120252. 15,
  120253. };
  120254. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120255. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120256. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120257. };
  120258. static long _vq_quantmap__44c8_s_p8_0[] = {
  120259. 13, 11, 9, 7, 5, 3, 1, 0,
  120260. 2, 4, 6, 8, 10, 12, 14,
  120261. };
  120262. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120263. _vq_quantthresh__44c8_s_p8_0,
  120264. _vq_quantmap__44c8_s_p8_0,
  120265. 15,
  120266. 15
  120267. };
  120268. static static_codebook _44c8_s_p8_0 = {
  120269. 2, 225,
  120270. _vq_lengthlist__44c8_s_p8_0,
  120271. 1, -520986624, 1620377600, 4, 0,
  120272. _vq_quantlist__44c8_s_p8_0,
  120273. NULL,
  120274. &_vq_auxt__44c8_s_p8_0,
  120275. NULL,
  120276. 0
  120277. };
  120278. static long _vq_quantlist__44c8_s_p8_1[] = {
  120279. 10,
  120280. 9,
  120281. 11,
  120282. 8,
  120283. 12,
  120284. 7,
  120285. 13,
  120286. 6,
  120287. 14,
  120288. 5,
  120289. 15,
  120290. 4,
  120291. 16,
  120292. 3,
  120293. 17,
  120294. 2,
  120295. 18,
  120296. 1,
  120297. 19,
  120298. 0,
  120299. 20,
  120300. };
  120301. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120302. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120303. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120304. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120305. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120306. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120307. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120308. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120309. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120310. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120311. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120312. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120313. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120314. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120315. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120316. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120317. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120318. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120319. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120320. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120321. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120322. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120323. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120324. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120325. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120326. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120327. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120328. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120329. 10, 9, 9,10,10, 9,10, 9, 9,
  120330. };
  120331. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120332. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120333. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120334. 6.5, 7.5, 8.5, 9.5,
  120335. };
  120336. static long _vq_quantmap__44c8_s_p8_1[] = {
  120337. 19, 17, 15, 13, 11, 9, 7, 5,
  120338. 3, 1, 0, 2, 4, 6, 8, 10,
  120339. 12, 14, 16, 18, 20,
  120340. };
  120341. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120342. _vq_quantthresh__44c8_s_p8_1,
  120343. _vq_quantmap__44c8_s_p8_1,
  120344. 21,
  120345. 21
  120346. };
  120347. static static_codebook _44c8_s_p8_1 = {
  120348. 2, 441,
  120349. _vq_lengthlist__44c8_s_p8_1,
  120350. 1, -529268736, 1611661312, 5, 0,
  120351. _vq_quantlist__44c8_s_p8_1,
  120352. NULL,
  120353. &_vq_auxt__44c8_s_p8_1,
  120354. NULL,
  120355. 0
  120356. };
  120357. static long _vq_quantlist__44c8_s_p9_0[] = {
  120358. 8,
  120359. 7,
  120360. 9,
  120361. 6,
  120362. 10,
  120363. 5,
  120364. 11,
  120365. 4,
  120366. 12,
  120367. 3,
  120368. 13,
  120369. 2,
  120370. 14,
  120371. 1,
  120372. 15,
  120373. 0,
  120374. 16,
  120375. };
  120376. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120377. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120378. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120379. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120380. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120381. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120382. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120383. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120384. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120385. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120386. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120387. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120388. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120389. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120390. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120391. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120392. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120393. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120394. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120395. 10,
  120396. };
  120397. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120398. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120399. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120400. };
  120401. static long _vq_quantmap__44c8_s_p9_0[] = {
  120402. 15, 13, 11, 9, 7, 5, 3, 1,
  120403. 0, 2, 4, 6, 8, 10, 12, 14,
  120404. 16,
  120405. };
  120406. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120407. _vq_quantthresh__44c8_s_p9_0,
  120408. _vq_quantmap__44c8_s_p9_0,
  120409. 17,
  120410. 17
  120411. };
  120412. static static_codebook _44c8_s_p9_0 = {
  120413. 2, 289,
  120414. _vq_lengthlist__44c8_s_p9_0,
  120415. 1, -509798400, 1631393792, 5, 0,
  120416. _vq_quantlist__44c8_s_p9_0,
  120417. NULL,
  120418. &_vq_auxt__44c8_s_p9_0,
  120419. NULL,
  120420. 0
  120421. };
  120422. static long _vq_quantlist__44c8_s_p9_1[] = {
  120423. 9,
  120424. 8,
  120425. 10,
  120426. 7,
  120427. 11,
  120428. 6,
  120429. 12,
  120430. 5,
  120431. 13,
  120432. 4,
  120433. 14,
  120434. 3,
  120435. 15,
  120436. 2,
  120437. 16,
  120438. 1,
  120439. 17,
  120440. 0,
  120441. 18,
  120442. };
  120443. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120444. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120445. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120446. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120447. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120448. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120449. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120450. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120451. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120452. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120453. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120454. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120455. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120456. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120457. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120458. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120459. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120460. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120461. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120462. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120463. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120464. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120465. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120466. 14,13,13,14,14,15,14,15,14,
  120467. };
  120468. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120469. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120470. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120471. 367.5, 416.5,
  120472. };
  120473. static long _vq_quantmap__44c8_s_p9_1[] = {
  120474. 17, 15, 13, 11, 9, 7, 5, 3,
  120475. 1, 0, 2, 4, 6, 8, 10, 12,
  120476. 14, 16, 18,
  120477. };
  120478. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120479. _vq_quantthresh__44c8_s_p9_1,
  120480. _vq_quantmap__44c8_s_p9_1,
  120481. 19,
  120482. 19
  120483. };
  120484. static static_codebook _44c8_s_p9_1 = {
  120485. 2, 361,
  120486. _vq_lengthlist__44c8_s_p9_1,
  120487. 1, -518287360, 1622704128, 5, 0,
  120488. _vq_quantlist__44c8_s_p9_1,
  120489. NULL,
  120490. &_vq_auxt__44c8_s_p9_1,
  120491. NULL,
  120492. 0
  120493. };
  120494. static long _vq_quantlist__44c8_s_p9_2[] = {
  120495. 24,
  120496. 23,
  120497. 25,
  120498. 22,
  120499. 26,
  120500. 21,
  120501. 27,
  120502. 20,
  120503. 28,
  120504. 19,
  120505. 29,
  120506. 18,
  120507. 30,
  120508. 17,
  120509. 31,
  120510. 16,
  120511. 32,
  120512. 15,
  120513. 33,
  120514. 14,
  120515. 34,
  120516. 13,
  120517. 35,
  120518. 12,
  120519. 36,
  120520. 11,
  120521. 37,
  120522. 10,
  120523. 38,
  120524. 9,
  120525. 39,
  120526. 8,
  120527. 40,
  120528. 7,
  120529. 41,
  120530. 6,
  120531. 42,
  120532. 5,
  120533. 43,
  120534. 4,
  120535. 44,
  120536. 3,
  120537. 45,
  120538. 2,
  120539. 46,
  120540. 1,
  120541. 47,
  120542. 0,
  120543. 48,
  120544. };
  120545. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120546. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120547. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120548. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120549. 7,
  120550. };
  120551. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120552. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120553. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120554. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120555. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120556. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120557. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120558. };
  120559. static long _vq_quantmap__44c8_s_p9_2[] = {
  120560. 47, 45, 43, 41, 39, 37, 35, 33,
  120561. 31, 29, 27, 25, 23, 21, 19, 17,
  120562. 15, 13, 11, 9, 7, 5, 3, 1,
  120563. 0, 2, 4, 6, 8, 10, 12, 14,
  120564. 16, 18, 20, 22, 24, 26, 28, 30,
  120565. 32, 34, 36, 38, 40, 42, 44, 46,
  120566. 48,
  120567. };
  120568. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120569. _vq_quantthresh__44c8_s_p9_2,
  120570. _vq_quantmap__44c8_s_p9_2,
  120571. 49,
  120572. 49
  120573. };
  120574. static static_codebook _44c8_s_p9_2 = {
  120575. 1, 49,
  120576. _vq_lengthlist__44c8_s_p9_2,
  120577. 1, -526909440, 1611661312, 6, 0,
  120578. _vq_quantlist__44c8_s_p9_2,
  120579. NULL,
  120580. &_vq_auxt__44c8_s_p9_2,
  120581. NULL,
  120582. 0
  120583. };
  120584. static long _huff_lengthlist__44c8_s_short[] = {
  120585. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120586. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120587. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120588. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120589. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120590. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120591. 10, 9,11,14,
  120592. };
  120593. static static_codebook _huff_book__44c8_s_short = {
  120594. 2, 100,
  120595. _huff_lengthlist__44c8_s_short,
  120596. 0, 0, 0, 0, 0,
  120597. NULL,
  120598. NULL,
  120599. NULL,
  120600. NULL,
  120601. 0
  120602. };
  120603. static long _huff_lengthlist__44c9_s_long[] = {
  120604. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120605. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120606. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120607. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120608. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120609. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120610. 10, 9, 8, 9,
  120611. };
  120612. static static_codebook _huff_book__44c9_s_long = {
  120613. 2, 100,
  120614. _huff_lengthlist__44c9_s_long,
  120615. 0, 0, 0, 0, 0,
  120616. NULL,
  120617. NULL,
  120618. NULL,
  120619. NULL,
  120620. 0
  120621. };
  120622. static long _vq_quantlist__44c9_s_p1_0[] = {
  120623. 1,
  120624. 0,
  120625. 2,
  120626. };
  120627. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120628. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120629. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120630. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120631. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120632. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120633. 7,
  120634. };
  120635. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120636. -0.5, 0.5,
  120637. };
  120638. static long _vq_quantmap__44c9_s_p1_0[] = {
  120639. 1, 0, 2,
  120640. };
  120641. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120642. _vq_quantthresh__44c9_s_p1_0,
  120643. _vq_quantmap__44c9_s_p1_0,
  120644. 3,
  120645. 3
  120646. };
  120647. static static_codebook _44c9_s_p1_0 = {
  120648. 4, 81,
  120649. _vq_lengthlist__44c9_s_p1_0,
  120650. 1, -535822336, 1611661312, 2, 0,
  120651. _vq_quantlist__44c9_s_p1_0,
  120652. NULL,
  120653. &_vq_auxt__44c9_s_p1_0,
  120654. NULL,
  120655. 0
  120656. };
  120657. static long _vq_quantlist__44c9_s_p2_0[] = {
  120658. 2,
  120659. 1,
  120660. 3,
  120661. 0,
  120662. 4,
  120663. };
  120664. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120665. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120666. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120667. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120668. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120669. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120670. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120671. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120672. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120674. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120675. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120676. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120677. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120678. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120679. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120680. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120682. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120683. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120684. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120685. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120686. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120687. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120688. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120690. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120691. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120692. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120693. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120694. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120695. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120696. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120701. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120702. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120703. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120704. 12,
  120705. };
  120706. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120707. -1.5, -0.5, 0.5, 1.5,
  120708. };
  120709. static long _vq_quantmap__44c9_s_p2_0[] = {
  120710. 3, 1, 0, 2, 4,
  120711. };
  120712. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120713. _vq_quantthresh__44c9_s_p2_0,
  120714. _vq_quantmap__44c9_s_p2_0,
  120715. 5,
  120716. 5
  120717. };
  120718. static static_codebook _44c9_s_p2_0 = {
  120719. 4, 625,
  120720. _vq_lengthlist__44c9_s_p2_0,
  120721. 1, -533725184, 1611661312, 3, 0,
  120722. _vq_quantlist__44c9_s_p2_0,
  120723. NULL,
  120724. &_vq_auxt__44c9_s_p2_0,
  120725. NULL,
  120726. 0
  120727. };
  120728. static long _vq_quantlist__44c9_s_p3_0[] = {
  120729. 4,
  120730. 3,
  120731. 5,
  120732. 2,
  120733. 6,
  120734. 1,
  120735. 7,
  120736. 0,
  120737. 8,
  120738. };
  120739. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120740. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120741. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120742. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120743. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120745. 0,
  120746. };
  120747. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120748. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120749. };
  120750. static long _vq_quantmap__44c9_s_p3_0[] = {
  120751. 7, 5, 3, 1, 0, 2, 4, 6,
  120752. 8,
  120753. };
  120754. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120755. _vq_quantthresh__44c9_s_p3_0,
  120756. _vq_quantmap__44c9_s_p3_0,
  120757. 9,
  120758. 9
  120759. };
  120760. static static_codebook _44c9_s_p3_0 = {
  120761. 2, 81,
  120762. _vq_lengthlist__44c9_s_p3_0,
  120763. 1, -531628032, 1611661312, 4, 0,
  120764. _vq_quantlist__44c9_s_p3_0,
  120765. NULL,
  120766. &_vq_auxt__44c9_s_p3_0,
  120767. NULL,
  120768. 0
  120769. };
  120770. static long _vq_quantlist__44c9_s_p4_0[] = {
  120771. 8,
  120772. 7,
  120773. 9,
  120774. 6,
  120775. 10,
  120776. 5,
  120777. 11,
  120778. 4,
  120779. 12,
  120780. 3,
  120781. 13,
  120782. 2,
  120783. 14,
  120784. 1,
  120785. 15,
  120786. 0,
  120787. 16,
  120788. };
  120789. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120790. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120791. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120792. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120793. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120794. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120795. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120796. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120797. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120798. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120799. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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_p4_0[] = {
  120811. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120812. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120813. };
  120814. static long _vq_quantmap__44c9_s_p4_0[] = {
  120815. 15, 13, 11, 9, 7, 5, 3, 1,
  120816. 0, 2, 4, 6, 8, 10, 12, 14,
  120817. 16,
  120818. };
  120819. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120820. _vq_quantthresh__44c9_s_p4_0,
  120821. _vq_quantmap__44c9_s_p4_0,
  120822. 17,
  120823. 17
  120824. };
  120825. static static_codebook _44c9_s_p4_0 = {
  120826. 2, 289,
  120827. _vq_lengthlist__44c9_s_p4_0,
  120828. 1, -529530880, 1611661312, 5, 0,
  120829. _vq_quantlist__44c9_s_p4_0,
  120830. NULL,
  120831. &_vq_auxt__44c9_s_p4_0,
  120832. NULL,
  120833. 0
  120834. };
  120835. static long _vq_quantlist__44c9_s_p5_0[] = {
  120836. 1,
  120837. 0,
  120838. 2,
  120839. };
  120840. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120841. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120842. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120843. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120844. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120845. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120846. 12,
  120847. };
  120848. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120849. -5.5, 5.5,
  120850. };
  120851. static long _vq_quantmap__44c9_s_p5_0[] = {
  120852. 1, 0, 2,
  120853. };
  120854. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120855. _vq_quantthresh__44c9_s_p5_0,
  120856. _vq_quantmap__44c9_s_p5_0,
  120857. 3,
  120858. 3
  120859. };
  120860. static static_codebook _44c9_s_p5_0 = {
  120861. 4, 81,
  120862. _vq_lengthlist__44c9_s_p5_0,
  120863. 1, -529137664, 1618345984, 2, 0,
  120864. _vq_quantlist__44c9_s_p5_0,
  120865. NULL,
  120866. &_vq_auxt__44c9_s_p5_0,
  120867. NULL,
  120868. 0
  120869. };
  120870. static long _vq_quantlist__44c9_s_p5_1[] = {
  120871. 5,
  120872. 4,
  120873. 6,
  120874. 3,
  120875. 7,
  120876. 2,
  120877. 8,
  120878. 1,
  120879. 9,
  120880. 0,
  120881. 10,
  120882. };
  120883. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120884. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120885. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120886. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120887. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120888. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120889. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120890. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120891. 11,11,11, 7, 7, 7, 7, 7, 7,
  120892. };
  120893. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120894. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120895. 3.5, 4.5,
  120896. };
  120897. static long _vq_quantmap__44c9_s_p5_1[] = {
  120898. 9, 7, 5, 3, 1, 0, 2, 4,
  120899. 6, 8, 10,
  120900. };
  120901. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120902. _vq_quantthresh__44c9_s_p5_1,
  120903. _vq_quantmap__44c9_s_p5_1,
  120904. 11,
  120905. 11
  120906. };
  120907. static static_codebook _44c9_s_p5_1 = {
  120908. 2, 121,
  120909. _vq_lengthlist__44c9_s_p5_1,
  120910. 1, -531365888, 1611661312, 4, 0,
  120911. _vq_quantlist__44c9_s_p5_1,
  120912. NULL,
  120913. &_vq_auxt__44c9_s_p5_1,
  120914. NULL,
  120915. 0
  120916. };
  120917. static long _vq_quantlist__44c9_s_p6_0[] = {
  120918. 6,
  120919. 5,
  120920. 7,
  120921. 4,
  120922. 8,
  120923. 3,
  120924. 9,
  120925. 2,
  120926. 10,
  120927. 1,
  120928. 11,
  120929. 0,
  120930. 12,
  120931. };
  120932. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120933. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120934. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120935. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120936. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120937. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  120938. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  120939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120943. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120944. };
  120945. static float _vq_quantthresh__44c9_s_p6_0[] = {
  120946. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120947. 12.5, 17.5, 22.5, 27.5,
  120948. };
  120949. static long _vq_quantmap__44c9_s_p6_0[] = {
  120950. 11, 9, 7, 5, 3, 1, 0, 2,
  120951. 4, 6, 8, 10, 12,
  120952. };
  120953. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  120954. _vq_quantthresh__44c9_s_p6_0,
  120955. _vq_quantmap__44c9_s_p6_0,
  120956. 13,
  120957. 13
  120958. };
  120959. static static_codebook _44c9_s_p6_0 = {
  120960. 2, 169,
  120961. _vq_lengthlist__44c9_s_p6_0,
  120962. 1, -526516224, 1616117760, 4, 0,
  120963. _vq_quantlist__44c9_s_p6_0,
  120964. NULL,
  120965. &_vq_auxt__44c9_s_p6_0,
  120966. NULL,
  120967. 0
  120968. };
  120969. static long _vq_quantlist__44c9_s_p6_1[] = {
  120970. 2,
  120971. 1,
  120972. 3,
  120973. 0,
  120974. 4,
  120975. };
  120976. static long _vq_lengthlist__44c9_s_p6_1[] = {
  120977. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  120978. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  120979. };
  120980. static float _vq_quantthresh__44c9_s_p6_1[] = {
  120981. -1.5, -0.5, 0.5, 1.5,
  120982. };
  120983. static long _vq_quantmap__44c9_s_p6_1[] = {
  120984. 3, 1, 0, 2, 4,
  120985. };
  120986. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  120987. _vq_quantthresh__44c9_s_p6_1,
  120988. _vq_quantmap__44c9_s_p6_1,
  120989. 5,
  120990. 5
  120991. };
  120992. static static_codebook _44c9_s_p6_1 = {
  120993. 2, 25,
  120994. _vq_lengthlist__44c9_s_p6_1,
  120995. 1, -533725184, 1611661312, 3, 0,
  120996. _vq_quantlist__44c9_s_p6_1,
  120997. NULL,
  120998. &_vq_auxt__44c9_s_p6_1,
  120999. NULL,
  121000. 0
  121001. };
  121002. static long _vq_quantlist__44c9_s_p7_0[] = {
  121003. 6,
  121004. 5,
  121005. 7,
  121006. 4,
  121007. 8,
  121008. 3,
  121009. 9,
  121010. 2,
  121011. 10,
  121012. 1,
  121013. 11,
  121014. 0,
  121015. 12,
  121016. };
  121017. static long _vq_lengthlist__44c9_s_p7_0[] = {
  121018. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  121019. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  121020. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  121021. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  121022. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  121023. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  121024. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121025. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121026. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121027. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121028. 19,12,12,12,12,13,13,14,14,
  121029. };
  121030. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121031. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121032. 27.5, 38.5, 49.5, 60.5,
  121033. };
  121034. static long _vq_quantmap__44c9_s_p7_0[] = {
  121035. 11, 9, 7, 5, 3, 1, 0, 2,
  121036. 4, 6, 8, 10, 12,
  121037. };
  121038. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121039. _vq_quantthresh__44c9_s_p7_0,
  121040. _vq_quantmap__44c9_s_p7_0,
  121041. 13,
  121042. 13
  121043. };
  121044. static static_codebook _44c9_s_p7_0 = {
  121045. 2, 169,
  121046. _vq_lengthlist__44c9_s_p7_0,
  121047. 1, -523206656, 1618345984, 4, 0,
  121048. _vq_quantlist__44c9_s_p7_0,
  121049. NULL,
  121050. &_vq_auxt__44c9_s_p7_0,
  121051. NULL,
  121052. 0
  121053. };
  121054. static long _vq_quantlist__44c9_s_p7_1[] = {
  121055. 5,
  121056. 4,
  121057. 6,
  121058. 3,
  121059. 7,
  121060. 2,
  121061. 8,
  121062. 1,
  121063. 9,
  121064. 0,
  121065. 10,
  121066. };
  121067. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121068. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121069. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121070. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121071. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121072. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121073. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121074. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121075. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121076. };
  121077. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121078. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121079. 3.5, 4.5,
  121080. };
  121081. static long _vq_quantmap__44c9_s_p7_1[] = {
  121082. 9, 7, 5, 3, 1, 0, 2, 4,
  121083. 6, 8, 10,
  121084. };
  121085. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121086. _vq_quantthresh__44c9_s_p7_1,
  121087. _vq_quantmap__44c9_s_p7_1,
  121088. 11,
  121089. 11
  121090. };
  121091. static static_codebook _44c9_s_p7_1 = {
  121092. 2, 121,
  121093. _vq_lengthlist__44c9_s_p7_1,
  121094. 1, -531365888, 1611661312, 4, 0,
  121095. _vq_quantlist__44c9_s_p7_1,
  121096. NULL,
  121097. &_vq_auxt__44c9_s_p7_1,
  121098. NULL,
  121099. 0
  121100. };
  121101. static long _vq_quantlist__44c9_s_p8_0[] = {
  121102. 7,
  121103. 6,
  121104. 8,
  121105. 5,
  121106. 9,
  121107. 4,
  121108. 10,
  121109. 3,
  121110. 11,
  121111. 2,
  121112. 12,
  121113. 1,
  121114. 13,
  121115. 0,
  121116. 14,
  121117. };
  121118. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121119. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121120. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121121. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121122. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121123. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121124. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121125. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121126. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121127. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121128. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121129. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121130. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121131. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121132. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121133. 14,
  121134. };
  121135. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121136. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121137. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121138. };
  121139. static long _vq_quantmap__44c9_s_p8_0[] = {
  121140. 13, 11, 9, 7, 5, 3, 1, 0,
  121141. 2, 4, 6, 8, 10, 12, 14,
  121142. };
  121143. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121144. _vq_quantthresh__44c9_s_p8_0,
  121145. _vq_quantmap__44c9_s_p8_0,
  121146. 15,
  121147. 15
  121148. };
  121149. static static_codebook _44c9_s_p8_0 = {
  121150. 2, 225,
  121151. _vq_lengthlist__44c9_s_p8_0,
  121152. 1, -520986624, 1620377600, 4, 0,
  121153. _vq_quantlist__44c9_s_p8_0,
  121154. NULL,
  121155. &_vq_auxt__44c9_s_p8_0,
  121156. NULL,
  121157. 0
  121158. };
  121159. static long _vq_quantlist__44c9_s_p8_1[] = {
  121160. 10,
  121161. 9,
  121162. 11,
  121163. 8,
  121164. 12,
  121165. 7,
  121166. 13,
  121167. 6,
  121168. 14,
  121169. 5,
  121170. 15,
  121171. 4,
  121172. 16,
  121173. 3,
  121174. 17,
  121175. 2,
  121176. 18,
  121177. 1,
  121178. 19,
  121179. 0,
  121180. 20,
  121181. };
  121182. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121183. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121184. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121185. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121186. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121187. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121188. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121189. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121190. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121191. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121192. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121193. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121194. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121195. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121196. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121197. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121198. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121199. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121200. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121201. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121202. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121203. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121204. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121205. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121206. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121207. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121208. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121209. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121210. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121211. };
  121212. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121213. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121214. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121215. 6.5, 7.5, 8.5, 9.5,
  121216. };
  121217. static long _vq_quantmap__44c9_s_p8_1[] = {
  121218. 19, 17, 15, 13, 11, 9, 7, 5,
  121219. 3, 1, 0, 2, 4, 6, 8, 10,
  121220. 12, 14, 16, 18, 20,
  121221. };
  121222. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121223. _vq_quantthresh__44c9_s_p8_1,
  121224. _vq_quantmap__44c9_s_p8_1,
  121225. 21,
  121226. 21
  121227. };
  121228. static static_codebook _44c9_s_p8_1 = {
  121229. 2, 441,
  121230. _vq_lengthlist__44c9_s_p8_1,
  121231. 1, -529268736, 1611661312, 5, 0,
  121232. _vq_quantlist__44c9_s_p8_1,
  121233. NULL,
  121234. &_vq_auxt__44c9_s_p8_1,
  121235. NULL,
  121236. 0
  121237. };
  121238. static long _vq_quantlist__44c9_s_p9_0[] = {
  121239. 9,
  121240. 8,
  121241. 10,
  121242. 7,
  121243. 11,
  121244. 6,
  121245. 12,
  121246. 5,
  121247. 13,
  121248. 4,
  121249. 14,
  121250. 3,
  121251. 15,
  121252. 2,
  121253. 16,
  121254. 1,
  121255. 17,
  121256. 0,
  121257. 18,
  121258. };
  121259. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121260. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121261. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121262. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121263. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121264. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121265. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121266. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121267. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121268. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121269. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121270. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121271. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121272. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121273. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121274. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121275. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121276. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121277. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121278. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121279. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121280. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121281. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121282. 11,11,11,11,11,11,11,11,11,
  121283. };
  121284. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121285. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121286. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121287. 6982.5, 7913.5,
  121288. };
  121289. static long _vq_quantmap__44c9_s_p9_0[] = {
  121290. 17, 15, 13, 11, 9, 7, 5, 3,
  121291. 1, 0, 2, 4, 6, 8, 10, 12,
  121292. 14, 16, 18,
  121293. };
  121294. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121295. _vq_quantthresh__44c9_s_p9_0,
  121296. _vq_quantmap__44c9_s_p9_0,
  121297. 19,
  121298. 19
  121299. };
  121300. static static_codebook _44c9_s_p9_0 = {
  121301. 2, 361,
  121302. _vq_lengthlist__44c9_s_p9_0,
  121303. 1, -508535424, 1631393792, 5, 0,
  121304. _vq_quantlist__44c9_s_p9_0,
  121305. NULL,
  121306. &_vq_auxt__44c9_s_p9_0,
  121307. NULL,
  121308. 0
  121309. };
  121310. static long _vq_quantlist__44c9_s_p9_1[] = {
  121311. 9,
  121312. 8,
  121313. 10,
  121314. 7,
  121315. 11,
  121316. 6,
  121317. 12,
  121318. 5,
  121319. 13,
  121320. 4,
  121321. 14,
  121322. 3,
  121323. 15,
  121324. 2,
  121325. 16,
  121326. 1,
  121327. 17,
  121328. 0,
  121329. 18,
  121330. };
  121331. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121332. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121333. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121334. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121335. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121336. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121337. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121338. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121339. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121340. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121341. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121342. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121343. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121344. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121345. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121346. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121347. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121348. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121349. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121350. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121351. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121352. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121353. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121354. 13,13,13,14,13,14,15,15,15,
  121355. };
  121356. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121357. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121358. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121359. 367.5, 416.5,
  121360. };
  121361. static long _vq_quantmap__44c9_s_p9_1[] = {
  121362. 17, 15, 13, 11, 9, 7, 5, 3,
  121363. 1, 0, 2, 4, 6, 8, 10, 12,
  121364. 14, 16, 18,
  121365. };
  121366. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121367. _vq_quantthresh__44c9_s_p9_1,
  121368. _vq_quantmap__44c9_s_p9_1,
  121369. 19,
  121370. 19
  121371. };
  121372. static static_codebook _44c9_s_p9_1 = {
  121373. 2, 361,
  121374. _vq_lengthlist__44c9_s_p9_1,
  121375. 1, -518287360, 1622704128, 5, 0,
  121376. _vq_quantlist__44c9_s_p9_1,
  121377. NULL,
  121378. &_vq_auxt__44c9_s_p9_1,
  121379. NULL,
  121380. 0
  121381. };
  121382. static long _vq_quantlist__44c9_s_p9_2[] = {
  121383. 24,
  121384. 23,
  121385. 25,
  121386. 22,
  121387. 26,
  121388. 21,
  121389. 27,
  121390. 20,
  121391. 28,
  121392. 19,
  121393. 29,
  121394. 18,
  121395. 30,
  121396. 17,
  121397. 31,
  121398. 16,
  121399. 32,
  121400. 15,
  121401. 33,
  121402. 14,
  121403. 34,
  121404. 13,
  121405. 35,
  121406. 12,
  121407. 36,
  121408. 11,
  121409. 37,
  121410. 10,
  121411. 38,
  121412. 9,
  121413. 39,
  121414. 8,
  121415. 40,
  121416. 7,
  121417. 41,
  121418. 6,
  121419. 42,
  121420. 5,
  121421. 43,
  121422. 4,
  121423. 44,
  121424. 3,
  121425. 45,
  121426. 2,
  121427. 46,
  121428. 1,
  121429. 47,
  121430. 0,
  121431. 48,
  121432. };
  121433. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121434. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121435. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121436. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121437. 7,
  121438. };
  121439. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121440. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121441. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121442. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121443. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121444. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121445. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121446. };
  121447. static long _vq_quantmap__44c9_s_p9_2[] = {
  121448. 47, 45, 43, 41, 39, 37, 35, 33,
  121449. 31, 29, 27, 25, 23, 21, 19, 17,
  121450. 15, 13, 11, 9, 7, 5, 3, 1,
  121451. 0, 2, 4, 6, 8, 10, 12, 14,
  121452. 16, 18, 20, 22, 24, 26, 28, 30,
  121453. 32, 34, 36, 38, 40, 42, 44, 46,
  121454. 48,
  121455. };
  121456. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121457. _vq_quantthresh__44c9_s_p9_2,
  121458. _vq_quantmap__44c9_s_p9_2,
  121459. 49,
  121460. 49
  121461. };
  121462. static static_codebook _44c9_s_p9_2 = {
  121463. 1, 49,
  121464. _vq_lengthlist__44c9_s_p9_2,
  121465. 1, -526909440, 1611661312, 6, 0,
  121466. _vq_quantlist__44c9_s_p9_2,
  121467. NULL,
  121468. &_vq_auxt__44c9_s_p9_2,
  121469. NULL,
  121470. 0
  121471. };
  121472. static long _huff_lengthlist__44c9_s_short[] = {
  121473. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121474. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121475. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121476. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121477. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121478. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121479. 9, 8,10,13,
  121480. };
  121481. static static_codebook _huff_book__44c9_s_short = {
  121482. 2, 100,
  121483. _huff_lengthlist__44c9_s_short,
  121484. 0, 0, 0, 0, 0,
  121485. NULL,
  121486. NULL,
  121487. NULL,
  121488. NULL,
  121489. 0
  121490. };
  121491. static long _huff_lengthlist__44c0_s_long[] = {
  121492. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121493. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121494. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121495. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121496. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121497. 12,
  121498. };
  121499. static static_codebook _huff_book__44c0_s_long = {
  121500. 2, 81,
  121501. _huff_lengthlist__44c0_s_long,
  121502. 0, 0, 0, 0, 0,
  121503. NULL,
  121504. NULL,
  121505. NULL,
  121506. NULL,
  121507. 0
  121508. };
  121509. static long _vq_quantlist__44c0_s_p1_0[] = {
  121510. 1,
  121511. 0,
  121512. 2,
  121513. };
  121514. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121515. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121516. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121520. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121521. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121525. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121526. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121561. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121566. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121571. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121606. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121607. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121612. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121617. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  121618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121823. 0, 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,
  121926. };
  121927. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121928. -0.5, 0.5,
  121929. };
  121930. static long _vq_quantmap__44c0_s_p1_0[] = {
  121931. 1, 0, 2,
  121932. };
  121933. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121934. _vq_quantthresh__44c0_s_p1_0,
  121935. _vq_quantmap__44c0_s_p1_0,
  121936. 3,
  121937. 3
  121938. };
  121939. static static_codebook _44c0_s_p1_0 = {
  121940. 8, 6561,
  121941. _vq_lengthlist__44c0_s_p1_0,
  121942. 1, -535822336, 1611661312, 2, 0,
  121943. _vq_quantlist__44c0_s_p1_0,
  121944. NULL,
  121945. &_vq_auxt__44c0_s_p1_0,
  121946. NULL,
  121947. 0
  121948. };
  121949. static long _vq_quantlist__44c0_s_p2_0[] = {
  121950. 2,
  121951. 1,
  121952. 3,
  121953. 0,
  121954. 4,
  121955. };
  121956. static long _vq_lengthlist__44c0_s_p2_0[] = {
  121957. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  121959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121960. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  121962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121963. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121996. 0,
  121997. };
  121998. static float _vq_quantthresh__44c0_s_p2_0[] = {
  121999. -1.5, -0.5, 0.5, 1.5,
  122000. };
  122001. static long _vq_quantmap__44c0_s_p2_0[] = {
  122002. 3, 1, 0, 2, 4,
  122003. };
  122004. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  122005. _vq_quantthresh__44c0_s_p2_0,
  122006. _vq_quantmap__44c0_s_p2_0,
  122007. 5,
  122008. 5
  122009. };
  122010. static static_codebook _44c0_s_p2_0 = {
  122011. 4, 625,
  122012. _vq_lengthlist__44c0_s_p2_0,
  122013. 1, -533725184, 1611661312, 3, 0,
  122014. _vq_quantlist__44c0_s_p2_0,
  122015. NULL,
  122016. &_vq_auxt__44c0_s_p2_0,
  122017. NULL,
  122018. 0
  122019. };
  122020. static long _vq_quantlist__44c0_s_p3_0[] = {
  122021. 4,
  122022. 3,
  122023. 5,
  122024. 2,
  122025. 6,
  122026. 1,
  122027. 7,
  122028. 0,
  122029. 8,
  122030. };
  122031. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122032. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122033. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122034. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122035. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122036. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122037. 0,
  122038. };
  122039. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122040. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122041. };
  122042. static long _vq_quantmap__44c0_s_p3_0[] = {
  122043. 7, 5, 3, 1, 0, 2, 4, 6,
  122044. 8,
  122045. };
  122046. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122047. _vq_quantthresh__44c0_s_p3_0,
  122048. _vq_quantmap__44c0_s_p3_0,
  122049. 9,
  122050. 9
  122051. };
  122052. static static_codebook _44c0_s_p3_0 = {
  122053. 2, 81,
  122054. _vq_lengthlist__44c0_s_p3_0,
  122055. 1, -531628032, 1611661312, 4, 0,
  122056. _vq_quantlist__44c0_s_p3_0,
  122057. NULL,
  122058. &_vq_auxt__44c0_s_p3_0,
  122059. NULL,
  122060. 0
  122061. };
  122062. static long _vq_quantlist__44c0_s_p4_0[] = {
  122063. 4,
  122064. 3,
  122065. 5,
  122066. 2,
  122067. 6,
  122068. 1,
  122069. 7,
  122070. 0,
  122071. 8,
  122072. };
  122073. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122074. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122075. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122076. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122077. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122078. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122079. 10,
  122080. };
  122081. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122082. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122083. };
  122084. static long _vq_quantmap__44c0_s_p4_0[] = {
  122085. 7, 5, 3, 1, 0, 2, 4, 6,
  122086. 8,
  122087. };
  122088. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122089. _vq_quantthresh__44c0_s_p4_0,
  122090. _vq_quantmap__44c0_s_p4_0,
  122091. 9,
  122092. 9
  122093. };
  122094. static static_codebook _44c0_s_p4_0 = {
  122095. 2, 81,
  122096. _vq_lengthlist__44c0_s_p4_0,
  122097. 1, -531628032, 1611661312, 4, 0,
  122098. _vq_quantlist__44c0_s_p4_0,
  122099. NULL,
  122100. &_vq_auxt__44c0_s_p4_0,
  122101. NULL,
  122102. 0
  122103. };
  122104. static long _vq_quantlist__44c0_s_p5_0[] = {
  122105. 8,
  122106. 7,
  122107. 9,
  122108. 6,
  122109. 10,
  122110. 5,
  122111. 11,
  122112. 4,
  122113. 12,
  122114. 3,
  122115. 13,
  122116. 2,
  122117. 14,
  122118. 1,
  122119. 15,
  122120. 0,
  122121. 16,
  122122. };
  122123. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122124. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122125. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122126. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122127. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122128. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122129. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122130. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122131. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122132. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122133. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122134. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122135. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122136. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122137. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122138. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122139. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122140. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122141. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122142. 14,
  122143. };
  122144. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122145. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122146. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122147. };
  122148. static long _vq_quantmap__44c0_s_p5_0[] = {
  122149. 15, 13, 11, 9, 7, 5, 3, 1,
  122150. 0, 2, 4, 6, 8, 10, 12, 14,
  122151. 16,
  122152. };
  122153. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122154. _vq_quantthresh__44c0_s_p5_0,
  122155. _vq_quantmap__44c0_s_p5_0,
  122156. 17,
  122157. 17
  122158. };
  122159. static static_codebook _44c0_s_p5_0 = {
  122160. 2, 289,
  122161. _vq_lengthlist__44c0_s_p5_0,
  122162. 1, -529530880, 1611661312, 5, 0,
  122163. _vq_quantlist__44c0_s_p5_0,
  122164. NULL,
  122165. &_vq_auxt__44c0_s_p5_0,
  122166. NULL,
  122167. 0
  122168. };
  122169. static long _vq_quantlist__44c0_s_p6_0[] = {
  122170. 1,
  122171. 0,
  122172. 2,
  122173. };
  122174. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122175. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122176. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122177. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122178. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122179. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122180. 10,
  122181. };
  122182. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122183. -5.5, 5.5,
  122184. };
  122185. static long _vq_quantmap__44c0_s_p6_0[] = {
  122186. 1, 0, 2,
  122187. };
  122188. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122189. _vq_quantthresh__44c0_s_p6_0,
  122190. _vq_quantmap__44c0_s_p6_0,
  122191. 3,
  122192. 3
  122193. };
  122194. static static_codebook _44c0_s_p6_0 = {
  122195. 4, 81,
  122196. _vq_lengthlist__44c0_s_p6_0,
  122197. 1, -529137664, 1618345984, 2, 0,
  122198. _vq_quantlist__44c0_s_p6_0,
  122199. NULL,
  122200. &_vq_auxt__44c0_s_p6_0,
  122201. NULL,
  122202. 0
  122203. };
  122204. static long _vq_quantlist__44c0_s_p6_1[] = {
  122205. 5,
  122206. 4,
  122207. 6,
  122208. 3,
  122209. 7,
  122210. 2,
  122211. 8,
  122212. 1,
  122213. 9,
  122214. 0,
  122215. 10,
  122216. };
  122217. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122218. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122219. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122220. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122221. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122222. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122223. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122224. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122225. 10,10,10, 8, 8, 8, 8, 8, 8,
  122226. };
  122227. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122228. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122229. 3.5, 4.5,
  122230. };
  122231. static long _vq_quantmap__44c0_s_p6_1[] = {
  122232. 9, 7, 5, 3, 1, 0, 2, 4,
  122233. 6, 8, 10,
  122234. };
  122235. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122236. _vq_quantthresh__44c0_s_p6_1,
  122237. _vq_quantmap__44c0_s_p6_1,
  122238. 11,
  122239. 11
  122240. };
  122241. static static_codebook _44c0_s_p6_1 = {
  122242. 2, 121,
  122243. _vq_lengthlist__44c0_s_p6_1,
  122244. 1, -531365888, 1611661312, 4, 0,
  122245. _vq_quantlist__44c0_s_p6_1,
  122246. NULL,
  122247. &_vq_auxt__44c0_s_p6_1,
  122248. NULL,
  122249. 0
  122250. };
  122251. static long _vq_quantlist__44c0_s_p7_0[] = {
  122252. 6,
  122253. 5,
  122254. 7,
  122255. 4,
  122256. 8,
  122257. 3,
  122258. 9,
  122259. 2,
  122260. 10,
  122261. 1,
  122262. 11,
  122263. 0,
  122264. 12,
  122265. };
  122266. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122267. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122268. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122269. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122270. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122271. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122272. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122273. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122274. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122275. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122276. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122277. 0,12,12,11,11,12,12,13,13,
  122278. };
  122279. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122280. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122281. 12.5, 17.5, 22.5, 27.5,
  122282. };
  122283. static long _vq_quantmap__44c0_s_p7_0[] = {
  122284. 11, 9, 7, 5, 3, 1, 0, 2,
  122285. 4, 6, 8, 10, 12,
  122286. };
  122287. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122288. _vq_quantthresh__44c0_s_p7_0,
  122289. _vq_quantmap__44c0_s_p7_0,
  122290. 13,
  122291. 13
  122292. };
  122293. static static_codebook _44c0_s_p7_0 = {
  122294. 2, 169,
  122295. _vq_lengthlist__44c0_s_p7_0,
  122296. 1, -526516224, 1616117760, 4, 0,
  122297. _vq_quantlist__44c0_s_p7_0,
  122298. NULL,
  122299. &_vq_auxt__44c0_s_p7_0,
  122300. NULL,
  122301. 0
  122302. };
  122303. static long _vq_quantlist__44c0_s_p7_1[] = {
  122304. 2,
  122305. 1,
  122306. 3,
  122307. 0,
  122308. 4,
  122309. };
  122310. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122311. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122312. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122313. };
  122314. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122315. -1.5, -0.5, 0.5, 1.5,
  122316. };
  122317. static long _vq_quantmap__44c0_s_p7_1[] = {
  122318. 3, 1, 0, 2, 4,
  122319. };
  122320. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122321. _vq_quantthresh__44c0_s_p7_1,
  122322. _vq_quantmap__44c0_s_p7_1,
  122323. 5,
  122324. 5
  122325. };
  122326. static static_codebook _44c0_s_p7_1 = {
  122327. 2, 25,
  122328. _vq_lengthlist__44c0_s_p7_1,
  122329. 1, -533725184, 1611661312, 3, 0,
  122330. _vq_quantlist__44c0_s_p7_1,
  122331. NULL,
  122332. &_vq_auxt__44c0_s_p7_1,
  122333. NULL,
  122334. 0
  122335. };
  122336. static long _vq_quantlist__44c0_s_p8_0[] = {
  122337. 2,
  122338. 1,
  122339. 3,
  122340. 0,
  122341. 4,
  122342. };
  122343. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122344. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122345. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122346. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122347. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122348. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122349. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122350. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122351. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122352. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122353. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122354. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122355. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122356. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122357. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122358. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122359. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122360. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122361. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122362. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122363. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122364. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122365. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122366. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122367. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122368. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122369. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122370. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122371. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122372. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122373. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122374. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122375. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122376. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122377. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122378. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122379. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122380. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122381. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122382. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122383. 11,
  122384. };
  122385. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122386. -331.5, -110.5, 110.5, 331.5,
  122387. };
  122388. static long _vq_quantmap__44c0_s_p8_0[] = {
  122389. 3, 1, 0, 2, 4,
  122390. };
  122391. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122392. _vq_quantthresh__44c0_s_p8_0,
  122393. _vq_quantmap__44c0_s_p8_0,
  122394. 5,
  122395. 5
  122396. };
  122397. static static_codebook _44c0_s_p8_0 = {
  122398. 4, 625,
  122399. _vq_lengthlist__44c0_s_p8_0,
  122400. 1, -518283264, 1627103232, 3, 0,
  122401. _vq_quantlist__44c0_s_p8_0,
  122402. NULL,
  122403. &_vq_auxt__44c0_s_p8_0,
  122404. NULL,
  122405. 0
  122406. };
  122407. static long _vq_quantlist__44c0_s_p8_1[] = {
  122408. 6,
  122409. 5,
  122410. 7,
  122411. 4,
  122412. 8,
  122413. 3,
  122414. 9,
  122415. 2,
  122416. 10,
  122417. 1,
  122418. 11,
  122419. 0,
  122420. 12,
  122421. };
  122422. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122423. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122424. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122425. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122426. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122427. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122428. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122429. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122430. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122431. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122432. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122433. 16,13,13,12,12,14,14,15,13,
  122434. };
  122435. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122436. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122437. 42.5, 59.5, 76.5, 93.5,
  122438. };
  122439. static long _vq_quantmap__44c0_s_p8_1[] = {
  122440. 11, 9, 7, 5, 3, 1, 0, 2,
  122441. 4, 6, 8, 10, 12,
  122442. };
  122443. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122444. _vq_quantthresh__44c0_s_p8_1,
  122445. _vq_quantmap__44c0_s_p8_1,
  122446. 13,
  122447. 13
  122448. };
  122449. static static_codebook _44c0_s_p8_1 = {
  122450. 2, 169,
  122451. _vq_lengthlist__44c0_s_p8_1,
  122452. 1, -522616832, 1620115456, 4, 0,
  122453. _vq_quantlist__44c0_s_p8_1,
  122454. NULL,
  122455. &_vq_auxt__44c0_s_p8_1,
  122456. NULL,
  122457. 0
  122458. };
  122459. static long _vq_quantlist__44c0_s_p8_2[] = {
  122460. 8,
  122461. 7,
  122462. 9,
  122463. 6,
  122464. 10,
  122465. 5,
  122466. 11,
  122467. 4,
  122468. 12,
  122469. 3,
  122470. 13,
  122471. 2,
  122472. 14,
  122473. 1,
  122474. 15,
  122475. 0,
  122476. 16,
  122477. };
  122478. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122479. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122480. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122481. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122482. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122483. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122484. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122485. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122486. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122487. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122488. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122489. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122490. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122491. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122492. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122493. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122494. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122495. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122496. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122497. 10,
  122498. };
  122499. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122500. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122501. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122502. };
  122503. static long _vq_quantmap__44c0_s_p8_2[] = {
  122504. 15, 13, 11, 9, 7, 5, 3, 1,
  122505. 0, 2, 4, 6, 8, 10, 12, 14,
  122506. 16,
  122507. };
  122508. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122509. _vq_quantthresh__44c0_s_p8_2,
  122510. _vq_quantmap__44c0_s_p8_2,
  122511. 17,
  122512. 17
  122513. };
  122514. static static_codebook _44c0_s_p8_2 = {
  122515. 2, 289,
  122516. _vq_lengthlist__44c0_s_p8_2,
  122517. 1, -529530880, 1611661312, 5, 0,
  122518. _vq_quantlist__44c0_s_p8_2,
  122519. NULL,
  122520. &_vq_auxt__44c0_s_p8_2,
  122521. NULL,
  122522. 0
  122523. };
  122524. static long _huff_lengthlist__44c0_s_short[] = {
  122525. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122526. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122527. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122528. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122529. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122530. 12,
  122531. };
  122532. static static_codebook _huff_book__44c0_s_short = {
  122533. 2, 81,
  122534. _huff_lengthlist__44c0_s_short,
  122535. 0, 0, 0, 0, 0,
  122536. NULL,
  122537. NULL,
  122538. NULL,
  122539. NULL,
  122540. 0
  122541. };
  122542. static long _huff_lengthlist__44c0_sm_long[] = {
  122543. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122544. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122545. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122546. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122547. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122548. 13,
  122549. };
  122550. static static_codebook _huff_book__44c0_sm_long = {
  122551. 2, 81,
  122552. _huff_lengthlist__44c0_sm_long,
  122553. 0, 0, 0, 0, 0,
  122554. NULL,
  122555. NULL,
  122556. NULL,
  122557. NULL,
  122558. 0
  122559. };
  122560. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122561. 1,
  122562. 0,
  122563. 2,
  122564. };
  122565. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122566. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122567. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122571. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122572. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122576. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122577. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122612. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  122613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122617. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122622. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122657. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122658. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122663. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122668. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  122669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122874. 0, 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,
  122977. };
  122978. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  122979. -0.5, 0.5,
  122980. };
  122981. static long _vq_quantmap__44c0_sm_p1_0[] = {
  122982. 1, 0, 2,
  122983. };
  122984. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  122985. _vq_quantthresh__44c0_sm_p1_0,
  122986. _vq_quantmap__44c0_sm_p1_0,
  122987. 3,
  122988. 3
  122989. };
  122990. static static_codebook _44c0_sm_p1_0 = {
  122991. 8, 6561,
  122992. _vq_lengthlist__44c0_sm_p1_0,
  122993. 1, -535822336, 1611661312, 2, 0,
  122994. _vq_quantlist__44c0_sm_p1_0,
  122995. NULL,
  122996. &_vq_auxt__44c0_sm_p1_0,
  122997. NULL,
  122998. 0
  122999. };
  123000. static long _vq_quantlist__44c0_sm_p2_0[] = {
  123001. 2,
  123002. 1,
  123003. 3,
  123004. 0,
  123005. 4,
  123006. };
  123007. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  123008. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  123010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123011. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  123013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123014. 0, 0, 0, 0, 7, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123047. 0,
  123048. };
  123049. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123050. -1.5, -0.5, 0.5, 1.5,
  123051. };
  123052. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123053. 3, 1, 0, 2, 4,
  123054. };
  123055. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123056. _vq_quantthresh__44c0_sm_p2_0,
  123057. _vq_quantmap__44c0_sm_p2_0,
  123058. 5,
  123059. 5
  123060. };
  123061. static static_codebook _44c0_sm_p2_0 = {
  123062. 4, 625,
  123063. _vq_lengthlist__44c0_sm_p2_0,
  123064. 1, -533725184, 1611661312, 3, 0,
  123065. _vq_quantlist__44c0_sm_p2_0,
  123066. NULL,
  123067. &_vq_auxt__44c0_sm_p2_0,
  123068. NULL,
  123069. 0
  123070. };
  123071. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123072. 4,
  123073. 3,
  123074. 5,
  123075. 2,
  123076. 6,
  123077. 1,
  123078. 7,
  123079. 0,
  123080. 8,
  123081. };
  123082. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123083. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123084. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123085. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123086. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123087. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123088. 0,
  123089. };
  123090. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123091. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123092. };
  123093. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123094. 7, 5, 3, 1, 0, 2, 4, 6,
  123095. 8,
  123096. };
  123097. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123098. _vq_quantthresh__44c0_sm_p3_0,
  123099. _vq_quantmap__44c0_sm_p3_0,
  123100. 9,
  123101. 9
  123102. };
  123103. static static_codebook _44c0_sm_p3_0 = {
  123104. 2, 81,
  123105. _vq_lengthlist__44c0_sm_p3_0,
  123106. 1, -531628032, 1611661312, 4, 0,
  123107. _vq_quantlist__44c0_sm_p3_0,
  123108. NULL,
  123109. &_vq_auxt__44c0_sm_p3_0,
  123110. NULL,
  123111. 0
  123112. };
  123113. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123114. 4,
  123115. 3,
  123116. 5,
  123117. 2,
  123118. 6,
  123119. 1,
  123120. 7,
  123121. 0,
  123122. 8,
  123123. };
  123124. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123125. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123126. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123127. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123128. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123129. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123130. 11,
  123131. };
  123132. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123133. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123134. };
  123135. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123136. 7, 5, 3, 1, 0, 2, 4, 6,
  123137. 8,
  123138. };
  123139. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123140. _vq_quantthresh__44c0_sm_p4_0,
  123141. _vq_quantmap__44c0_sm_p4_0,
  123142. 9,
  123143. 9
  123144. };
  123145. static static_codebook _44c0_sm_p4_0 = {
  123146. 2, 81,
  123147. _vq_lengthlist__44c0_sm_p4_0,
  123148. 1, -531628032, 1611661312, 4, 0,
  123149. _vq_quantlist__44c0_sm_p4_0,
  123150. NULL,
  123151. &_vq_auxt__44c0_sm_p4_0,
  123152. NULL,
  123153. 0
  123154. };
  123155. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123156. 8,
  123157. 7,
  123158. 9,
  123159. 6,
  123160. 10,
  123161. 5,
  123162. 11,
  123163. 4,
  123164. 12,
  123165. 3,
  123166. 13,
  123167. 2,
  123168. 14,
  123169. 1,
  123170. 15,
  123171. 0,
  123172. 16,
  123173. };
  123174. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123175. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123176. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123177. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123178. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123179. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123180. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123181. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123182. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123183. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123184. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123185. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123186. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123187. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123188. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123189. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123190. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123191. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123192. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123193. 14,
  123194. };
  123195. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123196. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123197. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123198. };
  123199. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123200. 15, 13, 11, 9, 7, 5, 3, 1,
  123201. 0, 2, 4, 6, 8, 10, 12, 14,
  123202. 16,
  123203. };
  123204. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123205. _vq_quantthresh__44c0_sm_p5_0,
  123206. _vq_quantmap__44c0_sm_p5_0,
  123207. 17,
  123208. 17
  123209. };
  123210. static static_codebook _44c0_sm_p5_0 = {
  123211. 2, 289,
  123212. _vq_lengthlist__44c0_sm_p5_0,
  123213. 1, -529530880, 1611661312, 5, 0,
  123214. _vq_quantlist__44c0_sm_p5_0,
  123215. NULL,
  123216. &_vq_auxt__44c0_sm_p5_0,
  123217. NULL,
  123218. 0
  123219. };
  123220. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123221. 1,
  123222. 0,
  123223. 2,
  123224. };
  123225. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123226. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123227. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123228. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123229. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123230. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123231. 11,
  123232. };
  123233. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123234. -5.5, 5.5,
  123235. };
  123236. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123237. 1, 0, 2,
  123238. };
  123239. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123240. _vq_quantthresh__44c0_sm_p6_0,
  123241. _vq_quantmap__44c0_sm_p6_0,
  123242. 3,
  123243. 3
  123244. };
  123245. static static_codebook _44c0_sm_p6_0 = {
  123246. 4, 81,
  123247. _vq_lengthlist__44c0_sm_p6_0,
  123248. 1, -529137664, 1618345984, 2, 0,
  123249. _vq_quantlist__44c0_sm_p6_0,
  123250. NULL,
  123251. &_vq_auxt__44c0_sm_p6_0,
  123252. NULL,
  123253. 0
  123254. };
  123255. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123256. 5,
  123257. 4,
  123258. 6,
  123259. 3,
  123260. 7,
  123261. 2,
  123262. 8,
  123263. 1,
  123264. 9,
  123265. 0,
  123266. 10,
  123267. };
  123268. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123269. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123270. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123271. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123272. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123273. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123274. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123275. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123276. 10,10,10, 8, 8, 8, 8, 8, 8,
  123277. };
  123278. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123279. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123280. 3.5, 4.5,
  123281. };
  123282. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123283. 9, 7, 5, 3, 1, 0, 2, 4,
  123284. 6, 8, 10,
  123285. };
  123286. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123287. _vq_quantthresh__44c0_sm_p6_1,
  123288. _vq_quantmap__44c0_sm_p6_1,
  123289. 11,
  123290. 11
  123291. };
  123292. static static_codebook _44c0_sm_p6_1 = {
  123293. 2, 121,
  123294. _vq_lengthlist__44c0_sm_p6_1,
  123295. 1, -531365888, 1611661312, 4, 0,
  123296. _vq_quantlist__44c0_sm_p6_1,
  123297. NULL,
  123298. &_vq_auxt__44c0_sm_p6_1,
  123299. NULL,
  123300. 0
  123301. };
  123302. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123303. 6,
  123304. 5,
  123305. 7,
  123306. 4,
  123307. 8,
  123308. 3,
  123309. 9,
  123310. 2,
  123311. 10,
  123312. 1,
  123313. 11,
  123314. 0,
  123315. 12,
  123316. };
  123317. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123318. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123319. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123320. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123321. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123322. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123323. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123324. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123325. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123326. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123327. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123328. 0,12,12,11,11,13,12,14,14,
  123329. };
  123330. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123331. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123332. 12.5, 17.5, 22.5, 27.5,
  123333. };
  123334. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123335. 11, 9, 7, 5, 3, 1, 0, 2,
  123336. 4, 6, 8, 10, 12,
  123337. };
  123338. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123339. _vq_quantthresh__44c0_sm_p7_0,
  123340. _vq_quantmap__44c0_sm_p7_0,
  123341. 13,
  123342. 13
  123343. };
  123344. static static_codebook _44c0_sm_p7_0 = {
  123345. 2, 169,
  123346. _vq_lengthlist__44c0_sm_p7_0,
  123347. 1, -526516224, 1616117760, 4, 0,
  123348. _vq_quantlist__44c0_sm_p7_0,
  123349. NULL,
  123350. &_vq_auxt__44c0_sm_p7_0,
  123351. NULL,
  123352. 0
  123353. };
  123354. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123355. 2,
  123356. 1,
  123357. 3,
  123358. 0,
  123359. 4,
  123360. };
  123361. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123362. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123363. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123364. };
  123365. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123366. -1.5, -0.5, 0.5, 1.5,
  123367. };
  123368. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123369. 3, 1, 0, 2, 4,
  123370. };
  123371. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123372. _vq_quantthresh__44c0_sm_p7_1,
  123373. _vq_quantmap__44c0_sm_p7_1,
  123374. 5,
  123375. 5
  123376. };
  123377. static static_codebook _44c0_sm_p7_1 = {
  123378. 2, 25,
  123379. _vq_lengthlist__44c0_sm_p7_1,
  123380. 1, -533725184, 1611661312, 3, 0,
  123381. _vq_quantlist__44c0_sm_p7_1,
  123382. NULL,
  123383. &_vq_auxt__44c0_sm_p7_1,
  123384. NULL,
  123385. 0
  123386. };
  123387. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123388. 4,
  123389. 3,
  123390. 5,
  123391. 2,
  123392. 6,
  123393. 1,
  123394. 7,
  123395. 0,
  123396. 8,
  123397. };
  123398. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123399. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123400. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123401. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123402. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123403. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123404. 12,
  123405. };
  123406. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123407. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123408. };
  123409. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123410. 7, 5, 3, 1, 0, 2, 4, 6,
  123411. 8,
  123412. };
  123413. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123414. _vq_quantthresh__44c0_sm_p8_0,
  123415. _vq_quantmap__44c0_sm_p8_0,
  123416. 9,
  123417. 9
  123418. };
  123419. static static_codebook _44c0_sm_p8_0 = {
  123420. 2, 81,
  123421. _vq_lengthlist__44c0_sm_p8_0,
  123422. 1, -516186112, 1627103232, 4, 0,
  123423. _vq_quantlist__44c0_sm_p8_0,
  123424. NULL,
  123425. &_vq_auxt__44c0_sm_p8_0,
  123426. NULL,
  123427. 0
  123428. };
  123429. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123430. 6,
  123431. 5,
  123432. 7,
  123433. 4,
  123434. 8,
  123435. 3,
  123436. 9,
  123437. 2,
  123438. 10,
  123439. 1,
  123440. 11,
  123441. 0,
  123442. 12,
  123443. };
  123444. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123445. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123446. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123447. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123448. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123449. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123450. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123451. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123452. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123453. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123454. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123455. 20,13,13,12,12,16,13,15,13,
  123456. };
  123457. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123458. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123459. 42.5, 59.5, 76.5, 93.5,
  123460. };
  123461. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123462. 11, 9, 7, 5, 3, 1, 0, 2,
  123463. 4, 6, 8, 10, 12,
  123464. };
  123465. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123466. _vq_quantthresh__44c0_sm_p8_1,
  123467. _vq_quantmap__44c0_sm_p8_1,
  123468. 13,
  123469. 13
  123470. };
  123471. static static_codebook _44c0_sm_p8_1 = {
  123472. 2, 169,
  123473. _vq_lengthlist__44c0_sm_p8_1,
  123474. 1, -522616832, 1620115456, 4, 0,
  123475. _vq_quantlist__44c0_sm_p8_1,
  123476. NULL,
  123477. &_vq_auxt__44c0_sm_p8_1,
  123478. NULL,
  123479. 0
  123480. };
  123481. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123482. 8,
  123483. 7,
  123484. 9,
  123485. 6,
  123486. 10,
  123487. 5,
  123488. 11,
  123489. 4,
  123490. 12,
  123491. 3,
  123492. 13,
  123493. 2,
  123494. 14,
  123495. 1,
  123496. 15,
  123497. 0,
  123498. 16,
  123499. };
  123500. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123501. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123502. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123503. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123504. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123505. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123506. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123507. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123508. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123509. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123510. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123511. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123512. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123513. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123514. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123515. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123516. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123517. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123518. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123519. 9,
  123520. };
  123521. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123522. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123523. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123524. };
  123525. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123526. 15, 13, 11, 9, 7, 5, 3, 1,
  123527. 0, 2, 4, 6, 8, 10, 12, 14,
  123528. 16,
  123529. };
  123530. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123531. _vq_quantthresh__44c0_sm_p8_2,
  123532. _vq_quantmap__44c0_sm_p8_2,
  123533. 17,
  123534. 17
  123535. };
  123536. static static_codebook _44c0_sm_p8_2 = {
  123537. 2, 289,
  123538. _vq_lengthlist__44c0_sm_p8_2,
  123539. 1, -529530880, 1611661312, 5, 0,
  123540. _vq_quantlist__44c0_sm_p8_2,
  123541. NULL,
  123542. &_vq_auxt__44c0_sm_p8_2,
  123543. NULL,
  123544. 0
  123545. };
  123546. static long _huff_lengthlist__44c0_sm_short[] = {
  123547. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123548. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123549. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123550. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123551. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123552. 12,
  123553. };
  123554. static static_codebook _huff_book__44c0_sm_short = {
  123555. 2, 81,
  123556. _huff_lengthlist__44c0_sm_short,
  123557. 0, 0, 0, 0, 0,
  123558. NULL,
  123559. NULL,
  123560. NULL,
  123561. NULL,
  123562. 0
  123563. };
  123564. static long _huff_lengthlist__44c1_s_long[] = {
  123565. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123566. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123567. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123568. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123569. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123570. 11,
  123571. };
  123572. static static_codebook _huff_book__44c1_s_long = {
  123573. 2, 81,
  123574. _huff_lengthlist__44c1_s_long,
  123575. 0, 0, 0, 0, 0,
  123576. NULL,
  123577. NULL,
  123578. NULL,
  123579. NULL,
  123580. 0
  123581. };
  123582. static long _vq_quantlist__44c1_s_p1_0[] = {
  123583. 1,
  123584. 0,
  123585. 2,
  123586. };
  123587. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123588. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123589. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123593. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123594. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123598. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123599. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  123634. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123639. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  123640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  123644. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123679. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123680. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123685. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123690. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123896. 0, 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,
  123999. };
  124000. static float _vq_quantthresh__44c1_s_p1_0[] = {
  124001. -0.5, 0.5,
  124002. };
  124003. static long _vq_quantmap__44c1_s_p1_0[] = {
  124004. 1, 0, 2,
  124005. };
  124006. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  124007. _vq_quantthresh__44c1_s_p1_0,
  124008. _vq_quantmap__44c1_s_p1_0,
  124009. 3,
  124010. 3
  124011. };
  124012. static static_codebook _44c1_s_p1_0 = {
  124013. 8, 6561,
  124014. _vq_lengthlist__44c1_s_p1_0,
  124015. 1, -535822336, 1611661312, 2, 0,
  124016. _vq_quantlist__44c1_s_p1_0,
  124017. NULL,
  124018. &_vq_auxt__44c1_s_p1_0,
  124019. NULL,
  124020. 0
  124021. };
  124022. static long _vq_quantlist__44c1_s_p2_0[] = {
  124023. 2,
  124024. 1,
  124025. 3,
  124026. 0,
  124027. 4,
  124028. };
  124029. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124030. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124033. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124036. 0, 0, 0, 0, 6, 6, 6, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124069. 0,
  124070. };
  124071. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124072. -1.5, -0.5, 0.5, 1.5,
  124073. };
  124074. static long _vq_quantmap__44c1_s_p2_0[] = {
  124075. 3, 1, 0, 2, 4,
  124076. };
  124077. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124078. _vq_quantthresh__44c1_s_p2_0,
  124079. _vq_quantmap__44c1_s_p2_0,
  124080. 5,
  124081. 5
  124082. };
  124083. static static_codebook _44c1_s_p2_0 = {
  124084. 4, 625,
  124085. _vq_lengthlist__44c1_s_p2_0,
  124086. 1, -533725184, 1611661312, 3, 0,
  124087. _vq_quantlist__44c1_s_p2_0,
  124088. NULL,
  124089. &_vq_auxt__44c1_s_p2_0,
  124090. NULL,
  124091. 0
  124092. };
  124093. static long _vq_quantlist__44c1_s_p3_0[] = {
  124094. 4,
  124095. 3,
  124096. 5,
  124097. 2,
  124098. 6,
  124099. 1,
  124100. 7,
  124101. 0,
  124102. 8,
  124103. };
  124104. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124105. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124106. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124107. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124108. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124109. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124110. 0,
  124111. };
  124112. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124113. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124114. };
  124115. static long _vq_quantmap__44c1_s_p3_0[] = {
  124116. 7, 5, 3, 1, 0, 2, 4, 6,
  124117. 8,
  124118. };
  124119. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124120. _vq_quantthresh__44c1_s_p3_0,
  124121. _vq_quantmap__44c1_s_p3_0,
  124122. 9,
  124123. 9
  124124. };
  124125. static static_codebook _44c1_s_p3_0 = {
  124126. 2, 81,
  124127. _vq_lengthlist__44c1_s_p3_0,
  124128. 1, -531628032, 1611661312, 4, 0,
  124129. _vq_quantlist__44c1_s_p3_0,
  124130. NULL,
  124131. &_vq_auxt__44c1_s_p3_0,
  124132. NULL,
  124133. 0
  124134. };
  124135. static long _vq_quantlist__44c1_s_p4_0[] = {
  124136. 4,
  124137. 3,
  124138. 5,
  124139. 2,
  124140. 6,
  124141. 1,
  124142. 7,
  124143. 0,
  124144. 8,
  124145. };
  124146. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124147. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124148. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124149. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124150. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124151. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124152. 11,
  124153. };
  124154. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124155. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124156. };
  124157. static long _vq_quantmap__44c1_s_p4_0[] = {
  124158. 7, 5, 3, 1, 0, 2, 4, 6,
  124159. 8,
  124160. };
  124161. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124162. _vq_quantthresh__44c1_s_p4_0,
  124163. _vq_quantmap__44c1_s_p4_0,
  124164. 9,
  124165. 9
  124166. };
  124167. static static_codebook _44c1_s_p4_0 = {
  124168. 2, 81,
  124169. _vq_lengthlist__44c1_s_p4_0,
  124170. 1, -531628032, 1611661312, 4, 0,
  124171. _vq_quantlist__44c1_s_p4_0,
  124172. NULL,
  124173. &_vq_auxt__44c1_s_p4_0,
  124174. NULL,
  124175. 0
  124176. };
  124177. static long _vq_quantlist__44c1_s_p5_0[] = {
  124178. 8,
  124179. 7,
  124180. 9,
  124181. 6,
  124182. 10,
  124183. 5,
  124184. 11,
  124185. 4,
  124186. 12,
  124187. 3,
  124188. 13,
  124189. 2,
  124190. 14,
  124191. 1,
  124192. 15,
  124193. 0,
  124194. 16,
  124195. };
  124196. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124197. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124198. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124199. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124200. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124201. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124202. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124203. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124204. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124205. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124206. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124207. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124208. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124209. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124210. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124211. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124212. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124213. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124214. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124215. 14,
  124216. };
  124217. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124218. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124219. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124220. };
  124221. static long _vq_quantmap__44c1_s_p5_0[] = {
  124222. 15, 13, 11, 9, 7, 5, 3, 1,
  124223. 0, 2, 4, 6, 8, 10, 12, 14,
  124224. 16,
  124225. };
  124226. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124227. _vq_quantthresh__44c1_s_p5_0,
  124228. _vq_quantmap__44c1_s_p5_0,
  124229. 17,
  124230. 17
  124231. };
  124232. static static_codebook _44c1_s_p5_0 = {
  124233. 2, 289,
  124234. _vq_lengthlist__44c1_s_p5_0,
  124235. 1, -529530880, 1611661312, 5, 0,
  124236. _vq_quantlist__44c1_s_p5_0,
  124237. NULL,
  124238. &_vq_auxt__44c1_s_p5_0,
  124239. NULL,
  124240. 0
  124241. };
  124242. static long _vq_quantlist__44c1_s_p6_0[] = {
  124243. 1,
  124244. 0,
  124245. 2,
  124246. };
  124247. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124248. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124249. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124250. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124251. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124252. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124253. 11,
  124254. };
  124255. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124256. -5.5, 5.5,
  124257. };
  124258. static long _vq_quantmap__44c1_s_p6_0[] = {
  124259. 1, 0, 2,
  124260. };
  124261. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124262. _vq_quantthresh__44c1_s_p6_0,
  124263. _vq_quantmap__44c1_s_p6_0,
  124264. 3,
  124265. 3
  124266. };
  124267. static static_codebook _44c1_s_p6_0 = {
  124268. 4, 81,
  124269. _vq_lengthlist__44c1_s_p6_0,
  124270. 1, -529137664, 1618345984, 2, 0,
  124271. _vq_quantlist__44c1_s_p6_0,
  124272. NULL,
  124273. &_vq_auxt__44c1_s_p6_0,
  124274. NULL,
  124275. 0
  124276. };
  124277. static long _vq_quantlist__44c1_s_p6_1[] = {
  124278. 5,
  124279. 4,
  124280. 6,
  124281. 3,
  124282. 7,
  124283. 2,
  124284. 8,
  124285. 1,
  124286. 9,
  124287. 0,
  124288. 10,
  124289. };
  124290. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124291. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124292. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124293. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124294. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124295. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124296. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124297. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124298. 10,10,10, 8, 8, 8, 8, 8, 8,
  124299. };
  124300. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124301. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124302. 3.5, 4.5,
  124303. };
  124304. static long _vq_quantmap__44c1_s_p6_1[] = {
  124305. 9, 7, 5, 3, 1, 0, 2, 4,
  124306. 6, 8, 10,
  124307. };
  124308. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124309. _vq_quantthresh__44c1_s_p6_1,
  124310. _vq_quantmap__44c1_s_p6_1,
  124311. 11,
  124312. 11
  124313. };
  124314. static static_codebook _44c1_s_p6_1 = {
  124315. 2, 121,
  124316. _vq_lengthlist__44c1_s_p6_1,
  124317. 1, -531365888, 1611661312, 4, 0,
  124318. _vq_quantlist__44c1_s_p6_1,
  124319. NULL,
  124320. &_vq_auxt__44c1_s_p6_1,
  124321. NULL,
  124322. 0
  124323. };
  124324. static long _vq_quantlist__44c1_s_p7_0[] = {
  124325. 6,
  124326. 5,
  124327. 7,
  124328. 4,
  124329. 8,
  124330. 3,
  124331. 9,
  124332. 2,
  124333. 10,
  124334. 1,
  124335. 11,
  124336. 0,
  124337. 12,
  124338. };
  124339. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124340. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124341. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124342. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124343. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124344. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124345. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124346. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124347. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124348. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124349. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124350. 0,12,11,11,11,13,10,14,13,
  124351. };
  124352. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124353. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124354. 12.5, 17.5, 22.5, 27.5,
  124355. };
  124356. static long _vq_quantmap__44c1_s_p7_0[] = {
  124357. 11, 9, 7, 5, 3, 1, 0, 2,
  124358. 4, 6, 8, 10, 12,
  124359. };
  124360. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124361. _vq_quantthresh__44c1_s_p7_0,
  124362. _vq_quantmap__44c1_s_p7_0,
  124363. 13,
  124364. 13
  124365. };
  124366. static static_codebook _44c1_s_p7_0 = {
  124367. 2, 169,
  124368. _vq_lengthlist__44c1_s_p7_0,
  124369. 1, -526516224, 1616117760, 4, 0,
  124370. _vq_quantlist__44c1_s_p7_0,
  124371. NULL,
  124372. &_vq_auxt__44c1_s_p7_0,
  124373. NULL,
  124374. 0
  124375. };
  124376. static long _vq_quantlist__44c1_s_p7_1[] = {
  124377. 2,
  124378. 1,
  124379. 3,
  124380. 0,
  124381. 4,
  124382. };
  124383. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124384. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124385. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124386. };
  124387. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124388. -1.5, -0.5, 0.5, 1.5,
  124389. };
  124390. static long _vq_quantmap__44c1_s_p7_1[] = {
  124391. 3, 1, 0, 2, 4,
  124392. };
  124393. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124394. _vq_quantthresh__44c1_s_p7_1,
  124395. _vq_quantmap__44c1_s_p7_1,
  124396. 5,
  124397. 5
  124398. };
  124399. static static_codebook _44c1_s_p7_1 = {
  124400. 2, 25,
  124401. _vq_lengthlist__44c1_s_p7_1,
  124402. 1, -533725184, 1611661312, 3, 0,
  124403. _vq_quantlist__44c1_s_p7_1,
  124404. NULL,
  124405. &_vq_auxt__44c1_s_p7_1,
  124406. NULL,
  124407. 0
  124408. };
  124409. static long _vq_quantlist__44c1_s_p8_0[] = {
  124410. 6,
  124411. 5,
  124412. 7,
  124413. 4,
  124414. 8,
  124415. 3,
  124416. 9,
  124417. 2,
  124418. 10,
  124419. 1,
  124420. 11,
  124421. 0,
  124422. 12,
  124423. };
  124424. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124425. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124426. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124427. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124428. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124429. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124430. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124431. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124432. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124433. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124434. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124435. 10,10,10,10,10,10,10,10,10,
  124436. };
  124437. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124438. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124439. 552.5, 773.5, 994.5, 1215.5,
  124440. };
  124441. static long _vq_quantmap__44c1_s_p8_0[] = {
  124442. 11, 9, 7, 5, 3, 1, 0, 2,
  124443. 4, 6, 8, 10, 12,
  124444. };
  124445. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124446. _vq_quantthresh__44c1_s_p8_0,
  124447. _vq_quantmap__44c1_s_p8_0,
  124448. 13,
  124449. 13
  124450. };
  124451. static static_codebook _44c1_s_p8_0 = {
  124452. 2, 169,
  124453. _vq_lengthlist__44c1_s_p8_0,
  124454. 1, -514541568, 1627103232, 4, 0,
  124455. _vq_quantlist__44c1_s_p8_0,
  124456. NULL,
  124457. &_vq_auxt__44c1_s_p8_0,
  124458. NULL,
  124459. 0
  124460. };
  124461. static long _vq_quantlist__44c1_s_p8_1[] = {
  124462. 6,
  124463. 5,
  124464. 7,
  124465. 4,
  124466. 8,
  124467. 3,
  124468. 9,
  124469. 2,
  124470. 10,
  124471. 1,
  124472. 11,
  124473. 0,
  124474. 12,
  124475. };
  124476. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124477. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124478. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124479. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124480. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124481. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124482. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124483. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124484. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124485. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124486. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124487. 16,13,12,12,11,14,12,15,13,
  124488. };
  124489. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124490. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124491. 42.5, 59.5, 76.5, 93.5,
  124492. };
  124493. static long _vq_quantmap__44c1_s_p8_1[] = {
  124494. 11, 9, 7, 5, 3, 1, 0, 2,
  124495. 4, 6, 8, 10, 12,
  124496. };
  124497. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124498. _vq_quantthresh__44c1_s_p8_1,
  124499. _vq_quantmap__44c1_s_p8_1,
  124500. 13,
  124501. 13
  124502. };
  124503. static static_codebook _44c1_s_p8_1 = {
  124504. 2, 169,
  124505. _vq_lengthlist__44c1_s_p8_1,
  124506. 1, -522616832, 1620115456, 4, 0,
  124507. _vq_quantlist__44c1_s_p8_1,
  124508. NULL,
  124509. &_vq_auxt__44c1_s_p8_1,
  124510. NULL,
  124511. 0
  124512. };
  124513. static long _vq_quantlist__44c1_s_p8_2[] = {
  124514. 8,
  124515. 7,
  124516. 9,
  124517. 6,
  124518. 10,
  124519. 5,
  124520. 11,
  124521. 4,
  124522. 12,
  124523. 3,
  124524. 13,
  124525. 2,
  124526. 14,
  124527. 1,
  124528. 15,
  124529. 0,
  124530. 16,
  124531. };
  124532. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124533. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124534. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124535. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124536. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124537. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124538. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124539. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124540. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124541. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124542. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124543. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124544. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124545. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124546. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124547. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124548. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124549. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124550. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124551. 9,
  124552. };
  124553. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124554. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124555. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124556. };
  124557. static long _vq_quantmap__44c1_s_p8_2[] = {
  124558. 15, 13, 11, 9, 7, 5, 3, 1,
  124559. 0, 2, 4, 6, 8, 10, 12, 14,
  124560. 16,
  124561. };
  124562. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124563. _vq_quantthresh__44c1_s_p8_2,
  124564. _vq_quantmap__44c1_s_p8_2,
  124565. 17,
  124566. 17
  124567. };
  124568. static static_codebook _44c1_s_p8_2 = {
  124569. 2, 289,
  124570. _vq_lengthlist__44c1_s_p8_2,
  124571. 1, -529530880, 1611661312, 5, 0,
  124572. _vq_quantlist__44c1_s_p8_2,
  124573. NULL,
  124574. &_vq_auxt__44c1_s_p8_2,
  124575. NULL,
  124576. 0
  124577. };
  124578. static long _huff_lengthlist__44c1_s_short[] = {
  124579. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124580. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124581. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124582. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124583. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124584. 11,
  124585. };
  124586. static static_codebook _huff_book__44c1_s_short = {
  124587. 2, 81,
  124588. _huff_lengthlist__44c1_s_short,
  124589. 0, 0, 0, 0, 0,
  124590. NULL,
  124591. NULL,
  124592. NULL,
  124593. NULL,
  124594. 0
  124595. };
  124596. static long _huff_lengthlist__44c1_sm_long[] = {
  124597. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124598. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124599. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124600. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124601. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124602. 11,
  124603. };
  124604. static static_codebook _huff_book__44c1_sm_long = {
  124605. 2, 81,
  124606. _huff_lengthlist__44c1_sm_long,
  124607. 0, 0, 0, 0, 0,
  124608. NULL,
  124609. NULL,
  124610. NULL,
  124611. NULL,
  124612. 0
  124613. };
  124614. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124615. 1,
  124616. 0,
  124617. 2,
  124618. };
  124619. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124620. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124621. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124625. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124626. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124630. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124631. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  124666. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124671. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  124676. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124711. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124712. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124717. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124722. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  124723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124928. 0, 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,
  125031. };
  125032. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125033. -0.5, 0.5,
  125034. };
  125035. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125036. 1, 0, 2,
  125037. };
  125038. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125039. _vq_quantthresh__44c1_sm_p1_0,
  125040. _vq_quantmap__44c1_sm_p1_0,
  125041. 3,
  125042. 3
  125043. };
  125044. static static_codebook _44c1_sm_p1_0 = {
  125045. 8, 6561,
  125046. _vq_lengthlist__44c1_sm_p1_0,
  125047. 1, -535822336, 1611661312, 2, 0,
  125048. _vq_quantlist__44c1_sm_p1_0,
  125049. NULL,
  125050. &_vq_auxt__44c1_sm_p1_0,
  125051. NULL,
  125052. 0
  125053. };
  125054. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125055. 2,
  125056. 1,
  125057. 3,
  125058. 0,
  125059. 4,
  125060. };
  125061. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125062. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125065. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125068. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125101. 0,
  125102. };
  125103. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125104. -1.5, -0.5, 0.5, 1.5,
  125105. };
  125106. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125107. 3, 1, 0, 2, 4,
  125108. };
  125109. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125110. _vq_quantthresh__44c1_sm_p2_0,
  125111. _vq_quantmap__44c1_sm_p2_0,
  125112. 5,
  125113. 5
  125114. };
  125115. static static_codebook _44c1_sm_p2_0 = {
  125116. 4, 625,
  125117. _vq_lengthlist__44c1_sm_p2_0,
  125118. 1, -533725184, 1611661312, 3, 0,
  125119. _vq_quantlist__44c1_sm_p2_0,
  125120. NULL,
  125121. &_vq_auxt__44c1_sm_p2_0,
  125122. NULL,
  125123. 0
  125124. };
  125125. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125126. 4,
  125127. 3,
  125128. 5,
  125129. 2,
  125130. 6,
  125131. 1,
  125132. 7,
  125133. 0,
  125134. 8,
  125135. };
  125136. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125137. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125138. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125139. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125140. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125141. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125142. 0,
  125143. };
  125144. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125145. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125146. };
  125147. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125148. 7, 5, 3, 1, 0, 2, 4, 6,
  125149. 8,
  125150. };
  125151. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125152. _vq_quantthresh__44c1_sm_p3_0,
  125153. _vq_quantmap__44c1_sm_p3_0,
  125154. 9,
  125155. 9
  125156. };
  125157. static static_codebook _44c1_sm_p3_0 = {
  125158. 2, 81,
  125159. _vq_lengthlist__44c1_sm_p3_0,
  125160. 1, -531628032, 1611661312, 4, 0,
  125161. _vq_quantlist__44c1_sm_p3_0,
  125162. NULL,
  125163. &_vq_auxt__44c1_sm_p3_0,
  125164. NULL,
  125165. 0
  125166. };
  125167. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125168. 4,
  125169. 3,
  125170. 5,
  125171. 2,
  125172. 6,
  125173. 1,
  125174. 7,
  125175. 0,
  125176. 8,
  125177. };
  125178. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125179. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125180. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125181. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125182. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125183. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125184. 11,
  125185. };
  125186. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125187. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125188. };
  125189. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125190. 7, 5, 3, 1, 0, 2, 4, 6,
  125191. 8,
  125192. };
  125193. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125194. _vq_quantthresh__44c1_sm_p4_0,
  125195. _vq_quantmap__44c1_sm_p4_0,
  125196. 9,
  125197. 9
  125198. };
  125199. static static_codebook _44c1_sm_p4_0 = {
  125200. 2, 81,
  125201. _vq_lengthlist__44c1_sm_p4_0,
  125202. 1, -531628032, 1611661312, 4, 0,
  125203. _vq_quantlist__44c1_sm_p4_0,
  125204. NULL,
  125205. &_vq_auxt__44c1_sm_p4_0,
  125206. NULL,
  125207. 0
  125208. };
  125209. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125210. 8,
  125211. 7,
  125212. 9,
  125213. 6,
  125214. 10,
  125215. 5,
  125216. 11,
  125217. 4,
  125218. 12,
  125219. 3,
  125220. 13,
  125221. 2,
  125222. 14,
  125223. 1,
  125224. 15,
  125225. 0,
  125226. 16,
  125227. };
  125228. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125229. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125230. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125231. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125232. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125233. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125234. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125235. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125236. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125237. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125238. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125239. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125240. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125241. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125242. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125243. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125244. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125245. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125246. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125247. 14,
  125248. };
  125249. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125250. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125251. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125252. };
  125253. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125254. 15, 13, 11, 9, 7, 5, 3, 1,
  125255. 0, 2, 4, 6, 8, 10, 12, 14,
  125256. 16,
  125257. };
  125258. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125259. _vq_quantthresh__44c1_sm_p5_0,
  125260. _vq_quantmap__44c1_sm_p5_0,
  125261. 17,
  125262. 17
  125263. };
  125264. static static_codebook _44c1_sm_p5_0 = {
  125265. 2, 289,
  125266. _vq_lengthlist__44c1_sm_p5_0,
  125267. 1, -529530880, 1611661312, 5, 0,
  125268. _vq_quantlist__44c1_sm_p5_0,
  125269. NULL,
  125270. &_vq_auxt__44c1_sm_p5_0,
  125271. NULL,
  125272. 0
  125273. };
  125274. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125275. 1,
  125276. 0,
  125277. 2,
  125278. };
  125279. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125280. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125281. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125282. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125283. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125284. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125285. 11,
  125286. };
  125287. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125288. -5.5, 5.5,
  125289. };
  125290. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125291. 1, 0, 2,
  125292. };
  125293. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125294. _vq_quantthresh__44c1_sm_p6_0,
  125295. _vq_quantmap__44c1_sm_p6_0,
  125296. 3,
  125297. 3
  125298. };
  125299. static static_codebook _44c1_sm_p6_0 = {
  125300. 4, 81,
  125301. _vq_lengthlist__44c1_sm_p6_0,
  125302. 1, -529137664, 1618345984, 2, 0,
  125303. _vq_quantlist__44c1_sm_p6_0,
  125304. NULL,
  125305. &_vq_auxt__44c1_sm_p6_0,
  125306. NULL,
  125307. 0
  125308. };
  125309. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125310. 5,
  125311. 4,
  125312. 6,
  125313. 3,
  125314. 7,
  125315. 2,
  125316. 8,
  125317. 1,
  125318. 9,
  125319. 0,
  125320. 10,
  125321. };
  125322. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125323. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125324. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125325. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125326. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125327. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125328. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125329. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125330. 10,10,10, 8, 8, 8, 8, 8, 8,
  125331. };
  125332. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125333. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125334. 3.5, 4.5,
  125335. };
  125336. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125337. 9, 7, 5, 3, 1, 0, 2, 4,
  125338. 6, 8, 10,
  125339. };
  125340. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125341. _vq_quantthresh__44c1_sm_p6_1,
  125342. _vq_quantmap__44c1_sm_p6_1,
  125343. 11,
  125344. 11
  125345. };
  125346. static static_codebook _44c1_sm_p6_1 = {
  125347. 2, 121,
  125348. _vq_lengthlist__44c1_sm_p6_1,
  125349. 1, -531365888, 1611661312, 4, 0,
  125350. _vq_quantlist__44c1_sm_p6_1,
  125351. NULL,
  125352. &_vq_auxt__44c1_sm_p6_1,
  125353. NULL,
  125354. 0
  125355. };
  125356. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125357. 6,
  125358. 5,
  125359. 7,
  125360. 4,
  125361. 8,
  125362. 3,
  125363. 9,
  125364. 2,
  125365. 10,
  125366. 1,
  125367. 11,
  125368. 0,
  125369. 12,
  125370. };
  125371. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125372. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125373. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125374. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125375. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125376. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125377. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125378. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125379. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125380. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125381. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125382. 0,12,12,11,11,13,12,14,13,
  125383. };
  125384. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125385. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125386. 12.5, 17.5, 22.5, 27.5,
  125387. };
  125388. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125389. 11, 9, 7, 5, 3, 1, 0, 2,
  125390. 4, 6, 8, 10, 12,
  125391. };
  125392. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125393. _vq_quantthresh__44c1_sm_p7_0,
  125394. _vq_quantmap__44c1_sm_p7_0,
  125395. 13,
  125396. 13
  125397. };
  125398. static static_codebook _44c1_sm_p7_0 = {
  125399. 2, 169,
  125400. _vq_lengthlist__44c1_sm_p7_0,
  125401. 1, -526516224, 1616117760, 4, 0,
  125402. _vq_quantlist__44c1_sm_p7_0,
  125403. NULL,
  125404. &_vq_auxt__44c1_sm_p7_0,
  125405. NULL,
  125406. 0
  125407. };
  125408. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125409. 2,
  125410. 1,
  125411. 3,
  125412. 0,
  125413. 4,
  125414. };
  125415. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125416. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125417. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125418. };
  125419. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125420. -1.5, -0.5, 0.5, 1.5,
  125421. };
  125422. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125423. 3, 1, 0, 2, 4,
  125424. };
  125425. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125426. _vq_quantthresh__44c1_sm_p7_1,
  125427. _vq_quantmap__44c1_sm_p7_1,
  125428. 5,
  125429. 5
  125430. };
  125431. static static_codebook _44c1_sm_p7_1 = {
  125432. 2, 25,
  125433. _vq_lengthlist__44c1_sm_p7_1,
  125434. 1, -533725184, 1611661312, 3, 0,
  125435. _vq_quantlist__44c1_sm_p7_1,
  125436. NULL,
  125437. &_vq_auxt__44c1_sm_p7_1,
  125438. NULL,
  125439. 0
  125440. };
  125441. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125442. 6,
  125443. 5,
  125444. 7,
  125445. 4,
  125446. 8,
  125447. 3,
  125448. 9,
  125449. 2,
  125450. 10,
  125451. 1,
  125452. 11,
  125453. 0,
  125454. 12,
  125455. };
  125456. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125457. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125458. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125459. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125460. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125461. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125462. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125463. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125464. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125465. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125466. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125467. 13,13,13,13,13,13,13,13,13,
  125468. };
  125469. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125470. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125471. 552.5, 773.5, 994.5, 1215.5,
  125472. };
  125473. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125474. 11, 9, 7, 5, 3, 1, 0, 2,
  125475. 4, 6, 8, 10, 12,
  125476. };
  125477. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125478. _vq_quantthresh__44c1_sm_p8_0,
  125479. _vq_quantmap__44c1_sm_p8_0,
  125480. 13,
  125481. 13
  125482. };
  125483. static static_codebook _44c1_sm_p8_0 = {
  125484. 2, 169,
  125485. _vq_lengthlist__44c1_sm_p8_0,
  125486. 1, -514541568, 1627103232, 4, 0,
  125487. _vq_quantlist__44c1_sm_p8_0,
  125488. NULL,
  125489. &_vq_auxt__44c1_sm_p8_0,
  125490. NULL,
  125491. 0
  125492. };
  125493. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125494. 6,
  125495. 5,
  125496. 7,
  125497. 4,
  125498. 8,
  125499. 3,
  125500. 9,
  125501. 2,
  125502. 10,
  125503. 1,
  125504. 11,
  125505. 0,
  125506. 12,
  125507. };
  125508. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125509. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125510. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125511. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125512. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125513. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125514. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125515. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125516. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125517. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125518. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125519. 20,13,12,12,12,14,12,14,13,
  125520. };
  125521. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125522. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125523. 42.5, 59.5, 76.5, 93.5,
  125524. };
  125525. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125526. 11, 9, 7, 5, 3, 1, 0, 2,
  125527. 4, 6, 8, 10, 12,
  125528. };
  125529. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125530. _vq_quantthresh__44c1_sm_p8_1,
  125531. _vq_quantmap__44c1_sm_p8_1,
  125532. 13,
  125533. 13
  125534. };
  125535. static static_codebook _44c1_sm_p8_1 = {
  125536. 2, 169,
  125537. _vq_lengthlist__44c1_sm_p8_1,
  125538. 1, -522616832, 1620115456, 4, 0,
  125539. _vq_quantlist__44c1_sm_p8_1,
  125540. NULL,
  125541. &_vq_auxt__44c1_sm_p8_1,
  125542. NULL,
  125543. 0
  125544. };
  125545. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125546. 8,
  125547. 7,
  125548. 9,
  125549. 6,
  125550. 10,
  125551. 5,
  125552. 11,
  125553. 4,
  125554. 12,
  125555. 3,
  125556. 13,
  125557. 2,
  125558. 14,
  125559. 1,
  125560. 15,
  125561. 0,
  125562. 16,
  125563. };
  125564. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125565. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125566. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125567. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125568. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125569. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125570. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125571. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125572. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125573. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125574. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125575. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125576. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125577. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125578. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125579. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125580. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125581. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125582. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125583. 9,
  125584. };
  125585. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125586. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125587. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125588. };
  125589. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125590. 15, 13, 11, 9, 7, 5, 3, 1,
  125591. 0, 2, 4, 6, 8, 10, 12, 14,
  125592. 16,
  125593. };
  125594. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125595. _vq_quantthresh__44c1_sm_p8_2,
  125596. _vq_quantmap__44c1_sm_p8_2,
  125597. 17,
  125598. 17
  125599. };
  125600. static static_codebook _44c1_sm_p8_2 = {
  125601. 2, 289,
  125602. _vq_lengthlist__44c1_sm_p8_2,
  125603. 1, -529530880, 1611661312, 5, 0,
  125604. _vq_quantlist__44c1_sm_p8_2,
  125605. NULL,
  125606. &_vq_auxt__44c1_sm_p8_2,
  125607. NULL,
  125608. 0
  125609. };
  125610. static long _huff_lengthlist__44c1_sm_short[] = {
  125611. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125612. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125613. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125614. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125615. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125616. 11,
  125617. };
  125618. static static_codebook _huff_book__44c1_sm_short = {
  125619. 2, 81,
  125620. _huff_lengthlist__44c1_sm_short,
  125621. 0, 0, 0, 0, 0,
  125622. NULL,
  125623. NULL,
  125624. NULL,
  125625. NULL,
  125626. 0
  125627. };
  125628. static long _huff_lengthlist__44cn1_s_long[] = {
  125629. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125630. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125631. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125632. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125633. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125634. 20,
  125635. };
  125636. static static_codebook _huff_book__44cn1_s_long = {
  125637. 2, 81,
  125638. _huff_lengthlist__44cn1_s_long,
  125639. 0, 0, 0, 0, 0,
  125640. NULL,
  125641. NULL,
  125642. NULL,
  125643. NULL,
  125644. 0
  125645. };
  125646. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125647. 1,
  125648. 0,
  125649. 2,
  125650. };
  125651. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125652. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125653. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125657. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125658. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125662. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125663. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  125698. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0,
  125699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  125703. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  125708. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  125709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125743. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125744. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125749. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125754. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  125755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125960. 0, 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,
  126063. };
  126064. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126065. -0.5, 0.5,
  126066. };
  126067. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126068. 1, 0, 2,
  126069. };
  126070. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126071. _vq_quantthresh__44cn1_s_p1_0,
  126072. _vq_quantmap__44cn1_s_p1_0,
  126073. 3,
  126074. 3
  126075. };
  126076. static static_codebook _44cn1_s_p1_0 = {
  126077. 8, 6561,
  126078. _vq_lengthlist__44cn1_s_p1_0,
  126079. 1, -535822336, 1611661312, 2, 0,
  126080. _vq_quantlist__44cn1_s_p1_0,
  126081. NULL,
  126082. &_vq_auxt__44cn1_s_p1_0,
  126083. NULL,
  126084. 0
  126085. };
  126086. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126087. 2,
  126088. 1,
  126089. 3,
  126090. 0,
  126091. 4,
  126092. };
  126093. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126094. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126097. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126100. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126133. 0,
  126134. };
  126135. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126136. -1.5, -0.5, 0.5, 1.5,
  126137. };
  126138. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126139. 3, 1, 0, 2, 4,
  126140. };
  126141. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126142. _vq_quantthresh__44cn1_s_p2_0,
  126143. _vq_quantmap__44cn1_s_p2_0,
  126144. 5,
  126145. 5
  126146. };
  126147. static static_codebook _44cn1_s_p2_0 = {
  126148. 4, 625,
  126149. _vq_lengthlist__44cn1_s_p2_0,
  126150. 1, -533725184, 1611661312, 3, 0,
  126151. _vq_quantlist__44cn1_s_p2_0,
  126152. NULL,
  126153. &_vq_auxt__44cn1_s_p2_0,
  126154. NULL,
  126155. 0
  126156. };
  126157. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126158. 4,
  126159. 3,
  126160. 5,
  126161. 2,
  126162. 6,
  126163. 1,
  126164. 7,
  126165. 0,
  126166. 8,
  126167. };
  126168. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126169. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126170. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126171. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126172. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126173. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126174. 0,
  126175. };
  126176. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126177. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126178. };
  126179. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126180. 7, 5, 3, 1, 0, 2, 4, 6,
  126181. 8,
  126182. };
  126183. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126184. _vq_quantthresh__44cn1_s_p3_0,
  126185. _vq_quantmap__44cn1_s_p3_0,
  126186. 9,
  126187. 9
  126188. };
  126189. static static_codebook _44cn1_s_p3_0 = {
  126190. 2, 81,
  126191. _vq_lengthlist__44cn1_s_p3_0,
  126192. 1, -531628032, 1611661312, 4, 0,
  126193. _vq_quantlist__44cn1_s_p3_0,
  126194. NULL,
  126195. &_vq_auxt__44cn1_s_p3_0,
  126196. NULL,
  126197. 0
  126198. };
  126199. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126200. 4,
  126201. 3,
  126202. 5,
  126203. 2,
  126204. 6,
  126205. 1,
  126206. 7,
  126207. 0,
  126208. 8,
  126209. };
  126210. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126211. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126212. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126213. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126214. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126215. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126216. 11,
  126217. };
  126218. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126219. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126220. };
  126221. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126222. 7, 5, 3, 1, 0, 2, 4, 6,
  126223. 8,
  126224. };
  126225. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126226. _vq_quantthresh__44cn1_s_p4_0,
  126227. _vq_quantmap__44cn1_s_p4_0,
  126228. 9,
  126229. 9
  126230. };
  126231. static static_codebook _44cn1_s_p4_0 = {
  126232. 2, 81,
  126233. _vq_lengthlist__44cn1_s_p4_0,
  126234. 1, -531628032, 1611661312, 4, 0,
  126235. _vq_quantlist__44cn1_s_p4_0,
  126236. NULL,
  126237. &_vq_auxt__44cn1_s_p4_0,
  126238. NULL,
  126239. 0
  126240. };
  126241. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126242. 8,
  126243. 7,
  126244. 9,
  126245. 6,
  126246. 10,
  126247. 5,
  126248. 11,
  126249. 4,
  126250. 12,
  126251. 3,
  126252. 13,
  126253. 2,
  126254. 14,
  126255. 1,
  126256. 15,
  126257. 0,
  126258. 16,
  126259. };
  126260. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126261. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126262. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126263. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126264. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126265. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126266. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126267. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126268. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126269. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126270. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126271. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126272. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126273. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126274. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126275. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126276. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126277. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126278. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126279. 14,
  126280. };
  126281. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126282. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126283. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126284. };
  126285. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126286. 15, 13, 11, 9, 7, 5, 3, 1,
  126287. 0, 2, 4, 6, 8, 10, 12, 14,
  126288. 16,
  126289. };
  126290. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126291. _vq_quantthresh__44cn1_s_p5_0,
  126292. _vq_quantmap__44cn1_s_p5_0,
  126293. 17,
  126294. 17
  126295. };
  126296. static static_codebook _44cn1_s_p5_0 = {
  126297. 2, 289,
  126298. _vq_lengthlist__44cn1_s_p5_0,
  126299. 1, -529530880, 1611661312, 5, 0,
  126300. _vq_quantlist__44cn1_s_p5_0,
  126301. NULL,
  126302. &_vq_auxt__44cn1_s_p5_0,
  126303. NULL,
  126304. 0
  126305. };
  126306. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126307. 1,
  126308. 0,
  126309. 2,
  126310. };
  126311. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126312. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126313. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126314. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126315. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126316. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126317. 10,
  126318. };
  126319. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126320. -5.5, 5.5,
  126321. };
  126322. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126323. 1, 0, 2,
  126324. };
  126325. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126326. _vq_quantthresh__44cn1_s_p6_0,
  126327. _vq_quantmap__44cn1_s_p6_0,
  126328. 3,
  126329. 3
  126330. };
  126331. static static_codebook _44cn1_s_p6_0 = {
  126332. 4, 81,
  126333. _vq_lengthlist__44cn1_s_p6_0,
  126334. 1, -529137664, 1618345984, 2, 0,
  126335. _vq_quantlist__44cn1_s_p6_0,
  126336. NULL,
  126337. &_vq_auxt__44cn1_s_p6_0,
  126338. NULL,
  126339. 0
  126340. };
  126341. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126342. 5,
  126343. 4,
  126344. 6,
  126345. 3,
  126346. 7,
  126347. 2,
  126348. 8,
  126349. 1,
  126350. 9,
  126351. 0,
  126352. 10,
  126353. };
  126354. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126355. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126356. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126357. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126358. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126359. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126360. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126361. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126362. 10,10,10, 9, 9, 9, 9, 9, 9,
  126363. };
  126364. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126365. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126366. 3.5, 4.5,
  126367. };
  126368. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126369. 9, 7, 5, 3, 1, 0, 2, 4,
  126370. 6, 8, 10,
  126371. };
  126372. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126373. _vq_quantthresh__44cn1_s_p6_1,
  126374. _vq_quantmap__44cn1_s_p6_1,
  126375. 11,
  126376. 11
  126377. };
  126378. static static_codebook _44cn1_s_p6_1 = {
  126379. 2, 121,
  126380. _vq_lengthlist__44cn1_s_p6_1,
  126381. 1, -531365888, 1611661312, 4, 0,
  126382. _vq_quantlist__44cn1_s_p6_1,
  126383. NULL,
  126384. &_vq_auxt__44cn1_s_p6_1,
  126385. NULL,
  126386. 0
  126387. };
  126388. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126389. 6,
  126390. 5,
  126391. 7,
  126392. 4,
  126393. 8,
  126394. 3,
  126395. 9,
  126396. 2,
  126397. 10,
  126398. 1,
  126399. 11,
  126400. 0,
  126401. 12,
  126402. };
  126403. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126404. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126405. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126406. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126407. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126408. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126409. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126410. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126411. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126412. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126413. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126414. 0,13,13,12,12,13,13,13,14,
  126415. };
  126416. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126417. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126418. 12.5, 17.5, 22.5, 27.5,
  126419. };
  126420. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126421. 11, 9, 7, 5, 3, 1, 0, 2,
  126422. 4, 6, 8, 10, 12,
  126423. };
  126424. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126425. _vq_quantthresh__44cn1_s_p7_0,
  126426. _vq_quantmap__44cn1_s_p7_0,
  126427. 13,
  126428. 13
  126429. };
  126430. static static_codebook _44cn1_s_p7_0 = {
  126431. 2, 169,
  126432. _vq_lengthlist__44cn1_s_p7_0,
  126433. 1, -526516224, 1616117760, 4, 0,
  126434. _vq_quantlist__44cn1_s_p7_0,
  126435. NULL,
  126436. &_vq_auxt__44cn1_s_p7_0,
  126437. NULL,
  126438. 0
  126439. };
  126440. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126441. 2,
  126442. 1,
  126443. 3,
  126444. 0,
  126445. 4,
  126446. };
  126447. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126448. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126449. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126450. };
  126451. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126452. -1.5, -0.5, 0.5, 1.5,
  126453. };
  126454. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126455. 3, 1, 0, 2, 4,
  126456. };
  126457. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126458. _vq_quantthresh__44cn1_s_p7_1,
  126459. _vq_quantmap__44cn1_s_p7_1,
  126460. 5,
  126461. 5
  126462. };
  126463. static static_codebook _44cn1_s_p7_1 = {
  126464. 2, 25,
  126465. _vq_lengthlist__44cn1_s_p7_1,
  126466. 1, -533725184, 1611661312, 3, 0,
  126467. _vq_quantlist__44cn1_s_p7_1,
  126468. NULL,
  126469. &_vq_auxt__44cn1_s_p7_1,
  126470. NULL,
  126471. 0
  126472. };
  126473. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126474. 2,
  126475. 1,
  126476. 3,
  126477. 0,
  126478. 4,
  126479. };
  126480. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126481. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126482. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126483. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126484. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126485. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126486. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126487. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126488. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126489. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126490. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126491. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126492. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126493. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126494. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126495. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126496. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126497. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126498. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126499. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126500. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126501. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126502. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126503. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126504. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126505. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126506. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126507. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126508. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126509. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126510. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126511. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126512. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126513. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126514. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126515. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126516. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126517. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126518. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126519. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126520. 12,
  126521. };
  126522. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126523. -331.5, -110.5, 110.5, 331.5,
  126524. };
  126525. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126526. 3, 1, 0, 2, 4,
  126527. };
  126528. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126529. _vq_quantthresh__44cn1_s_p8_0,
  126530. _vq_quantmap__44cn1_s_p8_0,
  126531. 5,
  126532. 5
  126533. };
  126534. static static_codebook _44cn1_s_p8_0 = {
  126535. 4, 625,
  126536. _vq_lengthlist__44cn1_s_p8_0,
  126537. 1, -518283264, 1627103232, 3, 0,
  126538. _vq_quantlist__44cn1_s_p8_0,
  126539. NULL,
  126540. &_vq_auxt__44cn1_s_p8_0,
  126541. NULL,
  126542. 0
  126543. };
  126544. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126545. 6,
  126546. 5,
  126547. 7,
  126548. 4,
  126549. 8,
  126550. 3,
  126551. 9,
  126552. 2,
  126553. 10,
  126554. 1,
  126555. 11,
  126556. 0,
  126557. 12,
  126558. };
  126559. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126560. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126561. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126562. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126563. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126564. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126565. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126566. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126567. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126568. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126569. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126570. 15,12,12,11,11,14,12,13,14,
  126571. };
  126572. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126573. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126574. 42.5, 59.5, 76.5, 93.5,
  126575. };
  126576. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126577. 11, 9, 7, 5, 3, 1, 0, 2,
  126578. 4, 6, 8, 10, 12,
  126579. };
  126580. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126581. _vq_quantthresh__44cn1_s_p8_1,
  126582. _vq_quantmap__44cn1_s_p8_1,
  126583. 13,
  126584. 13
  126585. };
  126586. static static_codebook _44cn1_s_p8_1 = {
  126587. 2, 169,
  126588. _vq_lengthlist__44cn1_s_p8_1,
  126589. 1, -522616832, 1620115456, 4, 0,
  126590. _vq_quantlist__44cn1_s_p8_1,
  126591. NULL,
  126592. &_vq_auxt__44cn1_s_p8_1,
  126593. NULL,
  126594. 0
  126595. };
  126596. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126597. 8,
  126598. 7,
  126599. 9,
  126600. 6,
  126601. 10,
  126602. 5,
  126603. 11,
  126604. 4,
  126605. 12,
  126606. 3,
  126607. 13,
  126608. 2,
  126609. 14,
  126610. 1,
  126611. 15,
  126612. 0,
  126613. 16,
  126614. };
  126615. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126616. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126617. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126618. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126619. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126620. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126621. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126622. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126623. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126624. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126625. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126626. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126627. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126628. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126629. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126630. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126631. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126632. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126633. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126634. 9,
  126635. };
  126636. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126637. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126638. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126639. };
  126640. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126641. 15, 13, 11, 9, 7, 5, 3, 1,
  126642. 0, 2, 4, 6, 8, 10, 12, 14,
  126643. 16,
  126644. };
  126645. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126646. _vq_quantthresh__44cn1_s_p8_2,
  126647. _vq_quantmap__44cn1_s_p8_2,
  126648. 17,
  126649. 17
  126650. };
  126651. static static_codebook _44cn1_s_p8_2 = {
  126652. 2, 289,
  126653. _vq_lengthlist__44cn1_s_p8_2,
  126654. 1, -529530880, 1611661312, 5, 0,
  126655. _vq_quantlist__44cn1_s_p8_2,
  126656. NULL,
  126657. &_vq_auxt__44cn1_s_p8_2,
  126658. NULL,
  126659. 0
  126660. };
  126661. static long _huff_lengthlist__44cn1_s_short[] = {
  126662. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126663. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126664. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126665. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126666. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126667. 10,
  126668. };
  126669. static static_codebook _huff_book__44cn1_s_short = {
  126670. 2, 81,
  126671. _huff_lengthlist__44cn1_s_short,
  126672. 0, 0, 0, 0, 0,
  126673. NULL,
  126674. NULL,
  126675. NULL,
  126676. NULL,
  126677. 0
  126678. };
  126679. static long _huff_lengthlist__44cn1_sm_long[] = {
  126680. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126681. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126682. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126683. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126684. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126685. 17,
  126686. };
  126687. static static_codebook _huff_book__44cn1_sm_long = {
  126688. 2, 81,
  126689. _huff_lengthlist__44cn1_sm_long,
  126690. 0, 0, 0, 0, 0,
  126691. NULL,
  126692. NULL,
  126693. NULL,
  126694. NULL,
  126695. 0
  126696. };
  126697. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126698. 1,
  126699. 0,
  126700. 2,
  126701. };
  126702. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126703. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126704. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126708. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126709. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126713. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126714. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126749. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  126754. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  126759. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  126760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126794. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126795. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126800. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126805. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  126806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127011. 0, 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,
  127114. };
  127115. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127116. -0.5, 0.5,
  127117. };
  127118. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127119. 1, 0, 2,
  127120. };
  127121. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127122. _vq_quantthresh__44cn1_sm_p1_0,
  127123. _vq_quantmap__44cn1_sm_p1_0,
  127124. 3,
  127125. 3
  127126. };
  127127. static static_codebook _44cn1_sm_p1_0 = {
  127128. 8, 6561,
  127129. _vq_lengthlist__44cn1_sm_p1_0,
  127130. 1, -535822336, 1611661312, 2, 0,
  127131. _vq_quantlist__44cn1_sm_p1_0,
  127132. NULL,
  127133. &_vq_auxt__44cn1_sm_p1_0,
  127134. NULL,
  127135. 0
  127136. };
  127137. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127138. 2,
  127139. 1,
  127140. 3,
  127141. 0,
  127142. 4,
  127143. };
  127144. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127145. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127148. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127151. 0, 0, 0, 0, 7, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127184. 0,
  127185. };
  127186. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127187. -1.5, -0.5, 0.5, 1.5,
  127188. };
  127189. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127190. 3, 1, 0, 2, 4,
  127191. };
  127192. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127193. _vq_quantthresh__44cn1_sm_p2_0,
  127194. _vq_quantmap__44cn1_sm_p2_0,
  127195. 5,
  127196. 5
  127197. };
  127198. static static_codebook _44cn1_sm_p2_0 = {
  127199. 4, 625,
  127200. _vq_lengthlist__44cn1_sm_p2_0,
  127201. 1, -533725184, 1611661312, 3, 0,
  127202. _vq_quantlist__44cn1_sm_p2_0,
  127203. NULL,
  127204. &_vq_auxt__44cn1_sm_p2_0,
  127205. NULL,
  127206. 0
  127207. };
  127208. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127209. 4,
  127210. 3,
  127211. 5,
  127212. 2,
  127213. 6,
  127214. 1,
  127215. 7,
  127216. 0,
  127217. 8,
  127218. };
  127219. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127220. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127221. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127222. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127223. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127224. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127225. 0,
  127226. };
  127227. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127228. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127229. };
  127230. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127231. 7, 5, 3, 1, 0, 2, 4, 6,
  127232. 8,
  127233. };
  127234. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127235. _vq_quantthresh__44cn1_sm_p3_0,
  127236. _vq_quantmap__44cn1_sm_p3_0,
  127237. 9,
  127238. 9
  127239. };
  127240. static static_codebook _44cn1_sm_p3_0 = {
  127241. 2, 81,
  127242. _vq_lengthlist__44cn1_sm_p3_0,
  127243. 1, -531628032, 1611661312, 4, 0,
  127244. _vq_quantlist__44cn1_sm_p3_0,
  127245. NULL,
  127246. &_vq_auxt__44cn1_sm_p3_0,
  127247. NULL,
  127248. 0
  127249. };
  127250. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127251. 4,
  127252. 3,
  127253. 5,
  127254. 2,
  127255. 6,
  127256. 1,
  127257. 7,
  127258. 0,
  127259. 8,
  127260. };
  127261. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127262. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127263. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127264. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127265. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127266. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127267. 11,
  127268. };
  127269. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127270. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127271. };
  127272. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127273. 7, 5, 3, 1, 0, 2, 4, 6,
  127274. 8,
  127275. };
  127276. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127277. _vq_quantthresh__44cn1_sm_p4_0,
  127278. _vq_quantmap__44cn1_sm_p4_0,
  127279. 9,
  127280. 9
  127281. };
  127282. static static_codebook _44cn1_sm_p4_0 = {
  127283. 2, 81,
  127284. _vq_lengthlist__44cn1_sm_p4_0,
  127285. 1, -531628032, 1611661312, 4, 0,
  127286. _vq_quantlist__44cn1_sm_p4_0,
  127287. NULL,
  127288. &_vq_auxt__44cn1_sm_p4_0,
  127289. NULL,
  127290. 0
  127291. };
  127292. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127293. 8,
  127294. 7,
  127295. 9,
  127296. 6,
  127297. 10,
  127298. 5,
  127299. 11,
  127300. 4,
  127301. 12,
  127302. 3,
  127303. 13,
  127304. 2,
  127305. 14,
  127306. 1,
  127307. 15,
  127308. 0,
  127309. 16,
  127310. };
  127311. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127312. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127313. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127314. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127315. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127316. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127317. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127318. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127319. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127320. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127321. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127322. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127323. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127324. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127325. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127326. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127327. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127328. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127329. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127330. 14,
  127331. };
  127332. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127333. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127334. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127335. };
  127336. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127337. 15, 13, 11, 9, 7, 5, 3, 1,
  127338. 0, 2, 4, 6, 8, 10, 12, 14,
  127339. 16,
  127340. };
  127341. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127342. _vq_quantthresh__44cn1_sm_p5_0,
  127343. _vq_quantmap__44cn1_sm_p5_0,
  127344. 17,
  127345. 17
  127346. };
  127347. static static_codebook _44cn1_sm_p5_0 = {
  127348. 2, 289,
  127349. _vq_lengthlist__44cn1_sm_p5_0,
  127350. 1, -529530880, 1611661312, 5, 0,
  127351. _vq_quantlist__44cn1_sm_p5_0,
  127352. NULL,
  127353. &_vq_auxt__44cn1_sm_p5_0,
  127354. NULL,
  127355. 0
  127356. };
  127357. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127358. 1,
  127359. 0,
  127360. 2,
  127361. };
  127362. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127363. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127364. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127365. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127366. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127367. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127368. 10,
  127369. };
  127370. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127371. -5.5, 5.5,
  127372. };
  127373. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127374. 1, 0, 2,
  127375. };
  127376. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127377. _vq_quantthresh__44cn1_sm_p6_0,
  127378. _vq_quantmap__44cn1_sm_p6_0,
  127379. 3,
  127380. 3
  127381. };
  127382. static static_codebook _44cn1_sm_p6_0 = {
  127383. 4, 81,
  127384. _vq_lengthlist__44cn1_sm_p6_0,
  127385. 1, -529137664, 1618345984, 2, 0,
  127386. _vq_quantlist__44cn1_sm_p6_0,
  127387. NULL,
  127388. &_vq_auxt__44cn1_sm_p6_0,
  127389. NULL,
  127390. 0
  127391. };
  127392. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127393. 5,
  127394. 4,
  127395. 6,
  127396. 3,
  127397. 7,
  127398. 2,
  127399. 8,
  127400. 1,
  127401. 9,
  127402. 0,
  127403. 10,
  127404. };
  127405. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127406. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127407. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127408. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127409. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127410. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127411. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127412. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127413. 10,10,10, 8, 9, 8, 8, 9, 8,
  127414. };
  127415. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127416. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127417. 3.5, 4.5,
  127418. };
  127419. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127420. 9, 7, 5, 3, 1, 0, 2, 4,
  127421. 6, 8, 10,
  127422. };
  127423. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127424. _vq_quantthresh__44cn1_sm_p6_1,
  127425. _vq_quantmap__44cn1_sm_p6_1,
  127426. 11,
  127427. 11
  127428. };
  127429. static static_codebook _44cn1_sm_p6_1 = {
  127430. 2, 121,
  127431. _vq_lengthlist__44cn1_sm_p6_1,
  127432. 1, -531365888, 1611661312, 4, 0,
  127433. _vq_quantlist__44cn1_sm_p6_1,
  127434. NULL,
  127435. &_vq_auxt__44cn1_sm_p6_1,
  127436. NULL,
  127437. 0
  127438. };
  127439. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127440. 6,
  127441. 5,
  127442. 7,
  127443. 4,
  127444. 8,
  127445. 3,
  127446. 9,
  127447. 2,
  127448. 10,
  127449. 1,
  127450. 11,
  127451. 0,
  127452. 12,
  127453. };
  127454. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127455. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127456. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127457. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127458. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127459. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127460. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127461. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127462. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127463. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127464. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127465. 0,13,12,12,12,13,13,13,14,
  127466. };
  127467. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127468. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127469. 12.5, 17.5, 22.5, 27.5,
  127470. };
  127471. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127472. 11, 9, 7, 5, 3, 1, 0, 2,
  127473. 4, 6, 8, 10, 12,
  127474. };
  127475. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127476. _vq_quantthresh__44cn1_sm_p7_0,
  127477. _vq_quantmap__44cn1_sm_p7_0,
  127478. 13,
  127479. 13
  127480. };
  127481. static static_codebook _44cn1_sm_p7_0 = {
  127482. 2, 169,
  127483. _vq_lengthlist__44cn1_sm_p7_0,
  127484. 1, -526516224, 1616117760, 4, 0,
  127485. _vq_quantlist__44cn1_sm_p7_0,
  127486. NULL,
  127487. &_vq_auxt__44cn1_sm_p7_0,
  127488. NULL,
  127489. 0
  127490. };
  127491. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127492. 2,
  127493. 1,
  127494. 3,
  127495. 0,
  127496. 4,
  127497. };
  127498. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127499. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127500. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127501. };
  127502. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127503. -1.5, -0.5, 0.5, 1.5,
  127504. };
  127505. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127506. 3, 1, 0, 2, 4,
  127507. };
  127508. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127509. _vq_quantthresh__44cn1_sm_p7_1,
  127510. _vq_quantmap__44cn1_sm_p7_1,
  127511. 5,
  127512. 5
  127513. };
  127514. static static_codebook _44cn1_sm_p7_1 = {
  127515. 2, 25,
  127516. _vq_lengthlist__44cn1_sm_p7_1,
  127517. 1, -533725184, 1611661312, 3, 0,
  127518. _vq_quantlist__44cn1_sm_p7_1,
  127519. NULL,
  127520. &_vq_auxt__44cn1_sm_p7_1,
  127521. NULL,
  127522. 0
  127523. };
  127524. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127525. 4,
  127526. 3,
  127527. 5,
  127528. 2,
  127529. 6,
  127530. 1,
  127531. 7,
  127532. 0,
  127533. 8,
  127534. };
  127535. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127536. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127537. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127538. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127539. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127540. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127541. 14,
  127542. };
  127543. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127544. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127545. };
  127546. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127547. 7, 5, 3, 1, 0, 2, 4, 6,
  127548. 8,
  127549. };
  127550. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127551. _vq_quantthresh__44cn1_sm_p8_0,
  127552. _vq_quantmap__44cn1_sm_p8_0,
  127553. 9,
  127554. 9
  127555. };
  127556. static static_codebook _44cn1_sm_p8_0 = {
  127557. 2, 81,
  127558. _vq_lengthlist__44cn1_sm_p8_0,
  127559. 1, -516186112, 1627103232, 4, 0,
  127560. _vq_quantlist__44cn1_sm_p8_0,
  127561. NULL,
  127562. &_vq_auxt__44cn1_sm_p8_0,
  127563. NULL,
  127564. 0
  127565. };
  127566. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127567. 6,
  127568. 5,
  127569. 7,
  127570. 4,
  127571. 8,
  127572. 3,
  127573. 9,
  127574. 2,
  127575. 10,
  127576. 1,
  127577. 11,
  127578. 0,
  127579. 12,
  127580. };
  127581. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127582. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127583. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127584. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127585. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127586. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127587. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127588. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127589. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127590. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127591. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127592. 17,12,12,11,10,13,11,13,13,
  127593. };
  127594. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127595. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127596. 42.5, 59.5, 76.5, 93.5,
  127597. };
  127598. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127599. 11, 9, 7, 5, 3, 1, 0, 2,
  127600. 4, 6, 8, 10, 12,
  127601. };
  127602. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127603. _vq_quantthresh__44cn1_sm_p8_1,
  127604. _vq_quantmap__44cn1_sm_p8_1,
  127605. 13,
  127606. 13
  127607. };
  127608. static static_codebook _44cn1_sm_p8_1 = {
  127609. 2, 169,
  127610. _vq_lengthlist__44cn1_sm_p8_1,
  127611. 1, -522616832, 1620115456, 4, 0,
  127612. _vq_quantlist__44cn1_sm_p8_1,
  127613. NULL,
  127614. &_vq_auxt__44cn1_sm_p8_1,
  127615. NULL,
  127616. 0
  127617. };
  127618. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127619. 8,
  127620. 7,
  127621. 9,
  127622. 6,
  127623. 10,
  127624. 5,
  127625. 11,
  127626. 4,
  127627. 12,
  127628. 3,
  127629. 13,
  127630. 2,
  127631. 14,
  127632. 1,
  127633. 15,
  127634. 0,
  127635. 16,
  127636. };
  127637. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127638. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127639. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127640. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127641. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127642. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127643. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127644. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127645. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127646. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127647. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127648. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127649. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127650. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127651. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127652. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127653. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127654. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127655. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127656. 9,
  127657. };
  127658. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127659. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127660. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127661. };
  127662. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127663. 15, 13, 11, 9, 7, 5, 3, 1,
  127664. 0, 2, 4, 6, 8, 10, 12, 14,
  127665. 16,
  127666. };
  127667. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127668. _vq_quantthresh__44cn1_sm_p8_2,
  127669. _vq_quantmap__44cn1_sm_p8_2,
  127670. 17,
  127671. 17
  127672. };
  127673. static static_codebook _44cn1_sm_p8_2 = {
  127674. 2, 289,
  127675. _vq_lengthlist__44cn1_sm_p8_2,
  127676. 1, -529530880, 1611661312, 5, 0,
  127677. _vq_quantlist__44cn1_sm_p8_2,
  127678. NULL,
  127679. &_vq_auxt__44cn1_sm_p8_2,
  127680. NULL,
  127681. 0
  127682. };
  127683. static long _huff_lengthlist__44cn1_sm_short[] = {
  127684. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127685. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127686. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127687. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127688. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127689. 9,
  127690. };
  127691. static static_codebook _huff_book__44cn1_sm_short = {
  127692. 2, 81,
  127693. _huff_lengthlist__44cn1_sm_short,
  127694. 0, 0, 0, 0, 0,
  127695. NULL,
  127696. NULL,
  127697. NULL,
  127698. NULL,
  127699. 0
  127700. };
  127701. /*** End of inlined file: res_books_stereo.h ***/
  127702. static vorbis_info_residue0 _residue_44_low={
  127703. 0,-1, -1, 9,-1,
  127704. {0},
  127705. {-1},
  127706. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127707. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127708. };
  127709. static vorbis_info_residue0 _residue_44_mid={
  127710. 0,-1, -1, 10,-1,
  127711. {0},
  127712. {-1},
  127713. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127714. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127715. };
  127716. static vorbis_info_residue0 _residue_44_high={
  127717. 0,-1, -1, 10,-1,
  127718. {0},
  127719. {-1},
  127720. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127721. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127722. };
  127723. static static_bookblock _resbook_44s_n1={
  127724. {
  127725. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127726. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127727. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127728. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127729. }
  127730. };
  127731. static static_bookblock _resbook_44sm_n1={
  127732. {
  127733. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127734. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127735. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127736. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127737. }
  127738. };
  127739. static static_bookblock _resbook_44s_0={
  127740. {
  127741. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127742. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127743. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127744. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127745. }
  127746. };
  127747. static static_bookblock _resbook_44sm_0={
  127748. {
  127749. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127750. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127751. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127752. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127753. }
  127754. };
  127755. static static_bookblock _resbook_44s_1={
  127756. {
  127757. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127758. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127759. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127760. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127761. }
  127762. };
  127763. static static_bookblock _resbook_44sm_1={
  127764. {
  127765. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127766. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127767. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127768. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127769. }
  127770. };
  127771. static static_bookblock _resbook_44s_2={
  127772. {
  127773. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127774. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127775. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127776. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127777. }
  127778. };
  127779. static static_bookblock _resbook_44s_3={
  127780. {
  127781. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127782. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127783. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127784. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127785. }
  127786. };
  127787. static static_bookblock _resbook_44s_4={
  127788. {
  127789. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127790. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127791. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127792. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127793. }
  127794. };
  127795. static static_bookblock _resbook_44s_5={
  127796. {
  127797. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127798. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127799. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127800. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127801. }
  127802. };
  127803. static static_bookblock _resbook_44s_6={
  127804. {
  127805. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127806. {0,0,&_44c6_s_p4_0},
  127807. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127808. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127809. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127810. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127811. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127812. }
  127813. };
  127814. static static_bookblock _resbook_44s_7={
  127815. {
  127816. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127817. {0,0,&_44c7_s_p4_0},
  127818. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127819. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127820. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127821. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127822. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127823. }
  127824. };
  127825. static static_bookblock _resbook_44s_8={
  127826. {
  127827. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127828. {0,0,&_44c8_s_p4_0},
  127829. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127830. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127831. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127832. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127833. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127834. }
  127835. };
  127836. static static_bookblock _resbook_44s_9={
  127837. {
  127838. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127839. {0,0,&_44c9_s_p4_0},
  127840. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127841. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127842. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127843. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127844. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127845. }
  127846. };
  127847. static vorbis_residue_template _res_44s_n1[]={
  127848. {2,0, &_residue_44_low,
  127849. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127850. &_resbook_44s_n1,&_resbook_44sm_n1},
  127851. {2,0, &_residue_44_low,
  127852. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127853. &_resbook_44s_n1,&_resbook_44sm_n1}
  127854. };
  127855. static vorbis_residue_template _res_44s_0[]={
  127856. {2,0, &_residue_44_low,
  127857. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127858. &_resbook_44s_0,&_resbook_44sm_0},
  127859. {2,0, &_residue_44_low,
  127860. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127861. &_resbook_44s_0,&_resbook_44sm_0}
  127862. };
  127863. static vorbis_residue_template _res_44s_1[]={
  127864. {2,0, &_residue_44_low,
  127865. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127866. &_resbook_44s_1,&_resbook_44sm_1},
  127867. {2,0, &_residue_44_low,
  127868. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127869. &_resbook_44s_1,&_resbook_44sm_1}
  127870. };
  127871. static vorbis_residue_template _res_44s_2[]={
  127872. {2,0, &_residue_44_mid,
  127873. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127874. &_resbook_44s_2,&_resbook_44s_2},
  127875. {2,0, &_residue_44_mid,
  127876. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127877. &_resbook_44s_2,&_resbook_44s_2}
  127878. };
  127879. static vorbis_residue_template _res_44s_3[]={
  127880. {2,0, &_residue_44_mid,
  127881. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127882. &_resbook_44s_3,&_resbook_44s_3},
  127883. {2,0, &_residue_44_mid,
  127884. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127885. &_resbook_44s_3,&_resbook_44s_3}
  127886. };
  127887. static vorbis_residue_template _res_44s_4[]={
  127888. {2,0, &_residue_44_mid,
  127889. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127890. &_resbook_44s_4,&_resbook_44s_4},
  127891. {2,0, &_residue_44_mid,
  127892. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127893. &_resbook_44s_4,&_resbook_44s_4}
  127894. };
  127895. static vorbis_residue_template _res_44s_5[]={
  127896. {2,0, &_residue_44_mid,
  127897. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127898. &_resbook_44s_5,&_resbook_44s_5},
  127899. {2,0, &_residue_44_mid,
  127900. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127901. &_resbook_44s_5,&_resbook_44s_5}
  127902. };
  127903. static vorbis_residue_template _res_44s_6[]={
  127904. {2,0, &_residue_44_high,
  127905. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127906. &_resbook_44s_6,&_resbook_44s_6},
  127907. {2,0, &_residue_44_high,
  127908. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127909. &_resbook_44s_6,&_resbook_44s_6}
  127910. };
  127911. static vorbis_residue_template _res_44s_7[]={
  127912. {2,0, &_residue_44_high,
  127913. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127914. &_resbook_44s_7,&_resbook_44s_7},
  127915. {2,0, &_residue_44_high,
  127916. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127917. &_resbook_44s_7,&_resbook_44s_7}
  127918. };
  127919. static vorbis_residue_template _res_44s_8[]={
  127920. {2,0, &_residue_44_high,
  127921. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127922. &_resbook_44s_8,&_resbook_44s_8},
  127923. {2,0, &_residue_44_high,
  127924. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127925. &_resbook_44s_8,&_resbook_44s_8}
  127926. };
  127927. static vorbis_residue_template _res_44s_9[]={
  127928. {2,0, &_residue_44_high,
  127929. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127930. &_resbook_44s_9,&_resbook_44s_9},
  127931. {2,0, &_residue_44_high,
  127932. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127933. &_resbook_44s_9,&_resbook_44s_9}
  127934. };
  127935. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127936. { _map_nominal, _res_44s_n1 }, /* -1 */
  127937. { _map_nominal, _res_44s_0 }, /* 0 */
  127938. { _map_nominal, _res_44s_1 }, /* 1 */
  127939. { _map_nominal, _res_44s_2 }, /* 2 */
  127940. { _map_nominal, _res_44s_3 }, /* 3 */
  127941. { _map_nominal, _res_44s_4 }, /* 4 */
  127942. { _map_nominal, _res_44s_5 }, /* 5 */
  127943. { _map_nominal, _res_44s_6 }, /* 6 */
  127944. { _map_nominal, _res_44s_7 }, /* 7 */
  127945. { _map_nominal, _res_44s_8 }, /* 8 */
  127946. { _map_nominal, _res_44s_9 }, /* 9 */
  127947. };
  127948. /*** End of inlined file: residue_44.h ***/
  127949. /*** Start of inlined file: psych_44.h ***/
  127950. static vorbis_info_psy_global _psy_global_44[5]={
  127951. {8, /* lines per eighth octave */
  127952. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  127953. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  127954. -6.f,
  127955. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127956. },
  127957. {8, /* lines per eighth octave */
  127958. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127959. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  127960. -6.f,
  127961. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127962. },
  127963. {8, /* lines per eighth octave */
  127964. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127965. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  127966. -6.f,
  127967. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127968. },
  127969. {8, /* lines per eighth octave */
  127970. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  127971. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  127972. -6.f,
  127973. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127974. },
  127975. {8, /* lines per eighth octave */
  127976. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  127977. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  127978. -6.f,
  127979. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127980. },
  127981. };
  127982. static compandblock _psy_compand_44[6]={
  127983. {{
  127984. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127985. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127986. 16,17,18,19,20,21,22, 23, /* 23dB */
  127987. 24,25,26,27,28,29,30, 31, /* 31dB */
  127988. 32,33,34,35,36,37,38, 39, /* 39dB */
  127989. }},
  127990. {{
  127991. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  127992. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  127993. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  127994. 15,16,17,17,17,18,18, 19, /* 31dB */
  127995. 19,19,20,21,22,23,24, 25, /* 39dB */
  127996. }},
  127997. {{
  127998. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  127999. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  128000. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128001. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128002. 11,12,13,14,15,16,17, 18, /* 39dB */
  128003. }},
  128004. {{
  128005. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128006. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128007. 16,17,18,19,20,21,22, 23, /* 23dB */
  128008. 24,25,26,27,28,29,30, 31, /* 31dB */
  128009. 32,33,34,35,36,37,38, 39, /* 39dB */
  128010. }},
  128011. {{
  128012. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128013. 8, 9,10,11,12,12,13, 13, /* 15dB */
  128014. 13,14,14,14,15,15,15, 15, /* 23dB */
  128015. 16,16,17,17,17,18,18, 19, /* 31dB */
  128016. 19,19,20,21,22,23,24, 25, /* 39dB */
  128017. }},
  128018. {{
  128019. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128020. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  128021. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128022. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128023. 11,12,13,14,15,16,17, 18, /* 39dB */
  128024. }}
  128025. };
  128026. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128027. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128028. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128029. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128030. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128031. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128032. /* 4 */
  128033. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128034. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128035. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128036. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128037. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128038. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128039. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128040. };
  128041. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128042. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128043. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128044. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128045. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128046. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128047. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128048. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128049. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128050. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128051. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128052. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128053. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128054. };
  128055. static noise3 _psy_noisebias_trans[12]={
  128056. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128057. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128058. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128059. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128060. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128061. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128062. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128063. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128064. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128065. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128066. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128067. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128068. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128069. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128070. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128071. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128072. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128073. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128074. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128075. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128076. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128077. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128078. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128079. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128080. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128081. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128082. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128083. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128084. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128085. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128086. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128087. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128088. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128089. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128090. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128091. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128092. };
  128093. static noise3 _psy_noisebias_long[12]={
  128094. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128095. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128096. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128097. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128098. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128099. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128100. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128101. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128102. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128103. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128104. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128105. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128106. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128107. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128108. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128109. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128110. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128111. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128112. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128113. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128114. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128115. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128116. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128117. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128118. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128119. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128120. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128121. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128122. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128123. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128124. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128125. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128126. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128127. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128128. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128129. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128130. };
  128131. static noise3 _psy_noisebias_impulse[12]={
  128132. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128133. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128134. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128135. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128136. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128137. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128138. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128139. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128140. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128141. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128142. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128143. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128144. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128145. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128146. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128147. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128148. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128149. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128150. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128151. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128152. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128153. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128154. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128155. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128156. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128157. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128158. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128159. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128160. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128161. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128162. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128163. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128164. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128165. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128166. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128167. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128168. };
  128169. static noise3 _psy_noisebias_padding[12]={
  128170. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128171. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128172. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128173. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128174. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128175. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128176. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128177. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128178. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128179. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128180. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128181. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128182. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128183. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128184. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128185. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128186. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128187. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128188. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128189. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128190. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128191. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128192. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128193. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128194. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128195. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128196. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128197. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128198. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128199. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128200. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128201. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128202. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128203. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128204. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128205. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128206. };
  128207. static noiseguard _psy_noiseguards_44[4]={
  128208. {3,3,15},
  128209. {3,3,15},
  128210. {10,10,100},
  128211. {10,10,100},
  128212. };
  128213. static int _psy_tone_suppress[12]={
  128214. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128215. };
  128216. static int _psy_tone_0dB[12]={
  128217. 90,90,95,95,95,95,105,105,105,105,105,105,
  128218. };
  128219. static int _psy_noise_suppress[12]={
  128220. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128221. };
  128222. static vorbis_info_psy _psy_info_template={
  128223. -1,
  128224. -140.,-140.,
  128225. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128226. 1, -0.f, .5f, .5f, 0,0,0,
  128227. {{-1},{-1},{-1}},{-1},105.f,
  128228. 0,0,-1,-1,0.,
  128229. };
  128230. static int _psy_ath_floater[12]={
  128231. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128232. };
  128233. static int _psy_ath_abs[12]={
  128234. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128235. };
  128236. static adj_stereo _psy_stereo_modes_44[12]={
  128237. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128238. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128239. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128240. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128241. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128242. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128243. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128244. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128245. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128246. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128247. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128248. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128249. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128250. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128251. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128252. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128253. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128254. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128255. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128256. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128257. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128258. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128259. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128260. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128261. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128262. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128263. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128264. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128265. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128266. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128267. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128268. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128269. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128270. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128271. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128272. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128273. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128274. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128275. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128276. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128277. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128278. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128279. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128280. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128281. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128282. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128283. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128284. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128285. };
  128286. static att3 _psy_tone_masteratt_44[12]={
  128287. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128288. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128289. /* 1 */
  128290. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128291. /* 2 */
  128292. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128293. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128294. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128295. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128296. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128297. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128298. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128299. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128300. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128301. };
  128302. static double _psy_lowpass_44[12]={
  128303. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128304. };
  128305. static int _noise_start_short_44[11]={
  128306. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128307. };
  128308. static int _noise_start_long_44[11]={
  128309. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128310. };
  128311. static int _noise_part_short_44[11]={
  128312. 8,8,8,8,8,8,8,8,8,8,8
  128313. };
  128314. static int _noise_part_long_44[11]={
  128315. 32,32,32,32,32,32,32,32,32,32,32
  128316. };
  128317. static double _noise_thresh_44[11]={
  128318. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128319. };
  128320. static double _noise_thresh_5only[2]={
  128321. .5,.5,
  128322. };
  128323. /*** End of inlined file: psych_44.h ***/
  128324. static double rate_mapping_44_stereo[12]={
  128325. 22500.,32000.,40000.,48000.,56000.,64000.,
  128326. 80000.,96000.,112000.,128000.,160000.,250001.
  128327. };
  128328. static double quality_mapping_44[12]={
  128329. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128330. };
  128331. static int blocksize_short_44[11]={
  128332. 512,256,256,256,256,256,256,256,256,256,256
  128333. };
  128334. static int blocksize_long_44[11]={
  128335. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128336. };
  128337. static double _psy_compand_short_mapping[12]={
  128338. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128339. };
  128340. static double _psy_compand_long_mapping[12]={
  128341. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128342. };
  128343. static double _global_mapping_44[12]={
  128344. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128345. };
  128346. static int _floor_short_mapping_44[11]={
  128347. 1,0,0,2,2,4,5,5,5,5,5
  128348. };
  128349. static int _floor_long_mapping_44[11]={
  128350. 8,7,7,7,7,7,7,7,7,7,7
  128351. };
  128352. ve_setup_data_template ve_setup_44_stereo={
  128353. 11,
  128354. rate_mapping_44_stereo,
  128355. quality_mapping_44,
  128356. 2,
  128357. 40000,
  128358. 50000,
  128359. blocksize_short_44,
  128360. blocksize_long_44,
  128361. _psy_tone_masteratt_44,
  128362. _psy_tone_0dB,
  128363. _psy_tone_suppress,
  128364. _vp_tonemask_adj_otherblock,
  128365. _vp_tonemask_adj_longblock,
  128366. _vp_tonemask_adj_otherblock,
  128367. _psy_noiseguards_44,
  128368. _psy_noisebias_impulse,
  128369. _psy_noisebias_padding,
  128370. _psy_noisebias_trans,
  128371. _psy_noisebias_long,
  128372. _psy_noise_suppress,
  128373. _psy_compand_44,
  128374. _psy_compand_short_mapping,
  128375. _psy_compand_long_mapping,
  128376. {_noise_start_short_44,_noise_start_long_44},
  128377. {_noise_part_short_44,_noise_part_long_44},
  128378. _noise_thresh_44,
  128379. _psy_ath_floater,
  128380. _psy_ath_abs,
  128381. _psy_lowpass_44,
  128382. _psy_global_44,
  128383. _global_mapping_44,
  128384. _psy_stereo_modes_44,
  128385. _floor_books,
  128386. _floor,
  128387. _floor_short_mapping_44,
  128388. _floor_long_mapping_44,
  128389. _mapres_template_44_stereo
  128390. };
  128391. /*** End of inlined file: setup_44.h ***/
  128392. /*** Start of inlined file: setup_44u.h ***/
  128393. /*** Start of inlined file: residue_44u.h ***/
  128394. /*** Start of inlined file: res_books_uncoupled.h ***/
  128395. static long _vq_quantlist__16u0__p1_0[] = {
  128396. 1,
  128397. 0,
  128398. 2,
  128399. };
  128400. static long _vq_lengthlist__16u0__p1_0[] = {
  128401. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128402. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128403. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128404. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128405. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128406. 12,
  128407. };
  128408. static float _vq_quantthresh__16u0__p1_0[] = {
  128409. -0.5, 0.5,
  128410. };
  128411. static long _vq_quantmap__16u0__p1_0[] = {
  128412. 1, 0, 2,
  128413. };
  128414. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128415. _vq_quantthresh__16u0__p1_0,
  128416. _vq_quantmap__16u0__p1_0,
  128417. 3,
  128418. 3
  128419. };
  128420. static static_codebook _16u0__p1_0 = {
  128421. 4, 81,
  128422. _vq_lengthlist__16u0__p1_0,
  128423. 1, -535822336, 1611661312, 2, 0,
  128424. _vq_quantlist__16u0__p1_0,
  128425. NULL,
  128426. &_vq_auxt__16u0__p1_0,
  128427. NULL,
  128428. 0
  128429. };
  128430. static long _vq_quantlist__16u0__p2_0[] = {
  128431. 1,
  128432. 0,
  128433. 2,
  128434. };
  128435. static long _vq_lengthlist__16u0__p2_0[] = {
  128436. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128437. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128438. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128439. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128440. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128441. 8,
  128442. };
  128443. static float _vq_quantthresh__16u0__p2_0[] = {
  128444. -0.5, 0.5,
  128445. };
  128446. static long _vq_quantmap__16u0__p2_0[] = {
  128447. 1, 0, 2,
  128448. };
  128449. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128450. _vq_quantthresh__16u0__p2_0,
  128451. _vq_quantmap__16u0__p2_0,
  128452. 3,
  128453. 3
  128454. };
  128455. static static_codebook _16u0__p2_0 = {
  128456. 4, 81,
  128457. _vq_lengthlist__16u0__p2_0,
  128458. 1, -535822336, 1611661312, 2, 0,
  128459. _vq_quantlist__16u0__p2_0,
  128460. NULL,
  128461. &_vq_auxt__16u0__p2_0,
  128462. NULL,
  128463. 0
  128464. };
  128465. static long _vq_quantlist__16u0__p3_0[] = {
  128466. 2,
  128467. 1,
  128468. 3,
  128469. 0,
  128470. 4,
  128471. };
  128472. static long _vq_lengthlist__16u0__p3_0[] = {
  128473. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128474. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128475. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128476. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128477. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128478. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128479. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128480. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128481. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128482. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128483. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128484. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128485. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128486. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128487. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128488. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128489. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128490. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128491. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128492. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128493. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128494. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128495. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128496. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128497. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128498. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128499. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128500. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128501. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128502. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128503. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128504. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128505. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128506. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128507. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128508. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128509. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128510. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128511. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128512. 18,
  128513. };
  128514. static float _vq_quantthresh__16u0__p3_0[] = {
  128515. -1.5, -0.5, 0.5, 1.5,
  128516. };
  128517. static long _vq_quantmap__16u0__p3_0[] = {
  128518. 3, 1, 0, 2, 4,
  128519. };
  128520. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128521. _vq_quantthresh__16u0__p3_0,
  128522. _vq_quantmap__16u0__p3_0,
  128523. 5,
  128524. 5
  128525. };
  128526. static static_codebook _16u0__p3_0 = {
  128527. 4, 625,
  128528. _vq_lengthlist__16u0__p3_0,
  128529. 1, -533725184, 1611661312, 3, 0,
  128530. _vq_quantlist__16u0__p3_0,
  128531. NULL,
  128532. &_vq_auxt__16u0__p3_0,
  128533. NULL,
  128534. 0
  128535. };
  128536. static long _vq_quantlist__16u0__p4_0[] = {
  128537. 2,
  128538. 1,
  128539. 3,
  128540. 0,
  128541. 4,
  128542. };
  128543. static long _vq_lengthlist__16u0__p4_0[] = {
  128544. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128545. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128546. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128547. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128548. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128549. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128550. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128551. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128552. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128553. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128554. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128555. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128556. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128557. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128558. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128559. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128560. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128561. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128562. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128563. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128564. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128565. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128566. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128567. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128568. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128569. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128570. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128571. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128572. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128573. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128574. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128575. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128576. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128577. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128578. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128579. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128580. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128581. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128582. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128583. 11,
  128584. };
  128585. static float _vq_quantthresh__16u0__p4_0[] = {
  128586. -1.5, -0.5, 0.5, 1.5,
  128587. };
  128588. static long _vq_quantmap__16u0__p4_0[] = {
  128589. 3, 1, 0, 2, 4,
  128590. };
  128591. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128592. _vq_quantthresh__16u0__p4_0,
  128593. _vq_quantmap__16u0__p4_0,
  128594. 5,
  128595. 5
  128596. };
  128597. static static_codebook _16u0__p4_0 = {
  128598. 4, 625,
  128599. _vq_lengthlist__16u0__p4_0,
  128600. 1, -533725184, 1611661312, 3, 0,
  128601. _vq_quantlist__16u0__p4_0,
  128602. NULL,
  128603. &_vq_auxt__16u0__p4_0,
  128604. NULL,
  128605. 0
  128606. };
  128607. static long _vq_quantlist__16u0__p5_0[] = {
  128608. 4,
  128609. 3,
  128610. 5,
  128611. 2,
  128612. 6,
  128613. 1,
  128614. 7,
  128615. 0,
  128616. 8,
  128617. };
  128618. static long _vq_lengthlist__16u0__p5_0[] = {
  128619. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128620. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128621. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128622. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128623. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128624. 12,
  128625. };
  128626. static float _vq_quantthresh__16u0__p5_0[] = {
  128627. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128628. };
  128629. static long _vq_quantmap__16u0__p5_0[] = {
  128630. 7, 5, 3, 1, 0, 2, 4, 6,
  128631. 8,
  128632. };
  128633. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128634. _vq_quantthresh__16u0__p5_0,
  128635. _vq_quantmap__16u0__p5_0,
  128636. 9,
  128637. 9
  128638. };
  128639. static static_codebook _16u0__p5_0 = {
  128640. 2, 81,
  128641. _vq_lengthlist__16u0__p5_0,
  128642. 1, -531628032, 1611661312, 4, 0,
  128643. _vq_quantlist__16u0__p5_0,
  128644. NULL,
  128645. &_vq_auxt__16u0__p5_0,
  128646. NULL,
  128647. 0
  128648. };
  128649. static long _vq_quantlist__16u0__p6_0[] = {
  128650. 6,
  128651. 5,
  128652. 7,
  128653. 4,
  128654. 8,
  128655. 3,
  128656. 9,
  128657. 2,
  128658. 10,
  128659. 1,
  128660. 11,
  128661. 0,
  128662. 12,
  128663. };
  128664. static long _vq_lengthlist__16u0__p6_0[] = {
  128665. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128666. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128667. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128668. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128669. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128670. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128671. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128672. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128673. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128674. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128675. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128676. };
  128677. static float _vq_quantthresh__16u0__p6_0[] = {
  128678. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128679. 12.5, 17.5, 22.5, 27.5,
  128680. };
  128681. static long _vq_quantmap__16u0__p6_0[] = {
  128682. 11, 9, 7, 5, 3, 1, 0, 2,
  128683. 4, 6, 8, 10, 12,
  128684. };
  128685. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128686. _vq_quantthresh__16u0__p6_0,
  128687. _vq_quantmap__16u0__p6_0,
  128688. 13,
  128689. 13
  128690. };
  128691. static static_codebook _16u0__p6_0 = {
  128692. 2, 169,
  128693. _vq_lengthlist__16u0__p6_0,
  128694. 1, -526516224, 1616117760, 4, 0,
  128695. _vq_quantlist__16u0__p6_0,
  128696. NULL,
  128697. &_vq_auxt__16u0__p6_0,
  128698. NULL,
  128699. 0
  128700. };
  128701. static long _vq_quantlist__16u0__p6_1[] = {
  128702. 2,
  128703. 1,
  128704. 3,
  128705. 0,
  128706. 4,
  128707. };
  128708. static long _vq_lengthlist__16u0__p6_1[] = {
  128709. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128710. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128711. };
  128712. static float _vq_quantthresh__16u0__p6_1[] = {
  128713. -1.5, -0.5, 0.5, 1.5,
  128714. };
  128715. static long _vq_quantmap__16u0__p6_1[] = {
  128716. 3, 1, 0, 2, 4,
  128717. };
  128718. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128719. _vq_quantthresh__16u0__p6_1,
  128720. _vq_quantmap__16u0__p6_1,
  128721. 5,
  128722. 5
  128723. };
  128724. static static_codebook _16u0__p6_1 = {
  128725. 2, 25,
  128726. _vq_lengthlist__16u0__p6_1,
  128727. 1, -533725184, 1611661312, 3, 0,
  128728. _vq_quantlist__16u0__p6_1,
  128729. NULL,
  128730. &_vq_auxt__16u0__p6_1,
  128731. NULL,
  128732. 0
  128733. };
  128734. static long _vq_quantlist__16u0__p7_0[] = {
  128735. 1,
  128736. 0,
  128737. 2,
  128738. };
  128739. static long _vq_lengthlist__16u0__p7_0[] = {
  128740. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128741. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128742. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128743. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128744. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128745. 7,
  128746. };
  128747. static float _vq_quantthresh__16u0__p7_0[] = {
  128748. -157.5, 157.5,
  128749. };
  128750. static long _vq_quantmap__16u0__p7_0[] = {
  128751. 1, 0, 2,
  128752. };
  128753. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128754. _vq_quantthresh__16u0__p7_0,
  128755. _vq_quantmap__16u0__p7_0,
  128756. 3,
  128757. 3
  128758. };
  128759. static static_codebook _16u0__p7_0 = {
  128760. 4, 81,
  128761. _vq_lengthlist__16u0__p7_0,
  128762. 1, -518803456, 1628680192, 2, 0,
  128763. _vq_quantlist__16u0__p7_0,
  128764. NULL,
  128765. &_vq_auxt__16u0__p7_0,
  128766. NULL,
  128767. 0
  128768. };
  128769. static long _vq_quantlist__16u0__p7_1[] = {
  128770. 7,
  128771. 6,
  128772. 8,
  128773. 5,
  128774. 9,
  128775. 4,
  128776. 10,
  128777. 3,
  128778. 11,
  128779. 2,
  128780. 12,
  128781. 1,
  128782. 13,
  128783. 0,
  128784. 14,
  128785. };
  128786. static long _vq_lengthlist__16u0__p7_1[] = {
  128787. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128788. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128789. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128790. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128791. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128792. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128793. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128794. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128795. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128796. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128797. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128798. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128799. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128800. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128801. 10,
  128802. };
  128803. static float _vq_quantthresh__16u0__p7_1[] = {
  128804. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128805. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128806. };
  128807. static long _vq_quantmap__16u0__p7_1[] = {
  128808. 13, 11, 9, 7, 5, 3, 1, 0,
  128809. 2, 4, 6, 8, 10, 12, 14,
  128810. };
  128811. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128812. _vq_quantthresh__16u0__p7_1,
  128813. _vq_quantmap__16u0__p7_1,
  128814. 15,
  128815. 15
  128816. };
  128817. static static_codebook _16u0__p7_1 = {
  128818. 2, 225,
  128819. _vq_lengthlist__16u0__p7_1,
  128820. 1, -520986624, 1620377600, 4, 0,
  128821. _vq_quantlist__16u0__p7_1,
  128822. NULL,
  128823. &_vq_auxt__16u0__p7_1,
  128824. NULL,
  128825. 0
  128826. };
  128827. static long _vq_quantlist__16u0__p7_2[] = {
  128828. 10,
  128829. 9,
  128830. 11,
  128831. 8,
  128832. 12,
  128833. 7,
  128834. 13,
  128835. 6,
  128836. 14,
  128837. 5,
  128838. 15,
  128839. 4,
  128840. 16,
  128841. 3,
  128842. 17,
  128843. 2,
  128844. 18,
  128845. 1,
  128846. 19,
  128847. 0,
  128848. 20,
  128849. };
  128850. static long _vq_lengthlist__16u0__p7_2[] = {
  128851. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128852. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128853. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128854. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128855. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128856. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128857. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128858. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128859. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128860. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128861. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128862. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128863. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128864. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128865. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128866. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128867. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128868. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128869. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128870. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128871. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128872. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128873. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128874. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128875. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128876. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128877. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128878. 10,10,12,11,10,11,11,11,10,
  128879. };
  128880. static float _vq_quantthresh__16u0__p7_2[] = {
  128881. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128882. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128883. 6.5, 7.5, 8.5, 9.5,
  128884. };
  128885. static long _vq_quantmap__16u0__p7_2[] = {
  128886. 19, 17, 15, 13, 11, 9, 7, 5,
  128887. 3, 1, 0, 2, 4, 6, 8, 10,
  128888. 12, 14, 16, 18, 20,
  128889. };
  128890. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128891. _vq_quantthresh__16u0__p7_2,
  128892. _vq_quantmap__16u0__p7_2,
  128893. 21,
  128894. 21
  128895. };
  128896. static static_codebook _16u0__p7_2 = {
  128897. 2, 441,
  128898. _vq_lengthlist__16u0__p7_2,
  128899. 1, -529268736, 1611661312, 5, 0,
  128900. _vq_quantlist__16u0__p7_2,
  128901. NULL,
  128902. &_vq_auxt__16u0__p7_2,
  128903. NULL,
  128904. 0
  128905. };
  128906. static long _huff_lengthlist__16u0__single[] = {
  128907. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128908. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128909. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128910. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128911. };
  128912. static static_codebook _huff_book__16u0__single = {
  128913. 2, 64,
  128914. _huff_lengthlist__16u0__single,
  128915. 0, 0, 0, 0, 0,
  128916. NULL,
  128917. NULL,
  128918. NULL,
  128919. NULL,
  128920. 0
  128921. };
  128922. static long _huff_lengthlist__16u1__long[] = {
  128923. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128924. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128925. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128926. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128927. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128928. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128929. 16,13,16,18,
  128930. };
  128931. static static_codebook _huff_book__16u1__long = {
  128932. 2, 100,
  128933. _huff_lengthlist__16u1__long,
  128934. 0, 0, 0, 0, 0,
  128935. NULL,
  128936. NULL,
  128937. NULL,
  128938. NULL,
  128939. 0
  128940. };
  128941. static long _vq_quantlist__16u1__p1_0[] = {
  128942. 1,
  128943. 0,
  128944. 2,
  128945. };
  128946. static long _vq_lengthlist__16u1__p1_0[] = {
  128947. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  128948. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  128949. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  128950. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  128951. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  128952. 11,
  128953. };
  128954. static float _vq_quantthresh__16u1__p1_0[] = {
  128955. -0.5, 0.5,
  128956. };
  128957. static long _vq_quantmap__16u1__p1_0[] = {
  128958. 1, 0, 2,
  128959. };
  128960. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  128961. _vq_quantthresh__16u1__p1_0,
  128962. _vq_quantmap__16u1__p1_0,
  128963. 3,
  128964. 3
  128965. };
  128966. static static_codebook _16u1__p1_0 = {
  128967. 4, 81,
  128968. _vq_lengthlist__16u1__p1_0,
  128969. 1, -535822336, 1611661312, 2, 0,
  128970. _vq_quantlist__16u1__p1_0,
  128971. NULL,
  128972. &_vq_auxt__16u1__p1_0,
  128973. NULL,
  128974. 0
  128975. };
  128976. static long _vq_quantlist__16u1__p2_0[] = {
  128977. 1,
  128978. 0,
  128979. 2,
  128980. };
  128981. static long _vq_lengthlist__16u1__p2_0[] = {
  128982. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  128983. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  128984. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  128985. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  128986. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  128987. 8,
  128988. };
  128989. static float _vq_quantthresh__16u1__p2_0[] = {
  128990. -0.5, 0.5,
  128991. };
  128992. static long _vq_quantmap__16u1__p2_0[] = {
  128993. 1, 0, 2,
  128994. };
  128995. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  128996. _vq_quantthresh__16u1__p2_0,
  128997. _vq_quantmap__16u1__p2_0,
  128998. 3,
  128999. 3
  129000. };
  129001. static static_codebook _16u1__p2_0 = {
  129002. 4, 81,
  129003. _vq_lengthlist__16u1__p2_0,
  129004. 1, -535822336, 1611661312, 2, 0,
  129005. _vq_quantlist__16u1__p2_0,
  129006. NULL,
  129007. &_vq_auxt__16u1__p2_0,
  129008. NULL,
  129009. 0
  129010. };
  129011. static long _vq_quantlist__16u1__p3_0[] = {
  129012. 2,
  129013. 1,
  129014. 3,
  129015. 0,
  129016. 4,
  129017. };
  129018. static long _vq_lengthlist__16u1__p3_0[] = {
  129019. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129020. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  129021. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  129022. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  129023. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  129024. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129025. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129026. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129027. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129028. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129029. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129030. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129031. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129032. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129033. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129034. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129035. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129036. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129037. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129038. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129039. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129040. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129041. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129042. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129043. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129044. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129045. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129046. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129047. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129048. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129049. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129050. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129051. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129052. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129053. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129054. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129055. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129056. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129057. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129058. 16,
  129059. };
  129060. static float _vq_quantthresh__16u1__p3_0[] = {
  129061. -1.5, -0.5, 0.5, 1.5,
  129062. };
  129063. static long _vq_quantmap__16u1__p3_0[] = {
  129064. 3, 1, 0, 2, 4,
  129065. };
  129066. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129067. _vq_quantthresh__16u1__p3_0,
  129068. _vq_quantmap__16u1__p3_0,
  129069. 5,
  129070. 5
  129071. };
  129072. static static_codebook _16u1__p3_0 = {
  129073. 4, 625,
  129074. _vq_lengthlist__16u1__p3_0,
  129075. 1, -533725184, 1611661312, 3, 0,
  129076. _vq_quantlist__16u1__p3_0,
  129077. NULL,
  129078. &_vq_auxt__16u1__p3_0,
  129079. NULL,
  129080. 0
  129081. };
  129082. static long _vq_quantlist__16u1__p4_0[] = {
  129083. 2,
  129084. 1,
  129085. 3,
  129086. 0,
  129087. 4,
  129088. };
  129089. static long _vq_lengthlist__16u1__p4_0[] = {
  129090. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129091. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129092. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129093. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129094. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129095. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129096. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129097. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129098. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129099. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129100. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129101. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129102. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129103. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129104. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129105. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129106. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129107. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129108. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129109. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129110. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129111. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129112. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129113. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129114. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129115. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129116. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129117. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129118. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129119. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129120. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129121. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129122. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129123. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129124. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129125. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129126. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129127. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129128. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129129. 11,
  129130. };
  129131. static float _vq_quantthresh__16u1__p4_0[] = {
  129132. -1.5, -0.5, 0.5, 1.5,
  129133. };
  129134. static long _vq_quantmap__16u1__p4_0[] = {
  129135. 3, 1, 0, 2, 4,
  129136. };
  129137. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129138. _vq_quantthresh__16u1__p4_0,
  129139. _vq_quantmap__16u1__p4_0,
  129140. 5,
  129141. 5
  129142. };
  129143. static static_codebook _16u1__p4_0 = {
  129144. 4, 625,
  129145. _vq_lengthlist__16u1__p4_0,
  129146. 1, -533725184, 1611661312, 3, 0,
  129147. _vq_quantlist__16u1__p4_0,
  129148. NULL,
  129149. &_vq_auxt__16u1__p4_0,
  129150. NULL,
  129151. 0
  129152. };
  129153. static long _vq_quantlist__16u1__p5_0[] = {
  129154. 4,
  129155. 3,
  129156. 5,
  129157. 2,
  129158. 6,
  129159. 1,
  129160. 7,
  129161. 0,
  129162. 8,
  129163. };
  129164. static long _vq_lengthlist__16u1__p5_0[] = {
  129165. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129166. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129167. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129168. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129169. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129170. 13,
  129171. };
  129172. static float _vq_quantthresh__16u1__p5_0[] = {
  129173. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129174. };
  129175. static long _vq_quantmap__16u1__p5_0[] = {
  129176. 7, 5, 3, 1, 0, 2, 4, 6,
  129177. 8,
  129178. };
  129179. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129180. _vq_quantthresh__16u1__p5_0,
  129181. _vq_quantmap__16u1__p5_0,
  129182. 9,
  129183. 9
  129184. };
  129185. static static_codebook _16u1__p5_0 = {
  129186. 2, 81,
  129187. _vq_lengthlist__16u1__p5_0,
  129188. 1, -531628032, 1611661312, 4, 0,
  129189. _vq_quantlist__16u1__p5_0,
  129190. NULL,
  129191. &_vq_auxt__16u1__p5_0,
  129192. NULL,
  129193. 0
  129194. };
  129195. static long _vq_quantlist__16u1__p6_0[] = {
  129196. 4,
  129197. 3,
  129198. 5,
  129199. 2,
  129200. 6,
  129201. 1,
  129202. 7,
  129203. 0,
  129204. 8,
  129205. };
  129206. static long _vq_lengthlist__16u1__p6_0[] = {
  129207. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129208. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129209. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129210. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129211. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129212. 11,
  129213. };
  129214. static float _vq_quantthresh__16u1__p6_0[] = {
  129215. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129216. };
  129217. static long _vq_quantmap__16u1__p6_0[] = {
  129218. 7, 5, 3, 1, 0, 2, 4, 6,
  129219. 8,
  129220. };
  129221. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129222. _vq_quantthresh__16u1__p6_0,
  129223. _vq_quantmap__16u1__p6_0,
  129224. 9,
  129225. 9
  129226. };
  129227. static static_codebook _16u1__p6_0 = {
  129228. 2, 81,
  129229. _vq_lengthlist__16u1__p6_0,
  129230. 1, -531628032, 1611661312, 4, 0,
  129231. _vq_quantlist__16u1__p6_0,
  129232. NULL,
  129233. &_vq_auxt__16u1__p6_0,
  129234. NULL,
  129235. 0
  129236. };
  129237. static long _vq_quantlist__16u1__p7_0[] = {
  129238. 1,
  129239. 0,
  129240. 2,
  129241. };
  129242. static long _vq_lengthlist__16u1__p7_0[] = {
  129243. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129244. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129245. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129246. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129247. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129248. 13,
  129249. };
  129250. static float _vq_quantthresh__16u1__p7_0[] = {
  129251. -5.5, 5.5,
  129252. };
  129253. static long _vq_quantmap__16u1__p7_0[] = {
  129254. 1, 0, 2,
  129255. };
  129256. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129257. _vq_quantthresh__16u1__p7_0,
  129258. _vq_quantmap__16u1__p7_0,
  129259. 3,
  129260. 3
  129261. };
  129262. static static_codebook _16u1__p7_0 = {
  129263. 4, 81,
  129264. _vq_lengthlist__16u1__p7_0,
  129265. 1, -529137664, 1618345984, 2, 0,
  129266. _vq_quantlist__16u1__p7_0,
  129267. NULL,
  129268. &_vq_auxt__16u1__p7_0,
  129269. NULL,
  129270. 0
  129271. };
  129272. static long _vq_quantlist__16u1__p7_1[] = {
  129273. 5,
  129274. 4,
  129275. 6,
  129276. 3,
  129277. 7,
  129278. 2,
  129279. 8,
  129280. 1,
  129281. 9,
  129282. 0,
  129283. 10,
  129284. };
  129285. static long _vq_lengthlist__16u1__p7_1[] = {
  129286. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129287. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129288. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129289. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129290. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129291. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129292. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129293. 8, 9, 9,10,10,10,10,10,10,
  129294. };
  129295. static float _vq_quantthresh__16u1__p7_1[] = {
  129296. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129297. 3.5, 4.5,
  129298. };
  129299. static long _vq_quantmap__16u1__p7_1[] = {
  129300. 9, 7, 5, 3, 1, 0, 2, 4,
  129301. 6, 8, 10,
  129302. };
  129303. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129304. _vq_quantthresh__16u1__p7_1,
  129305. _vq_quantmap__16u1__p7_1,
  129306. 11,
  129307. 11
  129308. };
  129309. static static_codebook _16u1__p7_1 = {
  129310. 2, 121,
  129311. _vq_lengthlist__16u1__p7_1,
  129312. 1, -531365888, 1611661312, 4, 0,
  129313. _vq_quantlist__16u1__p7_1,
  129314. NULL,
  129315. &_vq_auxt__16u1__p7_1,
  129316. NULL,
  129317. 0
  129318. };
  129319. static long _vq_quantlist__16u1__p8_0[] = {
  129320. 5,
  129321. 4,
  129322. 6,
  129323. 3,
  129324. 7,
  129325. 2,
  129326. 8,
  129327. 1,
  129328. 9,
  129329. 0,
  129330. 10,
  129331. };
  129332. static long _vq_lengthlist__16u1__p8_0[] = {
  129333. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129334. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129335. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129336. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129337. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129338. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129339. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129340. 13,14,14,15,15,16,16,15,16,
  129341. };
  129342. static float _vq_quantthresh__16u1__p8_0[] = {
  129343. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129344. 38.5, 49.5,
  129345. };
  129346. static long _vq_quantmap__16u1__p8_0[] = {
  129347. 9, 7, 5, 3, 1, 0, 2, 4,
  129348. 6, 8, 10,
  129349. };
  129350. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129351. _vq_quantthresh__16u1__p8_0,
  129352. _vq_quantmap__16u1__p8_0,
  129353. 11,
  129354. 11
  129355. };
  129356. static static_codebook _16u1__p8_0 = {
  129357. 2, 121,
  129358. _vq_lengthlist__16u1__p8_0,
  129359. 1, -524582912, 1618345984, 4, 0,
  129360. _vq_quantlist__16u1__p8_0,
  129361. NULL,
  129362. &_vq_auxt__16u1__p8_0,
  129363. NULL,
  129364. 0
  129365. };
  129366. static long _vq_quantlist__16u1__p8_1[] = {
  129367. 5,
  129368. 4,
  129369. 6,
  129370. 3,
  129371. 7,
  129372. 2,
  129373. 8,
  129374. 1,
  129375. 9,
  129376. 0,
  129377. 10,
  129378. };
  129379. static long _vq_lengthlist__16u1__p8_1[] = {
  129380. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129381. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129382. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129383. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129384. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129385. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129386. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129387. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129388. };
  129389. static float _vq_quantthresh__16u1__p8_1[] = {
  129390. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129391. 3.5, 4.5,
  129392. };
  129393. static long _vq_quantmap__16u1__p8_1[] = {
  129394. 9, 7, 5, 3, 1, 0, 2, 4,
  129395. 6, 8, 10,
  129396. };
  129397. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129398. _vq_quantthresh__16u1__p8_1,
  129399. _vq_quantmap__16u1__p8_1,
  129400. 11,
  129401. 11
  129402. };
  129403. static static_codebook _16u1__p8_1 = {
  129404. 2, 121,
  129405. _vq_lengthlist__16u1__p8_1,
  129406. 1, -531365888, 1611661312, 4, 0,
  129407. _vq_quantlist__16u1__p8_1,
  129408. NULL,
  129409. &_vq_auxt__16u1__p8_1,
  129410. NULL,
  129411. 0
  129412. };
  129413. static long _vq_quantlist__16u1__p9_0[] = {
  129414. 7,
  129415. 6,
  129416. 8,
  129417. 5,
  129418. 9,
  129419. 4,
  129420. 10,
  129421. 3,
  129422. 11,
  129423. 2,
  129424. 12,
  129425. 1,
  129426. 13,
  129427. 0,
  129428. 14,
  129429. };
  129430. static long _vq_lengthlist__16u1__p9_0[] = {
  129431. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129432. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129433. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129434. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129435. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129436. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129437. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129438. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129439. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129440. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129441. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129442. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129443. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129444. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129445. 8,
  129446. };
  129447. static float _vq_quantthresh__16u1__p9_0[] = {
  129448. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129449. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129450. };
  129451. static long _vq_quantmap__16u1__p9_0[] = {
  129452. 13, 11, 9, 7, 5, 3, 1, 0,
  129453. 2, 4, 6, 8, 10, 12, 14,
  129454. };
  129455. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129456. _vq_quantthresh__16u1__p9_0,
  129457. _vq_quantmap__16u1__p9_0,
  129458. 15,
  129459. 15
  129460. };
  129461. static static_codebook _16u1__p9_0 = {
  129462. 2, 225,
  129463. _vq_lengthlist__16u1__p9_0,
  129464. 1, -514071552, 1627381760, 4, 0,
  129465. _vq_quantlist__16u1__p9_0,
  129466. NULL,
  129467. &_vq_auxt__16u1__p9_0,
  129468. NULL,
  129469. 0
  129470. };
  129471. static long _vq_quantlist__16u1__p9_1[] = {
  129472. 7,
  129473. 6,
  129474. 8,
  129475. 5,
  129476. 9,
  129477. 4,
  129478. 10,
  129479. 3,
  129480. 11,
  129481. 2,
  129482. 12,
  129483. 1,
  129484. 13,
  129485. 0,
  129486. 14,
  129487. };
  129488. static long _vq_lengthlist__16u1__p9_1[] = {
  129489. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129490. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129491. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129492. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129493. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129494. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129495. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129496. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129497. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129498. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129499. 10,10,10,10,10,10,10,10, 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,
  129504. };
  129505. static float _vq_quantthresh__16u1__p9_1[] = {
  129506. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129507. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129508. };
  129509. static long _vq_quantmap__16u1__p9_1[] = {
  129510. 13, 11, 9, 7, 5, 3, 1, 0,
  129511. 2, 4, 6, 8, 10, 12, 14,
  129512. };
  129513. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129514. _vq_quantthresh__16u1__p9_1,
  129515. _vq_quantmap__16u1__p9_1,
  129516. 15,
  129517. 15
  129518. };
  129519. static static_codebook _16u1__p9_1 = {
  129520. 2, 225,
  129521. _vq_lengthlist__16u1__p9_1,
  129522. 1, -522338304, 1620115456, 4, 0,
  129523. _vq_quantlist__16u1__p9_1,
  129524. NULL,
  129525. &_vq_auxt__16u1__p9_1,
  129526. NULL,
  129527. 0
  129528. };
  129529. static long _vq_quantlist__16u1__p9_2[] = {
  129530. 8,
  129531. 7,
  129532. 9,
  129533. 6,
  129534. 10,
  129535. 5,
  129536. 11,
  129537. 4,
  129538. 12,
  129539. 3,
  129540. 13,
  129541. 2,
  129542. 14,
  129543. 1,
  129544. 15,
  129545. 0,
  129546. 16,
  129547. };
  129548. static long _vq_lengthlist__16u1__p9_2[] = {
  129549. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129550. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129551. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129552. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129553. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129554. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129555. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129556. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129557. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129558. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129559. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129560. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129561. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129562. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129563. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129564. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129565. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129566. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129567. 10,
  129568. };
  129569. static float _vq_quantthresh__16u1__p9_2[] = {
  129570. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129571. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129572. };
  129573. static long _vq_quantmap__16u1__p9_2[] = {
  129574. 15, 13, 11, 9, 7, 5, 3, 1,
  129575. 0, 2, 4, 6, 8, 10, 12, 14,
  129576. 16,
  129577. };
  129578. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129579. _vq_quantthresh__16u1__p9_2,
  129580. _vq_quantmap__16u1__p9_2,
  129581. 17,
  129582. 17
  129583. };
  129584. static static_codebook _16u1__p9_2 = {
  129585. 2, 289,
  129586. _vq_lengthlist__16u1__p9_2,
  129587. 1, -529530880, 1611661312, 5, 0,
  129588. _vq_quantlist__16u1__p9_2,
  129589. NULL,
  129590. &_vq_auxt__16u1__p9_2,
  129591. NULL,
  129592. 0
  129593. };
  129594. static long _huff_lengthlist__16u1__short[] = {
  129595. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129596. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129597. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129598. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129599. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129600. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129601. 16,16,16,16,
  129602. };
  129603. static static_codebook _huff_book__16u1__short = {
  129604. 2, 100,
  129605. _huff_lengthlist__16u1__short,
  129606. 0, 0, 0, 0, 0,
  129607. NULL,
  129608. NULL,
  129609. NULL,
  129610. NULL,
  129611. 0
  129612. };
  129613. static long _huff_lengthlist__16u2__long[] = {
  129614. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129615. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129616. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129617. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129618. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129619. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129620. 13,14,18,18,
  129621. };
  129622. static static_codebook _huff_book__16u2__long = {
  129623. 2, 100,
  129624. _huff_lengthlist__16u2__long,
  129625. 0, 0, 0, 0, 0,
  129626. NULL,
  129627. NULL,
  129628. NULL,
  129629. NULL,
  129630. 0
  129631. };
  129632. static long _huff_lengthlist__16u2__short[] = {
  129633. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129634. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129635. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129636. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129637. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129638. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129639. 16,16,16,16,
  129640. };
  129641. static static_codebook _huff_book__16u2__short = {
  129642. 2, 100,
  129643. _huff_lengthlist__16u2__short,
  129644. 0, 0, 0, 0, 0,
  129645. NULL,
  129646. NULL,
  129647. NULL,
  129648. NULL,
  129649. 0
  129650. };
  129651. static long _vq_quantlist__16u2_p1_0[] = {
  129652. 1,
  129653. 0,
  129654. 2,
  129655. };
  129656. static long _vq_lengthlist__16u2_p1_0[] = {
  129657. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129658. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129659. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129660. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129661. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129662. 10,
  129663. };
  129664. static float _vq_quantthresh__16u2_p1_0[] = {
  129665. -0.5, 0.5,
  129666. };
  129667. static long _vq_quantmap__16u2_p1_0[] = {
  129668. 1, 0, 2,
  129669. };
  129670. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129671. _vq_quantthresh__16u2_p1_0,
  129672. _vq_quantmap__16u2_p1_0,
  129673. 3,
  129674. 3
  129675. };
  129676. static static_codebook _16u2_p1_0 = {
  129677. 4, 81,
  129678. _vq_lengthlist__16u2_p1_0,
  129679. 1, -535822336, 1611661312, 2, 0,
  129680. _vq_quantlist__16u2_p1_0,
  129681. NULL,
  129682. &_vq_auxt__16u2_p1_0,
  129683. NULL,
  129684. 0
  129685. };
  129686. static long _vq_quantlist__16u2_p2_0[] = {
  129687. 2,
  129688. 1,
  129689. 3,
  129690. 0,
  129691. 4,
  129692. };
  129693. static long _vq_lengthlist__16u2_p2_0[] = {
  129694. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129695. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129696. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129697. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129698. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129699. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129700. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129701. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129702. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129703. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129704. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129705. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129706. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129707. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129708. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129709. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129710. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129711. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129712. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129713. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129714. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129715. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129716. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129717. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129718. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129719. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129720. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129721. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129722. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129723. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129724. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129725. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129726. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129727. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129728. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129729. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129730. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129731. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129732. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129733. 13,
  129734. };
  129735. static float _vq_quantthresh__16u2_p2_0[] = {
  129736. -1.5, -0.5, 0.5, 1.5,
  129737. };
  129738. static long _vq_quantmap__16u2_p2_0[] = {
  129739. 3, 1, 0, 2, 4,
  129740. };
  129741. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129742. _vq_quantthresh__16u2_p2_0,
  129743. _vq_quantmap__16u2_p2_0,
  129744. 5,
  129745. 5
  129746. };
  129747. static static_codebook _16u2_p2_0 = {
  129748. 4, 625,
  129749. _vq_lengthlist__16u2_p2_0,
  129750. 1, -533725184, 1611661312, 3, 0,
  129751. _vq_quantlist__16u2_p2_0,
  129752. NULL,
  129753. &_vq_auxt__16u2_p2_0,
  129754. NULL,
  129755. 0
  129756. };
  129757. static long _vq_quantlist__16u2_p3_0[] = {
  129758. 4,
  129759. 3,
  129760. 5,
  129761. 2,
  129762. 6,
  129763. 1,
  129764. 7,
  129765. 0,
  129766. 8,
  129767. };
  129768. static long _vq_lengthlist__16u2_p3_0[] = {
  129769. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129770. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129771. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129772. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129773. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129774. 11,
  129775. };
  129776. static float _vq_quantthresh__16u2_p3_0[] = {
  129777. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129778. };
  129779. static long _vq_quantmap__16u2_p3_0[] = {
  129780. 7, 5, 3, 1, 0, 2, 4, 6,
  129781. 8,
  129782. };
  129783. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129784. _vq_quantthresh__16u2_p3_0,
  129785. _vq_quantmap__16u2_p3_0,
  129786. 9,
  129787. 9
  129788. };
  129789. static static_codebook _16u2_p3_0 = {
  129790. 2, 81,
  129791. _vq_lengthlist__16u2_p3_0,
  129792. 1, -531628032, 1611661312, 4, 0,
  129793. _vq_quantlist__16u2_p3_0,
  129794. NULL,
  129795. &_vq_auxt__16u2_p3_0,
  129796. NULL,
  129797. 0
  129798. };
  129799. static long _vq_quantlist__16u2_p4_0[] = {
  129800. 8,
  129801. 7,
  129802. 9,
  129803. 6,
  129804. 10,
  129805. 5,
  129806. 11,
  129807. 4,
  129808. 12,
  129809. 3,
  129810. 13,
  129811. 2,
  129812. 14,
  129813. 1,
  129814. 15,
  129815. 0,
  129816. 16,
  129817. };
  129818. static long _vq_lengthlist__16u2_p4_0[] = {
  129819. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129820. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129821. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129822. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129823. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129824. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129825. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129826. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129827. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129828. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129829. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129830. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129831. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129832. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129833. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129834. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129835. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129836. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129837. 14,
  129838. };
  129839. static float _vq_quantthresh__16u2_p4_0[] = {
  129840. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129841. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129842. };
  129843. static long _vq_quantmap__16u2_p4_0[] = {
  129844. 15, 13, 11, 9, 7, 5, 3, 1,
  129845. 0, 2, 4, 6, 8, 10, 12, 14,
  129846. 16,
  129847. };
  129848. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129849. _vq_quantthresh__16u2_p4_0,
  129850. _vq_quantmap__16u2_p4_0,
  129851. 17,
  129852. 17
  129853. };
  129854. static static_codebook _16u2_p4_0 = {
  129855. 2, 289,
  129856. _vq_lengthlist__16u2_p4_0,
  129857. 1, -529530880, 1611661312, 5, 0,
  129858. _vq_quantlist__16u2_p4_0,
  129859. NULL,
  129860. &_vq_auxt__16u2_p4_0,
  129861. NULL,
  129862. 0
  129863. };
  129864. static long _vq_quantlist__16u2_p5_0[] = {
  129865. 1,
  129866. 0,
  129867. 2,
  129868. };
  129869. static long _vq_lengthlist__16u2_p5_0[] = {
  129870. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129871. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129872. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129873. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129874. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129875. 10,
  129876. };
  129877. static float _vq_quantthresh__16u2_p5_0[] = {
  129878. -5.5, 5.5,
  129879. };
  129880. static long _vq_quantmap__16u2_p5_0[] = {
  129881. 1, 0, 2,
  129882. };
  129883. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129884. _vq_quantthresh__16u2_p5_0,
  129885. _vq_quantmap__16u2_p5_0,
  129886. 3,
  129887. 3
  129888. };
  129889. static static_codebook _16u2_p5_0 = {
  129890. 4, 81,
  129891. _vq_lengthlist__16u2_p5_0,
  129892. 1, -529137664, 1618345984, 2, 0,
  129893. _vq_quantlist__16u2_p5_0,
  129894. NULL,
  129895. &_vq_auxt__16u2_p5_0,
  129896. NULL,
  129897. 0
  129898. };
  129899. static long _vq_quantlist__16u2_p5_1[] = {
  129900. 5,
  129901. 4,
  129902. 6,
  129903. 3,
  129904. 7,
  129905. 2,
  129906. 8,
  129907. 1,
  129908. 9,
  129909. 0,
  129910. 10,
  129911. };
  129912. static long _vq_lengthlist__16u2_p5_1[] = {
  129913. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129914. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129915. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129916. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129917. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129918. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129919. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129920. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129921. };
  129922. static float _vq_quantthresh__16u2_p5_1[] = {
  129923. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129924. 3.5, 4.5,
  129925. };
  129926. static long _vq_quantmap__16u2_p5_1[] = {
  129927. 9, 7, 5, 3, 1, 0, 2, 4,
  129928. 6, 8, 10,
  129929. };
  129930. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129931. _vq_quantthresh__16u2_p5_1,
  129932. _vq_quantmap__16u2_p5_1,
  129933. 11,
  129934. 11
  129935. };
  129936. static static_codebook _16u2_p5_1 = {
  129937. 2, 121,
  129938. _vq_lengthlist__16u2_p5_1,
  129939. 1, -531365888, 1611661312, 4, 0,
  129940. _vq_quantlist__16u2_p5_1,
  129941. NULL,
  129942. &_vq_auxt__16u2_p5_1,
  129943. NULL,
  129944. 0
  129945. };
  129946. static long _vq_quantlist__16u2_p6_0[] = {
  129947. 6,
  129948. 5,
  129949. 7,
  129950. 4,
  129951. 8,
  129952. 3,
  129953. 9,
  129954. 2,
  129955. 10,
  129956. 1,
  129957. 11,
  129958. 0,
  129959. 12,
  129960. };
  129961. static long _vq_lengthlist__16u2_p6_0[] = {
  129962. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  129963. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  129964. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  129965. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  129966. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  129967. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  129968. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  129969. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  129970. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  129971. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  129972. 12,13,13,14,14,14,14,15,15,
  129973. };
  129974. static float _vq_quantthresh__16u2_p6_0[] = {
  129975. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129976. 12.5, 17.5, 22.5, 27.5,
  129977. };
  129978. static long _vq_quantmap__16u2_p6_0[] = {
  129979. 11, 9, 7, 5, 3, 1, 0, 2,
  129980. 4, 6, 8, 10, 12,
  129981. };
  129982. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  129983. _vq_quantthresh__16u2_p6_0,
  129984. _vq_quantmap__16u2_p6_0,
  129985. 13,
  129986. 13
  129987. };
  129988. static static_codebook _16u2_p6_0 = {
  129989. 2, 169,
  129990. _vq_lengthlist__16u2_p6_0,
  129991. 1, -526516224, 1616117760, 4, 0,
  129992. _vq_quantlist__16u2_p6_0,
  129993. NULL,
  129994. &_vq_auxt__16u2_p6_0,
  129995. NULL,
  129996. 0
  129997. };
  129998. static long _vq_quantlist__16u2_p6_1[] = {
  129999. 2,
  130000. 1,
  130001. 3,
  130002. 0,
  130003. 4,
  130004. };
  130005. static long _vq_lengthlist__16u2_p6_1[] = {
  130006. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  130007. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  130008. };
  130009. static float _vq_quantthresh__16u2_p6_1[] = {
  130010. -1.5, -0.5, 0.5, 1.5,
  130011. };
  130012. static long _vq_quantmap__16u2_p6_1[] = {
  130013. 3, 1, 0, 2, 4,
  130014. };
  130015. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  130016. _vq_quantthresh__16u2_p6_1,
  130017. _vq_quantmap__16u2_p6_1,
  130018. 5,
  130019. 5
  130020. };
  130021. static static_codebook _16u2_p6_1 = {
  130022. 2, 25,
  130023. _vq_lengthlist__16u2_p6_1,
  130024. 1, -533725184, 1611661312, 3, 0,
  130025. _vq_quantlist__16u2_p6_1,
  130026. NULL,
  130027. &_vq_auxt__16u2_p6_1,
  130028. NULL,
  130029. 0
  130030. };
  130031. static long _vq_quantlist__16u2_p7_0[] = {
  130032. 6,
  130033. 5,
  130034. 7,
  130035. 4,
  130036. 8,
  130037. 3,
  130038. 9,
  130039. 2,
  130040. 10,
  130041. 1,
  130042. 11,
  130043. 0,
  130044. 12,
  130045. };
  130046. static long _vq_lengthlist__16u2_p7_0[] = {
  130047. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130048. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130049. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130050. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130051. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130052. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130053. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130054. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130055. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130056. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130057. 12,13,13,13,14,14,14,15,14,
  130058. };
  130059. static float _vq_quantthresh__16u2_p7_0[] = {
  130060. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130061. 27.5, 38.5, 49.5, 60.5,
  130062. };
  130063. static long _vq_quantmap__16u2_p7_0[] = {
  130064. 11, 9, 7, 5, 3, 1, 0, 2,
  130065. 4, 6, 8, 10, 12,
  130066. };
  130067. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130068. _vq_quantthresh__16u2_p7_0,
  130069. _vq_quantmap__16u2_p7_0,
  130070. 13,
  130071. 13
  130072. };
  130073. static static_codebook _16u2_p7_0 = {
  130074. 2, 169,
  130075. _vq_lengthlist__16u2_p7_0,
  130076. 1, -523206656, 1618345984, 4, 0,
  130077. _vq_quantlist__16u2_p7_0,
  130078. NULL,
  130079. &_vq_auxt__16u2_p7_0,
  130080. NULL,
  130081. 0
  130082. };
  130083. static long _vq_quantlist__16u2_p7_1[] = {
  130084. 5,
  130085. 4,
  130086. 6,
  130087. 3,
  130088. 7,
  130089. 2,
  130090. 8,
  130091. 1,
  130092. 9,
  130093. 0,
  130094. 10,
  130095. };
  130096. static long _vq_lengthlist__16u2_p7_1[] = {
  130097. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130098. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130099. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130100. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130101. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130102. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130103. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130104. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130105. };
  130106. static float _vq_quantthresh__16u2_p7_1[] = {
  130107. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130108. 3.5, 4.5,
  130109. };
  130110. static long _vq_quantmap__16u2_p7_1[] = {
  130111. 9, 7, 5, 3, 1, 0, 2, 4,
  130112. 6, 8, 10,
  130113. };
  130114. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130115. _vq_quantthresh__16u2_p7_1,
  130116. _vq_quantmap__16u2_p7_1,
  130117. 11,
  130118. 11
  130119. };
  130120. static static_codebook _16u2_p7_1 = {
  130121. 2, 121,
  130122. _vq_lengthlist__16u2_p7_1,
  130123. 1, -531365888, 1611661312, 4, 0,
  130124. _vq_quantlist__16u2_p7_1,
  130125. NULL,
  130126. &_vq_auxt__16u2_p7_1,
  130127. NULL,
  130128. 0
  130129. };
  130130. static long _vq_quantlist__16u2_p8_0[] = {
  130131. 7,
  130132. 6,
  130133. 8,
  130134. 5,
  130135. 9,
  130136. 4,
  130137. 10,
  130138. 3,
  130139. 11,
  130140. 2,
  130141. 12,
  130142. 1,
  130143. 13,
  130144. 0,
  130145. 14,
  130146. };
  130147. static long _vq_lengthlist__16u2_p8_0[] = {
  130148. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130149. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130150. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130151. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130152. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130153. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130154. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130155. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130156. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130157. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130158. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130159. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130160. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130161. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130162. 14,
  130163. };
  130164. static float _vq_quantthresh__16u2_p8_0[] = {
  130165. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130166. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130167. };
  130168. static long _vq_quantmap__16u2_p8_0[] = {
  130169. 13, 11, 9, 7, 5, 3, 1, 0,
  130170. 2, 4, 6, 8, 10, 12, 14,
  130171. };
  130172. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130173. _vq_quantthresh__16u2_p8_0,
  130174. _vq_quantmap__16u2_p8_0,
  130175. 15,
  130176. 15
  130177. };
  130178. static static_codebook _16u2_p8_0 = {
  130179. 2, 225,
  130180. _vq_lengthlist__16u2_p8_0,
  130181. 1, -520986624, 1620377600, 4, 0,
  130182. _vq_quantlist__16u2_p8_0,
  130183. NULL,
  130184. &_vq_auxt__16u2_p8_0,
  130185. NULL,
  130186. 0
  130187. };
  130188. static long _vq_quantlist__16u2_p8_1[] = {
  130189. 10,
  130190. 9,
  130191. 11,
  130192. 8,
  130193. 12,
  130194. 7,
  130195. 13,
  130196. 6,
  130197. 14,
  130198. 5,
  130199. 15,
  130200. 4,
  130201. 16,
  130202. 3,
  130203. 17,
  130204. 2,
  130205. 18,
  130206. 1,
  130207. 19,
  130208. 0,
  130209. 20,
  130210. };
  130211. static long _vq_lengthlist__16u2_p8_1[] = {
  130212. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130213. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130214. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130215. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130216. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130217. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130218. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130219. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130220. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130221. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130222. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130223. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130224. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130225. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130226. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130227. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130228. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130229. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130230. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130231. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130232. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130233. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130234. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130235. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130236. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130237. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130238. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130239. 11,11,10,11,11,11,10,11,11,
  130240. };
  130241. static float _vq_quantthresh__16u2_p8_1[] = {
  130242. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130243. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130244. 6.5, 7.5, 8.5, 9.5,
  130245. };
  130246. static long _vq_quantmap__16u2_p8_1[] = {
  130247. 19, 17, 15, 13, 11, 9, 7, 5,
  130248. 3, 1, 0, 2, 4, 6, 8, 10,
  130249. 12, 14, 16, 18, 20,
  130250. };
  130251. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130252. _vq_quantthresh__16u2_p8_1,
  130253. _vq_quantmap__16u2_p8_1,
  130254. 21,
  130255. 21
  130256. };
  130257. static static_codebook _16u2_p8_1 = {
  130258. 2, 441,
  130259. _vq_lengthlist__16u2_p8_1,
  130260. 1, -529268736, 1611661312, 5, 0,
  130261. _vq_quantlist__16u2_p8_1,
  130262. NULL,
  130263. &_vq_auxt__16u2_p8_1,
  130264. NULL,
  130265. 0
  130266. };
  130267. static long _vq_quantlist__16u2_p9_0[] = {
  130268. 5586,
  130269. 4655,
  130270. 6517,
  130271. 3724,
  130272. 7448,
  130273. 2793,
  130274. 8379,
  130275. 1862,
  130276. 9310,
  130277. 931,
  130278. 10241,
  130279. 0,
  130280. 11172,
  130281. 5521,
  130282. 5651,
  130283. };
  130284. static long _vq_lengthlist__16u2_p9_0[] = {
  130285. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130286. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130287. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130288. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130289. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130290. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130291. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130292. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130293. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130294. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130295. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130296. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130297. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130298. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130299. 5,
  130300. };
  130301. static float _vq_quantthresh__16u2_p9_0[] = {
  130302. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130303. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130304. };
  130305. static long _vq_quantmap__16u2_p9_0[] = {
  130306. 11, 9, 7, 5, 3, 1, 13, 0,
  130307. 14, 2, 4, 6, 8, 10, 12,
  130308. };
  130309. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130310. _vq_quantthresh__16u2_p9_0,
  130311. _vq_quantmap__16u2_p9_0,
  130312. 15,
  130313. 15
  130314. };
  130315. static static_codebook _16u2_p9_0 = {
  130316. 2, 225,
  130317. _vq_lengthlist__16u2_p9_0,
  130318. 1, -510275072, 1611661312, 14, 0,
  130319. _vq_quantlist__16u2_p9_0,
  130320. NULL,
  130321. &_vq_auxt__16u2_p9_0,
  130322. NULL,
  130323. 0
  130324. };
  130325. static long _vq_quantlist__16u2_p9_1[] = {
  130326. 392,
  130327. 343,
  130328. 441,
  130329. 294,
  130330. 490,
  130331. 245,
  130332. 539,
  130333. 196,
  130334. 588,
  130335. 147,
  130336. 637,
  130337. 98,
  130338. 686,
  130339. 49,
  130340. 735,
  130341. 0,
  130342. 784,
  130343. 388,
  130344. 396,
  130345. };
  130346. static long _vq_lengthlist__16u2_p9_1[] = {
  130347. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130348. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130349. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130350. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130351. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130352. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130353. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130354. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130355. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130356. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130357. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130358. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130359. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130360. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130361. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130362. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130363. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130364. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130365. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130366. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130367. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130368. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130369. 11,11,11,11,11,11,11, 5, 4,
  130370. };
  130371. static float _vq_quantthresh__16u2_p9_1[] = {
  130372. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130373. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130374. 318.5, 367.5,
  130375. };
  130376. static long _vq_quantmap__16u2_p9_1[] = {
  130377. 15, 13, 11, 9, 7, 5, 3, 1,
  130378. 17, 0, 18, 2, 4, 6, 8, 10,
  130379. 12, 14, 16,
  130380. };
  130381. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130382. _vq_quantthresh__16u2_p9_1,
  130383. _vq_quantmap__16u2_p9_1,
  130384. 19,
  130385. 19
  130386. };
  130387. static static_codebook _16u2_p9_1 = {
  130388. 2, 361,
  130389. _vq_lengthlist__16u2_p9_1,
  130390. 1, -518488064, 1611661312, 10, 0,
  130391. _vq_quantlist__16u2_p9_1,
  130392. NULL,
  130393. &_vq_auxt__16u2_p9_1,
  130394. NULL,
  130395. 0
  130396. };
  130397. static long _vq_quantlist__16u2_p9_2[] = {
  130398. 24,
  130399. 23,
  130400. 25,
  130401. 22,
  130402. 26,
  130403. 21,
  130404. 27,
  130405. 20,
  130406. 28,
  130407. 19,
  130408. 29,
  130409. 18,
  130410. 30,
  130411. 17,
  130412. 31,
  130413. 16,
  130414. 32,
  130415. 15,
  130416. 33,
  130417. 14,
  130418. 34,
  130419. 13,
  130420. 35,
  130421. 12,
  130422. 36,
  130423. 11,
  130424. 37,
  130425. 10,
  130426. 38,
  130427. 9,
  130428. 39,
  130429. 8,
  130430. 40,
  130431. 7,
  130432. 41,
  130433. 6,
  130434. 42,
  130435. 5,
  130436. 43,
  130437. 4,
  130438. 44,
  130439. 3,
  130440. 45,
  130441. 2,
  130442. 46,
  130443. 1,
  130444. 47,
  130445. 0,
  130446. 48,
  130447. };
  130448. static long _vq_lengthlist__16u2_p9_2[] = {
  130449. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130450. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130451. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130452. 11,
  130453. };
  130454. static float _vq_quantthresh__16u2_p9_2[] = {
  130455. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130456. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130457. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130458. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130459. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130460. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130461. };
  130462. static long _vq_quantmap__16u2_p9_2[] = {
  130463. 47, 45, 43, 41, 39, 37, 35, 33,
  130464. 31, 29, 27, 25, 23, 21, 19, 17,
  130465. 15, 13, 11, 9, 7, 5, 3, 1,
  130466. 0, 2, 4, 6, 8, 10, 12, 14,
  130467. 16, 18, 20, 22, 24, 26, 28, 30,
  130468. 32, 34, 36, 38, 40, 42, 44, 46,
  130469. 48,
  130470. };
  130471. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130472. _vq_quantthresh__16u2_p9_2,
  130473. _vq_quantmap__16u2_p9_2,
  130474. 49,
  130475. 49
  130476. };
  130477. static static_codebook _16u2_p9_2 = {
  130478. 1, 49,
  130479. _vq_lengthlist__16u2_p9_2,
  130480. 1, -526909440, 1611661312, 6, 0,
  130481. _vq_quantlist__16u2_p9_2,
  130482. NULL,
  130483. &_vq_auxt__16u2_p9_2,
  130484. NULL,
  130485. 0
  130486. };
  130487. static long _vq_quantlist__8u0__p1_0[] = {
  130488. 1,
  130489. 0,
  130490. 2,
  130491. };
  130492. static long _vq_lengthlist__8u0__p1_0[] = {
  130493. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130494. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130495. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130496. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130497. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130498. 11,
  130499. };
  130500. static float _vq_quantthresh__8u0__p1_0[] = {
  130501. -0.5, 0.5,
  130502. };
  130503. static long _vq_quantmap__8u0__p1_0[] = {
  130504. 1, 0, 2,
  130505. };
  130506. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130507. _vq_quantthresh__8u0__p1_0,
  130508. _vq_quantmap__8u0__p1_0,
  130509. 3,
  130510. 3
  130511. };
  130512. static static_codebook _8u0__p1_0 = {
  130513. 4, 81,
  130514. _vq_lengthlist__8u0__p1_0,
  130515. 1, -535822336, 1611661312, 2, 0,
  130516. _vq_quantlist__8u0__p1_0,
  130517. NULL,
  130518. &_vq_auxt__8u0__p1_0,
  130519. NULL,
  130520. 0
  130521. };
  130522. static long _vq_quantlist__8u0__p2_0[] = {
  130523. 1,
  130524. 0,
  130525. 2,
  130526. };
  130527. static long _vq_lengthlist__8u0__p2_0[] = {
  130528. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130529. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130530. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130531. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130532. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130533. 8,
  130534. };
  130535. static float _vq_quantthresh__8u0__p2_0[] = {
  130536. -0.5, 0.5,
  130537. };
  130538. static long _vq_quantmap__8u0__p2_0[] = {
  130539. 1, 0, 2,
  130540. };
  130541. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130542. _vq_quantthresh__8u0__p2_0,
  130543. _vq_quantmap__8u0__p2_0,
  130544. 3,
  130545. 3
  130546. };
  130547. static static_codebook _8u0__p2_0 = {
  130548. 4, 81,
  130549. _vq_lengthlist__8u0__p2_0,
  130550. 1, -535822336, 1611661312, 2, 0,
  130551. _vq_quantlist__8u0__p2_0,
  130552. NULL,
  130553. &_vq_auxt__8u0__p2_0,
  130554. NULL,
  130555. 0
  130556. };
  130557. static long _vq_quantlist__8u0__p3_0[] = {
  130558. 2,
  130559. 1,
  130560. 3,
  130561. 0,
  130562. 4,
  130563. };
  130564. static long _vq_lengthlist__8u0__p3_0[] = {
  130565. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130566. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130567. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130568. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130569. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130570. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130571. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130572. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130573. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130574. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130575. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130576. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130577. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130578. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130579. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130580. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130581. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130582. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130583. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130584. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130585. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130586. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130587. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130588. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130589. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130590. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130591. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130592. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130593. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130594. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130595. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130596. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130597. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130598. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130599. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130600. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130601. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130602. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130603. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130604. 16,
  130605. };
  130606. static float _vq_quantthresh__8u0__p3_0[] = {
  130607. -1.5, -0.5, 0.5, 1.5,
  130608. };
  130609. static long _vq_quantmap__8u0__p3_0[] = {
  130610. 3, 1, 0, 2, 4,
  130611. };
  130612. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130613. _vq_quantthresh__8u0__p3_0,
  130614. _vq_quantmap__8u0__p3_0,
  130615. 5,
  130616. 5
  130617. };
  130618. static static_codebook _8u0__p3_0 = {
  130619. 4, 625,
  130620. _vq_lengthlist__8u0__p3_0,
  130621. 1, -533725184, 1611661312, 3, 0,
  130622. _vq_quantlist__8u0__p3_0,
  130623. NULL,
  130624. &_vq_auxt__8u0__p3_0,
  130625. NULL,
  130626. 0
  130627. };
  130628. static long _vq_quantlist__8u0__p4_0[] = {
  130629. 2,
  130630. 1,
  130631. 3,
  130632. 0,
  130633. 4,
  130634. };
  130635. static long _vq_lengthlist__8u0__p4_0[] = {
  130636. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130637. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130638. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130639. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130640. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130641. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130642. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130643. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130644. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130645. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130646. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130647. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130648. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130649. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130650. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130651. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130652. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130653. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130654. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130655. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130656. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130657. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130658. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130659. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130660. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130661. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130662. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130663. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130664. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130665. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130666. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130667. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130668. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130669. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130670. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130671. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130672. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130673. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130674. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130675. 12,
  130676. };
  130677. static float _vq_quantthresh__8u0__p4_0[] = {
  130678. -1.5, -0.5, 0.5, 1.5,
  130679. };
  130680. static long _vq_quantmap__8u0__p4_0[] = {
  130681. 3, 1, 0, 2, 4,
  130682. };
  130683. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130684. _vq_quantthresh__8u0__p4_0,
  130685. _vq_quantmap__8u0__p4_0,
  130686. 5,
  130687. 5
  130688. };
  130689. static static_codebook _8u0__p4_0 = {
  130690. 4, 625,
  130691. _vq_lengthlist__8u0__p4_0,
  130692. 1, -533725184, 1611661312, 3, 0,
  130693. _vq_quantlist__8u0__p4_0,
  130694. NULL,
  130695. &_vq_auxt__8u0__p4_0,
  130696. NULL,
  130697. 0
  130698. };
  130699. static long _vq_quantlist__8u0__p5_0[] = {
  130700. 4,
  130701. 3,
  130702. 5,
  130703. 2,
  130704. 6,
  130705. 1,
  130706. 7,
  130707. 0,
  130708. 8,
  130709. };
  130710. static long _vq_lengthlist__8u0__p5_0[] = {
  130711. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130712. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130713. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130714. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130715. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130716. 12,
  130717. };
  130718. static float _vq_quantthresh__8u0__p5_0[] = {
  130719. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130720. };
  130721. static long _vq_quantmap__8u0__p5_0[] = {
  130722. 7, 5, 3, 1, 0, 2, 4, 6,
  130723. 8,
  130724. };
  130725. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130726. _vq_quantthresh__8u0__p5_0,
  130727. _vq_quantmap__8u0__p5_0,
  130728. 9,
  130729. 9
  130730. };
  130731. static static_codebook _8u0__p5_0 = {
  130732. 2, 81,
  130733. _vq_lengthlist__8u0__p5_0,
  130734. 1, -531628032, 1611661312, 4, 0,
  130735. _vq_quantlist__8u0__p5_0,
  130736. NULL,
  130737. &_vq_auxt__8u0__p5_0,
  130738. NULL,
  130739. 0
  130740. };
  130741. static long _vq_quantlist__8u0__p6_0[] = {
  130742. 6,
  130743. 5,
  130744. 7,
  130745. 4,
  130746. 8,
  130747. 3,
  130748. 9,
  130749. 2,
  130750. 10,
  130751. 1,
  130752. 11,
  130753. 0,
  130754. 12,
  130755. };
  130756. static long _vq_lengthlist__8u0__p6_0[] = {
  130757. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130758. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130759. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130760. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130761. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130762. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130763. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130764. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130765. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130766. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130767. 16, 0,15, 0,17, 0, 0, 0, 0,
  130768. };
  130769. static float _vq_quantthresh__8u0__p6_0[] = {
  130770. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130771. 12.5, 17.5, 22.5, 27.5,
  130772. };
  130773. static long _vq_quantmap__8u0__p6_0[] = {
  130774. 11, 9, 7, 5, 3, 1, 0, 2,
  130775. 4, 6, 8, 10, 12,
  130776. };
  130777. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130778. _vq_quantthresh__8u0__p6_0,
  130779. _vq_quantmap__8u0__p6_0,
  130780. 13,
  130781. 13
  130782. };
  130783. static static_codebook _8u0__p6_0 = {
  130784. 2, 169,
  130785. _vq_lengthlist__8u0__p6_0,
  130786. 1, -526516224, 1616117760, 4, 0,
  130787. _vq_quantlist__8u0__p6_0,
  130788. NULL,
  130789. &_vq_auxt__8u0__p6_0,
  130790. NULL,
  130791. 0
  130792. };
  130793. static long _vq_quantlist__8u0__p6_1[] = {
  130794. 2,
  130795. 1,
  130796. 3,
  130797. 0,
  130798. 4,
  130799. };
  130800. static long _vq_lengthlist__8u0__p6_1[] = {
  130801. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130802. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130803. };
  130804. static float _vq_quantthresh__8u0__p6_1[] = {
  130805. -1.5, -0.5, 0.5, 1.5,
  130806. };
  130807. static long _vq_quantmap__8u0__p6_1[] = {
  130808. 3, 1, 0, 2, 4,
  130809. };
  130810. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130811. _vq_quantthresh__8u0__p6_1,
  130812. _vq_quantmap__8u0__p6_1,
  130813. 5,
  130814. 5
  130815. };
  130816. static static_codebook _8u0__p6_1 = {
  130817. 2, 25,
  130818. _vq_lengthlist__8u0__p6_1,
  130819. 1, -533725184, 1611661312, 3, 0,
  130820. _vq_quantlist__8u0__p6_1,
  130821. NULL,
  130822. &_vq_auxt__8u0__p6_1,
  130823. NULL,
  130824. 0
  130825. };
  130826. static long _vq_quantlist__8u0__p7_0[] = {
  130827. 1,
  130828. 0,
  130829. 2,
  130830. };
  130831. static long _vq_lengthlist__8u0__p7_0[] = {
  130832. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130833. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130834. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130835. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130836. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130837. 7,
  130838. };
  130839. static float _vq_quantthresh__8u0__p7_0[] = {
  130840. -157.5, 157.5,
  130841. };
  130842. static long _vq_quantmap__8u0__p7_0[] = {
  130843. 1, 0, 2,
  130844. };
  130845. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130846. _vq_quantthresh__8u0__p7_0,
  130847. _vq_quantmap__8u0__p7_0,
  130848. 3,
  130849. 3
  130850. };
  130851. static static_codebook _8u0__p7_0 = {
  130852. 4, 81,
  130853. _vq_lengthlist__8u0__p7_0,
  130854. 1, -518803456, 1628680192, 2, 0,
  130855. _vq_quantlist__8u0__p7_0,
  130856. NULL,
  130857. &_vq_auxt__8u0__p7_0,
  130858. NULL,
  130859. 0
  130860. };
  130861. static long _vq_quantlist__8u0__p7_1[] = {
  130862. 7,
  130863. 6,
  130864. 8,
  130865. 5,
  130866. 9,
  130867. 4,
  130868. 10,
  130869. 3,
  130870. 11,
  130871. 2,
  130872. 12,
  130873. 1,
  130874. 13,
  130875. 0,
  130876. 14,
  130877. };
  130878. static long _vq_lengthlist__8u0__p7_1[] = {
  130879. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130880. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130881. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130882. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130883. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130884. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130885. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130886. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130887. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130888. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130889. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130890. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130891. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130892. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130893. 10,
  130894. };
  130895. static float _vq_quantthresh__8u0__p7_1[] = {
  130896. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130897. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130898. };
  130899. static long _vq_quantmap__8u0__p7_1[] = {
  130900. 13, 11, 9, 7, 5, 3, 1, 0,
  130901. 2, 4, 6, 8, 10, 12, 14,
  130902. };
  130903. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130904. _vq_quantthresh__8u0__p7_1,
  130905. _vq_quantmap__8u0__p7_1,
  130906. 15,
  130907. 15
  130908. };
  130909. static static_codebook _8u0__p7_1 = {
  130910. 2, 225,
  130911. _vq_lengthlist__8u0__p7_1,
  130912. 1, -520986624, 1620377600, 4, 0,
  130913. _vq_quantlist__8u0__p7_1,
  130914. NULL,
  130915. &_vq_auxt__8u0__p7_1,
  130916. NULL,
  130917. 0
  130918. };
  130919. static long _vq_quantlist__8u0__p7_2[] = {
  130920. 10,
  130921. 9,
  130922. 11,
  130923. 8,
  130924. 12,
  130925. 7,
  130926. 13,
  130927. 6,
  130928. 14,
  130929. 5,
  130930. 15,
  130931. 4,
  130932. 16,
  130933. 3,
  130934. 17,
  130935. 2,
  130936. 18,
  130937. 1,
  130938. 19,
  130939. 0,
  130940. 20,
  130941. };
  130942. static long _vq_lengthlist__8u0__p7_2[] = {
  130943. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  130944. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  130945. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  130946. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  130947. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  130948. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  130949. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  130950. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  130951. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  130952. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  130953. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  130954. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  130955. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  130956. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  130957. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  130958. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  130959. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  130960. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  130961. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  130962. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  130963. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  130964. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  130965. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  130966. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  130967. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  130968. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  130969. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  130970. 11,12,11,11,11,10,10,11,11,
  130971. };
  130972. static float _vq_quantthresh__8u0__p7_2[] = {
  130973. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130974. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130975. 6.5, 7.5, 8.5, 9.5,
  130976. };
  130977. static long _vq_quantmap__8u0__p7_2[] = {
  130978. 19, 17, 15, 13, 11, 9, 7, 5,
  130979. 3, 1, 0, 2, 4, 6, 8, 10,
  130980. 12, 14, 16, 18, 20,
  130981. };
  130982. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  130983. _vq_quantthresh__8u0__p7_2,
  130984. _vq_quantmap__8u0__p7_2,
  130985. 21,
  130986. 21
  130987. };
  130988. static static_codebook _8u0__p7_2 = {
  130989. 2, 441,
  130990. _vq_lengthlist__8u0__p7_2,
  130991. 1, -529268736, 1611661312, 5, 0,
  130992. _vq_quantlist__8u0__p7_2,
  130993. NULL,
  130994. &_vq_auxt__8u0__p7_2,
  130995. NULL,
  130996. 0
  130997. };
  130998. static long _huff_lengthlist__8u0__single[] = {
  130999. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  131000. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  131001. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  131002. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  131003. };
  131004. static static_codebook _huff_book__8u0__single = {
  131005. 2, 64,
  131006. _huff_lengthlist__8u0__single,
  131007. 0, 0, 0, 0, 0,
  131008. NULL,
  131009. NULL,
  131010. NULL,
  131011. NULL,
  131012. 0
  131013. };
  131014. static long _vq_quantlist__8u1__p1_0[] = {
  131015. 1,
  131016. 0,
  131017. 2,
  131018. };
  131019. static long _vq_lengthlist__8u1__p1_0[] = {
  131020. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  131021. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  131022. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  131023. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  131024. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131025. 10,
  131026. };
  131027. static float _vq_quantthresh__8u1__p1_0[] = {
  131028. -0.5, 0.5,
  131029. };
  131030. static long _vq_quantmap__8u1__p1_0[] = {
  131031. 1, 0, 2,
  131032. };
  131033. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131034. _vq_quantthresh__8u1__p1_0,
  131035. _vq_quantmap__8u1__p1_0,
  131036. 3,
  131037. 3
  131038. };
  131039. static static_codebook _8u1__p1_0 = {
  131040. 4, 81,
  131041. _vq_lengthlist__8u1__p1_0,
  131042. 1, -535822336, 1611661312, 2, 0,
  131043. _vq_quantlist__8u1__p1_0,
  131044. NULL,
  131045. &_vq_auxt__8u1__p1_0,
  131046. NULL,
  131047. 0
  131048. };
  131049. static long _vq_quantlist__8u1__p2_0[] = {
  131050. 1,
  131051. 0,
  131052. 2,
  131053. };
  131054. static long _vq_lengthlist__8u1__p2_0[] = {
  131055. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131056. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131057. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131058. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131059. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131060. 7,
  131061. };
  131062. static float _vq_quantthresh__8u1__p2_0[] = {
  131063. -0.5, 0.5,
  131064. };
  131065. static long _vq_quantmap__8u1__p2_0[] = {
  131066. 1, 0, 2,
  131067. };
  131068. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131069. _vq_quantthresh__8u1__p2_0,
  131070. _vq_quantmap__8u1__p2_0,
  131071. 3,
  131072. 3
  131073. };
  131074. static static_codebook _8u1__p2_0 = {
  131075. 4, 81,
  131076. _vq_lengthlist__8u1__p2_0,
  131077. 1, -535822336, 1611661312, 2, 0,
  131078. _vq_quantlist__8u1__p2_0,
  131079. NULL,
  131080. &_vq_auxt__8u1__p2_0,
  131081. NULL,
  131082. 0
  131083. };
  131084. static long _vq_quantlist__8u1__p3_0[] = {
  131085. 2,
  131086. 1,
  131087. 3,
  131088. 0,
  131089. 4,
  131090. };
  131091. static long _vq_lengthlist__8u1__p3_0[] = {
  131092. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131093. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131094. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131095. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131096. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131097. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131098. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131099. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131100. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131101. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131102. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131103. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131104. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131105. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131106. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131107. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131108. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131109. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131110. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131111. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131112. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131113. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131114. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131115. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131116. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131117. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131118. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131119. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131120. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131121. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131122. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131123. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131124. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131125. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131126. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131127. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131128. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131129. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131130. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131131. 16,
  131132. };
  131133. static float _vq_quantthresh__8u1__p3_0[] = {
  131134. -1.5, -0.5, 0.5, 1.5,
  131135. };
  131136. static long _vq_quantmap__8u1__p3_0[] = {
  131137. 3, 1, 0, 2, 4,
  131138. };
  131139. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131140. _vq_quantthresh__8u1__p3_0,
  131141. _vq_quantmap__8u1__p3_0,
  131142. 5,
  131143. 5
  131144. };
  131145. static static_codebook _8u1__p3_0 = {
  131146. 4, 625,
  131147. _vq_lengthlist__8u1__p3_0,
  131148. 1, -533725184, 1611661312, 3, 0,
  131149. _vq_quantlist__8u1__p3_0,
  131150. NULL,
  131151. &_vq_auxt__8u1__p3_0,
  131152. NULL,
  131153. 0
  131154. };
  131155. static long _vq_quantlist__8u1__p4_0[] = {
  131156. 2,
  131157. 1,
  131158. 3,
  131159. 0,
  131160. 4,
  131161. };
  131162. static long _vq_lengthlist__8u1__p4_0[] = {
  131163. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131164. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131165. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131166. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131167. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131168. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131169. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131170. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131171. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131172. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131173. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131174. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131175. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131176. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131177. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131178. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131179. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131180. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131181. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131182. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131183. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131184. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131185. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131186. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131187. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131188. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131189. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131190. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131191. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131192. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131193. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131194. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131195. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131196. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131197. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131198. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131199. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131200. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131201. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131202. 10,
  131203. };
  131204. static float _vq_quantthresh__8u1__p4_0[] = {
  131205. -1.5, -0.5, 0.5, 1.5,
  131206. };
  131207. static long _vq_quantmap__8u1__p4_0[] = {
  131208. 3, 1, 0, 2, 4,
  131209. };
  131210. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131211. _vq_quantthresh__8u1__p4_0,
  131212. _vq_quantmap__8u1__p4_0,
  131213. 5,
  131214. 5
  131215. };
  131216. static static_codebook _8u1__p4_0 = {
  131217. 4, 625,
  131218. _vq_lengthlist__8u1__p4_0,
  131219. 1, -533725184, 1611661312, 3, 0,
  131220. _vq_quantlist__8u1__p4_0,
  131221. NULL,
  131222. &_vq_auxt__8u1__p4_0,
  131223. NULL,
  131224. 0
  131225. };
  131226. static long _vq_quantlist__8u1__p5_0[] = {
  131227. 4,
  131228. 3,
  131229. 5,
  131230. 2,
  131231. 6,
  131232. 1,
  131233. 7,
  131234. 0,
  131235. 8,
  131236. };
  131237. static long _vq_lengthlist__8u1__p5_0[] = {
  131238. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131239. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131240. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131241. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131242. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131243. 13,
  131244. };
  131245. static float _vq_quantthresh__8u1__p5_0[] = {
  131246. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131247. };
  131248. static long _vq_quantmap__8u1__p5_0[] = {
  131249. 7, 5, 3, 1, 0, 2, 4, 6,
  131250. 8,
  131251. };
  131252. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131253. _vq_quantthresh__8u1__p5_0,
  131254. _vq_quantmap__8u1__p5_0,
  131255. 9,
  131256. 9
  131257. };
  131258. static static_codebook _8u1__p5_0 = {
  131259. 2, 81,
  131260. _vq_lengthlist__8u1__p5_0,
  131261. 1, -531628032, 1611661312, 4, 0,
  131262. _vq_quantlist__8u1__p5_0,
  131263. NULL,
  131264. &_vq_auxt__8u1__p5_0,
  131265. NULL,
  131266. 0
  131267. };
  131268. static long _vq_quantlist__8u1__p6_0[] = {
  131269. 4,
  131270. 3,
  131271. 5,
  131272. 2,
  131273. 6,
  131274. 1,
  131275. 7,
  131276. 0,
  131277. 8,
  131278. };
  131279. static long _vq_lengthlist__8u1__p6_0[] = {
  131280. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131281. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131282. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131283. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131284. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131285. 10,
  131286. };
  131287. static float _vq_quantthresh__8u1__p6_0[] = {
  131288. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131289. };
  131290. static long _vq_quantmap__8u1__p6_0[] = {
  131291. 7, 5, 3, 1, 0, 2, 4, 6,
  131292. 8,
  131293. };
  131294. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131295. _vq_quantthresh__8u1__p6_0,
  131296. _vq_quantmap__8u1__p6_0,
  131297. 9,
  131298. 9
  131299. };
  131300. static static_codebook _8u1__p6_0 = {
  131301. 2, 81,
  131302. _vq_lengthlist__8u1__p6_0,
  131303. 1, -531628032, 1611661312, 4, 0,
  131304. _vq_quantlist__8u1__p6_0,
  131305. NULL,
  131306. &_vq_auxt__8u1__p6_0,
  131307. NULL,
  131308. 0
  131309. };
  131310. static long _vq_quantlist__8u1__p7_0[] = {
  131311. 1,
  131312. 0,
  131313. 2,
  131314. };
  131315. static long _vq_lengthlist__8u1__p7_0[] = {
  131316. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131317. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131318. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131319. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131320. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131321. 11,
  131322. };
  131323. static float _vq_quantthresh__8u1__p7_0[] = {
  131324. -5.5, 5.5,
  131325. };
  131326. static long _vq_quantmap__8u1__p7_0[] = {
  131327. 1, 0, 2,
  131328. };
  131329. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131330. _vq_quantthresh__8u1__p7_0,
  131331. _vq_quantmap__8u1__p7_0,
  131332. 3,
  131333. 3
  131334. };
  131335. static static_codebook _8u1__p7_0 = {
  131336. 4, 81,
  131337. _vq_lengthlist__8u1__p7_0,
  131338. 1, -529137664, 1618345984, 2, 0,
  131339. _vq_quantlist__8u1__p7_0,
  131340. NULL,
  131341. &_vq_auxt__8u1__p7_0,
  131342. NULL,
  131343. 0
  131344. };
  131345. static long _vq_quantlist__8u1__p7_1[] = {
  131346. 5,
  131347. 4,
  131348. 6,
  131349. 3,
  131350. 7,
  131351. 2,
  131352. 8,
  131353. 1,
  131354. 9,
  131355. 0,
  131356. 10,
  131357. };
  131358. static long _vq_lengthlist__8u1__p7_1[] = {
  131359. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131360. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131361. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131362. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131363. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131364. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131365. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131366. 9, 9, 9, 9, 9,10,10,10,10,
  131367. };
  131368. static float _vq_quantthresh__8u1__p7_1[] = {
  131369. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131370. 3.5, 4.5,
  131371. };
  131372. static long _vq_quantmap__8u1__p7_1[] = {
  131373. 9, 7, 5, 3, 1, 0, 2, 4,
  131374. 6, 8, 10,
  131375. };
  131376. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131377. _vq_quantthresh__8u1__p7_1,
  131378. _vq_quantmap__8u1__p7_1,
  131379. 11,
  131380. 11
  131381. };
  131382. static static_codebook _8u1__p7_1 = {
  131383. 2, 121,
  131384. _vq_lengthlist__8u1__p7_1,
  131385. 1, -531365888, 1611661312, 4, 0,
  131386. _vq_quantlist__8u1__p7_1,
  131387. NULL,
  131388. &_vq_auxt__8u1__p7_1,
  131389. NULL,
  131390. 0
  131391. };
  131392. static long _vq_quantlist__8u1__p8_0[] = {
  131393. 5,
  131394. 4,
  131395. 6,
  131396. 3,
  131397. 7,
  131398. 2,
  131399. 8,
  131400. 1,
  131401. 9,
  131402. 0,
  131403. 10,
  131404. };
  131405. static long _vq_lengthlist__8u1__p8_0[] = {
  131406. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131407. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131408. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131409. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131410. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131411. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131412. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131413. 12,13,13,14,14,15,15,15,15,
  131414. };
  131415. static float _vq_quantthresh__8u1__p8_0[] = {
  131416. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131417. 38.5, 49.5,
  131418. };
  131419. static long _vq_quantmap__8u1__p8_0[] = {
  131420. 9, 7, 5, 3, 1, 0, 2, 4,
  131421. 6, 8, 10,
  131422. };
  131423. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131424. _vq_quantthresh__8u1__p8_0,
  131425. _vq_quantmap__8u1__p8_0,
  131426. 11,
  131427. 11
  131428. };
  131429. static static_codebook _8u1__p8_0 = {
  131430. 2, 121,
  131431. _vq_lengthlist__8u1__p8_0,
  131432. 1, -524582912, 1618345984, 4, 0,
  131433. _vq_quantlist__8u1__p8_0,
  131434. NULL,
  131435. &_vq_auxt__8u1__p8_0,
  131436. NULL,
  131437. 0
  131438. };
  131439. static long _vq_quantlist__8u1__p8_1[] = {
  131440. 5,
  131441. 4,
  131442. 6,
  131443. 3,
  131444. 7,
  131445. 2,
  131446. 8,
  131447. 1,
  131448. 9,
  131449. 0,
  131450. 10,
  131451. };
  131452. static long _vq_lengthlist__8u1__p8_1[] = {
  131453. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131454. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131455. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131456. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131457. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131458. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131459. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131460. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131461. };
  131462. static float _vq_quantthresh__8u1__p8_1[] = {
  131463. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131464. 3.5, 4.5,
  131465. };
  131466. static long _vq_quantmap__8u1__p8_1[] = {
  131467. 9, 7, 5, 3, 1, 0, 2, 4,
  131468. 6, 8, 10,
  131469. };
  131470. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131471. _vq_quantthresh__8u1__p8_1,
  131472. _vq_quantmap__8u1__p8_1,
  131473. 11,
  131474. 11
  131475. };
  131476. static static_codebook _8u1__p8_1 = {
  131477. 2, 121,
  131478. _vq_lengthlist__8u1__p8_1,
  131479. 1, -531365888, 1611661312, 4, 0,
  131480. _vq_quantlist__8u1__p8_1,
  131481. NULL,
  131482. &_vq_auxt__8u1__p8_1,
  131483. NULL,
  131484. 0
  131485. };
  131486. static long _vq_quantlist__8u1__p9_0[] = {
  131487. 7,
  131488. 6,
  131489. 8,
  131490. 5,
  131491. 9,
  131492. 4,
  131493. 10,
  131494. 3,
  131495. 11,
  131496. 2,
  131497. 12,
  131498. 1,
  131499. 13,
  131500. 0,
  131501. 14,
  131502. };
  131503. static long _vq_lengthlist__8u1__p9_0[] = {
  131504. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131505. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131506. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131507. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131508. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131509. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131510. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131511. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131512. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131513. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131514. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131515. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131516. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131517. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131518. 10,
  131519. };
  131520. static float _vq_quantthresh__8u1__p9_0[] = {
  131521. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131522. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131523. };
  131524. static long _vq_quantmap__8u1__p9_0[] = {
  131525. 13, 11, 9, 7, 5, 3, 1, 0,
  131526. 2, 4, 6, 8, 10, 12, 14,
  131527. };
  131528. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131529. _vq_quantthresh__8u1__p9_0,
  131530. _vq_quantmap__8u1__p9_0,
  131531. 15,
  131532. 15
  131533. };
  131534. static static_codebook _8u1__p9_0 = {
  131535. 2, 225,
  131536. _vq_lengthlist__8u1__p9_0,
  131537. 1, -514071552, 1627381760, 4, 0,
  131538. _vq_quantlist__8u1__p9_0,
  131539. NULL,
  131540. &_vq_auxt__8u1__p9_0,
  131541. NULL,
  131542. 0
  131543. };
  131544. static long _vq_quantlist__8u1__p9_1[] = {
  131545. 7,
  131546. 6,
  131547. 8,
  131548. 5,
  131549. 9,
  131550. 4,
  131551. 10,
  131552. 3,
  131553. 11,
  131554. 2,
  131555. 12,
  131556. 1,
  131557. 13,
  131558. 0,
  131559. 14,
  131560. };
  131561. static long _vq_lengthlist__8u1__p9_1[] = {
  131562. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131563. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131564. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131565. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131566. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131567. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131568. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131569. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131570. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131571. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131572. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131573. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131574. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131575. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131576. 13,
  131577. };
  131578. static float _vq_quantthresh__8u1__p9_1[] = {
  131579. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131580. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131581. };
  131582. static long _vq_quantmap__8u1__p9_1[] = {
  131583. 13, 11, 9, 7, 5, 3, 1, 0,
  131584. 2, 4, 6, 8, 10, 12, 14,
  131585. };
  131586. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131587. _vq_quantthresh__8u1__p9_1,
  131588. _vq_quantmap__8u1__p9_1,
  131589. 15,
  131590. 15
  131591. };
  131592. static static_codebook _8u1__p9_1 = {
  131593. 2, 225,
  131594. _vq_lengthlist__8u1__p9_1,
  131595. 1, -522338304, 1620115456, 4, 0,
  131596. _vq_quantlist__8u1__p9_1,
  131597. NULL,
  131598. &_vq_auxt__8u1__p9_1,
  131599. NULL,
  131600. 0
  131601. };
  131602. static long _vq_quantlist__8u1__p9_2[] = {
  131603. 8,
  131604. 7,
  131605. 9,
  131606. 6,
  131607. 10,
  131608. 5,
  131609. 11,
  131610. 4,
  131611. 12,
  131612. 3,
  131613. 13,
  131614. 2,
  131615. 14,
  131616. 1,
  131617. 15,
  131618. 0,
  131619. 16,
  131620. };
  131621. static long _vq_lengthlist__8u1__p9_2[] = {
  131622. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131623. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131624. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131625. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131626. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131627. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131628. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131629. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131630. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131631. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131632. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131633. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131634. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131635. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131636. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131637. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131638. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131639. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131640. 10,
  131641. };
  131642. static float _vq_quantthresh__8u1__p9_2[] = {
  131643. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131644. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131645. };
  131646. static long _vq_quantmap__8u1__p9_2[] = {
  131647. 15, 13, 11, 9, 7, 5, 3, 1,
  131648. 0, 2, 4, 6, 8, 10, 12, 14,
  131649. 16,
  131650. };
  131651. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131652. _vq_quantthresh__8u1__p9_2,
  131653. _vq_quantmap__8u1__p9_2,
  131654. 17,
  131655. 17
  131656. };
  131657. static static_codebook _8u1__p9_2 = {
  131658. 2, 289,
  131659. _vq_lengthlist__8u1__p9_2,
  131660. 1, -529530880, 1611661312, 5, 0,
  131661. _vq_quantlist__8u1__p9_2,
  131662. NULL,
  131663. &_vq_auxt__8u1__p9_2,
  131664. NULL,
  131665. 0
  131666. };
  131667. static long _huff_lengthlist__8u1__single[] = {
  131668. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131669. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131670. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131671. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131672. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131673. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131674. 13, 8, 8,15,
  131675. };
  131676. static static_codebook _huff_book__8u1__single = {
  131677. 2, 100,
  131678. _huff_lengthlist__8u1__single,
  131679. 0, 0, 0, 0, 0,
  131680. NULL,
  131681. NULL,
  131682. NULL,
  131683. NULL,
  131684. 0
  131685. };
  131686. static long _huff_lengthlist__44u0__long[] = {
  131687. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131688. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131689. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131690. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131691. };
  131692. static static_codebook _huff_book__44u0__long = {
  131693. 2, 64,
  131694. _huff_lengthlist__44u0__long,
  131695. 0, 0, 0, 0, 0,
  131696. NULL,
  131697. NULL,
  131698. NULL,
  131699. NULL,
  131700. 0
  131701. };
  131702. static long _vq_quantlist__44u0__p1_0[] = {
  131703. 1,
  131704. 0,
  131705. 2,
  131706. };
  131707. static long _vq_lengthlist__44u0__p1_0[] = {
  131708. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131709. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131710. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131711. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131712. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131713. 13,
  131714. };
  131715. static float _vq_quantthresh__44u0__p1_0[] = {
  131716. -0.5, 0.5,
  131717. };
  131718. static long _vq_quantmap__44u0__p1_0[] = {
  131719. 1, 0, 2,
  131720. };
  131721. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131722. _vq_quantthresh__44u0__p1_0,
  131723. _vq_quantmap__44u0__p1_0,
  131724. 3,
  131725. 3
  131726. };
  131727. static static_codebook _44u0__p1_0 = {
  131728. 4, 81,
  131729. _vq_lengthlist__44u0__p1_0,
  131730. 1, -535822336, 1611661312, 2, 0,
  131731. _vq_quantlist__44u0__p1_0,
  131732. NULL,
  131733. &_vq_auxt__44u0__p1_0,
  131734. NULL,
  131735. 0
  131736. };
  131737. static long _vq_quantlist__44u0__p2_0[] = {
  131738. 1,
  131739. 0,
  131740. 2,
  131741. };
  131742. static long _vq_lengthlist__44u0__p2_0[] = {
  131743. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131744. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131745. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131746. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131747. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131748. 9,
  131749. };
  131750. static float _vq_quantthresh__44u0__p2_0[] = {
  131751. -0.5, 0.5,
  131752. };
  131753. static long _vq_quantmap__44u0__p2_0[] = {
  131754. 1, 0, 2,
  131755. };
  131756. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131757. _vq_quantthresh__44u0__p2_0,
  131758. _vq_quantmap__44u0__p2_0,
  131759. 3,
  131760. 3
  131761. };
  131762. static static_codebook _44u0__p2_0 = {
  131763. 4, 81,
  131764. _vq_lengthlist__44u0__p2_0,
  131765. 1, -535822336, 1611661312, 2, 0,
  131766. _vq_quantlist__44u0__p2_0,
  131767. NULL,
  131768. &_vq_auxt__44u0__p2_0,
  131769. NULL,
  131770. 0
  131771. };
  131772. static long _vq_quantlist__44u0__p3_0[] = {
  131773. 2,
  131774. 1,
  131775. 3,
  131776. 0,
  131777. 4,
  131778. };
  131779. static long _vq_lengthlist__44u0__p3_0[] = {
  131780. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131781. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131782. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131783. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131784. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131785. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131786. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131787. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131788. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131789. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131790. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131791. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131792. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131793. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131794. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131795. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131796. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131797. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131798. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131799. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131800. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131801. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131802. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131803. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131804. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131805. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131806. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131807. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131808. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131809. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131810. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131811. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131812. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131813. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131814. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131815. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131816. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131817. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131818. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131819. 19,
  131820. };
  131821. static float _vq_quantthresh__44u0__p3_0[] = {
  131822. -1.5, -0.5, 0.5, 1.5,
  131823. };
  131824. static long _vq_quantmap__44u0__p3_0[] = {
  131825. 3, 1, 0, 2, 4,
  131826. };
  131827. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131828. _vq_quantthresh__44u0__p3_0,
  131829. _vq_quantmap__44u0__p3_0,
  131830. 5,
  131831. 5
  131832. };
  131833. static static_codebook _44u0__p3_0 = {
  131834. 4, 625,
  131835. _vq_lengthlist__44u0__p3_0,
  131836. 1, -533725184, 1611661312, 3, 0,
  131837. _vq_quantlist__44u0__p3_0,
  131838. NULL,
  131839. &_vq_auxt__44u0__p3_0,
  131840. NULL,
  131841. 0
  131842. };
  131843. static long _vq_quantlist__44u0__p4_0[] = {
  131844. 2,
  131845. 1,
  131846. 3,
  131847. 0,
  131848. 4,
  131849. };
  131850. static long _vq_lengthlist__44u0__p4_0[] = {
  131851. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131852. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131853. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131854. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131855. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131856. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131857. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131858. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131859. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131860. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131861. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131862. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131863. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131864. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131865. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131866. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131867. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131868. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131869. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131870. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131871. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131872. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131873. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131874. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131875. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131876. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131877. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131878. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131879. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131880. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131881. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131882. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131883. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131884. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131885. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131886. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131887. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131888. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131889. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131890. 12,
  131891. };
  131892. static float _vq_quantthresh__44u0__p4_0[] = {
  131893. -1.5, -0.5, 0.5, 1.5,
  131894. };
  131895. static long _vq_quantmap__44u0__p4_0[] = {
  131896. 3, 1, 0, 2, 4,
  131897. };
  131898. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131899. _vq_quantthresh__44u0__p4_0,
  131900. _vq_quantmap__44u0__p4_0,
  131901. 5,
  131902. 5
  131903. };
  131904. static static_codebook _44u0__p4_0 = {
  131905. 4, 625,
  131906. _vq_lengthlist__44u0__p4_0,
  131907. 1, -533725184, 1611661312, 3, 0,
  131908. _vq_quantlist__44u0__p4_0,
  131909. NULL,
  131910. &_vq_auxt__44u0__p4_0,
  131911. NULL,
  131912. 0
  131913. };
  131914. static long _vq_quantlist__44u0__p5_0[] = {
  131915. 4,
  131916. 3,
  131917. 5,
  131918. 2,
  131919. 6,
  131920. 1,
  131921. 7,
  131922. 0,
  131923. 8,
  131924. };
  131925. static long _vq_lengthlist__44u0__p5_0[] = {
  131926. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131927. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131928. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131929. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131930. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131931. 12,
  131932. };
  131933. static float _vq_quantthresh__44u0__p5_0[] = {
  131934. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131935. };
  131936. static long _vq_quantmap__44u0__p5_0[] = {
  131937. 7, 5, 3, 1, 0, 2, 4, 6,
  131938. 8,
  131939. };
  131940. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  131941. _vq_quantthresh__44u0__p5_0,
  131942. _vq_quantmap__44u0__p5_0,
  131943. 9,
  131944. 9
  131945. };
  131946. static static_codebook _44u0__p5_0 = {
  131947. 2, 81,
  131948. _vq_lengthlist__44u0__p5_0,
  131949. 1, -531628032, 1611661312, 4, 0,
  131950. _vq_quantlist__44u0__p5_0,
  131951. NULL,
  131952. &_vq_auxt__44u0__p5_0,
  131953. NULL,
  131954. 0
  131955. };
  131956. static long _vq_quantlist__44u0__p6_0[] = {
  131957. 6,
  131958. 5,
  131959. 7,
  131960. 4,
  131961. 8,
  131962. 3,
  131963. 9,
  131964. 2,
  131965. 10,
  131966. 1,
  131967. 11,
  131968. 0,
  131969. 12,
  131970. };
  131971. static long _vq_lengthlist__44u0__p6_0[] = {
  131972. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  131973. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  131974. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  131975. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  131976. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  131977. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  131978. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  131979. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  131980. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  131981. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  131982. 15,17,16,17,18,17,17,18, 0,
  131983. };
  131984. static float _vq_quantthresh__44u0__p6_0[] = {
  131985. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131986. 12.5, 17.5, 22.5, 27.5,
  131987. };
  131988. static long _vq_quantmap__44u0__p6_0[] = {
  131989. 11, 9, 7, 5, 3, 1, 0, 2,
  131990. 4, 6, 8, 10, 12,
  131991. };
  131992. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  131993. _vq_quantthresh__44u0__p6_0,
  131994. _vq_quantmap__44u0__p6_0,
  131995. 13,
  131996. 13
  131997. };
  131998. static static_codebook _44u0__p6_0 = {
  131999. 2, 169,
  132000. _vq_lengthlist__44u0__p6_0,
  132001. 1, -526516224, 1616117760, 4, 0,
  132002. _vq_quantlist__44u0__p6_0,
  132003. NULL,
  132004. &_vq_auxt__44u0__p6_0,
  132005. NULL,
  132006. 0
  132007. };
  132008. static long _vq_quantlist__44u0__p6_1[] = {
  132009. 2,
  132010. 1,
  132011. 3,
  132012. 0,
  132013. 4,
  132014. };
  132015. static long _vq_lengthlist__44u0__p6_1[] = {
  132016. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132017. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132018. };
  132019. static float _vq_quantthresh__44u0__p6_1[] = {
  132020. -1.5, -0.5, 0.5, 1.5,
  132021. };
  132022. static long _vq_quantmap__44u0__p6_1[] = {
  132023. 3, 1, 0, 2, 4,
  132024. };
  132025. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132026. _vq_quantthresh__44u0__p6_1,
  132027. _vq_quantmap__44u0__p6_1,
  132028. 5,
  132029. 5
  132030. };
  132031. static static_codebook _44u0__p6_1 = {
  132032. 2, 25,
  132033. _vq_lengthlist__44u0__p6_1,
  132034. 1, -533725184, 1611661312, 3, 0,
  132035. _vq_quantlist__44u0__p6_1,
  132036. NULL,
  132037. &_vq_auxt__44u0__p6_1,
  132038. NULL,
  132039. 0
  132040. };
  132041. static long _vq_quantlist__44u0__p7_0[] = {
  132042. 2,
  132043. 1,
  132044. 3,
  132045. 0,
  132046. 4,
  132047. };
  132048. static long _vq_lengthlist__44u0__p7_0[] = {
  132049. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132050. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132051. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132052. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132053. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132054. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132055. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132056. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132057. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132058. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132059. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132060. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132061. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132062. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132063. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132064. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132065. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132066. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132067. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132068. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132069. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132070. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132071. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132072. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132073. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132074. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132075. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132076. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132077. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132078. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132079. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  132080. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132081. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132082. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132083. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132084. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132085. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132086. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132087. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132088. 10,
  132089. };
  132090. static float _vq_quantthresh__44u0__p7_0[] = {
  132091. -253.5, -84.5, 84.5, 253.5,
  132092. };
  132093. static long _vq_quantmap__44u0__p7_0[] = {
  132094. 3, 1, 0, 2, 4,
  132095. };
  132096. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132097. _vq_quantthresh__44u0__p7_0,
  132098. _vq_quantmap__44u0__p7_0,
  132099. 5,
  132100. 5
  132101. };
  132102. static static_codebook _44u0__p7_0 = {
  132103. 4, 625,
  132104. _vq_lengthlist__44u0__p7_0,
  132105. 1, -518709248, 1626677248, 3, 0,
  132106. _vq_quantlist__44u0__p7_0,
  132107. NULL,
  132108. &_vq_auxt__44u0__p7_0,
  132109. NULL,
  132110. 0
  132111. };
  132112. static long _vq_quantlist__44u0__p7_1[] = {
  132113. 6,
  132114. 5,
  132115. 7,
  132116. 4,
  132117. 8,
  132118. 3,
  132119. 9,
  132120. 2,
  132121. 10,
  132122. 1,
  132123. 11,
  132124. 0,
  132125. 12,
  132126. };
  132127. static long _vq_lengthlist__44u0__p7_1[] = {
  132128. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132129. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132130. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132131. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132132. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132133. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132134. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132135. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132136. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132137. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132138. 15,15,15,15,15,15,15,15,15,
  132139. };
  132140. static float _vq_quantthresh__44u0__p7_1[] = {
  132141. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132142. 32.5, 45.5, 58.5, 71.5,
  132143. };
  132144. static long _vq_quantmap__44u0__p7_1[] = {
  132145. 11, 9, 7, 5, 3, 1, 0, 2,
  132146. 4, 6, 8, 10, 12,
  132147. };
  132148. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132149. _vq_quantthresh__44u0__p7_1,
  132150. _vq_quantmap__44u0__p7_1,
  132151. 13,
  132152. 13
  132153. };
  132154. static static_codebook _44u0__p7_1 = {
  132155. 2, 169,
  132156. _vq_lengthlist__44u0__p7_1,
  132157. 1, -523010048, 1618608128, 4, 0,
  132158. _vq_quantlist__44u0__p7_1,
  132159. NULL,
  132160. &_vq_auxt__44u0__p7_1,
  132161. NULL,
  132162. 0
  132163. };
  132164. static long _vq_quantlist__44u0__p7_2[] = {
  132165. 6,
  132166. 5,
  132167. 7,
  132168. 4,
  132169. 8,
  132170. 3,
  132171. 9,
  132172. 2,
  132173. 10,
  132174. 1,
  132175. 11,
  132176. 0,
  132177. 12,
  132178. };
  132179. static long _vq_lengthlist__44u0__p7_2[] = {
  132180. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132181. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132182. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132183. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132184. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132185. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132186. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132187. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132188. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132189. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132190. 9, 9, 9,10, 9, 9,10,10, 9,
  132191. };
  132192. static float _vq_quantthresh__44u0__p7_2[] = {
  132193. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132194. 2.5, 3.5, 4.5, 5.5,
  132195. };
  132196. static long _vq_quantmap__44u0__p7_2[] = {
  132197. 11, 9, 7, 5, 3, 1, 0, 2,
  132198. 4, 6, 8, 10, 12,
  132199. };
  132200. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132201. _vq_quantthresh__44u0__p7_2,
  132202. _vq_quantmap__44u0__p7_2,
  132203. 13,
  132204. 13
  132205. };
  132206. static static_codebook _44u0__p7_2 = {
  132207. 2, 169,
  132208. _vq_lengthlist__44u0__p7_2,
  132209. 1, -531103744, 1611661312, 4, 0,
  132210. _vq_quantlist__44u0__p7_2,
  132211. NULL,
  132212. &_vq_auxt__44u0__p7_2,
  132213. NULL,
  132214. 0
  132215. };
  132216. static long _huff_lengthlist__44u0__short[] = {
  132217. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132218. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132219. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132220. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132221. };
  132222. static static_codebook _huff_book__44u0__short = {
  132223. 2, 64,
  132224. _huff_lengthlist__44u0__short,
  132225. 0, 0, 0, 0, 0,
  132226. NULL,
  132227. NULL,
  132228. NULL,
  132229. NULL,
  132230. 0
  132231. };
  132232. static long _huff_lengthlist__44u1__long[] = {
  132233. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132234. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132235. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132236. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132237. };
  132238. static static_codebook _huff_book__44u1__long = {
  132239. 2, 64,
  132240. _huff_lengthlist__44u1__long,
  132241. 0, 0, 0, 0, 0,
  132242. NULL,
  132243. NULL,
  132244. NULL,
  132245. NULL,
  132246. 0
  132247. };
  132248. static long _vq_quantlist__44u1__p1_0[] = {
  132249. 1,
  132250. 0,
  132251. 2,
  132252. };
  132253. static long _vq_lengthlist__44u1__p1_0[] = {
  132254. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132255. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132256. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132257. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132258. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132259. 13,
  132260. };
  132261. static float _vq_quantthresh__44u1__p1_0[] = {
  132262. -0.5, 0.5,
  132263. };
  132264. static long _vq_quantmap__44u1__p1_0[] = {
  132265. 1, 0, 2,
  132266. };
  132267. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132268. _vq_quantthresh__44u1__p1_0,
  132269. _vq_quantmap__44u1__p1_0,
  132270. 3,
  132271. 3
  132272. };
  132273. static static_codebook _44u1__p1_0 = {
  132274. 4, 81,
  132275. _vq_lengthlist__44u1__p1_0,
  132276. 1, -535822336, 1611661312, 2, 0,
  132277. _vq_quantlist__44u1__p1_0,
  132278. NULL,
  132279. &_vq_auxt__44u1__p1_0,
  132280. NULL,
  132281. 0
  132282. };
  132283. static long _vq_quantlist__44u1__p2_0[] = {
  132284. 1,
  132285. 0,
  132286. 2,
  132287. };
  132288. static long _vq_lengthlist__44u1__p2_0[] = {
  132289. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132290. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132291. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132292. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132293. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132294. 9,
  132295. };
  132296. static float _vq_quantthresh__44u1__p2_0[] = {
  132297. -0.5, 0.5,
  132298. };
  132299. static long _vq_quantmap__44u1__p2_0[] = {
  132300. 1, 0, 2,
  132301. };
  132302. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132303. _vq_quantthresh__44u1__p2_0,
  132304. _vq_quantmap__44u1__p2_0,
  132305. 3,
  132306. 3
  132307. };
  132308. static static_codebook _44u1__p2_0 = {
  132309. 4, 81,
  132310. _vq_lengthlist__44u1__p2_0,
  132311. 1, -535822336, 1611661312, 2, 0,
  132312. _vq_quantlist__44u1__p2_0,
  132313. NULL,
  132314. &_vq_auxt__44u1__p2_0,
  132315. NULL,
  132316. 0
  132317. };
  132318. static long _vq_quantlist__44u1__p3_0[] = {
  132319. 2,
  132320. 1,
  132321. 3,
  132322. 0,
  132323. 4,
  132324. };
  132325. static long _vq_lengthlist__44u1__p3_0[] = {
  132326. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132327. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132328. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132329. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132330. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132331. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132332. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132333. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132334. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132335. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132336. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132337. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132338. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132339. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132340. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132341. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132342. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132343. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132344. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132345. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132346. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132347. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132348. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132349. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132350. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132351. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132352. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132353. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132354. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132355. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132356. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132357. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132358. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132359. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132360. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132361. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132362. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132363. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132364. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132365. 19,
  132366. };
  132367. static float _vq_quantthresh__44u1__p3_0[] = {
  132368. -1.5, -0.5, 0.5, 1.5,
  132369. };
  132370. static long _vq_quantmap__44u1__p3_0[] = {
  132371. 3, 1, 0, 2, 4,
  132372. };
  132373. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132374. _vq_quantthresh__44u1__p3_0,
  132375. _vq_quantmap__44u1__p3_0,
  132376. 5,
  132377. 5
  132378. };
  132379. static static_codebook _44u1__p3_0 = {
  132380. 4, 625,
  132381. _vq_lengthlist__44u1__p3_0,
  132382. 1, -533725184, 1611661312, 3, 0,
  132383. _vq_quantlist__44u1__p3_0,
  132384. NULL,
  132385. &_vq_auxt__44u1__p3_0,
  132386. NULL,
  132387. 0
  132388. };
  132389. static long _vq_quantlist__44u1__p4_0[] = {
  132390. 2,
  132391. 1,
  132392. 3,
  132393. 0,
  132394. 4,
  132395. };
  132396. static long _vq_lengthlist__44u1__p4_0[] = {
  132397. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132398. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132399. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132400. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132401. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132402. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132403. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132404. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132405. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132406. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132407. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132408. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132409. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132410. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132411. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132412. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132413. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132414. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132415. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132416. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132417. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132418. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132419. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132420. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132421. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132422. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132423. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132424. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132425. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132426. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132427. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132428. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132429. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132430. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132431. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132432. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132433. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132434. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132435. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132436. 12,
  132437. };
  132438. static float _vq_quantthresh__44u1__p4_0[] = {
  132439. -1.5, -0.5, 0.5, 1.5,
  132440. };
  132441. static long _vq_quantmap__44u1__p4_0[] = {
  132442. 3, 1, 0, 2, 4,
  132443. };
  132444. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132445. _vq_quantthresh__44u1__p4_0,
  132446. _vq_quantmap__44u1__p4_0,
  132447. 5,
  132448. 5
  132449. };
  132450. static static_codebook _44u1__p4_0 = {
  132451. 4, 625,
  132452. _vq_lengthlist__44u1__p4_0,
  132453. 1, -533725184, 1611661312, 3, 0,
  132454. _vq_quantlist__44u1__p4_0,
  132455. NULL,
  132456. &_vq_auxt__44u1__p4_0,
  132457. NULL,
  132458. 0
  132459. };
  132460. static long _vq_quantlist__44u1__p5_0[] = {
  132461. 4,
  132462. 3,
  132463. 5,
  132464. 2,
  132465. 6,
  132466. 1,
  132467. 7,
  132468. 0,
  132469. 8,
  132470. };
  132471. static long _vq_lengthlist__44u1__p5_0[] = {
  132472. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132473. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132474. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132475. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132476. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132477. 12,
  132478. };
  132479. static float _vq_quantthresh__44u1__p5_0[] = {
  132480. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132481. };
  132482. static long _vq_quantmap__44u1__p5_0[] = {
  132483. 7, 5, 3, 1, 0, 2, 4, 6,
  132484. 8,
  132485. };
  132486. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132487. _vq_quantthresh__44u1__p5_0,
  132488. _vq_quantmap__44u1__p5_0,
  132489. 9,
  132490. 9
  132491. };
  132492. static static_codebook _44u1__p5_0 = {
  132493. 2, 81,
  132494. _vq_lengthlist__44u1__p5_0,
  132495. 1, -531628032, 1611661312, 4, 0,
  132496. _vq_quantlist__44u1__p5_0,
  132497. NULL,
  132498. &_vq_auxt__44u1__p5_0,
  132499. NULL,
  132500. 0
  132501. };
  132502. static long _vq_quantlist__44u1__p6_0[] = {
  132503. 6,
  132504. 5,
  132505. 7,
  132506. 4,
  132507. 8,
  132508. 3,
  132509. 9,
  132510. 2,
  132511. 10,
  132512. 1,
  132513. 11,
  132514. 0,
  132515. 12,
  132516. };
  132517. static long _vq_lengthlist__44u1__p6_0[] = {
  132518. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132519. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132520. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132521. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132522. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132523. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132524. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132525. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132526. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132527. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132528. 15,17,16,17,18,17,17,18, 0,
  132529. };
  132530. static float _vq_quantthresh__44u1__p6_0[] = {
  132531. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132532. 12.5, 17.5, 22.5, 27.5,
  132533. };
  132534. static long _vq_quantmap__44u1__p6_0[] = {
  132535. 11, 9, 7, 5, 3, 1, 0, 2,
  132536. 4, 6, 8, 10, 12,
  132537. };
  132538. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132539. _vq_quantthresh__44u1__p6_0,
  132540. _vq_quantmap__44u1__p6_0,
  132541. 13,
  132542. 13
  132543. };
  132544. static static_codebook _44u1__p6_0 = {
  132545. 2, 169,
  132546. _vq_lengthlist__44u1__p6_0,
  132547. 1, -526516224, 1616117760, 4, 0,
  132548. _vq_quantlist__44u1__p6_0,
  132549. NULL,
  132550. &_vq_auxt__44u1__p6_0,
  132551. NULL,
  132552. 0
  132553. };
  132554. static long _vq_quantlist__44u1__p6_1[] = {
  132555. 2,
  132556. 1,
  132557. 3,
  132558. 0,
  132559. 4,
  132560. };
  132561. static long _vq_lengthlist__44u1__p6_1[] = {
  132562. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132563. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132564. };
  132565. static float _vq_quantthresh__44u1__p6_1[] = {
  132566. -1.5, -0.5, 0.5, 1.5,
  132567. };
  132568. static long _vq_quantmap__44u1__p6_1[] = {
  132569. 3, 1, 0, 2, 4,
  132570. };
  132571. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132572. _vq_quantthresh__44u1__p6_1,
  132573. _vq_quantmap__44u1__p6_1,
  132574. 5,
  132575. 5
  132576. };
  132577. static static_codebook _44u1__p6_1 = {
  132578. 2, 25,
  132579. _vq_lengthlist__44u1__p6_1,
  132580. 1, -533725184, 1611661312, 3, 0,
  132581. _vq_quantlist__44u1__p6_1,
  132582. NULL,
  132583. &_vq_auxt__44u1__p6_1,
  132584. NULL,
  132585. 0
  132586. };
  132587. static long _vq_quantlist__44u1__p7_0[] = {
  132588. 3,
  132589. 2,
  132590. 4,
  132591. 1,
  132592. 5,
  132593. 0,
  132594. 6,
  132595. };
  132596. static long _vq_lengthlist__44u1__p7_0[] = {
  132597. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132598. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132599. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132600. 8,
  132601. };
  132602. static float _vq_quantthresh__44u1__p7_0[] = {
  132603. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132604. };
  132605. static long _vq_quantmap__44u1__p7_0[] = {
  132606. 5, 3, 1, 0, 2, 4, 6,
  132607. };
  132608. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132609. _vq_quantthresh__44u1__p7_0,
  132610. _vq_quantmap__44u1__p7_0,
  132611. 7,
  132612. 7
  132613. };
  132614. static static_codebook _44u1__p7_0 = {
  132615. 2, 49,
  132616. _vq_lengthlist__44u1__p7_0,
  132617. 1, -518017024, 1626677248, 3, 0,
  132618. _vq_quantlist__44u1__p7_0,
  132619. NULL,
  132620. &_vq_auxt__44u1__p7_0,
  132621. NULL,
  132622. 0
  132623. };
  132624. static long _vq_quantlist__44u1__p7_1[] = {
  132625. 6,
  132626. 5,
  132627. 7,
  132628. 4,
  132629. 8,
  132630. 3,
  132631. 9,
  132632. 2,
  132633. 10,
  132634. 1,
  132635. 11,
  132636. 0,
  132637. 12,
  132638. };
  132639. static long _vq_lengthlist__44u1__p7_1[] = {
  132640. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132641. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132642. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132643. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132644. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132645. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132646. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132647. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132648. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132649. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132650. 15,15,15,15,15,15,15,15,15,
  132651. };
  132652. static float _vq_quantthresh__44u1__p7_1[] = {
  132653. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132654. 32.5, 45.5, 58.5, 71.5,
  132655. };
  132656. static long _vq_quantmap__44u1__p7_1[] = {
  132657. 11, 9, 7, 5, 3, 1, 0, 2,
  132658. 4, 6, 8, 10, 12,
  132659. };
  132660. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132661. _vq_quantthresh__44u1__p7_1,
  132662. _vq_quantmap__44u1__p7_1,
  132663. 13,
  132664. 13
  132665. };
  132666. static static_codebook _44u1__p7_1 = {
  132667. 2, 169,
  132668. _vq_lengthlist__44u1__p7_1,
  132669. 1, -523010048, 1618608128, 4, 0,
  132670. _vq_quantlist__44u1__p7_1,
  132671. NULL,
  132672. &_vq_auxt__44u1__p7_1,
  132673. NULL,
  132674. 0
  132675. };
  132676. static long _vq_quantlist__44u1__p7_2[] = {
  132677. 6,
  132678. 5,
  132679. 7,
  132680. 4,
  132681. 8,
  132682. 3,
  132683. 9,
  132684. 2,
  132685. 10,
  132686. 1,
  132687. 11,
  132688. 0,
  132689. 12,
  132690. };
  132691. static long _vq_lengthlist__44u1__p7_2[] = {
  132692. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132693. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132694. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132695. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132696. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132697. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132698. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132699. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132700. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132701. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132702. 9, 9, 9,10, 9, 9,10,10, 9,
  132703. };
  132704. static float _vq_quantthresh__44u1__p7_2[] = {
  132705. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132706. 2.5, 3.5, 4.5, 5.5,
  132707. };
  132708. static long _vq_quantmap__44u1__p7_2[] = {
  132709. 11, 9, 7, 5, 3, 1, 0, 2,
  132710. 4, 6, 8, 10, 12,
  132711. };
  132712. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132713. _vq_quantthresh__44u1__p7_2,
  132714. _vq_quantmap__44u1__p7_2,
  132715. 13,
  132716. 13
  132717. };
  132718. static static_codebook _44u1__p7_2 = {
  132719. 2, 169,
  132720. _vq_lengthlist__44u1__p7_2,
  132721. 1, -531103744, 1611661312, 4, 0,
  132722. _vq_quantlist__44u1__p7_2,
  132723. NULL,
  132724. &_vq_auxt__44u1__p7_2,
  132725. NULL,
  132726. 0
  132727. };
  132728. static long _huff_lengthlist__44u1__short[] = {
  132729. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132730. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132731. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132732. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132733. };
  132734. static static_codebook _huff_book__44u1__short = {
  132735. 2, 64,
  132736. _huff_lengthlist__44u1__short,
  132737. 0, 0, 0, 0, 0,
  132738. NULL,
  132739. NULL,
  132740. NULL,
  132741. NULL,
  132742. 0
  132743. };
  132744. static long _huff_lengthlist__44u2__long[] = {
  132745. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132746. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132747. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132748. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132749. };
  132750. static static_codebook _huff_book__44u2__long = {
  132751. 2, 64,
  132752. _huff_lengthlist__44u2__long,
  132753. 0, 0, 0, 0, 0,
  132754. NULL,
  132755. NULL,
  132756. NULL,
  132757. NULL,
  132758. 0
  132759. };
  132760. static long _vq_quantlist__44u2__p1_0[] = {
  132761. 1,
  132762. 0,
  132763. 2,
  132764. };
  132765. static long _vq_lengthlist__44u2__p1_0[] = {
  132766. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132767. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132768. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132769. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132770. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132771. 13,
  132772. };
  132773. static float _vq_quantthresh__44u2__p1_0[] = {
  132774. -0.5, 0.5,
  132775. };
  132776. static long _vq_quantmap__44u2__p1_0[] = {
  132777. 1, 0, 2,
  132778. };
  132779. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132780. _vq_quantthresh__44u2__p1_0,
  132781. _vq_quantmap__44u2__p1_0,
  132782. 3,
  132783. 3
  132784. };
  132785. static static_codebook _44u2__p1_0 = {
  132786. 4, 81,
  132787. _vq_lengthlist__44u2__p1_0,
  132788. 1, -535822336, 1611661312, 2, 0,
  132789. _vq_quantlist__44u2__p1_0,
  132790. NULL,
  132791. &_vq_auxt__44u2__p1_0,
  132792. NULL,
  132793. 0
  132794. };
  132795. static long _vq_quantlist__44u2__p2_0[] = {
  132796. 1,
  132797. 0,
  132798. 2,
  132799. };
  132800. static long _vq_lengthlist__44u2__p2_0[] = {
  132801. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132802. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132803. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132804. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132805. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132806. 9,
  132807. };
  132808. static float _vq_quantthresh__44u2__p2_0[] = {
  132809. -0.5, 0.5,
  132810. };
  132811. static long _vq_quantmap__44u2__p2_0[] = {
  132812. 1, 0, 2,
  132813. };
  132814. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132815. _vq_quantthresh__44u2__p2_0,
  132816. _vq_quantmap__44u2__p2_0,
  132817. 3,
  132818. 3
  132819. };
  132820. static static_codebook _44u2__p2_0 = {
  132821. 4, 81,
  132822. _vq_lengthlist__44u2__p2_0,
  132823. 1, -535822336, 1611661312, 2, 0,
  132824. _vq_quantlist__44u2__p2_0,
  132825. NULL,
  132826. &_vq_auxt__44u2__p2_0,
  132827. NULL,
  132828. 0
  132829. };
  132830. static long _vq_quantlist__44u2__p3_0[] = {
  132831. 2,
  132832. 1,
  132833. 3,
  132834. 0,
  132835. 4,
  132836. };
  132837. static long _vq_lengthlist__44u2__p3_0[] = {
  132838. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132839. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132840. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132841. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132842. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132843. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132844. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132845. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132846. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132847. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132848. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132849. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132850. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132851. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132852. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132853. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132854. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132855. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132856. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132857. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132858. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132859. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132860. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132861. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132862. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132863. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132864. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132865. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132866. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132867. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132868. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132869. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132870. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132871. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132872. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132873. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132874. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132875. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132876. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132877. 0,
  132878. };
  132879. static float _vq_quantthresh__44u2__p3_0[] = {
  132880. -1.5, -0.5, 0.5, 1.5,
  132881. };
  132882. static long _vq_quantmap__44u2__p3_0[] = {
  132883. 3, 1, 0, 2, 4,
  132884. };
  132885. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132886. _vq_quantthresh__44u2__p3_0,
  132887. _vq_quantmap__44u2__p3_0,
  132888. 5,
  132889. 5
  132890. };
  132891. static static_codebook _44u2__p3_0 = {
  132892. 4, 625,
  132893. _vq_lengthlist__44u2__p3_0,
  132894. 1, -533725184, 1611661312, 3, 0,
  132895. _vq_quantlist__44u2__p3_0,
  132896. NULL,
  132897. &_vq_auxt__44u2__p3_0,
  132898. NULL,
  132899. 0
  132900. };
  132901. static long _vq_quantlist__44u2__p4_0[] = {
  132902. 2,
  132903. 1,
  132904. 3,
  132905. 0,
  132906. 4,
  132907. };
  132908. static long _vq_lengthlist__44u2__p4_0[] = {
  132909. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132910. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132911. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132912. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132913. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132914. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132915. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132916. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132917. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132918. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132919. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132920. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132921. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132922. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132923. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132924. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132925. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132926. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132927. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132928. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132929. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132930. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132931. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132932. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132933. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132934. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132935. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132936. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  132937. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  132938. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  132939. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  132940. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  132941. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  132942. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  132943. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  132944. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  132945. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  132946. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  132947. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  132948. 13,
  132949. };
  132950. static float _vq_quantthresh__44u2__p4_0[] = {
  132951. -1.5, -0.5, 0.5, 1.5,
  132952. };
  132953. static long _vq_quantmap__44u2__p4_0[] = {
  132954. 3, 1, 0, 2, 4,
  132955. };
  132956. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  132957. _vq_quantthresh__44u2__p4_0,
  132958. _vq_quantmap__44u2__p4_0,
  132959. 5,
  132960. 5
  132961. };
  132962. static static_codebook _44u2__p4_0 = {
  132963. 4, 625,
  132964. _vq_lengthlist__44u2__p4_0,
  132965. 1, -533725184, 1611661312, 3, 0,
  132966. _vq_quantlist__44u2__p4_0,
  132967. NULL,
  132968. &_vq_auxt__44u2__p4_0,
  132969. NULL,
  132970. 0
  132971. };
  132972. static long _vq_quantlist__44u2__p5_0[] = {
  132973. 4,
  132974. 3,
  132975. 5,
  132976. 2,
  132977. 6,
  132978. 1,
  132979. 7,
  132980. 0,
  132981. 8,
  132982. };
  132983. static long _vq_lengthlist__44u2__p5_0[] = {
  132984. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  132985. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  132986. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  132987. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  132988. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  132989. 13,
  132990. };
  132991. static float _vq_quantthresh__44u2__p5_0[] = {
  132992. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132993. };
  132994. static long _vq_quantmap__44u2__p5_0[] = {
  132995. 7, 5, 3, 1, 0, 2, 4, 6,
  132996. 8,
  132997. };
  132998. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  132999. _vq_quantthresh__44u2__p5_0,
  133000. _vq_quantmap__44u2__p5_0,
  133001. 9,
  133002. 9
  133003. };
  133004. static static_codebook _44u2__p5_0 = {
  133005. 2, 81,
  133006. _vq_lengthlist__44u2__p5_0,
  133007. 1, -531628032, 1611661312, 4, 0,
  133008. _vq_quantlist__44u2__p5_0,
  133009. NULL,
  133010. &_vq_auxt__44u2__p5_0,
  133011. NULL,
  133012. 0
  133013. };
  133014. static long _vq_quantlist__44u2__p6_0[] = {
  133015. 6,
  133016. 5,
  133017. 7,
  133018. 4,
  133019. 8,
  133020. 3,
  133021. 9,
  133022. 2,
  133023. 10,
  133024. 1,
  133025. 11,
  133026. 0,
  133027. 12,
  133028. };
  133029. static long _vq_lengthlist__44u2__p6_0[] = {
  133030. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133031. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133032. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133033. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133034. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133035. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133036. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133037. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133038. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133039. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133040. 15,17,17,16,18,17,18, 0, 0,
  133041. };
  133042. static float _vq_quantthresh__44u2__p6_0[] = {
  133043. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133044. 12.5, 17.5, 22.5, 27.5,
  133045. };
  133046. static long _vq_quantmap__44u2__p6_0[] = {
  133047. 11, 9, 7, 5, 3, 1, 0, 2,
  133048. 4, 6, 8, 10, 12,
  133049. };
  133050. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133051. _vq_quantthresh__44u2__p6_0,
  133052. _vq_quantmap__44u2__p6_0,
  133053. 13,
  133054. 13
  133055. };
  133056. static static_codebook _44u2__p6_0 = {
  133057. 2, 169,
  133058. _vq_lengthlist__44u2__p6_0,
  133059. 1, -526516224, 1616117760, 4, 0,
  133060. _vq_quantlist__44u2__p6_0,
  133061. NULL,
  133062. &_vq_auxt__44u2__p6_0,
  133063. NULL,
  133064. 0
  133065. };
  133066. static long _vq_quantlist__44u2__p6_1[] = {
  133067. 2,
  133068. 1,
  133069. 3,
  133070. 0,
  133071. 4,
  133072. };
  133073. static long _vq_lengthlist__44u2__p6_1[] = {
  133074. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133075. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133076. };
  133077. static float _vq_quantthresh__44u2__p6_1[] = {
  133078. -1.5, -0.5, 0.5, 1.5,
  133079. };
  133080. static long _vq_quantmap__44u2__p6_1[] = {
  133081. 3, 1, 0, 2, 4,
  133082. };
  133083. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133084. _vq_quantthresh__44u2__p6_1,
  133085. _vq_quantmap__44u2__p6_1,
  133086. 5,
  133087. 5
  133088. };
  133089. static static_codebook _44u2__p6_1 = {
  133090. 2, 25,
  133091. _vq_lengthlist__44u2__p6_1,
  133092. 1, -533725184, 1611661312, 3, 0,
  133093. _vq_quantlist__44u2__p6_1,
  133094. NULL,
  133095. &_vq_auxt__44u2__p6_1,
  133096. NULL,
  133097. 0
  133098. };
  133099. static long _vq_quantlist__44u2__p7_0[] = {
  133100. 4,
  133101. 3,
  133102. 5,
  133103. 2,
  133104. 6,
  133105. 1,
  133106. 7,
  133107. 0,
  133108. 8,
  133109. };
  133110. static long _vq_lengthlist__44u2__p7_0[] = {
  133111. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133112. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133113. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133114. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133115. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133116. 11,
  133117. };
  133118. static float _vq_quantthresh__44u2__p7_0[] = {
  133119. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133120. };
  133121. static long _vq_quantmap__44u2__p7_0[] = {
  133122. 7, 5, 3, 1, 0, 2, 4, 6,
  133123. 8,
  133124. };
  133125. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133126. _vq_quantthresh__44u2__p7_0,
  133127. _vq_quantmap__44u2__p7_0,
  133128. 9,
  133129. 9
  133130. };
  133131. static static_codebook _44u2__p7_0 = {
  133132. 2, 81,
  133133. _vq_lengthlist__44u2__p7_0,
  133134. 1, -516612096, 1626677248, 4, 0,
  133135. _vq_quantlist__44u2__p7_0,
  133136. NULL,
  133137. &_vq_auxt__44u2__p7_0,
  133138. NULL,
  133139. 0
  133140. };
  133141. static long _vq_quantlist__44u2__p7_1[] = {
  133142. 6,
  133143. 5,
  133144. 7,
  133145. 4,
  133146. 8,
  133147. 3,
  133148. 9,
  133149. 2,
  133150. 10,
  133151. 1,
  133152. 11,
  133153. 0,
  133154. 12,
  133155. };
  133156. static long _vq_lengthlist__44u2__p7_1[] = {
  133157. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133158. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133159. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133160. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133161. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133162. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133163. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133164. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133165. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133166. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133167. 14,14,14,17,15,17,17,17,17,
  133168. };
  133169. static float _vq_quantthresh__44u2__p7_1[] = {
  133170. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133171. 32.5, 45.5, 58.5, 71.5,
  133172. };
  133173. static long _vq_quantmap__44u2__p7_1[] = {
  133174. 11, 9, 7, 5, 3, 1, 0, 2,
  133175. 4, 6, 8, 10, 12,
  133176. };
  133177. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133178. _vq_quantthresh__44u2__p7_1,
  133179. _vq_quantmap__44u2__p7_1,
  133180. 13,
  133181. 13
  133182. };
  133183. static static_codebook _44u2__p7_1 = {
  133184. 2, 169,
  133185. _vq_lengthlist__44u2__p7_1,
  133186. 1, -523010048, 1618608128, 4, 0,
  133187. _vq_quantlist__44u2__p7_1,
  133188. NULL,
  133189. &_vq_auxt__44u2__p7_1,
  133190. NULL,
  133191. 0
  133192. };
  133193. static long _vq_quantlist__44u2__p7_2[] = {
  133194. 6,
  133195. 5,
  133196. 7,
  133197. 4,
  133198. 8,
  133199. 3,
  133200. 9,
  133201. 2,
  133202. 10,
  133203. 1,
  133204. 11,
  133205. 0,
  133206. 12,
  133207. };
  133208. static long _vq_lengthlist__44u2__p7_2[] = {
  133209. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133210. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133211. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133212. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133213. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133214. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133215. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133216. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133217. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133218. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133219. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133220. };
  133221. static float _vq_quantthresh__44u2__p7_2[] = {
  133222. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133223. 2.5, 3.5, 4.5, 5.5,
  133224. };
  133225. static long _vq_quantmap__44u2__p7_2[] = {
  133226. 11, 9, 7, 5, 3, 1, 0, 2,
  133227. 4, 6, 8, 10, 12,
  133228. };
  133229. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133230. _vq_quantthresh__44u2__p7_2,
  133231. _vq_quantmap__44u2__p7_2,
  133232. 13,
  133233. 13
  133234. };
  133235. static static_codebook _44u2__p7_2 = {
  133236. 2, 169,
  133237. _vq_lengthlist__44u2__p7_2,
  133238. 1, -531103744, 1611661312, 4, 0,
  133239. _vq_quantlist__44u2__p7_2,
  133240. NULL,
  133241. &_vq_auxt__44u2__p7_2,
  133242. NULL,
  133243. 0
  133244. };
  133245. static long _huff_lengthlist__44u2__short[] = {
  133246. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133247. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133248. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133249. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133250. };
  133251. static static_codebook _huff_book__44u2__short = {
  133252. 2, 64,
  133253. _huff_lengthlist__44u2__short,
  133254. 0, 0, 0, 0, 0,
  133255. NULL,
  133256. NULL,
  133257. NULL,
  133258. NULL,
  133259. 0
  133260. };
  133261. static long _huff_lengthlist__44u3__long[] = {
  133262. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133263. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133264. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133265. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133266. };
  133267. static static_codebook _huff_book__44u3__long = {
  133268. 2, 64,
  133269. _huff_lengthlist__44u3__long,
  133270. 0, 0, 0, 0, 0,
  133271. NULL,
  133272. NULL,
  133273. NULL,
  133274. NULL,
  133275. 0
  133276. };
  133277. static long _vq_quantlist__44u3__p1_0[] = {
  133278. 1,
  133279. 0,
  133280. 2,
  133281. };
  133282. static long _vq_lengthlist__44u3__p1_0[] = {
  133283. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133284. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133285. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133286. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133287. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133288. 13,
  133289. };
  133290. static float _vq_quantthresh__44u3__p1_0[] = {
  133291. -0.5, 0.5,
  133292. };
  133293. static long _vq_quantmap__44u3__p1_0[] = {
  133294. 1, 0, 2,
  133295. };
  133296. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133297. _vq_quantthresh__44u3__p1_0,
  133298. _vq_quantmap__44u3__p1_0,
  133299. 3,
  133300. 3
  133301. };
  133302. static static_codebook _44u3__p1_0 = {
  133303. 4, 81,
  133304. _vq_lengthlist__44u3__p1_0,
  133305. 1, -535822336, 1611661312, 2, 0,
  133306. _vq_quantlist__44u3__p1_0,
  133307. NULL,
  133308. &_vq_auxt__44u3__p1_0,
  133309. NULL,
  133310. 0
  133311. };
  133312. static long _vq_quantlist__44u3__p2_0[] = {
  133313. 1,
  133314. 0,
  133315. 2,
  133316. };
  133317. static long _vq_lengthlist__44u3__p2_0[] = {
  133318. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133319. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133320. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133321. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133322. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133323. 9,
  133324. };
  133325. static float _vq_quantthresh__44u3__p2_0[] = {
  133326. -0.5, 0.5,
  133327. };
  133328. static long _vq_quantmap__44u3__p2_0[] = {
  133329. 1, 0, 2,
  133330. };
  133331. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133332. _vq_quantthresh__44u3__p2_0,
  133333. _vq_quantmap__44u3__p2_0,
  133334. 3,
  133335. 3
  133336. };
  133337. static static_codebook _44u3__p2_0 = {
  133338. 4, 81,
  133339. _vq_lengthlist__44u3__p2_0,
  133340. 1, -535822336, 1611661312, 2, 0,
  133341. _vq_quantlist__44u3__p2_0,
  133342. NULL,
  133343. &_vq_auxt__44u3__p2_0,
  133344. NULL,
  133345. 0
  133346. };
  133347. static long _vq_quantlist__44u3__p3_0[] = {
  133348. 2,
  133349. 1,
  133350. 3,
  133351. 0,
  133352. 4,
  133353. };
  133354. static long _vq_lengthlist__44u3__p3_0[] = {
  133355. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133356. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133357. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133358. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133359. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133360. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133361. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133362. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133363. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133364. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133365. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133366. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133367. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133368. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133369. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133370. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133371. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133372. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133373. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133374. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133375. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133376. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133377. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133378. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133379. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133380. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133381. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133382. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133383. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133384. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133385. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133386. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133387. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133388. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133389. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133390. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133391. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133392. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133393. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133394. 0,
  133395. };
  133396. static float _vq_quantthresh__44u3__p3_0[] = {
  133397. -1.5, -0.5, 0.5, 1.5,
  133398. };
  133399. static long _vq_quantmap__44u3__p3_0[] = {
  133400. 3, 1, 0, 2, 4,
  133401. };
  133402. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133403. _vq_quantthresh__44u3__p3_0,
  133404. _vq_quantmap__44u3__p3_0,
  133405. 5,
  133406. 5
  133407. };
  133408. static static_codebook _44u3__p3_0 = {
  133409. 4, 625,
  133410. _vq_lengthlist__44u3__p3_0,
  133411. 1, -533725184, 1611661312, 3, 0,
  133412. _vq_quantlist__44u3__p3_0,
  133413. NULL,
  133414. &_vq_auxt__44u3__p3_0,
  133415. NULL,
  133416. 0
  133417. };
  133418. static long _vq_quantlist__44u3__p4_0[] = {
  133419. 2,
  133420. 1,
  133421. 3,
  133422. 0,
  133423. 4,
  133424. };
  133425. static long _vq_lengthlist__44u3__p4_0[] = {
  133426. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133427. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133428. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133429. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133430. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133431. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133432. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133433. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133434. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133435. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133436. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133437. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133438. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133439. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133440. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133441. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133442. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133443. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133444. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133445. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133446. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133447. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133448. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133449. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133450. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133451. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133452. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133453. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133454. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133455. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133456. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133457. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133458. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133459. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133460. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133461. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133462. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133463. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133464. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133465. 13,
  133466. };
  133467. static float _vq_quantthresh__44u3__p4_0[] = {
  133468. -1.5, -0.5, 0.5, 1.5,
  133469. };
  133470. static long _vq_quantmap__44u3__p4_0[] = {
  133471. 3, 1, 0, 2, 4,
  133472. };
  133473. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133474. _vq_quantthresh__44u3__p4_0,
  133475. _vq_quantmap__44u3__p4_0,
  133476. 5,
  133477. 5
  133478. };
  133479. static static_codebook _44u3__p4_0 = {
  133480. 4, 625,
  133481. _vq_lengthlist__44u3__p4_0,
  133482. 1, -533725184, 1611661312, 3, 0,
  133483. _vq_quantlist__44u3__p4_0,
  133484. NULL,
  133485. &_vq_auxt__44u3__p4_0,
  133486. NULL,
  133487. 0
  133488. };
  133489. static long _vq_quantlist__44u3__p5_0[] = {
  133490. 4,
  133491. 3,
  133492. 5,
  133493. 2,
  133494. 6,
  133495. 1,
  133496. 7,
  133497. 0,
  133498. 8,
  133499. };
  133500. static long _vq_lengthlist__44u3__p5_0[] = {
  133501. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133502. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133503. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133504. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133505. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133506. 12,
  133507. };
  133508. static float _vq_quantthresh__44u3__p5_0[] = {
  133509. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133510. };
  133511. static long _vq_quantmap__44u3__p5_0[] = {
  133512. 7, 5, 3, 1, 0, 2, 4, 6,
  133513. 8,
  133514. };
  133515. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133516. _vq_quantthresh__44u3__p5_0,
  133517. _vq_quantmap__44u3__p5_0,
  133518. 9,
  133519. 9
  133520. };
  133521. static static_codebook _44u3__p5_0 = {
  133522. 2, 81,
  133523. _vq_lengthlist__44u3__p5_0,
  133524. 1, -531628032, 1611661312, 4, 0,
  133525. _vq_quantlist__44u3__p5_0,
  133526. NULL,
  133527. &_vq_auxt__44u3__p5_0,
  133528. NULL,
  133529. 0
  133530. };
  133531. static long _vq_quantlist__44u3__p6_0[] = {
  133532. 6,
  133533. 5,
  133534. 7,
  133535. 4,
  133536. 8,
  133537. 3,
  133538. 9,
  133539. 2,
  133540. 10,
  133541. 1,
  133542. 11,
  133543. 0,
  133544. 12,
  133545. };
  133546. static long _vq_lengthlist__44u3__p6_0[] = {
  133547. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133548. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133549. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133550. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133551. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133552. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133553. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133554. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133555. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133556. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133557. 15,16,16,16,17,18,16,20,18,
  133558. };
  133559. static float _vq_quantthresh__44u3__p6_0[] = {
  133560. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133561. 12.5, 17.5, 22.5, 27.5,
  133562. };
  133563. static long _vq_quantmap__44u3__p6_0[] = {
  133564. 11, 9, 7, 5, 3, 1, 0, 2,
  133565. 4, 6, 8, 10, 12,
  133566. };
  133567. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133568. _vq_quantthresh__44u3__p6_0,
  133569. _vq_quantmap__44u3__p6_0,
  133570. 13,
  133571. 13
  133572. };
  133573. static static_codebook _44u3__p6_0 = {
  133574. 2, 169,
  133575. _vq_lengthlist__44u3__p6_0,
  133576. 1, -526516224, 1616117760, 4, 0,
  133577. _vq_quantlist__44u3__p6_0,
  133578. NULL,
  133579. &_vq_auxt__44u3__p6_0,
  133580. NULL,
  133581. 0
  133582. };
  133583. static long _vq_quantlist__44u3__p6_1[] = {
  133584. 2,
  133585. 1,
  133586. 3,
  133587. 0,
  133588. 4,
  133589. };
  133590. static long _vq_lengthlist__44u3__p6_1[] = {
  133591. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133592. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133593. };
  133594. static float _vq_quantthresh__44u3__p6_1[] = {
  133595. -1.5, -0.5, 0.5, 1.5,
  133596. };
  133597. static long _vq_quantmap__44u3__p6_1[] = {
  133598. 3, 1, 0, 2, 4,
  133599. };
  133600. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133601. _vq_quantthresh__44u3__p6_1,
  133602. _vq_quantmap__44u3__p6_1,
  133603. 5,
  133604. 5
  133605. };
  133606. static static_codebook _44u3__p6_1 = {
  133607. 2, 25,
  133608. _vq_lengthlist__44u3__p6_1,
  133609. 1, -533725184, 1611661312, 3, 0,
  133610. _vq_quantlist__44u3__p6_1,
  133611. NULL,
  133612. &_vq_auxt__44u3__p6_1,
  133613. NULL,
  133614. 0
  133615. };
  133616. static long _vq_quantlist__44u3__p7_0[] = {
  133617. 4,
  133618. 3,
  133619. 5,
  133620. 2,
  133621. 6,
  133622. 1,
  133623. 7,
  133624. 0,
  133625. 8,
  133626. };
  133627. static long _vq_lengthlist__44u3__p7_0[] = {
  133628. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133629. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133630. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133631. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133632. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133633. 9,
  133634. };
  133635. static float _vq_quantthresh__44u3__p7_0[] = {
  133636. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133637. };
  133638. static long _vq_quantmap__44u3__p7_0[] = {
  133639. 7, 5, 3, 1, 0, 2, 4, 6,
  133640. 8,
  133641. };
  133642. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133643. _vq_quantthresh__44u3__p7_0,
  133644. _vq_quantmap__44u3__p7_0,
  133645. 9,
  133646. 9
  133647. };
  133648. static static_codebook _44u3__p7_0 = {
  133649. 2, 81,
  133650. _vq_lengthlist__44u3__p7_0,
  133651. 1, -515907584, 1627381760, 4, 0,
  133652. _vq_quantlist__44u3__p7_0,
  133653. NULL,
  133654. &_vq_auxt__44u3__p7_0,
  133655. NULL,
  133656. 0
  133657. };
  133658. static long _vq_quantlist__44u3__p7_1[] = {
  133659. 7,
  133660. 6,
  133661. 8,
  133662. 5,
  133663. 9,
  133664. 4,
  133665. 10,
  133666. 3,
  133667. 11,
  133668. 2,
  133669. 12,
  133670. 1,
  133671. 13,
  133672. 0,
  133673. 14,
  133674. };
  133675. static long _vq_lengthlist__44u3__p7_1[] = {
  133676. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133677. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133678. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133679. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133680. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133681. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133682. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133683. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133684. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133685. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133686. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133687. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133688. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133689. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133690. 17,
  133691. };
  133692. static float _vq_quantthresh__44u3__p7_1[] = {
  133693. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133694. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133695. };
  133696. static long _vq_quantmap__44u3__p7_1[] = {
  133697. 13, 11, 9, 7, 5, 3, 1, 0,
  133698. 2, 4, 6, 8, 10, 12, 14,
  133699. };
  133700. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133701. _vq_quantthresh__44u3__p7_1,
  133702. _vq_quantmap__44u3__p7_1,
  133703. 15,
  133704. 15
  133705. };
  133706. static static_codebook _44u3__p7_1 = {
  133707. 2, 225,
  133708. _vq_lengthlist__44u3__p7_1,
  133709. 1, -522338304, 1620115456, 4, 0,
  133710. _vq_quantlist__44u3__p7_1,
  133711. NULL,
  133712. &_vq_auxt__44u3__p7_1,
  133713. NULL,
  133714. 0
  133715. };
  133716. static long _vq_quantlist__44u3__p7_2[] = {
  133717. 8,
  133718. 7,
  133719. 9,
  133720. 6,
  133721. 10,
  133722. 5,
  133723. 11,
  133724. 4,
  133725. 12,
  133726. 3,
  133727. 13,
  133728. 2,
  133729. 14,
  133730. 1,
  133731. 15,
  133732. 0,
  133733. 16,
  133734. };
  133735. static long _vq_lengthlist__44u3__p7_2[] = {
  133736. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133737. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133738. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133739. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133740. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133741. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133742. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133743. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133744. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133745. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133746. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133747. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133748. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133749. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133750. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133751. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133752. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133753. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133754. 11,
  133755. };
  133756. static float _vq_quantthresh__44u3__p7_2[] = {
  133757. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133758. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133759. };
  133760. static long _vq_quantmap__44u3__p7_2[] = {
  133761. 15, 13, 11, 9, 7, 5, 3, 1,
  133762. 0, 2, 4, 6, 8, 10, 12, 14,
  133763. 16,
  133764. };
  133765. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133766. _vq_quantthresh__44u3__p7_2,
  133767. _vq_quantmap__44u3__p7_2,
  133768. 17,
  133769. 17
  133770. };
  133771. static static_codebook _44u3__p7_2 = {
  133772. 2, 289,
  133773. _vq_lengthlist__44u3__p7_2,
  133774. 1, -529530880, 1611661312, 5, 0,
  133775. _vq_quantlist__44u3__p7_2,
  133776. NULL,
  133777. &_vq_auxt__44u3__p7_2,
  133778. NULL,
  133779. 0
  133780. };
  133781. static long _huff_lengthlist__44u3__short[] = {
  133782. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133783. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133784. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133785. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133786. };
  133787. static static_codebook _huff_book__44u3__short = {
  133788. 2, 64,
  133789. _huff_lengthlist__44u3__short,
  133790. 0, 0, 0, 0, 0,
  133791. NULL,
  133792. NULL,
  133793. NULL,
  133794. NULL,
  133795. 0
  133796. };
  133797. static long _huff_lengthlist__44u4__long[] = {
  133798. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133799. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133800. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133801. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133802. };
  133803. static static_codebook _huff_book__44u4__long = {
  133804. 2, 64,
  133805. _huff_lengthlist__44u4__long,
  133806. 0, 0, 0, 0, 0,
  133807. NULL,
  133808. NULL,
  133809. NULL,
  133810. NULL,
  133811. 0
  133812. };
  133813. static long _vq_quantlist__44u4__p1_0[] = {
  133814. 1,
  133815. 0,
  133816. 2,
  133817. };
  133818. static long _vq_lengthlist__44u4__p1_0[] = {
  133819. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133820. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133821. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133822. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133823. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133824. 13,
  133825. };
  133826. static float _vq_quantthresh__44u4__p1_0[] = {
  133827. -0.5, 0.5,
  133828. };
  133829. static long _vq_quantmap__44u4__p1_0[] = {
  133830. 1, 0, 2,
  133831. };
  133832. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133833. _vq_quantthresh__44u4__p1_0,
  133834. _vq_quantmap__44u4__p1_0,
  133835. 3,
  133836. 3
  133837. };
  133838. static static_codebook _44u4__p1_0 = {
  133839. 4, 81,
  133840. _vq_lengthlist__44u4__p1_0,
  133841. 1, -535822336, 1611661312, 2, 0,
  133842. _vq_quantlist__44u4__p1_0,
  133843. NULL,
  133844. &_vq_auxt__44u4__p1_0,
  133845. NULL,
  133846. 0
  133847. };
  133848. static long _vq_quantlist__44u4__p2_0[] = {
  133849. 1,
  133850. 0,
  133851. 2,
  133852. };
  133853. static long _vq_lengthlist__44u4__p2_0[] = {
  133854. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133855. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133856. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133857. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133858. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133859. 9,
  133860. };
  133861. static float _vq_quantthresh__44u4__p2_0[] = {
  133862. -0.5, 0.5,
  133863. };
  133864. static long _vq_quantmap__44u4__p2_0[] = {
  133865. 1, 0, 2,
  133866. };
  133867. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133868. _vq_quantthresh__44u4__p2_0,
  133869. _vq_quantmap__44u4__p2_0,
  133870. 3,
  133871. 3
  133872. };
  133873. static static_codebook _44u4__p2_0 = {
  133874. 4, 81,
  133875. _vq_lengthlist__44u4__p2_0,
  133876. 1, -535822336, 1611661312, 2, 0,
  133877. _vq_quantlist__44u4__p2_0,
  133878. NULL,
  133879. &_vq_auxt__44u4__p2_0,
  133880. NULL,
  133881. 0
  133882. };
  133883. static long _vq_quantlist__44u4__p3_0[] = {
  133884. 2,
  133885. 1,
  133886. 3,
  133887. 0,
  133888. 4,
  133889. };
  133890. static long _vq_lengthlist__44u4__p3_0[] = {
  133891. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133892. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133893. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133894. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133895. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133896. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133897. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133898. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133899. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133900. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133901. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133902. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133903. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133904. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133905. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133906. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133907. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133908. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133909. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133910. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133911. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133912. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133913. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133914. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133915. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133916. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133917. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133918. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133919. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133920. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133921. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133922. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133923. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133924. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133925. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133926. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133927. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133928. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133929. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133930. 0,
  133931. };
  133932. static float _vq_quantthresh__44u4__p3_0[] = {
  133933. -1.5, -0.5, 0.5, 1.5,
  133934. };
  133935. static long _vq_quantmap__44u4__p3_0[] = {
  133936. 3, 1, 0, 2, 4,
  133937. };
  133938. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  133939. _vq_quantthresh__44u4__p3_0,
  133940. _vq_quantmap__44u4__p3_0,
  133941. 5,
  133942. 5
  133943. };
  133944. static static_codebook _44u4__p3_0 = {
  133945. 4, 625,
  133946. _vq_lengthlist__44u4__p3_0,
  133947. 1, -533725184, 1611661312, 3, 0,
  133948. _vq_quantlist__44u4__p3_0,
  133949. NULL,
  133950. &_vq_auxt__44u4__p3_0,
  133951. NULL,
  133952. 0
  133953. };
  133954. static long _vq_quantlist__44u4__p4_0[] = {
  133955. 2,
  133956. 1,
  133957. 3,
  133958. 0,
  133959. 4,
  133960. };
  133961. static long _vq_lengthlist__44u4__p4_0[] = {
  133962. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133963. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133964. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133965. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133966. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133967. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  133968. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  133969. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  133970. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133971. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133972. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133973. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133974. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133975. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  133976. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133977. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133978. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133979. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133980. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133981. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133982. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133983. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133984. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133985. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133986. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133987. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  133988. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  133989. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  133990. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  133991. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  133992. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  133993. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133994. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133995. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  133996. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133997. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  133998. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133999. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  134000. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  134001. 13,
  134002. };
  134003. static float _vq_quantthresh__44u4__p4_0[] = {
  134004. -1.5, -0.5, 0.5, 1.5,
  134005. };
  134006. static long _vq_quantmap__44u4__p4_0[] = {
  134007. 3, 1, 0, 2, 4,
  134008. };
  134009. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  134010. _vq_quantthresh__44u4__p4_0,
  134011. _vq_quantmap__44u4__p4_0,
  134012. 5,
  134013. 5
  134014. };
  134015. static static_codebook _44u4__p4_0 = {
  134016. 4, 625,
  134017. _vq_lengthlist__44u4__p4_0,
  134018. 1, -533725184, 1611661312, 3, 0,
  134019. _vq_quantlist__44u4__p4_0,
  134020. NULL,
  134021. &_vq_auxt__44u4__p4_0,
  134022. NULL,
  134023. 0
  134024. };
  134025. static long _vq_quantlist__44u4__p5_0[] = {
  134026. 4,
  134027. 3,
  134028. 5,
  134029. 2,
  134030. 6,
  134031. 1,
  134032. 7,
  134033. 0,
  134034. 8,
  134035. };
  134036. static long _vq_lengthlist__44u4__p5_0[] = {
  134037. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134038. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134039. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134040. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134041. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134042. 12,
  134043. };
  134044. static float _vq_quantthresh__44u4__p5_0[] = {
  134045. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134046. };
  134047. static long _vq_quantmap__44u4__p5_0[] = {
  134048. 7, 5, 3, 1, 0, 2, 4, 6,
  134049. 8,
  134050. };
  134051. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134052. _vq_quantthresh__44u4__p5_0,
  134053. _vq_quantmap__44u4__p5_0,
  134054. 9,
  134055. 9
  134056. };
  134057. static static_codebook _44u4__p5_0 = {
  134058. 2, 81,
  134059. _vq_lengthlist__44u4__p5_0,
  134060. 1, -531628032, 1611661312, 4, 0,
  134061. _vq_quantlist__44u4__p5_0,
  134062. NULL,
  134063. &_vq_auxt__44u4__p5_0,
  134064. NULL,
  134065. 0
  134066. };
  134067. static long _vq_quantlist__44u4__p6_0[] = {
  134068. 6,
  134069. 5,
  134070. 7,
  134071. 4,
  134072. 8,
  134073. 3,
  134074. 9,
  134075. 2,
  134076. 10,
  134077. 1,
  134078. 11,
  134079. 0,
  134080. 12,
  134081. };
  134082. static long _vq_lengthlist__44u4__p6_0[] = {
  134083. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134084. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134085. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134086. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134087. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134088. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134089. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134090. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134091. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134092. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134093. 16,16,16,17,17,18,17,20,21,
  134094. };
  134095. static float _vq_quantthresh__44u4__p6_0[] = {
  134096. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134097. 12.5, 17.5, 22.5, 27.5,
  134098. };
  134099. static long _vq_quantmap__44u4__p6_0[] = {
  134100. 11, 9, 7, 5, 3, 1, 0, 2,
  134101. 4, 6, 8, 10, 12,
  134102. };
  134103. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134104. _vq_quantthresh__44u4__p6_0,
  134105. _vq_quantmap__44u4__p6_0,
  134106. 13,
  134107. 13
  134108. };
  134109. static static_codebook _44u4__p6_0 = {
  134110. 2, 169,
  134111. _vq_lengthlist__44u4__p6_0,
  134112. 1, -526516224, 1616117760, 4, 0,
  134113. _vq_quantlist__44u4__p6_0,
  134114. NULL,
  134115. &_vq_auxt__44u4__p6_0,
  134116. NULL,
  134117. 0
  134118. };
  134119. static long _vq_quantlist__44u4__p6_1[] = {
  134120. 2,
  134121. 1,
  134122. 3,
  134123. 0,
  134124. 4,
  134125. };
  134126. static long _vq_lengthlist__44u4__p6_1[] = {
  134127. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134128. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134129. };
  134130. static float _vq_quantthresh__44u4__p6_1[] = {
  134131. -1.5, -0.5, 0.5, 1.5,
  134132. };
  134133. static long _vq_quantmap__44u4__p6_1[] = {
  134134. 3, 1, 0, 2, 4,
  134135. };
  134136. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134137. _vq_quantthresh__44u4__p6_1,
  134138. _vq_quantmap__44u4__p6_1,
  134139. 5,
  134140. 5
  134141. };
  134142. static static_codebook _44u4__p6_1 = {
  134143. 2, 25,
  134144. _vq_lengthlist__44u4__p6_1,
  134145. 1, -533725184, 1611661312, 3, 0,
  134146. _vq_quantlist__44u4__p6_1,
  134147. NULL,
  134148. &_vq_auxt__44u4__p6_1,
  134149. NULL,
  134150. 0
  134151. };
  134152. static long _vq_quantlist__44u4__p7_0[] = {
  134153. 6,
  134154. 5,
  134155. 7,
  134156. 4,
  134157. 8,
  134158. 3,
  134159. 9,
  134160. 2,
  134161. 10,
  134162. 1,
  134163. 11,
  134164. 0,
  134165. 12,
  134166. };
  134167. static long _vq_lengthlist__44u4__p7_0[] = {
  134168. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134169. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134170. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134171. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134172. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134173. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134174. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134175. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134176. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134177. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134178. 11,11,11,11,11,11,11,11,11,
  134179. };
  134180. static float _vq_quantthresh__44u4__p7_0[] = {
  134181. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134182. 637.5, 892.5, 1147.5, 1402.5,
  134183. };
  134184. static long _vq_quantmap__44u4__p7_0[] = {
  134185. 11, 9, 7, 5, 3, 1, 0, 2,
  134186. 4, 6, 8, 10, 12,
  134187. };
  134188. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134189. _vq_quantthresh__44u4__p7_0,
  134190. _vq_quantmap__44u4__p7_0,
  134191. 13,
  134192. 13
  134193. };
  134194. static static_codebook _44u4__p7_0 = {
  134195. 2, 169,
  134196. _vq_lengthlist__44u4__p7_0,
  134197. 1, -514332672, 1627381760, 4, 0,
  134198. _vq_quantlist__44u4__p7_0,
  134199. NULL,
  134200. &_vq_auxt__44u4__p7_0,
  134201. NULL,
  134202. 0
  134203. };
  134204. static long _vq_quantlist__44u4__p7_1[] = {
  134205. 7,
  134206. 6,
  134207. 8,
  134208. 5,
  134209. 9,
  134210. 4,
  134211. 10,
  134212. 3,
  134213. 11,
  134214. 2,
  134215. 12,
  134216. 1,
  134217. 13,
  134218. 0,
  134219. 14,
  134220. };
  134221. static long _vq_lengthlist__44u4__p7_1[] = {
  134222. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134223. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134224. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134225. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134226. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134227. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134228. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134229. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134230. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134231. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134232. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134233. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134234. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134235. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134236. 16,
  134237. };
  134238. static float _vq_quantthresh__44u4__p7_1[] = {
  134239. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134240. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134241. };
  134242. static long _vq_quantmap__44u4__p7_1[] = {
  134243. 13, 11, 9, 7, 5, 3, 1, 0,
  134244. 2, 4, 6, 8, 10, 12, 14,
  134245. };
  134246. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134247. _vq_quantthresh__44u4__p7_1,
  134248. _vq_quantmap__44u4__p7_1,
  134249. 15,
  134250. 15
  134251. };
  134252. static static_codebook _44u4__p7_1 = {
  134253. 2, 225,
  134254. _vq_lengthlist__44u4__p7_1,
  134255. 1, -522338304, 1620115456, 4, 0,
  134256. _vq_quantlist__44u4__p7_1,
  134257. NULL,
  134258. &_vq_auxt__44u4__p7_1,
  134259. NULL,
  134260. 0
  134261. };
  134262. static long _vq_quantlist__44u4__p7_2[] = {
  134263. 8,
  134264. 7,
  134265. 9,
  134266. 6,
  134267. 10,
  134268. 5,
  134269. 11,
  134270. 4,
  134271. 12,
  134272. 3,
  134273. 13,
  134274. 2,
  134275. 14,
  134276. 1,
  134277. 15,
  134278. 0,
  134279. 16,
  134280. };
  134281. static long _vq_lengthlist__44u4__p7_2[] = {
  134282. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134283. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134284. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134285. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134286. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134287. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134288. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134289. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134290. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134291. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134292. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134293. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134294. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134295. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134296. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134297. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134298. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134299. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134300. 10,
  134301. };
  134302. static float _vq_quantthresh__44u4__p7_2[] = {
  134303. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134304. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134305. };
  134306. static long _vq_quantmap__44u4__p7_2[] = {
  134307. 15, 13, 11, 9, 7, 5, 3, 1,
  134308. 0, 2, 4, 6, 8, 10, 12, 14,
  134309. 16,
  134310. };
  134311. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134312. _vq_quantthresh__44u4__p7_2,
  134313. _vq_quantmap__44u4__p7_2,
  134314. 17,
  134315. 17
  134316. };
  134317. static static_codebook _44u4__p7_2 = {
  134318. 2, 289,
  134319. _vq_lengthlist__44u4__p7_2,
  134320. 1, -529530880, 1611661312, 5, 0,
  134321. _vq_quantlist__44u4__p7_2,
  134322. NULL,
  134323. &_vq_auxt__44u4__p7_2,
  134324. NULL,
  134325. 0
  134326. };
  134327. static long _huff_lengthlist__44u4__short[] = {
  134328. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134329. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134330. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134331. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134332. };
  134333. static static_codebook _huff_book__44u4__short = {
  134334. 2, 64,
  134335. _huff_lengthlist__44u4__short,
  134336. 0, 0, 0, 0, 0,
  134337. NULL,
  134338. NULL,
  134339. NULL,
  134340. NULL,
  134341. 0
  134342. };
  134343. static long _huff_lengthlist__44u5__long[] = {
  134344. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134345. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134346. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134347. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134348. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134349. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134350. 14, 8, 7, 8,
  134351. };
  134352. static static_codebook _huff_book__44u5__long = {
  134353. 2, 100,
  134354. _huff_lengthlist__44u5__long,
  134355. 0, 0, 0, 0, 0,
  134356. NULL,
  134357. NULL,
  134358. NULL,
  134359. NULL,
  134360. 0
  134361. };
  134362. static long _vq_quantlist__44u5__p1_0[] = {
  134363. 1,
  134364. 0,
  134365. 2,
  134366. };
  134367. static long _vq_lengthlist__44u5__p1_0[] = {
  134368. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134369. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134370. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134371. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134372. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134373. 12,
  134374. };
  134375. static float _vq_quantthresh__44u5__p1_0[] = {
  134376. -0.5, 0.5,
  134377. };
  134378. static long _vq_quantmap__44u5__p1_0[] = {
  134379. 1, 0, 2,
  134380. };
  134381. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134382. _vq_quantthresh__44u5__p1_0,
  134383. _vq_quantmap__44u5__p1_0,
  134384. 3,
  134385. 3
  134386. };
  134387. static static_codebook _44u5__p1_0 = {
  134388. 4, 81,
  134389. _vq_lengthlist__44u5__p1_0,
  134390. 1, -535822336, 1611661312, 2, 0,
  134391. _vq_quantlist__44u5__p1_0,
  134392. NULL,
  134393. &_vq_auxt__44u5__p1_0,
  134394. NULL,
  134395. 0
  134396. };
  134397. static long _vq_quantlist__44u5__p2_0[] = {
  134398. 1,
  134399. 0,
  134400. 2,
  134401. };
  134402. static long _vq_lengthlist__44u5__p2_0[] = {
  134403. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134404. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134405. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134406. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134407. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134408. 9,
  134409. };
  134410. static float _vq_quantthresh__44u5__p2_0[] = {
  134411. -0.5, 0.5,
  134412. };
  134413. static long _vq_quantmap__44u5__p2_0[] = {
  134414. 1, 0, 2,
  134415. };
  134416. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134417. _vq_quantthresh__44u5__p2_0,
  134418. _vq_quantmap__44u5__p2_0,
  134419. 3,
  134420. 3
  134421. };
  134422. static static_codebook _44u5__p2_0 = {
  134423. 4, 81,
  134424. _vq_lengthlist__44u5__p2_0,
  134425. 1, -535822336, 1611661312, 2, 0,
  134426. _vq_quantlist__44u5__p2_0,
  134427. NULL,
  134428. &_vq_auxt__44u5__p2_0,
  134429. NULL,
  134430. 0
  134431. };
  134432. static long _vq_quantlist__44u5__p3_0[] = {
  134433. 2,
  134434. 1,
  134435. 3,
  134436. 0,
  134437. 4,
  134438. };
  134439. static long _vq_lengthlist__44u5__p3_0[] = {
  134440. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134441. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134442. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134443. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134444. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134445. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134446. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134447. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134448. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134449. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134450. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134451. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134452. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134453. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134454. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134455. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134456. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134457. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134458. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134459. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134460. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134461. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134462. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134463. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134464. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134465. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134466. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134467. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134468. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134469. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134470. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134471. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134472. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134473. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134474. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134475. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134476. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134477. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134478. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134479. 0,
  134480. };
  134481. static float _vq_quantthresh__44u5__p3_0[] = {
  134482. -1.5, -0.5, 0.5, 1.5,
  134483. };
  134484. static long _vq_quantmap__44u5__p3_0[] = {
  134485. 3, 1, 0, 2, 4,
  134486. };
  134487. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134488. _vq_quantthresh__44u5__p3_0,
  134489. _vq_quantmap__44u5__p3_0,
  134490. 5,
  134491. 5
  134492. };
  134493. static static_codebook _44u5__p3_0 = {
  134494. 4, 625,
  134495. _vq_lengthlist__44u5__p3_0,
  134496. 1, -533725184, 1611661312, 3, 0,
  134497. _vq_quantlist__44u5__p3_0,
  134498. NULL,
  134499. &_vq_auxt__44u5__p3_0,
  134500. NULL,
  134501. 0
  134502. };
  134503. static long _vq_quantlist__44u5__p4_0[] = {
  134504. 2,
  134505. 1,
  134506. 3,
  134507. 0,
  134508. 4,
  134509. };
  134510. static long _vq_lengthlist__44u5__p4_0[] = {
  134511. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134512. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134513. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134514. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134515. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134516. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134517. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134518. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134519. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134520. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134521. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134522. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134523. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134524. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134525. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134526. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134527. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134528. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134529. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134530. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134531. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134532. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134533. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134534. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134535. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134536. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134537. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134538. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134539. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134540. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134541. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134542. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134543. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134544. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134545. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134546. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134547. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134548. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134549. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134550. 12,
  134551. };
  134552. static float _vq_quantthresh__44u5__p4_0[] = {
  134553. -1.5, -0.5, 0.5, 1.5,
  134554. };
  134555. static long _vq_quantmap__44u5__p4_0[] = {
  134556. 3, 1, 0, 2, 4,
  134557. };
  134558. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134559. _vq_quantthresh__44u5__p4_0,
  134560. _vq_quantmap__44u5__p4_0,
  134561. 5,
  134562. 5
  134563. };
  134564. static static_codebook _44u5__p4_0 = {
  134565. 4, 625,
  134566. _vq_lengthlist__44u5__p4_0,
  134567. 1, -533725184, 1611661312, 3, 0,
  134568. _vq_quantlist__44u5__p4_0,
  134569. NULL,
  134570. &_vq_auxt__44u5__p4_0,
  134571. NULL,
  134572. 0
  134573. };
  134574. static long _vq_quantlist__44u5__p5_0[] = {
  134575. 4,
  134576. 3,
  134577. 5,
  134578. 2,
  134579. 6,
  134580. 1,
  134581. 7,
  134582. 0,
  134583. 8,
  134584. };
  134585. static long _vq_lengthlist__44u5__p5_0[] = {
  134586. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134587. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134588. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134589. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134590. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134591. 14,
  134592. };
  134593. static float _vq_quantthresh__44u5__p5_0[] = {
  134594. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134595. };
  134596. static long _vq_quantmap__44u5__p5_0[] = {
  134597. 7, 5, 3, 1, 0, 2, 4, 6,
  134598. 8,
  134599. };
  134600. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134601. _vq_quantthresh__44u5__p5_0,
  134602. _vq_quantmap__44u5__p5_0,
  134603. 9,
  134604. 9
  134605. };
  134606. static static_codebook _44u5__p5_0 = {
  134607. 2, 81,
  134608. _vq_lengthlist__44u5__p5_0,
  134609. 1, -531628032, 1611661312, 4, 0,
  134610. _vq_quantlist__44u5__p5_0,
  134611. NULL,
  134612. &_vq_auxt__44u5__p5_0,
  134613. NULL,
  134614. 0
  134615. };
  134616. static long _vq_quantlist__44u5__p6_0[] = {
  134617. 4,
  134618. 3,
  134619. 5,
  134620. 2,
  134621. 6,
  134622. 1,
  134623. 7,
  134624. 0,
  134625. 8,
  134626. };
  134627. static long _vq_lengthlist__44u5__p6_0[] = {
  134628. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134629. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134630. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134631. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134632. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134633. 11,
  134634. };
  134635. static float _vq_quantthresh__44u5__p6_0[] = {
  134636. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134637. };
  134638. static long _vq_quantmap__44u5__p6_0[] = {
  134639. 7, 5, 3, 1, 0, 2, 4, 6,
  134640. 8,
  134641. };
  134642. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134643. _vq_quantthresh__44u5__p6_0,
  134644. _vq_quantmap__44u5__p6_0,
  134645. 9,
  134646. 9
  134647. };
  134648. static static_codebook _44u5__p6_0 = {
  134649. 2, 81,
  134650. _vq_lengthlist__44u5__p6_0,
  134651. 1, -531628032, 1611661312, 4, 0,
  134652. _vq_quantlist__44u5__p6_0,
  134653. NULL,
  134654. &_vq_auxt__44u5__p6_0,
  134655. NULL,
  134656. 0
  134657. };
  134658. static long _vq_quantlist__44u5__p7_0[] = {
  134659. 1,
  134660. 0,
  134661. 2,
  134662. };
  134663. static long _vq_lengthlist__44u5__p7_0[] = {
  134664. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134665. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134666. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134667. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134668. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134669. 12,
  134670. };
  134671. static float _vq_quantthresh__44u5__p7_0[] = {
  134672. -5.5, 5.5,
  134673. };
  134674. static long _vq_quantmap__44u5__p7_0[] = {
  134675. 1, 0, 2,
  134676. };
  134677. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134678. _vq_quantthresh__44u5__p7_0,
  134679. _vq_quantmap__44u5__p7_0,
  134680. 3,
  134681. 3
  134682. };
  134683. static static_codebook _44u5__p7_0 = {
  134684. 4, 81,
  134685. _vq_lengthlist__44u5__p7_0,
  134686. 1, -529137664, 1618345984, 2, 0,
  134687. _vq_quantlist__44u5__p7_0,
  134688. NULL,
  134689. &_vq_auxt__44u5__p7_0,
  134690. NULL,
  134691. 0
  134692. };
  134693. static long _vq_quantlist__44u5__p7_1[] = {
  134694. 5,
  134695. 4,
  134696. 6,
  134697. 3,
  134698. 7,
  134699. 2,
  134700. 8,
  134701. 1,
  134702. 9,
  134703. 0,
  134704. 10,
  134705. };
  134706. static long _vq_lengthlist__44u5__p7_1[] = {
  134707. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134708. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134709. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134710. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134711. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134712. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134713. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134714. 9, 9, 9, 9, 9,10,10,10,10,
  134715. };
  134716. static float _vq_quantthresh__44u5__p7_1[] = {
  134717. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134718. 3.5, 4.5,
  134719. };
  134720. static long _vq_quantmap__44u5__p7_1[] = {
  134721. 9, 7, 5, 3, 1, 0, 2, 4,
  134722. 6, 8, 10,
  134723. };
  134724. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134725. _vq_quantthresh__44u5__p7_1,
  134726. _vq_quantmap__44u5__p7_1,
  134727. 11,
  134728. 11
  134729. };
  134730. static static_codebook _44u5__p7_1 = {
  134731. 2, 121,
  134732. _vq_lengthlist__44u5__p7_1,
  134733. 1, -531365888, 1611661312, 4, 0,
  134734. _vq_quantlist__44u5__p7_1,
  134735. NULL,
  134736. &_vq_auxt__44u5__p7_1,
  134737. NULL,
  134738. 0
  134739. };
  134740. static long _vq_quantlist__44u5__p8_0[] = {
  134741. 5,
  134742. 4,
  134743. 6,
  134744. 3,
  134745. 7,
  134746. 2,
  134747. 8,
  134748. 1,
  134749. 9,
  134750. 0,
  134751. 10,
  134752. };
  134753. static long _vq_lengthlist__44u5__p8_0[] = {
  134754. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134755. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134756. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134757. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134758. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134759. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134760. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134761. 12,13,13,14,14,14,14,15,15,
  134762. };
  134763. static float _vq_quantthresh__44u5__p8_0[] = {
  134764. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134765. 38.5, 49.5,
  134766. };
  134767. static long _vq_quantmap__44u5__p8_0[] = {
  134768. 9, 7, 5, 3, 1, 0, 2, 4,
  134769. 6, 8, 10,
  134770. };
  134771. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134772. _vq_quantthresh__44u5__p8_0,
  134773. _vq_quantmap__44u5__p8_0,
  134774. 11,
  134775. 11
  134776. };
  134777. static static_codebook _44u5__p8_0 = {
  134778. 2, 121,
  134779. _vq_lengthlist__44u5__p8_0,
  134780. 1, -524582912, 1618345984, 4, 0,
  134781. _vq_quantlist__44u5__p8_0,
  134782. NULL,
  134783. &_vq_auxt__44u5__p8_0,
  134784. NULL,
  134785. 0
  134786. };
  134787. static long _vq_quantlist__44u5__p8_1[] = {
  134788. 5,
  134789. 4,
  134790. 6,
  134791. 3,
  134792. 7,
  134793. 2,
  134794. 8,
  134795. 1,
  134796. 9,
  134797. 0,
  134798. 10,
  134799. };
  134800. static long _vq_lengthlist__44u5__p8_1[] = {
  134801. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134802. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134803. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134804. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134805. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134806. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134807. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134808. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134809. };
  134810. static float _vq_quantthresh__44u5__p8_1[] = {
  134811. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134812. 3.5, 4.5,
  134813. };
  134814. static long _vq_quantmap__44u5__p8_1[] = {
  134815. 9, 7, 5, 3, 1, 0, 2, 4,
  134816. 6, 8, 10,
  134817. };
  134818. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134819. _vq_quantthresh__44u5__p8_1,
  134820. _vq_quantmap__44u5__p8_1,
  134821. 11,
  134822. 11
  134823. };
  134824. static static_codebook _44u5__p8_1 = {
  134825. 2, 121,
  134826. _vq_lengthlist__44u5__p8_1,
  134827. 1, -531365888, 1611661312, 4, 0,
  134828. _vq_quantlist__44u5__p8_1,
  134829. NULL,
  134830. &_vq_auxt__44u5__p8_1,
  134831. NULL,
  134832. 0
  134833. };
  134834. static long _vq_quantlist__44u5__p9_0[] = {
  134835. 6,
  134836. 5,
  134837. 7,
  134838. 4,
  134839. 8,
  134840. 3,
  134841. 9,
  134842. 2,
  134843. 10,
  134844. 1,
  134845. 11,
  134846. 0,
  134847. 12,
  134848. };
  134849. static long _vq_lengthlist__44u5__p9_0[] = {
  134850. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134851. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134852. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134853. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134854. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134855. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134856. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134857. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134858. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134859. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134860. 12,12,12,12,12,12,12,12,12,
  134861. };
  134862. static float _vq_quantthresh__44u5__p9_0[] = {
  134863. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134864. 637.5, 892.5, 1147.5, 1402.5,
  134865. };
  134866. static long _vq_quantmap__44u5__p9_0[] = {
  134867. 11, 9, 7, 5, 3, 1, 0, 2,
  134868. 4, 6, 8, 10, 12,
  134869. };
  134870. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134871. _vq_quantthresh__44u5__p9_0,
  134872. _vq_quantmap__44u5__p9_0,
  134873. 13,
  134874. 13
  134875. };
  134876. static static_codebook _44u5__p9_0 = {
  134877. 2, 169,
  134878. _vq_lengthlist__44u5__p9_0,
  134879. 1, -514332672, 1627381760, 4, 0,
  134880. _vq_quantlist__44u5__p9_0,
  134881. NULL,
  134882. &_vq_auxt__44u5__p9_0,
  134883. NULL,
  134884. 0
  134885. };
  134886. static long _vq_quantlist__44u5__p9_1[] = {
  134887. 7,
  134888. 6,
  134889. 8,
  134890. 5,
  134891. 9,
  134892. 4,
  134893. 10,
  134894. 3,
  134895. 11,
  134896. 2,
  134897. 12,
  134898. 1,
  134899. 13,
  134900. 0,
  134901. 14,
  134902. };
  134903. static long _vq_lengthlist__44u5__p9_1[] = {
  134904. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134905. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134906. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134907. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134908. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134909. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134910. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134911. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134912. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134913. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134914. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134915. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134916. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134917. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134918. 14,
  134919. };
  134920. static float _vq_quantthresh__44u5__p9_1[] = {
  134921. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134922. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134923. };
  134924. static long _vq_quantmap__44u5__p9_1[] = {
  134925. 13, 11, 9, 7, 5, 3, 1, 0,
  134926. 2, 4, 6, 8, 10, 12, 14,
  134927. };
  134928. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134929. _vq_quantthresh__44u5__p9_1,
  134930. _vq_quantmap__44u5__p9_1,
  134931. 15,
  134932. 15
  134933. };
  134934. static static_codebook _44u5__p9_1 = {
  134935. 2, 225,
  134936. _vq_lengthlist__44u5__p9_1,
  134937. 1, -522338304, 1620115456, 4, 0,
  134938. _vq_quantlist__44u5__p9_1,
  134939. NULL,
  134940. &_vq_auxt__44u5__p9_1,
  134941. NULL,
  134942. 0
  134943. };
  134944. static long _vq_quantlist__44u5__p9_2[] = {
  134945. 8,
  134946. 7,
  134947. 9,
  134948. 6,
  134949. 10,
  134950. 5,
  134951. 11,
  134952. 4,
  134953. 12,
  134954. 3,
  134955. 13,
  134956. 2,
  134957. 14,
  134958. 1,
  134959. 15,
  134960. 0,
  134961. 16,
  134962. };
  134963. static long _vq_lengthlist__44u5__p9_2[] = {
  134964. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134965. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134966. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134967. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134968. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134969. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  134970. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134971. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  134972. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134973. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  134974. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  134975. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  134976. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134977. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134978. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134979. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134980. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  134981. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  134982. 10,
  134983. };
  134984. static float _vq_quantthresh__44u5__p9_2[] = {
  134985. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134986. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134987. };
  134988. static long _vq_quantmap__44u5__p9_2[] = {
  134989. 15, 13, 11, 9, 7, 5, 3, 1,
  134990. 0, 2, 4, 6, 8, 10, 12, 14,
  134991. 16,
  134992. };
  134993. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  134994. _vq_quantthresh__44u5__p9_2,
  134995. _vq_quantmap__44u5__p9_2,
  134996. 17,
  134997. 17
  134998. };
  134999. static static_codebook _44u5__p9_2 = {
  135000. 2, 289,
  135001. _vq_lengthlist__44u5__p9_2,
  135002. 1, -529530880, 1611661312, 5, 0,
  135003. _vq_quantlist__44u5__p9_2,
  135004. NULL,
  135005. &_vq_auxt__44u5__p9_2,
  135006. NULL,
  135007. 0
  135008. };
  135009. static long _huff_lengthlist__44u5__short[] = {
  135010. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  135011. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  135012. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  135013. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  135014. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  135015. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  135016. 6, 8,15,17,
  135017. };
  135018. static static_codebook _huff_book__44u5__short = {
  135019. 2, 100,
  135020. _huff_lengthlist__44u5__short,
  135021. 0, 0, 0, 0, 0,
  135022. NULL,
  135023. NULL,
  135024. NULL,
  135025. NULL,
  135026. 0
  135027. };
  135028. static long _huff_lengthlist__44u6__long[] = {
  135029. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135030. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135031. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135032. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135033. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135034. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135035. 13, 8, 7, 7,
  135036. };
  135037. static static_codebook _huff_book__44u6__long = {
  135038. 2, 100,
  135039. _huff_lengthlist__44u6__long,
  135040. 0, 0, 0, 0, 0,
  135041. NULL,
  135042. NULL,
  135043. NULL,
  135044. NULL,
  135045. 0
  135046. };
  135047. static long _vq_quantlist__44u6__p1_0[] = {
  135048. 1,
  135049. 0,
  135050. 2,
  135051. };
  135052. static long _vq_lengthlist__44u6__p1_0[] = {
  135053. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135054. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135055. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135056. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135057. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135058. 12,
  135059. };
  135060. static float _vq_quantthresh__44u6__p1_0[] = {
  135061. -0.5, 0.5,
  135062. };
  135063. static long _vq_quantmap__44u6__p1_0[] = {
  135064. 1, 0, 2,
  135065. };
  135066. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135067. _vq_quantthresh__44u6__p1_0,
  135068. _vq_quantmap__44u6__p1_0,
  135069. 3,
  135070. 3
  135071. };
  135072. static static_codebook _44u6__p1_0 = {
  135073. 4, 81,
  135074. _vq_lengthlist__44u6__p1_0,
  135075. 1, -535822336, 1611661312, 2, 0,
  135076. _vq_quantlist__44u6__p1_0,
  135077. NULL,
  135078. &_vq_auxt__44u6__p1_0,
  135079. NULL,
  135080. 0
  135081. };
  135082. static long _vq_quantlist__44u6__p2_0[] = {
  135083. 1,
  135084. 0,
  135085. 2,
  135086. };
  135087. static long _vq_lengthlist__44u6__p2_0[] = {
  135088. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135089. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135090. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135091. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135092. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135093. 9,
  135094. };
  135095. static float _vq_quantthresh__44u6__p2_0[] = {
  135096. -0.5, 0.5,
  135097. };
  135098. static long _vq_quantmap__44u6__p2_0[] = {
  135099. 1, 0, 2,
  135100. };
  135101. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135102. _vq_quantthresh__44u6__p2_0,
  135103. _vq_quantmap__44u6__p2_0,
  135104. 3,
  135105. 3
  135106. };
  135107. static static_codebook _44u6__p2_0 = {
  135108. 4, 81,
  135109. _vq_lengthlist__44u6__p2_0,
  135110. 1, -535822336, 1611661312, 2, 0,
  135111. _vq_quantlist__44u6__p2_0,
  135112. NULL,
  135113. &_vq_auxt__44u6__p2_0,
  135114. NULL,
  135115. 0
  135116. };
  135117. static long _vq_quantlist__44u6__p3_0[] = {
  135118. 2,
  135119. 1,
  135120. 3,
  135121. 0,
  135122. 4,
  135123. };
  135124. static long _vq_lengthlist__44u6__p3_0[] = {
  135125. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135126. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135127. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135128. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135129. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135130. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135131. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135132. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135133. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135134. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135135. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135136. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135137. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135138. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135139. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135140. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135141. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135142. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135143. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135144. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135145. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135146. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135147. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135148. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135149. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135150. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135151. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135152. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135153. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135154. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135155. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135156. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135157. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135158. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135159. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135160. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135161. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135162. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135163. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135164. 19,
  135165. };
  135166. static float _vq_quantthresh__44u6__p3_0[] = {
  135167. -1.5, -0.5, 0.5, 1.5,
  135168. };
  135169. static long _vq_quantmap__44u6__p3_0[] = {
  135170. 3, 1, 0, 2, 4,
  135171. };
  135172. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135173. _vq_quantthresh__44u6__p3_0,
  135174. _vq_quantmap__44u6__p3_0,
  135175. 5,
  135176. 5
  135177. };
  135178. static static_codebook _44u6__p3_0 = {
  135179. 4, 625,
  135180. _vq_lengthlist__44u6__p3_0,
  135181. 1, -533725184, 1611661312, 3, 0,
  135182. _vq_quantlist__44u6__p3_0,
  135183. NULL,
  135184. &_vq_auxt__44u6__p3_0,
  135185. NULL,
  135186. 0
  135187. };
  135188. static long _vq_quantlist__44u6__p4_0[] = {
  135189. 2,
  135190. 1,
  135191. 3,
  135192. 0,
  135193. 4,
  135194. };
  135195. static long _vq_lengthlist__44u6__p4_0[] = {
  135196. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135197. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135198. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135199. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135200. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135201. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135202. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135203. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135204. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135205. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135206. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135207. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135208. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135209. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135210. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135211. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135212. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135213. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135214. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135215. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135216. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135217. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135218. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135219. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135220. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135221. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135222. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135223. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135224. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135225. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135226. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135227. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135228. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135229. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135230. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135231. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135232. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135233. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135234. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135235. 13,
  135236. };
  135237. static float _vq_quantthresh__44u6__p4_0[] = {
  135238. -1.5, -0.5, 0.5, 1.5,
  135239. };
  135240. static long _vq_quantmap__44u6__p4_0[] = {
  135241. 3, 1, 0, 2, 4,
  135242. };
  135243. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135244. _vq_quantthresh__44u6__p4_0,
  135245. _vq_quantmap__44u6__p4_0,
  135246. 5,
  135247. 5
  135248. };
  135249. static static_codebook _44u6__p4_0 = {
  135250. 4, 625,
  135251. _vq_lengthlist__44u6__p4_0,
  135252. 1, -533725184, 1611661312, 3, 0,
  135253. _vq_quantlist__44u6__p4_0,
  135254. NULL,
  135255. &_vq_auxt__44u6__p4_0,
  135256. NULL,
  135257. 0
  135258. };
  135259. static long _vq_quantlist__44u6__p5_0[] = {
  135260. 4,
  135261. 3,
  135262. 5,
  135263. 2,
  135264. 6,
  135265. 1,
  135266. 7,
  135267. 0,
  135268. 8,
  135269. };
  135270. static long _vq_lengthlist__44u6__p5_0[] = {
  135271. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135272. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135273. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135274. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135275. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135276. 14,
  135277. };
  135278. static float _vq_quantthresh__44u6__p5_0[] = {
  135279. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135280. };
  135281. static long _vq_quantmap__44u6__p5_0[] = {
  135282. 7, 5, 3, 1, 0, 2, 4, 6,
  135283. 8,
  135284. };
  135285. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135286. _vq_quantthresh__44u6__p5_0,
  135287. _vq_quantmap__44u6__p5_0,
  135288. 9,
  135289. 9
  135290. };
  135291. static static_codebook _44u6__p5_0 = {
  135292. 2, 81,
  135293. _vq_lengthlist__44u6__p5_0,
  135294. 1, -531628032, 1611661312, 4, 0,
  135295. _vq_quantlist__44u6__p5_0,
  135296. NULL,
  135297. &_vq_auxt__44u6__p5_0,
  135298. NULL,
  135299. 0
  135300. };
  135301. static long _vq_quantlist__44u6__p6_0[] = {
  135302. 4,
  135303. 3,
  135304. 5,
  135305. 2,
  135306. 6,
  135307. 1,
  135308. 7,
  135309. 0,
  135310. 8,
  135311. };
  135312. static long _vq_lengthlist__44u6__p6_0[] = {
  135313. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135314. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135315. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135316. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135317. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135318. 12,
  135319. };
  135320. static float _vq_quantthresh__44u6__p6_0[] = {
  135321. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135322. };
  135323. static long _vq_quantmap__44u6__p6_0[] = {
  135324. 7, 5, 3, 1, 0, 2, 4, 6,
  135325. 8,
  135326. };
  135327. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135328. _vq_quantthresh__44u6__p6_0,
  135329. _vq_quantmap__44u6__p6_0,
  135330. 9,
  135331. 9
  135332. };
  135333. static static_codebook _44u6__p6_0 = {
  135334. 2, 81,
  135335. _vq_lengthlist__44u6__p6_0,
  135336. 1, -531628032, 1611661312, 4, 0,
  135337. _vq_quantlist__44u6__p6_0,
  135338. NULL,
  135339. &_vq_auxt__44u6__p6_0,
  135340. NULL,
  135341. 0
  135342. };
  135343. static long _vq_quantlist__44u6__p7_0[] = {
  135344. 1,
  135345. 0,
  135346. 2,
  135347. };
  135348. static long _vq_lengthlist__44u6__p7_0[] = {
  135349. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135350. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135351. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135352. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135353. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135354. 10,
  135355. };
  135356. static float _vq_quantthresh__44u6__p7_0[] = {
  135357. -5.5, 5.5,
  135358. };
  135359. static long _vq_quantmap__44u6__p7_0[] = {
  135360. 1, 0, 2,
  135361. };
  135362. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135363. _vq_quantthresh__44u6__p7_0,
  135364. _vq_quantmap__44u6__p7_0,
  135365. 3,
  135366. 3
  135367. };
  135368. static static_codebook _44u6__p7_0 = {
  135369. 4, 81,
  135370. _vq_lengthlist__44u6__p7_0,
  135371. 1, -529137664, 1618345984, 2, 0,
  135372. _vq_quantlist__44u6__p7_0,
  135373. NULL,
  135374. &_vq_auxt__44u6__p7_0,
  135375. NULL,
  135376. 0
  135377. };
  135378. static long _vq_quantlist__44u6__p7_1[] = {
  135379. 5,
  135380. 4,
  135381. 6,
  135382. 3,
  135383. 7,
  135384. 2,
  135385. 8,
  135386. 1,
  135387. 9,
  135388. 0,
  135389. 10,
  135390. };
  135391. static long _vq_lengthlist__44u6__p7_1[] = {
  135392. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135393. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135394. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135395. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135396. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135397. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135398. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135399. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135400. };
  135401. static float _vq_quantthresh__44u6__p7_1[] = {
  135402. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135403. 3.5, 4.5,
  135404. };
  135405. static long _vq_quantmap__44u6__p7_1[] = {
  135406. 9, 7, 5, 3, 1, 0, 2, 4,
  135407. 6, 8, 10,
  135408. };
  135409. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135410. _vq_quantthresh__44u6__p7_1,
  135411. _vq_quantmap__44u6__p7_1,
  135412. 11,
  135413. 11
  135414. };
  135415. static static_codebook _44u6__p7_1 = {
  135416. 2, 121,
  135417. _vq_lengthlist__44u6__p7_1,
  135418. 1, -531365888, 1611661312, 4, 0,
  135419. _vq_quantlist__44u6__p7_1,
  135420. NULL,
  135421. &_vq_auxt__44u6__p7_1,
  135422. NULL,
  135423. 0
  135424. };
  135425. static long _vq_quantlist__44u6__p8_0[] = {
  135426. 5,
  135427. 4,
  135428. 6,
  135429. 3,
  135430. 7,
  135431. 2,
  135432. 8,
  135433. 1,
  135434. 9,
  135435. 0,
  135436. 10,
  135437. };
  135438. static long _vq_lengthlist__44u6__p8_0[] = {
  135439. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135440. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135441. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135442. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135443. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135444. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135445. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135446. 12,13,13,14,14,14,15,15,15,
  135447. };
  135448. static float _vq_quantthresh__44u6__p8_0[] = {
  135449. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135450. 38.5, 49.5,
  135451. };
  135452. static long _vq_quantmap__44u6__p8_0[] = {
  135453. 9, 7, 5, 3, 1, 0, 2, 4,
  135454. 6, 8, 10,
  135455. };
  135456. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135457. _vq_quantthresh__44u6__p8_0,
  135458. _vq_quantmap__44u6__p8_0,
  135459. 11,
  135460. 11
  135461. };
  135462. static static_codebook _44u6__p8_0 = {
  135463. 2, 121,
  135464. _vq_lengthlist__44u6__p8_0,
  135465. 1, -524582912, 1618345984, 4, 0,
  135466. _vq_quantlist__44u6__p8_0,
  135467. NULL,
  135468. &_vq_auxt__44u6__p8_0,
  135469. NULL,
  135470. 0
  135471. };
  135472. static long _vq_quantlist__44u6__p8_1[] = {
  135473. 5,
  135474. 4,
  135475. 6,
  135476. 3,
  135477. 7,
  135478. 2,
  135479. 8,
  135480. 1,
  135481. 9,
  135482. 0,
  135483. 10,
  135484. };
  135485. static long _vq_lengthlist__44u6__p8_1[] = {
  135486. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135487. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135488. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135489. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135490. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135491. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135492. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135493. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135494. };
  135495. static float _vq_quantthresh__44u6__p8_1[] = {
  135496. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135497. 3.5, 4.5,
  135498. };
  135499. static long _vq_quantmap__44u6__p8_1[] = {
  135500. 9, 7, 5, 3, 1, 0, 2, 4,
  135501. 6, 8, 10,
  135502. };
  135503. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135504. _vq_quantthresh__44u6__p8_1,
  135505. _vq_quantmap__44u6__p8_1,
  135506. 11,
  135507. 11
  135508. };
  135509. static static_codebook _44u6__p8_1 = {
  135510. 2, 121,
  135511. _vq_lengthlist__44u6__p8_1,
  135512. 1, -531365888, 1611661312, 4, 0,
  135513. _vq_quantlist__44u6__p8_1,
  135514. NULL,
  135515. &_vq_auxt__44u6__p8_1,
  135516. NULL,
  135517. 0
  135518. };
  135519. static long _vq_quantlist__44u6__p9_0[] = {
  135520. 7,
  135521. 6,
  135522. 8,
  135523. 5,
  135524. 9,
  135525. 4,
  135526. 10,
  135527. 3,
  135528. 11,
  135529. 2,
  135530. 12,
  135531. 1,
  135532. 13,
  135533. 0,
  135534. 14,
  135535. };
  135536. static long _vq_lengthlist__44u6__p9_0[] = {
  135537. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135538. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135539. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135540. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135541. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135542. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135543. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135544. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135545. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135546. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135547. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135548. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135549. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135550. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135551. 14,
  135552. };
  135553. static float _vq_quantthresh__44u6__p9_0[] = {
  135554. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135555. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135556. };
  135557. static long _vq_quantmap__44u6__p9_0[] = {
  135558. 13, 11, 9, 7, 5, 3, 1, 0,
  135559. 2, 4, 6, 8, 10, 12, 14,
  135560. };
  135561. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135562. _vq_quantthresh__44u6__p9_0,
  135563. _vq_quantmap__44u6__p9_0,
  135564. 15,
  135565. 15
  135566. };
  135567. static static_codebook _44u6__p9_0 = {
  135568. 2, 225,
  135569. _vq_lengthlist__44u6__p9_0,
  135570. 1, -514071552, 1627381760, 4, 0,
  135571. _vq_quantlist__44u6__p9_0,
  135572. NULL,
  135573. &_vq_auxt__44u6__p9_0,
  135574. NULL,
  135575. 0
  135576. };
  135577. static long _vq_quantlist__44u6__p9_1[] = {
  135578. 7,
  135579. 6,
  135580. 8,
  135581. 5,
  135582. 9,
  135583. 4,
  135584. 10,
  135585. 3,
  135586. 11,
  135587. 2,
  135588. 12,
  135589. 1,
  135590. 13,
  135591. 0,
  135592. 14,
  135593. };
  135594. static long _vq_lengthlist__44u6__p9_1[] = {
  135595. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135596. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135597. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135598. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135599. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135600. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135601. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135602. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135603. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135604. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135605. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135606. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135607. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135608. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135609. 13,
  135610. };
  135611. static float _vq_quantthresh__44u6__p9_1[] = {
  135612. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135613. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135614. };
  135615. static long _vq_quantmap__44u6__p9_1[] = {
  135616. 13, 11, 9, 7, 5, 3, 1, 0,
  135617. 2, 4, 6, 8, 10, 12, 14,
  135618. };
  135619. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135620. _vq_quantthresh__44u6__p9_1,
  135621. _vq_quantmap__44u6__p9_1,
  135622. 15,
  135623. 15
  135624. };
  135625. static static_codebook _44u6__p9_1 = {
  135626. 2, 225,
  135627. _vq_lengthlist__44u6__p9_1,
  135628. 1, -522338304, 1620115456, 4, 0,
  135629. _vq_quantlist__44u6__p9_1,
  135630. NULL,
  135631. &_vq_auxt__44u6__p9_1,
  135632. NULL,
  135633. 0
  135634. };
  135635. static long _vq_quantlist__44u6__p9_2[] = {
  135636. 8,
  135637. 7,
  135638. 9,
  135639. 6,
  135640. 10,
  135641. 5,
  135642. 11,
  135643. 4,
  135644. 12,
  135645. 3,
  135646. 13,
  135647. 2,
  135648. 14,
  135649. 1,
  135650. 15,
  135651. 0,
  135652. 16,
  135653. };
  135654. static long _vq_lengthlist__44u6__p9_2[] = {
  135655. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135656. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135657. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135658. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135659. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135660. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135661. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135662. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135663. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135664. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135665. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135666. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135667. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135668. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135669. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135670. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135671. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135672. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135673. 10,
  135674. };
  135675. static float _vq_quantthresh__44u6__p9_2[] = {
  135676. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135677. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135678. };
  135679. static long _vq_quantmap__44u6__p9_2[] = {
  135680. 15, 13, 11, 9, 7, 5, 3, 1,
  135681. 0, 2, 4, 6, 8, 10, 12, 14,
  135682. 16,
  135683. };
  135684. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135685. _vq_quantthresh__44u6__p9_2,
  135686. _vq_quantmap__44u6__p9_2,
  135687. 17,
  135688. 17
  135689. };
  135690. static static_codebook _44u6__p9_2 = {
  135691. 2, 289,
  135692. _vq_lengthlist__44u6__p9_2,
  135693. 1, -529530880, 1611661312, 5, 0,
  135694. _vq_quantlist__44u6__p9_2,
  135695. NULL,
  135696. &_vq_auxt__44u6__p9_2,
  135697. NULL,
  135698. 0
  135699. };
  135700. static long _huff_lengthlist__44u6__short[] = {
  135701. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135702. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135703. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135704. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135705. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135706. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135707. 7, 6, 9,16,
  135708. };
  135709. static static_codebook _huff_book__44u6__short = {
  135710. 2, 100,
  135711. _huff_lengthlist__44u6__short,
  135712. 0, 0, 0, 0, 0,
  135713. NULL,
  135714. NULL,
  135715. NULL,
  135716. NULL,
  135717. 0
  135718. };
  135719. static long _huff_lengthlist__44u7__long[] = {
  135720. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135721. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135722. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135723. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135724. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135725. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135726. 12, 8, 6, 7,
  135727. };
  135728. static static_codebook _huff_book__44u7__long = {
  135729. 2, 100,
  135730. _huff_lengthlist__44u7__long,
  135731. 0, 0, 0, 0, 0,
  135732. NULL,
  135733. NULL,
  135734. NULL,
  135735. NULL,
  135736. 0
  135737. };
  135738. static long _vq_quantlist__44u7__p1_0[] = {
  135739. 1,
  135740. 0,
  135741. 2,
  135742. };
  135743. static long _vq_lengthlist__44u7__p1_0[] = {
  135744. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135745. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135746. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135747. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135748. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135749. 12,
  135750. };
  135751. static float _vq_quantthresh__44u7__p1_0[] = {
  135752. -0.5, 0.5,
  135753. };
  135754. static long _vq_quantmap__44u7__p1_0[] = {
  135755. 1, 0, 2,
  135756. };
  135757. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135758. _vq_quantthresh__44u7__p1_0,
  135759. _vq_quantmap__44u7__p1_0,
  135760. 3,
  135761. 3
  135762. };
  135763. static static_codebook _44u7__p1_0 = {
  135764. 4, 81,
  135765. _vq_lengthlist__44u7__p1_0,
  135766. 1, -535822336, 1611661312, 2, 0,
  135767. _vq_quantlist__44u7__p1_0,
  135768. NULL,
  135769. &_vq_auxt__44u7__p1_0,
  135770. NULL,
  135771. 0
  135772. };
  135773. static long _vq_quantlist__44u7__p2_0[] = {
  135774. 1,
  135775. 0,
  135776. 2,
  135777. };
  135778. static long _vq_lengthlist__44u7__p2_0[] = {
  135779. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135780. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135781. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135782. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135783. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135784. 9,
  135785. };
  135786. static float _vq_quantthresh__44u7__p2_0[] = {
  135787. -0.5, 0.5,
  135788. };
  135789. static long _vq_quantmap__44u7__p2_0[] = {
  135790. 1, 0, 2,
  135791. };
  135792. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135793. _vq_quantthresh__44u7__p2_0,
  135794. _vq_quantmap__44u7__p2_0,
  135795. 3,
  135796. 3
  135797. };
  135798. static static_codebook _44u7__p2_0 = {
  135799. 4, 81,
  135800. _vq_lengthlist__44u7__p2_0,
  135801. 1, -535822336, 1611661312, 2, 0,
  135802. _vq_quantlist__44u7__p2_0,
  135803. NULL,
  135804. &_vq_auxt__44u7__p2_0,
  135805. NULL,
  135806. 0
  135807. };
  135808. static long _vq_quantlist__44u7__p3_0[] = {
  135809. 2,
  135810. 1,
  135811. 3,
  135812. 0,
  135813. 4,
  135814. };
  135815. static long _vq_lengthlist__44u7__p3_0[] = {
  135816. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135817. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135818. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135819. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135820. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135821. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135822. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135823. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135824. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135825. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135826. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135827. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135828. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135829. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135830. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135831. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135832. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135833. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135834. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135835. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135836. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135837. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135838. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135839. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135840. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135841. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135842. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135843. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135844. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135845. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135846. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135847. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135848. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135849. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135850. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135851. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135852. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135853. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135854. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135855. 0,
  135856. };
  135857. static float _vq_quantthresh__44u7__p3_0[] = {
  135858. -1.5, -0.5, 0.5, 1.5,
  135859. };
  135860. static long _vq_quantmap__44u7__p3_0[] = {
  135861. 3, 1, 0, 2, 4,
  135862. };
  135863. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135864. _vq_quantthresh__44u7__p3_0,
  135865. _vq_quantmap__44u7__p3_0,
  135866. 5,
  135867. 5
  135868. };
  135869. static static_codebook _44u7__p3_0 = {
  135870. 4, 625,
  135871. _vq_lengthlist__44u7__p3_0,
  135872. 1, -533725184, 1611661312, 3, 0,
  135873. _vq_quantlist__44u7__p3_0,
  135874. NULL,
  135875. &_vq_auxt__44u7__p3_0,
  135876. NULL,
  135877. 0
  135878. };
  135879. static long _vq_quantlist__44u7__p4_0[] = {
  135880. 2,
  135881. 1,
  135882. 3,
  135883. 0,
  135884. 4,
  135885. };
  135886. static long _vq_lengthlist__44u7__p4_0[] = {
  135887. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135888. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135889. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135890. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135891. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135892. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135893. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135894. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135895. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135896. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135897. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135898. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135899. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135900. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135901. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135902. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135903. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135904. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135905. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135906. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135907. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135908. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135909. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135910. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135911. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135912. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135913. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135914. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135915. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135916. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135917. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135918. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135919. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135920. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135921. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135922. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135923. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135924. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135925. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135926. 14,
  135927. };
  135928. static float _vq_quantthresh__44u7__p4_0[] = {
  135929. -1.5, -0.5, 0.5, 1.5,
  135930. };
  135931. static long _vq_quantmap__44u7__p4_0[] = {
  135932. 3, 1, 0, 2, 4,
  135933. };
  135934. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135935. _vq_quantthresh__44u7__p4_0,
  135936. _vq_quantmap__44u7__p4_0,
  135937. 5,
  135938. 5
  135939. };
  135940. static static_codebook _44u7__p4_0 = {
  135941. 4, 625,
  135942. _vq_lengthlist__44u7__p4_0,
  135943. 1, -533725184, 1611661312, 3, 0,
  135944. _vq_quantlist__44u7__p4_0,
  135945. NULL,
  135946. &_vq_auxt__44u7__p4_0,
  135947. NULL,
  135948. 0
  135949. };
  135950. static long _vq_quantlist__44u7__p5_0[] = {
  135951. 4,
  135952. 3,
  135953. 5,
  135954. 2,
  135955. 6,
  135956. 1,
  135957. 7,
  135958. 0,
  135959. 8,
  135960. };
  135961. static long _vq_lengthlist__44u7__p5_0[] = {
  135962. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135963. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  135964. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  135965. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  135966. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  135967. 14,
  135968. };
  135969. static float _vq_quantthresh__44u7__p5_0[] = {
  135970. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135971. };
  135972. static long _vq_quantmap__44u7__p5_0[] = {
  135973. 7, 5, 3, 1, 0, 2, 4, 6,
  135974. 8,
  135975. };
  135976. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  135977. _vq_quantthresh__44u7__p5_0,
  135978. _vq_quantmap__44u7__p5_0,
  135979. 9,
  135980. 9
  135981. };
  135982. static static_codebook _44u7__p5_0 = {
  135983. 2, 81,
  135984. _vq_lengthlist__44u7__p5_0,
  135985. 1, -531628032, 1611661312, 4, 0,
  135986. _vq_quantlist__44u7__p5_0,
  135987. NULL,
  135988. &_vq_auxt__44u7__p5_0,
  135989. NULL,
  135990. 0
  135991. };
  135992. static long _vq_quantlist__44u7__p6_0[] = {
  135993. 4,
  135994. 3,
  135995. 5,
  135996. 2,
  135997. 6,
  135998. 1,
  135999. 7,
  136000. 0,
  136001. 8,
  136002. };
  136003. static long _vq_lengthlist__44u7__p6_0[] = {
  136004. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  136005. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136006. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136007. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  136008. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  136009. 12,
  136010. };
  136011. static float _vq_quantthresh__44u7__p6_0[] = {
  136012. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136013. };
  136014. static long _vq_quantmap__44u7__p6_0[] = {
  136015. 7, 5, 3, 1, 0, 2, 4, 6,
  136016. 8,
  136017. };
  136018. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  136019. _vq_quantthresh__44u7__p6_0,
  136020. _vq_quantmap__44u7__p6_0,
  136021. 9,
  136022. 9
  136023. };
  136024. static static_codebook _44u7__p6_0 = {
  136025. 2, 81,
  136026. _vq_lengthlist__44u7__p6_0,
  136027. 1, -531628032, 1611661312, 4, 0,
  136028. _vq_quantlist__44u7__p6_0,
  136029. NULL,
  136030. &_vq_auxt__44u7__p6_0,
  136031. NULL,
  136032. 0
  136033. };
  136034. static long _vq_quantlist__44u7__p7_0[] = {
  136035. 1,
  136036. 0,
  136037. 2,
  136038. };
  136039. static long _vq_lengthlist__44u7__p7_0[] = {
  136040. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136041. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136042. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136043. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136044. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136045. 10,
  136046. };
  136047. static float _vq_quantthresh__44u7__p7_0[] = {
  136048. -5.5, 5.5,
  136049. };
  136050. static long _vq_quantmap__44u7__p7_0[] = {
  136051. 1, 0, 2,
  136052. };
  136053. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136054. _vq_quantthresh__44u7__p7_0,
  136055. _vq_quantmap__44u7__p7_0,
  136056. 3,
  136057. 3
  136058. };
  136059. static static_codebook _44u7__p7_0 = {
  136060. 4, 81,
  136061. _vq_lengthlist__44u7__p7_0,
  136062. 1, -529137664, 1618345984, 2, 0,
  136063. _vq_quantlist__44u7__p7_0,
  136064. NULL,
  136065. &_vq_auxt__44u7__p7_0,
  136066. NULL,
  136067. 0
  136068. };
  136069. static long _vq_quantlist__44u7__p7_1[] = {
  136070. 5,
  136071. 4,
  136072. 6,
  136073. 3,
  136074. 7,
  136075. 2,
  136076. 8,
  136077. 1,
  136078. 9,
  136079. 0,
  136080. 10,
  136081. };
  136082. static long _vq_lengthlist__44u7__p7_1[] = {
  136083. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136084. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136085. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136086. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136087. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136088. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136089. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136090. 8, 9, 9, 9, 9, 9,10,10,10,
  136091. };
  136092. static float _vq_quantthresh__44u7__p7_1[] = {
  136093. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136094. 3.5, 4.5,
  136095. };
  136096. static long _vq_quantmap__44u7__p7_1[] = {
  136097. 9, 7, 5, 3, 1, 0, 2, 4,
  136098. 6, 8, 10,
  136099. };
  136100. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136101. _vq_quantthresh__44u7__p7_1,
  136102. _vq_quantmap__44u7__p7_1,
  136103. 11,
  136104. 11
  136105. };
  136106. static static_codebook _44u7__p7_1 = {
  136107. 2, 121,
  136108. _vq_lengthlist__44u7__p7_1,
  136109. 1, -531365888, 1611661312, 4, 0,
  136110. _vq_quantlist__44u7__p7_1,
  136111. NULL,
  136112. &_vq_auxt__44u7__p7_1,
  136113. NULL,
  136114. 0
  136115. };
  136116. static long _vq_quantlist__44u7__p8_0[] = {
  136117. 5,
  136118. 4,
  136119. 6,
  136120. 3,
  136121. 7,
  136122. 2,
  136123. 8,
  136124. 1,
  136125. 9,
  136126. 0,
  136127. 10,
  136128. };
  136129. static long _vq_lengthlist__44u7__p8_0[] = {
  136130. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136131. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136132. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136133. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136134. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136135. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136136. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136137. 12,13,13,14,14,15,15,15,16,
  136138. };
  136139. static float _vq_quantthresh__44u7__p8_0[] = {
  136140. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136141. 38.5, 49.5,
  136142. };
  136143. static long _vq_quantmap__44u7__p8_0[] = {
  136144. 9, 7, 5, 3, 1, 0, 2, 4,
  136145. 6, 8, 10,
  136146. };
  136147. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136148. _vq_quantthresh__44u7__p8_0,
  136149. _vq_quantmap__44u7__p8_0,
  136150. 11,
  136151. 11
  136152. };
  136153. static static_codebook _44u7__p8_0 = {
  136154. 2, 121,
  136155. _vq_lengthlist__44u7__p8_0,
  136156. 1, -524582912, 1618345984, 4, 0,
  136157. _vq_quantlist__44u7__p8_0,
  136158. NULL,
  136159. &_vq_auxt__44u7__p8_0,
  136160. NULL,
  136161. 0
  136162. };
  136163. static long _vq_quantlist__44u7__p8_1[] = {
  136164. 5,
  136165. 4,
  136166. 6,
  136167. 3,
  136168. 7,
  136169. 2,
  136170. 8,
  136171. 1,
  136172. 9,
  136173. 0,
  136174. 10,
  136175. };
  136176. static long _vq_lengthlist__44u7__p8_1[] = {
  136177. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136178. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136179. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136180. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136181. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136182. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136183. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136184. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136185. };
  136186. static float _vq_quantthresh__44u7__p8_1[] = {
  136187. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136188. 3.5, 4.5,
  136189. };
  136190. static long _vq_quantmap__44u7__p8_1[] = {
  136191. 9, 7, 5, 3, 1, 0, 2, 4,
  136192. 6, 8, 10,
  136193. };
  136194. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136195. _vq_quantthresh__44u7__p8_1,
  136196. _vq_quantmap__44u7__p8_1,
  136197. 11,
  136198. 11
  136199. };
  136200. static static_codebook _44u7__p8_1 = {
  136201. 2, 121,
  136202. _vq_lengthlist__44u7__p8_1,
  136203. 1, -531365888, 1611661312, 4, 0,
  136204. _vq_quantlist__44u7__p8_1,
  136205. NULL,
  136206. &_vq_auxt__44u7__p8_1,
  136207. NULL,
  136208. 0
  136209. };
  136210. static long _vq_quantlist__44u7__p9_0[] = {
  136211. 5,
  136212. 4,
  136213. 6,
  136214. 3,
  136215. 7,
  136216. 2,
  136217. 8,
  136218. 1,
  136219. 9,
  136220. 0,
  136221. 10,
  136222. };
  136223. static long _vq_lengthlist__44u7__p9_0[] = {
  136224. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136225. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136226. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136227. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136228. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136229. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136230. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136231. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136232. };
  136233. static float _vq_quantthresh__44u7__p9_0[] = {
  136234. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136235. 2229.5, 2866.5,
  136236. };
  136237. static long _vq_quantmap__44u7__p9_0[] = {
  136238. 9, 7, 5, 3, 1, 0, 2, 4,
  136239. 6, 8, 10,
  136240. };
  136241. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136242. _vq_quantthresh__44u7__p9_0,
  136243. _vq_quantmap__44u7__p9_0,
  136244. 11,
  136245. 11
  136246. };
  136247. static static_codebook _44u7__p9_0 = {
  136248. 2, 121,
  136249. _vq_lengthlist__44u7__p9_0,
  136250. 1, -512171520, 1630791680, 4, 0,
  136251. _vq_quantlist__44u7__p9_0,
  136252. NULL,
  136253. &_vq_auxt__44u7__p9_0,
  136254. NULL,
  136255. 0
  136256. };
  136257. static long _vq_quantlist__44u7__p9_1[] = {
  136258. 6,
  136259. 5,
  136260. 7,
  136261. 4,
  136262. 8,
  136263. 3,
  136264. 9,
  136265. 2,
  136266. 10,
  136267. 1,
  136268. 11,
  136269. 0,
  136270. 12,
  136271. };
  136272. static long _vq_lengthlist__44u7__p9_1[] = {
  136273. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136274. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136275. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136276. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136277. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136278. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136279. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136280. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136281. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136282. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136283. 15,15,15,15,17,17,16,17,16,
  136284. };
  136285. static float _vq_quantthresh__44u7__p9_1[] = {
  136286. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136287. 122.5, 171.5, 220.5, 269.5,
  136288. };
  136289. static long _vq_quantmap__44u7__p9_1[] = {
  136290. 11, 9, 7, 5, 3, 1, 0, 2,
  136291. 4, 6, 8, 10, 12,
  136292. };
  136293. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136294. _vq_quantthresh__44u7__p9_1,
  136295. _vq_quantmap__44u7__p9_1,
  136296. 13,
  136297. 13
  136298. };
  136299. static static_codebook _44u7__p9_1 = {
  136300. 2, 169,
  136301. _vq_lengthlist__44u7__p9_1,
  136302. 1, -518889472, 1622704128, 4, 0,
  136303. _vq_quantlist__44u7__p9_1,
  136304. NULL,
  136305. &_vq_auxt__44u7__p9_1,
  136306. NULL,
  136307. 0
  136308. };
  136309. static long _vq_quantlist__44u7__p9_2[] = {
  136310. 24,
  136311. 23,
  136312. 25,
  136313. 22,
  136314. 26,
  136315. 21,
  136316. 27,
  136317. 20,
  136318. 28,
  136319. 19,
  136320. 29,
  136321. 18,
  136322. 30,
  136323. 17,
  136324. 31,
  136325. 16,
  136326. 32,
  136327. 15,
  136328. 33,
  136329. 14,
  136330. 34,
  136331. 13,
  136332. 35,
  136333. 12,
  136334. 36,
  136335. 11,
  136336. 37,
  136337. 10,
  136338. 38,
  136339. 9,
  136340. 39,
  136341. 8,
  136342. 40,
  136343. 7,
  136344. 41,
  136345. 6,
  136346. 42,
  136347. 5,
  136348. 43,
  136349. 4,
  136350. 44,
  136351. 3,
  136352. 45,
  136353. 2,
  136354. 46,
  136355. 1,
  136356. 47,
  136357. 0,
  136358. 48,
  136359. };
  136360. static long _vq_lengthlist__44u7__p9_2[] = {
  136361. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136362. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136363. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136364. 8,
  136365. };
  136366. static float _vq_quantthresh__44u7__p9_2[] = {
  136367. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136368. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136369. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136370. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136371. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136372. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136373. };
  136374. static long _vq_quantmap__44u7__p9_2[] = {
  136375. 47, 45, 43, 41, 39, 37, 35, 33,
  136376. 31, 29, 27, 25, 23, 21, 19, 17,
  136377. 15, 13, 11, 9, 7, 5, 3, 1,
  136378. 0, 2, 4, 6, 8, 10, 12, 14,
  136379. 16, 18, 20, 22, 24, 26, 28, 30,
  136380. 32, 34, 36, 38, 40, 42, 44, 46,
  136381. 48,
  136382. };
  136383. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136384. _vq_quantthresh__44u7__p9_2,
  136385. _vq_quantmap__44u7__p9_2,
  136386. 49,
  136387. 49
  136388. };
  136389. static static_codebook _44u7__p9_2 = {
  136390. 1, 49,
  136391. _vq_lengthlist__44u7__p9_2,
  136392. 1, -526909440, 1611661312, 6, 0,
  136393. _vq_quantlist__44u7__p9_2,
  136394. NULL,
  136395. &_vq_auxt__44u7__p9_2,
  136396. NULL,
  136397. 0
  136398. };
  136399. static long _huff_lengthlist__44u7__short[] = {
  136400. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136401. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136402. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136403. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136404. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136405. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136406. 6, 8, 5, 9,
  136407. };
  136408. static static_codebook _huff_book__44u7__short = {
  136409. 2, 100,
  136410. _huff_lengthlist__44u7__short,
  136411. 0, 0, 0, 0, 0,
  136412. NULL,
  136413. NULL,
  136414. NULL,
  136415. NULL,
  136416. 0
  136417. };
  136418. static long _huff_lengthlist__44u8__long[] = {
  136419. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136420. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136421. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136422. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136423. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136424. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136425. 10, 8, 8, 9,
  136426. };
  136427. static static_codebook _huff_book__44u8__long = {
  136428. 2, 100,
  136429. _huff_lengthlist__44u8__long,
  136430. 0, 0, 0, 0, 0,
  136431. NULL,
  136432. NULL,
  136433. NULL,
  136434. NULL,
  136435. 0
  136436. };
  136437. static long _huff_lengthlist__44u8__short[] = {
  136438. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136439. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136440. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136441. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136442. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136443. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136444. 10,10,15,17,
  136445. };
  136446. static static_codebook _huff_book__44u8__short = {
  136447. 2, 100,
  136448. _huff_lengthlist__44u8__short,
  136449. 0, 0, 0, 0, 0,
  136450. NULL,
  136451. NULL,
  136452. NULL,
  136453. NULL,
  136454. 0
  136455. };
  136456. static long _vq_quantlist__44u8_p1_0[] = {
  136457. 1,
  136458. 0,
  136459. 2,
  136460. };
  136461. static long _vq_lengthlist__44u8_p1_0[] = {
  136462. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136463. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136464. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136465. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136466. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136467. 10,
  136468. };
  136469. static float _vq_quantthresh__44u8_p1_0[] = {
  136470. -0.5, 0.5,
  136471. };
  136472. static long _vq_quantmap__44u8_p1_0[] = {
  136473. 1, 0, 2,
  136474. };
  136475. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136476. _vq_quantthresh__44u8_p1_0,
  136477. _vq_quantmap__44u8_p1_0,
  136478. 3,
  136479. 3
  136480. };
  136481. static static_codebook _44u8_p1_0 = {
  136482. 4, 81,
  136483. _vq_lengthlist__44u8_p1_0,
  136484. 1, -535822336, 1611661312, 2, 0,
  136485. _vq_quantlist__44u8_p1_0,
  136486. NULL,
  136487. &_vq_auxt__44u8_p1_0,
  136488. NULL,
  136489. 0
  136490. };
  136491. static long _vq_quantlist__44u8_p2_0[] = {
  136492. 2,
  136493. 1,
  136494. 3,
  136495. 0,
  136496. 4,
  136497. };
  136498. static long _vq_lengthlist__44u8_p2_0[] = {
  136499. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136500. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136501. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136502. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136503. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136504. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136505. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136506. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136507. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136508. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136509. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136510. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136511. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136512. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136513. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136514. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136515. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136516. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136517. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136518. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136519. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136520. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136521. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136522. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136523. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136524. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136525. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136526. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136527. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136528. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136529. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136530. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136531. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136532. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136533. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136534. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136535. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136536. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136537. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136538. 14,
  136539. };
  136540. static float _vq_quantthresh__44u8_p2_0[] = {
  136541. -1.5, -0.5, 0.5, 1.5,
  136542. };
  136543. static long _vq_quantmap__44u8_p2_0[] = {
  136544. 3, 1, 0, 2, 4,
  136545. };
  136546. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136547. _vq_quantthresh__44u8_p2_0,
  136548. _vq_quantmap__44u8_p2_0,
  136549. 5,
  136550. 5
  136551. };
  136552. static static_codebook _44u8_p2_0 = {
  136553. 4, 625,
  136554. _vq_lengthlist__44u8_p2_0,
  136555. 1, -533725184, 1611661312, 3, 0,
  136556. _vq_quantlist__44u8_p2_0,
  136557. NULL,
  136558. &_vq_auxt__44u8_p2_0,
  136559. NULL,
  136560. 0
  136561. };
  136562. static long _vq_quantlist__44u8_p3_0[] = {
  136563. 4,
  136564. 3,
  136565. 5,
  136566. 2,
  136567. 6,
  136568. 1,
  136569. 7,
  136570. 0,
  136571. 8,
  136572. };
  136573. static long _vq_lengthlist__44u8_p3_0[] = {
  136574. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136575. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136576. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136577. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136578. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136579. 12,
  136580. };
  136581. static float _vq_quantthresh__44u8_p3_0[] = {
  136582. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136583. };
  136584. static long _vq_quantmap__44u8_p3_0[] = {
  136585. 7, 5, 3, 1, 0, 2, 4, 6,
  136586. 8,
  136587. };
  136588. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136589. _vq_quantthresh__44u8_p3_0,
  136590. _vq_quantmap__44u8_p3_0,
  136591. 9,
  136592. 9
  136593. };
  136594. static static_codebook _44u8_p3_0 = {
  136595. 2, 81,
  136596. _vq_lengthlist__44u8_p3_0,
  136597. 1, -531628032, 1611661312, 4, 0,
  136598. _vq_quantlist__44u8_p3_0,
  136599. NULL,
  136600. &_vq_auxt__44u8_p3_0,
  136601. NULL,
  136602. 0
  136603. };
  136604. static long _vq_quantlist__44u8_p4_0[] = {
  136605. 8,
  136606. 7,
  136607. 9,
  136608. 6,
  136609. 10,
  136610. 5,
  136611. 11,
  136612. 4,
  136613. 12,
  136614. 3,
  136615. 13,
  136616. 2,
  136617. 14,
  136618. 1,
  136619. 15,
  136620. 0,
  136621. 16,
  136622. };
  136623. static long _vq_lengthlist__44u8_p4_0[] = {
  136624. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136625. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136626. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136627. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136628. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136629. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136630. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136631. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136632. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136633. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136634. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136635. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136636. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136637. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136638. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136639. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136640. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136641. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136642. 14,
  136643. };
  136644. static float _vq_quantthresh__44u8_p4_0[] = {
  136645. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136646. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136647. };
  136648. static long _vq_quantmap__44u8_p4_0[] = {
  136649. 15, 13, 11, 9, 7, 5, 3, 1,
  136650. 0, 2, 4, 6, 8, 10, 12, 14,
  136651. 16,
  136652. };
  136653. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136654. _vq_quantthresh__44u8_p4_0,
  136655. _vq_quantmap__44u8_p4_0,
  136656. 17,
  136657. 17
  136658. };
  136659. static static_codebook _44u8_p4_0 = {
  136660. 2, 289,
  136661. _vq_lengthlist__44u8_p4_0,
  136662. 1, -529530880, 1611661312, 5, 0,
  136663. _vq_quantlist__44u8_p4_0,
  136664. NULL,
  136665. &_vq_auxt__44u8_p4_0,
  136666. NULL,
  136667. 0
  136668. };
  136669. static long _vq_quantlist__44u8_p5_0[] = {
  136670. 1,
  136671. 0,
  136672. 2,
  136673. };
  136674. static long _vq_lengthlist__44u8_p5_0[] = {
  136675. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136676. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136677. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136678. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136679. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136680. 10,
  136681. };
  136682. static float _vq_quantthresh__44u8_p5_0[] = {
  136683. -5.5, 5.5,
  136684. };
  136685. static long _vq_quantmap__44u8_p5_0[] = {
  136686. 1, 0, 2,
  136687. };
  136688. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136689. _vq_quantthresh__44u8_p5_0,
  136690. _vq_quantmap__44u8_p5_0,
  136691. 3,
  136692. 3
  136693. };
  136694. static static_codebook _44u8_p5_0 = {
  136695. 4, 81,
  136696. _vq_lengthlist__44u8_p5_0,
  136697. 1, -529137664, 1618345984, 2, 0,
  136698. _vq_quantlist__44u8_p5_0,
  136699. NULL,
  136700. &_vq_auxt__44u8_p5_0,
  136701. NULL,
  136702. 0
  136703. };
  136704. static long _vq_quantlist__44u8_p5_1[] = {
  136705. 5,
  136706. 4,
  136707. 6,
  136708. 3,
  136709. 7,
  136710. 2,
  136711. 8,
  136712. 1,
  136713. 9,
  136714. 0,
  136715. 10,
  136716. };
  136717. static long _vq_lengthlist__44u8_p5_1[] = {
  136718. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136719. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136720. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136721. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136722. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136723. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136724. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136725. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136726. };
  136727. static float _vq_quantthresh__44u8_p5_1[] = {
  136728. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136729. 3.5, 4.5,
  136730. };
  136731. static long _vq_quantmap__44u8_p5_1[] = {
  136732. 9, 7, 5, 3, 1, 0, 2, 4,
  136733. 6, 8, 10,
  136734. };
  136735. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136736. _vq_quantthresh__44u8_p5_1,
  136737. _vq_quantmap__44u8_p5_1,
  136738. 11,
  136739. 11
  136740. };
  136741. static static_codebook _44u8_p5_1 = {
  136742. 2, 121,
  136743. _vq_lengthlist__44u8_p5_1,
  136744. 1, -531365888, 1611661312, 4, 0,
  136745. _vq_quantlist__44u8_p5_1,
  136746. NULL,
  136747. &_vq_auxt__44u8_p5_1,
  136748. NULL,
  136749. 0
  136750. };
  136751. static long _vq_quantlist__44u8_p6_0[] = {
  136752. 6,
  136753. 5,
  136754. 7,
  136755. 4,
  136756. 8,
  136757. 3,
  136758. 9,
  136759. 2,
  136760. 10,
  136761. 1,
  136762. 11,
  136763. 0,
  136764. 12,
  136765. };
  136766. static long _vq_lengthlist__44u8_p6_0[] = {
  136767. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136768. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136769. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136770. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136771. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136772. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136773. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136774. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136775. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136776. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136777. 11,11,11,11,11,12,11,12,12,
  136778. };
  136779. static float _vq_quantthresh__44u8_p6_0[] = {
  136780. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136781. 12.5, 17.5, 22.5, 27.5,
  136782. };
  136783. static long _vq_quantmap__44u8_p6_0[] = {
  136784. 11, 9, 7, 5, 3, 1, 0, 2,
  136785. 4, 6, 8, 10, 12,
  136786. };
  136787. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136788. _vq_quantthresh__44u8_p6_0,
  136789. _vq_quantmap__44u8_p6_0,
  136790. 13,
  136791. 13
  136792. };
  136793. static static_codebook _44u8_p6_0 = {
  136794. 2, 169,
  136795. _vq_lengthlist__44u8_p6_0,
  136796. 1, -526516224, 1616117760, 4, 0,
  136797. _vq_quantlist__44u8_p6_0,
  136798. NULL,
  136799. &_vq_auxt__44u8_p6_0,
  136800. NULL,
  136801. 0
  136802. };
  136803. static long _vq_quantlist__44u8_p6_1[] = {
  136804. 2,
  136805. 1,
  136806. 3,
  136807. 0,
  136808. 4,
  136809. };
  136810. static long _vq_lengthlist__44u8_p6_1[] = {
  136811. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136812. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136813. };
  136814. static float _vq_quantthresh__44u8_p6_1[] = {
  136815. -1.5, -0.5, 0.5, 1.5,
  136816. };
  136817. static long _vq_quantmap__44u8_p6_1[] = {
  136818. 3, 1, 0, 2, 4,
  136819. };
  136820. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136821. _vq_quantthresh__44u8_p6_1,
  136822. _vq_quantmap__44u8_p6_1,
  136823. 5,
  136824. 5
  136825. };
  136826. static static_codebook _44u8_p6_1 = {
  136827. 2, 25,
  136828. _vq_lengthlist__44u8_p6_1,
  136829. 1, -533725184, 1611661312, 3, 0,
  136830. _vq_quantlist__44u8_p6_1,
  136831. NULL,
  136832. &_vq_auxt__44u8_p6_1,
  136833. NULL,
  136834. 0
  136835. };
  136836. static long _vq_quantlist__44u8_p7_0[] = {
  136837. 6,
  136838. 5,
  136839. 7,
  136840. 4,
  136841. 8,
  136842. 3,
  136843. 9,
  136844. 2,
  136845. 10,
  136846. 1,
  136847. 11,
  136848. 0,
  136849. 12,
  136850. };
  136851. static long _vq_lengthlist__44u8_p7_0[] = {
  136852. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136853. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136854. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136855. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136856. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136857. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136858. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136859. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136860. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136861. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136862. 13,13,14,14,14,15,15,15,16,
  136863. };
  136864. static float _vq_quantthresh__44u8_p7_0[] = {
  136865. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136866. 27.5, 38.5, 49.5, 60.5,
  136867. };
  136868. static long _vq_quantmap__44u8_p7_0[] = {
  136869. 11, 9, 7, 5, 3, 1, 0, 2,
  136870. 4, 6, 8, 10, 12,
  136871. };
  136872. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136873. _vq_quantthresh__44u8_p7_0,
  136874. _vq_quantmap__44u8_p7_0,
  136875. 13,
  136876. 13
  136877. };
  136878. static static_codebook _44u8_p7_0 = {
  136879. 2, 169,
  136880. _vq_lengthlist__44u8_p7_0,
  136881. 1, -523206656, 1618345984, 4, 0,
  136882. _vq_quantlist__44u8_p7_0,
  136883. NULL,
  136884. &_vq_auxt__44u8_p7_0,
  136885. NULL,
  136886. 0
  136887. };
  136888. static long _vq_quantlist__44u8_p7_1[] = {
  136889. 5,
  136890. 4,
  136891. 6,
  136892. 3,
  136893. 7,
  136894. 2,
  136895. 8,
  136896. 1,
  136897. 9,
  136898. 0,
  136899. 10,
  136900. };
  136901. static long _vq_lengthlist__44u8_p7_1[] = {
  136902. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136903. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136904. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136905. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136906. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136907. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136908. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136909. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136910. };
  136911. static float _vq_quantthresh__44u8_p7_1[] = {
  136912. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136913. 3.5, 4.5,
  136914. };
  136915. static long _vq_quantmap__44u8_p7_1[] = {
  136916. 9, 7, 5, 3, 1, 0, 2, 4,
  136917. 6, 8, 10,
  136918. };
  136919. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136920. _vq_quantthresh__44u8_p7_1,
  136921. _vq_quantmap__44u8_p7_1,
  136922. 11,
  136923. 11
  136924. };
  136925. static static_codebook _44u8_p7_1 = {
  136926. 2, 121,
  136927. _vq_lengthlist__44u8_p7_1,
  136928. 1, -531365888, 1611661312, 4, 0,
  136929. _vq_quantlist__44u8_p7_1,
  136930. NULL,
  136931. &_vq_auxt__44u8_p7_1,
  136932. NULL,
  136933. 0
  136934. };
  136935. static long _vq_quantlist__44u8_p8_0[] = {
  136936. 7,
  136937. 6,
  136938. 8,
  136939. 5,
  136940. 9,
  136941. 4,
  136942. 10,
  136943. 3,
  136944. 11,
  136945. 2,
  136946. 12,
  136947. 1,
  136948. 13,
  136949. 0,
  136950. 14,
  136951. };
  136952. static long _vq_lengthlist__44u8_p8_0[] = {
  136953. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  136954. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  136955. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  136956. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  136957. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  136958. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  136959. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  136960. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  136961. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  136962. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  136963. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  136964. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  136965. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  136966. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  136967. 17,
  136968. };
  136969. static float _vq_quantthresh__44u8_p8_0[] = {
  136970. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  136971. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  136972. };
  136973. static long _vq_quantmap__44u8_p8_0[] = {
  136974. 13, 11, 9, 7, 5, 3, 1, 0,
  136975. 2, 4, 6, 8, 10, 12, 14,
  136976. };
  136977. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  136978. _vq_quantthresh__44u8_p8_0,
  136979. _vq_quantmap__44u8_p8_0,
  136980. 15,
  136981. 15
  136982. };
  136983. static static_codebook _44u8_p8_0 = {
  136984. 2, 225,
  136985. _vq_lengthlist__44u8_p8_0,
  136986. 1, -520986624, 1620377600, 4, 0,
  136987. _vq_quantlist__44u8_p8_0,
  136988. NULL,
  136989. &_vq_auxt__44u8_p8_0,
  136990. NULL,
  136991. 0
  136992. };
  136993. static long _vq_quantlist__44u8_p8_1[] = {
  136994. 10,
  136995. 9,
  136996. 11,
  136997. 8,
  136998. 12,
  136999. 7,
  137000. 13,
  137001. 6,
  137002. 14,
  137003. 5,
  137004. 15,
  137005. 4,
  137006. 16,
  137007. 3,
  137008. 17,
  137009. 2,
  137010. 18,
  137011. 1,
  137012. 19,
  137013. 0,
  137014. 20,
  137015. };
  137016. static long _vq_lengthlist__44u8_p8_1[] = {
  137017. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137018. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137019. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  137020. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137021. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137022. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137023. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137024. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137025. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137026. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137027. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137028. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137029. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137030. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137031. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137032. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137033. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137034. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137035. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137036. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137037. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137038. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137039. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137040. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137041. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137042. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137043. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137044. 10,10,10,10,10,10,10,10,10,
  137045. };
  137046. static float _vq_quantthresh__44u8_p8_1[] = {
  137047. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137048. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137049. 6.5, 7.5, 8.5, 9.5,
  137050. };
  137051. static long _vq_quantmap__44u8_p8_1[] = {
  137052. 19, 17, 15, 13, 11, 9, 7, 5,
  137053. 3, 1, 0, 2, 4, 6, 8, 10,
  137054. 12, 14, 16, 18, 20,
  137055. };
  137056. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137057. _vq_quantthresh__44u8_p8_1,
  137058. _vq_quantmap__44u8_p8_1,
  137059. 21,
  137060. 21
  137061. };
  137062. static static_codebook _44u8_p8_1 = {
  137063. 2, 441,
  137064. _vq_lengthlist__44u8_p8_1,
  137065. 1, -529268736, 1611661312, 5, 0,
  137066. _vq_quantlist__44u8_p8_1,
  137067. NULL,
  137068. &_vq_auxt__44u8_p8_1,
  137069. NULL,
  137070. 0
  137071. };
  137072. static long _vq_quantlist__44u8_p9_0[] = {
  137073. 4,
  137074. 3,
  137075. 5,
  137076. 2,
  137077. 6,
  137078. 1,
  137079. 7,
  137080. 0,
  137081. 8,
  137082. };
  137083. static long _vq_lengthlist__44u8_p9_0[] = {
  137084. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137085. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137086. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137087. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137088. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137089. 8,
  137090. };
  137091. static float _vq_quantthresh__44u8_p9_0[] = {
  137092. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137093. };
  137094. static long _vq_quantmap__44u8_p9_0[] = {
  137095. 7, 5, 3, 1, 0, 2, 4, 6,
  137096. 8,
  137097. };
  137098. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137099. _vq_quantthresh__44u8_p9_0,
  137100. _vq_quantmap__44u8_p9_0,
  137101. 9,
  137102. 9
  137103. };
  137104. static static_codebook _44u8_p9_0 = {
  137105. 2, 81,
  137106. _vq_lengthlist__44u8_p9_0,
  137107. 1, -511895552, 1631393792, 4, 0,
  137108. _vq_quantlist__44u8_p9_0,
  137109. NULL,
  137110. &_vq_auxt__44u8_p9_0,
  137111. NULL,
  137112. 0
  137113. };
  137114. static long _vq_quantlist__44u8_p9_1[] = {
  137115. 9,
  137116. 8,
  137117. 10,
  137118. 7,
  137119. 11,
  137120. 6,
  137121. 12,
  137122. 5,
  137123. 13,
  137124. 4,
  137125. 14,
  137126. 3,
  137127. 15,
  137128. 2,
  137129. 16,
  137130. 1,
  137131. 17,
  137132. 0,
  137133. 18,
  137134. };
  137135. static long _vq_lengthlist__44u8_p9_1[] = {
  137136. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137137. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137138. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137139. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137140. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137141. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137142. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137143. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137144. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137145. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137146. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137147. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137148. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137149. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137150. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137151. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137152. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137153. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137154. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137155. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137156. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137157. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137158. 16,15,16,16,16,16,16,16,16,
  137159. };
  137160. static float _vq_quantthresh__44u8_p9_1[] = {
  137161. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137162. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137163. 367.5, 416.5,
  137164. };
  137165. static long _vq_quantmap__44u8_p9_1[] = {
  137166. 17, 15, 13, 11, 9, 7, 5, 3,
  137167. 1, 0, 2, 4, 6, 8, 10, 12,
  137168. 14, 16, 18,
  137169. };
  137170. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137171. _vq_quantthresh__44u8_p9_1,
  137172. _vq_quantmap__44u8_p9_1,
  137173. 19,
  137174. 19
  137175. };
  137176. static static_codebook _44u8_p9_1 = {
  137177. 2, 361,
  137178. _vq_lengthlist__44u8_p9_1,
  137179. 1, -518287360, 1622704128, 5, 0,
  137180. _vq_quantlist__44u8_p9_1,
  137181. NULL,
  137182. &_vq_auxt__44u8_p9_1,
  137183. NULL,
  137184. 0
  137185. };
  137186. static long _vq_quantlist__44u8_p9_2[] = {
  137187. 24,
  137188. 23,
  137189. 25,
  137190. 22,
  137191. 26,
  137192. 21,
  137193. 27,
  137194. 20,
  137195. 28,
  137196. 19,
  137197. 29,
  137198. 18,
  137199. 30,
  137200. 17,
  137201. 31,
  137202. 16,
  137203. 32,
  137204. 15,
  137205. 33,
  137206. 14,
  137207. 34,
  137208. 13,
  137209. 35,
  137210. 12,
  137211. 36,
  137212. 11,
  137213. 37,
  137214. 10,
  137215. 38,
  137216. 9,
  137217. 39,
  137218. 8,
  137219. 40,
  137220. 7,
  137221. 41,
  137222. 6,
  137223. 42,
  137224. 5,
  137225. 43,
  137226. 4,
  137227. 44,
  137228. 3,
  137229. 45,
  137230. 2,
  137231. 46,
  137232. 1,
  137233. 47,
  137234. 0,
  137235. 48,
  137236. };
  137237. static long _vq_lengthlist__44u8_p9_2[] = {
  137238. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137239. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137240. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137241. 7,
  137242. };
  137243. static float _vq_quantthresh__44u8_p9_2[] = {
  137244. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137245. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137246. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137247. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137248. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137249. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137250. };
  137251. static long _vq_quantmap__44u8_p9_2[] = {
  137252. 47, 45, 43, 41, 39, 37, 35, 33,
  137253. 31, 29, 27, 25, 23, 21, 19, 17,
  137254. 15, 13, 11, 9, 7, 5, 3, 1,
  137255. 0, 2, 4, 6, 8, 10, 12, 14,
  137256. 16, 18, 20, 22, 24, 26, 28, 30,
  137257. 32, 34, 36, 38, 40, 42, 44, 46,
  137258. 48,
  137259. };
  137260. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137261. _vq_quantthresh__44u8_p9_2,
  137262. _vq_quantmap__44u8_p9_2,
  137263. 49,
  137264. 49
  137265. };
  137266. static static_codebook _44u8_p9_2 = {
  137267. 1, 49,
  137268. _vq_lengthlist__44u8_p9_2,
  137269. 1, -526909440, 1611661312, 6, 0,
  137270. _vq_quantlist__44u8_p9_2,
  137271. NULL,
  137272. &_vq_auxt__44u8_p9_2,
  137273. NULL,
  137274. 0
  137275. };
  137276. static long _huff_lengthlist__44u9__long[] = {
  137277. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137278. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137279. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137280. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137281. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137282. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137283. 10, 8, 8, 9,
  137284. };
  137285. static static_codebook _huff_book__44u9__long = {
  137286. 2, 100,
  137287. _huff_lengthlist__44u9__long,
  137288. 0, 0, 0, 0, 0,
  137289. NULL,
  137290. NULL,
  137291. NULL,
  137292. NULL,
  137293. 0
  137294. };
  137295. static long _huff_lengthlist__44u9__short[] = {
  137296. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137297. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137298. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137299. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137300. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137301. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137302. 9, 9,12,15,
  137303. };
  137304. static static_codebook _huff_book__44u9__short = {
  137305. 2, 100,
  137306. _huff_lengthlist__44u9__short,
  137307. 0, 0, 0, 0, 0,
  137308. NULL,
  137309. NULL,
  137310. NULL,
  137311. NULL,
  137312. 0
  137313. };
  137314. static long _vq_quantlist__44u9_p1_0[] = {
  137315. 1,
  137316. 0,
  137317. 2,
  137318. };
  137319. static long _vq_lengthlist__44u9_p1_0[] = {
  137320. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137321. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137322. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137323. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137324. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137325. 10,
  137326. };
  137327. static float _vq_quantthresh__44u9_p1_0[] = {
  137328. -0.5, 0.5,
  137329. };
  137330. static long _vq_quantmap__44u9_p1_0[] = {
  137331. 1, 0, 2,
  137332. };
  137333. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137334. _vq_quantthresh__44u9_p1_0,
  137335. _vq_quantmap__44u9_p1_0,
  137336. 3,
  137337. 3
  137338. };
  137339. static static_codebook _44u9_p1_0 = {
  137340. 4, 81,
  137341. _vq_lengthlist__44u9_p1_0,
  137342. 1, -535822336, 1611661312, 2, 0,
  137343. _vq_quantlist__44u9_p1_0,
  137344. NULL,
  137345. &_vq_auxt__44u9_p1_0,
  137346. NULL,
  137347. 0
  137348. };
  137349. static long _vq_quantlist__44u9_p2_0[] = {
  137350. 2,
  137351. 1,
  137352. 3,
  137353. 0,
  137354. 4,
  137355. };
  137356. static long _vq_lengthlist__44u9_p2_0[] = {
  137357. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137358. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137359. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137360. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137361. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137362. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137363. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137364. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137365. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137366. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137367. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137368. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137369. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137370. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137371. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137372. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137373. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137374. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137375. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137376. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137377. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137378. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137379. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137380. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137381. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137382. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137383. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137384. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137385. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137386. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137387. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137388. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137389. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137390. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137391. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137392. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137393. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137394. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137395. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137396. 14,
  137397. };
  137398. static float _vq_quantthresh__44u9_p2_0[] = {
  137399. -1.5, -0.5, 0.5, 1.5,
  137400. };
  137401. static long _vq_quantmap__44u9_p2_0[] = {
  137402. 3, 1, 0, 2, 4,
  137403. };
  137404. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137405. _vq_quantthresh__44u9_p2_0,
  137406. _vq_quantmap__44u9_p2_0,
  137407. 5,
  137408. 5
  137409. };
  137410. static static_codebook _44u9_p2_0 = {
  137411. 4, 625,
  137412. _vq_lengthlist__44u9_p2_0,
  137413. 1, -533725184, 1611661312, 3, 0,
  137414. _vq_quantlist__44u9_p2_0,
  137415. NULL,
  137416. &_vq_auxt__44u9_p2_0,
  137417. NULL,
  137418. 0
  137419. };
  137420. static long _vq_quantlist__44u9_p3_0[] = {
  137421. 4,
  137422. 3,
  137423. 5,
  137424. 2,
  137425. 6,
  137426. 1,
  137427. 7,
  137428. 0,
  137429. 8,
  137430. };
  137431. static long _vq_lengthlist__44u9_p3_0[] = {
  137432. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137433. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137434. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137435. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137436. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137437. 11,
  137438. };
  137439. static float _vq_quantthresh__44u9_p3_0[] = {
  137440. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137441. };
  137442. static long _vq_quantmap__44u9_p3_0[] = {
  137443. 7, 5, 3, 1, 0, 2, 4, 6,
  137444. 8,
  137445. };
  137446. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137447. _vq_quantthresh__44u9_p3_0,
  137448. _vq_quantmap__44u9_p3_0,
  137449. 9,
  137450. 9
  137451. };
  137452. static static_codebook _44u9_p3_0 = {
  137453. 2, 81,
  137454. _vq_lengthlist__44u9_p3_0,
  137455. 1, -531628032, 1611661312, 4, 0,
  137456. _vq_quantlist__44u9_p3_0,
  137457. NULL,
  137458. &_vq_auxt__44u9_p3_0,
  137459. NULL,
  137460. 0
  137461. };
  137462. static long _vq_quantlist__44u9_p4_0[] = {
  137463. 8,
  137464. 7,
  137465. 9,
  137466. 6,
  137467. 10,
  137468. 5,
  137469. 11,
  137470. 4,
  137471. 12,
  137472. 3,
  137473. 13,
  137474. 2,
  137475. 14,
  137476. 1,
  137477. 15,
  137478. 0,
  137479. 16,
  137480. };
  137481. static long _vq_lengthlist__44u9_p4_0[] = {
  137482. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137483. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137484. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137485. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137486. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137487. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137488. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137489. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137490. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137491. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137492. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137493. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137494. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137495. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137496. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137497. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137498. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137499. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137500. 14,
  137501. };
  137502. static float _vq_quantthresh__44u9_p4_0[] = {
  137503. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137504. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137505. };
  137506. static long _vq_quantmap__44u9_p4_0[] = {
  137507. 15, 13, 11, 9, 7, 5, 3, 1,
  137508. 0, 2, 4, 6, 8, 10, 12, 14,
  137509. 16,
  137510. };
  137511. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137512. _vq_quantthresh__44u9_p4_0,
  137513. _vq_quantmap__44u9_p4_0,
  137514. 17,
  137515. 17
  137516. };
  137517. static static_codebook _44u9_p4_0 = {
  137518. 2, 289,
  137519. _vq_lengthlist__44u9_p4_0,
  137520. 1, -529530880, 1611661312, 5, 0,
  137521. _vq_quantlist__44u9_p4_0,
  137522. NULL,
  137523. &_vq_auxt__44u9_p4_0,
  137524. NULL,
  137525. 0
  137526. };
  137527. static long _vq_quantlist__44u9_p5_0[] = {
  137528. 1,
  137529. 0,
  137530. 2,
  137531. };
  137532. static long _vq_lengthlist__44u9_p5_0[] = {
  137533. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137534. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137535. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137536. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137537. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137538. 10,
  137539. };
  137540. static float _vq_quantthresh__44u9_p5_0[] = {
  137541. -5.5, 5.5,
  137542. };
  137543. static long _vq_quantmap__44u9_p5_0[] = {
  137544. 1, 0, 2,
  137545. };
  137546. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137547. _vq_quantthresh__44u9_p5_0,
  137548. _vq_quantmap__44u9_p5_0,
  137549. 3,
  137550. 3
  137551. };
  137552. static static_codebook _44u9_p5_0 = {
  137553. 4, 81,
  137554. _vq_lengthlist__44u9_p5_0,
  137555. 1, -529137664, 1618345984, 2, 0,
  137556. _vq_quantlist__44u9_p5_0,
  137557. NULL,
  137558. &_vq_auxt__44u9_p5_0,
  137559. NULL,
  137560. 0
  137561. };
  137562. static long _vq_quantlist__44u9_p5_1[] = {
  137563. 5,
  137564. 4,
  137565. 6,
  137566. 3,
  137567. 7,
  137568. 2,
  137569. 8,
  137570. 1,
  137571. 9,
  137572. 0,
  137573. 10,
  137574. };
  137575. static long _vq_lengthlist__44u9_p5_1[] = {
  137576. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137577. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137578. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137579. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137580. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137581. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137582. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137583. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137584. };
  137585. static float _vq_quantthresh__44u9_p5_1[] = {
  137586. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137587. 3.5, 4.5,
  137588. };
  137589. static long _vq_quantmap__44u9_p5_1[] = {
  137590. 9, 7, 5, 3, 1, 0, 2, 4,
  137591. 6, 8, 10,
  137592. };
  137593. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137594. _vq_quantthresh__44u9_p5_1,
  137595. _vq_quantmap__44u9_p5_1,
  137596. 11,
  137597. 11
  137598. };
  137599. static static_codebook _44u9_p5_1 = {
  137600. 2, 121,
  137601. _vq_lengthlist__44u9_p5_1,
  137602. 1, -531365888, 1611661312, 4, 0,
  137603. _vq_quantlist__44u9_p5_1,
  137604. NULL,
  137605. &_vq_auxt__44u9_p5_1,
  137606. NULL,
  137607. 0
  137608. };
  137609. static long _vq_quantlist__44u9_p6_0[] = {
  137610. 6,
  137611. 5,
  137612. 7,
  137613. 4,
  137614. 8,
  137615. 3,
  137616. 9,
  137617. 2,
  137618. 10,
  137619. 1,
  137620. 11,
  137621. 0,
  137622. 12,
  137623. };
  137624. static long _vq_lengthlist__44u9_p6_0[] = {
  137625. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137626. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137627. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137628. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137629. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137630. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137631. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137632. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137633. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137634. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137635. 10,11,11,11,11,12,11,12,12,
  137636. };
  137637. static float _vq_quantthresh__44u9_p6_0[] = {
  137638. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137639. 12.5, 17.5, 22.5, 27.5,
  137640. };
  137641. static long _vq_quantmap__44u9_p6_0[] = {
  137642. 11, 9, 7, 5, 3, 1, 0, 2,
  137643. 4, 6, 8, 10, 12,
  137644. };
  137645. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137646. _vq_quantthresh__44u9_p6_0,
  137647. _vq_quantmap__44u9_p6_0,
  137648. 13,
  137649. 13
  137650. };
  137651. static static_codebook _44u9_p6_0 = {
  137652. 2, 169,
  137653. _vq_lengthlist__44u9_p6_0,
  137654. 1, -526516224, 1616117760, 4, 0,
  137655. _vq_quantlist__44u9_p6_0,
  137656. NULL,
  137657. &_vq_auxt__44u9_p6_0,
  137658. NULL,
  137659. 0
  137660. };
  137661. static long _vq_quantlist__44u9_p6_1[] = {
  137662. 2,
  137663. 1,
  137664. 3,
  137665. 0,
  137666. 4,
  137667. };
  137668. static long _vq_lengthlist__44u9_p6_1[] = {
  137669. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137670. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137671. };
  137672. static float _vq_quantthresh__44u9_p6_1[] = {
  137673. -1.5, -0.5, 0.5, 1.5,
  137674. };
  137675. static long _vq_quantmap__44u9_p6_1[] = {
  137676. 3, 1, 0, 2, 4,
  137677. };
  137678. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137679. _vq_quantthresh__44u9_p6_1,
  137680. _vq_quantmap__44u9_p6_1,
  137681. 5,
  137682. 5
  137683. };
  137684. static static_codebook _44u9_p6_1 = {
  137685. 2, 25,
  137686. _vq_lengthlist__44u9_p6_1,
  137687. 1, -533725184, 1611661312, 3, 0,
  137688. _vq_quantlist__44u9_p6_1,
  137689. NULL,
  137690. &_vq_auxt__44u9_p6_1,
  137691. NULL,
  137692. 0
  137693. };
  137694. static long _vq_quantlist__44u9_p7_0[] = {
  137695. 6,
  137696. 5,
  137697. 7,
  137698. 4,
  137699. 8,
  137700. 3,
  137701. 9,
  137702. 2,
  137703. 10,
  137704. 1,
  137705. 11,
  137706. 0,
  137707. 12,
  137708. };
  137709. static long _vq_lengthlist__44u9_p7_0[] = {
  137710. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137711. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137712. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137713. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137714. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137715. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137716. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137717. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137718. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137719. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137720. 12,13,13,14,14,14,15,15,15,
  137721. };
  137722. static float _vq_quantthresh__44u9_p7_0[] = {
  137723. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137724. 27.5, 38.5, 49.5, 60.5,
  137725. };
  137726. static long _vq_quantmap__44u9_p7_0[] = {
  137727. 11, 9, 7, 5, 3, 1, 0, 2,
  137728. 4, 6, 8, 10, 12,
  137729. };
  137730. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137731. _vq_quantthresh__44u9_p7_0,
  137732. _vq_quantmap__44u9_p7_0,
  137733. 13,
  137734. 13
  137735. };
  137736. static static_codebook _44u9_p7_0 = {
  137737. 2, 169,
  137738. _vq_lengthlist__44u9_p7_0,
  137739. 1, -523206656, 1618345984, 4, 0,
  137740. _vq_quantlist__44u9_p7_0,
  137741. NULL,
  137742. &_vq_auxt__44u9_p7_0,
  137743. NULL,
  137744. 0
  137745. };
  137746. static long _vq_quantlist__44u9_p7_1[] = {
  137747. 5,
  137748. 4,
  137749. 6,
  137750. 3,
  137751. 7,
  137752. 2,
  137753. 8,
  137754. 1,
  137755. 9,
  137756. 0,
  137757. 10,
  137758. };
  137759. static long _vq_lengthlist__44u9_p7_1[] = {
  137760. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137761. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137762. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137763. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137764. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137765. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137766. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137767. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137768. };
  137769. static float _vq_quantthresh__44u9_p7_1[] = {
  137770. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137771. 3.5, 4.5,
  137772. };
  137773. static long _vq_quantmap__44u9_p7_1[] = {
  137774. 9, 7, 5, 3, 1, 0, 2, 4,
  137775. 6, 8, 10,
  137776. };
  137777. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137778. _vq_quantthresh__44u9_p7_1,
  137779. _vq_quantmap__44u9_p7_1,
  137780. 11,
  137781. 11
  137782. };
  137783. static static_codebook _44u9_p7_1 = {
  137784. 2, 121,
  137785. _vq_lengthlist__44u9_p7_1,
  137786. 1, -531365888, 1611661312, 4, 0,
  137787. _vq_quantlist__44u9_p7_1,
  137788. NULL,
  137789. &_vq_auxt__44u9_p7_1,
  137790. NULL,
  137791. 0
  137792. };
  137793. static long _vq_quantlist__44u9_p8_0[] = {
  137794. 7,
  137795. 6,
  137796. 8,
  137797. 5,
  137798. 9,
  137799. 4,
  137800. 10,
  137801. 3,
  137802. 11,
  137803. 2,
  137804. 12,
  137805. 1,
  137806. 13,
  137807. 0,
  137808. 14,
  137809. };
  137810. static long _vq_lengthlist__44u9_p8_0[] = {
  137811. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137812. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137813. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137814. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137815. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137816. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137817. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137818. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137819. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137820. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137821. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137822. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137823. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137824. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137825. 15,
  137826. };
  137827. static float _vq_quantthresh__44u9_p8_0[] = {
  137828. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137829. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137830. };
  137831. static long _vq_quantmap__44u9_p8_0[] = {
  137832. 13, 11, 9, 7, 5, 3, 1, 0,
  137833. 2, 4, 6, 8, 10, 12, 14,
  137834. };
  137835. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137836. _vq_quantthresh__44u9_p8_0,
  137837. _vq_quantmap__44u9_p8_0,
  137838. 15,
  137839. 15
  137840. };
  137841. static static_codebook _44u9_p8_0 = {
  137842. 2, 225,
  137843. _vq_lengthlist__44u9_p8_0,
  137844. 1, -520986624, 1620377600, 4, 0,
  137845. _vq_quantlist__44u9_p8_0,
  137846. NULL,
  137847. &_vq_auxt__44u9_p8_0,
  137848. NULL,
  137849. 0
  137850. };
  137851. static long _vq_quantlist__44u9_p8_1[] = {
  137852. 10,
  137853. 9,
  137854. 11,
  137855. 8,
  137856. 12,
  137857. 7,
  137858. 13,
  137859. 6,
  137860. 14,
  137861. 5,
  137862. 15,
  137863. 4,
  137864. 16,
  137865. 3,
  137866. 17,
  137867. 2,
  137868. 18,
  137869. 1,
  137870. 19,
  137871. 0,
  137872. 20,
  137873. };
  137874. static long _vq_lengthlist__44u9_p8_1[] = {
  137875. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137876. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137877. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137878. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137879. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137880. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137881. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137882. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137883. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137884. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137885. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137886. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137887. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137888. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137889. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137890. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137891. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137892. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137893. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137894. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137895. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137896. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137897. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137898. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137899. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137900. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137901. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137902. 10,10,10,10,10,10,10,10,10,
  137903. };
  137904. static float _vq_quantthresh__44u9_p8_1[] = {
  137905. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137906. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137907. 6.5, 7.5, 8.5, 9.5,
  137908. };
  137909. static long _vq_quantmap__44u9_p8_1[] = {
  137910. 19, 17, 15, 13, 11, 9, 7, 5,
  137911. 3, 1, 0, 2, 4, 6, 8, 10,
  137912. 12, 14, 16, 18, 20,
  137913. };
  137914. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137915. _vq_quantthresh__44u9_p8_1,
  137916. _vq_quantmap__44u9_p8_1,
  137917. 21,
  137918. 21
  137919. };
  137920. static static_codebook _44u9_p8_1 = {
  137921. 2, 441,
  137922. _vq_lengthlist__44u9_p8_1,
  137923. 1, -529268736, 1611661312, 5, 0,
  137924. _vq_quantlist__44u9_p8_1,
  137925. NULL,
  137926. &_vq_auxt__44u9_p8_1,
  137927. NULL,
  137928. 0
  137929. };
  137930. static long _vq_quantlist__44u9_p9_0[] = {
  137931. 7,
  137932. 6,
  137933. 8,
  137934. 5,
  137935. 9,
  137936. 4,
  137937. 10,
  137938. 3,
  137939. 11,
  137940. 2,
  137941. 12,
  137942. 1,
  137943. 13,
  137944. 0,
  137945. 14,
  137946. };
  137947. static long _vq_lengthlist__44u9_p9_0[] = {
  137948. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  137949. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  137950. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137951. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137952. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137953. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137954. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137955. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137956. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137957. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137958. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137959. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137960. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137961. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137962. 10,
  137963. };
  137964. static float _vq_quantthresh__44u9_p9_0[] = {
  137965. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  137966. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  137967. };
  137968. static long _vq_quantmap__44u9_p9_0[] = {
  137969. 13, 11, 9, 7, 5, 3, 1, 0,
  137970. 2, 4, 6, 8, 10, 12, 14,
  137971. };
  137972. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  137973. _vq_quantthresh__44u9_p9_0,
  137974. _vq_quantmap__44u9_p9_0,
  137975. 15,
  137976. 15
  137977. };
  137978. static static_codebook _44u9_p9_0 = {
  137979. 2, 225,
  137980. _vq_lengthlist__44u9_p9_0,
  137981. 1, -510036736, 1631393792, 4, 0,
  137982. _vq_quantlist__44u9_p9_0,
  137983. NULL,
  137984. &_vq_auxt__44u9_p9_0,
  137985. NULL,
  137986. 0
  137987. };
  137988. static long _vq_quantlist__44u9_p9_1[] = {
  137989. 9,
  137990. 8,
  137991. 10,
  137992. 7,
  137993. 11,
  137994. 6,
  137995. 12,
  137996. 5,
  137997. 13,
  137998. 4,
  137999. 14,
  138000. 3,
  138001. 15,
  138002. 2,
  138003. 16,
  138004. 1,
  138005. 17,
  138006. 0,
  138007. 18,
  138008. };
  138009. static long _vq_lengthlist__44u9_p9_1[] = {
  138010. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  138011. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  138012. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  138013. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  138014. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  138015. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  138016. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  138017. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  138018. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  138019. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  138020. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  138021. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  138022. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  138023. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  138024. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138025. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138026. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138027. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138028. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138029. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138030. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138031. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138032. 17,17,15,17,15,17,16,16,17,
  138033. };
  138034. static float _vq_quantthresh__44u9_p9_1[] = {
  138035. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138036. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138037. 367.5, 416.5,
  138038. };
  138039. static long _vq_quantmap__44u9_p9_1[] = {
  138040. 17, 15, 13, 11, 9, 7, 5, 3,
  138041. 1, 0, 2, 4, 6, 8, 10, 12,
  138042. 14, 16, 18,
  138043. };
  138044. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138045. _vq_quantthresh__44u9_p9_1,
  138046. _vq_quantmap__44u9_p9_1,
  138047. 19,
  138048. 19
  138049. };
  138050. static static_codebook _44u9_p9_1 = {
  138051. 2, 361,
  138052. _vq_lengthlist__44u9_p9_1,
  138053. 1, -518287360, 1622704128, 5, 0,
  138054. _vq_quantlist__44u9_p9_1,
  138055. NULL,
  138056. &_vq_auxt__44u9_p9_1,
  138057. NULL,
  138058. 0
  138059. };
  138060. static long _vq_quantlist__44u9_p9_2[] = {
  138061. 24,
  138062. 23,
  138063. 25,
  138064. 22,
  138065. 26,
  138066. 21,
  138067. 27,
  138068. 20,
  138069. 28,
  138070. 19,
  138071. 29,
  138072. 18,
  138073. 30,
  138074. 17,
  138075. 31,
  138076. 16,
  138077. 32,
  138078. 15,
  138079. 33,
  138080. 14,
  138081. 34,
  138082. 13,
  138083. 35,
  138084. 12,
  138085. 36,
  138086. 11,
  138087. 37,
  138088. 10,
  138089. 38,
  138090. 9,
  138091. 39,
  138092. 8,
  138093. 40,
  138094. 7,
  138095. 41,
  138096. 6,
  138097. 42,
  138098. 5,
  138099. 43,
  138100. 4,
  138101. 44,
  138102. 3,
  138103. 45,
  138104. 2,
  138105. 46,
  138106. 1,
  138107. 47,
  138108. 0,
  138109. 48,
  138110. };
  138111. static long _vq_lengthlist__44u9_p9_2[] = {
  138112. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138113. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138114. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138115. 7,
  138116. };
  138117. static float _vq_quantthresh__44u9_p9_2[] = {
  138118. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138119. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138120. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138121. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138122. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138123. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138124. };
  138125. static long _vq_quantmap__44u9_p9_2[] = {
  138126. 47, 45, 43, 41, 39, 37, 35, 33,
  138127. 31, 29, 27, 25, 23, 21, 19, 17,
  138128. 15, 13, 11, 9, 7, 5, 3, 1,
  138129. 0, 2, 4, 6, 8, 10, 12, 14,
  138130. 16, 18, 20, 22, 24, 26, 28, 30,
  138131. 32, 34, 36, 38, 40, 42, 44, 46,
  138132. 48,
  138133. };
  138134. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138135. _vq_quantthresh__44u9_p9_2,
  138136. _vq_quantmap__44u9_p9_2,
  138137. 49,
  138138. 49
  138139. };
  138140. static static_codebook _44u9_p9_2 = {
  138141. 1, 49,
  138142. _vq_lengthlist__44u9_p9_2,
  138143. 1, -526909440, 1611661312, 6, 0,
  138144. _vq_quantlist__44u9_p9_2,
  138145. NULL,
  138146. &_vq_auxt__44u9_p9_2,
  138147. NULL,
  138148. 0
  138149. };
  138150. static long _huff_lengthlist__44un1__long[] = {
  138151. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138152. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138153. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138154. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138155. };
  138156. static static_codebook _huff_book__44un1__long = {
  138157. 2, 64,
  138158. _huff_lengthlist__44un1__long,
  138159. 0, 0, 0, 0, 0,
  138160. NULL,
  138161. NULL,
  138162. NULL,
  138163. NULL,
  138164. 0
  138165. };
  138166. static long _vq_quantlist__44un1__p1_0[] = {
  138167. 1,
  138168. 0,
  138169. 2,
  138170. };
  138171. static long _vq_lengthlist__44un1__p1_0[] = {
  138172. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138173. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138174. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138175. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138176. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138177. 12,
  138178. };
  138179. static float _vq_quantthresh__44un1__p1_0[] = {
  138180. -0.5, 0.5,
  138181. };
  138182. static long _vq_quantmap__44un1__p1_0[] = {
  138183. 1, 0, 2,
  138184. };
  138185. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138186. _vq_quantthresh__44un1__p1_0,
  138187. _vq_quantmap__44un1__p1_0,
  138188. 3,
  138189. 3
  138190. };
  138191. static static_codebook _44un1__p1_0 = {
  138192. 4, 81,
  138193. _vq_lengthlist__44un1__p1_0,
  138194. 1, -535822336, 1611661312, 2, 0,
  138195. _vq_quantlist__44un1__p1_0,
  138196. NULL,
  138197. &_vq_auxt__44un1__p1_0,
  138198. NULL,
  138199. 0
  138200. };
  138201. static long _vq_quantlist__44un1__p2_0[] = {
  138202. 1,
  138203. 0,
  138204. 2,
  138205. };
  138206. static long _vq_lengthlist__44un1__p2_0[] = {
  138207. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138208. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138209. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138210. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138211. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138212. 8,
  138213. };
  138214. static float _vq_quantthresh__44un1__p2_0[] = {
  138215. -0.5, 0.5,
  138216. };
  138217. static long _vq_quantmap__44un1__p2_0[] = {
  138218. 1, 0, 2,
  138219. };
  138220. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138221. _vq_quantthresh__44un1__p2_0,
  138222. _vq_quantmap__44un1__p2_0,
  138223. 3,
  138224. 3
  138225. };
  138226. static static_codebook _44un1__p2_0 = {
  138227. 4, 81,
  138228. _vq_lengthlist__44un1__p2_0,
  138229. 1, -535822336, 1611661312, 2, 0,
  138230. _vq_quantlist__44un1__p2_0,
  138231. NULL,
  138232. &_vq_auxt__44un1__p2_0,
  138233. NULL,
  138234. 0
  138235. };
  138236. static long _vq_quantlist__44un1__p3_0[] = {
  138237. 2,
  138238. 1,
  138239. 3,
  138240. 0,
  138241. 4,
  138242. };
  138243. static long _vq_lengthlist__44un1__p3_0[] = {
  138244. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138245. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138246. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138247. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138248. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138249. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138250. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138251. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138252. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138253. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138254. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138255. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138256. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138257. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138258. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138259. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138260. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138261. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138262. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138263. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138264. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138265. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138266. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138267. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138268. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138269. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138270. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138271. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138272. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138273. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138274. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138275. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138276. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138277. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138278. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138279. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138280. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138281. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138282. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138283. 17,
  138284. };
  138285. static float _vq_quantthresh__44un1__p3_0[] = {
  138286. -1.5, -0.5, 0.5, 1.5,
  138287. };
  138288. static long _vq_quantmap__44un1__p3_0[] = {
  138289. 3, 1, 0, 2, 4,
  138290. };
  138291. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138292. _vq_quantthresh__44un1__p3_0,
  138293. _vq_quantmap__44un1__p3_0,
  138294. 5,
  138295. 5
  138296. };
  138297. static static_codebook _44un1__p3_0 = {
  138298. 4, 625,
  138299. _vq_lengthlist__44un1__p3_0,
  138300. 1, -533725184, 1611661312, 3, 0,
  138301. _vq_quantlist__44un1__p3_0,
  138302. NULL,
  138303. &_vq_auxt__44un1__p3_0,
  138304. NULL,
  138305. 0
  138306. };
  138307. static long _vq_quantlist__44un1__p4_0[] = {
  138308. 2,
  138309. 1,
  138310. 3,
  138311. 0,
  138312. 4,
  138313. };
  138314. static long _vq_lengthlist__44un1__p4_0[] = {
  138315. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138316. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138317. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138318. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138319. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138320. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138321. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138322. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138323. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138324. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138325. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138326. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138327. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138328. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138329. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138330. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138331. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138332. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138333. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138334. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138335. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138336. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138337. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138338. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138339. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138340. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138341. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138342. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138343. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138344. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138345. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138346. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138347. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138348. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138349. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138350. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138351. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138352. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138353. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138354. 12,
  138355. };
  138356. static float _vq_quantthresh__44un1__p4_0[] = {
  138357. -1.5, -0.5, 0.5, 1.5,
  138358. };
  138359. static long _vq_quantmap__44un1__p4_0[] = {
  138360. 3, 1, 0, 2, 4,
  138361. };
  138362. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138363. _vq_quantthresh__44un1__p4_0,
  138364. _vq_quantmap__44un1__p4_0,
  138365. 5,
  138366. 5
  138367. };
  138368. static static_codebook _44un1__p4_0 = {
  138369. 4, 625,
  138370. _vq_lengthlist__44un1__p4_0,
  138371. 1, -533725184, 1611661312, 3, 0,
  138372. _vq_quantlist__44un1__p4_0,
  138373. NULL,
  138374. &_vq_auxt__44un1__p4_0,
  138375. NULL,
  138376. 0
  138377. };
  138378. static long _vq_quantlist__44un1__p5_0[] = {
  138379. 4,
  138380. 3,
  138381. 5,
  138382. 2,
  138383. 6,
  138384. 1,
  138385. 7,
  138386. 0,
  138387. 8,
  138388. };
  138389. static long _vq_lengthlist__44un1__p5_0[] = {
  138390. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138391. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138392. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138393. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138394. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138395. 12,
  138396. };
  138397. static float _vq_quantthresh__44un1__p5_0[] = {
  138398. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138399. };
  138400. static long _vq_quantmap__44un1__p5_0[] = {
  138401. 7, 5, 3, 1, 0, 2, 4, 6,
  138402. 8,
  138403. };
  138404. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138405. _vq_quantthresh__44un1__p5_0,
  138406. _vq_quantmap__44un1__p5_0,
  138407. 9,
  138408. 9
  138409. };
  138410. static static_codebook _44un1__p5_0 = {
  138411. 2, 81,
  138412. _vq_lengthlist__44un1__p5_0,
  138413. 1, -531628032, 1611661312, 4, 0,
  138414. _vq_quantlist__44un1__p5_0,
  138415. NULL,
  138416. &_vq_auxt__44un1__p5_0,
  138417. NULL,
  138418. 0
  138419. };
  138420. static long _vq_quantlist__44un1__p6_0[] = {
  138421. 6,
  138422. 5,
  138423. 7,
  138424. 4,
  138425. 8,
  138426. 3,
  138427. 9,
  138428. 2,
  138429. 10,
  138430. 1,
  138431. 11,
  138432. 0,
  138433. 12,
  138434. };
  138435. static long _vq_lengthlist__44un1__p6_0[] = {
  138436. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138437. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138438. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138439. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138440. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138441. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138442. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138443. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138444. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138445. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138446. 16, 0,15,18,18, 0,16, 0, 0,
  138447. };
  138448. static float _vq_quantthresh__44un1__p6_0[] = {
  138449. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138450. 12.5, 17.5, 22.5, 27.5,
  138451. };
  138452. static long _vq_quantmap__44un1__p6_0[] = {
  138453. 11, 9, 7, 5, 3, 1, 0, 2,
  138454. 4, 6, 8, 10, 12,
  138455. };
  138456. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138457. _vq_quantthresh__44un1__p6_0,
  138458. _vq_quantmap__44un1__p6_0,
  138459. 13,
  138460. 13
  138461. };
  138462. static static_codebook _44un1__p6_0 = {
  138463. 2, 169,
  138464. _vq_lengthlist__44un1__p6_0,
  138465. 1, -526516224, 1616117760, 4, 0,
  138466. _vq_quantlist__44un1__p6_0,
  138467. NULL,
  138468. &_vq_auxt__44un1__p6_0,
  138469. NULL,
  138470. 0
  138471. };
  138472. static long _vq_quantlist__44un1__p6_1[] = {
  138473. 2,
  138474. 1,
  138475. 3,
  138476. 0,
  138477. 4,
  138478. };
  138479. static long _vq_lengthlist__44un1__p6_1[] = {
  138480. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138481. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138482. };
  138483. static float _vq_quantthresh__44un1__p6_1[] = {
  138484. -1.5, -0.5, 0.5, 1.5,
  138485. };
  138486. static long _vq_quantmap__44un1__p6_1[] = {
  138487. 3, 1, 0, 2, 4,
  138488. };
  138489. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138490. _vq_quantthresh__44un1__p6_1,
  138491. _vq_quantmap__44un1__p6_1,
  138492. 5,
  138493. 5
  138494. };
  138495. static static_codebook _44un1__p6_1 = {
  138496. 2, 25,
  138497. _vq_lengthlist__44un1__p6_1,
  138498. 1, -533725184, 1611661312, 3, 0,
  138499. _vq_quantlist__44un1__p6_1,
  138500. NULL,
  138501. &_vq_auxt__44un1__p6_1,
  138502. NULL,
  138503. 0
  138504. };
  138505. static long _vq_quantlist__44un1__p7_0[] = {
  138506. 2,
  138507. 1,
  138508. 3,
  138509. 0,
  138510. 4,
  138511. };
  138512. static long _vq_lengthlist__44un1__p7_0[] = {
  138513. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138514. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138515. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138516. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138517. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138518. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138519. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138520. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138521. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138522. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138523. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138524. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138525. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138526. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138527. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138528. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138529. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138530. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138531. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138532. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138533. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138534. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138535. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138536. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138537. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138538. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138539. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138540. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138541. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138542. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138543. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138544. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138545. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138546. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138547. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138548. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138549. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138550. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138551. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138552. 10,
  138553. };
  138554. static float _vq_quantthresh__44un1__p7_0[] = {
  138555. -253.5, -84.5, 84.5, 253.5,
  138556. };
  138557. static long _vq_quantmap__44un1__p7_0[] = {
  138558. 3, 1, 0, 2, 4,
  138559. };
  138560. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138561. _vq_quantthresh__44un1__p7_0,
  138562. _vq_quantmap__44un1__p7_0,
  138563. 5,
  138564. 5
  138565. };
  138566. static static_codebook _44un1__p7_0 = {
  138567. 4, 625,
  138568. _vq_lengthlist__44un1__p7_0,
  138569. 1, -518709248, 1626677248, 3, 0,
  138570. _vq_quantlist__44un1__p7_0,
  138571. NULL,
  138572. &_vq_auxt__44un1__p7_0,
  138573. NULL,
  138574. 0
  138575. };
  138576. static long _vq_quantlist__44un1__p7_1[] = {
  138577. 6,
  138578. 5,
  138579. 7,
  138580. 4,
  138581. 8,
  138582. 3,
  138583. 9,
  138584. 2,
  138585. 10,
  138586. 1,
  138587. 11,
  138588. 0,
  138589. 12,
  138590. };
  138591. static long _vq_lengthlist__44un1__p7_1[] = {
  138592. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138593. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138594. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138595. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138596. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138597. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138598. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138599. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138600. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138601. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138602. 12,13,13,12,13,13,14,14,14,
  138603. };
  138604. static float _vq_quantthresh__44un1__p7_1[] = {
  138605. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138606. 32.5, 45.5, 58.5, 71.5,
  138607. };
  138608. static long _vq_quantmap__44un1__p7_1[] = {
  138609. 11, 9, 7, 5, 3, 1, 0, 2,
  138610. 4, 6, 8, 10, 12,
  138611. };
  138612. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138613. _vq_quantthresh__44un1__p7_1,
  138614. _vq_quantmap__44un1__p7_1,
  138615. 13,
  138616. 13
  138617. };
  138618. static static_codebook _44un1__p7_1 = {
  138619. 2, 169,
  138620. _vq_lengthlist__44un1__p7_1,
  138621. 1, -523010048, 1618608128, 4, 0,
  138622. _vq_quantlist__44un1__p7_1,
  138623. NULL,
  138624. &_vq_auxt__44un1__p7_1,
  138625. NULL,
  138626. 0
  138627. };
  138628. static long _vq_quantlist__44un1__p7_2[] = {
  138629. 6,
  138630. 5,
  138631. 7,
  138632. 4,
  138633. 8,
  138634. 3,
  138635. 9,
  138636. 2,
  138637. 10,
  138638. 1,
  138639. 11,
  138640. 0,
  138641. 12,
  138642. };
  138643. static long _vq_lengthlist__44un1__p7_2[] = {
  138644. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138645. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138646. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138647. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138648. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138649. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138650. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138651. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138652. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138653. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138654. 9, 9, 9,10,10,10,10,10,10,
  138655. };
  138656. static float _vq_quantthresh__44un1__p7_2[] = {
  138657. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138658. 2.5, 3.5, 4.5, 5.5,
  138659. };
  138660. static long _vq_quantmap__44un1__p7_2[] = {
  138661. 11, 9, 7, 5, 3, 1, 0, 2,
  138662. 4, 6, 8, 10, 12,
  138663. };
  138664. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138665. _vq_quantthresh__44un1__p7_2,
  138666. _vq_quantmap__44un1__p7_2,
  138667. 13,
  138668. 13
  138669. };
  138670. static static_codebook _44un1__p7_2 = {
  138671. 2, 169,
  138672. _vq_lengthlist__44un1__p7_2,
  138673. 1, -531103744, 1611661312, 4, 0,
  138674. _vq_quantlist__44un1__p7_2,
  138675. NULL,
  138676. &_vq_auxt__44un1__p7_2,
  138677. NULL,
  138678. 0
  138679. };
  138680. static long _huff_lengthlist__44un1__short[] = {
  138681. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138682. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138683. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138684. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138685. };
  138686. static static_codebook _huff_book__44un1__short = {
  138687. 2, 64,
  138688. _huff_lengthlist__44un1__short,
  138689. 0, 0, 0, 0, 0,
  138690. NULL,
  138691. NULL,
  138692. NULL,
  138693. NULL,
  138694. 0
  138695. };
  138696. /*** End of inlined file: res_books_uncoupled.h ***/
  138697. static vorbis_info_residue0 _residue_44_low_un={
  138698. 0,-1, -1, 8,-1,
  138699. {0},
  138700. {-1},
  138701. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138702. { -1, 25, -1, 45, -1, -1, -1}
  138703. };
  138704. static vorbis_info_residue0 _residue_44_mid_un={
  138705. 0,-1, -1, 10,-1,
  138706. {0},
  138707. {-1},
  138708. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138709. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138710. };
  138711. static vorbis_info_residue0 _residue_44_hi_un={
  138712. 0,-1, -1, 10,-1,
  138713. {0},
  138714. {-1},
  138715. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138716. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138717. };
  138718. static vorbis_info_mapping0 _map_nominal_u[2]={
  138719. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138720. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138721. };
  138722. static static_bookblock _resbook_44u_n1={
  138723. {
  138724. {0},
  138725. {0,0,&_44un1__p1_0},
  138726. {0,0,&_44un1__p2_0},
  138727. {0,0,&_44un1__p3_0},
  138728. {0,0,&_44un1__p4_0},
  138729. {0,0,&_44un1__p5_0},
  138730. {&_44un1__p6_0,&_44un1__p6_1},
  138731. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138732. }
  138733. };
  138734. static static_bookblock _resbook_44u_0={
  138735. {
  138736. {0},
  138737. {0,0,&_44u0__p1_0},
  138738. {0,0,&_44u0__p2_0},
  138739. {0,0,&_44u0__p3_0},
  138740. {0,0,&_44u0__p4_0},
  138741. {0,0,&_44u0__p5_0},
  138742. {&_44u0__p6_0,&_44u0__p6_1},
  138743. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138744. }
  138745. };
  138746. static static_bookblock _resbook_44u_1={
  138747. {
  138748. {0},
  138749. {0,0,&_44u1__p1_0},
  138750. {0,0,&_44u1__p2_0},
  138751. {0,0,&_44u1__p3_0},
  138752. {0,0,&_44u1__p4_0},
  138753. {0,0,&_44u1__p5_0},
  138754. {&_44u1__p6_0,&_44u1__p6_1},
  138755. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138756. }
  138757. };
  138758. static static_bookblock _resbook_44u_2={
  138759. {
  138760. {0},
  138761. {0,0,&_44u2__p1_0},
  138762. {0,0,&_44u2__p2_0},
  138763. {0,0,&_44u2__p3_0},
  138764. {0,0,&_44u2__p4_0},
  138765. {0,0,&_44u2__p5_0},
  138766. {&_44u2__p6_0,&_44u2__p6_1},
  138767. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138768. }
  138769. };
  138770. static static_bookblock _resbook_44u_3={
  138771. {
  138772. {0},
  138773. {0,0,&_44u3__p1_0},
  138774. {0,0,&_44u3__p2_0},
  138775. {0,0,&_44u3__p3_0},
  138776. {0,0,&_44u3__p4_0},
  138777. {0,0,&_44u3__p5_0},
  138778. {&_44u3__p6_0,&_44u3__p6_1},
  138779. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138780. }
  138781. };
  138782. static static_bookblock _resbook_44u_4={
  138783. {
  138784. {0},
  138785. {0,0,&_44u4__p1_0},
  138786. {0,0,&_44u4__p2_0},
  138787. {0,0,&_44u4__p3_0},
  138788. {0,0,&_44u4__p4_0},
  138789. {0,0,&_44u4__p5_0},
  138790. {&_44u4__p6_0,&_44u4__p6_1},
  138791. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138792. }
  138793. };
  138794. static static_bookblock _resbook_44u_5={
  138795. {
  138796. {0},
  138797. {0,0,&_44u5__p1_0},
  138798. {0,0,&_44u5__p2_0},
  138799. {0,0,&_44u5__p3_0},
  138800. {0,0,&_44u5__p4_0},
  138801. {0,0,&_44u5__p5_0},
  138802. {0,0,&_44u5__p6_0},
  138803. {&_44u5__p7_0,&_44u5__p7_1},
  138804. {&_44u5__p8_0,&_44u5__p8_1},
  138805. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138806. }
  138807. };
  138808. static static_bookblock _resbook_44u_6={
  138809. {
  138810. {0},
  138811. {0,0,&_44u6__p1_0},
  138812. {0,0,&_44u6__p2_0},
  138813. {0,0,&_44u6__p3_0},
  138814. {0,0,&_44u6__p4_0},
  138815. {0,0,&_44u6__p5_0},
  138816. {0,0,&_44u6__p6_0},
  138817. {&_44u6__p7_0,&_44u6__p7_1},
  138818. {&_44u6__p8_0,&_44u6__p8_1},
  138819. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138820. }
  138821. };
  138822. static static_bookblock _resbook_44u_7={
  138823. {
  138824. {0},
  138825. {0,0,&_44u7__p1_0},
  138826. {0,0,&_44u7__p2_0},
  138827. {0,0,&_44u7__p3_0},
  138828. {0,0,&_44u7__p4_0},
  138829. {0,0,&_44u7__p5_0},
  138830. {0,0,&_44u7__p6_0},
  138831. {&_44u7__p7_0,&_44u7__p7_1},
  138832. {&_44u7__p8_0,&_44u7__p8_1},
  138833. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138834. }
  138835. };
  138836. static static_bookblock _resbook_44u_8={
  138837. {
  138838. {0},
  138839. {0,0,&_44u8_p1_0},
  138840. {0,0,&_44u8_p2_0},
  138841. {0,0,&_44u8_p3_0},
  138842. {0,0,&_44u8_p4_0},
  138843. {&_44u8_p5_0,&_44u8_p5_1},
  138844. {&_44u8_p6_0,&_44u8_p6_1},
  138845. {&_44u8_p7_0,&_44u8_p7_1},
  138846. {&_44u8_p8_0,&_44u8_p8_1},
  138847. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138848. }
  138849. };
  138850. static static_bookblock _resbook_44u_9={
  138851. {
  138852. {0},
  138853. {0,0,&_44u9_p1_0},
  138854. {0,0,&_44u9_p2_0},
  138855. {0,0,&_44u9_p3_0},
  138856. {0,0,&_44u9_p4_0},
  138857. {&_44u9_p5_0,&_44u9_p5_1},
  138858. {&_44u9_p6_0,&_44u9_p6_1},
  138859. {&_44u9_p7_0,&_44u9_p7_1},
  138860. {&_44u9_p8_0,&_44u9_p8_1},
  138861. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138862. }
  138863. };
  138864. static vorbis_residue_template _res_44u_n1[]={
  138865. {1,0, &_residue_44_low_un,
  138866. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138867. &_resbook_44u_n1,&_resbook_44u_n1},
  138868. {1,0, &_residue_44_low_un,
  138869. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138870. &_resbook_44u_n1,&_resbook_44u_n1}
  138871. };
  138872. static vorbis_residue_template _res_44u_0[]={
  138873. {1,0, &_residue_44_low_un,
  138874. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138875. &_resbook_44u_0,&_resbook_44u_0},
  138876. {1,0, &_residue_44_low_un,
  138877. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138878. &_resbook_44u_0,&_resbook_44u_0}
  138879. };
  138880. static vorbis_residue_template _res_44u_1[]={
  138881. {1,0, &_residue_44_low_un,
  138882. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138883. &_resbook_44u_1,&_resbook_44u_1},
  138884. {1,0, &_residue_44_low_un,
  138885. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138886. &_resbook_44u_1,&_resbook_44u_1}
  138887. };
  138888. static vorbis_residue_template _res_44u_2[]={
  138889. {1,0, &_residue_44_low_un,
  138890. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138891. &_resbook_44u_2,&_resbook_44u_2},
  138892. {1,0, &_residue_44_low_un,
  138893. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138894. &_resbook_44u_2,&_resbook_44u_2}
  138895. };
  138896. static vorbis_residue_template _res_44u_3[]={
  138897. {1,0, &_residue_44_low_un,
  138898. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138899. &_resbook_44u_3,&_resbook_44u_3},
  138900. {1,0, &_residue_44_low_un,
  138901. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138902. &_resbook_44u_3,&_resbook_44u_3}
  138903. };
  138904. static vorbis_residue_template _res_44u_4[]={
  138905. {1,0, &_residue_44_low_un,
  138906. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138907. &_resbook_44u_4,&_resbook_44u_4},
  138908. {1,0, &_residue_44_low_un,
  138909. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138910. &_resbook_44u_4,&_resbook_44u_4}
  138911. };
  138912. static vorbis_residue_template _res_44u_5[]={
  138913. {1,0, &_residue_44_mid_un,
  138914. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138915. &_resbook_44u_5,&_resbook_44u_5},
  138916. {1,0, &_residue_44_mid_un,
  138917. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138918. &_resbook_44u_5,&_resbook_44u_5}
  138919. };
  138920. static vorbis_residue_template _res_44u_6[]={
  138921. {1,0, &_residue_44_mid_un,
  138922. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138923. &_resbook_44u_6,&_resbook_44u_6},
  138924. {1,0, &_residue_44_mid_un,
  138925. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138926. &_resbook_44u_6,&_resbook_44u_6}
  138927. };
  138928. static vorbis_residue_template _res_44u_7[]={
  138929. {1,0, &_residue_44_mid_un,
  138930. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138931. &_resbook_44u_7,&_resbook_44u_7},
  138932. {1,0, &_residue_44_mid_un,
  138933. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138934. &_resbook_44u_7,&_resbook_44u_7}
  138935. };
  138936. static vorbis_residue_template _res_44u_8[]={
  138937. {1,0, &_residue_44_hi_un,
  138938. &_huff_book__44u8__short,&_huff_book__44u8__short,
  138939. &_resbook_44u_8,&_resbook_44u_8},
  138940. {1,0, &_residue_44_hi_un,
  138941. &_huff_book__44u8__long,&_huff_book__44u8__long,
  138942. &_resbook_44u_8,&_resbook_44u_8}
  138943. };
  138944. static vorbis_residue_template _res_44u_9[]={
  138945. {1,0, &_residue_44_hi_un,
  138946. &_huff_book__44u9__short,&_huff_book__44u9__short,
  138947. &_resbook_44u_9,&_resbook_44u_9},
  138948. {1,0, &_residue_44_hi_un,
  138949. &_huff_book__44u9__long,&_huff_book__44u9__long,
  138950. &_resbook_44u_9,&_resbook_44u_9}
  138951. };
  138952. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  138953. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  138954. { _map_nominal_u, _res_44u_0 }, /* 0 */
  138955. { _map_nominal_u, _res_44u_1 }, /* 1 */
  138956. { _map_nominal_u, _res_44u_2 }, /* 2 */
  138957. { _map_nominal_u, _res_44u_3 }, /* 3 */
  138958. { _map_nominal_u, _res_44u_4 }, /* 4 */
  138959. { _map_nominal_u, _res_44u_5 }, /* 5 */
  138960. { _map_nominal_u, _res_44u_6 }, /* 6 */
  138961. { _map_nominal_u, _res_44u_7 }, /* 7 */
  138962. { _map_nominal_u, _res_44u_8 }, /* 8 */
  138963. { _map_nominal_u, _res_44u_9 }, /* 9 */
  138964. };
  138965. /*** End of inlined file: residue_44u.h ***/
  138966. static double rate_mapping_44_un[12]={
  138967. 32000.,48000.,60000.,70000.,80000.,86000.,
  138968. 96000.,110000.,120000.,140000.,160000.,240001.
  138969. };
  138970. ve_setup_data_template ve_setup_44_uncoupled={
  138971. 11,
  138972. rate_mapping_44_un,
  138973. quality_mapping_44,
  138974. -1,
  138975. 40000,
  138976. 50000,
  138977. blocksize_short_44,
  138978. blocksize_long_44,
  138979. _psy_tone_masteratt_44,
  138980. _psy_tone_0dB,
  138981. _psy_tone_suppress,
  138982. _vp_tonemask_adj_otherblock,
  138983. _vp_tonemask_adj_longblock,
  138984. _vp_tonemask_adj_otherblock,
  138985. _psy_noiseguards_44,
  138986. _psy_noisebias_impulse,
  138987. _psy_noisebias_padding,
  138988. _psy_noisebias_trans,
  138989. _psy_noisebias_long,
  138990. _psy_noise_suppress,
  138991. _psy_compand_44,
  138992. _psy_compand_short_mapping,
  138993. _psy_compand_long_mapping,
  138994. {_noise_start_short_44,_noise_start_long_44},
  138995. {_noise_part_short_44,_noise_part_long_44},
  138996. _noise_thresh_44,
  138997. _psy_ath_floater,
  138998. _psy_ath_abs,
  138999. _psy_lowpass_44,
  139000. _psy_global_44,
  139001. _global_mapping_44,
  139002. NULL,
  139003. _floor_books,
  139004. _floor,
  139005. _floor_short_mapping_44,
  139006. _floor_long_mapping_44,
  139007. _mapres_template_44_uncoupled
  139008. };
  139009. /*** End of inlined file: setup_44u.h ***/
  139010. /*** Start of inlined file: setup_32.h ***/
  139011. static double rate_mapping_32[12]={
  139012. 18000.,28000.,35000.,45000.,56000.,60000.,
  139013. 75000.,90000.,100000.,115000.,150000.,190000.,
  139014. };
  139015. static double rate_mapping_32_un[12]={
  139016. 30000.,42000.,52000.,64000.,72000.,78000.,
  139017. 86000.,92000.,110000.,120000.,140000.,190000.,
  139018. };
  139019. static double _psy_lowpass_32[12]={
  139020. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  139021. };
  139022. ve_setup_data_template ve_setup_32_stereo={
  139023. 11,
  139024. rate_mapping_32,
  139025. quality_mapping_44,
  139026. 2,
  139027. 26000,
  139028. 40000,
  139029. blocksize_short_44,
  139030. blocksize_long_44,
  139031. _psy_tone_masteratt_44,
  139032. _psy_tone_0dB,
  139033. _psy_tone_suppress,
  139034. _vp_tonemask_adj_otherblock,
  139035. _vp_tonemask_adj_longblock,
  139036. _vp_tonemask_adj_otherblock,
  139037. _psy_noiseguards_44,
  139038. _psy_noisebias_impulse,
  139039. _psy_noisebias_padding,
  139040. _psy_noisebias_trans,
  139041. _psy_noisebias_long,
  139042. _psy_noise_suppress,
  139043. _psy_compand_44,
  139044. _psy_compand_short_mapping,
  139045. _psy_compand_long_mapping,
  139046. {_noise_start_short_44,_noise_start_long_44},
  139047. {_noise_part_short_44,_noise_part_long_44},
  139048. _noise_thresh_44,
  139049. _psy_ath_floater,
  139050. _psy_ath_abs,
  139051. _psy_lowpass_32,
  139052. _psy_global_44,
  139053. _global_mapping_44,
  139054. _psy_stereo_modes_44,
  139055. _floor_books,
  139056. _floor,
  139057. _floor_short_mapping_44,
  139058. _floor_long_mapping_44,
  139059. _mapres_template_44_stereo
  139060. };
  139061. ve_setup_data_template ve_setup_32_uncoupled={
  139062. 11,
  139063. rate_mapping_32_un,
  139064. quality_mapping_44,
  139065. -1,
  139066. 26000,
  139067. 40000,
  139068. blocksize_short_44,
  139069. blocksize_long_44,
  139070. _psy_tone_masteratt_44,
  139071. _psy_tone_0dB,
  139072. _psy_tone_suppress,
  139073. _vp_tonemask_adj_otherblock,
  139074. _vp_tonemask_adj_longblock,
  139075. _vp_tonemask_adj_otherblock,
  139076. _psy_noiseguards_44,
  139077. _psy_noisebias_impulse,
  139078. _psy_noisebias_padding,
  139079. _psy_noisebias_trans,
  139080. _psy_noisebias_long,
  139081. _psy_noise_suppress,
  139082. _psy_compand_44,
  139083. _psy_compand_short_mapping,
  139084. _psy_compand_long_mapping,
  139085. {_noise_start_short_44,_noise_start_long_44},
  139086. {_noise_part_short_44,_noise_part_long_44},
  139087. _noise_thresh_44,
  139088. _psy_ath_floater,
  139089. _psy_ath_abs,
  139090. _psy_lowpass_32,
  139091. _psy_global_44,
  139092. _global_mapping_44,
  139093. NULL,
  139094. _floor_books,
  139095. _floor,
  139096. _floor_short_mapping_44,
  139097. _floor_long_mapping_44,
  139098. _mapres_template_44_uncoupled
  139099. };
  139100. /*** End of inlined file: setup_32.h ***/
  139101. /*** Start of inlined file: setup_8.h ***/
  139102. /*** Start of inlined file: psych_8.h ***/
  139103. static att3 _psy_tone_masteratt_8[3]={
  139104. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139105. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139106. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139107. };
  139108. static vp_adjblock _vp_tonemask_adj_8[3]={
  139109. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139110. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139111. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139112. };
  139113. static noise3 _psy_noisebias_8[3]={
  139114. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139115. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139116. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139117. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139118. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139119. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139120. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139121. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139122. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139123. };
  139124. static adj_stereo _psy_stereo_modes_8[3]={
  139125. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139126. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139127. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139128. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139129. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139130. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139131. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139132. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139133. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139134. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139135. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139136. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139137. };
  139138. static noiseguard _psy_noiseguards_8[2]={
  139139. {10,10,-1},
  139140. {10,10,-1},
  139141. };
  139142. static compandblock _psy_compand_8[2]={
  139143. {{
  139144. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139145. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139146. 12,12,13,13,14,14,15, 15, /* 23dB */
  139147. 16,16,17,17,17,18,18, 19, /* 31dB */
  139148. 19,19,20,21,22,23,24, 25, /* 39dB */
  139149. }},
  139150. {{
  139151. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139152. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139153. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139154. 9,10,11,12,13,14,15, 16, /* 31dB */
  139155. 17,18,19,20,21,22,23, 24, /* 39dB */
  139156. }},
  139157. };
  139158. static double _psy_lowpass_8[3]={3.,4.,4.};
  139159. static int _noise_start_8[2]={
  139160. 64,64,
  139161. };
  139162. static int _noise_part_8[2]={
  139163. 8,8,
  139164. };
  139165. static int _psy_ath_floater_8[3]={
  139166. -100,-100,-105,
  139167. };
  139168. static int _psy_ath_abs_8[3]={
  139169. -130,-130,-140,
  139170. };
  139171. /*** End of inlined file: psych_8.h ***/
  139172. /*** Start of inlined file: residue_8.h ***/
  139173. static static_bookblock _resbook_8s_0={
  139174. {
  139175. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139176. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139177. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139178. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139179. }
  139180. };
  139181. static static_bookblock _resbook_8s_1={
  139182. {
  139183. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139184. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139185. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139186. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139187. }
  139188. };
  139189. static vorbis_residue_template _res_8s_0[]={
  139190. {2,0, &_residue_44_mid,
  139191. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139192. &_resbook_8s_0,&_resbook_8s_0},
  139193. };
  139194. static vorbis_residue_template _res_8s_1[]={
  139195. {2,0, &_residue_44_mid,
  139196. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139197. &_resbook_8s_1,&_resbook_8s_1},
  139198. };
  139199. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139200. { _map_nominal, _res_8s_0 }, /* 0 */
  139201. { _map_nominal, _res_8s_1 }, /* 1 */
  139202. };
  139203. static static_bookblock _resbook_8u_0={
  139204. {
  139205. {0},
  139206. {0,0,&_8u0__p1_0},
  139207. {0,0,&_8u0__p2_0},
  139208. {0,0,&_8u0__p3_0},
  139209. {0,0,&_8u0__p4_0},
  139210. {0,0,&_8u0__p5_0},
  139211. {&_8u0__p6_0,&_8u0__p6_1},
  139212. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139213. }
  139214. };
  139215. static static_bookblock _resbook_8u_1={
  139216. {
  139217. {0},
  139218. {0,0,&_8u1__p1_0},
  139219. {0,0,&_8u1__p2_0},
  139220. {0,0,&_8u1__p3_0},
  139221. {0,0,&_8u1__p4_0},
  139222. {0,0,&_8u1__p5_0},
  139223. {0,0,&_8u1__p6_0},
  139224. {&_8u1__p7_0,&_8u1__p7_1},
  139225. {&_8u1__p8_0,&_8u1__p8_1},
  139226. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139227. }
  139228. };
  139229. static vorbis_residue_template _res_8u_0[]={
  139230. {1,0, &_residue_44_low_un,
  139231. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139232. &_resbook_8u_0,&_resbook_8u_0},
  139233. };
  139234. static vorbis_residue_template _res_8u_1[]={
  139235. {1,0, &_residue_44_mid_un,
  139236. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139237. &_resbook_8u_1,&_resbook_8u_1},
  139238. };
  139239. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139240. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139241. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139242. };
  139243. /*** End of inlined file: residue_8.h ***/
  139244. static int blocksize_8[2]={
  139245. 512,512
  139246. };
  139247. static int _floor_mapping_8[2]={
  139248. 6,6,
  139249. };
  139250. static double rate_mapping_8[3]={
  139251. 6000.,9000.,32000.,
  139252. };
  139253. static double rate_mapping_8_uncoupled[3]={
  139254. 8000.,14000.,42000.,
  139255. };
  139256. static double quality_mapping_8[3]={
  139257. -.1,.0,1.
  139258. };
  139259. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139260. static double _global_mapping_8[3]={ 1., 2., 3. };
  139261. ve_setup_data_template ve_setup_8_stereo={
  139262. 2,
  139263. rate_mapping_8,
  139264. quality_mapping_8,
  139265. 2,
  139266. 8000,
  139267. 9000,
  139268. blocksize_8,
  139269. blocksize_8,
  139270. _psy_tone_masteratt_8,
  139271. _psy_tone_0dB,
  139272. _psy_tone_suppress,
  139273. _vp_tonemask_adj_8,
  139274. NULL,
  139275. _vp_tonemask_adj_8,
  139276. _psy_noiseguards_8,
  139277. _psy_noisebias_8,
  139278. _psy_noisebias_8,
  139279. NULL,
  139280. NULL,
  139281. _psy_noise_suppress,
  139282. _psy_compand_8,
  139283. _psy_compand_8_mapping,
  139284. NULL,
  139285. {_noise_start_8,_noise_start_8},
  139286. {_noise_part_8,_noise_part_8},
  139287. _noise_thresh_5only,
  139288. _psy_ath_floater_8,
  139289. _psy_ath_abs_8,
  139290. _psy_lowpass_8,
  139291. _psy_global_44,
  139292. _global_mapping_8,
  139293. _psy_stereo_modes_8,
  139294. _floor_books,
  139295. _floor,
  139296. _floor_mapping_8,
  139297. NULL,
  139298. _mapres_template_8_stereo
  139299. };
  139300. ve_setup_data_template ve_setup_8_uncoupled={
  139301. 2,
  139302. rate_mapping_8_uncoupled,
  139303. quality_mapping_8,
  139304. -1,
  139305. 8000,
  139306. 9000,
  139307. blocksize_8,
  139308. blocksize_8,
  139309. _psy_tone_masteratt_8,
  139310. _psy_tone_0dB,
  139311. _psy_tone_suppress,
  139312. _vp_tonemask_adj_8,
  139313. NULL,
  139314. _vp_tonemask_adj_8,
  139315. _psy_noiseguards_8,
  139316. _psy_noisebias_8,
  139317. _psy_noisebias_8,
  139318. NULL,
  139319. NULL,
  139320. _psy_noise_suppress,
  139321. _psy_compand_8,
  139322. _psy_compand_8_mapping,
  139323. NULL,
  139324. {_noise_start_8,_noise_start_8},
  139325. {_noise_part_8,_noise_part_8},
  139326. _noise_thresh_5only,
  139327. _psy_ath_floater_8,
  139328. _psy_ath_abs_8,
  139329. _psy_lowpass_8,
  139330. _psy_global_44,
  139331. _global_mapping_8,
  139332. _psy_stereo_modes_8,
  139333. _floor_books,
  139334. _floor,
  139335. _floor_mapping_8,
  139336. NULL,
  139337. _mapres_template_8_uncoupled
  139338. };
  139339. /*** End of inlined file: setup_8.h ***/
  139340. /*** Start of inlined file: setup_11.h ***/
  139341. /*** Start of inlined file: psych_11.h ***/
  139342. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139343. static att3 _psy_tone_masteratt_11[3]={
  139344. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139345. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139346. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139347. };
  139348. static vp_adjblock _vp_tonemask_adj_11[3]={
  139349. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139350. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139351. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139352. };
  139353. static noise3 _psy_noisebias_11[3]={
  139354. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139355. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139356. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139357. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139358. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139359. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139360. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139361. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139362. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139363. };
  139364. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139365. /*** End of inlined file: psych_11.h ***/
  139366. static int blocksize_11[2]={
  139367. 512,512
  139368. };
  139369. static int _floor_mapping_11[2]={
  139370. 6,6,
  139371. };
  139372. static double rate_mapping_11[3]={
  139373. 8000.,13000.,44000.,
  139374. };
  139375. static double rate_mapping_11_uncoupled[3]={
  139376. 12000.,20000.,50000.,
  139377. };
  139378. static double quality_mapping_11[3]={
  139379. -.1,.0,1.
  139380. };
  139381. ve_setup_data_template ve_setup_11_stereo={
  139382. 2,
  139383. rate_mapping_11,
  139384. quality_mapping_11,
  139385. 2,
  139386. 9000,
  139387. 15000,
  139388. blocksize_11,
  139389. blocksize_11,
  139390. _psy_tone_masteratt_11,
  139391. _psy_tone_0dB,
  139392. _psy_tone_suppress,
  139393. _vp_tonemask_adj_11,
  139394. NULL,
  139395. _vp_tonemask_adj_11,
  139396. _psy_noiseguards_8,
  139397. _psy_noisebias_11,
  139398. _psy_noisebias_11,
  139399. NULL,
  139400. NULL,
  139401. _psy_noise_suppress,
  139402. _psy_compand_8,
  139403. _psy_compand_8_mapping,
  139404. NULL,
  139405. {_noise_start_8,_noise_start_8},
  139406. {_noise_part_8,_noise_part_8},
  139407. _noise_thresh_11,
  139408. _psy_ath_floater_8,
  139409. _psy_ath_abs_8,
  139410. _psy_lowpass_11,
  139411. _psy_global_44,
  139412. _global_mapping_8,
  139413. _psy_stereo_modes_8,
  139414. _floor_books,
  139415. _floor,
  139416. _floor_mapping_11,
  139417. NULL,
  139418. _mapres_template_8_stereo
  139419. };
  139420. ve_setup_data_template ve_setup_11_uncoupled={
  139421. 2,
  139422. rate_mapping_11_uncoupled,
  139423. quality_mapping_11,
  139424. -1,
  139425. 9000,
  139426. 15000,
  139427. blocksize_11,
  139428. blocksize_11,
  139429. _psy_tone_masteratt_11,
  139430. _psy_tone_0dB,
  139431. _psy_tone_suppress,
  139432. _vp_tonemask_adj_11,
  139433. NULL,
  139434. _vp_tonemask_adj_11,
  139435. _psy_noiseguards_8,
  139436. _psy_noisebias_11,
  139437. _psy_noisebias_11,
  139438. NULL,
  139439. NULL,
  139440. _psy_noise_suppress,
  139441. _psy_compand_8,
  139442. _psy_compand_8_mapping,
  139443. NULL,
  139444. {_noise_start_8,_noise_start_8},
  139445. {_noise_part_8,_noise_part_8},
  139446. _noise_thresh_11,
  139447. _psy_ath_floater_8,
  139448. _psy_ath_abs_8,
  139449. _psy_lowpass_11,
  139450. _psy_global_44,
  139451. _global_mapping_8,
  139452. _psy_stereo_modes_8,
  139453. _floor_books,
  139454. _floor,
  139455. _floor_mapping_11,
  139456. NULL,
  139457. _mapres_template_8_uncoupled
  139458. };
  139459. /*** End of inlined file: setup_11.h ***/
  139460. /*** Start of inlined file: setup_16.h ***/
  139461. /*** Start of inlined file: psych_16.h ***/
  139462. static adj_stereo _psy_stereo_modes_16[4]={
  139463. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139464. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139465. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139466. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139467. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139468. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139469. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139470. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139471. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139472. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139473. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139474. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139475. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139476. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139477. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139478. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139479. };
  139480. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139481. static att3 _psy_tone_masteratt_16[4]={
  139482. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139483. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139484. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139485. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139486. };
  139487. static vp_adjblock _vp_tonemask_adj_16[4]={
  139488. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139489. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139490. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139491. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139492. };
  139493. static noise3 _psy_noisebias_16_short[4]={
  139494. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139495. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139496. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139497. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139498. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139499. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139500. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139501. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139502. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139503. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139504. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139505. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139506. };
  139507. static noise3 _psy_noisebias_16_impulse[4]={
  139508. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139509. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139510. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139511. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139512. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139513. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139514. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139515. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139516. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139517. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139518. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139519. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139520. };
  139521. static noise3 _psy_noisebias_16[4]={
  139522. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139523. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139524. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139525. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139526. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139527. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139528. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139529. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139530. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139531. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139532. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139533. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139534. };
  139535. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139536. static int _noise_start_16[3]={ 256,256,9999 };
  139537. static int _noise_part_16[4]={ 8,8,8,8 };
  139538. static int _psy_ath_floater_16[4]={
  139539. -100,-100,-100,-105,
  139540. };
  139541. static int _psy_ath_abs_16[4]={
  139542. -130,-130,-130,-140,
  139543. };
  139544. /*** End of inlined file: psych_16.h ***/
  139545. /*** Start of inlined file: residue_16.h ***/
  139546. static static_bookblock _resbook_16s_0={
  139547. {
  139548. {0},
  139549. {0,0,&_16c0_s_p1_0},
  139550. {0,0,&_16c0_s_p2_0},
  139551. {0,0,&_16c0_s_p3_0},
  139552. {0,0,&_16c0_s_p4_0},
  139553. {0,0,&_16c0_s_p5_0},
  139554. {0,0,&_16c0_s_p6_0},
  139555. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139556. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139557. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139558. }
  139559. };
  139560. static static_bookblock _resbook_16s_1={
  139561. {
  139562. {0},
  139563. {0,0,&_16c1_s_p1_0},
  139564. {0,0,&_16c1_s_p2_0},
  139565. {0,0,&_16c1_s_p3_0},
  139566. {0,0,&_16c1_s_p4_0},
  139567. {0,0,&_16c1_s_p5_0},
  139568. {0,0,&_16c1_s_p6_0},
  139569. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139570. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139571. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139572. }
  139573. };
  139574. static static_bookblock _resbook_16s_2={
  139575. {
  139576. {0},
  139577. {0,0,&_16c2_s_p1_0},
  139578. {0,0,&_16c2_s_p2_0},
  139579. {0,0,&_16c2_s_p3_0},
  139580. {0,0,&_16c2_s_p4_0},
  139581. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139582. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139583. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139584. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139585. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139586. }
  139587. };
  139588. static vorbis_residue_template _res_16s_0[]={
  139589. {2,0, &_residue_44_mid,
  139590. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139591. &_resbook_16s_0,&_resbook_16s_0},
  139592. };
  139593. static vorbis_residue_template _res_16s_1[]={
  139594. {2,0, &_residue_44_mid,
  139595. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139596. &_resbook_16s_1,&_resbook_16s_1},
  139597. {2,0, &_residue_44_mid,
  139598. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139599. &_resbook_16s_1,&_resbook_16s_1}
  139600. };
  139601. static vorbis_residue_template _res_16s_2[]={
  139602. {2,0, &_residue_44_high,
  139603. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139604. &_resbook_16s_2,&_resbook_16s_2},
  139605. {2,0, &_residue_44_high,
  139606. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139607. &_resbook_16s_2,&_resbook_16s_2}
  139608. };
  139609. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139610. { _map_nominal, _res_16s_0 }, /* 0 */
  139611. { _map_nominal, _res_16s_1 }, /* 1 */
  139612. { _map_nominal, _res_16s_2 }, /* 2 */
  139613. };
  139614. static static_bookblock _resbook_16u_0={
  139615. {
  139616. {0},
  139617. {0,0,&_16u0__p1_0},
  139618. {0,0,&_16u0__p2_0},
  139619. {0,0,&_16u0__p3_0},
  139620. {0,0,&_16u0__p4_0},
  139621. {0,0,&_16u0__p5_0},
  139622. {&_16u0__p6_0,&_16u0__p6_1},
  139623. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139624. }
  139625. };
  139626. static static_bookblock _resbook_16u_1={
  139627. {
  139628. {0},
  139629. {0,0,&_16u1__p1_0},
  139630. {0,0,&_16u1__p2_0},
  139631. {0,0,&_16u1__p3_0},
  139632. {0,0,&_16u1__p4_0},
  139633. {0,0,&_16u1__p5_0},
  139634. {0,0,&_16u1__p6_0},
  139635. {&_16u1__p7_0,&_16u1__p7_1},
  139636. {&_16u1__p8_0,&_16u1__p8_1},
  139637. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139638. }
  139639. };
  139640. static static_bookblock _resbook_16u_2={
  139641. {
  139642. {0},
  139643. {0,0,&_16u2_p1_0},
  139644. {0,0,&_16u2_p2_0},
  139645. {0,0,&_16u2_p3_0},
  139646. {0,0,&_16u2_p4_0},
  139647. {&_16u2_p5_0,&_16u2_p5_1},
  139648. {&_16u2_p6_0,&_16u2_p6_1},
  139649. {&_16u2_p7_0,&_16u2_p7_1},
  139650. {&_16u2_p8_0,&_16u2_p8_1},
  139651. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139652. }
  139653. };
  139654. static vorbis_residue_template _res_16u_0[]={
  139655. {1,0, &_residue_44_low_un,
  139656. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139657. &_resbook_16u_0,&_resbook_16u_0},
  139658. };
  139659. static vorbis_residue_template _res_16u_1[]={
  139660. {1,0, &_residue_44_mid_un,
  139661. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139662. &_resbook_16u_1,&_resbook_16u_1},
  139663. {1,0, &_residue_44_mid_un,
  139664. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139665. &_resbook_16u_1,&_resbook_16u_1}
  139666. };
  139667. static vorbis_residue_template _res_16u_2[]={
  139668. {1,0, &_residue_44_hi_un,
  139669. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139670. &_resbook_16u_2,&_resbook_16u_2},
  139671. {1,0, &_residue_44_hi_un,
  139672. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139673. &_resbook_16u_2,&_resbook_16u_2}
  139674. };
  139675. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139676. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139677. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139678. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139679. };
  139680. /*** End of inlined file: residue_16.h ***/
  139681. static int blocksize_16_short[3]={
  139682. 1024,512,512
  139683. };
  139684. static int blocksize_16_long[3]={
  139685. 1024,1024,1024
  139686. };
  139687. static int _floor_mapping_16_short[3]={
  139688. 9,3,3
  139689. };
  139690. static int _floor_mapping_16[3]={
  139691. 9,9,9
  139692. };
  139693. static double rate_mapping_16[4]={
  139694. 12000.,20000.,44000.,86000.
  139695. };
  139696. static double rate_mapping_16_uncoupled[4]={
  139697. 16000.,28000.,64000.,100000.
  139698. };
  139699. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139700. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139701. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139702. ve_setup_data_template ve_setup_16_stereo={
  139703. 3,
  139704. rate_mapping_16,
  139705. quality_mapping_16,
  139706. 2,
  139707. 15000,
  139708. 19000,
  139709. blocksize_16_short,
  139710. blocksize_16_long,
  139711. _psy_tone_masteratt_16,
  139712. _psy_tone_0dB,
  139713. _psy_tone_suppress,
  139714. _vp_tonemask_adj_16,
  139715. _vp_tonemask_adj_16,
  139716. _vp_tonemask_adj_16,
  139717. _psy_noiseguards_8,
  139718. _psy_noisebias_16_impulse,
  139719. _psy_noisebias_16_short,
  139720. _psy_noisebias_16_short,
  139721. _psy_noisebias_16,
  139722. _psy_noise_suppress,
  139723. _psy_compand_8,
  139724. _psy_compand_16_mapping,
  139725. _psy_compand_16_mapping,
  139726. {_noise_start_16,_noise_start_16},
  139727. { _noise_part_16, _noise_part_16},
  139728. _noise_thresh_16,
  139729. _psy_ath_floater_16,
  139730. _psy_ath_abs_16,
  139731. _psy_lowpass_16,
  139732. _psy_global_44,
  139733. _global_mapping_16,
  139734. _psy_stereo_modes_16,
  139735. _floor_books,
  139736. _floor,
  139737. _floor_mapping_16_short,
  139738. _floor_mapping_16,
  139739. _mapres_template_16_stereo
  139740. };
  139741. ve_setup_data_template ve_setup_16_uncoupled={
  139742. 3,
  139743. rate_mapping_16_uncoupled,
  139744. quality_mapping_16,
  139745. -1,
  139746. 15000,
  139747. 19000,
  139748. blocksize_16_short,
  139749. blocksize_16_long,
  139750. _psy_tone_masteratt_16,
  139751. _psy_tone_0dB,
  139752. _psy_tone_suppress,
  139753. _vp_tonemask_adj_16,
  139754. _vp_tonemask_adj_16,
  139755. _vp_tonemask_adj_16,
  139756. _psy_noiseguards_8,
  139757. _psy_noisebias_16_impulse,
  139758. _psy_noisebias_16_short,
  139759. _psy_noisebias_16_short,
  139760. _psy_noisebias_16,
  139761. _psy_noise_suppress,
  139762. _psy_compand_8,
  139763. _psy_compand_16_mapping,
  139764. _psy_compand_16_mapping,
  139765. {_noise_start_16,_noise_start_16},
  139766. { _noise_part_16, _noise_part_16},
  139767. _noise_thresh_16,
  139768. _psy_ath_floater_16,
  139769. _psy_ath_abs_16,
  139770. _psy_lowpass_16,
  139771. _psy_global_44,
  139772. _global_mapping_16,
  139773. _psy_stereo_modes_16,
  139774. _floor_books,
  139775. _floor,
  139776. _floor_mapping_16_short,
  139777. _floor_mapping_16,
  139778. _mapres_template_16_uncoupled
  139779. };
  139780. /*** End of inlined file: setup_16.h ***/
  139781. /*** Start of inlined file: setup_22.h ***/
  139782. static double rate_mapping_22[4]={
  139783. 15000.,20000.,44000.,86000.
  139784. };
  139785. static double rate_mapping_22_uncoupled[4]={
  139786. 16000.,28000.,50000.,90000.
  139787. };
  139788. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139789. ve_setup_data_template ve_setup_22_stereo={
  139790. 3,
  139791. rate_mapping_22,
  139792. quality_mapping_16,
  139793. 2,
  139794. 19000,
  139795. 26000,
  139796. blocksize_16_short,
  139797. blocksize_16_long,
  139798. _psy_tone_masteratt_16,
  139799. _psy_tone_0dB,
  139800. _psy_tone_suppress,
  139801. _vp_tonemask_adj_16,
  139802. _vp_tonemask_adj_16,
  139803. _vp_tonemask_adj_16,
  139804. _psy_noiseguards_8,
  139805. _psy_noisebias_16_impulse,
  139806. _psy_noisebias_16_short,
  139807. _psy_noisebias_16_short,
  139808. _psy_noisebias_16,
  139809. _psy_noise_suppress,
  139810. _psy_compand_8,
  139811. _psy_compand_8_mapping,
  139812. _psy_compand_8_mapping,
  139813. {_noise_start_16,_noise_start_16},
  139814. { _noise_part_16, _noise_part_16},
  139815. _noise_thresh_16,
  139816. _psy_ath_floater_16,
  139817. _psy_ath_abs_16,
  139818. _psy_lowpass_22,
  139819. _psy_global_44,
  139820. _global_mapping_16,
  139821. _psy_stereo_modes_16,
  139822. _floor_books,
  139823. _floor,
  139824. _floor_mapping_16_short,
  139825. _floor_mapping_16,
  139826. _mapres_template_16_stereo
  139827. };
  139828. ve_setup_data_template ve_setup_22_uncoupled={
  139829. 3,
  139830. rate_mapping_22_uncoupled,
  139831. quality_mapping_16,
  139832. -1,
  139833. 19000,
  139834. 26000,
  139835. blocksize_16_short,
  139836. blocksize_16_long,
  139837. _psy_tone_masteratt_16,
  139838. _psy_tone_0dB,
  139839. _psy_tone_suppress,
  139840. _vp_tonemask_adj_16,
  139841. _vp_tonemask_adj_16,
  139842. _vp_tonemask_adj_16,
  139843. _psy_noiseguards_8,
  139844. _psy_noisebias_16_impulse,
  139845. _psy_noisebias_16_short,
  139846. _psy_noisebias_16_short,
  139847. _psy_noisebias_16,
  139848. _psy_noise_suppress,
  139849. _psy_compand_8,
  139850. _psy_compand_8_mapping,
  139851. _psy_compand_8_mapping,
  139852. {_noise_start_16,_noise_start_16},
  139853. { _noise_part_16, _noise_part_16},
  139854. _noise_thresh_16,
  139855. _psy_ath_floater_16,
  139856. _psy_ath_abs_16,
  139857. _psy_lowpass_22,
  139858. _psy_global_44,
  139859. _global_mapping_16,
  139860. _psy_stereo_modes_16,
  139861. _floor_books,
  139862. _floor,
  139863. _floor_mapping_16_short,
  139864. _floor_mapping_16,
  139865. _mapres_template_16_uncoupled
  139866. };
  139867. /*** End of inlined file: setup_22.h ***/
  139868. /*** Start of inlined file: setup_X.h ***/
  139869. static double rate_mapping_X[12]={
  139870. -1.,-1.,-1.,-1.,-1.,-1.,
  139871. -1.,-1.,-1.,-1.,-1.,-1.
  139872. };
  139873. ve_setup_data_template ve_setup_X_stereo={
  139874. 11,
  139875. rate_mapping_X,
  139876. quality_mapping_44,
  139877. 2,
  139878. 50000,
  139879. 200000,
  139880. blocksize_short_44,
  139881. blocksize_long_44,
  139882. _psy_tone_masteratt_44,
  139883. _psy_tone_0dB,
  139884. _psy_tone_suppress,
  139885. _vp_tonemask_adj_otherblock,
  139886. _vp_tonemask_adj_longblock,
  139887. _vp_tonemask_adj_otherblock,
  139888. _psy_noiseguards_44,
  139889. _psy_noisebias_impulse,
  139890. _psy_noisebias_padding,
  139891. _psy_noisebias_trans,
  139892. _psy_noisebias_long,
  139893. _psy_noise_suppress,
  139894. _psy_compand_44,
  139895. _psy_compand_short_mapping,
  139896. _psy_compand_long_mapping,
  139897. {_noise_start_short_44,_noise_start_long_44},
  139898. {_noise_part_short_44,_noise_part_long_44},
  139899. _noise_thresh_44,
  139900. _psy_ath_floater,
  139901. _psy_ath_abs,
  139902. _psy_lowpass_44,
  139903. _psy_global_44,
  139904. _global_mapping_44,
  139905. _psy_stereo_modes_44,
  139906. _floor_books,
  139907. _floor,
  139908. _floor_short_mapping_44,
  139909. _floor_long_mapping_44,
  139910. _mapres_template_44_stereo
  139911. };
  139912. ve_setup_data_template ve_setup_X_uncoupled={
  139913. 11,
  139914. rate_mapping_X,
  139915. quality_mapping_44,
  139916. -1,
  139917. 50000,
  139918. 200000,
  139919. blocksize_short_44,
  139920. blocksize_long_44,
  139921. _psy_tone_masteratt_44,
  139922. _psy_tone_0dB,
  139923. _psy_tone_suppress,
  139924. _vp_tonemask_adj_otherblock,
  139925. _vp_tonemask_adj_longblock,
  139926. _vp_tonemask_adj_otherblock,
  139927. _psy_noiseguards_44,
  139928. _psy_noisebias_impulse,
  139929. _psy_noisebias_padding,
  139930. _psy_noisebias_trans,
  139931. _psy_noisebias_long,
  139932. _psy_noise_suppress,
  139933. _psy_compand_44,
  139934. _psy_compand_short_mapping,
  139935. _psy_compand_long_mapping,
  139936. {_noise_start_short_44,_noise_start_long_44},
  139937. {_noise_part_short_44,_noise_part_long_44},
  139938. _noise_thresh_44,
  139939. _psy_ath_floater,
  139940. _psy_ath_abs,
  139941. _psy_lowpass_44,
  139942. _psy_global_44,
  139943. _global_mapping_44,
  139944. NULL,
  139945. _floor_books,
  139946. _floor,
  139947. _floor_short_mapping_44,
  139948. _floor_long_mapping_44,
  139949. _mapres_template_44_uncoupled
  139950. };
  139951. ve_setup_data_template ve_setup_XX_stereo={
  139952. 2,
  139953. rate_mapping_X,
  139954. quality_mapping_8,
  139955. 2,
  139956. 0,
  139957. 8000,
  139958. blocksize_8,
  139959. blocksize_8,
  139960. _psy_tone_masteratt_8,
  139961. _psy_tone_0dB,
  139962. _psy_tone_suppress,
  139963. _vp_tonemask_adj_8,
  139964. NULL,
  139965. _vp_tonemask_adj_8,
  139966. _psy_noiseguards_8,
  139967. _psy_noisebias_8,
  139968. _psy_noisebias_8,
  139969. NULL,
  139970. NULL,
  139971. _psy_noise_suppress,
  139972. _psy_compand_8,
  139973. _psy_compand_8_mapping,
  139974. NULL,
  139975. {_noise_start_8,_noise_start_8},
  139976. {_noise_part_8,_noise_part_8},
  139977. _noise_thresh_5only,
  139978. _psy_ath_floater_8,
  139979. _psy_ath_abs_8,
  139980. _psy_lowpass_8,
  139981. _psy_global_44,
  139982. _global_mapping_8,
  139983. _psy_stereo_modes_8,
  139984. _floor_books,
  139985. _floor,
  139986. _floor_mapping_8,
  139987. NULL,
  139988. _mapres_template_8_stereo
  139989. };
  139990. ve_setup_data_template ve_setup_XX_uncoupled={
  139991. 2,
  139992. rate_mapping_X,
  139993. quality_mapping_8,
  139994. -1,
  139995. 0,
  139996. 8000,
  139997. blocksize_8,
  139998. blocksize_8,
  139999. _psy_tone_masteratt_8,
  140000. _psy_tone_0dB,
  140001. _psy_tone_suppress,
  140002. _vp_tonemask_adj_8,
  140003. NULL,
  140004. _vp_tonemask_adj_8,
  140005. _psy_noiseguards_8,
  140006. _psy_noisebias_8,
  140007. _psy_noisebias_8,
  140008. NULL,
  140009. NULL,
  140010. _psy_noise_suppress,
  140011. _psy_compand_8,
  140012. _psy_compand_8_mapping,
  140013. NULL,
  140014. {_noise_start_8,_noise_start_8},
  140015. {_noise_part_8,_noise_part_8},
  140016. _noise_thresh_5only,
  140017. _psy_ath_floater_8,
  140018. _psy_ath_abs_8,
  140019. _psy_lowpass_8,
  140020. _psy_global_44,
  140021. _global_mapping_8,
  140022. _psy_stereo_modes_8,
  140023. _floor_books,
  140024. _floor,
  140025. _floor_mapping_8,
  140026. NULL,
  140027. _mapres_template_8_uncoupled
  140028. };
  140029. /*** End of inlined file: setup_X.h ***/
  140030. static ve_setup_data_template *setup_list[]={
  140031. &ve_setup_44_stereo,
  140032. &ve_setup_44_uncoupled,
  140033. &ve_setup_32_stereo,
  140034. &ve_setup_32_uncoupled,
  140035. &ve_setup_22_stereo,
  140036. &ve_setup_22_uncoupled,
  140037. &ve_setup_16_stereo,
  140038. &ve_setup_16_uncoupled,
  140039. &ve_setup_11_stereo,
  140040. &ve_setup_11_uncoupled,
  140041. &ve_setup_8_stereo,
  140042. &ve_setup_8_uncoupled,
  140043. &ve_setup_X_stereo,
  140044. &ve_setup_X_uncoupled,
  140045. &ve_setup_XX_stereo,
  140046. &ve_setup_XX_uncoupled,
  140047. 0
  140048. };
  140049. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140050. if(vi && vi->codec_setup){
  140051. vi->version=0;
  140052. vi->channels=ch;
  140053. vi->rate=rate;
  140054. return(0);
  140055. }
  140056. return(OV_EINVAL);
  140057. }
  140058. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140059. static_codebook ***books,
  140060. vorbis_info_floor1 *in,
  140061. int *x){
  140062. int i,k,is=s;
  140063. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140064. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140065. memcpy(f,in+x[is],sizeof(*f));
  140066. f->n=ci->blocksizes[block]>>1;
  140067. {
  140068. int partitions=f->partitions;
  140069. int maxclass=-1;
  140070. int maxbook=-1;
  140071. for(i=0;i<partitions;i++)
  140072. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140073. for(i=0;i<=maxclass;i++){
  140074. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140075. f->class_book[i]+=ci->books;
  140076. for(k=0;k<(1<<f->class_subs[i]);k++){
  140077. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140078. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140079. }
  140080. }
  140081. for(i=0;i<=maxbook;i++)
  140082. ci->book_param[ci->books++]=books[x[is]][i];
  140083. }
  140084. ci->floor_type[ci->floors]=1;
  140085. ci->floor_param[ci->floors]=f;
  140086. ci->floors++;
  140087. return;
  140088. }
  140089. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140090. vorbis_info_psy_global *in,
  140091. double *x){
  140092. int i,is=s;
  140093. double ds=s-is;
  140094. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140095. vorbis_info_psy_global *g=&ci->psy_g_param;
  140096. memcpy(g,in+(int)x[is],sizeof(*g));
  140097. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140098. is=(int)ds;
  140099. ds-=is;
  140100. if(ds==0 && is>0){
  140101. is--;
  140102. ds=1.;
  140103. }
  140104. for(i=0;i<4;i++){
  140105. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140106. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140107. }
  140108. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140109. return;
  140110. }
  140111. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140112. highlevel_encode_setup *hi,
  140113. adj_stereo *p){
  140114. float s=hi->stereo_point_setting;
  140115. int i,is=s;
  140116. double ds=s-is;
  140117. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140118. vorbis_info_psy_global *g=&ci->psy_g_param;
  140119. if(p){
  140120. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140121. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140122. if(hi->managed){
  140123. for(i=0;i<PACKETBLOBS;i++){
  140124. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140125. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140126. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140127. g->coupling_pkHz[i]=kHz;
  140128. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140129. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140130. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140131. }
  140132. }else{
  140133. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140134. for(i=0;i<PACKETBLOBS;i++){
  140135. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140136. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140137. g->coupling_pkHz[i]=kHz;
  140138. }
  140139. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140140. for(i=0;i<PACKETBLOBS;i++){
  140141. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140142. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140143. }
  140144. }
  140145. }else{
  140146. for(i=0;i<PACKETBLOBS;i++){
  140147. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140148. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140149. }
  140150. }
  140151. return;
  140152. }
  140153. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140154. int *nn_start,
  140155. int *nn_partition,
  140156. double *nn_thresh,
  140157. int block){
  140158. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140159. vorbis_info_psy *p=ci->psy_param[block];
  140160. highlevel_encode_setup *hi=&ci->hi;
  140161. int is=s;
  140162. if(block>=ci->psys)
  140163. ci->psys=block+1;
  140164. if(!p){
  140165. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140166. ci->psy_param[block]=p;
  140167. }
  140168. memcpy(p,&_psy_info_template,sizeof(*p));
  140169. p->blockflag=block>>1;
  140170. if(hi->noise_normalize_p){
  140171. p->normal_channel_p=1;
  140172. p->normal_point_p=1;
  140173. p->normal_start=nn_start[is];
  140174. p->normal_partition=nn_partition[is];
  140175. p->normal_thresh=nn_thresh[is];
  140176. }
  140177. return;
  140178. }
  140179. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140180. att3 *att,
  140181. int *max,
  140182. vp_adjblock *in){
  140183. int i,is=s;
  140184. double ds=s-is;
  140185. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140186. vorbis_info_psy *p=ci->psy_param[block];
  140187. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140188. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140189. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140190. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140191. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140192. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140193. for(i=0;i<P_BANDS;i++)
  140194. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140195. return;
  140196. }
  140197. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140198. compandblock *in, double *x){
  140199. int i,is=s;
  140200. double ds=s-is;
  140201. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140202. vorbis_info_psy *p=ci->psy_param[block];
  140203. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140204. is=(int)ds;
  140205. ds-=is;
  140206. if(ds==0 && is>0){
  140207. is--;
  140208. ds=1.;
  140209. }
  140210. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140211. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140212. return;
  140213. }
  140214. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140215. int *suppress){
  140216. int is=s;
  140217. double ds=s-is;
  140218. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140219. vorbis_info_psy *p=ci->psy_param[block];
  140220. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140221. return;
  140222. }
  140223. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140224. int *suppress,
  140225. noise3 *in,
  140226. noiseguard *guard,
  140227. double userbias){
  140228. int i,is=s,j;
  140229. double ds=s-is;
  140230. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140231. vorbis_info_psy *p=ci->psy_param[block];
  140232. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140233. p->noisewindowlomin=guard[block].lo;
  140234. p->noisewindowhimin=guard[block].hi;
  140235. p->noisewindowfixed=guard[block].fixed;
  140236. for(j=0;j<P_NOISECURVES;j++)
  140237. for(i=0;i<P_BANDS;i++)
  140238. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140239. for(j=0;j<P_NOISECURVES;j++){
  140240. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140241. for(i=0;i<P_BANDS;i++){
  140242. p->noiseoff[j][i]+=userbias;
  140243. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140244. }
  140245. }
  140246. return;
  140247. }
  140248. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140249. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140250. vorbis_info_psy *p=ci->psy_param[block];
  140251. p->ath_adjatt=ci->hi.ath_floating_dB;
  140252. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140253. return;
  140254. }
  140255. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140256. int i;
  140257. for(i=0;i<ci->books;i++)
  140258. if(ci->book_param[i]==book)return(i);
  140259. return(ci->books++);
  140260. }
  140261. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140262. int *shortb,int *longb){
  140263. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140264. int is=s;
  140265. int blockshort=shortb[is];
  140266. int blocklong=longb[is];
  140267. ci->blocksizes[0]=blockshort;
  140268. ci->blocksizes[1]=blocklong;
  140269. }
  140270. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140271. int number, int block,
  140272. vorbis_residue_template *res){
  140273. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140274. int i,n;
  140275. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140276. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140277. memcpy(r,res->res,sizeof(*r));
  140278. if(ci->residues<=number)ci->residues=number+1;
  140279. switch(ci->blocksizes[block]){
  140280. case 64:case 128:case 256:
  140281. r->grouping=16;
  140282. break;
  140283. default:
  140284. r->grouping=32;
  140285. break;
  140286. }
  140287. ci->residue_type[number]=res->res_type;
  140288. n=r->end=ci->blocksizes[block]>>1;
  140289. if(res->res_type==2)
  140290. n=r->end*=vi->channels;
  140291. {
  140292. int booklist=0,k;
  140293. if(ci->hi.managed){
  140294. for(i=0;i<r->partitions;i++)
  140295. for(k=0;k<3;k++)
  140296. if(res->books_base_managed->books[i][k])
  140297. r->secondstages[i]|=(1<<k);
  140298. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140299. ci->book_param[r->groupbook]=res->book_aux_managed;
  140300. for(i=0;i<r->partitions;i++){
  140301. for(k=0;k<3;k++){
  140302. if(res->books_base_managed->books[i][k]){
  140303. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140304. r->booklist[booklist++]=bookid;
  140305. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140306. }
  140307. }
  140308. }
  140309. }else{
  140310. for(i=0;i<r->partitions;i++)
  140311. for(k=0;k<3;k++)
  140312. if(res->books_base->books[i][k])
  140313. r->secondstages[i]|=(1<<k);
  140314. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140315. ci->book_param[r->groupbook]=res->book_aux;
  140316. for(i=0;i<r->partitions;i++){
  140317. for(k=0;k<3;k++){
  140318. if(res->books_base->books[i][k]){
  140319. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140320. r->booklist[booklist++]=bookid;
  140321. ci->book_param[bookid]=res->books_base->books[i][k];
  140322. }
  140323. }
  140324. }
  140325. }
  140326. }
  140327. {
  140328. double freq=ci->hi.lowpass_kHz*1000.;
  140329. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140330. double nyq=vi->rate/2.;
  140331. long blocksize=ci->blocksizes[block]>>1;
  140332. if(freq>nyq)freq=nyq;
  140333. f->n=freq/nyq*blocksize;
  140334. if(res->limit_type){
  140335. if(ci->hi.managed)
  140336. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140337. else
  140338. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140339. if(freq>nyq)freq=nyq;
  140340. }
  140341. if(ci->residue_type[block]==2)
  140342. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140343. r->grouping;
  140344. else
  140345. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140346. r->grouping;
  140347. }
  140348. }
  140349. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140350. vorbis_mapping_template *maps){
  140351. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140352. int i,j,is=s,modes=2;
  140353. vorbis_info_mapping0 *map=maps[is].map;
  140354. vorbis_info_mode *mode=_mode_template;
  140355. vorbis_residue_template *res=maps[is].res;
  140356. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140357. for(i=0;i<modes;i++){
  140358. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140359. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140360. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140361. if(i>=ci->modes)ci->modes=i+1;
  140362. ci->map_type[i]=0;
  140363. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140364. if(i>=ci->maps)ci->maps=i+1;
  140365. for(j=0;j<map[i].submaps;j++)
  140366. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140367. ,res+map[i].residuesubmap[j]);
  140368. }
  140369. }
  140370. static double setting_to_approx_bitrate(vorbis_info *vi){
  140371. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140372. highlevel_encode_setup *hi=&ci->hi;
  140373. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140374. int is=hi->base_setting;
  140375. double ds=hi->base_setting-is;
  140376. int ch=vi->channels;
  140377. double *r=setup->rate_mapping;
  140378. if(r==NULL)
  140379. return(-1);
  140380. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140381. }
  140382. static void get_setup_template(vorbis_info *vi,
  140383. long ch,long srate,
  140384. double req,int q_or_bitrate){
  140385. int i=0,j;
  140386. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140387. highlevel_encode_setup *hi=&ci->hi;
  140388. if(q_or_bitrate)req/=ch;
  140389. while(setup_list[i]){
  140390. if(setup_list[i]->coupling_restriction==-1 ||
  140391. setup_list[i]->coupling_restriction==ch){
  140392. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140393. srate<=setup_list[i]->samplerate_max_restriction){
  140394. int mappings=setup_list[i]->mappings;
  140395. double *map=(q_or_bitrate?
  140396. setup_list[i]->rate_mapping:
  140397. setup_list[i]->quality_mapping);
  140398. if(req<map[0]){++i;continue;}
  140399. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140400. for(j=0;j<mappings;j++)
  140401. if(req>=map[j] && req<map[j+1])break;
  140402. hi->setup=setup_list[i];
  140403. if(j==mappings)
  140404. hi->base_setting=j-.001;
  140405. else{
  140406. float low=map[j];
  140407. float high=map[j+1];
  140408. float del=(req-low)/(high-low);
  140409. hi->base_setting=j+del;
  140410. }
  140411. return;
  140412. }
  140413. }
  140414. i++;
  140415. }
  140416. hi->setup=NULL;
  140417. }
  140418. int vorbis_encode_setup_init(vorbis_info *vi){
  140419. int i0=0,singleblock=0;
  140420. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140421. ve_setup_data_template *setup=NULL;
  140422. highlevel_encode_setup *hi=&ci->hi;
  140423. if(ci==NULL)return(OV_EINVAL);
  140424. if(!hi->impulse_block_p)i0=1;
  140425. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140426. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140427. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140428. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140429. setup=(ve_setup_data_template *)hi->setup;
  140430. if(setup==NULL)return(OV_EINVAL);
  140431. hi->set_in_stone=1;
  140432. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140433. setup->blocksize_short,
  140434. setup->blocksize_long);
  140435. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140436. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140437. setup->floor_books,
  140438. setup->floor_params,
  140439. setup->floor_short_mapping);
  140440. if(!singleblock)
  140441. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140442. setup->floor_books,
  140443. setup->floor_params,
  140444. setup->floor_long_mapping);
  140445. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140446. setup->global_params,
  140447. setup->global_mapping);
  140448. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140449. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140450. setup->psy_noise_normal_start[0],
  140451. setup->psy_noise_normal_partition[0],
  140452. setup->psy_noise_normal_thresh,
  140453. 0);
  140454. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140455. setup->psy_noise_normal_start[0],
  140456. setup->psy_noise_normal_partition[0],
  140457. setup->psy_noise_normal_thresh,
  140458. 1);
  140459. if(!singleblock){
  140460. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140461. setup->psy_noise_normal_start[1],
  140462. setup->psy_noise_normal_partition[1],
  140463. setup->psy_noise_normal_thresh,
  140464. 2);
  140465. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140466. setup->psy_noise_normal_start[1],
  140467. setup->psy_noise_normal_partition[1],
  140468. setup->psy_noise_normal_thresh,
  140469. 3);
  140470. }
  140471. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140472. setup->psy_tone_masteratt,
  140473. setup->psy_tone_0dB,
  140474. setup->psy_tone_adj_impulse);
  140475. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140476. setup->psy_tone_masteratt,
  140477. setup->psy_tone_0dB,
  140478. setup->psy_tone_adj_other);
  140479. if(!singleblock){
  140480. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140481. setup->psy_tone_masteratt,
  140482. setup->psy_tone_0dB,
  140483. setup->psy_tone_adj_other);
  140484. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140485. setup->psy_tone_masteratt,
  140486. setup->psy_tone_0dB,
  140487. setup->psy_tone_adj_long);
  140488. }
  140489. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140490. setup->psy_noise_compand,
  140491. setup->psy_noise_compand_short_mapping);
  140492. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140493. setup->psy_noise_compand,
  140494. setup->psy_noise_compand_short_mapping);
  140495. if(!singleblock){
  140496. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140497. setup->psy_noise_compand,
  140498. setup->psy_noise_compand_long_mapping);
  140499. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140500. setup->psy_noise_compand,
  140501. setup->psy_noise_compand_long_mapping);
  140502. }
  140503. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140504. setup->psy_tone_dBsuppress);
  140505. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140506. setup->psy_tone_dBsuppress);
  140507. if(!singleblock){
  140508. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140509. setup->psy_tone_dBsuppress);
  140510. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140511. setup->psy_tone_dBsuppress);
  140512. }
  140513. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140514. setup->psy_noise_dBsuppress,
  140515. setup->psy_noise_bias_impulse,
  140516. setup->psy_noiseguards,
  140517. (i0==0?hi->impulse_noisetune:0.));
  140518. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140519. setup->psy_noise_dBsuppress,
  140520. setup->psy_noise_bias_padding,
  140521. setup->psy_noiseguards,0.);
  140522. if(!singleblock){
  140523. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140524. setup->psy_noise_dBsuppress,
  140525. setup->psy_noise_bias_trans,
  140526. setup->psy_noiseguards,0.);
  140527. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140528. setup->psy_noise_dBsuppress,
  140529. setup->psy_noise_bias_long,
  140530. setup->psy_noiseguards,0.);
  140531. }
  140532. vorbis_encode_ath_setup(vi,0);
  140533. vorbis_encode_ath_setup(vi,1);
  140534. if(!singleblock){
  140535. vorbis_encode_ath_setup(vi,2);
  140536. vorbis_encode_ath_setup(vi,3);
  140537. }
  140538. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140539. if(hi->bitrate_av>0)
  140540. vi->bitrate_nominal=hi->bitrate_av;
  140541. else{
  140542. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140543. }
  140544. vi->bitrate_lower=hi->bitrate_min;
  140545. vi->bitrate_upper=hi->bitrate_max;
  140546. if(hi->bitrate_av)
  140547. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140548. else
  140549. vi->bitrate_window=0.;
  140550. if(hi->managed){
  140551. ci->bi.avg_rate=hi->bitrate_av;
  140552. ci->bi.min_rate=hi->bitrate_min;
  140553. ci->bi.max_rate=hi->bitrate_max;
  140554. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140555. ci->bi.reservoir_bias=
  140556. hi->bitrate_reservoir_bias;
  140557. ci->bi.slew_damp=hi->bitrate_av_damp;
  140558. }
  140559. return(0);
  140560. }
  140561. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140562. long channels,
  140563. long rate){
  140564. int ret=0,i,is;
  140565. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140566. highlevel_encode_setup *hi=&ci->hi;
  140567. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140568. double ds;
  140569. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140570. if(ret)return(ret);
  140571. is=hi->base_setting;
  140572. ds=hi->base_setting-is;
  140573. hi->short_setting=hi->base_setting;
  140574. hi->long_setting=hi->base_setting;
  140575. hi->managed=0;
  140576. hi->impulse_block_p=1;
  140577. hi->noise_normalize_p=1;
  140578. hi->stereo_point_setting=hi->base_setting;
  140579. hi->lowpass_kHz=
  140580. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140581. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140582. setup->psy_ath_float[is+1]*ds;
  140583. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140584. setup->psy_ath_abs[is+1]*ds;
  140585. hi->amplitude_track_dBpersec=-6.;
  140586. hi->trigger_setting=hi->base_setting;
  140587. for(i=0;i<4;i++){
  140588. hi->block[i].tone_mask_setting=hi->base_setting;
  140589. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140590. hi->block[i].noise_bias_setting=hi->base_setting;
  140591. hi->block[i].noise_compand_setting=hi->base_setting;
  140592. }
  140593. return(ret);
  140594. }
  140595. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140596. long channels,
  140597. long rate,
  140598. float quality){
  140599. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140600. highlevel_encode_setup *hi=&ci->hi;
  140601. quality+=.0000001;
  140602. if(quality>=1.)quality=.9999;
  140603. get_setup_template(vi,channels,rate,quality,0);
  140604. if(!hi->setup)return OV_EIMPL;
  140605. return vorbis_encode_setup_setting(vi,channels,rate);
  140606. }
  140607. int vorbis_encode_init_vbr(vorbis_info *vi,
  140608. long channels,
  140609. long rate,
  140610. float base_quality /* 0. to 1. */
  140611. ){
  140612. int ret=0;
  140613. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140614. if(ret){
  140615. vorbis_info_clear(vi);
  140616. return ret;
  140617. }
  140618. ret=vorbis_encode_setup_init(vi);
  140619. if(ret)
  140620. vorbis_info_clear(vi);
  140621. return(ret);
  140622. }
  140623. int vorbis_encode_setup_managed(vorbis_info *vi,
  140624. long channels,
  140625. long rate,
  140626. long max_bitrate,
  140627. long nominal_bitrate,
  140628. long min_bitrate){
  140629. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140630. highlevel_encode_setup *hi=&ci->hi;
  140631. double tnominal=nominal_bitrate;
  140632. int ret=0;
  140633. if(nominal_bitrate<=0.){
  140634. if(max_bitrate>0.){
  140635. if(min_bitrate>0.)
  140636. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140637. else
  140638. nominal_bitrate=max_bitrate*.875;
  140639. }else{
  140640. if(min_bitrate>0.){
  140641. nominal_bitrate=min_bitrate;
  140642. }else{
  140643. return(OV_EINVAL);
  140644. }
  140645. }
  140646. }
  140647. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140648. if(!hi->setup)return OV_EIMPL;
  140649. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140650. if(ret){
  140651. vorbis_info_clear(vi);
  140652. return ret;
  140653. }
  140654. hi->managed=1;
  140655. hi->bitrate_min=min_bitrate;
  140656. hi->bitrate_max=max_bitrate;
  140657. hi->bitrate_av=tnominal;
  140658. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140659. hi->bitrate_reservoir=nominal_bitrate*2;
  140660. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140661. return(ret);
  140662. }
  140663. int vorbis_encode_init(vorbis_info *vi,
  140664. long channels,
  140665. long rate,
  140666. long max_bitrate,
  140667. long nominal_bitrate,
  140668. long min_bitrate){
  140669. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140670. max_bitrate,
  140671. nominal_bitrate,
  140672. min_bitrate);
  140673. if(ret){
  140674. vorbis_info_clear(vi);
  140675. return(ret);
  140676. }
  140677. ret=vorbis_encode_setup_init(vi);
  140678. if(ret)
  140679. vorbis_info_clear(vi);
  140680. return(ret);
  140681. }
  140682. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140683. if(vi){
  140684. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140685. highlevel_encode_setup *hi=&ci->hi;
  140686. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140687. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140688. switch(number){
  140689. case OV_ECTL_RATEMANAGE_GET:
  140690. {
  140691. struct ovectl_ratemanage_arg *ai=
  140692. (struct ovectl_ratemanage_arg *)arg;
  140693. ai->management_active=hi->managed;
  140694. ai->bitrate_hard_window=ai->bitrate_av_window=
  140695. (double)hi->bitrate_reservoir/vi->rate;
  140696. ai->bitrate_av_window_center=1.;
  140697. ai->bitrate_hard_min=hi->bitrate_min;
  140698. ai->bitrate_hard_max=hi->bitrate_max;
  140699. ai->bitrate_av_lo=hi->bitrate_av;
  140700. ai->bitrate_av_hi=hi->bitrate_av;
  140701. }
  140702. return(0);
  140703. case OV_ECTL_RATEMANAGE_SET:
  140704. {
  140705. struct ovectl_ratemanage_arg *ai=
  140706. (struct ovectl_ratemanage_arg *)arg;
  140707. if(ai==NULL){
  140708. hi->managed=0;
  140709. }else{
  140710. hi->managed=ai->management_active;
  140711. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140712. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140713. }
  140714. }
  140715. return 0;
  140716. case OV_ECTL_RATEMANAGE_AVG:
  140717. {
  140718. struct ovectl_ratemanage_arg *ai=
  140719. (struct ovectl_ratemanage_arg *)arg;
  140720. if(ai==NULL){
  140721. hi->bitrate_av=0;
  140722. }else{
  140723. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140724. }
  140725. }
  140726. return(0);
  140727. case OV_ECTL_RATEMANAGE_HARD:
  140728. {
  140729. struct ovectl_ratemanage_arg *ai=
  140730. (struct ovectl_ratemanage_arg *)arg;
  140731. if(ai==NULL){
  140732. hi->bitrate_min=0;
  140733. hi->bitrate_max=0;
  140734. }else{
  140735. hi->bitrate_min=ai->bitrate_hard_min;
  140736. hi->bitrate_max=ai->bitrate_hard_max;
  140737. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140738. (hi->bitrate_max+hi->bitrate_min)*.5;
  140739. }
  140740. if(hi->bitrate_reservoir<128.)
  140741. hi->bitrate_reservoir=128.;
  140742. }
  140743. return(0);
  140744. case OV_ECTL_RATEMANAGE2_GET:
  140745. {
  140746. struct ovectl_ratemanage2_arg *ai=
  140747. (struct ovectl_ratemanage2_arg *)arg;
  140748. if(ai==NULL)return OV_EINVAL;
  140749. ai->management_active=hi->managed;
  140750. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140751. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140752. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140753. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140754. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140755. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140756. }
  140757. return (0);
  140758. case OV_ECTL_RATEMANAGE2_SET:
  140759. {
  140760. struct ovectl_ratemanage2_arg *ai=
  140761. (struct ovectl_ratemanage2_arg *)arg;
  140762. if(ai==NULL){
  140763. hi->managed=0;
  140764. }else{
  140765. if(ai->bitrate_limit_min_kbps>0 &&
  140766. ai->bitrate_average_kbps>0 &&
  140767. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140768. return OV_EINVAL;
  140769. if(ai->bitrate_limit_max_kbps>0 &&
  140770. ai->bitrate_average_kbps>0 &&
  140771. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140772. return OV_EINVAL;
  140773. if(ai->bitrate_limit_min_kbps>0 &&
  140774. ai->bitrate_limit_max_kbps>0 &&
  140775. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140776. return OV_EINVAL;
  140777. if(ai->bitrate_average_damping <= 0.)
  140778. return OV_EINVAL;
  140779. if(ai->bitrate_limit_reservoir_bits < 0)
  140780. return OV_EINVAL;
  140781. if(ai->bitrate_limit_reservoir_bias < 0.)
  140782. return OV_EINVAL;
  140783. if(ai->bitrate_limit_reservoir_bias > 1.)
  140784. return OV_EINVAL;
  140785. hi->managed=ai->management_active;
  140786. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140787. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140788. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140789. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140790. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140791. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140792. }
  140793. }
  140794. return 0;
  140795. case OV_ECTL_LOWPASS_GET:
  140796. {
  140797. double *farg=(double *)arg;
  140798. *farg=hi->lowpass_kHz;
  140799. }
  140800. return(0);
  140801. case OV_ECTL_LOWPASS_SET:
  140802. {
  140803. double *farg=(double *)arg;
  140804. hi->lowpass_kHz=*farg;
  140805. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140806. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140807. }
  140808. return(0);
  140809. case OV_ECTL_IBLOCK_GET:
  140810. {
  140811. double *farg=(double *)arg;
  140812. *farg=hi->impulse_noisetune;
  140813. }
  140814. return(0);
  140815. case OV_ECTL_IBLOCK_SET:
  140816. {
  140817. double *farg=(double *)arg;
  140818. hi->impulse_noisetune=*farg;
  140819. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140820. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140821. }
  140822. return(0);
  140823. }
  140824. return(OV_EIMPL);
  140825. }
  140826. return(OV_EINVAL);
  140827. }
  140828. #endif
  140829. /*** End of inlined file: vorbisenc.c ***/
  140830. /*** Start of inlined file: vorbisfile.c ***/
  140831. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140832. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140833. // tasks..
  140834. #if JUCE_MSVC
  140835. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140836. #endif
  140837. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140838. #if JUCE_USE_OGGVORBIS
  140839. #include <stdlib.h>
  140840. #include <stdio.h>
  140841. #include <errno.h>
  140842. #include <string.h>
  140843. #include <math.h>
  140844. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140845. over 8k gets what they deserve */
  140846. static long _get_data(OggVorbis_File *vf){
  140847. errno=0;
  140848. if(vf->datasource){
  140849. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140850. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140851. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140852. if(bytes==0 && errno)return(-1);
  140853. return(bytes);
  140854. }else
  140855. return(0);
  140856. }
  140857. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140858. if(vf->datasource){
  140859. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140860. vf->offset=offset;
  140861. ogg_sync_reset(&vf->oy);
  140862. }else{
  140863. return;
  140864. }
  140865. }
  140866. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140867. ogg_int64_t boundary){
  140868. if(boundary>0)boundary+=vf->offset;
  140869. while(1){
  140870. long more;
  140871. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140872. more=ogg_sync_pageseek(&vf->oy,og);
  140873. if(more<0){
  140874. vf->offset-=more;
  140875. }else{
  140876. if(more==0){
  140877. if(!boundary)return(OV_FALSE);
  140878. {
  140879. long ret=_get_data(vf);
  140880. if(ret==0)return(OV_EOF);
  140881. if(ret<0)return(OV_EREAD);
  140882. }
  140883. }else{
  140884. ogg_int64_t ret=vf->offset;
  140885. vf->offset+=more;
  140886. return(ret);
  140887. }
  140888. }
  140889. }
  140890. }
  140891. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140892. ogg_int64_t begin=vf->offset;
  140893. ogg_int64_t end=begin;
  140894. ogg_int64_t ret;
  140895. ogg_int64_t offset=-1;
  140896. while(offset==-1){
  140897. begin-=CHUNKSIZE;
  140898. if(begin<0)
  140899. begin=0;
  140900. _seek_helper(vf,begin);
  140901. while(vf->offset<end){
  140902. ret=_get_next_page(vf,og,end-vf->offset);
  140903. if(ret==OV_EREAD)return(OV_EREAD);
  140904. if(ret<0){
  140905. break;
  140906. }else{
  140907. offset=ret;
  140908. }
  140909. }
  140910. }
  140911. _seek_helper(vf,offset);
  140912. ret=_get_next_page(vf,og,CHUNKSIZE);
  140913. if(ret<0)
  140914. return(OV_EFAULT);
  140915. return(offset);
  140916. }
  140917. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140918. ogg_int64_t begin,
  140919. ogg_int64_t searched,
  140920. ogg_int64_t end,
  140921. long currentno,
  140922. long m){
  140923. ogg_int64_t endsearched=end;
  140924. ogg_int64_t next=end;
  140925. ogg_page og;
  140926. ogg_int64_t ret;
  140927. while(searched<endsearched){
  140928. ogg_int64_t bisect;
  140929. if(endsearched-searched<CHUNKSIZE){
  140930. bisect=searched;
  140931. }else{
  140932. bisect=(searched+endsearched)/2;
  140933. }
  140934. _seek_helper(vf,bisect);
  140935. ret=_get_next_page(vf,&og,-1);
  140936. if(ret==OV_EREAD)return(OV_EREAD);
  140937. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  140938. endsearched=bisect;
  140939. if(ret>=0)next=ret;
  140940. }else{
  140941. searched=ret+og.header_len+og.body_len;
  140942. }
  140943. }
  140944. _seek_helper(vf,next);
  140945. ret=_get_next_page(vf,&og,-1);
  140946. if(ret==OV_EREAD)return(OV_EREAD);
  140947. if(searched>=end || ret<0){
  140948. vf->links=m+1;
  140949. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  140950. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  140951. vf->offsets[m+1]=searched;
  140952. }else{
  140953. ret=_bisect_forward_serialno(vf,next,vf->offset,
  140954. end,ogg_page_serialno(&og),m+1);
  140955. if(ret==OV_EREAD)return(OV_EREAD);
  140956. }
  140957. vf->offsets[m]=begin;
  140958. vf->serialnos[m]=currentno;
  140959. return(0);
  140960. }
  140961. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  140962. long *serialno,ogg_page *og_ptr){
  140963. ogg_page og;
  140964. ogg_packet op;
  140965. int i,ret;
  140966. if(!og_ptr){
  140967. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  140968. if(llret==OV_EREAD)return(OV_EREAD);
  140969. if(llret<0)return OV_ENOTVORBIS;
  140970. og_ptr=&og;
  140971. }
  140972. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  140973. if(serialno)*serialno=vf->os.serialno;
  140974. vf->ready_state=STREAMSET;
  140975. vorbis_info_init(vi);
  140976. vorbis_comment_init(vc);
  140977. i=0;
  140978. while(i<3){
  140979. ogg_stream_pagein(&vf->os,og_ptr);
  140980. while(i<3){
  140981. int result=ogg_stream_packetout(&vf->os,&op);
  140982. if(result==0)break;
  140983. if(result==-1){
  140984. ret=OV_EBADHEADER;
  140985. goto bail_header;
  140986. }
  140987. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  140988. goto bail_header;
  140989. }
  140990. i++;
  140991. }
  140992. if(i<3)
  140993. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  140994. ret=OV_EBADHEADER;
  140995. goto bail_header;
  140996. }
  140997. }
  140998. return 0;
  140999. bail_header:
  141000. vorbis_info_clear(vi);
  141001. vorbis_comment_clear(vc);
  141002. vf->ready_state=OPENED;
  141003. return ret;
  141004. }
  141005. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  141006. ogg_page og;
  141007. int i;
  141008. ogg_int64_t ret;
  141009. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  141010. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  141011. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  141012. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  141013. for(i=0;i<vf->links;i++){
  141014. if(i==0){
  141015. vf->dataoffsets[i]=dataoffset;
  141016. _seek_helper(vf,dataoffset);
  141017. }else{
  141018. _seek_helper(vf,vf->offsets[i]);
  141019. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  141020. vf->dataoffsets[i]=-1;
  141021. }else{
  141022. vf->dataoffsets[i]=vf->offset;
  141023. }
  141024. }
  141025. if(vf->dataoffsets[i]!=-1){
  141026. ogg_int64_t accumulated=0;
  141027. long lastblock=-1;
  141028. int result;
  141029. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141030. while(1){
  141031. ogg_packet op;
  141032. ret=_get_next_page(vf,&og,-1);
  141033. if(ret<0)
  141034. break;
  141035. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141036. break;
  141037. ogg_stream_pagein(&vf->os,&og);
  141038. while((result=ogg_stream_packetout(&vf->os,&op))){
  141039. if(result>0){ /* ignore holes */
  141040. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141041. if(lastblock!=-1)
  141042. accumulated+=(lastblock+thisblock)>>2;
  141043. lastblock=thisblock;
  141044. }
  141045. }
  141046. if(ogg_page_granulepos(&og)!=-1){
  141047. accumulated= ogg_page_granulepos(&og)-accumulated;
  141048. break;
  141049. }
  141050. }
  141051. if(accumulated<0)accumulated=0;
  141052. vf->pcmlengths[i*2]=accumulated;
  141053. }
  141054. {
  141055. ogg_int64_t end=vf->offsets[i+1];
  141056. _seek_helper(vf,end);
  141057. while(1){
  141058. ret=_get_prev_page(vf,&og);
  141059. if(ret<0){
  141060. vorbis_info_clear(vf->vi+i);
  141061. vorbis_comment_clear(vf->vc+i);
  141062. break;
  141063. }
  141064. if(ogg_page_granulepos(&og)!=-1){
  141065. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141066. break;
  141067. }
  141068. vf->offset=ret;
  141069. }
  141070. }
  141071. }
  141072. }
  141073. static int _make_decode_ready(OggVorbis_File *vf){
  141074. if(vf->ready_state>STREAMSET)return 0;
  141075. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141076. if(vf->seekable){
  141077. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141078. return OV_EBADLINK;
  141079. }else{
  141080. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141081. return OV_EBADLINK;
  141082. }
  141083. vorbis_block_init(&vf->vd,&vf->vb);
  141084. vf->ready_state=INITSET;
  141085. vf->bittrack=0.f;
  141086. vf->samptrack=0.f;
  141087. return 0;
  141088. }
  141089. static int _open_seekable2(OggVorbis_File *vf){
  141090. long serialno=vf->current_serialno;
  141091. ogg_int64_t dataoffset=vf->offset, end;
  141092. ogg_page og;
  141093. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141094. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141095. end=_get_prev_page(vf,&og);
  141096. if(end<0)return(end);
  141097. if(ogg_page_serialno(&og)!=serialno){
  141098. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141099. }else{
  141100. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141101. }
  141102. _prefetch_all_headers(vf,dataoffset);
  141103. return(ov_raw_seek(vf,0));
  141104. }
  141105. static void _decode_clear(OggVorbis_File *vf){
  141106. vorbis_dsp_clear(&vf->vd);
  141107. vorbis_block_clear(&vf->vb);
  141108. vf->ready_state=OPENED;
  141109. }
  141110. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141111. ogg_packet *op_in,
  141112. int readp,
  141113. int spanp){
  141114. ogg_page og;
  141115. while(1){
  141116. if(vf->ready_state==INITSET){
  141117. while(1) {
  141118. ogg_packet op;
  141119. ogg_packet *op_ptr=(op_in?op_in:&op);
  141120. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141121. ogg_int64_t granulepos;
  141122. op_in=NULL;
  141123. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141124. if(result>0){
  141125. granulepos=op_ptr->granulepos;
  141126. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141127. header handling. The
  141128. header packets aren't
  141129. audio, so if/when we
  141130. submit them,
  141131. vorbis_synthesis will
  141132. reject them */
  141133. {
  141134. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141135. if(oldsamples)return(OV_EFAULT);
  141136. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141137. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141138. vf->bittrack+=op_ptr->bytes*8;
  141139. }
  141140. if(granulepos!=-1 && !op_ptr->e_o_s){
  141141. int link=(vf->seekable?vf->current_link:0);
  141142. int i,samples;
  141143. if(vf->seekable && link>0)
  141144. granulepos-=vf->pcmlengths[link*2];
  141145. if(granulepos<0)granulepos=0; /* actually, this
  141146. shouldn't be possible
  141147. here unless the stream
  141148. is very broken */
  141149. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141150. granulepos-=samples;
  141151. for(i=0;i<link;i++)
  141152. granulepos+=vf->pcmlengths[i*2+1];
  141153. vf->pcm_offset=granulepos;
  141154. }
  141155. return(1);
  141156. }
  141157. }
  141158. else
  141159. break;
  141160. }
  141161. }
  141162. if(vf->ready_state>=OPENED){
  141163. ogg_int64_t ret;
  141164. if(!readp)return(0);
  141165. if((ret=_get_next_page(vf,&og,-1))<0){
  141166. return(OV_EOF); /* eof.
  141167. leave unitialized */
  141168. }
  141169. vf->bittrack+=og.header_len*8;
  141170. if(vf->ready_state==INITSET){
  141171. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141172. if(!spanp)
  141173. return(OV_EOF);
  141174. _decode_clear(vf);
  141175. if(!vf->seekable){
  141176. vorbis_info_clear(vf->vi);
  141177. vorbis_comment_clear(vf->vc);
  141178. }
  141179. }
  141180. }
  141181. }
  141182. if(vf->ready_state!=INITSET){
  141183. int link;
  141184. if(vf->ready_state<STREAMSET){
  141185. if(vf->seekable){
  141186. vf->current_serialno=ogg_page_serialno(&og);
  141187. for(link=0;link<vf->links;link++)
  141188. if(vf->serialnos[link]==vf->current_serialno)break;
  141189. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141190. stream. error out,
  141191. leave machine
  141192. uninitialized */
  141193. vf->current_link=link;
  141194. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141195. vf->ready_state=STREAMSET;
  141196. }else{
  141197. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141198. if(ret)return(ret);
  141199. vf->current_link++;
  141200. link=0;
  141201. }
  141202. }
  141203. {
  141204. int ret=_make_decode_ready(vf);
  141205. if(ret<0)return ret;
  141206. }
  141207. }
  141208. ogg_stream_pagein(&vf->os,&og);
  141209. }
  141210. }
  141211. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141212. if(f==NULL)return(-1);
  141213. return fseek(f,off,whence);
  141214. }
  141215. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141216. long ibytes, ov_callbacks callbacks){
  141217. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141218. int ret;
  141219. memset(vf,0,sizeof(*vf));
  141220. vf->datasource=f;
  141221. vf->callbacks = callbacks;
  141222. ogg_sync_init(&vf->oy);
  141223. if(initial){
  141224. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141225. memcpy(buffer,initial,ibytes);
  141226. ogg_sync_wrote(&vf->oy,ibytes);
  141227. }
  141228. if(offsettest!=-1)vf->seekable=1;
  141229. vf->links=1;
  141230. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141231. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141232. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141233. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141234. vf->datasource=NULL;
  141235. ov_clear(vf);
  141236. }else
  141237. vf->ready_state=PARTOPEN;
  141238. return(ret);
  141239. }
  141240. static int _ov_open2(OggVorbis_File *vf){
  141241. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141242. vf->ready_state=OPENED;
  141243. if(vf->seekable){
  141244. int ret=_open_seekable2(vf);
  141245. if(ret){
  141246. vf->datasource=NULL;
  141247. ov_clear(vf);
  141248. }
  141249. return(ret);
  141250. }else
  141251. vf->ready_state=STREAMSET;
  141252. return 0;
  141253. }
  141254. int ov_clear(OggVorbis_File *vf){
  141255. if(vf){
  141256. vorbis_block_clear(&vf->vb);
  141257. vorbis_dsp_clear(&vf->vd);
  141258. ogg_stream_clear(&vf->os);
  141259. if(vf->vi && vf->links){
  141260. int i;
  141261. for(i=0;i<vf->links;i++){
  141262. vorbis_info_clear(vf->vi+i);
  141263. vorbis_comment_clear(vf->vc+i);
  141264. }
  141265. _ogg_free(vf->vi);
  141266. _ogg_free(vf->vc);
  141267. }
  141268. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141269. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141270. if(vf->serialnos)_ogg_free(vf->serialnos);
  141271. if(vf->offsets)_ogg_free(vf->offsets);
  141272. ogg_sync_clear(&vf->oy);
  141273. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141274. memset(vf,0,sizeof(*vf));
  141275. }
  141276. #ifdef DEBUG_LEAKS
  141277. _VDBG_dump();
  141278. #endif
  141279. return(0);
  141280. }
  141281. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141282. ov_callbacks callbacks){
  141283. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141284. if(ret)return ret;
  141285. return _ov_open2(vf);
  141286. }
  141287. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141288. ov_callbacks callbacks = {
  141289. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141290. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141291. (int (*)(void *)) fclose,
  141292. (long (*)(void *)) ftell
  141293. };
  141294. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141295. }
  141296. int ov_halfrate(OggVorbis_File *vf,int flag){
  141297. int i;
  141298. if(vf->vi==NULL)return OV_EINVAL;
  141299. if(!vf->seekable)return OV_EINVAL;
  141300. if(vf->ready_state>=STREAMSET)
  141301. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141302. will be able to swap this on the fly, but
  141303. for now dumping the decode machine is needed
  141304. to reinit the MDCT lookups. 1.1 libvorbis
  141305. is planned to be able to switch on the fly */
  141306. for(i=0;i<vf->links;i++){
  141307. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141308. ov_halfrate(vf,0);
  141309. return OV_EINVAL;
  141310. }
  141311. }
  141312. return 0;
  141313. }
  141314. int ov_halfrate_p(OggVorbis_File *vf){
  141315. if(vf->vi==NULL)return OV_EINVAL;
  141316. return vorbis_synthesis_halfrate_p(vf->vi);
  141317. }
  141318. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141319. ov_callbacks callbacks)
  141320. {
  141321. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141322. }
  141323. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141324. ov_callbacks callbacks = {
  141325. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141326. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141327. (int (*)(void *)) fclose,
  141328. (long (*)(void *)) ftell
  141329. };
  141330. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141331. }
  141332. int ov_test_open(OggVorbis_File *vf){
  141333. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141334. return _ov_open2(vf);
  141335. }
  141336. long ov_streams(OggVorbis_File *vf){
  141337. return vf->links;
  141338. }
  141339. long ov_seekable(OggVorbis_File *vf){
  141340. return vf->seekable;
  141341. }
  141342. long ov_bitrate(OggVorbis_File *vf,int i){
  141343. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141344. if(i>=vf->links)return(OV_EINVAL);
  141345. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141346. if(i<0){
  141347. ogg_int64_t bits=0;
  141348. int i;
  141349. float br;
  141350. for(i=0;i<vf->links;i++)
  141351. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141352. br = bits/ov_time_total(vf,-1);
  141353. return(rint(br));
  141354. }else{
  141355. if(vf->seekable){
  141356. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141357. }else{
  141358. if(vf->vi[i].bitrate_nominal>0){
  141359. return vf->vi[i].bitrate_nominal;
  141360. }else{
  141361. if(vf->vi[i].bitrate_upper>0){
  141362. if(vf->vi[i].bitrate_lower>0){
  141363. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141364. }else{
  141365. return vf->vi[i].bitrate_upper;
  141366. }
  141367. }
  141368. return(OV_FALSE);
  141369. }
  141370. }
  141371. }
  141372. }
  141373. long ov_bitrate_instant(OggVorbis_File *vf){
  141374. int link=(vf->seekable?vf->current_link:0);
  141375. long ret;
  141376. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141377. if(vf->samptrack==0)return(OV_FALSE);
  141378. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141379. vf->bittrack=0.f;
  141380. vf->samptrack=0.f;
  141381. return(ret);
  141382. }
  141383. long ov_serialnumber(OggVorbis_File *vf,int i){
  141384. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141385. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141386. if(i<0){
  141387. return(vf->current_serialno);
  141388. }else{
  141389. return(vf->serialnos[i]);
  141390. }
  141391. }
  141392. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141393. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141394. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141395. if(i<0){
  141396. ogg_int64_t acc=0;
  141397. int i;
  141398. for(i=0;i<vf->links;i++)
  141399. acc+=ov_raw_total(vf,i);
  141400. return(acc);
  141401. }else{
  141402. return(vf->offsets[i+1]-vf->offsets[i]);
  141403. }
  141404. }
  141405. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141406. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141407. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141408. if(i<0){
  141409. ogg_int64_t acc=0;
  141410. int i;
  141411. for(i=0;i<vf->links;i++)
  141412. acc+=ov_pcm_total(vf,i);
  141413. return(acc);
  141414. }else{
  141415. return(vf->pcmlengths[i*2+1]);
  141416. }
  141417. }
  141418. double ov_time_total(OggVorbis_File *vf,int i){
  141419. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141420. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141421. if(i<0){
  141422. double acc=0;
  141423. int i;
  141424. for(i=0;i<vf->links;i++)
  141425. acc+=ov_time_total(vf,i);
  141426. return(acc);
  141427. }else{
  141428. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141429. }
  141430. }
  141431. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141432. ogg_stream_state work_os;
  141433. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141434. if(!vf->seekable)
  141435. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141436. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141437. vf->pcm_offset=-1;
  141438. ogg_stream_reset_serialno(&vf->os,
  141439. vf->current_serialno); /* must set serialno */
  141440. vorbis_synthesis_restart(&vf->vd);
  141441. _seek_helper(vf,pos);
  141442. {
  141443. ogg_page og;
  141444. ogg_packet op;
  141445. int lastblock=0;
  141446. int accblock=0;
  141447. int thisblock;
  141448. int eosflag;
  141449. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141450. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141451. return from not necessarily
  141452. starting from the beginning */
  141453. while(1){
  141454. if(vf->ready_state>=STREAMSET){
  141455. int result=ogg_stream_packetout(&work_os,&op);
  141456. if(result>0){
  141457. if(vf->vi[vf->current_link].codec_setup){
  141458. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141459. if(thisblock<0){
  141460. ogg_stream_packetout(&vf->os,NULL);
  141461. thisblock=0;
  141462. }else{
  141463. if(eosflag)
  141464. ogg_stream_packetout(&vf->os,NULL);
  141465. else
  141466. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141467. }
  141468. if(op.granulepos!=-1){
  141469. int i,link=vf->current_link;
  141470. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141471. if(granulepos<0)granulepos=0;
  141472. for(i=0;i<link;i++)
  141473. granulepos+=vf->pcmlengths[i*2+1];
  141474. vf->pcm_offset=granulepos-accblock;
  141475. break;
  141476. }
  141477. lastblock=thisblock;
  141478. continue;
  141479. }else
  141480. ogg_stream_packetout(&vf->os,NULL);
  141481. }
  141482. }
  141483. if(!lastblock){
  141484. if(_get_next_page(vf,&og,-1)<0){
  141485. vf->pcm_offset=ov_pcm_total(vf,-1);
  141486. break;
  141487. }
  141488. }else{
  141489. vf->pcm_offset=-1;
  141490. break;
  141491. }
  141492. if(vf->ready_state>=STREAMSET)
  141493. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141494. _decode_clear(vf); /* clear out stream state */
  141495. ogg_stream_clear(&work_os);
  141496. }
  141497. if(vf->ready_state<STREAMSET){
  141498. int link;
  141499. vf->current_serialno=ogg_page_serialno(&og);
  141500. for(link=0;link<vf->links;link++)
  141501. if(vf->serialnos[link]==vf->current_serialno)break;
  141502. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141503. error out, leave
  141504. machine uninitialized */
  141505. vf->current_link=link;
  141506. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141507. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141508. vf->ready_state=STREAMSET;
  141509. }
  141510. ogg_stream_pagein(&vf->os,&og);
  141511. ogg_stream_pagein(&work_os,&og);
  141512. eosflag=ogg_page_eos(&og);
  141513. }
  141514. }
  141515. ogg_stream_clear(&work_os);
  141516. vf->bittrack=0.f;
  141517. vf->samptrack=0.f;
  141518. return(0);
  141519. seek_error:
  141520. vf->pcm_offset=-1;
  141521. ogg_stream_clear(&work_os);
  141522. _decode_clear(vf);
  141523. return OV_EBADLINK;
  141524. }
  141525. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141526. int link=-1;
  141527. ogg_int64_t result=0;
  141528. ogg_int64_t total=ov_pcm_total(vf,-1);
  141529. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141530. if(!vf->seekable)return(OV_ENOSEEK);
  141531. if(pos<0 || pos>total)return(OV_EINVAL);
  141532. for(link=vf->links-1;link>=0;link--){
  141533. total-=vf->pcmlengths[link*2+1];
  141534. if(pos>=total)break;
  141535. }
  141536. {
  141537. ogg_int64_t end=vf->offsets[link+1];
  141538. ogg_int64_t begin=vf->offsets[link];
  141539. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141540. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141541. ogg_int64_t target=pos-total+begintime;
  141542. ogg_int64_t best=begin;
  141543. ogg_page og;
  141544. while(begin<end){
  141545. ogg_int64_t bisect;
  141546. if(end-begin<CHUNKSIZE){
  141547. bisect=begin;
  141548. }else{
  141549. bisect=begin +
  141550. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141551. if(bisect<=begin)
  141552. bisect=begin+1;
  141553. }
  141554. _seek_helper(vf,bisect);
  141555. while(begin<end){
  141556. result=_get_next_page(vf,&og,end-vf->offset);
  141557. if(result==OV_EREAD) goto seek_error;
  141558. if(result<0){
  141559. if(bisect<=begin+1)
  141560. end=begin; /* found it */
  141561. else{
  141562. if(bisect==0) goto seek_error;
  141563. bisect-=CHUNKSIZE;
  141564. if(bisect<=begin)bisect=begin+1;
  141565. _seek_helper(vf,bisect);
  141566. }
  141567. }else{
  141568. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141569. if(granulepos==-1)continue;
  141570. if(granulepos<target){
  141571. best=result; /* raw offset of packet with granulepos */
  141572. begin=vf->offset; /* raw offset of next page */
  141573. begintime=granulepos;
  141574. if(target-begintime>44100)break;
  141575. bisect=begin; /* *not* begin + 1 */
  141576. }else{
  141577. if(bisect<=begin+1)
  141578. end=begin; /* found it */
  141579. else{
  141580. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141581. end=result;
  141582. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141583. if(bisect<=begin)bisect=begin+1;
  141584. _seek_helper(vf,bisect);
  141585. }else{
  141586. end=result;
  141587. endtime=granulepos;
  141588. break;
  141589. }
  141590. }
  141591. }
  141592. }
  141593. }
  141594. }
  141595. {
  141596. ogg_page og;
  141597. ogg_packet op;
  141598. _seek_helper(vf,best);
  141599. vf->pcm_offset=-1;
  141600. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141601. if(link!=vf->current_link){
  141602. _decode_clear(vf);
  141603. vf->current_link=link;
  141604. vf->current_serialno=ogg_page_serialno(&og);
  141605. vf->ready_state=STREAMSET;
  141606. }else{
  141607. vorbis_synthesis_restart(&vf->vd);
  141608. }
  141609. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141610. ogg_stream_pagein(&vf->os,&og);
  141611. while(1){
  141612. result=ogg_stream_packetpeek(&vf->os,&op);
  141613. if(result==0){
  141614. _seek_helper(vf,best);
  141615. while(1){
  141616. result=_get_prev_page(vf,&og);
  141617. if(result<0) goto seek_error;
  141618. if(ogg_page_granulepos(&og)>-1 ||
  141619. !ogg_page_continued(&og)){
  141620. return ov_raw_seek(vf,result);
  141621. }
  141622. vf->offset=result;
  141623. }
  141624. }
  141625. if(result<0){
  141626. result = OV_EBADPACKET;
  141627. goto seek_error;
  141628. }
  141629. if(op.granulepos!=-1){
  141630. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141631. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141632. vf->pcm_offset+=total;
  141633. break;
  141634. }else
  141635. result=ogg_stream_packetout(&vf->os,NULL);
  141636. }
  141637. }
  141638. }
  141639. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141640. result=OV_EFAULT;
  141641. goto seek_error;
  141642. }
  141643. vf->bittrack=0.f;
  141644. vf->samptrack=0.f;
  141645. return(0);
  141646. seek_error:
  141647. vf->pcm_offset=-1;
  141648. _decode_clear(vf);
  141649. return (int)result;
  141650. }
  141651. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141652. int thisblock,lastblock=0;
  141653. int ret=ov_pcm_seek_page(vf,pos);
  141654. if(ret<0)return(ret);
  141655. if((ret=_make_decode_ready(vf)))return ret;
  141656. while(1){
  141657. ogg_packet op;
  141658. ogg_page og;
  141659. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141660. if(ret>0){
  141661. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141662. if(thisblock<0){
  141663. ogg_stream_packetout(&vf->os,NULL);
  141664. continue; /* non audio packet */
  141665. }
  141666. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141667. if(vf->pcm_offset+((thisblock+
  141668. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141669. ogg_stream_packetout(&vf->os,NULL);
  141670. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141671. only tracking, no
  141672. pcm_decode */
  141673. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141674. if(op.granulepos>-1){
  141675. int i;
  141676. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141677. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141678. for(i=0;i<vf->current_link;i++)
  141679. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141680. }
  141681. lastblock=thisblock;
  141682. }else{
  141683. if(ret<0 && ret!=OV_HOLE)break;
  141684. if(_get_next_page(vf,&og,-1)<0)break;
  141685. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141686. if(vf->ready_state<STREAMSET){
  141687. int link;
  141688. vf->current_serialno=ogg_page_serialno(&og);
  141689. for(link=0;link<vf->links;link++)
  141690. if(vf->serialnos[link]==vf->current_serialno)break;
  141691. if(link==vf->links)return(OV_EBADLINK);
  141692. vf->current_link=link;
  141693. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141694. vf->ready_state=STREAMSET;
  141695. ret=_make_decode_ready(vf);
  141696. if(ret)return ret;
  141697. lastblock=0;
  141698. }
  141699. ogg_stream_pagein(&vf->os,&og);
  141700. }
  141701. }
  141702. vf->bittrack=0.f;
  141703. vf->samptrack=0.f;
  141704. while(vf->pcm_offset<pos){
  141705. ogg_int64_t target=pos-vf->pcm_offset;
  141706. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141707. if(samples>target)samples=target;
  141708. vorbis_synthesis_read(&vf->vd,samples);
  141709. vf->pcm_offset+=samples;
  141710. if(samples<target)
  141711. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141712. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141713. }
  141714. return 0;
  141715. }
  141716. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141717. int link=-1;
  141718. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141719. double time_total=ov_time_total(vf,-1);
  141720. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141721. if(!vf->seekable)return(OV_ENOSEEK);
  141722. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141723. for(link=vf->links-1;link>=0;link--){
  141724. pcm_total-=vf->pcmlengths[link*2+1];
  141725. time_total-=ov_time_total(vf,link);
  141726. if(seconds>=time_total)break;
  141727. }
  141728. {
  141729. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141730. return(ov_pcm_seek(vf,target));
  141731. }
  141732. }
  141733. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141734. int link=-1;
  141735. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141736. double time_total=ov_time_total(vf,-1);
  141737. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141738. if(!vf->seekable)return(OV_ENOSEEK);
  141739. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141740. for(link=vf->links-1;link>=0;link--){
  141741. pcm_total-=vf->pcmlengths[link*2+1];
  141742. time_total-=ov_time_total(vf,link);
  141743. if(seconds>=time_total)break;
  141744. }
  141745. {
  141746. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141747. return(ov_pcm_seek_page(vf,target));
  141748. }
  141749. }
  141750. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141751. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141752. return(vf->offset);
  141753. }
  141754. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141755. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141756. return(vf->pcm_offset);
  141757. }
  141758. double ov_time_tell(OggVorbis_File *vf){
  141759. int link=0;
  141760. ogg_int64_t pcm_total=0;
  141761. double time_total=0.f;
  141762. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141763. if(vf->seekable){
  141764. pcm_total=ov_pcm_total(vf,-1);
  141765. time_total=ov_time_total(vf,-1);
  141766. for(link=vf->links-1;link>=0;link--){
  141767. pcm_total-=vf->pcmlengths[link*2+1];
  141768. time_total-=ov_time_total(vf,link);
  141769. if(vf->pcm_offset>=pcm_total)break;
  141770. }
  141771. }
  141772. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141773. }
  141774. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141775. if(vf->seekable){
  141776. if(link<0)
  141777. if(vf->ready_state>=STREAMSET)
  141778. return vf->vi+vf->current_link;
  141779. else
  141780. return vf->vi;
  141781. else
  141782. if(link>=vf->links)
  141783. return NULL;
  141784. else
  141785. return vf->vi+link;
  141786. }else{
  141787. return vf->vi;
  141788. }
  141789. }
  141790. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141791. if(vf->seekable){
  141792. if(link<0)
  141793. if(vf->ready_state>=STREAMSET)
  141794. return vf->vc+vf->current_link;
  141795. else
  141796. return vf->vc;
  141797. else
  141798. if(link>=vf->links)
  141799. return NULL;
  141800. else
  141801. return vf->vc+link;
  141802. }else{
  141803. return vf->vc;
  141804. }
  141805. }
  141806. static int host_is_big_endian() {
  141807. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141808. unsigned char *bytewise = (unsigned char *)&pattern;
  141809. if (bytewise[0] == 0xfe) return 1;
  141810. return 0;
  141811. }
  141812. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141813. int bigendianp,int word,int sgned,int *bitstream){
  141814. int i,j;
  141815. int host_endian = host_is_big_endian();
  141816. float **pcm;
  141817. long samples;
  141818. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141819. while(1){
  141820. if(vf->ready_state==INITSET){
  141821. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141822. if(samples)break;
  141823. }
  141824. {
  141825. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141826. if(ret==OV_EOF)
  141827. return(0);
  141828. if(ret<=0)
  141829. return(ret);
  141830. }
  141831. }
  141832. if(samples>0){
  141833. long channels=ov_info(vf,-1)->channels;
  141834. long bytespersample=word * channels;
  141835. vorbis_fpu_control fpu;
  141836. (void) fpu; // (to avoid a warning about it being unused)
  141837. if(samples>length/bytespersample)samples=length/bytespersample;
  141838. if(samples <= 0)
  141839. return OV_EINVAL;
  141840. {
  141841. int val;
  141842. if(word==1){
  141843. int off=(sgned?0:128);
  141844. vorbis_fpu_setround(&fpu);
  141845. for(j=0;j<samples;j++)
  141846. for(i=0;i<channels;i++){
  141847. val=vorbis_ftoi(pcm[i][j]*128.f);
  141848. if(val>127)val=127;
  141849. else if(val<-128)val=-128;
  141850. *buffer++=val+off;
  141851. }
  141852. vorbis_fpu_restore(fpu);
  141853. }else{
  141854. int off=(sgned?0:32768);
  141855. if(host_endian==bigendianp){
  141856. if(sgned){
  141857. vorbis_fpu_setround(&fpu);
  141858. for(i=0;i<channels;i++) { /* It's faster in this order */
  141859. float *src=pcm[i];
  141860. short *dest=((short *)buffer)+i;
  141861. for(j=0;j<samples;j++) {
  141862. val=vorbis_ftoi(src[j]*32768.f);
  141863. if(val>32767)val=32767;
  141864. else if(val<-32768)val=-32768;
  141865. *dest=val;
  141866. dest+=channels;
  141867. }
  141868. }
  141869. vorbis_fpu_restore(fpu);
  141870. }else{
  141871. vorbis_fpu_setround(&fpu);
  141872. for(i=0;i<channels;i++) {
  141873. float *src=pcm[i];
  141874. short *dest=((short *)buffer)+i;
  141875. for(j=0;j<samples;j++) {
  141876. val=vorbis_ftoi(src[j]*32768.f);
  141877. if(val>32767)val=32767;
  141878. else if(val<-32768)val=-32768;
  141879. *dest=val+off;
  141880. dest+=channels;
  141881. }
  141882. }
  141883. vorbis_fpu_restore(fpu);
  141884. }
  141885. }else if(bigendianp){
  141886. vorbis_fpu_setround(&fpu);
  141887. for(j=0;j<samples;j++)
  141888. for(i=0;i<channels;i++){
  141889. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141890. if(val>32767)val=32767;
  141891. else if(val<-32768)val=-32768;
  141892. val+=off;
  141893. *buffer++=(val>>8);
  141894. *buffer++=(val&0xff);
  141895. }
  141896. vorbis_fpu_restore(fpu);
  141897. }else{
  141898. int val;
  141899. vorbis_fpu_setround(&fpu);
  141900. for(j=0;j<samples;j++)
  141901. for(i=0;i<channels;i++){
  141902. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141903. if(val>32767)val=32767;
  141904. else if(val<-32768)val=-32768;
  141905. val+=off;
  141906. *buffer++=(val&0xff);
  141907. *buffer++=(val>>8);
  141908. }
  141909. vorbis_fpu_restore(fpu);
  141910. }
  141911. }
  141912. }
  141913. vorbis_synthesis_read(&vf->vd,samples);
  141914. vf->pcm_offset+=samples;
  141915. if(bitstream)*bitstream=vf->current_link;
  141916. return(samples*bytespersample);
  141917. }else{
  141918. return(samples);
  141919. }
  141920. }
  141921. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141922. int *bitstream){
  141923. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141924. while(1){
  141925. if(vf->ready_state==INITSET){
  141926. float **pcm;
  141927. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141928. if(samples){
  141929. if(pcm_channels)*pcm_channels=pcm;
  141930. if(samples>length)samples=length;
  141931. vorbis_synthesis_read(&vf->vd,samples);
  141932. vf->pcm_offset+=samples;
  141933. if(bitstream)*bitstream=vf->current_link;
  141934. return samples;
  141935. }
  141936. }
  141937. {
  141938. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141939. if(ret==OV_EOF)return(0);
  141940. if(ret<=0)return(ret);
  141941. }
  141942. }
  141943. }
  141944. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  141945. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  141946. ogg_int64_t off);
  141947. static void _ov_splice(float **pcm,float **lappcm,
  141948. int n1, int n2,
  141949. int ch1, int ch2,
  141950. float *w1, float *w2){
  141951. int i,j;
  141952. float *w=w1;
  141953. int n=n1;
  141954. if(n1>n2){
  141955. n=n2;
  141956. w=w2;
  141957. }
  141958. for(j=0;j<ch1 && j<ch2;j++){
  141959. float *s=lappcm[j];
  141960. float *d=pcm[j];
  141961. for(i=0;i<n;i++){
  141962. float wd=w[i]*w[i];
  141963. float ws=1.-wd;
  141964. d[i]=d[i]*wd + s[i]*ws;
  141965. }
  141966. }
  141967. for(;j<ch2;j++){
  141968. float *d=pcm[j];
  141969. for(i=0;i<n;i++){
  141970. float wd=w[i]*w[i];
  141971. d[i]=d[i]*wd;
  141972. }
  141973. }
  141974. }
  141975. static int _ov_initset(OggVorbis_File *vf){
  141976. while(1){
  141977. if(vf->ready_state==INITSET)break;
  141978. {
  141979. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141980. if(ret<0 && ret!=OV_HOLE)return(ret);
  141981. }
  141982. }
  141983. return 0;
  141984. }
  141985. static int _ov_initprime(OggVorbis_File *vf){
  141986. vorbis_dsp_state *vd=&vf->vd;
  141987. while(1){
  141988. if(vf->ready_state==INITSET)
  141989. if(vorbis_synthesis_pcmout(vd,NULL))break;
  141990. {
  141991. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141992. if(ret<0 && ret!=OV_HOLE)return(ret);
  141993. }
  141994. }
  141995. return 0;
  141996. }
  141997. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  141998. float **lappcm,int lapsize){
  141999. int lapcount=0,i;
  142000. float **pcm;
  142001. while(lapcount<lapsize){
  142002. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  142003. if(samples){
  142004. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142005. for(i=0;i<vi->channels;i++)
  142006. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142007. lapcount+=samples;
  142008. vorbis_synthesis_read(vd,samples);
  142009. }else{
  142010. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  142011. if(ret==OV_EOF)break;
  142012. }
  142013. }
  142014. if(lapcount<lapsize){
  142015. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  142016. if(samples==0){
  142017. for(i=0;i<vi->channels;i++)
  142018. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  142019. lapcount=lapsize;
  142020. }else{
  142021. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142022. for(i=0;i<vi->channels;i++)
  142023. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142024. lapcount+=samples;
  142025. }
  142026. }
  142027. }
  142028. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142029. vorbis_info *vi1,*vi2;
  142030. float **lappcm;
  142031. float **pcm;
  142032. float *w1,*w2;
  142033. int n1,n2,i,ret,hs1,hs2;
  142034. if(vf1==vf2)return(0); /* degenerate case */
  142035. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142036. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142037. ret=_ov_initset(vf1);
  142038. if(ret)return(ret);
  142039. ret=_ov_initprime(vf2);
  142040. if(ret)return(ret);
  142041. vi1=ov_info(vf1,-1);
  142042. vi2=ov_info(vf2,-1);
  142043. hs1=ov_halfrate_p(vf1);
  142044. hs2=ov_halfrate_p(vf2);
  142045. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142046. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142047. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142048. w1=vorbis_window(&vf1->vd,0);
  142049. w2=vorbis_window(&vf2->vd,0);
  142050. for(i=0;i<vi1->channels;i++)
  142051. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142052. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142053. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142054. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142055. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142056. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142057. return(0);
  142058. }
  142059. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142060. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142061. vorbis_info *vi;
  142062. float **lappcm;
  142063. float **pcm;
  142064. float *w1,*w2;
  142065. int n1,n2,ch1,ch2,hs;
  142066. int i,ret;
  142067. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142068. ret=_ov_initset(vf);
  142069. if(ret)return(ret);
  142070. vi=ov_info(vf,-1);
  142071. hs=ov_halfrate_p(vf);
  142072. ch1=vi->channels;
  142073. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142074. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142075. persistent; even if the decode state
  142076. from this link gets dumped, this
  142077. window array continues to exist */
  142078. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142079. for(i=0;i<ch1;i++)
  142080. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142081. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142082. ret=localseek(vf,pos);
  142083. if(ret)return ret;
  142084. ret=_ov_initprime(vf);
  142085. if(ret)return(ret);
  142086. vi=ov_info(vf,-1);
  142087. ch2=vi->channels;
  142088. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142089. w2=vorbis_window(&vf->vd,0);
  142090. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142091. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142092. return(0);
  142093. }
  142094. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142095. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142096. }
  142097. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142098. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142099. }
  142100. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142101. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142102. }
  142103. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142104. int (*localseek)(OggVorbis_File *,double)){
  142105. vorbis_info *vi;
  142106. float **lappcm;
  142107. float **pcm;
  142108. float *w1,*w2;
  142109. int n1,n2,ch1,ch2,hs;
  142110. int i,ret;
  142111. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142112. ret=_ov_initset(vf);
  142113. if(ret)return(ret);
  142114. vi=ov_info(vf,-1);
  142115. hs=ov_halfrate_p(vf);
  142116. ch1=vi->channels;
  142117. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142118. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142119. persistent; even if the decode state
  142120. from this link gets dumped, this
  142121. window array continues to exist */
  142122. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142123. for(i=0;i<ch1;i++)
  142124. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142125. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142126. ret=localseek(vf,pos);
  142127. if(ret)return ret;
  142128. ret=_ov_initprime(vf);
  142129. if(ret)return(ret);
  142130. vi=ov_info(vf,-1);
  142131. ch2=vi->channels;
  142132. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142133. w2=vorbis_window(&vf->vd,0);
  142134. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142135. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142136. return(0);
  142137. }
  142138. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142139. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142140. }
  142141. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142142. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142143. }
  142144. #endif
  142145. /*** End of inlined file: vorbisfile.c ***/
  142146. /*** Start of inlined file: window.c ***/
  142147. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142148. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142149. // tasks..
  142150. #if JUCE_MSVC
  142151. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142152. #endif
  142153. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142154. #if JUCE_USE_OGGVORBIS
  142155. #include <stdlib.h>
  142156. #include <math.h>
  142157. static float vwin64[32] = {
  142158. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142159. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142160. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142161. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142162. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142163. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142164. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142165. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142166. };
  142167. static float vwin128[64] = {
  142168. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142169. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142170. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142171. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142172. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142173. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142174. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142175. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142176. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142177. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142178. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142179. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142180. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142181. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142182. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142183. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142184. };
  142185. static float vwin256[128] = {
  142186. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142187. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142188. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142189. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142190. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142191. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142192. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142193. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142194. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142195. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142196. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142197. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142198. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142199. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142200. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142201. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142202. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142203. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142204. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142205. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142206. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142207. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142208. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142209. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142210. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142211. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142212. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142213. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142214. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142215. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142216. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142217. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142218. };
  142219. static float vwin512[256] = {
  142220. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142221. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142222. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142223. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142224. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142225. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142226. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142227. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142228. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142229. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142230. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142231. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142232. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142233. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142234. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142235. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142236. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142237. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142238. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142239. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142240. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142241. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142242. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142243. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142244. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142245. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142246. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142247. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142248. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142249. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142250. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142251. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142252. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142253. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142254. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142255. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142256. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142257. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142258. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142259. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142260. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142261. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142262. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142263. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142264. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142265. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142266. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142267. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142268. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142269. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142270. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142271. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142272. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142273. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142274. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142275. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142276. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142277. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142278. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142279. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142280. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142281. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142282. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142283. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142284. };
  142285. static float vwin1024[512] = {
  142286. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142287. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142288. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142289. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142290. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142291. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142292. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142293. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142294. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142295. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142296. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142297. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142298. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142299. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142300. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142301. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142302. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142303. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142304. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142305. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142306. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142307. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142308. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142309. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142310. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142311. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142312. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142313. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142314. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142315. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142316. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142317. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142318. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142319. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142320. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142321. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142322. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142323. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142324. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142325. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142326. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142327. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142328. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142329. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142330. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142331. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142332. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142333. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142334. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142335. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142336. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142337. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142338. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142339. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142340. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142341. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142342. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142343. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142344. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142345. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142346. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142347. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142348. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142349. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142350. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142351. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142352. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142353. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142354. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142355. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142356. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142357. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142358. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142359. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142360. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142361. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142362. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142363. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142364. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142365. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142366. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142367. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142368. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142369. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142370. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142371. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142372. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142373. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142374. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142375. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142376. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142377. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142378. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142379. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142380. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142381. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142382. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142383. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142384. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142385. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142386. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142387. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142388. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142389. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142390. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142391. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142392. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142393. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142394. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142395. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142396. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142397. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142398. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142399. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142400. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142401. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142402. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142403. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142404. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142405. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142406. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142407. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142408. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142409. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142410. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142411. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142412. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142413. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142414. };
  142415. static float vwin2048[1024] = {
  142416. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142417. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142418. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142419. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142420. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142421. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142422. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142423. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142424. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142425. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142426. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142427. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142428. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142429. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142430. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142431. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142432. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142433. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142434. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142435. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142436. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142437. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142438. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142439. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142440. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142441. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142442. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142443. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142444. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142445. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142446. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142447. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142448. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142449. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142450. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142451. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142452. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142453. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142454. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142455. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142456. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142457. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142458. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142459. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142460. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142461. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142462. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142463. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142464. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142465. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142466. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142467. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142468. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142469. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142470. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142471. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142472. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142473. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142474. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142475. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142476. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142477. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142478. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142479. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142480. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142481. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142482. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142483. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142484. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142485. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142486. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142487. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142488. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142489. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142490. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142491. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142492. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142493. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142494. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142495. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142496. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142497. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142498. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142499. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142500. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142501. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142502. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142503. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142504. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142505. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142506. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142507. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142508. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142509. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142510. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142511. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142512. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142513. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142514. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142515. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142516. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142517. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142518. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142519. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142520. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142521. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142522. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142523. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142524. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142525. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142526. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142527. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142528. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142529. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142530. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142531. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142532. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142533. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142534. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142535. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142536. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142537. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142538. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142539. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142540. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142541. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142542. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142543. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142544. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142545. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142546. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142547. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142548. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142549. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142550. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142551. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142552. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142553. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142554. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142555. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142556. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142557. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142558. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142559. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142560. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142561. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142562. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142563. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142564. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142565. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142566. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142567. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142568. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142569. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142570. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142571. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142572. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142573. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142574. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142575. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142576. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142577. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142578. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142579. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142580. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142581. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142582. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142583. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142584. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142585. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142586. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142587. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142588. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142589. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142590. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142591. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142592. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142593. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142594. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142595. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142596. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142597. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142598. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142599. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142600. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142601. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142602. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142603. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142604. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142605. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142606. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142607. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142608. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142609. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142610. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142611. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142612. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142613. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142614. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142615. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142616. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142617. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142618. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142619. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142620. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142621. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142622. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142623. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142624. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142625. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142626. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142627. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142628. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142629. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142630. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142631. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142632. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142633. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142634. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142635. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142636. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142637. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142638. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142639. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142640. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142641. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142642. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142643. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142644. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142645. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142646. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142647. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142648. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142649. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142650. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142651. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142652. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142653. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142654. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142655. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142656. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142657. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142658. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142659. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142660. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142661. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142662. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142663. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142664. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142665. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142666. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142667. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142668. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142669. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142670. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142671. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142672. };
  142673. static float vwin4096[2048] = {
  142674. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142675. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142676. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142677. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142678. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142679. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142680. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142681. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142682. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142683. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142684. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142685. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142686. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142687. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142688. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142689. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142690. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142691. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142692. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142693. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142694. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142695. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142696. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142697. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142698. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142699. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142700. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142701. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142702. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142703. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142704. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142705. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142706. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142707. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142708. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142709. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142710. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142711. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142712. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142713. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142714. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142715. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142716. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142717. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142718. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142719. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142720. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142721. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142722. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142723. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142724. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142725. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142726. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142727. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142728. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142729. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142730. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142731. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142732. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142733. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142734. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142735. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142736. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142737. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142738. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142739. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142740. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142741. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142742. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142743. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142744. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142745. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142746. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142747. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142748. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142749. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142750. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142751. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142752. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142753. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142754. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142755. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142756. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142757. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142758. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142759. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142760. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142761. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142762. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142763. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142764. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142765. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142766. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142767. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142768. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142769. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142770. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142771. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142772. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142773. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142774. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142775. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142776. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142777. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142778. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142779. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142780. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142781. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142782. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142783. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142784. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142785. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142786. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142787. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142788. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142789. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142790. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142791. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142792. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142793. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142794. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142795. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142796. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142797. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142798. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142799. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142800. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142801. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142802. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142803. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142804. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142805. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142806. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142807. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142808. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142809. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142810. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142811. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142812. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142813. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142814. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142815. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142816. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142817. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142818. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142819. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142820. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142821. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142822. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142823. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142824. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142825. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142826. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142827. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142828. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142829. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142830. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142831. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142832. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142833. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142834. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142835. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142836. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142837. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142838. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142839. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142840. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142841. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142842. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142843. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142844. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142845. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142846. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142847. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142848. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142849. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142850. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142851. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142852. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142853. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142854. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142855. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142856. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142857. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142858. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142859. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142860. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142861. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142862. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142863. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142864. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142865. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142866. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142867. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142868. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142869. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142870. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142871. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142872. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142873. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142874. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142875. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142876. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142877. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142878. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142879. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142880. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142881. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142882. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142883. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142884. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142885. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142886. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142887. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142888. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142889. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142890. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142891. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142892. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142893. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142894. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142895. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142896. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142897. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142898. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142899. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142900. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142901. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142902. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142903. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142904. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142905. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142906. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142907. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142908. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142909. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142910. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142911. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142912. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142913. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142914. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142915. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142916. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142917. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142918. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142919. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142920. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142921. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142922. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142923. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142924. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142925. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142926. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142927. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142928. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142929. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142930. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142931. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142932. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142933. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142934. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142935. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142936. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  142937. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  142938. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  142939. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  142940. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  142941. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  142942. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  142943. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  142944. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  142945. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  142946. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  142947. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  142948. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  142949. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  142950. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  142951. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  142952. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  142953. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  142954. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  142955. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  142956. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  142957. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  142958. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  142959. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  142960. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  142961. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  142962. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  142963. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  142964. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  142965. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  142966. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  142967. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  142968. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  142969. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  142970. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  142971. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  142972. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  142973. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  142974. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  142975. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  142976. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  142977. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  142978. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  142979. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  142980. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  142981. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  142982. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  142983. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  142984. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  142985. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  142986. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  142987. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  142988. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  142989. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  142990. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  142991. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  142992. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  142993. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  142994. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  142995. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  142996. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  142997. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  142998. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  142999. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  143000. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  143001. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  143002. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  143003. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  143004. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  143005. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  143006. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  143007. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  143008. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  143009. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  143010. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  143011. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  143012. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  143013. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  143014. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  143015. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  143016. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  143017. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  143018. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  143019. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  143020. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  143021. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  143022. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  143023. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  143024. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143025. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143026. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143027. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143028. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143029. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143030. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143031. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143032. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143033. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143034. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143035. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143036. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143037. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143038. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143039. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143040. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143041. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143042. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143043. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143044. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143045. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143046. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143047. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143048. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143049. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143050. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143051. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143052. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143053. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143054. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143055. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143056. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143057. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143058. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143059. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143060. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143061. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143062. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143063. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143064. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143065. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143066. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143067. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143068. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143069. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143070. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143071. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143072. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143073. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143074. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143075. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143076. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143077. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143078. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143079. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143080. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143081. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143082. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143083. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143084. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143085. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143086. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143087. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143088. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143089. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143090. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143091. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143092. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143093. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143094. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143095. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143096. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143097. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143098. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143099. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143100. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143101. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143102. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143103. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143104. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143105. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143106. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143107. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143108. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143109. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143110. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143111. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143112. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143113. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143114. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143115. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143116. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143117. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143118. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143119. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143120. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143121. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143122. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143123. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143124. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143125. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143126. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143127. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143128. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143129. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143130. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143131. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143132. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143133. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143134. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143135. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143136. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143137. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143138. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143139. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143140. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143141. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143142. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143143. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143144. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143145. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143146. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143147. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143148. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143149. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143150. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143151. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143152. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143153. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143154. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143155. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143156. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143157. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143158. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143159. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143160. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143161. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143162. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143163. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143164. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143165. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143166. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143167. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143168. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143169. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143170. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143171. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143172. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143173. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143174. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143175. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143176. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143177. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143178. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143179. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143180. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143181. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143182. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143183. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143184. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143185. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143186. };
  143187. static float vwin8192[4096] = {
  143188. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143189. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143190. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143191. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143192. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143193. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143194. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143195. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143196. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143197. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143198. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143199. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143200. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143201. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143202. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143203. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143204. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143205. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143206. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143207. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143208. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143209. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143210. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143211. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143212. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143213. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143214. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143215. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143216. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143217. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143218. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143219. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143220. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143221. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143222. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143223. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143224. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143225. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143226. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143227. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143228. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143229. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143230. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143231. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143232. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143233. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143234. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143235. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143236. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143237. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143238. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143239. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143240. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143241. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143242. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143243. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143244. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143245. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143246. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143247. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143248. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143249. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143250. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143251. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143252. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143253. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143254. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143255. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143256. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143257. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143258. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143259. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143260. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143261. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143262. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143263. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143264. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143265. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143266. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143267. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143268. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143269. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143270. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143271. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143272. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143273. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143274. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143275. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143276. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143277. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143278. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143279. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143280. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143281. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143282. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143283. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143284. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143285. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143286. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143287. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143288. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143289. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143290. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143291. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143292. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143293. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143294. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143295. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143296. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143297. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143298. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143299. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143300. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143301. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143302. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143303. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143304. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143305. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143306. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143307. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143308. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143309. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143310. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143311. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143312. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143313. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143314. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143315. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143316. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143317. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143318. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143319. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143320. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143321. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143322. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143323. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143324. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143325. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143326. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143327. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143328. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143329. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143330. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143331. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143332. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143333. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143334. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143335. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143336. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143337. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143338. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143339. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143340. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143341. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143342. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143343. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143344. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143345. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143346. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143347. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143348. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143349. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143350. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143351. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143352. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143353. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143354. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143355. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143356. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143357. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143358. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143359. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143360. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143361. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143362. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143363. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143364. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143365. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143366. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143367. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143368. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143369. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143370. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143371. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143372. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143373. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143374. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143375. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143376. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143377. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143378. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143379. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143380. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143381. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143382. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143383. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143384. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143385. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143386. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143387. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143388. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143389. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143390. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143391. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143392. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143393. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143394. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143395. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143396. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143397. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143398. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143399. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143400. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143401. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143402. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143403. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143404. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143405. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143406. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143407. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143408. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143409. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143410. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143411. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143412. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143413. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143414. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143415. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143416. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143417. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143418. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143419. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143420. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143421. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143422. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143423. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143424. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143425. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143426. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143427. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143428. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143429. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143430. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143431. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143432. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143433. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143434. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143435. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143436. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143437. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143438. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143439. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143440. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143441. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143442. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143443. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143444. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143445. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143446. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143447. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143448. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143449. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143450. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143451. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143452. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143453. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143454. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143455. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143456. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143457. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143458. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143459. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143460. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143461. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143462. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143463. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143464. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143465. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143466. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143467. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143468. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143469. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143470. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143471. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143472. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143473. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143474. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143475. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143476. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143477. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143478. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143479. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143480. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143481. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143482. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143483. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143484. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143485. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143486. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143487. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143488. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143489. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143490. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143491. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143492. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143493. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143494. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143495. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143496. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143497. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143498. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143499. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143500. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143501. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143502. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143503. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143504. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143505. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143506. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143507. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143508. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143509. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143510. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143511. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143512. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143513. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143514. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143515. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143516. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143517. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143518. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143519. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143520. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143521. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143522. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143523. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143524. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143525. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143526. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143527. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143528. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143529. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143530. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143531. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143532. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143533. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143534. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143535. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143536. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143537. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143538. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143539. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143540. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143541. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143542. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143543. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143544. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143545. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143546. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143547. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143548. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143549. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143550. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143551. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143552. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143553. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143554. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143555. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143556. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143557. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143558. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143559. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143560. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143561. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143562. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143563. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143564. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143565. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143566. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143567. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143568. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143569. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143570. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143571. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143572. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143573. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143574. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143575. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143576. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143577. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143578. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143579. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143580. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143581. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143582. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143583. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143584. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143585. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143586. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143587. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143588. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143589. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143590. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143591. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143592. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143593. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143594. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143595. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143596. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143597. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143598. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143599. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143600. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143601. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143602. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143603. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143604. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143605. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143606. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143607. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143608. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143609. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143610. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143611. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143612. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143613. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143614. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143615. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143616. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143617. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143618. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143619. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143620. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143621. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143622. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143623. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143624. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143625. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143626. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143627. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143628. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143629. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143630. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143631. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143632. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143633. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143634. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143635. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143636. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143637. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143638. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143639. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143640. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143641. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143642. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143643. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143644. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143645. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143646. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143647. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143648. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143649. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143650. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143651. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143652. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143653. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143654. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143655. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143656. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143657. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143658. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143659. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143660. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143661. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143662. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143663. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143664. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143665. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143666. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143667. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143668. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143669. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143670. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143671. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143672. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143673. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143674. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143675. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143676. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143677. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143678. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143679. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143680. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143681. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143682. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143683. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143684. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143685. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143686. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143687. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143688. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143689. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143690. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143691. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143692. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143693. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143694. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143695. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143696. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143697. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143698. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143699. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143700. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143701. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143702. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143703. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143704. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143705. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143706. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143707. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143708. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143709. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143710. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143711. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143712. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143713. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143714. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143715. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143716. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143717. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143718. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143719. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143720. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143721. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143722. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143723. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143724. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143725. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143726. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143727. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143728. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143729. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143730. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143731. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143732. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143733. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143734. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143735. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143736. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143737. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143738. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143739. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143740. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143741. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143742. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143743. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143744. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143745. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143746. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143747. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143748. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143749. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143750. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143751. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143752. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143753. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143754. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143755. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143756. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143757. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143758. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143759. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143760. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143761. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143762. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143763. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143764. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143765. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143766. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143767. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143768. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143769. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143770. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143771. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143772. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143773. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143774. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143775. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143776. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143777. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143778. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143779. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143780. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143781. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143782. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143783. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143784. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143785. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143786. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143787. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143788. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143789. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143790. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143791. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143792. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143793. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143794. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143795. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143796. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143797. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143798. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143799. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143800. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143801. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143802. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143803. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143804. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143805. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143806. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143807. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143808. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143809. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143810. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143811. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143812. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143813. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143814. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143815. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143816. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143817. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143818. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143819. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143820. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143821. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143822. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143823. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143824. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143825. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143826. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143827. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143828. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143829. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143830. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143831. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143832. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143833. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143834. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143835. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143836. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143837. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143838. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143839. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143840. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143841. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143842. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143843. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143844. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143845. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143846. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143847. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143848. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143849. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143850. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143851. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143852. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143853. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143854. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143855. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143856. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143857. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143858. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143859. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143860. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143861. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143862. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143863. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143864. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143865. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143866. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143867. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143868. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143869. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143870. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143871. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143872. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143873. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143874. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143875. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143876. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143877. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143878. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143879. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143880. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143881. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143882. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143883. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143884. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143885. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143886. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143887. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143888. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143889. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143890. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143891. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143892. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143893. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143894. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143895. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143896. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143897. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143898. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143899. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143900. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143901. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143902. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143903. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143904. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143905. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143906. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143907. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143908. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143909. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143910. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143911. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143912. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143913. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143914. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143915. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143916. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143917. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143918. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143919. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143920. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143921. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143922. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143923. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143924. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143925. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143926. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143927. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143928. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143929. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143930. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143931. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143932. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143933. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143934. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143935. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143936. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  143937. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  143938. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  143939. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  143940. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  143941. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  143942. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  143943. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  143944. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  143945. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  143946. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  143947. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  143948. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  143949. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  143950. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  143951. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  143952. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  143953. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  143954. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  143955. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  143956. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  143957. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  143958. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  143959. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  143960. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  143961. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  143962. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  143963. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  143964. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  143965. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  143966. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  143967. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  143968. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  143969. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  143970. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  143971. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  143972. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  143973. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  143974. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  143975. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  143976. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  143977. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  143978. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  143979. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  143980. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  143981. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  143982. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  143983. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  143984. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  143985. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  143986. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  143987. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  143988. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  143989. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  143990. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  143991. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  143992. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  143993. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  143994. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  143995. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  143996. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  143997. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  143998. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  143999. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  144000. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  144001. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  144002. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  144003. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  144004. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  144005. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  144006. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  144007. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  144008. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  144009. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  144010. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  144011. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  144012. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  144013. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  144014. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  144015. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  144016. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  144017. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  144018. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  144019. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  144020. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  144021. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  144022. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  144023. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  144024. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144025. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144026. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144027. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144028. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144029. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144030. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144031. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144032. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144033. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144034. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144035. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144036. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144037. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144038. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144039. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144040. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144041. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144042. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144043. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144044. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144045. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144046. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144047. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144048. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144049. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144050. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144051. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144052. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144053. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144054. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144055. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144056. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144057. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144058. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144059. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144060. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144061. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144062. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144063. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144064. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144065. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144066. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144067. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144068. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144069. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144070. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144071. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144072. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144073. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144074. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144075. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144076. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144077. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144078. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144079. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144080. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144081. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144082. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144083. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144084. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144085. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144086. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144087. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144088. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144089. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144090. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144091. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144092. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144093. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144094. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144095. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144096. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144097. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144098. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144099. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144100. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144101. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144102. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144103. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144104. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144105. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144106. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144107. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144108. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144109. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144110. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144111. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144112. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144113. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144114. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144115. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144116. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144117. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144118. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144119. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144120. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144121. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144122. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144123. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144124. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144125. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144126. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144127. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144128. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144129. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144130. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144131. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144132. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144133. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144134. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144135. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144136. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144137. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144138. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144139. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144140. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144141. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144142. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144143. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144144. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144145. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144146. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144147. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144148. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144149. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144150. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144151. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144152. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144153. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144154. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144155. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144156. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144157. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144158. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144159. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144160. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144161. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144162. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144163. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144164. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144165. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144166. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144167. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144168. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144169. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144170. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144171. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144172. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144173. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144174. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144175. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144176. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144177. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144178. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144179. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144180. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144181. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144182. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144183. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144184. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144185. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144186. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144187. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144188. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144189. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144190. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144191. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144192. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144193. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144194. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144195. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144196. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144197. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144198. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144199. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144200. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144201. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144202. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144203. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144204. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144205. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144206. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144207. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144208. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144209. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144210. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144211. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144212. };
  144213. static float *vwin[8] = {
  144214. vwin64,
  144215. vwin128,
  144216. vwin256,
  144217. vwin512,
  144218. vwin1024,
  144219. vwin2048,
  144220. vwin4096,
  144221. vwin8192,
  144222. };
  144223. float *_vorbis_window_get(int n){
  144224. return vwin[n];
  144225. }
  144226. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144227. int lW,int W,int nW){
  144228. lW=(W?lW:0);
  144229. nW=(W?nW:0);
  144230. {
  144231. float *windowLW=vwin[winno[lW]];
  144232. float *windowNW=vwin[winno[nW]];
  144233. long n=blocksizes[W];
  144234. long ln=blocksizes[lW];
  144235. long rn=blocksizes[nW];
  144236. long leftbegin=n/4-ln/4;
  144237. long leftend=leftbegin+ln/2;
  144238. long rightbegin=n/2+n/4-rn/4;
  144239. long rightend=rightbegin+rn/2;
  144240. int i,p;
  144241. for(i=0;i<leftbegin;i++)
  144242. d[i]=0.f;
  144243. for(p=0;i<leftend;i++,p++)
  144244. d[i]*=windowLW[p];
  144245. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144246. d[i]*=windowNW[p];
  144247. for(;i<n;i++)
  144248. d[i]=0.f;
  144249. }
  144250. }
  144251. #endif
  144252. /*** End of inlined file: window.c ***/
  144253. #else
  144254. #include <vorbis/vorbisenc.h>
  144255. #include <vorbis/codec.h>
  144256. #include <vorbis/vorbisfile.h>
  144257. #endif
  144258. }
  144259. BEGIN_JUCE_NAMESPACE
  144260. static const char* const oggFormatName = "Ogg-Vorbis file";
  144261. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144262. class OggReader : public AudioFormatReader
  144263. {
  144264. OggVorbisNamespace::OggVorbis_File ovFile;
  144265. OggVorbisNamespace::ov_callbacks callbacks;
  144266. AudioSampleBuffer reservoir;
  144267. int reservoirStart, samplesInReservoir;
  144268. public:
  144269. OggReader (InputStream* const inp)
  144270. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144271. reservoir (2, 4096),
  144272. reservoirStart (0),
  144273. samplesInReservoir (0)
  144274. {
  144275. using namespace OggVorbisNamespace;
  144276. sampleRate = 0;
  144277. usesFloatingPointData = true;
  144278. callbacks.read_func = &oggReadCallback;
  144279. callbacks.seek_func = &oggSeekCallback;
  144280. callbacks.close_func = &oggCloseCallback;
  144281. callbacks.tell_func = &oggTellCallback;
  144282. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144283. if (err == 0)
  144284. {
  144285. vorbis_info* info = ov_info (&ovFile, -1);
  144286. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144287. numChannels = info->channels;
  144288. bitsPerSample = 16;
  144289. sampleRate = info->rate;
  144290. reservoir.setSize (numChannels,
  144291. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144292. }
  144293. }
  144294. ~OggReader()
  144295. {
  144296. ov_clear (&ovFile);
  144297. }
  144298. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144299. int64 startSampleInFile, int numSamples)
  144300. {
  144301. while (numSamples > 0)
  144302. {
  144303. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144304. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144305. {
  144306. // got a few samples overlapping, so use them before seeking..
  144307. const int numToUse = jmin (numSamples, numAvailable);
  144308. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144309. if (destSamples[i] != 0)
  144310. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144311. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144312. sizeof (float) * numToUse);
  144313. startSampleInFile += numToUse;
  144314. numSamples -= numToUse;
  144315. startOffsetInDestBuffer += numToUse;
  144316. if (numSamples == 0)
  144317. break;
  144318. }
  144319. if (startSampleInFile < reservoirStart
  144320. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144321. {
  144322. // buffer miss, so refill the reservoir
  144323. int bitStream = 0;
  144324. reservoirStart = jmax (0, (int) startSampleInFile);
  144325. samplesInReservoir = reservoir.getNumSamples();
  144326. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  144327. ov_pcm_seek (&ovFile, reservoirStart);
  144328. int offset = 0;
  144329. int numToRead = samplesInReservoir;
  144330. while (numToRead > 0)
  144331. {
  144332. float** dataIn = 0;
  144333. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144334. if (samps <= 0)
  144335. break;
  144336. jassert (samps <= numToRead);
  144337. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144338. {
  144339. memcpy (reservoir.getSampleData (i, offset),
  144340. dataIn[i],
  144341. sizeof (float) * samps);
  144342. }
  144343. numToRead -= samps;
  144344. offset += samps;
  144345. }
  144346. if (numToRead > 0)
  144347. reservoir.clear (offset, numToRead);
  144348. }
  144349. }
  144350. if (numSamples > 0)
  144351. {
  144352. for (int i = numDestChannels; --i >= 0;)
  144353. if (destSamples[i] != 0)
  144354. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144355. sizeof (int) * numSamples);
  144356. }
  144357. return true;
  144358. }
  144359. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144360. {
  144361. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144362. }
  144363. static int oggSeekCallback (void* datasource, OggVorbisNamespace::ogg_int64_t offset, int whence)
  144364. {
  144365. InputStream* const in = (InputStream*) datasource;
  144366. if (whence == SEEK_CUR)
  144367. offset += in->getPosition();
  144368. else if (whence == SEEK_END)
  144369. offset += in->getTotalLength();
  144370. in->setPosition (offset);
  144371. return 0;
  144372. }
  144373. static int oggCloseCallback (void*)
  144374. {
  144375. return 0;
  144376. }
  144377. static long oggTellCallback (void* datasource)
  144378. {
  144379. return (long) ((InputStream*) datasource)->getPosition();
  144380. }
  144381. juce_UseDebuggingNewOperator
  144382. };
  144383. class OggWriter : public AudioFormatWriter
  144384. {
  144385. OggVorbisNamespace::ogg_stream_state os;
  144386. OggVorbisNamespace::ogg_page og;
  144387. OggVorbisNamespace::ogg_packet op;
  144388. OggVorbisNamespace::vorbis_info vi;
  144389. OggVorbisNamespace::vorbis_comment vc;
  144390. OggVorbisNamespace::vorbis_dsp_state vd;
  144391. OggVorbisNamespace::vorbis_block vb;
  144392. public:
  144393. bool ok;
  144394. OggWriter (OutputStream* const out,
  144395. const double sampleRate,
  144396. const int numChannels,
  144397. const int bitsPerSample,
  144398. const int qualityIndex)
  144399. : AudioFormatWriter (out, TRANS (oggFormatName),
  144400. sampleRate,
  144401. numChannels,
  144402. bitsPerSample)
  144403. {
  144404. using namespace OggVorbisNamespace;
  144405. ok = false;
  144406. vorbis_info_init (&vi);
  144407. if (vorbis_encode_init_vbr (&vi,
  144408. numChannels,
  144409. (int) sampleRate,
  144410. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144411. {
  144412. vorbis_comment_init (&vc);
  144413. if (JUCEApplication::getInstance() != 0)
  144414. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144415. vorbis_analysis_init (&vd, &vi);
  144416. vorbis_block_init (&vd, &vb);
  144417. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144418. ogg_packet header;
  144419. ogg_packet header_comm;
  144420. ogg_packet header_code;
  144421. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144422. ogg_stream_packetin (&os, &header);
  144423. ogg_stream_packetin (&os, &header_comm);
  144424. ogg_stream_packetin (&os, &header_code);
  144425. for (;;)
  144426. {
  144427. if (ogg_stream_flush (&os, &og) == 0)
  144428. break;
  144429. output->write (og.header, og.header_len);
  144430. output->write (og.body, og.body_len);
  144431. }
  144432. ok = true;
  144433. }
  144434. }
  144435. ~OggWriter()
  144436. {
  144437. if (ok)
  144438. {
  144439. // write a zero-length packet to show ogg that we're finished..
  144440. write (0, 0);
  144441. ogg_stream_clear (&os);
  144442. vorbis_block_clear (&vb);
  144443. vorbis_dsp_clear (&vd);
  144444. vorbis_comment_clear (&vc);
  144445. vorbis_info_clear (&vi);
  144446. output->flush();
  144447. }
  144448. else
  144449. {
  144450. vorbis_info_clear (&vi);
  144451. output = 0; // to stop the base class deleting this, as it needs to be returned
  144452. // to the caller of createWriter()
  144453. }
  144454. }
  144455. bool write (const int** samplesToWrite, int numSamples)
  144456. {
  144457. if (! ok)
  144458. return false;
  144459. if (numSamples > 0)
  144460. {
  144461. const double gain = 1.0 / 0x80000000u;
  144462. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144463. for (int i = numChannels; --i >= 0;)
  144464. {
  144465. float* const dst = vorbisBuffer[i];
  144466. const int* const src = samplesToWrite [i];
  144467. if (src != 0 && dst != 0)
  144468. {
  144469. for (int j = 0; j < numSamples; ++j)
  144470. dst[j] = (float) (src[j] * gain);
  144471. }
  144472. }
  144473. }
  144474. vorbis_analysis_wrote (&vd, numSamples);
  144475. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144476. {
  144477. vorbis_analysis (&vb, 0);
  144478. vorbis_bitrate_addblock (&vb);
  144479. while (vorbis_bitrate_flushpacket (&vd, &op))
  144480. {
  144481. ogg_stream_packetin (&os, &op);
  144482. for (;;)
  144483. {
  144484. if (ogg_stream_pageout (&os, &og) == 0)
  144485. break;
  144486. output->write (og.header, og.header_len);
  144487. output->write (og.body, og.body_len);
  144488. if (ogg_page_eos (&og))
  144489. break;
  144490. }
  144491. }
  144492. }
  144493. return true;
  144494. }
  144495. juce_UseDebuggingNewOperator
  144496. };
  144497. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144498. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  144499. {
  144500. }
  144501. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144502. {
  144503. }
  144504. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144505. {
  144506. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144507. return Array <int> (rates);
  144508. }
  144509. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144510. {
  144511. Array <int> depths;
  144512. depths.add (32);
  144513. return depths;
  144514. }
  144515. bool OggVorbisAudioFormat::canDoStereo()
  144516. {
  144517. return true;
  144518. }
  144519. bool OggVorbisAudioFormat::canDoMono()
  144520. {
  144521. return true;
  144522. }
  144523. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144524. const bool deleteStreamIfOpeningFails)
  144525. {
  144526. ScopedPointer <OggReader> r (new OggReader (in));
  144527. if (r->sampleRate != 0)
  144528. return r.release();
  144529. if (! deleteStreamIfOpeningFails)
  144530. r->input = 0;
  144531. return 0;
  144532. }
  144533. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144534. double sampleRate,
  144535. unsigned int numChannels,
  144536. int bitsPerSample,
  144537. const StringPairArray& /*metadataValues*/,
  144538. int qualityOptionIndex)
  144539. {
  144540. ScopedPointer <OggWriter> w (new OggWriter (out,
  144541. sampleRate,
  144542. numChannels,
  144543. bitsPerSample,
  144544. qualityOptionIndex));
  144545. return w->ok ? w.release() : 0;
  144546. }
  144547. bool OggVorbisAudioFormat::isCompressed()
  144548. {
  144549. return true;
  144550. }
  144551. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144552. {
  144553. StringArray s;
  144554. s.add ("Low Quality");
  144555. s.add ("Medium Quality");
  144556. s.add ("High Quality");
  144557. return s;
  144558. }
  144559. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144560. {
  144561. FileInputStream* const in = source.createInputStream();
  144562. if (in != 0)
  144563. {
  144564. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144565. if (r != 0)
  144566. {
  144567. const int64 numSamps = r->lengthInSamples;
  144568. r = 0;
  144569. const int64 fileNumSamps = source.getSize() / 4;
  144570. const double ratio = numSamps / (double) fileNumSamps;
  144571. if (ratio > 12.0)
  144572. return 0;
  144573. else if (ratio > 6.0)
  144574. return 1;
  144575. else
  144576. return 2;
  144577. }
  144578. }
  144579. return 1;
  144580. }
  144581. END_JUCE_NAMESPACE
  144582. #endif
  144583. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144584. #endif
  144585. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144586. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144587. #if JUCE_MSVC
  144588. #pragma warning (push)
  144589. #endif
  144590. namespace jpeglibNamespace
  144591. {
  144592. #if JUCE_INCLUDE_JPEGLIB_CODE
  144593. #if JUCE_MINGW
  144594. typedef unsigned char boolean;
  144595. #endif
  144596. extern "C"
  144597. {
  144598. #define JPEG_INTERNALS
  144599. #undef FAR
  144600. /*** Start of inlined file: jpeglib.h ***/
  144601. #ifndef JPEGLIB_H
  144602. #define JPEGLIB_H
  144603. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144604. /*** Start of inlined file: jconfig.h ***/
  144605. // disable all the warnings under MSVC
  144606. #ifdef _MSC_VER
  144607. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144608. #endif
  144609. #ifdef __BORLANDC__
  144610. #pragma warn -8057
  144611. #pragma warn -8019
  144612. #pragma warn -8004
  144613. #pragma warn -8008
  144614. #endif
  144615. #define HAVE_PROTOTYPES
  144616. #define HAVE_UNSIGNED_CHAR
  144617. #define HAVE_UNSIGNED_SHORT
  144618. #undef CHAR_IS_UNSIGNED
  144619. #define HAVE_STDDEF_H
  144620. #define HAVE_STDLIB_H
  144621. #undef NEED_BSD_STRINGS
  144622. #undef NEED_SYS_TYPES_H
  144623. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144624. #undef NEED_SHORT_EXTERNAL_NAMES
  144625. #undef INCOMPLETE_TYPES_BROKEN
  144626. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144627. typedef unsigned char boolean;
  144628. #endif
  144629. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144630. #ifdef JPEG_INTERNALS
  144631. #undef RIGHT_SHIFT_IS_UNSIGNED
  144632. #endif /* JPEG_INTERNALS */
  144633. #ifdef JPEG_CJPEG_DJPEG
  144634. #define BMP_SUPPORTED /* BMP image file format */
  144635. #define GIF_SUPPORTED /* GIF image file format */
  144636. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144637. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144638. #define TARGA_SUPPORTED /* Targa image file format */
  144639. #define TWO_FILE_COMMANDLINE /* optional */
  144640. #define USE_SETMODE /* Microsoft has setmode() */
  144641. #undef NEED_SIGNAL_CATCHER
  144642. #undef DONT_USE_B_MODE
  144643. #undef PROGRESS_REPORT /* optional */
  144644. #endif /* JPEG_CJPEG_DJPEG */
  144645. /*** End of inlined file: jconfig.h ***/
  144646. /* widely used configuration options */
  144647. #endif
  144648. /*** Start of inlined file: jmorecfg.h ***/
  144649. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144650. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144651. #if BITS_IN_JSAMPLE == 8
  144652. #ifdef HAVE_UNSIGNED_CHAR
  144653. typedef unsigned char JSAMPLE;
  144654. #define GETJSAMPLE(value) ((int) (value))
  144655. #else /* not HAVE_UNSIGNED_CHAR */
  144656. typedef char JSAMPLE;
  144657. #ifdef CHAR_IS_UNSIGNED
  144658. #define GETJSAMPLE(value) ((int) (value))
  144659. #else
  144660. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144661. #endif /* CHAR_IS_UNSIGNED */
  144662. #endif /* HAVE_UNSIGNED_CHAR */
  144663. #define MAXJSAMPLE 255
  144664. #define CENTERJSAMPLE 128
  144665. #endif /* BITS_IN_JSAMPLE == 8 */
  144666. #if BITS_IN_JSAMPLE == 12
  144667. typedef short JSAMPLE;
  144668. #define GETJSAMPLE(value) ((int) (value))
  144669. #define MAXJSAMPLE 4095
  144670. #define CENTERJSAMPLE 2048
  144671. #endif /* BITS_IN_JSAMPLE == 12 */
  144672. typedef short JCOEF;
  144673. #ifdef HAVE_UNSIGNED_CHAR
  144674. typedef unsigned char JOCTET;
  144675. #define GETJOCTET(value) (value)
  144676. #else /* not HAVE_UNSIGNED_CHAR */
  144677. typedef char JOCTET;
  144678. #ifdef CHAR_IS_UNSIGNED
  144679. #define GETJOCTET(value) (value)
  144680. #else
  144681. #define GETJOCTET(value) ((value) & 0xFF)
  144682. #endif /* CHAR_IS_UNSIGNED */
  144683. #endif /* HAVE_UNSIGNED_CHAR */
  144684. #ifdef HAVE_UNSIGNED_CHAR
  144685. typedef unsigned char UINT8;
  144686. #else /* not HAVE_UNSIGNED_CHAR */
  144687. #ifdef CHAR_IS_UNSIGNED
  144688. typedef char UINT8;
  144689. #else /* not CHAR_IS_UNSIGNED */
  144690. typedef short UINT8;
  144691. #endif /* CHAR_IS_UNSIGNED */
  144692. #endif /* HAVE_UNSIGNED_CHAR */
  144693. #ifdef HAVE_UNSIGNED_SHORT
  144694. typedef unsigned short UINT16;
  144695. #else /* not HAVE_UNSIGNED_SHORT */
  144696. typedef unsigned int UINT16;
  144697. #endif /* HAVE_UNSIGNED_SHORT */
  144698. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144699. typedef short INT16;
  144700. #endif
  144701. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144702. typedef long INT32;
  144703. #endif
  144704. typedef unsigned int JDIMENSION;
  144705. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144706. #define METHODDEF(type) static type
  144707. #define LOCAL(type) static type
  144708. #define GLOBAL(type) type
  144709. #define EXTERN(type) extern type
  144710. #ifdef HAVE_PROTOTYPES
  144711. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144712. #else
  144713. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144714. #endif
  144715. #ifdef NEED_FAR_POINTERS
  144716. #define FAR far
  144717. #else
  144718. #define FAR
  144719. #endif
  144720. #ifndef HAVE_BOOLEAN
  144721. typedef int boolean;
  144722. #endif
  144723. #ifndef FALSE /* in case these macros already exist */
  144724. #define FALSE 0 /* values of boolean */
  144725. #endif
  144726. #ifndef TRUE
  144727. #define TRUE 1
  144728. #endif
  144729. #ifdef JPEG_INTERNALS
  144730. #define JPEG_INTERNAL_OPTIONS
  144731. #endif
  144732. #ifdef JPEG_INTERNAL_OPTIONS
  144733. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144734. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144735. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144736. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144737. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144738. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144739. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144740. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144741. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144742. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144743. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144744. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144745. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144746. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144747. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144748. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144749. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144750. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144751. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144752. #define RGB_GREEN 1 /* Offset of Green */
  144753. #define RGB_BLUE 2 /* Offset of Blue */
  144754. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144755. #ifndef INLINE
  144756. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144757. #define INLINE __inline__
  144758. #endif
  144759. #ifndef INLINE
  144760. #define INLINE /* default is to define it as empty */
  144761. #endif
  144762. #endif
  144763. #ifndef MULTIPLIER
  144764. #define MULTIPLIER int /* type for fastest integer multiply */
  144765. #endif
  144766. #ifndef FAST_FLOAT
  144767. #ifdef HAVE_PROTOTYPES
  144768. #define FAST_FLOAT float
  144769. #else
  144770. #define FAST_FLOAT double
  144771. #endif
  144772. #endif
  144773. #endif /* JPEG_INTERNAL_OPTIONS */
  144774. /*** End of inlined file: jmorecfg.h ***/
  144775. /* seldom changed options */
  144776. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144777. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144778. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144779. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144780. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144781. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144782. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144783. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144784. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144785. #ifndef D_MAX_BLOCKS_IN_MCU
  144786. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144787. #endif
  144788. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144789. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144790. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144791. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144792. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144793. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144794. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144795. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144796. typedef struct {
  144797. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144798. boolean sent_table; /* TRUE when table has been output */
  144799. } JQUANT_TBL;
  144800. typedef struct {
  144801. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144802. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144803. boolean sent_table; /* TRUE when table has been output */
  144804. } JHUFF_TBL;
  144805. typedef struct {
  144806. int component_id; /* identifier for this component (0..255) */
  144807. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144808. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144809. int v_samp_factor; /* vertical sampling factor (1..4) */
  144810. int quant_tbl_no; /* quantization table selector (0..3) */
  144811. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144812. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144813. JDIMENSION width_in_blocks;
  144814. JDIMENSION height_in_blocks;
  144815. int DCT_scaled_size;
  144816. JDIMENSION downsampled_width; /* actual width in samples */
  144817. JDIMENSION downsampled_height; /* actual height in samples */
  144818. boolean component_needed; /* do we need the value of this component? */
  144819. int MCU_width; /* number of blocks per MCU, horizontally */
  144820. int MCU_height; /* number of blocks per MCU, vertically */
  144821. int MCU_blocks; /* MCU_width * MCU_height */
  144822. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144823. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144824. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144825. JQUANT_TBL * quant_table;
  144826. void * dct_table;
  144827. } jpeg_component_info;
  144828. typedef struct {
  144829. int comps_in_scan; /* number of components encoded in this scan */
  144830. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144831. int Ss, Se; /* progressive JPEG spectral selection parms */
  144832. int Ah, Al; /* progressive JPEG successive approx. parms */
  144833. } jpeg_scan_info;
  144834. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144835. struct jpeg_marker_struct {
  144836. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144837. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144838. unsigned int original_length; /* # bytes of data in the file */
  144839. unsigned int data_length; /* # bytes of data saved at data[] */
  144840. JOCTET FAR * data; /* the data contained in the marker */
  144841. };
  144842. typedef enum {
  144843. JCS_UNKNOWN, /* error/unspecified */
  144844. JCS_GRAYSCALE, /* monochrome */
  144845. JCS_RGB, /* red/green/blue */
  144846. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144847. JCS_CMYK, /* C/M/Y/K */
  144848. JCS_YCCK /* Y/Cb/Cr/K */
  144849. } J_COLOR_SPACE;
  144850. typedef enum {
  144851. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144852. JDCT_IFAST, /* faster, less accurate integer method */
  144853. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144854. } J_DCT_METHOD;
  144855. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144856. #define JDCT_DEFAULT JDCT_ISLOW
  144857. #endif
  144858. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144859. #define JDCT_FASTEST JDCT_IFAST
  144860. #endif
  144861. typedef enum {
  144862. JDITHER_NONE, /* no dithering */
  144863. JDITHER_ORDERED, /* simple ordered dither */
  144864. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144865. } J_DITHER_MODE;
  144866. #define jpeg_common_fields \
  144867. struct jpeg_error_mgr * err; /* Error handler module */\
  144868. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144869. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144870. void * client_data; /* Available for use by application */\
  144871. boolean is_decompressor; /* So common code can tell which is which */\
  144872. int global_state /* For checking call sequence validity */
  144873. struct jpeg_common_struct {
  144874. jpeg_common_fields; /* Fields common to both master struct types */
  144875. };
  144876. typedef struct jpeg_common_struct * j_common_ptr;
  144877. typedef struct jpeg_compress_struct * j_compress_ptr;
  144878. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144879. struct jpeg_compress_struct {
  144880. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144881. struct jpeg_destination_mgr * dest;
  144882. JDIMENSION image_width; /* input image width */
  144883. JDIMENSION image_height; /* input image height */
  144884. int input_components; /* # of color components in input image */
  144885. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144886. double input_gamma; /* image gamma of input image */
  144887. int data_precision; /* bits of precision in image data */
  144888. int num_components; /* # of color components in JPEG image */
  144889. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144890. jpeg_component_info * comp_info;
  144891. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144892. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144893. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144894. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144895. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144896. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144897. int num_scans; /* # of entries in scan_info array */
  144898. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144899. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144900. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144901. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144902. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144903. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144904. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144905. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144906. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144907. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144908. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144909. UINT8 JFIF_minor_version;
  144910. UINT8 density_unit; /* JFIF code for pixel size units */
  144911. UINT16 X_density; /* Horizontal pixel density */
  144912. UINT16 Y_density; /* Vertical pixel density */
  144913. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144914. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144915. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144916. int max_h_samp_factor; /* largest h_samp_factor */
  144917. int max_v_samp_factor; /* largest v_samp_factor */
  144918. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144919. int comps_in_scan; /* # of JPEG components in this scan */
  144920. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144921. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144922. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144923. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144924. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144925. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144926. struct jpeg_comp_master * master;
  144927. struct jpeg_c_main_controller * main;
  144928. struct jpeg_c_prep_controller * prep;
  144929. struct jpeg_c_coef_controller * coef;
  144930. struct jpeg_marker_writer * marker;
  144931. struct jpeg_color_converter * cconvert;
  144932. struct jpeg_downsampler * downsample;
  144933. struct jpeg_forward_dct * fdct;
  144934. struct jpeg_entropy_encoder * entropy;
  144935. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144936. int script_space_size;
  144937. };
  144938. struct jpeg_decompress_struct {
  144939. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  144940. struct jpeg_source_mgr * src;
  144941. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  144942. JDIMENSION image_height; /* nominal image height */
  144943. int num_components; /* # of color components in JPEG image */
  144944. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144945. J_COLOR_SPACE out_color_space; /* colorspace for output */
  144946. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  144947. double output_gamma; /* image gamma wanted in output */
  144948. boolean buffered_image; /* TRUE=multiple output passes */
  144949. boolean raw_data_out; /* TRUE=downsampled data wanted */
  144950. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  144951. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  144952. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  144953. boolean quantize_colors; /* TRUE=colormapped output wanted */
  144954. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  144955. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  144956. int desired_number_of_colors; /* max # colors to use in created colormap */
  144957. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  144958. boolean enable_external_quant;/* enable future use of external colormap */
  144959. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  144960. JDIMENSION output_width; /* scaled image width */
  144961. JDIMENSION output_height; /* scaled image height */
  144962. int out_color_components; /* # of color components in out_color_space */
  144963. int output_components; /* # of color components returned */
  144964. int rec_outbuf_height; /* min recommended height of scanline buffer */
  144965. int actual_number_of_colors; /* number of entries in use */
  144966. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  144967. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  144968. int input_scan_number; /* Number of SOS markers seen so far */
  144969. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  144970. int output_scan_number; /* Nominal scan number being displayed */
  144971. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  144972. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  144973. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144974. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144975. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144976. int data_precision; /* bits of precision in image data */
  144977. jpeg_component_info * comp_info;
  144978. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  144979. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144980. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144981. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144982. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144983. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  144984. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  144985. UINT8 JFIF_major_version; /* JFIF version number */
  144986. UINT8 JFIF_minor_version;
  144987. UINT8 density_unit; /* JFIF code for pixel size units */
  144988. UINT16 X_density; /* Horizontal pixel density */
  144989. UINT16 Y_density; /* Vertical pixel density */
  144990. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  144991. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  144992. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144993. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  144994. int max_h_samp_factor; /* largest h_samp_factor */
  144995. int max_v_samp_factor; /* largest v_samp_factor */
  144996. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  144997. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  144998. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  144999. int comps_in_scan; /* # of JPEG components in this scan */
  145000. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145001. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145002. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145003. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145004. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  145005. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145006. int unread_marker;
  145007. struct jpeg_decomp_master * master;
  145008. struct jpeg_d_main_controller * main;
  145009. struct jpeg_d_coef_controller * coef;
  145010. struct jpeg_d_post_controller * post;
  145011. struct jpeg_input_controller * inputctl;
  145012. struct jpeg_marker_reader * marker;
  145013. struct jpeg_entropy_decoder * entropy;
  145014. struct jpeg_inverse_dct * idct;
  145015. struct jpeg_upsampler * upsample;
  145016. struct jpeg_color_deconverter * cconvert;
  145017. struct jpeg_color_quantizer * cquantize;
  145018. };
  145019. struct jpeg_error_mgr {
  145020. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  145021. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  145022. JMETHOD(void, output_message, (j_common_ptr cinfo));
  145023. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  145024. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  145025. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145026. int msg_code;
  145027. #define JMSG_STR_PARM_MAX 80
  145028. union {
  145029. int i[8];
  145030. char s[JMSG_STR_PARM_MAX];
  145031. } msg_parm;
  145032. int trace_level; /* max msg_level that will be displayed */
  145033. long num_warnings; /* number of corrupt-data warnings */
  145034. const char * const * jpeg_message_table; /* Library errors */
  145035. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145036. const char * const * addon_message_table; /* Non-library errors */
  145037. int first_addon_message; /* code for first string in addon table */
  145038. int last_addon_message; /* code for last string in addon table */
  145039. };
  145040. struct jpeg_progress_mgr {
  145041. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145042. long pass_counter; /* work units completed in this pass */
  145043. long pass_limit; /* total number of work units in this pass */
  145044. int completed_passes; /* passes completed so far */
  145045. int total_passes; /* total number of passes expected */
  145046. };
  145047. struct jpeg_destination_mgr {
  145048. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145049. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145050. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145051. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145052. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145053. };
  145054. struct jpeg_source_mgr {
  145055. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145056. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145057. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145058. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145059. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145060. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145061. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145062. };
  145063. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145064. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145065. #define JPOOL_NUMPOOLS 2
  145066. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145067. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145068. struct jpeg_memory_mgr {
  145069. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145070. size_t sizeofobject));
  145071. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145072. size_t sizeofobject));
  145073. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145074. JDIMENSION samplesperrow,
  145075. JDIMENSION numrows));
  145076. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145077. JDIMENSION blocksperrow,
  145078. JDIMENSION numrows));
  145079. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145080. int pool_id,
  145081. boolean pre_zero,
  145082. JDIMENSION samplesperrow,
  145083. JDIMENSION numrows,
  145084. JDIMENSION maxaccess));
  145085. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145086. int pool_id,
  145087. boolean pre_zero,
  145088. JDIMENSION blocksperrow,
  145089. JDIMENSION numrows,
  145090. JDIMENSION maxaccess));
  145091. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145092. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145093. jvirt_sarray_ptr ptr,
  145094. JDIMENSION start_row,
  145095. JDIMENSION num_rows,
  145096. boolean writable));
  145097. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145098. jvirt_barray_ptr ptr,
  145099. JDIMENSION start_row,
  145100. JDIMENSION num_rows,
  145101. boolean writable));
  145102. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145103. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145104. long max_memory_to_use;
  145105. long max_alloc_chunk;
  145106. };
  145107. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145108. #ifdef HAVE_PROTOTYPES
  145109. #define JPP(arglist) arglist
  145110. #else
  145111. #define JPP(arglist) ()
  145112. #endif
  145113. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145114. #define jpeg_std_error jStdError
  145115. #define jpeg_CreateCompress jCreaCompress
  145116. #define jpeg_CreateDecompress jCreaDecompress
  145117. #define jpeg_destroy_compress jDestCompress
  145118. #define jpeg_destroy_decompress jDestDecompress
  145119. #define jpeg_stdio_dest jStdDest
  145120. #define jpeg_stdio_src jStdSrc
  145121. #define jpeg_set_defaults jSetDefaults
  145122. #define jpeg_set_colorspace jSetColorspace
  145123. #define jpeg_default_colorspace jDefColorspace
  145124. #define jpeg_set_quality jSetQuality
  145125. #define jpeg_set_linear_quality jSetLQuality
  145126. #define jpeg_add_quant_table jAddQuantTable
  145127. #define jpeg_quality_scaling jQualityScaling
  145128. #define jpeg_simple_progression jSimProgress
  145129. #define jpeg_suppress_tables jSuppressTables
  145130. #define jpeg_alloc_quant_table jAlcQTable
  145131. #define jpeg_alloc_huff_table jAlcHTable
  145132. #define jpeg_start_compress jStrtCompress
  145133. #define jpeg_write_scanlines jWrtScanlines
  145134. #define jpeg_finish_compress jFinCompress
  145135. #define jpeg_write_raw_data jWrtRawData
  145136. #define jpeg_write_marker jWrtMarker
  145137. #define jpeg_write_m_header jWrtMHeader
  145138. #define jpeg_write_m_byte jWrtMByte
  145139. #define jpeg_write_tables jWrtTables
  145140. #define jpeg_read_header jReadHeader
  145141. #define jpeg_start_decompress jStrtDecompress
  145142. #define jpeg_read_scanlines jReadScanlines
  145143. #define jpeg_finish_decompress jFinDecompress
  145144. #define jpeg_read_raw_data jReadRawData
  145145. #define jpeg_has_multiple_scans jHasMultScn
  145146. #define jpeg_start_output jStrtOutput
  145147. #define jpeg_finish_output jFinOutput
  145148. #define jpeg_input_complete jInComplete
  145149. #define jpeg_new_colormap jNewCMap
  145150. #define jpeg_consume_input jConsumeInput
  145151. #define jpeg_calc_output_dimensions jCalcDimensions
  145152. #define jpeg_save_markers jSaveMarkers
  145153. #define jpeg_set_marker_processor jSetMarker
  145154. #define jpeg_read_coefficients jReadCoefs
  145155. #define jpeg_write_coefficients jWrtCoefs
  145156. #define jpeg_copy_critical_parameters jCopyCrit
  145157. #define jpeg_abort_compress jAbrtCompress
  145158. #define jpeg_abort_decompress jAbrtDecompress
  145159. #define jpeg_abort jAbort
  145160. #define jpeg_destroy jDestroy
  145161. #define jpeg_resync_to_restart jResyncRestart
  145162. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145163. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145164. JPP((struct jpeg_error_mgr * err));
  145165. #define jpeg_create_compress(cinfo) \
  145166. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145167. (size_t) sizeof(struct jpeg_compress_struct))
  145168. #define jpeg_create_decompress(cinfo) \
  145169. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145170. (size_t) sizeof(struct jpeg_decompress_struct))
  145171. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145172. int version, size_t structsize));
  145173. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145174. int version, size_t structsize));
  145175. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145176. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145177. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145178. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145179. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145180. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145181. J_COLOR_SPACE colorspace));
  145182. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145183. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145184. boolean force_baseline));
  145185. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145186. int scale_factor,
  145187. boolean force_baseline));
  145188. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145189. const unsigned int *basic_table,
  145190. int scale_factor,
  145191. boolean force_baseline));
  145192. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145193. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145194. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145195. boolean suppress));
  145196. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145197. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145198. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145199. boolean write_all_tables));
  145200. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145201. JSAMPARRAY scanlines,
  145202. JDIMENSION num_lines));
  145203. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145204. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145205. JSAMPIMAGE data,
  145206. JDIMENSION num_lines));
  145207. EXTERN(void) jpeg_write_marker
  145208. JPP((j_compress_ptr cinfo, int marker,
  145209. const JOCTET * dataptr, unsigned int datalen));
  145210. EXTERN(void) jpeg_write_m_header
  145211. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145212. EXTERN(void) jpeg_write_m_byte
  145213. JPP((j_compress_ptr cinfo, int val));
  145214. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145215. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145216. boolean require_image));
  145217. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145218. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145219. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145220. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145221. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145222. JSAMPARRAY scanlines,
  145223. JDIMENSION max_lines));
  145224. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145225. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145226. JSAMPIMAGE data,
  145227. JDIMENSION max_lines));
  145228. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145229. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145230. int scan_number));
  145231. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145232. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145233. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145234. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145235. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145236. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145237. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145238. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145239. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145240. EXTERN(void) jpeg_save_markers
  145241. JPP((j_decompress_ptr cinfo, int marker_code,
  145242. unsigned int length_limit));
  145243. EXTERN(void) jpeg_set_marker_processor
  145244. JPP((j_decompress_ptr cinfo, int marker_code,
  145245. jpeg_marker_parser_method routine));
  145246. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145247. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145248. jvirt_barray_ptr * coef_arrays));
  145249. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145250. j_compress_ptr dstinfo));
  145251. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145252. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145253. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145254. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145255. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145256. int desired));
  145257. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145258. #define JPEG_EOI 0xD9 /* EOI marker code */
  145259. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145260. #define JPEG_COM 0xFE /* COM marker code */
  145261. #ifdef INCOMPLETE_TYPES_BROKEN
  145262. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145263. struct jvirt_sarray_control { long dummy; };
  145264. struct jvirt_barray_control { long dummy; };
  145265. struct jpeg_comp_master { long dummy; };
  145266. struct jpeg_c_main_controller { long dummy; };
  145267. struct jpeg_c_prep_controller { long dummy; };
  145268. struct jpeg_c_coef_controller { long dummy; };
  145269. struct jpeg_marker_writer { long dummy; };
  145270. struct jpeg_color_converter { long dummy; };
  145271. struct jpeg_downsampler { long dummy; };
  145272. struct jpeg_forward_dct { long dummy; };
  145273. struct jpeg_entropy_encoder { long dummy; };
  145274. struct jpeg_decomp_master { long dummy; };
  145275. struct jpeg_d_main_controller { long dummy; };
  145276. struct jpeg_d_coef_controller { long dummy; };
  145277. struct jpeg_d_post_controller { long dummy; };
  145278. struct jpeg_input_controller { long dummy; };
  145279. struct jpeg_marker_reader { long dummy; };
  145280. struct jpeg_entropy_decoder { long dummy; };
  145281. struct jpeg_inverse_dct { long dummy; };
  145282. struct jpeg_upsampler { long dummy; };
  145283. struct jpeg_color_deconverter { long dummy; };
  145284. struct jpeg_color_quantizer { long dummy; };
  145285. #endif /* JPEG_INTERNALS */
  145286. #endif /* INCOMPLETE_TYPES_BROKEN */
  145287. #ifdef JPEG_INTERNALS
  145288. /*** Start of inlined file: jpegint.h ***/
  145289. typedef enum { /* Operating modes for buffer controllers */
  145290. JBUF_PASS_THRU, /* Plain stripwise operation */
  145291. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145292. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145293. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145294. } J_BUF_MODE;
  145295. #define CSTATE_START 100 /* after create_compress */
  145296. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145297. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145298. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145299. #define DSTATE_START 200 /* after create_decompress */
  145300. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145301. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145302. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145303. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145304. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145305. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145306. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145307. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145308. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145309. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145310. struct jpeg_comp_master {
  145311. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145312. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145313. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145314. boolean call_pass_startup; /* True if pass_startup must be called */
  145315. boolean is_last_pass; /* True during last pass */
  145316. };
  145317. struct jpeg_c_main_controller {
  145318. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145319. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145320. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145321. JDIMENSION in_rows_avail));
  145322. };
  145323. struct jpeg_c_prep_controller {
  145324. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145325. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145326. JSAMPARRAY input_buf,
  145327. JDIMENSION *in_row_ctr,
  145328. JDIMENSION in_rows_avail,
  145329. JSAMPIMAGE output_buf,
  145330. JDIMENSION *out_row_group_ctr,
  145331. JDIMENSION out_row_groups_avail));
  145332. };
  145333. struct jpeg_c_coef_controller {
  145334. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145335. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145336. JSAMPIMAGE input_buf));
  145337. };
  145338. struct jpeg_color_converter {
  145339. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145340. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145341. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145342. JDIMENSION output_row, int num_rows));
  145343. };
  145344. struct jpeg_downsampler {
  145345. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145346. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145347. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145348. JSAMPIMAGE output_buf,
  145349. JDIMENSION out_row_group_index));
  145350. boolean need_context_rows; /* TRUE if need rows above & below */
  145351. };
  145352. struct jpeg_forward_dct {
  145353. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145354. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145355. jpeg_component_info * compptr,
  145356. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145357. JDIMENSION start_row, JDIMENSION start_col,
  145358. JDIMENSION num_blocks));
  145359. };
  145360. struct jpeg_entropy_encoder {
  145361. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145362. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145363. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145364. };
  145365. struct jpeg_marker_writer {
  145366. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145367. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145368. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145369. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145370. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145371. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145372. unsigned int datalen));
  145373. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145374. };
  145375. struct jpeg_decomp_master {
  145376. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145377. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145378. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145379. };
  145380. struct jpeg_input_controller {
  145381. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145382. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145383. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145384. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145385. boolean has_multiple_scans; /* True if file has multiple scans */
  145386. boolean eoi_reached; /* True when EOI has been consumed */
  145387. };
  145388. struct jpeg_d_main_controller {
  145389. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145390. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145391. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145392. JDIMENSION out_rows_avail));
  145393. };
  145394. struct jpeg_d_coef_controller {
  145395. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145396. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145397. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145398. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145399. JSAMPIMAGE output_buf));
  145400. jvirt_barray_ptr *coef_arrays;
  145401. };
  145402. struct jpeg_d_post_controller {
  145403. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145404. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145405. JSAMPIMAGE input_buf,
  145406. JDIMENSION *in_row_group_ctr,
  145407. JDIMENSION in_row_groups_avail,
  145408. JSAMPARRAY output_buf,
  145409. JDIMENSION *out_row_ctr,
  145410. JDIMENSION out_rows_avail));
  145411. };
  145412. struct jpeg_marker_reader {
  145413. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145414. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145415. jpeg_marker_parser_method read_restart_marker;
  145416. boolean saw_SOI; /* found SOI? */
  145417. boolean saw_SOF; /* found SOF? */
  145418. int next_restart_num; /* next restart number expected (0-7) */
  145419. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145420. };
  145421. struct jpeg_entropy_decoder {
  145422. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145423. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145424. JBLOCKROW *MCU_data));
  145425. boolean insufficient_data; /* set TRUE after emitting warning */
  145426. };
  145427. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145428. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145429. JCOEFPTR coef_block,
  145430. JSAMPARRAY output_buf, JDIMENSION output_col));
  145431. struct jpeg_inverse_dct {
  145432. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145433. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145434. };
  145435. struct jpeg_upsampler {
  145436. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145437. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145438. JSAMPIMAGE input_buf,
  145439. JDIMENSION *in_row_group_ctr,
  145440. JDIMENSION in_row_groups_avail,
  145441. JSAMPARRAY output_buf,
  145442. JDIMENSION *out_row_ctr,
  145443. JDIMENSION out_rows_avail));
  145444. boolean need_context_rows; /* TRUE if need rows above & below */
  145445. };
  145446. struct jpeg_color_deconverter {
  145447. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145448. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145449. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145450. JSAMPARRAY output_buf, int num_rows));
  145451. };
  145452. struct jpeg_color_quantizer {
  145453. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145454. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145455. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145456. int num_rows));
  145457. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145458. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145459. };
  145460. #undef MAX
  145461. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145462. #undef MIN
  145463. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145464. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145465. #define SHIFT_TEMPS INT32 shift_temp;
  145466. #define RIGHT_SHIFT(x,shft) \
  145467. ((shift_temp = (x)) < 0 ? \
  145468. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145469. (shift_temp >> (shft)))
  145470. #else
  145471. #define SHIFT_TEMPS
  145472. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145473. #endif
  145474. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145475. #define jinit_compress_master jICompress
  145476. #define jinit_c_master_control jICMaster
  145477. #define jinit_c_main_controller jICMainC
  145478. #define jinit_c_prep_controller jICPrepC
  145479. #define jinit_c_coef_controller jICCoefC
  145480. #define jinit_color_converter jICColor
  145481. #define jinit_downsampler jIDownsampler
  145482. #define jinit_forward_dct jIFDCT
  145483. #define jinit_huff_encoder jIHEncoder
  145484. #define jinit_phuff_encoder jIPHEncoder
  145485. #define jinit_marker_writer jIMWriter
  145486. #define jinit_master_decompress jIDMaster
  145487. #define jinit_d_main_controller jIDMainC
  145488. #define jinit_d_coef_controller jIDCoefC
  145489. #define jinit_d_post_controller jIDPostC
  145490. #define jinit_input_controller jIInCtlr
  145491. #define jinit_marker_reader jIMReader
  145492. #define jinit_huff_decoder jIHDecoder
  145493. #define jinit_phuff_decoder jIPHDecoder
  145494. #define jinit_inverse_dct jIIDCT
  145495. #define jinit_upsampler jIUpsampler
  145496. #define jinit_color_deconverter jIDColor
  145497. #define jinit_1pass_quantizer jI1Quant
  145498. #define jinit_2pass_quantizer jI2Quant
  145499. #define jinit_merged_upsampler jIMUpsampler
  145500. #define jinit_memory_mgr jIMemMgr
  145501. #define jdiv_round_up jDivRound
  145502. #define jround_up jRound
  145503. #define jcopy_sample_rows jCopySamples
  145504. #define jcopy_block_row jCopyBlocks
  145505. #define jzero_far jZeroFar
  145506. #define jpeg_zigzag_order jZIGTable
  145507. #define jpeg_natural_order jZAGTable
  145508. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145509. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145510. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145511. boolean transcode_only));
  145512. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145513. boolean need_full_buffer));
  145514. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145515. boolean need_full_buffer));
  145516. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145517. boolean need_full_buffer));
  145518. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145519. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145520. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145521. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145522. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145523. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145524. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145525. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145526. boolean need_full_buffer));
  145527. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145528. boolean need_full_buffer));
  145529. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145530. boolean need_full_buffer));
  145531. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145532. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145533. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145534. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145535. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145536. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145537. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145538. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145539. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145540. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145541. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145542. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145543. EXTERN(long) jround_up JPP((long a, long b));
  145544. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145545. JSAMPARRAY output_array, int dest_row,
  145546. int num_rows, JDIMENSION num_cols));
  145547. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145548. JDIMENSION num_blocks));
  145549. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145550. #if 0 /* This table is not actually needed in v6a */
  145551. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145552. #endif
  145553. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145554. #ifdef INCOMPLETE_TYPES_BROKEN
  145555. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145556. struct jvirt_sarray_control { long dummy; };
  145557. struct jvirt_barray_control { long dummy; };
  145558. #endif
  145559. #endif /* INCOMPLETE_TYPES_BROKEN */
  145560. /*** End of inlined file: jpegint.h ***/
  145561. /* fetch private declarations */
  145562. /*** Start of inlined file: jerror.h ***/
  145563. #ifndef JMESSAGE
  145564. #ifndef JERROR_H
  145565. #define JMAKE_ENUM_LIST
  145566. #else
  145567. #define JMESSAGE(code,string)
  145568. #endif /* JERROR_H */
  145569. #endif /* JMESSAGE */
  145570. #ifdef JMAKE_ENUM_LIST
  145571. typedef enum {
  145572. #define JMESSAGE(code,string) code ,
  145573. #endif /* JMAKE_ENUM_LIST */
  145574. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145575. JMESSAGE(JERR_ARITH_NOTIMPL,
  145576. "Sorry, there are legal restrictions on arithmetic coding")
  145577. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145578. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145579. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145580. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145581. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145582. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145583. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145584. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145585. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145586. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145587. JMESSAGE(JERR_BAD_LIB_VERSION,
  145588. "Wrong JPEG library version: library is %d, caller expects %d")
  145589. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145590. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145591. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145592. JMESSAGE(JERR_BAD_PROGRESSION,
  145593. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145594. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145595. "Invalid progressive parameters at scan script entry %d")
  145596. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145597. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145598. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145599. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145600. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145601. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145602. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145603. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145604. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145605. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145606. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145607. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145608. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145609. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145610. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145611. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145612. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145613. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145614. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145615. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145616. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145617. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145618. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145619. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145620. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145621. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145622. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145623. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145624. "Cannot transcode due to multiple use of quantization table %d")
  145625. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145626. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145627. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145628. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145629. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145630. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145631. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145632. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145633. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145634. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145635. JMESSAGE(JERR_QUANT_COMPONENTS,
  145636. "Cannot quantize more than %d color components")
  145637. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145638. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145639. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145640. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145641. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145642. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145643. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145644. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145645. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145646. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145647. JMESSAGE(JERR_TFILE_WRITE,
  145648. "Write failed on temporary file --- out of disk space?")
  145649. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145650. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145651. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145652. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145653. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145654. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145655. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145656. JMESSAGE(JMSG_VERSION, JVERSION)
  145657. JMESSAGE(JTRC_16BIT_TABLES,
  145658. "Caution: quantization tables are too coarse for baseline JPEG")
  145659. JMESSAGE(JTRC_ADOBE,
  145660. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145661. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145662. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145663. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145664. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145665. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145666. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145667. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145668. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145669. JMESSAGE(JTRC_EOI, "End Of Image")
  145670. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145671. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145672. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145673. "Warning: thumbnail image size does not match data length %u")
  145674. JMESSAGE(JTRC_JFIF_EXTENSION,
  145675. "JFIF extension marker: type 0x%02x, length %u")
  145676. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145677. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145678. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145679. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145680. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145681. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145682. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145683. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145684. JMESSAGE(JTRC_RST, "RST%d")
  145685. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145686. "Smoothing not supported with nonstandard sampling ratios")
  145687. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145688. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145689. JMESSAGE(JTRC_SOI, "Start of Image")
  145690. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145691. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145692. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145693. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145694. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145695. JMESSAGE(JTRC_THUMB_JPEG,
  145696. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145697. JMESSAGE(JTRC_THUMB_PALETTE,
  145698. "JFIF extension marker: palette thumbnail image, length %u")
  145699. JMESSAGE(JTRC_THUMB_RGB,
  145700. "JFIF extension marker: RGB thumbnail image, length %u")
  145701. JMESSAGE(JTRC_UNKNOWN_IDS,
  145702. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145703. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145704. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145705. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145706. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145707. "Inconsistent progression sequence for component %d coefficient %d")
  145708. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145709. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145710. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145711. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145712. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145713. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145714. JMESSAGE(JWRN_MUST_RESYNC,
  145715. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145716. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145717. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145718. #ifdef JMAKE_ENUM_LIST
  145719. JMSG_LASTMSGCODE
  145720. } J_MESSAGE_CODE;
  145721. #undef JMAKE_ENUM_LIST
  145722. #endif /* JMAKE_ENUM_LIST */
  145723. #undef JMESSAGE
  145724. #ifndef JERROR_H
  145725. #define JERROR_H
  145726. #define ERREXIT(cinfo,code) \
  145727. ((cinfo)->err->msg_code = (code), \
  145728. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145729. #define ERREXIT1(cinfo,code,p1) \
  145730. ((cinfo)->err->msg_code = (code), \
  145731. (cinfo)->err->msg_parm.i[0] = (p1), \
  145732. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145733. #define ERREXIT2(cinfo,code,p1,p2) \
  145734. ((cinfo)->err->msg_code = (code), \
  145735. (cinfo)->err->msg_parm.i[0] = (p1), \
  145736. (cinfo)->err->msg_parm.i[1] = (p2), \
  145737. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145738. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145739. ((cinfo)->err->msg_code = (code), \
  145740. (cinfo)->err->msg_parm.i[0] = (p1), \
  145741. (cinfo)->err->msg_parm.i[1] = (p2), \
  145742. (cinfo)->err->msg_parm.i[2] = (p3), \
  145743. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145744. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  145745. ((cinfo)->err->msg_code = (code), \
  145746. (cinfo)->err->msg_parm.i[0] = (p1), \
  145747. (cinfo)->err->msg_parm.i[1] = (p2), \
  145748. (cinfo)->err->msg_parm.i[2] = (p3), \
  145749. (cinfo)->err->msg_parm.i[3] = (p4), \
  145750. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145751. #define ERREXITS(cinfo,code,str) \
  145752. ((cinfo)->err->msg_code = (code), \
  145753. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145754. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145755. #define MAKESTMT(stuff) do { stuff } while (0)
  145756. #define WARNMS(cinfo,code) \
  145757. ((cinfo)->err->msg_code = (code), \
  145758. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145759. #define WARNMS1(cinfo,code,p1) \
  145760. ((cinfo)->err->msg_code = (code), \
  145761. (cinfo)->err->msg_parm.i[0] = (p1), \
  145762. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145763. #define WARNMS2(cinfo,code,p1,p2) \
  145764. ((cinfo)->err->msg_code = (code), \
  145765. (cinfo)->err->msg_parm.i[0] = (p1), \
  145766. (cinfo)->err->msg_parm.i[1] = (p2), \
  145767. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145768. #define TRACEMS(cinfo,lvl,code) \
  145769. ((cinfo)->err->msg_code = (code), \
  145770. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145771. #define TRACEMS1(cinfo,lvl,code,p1) \
  145772. ((cinfo)->err->msg_code = (code), \
  145773. (cinfo)->err->msg_parm.i[0] = (p1), \
  145774. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145775. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145776. ((cinfo)->err->msg_code = (code), \
  145777. (cinfo)->err->msg_parm.i[0] = (p1), \
  145778. (cinfo)->err->msg_parm.i[1] = (p2), \
  145779. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145780. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145781. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145782. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145783. (cinfo)->err->msg_code = (code); \
  145784. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145785. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145786. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145787. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145788. (cinfo)->err->msg_code = (code); \
  145789. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145790. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145791. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145792. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145793. _mp[4] = (p5); \
  145794. (cinfo)->err->msg_code = (code); \
  145795. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145796. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145797. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145798. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145799. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145800. (cinfo)->err->msg_code = (code); \
  145801. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145802. #define TRACEMSS(cinfo,lvl,code,str) \
  145803. ((cinfo)->err->msg_code = (code), \
  145804. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145805. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145806. #endif /* JERROR_H */
  145807. /*** End of inlined file: jerror.h ***/
  145808. /* fetch error codes too */
  145809. #endif
  145810. #endif /* JPEGLIB_H */
  145811. /*** End of inlined file: jpeglib.h ***/
  145812. /*** Start of inlined file: jcapimin.c ***/
  145813. #define JPEG_INTERNALS
  145814. /*** Start of inlined file: jinclude.h ***/
  145815. #ifndef __jinclude_h__
  145816. #define __jinclude_h__
  145817. /*** Start of inlined file: jconfig.h ***/
  145818. // disable all the warnings under MSVC
  145819. #ifdef _MSC_VER
  145820. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145821. #endif
  145822. #ifdef __BORLANDC__
  145823. #pragma warn -8057
  145824. #pragma warn -8019
  145825. #pragma warn -8004
  145826. #pragma warn -8008
  145827. #endif
  145828. #define HAVE_PROTOTYPES
  145829. #define HAVE_UNSIGNED_CHAR
  145830. #define HAVE_UNSIGNED_SHORT
  145831. #undef CHAR_IS_UNSIGNED
  145832. #define HAVE_STDDEF_H
  145833. #define HAVE_STDLIB_H
  145834. #undef NEED_BSD_STRINGS
  145835. #undef NEED_SYS_TYPES_H
  145836. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145837. #undef NEED_SHORT_EXTERNAL_NAMES
  145838. #undef INCOMPLETE_TYPES_BROKEN
  145839. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145840. typedef unsigned char boolean;
  145841. #endif
  145842. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145843. #ifdef JPEG_INTERNALS
  145844. #undef RIGHT_SHIFT_IS_UNSIGNED
  145845. #endif /* JPEG_INTERNALS */
  145846. #ifdef JPEG_CJPEG_DJPEG
  145847. #define BMP_SUPPORTED /* BMP image file format */
  145848. #define GIF_SUPPORTED /* GIF image file format */
  145849. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145850. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145851. #define TARGA_SUPPORTED /* Targa image file format */
  145852. #define TWO_FILE_COMMANDLINE /* optional */
  145853. #define USE_SETMODE /* Microsoft has setmode() */
  145854. #undef NEED_SIGNAL_CATCHER
  145855. #undef DONT_USE_B_MODE
  145856. #undef PROGRESS_REPORT /* optional */
  145857. #endif /* JPEG_CJPEG_DJPEG */
  145858. /*** End of inlined file: jconfig.h ***/
  145859. /* auto configuration options */
  145860. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145861. #ifdef HAVE_STDDEF_H
  145862. #include <stddef.h>
  145863. #endif
  145864. #ifdef HAVE_STDLIB_H
  145865. #include <stdlib.h>
  145866. #endif
  145867. #ifdef NEED_SYS_TYPES_H
  145868. #include <sys/types.h>
  145869. #endif
  145870. #include <stdio.h>
  145871. #ifdef NEED_BSD_STRINGS
  145872. #include <strings.h>
  145873. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145874. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145875. #else /* not BSD, assume ANSI/SysV string lib */
  145876. #include <string.h>
  145877. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145878. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145879. #endif
  145880. #define SIZEOF(object) ((size_t) sizeof(object))
  145881. #define JFREAD(file,buf,sizeofbuf) \
  145882. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145883. #define JFWRITE(file,buf,sizeofbuf) \
  145884. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145885. typedef enum { /* JPEG marker codes */
  145886. M_SOF0 = 0xc0,
  145887. M_SOF1 = 0xc1,
  145888. M_SOF2 = 0xc2,
  145889. M_SOF3 = 0xc3,
  145890. M_SOF5 = 0xc5,
  145891. M_SOF6 = 0xc6,
  145892. M_SOF7 = 0xc7,
  145893. M_JPG = 0xc8,
  145894. M_SOF9 = 0xc9,
  145895. M_SOF10 = 0xca,
  145896. M_SOF11 = 0xcb,
  145897. M_SOF13 = 0xcd,
  145898. M_SOF14 = 0xce,
  145899. M_SOF15 = 0xcf,
  145900. M_DHT = 0xc4,
  145901. M_DAC = 0xcc,
  145902. M_RST0 = 0xd0,
  145903. M_RST1 = 0xd1,
  145904. M_RST2 = 0xd2,
  145905. M_RST3 = 0xd3,
  145906. M_RST4 = 0xd4,
  145907. M_RST5 = 0xd5,
  145908. M_RST6 = 0xd6,
  145909. M_RST7 = 0xd7,
  145910. M_SOI = 0xd8,
  145911. M_EOI = 0xd9,
  145912. M_SOS = 0xda,
  145913. M_DQT = 0xdb,
  145914. M_DNL = 0xdc,
  145915. M_DRI = 0xdd,
  145916. M_DHP = 0xde,
  145917. M_EXP = 0xdf,
  145918. M_APP0 = 0xe0,
  145919. M_APP1 = 0xe1,
  145920. M_APP2 = 0xe2,
  145921. M_APP3 = 0xe3,
  145922. M_APP4 = 0xe4,
  145923. M_APP5 = 0xe5,
  145924. M_APP6 = 0xe6,
  145925. M_APP7 = 0xe7,
  145926. M_APP8 = 0xe8,
  145927. M_APP9 = 0xe9,
  145928. M_APP10 = 0xea,
  145929. M_APP11 = 0xeb,
  145930. M_APP12 = 0xec,
  145931. M_APP13 = 0xed,
  145932. M_APP14 = 0xee,
  145933. M_APP15 = 0xef,
  145934. M_JPG0 = 0xf0,
  145935. M_JPG13 = 0xfd,
  145936. M_COM = 0xfe,
  145937. M_TEM = 0x01,
  145938. M_ERROR = 0x100
  145939. } JPEG_MARKER;
  145940. #ifdef AVOID_TABLES
  145941. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  145942. #else
  145943. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  145944. static const int extend_test[16] = /* entry n is 2**(n-1) */
  145945. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  145946. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  145947. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  145948. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  145949. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  145950. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  145951. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  145952. #endif /* AVOID_TABLES */
  145953. #endif
  145954. /*** End of inlined file: jinclude.h ***/
  145955. GLOBAL(void)
  145956. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  145957. {
  145958. int i;
  145959. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  145960. if (version != JPEG_LIB_VERSION)
  145961. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  145962. if (structsize != SIZEOF(struct jpeg_compress_struct))
  145963. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  145964. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  145965. {
  145966. struct jpeg_error_mgr * err = cinfo->err;
  145967. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  145968. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  145969. cinfo->err = err;
  145970. cinfo->client_data = client_data;
  145971. }
  145972. cinfo->is_decompressor = FALSE;
  145973. jinit_memory_mgr((j_common_ptr) cinfo);
  145974. cinfo->progress = NULL;
  145975. cinfo->dest = NULL;
  145976. cinfo->comp_info = NULL;
  145977. for (i = 0; i < NUM_QUANT_TBLS; i++)
  145978. cinfo->quant_tbl_ptrs[i] = NULL;
  145979. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145980. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  145981. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  145982. }
  145983. cinfo->script_space = NULL;
  145984. cinfo->input_gamma = 1.0; /* in case application forgets */
  145985. cinfo->global_state = CSTATE_START;
  145986. }
  145987. GLOBAL(void)
  145988. jpeg_destroy_compress (j_compress_ptr cinfo)
  145989. {
  145990. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  145991. }
  145992. GLOBAL(void)
  145993. jpeg_abort_compress (j_compress_ptr cinfo)
  145994. {
  145995. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  145996. }
  145997. GLOBAL(void)
  145998. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  145999. {
  146000. int i;
  146001. JQUANT_TBL * qtbl;
  146002. JHUFF_TBL * htbl;
  146003. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146004. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  146005. qtbl->sent_table = suppress;
  146006. }
  146007. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146008. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  146009. htbl->sent_table = suppress;
  146010. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  146011. htbl->sent_table = suppress;
  146012. }
  146013. }
  146014. GLOBAL(void)
  146015. jpeg_finish_compress (j_compress_ptr cinfo)
  146016. {
  146017. JDIMENSION iMCU_row;
  146018. if (cinfo->global_state == CSTATE_SCANNING ||
  146019. cinfo->global_state == CSTATE_RAW_OK) {
  146020. if (cinfo->next_scanline < cinfo->image_height)
  146021. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  146022. (*cinfo->master->finish_pass) (cinfo);
  146023. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  146024. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146025. while (! cinfo->master->is_last_pass) {
  146026. (*cinfo->master->prepare_for_pass) (cinfo);
  146027. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146028. if (cinfo->progress != NULL) {
  146029. cinfo->progress->pass_counter = (long) iMCU_row;
  146030. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146031. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146032. }
  146033. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146034. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146035. }
  146036. (*cinfo->master->finish_pass) (cinfo);
  146037. }
  146038. (*cinfo->marker->write_file_trailer) (cinfo);
  146039. (*cinfo->dest->term_destination) (cinfo);
  146040. jpeg_abort((j_common_ptr) cinfo);
  146041. }
  146042. GLOBAL(void)
  146043. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146044. const JOCTET *dataptr, unsigned int datalen)
  146045. {
  146046. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146047. if (cinfo->next_scanline != 0 ||
  146048. (cinfo->global_state != CSTATE_SCANNING &&
  146049. cinfo->global_state != CSTATE_RAW_OK &&
  146050. cinfo->global_state != CSTATE_WRCOEFS))
  146051. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146052. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146053. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146054. while (datalen--) {
  146055. (*write_marker_byte) (cinfo, *dataptr);
  146056. dataptr++;
  146057. }
  146058. }
  146059. GLOBAL(void)
  146060. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146061. {
  146062. if (cinfo->next_scanline != 0 ||
  146063. (cinfo->global_state != CSTATE_SCANNING &&
  146064. cinfo->global_state != CSTATE_RAW_OK &&
  146065. cinfo->global_state != CSTATE_WRCOEFS))
  146066. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146067. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146068. }
  146069. GLOBAL(void)
  146070. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146071. {
  146072. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146073. }
  146074. GLOBAL(void)
  146075. jpeg_write_tables (j_compress_ptr cinfo)
  146076. {
  146077. if (cinfo->global_state != CSTATE_START)
  146078. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146079. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146080. (*cinfo->dest->init_destination) (cinfo);
  146081. jinit_marker_writer(cinfo);
  146082. (*cinfo->marker->write_tables_only) (cinfo);
  146083. (*cinfo->dest->term_destination) (cinfo);
  146084. }
  146085. /*** End of inlined file: jcapimin.c ***/
  146086. /*** Start of inlined file: jcapistd.c ***/
  146087. #define JPEG_INTERNALS
  146088. GLOBAL(void)
  146089. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146090. {
  146091. if (cinfo->global_state != CSTATE_START)
  146092. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146093. if (write_all_tables)
  146094. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146095. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146096. (*cinfo->dest->init_destination) (cinfo);
  146097. jinit_compress_master(cinfo);
  146098. (*cinfo->master->prepare_for_pass) (cinfo);
  146099. cinfo->next_scanline = 0;
  146100. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146101. }
  146102. GLOBAL(JDIMENSION)
  146103. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146104. JDIMENSION num_lines)
  146105. {
  146106. JDIMENSION row_ctr, rows_left;
  146107. if (cinfo->global_state != CSTATE_SCANNING)
  146108. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146109. if (cinfo->next_scanline >= cinfo->image_height)
  146110. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146111. if (cinfo->progress != NULL) {
  146112. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146113. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146114. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146115. }
  146116. if (cinfo->master->call_pass_startup)
  146117. (*cinfo->master->pass_startup) (cinfo);
  146118. rows_left = cinfo->image_height - cinfo->next_scanline;
  146119. if (num_lines > rows_left)
  146120. num_lines = rows_left;
  146121. row_ctr = 0;
  146122. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146123. cinfo->next_scanline += row_ctr;
  146124. return row_ctr;
  146125. }
  146126. GLOBAL(JDIMENSION)
  146127. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146128. JDIMENSION num_lines)
  146129. {
  146130. JDIMENSION lines_per_iMCU_row;
  146131. if (cinfo->global_state != CSTATE_RAW_OK)
  146132. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146133. if (cinfo->next_scanline >= cinfo->image_height) {
  146134. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146135. return 0;
  146136. }
  146137. if (cinfo->progress != NULL) {
  146138. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146139. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146140. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146141. }
  146142. if (cinfo->master->call_pass_startup)
  146143. (*cinfo->master->pass_startup) (cinfo);
  146144. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146145. if (num_lines < lines_per_iMCU_row)
  146146. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146147. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146148. return 0;
  146149. }
  146150. cinfo->next_scanline += lines_per_iMCU_row;
  146151. return lines_per_iMCU_row;
  146152. }
  146153. /*** End of inlined file: jcapistd.c ***/
  146154. /*** Start of inlined file: jccoefct.c ***/
  146155. #define JPEG_INTERNALS
  146156. #ifdef ENTROPY_OPT_SUPPORTED
  146157. #define FULL_COEF_BUFFER_SUPPORTED
  146158. #else
  146159. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146160. #define FULL_COEF_BUFFER_SUPPORTED
  146161. #endif
  146162. #endif
  146163. typedef struct {
  146164. struct jpeg_c_coef_controller pub; /* public fields */
  146165. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146166. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146167. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146168. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146169. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146170. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146171. } my_coef_controller;
  146172. typedef my_coef_controller * my_coef_ptr;
  146173. METHODDEF(boolean) compress_data
  146174. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146175. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146176. METHODDEF(boolean) compress_first_pass
  146177. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146178. METHODDEF(boolean) compress_output
  146179. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146180. #endif
  146181. LOCAL(void)
  146182. start_iMCU_row (j_compress_ptr cinfo)
  146183. {
  146184. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146185. if (cinfo->comps_in_scan > 1) {
  146186. coef->MCU_rows_per_iMCU_row = 1;
  146187. } else {
  146188. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146189. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146190. else
  146191. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146192. }
  146193. coef->mcu_ctr = 0;
  146194. coef->MCU_vert_offset = 0;
  146195. }
  146196. METHODDEF(void)
  146197. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146198. {
  146199. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146200. coef->iMCU_row_num = 0;
  146201. start_iMCU_row(cinfo);
  146202. switch (pass_mode) {
  146203. case JBUF_PASS_THRU:
  146204. if (coef->whole_image[0] != NULL)
  146205. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146206. coef->pub.compress_data = compress_data;
  146207. break;
  146208. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146209. case JBUF_SAVE_AND_PASS:
  146210. if (coef->whole_image[0] == NULL)
  146211. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146212. coef->pub.compress_data = compress_first_pass;
  146213. break;
  146214. case JBUF_CRANK_DEST:
  146215. if (coef->whole_image[0] == NULL)
  146216. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146217. coef->pub.compress_data = compress_output;
  146218. break;
  146219. #endif
  146220. default:
  146221. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146222. break;
  146223. }
  146224. }
  146225. METHODDEF(boolean)
  146226. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146227. {
  146228. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146229. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146230. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146231. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146232. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146233. JDIMENSION ypos, xpos;
  146234. jpeg_component_info *compptr;
  146235. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146236. yoffset++) {
  146237. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146238. MCU_col_num++) {
  146239. blkn = 0;
  146240. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146241. compptr = cinfo->cur_comp_info[ci];
  146242. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146243. : compptr->last_col_width;
  146244. xpos = MCU_col_num * compptr->MCU_sample_width;
  146245. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146246. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146247. if (coef->iMCU_row_num < last_iMCU_row ||
  146248. yoffset+yindex < compptr->last_row_height) {
  146249. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146250. input_buf[compptr->component_index],
  146251. coef->MCU_buffer[blkn],
  146252. ypos, xpos, (JDIMENSION) blockcnt);
  146253. if (blockcnt < compptr->MCU_width) {
  146254. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146255. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146256. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146257. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146258. }
  146259. }
  146260. } else {
  146261. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146262. compptr->MCU_width * SIZEOF(JBLOCK));
  146263. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146264. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146265. }
  146266. }
  146267. blkn += compptr->MCU_width;
  146268. ypos += DCTSIZE;
  146269. }
  146270. }
  146271. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146272. coef->MCU_vert_offset = yoffset;
  146273. coef->mcu_ctr = MCU_col_num;
  146274. return FALSE;
  146275. }
  146276. }
  146277. coef->mcu_ctr = 0;
  146278. }
  146279. coef->iMCU_row_num++;
  146280. start_iMCU_row(cinfo);
  146281. return TRUE;
  146282. }
  146283. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146284. METHODDEF(boolean)
  146285. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146286. {
  146287. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146288. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146289. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146290. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146291. JCOEF lastDC;
  146292. jpeg_component_info *compptr;
  146293. JBLOCKARRAY buffer;
  146294. JBLOCKROW thisblockrow, lastblockrow;
  146295. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146296. ci++, compptr++) {
  146297. buffer = (*cinfo->mem->access_virt_barray)
  146298. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146299. coef->iMCU_row_num * compptr->v_samp_factor,
  146300. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146301. if (coef->iMCU_row_num < last_iMCU_row)
  146302. block_rows = compptr->v_samp_factor;
  146303. else {
  146304. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146305. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146306. }
  146307. blocks_across = compptr->width_in_blocks;
  146308. h_samp_factor = compptr->h_samp_factor;
  146309. ndummy = (int) (blocks_across % h_samp_factor);
  146310. if (ndummy > 0)
  146311. ndummy = h_samp_factor - ndummy;
  146312. for (block_row = 0; block_row < block_rows; block_row++) {
  146313. thisblockrow = buffer[block_row];
  146314. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146315. input_buf[ci], thisblockrow,
  146316. (JDIMENSION) (block_row * DCTSIZE),
  146317. (JDIMENSION) 0, blocks_across);
  146318. if (ndummy > 0) {
  146319. thisblockrow += blocks_across; /* => first dummy block */
  146320. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146321. lastDC = thisblockrow[-1][0];
  146322. for (bi = 0; bi < ndummy; bi++) {
  146323. thisblockrow[bi][0] = lastDC;
  146324. }
  146325. }
  146326. }
  146327. if (coef->iMCU_row_num == last_iMCU_row) {
  146328. blocks_across += ndummy; /* include lower right corner */
  146329. MCUs_across = blocks_across / h_samp_factor;
  146330. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146331. block_row++) {
  146332. thisblockrow = buffer[block_row];
  146333. lastblockrow = buffer[block_row-1];
  146334. jzero_far((void FAR *) thisblockrow,
  146335. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146336. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146337. lastDC = lastblockrow[h_samp_factor-1][0];
  146338. for (bi = 0; bi < h_samp_factor; bi++) {
  146339. thisblockrow[bi][0] = lastDC;
  146340. }
  146341. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146342. lastblockrow += h_samp_factor;
  146343. }
  146344. }
  146345. }
  146346. }
  146347. return compress_output(cinfo, input_buf);
  146348. }
  146349. METHODDEF(boolean)
  146350. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146351. {
  146352. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146353. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146354. int blkn, ci, xindex, yindex, yoffset;
  146355. JDIMENSION start_col;
  146356. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146357. JBLOCKROW buffer_ptr;
  146358. jpeg_component_info *compptr;
  146359. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146360. compptr = cinfo->cur_comp_info[ci];
  146361. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146362. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146363. coef->iMCU_row_num * compptr->v_samp_factor,
  146364. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146365. }
  146366. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146367. yoffset++) {
  146368. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146369. MCU_col_num++) {
  146370. blkn = 0; /* index of current DCT block within MCU */
  146371. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146372. compptr = cinfo->cur_comp_info[ci];
  146373. start_col = MCU_col_num * compptr->MCU_width;
  146374. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146375. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146376. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146377. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146378. }
  146379. }
  146380. }
  146381. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146382. coef->MCU_vert_offset = yoffset;
  146383. coef->mcu_ctr = MCU_col_num;
  146384. return FALSE;
  146385. }
  146386. }
  146387. coef->mcu_ctr = 0;
  146388. }
  146389. coef->iMCU_row_num++;
  146390. start_iMCU_row(cinfo);
  146391. return TRUE;
  146392. }
  146393. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146394. GLOBAL(void)
  146395. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146396. {
  146397. my_coef_ptr coef;
  146398. coef = (my_coef_ptr)
  146399. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146400. SIZEOF(my_coef_controller));
  146401. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146402. coef->pub.start_pass = start_pass_coef;
  146403. if (need_full_buffer) {
  146404. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146405. int ci;
  146406. jpeg_component_info *compptr;
  146407. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146408. ci++, compptr++) {
  146409. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146410. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146411. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146412. (long) compptr->h_samp_factor),
  146413. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146414. (long) compptr->v_samp_factor),
  146415. (JDIMENSION) compptr->v_samp_factor);
  146416. }
  146417. #else
  146418. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146419. #endif
  146420. } else {
  146421. JBLOCKROW buffer;
  146422. int i;
  146423. buffer = (JBLOCKROW)
  146424. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146425. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146426. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146427. coef->MCU_buffer[i] = buffer + i;
  146428. }
  146429. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146430. }
  146431. }
  146432. /*** End of inlined file: jccoefct.c ***/
  146433. /*** Start of inlined file: jccolor.c ***/
  146434. #define JPEG_INTERNALS
  146435. typedef struct {
  146436. struct jpeg_color_converter pub; /* public fields */
  146437. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146438. } my_color_converter;
  146439. typedef my_color_converter * my_cconvert_ptr;
  146440. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146441. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146442. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146443. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146444. #define R_Y_OFF 0 /* offset to R => Y section */
  146445. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146446. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146447. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146448. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146449. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146450. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146451. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146452. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146453. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146454. METHODDEF(void)
  146455. rgb_ycc_start (j_compress_ptr cinfo)
  146456. {
  146457. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146458. INT32 * rgb_ycc_tab;
  146459. INT32 i;
  146460. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146461. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146462. (TABLE_SIZE * SIZEOF(INT32)));
  146463. for (i = 0; i <= MAXJSAMPLE; i++) {
  146464. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146465. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146466. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146467. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146468. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146469. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146470. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146471. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146472. }
  146473. }
  146474. METHODDEF(void)
  146475. rgb_ycc_convert (j_compress_ptr cinfo,
  146476. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146477. JDIMENSION output_row, int num_rows)
  146478. {
  146479. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146480. register int r, g, b;
  146481. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146482. register JSAMPROW inptr;
  146483. register JSAMPROW outptr0, outptr1, outptr2;
  146484. register JDIMENSION col;
  146485. JDIMENSION num_cols = cinfo->image_width;
  146486. while (--num_rows >= 0) {
  146487. inptr = *input_buf++;
  146488. outptr0 = output_buf[0][output_row];
  146489. outptr1 = output_buf[1][output_row];
  146490. outptr2 = output_buf[2][output_row];
  146491. output_row++;
  146492. for (col = 0; col < num_cols; col++) {
  146493. r = GETJSAMPLE(inptr[RGB_RED]);
  146494. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146495. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146496. inptr += RGB_PIXELSIZE;
  146497. outptr0[col] = (JSAMPLE)
  146498. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146499. >> SCALEBITS);
  146500. outptr1[col] = (JSAMPLE)
  146501. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146502. >> SCALEBITS);
  146503. outptr2[col] = (JSAMPLE)
  146504. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146505. >> SCALEBITS);
  146506. }
  146507. }
  146508. }
  146509. METHODDEF(void)
  146510. rgb_gray_convert (j_compress_ptr cinfo,
  146511. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146512. JDIMENSION output_row, int num_rows)
  146513. {
  146514. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146515. register int r, g, b;
  146516. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146517. register JSAMPROW inptr;
  146518. register JSAMPROW outptr;
  146519. register JDIMENSION col;
  146520. JDIMENSION num_cols = cinfo->image_width;
  146521. while (--num_rows >= 0) {
  146522. inptr = *input_buf++;
  146523. outptr = output_buf[0][output_row];
  146524. output_row++;
  146525. for (col = 0; col < num_cols; col++) {
  146526. r = GETJSAMPLE(inptr[RGB_RED]);
  146527. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146528. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146529. inptr += RGB_PIXELSIZE;
  146530. outptr[col] = (JSAMPLE)
  146531. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146532. >> SCALEBITS);
  146533. }
  146534. }
  146535. }
  146536. METHODDEF(void)
  146537. cmyk_ycck_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, outptr3;
  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. outptr3 = output_buf[3][output_row];
  146554. output_row++;
  146555. for (col = 0; col < num_cols; col++) {
  146556. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146557. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146558. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146559. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146560. inptr += 4;
  146561. outptr0[col] = (JSAMPLE)
  146562. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146563. >> SCALEBITS);
  146564. outptr1[col] = (JSAMPLE)
  146565. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146566. >> SCALEBITS);
  146567. outptr2[col] = (JSAMPLE)
  146568. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146569. >> SCALEBITS);
  146570. }
  146571. }
  146572. }
  146573. METHODDEF(void)
  146574. grayscale_convert (j_compress_ptr cinfo,
  146575. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146576. JDIMENSION output_row, int num_rows)
  146577. {
  146578. register JSAMPROW inptr;
  146579. register JSAMPROW outptr;
  146580. register JDIMENSION col;
  146581. JDIMENSION num_cols = cinfo->image_width;
  146582. int instride = cinfo->input_components;
  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. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146589. inptr += instride;
  146590. }
  146591. }
  146592. }
  146593. METHODDEF(void)
  146594. null_convert (j_compress_ptr cinfo,
  146595. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146596. JDIMENSION output_row, int num_rows)
  146597. {
  146598. register JSAMPROW inptr;
  146599. register JSAMPROW outptr;
  146600. register JDIMENSION col;
  146601. register int ci;
  146602. int nc = cinfo->num_components;
  146603. JDIMENSION num_cols = cinfo->image_width;
  146604. while (--num_rows >= 0) {
  146605. for (ci = 0; ci < nc; ci++) {
  146606. inptr = *input_buf;
  146607. outptr = output_buf[ci][output_row];
  146608. for (col = 0; col < num_cols; col++) {
  146609. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146610. inptr += nc;
  146611. }
  146612. }
  146613. input_buf++;
  146614. output_row++;
  146615. }
  146616. }
  146617. METHODDEF(void)
  146618. null_method (j_compress_ptr cinfo)
  146619. {
  146620. }
  146621. GLOBAL(void)
  146622. jinit_color_converter (j_compress_ptr cinfo)
  146623. {
  146624. my_cconvert_ptr cconvert;
  146625. cconvert = (my_cconvert_ptr)
  146626. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146627. SIZEOF(my_color_converter));
  146628. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146629. cconvert->pub.start_pass = null_method;
  146630. switch (cinfo->in_color_space) {
  146631. case JCS_GRAYSCALE:
  146632. if (cinfo->input_components != 1)
  146633. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146634. break;
  146635. case JCS_RGB:
  146636. #if RGB_PIXELSIZE != 3
  146637. if (cinfo->input_components != RGB_PIXELSIZE)
  146638. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146639. break;
  146640. #endif /* else share code with YCbCr */
  146641. case JCS_YCbCr:
  146642. if (cinfo->input_components != 3)
  146643. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146644. break;
  146645. case JCS_CMYK:
  146646. case JCS_YCCK:
  146647. if (cinfo->input_components != 4)
  146648. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146649. break;
  146650. default: /* JCS_UNKNOWN can be anything */
  146651. if (cinfo->input_components < 1)
  146652. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146653. break;
  146654. }
  146655. switch (cinfo->jpeg_color_space) {
  146656. case JCS_GRAYSCALE:
  146657. if (cinfo->num_components != 1)
  146658. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146659. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146660. cconvert->pub.color_convert = grayscale_convert;
  146661. else if (cinfo->in_color_space == JCS_RGB) {
  146662. cconvert->pub.start_pass = rgb_ycc_start;
  146663. cconvert->pub.color_convert = rgb_gray_convert;
  146664. } else if (cinfo->in_color_space == JCS_YCbCr)
  146665. cconvert->pub.color_convert = grayscale_convert;
  146666. else
  146667. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146668. break;
  146669. case JCS_RGB:
  146670. if (cinfo->num_components != 3)
  146671. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146672. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146673. cconvert->pub.color_convert = null_convert;
  146674. else
  146675. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146676. break;
  146677. case JCS_YCbCr:
  146678. if (cinfo->num_components != 3)
  146679. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146680. if (cinfo->in_color_space == JCS_RGB) {
  146681. cconvert->pub.start_pass = rgb_ycc_start;
  146682. cconvert->pub.color_convert = rgb_ycc_convert;
  146683. } else if (cinfo->in_color_space == JCS_YCbCr)
  146684. cconvert->pub.color_convert = null_convert;
  146685. else
  146686. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146687. break;
  146688. case JCS_CMYK:
  146689. if (cinfo->num_components != 4)
  146690. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146691. if (cinfo->in_color_space == JCS_CMYK)
  146692. cconvert->pub.color_convert = null_convert;
  146693. else
  146694. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146695. break;
  146696. case JCS_YCCK:
  146697. if (cinfo->num_components != 4)
  146698. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146699. if (cinfo->in_color_space == JCS_CMYK) {
  146700. cconvert->pub.start_pass = rgb_ycc_start;
  146701. cconvert->pub.color_convert = cmyk_ycck_convert;
  146702. } else if (cinfo->in_color_space == JCS_YCCK)
  146703. cconvert->pub.color_convert = null_convert;
  146704. else
  146705. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146706. break;
  146707. default: /* allow null conversion of JCS_UNKNOWN */
  146708. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146709. cinfo->num_components != cinfo->input_components)
  146710. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146711. cconvert->pub.color_convert = null_convert;
  146712. break;
  146713. }
  146714. }
  146715. /*** End of inlined file: jccolor.c ***/
  146716. #undef FIX
  146717. /*** Start of inlined file: jcdctmgr.c ***/
  146718. #define JPEG_INTERNALS
  146719. /*** Start of inlined file: jdct.h ***/
  146720. #ifndef __jdct_h__
  146721. #define __jdct_h__
  146722. #if BITS_IN_JSAMPLE == 8
  146723. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146724. #else
  146725. typedef INT32 DCTELEM; /* must have 32 bits */
  146726. #endif
  146727. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146728. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146729. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146730. #if BITS_IN_JSAMPLE == 8
  146731. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146732. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146733. #else
  146734. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146735. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146736. #endif
  146737. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146738. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146739. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146740. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146741. #define jpeg_fdct_islow jFDislow
  146742. #define jpeg_fdct_ifast jFDifast
  146743. #define jpeg_fdct_float jFDfloat
  146744. #define jpeg_idct_islow jRDislow
  146745. #define jpeg_idct_ifast jRDifast
  146746. #define jpeg_idct_float jRDfloat
  146747. #define jpeg_idct_4x4 jRD4x4
  146748. #define jpeg_idct_2x2 jRD2x2
  146749. #define jpeg_idct_1x1 jRD1x1
  146750. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146751. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146752. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146753. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146754. EXTERN(void) jpeg_idct_islow
  146755. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146756. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146757. EXTERN(void) jpeg_idct_ifast
  146758. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146759. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146760. EXTERN(void) jpeg_idct_float
  146761. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146762. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146763. EXTERN(void) jpeg_idct_4x4
  146764. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146765. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146766. EXTERN(void) jpeg_idct_2x2
  146767. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146768. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146769. EXTERN(void) jpeg_idct_1x1
  146770. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146771. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146772. #define ONE ((INT32) 1)
  146773. #define CONST_SCALE (ONE << CONST_BITS)
  146774. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146775. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146776. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146777. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146778. #endif
  146779. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146780. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146781. #endif
  146782. #ifndef MULTIPLY16C16 /* default definition */
  146783. #define MULTIPLY16C16(var,const) ((var) * (const))
  146784. #endif
  146785. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146786. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146787. #endif
  146788. #ifndef MULTIPLY16V16 /* default definition */
  146789. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146790. #endif
  146791. #endif
  146792. /*** End of inlined file: jdct.h ***/
  146793. /* Private declarations for DCT subsystem */
  146794. typedef struct {
  146795. struct jpeg_forward_dct pub; /* public fields */
  146796. forward_DCT_method_ptr do_dct;
  146797. DCTELEM * divisors[NUM_QUANT_TBLS];
  146798. #ifdef DCT_FLOAT_SUPPORTED
  146799. float_DCT_method_ptr do_float_dct;
  146800. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146801. #endif
  146802. } my_fdct_controller;
  146803. typedef my_fdct_controller * my_fdct_ptr;
  146804. METHODDEF(void)
  146805. start_pass_fdctmgr (j_compress_ptr cinfo)
  146806. {
  146807. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146808. int ci, qtblno, i;
  146809. jpeg_component_info *compptr;
  146810. JQUANT_TBL * qtbl;
  146811. DCTELEM * dtbl;
  146812. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146813. ci++, compptr++) {
  146814. qtblno = compptr->quant_tbl_no;
  146815. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146816. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146817. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146818. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146819. switch (cinfo->dct_method) {
  146820. #ifdef DCT_ISLOW_SUPPORTED
  146821. case JDCT_ISLOW:
  146822. if (fdct->divisors[qtblno] == NULL) {
  146823. fdct->divisors[qtblno] = (DCTELEM *)
  146824. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146825. DCTSIZE2 * SIZEOF(DCTELEM));
  146826. }
  146827. dtbl = fdct->divisors[qtblno];
  146828. for (i = 0; i < DCTSIZE2; i++) {
  146829. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146830. }
  146831. break;
  146832. #endif
  146833. #ifdef DCT_IFAST_SUPPORTED
  146834. case JDCT_IFAST:
  146835. {
  146836. #define CONST_BITS 14
  146837. static const INT16 aanscales[DCTSIZE2] = {
  146838. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146839. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146840. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146841. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146842. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146843. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146844. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146845. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146846. };
  146847. SHIFT_TEMPS
  146848. if (fdct->divisors[qtblno] == NULL) {
  146849. fdct->divisors[qtblno] = (DCTELEM *)
  146850. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146851. DCTSIZE2 * SIZEOF(DCTELEM));
  146852. }
  146853. dtbl = fdct->divisors[qtblno];
  146854. for (i = 0; i < DCTSIZE2; i++) {
  146855. dtbl[i] = (DCTELEM)
  146856. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146857. (INT32) aanscales[i]),
  146858. CONST_BITS-3);
  146859. }
  146860. }
  146861. break;
  146862. #endif
  146863. #ifdef DCT_FLOAT_SUPPORTED
  146864. case JDCT_FLOAT:
  146865. {
  146866. FAST_FLOAT * fdtbl;
  146867. int row, col;
  146868. static const double aanscalefactor[DCTSIZE] = {
  146869. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146870. 1.0, 0.785694958, 0.541196100, 0.275899379
  146871. };
  146872. if (fdct->float_divisors[qtblno] == NULL) {
  146873. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146874. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146875. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146876. }
  146877. fdtbl = fdct->float_divisors[qtblno];
  146878. i = 0;
  146879. for (row = 0; row < DCTSIZE; row++) {
  146880. for (col = 0; col < DCTSIZE; col++) {
  146881. fdtbl[i] = (FAST_FLOAT)
  146882. (1.0 / (((double) qtbl->quantval[i] *
  146883. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146884. i++;
  146885. }
  146886. }
  146887. }
  146888. break;
  146889. #endif
  146890. default:
  146891. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146892. break;
  146893. }
  146894. }
  146895. }
  146896. METHODDEF(void)
  146897. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146898. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146899. JDIMENSION start_row, JDIMENSION start_col,
  146900. JDIMENSION num_blocks)
  146901. {
  146902. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146903. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146904. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146905. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146906. JDIMENSION bi;
  146907. sample_data += start_row; /* fold in the vertical offset once */
  146908. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146909. { register DCTELEM *workspaceptr;
  146910. register JSAMPROW elemptr;
  146911. register int elemr;
  146912. workspaceptr = workspace;
  146913. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146914. elemptr = sample_data[elemr] + start_col;
  146915. #if DCTSIZE == 8 /* unroll the inner loop */
  146916. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146917. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146918. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146919. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146920. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146921. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146922. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146923. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146924. #else
  146925. { register int elemc;
  146926. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146927. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146928. }
  146929. }
  146930. #endif
  146931. }
  146932. }
  146933. (*do_dct) (workspace);
  146934. { register DCTELEM temp, qval;
  146935. register int i;
  146936. register JCOEFPTR output_ptr = coef_blocks[bi];
  146937. for (i = 0; i < DCTSIZE2; i++) {
  146938. qval = divisors[i];
  146939. temp = workspace[i];
  146940. #ifdef FAST_DIVIDE
  146941. #define DIVIDE_BY(a,b) a /= b
  146942. #else
  146943. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  146944. #endif
  146945. if (temp < 0) {
  146946. temp = -temp;
  146947. temp += qval>>1; /* for rounding */
  146948. DIVIDE_BY(temp, qval);
  146949. temp = -temp;
  146950. } else {
  146951. temp += qval>>1; /* for rounding */
  146952. DIVIDE_BY(temp, qval);
  146953. }
  146954. output_ptr[i] = (JCOEF) temp;
  146955. }
  146956. }
  146957. }
  146958. }
  146959. #ifdef DCT_FLOAT_SUPPORTED
  146960. METHODDEF(void)
  146961. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146962. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146963. JDIMENSION start_row, JDIMENSION start_col,
  146964. JDIMENSION num_blocks)
  146965. {
  146966. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146967. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  146968. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  146969. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146970. JDIMENSION bi;
  146971. sample_data += start_row; /* fold in the vertical offset once */
  146972. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146973. { register FAST_FLOAT *workspaceptr;
  146974. register JSAMPROW elemptr;
  146975. register int elemr;
  146976. workspaceptr = workspace;
  146977. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146978. elemptr = sample_data[elemr] + start_col;
  146979. #if DCTSIZE == 8 /* unroll the inner loop */
  146980. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146981. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146982. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146983. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146984. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146985. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146986. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146987. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146988. #else
  146989. { register int elemc;
  146990. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146991. *workspaceptr++ = (FAST_FLOAT)
  146992. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146993. }
  146994. }
  146995. #endif
  146996. }
  146997. }
  146998. (*do_dct) (workspace);
  146999. { register FAST_FLOAT temp;
  147000. register int i;
  147001. register JCOEFPTR output_ptr = coef_blocks[bi];
  147002. for (i = 0; i < DCTSIZE2; i++) {
  147003. temp = workspace[i] * divisors[i];
  147004. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  147005. }
  147006. }
  147007. }
  147008. }
  147009. #endif /* DCT_FLOAT_SUPPORTED */
  147010. GLOBAL(void)
  147011. jinit_forward_dct (j_compress_ptr cinfo)
  147012. {
  147013. my_fdct_ptr fdct;
  147014. int i;
  147015. fdct = (my_fdct_ptr)
  147016. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147017. SIZEOF(my_fdct_controller));
  147018. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  147019. fdct->pub.start_pass = start_pass_fdctmgr;
  147020. switch (cinfo->dct_method) {
  147021. #ifdef DCT_ISLOW_SUPPORTED
  147022. case JDCT_ISLOW:
  147023. fdct->pub.forward_DCT = forward_DCT;
  147024. fdct->do_dct = jpeg_fdct_islow;
  147025. break;
  147026. #endif
  147027. #ifdef DCT_IFAST_SUPPORTED
  147028. case JDCT_IFAST:
  147029. fdct->pub.forward_DCT = forward_DCT;
  147030. fdct->do_dct = jpeg_fdct_ifast;
  147031. break;
  147032. #endif
  147033. #ifdef DCT_FLOAT_SUPPORTED
  147034. case JDCT_FLOAT:
  147035. fdct->pub.forward_DCT = forward_DCT_float;
  147036. fdct->do_float_dct = jpeg_fdct_float;
  147037. break;
  147038. #endif
  147039. default:
  147040. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147041. break;
  147042. }
  147043. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147044. fdct->divisors[i] = NULL;
  147045. #ifdef DCT_FLOAT_SUPPORTED
  147046. fdct->float_divisors[i] = NULL;
  147047. #endif
  147048. }
  147049. }
  147050. /*** End of inlined file: jcdctmgr.c ***/
  147051. #undef CONST_BITS
  147052. /*** Start of inlined file: jchuff.c ***/
  147053. #define JPEG_INTERNALS
  147054. /*** Start of inlined file: jchuff.h ***/
  147055. #ifndef _jchuff_h_
  147056. #define _jchuff_h_
  147057. #if BITS_IN_JSAMPLE == 8
  147058. #define MAX_COEF_BITS 10
  147059. #else
  147060. #define MAX_COEF_BITS 14
  147061. #endif
  147062. typedef struct {
  147063. unsigned int ehufco[256]; /* code for each symbol */
  147064. char ehufsi[256]; /* length of code for each symbol */
  147065. } c_derived_tbl;
  147066. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147067. #define jpeg_make_c_derived_tbl jMkCDerived
  147068. #define jpeg_gen_optimal_table jGenOptTbl
  147069. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147070. EXTERN(void) jpeg_make_c_derived_tbl
  147071. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147072. c_derived_tbl ** pdtbl));
  147073. EXTERN(void) jpeg_gen_optimal_table
  147074. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147075. #endif
  147076. /*** End of inlined file: jchuff.h ***/
  147077. /* Declarations shared with jcphuff.c */
  147078. typedef struct {
  147079. INT32 put_buffer; /* current bit-accumulation buffer */
  147080. int put_bits; /* # of bits now in it */
  147081. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147082. } savable_state;
  147083. #ifndef NO_STRUCT_ASSIGN
  147084. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147085. #else
  147086. #if MAX_COMPS_IN_SCAN == 4
  147087. #define ASSIGN_STATE(dest,src) \
  147088. ((dest).put_buffer = (src).put_buffer, \
  147089. (dest).put_bits = (src).put_bits, \
  147090. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147091. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147092. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147093. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147094. #endif
  147095. #endif
  147096. typedef struct {
  147097. struct jpeg_entropy_encoder pub; /* public fields */
  147098. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147099. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147100. int next_restart_num; /* next restart number to write (0-7) */
  147101. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147102. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147103. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147104. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147105. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147106. #endif
  147107. } huff_entropy_encoder;
  147108. typedef huff_entropy_encoder * huff_entropy_ptr;
  147109. typedef struct {
  147110. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147111. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147112. savable_state cur; /* Current bit buffer & DC state */
  147113. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147114. } working_state;
  147115. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147116. JBLOCKROW *MCU_data));
  147117. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147118. #ifdef ENTROPY_OPT_SUPPORTED
  147119. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147120. JBLOCKROW *MCU_data));
  147121. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147122. #endif
  147123. METHODDEF(void)
  147124. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147125. {
  147126. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147127. int ci, dctbl, actbl;
  147128. jpeg_component_info * compptr;
  147129. if (gather_statistics) {
  147130. #ifdef ENTROPY_OPT_SUPPORTED
  147131. entropy->pub.encode_mcu = encode_mcu_gather;
  147132. entropy->pub.finish_pass = finish_pass_gather;
  147133. #else
  147134. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147135. #endif
  147136. } else {
  147137. entropy->pub.encode_mcu = encode_mcu_huff;
  147138. entropy->pub.finish_pass = finish_pass_huff;
  147139. }
  147140. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147141. compptr = cinfo->cur_comp_info[ci];
  147142. dctbl = compptr->dc_tbl_no;
  147143. actbl = compptr->ac_tbl_no;
  147144. if (gather_statistics) {
  147145. #ifdef ENTROPY_OPT_SUPPORTED
  147146. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147147. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147148. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147149. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147150. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147151. entropy->dc_count_ptrs[dctbl] = (long *)
  147152. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147153. 257 * SIZEOF(long));
  147154. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147155. if (entropy->ac_count_ptrs[actbl] == NULL)
  147156. entropy->ac_count_ptrs[actbl] = (long *)
  147157. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147158. 257 * SIZEOF(long));
  147159. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147160. #endif
  147161. } else {
  147162. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147163. & entropy->dc_derived_tbls[dctbl]);
  147164. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147165. & entropy->ac_derived_tbls[actbl]);
  147166. }
  147167. entropy->saved.last_dc_val[ci] = 0;
  147168. }
  147169. entropy->saved.put_buffer = 0;
  147170. entropy->saved.put_bits = 0;
  147171. entropy->restarts_to_go = cinfo->restart_interval;
  147172. entropy->next_restart_num = 0;
  147173. }
  147174. GLOBAL(void)
  147175. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147176. c_derived_tbl ** pdtbl)
  147177. {
  147178. JHUFF_TBL *htbl;
  147179. c_derived_tbl *dtbl;
  147180. int p, i, l, lastp, si, maxsymbol;
  147181. char huffsize[257];
  147182. unsigned int huffcode[257];
  147183. unsigned int code;
  147184. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147185. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147186. htbl =
  147187. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147188. if (htbl == NULL)
  147189. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147190. if (*pdtbl == NULL)
  147191. *pdtbl = (c_derived_tbl *)
  147192. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147193. SIZEOF(c_derived_tbl));
  147194. dtbl = *pdtbl;
  147195. p = 0;
  147196. for (l = 1; l <= 16; l++) {
  147197. i = (int) htbl->bits[l];
  147198. if (i < 0 || p + i > 256) /* protect against table overrun */
  147199. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147200. while (i--)
  147201. huffsize[p++] = (char) l;
  147202. }
  147203. huffsize[p] = 0;
  147204. lastp = p;
  147205. code = 0;
  147206. si = huffsize[0];
  147207. p = 0;
  147208. while (huffsize[p]) {
  147209. while (((int) huffsize[p]) == si) {
  147210. huffcode[p++] = code;
  147211. code++;
  147212. }
  147213. if (((INT32) code) >= (((INT32) 1) << si))
  147214. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147215. code <<= 1;
  147216. si++;
  147217. }
  147218. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147219. maxsymbol = isDC ? 15 : 255;
  147220. for (p = 0; p < lastp; p++) {
  147221. i = htbl->huffval[p];
  147222. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147223. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147224. dtbl->ehufco[i] = huffcode[p];
  147225. dtbl->ehufsi[i] = huffsize[p];
  147226. }
  147227. }
  147228. #define emit_byte(state,val,action) \
  147229. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147230. if (--(state)->free_in_buffer == 0) \
  147231. if (! dump_buffer(state)) \
  147232. { action; } }
  147233. LOCAL(boolean)
  147234. dump_buffer (working_state * state)
  147235. {
  147236. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147237. if (! (*dest->empty_output_buffer) (state->cinfo))
  147238. return FALSE;
  147239. state->next_output_byte = dest->next_output_byte;
  147240. state->free_in_buffer = dest->free_in_buffer;
  147241. return TRUE;
  147242. }
  147243. INLINE
  147244. LOCAL(boolean)
  147245. emit_bits (working_state * state, unsigned int code, int size)
  147246. {
  147247. register INT32 put_buffer = (INT32) code;
  147248. register int put_bits = state->cur.put_bits;
  147249. if (size == 0)
  147250. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147251. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147252. put_bits += size; /* new number of bits in buffer */
  147253. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147254. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147255. while (put_bits >= 8) {
  147256. int c = (int) ((put_buffer >> 16) & 0xFF);
  147257. emit_byte(state, c, return FALSE);
  147258. if (c == 0xFF) { /* need to stuff a zero byte? */
  147259. emit_byte(state, 0, return FALSE);
  147260. }
  147261. put_buffer <<= 8;
  147262. put_bits -= 8;
  147263. }
  147264. state->cur.put_buffer = put_buffer; /* update state variables */
  147265. state->cur.put_bits = put_bits;
  147266. return TRUE;
  147267. }
  147268. LOCAL(boolean)
  147269. flush_bits (working_state * state)
  147270. {
  147271. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147272. return FALSE;
  147273. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147274. state->cur.put_bits = 0;
  147275. return TRUE;
  147276. }
  147277. LOCAL(boolean)
  147278. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147279. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147280. {
  147281. register int temp, temp2;
  147282. register int nbits;
  147283. register int k, r, i;
  147284. temp = temp2 = block[0] - last_dc_val;
  147285. if (temp < 0) {
  147286. temp = -temp; /* temp is abs value of input */
  147287. temp2--;
  147288. }
  147289. nbits = 0;
  147290. while (temp) {
  147291. nbits++;
  147292. temp >>= 1;
  147293. }
  147294. if (nbits > MAX_COEF_BITS+1)
  147295. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147296. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147297. return FALSE;
  147298. if (nbits) /* emit_bits rejects calls with size 0 */
  147299. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147300. return FALSE;
  147301. r = 0; /* r = run length of zeros */
  147302. for (k = 1; k < DCTSIZE2; k++) {
  147303. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147304. r++;
  147305. } else {
  147306. while (r > 15) {
  147307. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147308. return FALSE;
  147309. r -= 16;
  147310. }
  147311. temp2 = temp;
  147312. if (temp < 0) {
  147313. temp = -temp; /* temp is abs value of input */
  147314. temp2--;
  147315. }
  147316. nbits = 1; /* there must be at least one 1 bit */
  147317. while ((temp >>= 1))
  147318. nbits++;
  147319. if (nbits > MAX_COEF_BITS)
  147320. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147321. i = (r << 4) + nbits;
  147322. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147323. return FALSE;
  147324. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147325. return FALSE;
  147326. r = 0;
  147327. }
  147328. }
  147329. if (r > 0)
  147330. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147331. return FALSE;
  147332. return TRUE;
  147333. }
  147334. LOCAL(boolean)
  147335. emit_restart (working_state * state, int restart_num)
  147336. {
  147337. int ci;
  147338. if (! flush_bits(state))
  147339. return FALSE;
  147340. emit_byte(state, 0xFF, return FALSE);
  147341. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147342. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147343. state->cur.last_dc_val[ci] = 0;
  147344. return TRUE;
  147345. }
  147346. METHODDEF(boolean)
  147347. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147348. {
  147349. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147350. working_state state;
  147351. int blkn, ci;
  147352. jpeg_component_info * compptr;
  147353. state.next_output_byte = cinfo->dest->next_output_byte;
  147354. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147355. ASSIGN_STATE(state.cur, entropy->saved);
  147356. state.cinfo = cinfo;
  147357. if (cinfo->restart_interval) {
  147358. if (entropy->restarts_to_go == 0)
  147359. if (! emit_restart(&state, entropy->next_restart_num))
  147360. return FALSE;
  147361. }
  147362. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147363. ci = cinfo->MCU_membership[blkn];
  147364. compptr = cinfo->cur_comp_info[ci];
  147365. if (! encode_one_block(&state,
  147366. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147367. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147368. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147369. return FALSE;
  147370. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147371. }
  147372. cinfo->dest->next_output_byte = state.next_output_byte;
  147373. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147374. ASSIGN_STATE(entropy->saved, state.cur);
  147375. if (cinfo->restart_interval) {
  147376. if (entropy->restarts_to_go == 0) {
  147377. entropy->restarts_to_go = cinfo->restart_interval;
  147378. entropy->next_restart_num++;
  147379. entropy->next_restart_num &= 7;
  147380. }
  147381. entropy->restarts_to_go--;
  147382. }
  147383. return TRUE;
  147384. }
  147385. METHODDEF(void)
  147386. finish_pass_huff (j_compress_ptr cinfo)
  147387. {
  147388. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147389. working_state state;
  147390. state.next_output_byte = cinfo->dest->next_output_byte;
  147391. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147392. ASSIGN_STATE(state.cur, entropy->saved);
  147393. state.cinfo = cinfo;
  147394. if (! flush_bits(&state))
  147395. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147396. cinfo->dest->next_output_byte = state.next_output_byte;
  147397. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147398. ASSIGN_STATE(entropy->saved, state.cur);
  147399. }
  147400. #ifdef ENTROPY_OPT_SUPPORTED
  147401. LOCAL(void)
  147402. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147403. long dc_counts[], long ac_counts[])
  147404. {
  147405. register int temp;
  147406. register int nbits;
  147407. register int k, r;
  147408. temp = block[0] - last_dc_val;
  147409. if (temp < 0)
  147410. temp = -temp;
  147411. nbits = 0;
  147412. while (temp) {
  147413. nbits++;
  147414. temp >>= 1;
  147415. }
  147416. if (nbits > MAX_COEF_BITS+1)
  147417. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147418. dc_counts[nbits]++;
  147419. r = 0; /* r = run length of zeros */
  147420. for (k = 1; k < DCTSIZE2; k++) {
  147421. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147422. r++;
  147423. } else {
  147424. while (r > 15) {
  147425. ac_counts[0xF0]++;
  147426. r -= 16;
  147427. }
  147428. if (temp < 0)
  147429. temp = -temp;
  147430. nbits = 1; /* there must be at least one 1 bit */
  147431. while ((temp >>= 1))
  147432. nbits++;
  147433. if (nbits > MAX_COEF_BITS)
  147434. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147435. ac_counts[(r << 4) + nbits]++;
  147436. r = 0;
  147437. }
  147438. }
  147439. if (r > 0)
  147440. ac_counts[0]++;
  147441. }
  147442. METHODDEF(boolean)
  147443. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147444. {
  147445. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147446. int blkn, ci;
  147447. jpeg_component_info * compptr;
  147448. if (cinfo->restart_interval) {
  147449. if (entropy->restarts_to_go == 0) {
  147450. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147451. entropy->saved.last_dc_val[ci] = 0;
  147452. entropy->restarts_to_go = cinfo->restart_interval;
  147453. }
  147454. entropy->restarts_to_go--;
  147455. }
  147456. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147457. ci = cinfo->MCU_membership[blkn];
  147458. compptr = cinfo->cur_comp_info[ci];
  147459. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147460. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147461. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147462. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147463. }
  147464. return TRUE;
  147465. }
  147466. GLOBAL(void)
  147467. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147468. {
  147469. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147470. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147471. int codesize[257]; /* codesize[k] = code length of symbol k */
  147472. int others[257]; /* next symbol in current branch of tree */
  147473. int c1, c2;
  147474. int p, i, j;
  147475. long v;
  147476. MEMZERO(bits, SIZEOF(bits));
  147477. MEMZERO(codesize, SIZEOF(codesize));
  147478. for (i = 0; i < 257; i++)
  147479. others[i] = -1; /* init links to empty */
  147480. freq[256] = 1; /* make sure 256 has a nonzero count */
  147481. for (;;) {
  147482. c1 = -1;
  147483. v = 1000000000L;
  147484. for (i = 0; i <= 256; i++) {
  147485. if (freq[i] && freq[i] <= v) {
  147486. v = freq[i];
  147487. c1 = i;
  147488. }
  147489. }
  147490. c2 = -1;
  147491. v = 1000000000L;
  147492. for (i = 0; i <= 256; i++) {
  147493. if (freq[i] && freq[i] <= v && i != c1) {
  147494. v = freq[i];
  147495. c2 = i;
  147496. }
  147497. }
  147498. if (c2 < 0)
  147499. break;
  147500. freq[c1] += freq[c2];
  147501. freq[c2] = 0;
  147502. codesize[c1]++;
  147503. while (others[c1] >= 0) {
  147504. c1 = others[c1];
  147505. codesize[c1]++;
  147506. }
  147507. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147508. codesize[c2]++;
  147509. while (others[c2] >= 0) {
  147510. c2 = others[c2];
  147511. codesize[c2]++;
  147512. }
  147513. }
  147514. for (i = 0; i <= 256; i++) {
  147515. if (codesize[i]) {
  147516. if (codesize[i] > MAX_CLEN)
  147517. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147518. bits[codesize[i]]++;
  147519. }
  147520. }
  147521. for (i = MAX_CLEN; i > 16; i--) {
  147522. while (bits[i] > 0) {
  147523. j = i - 2; /* find length of new prefix to be used */
  147524. while (bits[j] == 0)
  147525. j--;
  147526. bits[i] -= 2; /* remove two symbols */
  147527. bits[i-1]++; /* one goes in this length */
  147528. bits[j+1] += 2; /* two new symbols in this length */
  147529. bits[j]--; /* symbol of this length is now a prefix */
  147530. }
  147531. }
  147532. while (bits[i] == 0) /* find largest codelength still in use */
  147533. i--;
  147534. bits[i]--;
  147535. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147536. p = 0;
  147537. for (i = 1; i <= MAX_CLEN; i++) {
  147538. for (j = 0; j <= 255; j++) {
  147539. if (codesize[j] == i) {
  147540. htbl->huffval[p] = (UINT8) j;
  147541. p++;
  147542. }
  147543. }
  147544. }
  147545. htbl->sent_table = FALSE;
  147546. }
  147547. METHODDEF(void)
  147548. finish_pass_gather (j_compress_ptr cinfo)
  147549. {
  147550. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147551. int ci, dctbl, actbl;
  147552. jpeg_component_info * compptr;
  147553. JHUFF_TBL **htblptr;
  147554. boolean did_dc[NUM_HUFF_TBLS];
  147555. boolean did_ac[NUM_HUFF_TBLS];
  147556. MEMZERO(did_dc, SIZEOF(did_dc));
  147557. MEMZERO(did_ac, SIZEOF(did_ac));
  147558. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147559. compptr = cinfo->cur_comp_info[ci];
  147560. dctbl = compptr->dc_tbl_no;
  147561. actbl = compptr->ac_tbl_no;
  147562. if (! did_dc[dctbl]) {
  147563. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147564. if (*htblptr == NULL)
  147565. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147566. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147567. did_dc[dctbl] = TRUE;
  147568. }
  147569. if (! did_ac[actbl]) {
  147570. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147571. if (*htblptr == NULL)
  147572. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147573. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147574. did_ac[actbl] = TRUE;
  147575. }
  147576. }
  147577. }
  147578. #endif /* ENTROPY_OPT_SUPPORTED */
  147579. GLOBAL(void)
  147580. jinit_huff_encoder (j_compress_ptr cinfo)
  147581. {
  147582. huff_entropy_ptr entropy;
  147583. int i;
  147584. entropy = (huff_entropy_ptr)
  147585. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147586. SIZEOF(huff_entropy_encoder));
  147587. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147588. entropy->pub.start_pass = start_pass_huff;
  147589. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147590. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147591. #ifdef ENTROPY_OPT_SUPPORTED
  147592. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147593. #endif
  147594. }
  147595. }
  147596. /*** End of inlined file: jchuff.c ***/
  147597. #undef emit_byte
  147598. /*** Start of inlined file: jcinit.c ***/
  147599. #define JPEG_INTERNALS
  147600. GLOBAL(void)
  147601. jinit_compress_master (j_compress_ptr cinfo)
  147602. {
  147603. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147604. if (! cinfo->raw_data_in) {
  147605. jinit_color_converter(cinfo);
  147606. jinit_downsampler(cinfo);
  147607. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147608. }
  147609. jinit_forward_dct(cinfo);
  147610. if (cinfo->arith_code) {
  147611. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147612. } else {
  147613. if (cinfo->progressive_mode) {
  147614. #ifdef C_PROGRESSIVE_SUPPORTED
  147615. jinit_phuff_encoder(cinfo);
  147616. #else
  147617. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147618. #endif
  147619. } else
  147620. jinit_huff_encoder(cinfo);
  147621. }
  147622. jinit_c_coef_controller(cinfo,
  147623. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147624. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147625. jinit_marker_writer(cinfo);
  147626. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147627. (*cinfo->marker->write_file_header) (cinfo);
  147628. }
  147629. /*** End of inlined file: jcinit.c ***/
  147630. /*** Start of inlined file: jcmainct.c ***/
  147631. #define JPEG_INTERNALS
  147632. #undef FULL_MAIN_BUFFER_SUPPORTED
  147633. typedef struct {
  147634. struct jpeg_c_main_controller pub; /* public fields */
  147635. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147636. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147637. boolean suspended; /* remember if we suspended output */
  147638. J_BUF_MODE pass_mode; /* current operating mode */
  147639. JSAMPARRAY buffer[MAX_COMPONENTS];
  147640. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147641. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147642. #endif
  147643. } my_main_controller;
  147644. typedef my_main_controller * my_main_ptr;
  147645. METHODDEF(void) process_data_simple_main
  147646. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147647. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147648. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147649. METHODDEF(void) process_data_buffer_main
  147650. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147651. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147652. #endif
  147653. METHODDEF(void)
  147654. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147655. {
  147656. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147657. if (cinfo->raw_data_in)
  147658. return;
  147659. main_->cur_iMCU_row = 0; /* initialize counters */
  147660. main_->rowgroup_ctr = 0;
  147661. main_->suspended = FALSE;
  147662. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147663. switch (pass_mode) {
  147664. case JBUF_PASS_THRU:
  147665. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147666. if (main_->whole_image[0] != NULL)
  147667. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147668. #endif
  147669. main_->pub.process_data = process_data_simple_main;
  147670. break;
  147671. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147672. case JBUF_SAVE_SOURCE:
  147673. case JBUF_CRANK_DEST:
  147674. case JBUF_SAVE_AND_PASS:
  147675. if (main_->whole_image[0] == NULL)
  147676. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147677. main_->pub.process_data = process_data_buffer_main;
  147678. break;
  147679. #endif
  147680. default:
  147681. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147682. break;
  147683. }
  147684. }
  147685. METHODDEF(void)
  147686. process_data_simple_main (j_compress_ptr cinfo,
  147687. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147688. JDIMENSION in_rows_avail)
  147689. {
  147690. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147691. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147692. if (main_->rowgroup_ctr < DCTSIZE)
  147693. (*cinfo->prep->pre_process_data) (cinfo,
  147694. input_buf, in_row_ctr, in_rows_avail,
  147695. main_->buffer, &main_->rowgroup_ctr,
  147696. (JDIMENSION) DCTSIZE);
  147697. if (main_->rowgroup_ctr != DCTSIZE)
  147698. return;
  147699. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147700. if (! main_->suspended) {
  147701. (*in_row_ctr)--;
  147702. main_->suspended = TRUE;
  147703. }
  147704. return;
  147705. }
  147706. if (main_->suspended) {
  147707. (*in_row_ctr)++;
  147708. main_->suspended = FALSE;
  147709. }
  147710. main_->rowgroup_ctr = 0;
  147711. main_->cur_iMCU_row++;
  147712. }
  147713. }
  147714. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147715. METHODDEF(void)
  147716. process_data_buffer_main (j_compress_ptr cinfo,
  147717. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147718. JDIMENSION in_rows_avail)
  147719. {
  147720. my_main_ptr main = (my_main_ptr) cinfo->main;
  147721. int ci;
  147722. jpeg_component_info *compptr;
  147723. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147724. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147725. if (main->rowgroup_ctr == 0) {
  147726. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147727. ci++, compptr++) {
  147728. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147729. ((j_common_ptr) cinfo, main->whole_image[ci],
  147730. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147731. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147732. }
  147733. if (! writing) {
  147734. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147735. main->rowgroup_ctr = DCTSIZE;
  147736. }
  147737. }
  147738. if (writing) {
  147739. (*cinfo->prep->pre_process_data) (cinfo,
  147740. input_buf, in_row_ctr, in_rows_avail,
  147741. main->buffer, &main->rowgroup_ctr,
  147742. (JDIMENSION) DCTSIZE);
  147743. if (main->rowgroup_ctr < DCTSIZE)
  147744. return;
  147745. }
  147746. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147747. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147748. if (! main->suspended) {
  147749. (*in_row_ctr)--;
  147750. main->suspended = TRUE;
  147751. }
  147752. return;
  147753. }
  147754. if (main->suspended) {
  147755. (*in_row_ctr)++;
  147756. main->suspended = FALSE;
  147757. }
  147758. }
  147759. main->rowgroup_ctr = 0;
  147760. main->cur_iMCU_row++;
  147761. }
  147762. }
  147763. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147764. GLOBAL(void)
  147765. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147766. {
  147767. my_main_ptr main_;
  147768. int ci;
  147769. jpeg_component_info *compptr;
  147770. main_ = (my_main_ptr)
  147771. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147772. SIZEOF(my_main_controller));
  147773. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147774. main_->pub.start_pass = start_pass_main;
  147775. if (cinfo->raw_data_in)
  147776. return;
  147777. if (need_full_buffer) {
  147778. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147779. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147780. ci++, compptr++) {
  147781. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147782. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147783. compptr->width_in_blocks * DCTSIZE,
  147784. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147785. (long) compptr->v_samp_factor) * DCTSIZE,
  147786. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147787. }
  147788. #else
  147789. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147790. #endif
  147791. } else {
  147792. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147793. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147794. #endif
  147795. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147796. ci++, compptr++) {
  147797. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147798. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147799. compptr->width_in_blocks * DCTSIZE,
  147800. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147801. }
  147802. }
  147803. }
  147804. /*** End of inlined file: jcmainct.c ***/
  147805. /*** Start of inlined file: jcmarker.c ***/
  147806. #define JPEG_INTERNALS
  147807. typedef struct {
  147808. struct jpeg_marker_writer pub; /* public fields */
  147809. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147810. } my_marker_writer;
  147811. typedef my_marker_writer * my_marker_ptr;
  147812. LOCAL(void)
  147813. emit_byte (j_compress_ptr cinfo, int val)
  147814. {
  147815. struct jpeg_destination_mgr * dest = cinfo->dest;
  147816. *(dest->next_output_byte)++ = (JOCTET) val;
  147817. if (--dest->free_in_buffer == 0) {
  147818. if (! (*dest->empty_output_buffer) (cinfo))
  147819. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147820. }
  147821. }
  147822. LOCAL(void)
  147823. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147824. {
  147825. emit_byte(cinfo, 0xFF);
  147826. emit_byte(cinfo, (int) mark);
  147827. }
  147828. LOCAL(void)
  147829. emit_2bytes (j_compress_ptr cinfo, int value)
  147830. {
  147831. emit_byte(cinfo, (value >> 8) & 0xFF);
  147832. emit_byte(cinfo, value & 0xFF);
  147833. }
  147834. LOCAL(int)
  147835. emit_dqt (j_compress_ptr cinfo, int index)
  147836. {
  147837. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147838. int prec;
  147839. int i;
  147840. if (qtbl == NULL)
  147841. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147842. prec = 0;
  147843. for (i = 0; i < DCTSIZE2; i++) {
  147844. if (qtbl->quantval[i] > 255)
  147845. prec = 1;
  147846. }
  147847. if (! qtbl->sent_table) {
  147848. emit_marker(cinfo, M_DQT);
  147849. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147850. emit_byte(cinfo, index + (prec<<4));
  147851. for (i = 0; i < DCTSIZE2; i++) {
  147852. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147853. if (prec)
  147854. emit_byte(cinfo, (int) (qval >> 8));
  147855. emit_byte(cinfo, (int) (qval & 0xFF));
  147856. }
  147857. qtbl->sent_table = TRUE;
  147858. }
  147859. return prec;
  147860. }
  147861. LOCAL(void)
  147862. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147863. {
  147864. JHUFF_TBL * htbl;
  147865. int length, i;
  147866. if (is_ac) {
  147867. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147868. index += 0x10; /* output index has AC bit set */
  147869. } else {
  147870. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147871. }
  147872. if (htbl == NULL)
  147873. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147874. if (! htbl->sent_table) {
  147875. emit_marker(cinfo, M_DHT);
  147876. length = 0;
  147877. for (i = 1; i <= 16; i++)
  147878. length += htbl->bits[i];
  147879. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147880. emit_byte(cinfo, index);
  147881. for (i = 1; i <= 16; i++)
  147882. emit_byte(cinfo, htbl->bits[i]);
  147883. for (i = 0; i < length; i++)
  147884. emit_byte(cinfo, htbl->huffval[i]);
  147885. htbl->sent_table = TRUE;
  147886. }
  147887. }
  147888. LOCAL(void)
  147889. emit_dac (j_compress_ptr cinfo)
  147890. {
  147891. #ifdef C_ARITH_CODING_SUPPORTED
  147892. char dc_in_use[NUM_ARITH_TBLS];
  147893. char ac_in_use[NUM_ARITH_TBLS];
  147894. int length, i;
  147895. jpeg_component_info *compptr;
  147896. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147897. dc_in_use[i] = ac_in_use[i] = 0;
  147898. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147899. compptr = cinfo->cur_comp_info[i];
  147900. dc_in_use[compptr->dc_tbl_no] = 1;
  147901. ac_in_use[compptr->ac_tbl_no] = 1;
  147902. }
  147903. length = 0;
  147904. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147905. length += dc_in_use[i] + ac_in_use[i];
  147906. emit_marker(cinfo, M_DAC);
  147907. emit_2bytes(cinfo, length*2 + 2);
  147908. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147909. if (dc_in_use[i]) {
  147910. emit_byte(cinfo, i);
  147911. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147912. }
  147913. if (ac_in_use[i]) {
  147914. emit_byte(cinfo, i + 0x10);
  147915. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147916. }
  147917. }
  147918. #endif /* C_ARITH_CODING_SUPPORTED */
  147919. }
  147920. LOCAL(void)
  147921. emit_dri (j_compress_ptr cinfo)
  147922. {
  147923. emit_marker(cinfo, M_DRI);
  147924. emit_2bytes(cinfo, 4); /* fixed length */
  147925. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147926. }
  147927. LOCAL(void)
  147928. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147929. {
  147930. int ci;
  147931. jpeg_component_info *compptr;
  147932. emit_marker(cinfo, code);
  147933. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147934. if ((long) cinfo->image_height > 65535L ||
  147935. (long) cinfo->image_width > 65535L)
  147936. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147937. emit_byte(cinfo, cinfo->data_precision);
  147938. emit_2bytes(cinfo, (int) cinfo->image_height);
  147939. emit_2bytes(cinfo, (int) cinfo->image_width);
  147940. emit_byte(cinfo, cinfo->num_components);
  147941. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147942. ci++, compptr++) {
  147943. emit_byte(cinfo, compptr->component_id);
  147944. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  147945. emit_byte(cinfo, compptr->quant_tbl_no);
  147946. }
  147947. }
  147948. LOCAL(void)
  147949. emit_sos (j_compress_ptr cinfo)
  147950. {
  147951. int i, td, ta;
  147952. jpeg_component_info *compptr;
  147953. emit_marker(cinfo, M_SOS);
  147954. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  147955. emit_byte(cinfo, cinfo->comps_in_scan);
  147956. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147957. compptr = cinfo->cur_comp_info[i];
  147958. emit_byte(cinfo, compptr->component_id);
  147959. td = compptr->dc_tbl_no;
  147960. ta = compptr->ac_tbl_no;
  147961. if (cinfo->progressive_mode) {
  147962. if (cinfo->Ss == 0) {
  147963. ta = 0; /* DC scan */
  147964. if (cinfo->Ah != 0 && !cinfo->arith_code)
  147965. td = 0; /* no DC table either */
  147966. } else {
  147967. td = 0; /* AC scan */
  147968. }
  147969. }
  147970. emit_byte(cinfo, (td << 4) + ta);
  147971. }
  147972. emit_byte(cinfo, cinfo->Ss);
  147973. emit_byte(cinfo, cinfo->Se);
  147974. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  147975. }
  147976. LOCAL(void)
  147977. emit_jfif_app0 (j_compress_ptr cinfo)
  147978. {
  147979. emit_marker(cinfo, M_APP0);
  147980. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  147981. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  147982. emit_byte(cinfo, 0x46);
  147983. emit_byte(cinfo, 0x49);
  147984. emit_byte(cinfo, 0x46);
  147985. emit_byte(cinfo, 0);
  147986. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  147987. emit_byte(cinfo, cinfo->JFIF_minor_version);
  147988. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  147989. emit_2bytes(cinfo, (int) cinfo->X_density);
  147990. emit_2bytes(cinfo, (int) cinfo->Y_density);
  147991. emit_byte(cinfo, 0); /* No thumbnail image */
  147992. emit_byte(cinfo, 0);
  147993. }
  147994. LOCAL(void)
  147995. emit_adobe_app14 (j_compress_ptr cinfo)
  147996. {
  147997. emit_marker(cinfo, M_APP14);
  147998. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  147999. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  148000. emit_byte(cinfo, 0x64);
  148001. emit_byte(cinfo, 0x6F);
  148002. emit_byte(cinfo, 0x62);
  148003. emit_byte(cinfo, 0x65);
  148004. emit_2bytes(cinfo, 100); /* Version */
  148005. emit_2bytes(cinfo, 0); /* Flags0 */
  148006. emit_2bytes(cinfo, 0); /* Flags1 */
  148007. switch (cinfo->jpeg_color_space) {
  148008. case JCS_YCbCr:
  148009. emit_byte(cinfo, 1); /* Color transform = 1 */
  148010. break;
  148011. case JCS_YCCK:
  148012. emit_byte(cinfo, 2); /* Color transform = 2 */
  148013. break;
  148014. default:
  148015. emit_byte(cinfo, 0); /* Color transform = 0 */
  148016. break;
  148017. }
  148018. }
  148019. METHODDEF(void)
  148020. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  148021. {
  148022. if (datalen > (unsigned int) 65533) /* safety check */
  148023. ERREXIT(cinfo, JERR_BAD_LENGTH);
  148024. emit_marker(cinfo, (JPEG_MARKER) marker);
  148025. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148026. }
  148027. METHODDEF(void)
  148028. write_marker_byte (j_compress_ptr cinfo, int val)
  148029. {
  148030. emit_byte(cinfo, val);
  148031. }
  148032. METHODDEF(void)
  148033. write_file_header (j_compress_ptr cinfo)
  148034. {
  148035. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148036. emit_marker(cinfo, M_SOI); /* first the SOI */
  148037. marker->last_restart_interval = 0;
  148038. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148039. emit_jfif_app0(cinfo);
  148040. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148041. emit_adobe_app14(cinfo);
  148042. }
  148043. METHODDEF(void)
  148044. write_frame_header (j_compress_ptr cinfo)
  148045. {
  148046. int ci, prec;
  148047. boolean is_baseline;
  148048. jpeg_component_info *compptr;
  148049. prec = 0;
  148050. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148051. ci++, compptr++) {
  148052. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148053. }
  148054. if (cinfo->arith_code || cinfo->progressive_mode ||
  148055. cinfo->data_precision != 8) {
  148056. is_baseline = FALSE;
  148057. } else {
  148058. is_baseline = TRUE;
  148059. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148060. ci++, compptr++) {
  148061. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148062. is_baseline = FALSE;
  148063. }
  148064. if (prec && is_baseline) {
  148065. is_baseline = FALSE;
  148066. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148067. }
  148068. }
  148069. if (cinfo->arith_code) {
  148070. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148071. } else {
  148072. if (cinfo->progressive_mode)
  148073. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148074. else if (is_baseline)
  148075. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148076. else
  148077. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148078. }
  148079. }
  148080. METHODDEF(void)
  148081. write_scan_header (j_compress_ptr cinfo)
  148082. {
  148083. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148084. int i;
  148085. jpeg_component_info *compptr;
  148086. if (cinfo->arith_code) {
  148087. emit_dac(cinfo);
  148088. } else {
  148089. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148090. compptr = cinfo->cur_comp_info[i];
  148091. if (cinfo->progressive_mode) {
  148092. if (cinfo->Ss == 0) {
  148093. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148094. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148095. } else {
  148096. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148097. }
  148098. } else {
  148099. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148100. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148101. }
  148102. }
  148103. }
  148104. if (cinfo->restart_interval != marker->last_restart_interval) {
  148105. emit_dri(cinfo);
  148106. marker->last_restart_interval = cinfo->restart_interval;
  148107. }
  148108. emit_sos(cinfo);
  148109. }
  148110. METHODDEF(void)
  148111. write_file_trailer (j_compress_ptr cinfo)
  148112. {
  148113. emit_marker(cinfo, M_EOI);
  148114. }
  148115. METHODDEF(void)
  148116. write_tables_only (j_compress_ptr cinfo)
  148117. {
  148118. int i;
  148119. emit_marker(cinfo, M_SOI);
  148120. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148121. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148122. (void) emit_dqt(cinfo, i);
  148123. }
  148124. if (! cinfo->arith_code) {
  148125. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148126. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148127. emit_dht(cinfo, i, FALSE);
  148128. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148129. emit_dht(cinfo, i, TRUE);
  148130. }
  148131. }
  148132. emit_marker(cinfo, M_EOI);
  148133. }
  148134. GLOBAL(void)
  148135. jinit_marker_writer (j_compress_ptr cinfo)
  148136. {
  148137. my_marker_ptr marker;
  148138. marker = (my_marker_ptr)
  148139. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148140. SIZEOF(my_marker_writer));
  148141. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148142. marker->pub.write_file_header = write_file_header;
  148143. marker->pub.write_frame_header = write_frame_header;
  148144. marker->pub.write_scan_header = write_scan_header;
  148145. marker->pub.write_file_trailer = write_file_trailer;
  148146. marker->pub.write_tables_only = write_tables_only;
  148147. marker->pub.write_marker_header = write_marker_header;
  148148. marker->pub.write_marker_byte = write_marker_byte;
  148149. marker->last_restart_interval = 0;
  148150. }
  148151. /*** End of inlined file: jcmarker.c ***/
  148152. /*** Start of inlined file: jcmaster.c ***/
  148153. #define JPEG_INTERNALS
  148154. typedef enum {
  148155. main_pass, /* input data, also do first output step */
  148156. huff_opt_pass, /* Huffman code optimization pass */
  148157. output_pass /* data output pass */
  148158. } c_pass_type;
  148159. typedef struct {
  148160. struct jpeg_comp_master pub; /* public fields */
  148161. c_pass_type pass_type; /* the type of the current pass */
  148162. int pass_number; /* # of passes completed */
  148163. int total_passes; /* total # of passes needed */
  148164. int scan_number; /* current index in scan_info[] */
  148165. } my_comp_master;
  148166. typedef my_comp_master * my_master_ptr;
  148167. LOCAL(void)
  148168. initial_setup (j_compress_ptr cinfo)
  148169. {
  148170. int ci;
  148171. jpeg_component_info *compptr;
  148172. long samplesperrow;
  148173. JDIMENSION jd_samplesperrow;
  148174. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148175. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148176. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148177. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148178. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148179. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148180. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148181. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148182. if ((long) jd_samplesperrow != samplesperrow)
  148183. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148184. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148185. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148186. if (cinfo->num_components > MAX_COMPONENTS)
  148187. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148188. MAX_COMPONENTS);
  148189. cinfo->max_h_samp_factor = 1;
  148190. cinfo->max_v_samp_factor = 1;
  148191. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148192. ci++, compptr++) {
  148193. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148194. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148195. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148196. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148197. compptr->h_samp_factor);
  148198. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148199. compptr->v_samp_factor);
  148200. }
  148201. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148202. ci++, compptr++) {
  148203. compptr->component_index = ci;
  148204. compptr->DCT_scaled_size = DCTSIZE;
  148205. compptr->width_in_blocks = (JDIMENSION)
  148206. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148207. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148208. compptr->height_in_blocks = (JDIMENSION)
  148209. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148210. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148211. compptr->downsampled_width = (JDIMENSION)
  148212. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148213. (long) cinfo->max_h_samp_factor);
  148214. compptr->downsampled_height = (JDIMENSION)
  148215. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148216. (long) cinfo->max_v_samp_factor);
  148217. compptr->component_needed = TRUE;
  148218. }
  148219. cinfo->total_iMCU_rows = (JDIMENSION)
  148220. jdiv_round_up((long) cinfo->image_height,
  148221. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148222. }
  148223. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148224. LOCAL(void)
  148225. validate_script (j_compress_ptr cinfo)
  148226. {
  148227. const jpeg_scan_info * scanptr;
  148228. int scanno, ncomps, ci, coefi, thisi;
  148229. int Ss, Se, Ah, Al;
  148230. boolean component_sent[MAX_COMPONENTS];
  148231. #ifdef C_PROGRESSIVE_SUPPORTED
  148232. int * last_bitpos_ptr;
  148233. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148234. #endif
  148235. if (cinfo->num_scans <= 0)
  148236. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148237. scanptr = cinfo->scan_info;
  148238. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148239. #ifdef C_PROGRESSIVE_SUPPORTED
  148240. cinfo->progressive_mode = TRUE;
  148241. last_bitpos_ptr = & last_bitpos[0][0];
  148242. for (ci = 0; ci < cinfo->num_components; ci++)
  148243. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148244. *last_bitpos_ptr++ = -1;
  148245. #else
  148246. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148247. #endif
  148248. } else {
  148249. cinfo->progressive_mode = FALSE;
  148250. for (ci = 0; ci < cinfo->num_components; ci++)
  148251. component_sent[ci] = FALSE;
  148252. }
  148253. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148254. ncomps = scanptr->comps_in_scan;
  148255. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148256. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148257. for (ci = 0; ci < ncomps; ci++) {
  148258. thisi = scanptr->component_index[ci];
  148259. if (thisi < 0 || thisi >= cinfo->num_components)
  148260. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148261. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148262. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148263. }
  148264. Ss = scanptr->Ss;
  148265. Se = scanptr->Se;
  148266. Ah = scanptr->Ah;
  148267. Al = scanptr->Al;
  148268. if (cinfo->progressive_mode) {
  148269. #ifdef C_PROGRESSIVE_SUPPORTED
  148270. #if BITS_IN_JSAMPLE == 8
  148271. #define MAX_AH_AL 10
  148272. #else
  148273. #define MAX_AH_AL 13
  148274. #endif
  148275. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148276. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148277. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148278. if (Ss == 0) {
  148279. if (Se != 0) /* DC and AC together not OK */
  148280. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148281. } else {
  148282. if (ncomps != 1) /* AC scans must be for only one component */
  148283. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148284. }
  148285. for (ci = 0; ci < ncomps; ci++) {
  148286. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148287. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148288. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148289. for (coefi = Ss; coefi <= Se; coefi++) {
  148290. if (last_bitpos_ptr[coefi] < 0) {
  148291. if (Ah != 0)
  148292. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148293. } else {
  148294. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148295. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148296. }
  148297. last_bitpos_ptr[coefi] = Al;
  148298. }
  148299. }
  148300. #endif
  148301. } else {
  148302. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148303. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148304. for (ci = 0; ci < ncomps; ci++) {
  148305. thisi = scanptr->component_index[ci];
  148306. if (component_sent[thisi])
  148307. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148308. component_sent[thisi] = TRUE;
  148309. }
  148310. }
  148311. }
  148312. if (cinfo->progressive_mode) {
  148313. #ifdef C_PROGRESSIVE_SUPPORTED
  148314. for (ci = 0; ci < cinfo->num_components; ci++) {
  148315. if (last_bitpos[ci][0] < 0)
  148316. ERREXIT(cinfo, JERR_MISSING_DATA);
  148317. }
  148318. #endif
  148319. } else {
  148320. for (ci = 0; ci < cinfo->num_components; ci++) {
  148321. if (! component_sent[ci])
  148322. ERREXIT(cinfo, JERR_MISSING_DATA);
  148323. }
  148324. }
  148325. }
  148326. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148327. LOCAL(void)
  148328. select_scan_parameters (j_compress_ptr cinfo)
  148329. {
  148330. int ci;
  148331. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148332. if (cinfo->scan_info != NULL) {
  148333. my_master_ptr master = (my_master_ptr) cinfo->master;
  148334. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148335. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148336. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148337. cinfo->cur_comp_info[ci] =
  148338. &cinfo->comp_info[scanptr->component_index[ci]];
  148339. }
  148340. cinfo->Ss = scanptr->Ss;
  148341. cinfo->Se = scanptr->Se;
  148342. cinfo->Ah = scanptr->Ah;
  148343. cinfo->Al = scanptr->Al;
  148344. }
  148345. else
  148346. #endif
  148347. {
  148348. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148349. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148350. MAX_COMPS_IN_SCAN);
  148351. cinfo->comps_in_scan = cinfo->num_components;
  148352. for (ci = 0; ci < cinfo->num_components; ci++) {
  148353. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148354. }
  148355. cinfo->Ss = 0;
  148356. cinfo->Se = DCTSIZE2-1;
  148357. cinfo->Ah = 0;
  148358. cinfo->Al = 0;
  148359. }
  148360. }
  148361. LOCAL(void)
  148362. per_scan_setup (j_compress_ptr cinfo)
  148363. {
  148364. int ci, mcublks, tmp;
  148365. jpeg_component_info *compptr;
  148366. if (cinfo->comps_in_scan == 1) {
  148367. compptr = cinfo->cur_comp_info[0];
  148368. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148369. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148370. compptr->MCU_width = 1;
  148371. compptr->MCU_height = 1;
  148372. compptr->MCU_blocks = 1;
  148373. compptr->MCU_sample_width = DCTSIZE;
  148374. compptr->last_col_width = 1;
  148375. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148376. if (tmp == 0) tmp = compptr->v_samp_factor;
  148377. compptr->last_row_height = tmp;
  148378. cinfo->blocks_in_MCU = 1;
  148379. cinfo->MCU_membership[0] = 0;
  148380. } else {
  148381. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148382. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148383. MAX_COMPS_IN_SCAN);
  148384. cinfo->MCUs_per_row = (JDIMENSION)
  148385. jdiv_round_up((long) cinfo->image_width,
  148386. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148387. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148388. jdiv_round_up((long) cinfo->image_height,
  148389. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148390. cinfo->blocks_in_MCU = 0;
  148391. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148392. compptr = cinfo->cur_comp_info[ci];
  148393. compptr->MCU_width = compptr->h_samp_factor;
  148394. compptr->MCU_height = compptr->v_samp_factor;
  148395. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148396. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148397. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148398. if (tmp == 0) tmp = compptr->MCU_width;
  148399. compptr->last_col_width = tmp;
  148400. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148401. if (tmp == 0) tmp = compptr->MCU_height;
  148402. compptr->last_row_height = tmp;
  148403. mcublks = compptr->MCU_blocks;
  148404. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148405. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148406. while (mcublks-- > 0) {
  148407. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148408. }
  148409. }
  148410. }
  148411. if (cinfo->restart_in_rows > 0) {
  148412. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148413. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148414. }
  148415. }
  148416. METHODDEF(void)
  148417. prepare_for_pass (j_compress_ptr cinfo)
  148418. {
  148419. my_master_ptr master = (my_master_ptr) cinfo->master;
  148420. switch (master->pass_type) {
  148421. case main_pass:
  148422. select_scan_parameters(cinfo);
  148423. per_scan_setup(cinfo);
  148424. if (! cinfo->raw_data_in) {
  148425. (*cinfo->cconvert->start_pass) (cinfo);
  148426. (*cinfo->downsample->start_pass) (cinfo);
  148427. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148428. }
  148429. (*cinfo->fdct->start_pass) (cinfo);
  148430. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148431. (*cinfo->coef->start_pass) (cinfo,
  148432. (master->total_passes > 1 ?
  148433. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148434. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148435. if (cinfo->optimize_coding) {
  148436. master->pub.call_pass_startup = FALSE;
  148437. } else {
  148438. master->pub.call_pass_startup = TRUE;
  148439. }
  148440. break;
  148441. #ifdef ENTROPY_OPT_SUPPORTED
  148442. case huff_opt_pass:
  148443. select_scan_parameters(cinfo);
  148444. per_scan_setup(cinfo);
  148445. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148446. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148447. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148448. master->pub.call_pass_startup = FALSE;
  148449. break;
  148450. }
  148451. master->pass_type = output_pass;
  148452. master->pass_number++;
  148453. #endif
  148454. case output_pass:
  148455. if (! cinfo->optimize_coding) {
  148456. select_scan_parameters(cinfo);
  148457. per_scan_setup(cinfo);
  148458. }
  148459. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148460. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148461. if (master->scan_number == 0)
  148462. (*cinfo->marker->write_frame_header) (cinfo);
  148463. (*cinfo->marker->write_scan_header) (cinfo);
  148464. master->pub.call_pass_startup = FALSE;
  148465. break;
  148466. default:
  148467. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148468. }
  148469. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148470. if (cinfo->progress != NULL) {
  148471. cinfo->progress->completed_passes = master->pass_number;
  148472. cinfo->progress->total_passes = master->total_passes;
  148473. }
  148474. }
  148475. METHODDEF(void)
  148476. pass_startup (j_compress_ptr cinfo)
  148477. {
  148478. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148479. (*cinfo->marker->write_frame_header) (cinfo);
  148480. (*cinfo->marker->write_scan_header) (cinfo);
  148481. }
  148482. METHODDEF(void)
  148483. finish_pass_master (j_compress_ptr cinfo)
  148484. {
  148485. my_master_ptr master = (my_master_ptr) cinfo->master;
  148486. (*cinfo->entropy->finish_pass) (cinfo);
  148487. switch (master->pass_type) {
  148488. case main_pass:
  148489. master->pass_type = output_pass;
  148490. if (! cinfo->optimize_coding)
  148491. master->scan_number++;
  148492. break;
  148493. case huff_opt_pass:
  148494. master->pass_type = output_pass;
  148495. break;
  148496. case output_pass:
  148497. if (cinfo->optimize_coding)
  148498. master->pass_type = huff_opt_pass;
  148499. master->scan_number++;
  148500. break;
  148501. }
  148502. master->pass_number++;
  148503. }
  148504. GLOBAL(void)
  148505. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148506. {
  148507. my_master_ptr master;
  148508. master = (my_master_ptr)
  148509. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148510. SIZEOF(my_comp_master));
  148511. cinfo->master = (struct jpeg_comp_master *) master;
  148512. master->pub.prepare_for_pass = prepare_for_pass;
  148513. master->pub.pass_startup = pass_startup;
  148514. master->pub.finish_pass = finish_pass_master;
  148515. master->pub.is_last_pass = FALSE;
  148516. initial_setup(cinfo);
  148517. if (cinfo->scan_info != NULL) {
  148518. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148519. validate_script(cinfo);
  148520. #else
  148521. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148522. #endif
  148523. } else {
  148524. cinfo->progressive_mode = FALSE;
  148525. cinfo->num_scans = 1;
  148526. }
  148527. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148528. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148529. if (transcode_only) {
  148530. if (cinfo->optimize_coding)
  148531. master->pass_type = huff_opt_pass;
  148532. else
  148533. master->pass_type = output_pass;
  148534. } else {
  148535. master->pass_type = main_pass;
  148536. }
  148537. master->scan_number = 0;
  148538. master->pass_number = 0;
  148539. if (cinfo->optimize_coding)
  148540. master->total_passes = cinfo->num_scans * 2;
  148541. else
  148542. master->total_passes = cinfo->num_scans;
  148543. }
  148544. /*** End of inlined file: jcmaster.c ***/
  148545. /*** Start of inlined file: jcomapi.c ***/
  148546. #define JPEG_INTERNALS
  148547. GLOBAL(void)
  148548. jpeg_abort (j_common_ptr cinfo)
  148549. {
  148550. int pool;
  148551. if (cinfo->mem == NULL)
  148552. return;
  148553. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148554. (*cinfo->mem->free_pool) (cinfo, pool);
  148555. }
  148556. if (cinfo->is_decompressor) {
  148557. cinfo->global_state = DSTATE_START;
  148558. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148559. } else {
  148560. cinfo->global_state = CSTATE_START;
  148561. }
  148562. }
  148563. GLOBAL(void)
  148564. jpeg_destroy (j_common_ptr cinfo)
  148565. {
  148566. if (cinfo->mem != NULL)
  148567. (*cinfo->mem->self_destruct) (cinfo);
  148568. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148569. cinfo->global_state = 0; /* mark it destroyed */
  148570. }
  148571. GLOBAL(JQUANT_TBL *)
  148572. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148573. {
  148574. JQUANT_TBL *tbl;
  148575. tbl = (JQUANT_TBL *)
  148576. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148577. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148578. return tbl;
  148579. }
  148580. GLOBAL(JHUFF_TBL *)
  148581. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148582. {
  148583. JHUFF_TBL *tbl;
  148584. tbl = (JHUFF_TBL *)
  148585. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148586. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148587. return tbl;
  148588. }
  148589. /*** End of inlined file: jcomapi.c ***/
  148590. /*** Start of inlined file: jcparam.c ***/
  148591. #define JPEG_INTERNALS
  148592. GLOBAL(void)
  148593. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148594. const unsigned int *basic_table,
  148595. int scale_factor, boolean force_baseline)
  148596. {
  148597. JQUANT_TBL ** qtblptr;
  148598. int i;
  148599. long temp;
  148600. if (cinfo->global_state != CSTATE_START)
  148601. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148602. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148603. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148604. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148605. if (*qtblptr == NULL)
  148606. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148607. for (i = 0; i < DCTSIZE2; i++) {
  148608. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148609. if (temp <= 0L) temp = 1L;
  148610. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148611. if (force_baseline && temp > 255L)
  148612. temp = 255L; /* limit to baseline range if requested */
  148613. (*qtblptr)->quantval[i] = (UINT16) temp;
  148614. }
  148615. (*qtblptr)->sent_table = FALSE;
  148616. }
  148617. GLOBAL(void)
  148618. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148619. boolean force_baseline)
  148620. {
  148621. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148622. 16, 11, 10, 16, 24, 40, 51, 61,
  148623. 12, 12, 14, 19, 26, 58, 60, 55,
  148624. 14, 13, 16, 24, 40, 57, 69, 56,
  148625. 14, 17, 22, 29, 51, 87, 80, 62,
  148626. 18, 22, 37, 56, 68, 109, 103, 77,
  148627. 24, 35, 55, 64, 81, 104, 113, 92,
  148628. 49, 64, 78, 87, 103, 121, 120, 101,
  148629. 72, 92, 95, 98, 112, 100, 103, 99
  148630. };
  148631. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148632. 17, 18, 24, 47, 99, 99, 99, 99,
  148633. 18, 21, 26, 66, 99, 99, 99, 99,
  148634. 24, 26, 56, 99, 99, 99, 99, 99,
  148635. 47, 66, 99, 99, 99, 99, 99, 99,
  148636. 99, 99, 99, 99, 99, 99, 99, 99,
  148637. 99, 99, 99, 99, 99, 99, 99, 99,
  148638. 99, 99, 99, 99, 99, 99, 99, 99,
  148639. 99, 99, 99, 99, 99, 99, 99, 99
  148640. };
  148641. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148642. scale_factor, force_baseline);
  148643. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148644. scale_factor, force_baseline);
  148645. }
  148646. GLOBAL(int)
  148647. jpeg_quality_scaling (int quality)
  148648. {
  148649. if (quality <= 0) quality = 1;
  148650. if (quality > 100) quality = 100;
  148651. if (quality < 50)
  148652. quality = 5000 / quality;
  148653. else
  148654. quality = 200 - quality*2;
  148655. return quality;
  148656. }
  148657. GLOBAL(void)
  148658. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148659. {
  148660. quality = jpeg_quality_scaling(quality);
  148661. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148662. }
  148663. LOCAL(void)
  148664. add_huff_table (j_compress_ptr cinfo,
  148665. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148666. {
  148667. int nsymbols, len;
  148668. if (*htblptr == NULL)
  148669. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148670. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148671. nsymbols = 0;
  148672. for (len = 1; len <= 16; len++)
  148673. nsymbols += bits[len];
  148674. if (nsymbols < 1 || nsymbols > 256)
  148675. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148676. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148677. (*htblptr)->sent_table = FALSE;
  148678. }
  148679. LOCAL(void)
  148680. std_huff_tables (j_compress_ptr cinfo)
  148681. {
  148682. static const UINT8 bits_dc_luminance[17] =
  148683. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148684. static const UINT8 val_dc_luminance[] =
  148685. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148686. static const UINT8 bits_dc_chrominance[17] =
  148687. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148688. static const UINT8 val_dc_chrominance[] =
  148689. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148690. static const UINT8 bits_ac_luminance[17] =
  148691. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148692. static const UINT8 val_ac_luminance[] =
  148693. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148694. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148695. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148696. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148697. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148698. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148699. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148700. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148701. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148702. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148703. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148704. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148705. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148706. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148707. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148708. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148709. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148710. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148711. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148712. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148713. 0xf9, 0xfa };
  148714. static const UINT8 bits_ac_chrominance[17] =
  148715. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148716. static const UINT8 val_ac_chrominance[] =
  148717. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148718. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148719. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148720. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148721. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148722. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148723. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148724. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148725. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148726. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148727. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148728. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148729. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148730. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148731. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148732. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148733. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148734. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148735. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148736. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148737. 0xf9, 0xfa };
  148738. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148739. bits_dc_luminance, val_dc_luminance);
  148740. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148741. bits_ac_luminance, val_ac_luminance);
  148742. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148743. bits_dc_chrominance, val_dc_chrominance);
  148744. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148745. bits_ac_chrominance, val_ac_chrominance);
  148746. }
  148747. GLOBAL(void)
  148748. jpeg_set_defaults (j_compress_ptr cinfo)
  148749. {
  148750. int i;
  148751. if (cinfo->global_state != CSTATE_START)
  148752. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148753. if (cinfo->comp_info == NULL)
  148754. cinfo->comp_info = (jpeg_component_info *)
  148755. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148756. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148757. cinfo->data_precision = BITS_IN_JSAMPLE;
  148758. jpeg_set_quality(cinfo, 75, TRUE);
  148759. std_huff_tables(cinfo);
  148760. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148761. cinfo->arith_dc_L[i] = 0;
  148762. cinfo->arith_dc_U[i] = 1;
  148763. cinfo->arith_ac_K[i] = 5;
  148764. }
  148765. cinfo->scan_info = NULL;
  148766. cinfo->num_scans = 0;
  148767. cinfo->raw_data_in = FALSE;
  148768. cinfo->arith_code = FALSE;
  148769. cinfo->optimize_coding = FALSE;
  148770. if (cinfo->data_precision > 8)
  148771. cinfo->optimize_coding = TRUE;
  148772. cinfo->CCIR601_sampling = FALSE;
  148773. cinfo->smoothing_factor = 0;
  148774. cinfo->dct_method = JDCT_DEFAULT;
  148775. cinfo->restart_interval = 0;
  148776. cinfo->restart_in_rows = 0;
  148777. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148778. cinfo->JFIF_minor_version = 1;
  148779. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148780. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148781. cinfo->Y_density = 1;
  148782. jpeg_default_colorspace(cinfo);
  148783. }
  148784. GLOBAL(void)
  148785. jpeg_default_colorspace (j_compress_ptr cinfo)
  148786. {
  148787. switch (cinfo->in_color_space) {
  148788. case JCS_GRAYSCALE:
  148789. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148790. break;
  148791. case JCS_RGB:
  148792. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148793. break;
  148794. case JCS_YCbCr:
  148795. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148796. break;
  148797. case JCS_CMYK:
  148798. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148799. break;
  148800. case JCS_YCCK:
  148801. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148802. break;
  148803. case JCS_UNKNOWN:
  148804. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148805. break;
  148806. default:
  148807. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148808. }
  148809. }
  148810. GLOBAL(void)
  148811. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148812. {
  148813. jpeg_component_info * compptr;
  148814. int ci;
  148815. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148816. (compptr = &cinfo->comp_info[index], \
  148817. compptr->component_id = (id), \
  148818. compptr->h_samp_factor = (hsamp), \
  148819. compptr->v_samp_factor = (vsamp), \
  148820. compptr->quant_tbl_no = (quant), \
  148821. compptr->dc_tbl_no = (dctbl), \
  148822. compptr->ac_tbl_no = (actbl) )
  148823. if (cinfo->global_state != CSTATE_START)
  148824. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148825. cinfo->jpeg_color_space = colorspace;
  148826. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148827. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148828. switch (colorspace) {
  148829. case JCS_GRAYSCALE:
  148830. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148831. cinfo->num_components = 1;
  148832. SET_COMP(0, 1, 1,1, 0, 0,0);
  148833. break;
  148834. case JCS_RGB:
  148835. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148836. cinfo->num_components = 3;
  148837. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148838. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148839. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148840. break;
  148841. case JCS_YCbCr:
  148842. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148843. cinfo->num_components = 3;
  148844. SET_COMP(0, 1, 2,2, 0, 0,0);
  148845. SET_COMP(1, 2, 1,1, 1, 1,1);
  148846. SET_COMP(2, 3, 1,1, 1, 1,1);
  148847. break;
  148848. case JCS_CMYK:
  148849. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148850. cinfo->num_components = 4;
  148851. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148852. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148853. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148854. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148855. break;
  148856. case JCS_YCCK:
  148857. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148858. cinfo->num_components = 4;
  148859. SET_COMP(0, 1, 2,2, 0, 0,0);
  148860. SET_COMP(1, 2, 1,1, 1, 1,1);
  148861. SET_COMP(2, 3, 1,1, 1, 1,1);
  148862. SET_COMP(3, 4, 2,2, 0, 0,0);
  148863. break;
  148864. case JCS_UNKNOWN:
  148865. cinfo->num_components = cinfo->input_components;
  148866. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148867. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148868. MAX_COMPONENTS);
  148869. for (ci = 0; ci < cinfo->num_components; ci++) {
  148870. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148871. }
  148872. break;
  148873. default:
  148874. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148875. }
  148876. }
  148877. #ifdef C_PROGRESSIVE_SUPPORTED
  148878. LOCAL(jpeg_scan_info *)
  148879. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148880. int Ss, int Se, int Ah, int Al)
  148881. {
  148882. scanptr->comps_in_scan = 1;
  148883. scanptr->component_index[0] = ci;
  148884. scanptr->Ss = Ss;
  148885. scanptr->Se = Se;
  148886. scanptr->Ah = Ah;
  148887. scanptr->Al = Al;
  148888. scanptr++;
  148889. return scanptr;
  148890. }
  148891. LOCAL(jpeg_scan_info *)
  148892. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148893. int Ss, int Se, int Ah, int Al)
  148894. {
  148895. int ci;
  148896. for (ci = 0; ci < ncomps; ci++) {
  148897. scanptr->comps_in_scan = 1;
  148898. scanptr->component_index[0] = ci;
  148899. scanptr->Ss = Ss;
  148900. scanptr->Se = Se;
  148901. scanptr->Ah = Ah;
  148902. scanptr->Al = Al;
  148903. scanptr++;
  148904. }
  148905. return scanptr;
  148906. }
  148907. LOCAL(jpeg_scan_info *)
  148908. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148909. {
  148910. int ci;
  148911. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148912. scanptr->comps_in_scan = ncomps;
  148913. for (ci = 0; ci < ncomps; ci++)
  148914. scanptr->component_index[ci] = ci;
  148915. scanptr->Ss = scanptr->Se = 0;
  148916. scanptr->Ah = Ah;
  148917. scanptr->Al = Al;
  148918. scanptr++;
  148919. } else {
  148920. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148921. }
  148922. return scanptr;
  148923. }
  148924. GLOBAL(void)
  148925. jpeg_simple_progression (j_compress_ptr cinfo)
  148926. {
  148927. int ncomps = cinfo->num_components;
  148928. int nscans;
  148929. jpeg_scan_info * scanptr;
  148930. if (cinfo->global_state != CSTATE_START)
  148931. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148932. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148933. nscans = 10;
  148934. } else {
  148935. if (ncomps > MAX_COMPS_IN_SCAN)
  148936. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148937. else
  148938. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  148939. }
  148940. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  148941. cinfo->script_space_size = MAX(nscans, 10);
  148942. cinfo->script_space = (jpeg_scan_info *)
  148943. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148944. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  148945. }
  148946. scanptr = cinfo->script_space;
  148947. cinfo->scan_info = scanptr;
  148948. cinfo->num_scans = nscans;
  148949. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148950. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148951. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  148952. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  148953. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  148954. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  148955. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  148956. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148957. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  148958. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  148959. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  148960. } else {
  148961. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148962. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  148963. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  148964. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  148965. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148966. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  148967. }
  148968. }
  148969. #endif /* C_PROGRESSIVE_SUPPORTED */
  148970. /*** End of inlined file: jcparam.c ***/
  148971. /*** Start of inlined file: jcphuff.c ***/
  148972. #define JPEG_INTERNALS
  148973. #ifdef C_PROGRESSIVE_SUPPORTED
  148974. typedef struct {
  148975. struct jpeg_entropy_encoder pub; /* public fields */
  148976. boolean gather_statistics;
  148977. JOCTET * next_output_byte; /* => next byte to write in buffer */
  148978. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  148979. INT32 put_buffer; /* current bit-accumulation buffer */
  148980. int put_bits; /* # of bits now in it */
  148981. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  148982. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  148983. int ac_tbl_no; /* the table number of the single component */
  148984. unsigned int EOBRUN; /* run length of EOBs */
  148985. unsigned int BE; /* # of buffered correction bits before MCU */
  148986. char * bit_buffer; /* buffer for correction bits (1 per char) */
  148987. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  148988. int next_restart_num; /* next restart number to write (0-7) */
  148989. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  148990. long * count_ptrs[NUM_HUFF_TBLS];
  148991. } phuff_entropy_encoder;
  148992. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  148993. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  148994. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  148995. #define ISHIFT_TEMPS int ishift_temp;
  148996. #define IRIGHT_SHIFT(x,shft) \
  148997. ((ishift_temp = (x)) < 0 ? \
  148998. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  148999. (ishift_temp >> (shft)))
  149000. #else
  149001. #define ISHIFT_TEMPS
  149002. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  149003. #endif
  149004. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  149005. JBLOCKROW *MCU_data));
  149006. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  149007. JBLOCKROW *MCU_data));
  149008. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  149009. JBLOCKROW *MCU_data));
  149010. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  149011. JBLOCKROW *MCU_data));
  149012. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  149013. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  149014. METHODDEF(void)
  149015. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  149016. {
  149017. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149018. boolean is_DC_band;
  149019. int ci, tbl;
  149020. jpeg_component_info * compptr;
  149021. entropy->cinfo = cinfo;
  149022. entropy->gather_statistics = gather_statistics;
  149023. is_DC_band = (cinfo->Ss == 0);
  149024. if (cinfo->Ah == 0) {
  149025. if (is_DC_band)
  149026. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149027. else
  149028. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149029. } else {
  149030. if (is_DC_band)
  149031. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149032. else {
  149033. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149034. if (entropy->bit_buffer == NULL)
  149035. entropy->bit_buffer = (char *)
  149036. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149037. MAX_CORR_BITS * SIZEOF(char));
  149038. }
  149039. }
  149040. if (gather_statistics)
  149041. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149042. else
  149043. entropy->pub.finish_pass = finish_pass_phuff;
  149044. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149045. compptr = cinfo->cur_comp_info[ci];
  149046. entropy->last_dc_val[ci] = 0;
  149047. if (is_DC_band) {
  149048. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149049. continue;
  149050. tbl = compptr->dc_tbl_no;
  149051. } else {
  149052. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149053. }
  149054. if (gather_statistics) {
  149055. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149056. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149057. if (entropy->count_ptrs[tbl] == NULL)
  149058. entropy->count_ptrs[tbl] = (long *)
  149059. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149060. 257 * SIZEOF(long));
  149061. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149062. } else {
  149063. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149064. & entropy->derived_tbls[tbl]);
  149065. }
  149066. }
  149067. entropy->EOBRUN = 0;
  149068. entropy->BE = 0;
  149069. entropy->put_buffer = 0;
  149070. entropy->put_bits = 0;
  149071. entropy->restarts_to_go = cinfo->restart_interval;
  149072. entropy->next_restart_num = 0;
  149073. }
  149074. #define emit_byte(entropy,val) \
  149075. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149076. if (--(entropy)->free_in_buffer == 0) \
  149077. dump_buffer_p(entropy); }
  149078. LOCAL(void)
  149079. dump_buffer_p (phuff_entropy_ptr entropy)
  149080. {
  149081. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149082. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149083. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149084. entropy->next_output_byte = dest->next_output_byte;
  149085. entropy->free_in_buffer = dest->free_in_buffer;
  149086. }
  149087. INLINE
  149088. LOCAL(void)
  149089. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149090. {
  149091. register INT32 put_buffer = (INT32) code;
  149092. register int put_bits = entropy->put_bits;
  149093. if (size == 0)
  149094. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149095. if (entropy->gather_statistics)
  149096. return; /* do nothing if we're only getting stats */
  149097. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149098. put_bits += size; /* new number of bits in buffer */
  149099. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149100. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149101. while (put_bits >= 8) {
  149102. int c = (int) ((put_buffer >> 16) & 0xFF);
  149103. emit_byte(entropy, c);
  149104. if (c == 0xFF) { /* need to stuff a zero byte? */
  149105. emit_byte(entropy, 0);
  149106. }
  149107. put_buffer <<= 8;
  149108. put_bits -= 8;
  149109. }
  149110. entropy->put_buffer = put_buffer; /* update variables */
  149111. entropy->put_bits = put_bits;
  149112. }
  149113. LOCAL(void)
  149114. flush_bits_p (phuff_entropy_ptr entropy)
  149115. {
  149116. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149117. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149118. entropy->put_bits = 0;
  149119. }
  149120. INLINE
  149121. LOCAL(void)
  149122. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149123. {
  149124. if (entropy->gather_statistics)
  149125. entropy->count_ptrs[tbl_no][symbol]++;
  149126. else {
  149127. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149128. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149129. }
  149130. }
  149131. LOCAL(void)
  149132. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149133. unsigned int nbits)
  149134. {
  149135. if (entropy->gather_statistics)
  149136. return; /* no real work */
  149137. while (nbits > 0) {
  149138. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149139. bufstart++;
  149140. nbits--;
  149141. }
  149142. }
  149143. LOCAL(void)
  149144. emit_eobrun (phuff_entropy_ptr entropy)
  149145. {
  149146. register int temp, nbits;
  149147. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149148. temp = entropy->EOBRUN;
  149149. nbits = 0;
  149150. while ((temp >>= 1))
  149151. nbits++;
  149152. if (nbits > 14)
  149153. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149154. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149155. if (nbits)
  149156. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149157. entropy->EOBRUN = 0;
  149158. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149159. entropy->BE = 0;
  149160. }
  149161. }
  149162. LOCAL(void)
  149163. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149164. {
  149165. int ci;
  149166. emit_eobrun(entropy);
  149167. if (! entropy->gather_statistics) {
  149168. flush_bits_p(entropy);
  149169. emit_byte(entropy, 0xFF);
  149170. emit_byte(entropy, JPEG_RST0 + restart_num);
  149171. }
  149172. if (entropy->cinfo->Ss == 0) {
  149173. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149174. entropy->last_dc_val[ci] = 0;
  149175. } else {
  149176. entropy->EOBRUN = 0;
  149177. entropy->BE = 0;
  149178. }
  149179. }
  149180. METHODDEF(boolean)
  149181. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149182. {
  149183. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149184. register int temp, temp2;
  149185. register int nbits;
  149186. int blkn, ci;
  149187. int Al = cinfo->Al;
  149188. JBLOCKROW block;
  149189. jpeg_component_info * compptr;
  149190. ISHIFT_TEMPS
  149191. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149192. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149193. if (cinfo->restart_interval)
  149194. if (entropy->restarts_to_go == 0)
  149195. emit_restart_p(entropy, entropy->next_restart_num);
  149196. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149197. block = MCU_data[blkn];
  149198. ci = cinfo->MCU_membership[blkn];
  149199. compptr = cinfo->cur_comp_info[ci];
  149200. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149201. temp = temp2 - entropy->last_dc_val[ci];
  149202. entropy->last_dc_val[ci] = temp2;
  149203. temp2 = temp;
  149204. if (temp < 0) {
  149205. temp = -temp; /* temp is abs value of input */
  149206. temp2--;
  149207. }
  149208. nbits = 0;
  149209. while (temp) {
  149210. nbits++;
  149211. temp >>= 1;
  149212. }
  149213. if (nbits > MAX_COEF_BITS+1)
  149214. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149215. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149216. if (nbits) /* emit_bits rejects calls with size 0 */
  149217. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149218. }
  149219. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149220. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149221. if (cinfo->restart_interval) {
  149222. if (entropy->restarts_to_go == 0) {
  149223. entropy->restarts_to_go = cinfo->restart_interval;
  149224. entropy->next_restart_num++;
  149225. entropy->next_restart_num &= 7;
  149226. }
  149227. entropy->restarts_to_go--;
  149228. }
  149229. return TRUE;
  149230. }
  149231. METHODDEF(boolean)
  149232. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149233. {
  149234. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149235. register int temp, temp2;
  149236. register int nbits;
  149237. register int r, k;
  149238. int Se = cinfo->Se;
  149239. int Al = cinfo->Al;
  149240. JBLOCKROW block;
  149241. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149242. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149243. if (cinfo->restart_interval)
  149244. if (entropy->restarts_to_go == 0)
  149245. emit_restart_p(entropy, entropy->next_restart_num);
  149246. block = MCU_data[0];
  149247. r = 0; /* r = run length of zeros */
  149248. for (k = cinfo->Ss; k <= Se; k++) {
  149249. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149250. r++;
  149251. continue;
  149252. }
  149253. if (temp < 0) {
  149254. temp = -temp; /* temp is abs value of input */
  149255. temp >>= Al; /* apply the point transform */
  149256. temp2 = ~temp;
  149257. } else {
  149258. temp >>= Al; /* apply the point transform */
  149259. temp2 = temp;
  149260. }
  149261. if (temp == 0) {
  149262. r++;
  149263. continue;
  149264. }
  149265. if (entropy->EOBRUN > 0)
  149266. emit_eobrun(entropy);
  149267. while (r > 15) {
  149268. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149269. r -= 16;
  149270. }
  149271. nbits = 1; /* there must be at least one 1 bit */
  149272. while ((temp >>= 1))
  149273. nbits++;
  149274. if (nbits > MAX_COEF_BITS)
  149275. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149276. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149277. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149278. r = 0; /* reset zero run length */
  149279. }
  149280. if (r > 0) { /* If there are trailing zeroes, */
  149281. entropy->EOBRUN++; /* count an EOB */
  149282. if (entropy->EOBRUN == 0x7FFF)
  149283. emit_eobrun(entropy); /* force it out to avoid overflow */
  149284. }
  149285. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149286. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149287. if (cinfo->restart_interval) {
  149288. if (entropy->restarts_to_go == 0) {
  149289. entropy->restarts_to_go = cinfo->restart_interval;
  149290. entropy->next_restart_num++;
  149291. entropy->next_restart_num &= 7;
  149292. }
  149293. entropy->restarts_to_go--;
  149294. }
  149295. return TRUE;
  149296. }
  149297. METHODDEF(boolean)
  149298. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149299. {
  149300. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149301. register int temp;
  149302. int blkn;
  149303. int Al = cinfo->Al;
  149304. JBLOCKROW block;
  149305. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149306. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149307. if (cinfo->restart_interval)
  149308. if (entropy->restarts_to_go == 0)
  149309. emit_restart_p(entropy, entropy->next_restart_num);
  149310. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149311. block = MCU_data[blkn];
  149312. temp = (*block)[0];
  149313. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149314. }
  149315. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149316. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149317. if (cinfo->restart_interval) {
  149318. if (entropy->restarts_to_go == 0) {
  149319. entropy->restarts_to_go = cinfo->restart_interval;
  149320. entropy->next_restart_num++;
  149321. entropy->next_restart_num &= 7;
  149322. }
  149323. entropy->restarts_to_go--;
  149324. }
  149325. return TRUE;
  149326. }
  149327. METHODDEF(boolean)
  149328. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149329. {
  149330. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149331. register int temp;
  149332. register int r, k;
  149333. int EOB;
  149334. char *BR_buffer;
  149335. unsigned int BR;
  149336. int Se = cinfo->Se;
  149337. int Al = cinfo->Al;
  149338. JBLOCKROW block;
  149339. int absvalues[DCTSIZE2];
  149340. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149341. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149342. if (cinfo->restart_interval)
  149343. if (entropy->restarts_to_go == 0)
  149344. emit_restart_p(entropy, entropy->next_restart_num);
  149345. block = MCU_data[0];
  149346. EOB = 0;
  149347. for (k = cinfo->Ss; k <= Se; k++) {
  149348. temp = (*block)[jpeg_natural_order[k]];
  149349. if (temp < 0)
  149350. temp = -temp; /* temp is abs value of input */
  149351. temp >>= Al; /* apply the point transform */
  149352. absvalues[k] = temp; /* save abs value for main pass */
  149353. if (temp == 1)
  149354. EOB = k; /* EOB = index of last newly-nonzero coef */
  149355. }
  149356. r = 0; /* r = run length of zeros */
  149357. BR = 0; /* BR = count of buffered bits added now */
  149358. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149359. for (k = cinfo->Ss; k <= Se; k++) {
  149360. if ((temp = absvalues[k]) == 0) {
  149361. r++;
  149362. continue;
  149363. }
  149364. while (r > 15 && k <= EOB) {
  149365. emit_eobrun(entropy);
  149366. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149367. r -= 16;
  149368. emit_buffered_bits(entropy, BR_buffer, BR);
  149369. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149370. BR = 0;
  149371. }
  149372. if (temp > 1) {
  149373. BR_buffer[BR++] = (char) (temp & 1);
  149374. continue;
  149375. }
  149376. emit_eobrun(entropy);
  149377. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149378. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149379. emit_bits_p(entropy, (unsigned int) temp, 1);
  149380. emit_buffered_bits(entropy, BR_buffer, BR);
  149381. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149382. BR = 0;
  149383. r = 0; /* reset zero run length */
  149384. }
  149385. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149386. entropy->EOBRUN++; /* count an EOB */
  149387. entropy->BE += BR; /* concat my correction bits to older ones */
  149388. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149389. emit_eobrun(entropy);
  149390. }
  149391. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149392. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149393. if (cinfo->restart_interval) {
  149394. if (entropy->restarts_to_go == 0) {
  149395. entropy->restarts_to_go = cinfo->restart_interval;
  149396. entropy->next_restart_num++;
  149397. entropy->next_restart_num &= 7;
  149398. }
  149399. entropy->restarts_to_go--;
  149400. }
  149401. return TRUE;
  149402. }
  149403. METHODDEF(void)
  149404. finish_pass_phuff (j_compress_ptr cinfo)
  149405. {
  149406. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149407. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149408. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149409. emit_eobrun(entropy);
  149410. flush_bits_p(entropy);
  149411. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149412. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149413. }
  149414. METHODDEF(void)
  149415. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149416. {
  149417. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149418. boolean is_DC_band;
  149419. int ci, tbl;
  149420. jpeg_component_info * compptr;
  149421. JHUFF_TBL **htblptr;
  149422. boolean did[NUM_HUFF_TBLS];
  149423. emit_eobrun(entropy);
  149424. is_DC_band = (cinfo->Ss == 0);
  149425. MEMZERO(did, SIZEOF(did));
  149426. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149427. compptr = cinfo->cur_comp_info[ci];
  149428. if (is_DC_band) {
  149429. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149430. continue;
  149431. tbl = compptr->dc_tbl_no;
  149432. } else {
  149433. tbl = compptr->ac_tbl_no;
  149434. }
  149435. if (! did[tbl]) {
  149436. if (is_DC_band)
  149437. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149438. else
  149439. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149440. if (*htblptr == NULL)
  149441. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149442. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149443. did[tbl] = TRUE;
  149444. }
  149445. }
  149446. }
  149447. GLOBAL(void)
  149448. jinit_phuff_encoder (j_compress_ptr cinfo)
  149449. {
  149450. phuff_entropy_ptr entropy;
  149451. int i;
  149452. entropy = (phuff_entropy_ptr)
  149453. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149454. SIZEOF(phuff_entropy_encoder));
  149455. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149456. entropy->pub.start_pass = start_pass_phuff;
  149457. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149458. entropy->derived_tbls[i] = NULL;
  149459. entropy->count_ptrs[i] = NULL;
  149460. }
  149461. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149462. }
  149463. #endif /* C_PROGRESSIVE_SUPPORTED */
  149464. /*** End of inlined file: jcphuff.c ***/
  149465. /*** Start of inlined file: jcprepct.c ***/
  149466. #define JPEG_INTERNALS
  149467. #ifdef INPUT_SMOOTHING_SUPPORTED
  149468. #define CONTEXT_ROWS_SUPPORTED
  149469. #endif
  149470. typedef struct {
  149471. struct jpeg_c_prep_controller pub; /* public fields */
  149472. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149473. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149474. int next_buf_row; /* index of next row to store in color_buf */
  149475. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149476. int this_row_group; /* starting row index of group to process */
  149477. int next_buf_stop; /* downsample when we reach this index */
  149478. #endif
  149479. } my_prep_controller;
  149480. typedef my_prep_controller * my_prep_ptr;
  149481. METHODDEF(void)
  149482. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149483. {
  149484. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149485. if (pass_mode != JBUF_PASS_THRU)
  149486. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149487. prep->rows_to_go = cinfo->image_height;
  149488. prep->next_buf_row = 0;
  149489. #ifdef CONTEXT_ROWS_SUPPORTED
  149490. prep->this_row_group = 0;
  149491. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149492. #endif
  149493. }
  149494. LOCAL(void)
  149495. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149496. int input_rows, int output_rows)
  149497. {
  149498. register int row;
  149499. for (row = input_rows; row < output_rows; row++) {
  149500. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149501. 1, num_cols);
  149502. }
  149503. }
  149504. METHODDEF(void)
  149505. pre_process_data (j_compress_ptr cinfo,
  149506. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149507. JDIMENSION in_rows_avail,
  149508. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149509. JDIMENSION out_row_groups_avail)
  149510. {
  149511. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149512. int numrows, ci;
  149513. JDIMENSION inrows;
  149514. jpeg_component_info * compptr;
  149515. while (*in_row_ctr < in_rows_avail &&
  149516. *out_row_group_ctr < out_row_groups_avail) {
  149517. inrows = in_rows_avail - *in_row_ctr;
  149518. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149519. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149520. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149521. prep->color_buf,
  149522. (JDIMENSION) prep->next_buf_row,
  149523. numrows);
  149524. *in_row_ctr += numrows;
  149525. prep->next_buf_row += numrows;
  149526. prep->rows_to_go -= numrows;
  149527. if (prep->rows_to_go == 0 &&
  149528. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149529. for (ci = 0; ci < cinfo->num_components; ci++) {
  149530. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149531. prep->next_buf_row, cinfo->max_v_samp_factor);
  149532. }
  149533. prep->next_buf_row = cinfo->max_v_samp_factor;
  149534. }
  149535. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149536. (*cinfo->downsample->downsample) (cinfo,
  149537. prep->color_buf, (JDIMENSION) 0,
  149538. output_buf, *out_row_group_ctr);
  149539. prep->next_buf_row = 0;
  149540. (*out_row_group_ctr)++;
  149541. }
  149542. if (prep->rows_to_go == 0 &&
  149543. *out_row_group_ctr < out_row_groups_avail) {
  149544. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149545. ci++, compptr++) {
  149546. expand_bottom_edge(output_buf[ci],
  149547. compptr->width_in_blocks * DCTSIZE,
  149548. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149549. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149550. }
  149551. *out_row_group_ctr = out_row_groups_avail;
  149552. break; /* can exit outer loop without test */
  149553. }
  149554. }
  149555. }
  149556. #ifdef CONTEXT_ROWS_SUPPORTED
  149557. METHODDEF(void)
  149558. pre_process_context (j_compress_ptr cinfo,
  149559. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149560. JDIMENSION in_rows_avail,
  149561. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149562. JDIMENSION out_row_groups_avail)
  149563. {
  149564. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149565. int numrows, ci;
  149566. int buf_height = cinfo->max_v_samp_factor * 3;
  149567. JDIMENSION inrows;
  149568. while (*out_row_group_ctr < out_row_groups_avail) {
  149569. if (*in_row_ctr < in_rows_avail) {
  149570. inrows = in_rows_avail - *in_row_ctr;
  149571. numrows = prep->next_buf_stop - prep->next_buf_row;
  149572. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149573. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149574. prep->color_buf,
  149575. (JDIMENSION) prep->next_buf_row,
  149576. numrows);
  149577. if (prep->rows_to_go == cinfo->image_height) {
  149578. for (ci = 0; ci < cinfo->num_components; ci++) {
  149579. int row;
  149580. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149581. jcopy_sample_rows(prep->color_buf[ci], 0,
  149582. prep->color_buf[ci], -row,
  149583. 1, cinfo->image_width);
  149584. }
  149585. }
  149586. }
  149587. *in_row_ctr += numrows;
  149588. prep->next_buf_row += numrows;
  149589. prep->rows_to_go -= numrows;
  149590. } else {
  149591. if (prep->rows_to_go != 0)
  149592. break;
  149593. if (prep->next_buf_row < prep->next_buf_stop) {
  149594. for (ci = 0; ci < cinfo->num_components; ci++) {
  149595. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149596. prep->next_buf_row, prep->next_buf_stop);
  149597. }
  149598. prep->next_buf_row = prep->next_buf_stop;
  149599. }
  149600. }
  149601. if (prep->next_buf_row == prep->next_buf_stop) {
  149602. (*cinfo->downsample->downsample) (cinfo,
  149603. prep->color_buf,
  149604. (JDIMENSION) prep->this_row_group,
  149605. output_buf, *out_row_group_ctr);
  149606. (*out_row_group_ctr)++;
  149607. prep->this_row_group += cinfo->max_v_samp_factor;
  149608. if (prep->this_row_group >= buf_height)
  149609. prep->this_row_group = 0;
  149610. if (prep->next_buf_row >= buf_height)
  149611. prep->next_buf_row = 0;
  149612. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149613. }
  149614. }
  149615. }
  149616. LOCAL(void)
  149617. create_context_buffer (j_compress_ptr cinfo)
  149618. {
  149619. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149620. int rgroup_height = cinfo->max_v_samp_factor;
  149621. int ci, i;
  149622. jpeg_component_info * compptr;
  149623. JSAMPARRAY true_buffer, fake_buffer;
  149624. fake_buffer = (JSAMPARRAY)
  149625. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149626. (cinfo->num_components * 5 * rgroup_height) *
  149627. SIZEOF(JSAMPROW));
  149628. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149629. ci++, compptr++) {
  149630. true_buffer = (*cinfo->mem->alloc_sarray)
  149631. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149632. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149633. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149634. (JDIMENSION) (3 * rgroup_height));
  149635. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149636. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149637. for (i = 0; i < rgroup_height; i++) {
  149638. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149639. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149640. }
  149641. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149642. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149643. }
  149644. }
  149645. #endif /* CONTEXT_ROWS_SUPPORTED */
  149646. GLOBAL(void)
  149647. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149648. {
  149649. my_prep_ptr prep;
  149650. int ci;
  149651. jpeg_component_info * compptr;
  149652. if (need_full_buffer) /* safety check */
  149653. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149654. prep = (my_prep_ptr)
  149655. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149656. SIZEOF(my_prep_controller));
  149657. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149658. prep->pub.start_pass = start_pass_prep;
  149659. if (cinfo->downsample->need_context_rows) {
  149660. #ifdef CONTEXT_ROWS_SUPPORTED
  149661. prep->pub.pre_process_data = pre_process_context;
  149662. create_context_buffer(cinfo);
  149663. #else
  149664. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149665. #endif
  149666. } else {
  149667. prep->pub.pre_process_data = pre_process_data;
  149668. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149669. ci++, compptr++) {
  149670. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149671. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149672. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149673. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149674. (JDIMENSION) cinfo->max_v_samp_factor);
  149675. }
  149676. }
  149677. }
  149678. /*** End of inlined file: jcprepct.c ***/
  149679. /*** Start of inlined file: jcsample.c ***/
  149680. #define JPEG_INTERNALS
  149681. typedef JMETHOD(void, downsample1_ptr,
  149682. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149683. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149684. typedef struct {
  149685. struct jpeg_downsampler pub; /* public fields */
  149686. downsample1_ptr methods[MAX_COMPONENTS];
  149687. } my_downsampler;
  149688. typedef my_downsampler * my_downsample_ptr;
  149689. METHODDEF(void)
  149690. start_pass_downsample (j_compress_ptr cinfo)
  149691. {
  149692. }
  149693. LOCAL(void)
  149694. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149695. JDIMENSION input_cols, JDIMENSION output_cols)
  149696. {
  149697. register JSAMPROW ptr;
  149698. register JSAMPLE pixval;
  149699. register int count;
  149700. int row;
  149701. int numcols = (int) (output_cols - input_cols);
  149702. if (numcols > 0) {
  149703. for (row = 0; row < num_rows; row++) {
  149704. ptr = image_data[row] + input_cols;
  149705. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149706. for (count = numcols; count > 0; count--)
  149707. *ptr++ = pixval;
  149708. }
  149709. }
  149710. }
  149711. METHODDEF(void)
  149712. sep_downsample (j_compress_ptr cinfo,
  149713. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149714. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149715. {
  149716. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149717. int ci;
  149718. jpeg_component_info * compptr;
  149719. JSAMPARRAY in_ptr, out_ptr;
  149720. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149721. ci++, compptr++) {
  149722. in_ptr = input_buf[ci] + in_row_index;
  149723. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149724. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149725. }
  149726. }
  149727. METHODDEF(void)
  149728. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149729. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149730. {
  149731. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149732. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149733. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149734. JSAMPROW inptr, outptr;
  149735. INT32 outvalue;
  149736. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149737. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149738. numpix = h_expand * v_expand;
  149739. numpix2 = numpix/2;
  149740. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149741. cinfo->image_width, output_cols * h_expand);
  149742. inrow = 0;
  149743. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149744. outptr = output_data[outrow];
  149745. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149746. outcol++, outcol_h += h_expand) {
  149747. outvalue = 0;
  149748. for (v = 0; v < v_expand; v++) {
  149749. inptr = input_data[inrow+v] + outcol_h;
  149750. for (h = 0; h < h_expand; h++) {
  149751. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149752. }
  149753. }
  149754. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149755. }
  149756. inrow += v_expand;
  149757. }
  149758. }
  149759. METHODDEF(void)
  149760. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149761. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149762. {
  149763. jcopy_sample_rows(input_data, 0, output_data, 0,
  149764. cinfo->max_v_samp_factor, cinfo->image_width);
  149765. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149766. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149767. }
  149768. METHODDEF(void)
  149769. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149770. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149771. {
  149772. int outrow;
  149773. JDIMENSION outcol;
  149774. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149775. register JSAMPROW inptr, outptr;
  149776. register int bias;
  149777. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149778. cinfo->image_width, output_cols * 2);
  149779. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149780. outptr = output_data[outrow];
  149781. inptr = input_data[outrow];
  149782. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149783. for (outcol = 0; outcol < output_cols; outcol++) {
  149784. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149785. + bias) >> 1);
  149786. bias ^= 1; /* 0=>1, 1=>0 */
  149787. inptr += 2;
  149788. }
  149789. }
  149790. }
  149791. METHODDEF(void)
  149792. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149793. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149794. {
  149795. int inrow, outrow;
  149796. JDIMENSION outcol;
  149797. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149798. register JSAMPROW inptr0, inptr1, outptr;
  149799. register int bias;
  149800. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149801. cinfo->image_width, output_cols * 2);
  149802. inrow = 0;
  149803. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149804. outptr = output_data[outrow];
  149805. inptr0 = input_data[inrow];
  149806. inptr1 = input_data[inrow+1];
  149807. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149808. for (outcol = 0; outcol < output_cols; outcol++) {
  149809. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149810. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149811. + bias) >> 2);
  149812. bias ^= 3; /* 1=>2, 2=>1 */
  149813. inptr0 += 2; inptr1 += 2;
  149814. }
  149815. inrow += 2;
  149816. }
  149817. }
  149818. #ifdef INPUT_SMOOTHING_SUPPORTED
  149819. METHODDEF(void)
  149820. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149821. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149822. {
  149823. int inrow, outrow;
  149824. JDIMENSION colctr;
  149825. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149826. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149827. INT32 membersum, neighsum, memberscale, neighscale;
  149828. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149829. cinfo->image_width, output_cols * 2);
  149830. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149831. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149832. inrow = 0;
  149833. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149834. outptr = output_data[outrow];
  149835. inptr0 = input_data[inrow];
  149836. inptr1 = input_data[inrow+1];
  149837. above_ptr = input_data[inrow-1];
  149838. below_ptr = input_data[inrow+2];
  149839. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149840. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149841. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149842. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149843. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149844. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149845. neighsum += neighsum;
  149846. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149847. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149848. membersum = membersum * memberscale + neighsum * neighscale;
  149849. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149850. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149851. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149852. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149853. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149854. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149855. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149856. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149857. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149858. neighsum += neighsum;
  149859. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149860. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149861. membersum = membersum * memberscale + neighsum * neighscale;
  149862. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149863. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149864. }
  149865. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149866. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149867. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149868. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149869. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  149870. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149871. neighsum += neighsum;
  149872. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149873. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149874. membersum = membersum * memberscale + neighsum * neighscale;
  149875. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149876. inrow += 2;
  149877. }
  149878. }
  149879. METHODDEF(void)
  149880. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149881. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149882. {
  149883. int outrow;
  149884. JDIMENSION colctr;
  149885. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149886. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149887. INT32 membersum, neighsum, memberscale, neighscale;
  149888. int colsum, lastcolsum, nextcolsum;
  149889. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149890. cinfo->image_width, output_cols);
  149891. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149892. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149893. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149894. outptr = output_data[outrow];
  149895. inptr = input_data[outrow];
  149896. above_ptr = input_data[outrow-1];
  149897. below_ptr = input_data[outrow+1];
  149898. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149899. GETJSAMPLE(*inptr);
  149900. membersum = GETJSAMPLE(*inptr++);
  149901. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149902. GETJSAMPLE(*inptr);
  149903. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149904. membersum = membersum * memberscale + neighsum * neighscale;
  149905. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149906. lastcolsum = colsum; colsum = nextcolsum;
  149907. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149908. membersum = GETJSAMPLE(*inptr++);
  149909. above_ptr++; below_ptr++;
  149910. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149911. GETJSAMPLE(*inptr);
  149912. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149913. membersum = membersum * memberscale + neighsum * neighscale;
  149914. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149915. lastcolsum = colsum; colsum = nextcolsum;
  149916. }
  149917. membersum = GETJSAMPLE(*inptr);
  149918. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149919. membersum = membersum * memberscale + neighsum * neighscale;
  149920. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149921. }
  149922. }
  149923. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149924. GLOBAL(void)
  149925. jinit_downsampler (j_compress_ptr cinfo)
  149926. {
  149927. my_downsample_ptr downsample;
  149928. int ci;
  149929. jpeg_component_info * compptr;
  149930. boolean smoothok = TRUE;
  149931. downsample = (my_downsample_ptr)
  149932. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149933. SIZEOF(my_downsampler));
  149934. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149935. downsample->pub.start_pass = start_pass_downsample;
  149936. downsample->pub.downsample = sep_downsample;
  149937. downsample->pub.need_context_rows = FALSE;
  149938. if (cinfo->CCIR601_sampling)
  149939. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  149940. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149941. ci++, compptr++) {
  149942. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  149943. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149944. #ifdef INPUT_SMOOTHING_SUPPORTED
  149945. if (cinfo->smoothing_factor) {
  149946. downsample->methods[ci] = fullsize_smooth_downsample;
  149947. downsample->pub.need_context_rows = TRUE;
  149948. } else
  149949. #endif
  149950. downsample->methods[ci] = fullsize_downsample;
  149951. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149952. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149953. smoothok = FALSE;
  149954. downsample->methods[ci] = h2v1_downsample;
  149955. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149956. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  149957. #ifdef INPUT_SMOOTHING_SUPPORTED
  149958. if (cinfo->smoothing_factor) {
  149959. downsample->methods[ci] = h2v2_smooth_downsample;
  149960. downsample->pub.need_context_rows = TRUE;
  149961. } else
  149962. #endif
  149963. downsample->methods[ci] = h2v2_downsample;
  149964. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  149965. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  149966. smoothok = FALSE;
  149967. downsample->methods[ci] = int_downsample;
  149968. } else
  149969. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  149970. }
  149971. #ifdef INPUT_SMOOTHING_SUPPORTED
  149972. if (cinfo->smoothing_factor && !smoothok)
  149973. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  149974. #endif
  149975. }
  149976. /*** End of inlined file: jcsample.c ***/
  149977. /*** Start of inlined file: jctrans.c ***/
  149978. #define JPEG_INTERNALS
  149979. LOCAL(void) transencode_master_selection
  149980. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149981. LOCAL(void) transencode_coef_controller
  149982. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149983. GLOBAL(void)
  149984. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  149985. {
  149986. if (cinfo->global_state != CSTATE_START)
  149987. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149988. jpeg_suppress_tables(cinfo, FALSE);
  149989. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  149990. (*cinfo->dest->init_destination) (cinfo);
  149991. transencode_master_selection(cinfo, coef_arrays);
  149992. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  149993. cinfo->global_state = CSTATE_WRCOEFS;
  149994. }
  149995. GLOBAL(void)
  149996. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  149997. j_compress_ptr dstinfo)
  149998. {
  149999. JQUANT_TBL ** qtblptr;
  150000. jpeg_component_info *incomp, *outcomp;
  150001. JQUANT_TBL *c_quant, *slot_quant;
  150002. int tblno, ci, coefi;
  150003. if (dstinfo->global_state != CSTATE_START)
  150004. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  150005. dstinfo->image_width = srcinfo->image_width;
  150006. dstinfo->image_height = srcinfo->image_height;
  150007. dstinfo->input_components = srcinfo->num_components;
  150008. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  150009. jpeg_set_defaults(dstinfo);
  150010. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  150011. dstinfo->data_precision = srcinfo->data_precision;
  150012. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  150013. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  150014. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  150015. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  150016. if (*qtblptr == NULL)
  150017. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  150018. MEMCOPY((*qtblptr)->quantval,
  150019. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  150020. SIZEOF((*qtblptr)->quantval));
  150021. (*qtblptr)->sent_table = FALSE;
  150022. }
  150023. }
  150024. dstinfo->num_components = srcinfo->num_components;
  150025. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150026. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150027. MAX_COMPONENTS);
  150028. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150029. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150030. outcomp->component_id = incomp->component_id;
  150031. outcomp->h_samp_factor = incomp->h_samp_factor;
  150032. outcomp->v_samp_factor = incomp->v_samp_factor;
  150033. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150034. tblno = outcomp->quant_tbl_no;
  150035. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150036. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150037. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150038. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150039. c_quant = incomp->quant_table;
  150040. if (c_quant != NULL) {
  150041. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150042. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150043. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150044. }
  150045. }
  150046. }
  150047. if (srcinfo->saw_JFIF_marker) {
  150048. if (srcinfo->JFIF_major_version == 1) {
  150049. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150050. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150051. }
  150052. dstinfo->density_unit = srcinfo->density_unit;
  150053. dstinfo->X_density = srcinfo->X_density;
  150054. dstinfo->Y_density = srcinfo->Y_density;
  150055. }
  150056. }
  150057. LOCAL(void)
  150058. transencode_master_selection (j_compress_ptr cinfo,
  150059. jvirt_barray_ptr * coef_arrays)
  150060. {
  150061. cinfo->input_components = 1;
  150062. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150063. if (cinfo->arith_code) {
  150064. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150065. } else {
  150066. if (cinfo->progressive_mode) {
  150067. #ifdef C_PROGRESSIVE_SUPPORTED
  150068. jinit_phuff_encoder(cinfo);
  150069. #else
  150070. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150071. #endif
  150072. } else
  150073. jinit_huff_encoder(cinfo);
  150074. }
  150075. transencode_coef_controller(cinfo, coef_arrays);
  150076. jinit_marker_writer(cinfo);
  150077. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150078. (*cinfo->marker->write_file_header) (cinfo);
  150079. }
  150080. typedef struct {
  150081. struct jpeg_c_coef_controller pub; /* public fields */
  150082. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150083. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150084. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150085. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150086. jvirt_barray_ptr * whole_image;
  150087. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150088. } my_coef_controller2;
  150089. typedef my_coef_controller2 * my_coef_ptr2;
  150090. LOCAL(void)
  150091. start_iMCU_row2 (j_compress_ptr cinfo)
  150092. {
  150093. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150094. if (cinfo->comps_in_scan > 1) {
  150095. coef->MCU_rows_per_iMCU_row = 1;
  150096. } else {
  150097. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150098. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150099. else
  150100. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150101. }
  150102. coef->mcu_ctr = 0;
  150103. coef->MCU_vert_offset = 0;
  150104. }
  150105. METHODDEF(void)
  150106. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150107. {
  150108. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150109. if (pass_mode != JBUF_CRANK_DEST)
  150110. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150111. coef->iMCU_row_num = 0;
  150112. start_iMCU_row2(cinfo);
  150113. }
  150114. METHODDEF(boolean)
  150115. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150116. {
  150117. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150118. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150119. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150120. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150121. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150122. JDIMENSION start_col;
  150123. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150124. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150125. JBLOCKROW buffer_ptr;
  150126. jpeg_component_info *compptr;
  150127. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150128. compptr = cinfo->cur_comp_info[ci];
  150129. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150130. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150131. coef->iMCU_row_num * compptr->v_samp_factor,
  150132. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150133. }
  150134. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150135. yoffset++) {
  150136. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150137. MCU_col_num++) {
  150138. blkn = 0; /* index of current DCT block within MCU */
  150139. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150140. compptr = cinfo->cur_comp_info[ci];
  150141. start_col = MCU_col_num * compptr->MCU_width;
  150142. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150143. : compptr->last_col_width;
  150144. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150145. if (coef->iMCU_row_num < last_iMCU_row ||
  150146. yindex+yoffset < compptr->last_row_height) {
  150147. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150148. for (xindex = 0; xindex < blockcnt; xindex++)
  150149. MCU_buffer[blkn++] = buffer_ptr++;
  150150. } else {
  150151. xindex = 0;
  150152. }
  150153. for (; xindex < compptr->MCU_width; xindex++) {
  150154. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150155. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150156. blkn++;
  150157. }
  150158. }
  150159. }
  150160. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150161. coef->MCU_vert_offset = yoffset;
  150162. coef->mcu_ctr = MCU_col_num;
  150163. return FALSE;
  150164. }
  150165. }
  150166. coef->mcu_ctr = 0;
  150167. }
  150168. coef->iMCU_row_num++;
  150169. start_iMCU_row2(cinfo);
  150170. return TRUE;
  150171. }
  150172. LOCAL(void)
  150173. transencode_coef_controller (j_compress_ptr cinfo,
  150174. jvirt_barray_ptr * coef_arrays)
  150175. {
  150176. my_coef_ptr2 coef;
  150177. JBLOCKROW buffer;
  150178. int i;
  150179. coef = (my_coef_ptr2)
  150180. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150181. SIZEOF(my_coef_controller2));
  150182. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150183. coef->pub.start_pass = start_pass_coef2;
  150184. coef->pub.compress_data = compress_output2;
  150185. coef->whole_image = coef_arrays;
  150186. buffer = (JBLOCKROW)
  150187. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150188. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150189. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150190. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150191. coef->dummy_buffer[i] = buffer + i;
  150192. }
  150193. }
  150194. /*** End of inlined file: jctrans.c ***/
  150195. /*** Start of inlined file: jdapistd.c ***/
  150196. #define JPEG_INTERNALS
  150197. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150198. GLOBAL(boolean)
  150199. jpeg_start_decompress (j_decompress_ptr cinfo)
  150200. {
  150201. if (cinfo->global_state == DSTATE_READY) {
  150202. jinit_master_decompress(cinfo);
  150203. if (cinfo->buffered_image) {
  150204. cinfo->global_state = DSTATE_BUFIMAGE;
  150205. return TRUE;
  150206. }
  150207. cinfo->global_state = DSTATE_PRELOAD;
  150208. }
  150209. if (cinfo->global_state == DSTATE_PRELOAD) {
  150210. if (cinfo->inputctl->has_multiple_scans) {
  150211. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150212. for (;;) {
  150213. int retcode;
  150214. if (cinfo->progress != NULL)
  150215. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150216. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150217. if (retcode == JPEG_SUSPENDED)
  150218. return FALSE;
  150219. if (retcode == JPEG_REACHED_EOI)
  150220. break;
  150221. if (cinfo->progress != NULL &&
  150222. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150223. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150224. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150225. }
  150226. }
  150227. }
  150228. #else
  150229. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150230. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150231. }
  150232. cinfo->output_scan_number = cinfo->input_scan_number;
  150233. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150234. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150235. return output_pass_setup(cinfo);
  150236. }
  150237. LOCAL(boolean)
  150238. output_pass_setup (j_decompress_ptr cinfo)
  150239. {
  150240. if (cinfo->global_state != DSTATE_PRESCAN) {
  150241. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150242. cinfo->output_scanline = 0;
  150243. cinfo->global_state = DSTATE_PRESCAN;
  150244. }
  150245. while (cinfo->master->is_dummy_pass) {
  150246. #ifdef QUANT_2PASS_SUPPORTED
  150247. while (cinfo->output_scanline < cinfo->output_height) {
  150248. JDIMENSION last_scanline;
  150249. if (cinfo->progress != NULL) {
  150250. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150251. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150252. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150253. }
  150254. last_scanline = cinfo->output_scanline;
  150255. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150256. &cinfo->output_scanline, (JDIMENSION) 0);
  150257. if (cinfo->output_scanline == last_scanline)
  150258. return FALSE; /* No progress made, must suspend */
  150259. }
  150260. (*cinfo->master->finish_output_pass) (cinfo);
  150261. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150262. cinfo->output_scanline = 0;
  150263. #else
  150264. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150265. #endif /* QUANT_2PASS_SUPPORTED */
  150266. }
  150267. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150268. return TRUE;
  150269. }
  150270. GLOBAL(JDIMENSION)
  150271. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150272. JDIMENSION max_lines)
  150273. {
  150274. JDIMENSION row_ctr;
  150275. if (cinfo->global_state != DSTATE_SCANNING)
  150276. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150277. if (cinfo->output_scanline >= cinfo->output_height) {
  150278. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150279. return 0;
  150280. }
  150281. if (cinfo->progress != NULL) {
  150282. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150283. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150284. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150285. }
  150286. row_ctr = 0;
  150287. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150288. cinfo->output_scanline += row_ctr;
  150289. return row_ctr;
  150290. }
  150291. GLOBAL(JDIMENSION)
  150292. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150293. JDIMENSION max_lines)
  150294. {
  150295. JDIMENSION lines_per_iMCU_row;
  150296. if (cinfo->global_state != DSTATE_RAW_OK)
  150297. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150298. if (cinfo->output_scanline >= cinfo->output_height) {
  150299. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150300. return 0;
  150301. }
  150302. if (cinfo->progress != NULL) {
  150303. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150304. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150305. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150306. }
  150307. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150308. if (max_lines < lines_per_iMCU_row)
  150309. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150310. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150311. return 0; /* suspension forced, can do nothing more */
  150312. cinfo->output_scanline += lines_per_iMCU_row;
  150313. return lines_per_iMCU_row;
  150314. }
  150315. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150316. GLOBAL(boolean)
  150317. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150318. {
  150319. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150320. cinfo->global_state != DSTATE_PRESCAN)
  150321. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150322. if (scan_number <= 0)
  150323. scan_number = 1;
  150324. if (cinfo->inputctl->eoi_reached &&
  150325. scan_number > cinfo->input_scan_number)
  150326. scan_number = cinfo->input_scan_number;
  150327. cinfo->output_scan_number = scan_number;
  150328. return output_pass_setup(cinfo);
  150329. }
  150330. GLOBAL(boolean)
  150331. jpeg_finish_output (j_decompress_ptr cinfo)
  150332. {
  150333. if ((cinfo->global_state == DSTATE_SCANNING ||
  150334. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150335. (*cinfo->master->finish_output_pass) (cinfo);
  150336. cinfo->global_state = DSTATE_BUFPOST;
  150337. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150338. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150339. }
  150340. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150341. ! cinfo->inputctl->eoi_reached) {
  150342. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150343. return FALSE; /* Suspend, come back later */
  150344. }
  150345. cinfo->global_state = DSTATE_BUFIMAGE;
  150346. return TRUE;
  150347. }
  150348. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150349. /*** End of inlined file: jdapistd.c ***/
  150350. /*** Start of inlined file: jdapimin.c ***/
  150351. #define JPEG_INTERNALS
  150352. GLOBAL(void)
  150353. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150354. {
  150355. int i;
  150356. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150357. if (version != JPEG_LIB_VERSION)
  150358. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150359. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150360. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150361. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150362. {
  150363. struct jpeg_error_mgr * err = cinfo->err;
  150364. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150365. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150366. cinfo->err = err;
  150367. cinfo->client_data = client_data;
  150368. }
  150369. cinfo->is_decompressor = TRUE;
  150370. jinit_memory_mgr((j_common_ptr) cinfo);
  150371. cinfo->progress = NULL;
  150372. cinfo->src = NULL;
  150373. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150374. cinfo->quant_tbl_ptrs[i] = NULL;
  150375. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150376. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150377. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150378. }
  150379. cinfo->marker_list = NULL;
  150380. jinit_marker_reader(cinfo);
  150381. jinit_input_controller(cinfo);
  150382. cinfo->global_state = DSTATE_START;
  150383. }
  150384. GLOBAL(void)
  150385. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150386. {
  150387. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150388. }
  150389. GLOBAL(void)
  150390. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150391. {
  150392. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150393. }
  150394. LOCAL(void)
  150395. default_decompress_parms (j_decompress_ptr cinfo)
  150396. {
  150397. switch (cinfo->num_components) {
  150398. case 1:
  150399. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150400. cinfo->out_color_space = JCS_GRAYSCALE;
  150401. break;
  150402. case 3:
  150403. if (cinfo->saw_JFIF_marker) {
  150404. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150405. } else if (cinfo->saw_Adobe_marker) {
  150406. switch (cinfo->Adobe_transform) {
  150407. case 0:
  150408. cinfo->jpeg_color_space = JCS_RGB;
  150409. break;
  150410. case 1:
  150411. cinfo->jpeg_color_space = JCS_YCbCr;
  150412. break;
  150413. default:
  150414. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150415. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150416. break;
  150417. }
  150418. } else {
  150419. int cid0 = cinfo->comp_info[0].component_id;
  150420. int cid1 = cinfo->comp_info[1].component_id;
  150421. int cid2 = cinfo->comp_info[2].component_id;
  150422. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150423. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150424. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150425. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150426. else {
  150427. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150428. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150429. }
  150430. }
  150431. cinfo->out_color_space = JCS_RGB;
  150432. break;
  150433. case 4:
  150434. if (cinfo->saw_Adobe_marker) {
  150435. switch (cinfo->Adobe_transform) {
  150436. case 0:
  150437. cinfo->jpeg_color_space = JCS_CMYK;
  150438. break;
  150439. case 2:
  150440. cinfo->jpeg_color_space = JCS_YCCK;
  150441. break;
  150442. default:
  150443. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150444. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150445. break;
  150446. }
  150447. } else {
  150448. cinfo->jpeg_color_space = JCS_CMYK;
  150449. }
  150450. cinfo->out_color_space = JCS_CMYK;
  150451. break;
  150452. default:
  150453. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150454. cinfo->out_color_space = JCS_UNKNOWN;
  150455. break;
  150456. }
  150457. cinfo->scale_num = 1; /* 1:1 scaling */
  150458. cinfo->scale_denom = 1;
  150459. cinfo->output_gamma = 1.0;
  150460. cinfo->buffered_image = FALSE;
  150461. cinfo->raw_data_out = FALSE;
  150462. cinfo->dct_method = JDCT_DEFAULT;
  150463. cinfo->do_fancy_upsampling = TRUE;
  150464. cinfo->do_block_smoothing = TRUE;
  150465. cinfo->quantize_colors = FALSE;
  150466. cinfo->dither_mode = JDITHER_FS;
  150467. #ifdef QUANT_2PASS_SUPPORTED
  150468. cinfo->two_pass_quantize = TRUE;
  150469. #else
  150470. cinfo->two_pass_quantize = FALSE;
  150471. #endif
  150472. cinfo->desired_number_of_colors = 256;
  150473. cinfo->colormap = NULL;
  150474. cinfo->enable_1pass_quant = FALSE;
  150475. cinfo->enable_external_quant = FALSE;
  150476. cinfo->enable_2pass_quant = FALSE;
  150477. }
  150478. GLOBAL(int)
  150479. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150480. {
  150481. int retcode;
  150482. if (cinfo->global_state != DSTATE_START &&
  150483. cinfo->global_state != DSTATE_INHEADER)
  150484. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150485. retcode = jpeg_consume_input(cinfo);
  150486. switch (retcode) {
  150487. case JPEG_REACHED_SOS:
  150488. retcode = JPEG_HEADER_OK;
  150489. break;
  150490. case JPEG_REACHED_EOI:
  150491. if (require_image) /* Complain if application wanted an image */
  150492. ERREXIT(cinfo, JERR_NO_IMAGE);
  150493. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150494. retcode = JPEG_HEADER_TABLES_ONLY;
  150495. break;
  150496. case JPEG_SUSPENDED:
  150497. break;
  150498. }
  150499. return retcode;
  150500. }
  150501. GLOBAL(int)
  150502. jpeg_consume_input (j_decompress_ptr cinfo)
  150503. {
  150504. int retcode = JPEG_SUSPENDED;
  150505. switch (cinfo->global_state) {
  150506. case DSTATE_START:
  150507. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150508. (*cinfo->src->init_source) (cinfo);
  150509. cinfo->global_state = DSTATE_INHEADER;
  150510. case DSTATE_INHEADER:
  150511. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150512. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150513. default_decompress_parms(cinfo);
  150514. cinfo->global_state = DSTATE_READY;
  150515. }
  150516. break;
  150517. case DSTATE_READY:
  150518. retcode = JPEG_REACHED_SOS;
  150519. break;
  150520. case DSTATE_PRELOAD:
  150521. case DSTATE_PRESCAN:
  150522. case DSTATE_SCANNING:
  150523. case DSTATE_RAW_OK:
  150524. case DSTATE_BUFIMAGE:
  150525. case DSTATE_BUFPOST:
  150526. case DSTATE_STOPPING:
  150527. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150528. break;
  150529. default:
  150530. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150531. }
  150532. return retcode;
  150533. }
  150534. GLOBAL(boolean)
  150535. jpeg_input_complete (j_decompress_ptr cinfo)
  150536. {
  150537. if (cinfo->global_state < DSTATE_START ||
  150538. cinfo->global_state > DSTATE_STOPPING)
  150539. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150540. return cinfo->inputctl->eoi_reached;
  150541. }
  150542. GLOBAL(boolean)
  150543. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150544. {
  150545. if (cinfo->global_state < DSTATE_READY ||
  150546. cinfo->global_state > DSTATE_STOPPING)
  150547. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150548. return cinfo->inputctl->has_multiple_scans;
  150549. }
  150550. GLOBAL(boolean)
  150551. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150552. {
  150553. if ((cinfo->global_state == DSTATE_SCANNING ||
  150554. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150555. if (cinfo->output_scanline < cinfo->output_height)
  150556. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150557. (*cinfo->master->finish_output_pass) (cinfo);
  150558. cinfo->global_state = DSTATE_STOPPING;
  150559. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150560. cinfo->global_state = DSTATE_STOPPING;
  150561. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150562. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150563. }
  150564. while (! cinfo->inputctl->eoi_reached) {
  150565. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150566. return FALSE; /* Suspend, come back later */
  150567. }
  150568. (*cinfo->src->term_source) (cinfo);
  150569. jpeg_abort((j_common_ptr) cinfo);
  150570. return TRUE;
  150571. }
  150572. /*** End of inlined file: jdapimin.c ***/
  150573. /*** Start of inlined file: jdatasrc.c ***/
  150574. /*** Start of inlined file: jerror.h ***/
  150575. #ifndef JMESSAGE
  150576. #ifndef JERROR_H
  150577. #define JMAKE_ENUM_LIST
  150578. #else
  150579. #define JMESSAGE(code,string)
  150580. #endif /* JERROR_H */
  150581. #endif /* JMESSAGE */
  150582. #ifdef JMAKE_ENUM_LIST
  150583. typedef enum {
  150584. #define JMESSAGE(code,string) code ,
  150585. #endif /* JMAKE_ENUM_LIST */
  150586. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150587. JMESSAGE(JERR_ARITH_NOTIMPL,
  150588. "Sorry, there are legal restrictions on arithmetic coding")
  150589. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150590. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150591. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150592. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150593. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150594. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150595. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150596. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150597. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150598. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150599. JMESSAGE(JERR_BAD_LIB_VERSION,
  150600. "Wrong JPEG library version: library is %d, caller expects %d")
  150601. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150602. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150603. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150604. JMESSAGE(JERR_BAD_PROGRESSION,
  150605. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150606. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150607. "Invalid progressive parameters at scan script entry %d")
  150608. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150609. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150610. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150611. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150612. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150613. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150614. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150615. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150616. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150617. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150618. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150619. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150620. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150621. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150622. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150623. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150624. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150625. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150626. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150627. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150628. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150629. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150630. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150631. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150632. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150633. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150634. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150635. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150636. "Cannot transcode due to multiple use of quantization table %d")
  150637. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150638. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150639. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150640. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150641. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150642. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150643. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150644. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150645. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150646. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150647. JMESSAGE(JERR_QUANT_COMPONENTS,
  150648. "Cannot quantize more than %d color components")
  150649. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150650. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150651. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150652. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150653. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150654. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150655. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150656. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150657. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150658. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150659. JMESSAGE(JERR_TFILE_WRITE,
  150660. "Write failed on temporary file --- out of disk space?")
  150661. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150662. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150663. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150664. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150665. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150666. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150667. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150668. JMESSAGE(JMSG_VERSION, JVERSION)
  150669. JMESSAGE(JTRC_16BIT_TABLES,
  150670. "Caution: quantization tables are too coarse for baseline JPEG")
  150671. JMESSAGE(JTRC_ADOBE,
  150672. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150673. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150674. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150675. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150676. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150677. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150678. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150679. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150680. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150681. JMESSAGE(JTRC_EOI, "End Of Image")
  150682. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150683. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150684. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150685. "Warning: thumbnail image size does not match data length %u")
  150686. JMESSAGE(JTRC_JFIF_EXTENSION,
  150687. "JFIF extension marker: type 0x%02x, length %u")
  150688. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150689. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150690. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150691. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150692. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150693. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150694. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150695. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150696. JMESSAGE(JTRC_RST, "RST%d")
  150697. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150698. "Smoothing not supported with nonstandard sampling ratios")
  150699. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150700. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150701. JMESSAGE(JTRC_SOI, "Start of Image")
  150702. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150703. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150704. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150705. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150706. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150707. JMESSAGE(JTRC_THUMB_JPEG,
  150708. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150709. JMESSAGE(JTRC_THUMB_PALETTE,
  150710. "JFIF extension marker: palette thumbnail image, length %u")
  150711. JMESSAGE(JTRC_THUMB_RGB,
  150712. "JFIF extension marker: RGB thumbnail image, length %u")
  150713. JMESSAGE(JTRC_UNKNOWN_IDS,
  150714. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150715. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150716. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150717. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150718. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150719. "Inconsistent progression sequence for component %d coefficient %d")
  150720. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150721. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150722. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150723. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150724. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150725. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150726. JMESSAGE(JWRN_MUST_RESYNC,
  150727. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150728. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150729. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150730. #ifdef JMAKE_ENUM_LIST
  150731. JMSG_LASTMSGCODE
  150732. } J_MESSAGE_CODE;
  150733. #undef JMAKE_ENUM_LIST
  150734. #endif /* JMAKE_ENUM_LIST */
  150735. #undef JMESSAGE
  150736. #ifndef JERROR_H
  150737. #define JERROR_H
  150738. #define ERREXIT(cinfo,code) \
  150739. ((cinfo)->err->msg_code = (code), \
  150740. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150741. #define ERREXIT1(cinfo,code,p1) \
  150742. ((cinfo)->err->msg_code = (code), \
  150743. (cinfo)->err->msg_parm.i[0] = (p1), \
  150744. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150745. #define ERREXIT2(cinfo,code,p1,p2) \
  150746. ((cinfo)->err->msg_code = (code), \
  150747. (cinfo)->err->msg_parm.i[0] = (p1), \
  150748. (cinfo)->err->msg_parm.i[1] = (p2), \
  150749. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150750. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150751. ((cinfo)->err->msg_code = (code), \
  150752. (cinfo)->err->msg_parm.i[0] = (p1), \
  150753. (cinfo)->err->msg_parm.i[1] = (p2), \
  150754. (cinfo)->err->msg_parm.i[2] = (p3), \
  150755. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150756. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  150757. ((cinfo)->err->msg_code = (code), \
  150758. (cinfo)->err->msg_parm.i[0] = (p1), \
  150759. (cinfo)->err->msg_parm.i[1] = (p2), \
  150760. (cinfo)->err->msg_parm.i[2] = (p3), \
  150761. (cinfo)->err->msg_parm.i[3] = (p4), \
  150762. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150763. #define ERREXITS(cinfo,code,str) \
  150764. ((cinfo)->err->msg_code = (code), \
  150765. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150766. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150767. #define MAKESTMT(stuff) do { stuff } while (0)
  150768. #define WARNMS(cinfo,code) \
  150769. ((cinfo)->err->msg_code = (code), \
  150770. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150771. #define WARNMS1(cinfo,code,p1) \
  150772. ((cinfo)->err->msg_code = (code), \
  150773. (cinfo)->err->msg_parm.i[0] = (p1), \
  150774. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150775. #define WARNMS2(cinfo,code,p1,p2) \
  150776. ((cinfo)->err->msg_code = (code), \
  150777. (cinfo)->err->msg_parm.i[0] = (p1), \
  150778. (cinfo)->err->msg_parm.i[1] = (p2), \
  150779. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150780. #define TRACEMS(cinfo,lvl,code) \
  150781. ((cinfo)->err->msg_code = (code), \
  150782. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150783. #define TRACEMS1(cinfo,lvl,code,p1) \
  150784. ((cinfo)->err->msg_code = (code), \
  150785. (cinfo)->err->msg_parm.i[0] = (p1), \
  150786. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150787. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150788. ((cinfo)->err->msg_code = (code), \
  150789. (cinfo)->err->msg_parm.i[0] = (p1), \
  150790. (cinfo)->err->msg_parm.i[1] = (p2), \
  150791. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150792. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150793. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150794. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150795. (cinfo)->err->msg_code = (code); \
  150796. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150797. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150798. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150799. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150800. (cinfo)->err->msg_code = (code); \
  150801. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150802. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150803. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150804. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150805. _mp[4] = (p5); \
  150806. (cinfo)->err->msg_code = (code); \
  150807. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150808. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150809. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150810. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150811. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150812. (cinfo)->err->msg_code = (code); \
  150813. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150814. #define TRACEMSS(cinfo,lvl,code,str) \
  150815. ((cinfo)->err->msg_code = (code), \
  150816. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150817. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150818. #endif /* JERROR_H */
  150819. /*** End of inlined file: jerror.h ***/
  150820. typedef struct {
  150821. struct jpeg_source_mgr pub; /* public fields */
  150822. FILE * infile; /* source stream */
  150823. JOCTET * buffer; /* start of buffer */
  150824. boolean start_of_file; /* have we gotten any data yet? */
  150825. } my_source_mgr;
  150826. typedef my_source_mgr * my_src_ptr;
  150827. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150828. METHODDEF(void)
  150829. init_source (j_decompress_ptr cinfo)
  150830. {
  150831. my_src_ptr src = (my_src_ptr) cinfo->src;
  150832. src->start_of_file = TRUE;
  150833. }
  150834. METHODDEF(boolean)
  150835. fill_input_buffer (j_decompress_ptr cinfo)
  150836. {
  150837. my_src_ptr src = (my_src_ptr) cinfo->src;
  150838. size_t nbytes;
  150839. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150840. if (nbytes <= 0) {
  150841. if (src->start_of_file) /* Treat empty input file as fatal error */
  150842. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150843. WARNMS(cinfo, JWRN_JPEG_EOF);
  150844. src->buffer[0] = (JOCTET) 0xFF;
  150845. src->buffer[1] = (JOCTET) JPEG_EOI;
  150846. nbytes = 2;
  150847. }
  150848. src->pub.next_input_byte = src->buffer;
  150849. src->pub.bytes_in_buffer = nbytes;
  150850. src->start_of_file = FALSE;
  150851. return TRUE;
  150852. }
  150853. METHODDEF(void)
  150854. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150855. {
  150856. my_src_ptr src = (my_src_ptr) cinfo->src;
  150857. if (num_bytes > 0) {
  150858. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150859. num_bytes -= (long) src->pub.bytes_in_buffer;
  150860. (void) fill_input_buffer(cinfo);
  150861. }
  150862. src->pub.next_input_byte += (size_t) num_bytes;
  150863. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150864. }
  150865. }
  150866. METHODDEF(void)
  150867. term_source (j_decompress_ptr cinfo)
  150868. {
  150869. }
  150870. GLOBAL(void)
  150871. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150872. {
  150873. my_src_ptr src;
  150874. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150875. cinfo->src = (struct jpeg_source_mgr *)
  150876. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150877. SIZEOF(my_source_mgr));
  150878. src = (my_src_ptr) cinfo->src;
  150879. src->buffer = (JOCTET *)
  150880. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150881. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150882. }
  150883. src = (my_src_ptr) cinfo->src;
  150884. src->pub.init_source = init_source;
  150885. src->pub.fill_input_buffer = fill_input_buffer;
  150886. src->pub.skip_input_data = skip_input_data;
  150887. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150888. src->pub.term_source = term_source;
  150889. src->infile = infile;
  150890. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150891. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150892. }
  150893. /*** End of inlined file: jdatasrc.c ***/
  150894. /*** Start of inlined file: jdcoefct.c ***/
  150895. #define JPEG_INTERNALS
  150896. #ifndef D_PROGRESSIVE_SUPPORTED
  150897. #undef BLOCK_SMOOTHING_SUPPORTED
  150898. #endif
  150899. typedef struct {
  150900. struct jpeg_d_coef_controller pub; /* public fields */
  150901. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150902. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150903. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150904. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150905. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150906. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150907. #endif
  150908. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150909. int * coef_bits_latch;
  150910. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150911. #endif
  150912. } my_coef_controller3;
  150913. typedef my_coef_controller3 * my_coef_ptr3;
  150914. METHODDEF(int) decompress_onepass
  150915. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150916. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150917. METHODDEF(int) decompress_data
  150918. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150919. #endif
  150920. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150921. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150922. METHODDEF(int) decompress_smooth_data
  150923. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150924. #endif
  150925. LOCAL(void)
  150926. start_iMCU_row3 (j_decompress_ptr cinfo)
  150927. {
  150928. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150929. if (cinfo->comps_in_scan > 1) {
  150930. coef->MCU_rows_per_iMCU_row = 1;
  150931. } else {
  150932. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150933. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150934. else
  150935. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150936. }
  150937. coef->MCU_ctr = 0;
  150938. coef->MCU_vert_offset = 0;
  150939. }
  150940. METHODDEF(void)
  150941. start_input_pass (j_decompress_ptr cinfo)
  150942. {
  150943. cinfo->input_iMCU_row = 0;
  150944. start_iMCU_row3(cinfo);
  150945. }
  150946. METHODDEF(void)
  150947. start_output_pass (j_decompress_ptr cinfo)
  150948. {
  150949. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150950. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150951. if (coef->pub.coef_arrays != NULL) {
  150952. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  150953. coef->pub.decompress_data = decompress_smooth_data;
  150954. else
  150955. coef->pub.decompress_data = decompress_data;
  150956. }
  150957. #endif
  150958. cinfo->output_iMCU_row = 0;
  150959. }
  150960. METHODDEF(int)
  150961. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150962. {
  150963. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150964. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150965. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150966. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150967. int blkn, ci, xindex, yindex, yoffset, useful_width;
  150968. JSAMPARRAY output_ptr;
  150969. JDIMENSION start_col, output_col;
  150970. jpeg_component_info *compptr;
  150971. inverse_DCT_method_ptr inverse_DCT;
  150972. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150973. yoffset++) {
  150974. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  150975. MCU_col_num++) {
  150976. jzero_far((void FAR *) coef->MCU_buffer[0],
  150977. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  150978. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150979. coef->MCU_vert_offset = yoffset;
  150980. coef->MCU_ctr = MCU_col_num;
  150981. return JPEG_SUSPENDED;
  150982. }
  150983. blkn = 0; /* index of current DCT block within MCU */
  150984. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150985. compptr = cinfo->cur_comp_info[ci];
  150986. if (! compptr->component_needed) {
  150987. blkn += compptr->MCU_blocks;
  150988. continue;
  150989. }
  150990. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  150991. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150992. : compptr->last_col_width;
  150993. output_ptr = output_buf[compptr->component_index] +
  150994. yoffset * compptr->DCT_scaled_size;
  150995. start_col = MCU_col_num * compptr->MCU_sample_width;
  150996. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150997. if (cinfo->input_iMCU_row < last_iMCU_row ||
  150998. yoffset+yindex < compptr->last_row_height) {
  150999. output_col = start_col;
  151000. for (xindex = 0; xindex < useful_width; xindex++) {
  151001. (*inverse_DCT) (cinfo, compptr,
  151002. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  151003. output_ptr, output_col);
  151004. output_col += compptr->DCT_scaled_size;
  151005. }
  151006. }
  151007. blkn += compptr->MCU_width;
  151008. output_ptr += compptr->DCT_scaled_size;
  151009. }
  151010. }
  151011. }
  151012. coef->MCU_ctr = 0;
  151013. }
  151014. cinfo->output_iMCU_row++;
  151015. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151016. start_iMCU_row3(cinfo);
  151017. return JPEG_ROW_COMPLETED;
  151018. }
  151019. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151020. return JPEG_SCAN_COMPLETED;
  151021. }
  151022. METHODDEF(int)
  151023. dummy_consume_data (j_decompress_ptr cinfo)
  151024. {
  151025. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151026. }
  151027. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151028. METHODDEF(int)
  151029. consume_data (j_decompress_ptr cinfo)
  151030. {
  151031. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151032. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151033. int blkn, ci, xindex, yindex, yoffset;
  151034. JDIMENSION start_col;
  151035. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151036. JBLOCKROW buffer_ptr;
  151037. jpeg_component_info *compptr;
  151038. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151039. compptr = cinfo->cur_comp_info[ci];
  151040. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151041. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151042. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151043. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151044. }
  151045. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151046. yoffset++) {
  151047. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151048. MCU_col_num++) {
  151049. blkn = 0; /* index of current DCT block within MCU */
  151050. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151051. compptr = cinfo->cur_comp_info[ci];
  151052. start_col = MCU_col_num * compptr->MCU_width;
  151053. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151054. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151055. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151056. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151057. }
  151058. }
  151059. }
  151060. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151061. coef->MCU_vert_offset = yoffset;
  151062. coef->MCU_ctr = MCU_col_num;
  151063. return JPEG_SUSPENDED;
  151064. }
  151065. }
  151066. coef->MCU_ctr = 0;
  151067. }
  151068. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151069. start_iMCU_row3(cinfo);
  151070. return JPEG_ROW_COMPLETED;
  151071. }
  151072. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151073. return JPEG_SCAN_COMPLETED;
  151074. }
  151075. METHODDEF(int)
  151076. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151077. {
  151078. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151079. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151080. JDIMENSION block_num;
  151081. int ci, block_row, block_rows;
  151082. JBLOCKARRAY buffer;
  151083. JBLOCKROW buffer_ptr;
  151084. JSAMPARRAY output_ptr;
  151085. JDIMENSION output_col;
  151086. jpeg_component_info *compptr;
  151087. inverse_DCT_method_ptr inverse_DCT;
  151088. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151089. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151090. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151091. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151092. return JPEG_SUSPENDED;
  151093. }
  151094. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151095. ci++, compptr++) {
  151096. if (! compptr->component_needed)
  151097. continue;
  151098. buffer = (*cinfo->mem->access_virt_barray)
  151099. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151100. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151101. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151102. if (cinfo->output_iMCU_row < last_iMCU_row)
  151103. block_rows = compptr->v_samp_factor;
  151104. else {
  151105. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151106. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151107. }
  151108. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151109. output_ptr = output_buf[ci];
  151110. for (block_row = 0; block_row < block_rows; block_row++) {
  151111. buffer_ptr = buffer[block_row];
  151112. output_col = 0;
  151113. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151114. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151115. output_ptr, output_col);
  151116. buffer_ptr++;
  151117. output_col += compptr->DCT_scaled_size;
  151118. }
  151119. output_ptr += compptr->DCT_scaled_size;
  151120. }
  151121. }
  151122. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151123. return JPEG_ROW_COMPLETED;
  151124. return JPEG_SCAN_COMPLETED;
  151125. }
  151126. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151127. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151128. #define Q01_POS 1
  151129. #define Q10_POS 8
  151130. #define Q20_POS 16
  151131. #define Q11_POS 9
  151132. #define Q02_POS 2
  151133. LOCAL(boolean)
  151134. smoothing_ok (j_decompress_ptr cinfo)
  151135. {
  151136. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151137. boolean smoothing_useful = FALSE;
  151138. int ci, coefi;
  151139. jpeg_component_info *compptr;
  151140. JQUANT_TBL * qtable;
  151141. int * coef_bits;
  151142. int * coef_bits_latch;
  151143. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151144. return FALSE;
  151145. if (coef->coef_bits_latch == NULL)
  151146. coef->coef_bits_latch = (int *)
  151147. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151148. cinfo->num_components *
  151149. (SAVED_COEFS * SIZEOF(int)));
  151150. coef_bits_latch = coef->coef_bits_latch;
  151151. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151152. ci++, compptr++) {
  151153. if ((qtable = compptr->quant_table) == NULL)
  151154. return FALSE;
  151155. if (qtable->quantval[0] == 0 ||
  151156. qtable->quantval[Q01_POS] == 0 ||
  151157. qtable->quantval[Q10_POS] == 0 ||
  151158. qtable->quantval[Q20_POS] == 0 ||
  151159. qtable->quantval[Q11_POS] == 0 ||
  151160. qtable->quantval[Q02_POS] == 0)
  151161. return FALSE;
  151162. coef_bits = cinfo->coef_bits[ci];
  151163. if (coef_bits[0] < 0)
  151164. return FALSE;
  151165. for (coefi = 1; coefi <= 5; coefi++) {
  151166. coef_bits_latch[coefi] = coef_bits[coefi];
  151167. if (coef_bits[coefi] != 0)
  151168. smoothing_useful = TRUE;
  151169. }
  151170. coef_bits_latch += SAVED_COEFS;
  151171. }
  151172. return smoothing_useful;
  151173. }
  151174. METHODDEF(int)
  151175. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151176. {
  151177. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151178. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151179. JDIMENSION block_num, last_block_column;
  151180. int ci, block_row, block_rows, access_rows;
  151181. JBLOCKARRAY buffer;
  151182. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151183. JSAMPARRAY output_ptr;
  151184. JDIMENSION output_col;
  151185. jpeg_component_info *compptr;
  151186. inverse_DCT_method_ptr inverse_DCT;
  151187. boolean first_row, last_row;
  151188. JBLOCK workspace;
  151189. int *coef_bits;
  151190. JQUANT_TBL *quanttbl;
  151191. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151192. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151193. int Al, pred;
  151194. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151195. ! cinfo->inputctl->eoi_reached) {
  151196. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151197. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151198. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151199. break;
  151200. }
  151201. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151202. return JPEG_SUSPENDED;
  151203. }
  151204. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151205. ci++, compptr++) {
  151206. if (! compptr->component_needed)
  151207. continue;
  151208. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151209. block_rows = compptr->v_samp_factor;
  151210. access_rows = block_rows * 2; /* this and next iMCU row */
  151211. last_row = FALSE;
  151212. } else {
  151213. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151214. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151215. access_rows = block_rows; /* this iMCU row only */
  151216. last_row = TRUE;
  151217. }
  151218. if (cinfo->output_iMCU_row > 0) {
  151219. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151220. buffer = (*cinfo->mem->access_virt_barray)
  151221. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151222. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151223. (JDIMENSION) access_rows, FALSE);
  151224. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151225. first_row = FALSE;
  151226. } else {
  151227. buffer = (*cinfo->mem->access_virt_barray)
  151228. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151229. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151230. first_row = TRUE;
  151231. }
  151232. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151233. quanttbl = compptr->quant_table;
  151234. Q00 = quanttbl->quantval[0];
  151235. Q01 = quanttbl->quantval[Q01_POS];
  151236. Q10 = quanttbl->quantval[Q10_POS];
  151237. Q20 = quanttbl->quantval[Q20_POS];
  151238. Q11 = quanttbl->quantval[Q11_POS];
  151239. Q02 = quanttbl->quantval[Q02_POS];
  151240. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151241. output_ptr = output_buf[ci];
  151242. for (block_row = 0; block_row < block_rows; block_row++) {
  151243. buffer_ptr = buffer[block_row];
  151244. if (first_row && block_row == 0)
  151245. prev_block_row = buffer_ptr;
  151246. else
  151247. prev_block_row = buffer[block_row-1];
  151248. if (last_row && block_row == block_rows-1)
  151249. next_block_row = buffer_ptr;
  151250. else
  151251. next_block_row = buffer[block_row+1];
  151252. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151253. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151254. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151255. output_col = 0;
  151256. last_block_column = compptr->width_in_blocks - 1;
  151257. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151258. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151259. if (block_num < last_block_column) {
  151260. DC3 = (int) prev_block_row[1][0];
  151261. DC6 = (int) buffer_ptr[1][0];
  151262. DC9 = (int) next_block_row[1][0];
  151263. }
  151264. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151265. num = 36 * Q00 * (DC4 - DC6);
  151266. if (num >= 0) {
  151267. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151268. if (Al > 0 && pred >= (1<<Al))
  151269. pred = (1<<Al)-1;
  151270. } else {
  151271. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151272. if (Al > 0 && pred >= (1<<Al))
  151273. pred = (1<<Al)-1;
  151274. pred = -pred;
  151275. }
  151276. workspace[1] = (JCOEF) pred;
  151277. }
  151278. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151279. num = 36 * Q00 * (DC2 - DC8);
  151280. if (num >= 0) {
  151281. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151282. if (Al > 0 && pred >= (1<<Al))
  151283. pred = (1<<Al)-1;
  151284. } else {
  151285. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151286. if (Al > 0 && pred >= (1<<Al))
  151287. pred = (1<<Al)-1;
  151288. pred = -pred;
  151289. }
  151290. workspace[8] = (JCOEF) pred;
  151291. }
  151292. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151293. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151294. if (num >= 0) {
  151295. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151296. if (Al > 0 && pred >= (1<<Al))
  151297. pred = (1<<Al)-1;
  151298. } else {
  151299. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151300. if (Al > 0 && pred >= (1<<Al))
  151301. pred = (1<<Al)-1;
  151302. pred = -pred;
  151303. }
  151304. workspace[16] = (JCOEF) pred;
  151305. }
  151306. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151307. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151308. if (num >= 0) {
  151309. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151310. if (Al > 0 && pred >= (1<<Al))
  151311. pred = (1<<Al)-1;
  151312. } else {
  151313. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151314. if (Al > 0 && pred >= (1<<Al))
  151315. pred = (1<<Al)-1;
  151316. pred = -pred;
  151317. }
  151318. workspace[9] = (JCOEF) pred;
  151319. }
  151320. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151321. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151322. if (num >= 0) {
  151323. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151324. if (Al > 0 && pred >= (1<<Al))
  151325. pred = (1<<Al)-1;
  151326. } else {
  151327. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151328. if (Al > 0 && pred >= (1<<Al))
  151329. pred = (1<<Al)-1;
  151330. pred = -pred;
  151331. }
  151332. workspace[2] = (JCOEF) pred;
  151333. }
  151334. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151335. output_ptr, output_col);
  151336. DC1 = DC2; DC2 = DC3;
  151337. DC4 = DC5; DC5 = DC6;
  151338. DC7 = DC8; DC8 = DC9;
  151339. buffer_ptr++, prev_block_row++, next_block_row++;
  151340. output_col += compptr->DCT_scaled_size;
  151341. }
  151342. output_ptr += compptr->DCT_scaled_size;
  151343. }
  151344. }
  151345. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151346. return JPEG_ROW_COMPLETED;
  151347. return JPEG_SCAN_COMPLETED;
  151348. }
  151349. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151350. GLOBAL(void)
  151351. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151352. {
  151353. my_coef_ptr3 coef;
  151354. coef = (my_coef_ptr3)
  151355. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151356. SIZEOF(my_coef_controller3));
  151357. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151358. coef->pub.start_input_pass = start_input_pass;
  151359. coef->pub.start_output_pass = start_output_pass;
  151360. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151361. coef->coef_bits_latch = NULL;
  151362. #endif
  151363. if (need_full_buffer) {
  151364. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151365. int ci, access_rows;
  151366. jpeg_component_info *compptr;
  151367. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151368. ci++, compptr++) {
  151369. access_rows = compptr->v_samp_factor;
  151370. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151371. if (cinfo->progressive_mode)
  151372. access_rows *= 3;
  151373. #endif
  151374. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151375. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151376. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151377. (long) compptr->h_samp_factor),
  151378. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151379. (long) compptr->v_samp_factor),
  151380. (JDIMENSION) access_rows);
  151381. }
  151382. coef->pub.consume_data = consume_data;
  151383. coef->pub.decompress_data = decompress_data;
  151384. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151385. #else
  151386. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151387. #endif
  151388. } else {
  151389. JBLOCKROW buffer;
  151390. int i;
  151391. buffer = (JBLOCKROW)
  151392. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151393. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151394. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151395. coef->MCU_buffer[i] = buffer + i;
  151396. }
  151397. coef->pub.consume_data = dummy_consume_data;
  151398. coef->pub.decompress_data = decompress_onepass;
  151399. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151400. }
  151401. }
  151402. /*** End of inlined file: jdcoefct.c ***/
  151403. #undef FIX
  151404. /*** Start of inlined file: jdcolor.c ***/
  151405. #define JPEG_INTERNALS
  151406. typedef struct {
  151407. struct jpeg_color_deconverter pub; /* public fields */
  151408. int * Cr_r_tab; /* => table for Cr to R conversion */
  151409. int * Cb_b_tab; /* => table for Cb to B conversion */
  151410. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151411. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151412. } my_color_deconverter2;
  151413. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151414. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151415. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151416. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151417. LOCAL(void)
  151418. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151419. {
  151420. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151421. int i;
  151422. INT32 x;
  151423. SHIFT_TEMPS
  151424. cconvert->Cr_r_tab = (int *)
  151425. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151426. (MAXJSAMPLE+1) * SIZEOF(int));
  151427. cconvert->Cb_b_tab = (int *)
  151428. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151429. (MAXJSAMPLE+1) * SIZEOF(int));
  151430. cconvert->Cr_g_tab = (INT32 *)
  151431. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151432. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151433. cconvert->Cb_g_tab = (INT32 *)
  151434. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151435. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151436. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151437. cconvert->Cr_r_tab[i] = (int)
  151438. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151439. cconvert->Cb_b_tab[i] = (int)
  151440. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151441. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151442. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151443. }
  151444. }
  151445. METHODDEF(void)
  151446. ycc_rgb_convert (j_decompress_ptr cinfo,
  151447. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151448. JSAMPARRAY output_buf, int num_rows)
  151449. {
  151450. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151451. register int y, cb, cr;
  151452. register JSAMPROW outptr;
  151453. register JSAMPROW inptr0, inptr1, inptr2;
  151454. register JDIMENSION col;
  151455. JDIMENSION num_cols = cinfo->output_width;
  151456. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151457. register int * Crrtab = cconvert->Cr_r_tab;
  151458. register int * Cbbtab = cconvert->Cb_b_tab;
  151459. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151460. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151461. SHIFT_TEMPS
  151462. while (--num_rows >= 0) {
  151463. inptr0 = input_buf[0][input_row];
  151464. inptr1 = input_buf[1][input_row];
  151465. inptr2 = input_buf[2][input_row];
  151466. input_row++;
  151467. outptr = *output_buf++;
  151468. for (col = 0; col < num_cols; col++) {
  151469. y = GETJSAMPLE(inptr0[col]);
  151470. cb = GETJSAMPLE(inptr1[col]);
  151471. cr = GETJSAMPLE(inptr2[col]);
  151472. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151473. outptr[RGB_GREEN] = range_limit[y +
  151474. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151475. SCALEBITS))];
  151476. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151477. outptr += RGB_PIXELSIZE;
  151478. }
  151479. }
  151480. }
  151481. METHODDEF(void)
  151482. null_convert2 (j_decompress_ptr cinfo,
  151483. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151484. JSAMPARRAY output_buf, int num_rows)
  151485. {
  151486. register JSAMPROW inptr, outptr;
  151487. register JDIMENSION count;
  151488. register int num_components = cinfo->num_components;
  151489. JDIMENSION num_cols = cinfo->output_width;
  151490. int ci;
  151491. while (--num_rows >= 0) {
  151492. for (ci = 0; ci < num_components; ci++) {
  151493. inptr = input_buf[ci][input_row];
  151494. outptr = output_buf[0] + ci;
  151495. for (count = num_cols; count > 0; count--) {
  151496. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151497. outptr += num_components;
  151498. }
  151499. }
  151500. input_row++;
  151501. output_buf++;
  151502. }
  151503. }
  151504. METHODDEF(void)
  151505. grayscale_convert2 (j_decompress_ptr cinfo,
  151506. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151507. JSAMPARRAY output_buf, int num_rows)
  151508. {
  151509. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151510. num_rows, cinfo->output_width);
  151511. }
  151512. METHODDEF(void)
  151513. gray_rgb_convert (j_decompress_ptr cinfo,
  151514. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151515. JSAMPARRAY output_buf, int num_rows)
  151516. {
  151517. register JSAMPROW inptr, outptr;
  151518. register JDIMENSION col;
  151519. JDIMENSION num_cols = cinfo->output_width;
  151520. while (--num_rows >= 0) {
  151521. inptr = input_buf[0][input_row++];
  151522. outptr = *output_buf++;
  151523. for (col = 0; col < num_cols; col++) {
  151524. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151525. outptr += RGB_PIXELSIZE;
  151526. }
  151527. }
  151528. }
  151529. METHODDEF(void)
  151530. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151531. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151532. JSAMPARRAY output_buf, int num_rows)
  151533. {
  151534. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151535. register int y, cb, cr;
  151536. register JSAMPROW outptr;
  151537. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151538. register JDIMENSION col;
  151539. JDIMENSION num_cols = cinfo->output_width;
  151540. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151541. register int * Crrtab = cconvert->Cr_r_tab;
  151542. register int * Cbbtab = cconvert->Cb_b_tab;
  151543. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151544. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151545. SHIFT_TEMPS
  151546. while (--num_rows >= 0) {
  151547. inptr0 = input_buf[0][input_row];
  151548. inptr1 = input_buf[1][input_row];
  151549. inptr2 = input_buf[2][input_row];
  151550. inptr3 = input_buf[3][input_row];
  151551. input_row++;
  151552. outptr = *output_buf++;
  151553. for (col = 0; col < num_cols; col++) {
  151554. y = GETJSAMPLE(inptr0[col]);
  151555. cb = GETJSAMPLE(inptr1[col]);
  151556. cr = GETJSAMPLE(inptr2[col]);
  151557. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151558. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151559. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151560. SCALEBITS)))];
  151561. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151562. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151563. outptr += 4;
  151564. }
  151565. }
  151566. }
  151567. METHODDEF(void)
  151568. start_pass_dcolor (j_decompress_ptr cinfo)
  151569. {
  151570. }
  151571. GLOBAL(void)
  151572. jinit_color_deconverter (j_decompress_ptr cinfo)
  151573. {
  151574. my_cconvert_ptr2 cconvert;
  151575. int ci;
  151576. cconvert = (my_cconvert_ptr2)
  151577. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151578. SIZEOF(my_color_deconverter2));
  151579. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151580. cconvert->pub.start_pass = start_pass_dcolor;
  151581. switch (cinfo->jpeg_color_space) {
  151582. case JCS_GRAYSCALE:
  151583. if (cinfo->num_components != 1)
  151584. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151585. break;
  151586. case JCS_RGB:
  151587. case JCS_YCbCr:
  151588. if (cinfo->num_components != 3)
  151589. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151590. break;
  151591. case JCS_CMYK:
  151592. case JCS_YCCK:
  151593. if (cinfo->num_components != 4)
  151594. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151595. break;
  151596. default: /* JCS_UNKNOWN can be anything */
  151597. if (cinfo->num_components < 1)
  151598. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151599. break;
  151600. }
  151601. switch (cinfo->out_color_space) {
  151602. case JCS_GRAYSCALE:
  151603. cinfo->out_color_components = 1;
  151604. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151605. cinfo->jpeg_color_space == JCS_YCbCr) {
  151606. cconvert->pub.color_convert = grayscale_convert2;
  151607. for (ci = 1; ci < cinfo->num_components; ci++)
  151608. cinfo->comp_info[ci].component_needed = FALSE;
  151609. } else
  151610. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151611. break;
  151612. case JCS_RGB:
  151613. cinfo->out_color_components = RGB_PIXELSIZE;
  151614. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151615. cconvert->pub.color_convert = ycc_rgb_convert;
  151616. build_ycc_rgb_table(cinfo);
  151617. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151618. cconvert->pub.color_convert = gray_rgb_convert;
  151619. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151620. cconvert->pub.color_convert = null_convert2;
  151621. } else
  151622. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151623. break;
  151624. case JCS_CMYK:
  151625. cinfo->out_color_components = 4;
  151626. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151627. cconvert->pub.color_convert = ycck_cmyk_convert;
  151628. build_ycc_rgb_table(cinfo);
  151629. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151630. cconvert->pub.color_convert = null_convert2;
  151631. } else
  151632. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151633. break;
  151634. default:
  151635. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151636. cinfo->out_color_components = cinfo->num_components;
  151637. cconvert->pub.color_convert = null_convert2;
  151638. } else /* unsupported non-null conversion */
  151639. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151640. break;
  151641. }
  151642. if (cinfo->quantize_colors)
  151643. cinfo->output_components = 1; /* single colormapped output component */
  151644. else
  151645. cinfo->output_components = cinfo->out_color_components;
  151646. }
  151647. /*** End of inlined file: jdcolor.c ***/
  151648. #undef FIX
  151649. /*** Start of inlined file: jddctmgr.c ***/
  151650. #define JPEG_INTERNALS
  151651. typedef struct {
  151652. struct jpeg_inverse_dct pub; /* public fields */
  151653. int cur_method[MAX_COMPONENTS];
  151654. } my_idct_controller;
  151655. typedef my_idct_controller * my_idct_ptr;
  151656. typedef union {
  151657. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151658. #ifdef DCT_IFAST_SUPPORTED
  151659. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151660. #endif
  151661. #ifdef DCT_FLOAT_SUPPORTED
  151662. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151663. #endif
  151664. } multiplier_table;
  151665. #ifdef DCT_ISLOW_SUPPORTED
  151666. #define PROVIDE_ISLOW_TABLES
  151667. #else
  151668. #ifdef IDCT_SCALING_SUPPORTED
  151669. #define PROVIDE_ISLOW_TABLES
  151670. #endif
  151671. #endif
  151672. METHODDEF(void)
  151673. start_pass (j_decompress_ptr cinfo)
  151674. {
  151675. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151676. int ci, i;
  151677. jpeg_component_info *compptr;
  151678. int method = 0;
  151679. inverse_DCT_method_ptr method_ptr = NULL;
  151680. JQUANT_TBL * qtbl;
  151681. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151682. ci++, compptr++) {
  151683. switch (compptr->DCT_scaled_size) {
  151684. #ifdef IDCT_SCALING_SUPPORTED
  151685. case 1:
  151686. method_ptr = jpeg_idct_1x1;
  151687. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151688. break;
  151689. case 2:
  151690. method_ptr = jpeg_idct_2x2;
  151691. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151692. break;
  151693. case 4:
  151694. method_ptr = jpeg_idct_4x4;
  151695. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151696. break;
  151697. #endif
  151698. case DCTSIZE:
  151699. switch (cinfo->dct_method) {
  151700. #ifdef DCT_ISLOW_SUPPORTED
  151701. case JDCT_ISLOW:
  151702. method_ptr = jpeg_idct_islow;
  151703. method = JDCT_ISLOW;
  151704. break;
  151705. #endif
  151706. #ifdef DCT_IFAST_SUPPORTED
  151707. case JDCT_IFAST:
  151708. method_ptr = jpeg_idct_ifast;
  151709. method = JDCT_IFAST;
  151710. break;
  151711. #endif
  151712. #ifdef DCT_FLOAT_SUPPORTED
  151713. case JDCT_FLOAT:
  151714. method_ptr = jpeg_idct_float;
  151715. method = JDCT_FLOAT;
  151716. break;
  151717. #endif
  151718. default:
  151719. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151720. break;
  151721. }
  151722. break;
  151723. default:
  151724. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151725. break;
  151726. }
  151727. idct->pub.inverse_DCT[ci] = method_ptr;
  151728. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151729. continue;
  151730. qtbl = compptr->quant_table;
  151731. if (qtbl == NULL) /* happens if no data yet for component */
  151732. continue;
  151733. idct->cur_method[ci] = method;
  151734. switch (method) {
  151735. #ifdef PROVIDE_ISLOW_TABLES
  151736. case JDCT_ISLOW:
  151737. {
  151738. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151739. for (i = 0; i < DCTSIZE2; i++) {
  151740. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151741. }
  151742. }
  151743. break;
  151744. #endif
  151745. #ifdef DCT_IFAST_SUPPORTED
  151746. case JDCT_IFAST:
  151747. {
  151748. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151749. #define CONST_BITS 14
  151750. static const INT16 aanscales[DCTSIZE2] = {
  151751. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151752. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151753. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151754. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151755. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151756. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151757. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151758. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151759. };
  151760. SHIFT_TEMPS
  151761. for (i = 0; i < DCTSIZE2; i++) {
  151762. ifmtbl[i] = (IFAST_MULT_TYPE)
  151763. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151764. (INT32) aanscales[i]),
  151765. CONST_BITS-IFAST_SCALE_BITS);
  151766. }
  151767. }
  151768. break;
  151769. #endif
  151770. #ifdef DCT_FLOAT_SUPPORTED
  151771. case JDCT_FLOAT:
  151772. {
  151773. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151774. int row, col;
  151775. static const double aanscalefactor[DCTSIZE] = {
  151776. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151777. 1.0, 0.785694958, 0.541196100, 0.275899379
  151778. };
  151779. i = 0;
  151780. for (row = 0; row < DCTSIZE; row++) {
  151781. for (col = 0; col < DCTSIZE; col++) {
  151782. fmtbl[i] = (FLOAT_MULT_TYPE)
  151783. ((double) qtbl->quantval[i] *
  151784. aanscalefactor[row] * aanscalefactor[col]);
  151785. i++;
  151786. }
  151787. }
  151788. }
  151789. break;
  151790. #endif
  151791. default:
  151792. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151793. break;
  151794. }
  151795. }
  151796. }
  151797. GLOBAL(void)
  151798. jinit_inverse_dct (j_decompress_ptr cinfo)
  151799. {
  151800. my_idct_ptr idct;
  151801. int ci;
  151802. jpeg_component_info *compptr;
  151803. idct = (my_idct_ptr)
  151804. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151805. SIZEOF(my_idct_controller));
  151806. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151807. idct->pub.start_pass = start_pass;
  151808. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151809. ci++, compptr++) {
  151810. compptr->dct_table =
  151811. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151812. SIZEOF(multiplier_table));
  151813. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151814. idct->cur_method[ci] = -1;
  151815. }
  151816. }
  151817. /*** End of inlined file: jddctmgr.c ***/
  151818. #undef CONST_BITS
  151819. #undef ASSIGN_STATE
  151820. /*** Start of inlined file: jdhuff.c ***/
  151821. #define JPEG_INTERNALS
  151822. /*** Start of inlined file: jdhuff.h ***/
  151823. #ifndef __jdhuff_h__
  151824. #define __jdhuff_h__
  151825. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151826. #define jpeg_make_d_derived_tbl jMkDDerived
  151827. #define jpeg_fill_bit_buffer jFilBitBuf
  151828. #define jpeg_huff_decode jHufDecode
  151829. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151830. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151831. typedef struct {
  151832. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151833. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151834. JHUFF_TBL *pub;
  151835. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151836. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151837. } d_derived_tbl;
  151838. EXTERN(void) jpeg_make_d_derived_tbl
  151839. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151840. d_derived_tbl ** pdtbl));
  151841. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151842. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151843. typedef struct { /* Bitreading state saved across MCUs */
  151844. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151845. int bits_left; /* # of unused bits in it */
  151846. } bitread_perm_state;
  151847. typedef struct { /* Bitreading working state within an MCU */
  151848. const JOCTET * next_input_byte; /* => next byte to read from source */
  151849. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151850. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151851. int bits_left; /* # of unused bits in it */
  151852. j_decompress_ptr cinfo; /* back link to decompress master record */
  151853. } bitread_working_state;
  151854. #define BITREAD_STATE_VARS \
  151855. register bit_buf_type get_buffer; \
  151856. register int bits_left; \
  151857. bitread_working_state br_state
  151858. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151859. br_state.cinfo = cinfop; \
  151860. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151861. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151862. get_buffer = permstate.get_buffer; \
  151863. bits_left = permstate.bits_left;
  151864. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151865. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151866. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151867. permstate.get_buffer = get_buffer; \
  151868. permstate.bits_left = bits_left
  151869. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151870. { if (bits_left < (nbits)) { \
  151871. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151872. { action; } \
  151873. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151874. #define GET_BITS(nbits) \
  151875. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151876. #define PEEK_BITS(nbits) \
  151877. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151878. #define DROP_BITS(nbits) \
  151879. (bits_left -= (nbits))
  151880. EXTERN(boolean) jpeg_fill_bit_buffer
  151881. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151882. register int bits_left, int nbits));
  151883. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151884. { register int nb, look; \
  151885. if (bits_left < HUFF_LOOKAHEAD) { \
  151886. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151887. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151888. if (bits_left < HUFF_LOOKAHEAD) { \
  151889. nb = 1; goto slowlabel; \
  151890. } \
  151891. } \
  151892. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151893. if ((nb = htbl->look_nbits[look]) != 0) { \
  151894. DROP_BITS(nb); \
  151895. result = htbl->look_sym[look]; \
  151896. } else { \
  151897. nb = HUFF_LOOKAHEAD+1; \
  151898. slowlabel: \
  151899. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151900. { failaction; } \
  151901. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151902. } \
  151903. }
  151904. EXTERN(int) jpeg_huff_decode
  151905. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151906. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151907. #endif
  151908. /*** End of inlined file: jdhuff.h ***/
  151909. /* Declarations shared with jdphuff.c */
  151910. typedef struct {
  151911. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151912. } savable_state2;
  151913. #ifndef NO_STRUCT_ASSIGN
  151914. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151915. #else
  151916. #if MAX_COMPS_IN_SCAN == 4
  151917. #define ASSIGN_STATE(dest,src) \
  151918. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151919. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151920. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151921. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151922. #endif
  151923. #endif
  151924. typedef struct {
  151925. struct jpeg_entropy_decoder pub; /* public fields */
  151926. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151927. savable_state2 saved; /* Other state at start of MCU */
  151928. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151929. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151930. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151931. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151932. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151933. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151934. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151935. } huff_entropy_decoder2;
  151936. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151937. METHODDEF(void)
  151938. start_pass_huff_decoder (j_decompress_ptr cinfo)
  151939. {
  151940. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151941. int ci, blkn, dctbl, actbl;
  151942. jpeg_component_info * compptr;
  151943. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  151944. cinfo->Ah != 0 || cinfo->Al != 0)
  151945. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  151946. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151947. compptr = cinfo->cur_comp_info[ci];
  151948. dctbl = compptr->dc_tbl_no;
  151949. actbl = compptr->ac_tbl_no;
  151950. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  151951. & entropy->dc_derived_tbls[dctbl]);
  151952. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  151953. & entropy->ac_derived_tbls[actbl]);
  151954. entropy->saved.last_dc_val[ci] = 0;
  151955. }
  151956. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151957. ci = cinfo->MCU_membership[blkn];
  151958. compptr = cinfo->cur_comp_info[ci];
  151959. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  151960. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  151961. if (compptr->component_needed) {
  151962. entropy->dc_needed[blkn] = TRUE;
  151963. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  151964. } else {
  151965. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  151966. }
  151967. }
  151968. entropy->bitstate.bits_left = 0;
  151969. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  151970. entropy->pub.insufficient_data = FALSE;
  151971. entropy->restarts_to_go = cinfo->restart_interval;
  151972. }
  151973. GLOBAL(void)
  151974. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  151975. d_derived_tbl ** pdtbl)
  151976. {
  151977. JHUFF_TBL *htbl;
  151978. d_derived_tbl *dtbl;
  151979. int p, i, l, si, numsymbols;
  151980. int lookbits, ctr;
  151981. char huffsize[257];
  151982. unsigned int huffcode[257];
  151983. unsigned int code;
  151984. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  151985. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151986. htbl =
  151987. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  151988. if (htbl == NULL)
  151989. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151990. if (*pdtbl == NULL)
  151991. *pdtbl = (d_derived_tbl *)
  151992. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151993. SIZEOF(d_derived_tbl));
  151994. dtbl = *pdtbl;
  151995. dtbl->pub = htbl; /* fill in back link */
  151996. p = 0;
  151997. for (l = 1; l <= 16; l++) {
  151998. i = (int) htbl->bits[l];
  151999. if (i < 0 || p + i > 256) /* protect against table overrun */
  152000. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152001. while (i--)
  152002. huffsize[p++] = (char) l;
  152003. }
  152004. huffsize[p] = 0;
  152005. numsymbols = p;
  152006. code = 0;
  152007. si = huffsize[0];
  152008. p = 0;
  152009. while (huffsize[p]) {
  152010. while (((int) huffsize[p]) == si) {
  152011. huffcode[p++] = code;
  152012. code++;
  152013. }
  152014. if (((INT32) code) >= (((INT32) 1) << si))
  152015. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152016. code <<= 1;
  152017. si++;
  152018. }
  152019. p = 0;
  152020. for (l = 1; l <= 16; l++) {
  152021. if (htbl->bits[l]) {
  152022. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  152023. p += htbl->bits[l];
  152024. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  152025. } else {
  152026. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152027. }
  152028. }
  152029. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152030. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152031. p = 0;
  152032. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152033. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152034. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152035. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152036. dtbl->look_nbits[lookbits] = l;
  152037. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152038. lookbits++;
  152039. }
  152040. }
  152041. }
  152042. if (isDC) {
  152043. for (i = 0; i < numsymbols; i++) {
  152044. int sym = htbl->huffval[i];
  152045. if (sym < 0 || sym > 15)
  152046. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152047. }
  152048. }
  152049. }
  152050. #ifdef SLOW_SHIFT_32
  152051. #define MIN_GET_BITS 15 /* minimum allowable value */
  152052. #else
  152053. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152054. #endif
  152055. GLOBAL(boolean)
  152056. jpeg_fill_bit_buffer (bitread_working_state * state,
  152057. register bit_buf_type get_buffer, register int bits_left,
  152058. int nbits)
  152059. {
  152060. register const JOCTET * next_input_byte = state->next_input_byte;
  152061. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152062. j_decompress_ptr cinfo = state->cinfo;
  152063. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152064. while (bits_left < MIN_GET_BITS) {
  152065. register int c;
  152066. if (bytes_in_buffer == 0) {
  152067. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152068. return FALSE;
  152069. next_input_byte = cinfo->src->next_input_byte;
  152070. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152071. }
  152072. bytes_in_buffer--;
  152073. c = GETJOCTET(*next_input_byte++);
  152074. if (c == 0xFF) {
  152075. do {
  152076. if (bytes_in_buffer == 0) {
  152077. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152078. return FALSE;
  152079. next_input_byte = cinfo->src->next_input_byte;
  152080. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152081. }
  152082. bytes_in_buffer--;
  152083. c = GETJOCTET(*next_input_byte++);
  152084. } while (c == 0xFF);
  152085. if (c == 0) {
  152086. c = 0xFF;
  152087. } else {
  152088. cinfo->unread_marker = c;
  152089. goto no_more_bytes;
  152090. }
  152091. }
  152092. get_buffer = (get_buffer << 8) | c;
  152093. bits_left += 8;
  152094. } /* end while */
  152095. } else {
  152096. no_more_bytes:
  152097. if (nbits > bits_left) {
  152098. if (! cinfo->entropy->insufficient_data) {
  152099. WARNMS(cinfo, JWRN_HIT_MARKER);
  152100. cinfo->entropy->insufficient_data = TRUE;
  152101. }
  152102. get_buffer <<= MIN_GET_BITS - bits_left;
  152103. bits_left = MIN_GET_BITS;
  152104. }
  152105. }
  152106. state->next_input_byte = next_input_byte;
  152107. state->bytes_in_buffer = bytes_in_buffer;
  152108. state->get_buffer = get_buffer;
  152109. state->bits_left = bits_left;
  152110. return TRUE;
  152111. }
  152112. GLOBAL(int)
  152113. jpeg_huff_decode (bitread_working_state * state,
  152114. register bit_buf_type get_buffer, register int bits_left,
  152115. d_derived_tbl * htbl, int min_bits)
  152116. {
  152117. register int l = min_bits;
  152118. register INT32 code;
  152119. CHECK_BIT_BUFFER(*state, l, return -1);
  152120. code = GET_BITS(l);
  152121. while (code > htbl->maxcode[l]) {
  152122. code <<= 1;
  152123. CHECK_BIT_BUFFER(*state, 1, return -1);
  152124. code |= GET_BITS(1);
  152125. l++;
  152126. }
  152127. state->get_buffer = get_buffer;
  152128. state->bits_left = bits_left;
  152129. if (l > 16) {
  152130. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152131. return 0; /* fake a zero as the safest result */
  152132. }
  152133. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152134. }
  152135. LOCAL(boolean)
  152136. process_restart (j_decompress_ptr cinfo)
  152137. {
  152138. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152139. int ci;
  152140. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152141. entropy->bitstate.bits_left = 0;
  152142. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152143. return FALSE;
  152144. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152145. entropy->saved.last_dc_val[ci] = 0;
  152146. entropy->restarts_to_go = cinfo->restart_interval;
  152147. if (cinfo->unread_marker == 0)
  152148. entropy->pub.insufficient_data = FALSE;
  152149. return TRUE;
  152150. }
  152151. METHODDEF(boolean)
  152152. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152153. {
  152154. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152155. int blkn;
  152156. BITREAD_STATE_VARS;
  152157. savable_state2 state;
  152158. if (cinfo->restart_interval) {
  152159. if (entropy->restarts_to_go == 0)
  152160. if (! process_restart(cinfo))
  152161. return FALSE;
  152162. }
  152163. if (! entropy->pub.insufficient_data) {
  152164. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152165. ASSIGN_STATE(state, entropy->saved);
  152166. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152167. JBLOCKROW block = MCU_data[blkn];
  152168. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152169. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152170. register int s, k, r;
  152171. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152172. if (s) {
  152173. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152174. r = GET_BITS(s);
  152175. s = HUFF_EXTEND(r, s);
  152176. }
  152177. if (entropy->dc_needed[blkn]) {
  152178. int ci = cinfo->MCU_membership[blkn];
  152179. s += state.last_dc_val[ci];
  152180. state.last_dc_val[ci] = s;
  152181. (*block)[0] = (JCOEF) s;
  152182. }
  152183. if (entropy->ac_needed[blkn]) {
  152184. for (k = 1; k < DCTSIZE2; k++) {
  152185. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152186. r = s >> 4;
  152187. s &= 15;
  152188. if (s) {
  152189. k += r;
  152190. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152191. r = GET_BITS(s);
  152192. s = HUFF_EXTEND(r, s);
  152193. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152194. } else {
  152195. if (r != 15)
  152196. break;
  152197. k += 15;
  152198. }
  152199. }
  152200. } else {
  152201. for (k = 1; k < DCTSIZE2; k++) {
  152202. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152203. r = s >> 4;
  152204. s &= 15;
  152205. if (s) {
  152206. k += r;
  152207. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152208. DROP_BITS(s);
  152209. } else {
  152210. if (r != 15)
  152211. break;
  152212. k += 15;
  152213. }
  152214. }
  152215. }
  152216. }
  152217. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152218. ASSIGN_STATE(entropy->saved, state);
  152219. }
  152220. entropy->restarts_to_go--;
  152221. return TRUE;
  152222. }
  152223. GLOBAL(void)
  152224. jinit_huff_decoder (j_decompress_ptr cinfo)
  152225. {
  152226. huff_entropy_ptr2 entropy;
  152227. int i;
  152228. entropy = (huff_entropy_ptr2)
  152229. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152230. SIZEOF(huff_entropy_decoder2));
  152231. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152232. entropy->pub.start_pass = start_pass_huff_decoder;
  152233. entropy->pub.decode_mcu = decode_mcu;
  152234. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152235. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152236. }
  152237. }
  152238. /*** End of inlined file: jdhuff.c ***/
  152239. /*** Start of inlined file: jdinput.c ***/
  152240. #define JPEG_INTERNALS
  152241. typedef struct {
  152242. struct jpeg_input_controller pub; /* public fields */
  152243. boolean inheaders; /* TRUE until first SOS is reached */
  152244. } my_input_controller;
  152245. typedef my_input_controller * my_inputctl_ptr;
  152246. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152247. LOCAL(void)
  152248. initial_setup2 (j_decompress_ptr cinfo)
  152249. {
  152250. int ci;
  152251. jpeg_component_info *compptr;
  152252. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152253. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152254. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152255. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152256. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152257. if (cinfo->num_components > MAX_COMPONENTS)
  152258. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152259. MAX_COMPONENTS);
  152260. cinfo->max_h_samp_factor = 1;
  152261. cinfo->max_v_samp_factor = 1;
  152262. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152263. ci++, compptr++) {
  152264. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152265. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152266. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152267. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152268. compptr->h_samp_factor);
  152269. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152270. compptr->v_samp_factor);
  152271. }
  152272. cinfo->min_DCT_scaled_size = DCTSIZE;
  152273. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152274. ci++, compptr++) {
  152275. compptr->DCT_scaled_size = DCTSIZE;
  152276. compptr->width_in_blocks = (JDIMENSION)
  152277. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152278. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152279. compptr->height_in_blocks = (JDIMENSION)
  152280. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152281. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152282. compptr->downsampled_width = (JDIMENSION)
  152283. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152284. (long) cinfo->max_h_samp_factor);
  152285. compptr->downsampled_height = (JDIMENSION)
  152286. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152287. (long) cinfo->max_v_samp_factor);
  152288. compptr->component_needed = TRUE;
  152289. compptr->quant_table = NULL;
  152290. }
  152291. cinfo->total_iMCU_rows = (JDIMENSION)
  152292. jdiv_round_up((long) cinfo->image_height,
  152293. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152294. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152295. cinfo->inputctl->has_multiple_scans = TRUE;
  152296. else
  152297. cinfo->inputctl->has_multiple_scans = FALSE;
  152298. }
  152299. LOCAL(void)
  152300. per_scan_setup2 (j_decompress_ptr cinfo)
  152301. {
  152302. int ci, mcublks, tmp;
  152303. jpeg_component_info *compptr;
  152304. if (cinfo->comps_in_scan == 1) {
  152305. compptr = cinfo->cur_comp_info[0];
  152306. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152307. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152308. compptr->MCU_width = 1;
  152309. compptr->MCU_height = 1;
  152310. compptr->MCU_blocks = 1;
  152311. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152312. compptr->last_col_width = 1;
  152313. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152314. if (tmp == 0) tmp = compptr->v_samp_factor;
  152315. compptr->last_row_height = tmp;
  152316. cinfo->blocks_in_MCU = 1;
  152317. cinfo->MCU_membership[0] = 0;
  152318. } else {
  152319. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152320. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152321. MAX_COMPS_IN_SCAN);
  152322. cinfo->MCUs_per_row = (JDIMENSION)
  152323. jdiv_round_up((long) cinfo->image_width,
  152324. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152325. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152326. jdiv_round_up((long) cinfo->image_height,
  152327. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152328. cinfo->blocks_in_MCU = 0;
  152329. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152330. compptr = cinfo->cur_comp_info[ci];
  152331. compptr->MCU_width = compptr->h_samp_factor;
  152332. compptr->MCU_height = compptr->v_samp_factor;
  152333. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152334. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152335. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152336. if (tmp == 0) tmp = compptr->MCU_width;
  152337. compptr->last_col_width = tmp;
  152338. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152339. if (tmp == 0) tmp = compptr->MCU_height;
  152340. compptr->last_row_height = tmp;
  152341. mcublks = compptr->MCU_blocks;
  152342. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152343. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152344. while (mcublks-- > 0) {
  152345. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152346. }
  152347. }
  152348. }
  152349. }
  152350. LOCAL(void)
  152351. latch_quant_tables (j_decompress_ptr cinfo)
  152352. {
  152353. int ci, qtblno;
  152354. jpeg_component_info *compptr;
  152355. JQUANT_TBL * qtbl;
  152356. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152357. compptr = cinfo->cur_comp_info[ci];
  152358. if (compptr->quant_table != NULL)
  152359. continue;
  152360. qtblno = compptr->quant_tbl_no;
  152361. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152362. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152363. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152364. qtbl = (JQUANT_TBL *)
  152365. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152366. SIZEOF(JQUANT_TBL));
  152367. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152368. compptr->quant_table = qtbl;
  152369. }
  152370. }
  152371. METHODDEF(void)
  152372. start_input_pass2 (j_decompress_ptr cinfo)
  152373. {
  152374. per_scan_setup2(cinfo);
  152375. latch_quant_tables(cinfo);
  152376. (*cinfo->entropy->start_pass) (cinfo);
  152377. (*cinfo->coef->start_input_pass) (cinfo);
  152378. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152379. }
  152380. METHODDEF(void)
  152381. finish_input_pass (j_decompress_ptr cinfo)
  152382. {
  152383. cinfo->inputctl->consume_input = consume_markers;
  152384. }
  152385. METHODDEF(int)
  152386. consume_markers (j_decompress_ptr cinfo)
  152387. {
  152388. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152389. int val;
  152390. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152391. return JPEG_REACHED_EOI;
  152392. val = (*cinfo->marker->read_markers) (cinfo);
  152393. switch (val) {
  152394. case JPEG_REACHED_SOS: /* Found SOS */
  152395. if (inputctl->inheaders) { /* 1st SOS */
  152396. initial_setup2(cinfo);
  152397. inputctl->inheaders = FALSE;
  152398. } else { /* 2nd or later SOS marker */
  152399. if (! inputctl->pub.has_multiple_scans)
  152400. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152401. start_input_pass2(cinfo);
  152402. }
  152403. break;
  152404. case JPEG_REACHED_EOI: /* Found EOI */
  152405. inputctl->pub.eoi_reached = TRUE;
  152406. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152407. if (cinfo->marker->saw_SOF)
  152408. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152409. } else {
  152410. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152411. cinfo->output_scan_number = cinfo->input_scan_number;
  152412. }
  152413. break;
  152414. case JPEG_SUSPENDED:
  152415. break;
  152416. }
  152417. return val;
  152418. }
  152419. METHODDEF(void)
  152420. reset_input_controller (j_decompress_ptr cinfo)
  152421. {
  152422. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152423. inputctl->pub.consume_input = consume_markers;
  152424. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152425. inputctl->pub.eoi_reached = FALSE;
  152426. inputctl->inheaders = TRUE;
  152427. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152428. (*cinfo->marker->reset_marker_reader) (cinfo);
  152429. cinfo->coef_bits = NULL;
  152430. }
  152431. GLOBAL(void)
  152432. jinit_input_controller (j_decompress_ptr cinfo)
  152433. {
  152434. my_inputctl_ptr inputctl;
  152435. inputctl = (my_inputctl_ptr)
  152436. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152437. SIZEOF(my_input_controller));
  152438. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152439. inputctl->pub.consume_input = consume_markers;
  152440. inputctl->pub.reset_input_controller = reset_input_controller;
  152441. inputctl->pub.start_input_pass = start_input_pass2;
  152442. inputctl->pub.finish_input_pass = finish_input_pass;
  152443. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152444. inputctl->pub.eoi_reached = FALSE;
  152445. inputctl->inheaders = TRUE;
  152446. }
  152447. /*** End of inlined file: jdinput.c ***/
  152448. /*** Start of inlined file: jdmainct.c ***/
  152449. #define JPEG_INTERNALS
  152450. typedef struct {
  152451. struct jpeg_d_main_controller pub; /* public fields */
  152452. JSAMPARRAY buffer[MAX_COMPONENTS];
  152453. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152454. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152455. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152456. int whichptr; /* indicates which pointer set is now in use */
  152457. int context_state; /* process_data state machine status */
  152458. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152459. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152460. } my_main_controller4;
  152461. typedef my_main_controller4 * my_main_ptr4;
  152462. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152463. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152464. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152465. METHODDEF(void) process_data_simple_main2
  152466. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152467. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152468. METHODDEF(void) process_data_context_main
  152469. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152470. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152471. #ifdef QUANT_2PASS_SUPPORTED
  152472. METHODDEF(void) process_data_crank_post
  152473. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152474. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152475. #endif
  152476. LOCAL(void)
  152477. alloc_funny_pointers (j_decompress_ptr cinfo)
  152478. {
  152479. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152480. int ci, rgroup;
  152481. int M = cinfo->min_DCT_scaled_size;
  152482. jpeg_component_info *compptr;
  152483. JSAMPARRAY xbuf;
  152484. main_->xbuffer[0] = (JSAMPIMAGE)
  152485. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152486. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152487. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152488. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152489. ci++, compptr++) {
  152490. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152491. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152492. xbuf = (JSAMPARRAY)
  152493. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152494. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152495. xbuf += rgroup; /* want one row group at negative offsets */
  152496. main_->xbuffer[0][ci] = xbuf;
  152497. xbuf += rgroup * (M + 4);
  152498. main_->xbuffer[1][ci] = xbuf;
  152499. }
  152500. }
  152501. LOCAL(void)
  152502. make_funny_pointers (j_decompress_ptr cinfo)
  152503. {
  152504. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152505. int ci, i, rgroup;
  152506. int M = cinfo->min_DCT_scaled_size;
  152507. jpeg_component_info *compptr;
  152508. JSAMPARRAY buf, xbuf0, xbuf1;
  152509. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152510. ci++, compptr++) {
  152511. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152512. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152513. xbuf0 = main_->xbuffer[0][ci];
  152514. xbuf1 = main_->xbuffer[1][ci];
  152515. buf = main_->buffer[ci];
  152516. for (i = 0; i < rgroup * (M + 2); i++) {
  152517. xbuf0[i] = xbuf1[i] = buf[i];
  152518. }
  152519. for (i = 0; i < rgroup * 2; i++) {
  152520. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152521. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152522. }
  152523. for (i = 0; i < rgroup; i++) {
  152524. xbuf0[i - rgroup] = xbuf0[0];
  152525. }
  152526. }
  152527. }
  152528. LOCAL(void)
  152529. set_wraparound_pointers (j_decompress_ptr cinfo)
  152530. {
  152531. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152532. int ci, i, rgroup;
  152533. int M = cinfo->min_DCT_scaled_size;
  152534. jpeg_component_info *compptr;
  152535. JSAMPARRAY xbuf0, xbuf1;
  152536. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152537. ci++, compptr++) {
  152538. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152539. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152540. xbuf0 = main_->xbuffer[0][ci];
  152541. xbuf1 = main_->xbuffer[1][ci];
  152542. for (i = 0; i < rgroup; i++) {
  152543. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152544. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152545. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152546. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152547. }
  152548. }
  152549. }
  152550. LOCAL(void)
  152551. set_bottom_pointers (j_decompress_ptr cinfo)
  152552. {
  152553. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152554. int ci, i, rgroup, iMCUheight, rows_left;
  152555. jpeg_component_info *compptr;
  152556. JSAMPARRAY xbuf;
  152557. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152558. ci++, compptr++) {
  152559. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152560. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152561. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152562. if (rows_left == 0) rows_left = iMCUheight;
  152563. if (ci == 0) {
  152564. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152565. }
  152566. xbuf = main_->xbuffer[main_->whichptr][ci];
  152567. for (i = 0; i < rgroup * 2; i++) {
  152568. xbuf[rows_left + i] = xbuf[rows_left-1];
  152569. }
  152570. }
  152571. }
  152572. METHODDEF(void)
  152573. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152574. {
  152575. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152576. switch (pass_mode) {
  152577. case JBUF_PASS_THRU:
  152578. if (cinfo->upsample->need_context_rows) {
  152579. main_->pub.process_data = process_data_context_main;
  152580. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152581. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152582. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152583. main_->iMCU_row_ctr = 0;
  152584. } else {
  152585. main_->pub.process_data = process_data_simple_main2;
  152586. }
  152587. main_->buffer_full = FALSE; /* Mark buffer empty */
  152588. main_->rowgroup_ctr = 0;
  152589. break;
  152590. #ifdef QUANT_2PASS_SUPPORTED
  152591. case JBUF_CRANK_DEST:
  152592. main_->pub.process_data = process_data_crank_post;
  152593. break;
  152594. #endif
  152595. default:
  152596. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152597. break;
  152598. }
  152599. }
  152600. METHODDEF(void)
  152601. process_data_simple_main2 (j_decompress_ptr cinfo,
  152602. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152603. JDIMENSION out_rows_avail)
  152604. {
  152605. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152606. JDIMENSION rowgroups_avail;
  152607. if (! main_->buffer_full) {
  152608. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152609. return; /* suspension forced, can do nothing more */
  152610. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152611. }
  152612. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152613. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152614. &main_->rowgroup_ctr, rowgroups_avail,
  152615. output_buf, out_row_ctr, out_rows_avail);
  152616. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152617. main_->buffer_full = FALSE;
  152618. main_->rowgroup_ctr = 0;
  152619. }
  152620. }
  152621. METHODDEF(void)
  152622. process_data_context_main (j_decompress_ptr cinfo,
  152623. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152624. JDIMENSION out_rows_avail)
  152625. {
  152626. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152627. if (! main_->buffer_full) {
  152628. if (! (*cinfo->coef->decompress_data) (cinfo,
  152629. main_->xbuffer[main_->whichptr]))
  152630. return; /* suspension forced, can do nothing more */
  152631. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152632. main_->iMCU_row_ctr++; /* count rows received */
  152633. }
  152634. switch (main_->context_state) {
  152635. case CTX_POSTPONED_ROW:
  152636. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152637. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152638. output_buf, out_row_ctr, out_rows_avail);
  152639. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152640. return; /* Need to suspend */
  152641. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152642. if (*out_row_ctr >= out_rows_avail)
  152643. return; /* Postprocessor exactly filled output buf */
  152644. case CTX_PREPARE_FOR_IMCU:
  152645. main_->rowgroup_ctr = 0;
  152646. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152647. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152648. set_bottom_pointers(cinfo);
  152649. main_->context_state = CTX_PROCESS_IMCU;
  152650. case CTX_PROCESS_IMCU:
  152651. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152652. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152653. output_buf, out_row_ctr, out_rows_avail);
  152654. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152655. return; /* Need to suspend */
  152656. if (main_->iMCU_row_ctr == 1)
  152657. set_wraparound_pointers(cinfo);
  152658. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152659. main_->buffer_full = FALSE;
  152660. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152661. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152662. main_->context_state = CTX_POSTPONED_ROW;
  152663. }
  152664. }
  152665. #ifdef QUANT_2PASS_SUPPORTED
  152666. METHODDEF(void)
  152667. process_data_crank_post (j_decompress_ptr cinfo,
  152668. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152669. JDIMENSION out_rows_avail)
  152670. {
  152671. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152672. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152673. output_buf, out_row_ctr, out_rows_avail);
  152674. }
  152675. #endif /* QUANT_2PASS_SUPPORTED */
  152676. GLOBAL(void)
  152677. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152678. {
  152679. my_main_ptr4 main_;
  152680. int ci, rgroup, ngroups;
  152681. jpeg_component_info *compptr;
  152682. main_ = (my_main_ptr4)
  152683. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152684. SIZEOF(my_main_controller4));
  152685. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152686. main_->pub.start_pass = start_pass_main2;
  152687. if (need_full_buffer) /* shouldn't happen */
  152688. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152689. if (cinfo->upsample->need_context_rows) {
  152690. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152691. ERREXIT(cinfo, JERR_NOTIMPL);
  152692. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152693. ngroups = cinfo->min_DCT_scaled_size + 2;
  152694. } else {
  152695. ngroups = cinfo->min_DCT_scaled_size;
  152696. }
  152697. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152698. ci++, compptr++) {
  152699. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152700. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152701. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152702. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152703. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152704. (JDIMENSION) (rgroup * ngroups));
  152705. }
  152706. }
  152707. /*** End of inlined file: jdmainct.c ***/
  152708. /*** Start of inlined file: jdmarker.c ***/
  152709. #define JPEG_INTERNALS
  152710. typedef struct {
  152711. struct jpeg_marker_reader pub; /* public fields */
  152712. jpeg_marker_parser_method process_COM;
  152713. jpeg_marker_parser_method process_APPn[16];
  152714. unsigned int length_limit_COM;
  152715. unsigned int length_limit_APPn[16];
  152716. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152717. unsigned int bytes_read; /* data bytes read so far in marker */
  152718. } my_marker_reader;
  152719. typedef my_marker_reader * my_marker_ptr2;
  152720. #define INPUT_VARS(cinfo) \
  152721. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152722. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152723. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152724. #define INPUT_SYNC(cinfo) \
  152725. ( datasrc->next_input_byte = next_input_byte, \
  152726. datasrc->bytes_in_buffer = bytes_in_buffer )
  152727. #define INPUT_RELOAD(cinfo) \
  152728. ( next_input_byte = datasrc->next_input_byte, \
  152729. bytes_in_buffer = datasrc->bytes_in_buffer )
  152730. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152731. if (bytes_in_buffer == 0) { \
  152732. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152733. { action; } \
  152734. INPUT_RELOAD(cinfo); \
  152735. }
  152736. #define INPUT_BYTE(cinfo,V,action) \
  152737. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152738. bytes_in_buffer--; \
  152739. V = GETJOCTET(*next_input_byte++); )
  152740. #define INPUT_2BYTES(cinfo,V,action) \
  152741. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152742. bytes_in_buffer--; \
  152743. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152744. MAKE_BYTE_AVAIL(cinfo,action); \
  152745. bytes_in_buffer--; \
  152746. V += GETJOCTET(*next_input_byte++); )
  152747. LOCAL(boolean)
  152748. get_soi (j_decompress_ptr cinfo)
  152749. {
  152750. int i;
  152751. TRACEMS(cinfo, 1, JTRC_SOI);
  152752. if (cinfo->marker->saw_SOI)
  152753. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152754. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152755. cinfo->arith_dc_L[i] = 0;
  152756. cinfo->arith_dc_U[i] = 1;
  152757. cinfo->arith_ac_K[i] = 5;
  152758. }
  152759. cinfo->restart_interval = 0;
  152760. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152761. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152762. cinfo->saw_JFIF_marker = FALSE;
  152763. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152764. cinfo->JFIF_minor_version = 1;
  152765. cinfo->density_unit = 0;
  152766. cinfo->X_density = 1;
  152767. cinfo->Y_density = 1;
  152768. cinfo->saw_Adobe_marker = FALSE;
  152769. cinfo->Adobe_transform = 0;
  152770. cinfo->marker->saw_SOI = TRUE;
  152771. return TRUE;
  152772. }
  152773. LOCAL(boolean)
  152774. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152775. {
  152776. INT32 length;
  152777. int c, ci;
  152778. jpeg_component_info * compptr;
  152779. INPUT_VARS(cinfo);
  152780. cinfo->progressive_mode = is_prog;
  152781. cinfo->arith_code = is_arith;
  152782. INPUT_2BYTES(cinfo, length, return FALSE);
  152783. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152784. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152785. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152786. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152787. length -= 8;
  152788. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152789. (int) cinfo->image_width, (int) cinfo->image_height,
  152790. cinfo->num_components);
  152791. if (cinfo->marker->saw_SOF)
  152792. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152793. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152794. || cinfo->num_components <= 0)
  152795. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152796. if (length != (cinfo->num_components * 3))
  152797. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152798. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152799. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152800. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152801. cinfo->num_components * SIZEOF(jpeg_component_info));
  152802. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152803. ci++, compptr++) {
  152804. compptr->component_index = ci;
  152805. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152806. INPUT_BYTE(cinfo, c, return FALSE);
  152807. compptr->h_samp_factor = (c >> 4) & 15;
  152808. compptr->v_samp_factor = (c ) & 15;
  152809. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152810. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152811. compptr->component_id, compptr->h_samp_factor,
  152812. compptr->v_samp_factor, compptr->quant_tbl_no);
  152813. }
  152814. cinfo->marker->saw_SOF = TRUE;
  152815. INPUT_SYNC(cinfo);
  152816. return TRUE;
  152817. }
  152818. LOCAL(boolean)
  152819. get_sos (j_decompress_ptr cinfo)
  152820. {
  152821. INT32 length;
  152822. int i, ci, n, c, cc;
  152823. jpeg_component_info * compptr;
  152824. INPUT_VARS(cinfo);
  152825. if (! cinfo->marker->saw_SOF)
  152826. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152827. INPUT_2BYTES(cinfo, length, return FALSE);
  152828. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152829. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152830. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152831. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152832. cinfo->comps_in_scan = n;
  152833. for (i = 0; i < n; i++) {
  152834. INPUT_BYTE(cinfo, cc, return FALSE);
  152835. INPUT_BYTE(cinfo, c, return FALSE);
  152836. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152837. ci++, compptr++) {
  152838. if (cc == compptr->component_id)
  152839. goto id_found;
  152840. }
  152841. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152842. id_found:
  152843. cinfo->cur_comp_info[i] = compptr;
  152844. compptr->dc_tbl_no = (c >> 4) & 15;
  152845. compptr->ac_tbl_no = (c ) & 15;
  152846. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152847. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152848. }
  152849. INPUT_BYTE(cinfo, c, return FALSE);
  152850. cinfo->Ss = c;
  152851. INPUT_BYTE(cinfo, c, return FALSE);
  152852. cinfo->Se = c;
  152853. INPUT_BYTE(cinfo, c, return FALSE);
  152854. cinfo->Ah = (c >> 4) & 15;
  152855. cinfo->Al = (c ) & 15;
  152856. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152857. cinfo->Ah, cinfo->Al);
  152858. cinfo->marker->next_restart_num = 0;
  152859. cinfo->input_scan_number++;
  152860. INPUT_SYNC(cinfo);
  152861. return TRUE;
  152862. }
  152863. #ifdef D_ARITH_CODING_SUPPORTED
  152864. LOCAL(boolean)
  152865. get_dac (j_decompress_ptr cinfo)
  152866. {
  152867. INT32 length;
  152868. int index, val;
  152869. INPUT_VARS(cinfo);
  152870. INPUT_2BYTES(cinfo, length, return FALSE);
  152871. length -= 2;
  152872. while (length > 0) {
  152873. INPUT_BYTE(cinfo, index, return FALSE);
  152874. INPUT_BYTE(cinfo, val, return FALSE);
  152875. length -= 2;
  152876. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152877. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152878. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152879. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152880. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152881. } else { /* define DC table */
  152882. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152883. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152884. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152885. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152886. }
  152887. }
  152888. if (length != 0)
  152889. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152890. INPUT_SYNC(cinfo);
  152891. return TRUE;
  152892. }
  152893. #else /* ! D_ARITH_CODING_SUPPORTED */
  152894. #define get_dac(cinfo) skip_variable(cinfo)
  152895. #endif /* D_ARITH_CODING_SUPPORTED */
  152896. LOCAL(boolean)
  152897. get_dht (j_decompress_ptr cinfo)
  152898. {
  152899. INT32 length;
  152900. UINT8 bits[17];
  152901. UINT8 huffval[256];
  152902. int i, index, count;
  152903. JHUFF_TBL **htblptr;
  152904. INPUT_VARS(cinfo);
  152905. INPUT_2BYTES(cinfo, length, return FALSE);
  152906. length -= 2;
  152907. while (length > 16) {
  152908. INPUT_BYTE(cinfo, index, return FALSE);
  152909. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152910. bits[0] = 0;
  152911. count = 0;
  152912. for (i = 1; i <= 16; i++) {
  152913. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152914. count += bits[i];
  152915. }
  152916. length -= 1 + 16;
  152917. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152918. bits[1], bits[2], bits[3], bits[4],
  152919. bits[5], bits[6], bits[7], bits[8]);
  152920. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152921. bits[9], bits[10], bits[11], bits[12],
  152922. bits[13], bits[14], bits[15], bits[16]);
  152923. if (count > 256 || ((INT32) count) > length)
  152924. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152925. for (i = 0; i < count; i++)
  152926. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152927. length -= count;
  152928. if (index & 0x10) { /* AC table definition */
  152929. index -= 0x10;
  152930. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152931. } else { /* DC table definition */
  152932. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152933. }
  152934. if (index < 0 || index >= NUM_HUFF_TBLS)
  152935. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152936. if (*htblptr == NULL)
  152937. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  152938. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  152939. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  152940. }
  152941. if (length != 0)
  152942. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152943. INPUT_SYNC(cinfo);
  152944. return TRUE;
  152945. }
  152946. LOCAL(boolean)
  152947. get_dqt (j_decompress_ptr cinfo)
  152948. {
  152949. INT32 length;
  152950. int n, i, prec;
  152951. unsigned int tmp;
  152952. JQUANT_TBL *quant_ptr;
  152953. INPUT_VARS(cinfo);
  152954. INPUT_2BYTES(cinfo, length, return FALSE);
  152955. length -= 2;
  152956. while (length > 0) {
  152957. INPUT_BYTE(cinfo, n, return FALSE);
  152958. prec = n >> 4;
  152959. n &= 0x0F;
  152960. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  152961. if (n >= NUM_QUANT_TBLS)
  152962. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  152963. if (cinfo->quant_tbl_ptrs[n] == NULL)
  152964. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  152965. quant_ptr = cinfo->quant_tbl_ptrs[n];
  152966. for (i = 0; i < DCTSIZE2; i++) {
  152967. if (prec)
  152968. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152969. else
  152970. INPUT_BYTE(cinfo, tmp, return FALSE);
  152971. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  152972. }
  152973. if (cinfo->err->trace_level >= 2) {
  152974. for (i = 0; i < DCTSIZE2; i += 8) {
  152975. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  152976. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  152977. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  152978. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  152979. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  152980. }
  152981. }
  152982. length -= DCTSIZE2+1;
  152983. if (prec) length -= DCTSIZE2;
  152984. }
  152985. if (length != 0)
  152986. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152987. INPUT_SYNC(cinfo);
  152988. return TRUE;
  152989. }
  152990. LOCAL(boolean)
  152991. get_dri (j_decompress_ptr cinfo)
  152992. {
  152993. INT32 length;
  152994. unsigned int tmp;
  152995. INPUT_VARS(cinfo);
  152996. INPUT_2BYTES(cinfo, length, return FALSE);
  152997. if (length != 4)
  152998. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152999. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153000. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  153001. cinfo->restart_interval = tmp;
  153002. INPUT_SYNC(cinfo);
  153003. return TRUE;
  153004. }
  153005. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  153006. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  153007. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  153008. LOCAL(void)
  153009. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153010. unsigned int datalen, INT32 remaining)
  153011. {
  153012. INT32 totallen = (INT32) datalen + remaining;
  153013. if (datalen >= APP0_DATA_LEN &&
  153014. GETJOCTET(data[0]) == 0x4A &&
  153015. GETJOCTET(data[1]) == 0x46 &&
  153016. GETJOCTET(data[2]) == 0x49 &&
  153017. GETJOCTET(data[3]) == 0x46 &&
  153018. GETJOCTET(data[4]) == 0) {
  153019. cinfo->saw_JFIF_marker = TRUE;
  153020. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  153021. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  153022. cinfo->density_unit = GETJOCTET(data[7]);
  153023. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  153024. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  153025. if (cinfo->JFIF_major_version != 1)
  153026. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153027. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153028. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153029. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153030. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153031. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153032. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153033. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153034. totallen -= APP0_DATA_LEN;
  153035. if (totallen !=
  153036. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153037. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153038. } else if (datalen >= 6 &&
  153039. GETJOCTET(data[0]) == 0x4A &&
  153040. GETJOCTET(data[1]) == 0x46 &&
  153041. GETJOCTET(data[2]) == 0x58 &&
  153042. GETJOCTET(data[3]) == 0x58 &&
  153043. GETJOCTET(data[4]) == 0) {
  153044. switch (GETJOCTET(data[5])) {
  153045. case 0x10:
  153046. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153047. break;
  153048. case 0x11:
  153049. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153050. break;
  153051. case 0x13:
  153052. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153053. break;
  153054. default:
  153055. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153056. GETJOCTET(data[5]), (int) totallen);
  153057. break;
  153058. }
  153059. } else {
  153060. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153061. }
  153062. }
  153063. LOCAL(void)
  153064. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153065. unsigned int datalen, INT32 remaining)
  153066. {
  153067. unsigned int version, flags0, flags1, transform;
  153068. if (datalen >= APP14_DATA_LEN &&
  153069. GETJOCTET(data[0]) == 0x41 &&
  153070. GETJOCTET(data[1]) == 0x64 &&
  153071. GETJOCTET(data[2]) == 0x6F &&
  153072. GETJOCTET(data[3]) == 0x62 &&
  153073. GETJOCTET(data[4]) == 0x65) {
  153074. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153075. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153076. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153077. transform = GETJOCTET(data[11]);
  153078. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153079. cinfo->saw_Adobe_marker = TRUE;
  153080. cinfo->Adobe_transform = (UINT8) transform;
  153081. } else {
  153082. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153083. }
  153084. }
  153085. METHODDEF(boolean)
  153086. get_interesting_appn (j_decompress_ptr cinfo)
  153087. {
  153088. INT32 length;
  153089. JOCTET b[APPN_DATA_LEN];
  153090. unsigned int i, numtoread;
  153091. INPUT_VARS(cinfo);
  153092. INPUT_2BYTES(cinfo, length, return FALSE);
  153093. length -= 2;
  153094. if (length >= APPN_DATA_LEN)
  153095. numtoread = APPN_DATA_LEN;
  153096. else if (length > 0)
  153097. numtoread = (unsigned int) length;
  153098. else
  153099. numtoread = 0;
  153100. for (i = 0; i < numtoread; i++)
  153101. INPUT_BYTE(cinfo, b[i], return FALSE);
  153102. length -= numtoread;
  153103. switch (cinfo->unread_marker) {
  153104. case M_APP0:
  153105. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153106. break;
  153107. case M_APP14:
  153108. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153109. break;
  153110. default:
  153111. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153112. break;
  153113. }
  153114. INPUT_SYNC(cinfo);
  153115. if (length > 0)
  153116. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153117. return TRUE;
  153118. }
  153119. #ifdef SAVE_MARKERS_SUPPORTED
  153120. METHODDEF(boolean)
  153121. save_marker (j_decompress_ptr cinfo)
  153122. {
  153123. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153124. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153125. unsigned int bytes_read, data_length;
  153126. JOCTET FAR * data;
  153127. INT32 length = 0;
  153128. INPUT_VARS(cinfo);
  153129. if (cur_marker == NULL) {
  153130. INPUT_2BYTES(cinfo, length, return FALSE);
  153131. length -= 2;
  153132. if (length >= 0) { /* watch out for bogus length word */
  153133. unsigned int limit;
  153134. if (cinfo->unread_marker == (int) M_COM)
  153135. limit = marker->length_limit_COM;
  153136. else
  153137. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153138. if ((unsigned int) length < limit)
  153139. limit = (unsigned int) length;
  153140. cur_marker = (jpeg_saved_marker_ptr)
  153141. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153142. SIZEOF(struct jpeg_marker_struct) + limit);
  153143. cur_marker->next = NULL;
  153144. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153145. cur_marker->original_length = (unsigned int) length;
  153146. cur_marker->data_length = limit;
  153147. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153148. marker->cur_marker = cur_marker;
  153149. marker->bytes_read = 0;
  153150. bytes_read = 0;
  153151. data_length = limit;
  153152. } else {
  153153. bytes_read = data_length = 0;
  153154. data = NULL;
  153155. }
  153156. } else {
  153157. bytes_read = marker->bytes_read;
  153158. data_length = cur_marker->data_length;
  153159. data = cur_marker->data + bytes_read;
  153160. }
  153161. while (bytes_read < data_length) {
  153162. INPUT_SYNC(cinfo); /* move the restart point to here */
  153163. marker->bytes_read = bytes_read;
  153164. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153165. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153166. *data++ = *next_input_byte++;
  153167. bytes_in_buffer--;
  153168. bytes_read++;
  153169. }
  153170. }
  153171. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153172. if (cinfo->marker_list == NULL) {
  153173. cinfo->marker_list = cur_marker;
  153174. } else {
  153175. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153176. while (prev->next != NULL)
  153177. prev = prev->next;
  153178. prev->next = cur_marker;
  153179. }
  153180. data = cur_marker->data;
  153181. length = cur_marker->original_length - data_length;
  153182. }
  153183. marker->cur_marker = NULL;
  153184. switch (cinfo->unread_marker) {
  153185. case M_APP0:
  153186. examine_app0(cinfo, data, data_length, length);
  153187. break;
  153188. case M_APP14:
  153189. examine_app14(cinfo, data, data_length, length);
  153190. break;
  153191. default:
  153192. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153193. (int) (data_length + length));
  153194. break;
  153195. }
  153196. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153197. if (length > 0)
  153198. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153199. return TRUE;
  153200. }
  153201. #endif /* SAVE_MARKERS_SUPPORTED */
  153202. METHODDEF(boolean)
  153203. skip_variable (j_decompress_ptr cinfo)
  153204. {
  153205. INT32 length;
  153206. INPUT_VARS(cinfo);
  153207. INPUT_2BYTES(cinfo, length, return FALSE);
  153208. length -= 2;
  153209. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153210. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153211. if (length > 0)
  153212. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153213. return TRUE;
  153214. }
  153215. LOCAL(boolean)
  153216. next_marker (j_decompress_ptr cinfo)
  153217. {
  153218. int c;
  153219. INPUT_VARS(cinfo);
  153220. for (;;) {
  153221. INPUT_BYTE(cinfo, c, return FALSE);
  153222. while (c != 0xFF) {
  153223. cinfo->marker->discarded_bytes++;
  153224. INPUT_SYNC(cinfo);
  153225. INPUT_BYTE(cinfo, c, return FALSE);
  153226. }
  153227. do {
  153228. INPUT_BYTE(cinfo, c, return FALSE);
  153229. } while (c == 0xFF);
  153230. if (c != 0)
  153231. break; /* found a valid marker, exit loop */
  153232. cinfo->marker->discarded_bytes += 2;
  153233. INPUT_SYNC(cinfo);
  153234. }
  153235. if (cinfo->marker->discarded_bytes != 0) {
  153236. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153237. cinfo->marker->discarded_bytes = 0;
  153238. }
  153239. cinfo->unread_marker = c;
  153240. INPUT_SYNC(cinfo);
  153241. return TRUE;
  153242. }
  153243. LOCAL(boolean)
  153244. first_marker (j_decompress_ptr cinfo)
  153245. {
  153246. int c, c2;
  153247. INPUT_VARS(cinfo);
  153248. INPUT_BYTE(cinfo, c, return FALSE);
  153249. INPUT_BYTE(cinfo, c2, return FALSE);
  153250. if (c != 0xFF || c2 != (int) M_SOI)
  153251. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153252. cinfo->unread_marker = c2;
  153253. INPUT_SYNC(cinfo);
  153254. return TRUE;
  153255. }
  153256. METHODDEF(int)
  153257. read_markers (j_decompress_ptr cinfo)
  153258. {
  153259. for (;;) {
  153260. if (cinfo->unread_marker == 0) {
  153261. if (! cinfo->marker->saw_SOI) {
  153262. if (! first_marker(cinfo))
  153263. return JPEG_SUSPENDED;
  153264. } else {
  153265. if (! next_marker(cinfo))
  153266. return JPEG_SUSPENDED;
  153267. }
  153268. }
  153269. switch (cinfo->unread_marker) {
  153270. case M_SOI:
  153271. if (! get_soi(cinfo))
  153272. return JPEG_SUSPENDED;
  153273. break;
  153274. case M_SOF0: /* Baseline */
  153275. case M_SOF1: /* Extended sequential, Huffman */
  153276. if (! get_sof(cinfo, FALSE, FALSE))
  153277. return JPEG_SUSPENDED;
  153278. break;
  153279. case M_SOF2: /* Progressive, Huffman */
  153280. if (! get_sof(cinfo, TRUE, FALSE))
  153281. return JPEG_SUSPENDED;
  153282. break;
  153283. case M_SOF9: /* Extended sequential, arithmetic */
  153284. if (! get_sof(cinfo, FALSE, TRUE))
  153285. return JPEG_SUSPENDED;
  153286. break;
  153287. case M_SOF10: /* Progressive, arithmetic */
  153288. if (! get_sof(cinfo, TRUE, TRUE))
  153289. return JPEG_SUSPENDED;
  153290. break;
  153291. case M_SOF3: /* Lossless, Huffman */
  153292. case M_SOF5: /* Differential sequential, Huffman */
  153293. case M_SOF6: /* Differential progressive, Huffman */
  153294. case M_SOF7: /* Differential lossless, Huffman */
  153295. case M_JPG: /* Reserved for JPEG extensions */
  153296. case M_SOF11: /* Lossless, arithmetic */
  153297. case M_SOF13: /* Differential sequential, arithmetic */
  153298. case M_SOF14: /* Differential progressive, arithmetic */
  153299. case M_SOF15: /* Differential lossless, arithmetic */
  153300. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153301. break;
  153302. case M_SOS:
  153303. if (! get_sos(cinfo))
  153304. return JPEG_SUSPENDED;
  153305. cinfo->unread_marker = 0; /* processed the marker */
  153306. return JPEG_REACHED_SOS;
  153307. case M_EOI:
  153308. TRACEMS(cinfo, 1, JTRC_EOI);
  153309. cinfo->unread_marker = 0; /* processed the marker */
  153310. return JPEG_REACHED_EOI;
  153311. case M_DAC:
  153312. if (! get_dac(cinfo))
  153313. return JPEG_SUSPENDED;
  153314. break;
  153315. case M_DHT:
  153316. if (! get_dht(cinfo))
  153317. return JPEG_SUSPENDED;
  153318. break;
  153319. case M_DQT:
  153320. if (! get_dqt(cinfo))
  153321. return JPEG_SUSPENDED;
  153322. break;
  153323. case M_DRI:
  153324. if (! get_dri(cinfo))
  153325. return JPEG_SUSPENDED;
  153326. break;
  153327. case M_APP0:
  153328. case M_APP1:
  153329. case M_APP2:
  153330. case M_APP3:
  153331. case M_APP4:
  153332. case M_APP5:
  153333. case M_APP6:
  153334. case M_APP7:
  153335. case M_APP8:
  153336. case M_APP9:
  153337. case M_APP10:
  153338. case M_APP11:
  153339. case M_APP12:
  153340. case M_APP13:
  153341. case M_APP14:
  153342. case M_APP15:
  153343. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153344. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153345. return JPEG_SUSPENDED;
  153346. break;
  153347. case M_COM:
  153348. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153349. return JPEG_SUSPENDED;
  153350. break;
  153351. case M_RST0: /* these are all parameterless */
  153352. case M_RST1:
  153353. case M_RST2:
  153354. case M_RST3:
  153355. case M_RST4:
  153356. case M_RST5:
  153357. case M_RST6:
  153358. case M_RST7:
  153359. case M_TEM:
  153360. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153361. break;
  153362. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153363. if (! skip_variable(cinfo))
  153364. return JPEG_SUSPENDED;
  153365. break;
  153366. default: /* must be DHP, EXP, JPGn, or RESn */
  153367. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153368. break;
  153369. }
  153370. cinfo->unread_marker = 0;
  153371. } /* end loop */
  153372. }
  153373. METHODDEF(boolean)
  153374. read_restart_marker (j_decompress_ptr cinfo)
  153375. {
  153376. if (cinfo->unread_marker == 0) {
  153377. if (! next_marker(cinfo))
  153378. return FALSE;
  153379. }
  153380. if (cinfo->unread_marker ==
  153381. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153382. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153383. cinfo->unread_marker = 0;
  153384. } else {
  153385. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153386. cinfo->marker->next_restart_num))
  153387. return FALSE;
  153388. }
  153389. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153390. return TRUE;
  153391. }
  153392. GLOBAL(boolean)
  153393. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153394. {
  153395. int marker = cinfo->unread_marker;
  153396. int action = 1;
  153397. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153398. for (;;) {
  153399. if (marker < (int) M_SOF0)
  153400. action = 2; /* invalid marker */
  153401. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153402. action = 3; /* valid non-restart marker */
  153403. else {
  153404. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153405. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153406. action = 3; /* one of the next two expected restarts */
  153407. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153408. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153409. action = 2; /* a prior restart, so advance */
  153410. else
  153411. action = 1; /* desired restart or too far away */
  153412. }
  153413. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153414. switch (action) {
  153415. case 1:
  153416. cinfo->unread_marker = 0;
  153417. return TRUE;
  153418. case 2:
  153419. if (! next_marker(cinfo))
  153420. return FALSE;
  153421. marker = cinfo->unread_marker;
  153422. break;
  153423. case 3:
  153424. return TRUE;
  153425. }
  153426. } /* end loop */
  153427. }
  153428. METHODDEF(void)
  153429. reset_marker_reader (j_decompress_ptr cinfo)
  153430. {
  153431. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153432. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153433. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153434. cinfo->unread_marker = 0; /* no pending marker */
  153435. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153436. marker->pub.saw_SOF = FALSE;
  153437. marker->pub.discarded_bytes = 0;
  153438. marker->cur_marker = NULL;
  153439. }
  153440. GLOBAL(void)
  153441. jinit_marker_reader (j_decompress_ptr cinfo)
  153442. {
  153443. my_marker_ptr2 marker;
  153444. int i;
  153445. marker = (my_marker_ptr2)
  153446. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153447. SIZEOF(my_marker_reader));
  153448. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153449. marker->pub.reset_marker_reader = reset_marker_reader;
  153450. marker->pub.read_markers = read_markers;
  153451. marker->pub.read_restart_marker = read_restart_marker;
  153452. marker->process_COM = skip_variable;
  153453. marker->length_limit_COM = 0;
  153454. for (i = 0; i < 16; i++) {
  153455. marker->process_APPn[i] = skip_variable;
  153456. marker->length_limit_APPn[i] = 0;
  153457. }
  153458. marker->process_APPn[0] = get_interesting_appn;
  153459. marker->process_APPn[14] = get_interesting_appn;
  153460. reset_marker_reader(cinfo);
  153461. }
  153462. #ifdef SAVE_MARKERS_SUPPORTED
  153463. GLOBAL(void)
  153464. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153465. unsigned int length_limit)
  153466. {
  153467. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153468. long maxlength;
  153469. jpeg_marker_parser_method processor;
  153470. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153471. if (((long) length_limit) > maxlength)
  153472. length_limit = (unsigned int) maxlength;
  153473. if (length_limit) {
  153474. processor = save_marker;
  153475. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153476. length_limit = APP0_DATA_LEN;
  153477. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153478. length_limit = APP14_DATA_LEN;
  153479. } else {
  153480. processor = skip_variable;
  153481. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153482. processor = get_interesting_appn;
  153483. }
  153484. if (marker_code == (int) M_COM) {
  153485. marker->process_COM = processor;
  153486. marker->length_limit_COM = length_limit;
  153487. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153488. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153489. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153490. } else
  153491. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153492. }
  153493. #endif /* SAVE_MARKERS_SUPPORTED */
  153494. GLOBAL(void)
  153495. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153496. jpeg_marker_parser_method routine)
  153497. {
  153498. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153499. if (marker_code == (int) M_COM)
  153500. marker->process_COM = routine;
  153501. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153502. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153503. else
  153504. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153505. }
  153506. /*** End of inlined file: jdmarker.c ***/
  153507. /*** Start of inlined file: jdmaster.c ***/
  153508. #define JPEG_INTERNALS
  153509. typedef struct {
  153510. struct jpeg_decomp_master pub; /* public fields */
  153511. int pass_number; /* # of passes completed */
  153512. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153513. struct jpeg_color_quantizer * quantizer_1pass;
  153514. struct jpeg_color_quantizer * quantizer_2pass;
  153515. } my_decomp_master;
  153516. typedef my_decomp_master * my_master_ptr6;
  153517. LOCAL(boolean)
  153518. use_merged_upsample (j_decompress_ptr cinfo)
  153519. {
  153520. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153521. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153522. return FALSE;
  153523. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153524. cinfo->out_color_space != JCS_RGB ||
  153525. cinfo->out_color_components != RGB_PIXELSIZE)
  153526. return FALSE;
  153527. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153528. cinfo->comp_info[1].h_samp_factor != 1 ||
  153529. cinfo->comp_info[2].h_samp_factor != 1 ||
  153530. cinfo->comp_info[0].v_samp_factor > 2 ||
  153531. cinfo->comp_info[1].v_samp_factor != 1 ||
  153532. cinfo->comp_info[2].v_samp_factor != 1)
  153533. return FALSE;
  153534. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153535. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153536. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153537. return FALSE;
  153538. return TRUE; /* by golly, it'll work... */
  153539. #else
  153540. return FALSE;
  153541. #endif
  153542. }
  153543. GLOBAL(void)
  153544. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153545. {
  153546. #ifdef IDCT_SCALING_SUPPORTED
  153547. int ci;
  153548. jpeg_component_info *compptr;
  153549. #endif
  153550. if (cinfo->global_state != DSTATE_READY)
  153551. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153552. #ifdef IDCT_SCALING_SUPPORTED
  153553. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153554. cinfo->output_width = (JDIMENSION)
  153555. jdiv_round_up((long) cinfo->image_width, 8L);
  153556. cinfo->output_height = (JDIMENSION)
  153557. jdiv_round_up((long) cinfo->image_height, 8L);
  153558. cinfo->min_DCT_scaled_size = 1;
  153559. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153560. cinfo->output_width = (JDIMENSION)
  153561. jdiv_round_up((long) cinfo->image_width, 4L);
  153562. cinfo->output_height = (JDIMENSION)
  153563. jdiv_round_up((long) cinfo->image_height, 4L);
  153564. cinfo->min_DCT_scaled_size = 2;
  153565. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153566. cinfo->output_width = (JDIMENSION)
  153567. jdiv_round_up((long) cinfo->image_width, 2L);
  153568. cinfo->output_height = (JDIMENSION)
  153569. jdiv_round_up((long) cinfo->image_height, 2L);
  153570. cinfo->min_DCT_scaled_size = 4;
  153571. } else {
  153572. cinfo->output_width = cinfo->image_width;
  153573. cinfo->output_height = cinfo->image_height;
  153574. cinfo->min_DCT_scaled_size = DCTSIZE;
  153575. }
  153576. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153577. ci++, compptr++) {
  153578. int ssize = cinfo->min_DCT_scaled_size;
  153579. while (ssize < DCTSIZE &&
  153580. (compptr->h_samp_factor * ssize * 2 <=
  153581. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153582. (compptr->v_samp_factor * ssize * 2 <=
  153583. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153584. ssize = ssize * 2;
  153585. }
  153586. compptr->DCT_scaled_size = ssize;
  153587. }
  153588. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153589. ci++, compptr++) {
  153590. compptr->downsampled_width = (JDIMENSION)
  153591. jdiv_round_up((long) cinfo->image_width *
  153592. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153593. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153594. compptr->downsampled_height = (JDIMENSION)
  153595. jdiv_round_up((long) cinfo->image_height *
  153596. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153597. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153598. }
  153599. #else /* !IDCT_SCALING_SUPPORTED */
  153600. cinfo->output_width = cinfo->image_width;
  153601. cinfo->output_height = cinfo->image_height;
  153602. #endif /* IDCT_SCALING_SUPPORTED */
  153603. switch (cinfo->out_color_space) {
  153604. case JCS_GRAYSCALE:
  153605. cinfo->out_color_components = 1;
  153606. break;
  153607. case JCS_RGB:
  153608. #if RGB_PIXELSIZE != 3
  153609. cinfo->out_color_components = RGB_PIXELSIZE;
  153610. break;
  153611. #endif /* else share code with YCbCr */
  153612. case JCS_YCbCr:
  153613. cinfo->out_color_components = 3;
  153614. break;
  153615. case JCS_CMYK:
  153616. case JCS_YCCK:
  153617. cinfo->out_color_components = 4;
  153618. break;
  153619. default: /* else must be same colorspace as in file */
  153620. cinfo->out_color_components = cinfo->num_components;
  153621. break;
  153622. }
  153623. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153624. cinfo->out_color_components);
  153625. if (use_merged_upsample(cinfo))
  153626. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153627. else
  153628. cinfo->rec_outbuf_height = 1;
  153629. }
  153630. LOCAL(void)
  153631. prepare_range_limit_table (j_decompress_ptr cinfo)
  153632. {
  153633. JSAMPLE * table;
  153634. int i;
  153635. table = (JSAMPLE *)
  153636. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153637. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153638. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153639. cinfo->sample_range_limit = table;
  153640. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153641. for (i = 0; i <= MAXJSAMPLE; i++)
  153642. table[i] = (JSAMPLE) i;
  153643. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153644. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153645. table[i] = MAXJSAMPLE;
  153646. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153647. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153648. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153649. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153650. }
  153651. LOCAL(void)
  153652. master_selection (j_decompress_ptr cinfo)
  153653. {
  153654. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153655. boolean use_c_buffer;
  153656. long samplesperrow;
  153657. JDIMENSION jd_samplesperrow;
  153658. jpeg_calc_output_dimensions(cinfo);
  153659. prepare_range_limit_table(cinfo);
  153660. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153661. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153662. if ((long) jd_samplesperrow != samplesperrow)
  153663. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153664. master->pass_number = 0;
  153665. master->using_merged_upsample = use_merged_upsample(cinfo);
  153666. master->quantizer_1pass = NULL;
  153667. master->quantizer_2pass = NULL;
  153668. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153669. cinfo->enable_1pass_quant = FALSE;
  153670. cinfo->enable_external_quant = FALSE;
  153671. cinfo->enable_2pass_quant = FALSE;
  153672. }
  153673. if (cinfo->quantize_colors) {
  153674. if (cinfo->raw_data_out)
  153675. ERREXIT(cinfo, JERR_NOTIMPL);
  153676. if (cinfo->out_color_components != 3) {
  153677. cinfo->enable_1pass_quant = TRUE;
  153678. cinfo->enable_external_quant = FALSE;
  153679. cinfo->enable_2pass_quant = FALSE;
  153680. cinfo->colormap = NULL;
  153681. } else if (cinfo->colormap != NULL) {
  153682. cinfo->enable_external_quant = TRUE;
  153683. } else if (cinfo->two_pass_quantize) {
  153684. cinfo->enable_2pass_quant = TRUE;
  153685. } else {
  153686. cinfo->enable_1pass_quant = TRUE;
  153687. }
  153688. if (cinfo->enable_1pass_quant) {
  153689. #ifdef QUANT_1PASS_SUPPORTED
  153690. jinit_1pass_quantizer(cinfo);
  153691. master->quantizer_1pass = cinfo->cquantize;
  153692. #else
  153693. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153694. #endif
  153695. }
  153696. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153697. #ifdef QUANT_2PASS_SUPPORTED
  153698. jinit_2pass_quantizer(cinfo);
  153699. master->quantizer_2pass = cinfo->cquantize;
  153700. #else
  153701. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153702. #endif
  153703. }
  153704. }
  153705. if (! cinfo->raw_data_out) {
  153706. if (master->using_merged_upsample) {
  153707. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153708. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153709. #else
  153710. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153711. #endif
  153712. } else {
  153713. jinit_color_deconverter(cinfo);
  153714. jinit_upsampler(cinfo);
  153715. }
  153716. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153717. }
  153718. jinit_inverse_dct(cinfo);
  153719. if (cinfo->arith_code) {
  153720. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153721. } else {
  153722. if (cinfo->progressive_mode) {
  153723. #ifdef D_PROGRESSIVE_SUPPORTED
  153724. jinit_phuff_decoder(cinfo);
  153725. #else
  153726. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153727. #endif
  153728. } else
  153729. jinit_huff_decoder(cinfo);
  153730. }
  153731. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153732. jinit_d_coef_controller(cinfo, use_c_buffer);
  153733. if (! cinfo->raw_data_out)
  153734. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153735. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153736. (*cinfo->inputctl->start_input_pass) (cinfo);
  153737. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153738. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153739. cinfo->inputctl->has_multiple_scans) {
  153740. int nscans;
  153741. if (cinfo->progressive_mode) {
  153742. nscans = 2 + 3 * cinfo->num_components;
  153743. } else {
  153744. nscans = cinfo->num_components;
  153745. }
  153746. cinfo->progress->pass_counter = 0L;
  153747. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153748. cinfo->progress->completed_passes = 0;
  153749. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153750. master->pass_number++;
  153751. }
  153752. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153753. }
  153754. METHODDEF(void)
  153755. prepare_for_output_pass (j_decompress_ptr cinfo)
  153756. {
  153757. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153758. if (master->pub.is_dummy_pass) {
  153759. #ifdef QUANT_2PASS_SUPPORTED
  153760. master->pub.is_dummy_pass = FALSE;
  153761. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153762. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153763. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153764. #else
  153765. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153766. #endif /* QUANT_2PASS_SUPPORTED */
  153767. } else {
  153768. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153769. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153770. cinfo->cquantize = master->quantizer_2pass;
  153771. master->pub.is_dummy_pass = TRUE;
  153772. } else if (cinfo->enable_1pass_quant) {
  153773. cinfo->cquantize = master->quantizer_1pass;
  153774. } else {
  153775. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153776. }
  153777. }
  153778. (*cinfo->idct->start_pass) (cinfo);
  153779. (*cinfo->coef->start_output_pass) (cinfo);
  153780. if (! cinfo->raw_data_out) {
  153781. if (! master->using_merged_upsample)
  153782. (*cinfo->cconvert->start_pass) (cinfo);
  153783. (*cinfo->upsample->start_pass) (cinfo);
  153784. if (cinfo->quantize_colors)
  153785. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153786. (*cinfo->post->start_pass) (cinfo,
  153787. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153788. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153789. }
  153790. }
  153791. if (cinfo->progress != NULL) {
  153792. cinfo->progress->completed_passes = master->pass_number;
  153793. cinfo->progress->total_passes = master->pass_number +
  153794. (master->pub.is_dummy_pass ? 2 : 1);
  153795. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153796. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153797. }
  153798. }
  153799. }
  153800. METHODDEF(void)
  153801. finish_output_pass (j_decompress_ptr cinfo)
  153802. {
  153803. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153804. if (cinfo->quantize_colors)
  153805. (*cinfo->cquantize->finish_pass) (cinfo);
  153806. master->pass_number++;
  153807. }
  153808. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153809. GLOBAL(void)
  153810. jpeg_new_colormap (j_decompress_ptr cinfo)
  153811. {
  153812. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153813. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153814. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153815. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153816. cinfo->colormap != NULL) {
  153817. cinfo->cquantize = master->quantizer_2pass;
  153818. (*cinfo->cquantize->new_color_map) (cinfo);
  153819. master->pub.is_dummy_pass = FALSE; /* just in case */
  153820. } else
  153821. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153822. }
  153823. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153824. GLOBAL(void)
  153825. jinit_master_decompress (j_decompress_ptr cinfo)
  153826. {
  153827. my_master_ptr6 master;
  153828. master = (my_master_ptr6)
  153829. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153830. SIZEOF(my_decomp_master));
  153831. cinfo->master = (struct jpeg_decomp_master *) master;
  153832. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153833. master->pub.finish_output_pass = finish_output_pass;
  153834. master->pub.is_dummy_pass = FALSE;
  153835. master_selection(cinfo);
  153836. }
  153837. /*** End of inlined file: jdmaster.c ***/
  153838. #undef FIX
  153839. /*** Start of inlined file: jdmerge.c ***/
  153840. #define JPEG_INTERNALS
  153841. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153842. typedef struct {
  153843. struct jpeg_upsampler pub; /* public fields */
  153844. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153845. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153846. JSAMPARRAY output_buf));
  153847. int * Cr_r_tab; /* => table for Cr to R conversion */
  153848. int * Cb_b_tab; /* => table for Cb to B conversion */
  153849. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153850. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153851. JSAMPROW spare_row;
  153852. boolean spare_full; /* T if spare buffer is occupied */
  153853. JDIMENSION out_row_width; /* samples per output row */
  153854. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153855. } my_upsampler;
  153856. typedef my_upsampler * my_upsample_ptr;
  153857. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153858. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153859. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153860. LOCAL(void)
  153861. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153862. {
  153863. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153864. int i;
  153865. INT32 x;
  153866. SHIFT_TEMPS
  153867. upsample->Cr_r_tab = (int *)
  153868. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153869. (MAXJSAMPLE+1) * SIZEOF(int));
  153870. upsample->Cb_b_tab = (int *)
  153871. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153872. (MAXJSAMPLE+1) * SIZEOF(int));
  153873. upsample->Cr_g_tab = (INT32 *)
  153874. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153875. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153876. upsample->Cb_g_tab = (INT32 *)
  153877. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153878. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153879. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153880. upsample->Cr_r_tab[i] = (int)
  153881. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153882. upsample->Cb_b_tab[i] = (int)
  153883. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153884. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153885. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153886. }
  153887. }
  153888. METHODDEF(void)
  153889. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153890. {
  153891. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153892. upsample->spare_full = FALSE;
  153893. upsample->rows_to_go = cinfo->output_height;
  153894. }
  153895. METHODDEF(void)
  153896. merged_2v_upsample (j_decompress_ptr cinfo,
  153897. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153898. JDIMENSION in_row_groups_avail,
  153899. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153900. JDIMENSION out_rows_avail)
  153901. {
  153902. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153903. JSAMPROW work_ptrs[2];
  153904. JDIMENSION num_rows; /* number of rows returned to caller */
  153905. if (upsample->spare_full) {
  153906. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153907. 1, upsample->out_row_width);
  153908. num_rows = 1;
  153909. upsample->spare_full = FALSE;
  153910. } else {
  153911. num_rows = 2;
  153912. if (num_rows > upsample->rows_to_go)
  153913. num_rows = upsample->rows_to_go;
  153914. out_rows_avail -= *out_row_ctr;
  153915. if (num_rows > out_rows_avail)
  153916. num_rows = out_rows_avail;
  153917. work_ptrs[0] = output_buf[*out_row_ctr];
  153918. if (num_rows > 1) {
  153919. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153920. } else {
  153921. work_ptrs[1] = upsample->spare_row;
  153922. upsample->spare_full = TRUE;
  153923. }
  153924. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153925. }
  153926. *out_row_ctr += num_rows;
  153927. upsample->rows_to_go -= num_rows;
  153928. if (! upsample->spare_full)
  153929. (*in_row_group_ctr)++;
  153930. }
  153931. METHODDEF(void)
  153932. merged_1v_upsample (j_decompress_ptr cinfo,
  153933. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153934. JDIMENSION in_row_groups_avail,
  153935. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153936. JDIMENSION out_rows_avail)
  153937. {
  153938. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153939. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  153940. output_buf + *out_row_ctr);
  153941. (*out_row_ctr)++;
  153942. (*in_row_group_ctr)++;
  153943. }
  153944. METHODDEF(void)
  153945. h2v1_merged_upsample (j_decompress_ptr cinfo,
  153946. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153947. JSAMPARRAY output_buf)
  153948. {
  153949. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153950. register int y, cred, cgreen, cblue;
  153951. int cb, cr;
  153952. register JSAMPROW outptr;
  153953. JSAMPROW inptr0, inptr1, inptr2;
  153954. JDIMENSION col;
  153955. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153956. int * Crrtab = upsample->Cr_r_tab;
  153957. int * Cbbtab = upsample->Cb_b_tab;
  153958. INT32 * Crgtab = upsample->Cr_g_tab;
  153959. INT32 * Cbgtab = upsample->Cb_g_tab;
  153960. SHIFT_TEMPS
  153961. inptr0 = input_buf[0][in_row_group_ctr];
  153962. inptr1 = input_buf[1][in_row_group_ctr];
  153963. inptr2 = input_buf[2][in_row_group_ctr];
  153964. outptr = output_buf[0];
  153965. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153966. cb = GETJSAMPLE(*inptr1++);
  153967. cr = GETJSAMPLE(*inptr2++);
  153968. cred = Crrtab[cr];
  153969. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153970. cblue = Cbbtab[cb];
  153971. y = GETJSAMPLE(*inptr0++);
  153972. outptr[RGB_RED] = range_limit[y + cred];
  153973. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153974. outptr[RGB_BLUE] = range_limit[y + cblue];
  153975. outptr += RGB_PIXELSIZE;
  153976. y = GETJSAMPLE(*inptr0++);
  153977. outptr[RGB_RED] = range_limit[y + cred];
  153978. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153979. outptr[RGB_BLUE] = range_limit[y + cblue];
  153980. outptr += RGB_PIXELSIZE;
  153981. }
  153982. if (cinfo->output_width & 1) {
  153983. cb = GETJSAMPLE(*inptr1);
  153984. cr = GETJSAMPLE(*inptr2);
  153985. cred = Crrtab[cr];
  153986. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153987. cblue = Cbbtab[cb];
  153988. y = GETJSAMPLE(*inptr0);
  153989. outptr[RGB_RED] = range_limit[y + cred];
  153990. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153991. outptr[RGB_BLUE] = range_limit[y + cblue];
  153992. }
  153993. }
  153994. METHODDEF(void)
  153995. h2v2_merged_upsample (j_decompress_ptr cinfo,
  153996. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153997. JSAMPARRAY output_buf)
  153998. {
  153999. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154000. register int y, cred, cgreen, cblue;
  154001. int cb, cr;
  154002. register JSAMPROW outptr0, outptr1;
  154003. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  154004. JDIMENSION col;
  154005. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154006. int * Crrtab = upsample->Cr_r_tab;
  154007. int * Cbbtab = upsample->Cb_b_tab;
  154008. INT32 * Crgtab = upsample->Cr_g_tab;
  154009. INT32 * Cbgtab = upsample->Cb_g_tab;
  154010. SHIFT_TEMPS
  154011. inptr00 = input_buf[0][in_row_group_ctr*2];
  154012. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  154013. inptr1 = input_buf[1][in_row_group_ctr];
  154014. inptr2 = input_buf[2][in_row_group_ctr];
  154015. outptr0 = output_buf[0];
  154016. outptr1 = output_buf[1];
  154017. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154018. cb = GETJSAMPLE(*inptr1++);
  154019. cr = GETJSAMPLE(*inptr2++);
  154020. cred = Crrtab[cr];
  154021. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154022. cblue = Cbbtab[cb];
  154023. y = GETJSAMPLE(*inptr00++);
  154024. outptr0[RGB_RED] = range_limit[y + cred];
  154025. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154026. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154027. outptr0 += RGB_PIXELSIZE;
  154028. y = GETJSAMPLE(*inptr00++);
  154029. outptr0[RGB_RED] = range_limit[y + cred];
  154030. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154031. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154032. outptr0 += RGB_PIXELSIZE;
  154033. y = GETJSAMPLE(*inptr01++);
  154034. outptr1[RGB_RED] = range_limit[y + cred];
  154035. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154036. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154037. outptr1 += RGB_PIXELSIZE;
  154038. y = GETJSAMPLE(*inptr01++);
  154039. outptr1[RGB_RED] = range_limit[y + cred];
  154040. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154041. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154042. outptr1 += 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(*inptr00);
  154051. outptr0[RGB_RED] = range_limit[y + cred];
  154052. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154053. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154054. y = GETJSAMPLE(*inptr01);
  154055. outptr1[RGB_RED] = range_limit[y + cred];
  154056. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154057. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154058. }
  154059. }
  154060. GLOBAL(void)
  154061. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154062. {
  154063. my_upsample_ptr upsample;
  154064. upsample = (my_upsample_ptr)
  154065. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154066. SIZEOF(my_upsampler));
  154067. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154068. upsample->pub.start_pass = start_pass_merged_upsample;
  154069. upsample->pub.need_context_rows = FALSE;
  154070. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154071. if (cinfo->max_v_samp_factor == 2) {
  154072. upsample->pub.upsample = merged_2v_upsample;
  154073. upsample->upmethod = h2v2_merged_upsample;
  154074. upsample->spare_row = (JSAMPROW)
  154075. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154076. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154077. } else {
  154078. upsample->pub.upsample = merged_1v_upsample;
  154079. upsample->upmethod = h2v1_merged_upsample;
  154080. upsample->spare_row = NULL;
  154081. }
  154082. build_ycc_rgb_table2(cinfo);
  154083. }
  154084. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154085. /*** End of inlined file: jdmerge.c ***/
  154086. #undef ASSIGN_STATE
  154087. /*** Start of inlined file: jdphuff.c ***/
  154088. #define JPEG_INTERNALS
  154089. #ifdef D_PROGRESSIVE_SUPPORTED
  154090. typedef struct {
  154091. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154092. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154093. } savable_state3;
  154094. #ifndef NO_STRUCT_ASSIGN
  154095. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154096. #else
  154097. #if MAX_COMPS_IN_SCAN == 4
  154098. #define ASSIGN_STATE(dest,src) \
  154099. ((dest).EOBRUN = (src).EOBRUN, \
  154100. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154101. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154102. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154103. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154104. #endif
  154105. #endif
  154106. typedef struct {
  154107. struct jpeg_entropy_decoder pub; /* public fields */
  154108. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154109. savable_state3 saved; /* Other state at start of MCU */
  154110. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154111. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154112. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154113. } phuff_entropy_decoder;
  154114. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154115. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154116. JBLOCKROW *MCU_data));
  154117. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154118. JBLOCKROW *MCU_data));
  154119. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154120. JBLOCKROW *MCU_data));
  154121. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154122. JBLOCKROW *MCU_data));
  154123. METHODDEF(void)
  154124. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154125. {
  154126. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154127. boolean is_DC_band, bad;
  154128. int ci, coefi, tbl;
  154129. int *coef_bit_ptr;
  154130. jpeg_component_info * compptr;
  154131. is_DC_band = (cinfo->Ss == 0);
  154132. bad = FALSE;
  154133. if (is_DC_band) {
  154134. if (cinfo->Se != 0)
  154135. bad = TRUE;
  154136. } else {
  154137. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154138. bad = TRUE;
  154139. if (cinfo->comps_in_scan != 1)
  154140. bad = TRUE;
  154141. }
  154142. if (cinfo->Ah != 0) {
  154143. if (cinfo->Al != cinfo->Ah-1)
  154144. bad = TRUE;
  154145. }
  154146. if (cinfo->Al > 13) /* need not check for < 0 */
  154147. bad = TRUE;
  154148. if (bad)
  154149. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154150. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154151. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154152. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154153. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154154. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154155. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154156. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154157. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154158. if (cinfo->Ah != expected)
  154159. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154160. coef_bit_ptr[coefi] = cinfo->Al;
  154161. }
  154162. }
  154163. if (cinfo->Ah == 0) {
  154164. if (is_DC_band)
  154165. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154166. else
  154167. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154168. } else {
  154169. if (is_DC_band)
  154170. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154171. else
  154172. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154173. }
  154174. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154175. compptr = cinfo->cur_comp_info[ci];
  154176. if (is_DC_band) {
  154177. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154178. tbl = compptr->dc_tbl_no;
  154179. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154180. & entropy->derived_tbls[tbl]);
  154181. }
  154182. } else {
  154183. tbl = compptr->ac_tbl_no;
  154184. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154185. & entropy->derived_tbls[tbl]);
  154186. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154187. }
  154188. entropy->saved.last_dc_val[ci] = 0;
  154189. }
  154190. entropy->bitstate.bits_left = 0;
  154191. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154192. entropy->pub.insufficient_data = FALSE;
  154193. entropy->saved.EOBRUN = 0;
  154194. entropy->restarts_to_go = cinfo->restart_interval;
  154195. }
  154196. LOCAL(boolean)
  154197. process_restartp (j_decompress_ptr cinfo)
  154198. {
  154199. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154200. int ci;
  154201. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154202. entropy->bitstate.bits_left = 0;
  154203. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154204. return FALSE;
  154205. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154206. entropy->saved.last_dc_val[ci] = 0;
  154207. entropy->saved.EOBRUN = 0;
  154208. entropy->restarts_to_go = cinfo->restart_interval;
  154209. if (cinfo->unread_marker == 0)
  154210. entropy->pub.insufficient_data = FALSE;
  154211. return TRUE;
  154212. }
  154213. METHODDEF(boolean)
  154214. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154215. {
  154216. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154217. int Al = cinfo->Al;
  154218. register int s, r;
  154219. int blkn, ci;
  154220. JBLOCKROW block;
  154221. BITREAD_STATE_VARS;
  154222. savable_state3 state;
  154223. d_derived_tbl * tbl;
  154224. jpeg_component_info * compptr;
  154225. if (cinfo->restart_interval) {
  154226. if (entropy->restarts_to_go == 0)
  154227. if (! process_restartp(cinfo))
  154228. return FALSE;
  154229. }
  154230. if (! entropy->pub.insufficient_data) {
  154231. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154232. ASSIGN_STATE(state, entropy->saved);
  154233. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154234. block = MCU_data[blkn];
  154235. ci = cinfo->MCU_membership[blkn];
  154236. compptr = cinfo->cur_comp_info[ci];
  154237. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154238. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154239. if (s) {
  154240. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154241. r = GET_BITS(s);
  154242. s = HUFF_EXTEND(r, s);
  154243. }
  154244. s += state.last_dc_val[ci];
  154245. state.last_dc_val[ci] = s;
  154246. (*block)[0] = (JCOEF) (s << Al);
  154247. }
  154248. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154249. ASSIGN_STATE(entropy->saved, state);
  154250. }
  154251. entropy->restarts_to_go--;
  154252. return TRUE;
  154253. }
  154254. METHODDEF(boolean)
  154255. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154256. {
  154257. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154258. int Se = cinfo->Se;
  154259. int Al = cinfo->Al;
  154260. register int s, k, r;
  154261. unsigned int EOBRUN;
  154262. JBLOCKROW block;
  154263. BITREAD_STATE_VARS;
  154264. d_derived_tbl * tbl;
  154265. if (cinfo->restart_interval) {
  154266. if (entropy->restarts_to_go == 0)
  154267. if (! process_restartp(cinfo))
  154268. return FALSE;
  154269. }
  154270. if (! entropy->pub.insufficient_data) {
  154271. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154272. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154273. EOBRUN--; /* ...process it now (we do nothing) */
  154274. else {
  154275. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154276. block = MCU_data[0];
  154277. tbl = entropy->ac_derived_tbl;
  154278. for (k = cinfo->Ss; k <= Se; k++) {
  154279. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154280. r = s >> 4;
  154281. s &= 15;
  154282. if (s) {
  154283. k += r;
  154284. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154285. r = GET_BITS(s);
  154286. s = HUFF_EXTEND(r, s);
  154287. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154288. } else {
  154289. if (r == 15) { /* ZRL */
  154290. k += 15; /* skip 15 zeroes in band */
  154291. } else { /* EOBr, run length is 2^r + appended bits */
  154292. EOBRUN = 1 << r;
  154293. if (r) { /* EOBr, r > 0 */
  154294. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154295. r = GET_BITS(r);
  154296. EOBRUN += r;
  154297. }
  154298. EOBRUN--; /* this band is processed at this moment */
  154299. break; /* force end-of-band */
  154300. }
  154301. }
  154302. }
  154303. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154304. }
  154305. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154306. }
  154307. entropy->restarts_to_go--;
  154308. return TRUE;
  154309. }
  154310. METHODDEF(boolean)
  154311. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154312. {
  154313. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154314. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154315. int blkn;
  154316. JBLOCKROW block;
  154317. BITREAD_STATE_VARS;
  154318. if (cinfo->restart_interval) {
  154319. if (entropy->restarts_to_go == 0)
  154320. if (! process_restartp(cinfo))
  154321. return FALSE;
  154322. }
  154323. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154324. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154325. block = MCU_data[blkn];
  154326. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154327. if (GET_BITS(1))
  154328. (*block)[0] |= p1;
  154329. }
  154330. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154331. entropy->restarts_to_go--;
  154332. return TRUE;
  154333. }
  154334. METHODDEF(boolean)
  154335. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154336. {
  154337. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154338. int Se = cinfo->Se;
  154339. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154340. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154341. register int s, k, r;
  154342. unsigned int EOBRUN;
  154343. JBLOCKROW block;
  154344. JCOEFPTR thiscoef;
  154345. BITREAD_STATE_VARS;
  154346. d_derived_tbl * tbl;
  154347. int num_newnz;
  154348. int newnz_pos[DCTSIZE2];
  154349. if (cinfo->restart_interval) {
  154350. if (entropy->restarts_to_go == 0)
  154351. if (! process_restartp(cinfo))
  154352. return FALSE;
  154353. }
  154354. if (! entropy->pub.insufficient_data) {
  154355. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154356. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154357. block = MCU_data[0];
  154358. tbl = entropy->ac_derived_tbl;
  154359. num_newnz = 0;
  154360. k = cinfo->Ss;
  154361. if (EOBRUN == 0) {
  154362. for (; k <= Se; k++) {
  154363. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154364. r = s >> 4;
  154365. s &= 15;
  154366. if (s) {
  154367. if (s != 1) /* size of new coef should always be 1 */
  154368. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154369. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154370. if (GET_BITS(1))
  154371. s = p1; /* newly nonzero coef is positive */
  154372. else
  154373. s = m1; /* newly nonzero coef is negative */
  154374. } else {
  154375. if (r != 15) {
  154376. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154377. if (r) {
  154378. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154379. r = GET_BITS(r);
  154380. EOBRUN += r;
  154381. }
  154382. break; /* rest of block is handled by EOB logic */
  154383. }
  154384. }
  154385. do {
  154386. thiscoef = *block + jpeg_natural_order[k];
  154387. if (*thiscoef != 0) {
  154388. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154389. if (GET_BITS(1)) {
  154390. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154391. if (*thiscoef >= 0)
  154392. *thiscoef += p1;
  154393. else
  154394. *thiscoef += m1;
  154395. }
  154396. }
  154397. } else {
  154398. if (--r < 0)
  154399. break; /* reached target zero coefficient */
  154400. }
  154401. k++;
  154402. } while (k <= Se);
  154403. if (s) {
  154404. int pos = jpeg_natural_order[k];
  154405. (*block)[pos] = (JCOEF) s;
  154406. newnz_pos[num_newnz++] = pos;
  154407. }
  154408. }
  154409. }
  154410. if (EOBRUN > 0) {
  154411. for (; k <= Se; k++) {
  154412. thiscoef = *block + jpeg_natural_order[k];
  154413. if (*thiscoef != 0) {
  154414. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154415. if (GET_BITS(1)) {
  154416. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154417. if (*thiscoef >= 0)
  154418. *thiscoef += p1;
  154419. else
  154420. *thiscoef += m1;
  154421. }
  154422. }
  154423. }
  154424. }
  154425. EOBRUN--;
  154426. }
  154427. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154428. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154429. }
  154430. entropy->restarts_to_go--;
  154431. return TRUE;
  154432. undoit:
  154433. while (num_newnz > 0)
  154434. (*block)[newnz_pos[--num_newnz]] = 0;
  154435. return FALSE;
  154436. }
  154437. GLOBAL(void)
  154438. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154439. {
  154440. phuff_entropy_ptr2 entropy;
  154441. int *coef_bit_ptr;
  154442. int ci, i;
  154443. entropy = (phuff_entropy_ptr2)
  154444. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154445. SIZEOF(phuff_entropy_decoder));
  154446. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154447. entropy->pub.start_pass = start_pass_phuff_decoder;
  154448. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154449. entropy->derived_tbls[i] = NULL;
  154450. }
  154451. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154452. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154453. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154454. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154455. for (ci = 0; ci < cinfo->num_components; ci++)
  154456. for (i = 0; i < DCTSIZE2; i++)
  154457. *coef_bit_ptr++ = -1;
  154458. }
  154459. #endif /* D_PROGRESSIVE_SUPPORTED */
  154460. /*** End of inlined file: jdphuff.c ***/
  154461. /*** Start of inlined file: jdpostct.c ***/
  154462. #define JPEG_INTERNALS
  154463. typedef struct {
  154464. struct jpeg_d_post_controller pub; /* public fields */
  154465. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154466. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154467. JDIMENSION strip_height; /* buffer size in rows */
  154468. JDIMENSION starting_row; /* row # of first row in current strip */
  154469. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154470. } my_post_controller;
  154471. typedef my_post_controller * my_post_ptr;
  154472. METHODDEF(void) post_process_1pass
  154473. JPP((j_decompress_ptr cinfo,
  154474. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154475. JDIMENSION in_row_groups_avail,
  154476. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154477. JDIMENSION out_rows_avail));
  154478. #ifdef QUANT_2PASS_SUPPORTED
  154479. METHODDEF(void) post_process_prepass
  154480. JPP((j_decompress_ptr cinfo,
  154481. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154482. JDIMENSION in_row_groups_avail,
  154483. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154484. JDIMENSION out_rows_avail));
  154485. METHODDEF(void) post_process_2pass
  154486. JPP((j_decompress_ptr cinfo,
  154487. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154488. JDIMENSION in_row_groups_avail,
  154489. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154490. JDIMENSION out_rows_avail));
  154491. #endif
  154492. METHODDEF(void)
  154493. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154494. {
  154495. my_post_ptr post = (my_post_ptr) cinfo->post;
  154496. switch (pass_mode) {
  154497. case JBUF_PASS_THRU:
  154498. if (cinfo->quantize_colors) {
  154499. post->pub.post_process_data = post_process_1pass;
  154500. if (post->buffer == NULL) {
  154501. post->buffer = (*cinfo->mem->access_virt_sarray)
  154502. ((j_common_ptr) cinfo, post->whole_image,
  154503. (JDIMENSION) 0, post->strip_height, TRUE);
  154504. }
  154505. } else {
  154506. post->pub.post_process_data = cinfo->upsample->upsample;
  154507. }
  154508. break;
  154509. #ifdef QUANT_2PASS_SUPPORTED
  154510. case JBUF_SAVE_AND_PASS:
  154511. if (post->whole_image == NULL)
  154512. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154513. post->pub.post_process_data = post_process_prepass;
  154514. break;
  154515. case JBUF_CRANK_DEST:
  154516. if (post->whole_image == NULL)
  154517. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154518. post->pub.post_process_data = post_process_2pass;
  154519. break;
  154520. #endif /* QUANT_2PASS_SUPPORTED */
  154521. default:
  154522. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154523. break;
  154524. }
  154525. post->starting_row = post->next_row = 0;
  154526. }
  154527. METHODDEF(void)
  154528. post_process_1pass (j_decompress_ptr cinfo,
  154529. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154530. JDIMENSION in_row_groups_avail,
  154531. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154532. JDIMENSION out_rows_avail)
  154533. {
  154534. my_post_ptr post = (my_post_ptr) cinfo->post;
  154535. JDIMENSION num_rows, max_rows;
  154536. max_rows = out_rows_avail - *out_row_ctr;
  154537. if (max_rows > post->strip_height)
  154538. max_rows = post->strip_height;
  154539. num_rows = 0;
  154540. (*cinfo->upsample->upsample) (cinfo,
  154541. input_buf, in_row_group_ctr, in_row_groups_avail,
  154542. post->buffer, &num_rows, max_rows);
  154543. (*cinfo->cquantize->color_quantize) (cinfo,
  154544. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154545. *out_row_ctr += num_rows;
  154546. }
  154547. #ifdef QUANT_2PASS_SUPPORTED
  154548. METHODDEF(void)
  154549. post_process_prepass (j_decompress_ptr cinfo,
  154550. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154551. JDIMENSION in_row_groups_avail,
  154552. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154553. JDIMENSION out_rows_avail)
  154554. {
  154555. my_post_ptr post = (my_post_ptr) cinfo->post;
  154556. JDIMENSION old_next_row, num_rows;
  154557. if (post->next_row == 0) {
  154558. post->buffer = (*cinfo->mem->access_virt_sarray)
  154559. ((j_common_ptr) cinfo, post->whole_image,
  154560. post->starting_row, post->strip_height, TRUE);
  154561. }
  154562. old_next_row = post->next_row;
  154563. (*cinfo->upsample->upsample) (cinfo,
  154564. input_buf, in_row_group_ctr, in_row_groups_avail,
  154565. post->buffer, &post->next_row, post->strip_height);
  154566. if (post->next_row > old_next_row) {
  154567. num_rows = post->next_row - old_next_row;
  154568. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154569. (JSAMPARRAY) NULL, (int) num_rows);
  154570. *out_row_ctr += num_rows;
  154571. }
  154572. if (post->next_row >= post->strip_height) {
  154573. post->starting_row += post->strip_height;
  154574. post->next_row = 0;
  154575. }
  154576. }
  154577. METHODDEF(void)
  154578. post_process_2pass (j_decompress_ptr cinfo,
  154579. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154580. JDIMENSION in_row_groups_avail,
  154581. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154582. JDIMENSION out_rows_avail)
  154583. {
  154584. my_post_ptr post = (my_post_ptr) cinfo->post;
  154585. JDIMENSION num_rows, max_rows;
  154586. if (post->next_row == 0) {
  154587. post->buffer = (*cinfo->mem->access_virt_sarray)
  154588. ((j_common_ptr) cinfo, post->whole_image,
  154589. post->starting_row, post->strip_height, FALSE);
  154590. }
  154591. num_rows = post->strip_height - post->next_row; /* available in strip */
  154592. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154593. if (num_rows > max_rows)
  154594. num_rows = max_rows;
  154595. max_rows = cinfo->output_height - post->starting_row;
  154596. if (num_rows > max_rows)
  154597. num_rows = max_rows;
  154598. (*cinfo->cquantize->color_quantize) (cinfo,
  154599. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154600. (int) num_rows);
  154601. *out_row_ctr += num_rows;
  154602. post->next_row += num_rows;
  154603. if (post->next_row >= post->strip_height) {
  154604. post->starting_row += post->strip_height;
  154605. post->next_row = 0;
  154606. }
  154607. }
  154608. #endif /* QUANT_2PASS_SUPPORTED */
  154609. GLOBAL(void)
  154610. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154611. {
  154612. my_post_ptr post;
  154613. post = (my_post_ptr)
  154614. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154615. SIZEOF(my_post_controller));
  154616. cinfo->post = (struct jpeg_d_post_controller *) post;
  154617. post->pub.start_pass = start_pass_dpost;
  154618. post->whole_image = NULL; /* flag for no virtual arrays */
  154619. post->buffer = NULL; /* flag for no strip buffer */
  154620. if (cinfo->quantize_colors) {
  154621. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154622. if (need_full_buffer) {
  154623. #ifdef QUANT_2PASS_SUPPORTED
  154624. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154625. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154626. cinfo->output_width * cinfo->out_color_components,
  154627. (JDIMENSION) jround_up((long) cinfo->output_height,
  154628. (long) post->strip_height),
  154629. post->strip_height);
  154630. #else
  154631. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154632. #endif /* QUANT_2PASS_SUPPORTED */
  154633. } else {
  154634. post->buffer = (*cinfo->mem->alloc_sarray)
  154635. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154636. cinfo->output_width * cinfo->out_color_components,
  154637. post->strip_height);
  154638. }
  154639. }
  154640. }
  154641. /*** End of inlined file: jdpostct.c ***/
  154642. #undef FIX
  154643. /*** Start of inlined file: jdsample.c ***/
  154644. #define JPEG_INTERNALS
  154645. typedef JMETHOD(void, upsample1_ptr,
  154646. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154647. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154648. typedef struct {
  154649. struct jpeg_upsampler pub; /* public fields */
  154650. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154651. upsample1_ptr methods[MAX_COMPONENTS];
  154652. int next_row_out; /* counts rows emitted from color_buf */
  154653. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154654. int rowgroup_height[MAX_COMPONENTS];
  154655. UINT8 h_expand[MAX_COMPONENTS];
  154656. UINT8 v_expand[MAX_COMPONENTS];
  154657. } my_upsampler2;
  154658. typedef my_upsampler2 * my_upsample_ptr2;
  154659. METHODDEF(void)
  154660. start_pass_upsample (j_decompress_ptr cinfo)
  154661. {
  154662. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154663. upsample->next_row_out = cinfo->max_v_samp_factor;
  154664. upsample->rows_to_go = cinfo->output_height;
  154665. }
  154666. METHODDEF(void)
  154667. sep_upsample (j_decompress_ptr cinfo,
  154668. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154669. JDIMENSION in_row_groups_avail,
  154670. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154671. JDIMENSION out_rows_avail)
  154672. {
  154673. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154674. int ci;
  154675. jpeg_component_info * compptr;
  154676. JDIMENSION num_rows;
  154677. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154678. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154679. ci++, compptr++) {
  154680. (*upsample->methods[ci]) (cinfo, compptr,
  154681. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154682. upsample->color_buf + ci);
  154683. }
  154684. upsample->next_row_out = 0;
  154685. }
  154686. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154687. if (num_rows > upsample->rows_to_go)
  154688. num_rows = upsample->rows_to_go;
  154689. out_rows_avail -= *out_row_ctr;
  154690. if (num_rows > out_rows_avail)
  154691. num_rows = out_rows_avail;
  154692. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154693. (JDIMENSION) upsample->next_row_out,
  154694. output_buf + *out_row_ctr,
  154695. (int) num_rows);
  154696. *out_row_ctr += num_rows;
  154697. upsample->rows_to_go -= num_rows;
  154698. upsample->next_row_out += num_rows;
  154699. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154700. (*in_row_group_ctr)++;
  154701. }
  154702. METHODDEF(void)
  154703. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154704. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154705. {
  154706. *output_data_ptr = input_data;
  154707. }
  154708. METHODDEF(void)
  154709. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154710. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154711. {
  154712. *output_data_ptr = NULL; /* safety check */
  154713. }
  154714. METHODDEF(void)
  154715. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154716. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154717. {
  154718. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154719. JSAMPARRAY output_data = *output_data_ptr;
  154720. register JSAMPROW inptr, outptr;
  154721. register JSAMPLE invalue;
  154722. register int h;
  154723. JSAMPROW outend;
  154724. int h_expand, v_expand;
  154725. int inrow, outrow;
  154726. h_expand = upsample->h_expand[compptr->component_index];
  154727. v_expand = upsample->v_expand[compptr->component_index];
  154728. inrow = outrow = 0;
  154729. while (outrow < cinfo->max_v_samp_factor) {
  154730. inptr = input_data[inrow];
  154731. outptr = output_data[outrow];
  154732. outend = outptr + cinfo->output_width;
  154733. while (outptr < outend) {
  154734. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154735. for (h = h_expand; h > 0; h--) {
  154736. *outptr++ = invalue;
  154737. }
  154738. }
  154739. if (v_expand > 1) {
  154740. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154741. v_expand-1, cinfo->output_width);
  154742. }
  154743. inrow++;
  154744. outrow += v_expand;
  154745. }
  154746. }
  154747. METHODDEF(void)
  154748. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154749. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154750. {
  154751. JSAMPARRAY output_data = *output_data_ptr;
  154752. register JSAMPROW inptr, outptr;
  154753. register JSAMPLE invalue;
  154754. JSAMPROW outend;
  154755. int inrow;
  154756. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154757. inptr = input_data[inrow];
  154758. outptr = output_data[inrow];
  154759. outend = outptr + cinfo->output_width;
  154760. while (outptr < outend) {
  154761. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154762. *outptr++ = invalue;
  154763. *outptr++ = invalue;
  154764. }
  154765. }
  154766. }
  154767. METHODDEF(void)
  154768. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154769. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154770. {
  154771. JSAMPARRAY output_data = *output_data_ptr;
  154772. register JSAMPROW inptr, outptr;
  154773. register JSAMPLE invalue;
  154774. JSAMPROW outend;
  154775. int inrow, outrow;
  154776. inrow = outrow = 0;
  154777. while (outrow < cinfo->max_v_samp_factor) {
  154778. inptr = input_data[inrow];
  154779. outptr = output_data[outrow];
  154780. outend = outptr + cinfo->output_width;
  154781. while (outptr < outend) {
  154782. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154783. *outptr++ = invalue;
  154784. *outptr++ = invalue;
  154785. }
  154786. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154787. 1, cinfo->output_width);
  154788. inrow++;
  154789. outrow += 2;
  154790. }
  154791. }
  154792. METHODDEF(void)
  154793. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154794. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154795. {
  154796. JSAMPARRAY output_data = *output_data_ptr;
  154797. register JSAMPROW inptr, outptr;
  154798. register int invalue;
  154799. register JDIMENSION colctr;
  154800. int inrow;
  154801. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154802. inptr = input_data[inrow];
  154803. outptr = output_data[inrow];
  154804. invalue = GETJSAMPLE(*inptr++);
  154805. *outptr++ = (JSAMPLE) invalue;
  154806. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154807. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154808. invalue = GETJSAMPLE(*inptr++) * 3;
  154809. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154810. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154811. }
  154812. invalue = GETJSAMPLE(*inptr);
  154813. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154814. *outptr++ = (JSAMPLE) invalue;
  154815. }
  154816. }
  154817. METHODDEF(void)
  154818. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154819. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154820. {
  154821. JSAMPARRAY output_data = *output_data_ptr;
  154822. register JSAMPROW inptr0, inptr1, outptr;
  154823. #if BITS_IN_JSAMPLE == 8
  154824. register int thiscolsum, lastcolsum, nextcolsum;
  154825. #else
  154826. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154827. #endif
  154828. register JDIMENSION colctr;
  154829. int inrow, outrow, v;
  154830. inrow = outrow = 0;
  154831. while (outrow < cinfo->max_v_samp_factor) {
  154832. for (v = 0; v < 2; v++) {
  154833. inptr0 = input_data[inrow];
  154834. if (v == 0) /* next nearest is row above */
  154835. inptr1 = input_data[inrow-1];
  154836. else /* next nearest is row below */
  154837. inptr1 = input_data[inrow+1];
  154838. outptr = output_data[outrow++];
  154839. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154840. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154841. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154842. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154843. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154844. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154845. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154846. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154847. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154848. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154849. }
  154850. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154851. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154852. }
  154853. inrow++;
  154854. }
  154855. }
  154856. GLOBAL(void)
  154857. jinit_upsampler (j_decompress_ptr cinfo)
  154858. {
  154859. my_upsample_ptr2 upsample;
  154860. int ci;
  154861. jpeg_component_info * compptr;
  154862. boolean need_buffer, do_fancy;
  154863. int h_in_group, v_in_group, h_out_group, v_out_group;
  154864. upsample = (my_upsample_ptr2)
  154865. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154866. SIZEOF(my_upsampler2));
  154867. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154868. upsample->pub.start_pass = start_pass_upsample;
  154869. upsample->pub.upsample = sep_upsample;
  154870. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154871. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154872. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154873. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154874. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154875. ci++, compptr++) {
  154876. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154877. cinfo->min_DCT_scaled_size;
  154878. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154879. cinfo->min_DCT_scaled_size;
  154880. h_out_group = cinfo->max_h_samp_factor;
  154881. v_out_group = cinfo->max_v_samp_factor;
  154882. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154883. need_buffer = TRUE;
  154884. if (! compptr->component_needed) {
  154885. upsample->methods[ci] = noop_upsample;
  154886. need_buffer = FALSE;
  154887. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154888. upsample->methods[ci] = fullsize_upsample;
  154889. need_buffer = FALSE;
  154890. } else if (h_in_group * 2 == h_out_group &&
  154891. v_in_group == v_out_group) {
  154892. if (do_fancy && compptr->downsampled_width > 2)
  154893. upsample->methods[ci] = h2v1_fancy_upsample;
  154894. else
  154895. upsample->methods[ci] = h2v1_upsample;
  154896. } else if (h_in_group * 2 == h_out_group &&
  154897. v_in_group * 2 == v_out_group) {
  154898. if (do_fancy && compptr->downsampled_width > 2) {
  154899. upsample->methods[ci] = h2v2_fancy_upsample;
  154900. upsample->pub.need_context_rows = TRUE;
  154901. } else
  154902. upsample->methods[ci] = h2v2_upsample;
  154903. } else if ((h_out_group % h_in_group) == 0 &&
  154904. (v_out_group % v_in_group) == 0) {
  154905. upsample->methods[ci] = int_upsample;
  154906. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154907. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154908. } else
  154909. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154910. if (need_buffer) {
  154911. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154912. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154913. (JDIMENSION) jround_up((long) cinfo->output_width,
  154914. (long) cinfo->max_h_samp_factor),
  154915. (JDIMENSION) cinfo->max_v_samp_factor);
  154916. }
  154917. }
  154918. }
  154919. /*** End of inlined file: jdsample.c ***/
  154920. /*** Start of inlined file: jdtrans.c ***/
  154921. #define JPEG_INTERNALS
  154922. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154923. GLOBAL(jvirt_barray_ptr *)
  154924. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154925. {
  154926. if (cinfo->global_state == DSTATE_READY) {
  154927. transdecode_master_selection(cinfo);
  154928. cinfo->global_state = DSTATE_RDCOEFS;
  154929. }
  154930. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154931. for (;;) {
  154932. int retcode;
  154933. if (cinfo->progress != NULL)
  154934. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154935. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154936. if (retcode == JPEG_SUSPENDED)
  154937. return NULL;
  154938. if (retcode == JPEG_REACHED_EOI)
  154939. break;
  154940. if (cinfo->progress != NULL &&
  154941. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  154942. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  154943. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  154944. }
  154945. }
  154946. }
  154947. cinfo->global_state = DSTATE_STOPPING;
  154948. }
  154949. if ((cinfo->global_state == DSTATE_STOPPING ||
  154950. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  154951. return cinfo->coef->coef_arrays;
  154952. }
  154953. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154954. return NULL; /* keep compiler happy */
  154955. }
  154956. LOCAL(void)
  154957. transdecode_master_selection (j_decompress_ptr cinfo)
  154958. {
  154959. cinfo->buffered_image = TRUE;
  154960. if (cinfo->arith_code) {
  154961. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154962. } else {
  154963. if (cinfo->progressive_mode) {
  154964. #ifdef D_PROGRESSIVE_SUPPORTED
  154965. jinit_phuff_decoder(cinfo);
  154966. #else
  154967. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154968. #endif
  154969. } else
  154970. jinit_huff_decoder(cinfo);
  154971. }
  154972. jinit_d_coef_controller(cinfo, TRUE);
  154973. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154974. (*cinfo->inputctl->start_input_pass) (cinfo);
  154975. if (cinfo->progress != NULL) {
  154976. int nscans;
  154977. if (cinfo->progressive_mode) {
  154978. nscans = 2 + 3 * cinfo->num_components;
  154979. } else if (cinfo->inputctl->has_multiple_scans) {
  154980. nscans = cinfo->num_components;
  154981. } else {
  154982. nscans = 1;
  154983. }
  154984. cinfo->progress->pass_counter = 0L;
  154985. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154986. cinfo->progress->completed_passes = 0;
  154987. cinfo->progress->total_passes = 1;
  154988. }
  154989. }
  154990. /*** End of inlined file: jdtrans.c ***/
  154991. /*** Start of inlined file: jfdctflt.c ***/
  154992. #define JPEG_INTERNALS
  154993. #ifdef DCT_FLOAT_SUPPORTED
  154994. #if DCTSIZE != 8
  154995. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154996. #endif
  154997. GLOBAL(void)
  154998. jpeg_fdct_float (FAST_FLOAT * data)
  154999. {
  155000. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155001. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155002. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  155003. FAST_FLOAT *dataptr;
  155004. int ctr;
  155005. dataptr = data;
  155006. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155007. tmp0 = dataptr[0] + dataptr[7];
  155008. tmp7 = dataptr[0] - dataptr[7];
  155009. tmp1 = dataptr[1] + dataptr[6];
  155010. tmp6 = dataptr[1] - dataptr[6];
  155011. tmp2 = dataptr[2] + dataptr[5];
  155012. tmp5 = dataptr[2] - dataptr[5];
  155013. tmp3 = dataptr[3] + dataptr[4];
  155014. tmp4 = dataptr[3] - dataptr[4];
  155015. tmp10 = tmp0 + tmp3; /* phase 2 */
  155016. tmp13 = tmp0 - tmp3;
  155017. tmp11 = tmp1 + tmp2;
  155018. tmp12 = tmp1 - tmp2;
  155019. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155020. dataptr[4] = tmp10 - tmp11;
  155021. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155022. dataptr[2] = tmp13 + z1; /* phase 5 */
  155023. dataptr[6] = tmp13 - z1;
  155024. tmp10 = tmp4 + tmp5; /* phase 2 */
  155025. tmp11 = tmp5 + tmp6;
  155026. tmp12 = tmp6 + tmp7;
  155027. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155028. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155029. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155030. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155031. z11 = tmp7 + z3; /* phase 5 */
  155032. z13 = tmp7 - z3;
  155033. dataptr[5] = z13 + z2; /* phase 6 */
  155034. dataptr[3] = z13 - z2;
  155035. dataptr[1] = z11 + z4;
  155036. dataptr[7] = z11 - z4;
  155037. dataptr += DCTSIZE; /* advance pointer to next row */
  155038. }
  155039. dataptr = data;
  155040. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155041. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155042. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155043. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155044. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155045. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155046. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155047. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155048. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155049. tmp10 = tmp0 + tmp3; /* phase 2 */
  155050. tmp13 = tmp0 - tmp3;
  155051. tmp11 = tmp1 + tmp2;
  155052. tmp12 = tmp1 - tmp2;
  155053. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155054. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155055. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155056. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155057. dataptr[DCTSIZE*6] = tmp13 - z1;
  155058. tmp10 = tmp4 + tmp5; /* phase 2 */
  155059. tmp11 = tmp5 + tmp6;
  155060. tmp12 = tmp6 + tmp7;
  155061. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155062. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155063. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155064. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155065. z11 = tmp7 + z3; /* phase 5 */
  155066. z13 = tmp7 - z3;
  155067. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155068. dataptr[DCTSIZE*3] = z13 - z2;
  155069. dataptr[DCTSIZE*1] = z11 + z4;
  155070. dataptr[DCTSIZE*7] = z11 - z4;
  155071. dataptr++; /* advance pointer to next column */
  155072. }
  155073. }
  155074. #endif /* DCT_FLOAT_SUPPORTED */
  155075. /*** End of inlined file: jfdctflt.c ***/
  155076. /*** Start of inlined file: jfdctint.c ***/
  155077. #define JPEG_INTERNALS
  155078. #ifdef DCT_ISLOW_SUPPORTED
  155079. #if DCTSIZE != 8
  155080. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155081. #endif
  155082. #if BITS_IN_JSAMPLE == 8
  155083. #define CONST_BITS 13
  155084. #define PASS1_BITS 2
  155085. #else
  155086. #define CONST_BITS 13
  155087. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155088. #endif
  155089. #if CONST_BITS == 13
  155090. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155091. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155092. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155093. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155094. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155095. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155096. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155097. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155098. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155099. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155100. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155101. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155102. #else
  155103. #define FIX_0_298631336 FIX(0.298631336)
  155104. #define FIX_0_390180644 FIX(0.390180644)
  155105. #define FIX_0_541196100 FIX(0.541196100)
  155106. #define FIX_0_765366865 FIX(0.765366865)
  155107. #define FIX_0_899976223 FIX(0.899976223)
  155108. #define FIX_1_175875602 FIX(1.175875602)
  155109. #define FIX_1_501321110 FIX(1.501321110)
  155110. #define FIX_1_847759065 FIX(1.847759065)
  155111. #define FIX_1_961570560 FIX(1.961570560)
  155112. #define FIX_2_053119869 FIX(2.053119869)
  155113. #define FIX_2_562915447 FIX(2.562915447)
  155114. #define FIX_3_072711026 FIX(3.072711026)
  155115. #endif
  155116. #if BITS_IN_JSAMPLE == 8
  155117. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155118. #else
  155119. #define MULTIPLY(var,const) ((var) * (const))
  155120. #endif
  155121. GLOBAL(void)
  155122. jpeg_fdct_islow (DCTELEM * data)
  155123. {
  155124. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155125. INT32 tmp10, tmp11, tmp12, tmp13;
  155126. INT32 z1, z2, z3, z4, z5;
  155127. DCTELEM *dataptr;
  155128. int ctr;
  155129. SHIFT_TEMPS
  155130. dataptr = data;
  155131. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155132. tmp0 = dataptr[0] + dataptr[7];
  155133. tmp7 = dataptr[0] - dataptr[7];
  155134. tmp1 = dataptr[1] + dataptr[6];
  155135. tmp6 = dataptr[1] - dataptr[6];
  155136. tmp2 = dataptr[2] + dataptr[5];
  155137. tmp5 = dataptr[2] - dataptr[5];
  155138. tmp3 = dataptr[3] + dataptr[4];
  155139. tmp4 = dataptr[3] - dataptr[4];
  155140. tmp10 = tmp0 + tmp3;
  155141. tmp13 = tmp0 - tmp3;
  155142. tmp11 = tmp1 + tmp2;
  155143. tmp12 = tmp1 - tmp2;
  155144. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155145. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155146. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155147. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155148. CONST_BITS-PASS1_BITS);
  155149. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155150. CONST_BITS-PASS1_BITS);
  155151. z1 = tmp4 + tmp7;
  155152. z2 = tmp5 + tmp6;
  155153. z3 = tmp4 + tmp6;
  155154. z4 = tmp5 + tmp7;
  155155. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155156. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155157. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155158. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155159. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155160. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155161. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155162. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155163. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155164. z3 += z5;
  155165. z4 += z5;
  155166. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155167. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155168. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155169. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155170. dataptr += DCTSIZE; /* advance pointer to next row */
  155171. }
  155172. dataptr = data;
  155173. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155174. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155175. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155176. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155177. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155178. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155179. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155180. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155181. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155182. tmp10 = tmp0 + tmp3;
  155183. tmp13 = tmp0 - tmp3;
  155184. tmp11 = tmp1 + tmp2;
  155185. tmp12 = tmp1 - tmp2;
  155186. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155187. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155188. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155189. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155190. CONST_BITS+PASS1_BITS);
  155191. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155192. CONST_BITS+PASS1_BITS);
  155193. z1 = tmp4 + tmp7;
  155194. z2 = tmp5 + tmp6;
  155195. z3 = tmp4 + tmp6;
  155196. z4 = tmp5 + tmp7;
  155197. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155198. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155199. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155200. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155201. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155202. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155203. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155204. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155205. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155206. z3 += z5;
  155207. z4 += z5;
  155208. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155209. CONST_BITS+PASS1_BITS);
  155210. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155211. CONST_BITS+PASS1_BITS);
  155212. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155213. CONST_BITS+PASS1_BITS);
  155214. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155215. CONST_BITS+PASS1_BITS);
  155216. dataptr++; /* advance pointer to next column */
  155217. }
  155218. }
  155219. #endif /* DCT_ISLOW_SUPPORTED */
  155220. /*** End of inlined file: jfdctint.c ***/
  155221. #undef CONST_BITS
  155222. #undef MULTIPLY
  155223. #undef FIX_0_541196100
  155224. /*** Start of inlined file: jfdctfst.c ***/
  155225. #define JPEG_INTERNALS
  155226. #ifdef DCT_IFAST_SUPPORTED
  155227. #if DCTSIZE != 8
  155228. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155229. #endif
  155230. #define CONST_BITS 8
  155231. #if CONST_BITS == 8
  155232. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155233. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155234. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155235. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155236. #else
  155237. #define FIX_0_382683433 FIX(0.382683433)
  155238. #define FIX_0_541196100 FIX(0.541196100)
  155239. #define FIX_0_707106781 FIX(0.707106781)
  155240. #define FIX_1_306562965 FIX(1.306562965)
  155241. #endif
  155242. #ifndef USE_ACCURATE_ROUNDING
  155243. #undef DESCALE
  155244. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155245. #endif
  155246. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155247. GLOBAL(void)
  155248. jpeg_fdct_ifast (DCTELEM * data)
  155249. {
  155250. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155251. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155252. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155253. DCTELEM *dataptr;
  155254. int ctr;
  155255. SHIFT_TEMPS
  155256. dataptr = data;
  155257. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155258. tmp0 = dataptr[0] + dataptr[7];
  155259. tmp7 = dataptr[0] - dataptr[7];
  155260. tmp1 = dataptr[1] + dataptr[6];
  155261. tmp6 = dataptr[1] - dataptr[6];
  155262. tmp2 = dataptr[2] + dataptr[5];
  155263. tmp5 = dataptr[2] - dataptr[5];
  155264. tmp3 = dataptr[3] + dataptr[4];
  155265. tmp4 = dataptr[3] - dataptr[4];
  155266. tmp10 = tmp0 + tmp3; /* phase 2 */
  155267. tmp13 = tmp0 - tmp3;
  155268. tmp11 = tmp1 + tmp2;
  155269. tmp12 = tmp1 - tmp2;
  155270. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155271. dataptr[4] = tmp10 - tmp11;
  155272. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155273. dataptr[2] = tmp13 + z1; /* phase 5 */
  155274. dataptr[6] = tmp13 - z1;
  155275. tmp10 = tmp4 + tmp5; /* phase 2 */
  155276. tmp11 = tmp5 + tmp6;
  155277. tmp12 = tmp6 + tmp7;
  155278. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155279. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155280. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155281. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155282. z11 = tmp7 + z3; /* phase 5 */
  155283. z13 = tmp7 - z3;
  155284. dataptr[5] = z13 + z2; /* phase 6 */
  155285. dataptr[3] = z13 - z2;
  155286. dataptr[1] = z11 + z4;
  155287. dataptr[7] = z11 - z4;
  155288. dataptr += DCTSIZE; /* advance pointer to next row */
  155289. }
  155290. dataptr = data;
  155291. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155292. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155293. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155294. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155295. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155296. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155297. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155298. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155299. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155300. tmp10 = tmp0 + tmp3; /* phase 2 */
  155301. tmp13 = tmp0 - tmp3;
  155302. tmp11 = tmp1 + tmp2;
  155303. tmp12 = tmp1 - tmp2;
  155304. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155305. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155306. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155307. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155308. dataptr[DCTSIZE*6] = tmp13 - z1;
  155309. tmp10 = tmp4 + tmp5; /* phase 2 */
  155310. tmp11 = tmp5 + tmp6;
  155311. tmp12 = tmp6 + tmp7;
  155312. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155313. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155314. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155315. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155316. z11 = tmp7 + z3; /* phase 5 */
  155317. z13 = tmp7 - z3;
  155318. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155319. dataptr[DCTSIZE*3] = z13 - z2;
  155320. dataptr[DCTSIZE*1] = z11 + z4;
  155321. dataptr[DCTSIZE*7] = z11 - z4;
  155322. dataptr++; /* advance pointer to next column */
  155323. }
  155324. }
  155325. #endif /* DCT_IFAST_SUPPORTED */
  155326. /*** End of inlined file: jfdctfst.c ***/
  155327. #undef FIX_0_541196100
  155328. /*** Start of inlined file: jidctflt.c ***/
  155329. #define JPEG_INTERNALS
  155330. #ifdef DCT_FLOAT_SUPPORTED
  155331. #if DCTSIZE != 8
  155332. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155333. #endif
  155334. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155335. GLOBAL(void)
  155336. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155337. JCOEFPTR coef_block,
  155338. JSAMPARRAY output_buf, JDIMENSION output_col)
  155339. {
  155340. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155341. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155342. FAST_FLOAT z5, z10, z11, z12, z13;
  155343. JCOEFPTR inptr;
  155344. FLOAT_MULT_TYPE * quantptr;
  155345. FAST_FLOAT * wsptr;
  155346. JSAMPROW outptr;
  155347. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155348. int ctr;
  155349. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155350. SHIFT_TEMPS
  155351. inptr = coef_block;
  155352. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155353. wsptr = workspace;
  155354. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155355. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155356. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155357. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155358. inptr[DCTSIZE*7] == 0) {
  155359. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155360. wsptr[DCTSIZE*0] = dcval;
  155361. wsptr[DCTSIZE*1] = dcval;
  155362. wsptr[DCTSIZE*2] = dcval;
  155363. wsptr[DCTSIZE*3] = dcval;
  155364. wsptr[DCTSIZE*4] = dcval;
  155365. wsptr[DCTSIZE*5] = dcval;
  155366. wsptr[DCTSIZE*6] = dcval;
  155367. wsptr[DCTSIZE*7] = dcval;
  155368. inptr++; /* advance pointers to next column */
  155369. quantptr++;
  155370. wsptr++;
  155371. continue;
  155372. }
  155373. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155374. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155375. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155376. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155377. tmp10 = tmp0 + tmp2; /* phase 3 */
  155378. tmp11 = tmp0 - tmp2;
  155379. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155380. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155381. tmp0 = tmp10 + tmp13; /* phase 2 */
  155382. tmp3 = tmp10 - tmp13;
  155383. tmp1 = tmp11 + tmp12;
  155384. tmp2 = tmp11 - tmp12;
  155385. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155386. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155387. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155388. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155389. z13 = tmp6 + tmp5; /* phase 6 */
  155390. z10 = tmp6 - tmp5;
  155391. z11 = tmp4 + tmp7;
  155392. z12 = tmp4 - tmp7;
  155393. tmp7 = z11 + z13; /* phase 5 */
  155394. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155395. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155396. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155397. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155398. tmp6 = tmp12 - tmp7; /* phase 2 */
  155399. tmp5 = tmp11 - tmp6;
  155400. tmp4 = tmp10 + tmp5;
  155401. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155402. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155403. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155404. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155405. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155406. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155407. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155408. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155409. inptr++; /* advance pointers to next column */
  155410. quantptr++;
  155411. wsptr++;
  155412. }
  155413. wsptr = workspace;
  155414. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155415. outptr = output_buf[ctr] + output_col;
  155416. tmp10 = wsptr[0] + wsptr[4];
  155417. tmp11 = wsptr[0] - wsptr[4];
  155418. tmp13 = wsptr[2] + wsptr[6];
  155419. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155420. tmp0 = tmp10 + tmp13;
  155421. tmp3 = tmp10 - tmp13;
  155422. tmp1 = tmp11 + tmp12;
  155423. tmp2 = tmp11 - tmp12;
  155424. z13 = wsptr[5] + wsptr[3];
  155425. z10 = wsptr[5] - wsptr[3];
  155426. z11 = wsptr[1] + wsptr[7];
  155427. z12 = wsptr[1] - wsptr[7];
  155428. tmp7 = z11 + z13;
  155429. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155430. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155431. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155432. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155433. tmp6 = tmp12 - tmp7;
  155434. tmp5 = tmp11 - tmp6;
  155435. tmp4 = tmp10 + tmp5;
  155436. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155437. & RANGE_MASK];
  155438. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155439. & RANGE_MASK];
  155440. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155441. & RANGE_MASK];
  155442. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155443. & RANGE_MASK];
  155444. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155445. & RANGE_MASK];
  155446. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155447. & RANGE_MASK];
  155448. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155449. & RANGE_MASK];
  155450. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155451. & RANGE_MASK];
  155452. wsptr += DCTSIZE; /* advance pointer to next row */
  155453. }
  155454. }
  155455. #endif /* DCT_FLOAT_SUPPORTED */
  155456. /*** End of inlined file: jidctflt.c ***/
  155457. #undef CONST_BITS
  155458. #undef FIX_1_847759065
  155459. #undef MULTIPLY
  155460. #undef DEQUANTIZE
  155461. #undef DESCALE
  155462. /*** Start of inlined file: jidctfst.c ***/
  155463. #define JPEG_INTERNALS
  155464. #ifdef DCT_IFAST_SUPPORTED
  155465. #if DCTSIZE != 8
  155466. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155467. #endif
  155468. #if BITS_IN_JSAMPLE == 8
  155469. #define CONST_BITS 8
  155470. #define PASS1_BITS 2
  155471. #else
  155472. #define CONST_BITS 8
  155473. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155474. #endif
  155475. #if CONST_BITS == 8
  155476. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155477. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155478. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155479. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155480. #else
  155481. #define FIX_1_082392200 FIX(1.082392200)
  155482. #define FIX_1_414213562 FIX(1.414213562)
  155483. #define FIX_1_847759065 FIX(1.847759065)
  155484. #define FIX_2_613125930 FIX(2.613125930)
  155485. #endif
  155486. #ifndef USE_ACCURATE_ROUNDING
  155487. #undef DESCALE
  155488. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155489. #endif
  155490. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155491. #if BITS_IN_JSAMPLE == 8
  155492. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155493. #else
  155494. #define DEQUANTIZE(coef,quantval) \
  155495. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155496. #endif
  155497. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155498. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155499. #if BITS_IN_JSAMPLE == 8
  155500. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155501. #else
  155502. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155503. #endif
  155504. #define IRIGHT_SHIFT(x,shft) \
  155505. ((ishift_temp = (x)) < 0 ? \
  155506. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155507. (ishift_temp >> (shft)))
  155508. #else
  155509. #define ISHIFT_TEMPS
  155510. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155511. #endif
  155512. #ifdef USE_ACCURATE_ROUNDING
  155513. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155514. #else
  155515. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155516. #endif
  155517. GLOBAL(void)
  155518. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155519. JCOEFPTR coef_block,
  155520. JSAMPARRAY output_buf, JDIMENSION output_col)
  155521. {
  155522. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155523. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155524. DCTELEM z5, z10, z11, z12, z13;
  155525. JCOEFPTR inptr;
  155526. IFAST_MULT_TYPE * quantptr;
  155527. int * wsptr;
  155528. JSAMPROW outptr;
  155529. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155530. int ctr;
  155531. int workspace[DCTSIZE2]; /* buffers data between passes */
  155532. SHIFT_TEMPS /* for DESCALE */
  155533. ISHIFT_TEMPS /* for IDESCALE */
  155534. inptr = coef_block;
  155535. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155536. wsptr = workspace;
  155537. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155538. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155539. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155540. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155541. inptr[DCTSIZE*7] == 0) {
  155542. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155543. wsptr[DCTSIZE*0] = dcval;
  155544. wsptr[DCTSIZE*1] = dcval;
  155545. wsptr[DCTSIZE*2] = dcval;
  155546. wsptr[DCTSIZE*3] = dcval;
  155547. wsptr[DCTSIZE*4] = dcval;
  155548. wsptr[DCTSIZE*5] = dcval;
  155549. wsptr[DCTSIZE*6] = dcval;
  155550. wsptr[DCTSIZE*7] = dcval;
  155551. inptr++; /* advance pointers to next column */
  155552. quantptr++;
  155553. wsptr++;
  155554. continue;
  155555. }
  155556. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155557. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155558. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155559. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155560. tmp10 = tmp0 + tmp2; /* phase 3 */
  155561. tmp11 = tmp0 - tmp2;
  155562. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155563. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155564. tmp0 = tmp10 + tmp13; /* phase 2 */
  155565. tmp3 = tmp10 - tmp13;
  155566. tmp1 = tmp11 + tmp12;
  155567. tmp2 = tmp11 - tmp12;
  155568. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155569. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155570. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155571. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155572. z13 = tmp6 + tmp5; /* phase 6 */
  155573. z10 = tmp6 - tmp5;
  155574. z11 = tmp4 + tmp7;
  155575. z12 = tmp4 - tmp7;
  155576. tmp7 = z11 + z13; /* phase 5 */
  155577. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155578. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155579. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155580. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155581. tmp6 = tmp12 - tmp7; /* phase 2 */
  155582. tmp5 = tmp11 - tmp6;
  155583. tmp4 = tmp10 + tmp5;
  155584. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155585. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155586. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155587. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155588. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155589. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155590. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155591. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155592. inptr++; /* advance pointers to next column */
  155593. quantptr++;
  155594. wsptr++;
  155595. }
  155596. wsptr = workspace;
  155597. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155598. outptr = output_buf[ctr] + output_col;
  155599. #ifndef NO_ZERO_ROW_TEST
  155600. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155601. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155602. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155603. & RANGE_MASK];
  155604. outptr[0] = dcval;
  155605. outptr[1] = dcval;
  155606. outptr[2] = dcval;
  155607. outptr[3] = dcval;
  155608. outptr[4] = dcval;
  155609. outptr[5] = dcval;
  155610. outptr[6] = dcval;
  155611. outptr[7] = dcval;
  155612. wsptr += DCTSIZE; /* advance pointer to next row */
  155613. continue;
  155614. }
  155615. #endif
  155616. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155617. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155618. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155619. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155620. - tmp13;
  155621. tmp0 = tmp10 + tmp13;
  155622. tmp3 = tmp10 - tmp13;
  155623. tmp1 = tmp11 + tmp12;
  155624. tmp2 = tmp11 - tmp12;
  155625. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155626. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155627. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155628. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155629. tmp7 = z11 + z13; /* phase 5 */
  155630. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155631. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155632. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155633. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155634. tmp6 = tmp12 - tmp7; /* phase 2 */
  155635. tmp5 = tmp11 - tmp6;
  155636. tmp4 = tmp10 + tmp5;
  155637. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155638. & RANGE_MASK];
  155639. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155640. & RANGE_MASK];
  155641. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155642. & RANGE_MASK];
  155643. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155644. & RANGE_MASK];
  155645. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155646. & RANGE_MASK];
  155647. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155648. & RANGE_MASK];
  155649. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155650. & RANGE_MASK];
  155651. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155652. & RANGE_MASK];
  155653. wsptr += DCTSIZE; /* advance pointer to next row */
  155654. }
  155655. }
  155656. #endif /* DCT_IFAST_SUPPORTED */
  155657. /*** End of inlined file: jidctfst.c ***/
  155658. #undef CONST_BITS
  155659. #undef FIX_1_847759065
  155660. #undef MULTIPLY
  155661. #undef DEQUANTIZE
  155662. /*** Start of inlined file: jidctint.c ***/
  155663. #define JPEG_INTERNALS
  155664. #ifdef DCT_ISLOW_SUPPORTED
  155665. #if DCTSIZE != 8
  155666. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155667. #endif
  155668. #if BITS_IN_JSAMPLE == 8
  155669. #define CONST_BITS 13
  155670. #define PASS1_BITS 2
  155671. #else
  155672. #define CONST_BITS 13
  155673. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155674. #endif
  155675. #if CONST_BITS == 13
  155676. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155677. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155678. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155679. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155680. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155681. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155682. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155683. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155684. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155685. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155686. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155687. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155688. #else
  155689. #define FIX_0_298631336 FIX(0.298631336)
  155690. #define FIX_0_390180644 FIX(0.390180644)
  155691. #define FIX_0_541196100 FIX(0.541196100)
  155692. #define FIX_0_765366865 FIX(0.765366865)
  155693. #define FIX_0_899976223 FIX(0.899976223)
  155694. #define FIX_1_175875602 FIX(1.175875602)
  155695. #define FIX_1_501321110 FIX(1.501321110)
  155696. #define FIX_1_847759065 FIX(1.847759065)
  155697. #define FIX_1_961570560 FIX(1.961570560)
  155698. #define FIX_2_053119869 FIX(2.053119869)
  155699. #define FIX_2_562915447 FIX(2.562915447)
  155700. #define FIX_3_072711026 FIX(3.072711026)
  155701. #endif
  155702. #if BITS_IN_JSAMPLE == 8
  155703. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155704. #else
  155705. #define MULTIPLY(var,const) ((var) * (const))
  155706. #endif
  155707. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155708. GLOBAL(void)
  155709. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155710. JCOEFPTR coef_block,
  155711. JSAMPARRAY output_buf, JDIMENSION output_col)
  155712. {
  155713. INT32 tmp0, tmp1, tmp2, tmp3;
  155714. INT32 tmp10, tmp11, tmp12, tmp13;
  155715. INT32 z1, z2, z3, z4, z5;
  155716. JCOEFPTR inptr;
  155717. ISLOW_MULT_TYPE * quantptr;
  155718. int * wsptr;
  155719. JSAMPROW outptr;
  155720. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155721. int ctr;
  155722. int workspace[DCTSIZE2]; /* buffers data between passes */
  155723. SHIFT_TEMPS
  155724. inptr = coef_block;
  155725. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155726. wsptr = workspace;
  155727. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155728. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155729. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155730. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155731. inptr[DCTSIZE*7] == 0) {
  155732. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155733. wsptr[DCTSIZE*0] = dcval;
  155734. wsptr[DCTSIZE*1] = dcval;
  155735. wsptr[DCTSIZE*2] = dcval;
  155736. wsptr[DCTSIZE*3] = dcval;
  155737. wsptr[DCTSIZE*4] = dcval;
  155738. wsptr[DCTSIZE*5] = dcval;
  155739. wsptr[DCTSIZE*6] = dcval;
  155740. wsptr[DCTSIZE*7] = dcval;
  155741. inptr++; /* advance pointers to next column */
  155742. quantptr++;
  155743. wsptr++;
  155744. continue;
  155745. }
  155746. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155747. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155748. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155749. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155750. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155751. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155752. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155753. tmp0 = (z2 + z3) << CONST_BITS;
  155754. tmp1 = (z2 - z3) << CONST_BITS;
  155755. tmp10 = tmp0 + tmp3;
  155756. tmp13 = tmp0 - tmp3;
  155757. tmp11 = tmp1 + tmp2;
  155758. tmp12 = tmp1 - tmp2;
  155759. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155760. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155761. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155762. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155763. z1 = tmp0 + tmp3;
  155764. z2 = tmp1 + tmp2;
  155765. z3 = tmp0 + tmp2;
  155766. z4 = tmp1 + tmp3;
  155767. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155768. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155769. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155770. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155771. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155772. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155773. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155774. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155775. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155776. z3 += z5;
  155777. z4 += z5;
  155778. tmp0 += z1 + z3;
  155779. tmp1 += z2 + z4;
  155780. tmp2 += z2 + z3;
  155781. tmp3 += z1 + z4;
  155782. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155783. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155784. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155785. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155786. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155787. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155788. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155789. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155790. inptr++; /* advance pointers to next column */
  155791. quantptr++;
  155792. wsptr++;
  155793. }
  155794. wsptr = workspace;
  155795. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155796. outptr = output_buf[ctr] + output_col;
  155797. #ifndef NO_ZERO_ROW_TEST
  155798. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155799. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155800. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155801. & RANGE_MASK];
  155802. outptr[0] = dcval;
  155803. outptr[1] = dcval;
  155804. outptr[2] = dcval;
  155805. outptr[3] = dcval;
  155806. outptr[4] = dcval;
  155807. outptr[5] = dcval;
  155808. outptr[6] = dcval;
  155809. outptr[7] = dcval;
  155810. wsptr += DCTSIZE; /* advance pointer to next row */
  155811. continue;
  155812. }
  155813. #endif
  155814. z2 = (INT32) wsptr[2];
  155815. z3 = (INT32) wsptr[6];
  155816. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155817. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155818. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155819. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155820. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155821. tmp10 = tmp0 + tmp3;
  155822. tmp13 = tmp0 - tmp3;
  155823. tmp11 = tmp1 + tmp2;
  155824. tmp12 = tmp1 - tmp2;
  155825. tmp0 = (INT32) wsptr[7];
  155826. tmp1 = (INT32) wsptr[5];
  155827. tmp2 = (INT32) wsptr[3];
  155828. tmp3 = (INT32) wsptr[1];
  155829. z1 = tmp0 + tmp3;
  155830. z2 = tmp1 + tmp2;
  155831. z3 = tmp0 + tmp2;
  155832. z4 = tmp1 + tmp3;
  155833. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155834. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155835. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155836. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155837. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155838. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155839. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155840. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155841. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155842. z3 += z5;
  155843. z4 += z5;
  155844. tmp0 += z1 + z3;
  155845. tmp1 += z2 + z4;
  155846. tmp2 += z2 + z3;
  155847. tmp3 += z1 + z4;
  155848. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155849. CONST_BITS+PASS1_BITS+3)
  155850. & RANGE_MASK];
  155851. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155852. CONST_BITS+PASS1_BITS+3)
  155853. & RANGE_MASK];
  155854. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155855. CONST_BITS+PASS1_BITS+3)
  155856. & RANGE_MASK];
  155857. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155858. CONST_BITS+PASS1_BITS+3)
  155859. & RANGE_MASK];
  155860. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155861. CONST_BITS+PASS1_BITS+3)
  155862. & RANGE_MASK];
  155863. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155864. CONST_BITS+PASS1_BITS+3)
  155865. & RANGE_MASK];
  155866. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155867. CONST_BITS+PASS1_BITS+3)
  155868. & RANGE_MASK];
  155869. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155870. CONST_BITS+PASS1_BITS+3)
  155871. & RANGE_MASK];
  155872. wsptr += DCTSIZE; /* advance pointer to next row */
  155873. }
  155874. }
  155875. #endif /* DCT_ISLOW_SUPPORTED */
  155876. /*** End of inlined file: jidctint.c ***/
  155877. /*** Start of inlined file: jidctred.c ***/
  155878. #define JPEG_INTERNALS
  155879. #ifdef IDCT_SCALING_SUPPORTED
  155880. #if DCTSIZE != 8
  155881. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155882. #endif
  155883. #if BITS_IN_JSAMPLE == 8
  155884. #define CONST_BITS 13
  155885. #define PASS1_BITS 2
  155886. #else
  155887. #define CONST_BITS 13
  155888. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155889. #endif
  155890. #if CONST_BITS == 13
  155891. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155892. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155893. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155894. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155895. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155896. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155897. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155898. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155899. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155900. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155901. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155902. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155903. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155904. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155905. #else
  155906. #define FIX_0_211164243 FIX(0.211164243)
  155907. #define FIX_0_509795579 FIX(0.509795579)
  155908. #define FIX_0_601344887 FIX(0.601344887)
  155909. #define FIX_0_720959822 FIX(0.720959822)
  155910. #define FIX_0_765366865 FIX(0.765366865)
  155911. #define FIX_0_850430095 FIX(0.850430095)
  155912. #define FIX_0_899976223 FIX(0.899976223)
  155913. #define FIX_1_061594337 FIX(1.061594337)
  155914. #define FIX_1_272758580 FIX(1.272758580)
  155915. #define FIX_1_451774981 FIX(1.451774981)
  155916. #define FIX_1_847759065 FIX(1.847759065)
  155917. #define FIX_2_172734803 FIX(2.172734803)
  155918. #define FIX_2_562915447 FIX(2.562915447)
  155919. #define FIX_3_624509785 FIX(3.624509785)
  155920. #endif
  155921. #if BITS_IN_JSAMPLE == 8
  155922. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155923. #else
  155924. #define MULTIPLY(var,const) ((var) * (const))
  155925. #endif
  155926. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155927. GLOBAL(void)
  155928. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155929. JCOEFPTR coef_block,
  155930. JSAMPARRAY output_buf, JDIMENSION output_col)
  155931. {
  155932. INT32 tmp0, tmp2, tmp10, tmp12;
  155933. INT32 z1, z2, z3, z4;
  155934. JCOEFPTR inptr;
  155935. ISLOW_MULT_TYPE * quantptr;
  155936. int * wsptr;
  155937. JSAMPROW outptr;
  155938. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155939. int ctr;
  155940. int workspace[DCTSIZE*4]; /* buffers data between passes */
  155941. SHIFT_TEMPS
  155942. inptr = coef_block;
  155943. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155944. wsptr = workspace;
  155945. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155946. if (ctr == DCTSIZE-4)
  155947. continue;
  155948. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155949. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  155950. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  155951. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155952. wsptr[DCTSIZE*0] = dcval;
  155953. wsptr[DCTSIZE*1] = dcval;
  155954. wsptr[DCTSIZE*2] = dcval;
  155955. wsptr[DCTSIZE*3] = dcval;
  155956. continue;
  155957. }
  155958. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155959. tmp0 <<= (CONST_BITS+1);
  155960. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155961. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155962. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  155963. tmp10 = tmp0 + tmp2;
  155964. tmp12 = tmp0 - tmp2;
  155965. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155966. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155967. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155968. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155969. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155970. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155971. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155972. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155973. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155974. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155975. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155976. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155977. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  155978. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  155979. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  155980. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  155981. }
  155982. wsptr = workspace;
  155983. for (ctr = 0; ctr < 4; ctr++) {
  155984. outptr = output_buf[ctr] + output_col;
  155985. #ifndef NO_ZERO_ROW_TEST
  155986. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  155987. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155988. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155989. & RANGE_MASK];
  155990. outptr[0] = dcval;
  155991. outptr[1] = dcval;
  155992. outptr[2] = dcval;
  155993. outptr[3] = dcval;
  155994. wsptr += DCTSIZE; /* advance pointer to next row */
  155995. continue;
  155996. }
  155997. #endif
  155998. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  155999. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  156000. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  156001. tmp10 = tmp0 + tmp2;
  156002. tmp12 = tmp0 - tmp2;
  156003. z1 = (INT32) wsptr[7];
  156004. z2 = (INT32) wsptr[5];
  156005. z3 = (INT32) wsptr[3];
  156006. z4 = (INT32) wsptr[1];
  156007. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156008. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156009. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156010. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156011. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156012. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156013. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156014. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156015. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  156016. CONST_BITS+PASS1_BITS+3+1)
  156017. & RANGE_MASK];
  156018. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  156019. CONST_BITS+PASS1_BITS+3+1)
  156020. & RANGE_MASK];
  156021. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  156022. CONST_BITS+PASS1_BITS+3+1)
  156023. & RANGE_MASK];
  156024. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  156025. CONST_BITS+PASS1_BITS+3+1)
  156026. & RANGE_MASK];
  156027. wsptr += DCTSIZE; /* advance pointer to next row */
  156028. }
  156029. }
  156030. GLOBAL(void)
  156031. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156032. JCOEFPTR coef_block,
  156033. JSAMPARRAY output_buf, JDIMENSION output_col)
  156034. {
  156035. INT32 tmp0, tmp10, z1;
  156036. JCOEFPTR inptr;
  156037. ISLOW_MULT_TYPE * quantptr;
  156038. int * wsptr;
  156039. JSAMPROW outptr;
  156040. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156041. int ctr;
  156042. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156043. SHIFT_TEMPS
  156044. inptr = coef_block;
  156045. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156046. wsptr = workspace;
  156047. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156048. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156049. continue;
  156050. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156051. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156052. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156053. wsptr[DCTSIZE*0] = dcval;
  156054. wsptr[DCTSIZE*1] = dcval;
  156055. continue;
  156056. }
  156057. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156058. tmp10 = z1 << (CONST_BITS+2);
  156059. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156060. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156061. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156062. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156063. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156064. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156065. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156066. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156067. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156068. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156069. }
  156070. wsptr = workspace;
  156071. for (ctr = 0; ctr < 2; ctr++) {
  156072. outptr = output_buf[ctr] + output_col;
  156073. #ifndef NO_ZERO_ROW_TEST
  156074. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156075. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156076. & RANGE_MASK];
  156077. outptr[0] = dcval;
  156078. outptr[1] = dcval;
  156079. wsptr += DCTSIZE; /* advance pointer to next row */
  156080. continue;
  156081. }
  156082. #endif
  156083. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156084. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156085. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156086. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156087. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156088. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156089. CONST_BITS+PASS1_BITS+3+2)
  156090. & RANGE_MASK];
  156091. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156092. CONST_BITS+PASS1_BITS+3+2)
  156093. & RANGE_MASK];
  156094. wsptr += DCTSIZE; /* advance pointer to next row */
  156095. }
  156096. }
  156097. GLOBAL(void)
  156098. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156099. JCOEFPTR coef_block,
  156100. JSAMPARRAY output_buf, JDIMENSION output_col)
  156101. {
  156102. int dcval;
  156103. ISLOW_MULT_TYPE * quantptr;
  156104. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156105. SHIFT_TEMPS
  156106. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156107. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156108. dcval = (int) DESCALE((INT32) dcval, 3);
  156109. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156110. }
  156111. #endif /* IDCT_SCALING_SUPPORTED */
  156112. /*** End of inlined file: jidctred.c ***/
  156113. /*** Start of inlined file: jmemmgr.c ***/
  156114. #define JPEG_INTERNALS
  156115. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156116. /*** Start of inlined file: jmemsys.h ***/
  156117. #ifndef __jmemsys_h__
  156118. #define __jmemsys_h__
  156119. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156120. #define jpeg_get_small jGetSmall
  156121. #define jpeg_free_small jFreeSmall
  156122. #define jpeg_get_large jGetLarge
  156123. #define jpeg_free_large jFreeLarge
  156124. #define jpeg_mem_available jMemAvail
  156125. #define jpeg_open_backing_store jOpenBackStore
  156126. #define jpeg_mem_init jMemInit
  156127. #define jpeg_mem_term jMemTerm
  156128. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156129. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156130. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156131. size_t sizeofobject));
  156132. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156133. size_t sizeofobject));
  156134. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156135. size_t sizeofobject));
  156136. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156137. #define MAX_ALLOC_CHUNK 1000000000L
  156138. #endif
  156139. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156140. long min_bytes_needed,
  156141. long max_bytes_needed,
  156142. long already_allocated));
  156143. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156144. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156145. typedef unsigned short XMSH; /* type of extended-memory handles */
  156146. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156147. typedef union {
  156148. short file_handle; /* DOS file handle if it's a temp file */
  156149. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156150. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156151. } handle_union;
  156152. #endif /* USE_MSDOS_MEMMGR */
  156153. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156154. #include <Files.h>
  156155. #endif /* USE_MAC_MEMMGR */
  156156. //typedef struct backing_store_struct * backing_store_ptr;
  156157. typedef struct backing_store_struct {
  156158. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156159. struct backing_store_struct *info,
  156160. void FAR * buffer_address,
  156161. long file_offset, long byte_count));
  156162. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156163. struct backing_store_struct *info,
  156164. void FAR * buffer_address,
  156165. long file_offset, long byte_count));
  156166. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156167. struct backing_store_struct *info));
  156168. #ifdef USE_MSDOS_MEMMGR
  156169. handle_union handle; /* reference to backing-store storage object */
  156170. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156171. #else
  156172. #ifdef USE_MAC_MEMMGR
  156173. short temp_file; /* file reference number to temp file */
  156174. FSSpec tempSpec; /* the FSSpec for the temp file */
  156175. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156176. #else
  156177. FILE * temp_file; /* stdio reference to temp file */
  156178. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156179. #endif
  156180. #endif
  156181. } backing_store_info;
  156182. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156183. struct backing_store_struct *info,
  156184. long total_bytes_needed));
  156185. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156186. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156187. #endif
  156188. /*** End of inlined file: jmemsys.h ***/
  156189. /* import the system-dependent declarations */
  156190. #ifndef NO_GETENV
  156191. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156192. extern char * getenv JPP((const char * name));
  156193. #endif
  156194. #endif
  156195. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156196. #define ALIGN_TYPE double
  156197. #endif
  156198. typedef union small_pool_struct * small_pool_ptr;
  156199. typedef union small_pool_struct {
  156200. struct {
  156201. small_pool_ptr next; /* next in list of pools */
  156202. size_t bytes_used; /* how many bytes already used within pool */
  156203. size_t bytes_left; /* bytes still available in this pool */
  156204. } hdr;
  156205. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156206. } small_pool_hdr;
  156207. typedef union large_pool_struct FAR * large_pool_ptr;
  156208. typedef union large_pool_struct {
  156209. struct {
  156210. large_pool_ptr next; /* next in list of pools */
  156211. size_t bytes_used; /* how many bytes already used within pool */
  156212. size_t bytes_left; /* bytes still available in this pool */
  156213. } hdr;
  156214. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156215. } large_pool_hdr;
  156216. typedef struct {
  156217. struct jpeg_memory_mgr pub; /* public fields */
  156218. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156219. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156220. jvirt_sarray_ptr virt_sarray_list;
  156221. jvirt_barray_ptr virt_barray_list;
  156222. long total_space_allocated;
  156223. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156224. } my_memory_mgr;
  156225. typedef my_memory_mgr * my_mem_ptr;
  156226. struct jvirt_sarray_control {
  156227. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156228. JDIMENSION rows_in_array; /* total virtual array height */
  156229. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156230. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156231. JDIMENSION rows_in_mem; /* height of memory buffer */
  156232. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156233. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156234. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156235. boolean pre_zero; /* pre-zero mode requested? */
  156236. boolean dirty; /* do current buffer contents need written? */
  156237. boolean b_s_open; /* is backing-store data valid? */
  156238. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156239. backing_store_info b_s_info; /* System-dependent control info */
  156240. };
  156241. struct jvirt_barray_control {
  156242. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156243. JDIMENSION rows_in_array; /* total virtual array height */
  156244. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156245. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156246. JDIMENSION rows_in_mem; /* height of memory buffer */
  156247. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156248. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156249. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156250. boolean pre_zero; /* pre-zero mode requested? */
  156251. boolean dirty; /* do current buffer contents need written? */
  156252. boolean b_s_open; /* is backing-store data valid? */
  156253. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156254. backing_store_info b_s_info; /* System-dependent control info */
  156255. };
  156256. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156257. LOCAL(void)
  156258. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156259. {
  156260. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156261. small_pool_ptr shdr_ptr;
  156262. large_pool_ptr lhdr_ptr;
  156263. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156264. pool_id, mem->total_space_allocated);
  156265. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156266. lhdr_ptr = lhdr_ptr->hdr.next) {
  156267. fprintf(stderr, " Large chunk used %ld\n",
  156268. (long) lhdr_ptr->hdr.bytes_used);
  156269. }
  156270. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156271. shdr_ptr = shdr_ptr->hdr.next) {
  156272. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156273. (long) shdr_ptr->hdr.bytes_used,
  156274. (long) shdr_ptr->hdr.bytes_left);
  156275. }
  156276. }
  156277. #endif /* MEM_STATS */
  156278. LOCAL(void)
  156279. out_of_memory (j_common_ptr cinfo, int which)
  156280. {
  156281. #ifdef MEM_STATS
  156282. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156283. #endif
  156284. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156285. }
  156286. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156287. {
  156288. 1600, /* first PERMANENT pool */
  156289. 16000 /* first IMAGE pool */
  156290. };
  156291. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156292. {
  156293. 0, /* additional PERMANENT pools */
  156294. 5000 /* additional IMAGE pools */
  156295. };
  156296. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156297. METHODDEF(void *)
  156298. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156299. {
  156300. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156301. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156302. char * data_ptr;
  156303. size_t odd_bytes, min_request, slop;
  156304. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156305. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156306. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156307. if (odd_bytes > 0)
  156308. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156309. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156310. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156311. prev_hdr_ptr = NULL;
  156312. hdr_ptr = mem->small_list[pool_id];
  156313. while (hdr_ptr != NULL) {
  156314. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156315. break; /* found pool with enough space */
  156316. prev_hdr_ptr = hdr_ptr;
  156317. hdr_ptr = hdr_ptr->hdr.next;
  156318. }
  156319. if (hdr_ptr == NULL) {
  156320. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156321. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156322. slop = first_pool_slop[pool_id];
  156323. else
  156324. slop = extra_pool_slop[pool_id];
  156325. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156326. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156327. for (;;) {
  156328. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156329. if (hdr_ptr != NULL)
  156330. break;
  156331. slop /= 2;
  156332. if (slop < MIN_SLOP) /* give up when it gets real small */
  156333. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156334. }
  156335. mem->total_space_allocated += min_request + slop;
  156336. hdr_ptr->hdr.next = NULL;
  156337. hdr_ptr->hdr.bytes_used = 0;
  156338. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156339. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156340. mem->small_list[pool_id] = hdr_ptr;
  156341. else
  156342. prev_hdr_ptr->hdr.next = hdr_ptr;
  156343. }
  156344. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156345. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156346. hdr_ptr->hdr.bytes_used += sizeofobject;
  156347. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156348. return (void *) data_ptr;
  156349. }
  156350. METHODDEF(void FAR *)
  156351. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156352. {
  156353. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156354. large_pool_ptr hdr_ptr;
  156355. size_t odd_bytes;
  156356. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156357. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156358. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156359. if (odd_bytes > 0)
  156360. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156361. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156362. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156363. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156364. SIZEOF(large_pool_hdr));
  156365. if (hdr_ptr == NULL)
  156366. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156367. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156368. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156369. hdr_ptr->hdr.bytes_used = sizeofobject;
  156370. hdr_ptr->hdr.bytes_left = 0;
  156371. mem->large_list[pool_id] = hdr_ptr;
  156372. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156373. }
  156374. METHODDEF(JSAMPARRAY)
  156375. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156376. JDIMENSION samplesperrow, JDIMENSION numrows)
  156377. {
  156378. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156379. JSAMPARRAY result;
  156380. JSAMPROW workspace;
  156381. JDIMENSION rowsperchunk, currow, i;
  156382. long ltemp;
  156383. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156384. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156385. if (ltemp <= 0)
  156386. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156387. if (ltemp < (long) numrows)
  156388. rowsperchunk = (JDIMENSION) ltemp;
  156389. else
  156390. rowsperchunk = numrows;
  156391. mem->last_rowsperchunk = rowsperchunk;
  156392. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156393. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156394. currow = 0;
  156395. while (currow < numrows) {
  156396. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156397. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156398. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156399. * SIZEOF(JSAMPLE)));
  156400. for (i = rowsperchunk; i > 0; i--) {
  156401. result[currow++] = workspace;
  156402. workspace += samplesperrow;
  156403. }
  156404. }
  156405. return result;
  156406. }
  156407. METHODDEF(JBLOCKARRAY)
  156408. alloc_barray (j_common_ptr cinfo, int pool_id,
  156409. JDIMENSION blocksperrow, JDIMENSION numrows)
  156410. {
  156411. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156412. JBLOCKARRAY result;
  156413. JBLOCKROW workspace;
  156414. JDIMENSION rowsperchunk, currow, i;
  156415. long ltemp;
  156416. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156417. ((long) blocksperrow * SIZEOF(JBLOCK));
  156418. if (ltemp <= 0)
  156419. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156420. if (ltemp < (long) numrows)
  156421. rowsperchunk = (JDIMENSION) ltemp;
  156422. else
  156423. rowsperchunk = numrows;
  156424. mem->last_rowsperchunk = rowsperchunk;
  156425. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156426. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156427. currow = 0;
  156428. while (currow < numrows) {
  156429. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156430. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156431. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156432. * SIZEOF(JBLOCK)));
  156433. for (i = rowsperchunk; i > 0; i--) {
  156434. result[currow++] = workspace;
  156435. workspace += blocksperrow;
  156436. }
  156437. }
  156438. return result;
  156439. }
  156440. METHODDEF(jvirt_sarray_ptr)
  156441. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156442. JDIMENSION samplesperrow, JDIMENSION numrows,
  156443. JDIMENSION maxaccess)
  156444. {
  156445. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156446. jvirt_sarray_ptr result;
  156447. if (pool_id != JPOOL_IMAGE)
  156448. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156449. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156450. SIZEOF(struct jvirt_sarray_control));
  156451. result->mem_buffer = NULL; /* marks array not yet realized */
  156452. result->rows_in_array = numrows;
  156453. result->samplesperrow = samplesperrow;
  156454. result->maxaccess = maxaccess;
  156455. result->pre_zero = pre_zero;
  156456. result->b_s_open = FALSE; /* no associated backing-store object */
  156457. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156458. mem->virt_sarray_list = result;
  156459. return result;
  156460. }
  156461. METHODDEF(jvirt_barray_ptr)
  156462. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156463. JDIMENSION blocksperrow, JDIMENSION numrows,
  156464. JDIMENSION maxaccess)
  156465. {
  156466. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156467. jvirt_barray_ptr result;
  156468. if (pool_id != JPOOL_IMAGE)
  156469. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156470. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156471. SIZEOF(struct jvirt_barray_control));
  156472. result->mem_buffer = NULL; /* marks array not yet realized */
  156473. result->rows_in_array = numrows;
  156474. result->blocksperrow = blocksperrow;
  156475. result->maxaccess = maxaccess;
  156476. result->pre_zero = pre_zero;
  156477. result->b_s_open = FALSE; /* no associated backing-store object */
  156478. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156479. mem->virt_barray_list = result;
  156480. return result;
  156481. }
  156482. METHODDEF(void)
  156483. realize_virt_arrays (j_common_ptr cinfo)
  156484. {
  156485. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156486. long space_per_minheight, maximum_space, avail_mem;
  156487. long minheights, max_minheights;
  156488. jvirt_sarray_ptr sptr;
  156489. jvirt_barray_ptr bptr;
  156490. space_per_minheight = 0;
  156491. maximum_space = 0;
  156492. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156493. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156494. space_per_minheight += (long) sptr->maxaccess *
  156495. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156496. maximum_space += (long) sptr->rows_in_array *
  156497. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156498. }
  156499. }
  156500. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156501. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156502. space_per_minheight += (long) bptr->maxaccess *
  156503. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156504. maximum_space += (long) bptr->rows_in_array *
  156505. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156506. }
  156507. }
  156508. if (space_per_minheight <= 0)
  156509. return; /* no unrealized arrays, no work */
  156510. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156511. mem->total_space_allocated);
  156512. if (avail_mem >= maximum_space)
  156513. max_minheights = 1000000000L;
  156514. else {
  156515. max_minheights = avail_mem / space_per_minheight;
  156516. if (max_minheights <= 0)
  156517. max_minheights = 1;
  156518. }
  156519. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156520. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156521. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156522. if (minheights <= max_minheights) {
  156523. sptr->rows_in_mem = sptr->rows_in_array;
  156524. } else {
  156525. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156526. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156527. (long) sptr->rows_in_array *
  156528. (long) sptr->samplesperrow *
  156529. (long) SIZEOF(JSAMPLE));
  156530. sptr->b_s_open = TRUE;
  156531. }
  156532. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156533. sptr->samplesperrow, sptr->rows_in_mem);
  156534. sptr->rowsperchunk = mem->last_rowsperchunk;
  156535. sptr->cur_start_row = 0;
  156536. sptr->first_undef_row = 0;
  156537. sptr->dirty = FALSE;
  156538. }
  156539. }
  156540. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156541. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156542. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156543. if (minheights <= max_minheights) {
  156544. bptr->rows_in_mem = bptr->rows_in_array;
  156545. } else {
  156546. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156547. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156548. (long) bptr->rows_in_array *
  156549. (long) bptr->blocksperrow *
  156550. (long) SIZEOF(JBLOCK));
  156551. bptr->b_s_open = TRUE;
  156552. }
  156553. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156554. bptr->blocksperrow, bptr->rows_in_mem);
  156555. bptr->rowsperchunk = mem->last_rowsperchunk;
  156556. bptr->cur_start_row = 0;
  156557. bptr->first_undef_row = 0;
  156558. bptr->dirty = FALSE;
  156559. }
  156560. }
  156561. }
  156562. LOCAL(void)
  156563. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156564. {
  156565. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156566. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156567. file_offset = ptr->cur_start_row * bytesperrow;
  156568. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156569. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156570. thisrow = (long) ptr->cur_start_row + i;
  156571. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156572. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156573. if (rows <= 0) /* this chunk might be past end of file! */
  156574. break;
  156575. byte_count = rows * bytesperrow;
  156576. if (writing)
  156577. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156578. (void FAR *) ptr->mem_buffer[i],
  156579. file_offset, byte_count);
  156580. else
  156581. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156582. (void FAR *) ptr->mem_buffer[i],
  156583. file_offset, byte_count);
  156584. file_offset += byte_count;
  156585. }
  156586. }
  156587. LOCAL(void)
  156588. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156589. {
  156590. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156591. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156592. file_offset = ptr->cur_start_row * bytesperrow;
  156593. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156594. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156595. thisrow = (long) ptr->cur_start_row + i;
  156596. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156597. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156598. if (rows <= 0) /* this chunk might be past end of file! */
  156599. break;
  156600. byte_count = rows * bytesperrow;
  156601. if (writing)
  156602. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156603. (void FAR *) ptr->mem_buffer[i],
  156604. file_offset, byte_count);
  156605. else
  156606. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156607. (void FAR *) ptr->mem_buffer[i],
  156608. file_offset, byte_count);
  156609. file_offset += byte_count;
  156610. }
  156611. }
  156612. METHODDEF(JSAMPARRAY)
  156613. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156614. JDIMENSION start_row, JDIMENSION num_rows,
  156615. boolean writable)
  156616. {
  156617. JDIMENSION end_row = start_row + num_rows;
  156618. JDIMENSION undef_row;
  156619. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156620. ptr->mem_buffer == NULL)
  156621. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156622. if (start_row < ptr->cur_start_row ||
  156623. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156624. if (! ptr->b_s_open)
  156625. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156626. if (ptr->dirty) {
  156627. do_sarray_io(cinfo, ptr, TRUE);
  156628. ptr->dirty = FALSE;
  156629. }
  156630. if (start_row > ptr->cur_start_row) {
  156631. ptr->cur_start_row = start_row;
  156632. } else {
  156633. long ltemp;
  156634. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156635. if (ltemp < 0)
  156636. ltemp = 0; /* don't fall off front end of file */
  156637. ptr->cur_start_row = (JDIMENSION) ltemp;
  156638. }
  156639. do_sarray_io(cinfo, ptr, FALSE);
  156640. }
  156641. if (ptr->first_undef_row < end_row) {
  156642. if (ptr->first_undef_row < start_row) {
  156643. if (writable) /* writer skipped over a section of array */
  156644. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156645. undef_row = start_row; /* but reader is allowed to read ahead */
  156646. } else {
  156647. undef_row = ptr->first_undef_row;
  156648. }
  156649. if (writable)
  156650. ptr->first_undef_row = end_row;
  156651. if (ptr->pre_zero) {
  156652. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156653. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156654. end_row -= ptr->cur_start_row;
  156655. while (undef_row < end_row) {
  156656. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156657. undef_row++;
  156658. }
  156659. } else {
  156660. if (! writable) /* reader looking at undefined data */
  156661. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156662. }
  156663. }
  156664. if (writable)
  156665. ptr->dirty = TRUE;
  156666. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156667. }
  156668. METHODDEF(JBLOCKARRAY)
  156669. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156670. JDIMENSION start_row, JDIMENSION num_rows,
  156671. boolean writable)
  156672. {
  156673. JDIMENSION end_row = start_row + num_rows;
  156674. JDIMENSION undef_row;
  156675. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156676. ptr->mem_buffer == NULL)
  156677. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156678. if (start_row < ptr->cur_start_row ||
  156679. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156680. if (! ptr->b_s_open)
  156681. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156682. if (ptr->dirty) {
  156683. do_barray_io(cinfo, ptr, TRUE);
  156684. ptr->dirty = FALSE;
  156685. }
  156686. if (start_row > ptr->cur_start_row) {
  156687. ptr->cur_start_row = start_row;
  156688. } else {
  156689. long ltemp;
  156690. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156691. if (ltemp < 0)
  156692. ltemp = 0; /* don't fall off front end of file */
  156693. ptr->cur_start_row = (JDIMENSION) ltemp;
  156694. }
  156695. do_barray_io(cinfo, ptr, FALSE);
  156696. }
  156697. if (ptr->first_undef_row < end_row) {
  156698. if (ptr->first_undef_row < start_row) {
  156699. if (writable) /* writer skipped over a section of array */
  156700. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156701. undef_row = start_row; /* but reader is allowed to read ahead */
  156702. } else {
  156703. undef_row = ptr->first_undef_row;
  156704. }
  156705. if (writable)
  156706. ptr->first_undef_row = end_row;
  156707. if (ptr->pre_zero) {
  156708. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156709. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156710. end_row -= ptr->cur_start_row;
  156711. while (undef_row < end_row) {
  156712. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156713. undef_row++;
  156714. }
  156715. } else {
  156716. if (! writable) /* reader looking at undefined data */
  156717. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156718. }
  156719. }
  156720. if (writable)
  156721. ptr->dirty = TRUE;
  156722. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156723. }
  156724. METHODDEF(void)
  156725. free_pool (j_common_ptr cinfo, int pool_id)
  156726. {
  156727. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156728. small_pool_ptr shdr_ptr;
  156729. large_pool_ptr lhdr_ptr;
  156730. size_t space_freed;
  156731. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156732. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156733. #ifdef MEM_STATS
  156734. if (cinfo->err->trace_level > 1)
  156735. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156736. #endif
  156737. if (pool_id == JPOOL_IMAGE) {
  156738. jvirt_sarray_ptr sptr;
  156739. jvirt_barray_ptr bptr;
  156740. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156741. if (sptr->b_s_open) { /* there may be no backing store */
  156742. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156743. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156744. }
  156745. }
  156746. mem->virt_sarray_list = NULL;
  156747. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156748. if (bptr->b_s_open) { /* there may be no backing store */
  156749. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156750. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156751. }
  156752. }
  156753. mem->virt_barray_list = NULL;
  156754. }
  156755. lhdr_ptr = mem->large_list[pool_id];
  156756. mem->large_list[pool_id] = NULL;
  156757. while (lhdr_ptr != NULL) {
  156758. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156759. space_freed = lhdr_ptr->hdr.bytes_used +
  156760. lhdr_ptr->hdr.bytes_left +
  156761. SIZEOF(large_pool_hdr);
  156762. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156763. mem->total_space_allocated -= space_freed;
  156764. lhdr_ptr = next_lhdr_ptr;
  156765. }
  156766. shdr_ptr = mem->small_list[pool_id];
  156767. mem->small_list[pool_id] = NULL;
  156768. while (shdr_ptr != NULL) {
  156769. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156770. space_freed = shdr_ptr->hdr.bytes_used +
  156771. shdr_ptr->hdr.bytes_left +
  156772. SIZEOF(small_pool_hdr);
  156773. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156774. mem->total_space_allocated -= space_freed;
  156775. shdr_ptr = next_shdr_ptr;
  156776. }
  156777. }
  156778. METHODDEF(void)
  156779. self_destruct (j_common_ptr cinfo)
  156780. {
  156781. int pool;
  156782. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156783. free_pool(cinfo, pool);
  156784. }
  156785. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156786. cinfo->mem = NULL; /* ensures I will be called only once */
  156787. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156788. }
  156789. GLOBAL(void)
  156790. jinit_memory_mgr (j_common_ptr cinfo)
  156791. {
  156792. my_mem_ptr mem;
  156793. long max_to_use;
  156794. int pool;
  156795. size_t test_mac;
  156796. cinfo->mem = NULL; /* for safety if init fails */
  156797. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156798. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156799. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156800. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156801. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156802. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156803. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156804. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156805. if (mem == NULL) {
  156806. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156807. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156808. }
  156809. mem->pub.alloc_small = alloc_small;
  156810. mem->pub.alloc_large = alloc_large;
  156811. mem->pub.alloc_sarray = alloc_sarray;
  156812. mem->pub.alloc_barray = alloc_barray;
  156813. mem->pub.request_virt_sarray = request_virt_sarray;
  156814. mem->pub.request_virt_barray = request_virt_barray;
  156815. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156816. mem->pub.access_virt_sarray = access_virt_sarray;
  156817. mem->pub.access_virt_barray = access_virt_barray;
  156818. mem->pub.free_pool = free_pool;
  156819. mem->pub.self_destruct = self_destruct;
  156820. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156821. mem->pub.max_memory_to_use = max_to_use;
  156822. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156823. mem->small_list[pool] = NULL;
  156824. mem->large_list[pool] = NULL;
  156825. }
  156826. mem->virt_sarray_list = NULL;
  156827. mem->virt_barray_list = NULL;
  156828. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156829. cinfo->mem = & mem->pub;
  156830. #ifndef NO_GETENV
  156831. { char * memenv;
  156832. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156833. char ch = 'x';
  156834. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156835. if (ch == 'm' || ch == 'M')
  156836. max_to_use *= 1000L;
  156837. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156838. }
  156839. }
  156840. }
  156841. #endif
  156842. }
  156843. /*** End of inlined file: jmemmgr.c ***/
  156844. /*** Start of inlined file: jmemnobs.c ***/
  156845. #define JPEG_INTERNALS
  156846. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156847. extern void * malloc JPP((size_t size));
  156848. extern void free JPP((void *ptr));
  156849. #endif
  156850. GLOBAL(void *)
  156851. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156852. {
  156853. return (void *) malloc(sizeofobject);
  156854. }
  156855. GLOBAL(void)
  156856. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156857. {
  156858. free(object);
  156859. }
  156860. GLOBAL(void FAR *)
  156861. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156862. {
  156863. return (void FAR *) malloc(sizeofobject);
  156864. }
  156865. GLOBAL(void)
  156866. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156867. {
  156868. free(object);
  156869. }
  156870. GLOBAL(long)
  156871. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156872. long max_bytes_needed, long already_allocated)
  156873. {
  156874. return max_bytes_needed;
  156875. }
  156876. GLOBAL(void)
  156877. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156878. long total_bytes_needed)
  156879. {
  156880. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156881. }
  156882. GLOBAL(long)
  156883. jpeg_mem_init (j_common_ptr cinfo)
  156884. {
  156885. return 0; /* just set max_memory_to_use to 0 */
  156886. }
  156887. GLOBAL(void)
  156888. jpeg_mem_term (j_common_ptr cinfo)
  156889. {
  156890. }
  156891. /*** End of inlined file: jmemnobs.c ***/
  156892. /*** Start of inlined file: jquant1.c ***/
  156893. #define JPEG_INTERNALS
  156894. #ifdef QUANT_1PASS_SUPPORTED
  156895. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156896. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156897. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156898. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156899. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156900. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156901. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156902. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156903. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156904. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156905. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156906. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156907. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156908. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156909. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156910. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156911. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156912. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156913. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156914. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156915. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156916. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156917. };
  156918. #if BITS_IN_JSAMPLE == 8
  156919. typedef INT16 FSERROR; /* 16 bits should be enough */
  156920. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156921. #else
  156922. typedef INT32 FSERROR; /* may need more than 16 bits */
  156923. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156924. #endif
  156925. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156926. #define MAX_Q_COMPS 4 /* max components I can handle */
  156927. typedef struct {
  156928. struct jpeg_color_quantizer pub; /* public fields */
  156929. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156930. int sv_actual; /* number of entries in use */
  156931. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156932. boolean is_padded; /* is the colorindex padded for odither? */
  156933. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156934. int row_index; /* cur row's vertical index in dither matrix */
  156935. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156936. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156937. boolean on_odd_row; /* flag to remember which row we are on */
  156938. } my_cquantizer;
  156939. typedef my_cquantizer * my_cquantize_ptr;
  156940. LOCAL(int)
  156941. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  156942. {
  156943. int nc = cinfo->out_color_components; /* number of color components */
  156944. int max_colors = cinfo->desired_number_of_colors;
  156945. int total_colors, iroot, i, j;
  156946. boolean changed;
  156947. long temp;
  156948. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  156949. iroot = 1;
  156950. do {
  156951. iroot++;
  156952. temp = iroot; /* set temp = iroot ** nc */
  156953. for (i = 1; i < nc; i++)
  156954. temp *= iroot;
  156955. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  156956. iroot--; /* now iroot = floor(root) */
  156957. if (iroot < 2)
  156958. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  156959. total_colors = 1;
  156960. for (i = 0; i < nc; i++) {
  156961. Ncolors[i] = iroot;
  156962. total_colors *= iroot;
  156963. }
  156964. do {
  156965. changed = FALSE;
  156966. for (i = 0; i < nc; i++) {
  156967. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  156968. temp = total_colors / Ncolors[j];
  156969. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  156970. if (temp > (long) max_colors)
  156971. break; /* won't fit, done with this pass */
  156972. Ncolors[j]++; /* OK, apply the increment */
  156973. total_colors = (int) temp;
  156974. changed = TRUE;
  156975. }
  156976. } while (changed);
  156977. return total_colors;
  156978. }
  156979. LOCAL(int)
  156980. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156981. {
  156982. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  156983. }
  156984. LOCAL(int)
  156985. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156986. {
  156987. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  156988. }
  156989. LOCAL(void)
  156990. create_colormap (j_decompress_ptr cinfo)
  156991. {
  156992. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156993. JSAMPARRAY colormap; /* Created colormap */
  156994. int total_colors; /* Number of distinct output colors */
  156995. int i,j,k, nci, blksize, blkdist, ptr, val;
  156996. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  156997. if (cinfo->out_color_components == 3)
  156998. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  156999. total_colors, cquantize->Ncolors[0],
  157000. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  157001. else
  157002. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  157003. colormap = (*cinfo->mem->alloc_sarray)
  157004. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157005. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  157006. blkdist = total_colors;
  157007. for (i = 0; i < cinfo->out_color_components; i++) {
  157008. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157009. blksize = blkdist / nci;
  157010. for (j = 0; j < nci; j++) {
  157011. val = output_value(cinfo, i, j, nci-1);
  157012. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  157013. for (k = 0; k < blksize; k++)
  157014. colormap[i][ptr+k] = (JSAMPLE) val;
  157015. }
  157016. }
  157017. blkdist = blksize; /* blksize of this color is blkdist of next */
  157018. }
  157019. cquantize->sv_colormap = colormap;
  157020. cquantize->sv_actual = total_colors;
  157021. }
  157022. LOCAL(void)
  157023. create_colorindex (j_decompress_ptr cinfo)
  157024. {
  157025. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157026. JSAMPROW indexptr;
  157027. int i,j,k, nci, blksize, val, pad;
  157028. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157029. pad = MAXJSAMPLE*2;
  157030. cquantize->is_padded = TRUE;
  157031. } else {
  157032. pad = 0;
  157033. cquantize->is_padded = FALSE;
  157034. }
  157035. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157036. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157037. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157038. (JDIMENSION) cinfo->out_color_components);
  157039. blksize = cquantize->sv_actual;
  157040. for (i = 0; i < cinfo->out_color_components; i++) {
  157041. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157042. blksize = blksize / nci;
  157043. if (pad)
  157044. cquantize->colorindex[i] += MAXJSAMPLE;
  157045. indexptr = cquantize->colorindex[i];
  157046. val = 0;
  157047. k = largest_input_value(cinfo, i, 0, nci-1);
  157048. for (j = 0; j <= MAXJSAMPLE; j++) {
  157049. while (j > k) /* advance val if past boundary */
  157050. k = largest_input_value(cinfo, i, ++val, nci-1);
  157051. indexptr[j] = (JSAMPLE) (val * blksize);
  157052. }
  157053. if (pad)
  157054. for (j = 1; j <= MAXJSAMPLE; j++) {
  157055. indexptr[-j] = indexptr[0];
  157056. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157057. }
  157058. }
  157059. }
  157060. LOCAL(ODITHER_MATRIX_PTR)
  157061. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157062. {
  157063. ODITHER_MATRIX_PTR odither;
  157064. int j,k;
  157065. INT32 num,den;
  157066. odither = (ODITHER_MATRIX_PTR)
  157067. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157068. SIZEOF(ODITHER_MATRIX));
  157069. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157070. for (j = 0; j < ODITHER_SIZE; j++) {
  157071. for (k = 0; k < ODITHER_SIZE; k++) {
  157072. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157073. * MAXJSAMPLE;
  157074. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157075. }
  157076. }
  157077. return odither;
  157078. }
  157079. LOCAL(void)
  157080. create_odither_tables (j_decompress_ptr cinfo)
  157081. {
  157082. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157083. ODITHER_MATRIX_PTR odither;
  157084. int i, j, nci;
  157085. for (i = 0; i < cinfo->out_color_components; i++) {
  157086. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157087. odither = NULL; /* search for matching prior component */
  157088. for (j = 0; j < i; j++) {
  157089. if (nci == cquantize->Ncolors[j]) {
  157090. odither = cquantize->odither[j];
  157091. break;
  157092. }
  157093. }
  157094. if (odither == NULL) /* need a new table? */
  157095. odither = make_odither_array(cinfo, nci);
  157096. cquantize->odither[i] = odither;
  157097. }
  157098. }
  157099. METHODDEF(void)
  157100. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157101. JSAMPARRAY output_buf, int num_rows)
  157102. {
  157103. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157104. JSAMPARRAY colorindex = cquantize->colorindex;
  157105. register int pixcode, ci;
  157106. register JSAMPROW ptrin, ptrout;
  157107. int row;
  157108. JDIMENSION col;
  157109. JDIMENSION width = cinfo->output_width;
  157110. register int nc = cinfo->out_color_components;
  157111. for (row = 0; row < num_rows; row++) {
  157112. ptrin = input_buf[row];
  157113. ptrout = output_buf[row];
  157114. for (col = width; col > 0; col--) {
  157115. pixcode = 0;
  157116. for (ci = 0; ci < nc; ci++) {
  157117. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157118. }
  157119. *ptrout++ = (JSAMPLE) pixcode;
  157120. }
  157121. }
  157122. }
  157123. METHODDEF(void)
  157124. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157125. JSAMPARRAY output_buf, int num_rows)
  157126. {
  157127. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157128. register int pixcode;
  157129. register JSAMPROW ptrin, ptrout;
  157130. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157131. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157132. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157133. int row;
  157134. JDIMENSION col;
  157135. JDIMENSION width = cinfo->output_width;
  157136. for (row = 0; row < num_rows; row++) {
  157137. ptrin = input_buf[row];
  157138. ptrout = output_buf[row];
  157139. for (col = width; col > 0; col--) {
  157140. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157141. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157142. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157143. *ptrout++ = (JSAMPLE) pixcode;
  157144. }
  157145. }
  157146. }
  157147. METHODDEF(void)
  157148. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157149. JSAMPARRAY output_buf, int num_rows)
  157150. {
  157151. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157152. register JSAMPROW input_ptr;
  157153. register JSAMPROW output_ptr;
  157154. JSAMPROW colorindex_ci;
  157155. int * dither; /* points to active row of dither matrix */
  157156. int row_index, col_index; /* current indexes into dither matrix */
  157157. int nc = cinfo->out_color_components;
  157158. int ci;
  157159. int row;
  157160. JDIMENSION col;
  157161. JDIMENSION width = cinfo->output_width;
  157162. for (row = 0; row < num_rows; row++) {
  157163. jzero_far((void FAR *) output_buf[row],
  157164. (size_t) (width * SIZEOF(JSAMPLE)));
  157165. row_index = cquantize->row_index;
  157166. for (ci = 0; ci < nc; ci++) {
  157167. input_ptr = input_buf[row] + ci;
  157168. output_ptr = output_buf[row];
  157169. colorindex_ci = cquantize->colorindex[ci];
  157170. dither = cquantize->odither[ci][row_index];
  157171. col_index = 0;
  157172. for (col = width; col > 0; col--) {
  157173. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157174. input_ptr += nc;
  157175. output_ptr++;
  157176. col_index = (col_index + 1) & ODITHER_MASK;
  157177. }
  157178. }
  157179. row_index = (row_index + 1) & ODITHER_MASK;
  157180. cquantize->row_index = row_index;
  157181. }
  157182. }
  157183. METHODDEF(void)
  157184. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157185. JSAMPARRAY output_buf, int num_rows)
  157186. {
  157187. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157188. register int pixcode;
  157189. register JSAMPROW input_ptr;
  157190. register JSAMPROW output_ptr;
  157191. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157192. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157193. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157194. int * dither0; /* points to active row of dither matrix */
  157195. int * dither1;
  157196. int * dither2;
  157197. int row_index, col_index; /* current indexes into dither matrix */
  157198. int row;
  157199. JDIMENSION col;
  157200. JDIMENSION width = cinfo->output_width;
  157201. for (row = 0; row < num_rows; row++) {
  157202. row_index = cquantize->row_index;
  157203. input_ptr = input_buf[row];
  157204. output_ptr = output_buf[row];
  157205. dither0 = cquantize->odither[0][row_index];
  157206. dither1 = cquantize->odither[1][row_index];
  157207. dither2 = cquantize->odither[2][row_index];
  157208. col_index = 0;
  157209. for (col = width; col > 0; col--) {
  157210. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157211. dither0[col_index]]);
  157212. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157213. dither1[col_index]]);
  157214. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157215. dither2[col_index]]);
  157216. *output_ptr++ = (JSAMPLE) pixcode;
  157217. col_index = (col_index + 1) & ODITHER_MASK;
  157218. }
  157219. row_index = (row_index + 1) & ODITHER_MASK;
  157220. cquantize->row_index = row_index;
  157221. }
  157222. }
  157223. METHODDEF(void)
  157224. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157225. JSAMPARRAY output_buf, int num_rows)
  157226. {
  157227. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157228. register LOCFSERROR cur; /* current error or pixel value */
  157229. LOCFSERROR belowerr; /* error for pixel below cur */
  157230. LOCFSERROR bpreverr; /* error for below/prev col */
  157231. LOCFSERROR bnexterr; /* error for below/next col */
  157232. LOCFSERROR delta;
  157233. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157234. register JSAMPROW input_ptr;
  157235. register JSAMPROW output_ptr;
  157236. JSAMPROW colorindex_ci;
  157237. JSAMPROW colormap_ci;
  157238. int pixcode;
  157239. int nc = cinfo->out_color_components;
  157240. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157241. int dirnc; /* dir * nc */
  157242. int ci;
  157243. int row;
  157244. JDIMENSION col;
  157245. JDIMENSION width = cinfo->output_width;
  157246. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157247. SHIFT_TEMPS
  157248. for (row = 0; row < num_rows; row++) {
  157249. jzero_far((void FAR *) output_buf[row],
  157250. (size_t) (width * SIZEOF(JSAMPLE)));
  157251. for (ci = 0; ci < nc; ci++) {
  157252. input_ptr = input_buf[row] + ci;
  157253. output_ptr = output_buf[row];
  157254. if (cquantize->on_odd_row) {
  157255. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157256. output_ptr += width-1;
  157257. dir = -1;
  157258. dirnc = -nc;
  157259. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157260. } else {
  157261. dir = 1;
  157262. dirnc = nc;
  157263. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157264. }
  157265. colorindex_ci = cquantize->colorindex[ci];
  157266. colormap_ci = cquantize->sv_colormap[ci];
  157267. cur = 0;
  157268. belowerr = bpreverr = 0;
  157269. for (col = width; col > 0; col--) {
  157270. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157271. cur += GETJSAMPLE(*input_ptr);
  157272. cur = GETJSAMPLE(range_limit[cur]);
  157273. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157274. *output_ptr += (JSAMPLE) pixcode;
  157275. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157276. bnexterr = cur;
  157277. delta = cur * 2;
  157278. cur += delta; /* form error * 3 */
  157279. errorptr[0] = (FSERROR) (bpreverr + cur);
  157280. cur += delta; /* form error * 5 */
  157281. bpreverr = belowerr + cur;
  157282. belowerr = bnexterr;
  157283. cur += delta; /* form error * 7 */
  157284. input_ptr += dirnc; /* advance input ptr to next column */
  157285. output_ptr += dir; /* advance output ptr to next column */
  157286. errorptr += dir; /* advance errorptr to current column */
  157287. }
  157288. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157289. }
  157290. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157291. }
  157292. }
  157293. LOCAL(void)
  157294. alloc_fs_workspace (j_decompress_ptr cinfo)
  157295. {
  157296. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157297. size_t arraysize;
  157298. int i;
  157299. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157300. for (i = 0; i < cinfo->out_color_components; i++) {
  157301. cquantize->fserrors[i] = (FSERRPTR)
  157302. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157303. }
  157304. }
  157305. METHODDEF(void)
  157306. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157307. {
  157308. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157309. size_t arraysize;
  157310. int i;
  157311. cinfo->colormap = cquantize->sv_colormap;
  157312. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157313. switch (cinfo->dither_mode) {
  157314. case JDITHER_NONE:
  157315. if (cinfo->out_color_components == 3)
  157316. cquantize->pub.color_quantize = color_quantize3;
  157317. else
  157318. cquantize->pub.color_quantize = color_quantize;
  157319. break;
  157320. case JDITHER_ORDERED:
  157321. if (cinfo->out_color_components == 3)
  157322. cquantize->pub.color_quantize = quantize3_ord_dither;
  157323. else
  157324. cquantize->pub.color_quantize = quantize_ord_dither;
  157325. cquantize->row_index = 0; /* initialize state for ordered dither */
  157326. if (! cquantize->is_padded)
  157327. create_colorindex(cinfo);
  157328. if (cquantize->odither[0] == NULL)
  157329. create_odither_tables(cinfo);
  157330. break;
  157331. case JDITHER_FS:
  157332. cquantize->pub.color_quantize = quantize_fs_dither;
  157333. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157334. if (cquantize->fserrors[0] == NULL)
  157335. alloc_fs_workspace(cinfo);
  157336. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157337. for (i = 0; i < cinfo->out_color_components; i++)
  157338. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157339. break;
  157340. default:
  157341. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157342. break;
  157343. }
  157344. }
  157345. METHODDEF(void)
  157346. finish_pass_1_quant (j_decompress_ptr cinfo)
  157347. {
  157348. }
  157349. METHODDEF(void)
  157350. new_color_map_1_quant (j_decompress_ptr cinfo)
  157351. {
  157352. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157353. }
  157354. GLOBAL(void)
  157355. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157356. {
  157357. my_cquantize_ptr cquantize;
  157358. cquantize = (my_cquantize_ptr)
  157359. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157360. SIZEOF(my_cquantizer));
  157361. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157362. cquantize->pub.start_pass = start_pass_1_quant;
  157363. cquantize->pub.finish_pass = finish_pass_1_quant;
  157364. cquantize->pub.new_color_map = new_color_map_1_quant;
  157365. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157366. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157367. if (cinfo->out_color_components > MAX_Q_COMPS)
  157368. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157369. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157370. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157371. create_colormap(cinfo);
  157372. create_colorindex(cinfo);
  157373. if (cinfo->dither_mode == JDITHER_FS)
  157374. alloc_fs_workspace(cinfo);
  157375. }
  157376. #endif /* QUANT_1PASS_SUPPORTED */
  157377. /*** End of inlined file: jquant1.c ***/
  157378. /*** Start of inlined file: jquant2.c ***/
  157379. #define JPEG_INTERNALS
  157380. #ifdef QUANT_2PASS_SUPPORTED
  157381. #define R_SCALE 2 /* scale R distances by this much */
  157382. #define G_SCALE 3 /* scale G distances by this much */
  157383. #define B_SCALE 1 /* and B by this much */
  157384. #if RGB_RED == 0
  157385. #define C0_SCALE R_SCALE
  157386. #endif
  157387. #if RGB_BLUE == 0
  157388. #define C0_SCALE B_SCALE
  157389. #endif
  157390. #if RGB_GREEN == 1
  157391. #define C1_SCALE G_SCALE
  157392. #endif
  157393. #if RGB_RED == 2
  157394. #define C2_SCALE R_SCALE
  157395. #endif
  157396. #if RGB_BLUE == 2
  157397. #define C2_SCALE B_SCALE
  157398. #endif
  157399. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157400. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157401. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157402. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157403. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157404. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157405. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157406. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157407. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157408. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157409. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157410. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157411. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157412. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157413. typedef hist2d * hist3d; /* type for top-level pointer */
  157414. #if BITS_IN_JSAMPLE == 8
  157415. typedef INT16 FSERROR; /* 16 bits should be enough */
  157416. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157417. #else
  157418. typedef INT32 FSERROR; /* may need more than 16 bits */
  157419. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157420. #endif
  157421. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157422. typedef struct {
  157423. struct jpeg_color_quantizer pub; /* public fields */
  157424. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157425. int desired; /* desired # of colors = size of colormap */
  157426. hist3d histogram; /* pointer to the histogram */
  157427. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157428. FSERRPTR fserrors; /* accumulated errors */
  157429. boolean on_odd_row; /* flag to remember which row we are on */
  157430. int * error_limiter; /* table for clamping the applied error */
  157431. } my_cquantizer2;
  157432. typedef my_cquantizer2 * my_cquantize_ptr2;
  157433. METHODDEF(void)
  157434. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157435. JSAMPARRAY output_buf, int num_rows)
  157436. {
  157437. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157438. register JSAMPROW ptr;
  157439. register histptr histp;
  157440. register hist3d histogram = cquantize->histogram;
  157441. int row;
  157442. JDIMENSION col;
  157443. JDIMENSION width = cinfo->output_width;
  157444. for (row = 0; row < num_rows; row++) {
  157445. ptr = input_buf[row];
  157446. for (col = width; col > 0; col--) {
  157447. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157448. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157449. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157450. if (++(*histp) <= 0)
  157451. (*histp)--;
  157452. ptr += 3;
  157453. }
  157454. }
  157455. }
  157456. typedef struct {
  157457. int c0min, c0max;
  157458. int c1min, c1max;
  157459. int c2min, c2max;
  157460. INT32 volume;
  157461. long colorcount;
  157462. } box;
  157463. typedef box * boxptr;
  157464. LOCAL(boxptr)
  157465. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157466. {
  157467. register boxptr boxp;
  157468. register int i;
  157469. register long maxc = 0;
  157470. boxptr which = NULL;
  157471. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157472. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157473. which = boxp;
  157474. maxc = boxp->colorcount;
  157475. }
  157476. }
  157477. return which;
  157478. }
  157479. LOCAL(boxptr)
  157480. find_biggest_volume (boxptr boxlist, int numboxes)
  157481. {
  157482. register boxptr boxp;
  157483. register int i;
  157484. register INT32 maxv = 0;
  157485. boxptr which = NULL;
  157486. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157487. if (boxp->volume > maxv) {
  157488. which = boxp;
  157489. maxv = boxp->volume;
  157490. }
  157491. }
  157492. return which;
  157493. }
  157494. LOCAL(void)
  157495. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157496. {
  157497. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157498. hist3d histogram = cquantize->histogram;
  157499. histptr histp;
  157500. int c0,c1,c2;
  157501. int c0min,c0max,c1min,c1max,c2min,c2max;
  157502. INT32 dist0,dist1,dist2;
  157503. long ccount;
  157504. c0min = boxp->c0min; c0max = boxp->c0max;
  157505. c1min = boxp->c1min; c1max = boxp->c1max;
  157506. c2min = boxp->c2min; c2max = boxp->c2max;
  157507. if (c0max > c0min)
  157508. for (c0 = c0min; c0 <= c0max; c0++)
  157509. for (c1 = c1min; c1 <= c1max; c1++) {
  157510. histp = & histogram[c0][c1][c2min];
  157511. for (c2 = c2min; c2 <= c2max; c2++)
  157512. if (*histp++ != 0) {
  157513. boxp->c0min = c0min = c0;
  157514. goto have_c0min;
  157515. }
  157516. }
  157517. have_c0min:
  157518. if (c0max > c0min)
  157519. for (c0 = c0max; c0 >= c0min; c0--)
  157520. for (c1 = c1min; c1 <= c1max; c1++) {
  157521. histp = & histogram[c0][c1][c2min];
  157522. for (c2 = c2min; c2 <= c2max; c2++)
  157523. if (*histp++ != 0) {
  157524. boxp->c0max = c0max = c0;
  157525. goto have_c0max;
  157526. }
  157527. }
  157528. have_c0max:
  157529. if (c1max > c1min)
  157530. for (c1 = c1min; c1 <= c1max; c1++)
  157531. for (c0 = c0min; c0 <= c0max; c0++) {
  157532. histp = & histogram[c0][c1][c2min];
  157533. for (c2 = c2min; c2 <= c2max; c2++)
  157534. if (*histp++ != 0) {
  157535. boxp->c1min = c1min = c1;
  157536. goto have_c1min;
  157537. }
  157538. }
  157539. have_c1min:
  157540. if (c1max > c1min)
  157541. for (c1 = c1max; c1 >= c1min; c1--)
  157542. for (c0 = c0min; c0 <= c0max; c0++) {
  157543. histp = & histogram[c0][c1][c2min];
  157544. for (c2 = c2min; c2 <= c2max; c2++)
  157545. if (*histp++ != 0) {
  157546. boxp->c1max = c1max = c1;
  157547. goto have_c1max;
  157548. }
  157549. }
  157550. have_c1max:
  157551. if (c2max > c2min)
  157552. for (c2 = c2min; c2 <= c2max; c2++)
  157553. for (c0 = c0min; c0 <= c0max; c0++) {
  157554. histp = & histogram[c0][c1min][c2];
  157555. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157556. if (*histp != 0) {
  157557. boxp->c2min = c2min = c2;
  157558. goto have_c2min;
  157559. }
  157560. }
  157561. have_c2min:
  157562. if (c2max > c2min)
  157563. for (c2 = c2max; c2 >= c2min; c2--)
  157564. for (c0 = c0min; c0 <= c0max; c0++) {
  157565. histp = & histogram[c0][c1min][c2];
  157566. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157567. if (*histp != 0) {
  157568. boxp->c2max = c2max = c2;
  157569. goto have_c2max;
  157570. }
  157571. }
  157572. have_c2max:
  157573. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157574. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157575. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157576. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157577. ccount = 0;
  157578. for (c0 = c0min; c0 <= c0max; c0++)
  157579. for (c1 = c1min; c1 <= c1max; c1++) {
  157580. histp = & histogram[c0][c1][c2min];
  157581. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157582. if (*histp != 0) {
  157583. ccount++;
  157584. }
  157585. }
  157586. boxp->colorcount = ccount;
  157587. }
  157588. LOCAL(int)
  157589. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157590. int desired_colors)
  157591. {
  157592. int n,lb;
  157593. int c0,c1,c2,cmax;
  157594. register boxptr b1,b2;
  157595. while (numboxes < desired_colors) {
  157596. if (numboxes*2 <= desired_colors) {
  157597. b1 = find_biggest_color_pop(boxlist, numboxes);
  157598. } else {
  157599. b1 = find_biggest_volume(boxlist, numboxes);
  157600. }
  157601. if (b1 == NULL) /* no splittable boxes left! */
  157602. break;
  157603. b2 = &boxlist[numboxes]; /* where new box will go */
  157604. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157605. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157606. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157607. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157608. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157609. #if RGB_RED == 0
  157610. cmax = c1; n = 1;
  157611. if (c0 > cmax) { cmax = c0; n = 0; }
  157612. if (c2 > cmax) { n = 2; }
  157613. #else
  157614. cmax = c1; n = 1;
  157615. if (c2 > cmax) { cmax = c2; n = 2; }
  157616. if (c0 > cmax) { n = 0; }
  157617. #endif
  157618. switch (n) {
  157619. case 0:
  157620. lb = (b1->c0max + b1->c0min) / 2;
  157621. b1->c0max = lb;
  157622. b2->c0min = lb+1;
  157623. break;
  157624. case 1:
  157625. lb = (b1->c1max + b1->c1min) / 2;
  157626. b1->c1max = lb;
  157627. b2->c1min = lb+1;
  157628. break;
  157629. case 2:
  157630. lb = (b1->c2max + b1->c2min) / 2;
  157631. b1->c2max = lb;
  157632. b2->c2min = lb+1;
  157633. break;
  157634. }
  157635. update_box(cinfo, b1);
  157636. update_box(cinfo, b2);
  157637. numboxes++;
  157638. }
  157639. return numboxes;
  157640. }
  157641. LOCAL(void)
  157642. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157643. {
  157644. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157645. hist3d histogram = cquantize->histogram;
  157646. histptr histp;
  157647. int c0,c1,c2;
  157648. int c0min,c0max,c1min,c1max,c2min,c2max;
  157649. long count;
  157650. long total = 0;
  157651. long c0total = 0;
  157652. long c1total = 0;
  157653. long c2total = 0;
  157654. c0min = boxp->c0min; c0max = boxp->c0max;
  157655. c1min = boxp->c1min; c1max = boxp->c1max;
  157656. c2min = boxp->c2min; c2max = boxp->c2max;
  157657. for (c0 = c0min; c0 <= c0max; c0++)
  157658. for (c1 = c1min; c1 <= c1max; c1++) {
  157659. histp = & histogram[c0][c1][c2min];
  157660. for (c2 = c2min; c2 <= c2max; c2++) {
  157661. if ((count = *histp++) != 0) {
  157662. total += count;
  157663. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157664. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157665. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157666. }
  157667. }
  157668. }
  157669. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157670. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157671. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157672. }
  157673. LOCAL(void)
  157674. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157675. {
  157676. boxptr boxlist;
  157677. int numboxes;
  157678. int i;
  157679. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157680. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157681. numboxes = 1;
  157682. boxlist[0].c0min = 0;
  157683. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157684. boxlist[0].c1min = 0;
  157685. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157686. boxlist[0].c2min = 0;
  157687. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157688. update_box(cinfo, & boxlist[0]);
  157689. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157690. for (i = 0; i < numboxes; i++)
  157691. compute_color(cinfo, & boxlist[i], i);
  157692. cinfo->actual_number_of_colors = numboxes;
  157693. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157694. }
  157695. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157696. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157697. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157698. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157699. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157700. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157701. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157702. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157703. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157704. LOCAL(int)
  157705. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157706. JSAMPLE colorlist[])
  157707. {
  157708. int numcolors = cinfo->actual_number_of_colors;
  157709. int maxc0, maxc1, maxc2;
  157710. int centerc0, centerc1, centerc2;
  157711. int i, x, ncolors;
  157712. INT32 minmaxdist, min_dist, max_dist, tdist;
  157713. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157714. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157715. centerc0 = (minc0 + maxc0) >> 1;
  157716. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157717. centerc1 = (minc1 + maxc1) >> 1;
  157718. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157719. centerc2 = (minc2 + maxc2) >> 1;
  157720. minmaxdist = 0x7FFFFFFFL;
  157721. for (i = 0; i < numcolors; i++) {
  157722. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157723. if (x < minc0) {
  157724. tdist = (x - minc0) * C0_SCALE;
  157725. min_dist = tdist*tdist;
  157726. tdist = (x - maxc0) * C0_SCALE;
  157727. max_dist = tdist*tdist;
  157728. } else if (x > maxc0) {
  157729. tdist = (x - maxc0) * C0_SCALE;
  157730. min_dist = tdist*tdist;
  157731. tdist = (x - minc0) * C0_SCALE;
  157732. max_dist = tdist*tdist;
  157733. } else {
  157734. min_dist = 0;
  157735. if (x <= centerc0) {
  157736. tdist = (x - maxc0) * C0_SCALE;
  157737. max_dist = tdist*tdist;
  157738. } else {
  157739. tdist = (x - minc0) * C0_SCALE;
  157740. max_dist = tdist*tdist;
  157741. }
  157742. }
  157743. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157744. if (x < minc1) {
  157745. tdist = (x - minc1) * C1_SCALE;
  157746. min_dist += tdist*tdist;
  157747. tdist = (x - maxc1) * C1_SCALE;
  157748. max_dist += tdist*tdist;
  157749. } else if (x > maxc1) {
  157750. tdist = (x - maxc1) * C1_SCALE;
  157751. min_dist += tdist*tdist;
  157752. tdist = (x - minc1) * C1_SCALE;
  157753. max_dist += tdist*tdist;
  157754. } else {
  157755. if (x <= centerc1) {
  157756. tdist = (x - maxc1) * C1_SCALE;
  157757. max_dist += tdist*tdist;
  157758. } else {
  157759. tdist = (x - minc1) * C1_SCALE;
  157760. max_dist += tdist*tdist;
  157761. }
  157762. }
  157763. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157764. if (x < minc2) {
  157765. tdist = (x - minc2) * C2_SCALE;
  157766. min_dist += tdist*tdist;
  157767. tdist = (x - maxc2) * C2_SCALE;
  157768. max_dist += tdist*tdist;
  157769. } else if (x > maxc2) {
  157770. tdist = (x - maxc2) * C2_SCALE;
  157771. min_dist += tdist*tdist;
  157772. tdist = (x - minc2) * C2_SCALE;
  157773. max_dist += tdist*tdist;
  157774. } else {
  157775. if (x <= centerc2) {
  157776. tdist = (x - maxc2) * C2_SCALE;
  157777. max_dist += tdist*tdist;
  157778. } else {
  157779. tdist = (x - minc2) * C2_SCALE;
  157780. max_dist += tdist*tdist;
  157781. }
  157782. }
  157783. mindist[i] = min_dist; /* save away the results */
  157784. if (max_dist < minmaxdist)
  157785. minmaxdist = max_dist;
  157786. }
  157787. ncolors = 0;
  157788. for (i = 0; i < numcolors; i++) {
  157789. if (mindist[i] <= minmaxdist)
  157790. colorlist[ncolors++] = (JSAMPLE) i;
  157791. }
  157792. return ncolors;
  157793. }
  157794. LOCAL(void)
  157795. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157796. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157797. {
  157798. int ic0, ic1, ic2;
  157799. int i, icolor;
  157800. register INT32 * bptr; /* pointer into bestdist[] array */
  157801. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157802. INT32 dist0, dist1; /* initial distance values */
  157803. register INT32 dist2; /* current distance in inner loop */
  157804. INT32 xx0, xx1; /* distance increments */
  157805. register INT32 xx2;
  157806. INT32 inc0, inc1, inc2; /* initial values for increments */
  157807. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157808. bptr = bestdist;
  157809. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157810. *bptr++ = 0x7FFFFFFFL;
  157811. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157812. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157813. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157814. for (i = 0; i < numcolors; i++) {
  157815. icolor = GETJSAMPLE(colorlist[i]);
  157816. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157817. dist0 = inc0*inc0;
  157818. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157819. dist0 += inc1*inc1;
  157820. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157821. dist0 += inc2*inc2;
  157822. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157823. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157824. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157825. bptr = bestdist;
  157826. cptr = bestcolor;
  157827. xx0 = inc0;
  157828. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157829. dist1 = dist0;
  157830. xx1 = inc1;
  157831. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157832. dist2 = dist1;
  157833. xx2 = inc2;
  157834. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157835. if (dist2 < *bptr) {
  157836. *bptr = dist2;
  157837. *cptr = (JSAMPLE) icolor;
  157838. }
  157839. dist2 += xx2;
  157840. xx2 += 2 * STEP_C2 * STEP_C2;
  157841. bptr++;
  157842. cptr++;
  157843. }
  157844. dist1 += xx1;
  157845. xx1 += 2 * STEP_C1 * STEP_C1;
  157846. }
  157847. dist0 += xx0;
  157848. xx0 += 2 * STEP_C0 * STEP_C0;
  157849. }
  157850. }
  157851. }
  157852. LOCAL(void)
  157853. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157854. {
  157855. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157856. hist3d histogram = cquantize->histogram;
  157857. int minc0, minc1, minc2; /* lower left corner of update box */
  157858. int ic0, ic1, ic2;
  157859. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157860. register histptr cachep; /* pointer into main cache array */
  157861. JSAMPLE colorlist[MAXNUMCOLORS];
  157862. int numcolors; /* number of candidate colors */
  157863. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157864. c0 >>= BOX_C0_LOG;
  157865. c1 >>= BOX_C1_LOG;
  157866. c2 >>= BOX_C2_LOG;
  157867. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157868. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157869. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157870. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157871. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157872. bestcolor);
  157873. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157874. c1 <<= BOX_C1_LOG;
  157875. c2 <<= BOX_C2_LOG;
  157876. cptr = bestcolor;
  157877. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157878. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157879. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157880. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157881. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157882. }
  157883. }
  157884. }
  157885. }
  157886. METHODDEF(void)
  157887. pass2_no_dither (j_decompress_ptr cinfo,
  157888. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157889. {
  157890. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157891. hist3d histogram = cquantize->histogram;
  157892. register JSAMPROW inptr, outptr;
  157893. register histptr cachep;
  157894. register int c0, c1, c2;
  157895. int row;
  157896. JDIMENSION col;
  157897. JDIMENSION width = cinfo->output_width;
  157898. for (row = 0; row < num_rows; row++) {
  157899. inptr = input_buf[row];
  157900. outptr = output_buf[row];
  157901. for (col = width; col > 0; col--) {
  157902. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157903. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157904. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157905. cachep = & histogram[c0][c1][c2];
  157906. if (*cachep == 0)
  157907. fill_inverse_cmap(cinfo, c0,c1,c2);
  157908. *outptr++ = (JSAMPLE) (*cachep - 1);
  157909. }
  157910. }
  157911. }
  157912. METHODDEF(void)
  157913. pass2_fs_dither (j_decompress_ptr cinfo,
  157914. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157915. {
  157916. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157917. hist3d histogram = cquantize->histogram;
  157918. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157919. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157920. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157921. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157922. JSAMPROW inptr; /* => current input pixel */
  157923. JSAMPROW outptr; /* => current output pixel */
  157924. histptr cachep;
  157925. int dir; /* +1 or -1 depending on direction */
  157926. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157927. int row;
  157928. JDIMENSION col;
  157929. JDIMENSION width = cinfo->output_width;
  157930. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157931. int *error_limit = cquantize->error_limiter;
  157932. JSAMPROW colormap0 = cinfo->colormap[0];
  157933. JSAMPROW colormap1 = cinfo->colormap[1];
  157934. JSAMPROW colormap2 = cinfo->colormap[2];
  157935. SHIFT_TEMPS
  157936. for (row = 0; row < num_rows; row++) {
  157937. inptr = input_buf[row];
  157938. outptr = output_buf[row];
  157939. if (cquantize->on_odd_row) {
  157940. inptr += (width-1) * 3; /* so point to rightmost pixel */
  157941. outptr += width-1;
  157942. dir = -1;
  157943. dir3 = -3;
  157944. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  157945. cquantize->on_odd_row = FALSE; /* flip for next time */
  157946. } else {
  157947. dir = 1;
  157948. dir3 = 3;
  157949. errorptr = cquantize->fserrors; /* => entry before first real column */
  157950. cquantize->on_odd_row = TRUE; /* flip for next time */
  157951. }
  157952. cur0 = cur1 = cur2 = 0;
  157953. belowerr0 = belowerr1 = belowerr2 = 0;
  157954. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  157955. for (col = width; col > 0; col--) {
  157956. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  157957. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  157958. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  157959. cur0 = error_limit[cur0];
  157960. cur1 = error_limit[cur1];
  157961. cur2 = error_limit[cur2];
  157962. cur0 += GETJSAMPLE(inptr[0]);
  157963. cur1 += GETJSAMPLE(inptr[1]);
  157964. cur2 += GETJSAMPLE(inptr[2]);
  157965. cur0 = GETJSAMPLE(range_limit[cur0]);
  157966. cur1 = GETJSAMPLE(range_limit[cur1]);
  157967. cur2 = GETJSAMPLE(range_limit[cur2]);
  157968. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  157969. if (*cachep == 0)
  157970. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  157971. { register int pixcode = *cachep - 1;
  157972. *outptr = (JSAMPLE) pixcode;
  157973. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  157974. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  157975. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  157976. }
  157977. { register LOCFSERROR bnexterr, delta;
  157978. bnexterr = cur0; /* Process component 0 */
  157979. delta = cur0 * 2;
  157980. cur0 += delta; /* form error * 3 */
  157981. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  157982. cur0 += delta; /* form error * 5 */
  157983. bpreverr0 = belowerr0 + cur0;
  157984. belowerr0 = bnexterr;
  157985. cur0 += delta; /* form error * 7 */
  157986. bnexterr = cur1; /* Process component 1 */
  157987. delta = cur1 * 2;
  157988. cur1 += delta; /* form error * 3 */
  157989. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  157990. cur1 += delta; /* form error * 5 */
  157991. bpreverr1 = belowerr1 + cur1;
  157992. belowerr1 = bnexterr;
  157993. cur1 += delta; /* form error * 7 */
  157994. bnexterr = cur2; /* Process component 2 */
  157995. delta = cur2 * 2;
  157996. cur2 += delta; /* form error * 3 */
  157997. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  157998. cur2 += delta; /* form error * 5 */
  157999. bpreverr2 = belowerr2 + cur2;
  158000. belowerr2 = bnexterr;
  158001. cur2 += delta; /* form error * 7 */
  158002. }
  158003. inptr += dir3; /* Advance pixel pointers to next column */
  158004. outptr += dir;
  158005. errorptr += dir3; /* advance errorptr to current column */
  158006. }
  158007. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  158008. errorptr[1] = (FSERROR) bpreverr1;
  158009. errorptr[2] = (FSERROR) bpreverr2;
  158010. }
  158011. }
  158012. LOCAL(void)
  158013. init_error_limit (j_decompress_ptr cinfo)
  158014. {
  158015. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158016. int * table;
  158017. int in, out;
  158018. table = (int *) (*cinfo->mem->alloc_small)
  158019. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  158020. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  158021. cquantize->error_limiter = table;
  158022. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  158023. out = 0;
  158024. for (in = 0; in < STEPSIZE; in++, out++) {
  158025. table[in] = out; table[-in] = -out;
  158026. }
  158027. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158028. table[in] = out; table[-in] = -out;
  158029. }
  158030. for (; in <= MAXJSAMPLE; in++) {
  158031. table[in] = out; table[-in] = -out;
  158032. }
  158033. #undef STEPSIZE
  158034. }
  158035. METHODDEF(void)
  158036. finish_pass1 (j_decompress_ptr cinfo)
  158037. {
  158038. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158039. cinfo->colormap = cquantize->sv_colormap;
  158040. select_colors(cinfo, cquantize->desired);
  158041. cquantize->needs_zeroed = TRUE;
  158042. }
  158043. METHODDEF(void)
  158044. finish_pass2 (j_decompress_ptr cinfo)
  158045. {
  158046. }
  158047. METHODDEF(void)
  158048. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158049. {
  158050. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158051. hist3d histogram = cquantize->histogram;
  158052. int i;
  158053. if (cinfo->dither_mode != JDITHER_NONE)
  158054. cinfo->dither_mode = JDITHER_FS;
  158055. if (is_pre_scan) {
  158056. cquantize->pub.color_quantize = prescan_quantize;
  158057. cquantize->pub.finish_pass = finish_pass1;
  158058. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158059. } else {
  158060. if (cinfo->dither_mode == JDITHER_FS)
  158061. cquantize->pub.color_quantize = pass2_fs_dither;
  158062. else
  158063. cquantize->pub.color_quantize = pass2_no_dither;
  158064. cquantize->pub.finish_pass = finish_pass2;
  158065. i = cinfo->actual_number_of_colors;
  158066. if (i < 1)
  158067. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158068. if (i > MAXNUMCOLORS)
  158069. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158070. if (cinfo->dither_mode == JDITHER_FS) {
  158071. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158072. (3 * SIZEOF(FSERROR)));
  158073. if (cquantize->fserrors == NULL)
  158074. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158075. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158076. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158077. if (cquantize->error_limiter == NULL)
  158078. init_error_limit(cinfo);
  158079. cquantize->on_odd_row = FALSE;
  158080. }
  158081. }
  158082. if (cquantize->needs_zeroed) {
  158083. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158084. jzero_far((void FAR *) histogram[i],
  158085. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158086. }
  158087. cquantize->needs_zeroed = FALSE;
  158088. }
  158089. }
  158090. METHODDEF(void)
  158091. new_color_map_2_quant (j_decompress_ptr cinfo)
  158092. {
  158093. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158094. cquantize->needs_zeroed = TRUE;
  158095. }
  158096. GLOBAL(void)
  158097. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158098. {
  158099. my_cquantize_ptr2 cquantize;
  158100. int i;
  158101. cquantize = (my_cquantize_ptr2)
  158102. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158103. SIZEOF(my_cquantizer2));
  158104. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158105. cquantize->pub.start_pass = start_pass_2_quant;
  158106. cquantize->pub.new_color_map = new_color_map_2_quant;
  158107. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158108. cquantize->error_limiter = NULL;
  158109. if (cinfo->out_color_components != 3)
  158110. ERREXIT(cinfo, JERR_NOTIMPL);
  158111. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158112. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158113. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158114. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158115. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158116. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158117. }
  158118. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158119. if (cinfo->enable_2pass_quant) {
  158120. int desired = cinfo->desired_number_of_colors;
  158121. if (desired < 8)
  158122. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158123. if (desired > MAXNUMCOLORS)
  158124. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158125. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158126. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158127. cquantize->desired = desired;
  158128. } else
  158129. cquantize->sv_colormap = NULL;
  158130. if (cinfo->dither_mode != JDITHER_NONE)
  158131. cinfo->dither_mode = JDITHER_FS;
  158132. if (cinfo->dither_mode == JDITHER_FS) {
  158133. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158134. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158135. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158136. init_error_limit(cinfo);
  158137. }
  158138. }
  158139. #endif /* QUANT_2PASS_SUPPORTED */
  158140. /*** End of inlined file: jquant2.c ***/
  158141. /*** Start of inlined file: jutils.c ***/
  158142. #define JPEG_INTERNALS
  158143. #if 0 /* This table is not actually needed in v6a */
  158144. const int jpeg_zigzag_order[DCTSIZE2] = {
  158145. 0, 1, 5, 6, 14, 15, 27, 28,
  158146. 2, 4, 7, 13, 16, 26, 29, 42,
  158147. 3, 8, 12, 17, 25, 30, 41, 43,
  158148. 9, 11, 18, 24, 31, 40, 44, 53,
  158149. 10, 19, 23, 32, 39, 45, 52, 54,
  158150. 20, 22, 33, 38, 46, 51, 55, 60,
  158151. 21, 34, 37, 47, 50, 56, 59, 61,
  158152. 35, 36, 48, 49, 57, 58, 62, 63
  158153. };
  158154. #endif
  158155. const int jpeg_natural_order[DCTSIZE2+16] = {
  158156. 0, 1, 8, 16, 9, 2, 3, 10,
  158157. 17, 24, 32, 25, 18, 11, 4, 5,
  158158. 12, 19, 26, 33, 40, 48, 41, 34,
  158159. 27, 20, 13, 6, 7, 14, 21, 28,
  158160. 35, 42, 49, 56, 57, 50, 43, 36,
  158161. 29, 22, 15, 23, 30, 37, 44, 51,
  158162. 58, 59, 52, 45, 38, 31, 39, 46,
  158163. 53, 60, 61, 54, 47, 55, 62, 63,
  158164. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158165. 63, 63, 63, 63, 63, 63, 63, 63
  158166. };
  158167. GLOBAL(long)
  158168. jdiv_round_up (long a, long b)
  158169. {
  158170. return (a + b - 1L) / b;
  158171. }
  158172. GLOBAL(long)
  158173. jround_up (long a, long b)
  158174. {
  158175. a += b - 1L;
  158176. return a - (a % b);
  158177. }
  158178. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158179. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158180. #define FMEMZERO(target,size) MEMZERO(target,size)
  158181. #else /* 80x86 case, define if we can */
  158182. #ifdef USE_FMEM
  158183. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158184. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158185. #endif
  158186. #endif
  158187. GLOBAL(void)
  158188. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158189. JSAMPARRAY output_array, int dest_row,
  158190. int num_rows, JDIMENSION num_cols)
  158191. {
  158192. register JSAMPROW inptr, outptr;
  158193. #ifdef FMEMCOPY
  158194. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158195. #else
  158196. register JDIMENSION count;
  158197. #endif
  158198. register int row;
  158199. input_array += source_row;
  158200. output_array += dest_row;
  158201. for (row = num_rows; row > 0; row--) {
  158202. inptr = *input_array++;
  158203. outptr = *output_array++;
  158204. #ifdef FMEMCOPY
  158205. FMEMCOPY(outptr, inptr, count);
  158206. #else
  158207. for (count = num_cols; count > 0; count--)
  158208. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158209. #endif
  158210. }
  158211. }
  158212. GLOBAL(void)
  158213. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158214. JDIMENSION num_blocks)
  158215. {
  158216. #ifdef FMEMCOPY
  158217. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158218. #else
  158219. register JCOEFPTR inptr, outptr;
  158220. register long count;
  158221. inptr = (JCOEFPTR) input_row;
  158222. outptr = (JCOEFPTR) output_row;
  158223. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158224. *outptr++ = *inptr++;
  158225. }
  158226. #endif
  158227. }
  158228. GLOBAL(void)
  158229. jzero_far (void FAR * target, size_t bytestozero)
  158230. {
  158231. #ifdef FMEMZERO
  158232. FMEMZERO(target, bytestozero);
  158233. #else
  158234. register char FAR * ptr = (char FAR *) target;
  158235. register size_t count;
  158236. for (count = bytestozero; count > 0; count--) {
  158237. *ptr++ = 0;
  158238. }
  158239. #endif
  158240. }
  158241. /*** End of inlined file: jutils.c ***/
  158242. /*** Start of inlined file: transupp.c ***/
  158243. #define JPEG_INTERNALS
  158244. /*** Start of inlined file: transupp.h ***/
  158245. #ifndef TRANSFORMS_SUPPORTED
  158246. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158247. #endif
  158248. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158249. #define jtransform_request_workspace jTrRequest
  158250. #define jtransform_adjust_parameters jTrAdjust
  158251. #define jtransform_execute_transformation jTrExec
  158252. #define jcopy_markers_setup jCMrkSetup
  158253. #define jcopy_markers_execute jCMrkExec
  158254. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158255. typedef enum {
  158256. JXFORM_NONE, /* no transformation */
  158257. JXFORM_FLIP_H, /* horizontal flip */
  158258. JXFORM_FLIP_V, /* vertical flip */
  158259. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158260. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158261. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158262. JXFORM_ROT_180, /* 180-degree rotation */
  158263. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158264. } JXFORM_CODE;
  158265. typedef struct {
  158266. JXFORM_CODE transform; /* image transform operator */
  158267. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158268. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158269. int num_components; /* # of components in workspace */
  158270. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158271. } jpeg_transform_info;
  158272. #if TRANSFORMS_SUPPORTED
  158273. EXTERN(void) jtransform_request_workspace
  158274. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158275. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158276. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158277. jvirt_barray_ptr *src_coef_arrays,
  158278. jpeg_transform_info *info));
  158279. EXTERN(void) jtransform_execute_transformation
  158280. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158281. jvirt_barray_ptr *src_coef_arrays,
  158282. jpeg_transform_info *info));
  158283. #endif /* TRANSFORMS_SUPPORTED */
  158284. typedef enum {
  158285. JCOPYOPT_NONE, /* copy no optional markers */
  158286. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158287. JCOPYOPT_ALL /* copy all optional markers */
  158288. } JCOPY_OPTION;
  158289. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158290. EXTERN(void) jcopy_markers_setup
  158291. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158292. EXTERN(void) jcopy_markers_execute
  158293. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158294. JCOPY_OPTION option));
  158295. /*** End of inlined file: transupp.h ***/
  158296. /* My own external interface */
  158297. #if TRANSFORMS_SUPPORTED
  158298. LOCAL(void)
  158299. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158300. jvirt_barray_ptr *src_coef_arrays)
  158301. {
  158302. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158303. int ci, k, offset_y;
  158304. JBLOCKARRAY buffer;
  158305. JCOEFPTR ptr1, ptr2;
  158306. JCOEF temp1, temp2;
  158307. jpeg_component_info *compptr;
  158308. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158309. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158310. compptr = dstinfo->comp_info + ci;
  158311. comp_width = MCU_cols * compptr->h_samp_factor;
  158312. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158313. blk_y += compptr->v_samp_factor) {
  158314. buffer = (*srcinfo->mem->access_virt_barray)
  158315. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158316. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158317. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158318. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158319. ptr1 = buffer[offset_y][blk_x];
  158320. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158321. for (k = 0; k < DCTSIZE2; k += 2) {
  158322. temp1 = *ptr1; /* swap even column */
  158323. temp2 = *ptr2;
  158324. *ptr1++ = temp2;
  158325. *ptr2++ = temp1;
  158326. temp1 = *ptr1; /* swap odd column with sign change */
  158327. temp2 = *ptr2;
  158328. *ptr1++ = -temp2;
  158329. *ptr2++ = -temp1;
  158330. }
  158331. }
  158332. }
  158333. }
  158334. }
  158335. }
  158336. LOCAL(void)
  158337. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158338. jvirt_barray_ptr *src_coef_arrays,
  158339. jvirt_barray_ptr *dst_coef_arrays)
  158340. {
  158341. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158342. int ci, i, j, offset_y;
  158343. JBLOCKARRAY src_buffer, dst_buffer;
  158344. JBLOCKROW src_row_ptr, dst_row_ptr;
  158345. JCOEFPTR src_ptr, dst_ptr;
  158346. jpeg_component_info *compptr;
  158347. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158348. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158349. compptr = dstinfo->comp_info + ci;
  158350. comp_height = MCU_rows * compptr->v_samp_factor;
  158351. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158352. dst_blk_y += compptr->v_samp_factor) {
  158353. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158354. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158355. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158356. if (dst_blk_y < comp_height) {
  158357. src_buffer = (*srcinfo->mem->access_virt_barray)
  158358. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158359. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158360. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158361. } else {
  158362. src_buffer = (*srcinfo->mem->access_virt_barray)
  158363. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158364. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158365. }
  158366. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158367. if (dst_blk_y < comp_height) {
  158368. dst_row_ptr = dst_buffer[offset_y];
  158369. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158370. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158371. dst_blk_x++) {
  158372. dst_ptr = dst_row_ptr[dst_blk_x];
  158373. src_ptr = src_row_ptr[dst_blk_x];
  158374. for (i = 0; i < DCTSIZE; i += 2) {
  158375. for (j = 0; j < DCTSIZE; j++)
  158376. *dst_ptr++ = *src_ptr++;
  158377. for (j = 0; j < DCTSIZE; j++)
  158378. *dst_ptr++ = - *src_ptr++;
  158379. }
  158380. }
  158381. } else {
  158382. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158383. compptr->width_in_blocks);
  158384. }
  158385. }
  158386. }
  158387. }
  158388. }
  158389. LOCAL(void)
  158390. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158391. jvirt_barray_ptr *src_coef_arrays,
  158392. jvirt_barray_ptr *dst_coef_arrays)
  158393. {
  158394. JDIMENSION dst_blk_x, dst_blk_y;
  158395. int ci, i, j, offset_x, offset_y;
  158396. JBLOCKARRAY src_buffer, dst_buffer;
  158397. JCOEFPTR src_ptr, dst_ptr;
  158398. jpeg_component_info *compptr;
  158399. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158400. compptr = dstinfo->comp_info + ci;
  158401. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158402. dst_blk_y += compptr->v_samp_factor) {
  158403. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158404. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158405. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158406. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158407. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158408. dst_blk_x += compptr->h_samp_factor) {
  158409. src_buffer = (*srcinfo->mem->access_virt_barray)
  158410. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158411. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158412. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158413. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158414. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158415. for (i = 0; i < DCTSIZE; i++)
  158416. for (j = 0; j < DCTSIZE; j++)
  158417. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158418. }
  158419. }
  158420. }
  158421. }
  158422. }
  158423. }
  158424. LOCAL(void)
  158425. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158426. jvirt_barray_ptr *src_coef_arrays,
  158427. jvirt_barray_ptr *dst_coef_arrays)
  158428. {
  158429. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158430. int ci, i, j, offset_x, offset_y;
  158431. JBLOCKARRAY src_buffer, dst_buffer;
  158432. JCOEFPTR src_ptr, dst_ptr;
  158433. jpeg_component_info *compptr;
  158434. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158435. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158436. compptr = dstinfo->comp_info + ci;
  158437. comp_width = MCU_cols * compptr->h_samp_factor;
  158438. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158439. dst_blk_y += compptr->v_samp_factor) {
  158440. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158441. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158442. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158443. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158444. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158445. dst_blk_x += compptr->h_samp_factor) {
  158446. src_buffer = (*srcinfo->mem->access_virt_barray)
  158447. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158448. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158449. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158450. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158451. if (dst_blk_x < comp_width) {
  158452. dst_ptr = dst_buffer[offset_y]
  158453. [comp_width - dst_blk_x - offset_x - 1];
  158454. for (i = 0; i < DCTSIZE; i++) {
  158455. for (j = 0; j < DCTSIZE; j++)
  158456. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158457. i++;
  158458. for (j = 0; j < DCTSIZE; j++)
  158459. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158460. }
  158461. } else {
  158462. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158463. for (i = 0; i < DCTSIZE; i++)
  158464. for (j = 0; j < DCTSIZE; j++)
  158465. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158466. }
  158467. }
  158468. }
  158469. }
  158470. }
  158471. }
  158472. }
  158473. LOCAL(void)
  158474. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158475. jvirt_barray_ptr *src_coef_arrays,
  158476. jvirt_barray_ptr *dst_coef_arrays)
  158477. {
  158478. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158479. int ci, i, j, offset_x, offset_y;
  158480. JBLOCKARRAY src_buffer, dst_buffer;
  158481. JCOEFPTR src_ptr, dst_ptr;
  158482. jpeg_component_info *compptr;
  158483. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158484. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158485. compptr = dstinfo->comp_info + ci;
  158486. comp_height = MCU_rows * compptr->v_samp_factor;
  158487. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158488. dst_blk_y += compptr->v_samp_factor) {
  158489. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158490. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158491. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158492. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158493. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158494. dst_blk_x += compptr->h_samp_factor) {
  158495. src_buffer = (*srcinfo->mem->access_virt_barray)
  158496. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158497. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158498. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158499. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158500. if (dst_blk_y < comp_height) {
  158501. src_ptr = src_buffer[offset_x]
  158502. [comp_height - dst_blk_y - offset_y - 1];
  158503. for (i = 0; i < DCTSIZE; i++) {
  158504. for (j = 0; j < DCTSIZE; j++) {
  158505. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158506. j++;
  158507. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158508. }
  158509. }
  158510. } else {
  158511. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158512. for (i = 0; i < DCTSIZE; i++)
  158513. for (j = 0; j < DCTSIZE; j++)
  158514. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158515. }
  158516. }
  158517. }
  158518. }
  158519. }
  158520. }
  158521. }
  158522. LOCAL(void)
  158523. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158524. jvirt_barray_ptr *src_coef_arrays,
  158525. jvirt_barray_ptr *dst_coef_arrays)
  158526. {
  158527. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158528. int ci, i, j, offset_y;
  158529. JBLOCKARRAY src_buffer, dst_buffer;
  158530. JBLOCKROW src_row_ptr, dst_row_ptr;
  158531. JCOEFPTR src_ptr, dst_ptr;
  158532. jpeg_component_info *compptr;
  158533. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158534. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158535. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158536. compptr = dstinfo->comp_info + ci;
  158537. comp_width = MCU_cols * compptr->h_samp_factor;
  158538. comp_height = MCU_rows * compptr->v_samp_factor;
  158539. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158540. dst_blk_y += compptr->v_samp_factor) {
  158541. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158542. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158543. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158544. if (dst_blk_y < comp_height) {
  158545. src_buffer = (*srcinfo->mem->access_virt_barray)
  158546. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158547. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158548. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158549. } else {
  158550. src_buffer = (*srcinfo->mem->access_virt_barray)
  158551. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158552. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158553. }
  158554. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158555. if (dst_blk_y < comp_height) {
  158556. dst_row_ptr = dst_buffer[offset_y];
  158557. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158558. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158559. dst_ptr = dst_row_ptr[dst_blk_x];
  158560. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158561. for (i = 0; i < DCTSIZE; i += 2) {
  158562. for (j = 0; j < DCTSIZE; j += 2) {
  158563. *dst_ptr++ = *src_ptr++;
  158564. *dst_ptr++ = - *src_ptr++;
  158565. }
  158566. for (j = 0; j < DCTSIZE; j += 2) {
  158567. *dst_ptr++ = - *src_ptr++;
  158568. *dst_ptr++ = *src_ptr++;
  158569. }
  158570. }
  158571. }
  158572. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158573. dst_ptr = dst_row_ptr[dst_blk_x];
  158574. src_ptr = src_row_ptr[dst_blk_x];
  158575. for (i = 0; i < DCTSIZE; i += 2) {
  158576. for (j = 0; j < DCTSIZE; j++)
  158577. *dst_ptr++ = *src_ptr++;
  158578. for (j = 0; j < DCTSIZE; j++)
  158579. *dst_ptr++ = - *src_ptr++;
  158580. }
  158581. }
  158582. } else {
  158583. dst_row_ptr = dst_buffer[offset_y];
  158584. src_row_ptr = src_buffer[offset_y];
  158585. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158586. dst_ptr = dst_row_ptr[dst_blk_x];
  158587. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158588. for (i = 0; i < DCTSIZE2; i += 2) {
  158589. *dst_ptr++ = *src_ptr++;
  158590. *dst_ptr++ = - *src_ptr++;
  158591. }
  158592. }
  158593. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158594. dst_ptr = dst_row_ptr[dst_blk_x];
  158595. src_ptr = src_row_ptr[dst_blk_x];
  158596. for (i = 0; i < DCTSIZE2; i++)
  158597. *dst_ptr++ = *src_ptr++;
  158598. }
  158599. }
  158600. }
  158601. }
  158602. }
  158603. }
  158604. LOCAL(void)
  158605. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158606. jvirt_barray_ptr *src_coef_arrays,
  158607. jvirt_barray_ptr *dst_coef_arrays)
  158608. {
  158609. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158610. int ci, i, j, offset_x, offset_y;
  158611. JBLOCKARRAY src_buffer, dst_buffer;
  158612. JCOEFPTR src_ptr, dst_ptr;
  158613. jpeg_component_info *compptr;
  158614. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158615. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158616. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158617. compptr = dstinfo->comp_info + ci;
  158618. comp_width = MCU_cols * compptr->h_samp_factor;
  158619. comp_height = MCU_rows * compptr->v_samp_factor;
  158620. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158621. dst_blk_y += compptr->v_samp_factor) {
  158622. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158623. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158624. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158625. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158626. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158627. dst_blk_x += compptr->h_samp_factor) {
  158628. src_buffer = (*srcinfo->mem->access_virt_barray)
  158629. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158630. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158631. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158632. if (dst_blk_y < comp_height) {
  158633. src_ptr = src_buffer[offset_x]
  158634. [comp_height - dst_blk_y - offset_y - 1];
  158635. if (dst_blk_x < comp_width) {
  158636. dst_ptr = dst_buffer[offset_y]
  158637. [comp_width - dst_blk_x - offset_x - 1];
  158638. for (i = 0; i < DCTSIZE; i++) {
  158639. for (j = 0; j < DCTSIZE; j++) {
  158640. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158641. j++;
  158642. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158643. }
  158644. i++;
  158645. for (j = 0; j < DCTSIZE; j++) {
  158646. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158647. j++;
  158648. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158649. }
  158650. }
  158651. } else {
  158652. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158653. for (i = 0; i < DCTSIZE; i++) {
  158654. for (j = 0; j < DCTSIZE; j++) {
  158655. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158656. j++;
  158657. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158658. }
  158659. }
  158660. }
  158661. } else {
  158662. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158663. if (dst_blk_x < comp_width) {
  158664. dst_ptr = dst_buffer[offset_y]
  158665. [comp_width - dst_blk_x - offset_x - 1];
  158666. for (i = 0; i < DCTSIZE; i++) {
  158667. for (j = 0; j < DCTSIZE; j++)
  158668. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158669. i++;
  158670. for (j = 0; j < DCTSIZE; j++)
  158671. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158672. }
  158673. } else {
  158674. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158675. for (i = 0; i < DCTSIZE; i++)
  158676. for (j = 0; j < DCTSIZE; j++)
  158677. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158678. }
  158679. }
  158680. }
  158681. }
  158682. }
  158683. }
  158684. }
  158685. }
  158686. GLOBAL(void)
  158687. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158688. jpeg_transform_info *info)
  158689. {
  158690. jvirt_barray_ptr *coef_arrays = NULL;
  158691. jpeg_component_info *compptr;
  158692. int ci;
  158693. if (info->force_grayscale &&
  158694. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158695. srcinfo->num_components == 3) {
  158696. info->num_components = 1;
  158697. } else {
  158698. info->num_components = srcinfo->num_components;
  158699. }
  158700. switch (info->transform) {
  158701. case JXFORM_NONE:
  158702. case JXFORM_FLIP_H:
  158703. break;
  158704. case JXFORM_FLIP_V:
  158705. case JXFORM_ROT_180:
  158706. coef_arrays = (jvirt_barray_ptr *)
  158707. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158708. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158709. for (ci = 0; ci < info->num_components; ci++) {
  158710. compptr = srcinfo->comp_info + ci;
  158711. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158712. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158713. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158714. (long) compptr->h_samp_factor),
  158715. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158716. (long) compptr->v_samp_factor),
  158717. (JDIMENSION) compptr->v_samp_factor);
  158718. }
  158719. break;
  158720. case JXFORM_TRANSPOSE:
  158721. case JXFORM_TRANSVERSE:
  158722. case JXFORM_ROT_90:
  158723. case JXFORM_ROT_270:
  158724. coef_arrays = (jvirt_barray_ptr *)
  158725. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158726. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158727. for (ci = 0; ci < info->num_components; ci++) {
  158728. compptr = srcinfo->comp_info + ci;
  158729. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158730. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158731. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158732. (long) compptr->v_samp_factor),
  158733. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158734. (long) compptr->h_samp_factor),
  158735. (JDIMENSION) compptr->h_samp_factor);
  158736. }
  158737. break;
  158738. }
  158739. info->workspace_coef_arrays = coef_arrays;
  158740. }
  158741. LOCAL(void)
  158742. transpose_critical_parameters (j_compress_ptr dstinfo)
  158743. {
  158744. int tblno, i, j, ci, itemp;
  158745. jpeg_component_info *compptr;
  158746. JQUANT_TBL *qtblptr;
  158747. JDIMENSION dtemp;
  158748. UINT16 qtemp;
  158749. dtemp = dstinfo->image_width;
  158750. dstinfo->image_width = dstinfo->image_height;
  158751. dstinfo->image_height = dtemp;
  158752. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158753. compptr = dstinfo->comp_info + ci;
  158754. itemp = compptr->h_samp_factor;
  158755. compptr->h_samp_factor = compptr->v_samp_factor;
  158756. compptr->v_samp_factor = itemp;
  158757. }
  158758. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158759. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158760. if (qtblptr != NULL) {
  158761. for (i = 0; i < DCTSIZE; i++) {
  158762. for (j = 0; j < i; j++) {
  158763. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158764. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158765. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158766. }
  158767. }
  158768. }
  158769. }
  158770. }
  158771. LOCAL(void)
  158772. trim_right_edge (j_compress_ptr dstinfo)
  158773. {
  158774. int ci, max_h_samp_factor;
  158775. JDIMENSION MCU_cols;
  158776. max_h_samp_factor = 1;
  158777. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158778. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158779. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158780. }
  158781. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158782. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158783. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158784. }
  158785. LOCAL(void)
  158786. trim_bottom_edge (j_compress_ptr dstinfo)
  158787. {
  158788. int ci, max_v_samp_factor;
  158789. JDIMENSION MCU_rows;
  158790. max_v_samp_factor = 1;
  158791. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158792. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158793. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158794. }
  158795. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158796. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158797. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158798. }
  158799. GLOBAL(jvirt_barray_ptr *)
  158800. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158801. j_compress_ptr dstinfo,
  158802. jvirt_barray_ptr *src_coef_arrays,
  158803. jpeg_transform_info *info)
  158804. {
  158805. if (info->force_grayscale) {
  158806. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158807. dstinfo->num_components == 3) ||
  158808. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158809. dstinfo->num_components == 1)) {
  158810. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158811. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158812. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158813. } else {
  158814. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158815. }
  158816. }
  158817. switch (info->transform) {
  158818. case JXFORM_NONE:
  158819. break;
  158820. case JXFORM_FLIP_H:
  158821. if (info->trim)
  158822. trim_right_edge(dstinfo);
  158823. break;
  158824. case JXFORM_FLIP_V:
  158825. if (info->trim)
  158826. trim_bottom_edge(dstinfo);
  158827. break;
  158828. case JXFORM_TRANSPOSE:
  158829. transpose_critical_parameters(dstinfo);
  158830. break;
  158831. case JXFORM_TRANSVERSE:
  158832. transpose_critical_parameters(dstinfo);
  158833. if (info->trim) {
  158834. trim_right_edge(dstinfo);
  158835. trim_bottom_edge(dstinfo);
  158836. }
  158837. break;
  158838. case JXFORM_ROT_90:
  158839. transpose_critical_parameters(dstinfo);
  158840. if (info->trim)
  158841. trim_right_edge(dstinfo);
  158842. break;
  158843. case JXFORM_ROT_180:
  158844. if (info->trim) {
  158845. trim_right_edge(dstinfo);
  158846. trim_bottom_edge(dstinfo);
  158847. }
  158848. break;
  158849. case JXFORM_ROT_270:
  158850. transpose_critical_parameters(dstinfo);
  158851. if (info->trim)
  158852. trim_bottom_edge(dstinfo);
  158853. break;
  158854. }
  158855. if (info->workspace_coef_arrays != NULL)
  158856. return info->workspace_coef_arrays;
  158857. return src_coef_arrays;
  158858. }
  158859. GLOBAL(void)
  158860. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158861. j_compress_ptr dstinfo,
  158862. jvirt_barray_ptr *src_coef_arrays,
  158863. jpeg_transform_info *info)
  158864. {
  158865. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158866. switch (info->transform) {
  158867. case JXFORM_NONE:
  158868. break;
  158869. case JXFORM_FLIP_H:
  158870. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158871. break;
  158872. case JXFORM_FLIP_V:
  158873. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158874. break;
  158875. case JXFORM_TRANSPOSE:
  158876. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158877. break;
  158878. case JXFORM_TRANSVERSE:
  158879. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158880. break;
  158881. case JXFORM_ROT_90:
  158882. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158883. break;
  158884. case JXFORM_ROT_180:
  158885. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158886. break;
  158887. case JXFORM_ROT_270:
  158888. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158889. break;
  158890. }
  158891. }
  158892. #endif /* TRANSFORMS_SUPPORTED */
  158893. GLOBAL(void)
  158894. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158895. {
  158896. #ifdef SAVE_MARKERS_SUPPORTED
  158897. int m;
  158898. if (option != JCOPYOPT_NONE) {
  158899. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158900. }
  158901. if (option == JCOPYOPT_ALL) {
  158902. for (m = 0; m < 16; m++)
  158903. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158904. }
  158905. #endif /* SAVE_MARKERS_SUPPORTED */
  158906. }
  158907. GLOBAL(void)
  158908. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158909. JCOPY_OPTION option)
  158910. {
  158911. jpeg_saved_marker_ptr marker;
  158912. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158913. if (dstinfo->write_JFIF_header &&
  158914. marker->marker == JPEG_APP0 &&
  158915. marker->data_length >= 5 &&
  158916. GETJOCTET(marker->data[0]) == 0x4A &&
  158917. GETJOCTET(marker->data[1]) == 0x46 &&
  158918. GETJOCTET(marker->data[2]) == 0x49 &&
  158919. GETJOCTET(marker->data[3]) == 0x46 &&
  158920. GETJOCTET(marker->data[4]) == 0)
  158921. continue; /* reject duplicate JFIF */
  158922. if (dstinfo->write_Adobe_marker &&
  158923. marker->marker == JPEG_APP0+14 &&
  158924. marker->data_length >= 5 &&
  158925. GETJOCTET(marker->data[0]) == 0x41 &&
  158926. GETJOCTET(marker->data[1]) == 0x64 &&
  158927. GETJOCTET(marker->data[2]) == 0x6F &&
  158928. GETJOCTET(marker->data[3]) == 0x62 &&
  158929. GETJOCTET(marker->data[4]) == 0x65)
  158930. continue; /* reject duplicate Adobe */
  158931. #ifdef NEED_FAR_POINTERS
  158932. {
  158933. unsigned int i;
  158934. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158935. for (i = 0; i < marker->data_length; i++)
  158936. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158937. }
  158938. #else
  158939. jpeg_write_marker(dstinfo, marker->marker,
  158940. marker->data, marker->data_length);
  158941. #endif
  158942. }
  158943. }
  158944. /*** End of inlined file: transupp.c ***/
  158945. }
  158946. #else
  158947. #define JPEG_INTERNALS
  158948. #undef FAR
  158949. #include <jpeglib.h>
  158950. #endif
  158951. }
  158952. #if JUCE_MSVC
  158953. #pragma warning (pop)
  158954. #endif
  158955. BEGIN_JUCE_NAMESPACE
  158956. namespace JPEGHelpers
  158957. {
  158958. using namespace jpeglibNamespace;
  158959. #if ! JUCE_MSVC
  158960. using jpeglibNamespace::boolean;
  158961. #endif
  158962. struct JPEGDecodingFailure {};
  158963. static void fatalErrorHandler (j_common_ptr)
  158964. {
  158965. throw JPEGDecodingFailure();
  158966. }
  158967. static void silentErrorCallback1 (j_common_ptr) {}
  158968. static void silentErrorCallback2 (j_common_ptr, int) {}
  158969. static void silentErrorCallback3 (j_common_ptr, char*) {}
  158970. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  158971. {
  158972. zerostruct (err);
  158973. err.error_exit = fatalErrorHandler;
  158974. err.emit_message = silentErrorCallback2;
  158975. err.output_message = silentErrorCallback1;
  158976. err.format_message = silentErrorCallback3;
  158977. err.reset_error_mgr = silentErrorCallback1;
  158978. }
  158979. static void dummyCallback1 (j_decompress_ptr)
  158980. {
  158981. }
  158982. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  158983. {
  158984. decompStruct->src->next_input_byte += num;
  158985. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  158986. decompStruct->src->bytes_in_buffer -= num;
  158987. }
  158988. static boolean jpegFill (j_decompress_ptr)
  158989. {
  158990. return 0;
  158991. }
  158992. static const int jpegBufferSize = 512;
  158993. struct JuceJpegDest : public jpeg_destination_mgr
  158994. {
  158995. OutputStream* output;
  158996. char* buffer;
  158997. };
  158998. static void jpegWriteInit (j_compress_ptr)
  158999. {
  159000. }
  159001. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159002. {
  159003. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159004. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159005. dest->output->write (dest->buffer, (int) numToWrite);
  159006. }
  159007. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159008. {
  159009. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159010. const int numToWrite = jpegBufferSize;
  159011. dest->next_output_byte = (JOCTET*) dest->buffer;
  159012. dest->free_in_buffer = jpegBufferSize;
  159013. return dest->output->write (dest->buffer, numToWrite);
  159014. }
  159015. }
  159016. Image* juce_loadJPEGImageFromStream (InputStream& in)
  159017. {
  159018. using namespace jpeglibNamespace;
  159019. using namespace JPEGHelpers;
  159020. MemoryBlock mb;
  159021. in.readIntoMemoryBlock (mb);
  159022. Image* image = 0;
  159023. if (mb.getSize() > 16)
  159024. {
  159025. struct jpeg_decompress_struct jpegDecompStruct;
  159026. struct jpeg_error_mgr jerr;
  159027. setupSilentErrorHandler (jerr);
  159028. jpegDecompStruct.err = &jerr;
  159029. jpeg_create_decompress (&jpegDecompStruct);
  159030. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  159031. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  159032. jpegDecompStruct.src->init_source = dummyCallback1;
  159033. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  159034. jpegDecompStruct.src->skip_input_data = jpegSkip;
  159035. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  159036. jpegDecompStruct.src->term_source = dummyCallback1;
  159037. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  159038. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  159039. try
  159040. {
  159041. jpeg_read_header (&jpegDecompStruct, TRUE);
  159042. jpeg_calc_output_dimensions (&jpegDecompStruct);
  159043. const int width = jpegDecompStruct.output_width;
  159044. const int height = jpegDecompStruct.output_height;
  159045. jpegDecompStruct.out_color_space = JCS_RGB;
  159046. JSAMPARRAY buffer
  159047. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  159048. JPOOL_IMAGE,
  159049. width * 3, 1);
  159050. if (jpeg_start_decompress (&jpegDecompStruct))
  159051. {
  159052. image = Image::createNativeImage (Image::RGB, width, height, false);
  159053. const bool hasAlphaChan = image->hasAlphaChannel();
  159054. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159055. for (int y = 0; y < height; ++y)
  159056. {
  159057. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159058. const uint8* src = *buffer;
  159059. uint8* dest = destData.getLinePointer (y);
  159060. if (hasAlphaChan)
  159061. {
  159062. for (int i = width; --i >= 0;)
  159063. {
  159064. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159065. ((PixelARGB*) dest)->premultiply();
  159066. dest += destData.pixelStride;
  159067. src += 3;
  159068. }
  159069. }
  159070. else
  159071. {
  159072. for (int i = width; --i >= 0;)
  159073. {
  159074. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159075. dest += destData.pixelStride;
  159076. src += 3;
  159077. }
  159078. }
  159079. }
  159080. jpeg_finish_decompress (&jpegDecompStruct);
  159081. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159082. }
  159083. jpeg_destroy_decompress (&jpegDecompStruct);
  159084. }
  159085. catch (...)
  159086. {}
  159087. }
  159088. return image;
  159089. }
  159090. bool juce_writeJPEGImageToStream (const Image& image,
  159091. OutputStream& out,
  159092. float quality)
  159093. {
  159094. using namespace jpeglibNamespace;
  159095. using namespace JPEGHelpers;
  159096. if (image.hasAlphaChannel())
  159097. {
  159098. // this method could fill the background in white and still save the image..
  159099. jassertfalse
  159100. return true;
  159101. }
  159102. struct jpeg_compress_struct jpegCompStruct;
  159103. struct jpeg_error_mgr jerr;
  159104. setupSilentErrorHandler (jerr);
  159105. jpegCompStruct.err = &jerr;
  159106. jpeg_create_compress (&jpegCompStruct);
  159107. JuceJpegDest dest;
  159108. jpegCompStruct.dest = &dest;
  159109. dest.output = &out;
  159110. HeapBlock <char> tempBuffer (jpegBufferSize);
  159111. dest.buffer = (char*) tempBuffer;
  159112. dest.next_output_byte = (JOCTET*) dest.buffer;
  159113. dest.free_in_buffer = jpegBufferSize;
  159114. dest.init_destination = jpegWriteInit;
  159115. dest.empty_output_buffer = jpegWriteFlush;
  159116. dest.term_destination = jpegWriteTerminate;
  159117. jpegCompStruct.image_width = image.getWidth();
  159118. jpegCompStruct.image_height = image.getHeight();
  159119. jpegCompStruct.input_components = 3;
  159120. jpegCompStruct.in_color_space = JCS_RGB;
  159121. jpegCompStruct.write_JFIF_header = 1;
  159122. jpegCompStruct.X_density = 72;
  159123. jpegCompStruct.Y_density = 72;
  159124. jpeg_set_defaults (&jpegCompStruct);
  159125. jpegCompStruct.dct_method = JDCT_FLOAT;
  159126. jpegCompStruct.optimize_coding = 1;
  159127. // jpegCompStruct.smoothing_factor = 10;
  159128. if (quality < 0.0f)
  159129. quality = 0.85f;
  159130. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159131. jpeg_start_compress (&jpegCompStruct, TRUE);
  159132. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159133. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159134. JPOOL_IMAGE,
  159135. strideBytes, 1);
  159136. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159137. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159138. {
  159139. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159140. uint8* dst = *buffer;
  159141. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159142. {
  159143. *dst++ = ((const PixelRGB*) src)->getRed();
  159144. *dst++ = ((const PixelRGB*) src)->getGreen();
  159145. *dst++ = ((const PixelRGB*) src)->getBlue();
  159146. src += srcData.pixelStride;
  159147. }
  159148. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159149. }
  159150. jpeg_finish_compress (&jpegCompStruct);
  159151. jpeg_destroy_compress (&jpegCompStruct);
  159152. out.flush();
  159153. return true;
  159154. }
  159155. END_JUCE_NAMESPACE
  159156. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159157. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159158. #ifdef _MSC_VER
  159159. #pragma warning (push)
  159160. #pragma warning (disable: 4390 4611)
  159161. #endif
  159162. namespace zlibNamespace
  159163. {
  159164. #if JUCE_INCLUDE_ZLIB_CODE
  159165. #undef OS_CODE
  159166. #undef fdopen
  159167. #undef OS_CODE
  159168. #else
  159169. #include <zlib.h>
  159170. #endif
  159171. }
  159172. namespace pnglibNamespace
  159173. {
  159174. using namespace zlibNamespace;
  159175. #if JUCE_INCLUDE_PNGLIB_CODE
  159176. #if _MSC_VER != 1310
  159177. using ::calloc; // (causes conflict in VS.NET 2003)
  159178. using ::malloc;
  159179. using ::free;
  159180. #endif
  159181. extern "C"
  159182. {
  159183. using ::abs;
  159184. #define PNG_INTERNAL
  159185. #define NO_DUMMY_DECL
  159186. #define PNG_SETJMP_NOT_SUPPORTED
  159187. /*** Start of inlined file: png.h ***/
  159188. #ifndef PNG_H
  159189. #define PNG_H
  159190. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159191. #define PNG_HEADER_VERSION_STRING \
  159192. " libpng version 1.2.21 - October 4, 2007\n"
  159193. #define PNG_LIBPNG_VER_SONUM 0
  159194. #define PNG_LIBPNG_VER_DLLNUM 13
  159195. #define PNG_LIBPNG_VER_MAJOR 1
  159196. #define PNG_LIBPNG_VER_MINOR 2
  159197. #define PNG_LIBPNG_VER_RELEASE 21
  159198. #define PNG_LIBPNG_VER_BUILD 0
  159199. #define PNG_LIBPNG_BUILD_ALPHA 1
  159200. #define PNG_LIBPNG_BUILD_BETA 2
  159201. #define PNG_LIBPNG_BUILD_RC 3
  159202. #define PNG_LIBPNG_BUILD_STABLE 4
  159203. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159204. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159205. PNG_LIBPNG_BUILD_STABLE only */
  159206. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159207. PNG_LIBPNG_BUILD_SPECIAL */
  159208. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159209. PNG_LIBPNG_BUILD_PRIVATE */
  159210. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159211. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159212. #ifndef PNG_VERSION_INFO_ONLY
  159213. #endif
  159214. /*** Start of inlined file: pngconf.h ***/
  159215. #ifndef PNGCONF_H
  159216. #define PNGCONF_H
  159217. #define PNG_1_2_X
  159218. // These are some Juce config settings that should remove any unnecessary code bloat..
  159219. #define PNG_NO_STDIO 1
  159220. #define PNG_DEBUG 0
  159221. #define PNG_NO_WARNINGS 1
  159222. #define PNG_NO_ERROR_TEXT 1
  159223. #define PNG_NO_ERROR_NUMBERS 1
  159224. #define PNG_NO_USER_MEM 1
  159225. #define PNG_NO_READ_iCCP 1
  159226. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159227. #define PNG_NO_READ_USER_CHUNKS 1
  159228. #define PNG_NO_READ_iTXt 1
  159229. #define PNG_NO_READ_sCAL 1
  159230. #define PNG_NO_READ_sPLT 1
  159231. #define png_error(a, b) png_err(a)
  159232. #define png_warning(a, b)
  159233. #define png_chunk_error(a, b) png_err(a)
  159234. #define png_chunk_warning(a, b)
  159235. #ifdef PNG_USER_CONFIG
  159236. # ifndef PNG_USER_PRIVATEBUILD
  159237. # define PNG_USER_PRIVATEBUILD
  159238. # endif
  159239. #include "pngusr.h"
  159240. #endif
  159241. #ifdef PNG_CONFIGURE_LIBPNG
  159242. #ifdef HAVE_CONFIG_H
  159243. #include "config.h"
  159244. #endif
  159245. #endif
  159246. #ifdef __STDC__
  159247. #ifdef SPECIALBUILD
  159248. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159249. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159250. #endif
  159251. #ifdef PRIVATEBUILD
  159252. # pragma message("PRIVATEBUILD is deprecated.\
  159253. Use PNG_USER_PRIVATEBUILD instead.")
  159254. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159255. #endif
  159256. #endif /* __STDC__ */
  159257. #ifndef PNG_VERSION_INFO_ONLY
  159258. # define PNG_WARN_UNINITIALIZED_ROW 1
  159259. #ifndef PNG_ZBUF_SIZE
  159260. # define PNG_ZBUF_SIZE 8192
  159261. #endif
  159262. #ifndef PNG_NO_READ_SUPPORTED
  159263. # define PNG_READ_SUPPORTED
  159264. #endif
  159265. #ifndef PNG_NO_WRITE_SUPPORTED
  159266. # define PNG_WRITE_SUPPORTED
  159267. #endif
  159268. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159269. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159270. # define PNG_MNG_FEATURES_SUPPORTED
  159271. # endif
  159272. #endif
  159273. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159274. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159275. # define PNG_FLOATING_POINT_SUPPORTED
  159276. # endif
  159277. #endif
  159278. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159279. # define PNG_MAX_MALLOC_64K
  159280. #endif
  159281. #if defined(__CYGWIN__)
  159282. # if defined(ALL_STATIC)
  159283. # if defined(PNG_BUILD_DLL)
  159284. # undef PNG_BUILD_DLL
  159285. # endif
  159286. # if defined(PNG_USE_DLL)
  159287. # undef PNG_USE_DLL
  159288. # endif
  159289. # if defined(PNG_DLL)
  159290. # undef PNG_DLL
  159291. # endif
  159292. # if !defined(PNG_STATIC)
  159293. # define PNG_STATIC
  159294. # endif
  159295. # else
  159296. # if defined (PNG_BUILD_DLL)
  159297. # if defined(PNG_STATIC)
  159298. # undef PNG_STATIC
  159299. # endif
  159300. # if defined(PNG_USE_DLL)
  159301. # undef PNG_USE_DLL
  159302. # endif
  159303. # if !defined(PNG_DLL)
  159304. # define PNG_DLL
  159305. # endif
  159306. # else
  159307. # if defined(PNG_STATIC)
  159308. # if defined(PNG_USE_DLL)
  159309. # undef PNG_USE_DLL
  159310. # endif
  159311. # if defined(PNG_DLL)
  159312. # undef PNG_DLL
  159313. # endif
  159314. # else
  159315. # if !defined(PNG_USE_DLL)
  159316. # define PNG_USE_DLL
  159317. # endif
  159318. # if !defined(PNG_DLL)
  159319. # define PNG_DLL
  159320. # endif
  159321. # endif
  159322. # endif
  159323. # endif
  159324. #endif
  159325. #if defined(_WIN32_WCE)
  159326. # include <windows.h>
  159327. # define PNG_NO_CONSOLE_IO
  159328. # ifdef PNG_DEBUG
  159329. # undef PNG_DEBUG
  159330. # endif
  159331. #endif
  159332. #ifdef PNG_BUILD_DLL
  159333. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159334. # ifndef PNG_NO_CONSOLE_IO
  159335. # define PNG_NO_CONSOLE_IO
  159336. # endif
  159337. # endif
  159338. #endif
  159339. # ifdef PNG_NO_STDIO
  159340. # ifndef PNG_NO_CONSOLE_IO
  159341. # define PNG_NO_CONSOLE_IO
  159342. # endif
  159343. # ifdef PNG_DEBUG
  159344. # if (PNG_DEBUG > 0)
  159345. # include <stdio.h>
  159346. # endif
  159347. # endif
  159348. # else
  159349. # if !defined(_WIN32_WCE)
  159350. # include <stdio.h>
  159351. # endif
  159352. # endif
  159353. #ifndef PNGARG
  159354. #ifdef OF /* zlib prototype munger */
  159355. # define PNGARG(arglist) OF(arglist)
  159356. #else
  159357. #ifdef _NO_PROTO
  159358. # define PNGARG(arglist) ()
  159359. # ifndef PNG_TYPECAST_NULL
  159360. # define PNG_TYPECAST_NULL
  159361. # endif
  159362. #else
  159363. # define PNGARG(arglist) arglist
  159364. #endif /* _NO_PROTO */
  159365. #endif /* OF */
  159366. #endif /* PNGARG */
  159367. #ifndef MACOS
  159368. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159369. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159370. # define MACOS
  159371. # endif
  159372. #endif
  159373. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159374. # include <sys/types.h>
  159375. #endif
  159376. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159377. # define PNG_SETJMP_SUPPORTED
  159378. #endif
  159379. #ifdef PNG_SETJMP_SUPPORTED
  159380. # ifdef __linux__
  159381. # ifdef _BSD_SOURCE
  159382. # define PNG_SAVE_BSD_SOURCE
  159383. # undef _BSD_SOURCE
  159384. # endif
  159385. # ifdef _SETJMP_H
  159386. __png.h__ already includes setjmp.h;
  159387. __dont__ include it again.;
  159388. # endif
  159389. # endif /* __linux__ */
  159390. # include <setjmp.h>
  159391. # ifdef __linux__
  159392. # ifdef PNG_SAVE_BSD_SOURCE
  159393. # define _BSD_SOURCE
  159394. # undef PNG_SAVE_BSD_SOURCE
  159395. # endif
  159396. # endif /* __linux__ */
  159397. #endif /* PNG_SETJMP_SUPPORTED */
  159398. #ifdef BSD
  159399. #if ! JUCE_MAC
  159400. # include <strings.h>
  159401. #endif
  159402. #else
  159403. # include <string.h>
  159404. #endif
  159405. #ifdef PNG_INTERNAL
  159406. #include <stdlib.h>
  159407. #define PNG_EXTERN
  159408. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159409. # if defined(MACOS)
  159410. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159411. # include <fp.h>
  159412. # endif
  159413. # else
  159414. # include <math.h>
  159415. # endif
  159416. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159417. # include <m68881.h>
  159418. # endif
  159419. #endif
  159420. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159421. # define PNG_ALWAYS_EXTERN
  159422. #endif
  159423. #if defined(__TURBOC__) && defined(__MSDOS__)
  159424. # include <mem.h>
  159425. # include <alloc.h>
  159426. #endif
  159427. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159428. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159429. # include <malloc.h>
  159430. #endif
  159431. #ifndef PNG_DITHER_RED_BITS
  159432. # define PNG_DITHER_RED_BITS 5
  159433. #endif
  159434. #ifndef PNG_DITHER_GREEN_BITS
  159435. # define PNG_DITHER_GREEN_BITS 5
  159436. #endif
  159437. #ifndef PNG_DITHER_BLUE_BITS
  159438. # define PNG_DITHER_BLUE_BITS 5
  159439. #endif
  159440. #ifndef PNG_MAX_GAMMA_8
  159441. # define PNG_MAX_GAMMA_8 11
  159442. #endif
  159443. #ifndef PNG_GAMMA_THRESHOLD
  159444. # define PNG_GAMMA_THRESHOLD 0.05
  159445. #endif
  159446. #endif /* PNG_INTERNAL */
  159447. #ifndef PNG_NO_CONST
  159448. # define PNG_CONST const
  159449. #else
  159450. # define PNG_CONST
  159451. #endif
  159452. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159453. # ifndef PNG_NO_iTXt_SUPPORTED
  159454. # define PNG_NO_iTXt_SUPPORTED
  159455. # endif
  159456. # ifndef PNG_NO_READ_iTXt
  159457. # define PNG_NO_READ_iTXt
  159458. # endif
  159459. # ifndef PNG_NO_WRITE_iTXt
  159460. # define PNG_NO_WRITE_iTXt
  159461. # endif
  159462. #endif
  159463. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159464. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159465. # define PNG_READ_iTXt
  159466. # endif
  159467. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159468. # define PNG_WRITE_iTXt
  159469. # endif
  159470. #endif
  159471. #ifdef PNG_LEGACY_SUPPORTED
  159472. # define PNG_NO_FREE_ME
  159473. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159474. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159475. # define PNG_NO_READ_USER_CHUNKS
  159476. # define PNG_NO_READ_iCCP
  159477. # define PNG_NO_WRITE_iCCP
  159478. # define PNG_NO_READ_iTXt
  159479. # define PNG_NO_WRITE_iTXt
  159480. # define PNG_NO_READ_sCAL
  159481. # define PNG_NO_WRITE_sCAL
  159482. # define PNG_NO_READ_sPLT
  159483. # define PNG_NO_WRITE_sPLT
  159484. # define PNG_NO_INFO_IMAGE
  159485. # define PNG_NO_READ_RGB_TO_GRAY
  159486. # define PNG_NO_READ_USER_TRANSFORM
  159487. # define PNG_NO_WRITE_USER_TRANSFORM
  159488. # define PNG_NO_USER_MEM
  159489. # define PNG_NO_READ_EMPTY_PLTE
  159490. # define PNG_NO_MNG_FEATURES
  159491. # define PNG_NO_FIXED_POINT_SUPPORTED
  159492. #endif
  159493. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159494. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159495. # define PNG_FIXED_POINT_SUPPORTED
  159496. #endif
  159497. #ifndef PNG_NO_FREE_ME
  159498. # define PNG_FREE_ME_SUPPORTED
  159499. #endif
  159500. #if defined(PNG_READ_SUPPORTED)
  159501. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159502. !defined(PNG_NO_READ_TRANSFORMS)
  159503. # define PNG_READ_TRANSFORMS_SUPPORTED
  159504. #endif
  159505. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159506. # ifndef PNG_NO_READ_EXPAND
  159507. # define PNG_READ_EXPAND_SUPPORTED
  159508. # endif
  159509. # ifndef PNG_NO_READ_SHIFT
  159510. # define PNG_READ_SHIFT_SUPPORTED
  159511. # endif
  159512. # ifndef PNG_NO_READ_PACK
  159513. # define PNG_READ_PACK_SUPPORTED
  159514. # endif
  159515. # ifndef PNG_NO_READ_BGR
  159516. # define PNG_READ_BGR_SUPPORTED
  159517. # endif
  159518. # ifndef PNG_NO_READ_SWAP
  159519. # define PNG_READ_SWAP_SUPPORTED
  159520. # endif
  159521. # ifndef PNG_NO_READ_PACKSWAP
  159522. # define PNG_READ_PACKSWAP_SUPPORTED
  159523. # endif
  159524. # ifndef PNG_NO_READ_INVERT
  159525. # define PNG_READ_INVERT_SUPPORTED
  159526. # endif
  159527. # ifndef PNG_NO_READ_DITHER
  159528. # define PNG_READ_DITHER_SUPPORTED
  159529. # endif
  159530. # ifndef PNG_NO_READ_BACKGROUND
  159531. # define PNG_READ_BACKGROUND_SUPPORTED
  159532. # endif
  159533. # ifndef PNG_NO_READ_16_TO_8
  159534. # define PNG_READ_16_TO_8_SUPPORTED
  159535. # endif
  159536. # ifndef PNG_NO_READ_FILLER
  159537. # define PNG_READ_FILLER_SUPPORTED
  159538. # endif
  159539. # ifndef PNG_NO_READ_GAMMA
  159540. # define PNG_READ_GAMMA_SUPPORTED
  159541. # endif
  159542. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159543. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159544. # endif
  159545. # ifndef PNG_NO_READ_SWAP_ALPHA
  159546. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159547. # endif
  159548. # ifndef PNG_NO_READ_INVERT_ALPHA
  159549. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159550. # endif
  159551. # ifndef PNG_NO_READ_STRIP_ALPHA
  159552. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159553. # endif
  159554. # ifndef PNG_NO_READ_USER_TRANSFORM
  159555. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159556. # endif
  159557. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159558. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159559. # endif
  159560. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159561. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159562. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159563. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159564. #endif /* about interlacing capability! You'll */
  159565. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159566. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159567. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159568. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159569. # endif
  159570. #endif
  159571. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159572. #ifndef PNG_NO_READ_EMPTY_PLTE
  159573. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159574. #endif
  159575. #endif
  159576. #endif /* PNG_READ_SUPPORTED */
  159577. #if defined(PNG_WRITE_SUPPORTED)
  159578. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159579. !defined(PNG_NO_WRITE_TRANSFORMS)
  159580. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159581. #endif
  159582. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159583. # ifndef PNG_NO_WRITE_SHIFT
  159584. # define PNG_WRITE_SHIFT_SUPPORTED
  159585. # endif
  159586. # ifndef PNG_NO_WRITE_PACK
  159587. # define PNG_WRITE_PACK_SUPPORTED
  159588. # endif
  159589. # ifndef PNG_NO_WRITE_BGR
  159590. # define PNG_WRITE_BGR_SUPPORTED
  159591. # endif
  159592. # ifndef PNG_NO_WRITE_SWAP
  159593. # define PNG_WRITE_SWAP_SUPPORTED
  159594. # endif
  159595. # ifndef PNG_NO_WRITE_PACKSWAP
  159596. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159597. # endif
  159598. # ifndef PNG_NO_WRITE_INVERT
  159599. # define PNG_WRITE_INVERT_SUPPORTED
  159600. # endif
  159601. # ifndef PNG_NO_WRITE_FILLER
  159602. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159603. # endif
  159604. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159605. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159606. # endif
  159607. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159608. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159609. # endif
  159610. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159611. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159612. # endif
  159613. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159614. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159615. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159616. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159617. encoders, but can cause trouble
  159618. if left undefined */
  159619. #endif
  159620. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159621. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159622. defined(PNG_FLOATING_POINT_SUPPORTED)
  159623. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159624. #endif
  159625. #ifndef PNG_NO_WRITE_FLUSH
  159626. # define PNG_WRITE_FLUSH_SUPPORTED
  159627. #endif
  159628. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159629. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159630. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159631. #endif
  159632. #endif
  159633. #endif /* PNG_WRITE_SUPPORTED */
  159634. #ifndef PNG_1_0_X
  159635. # ifndef PNG_NO_ERROR_NUMBERS
  159636. # define PNG_ERROR_NUMBERS_SUPPORTED
  159637. # endif
  159638. #endif /* PNG_1_0_X */
  159639. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159640. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159641. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159642. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159643. # endif
  159644. #endif
  159645. #ifndef PNG_NO_STDIO
  159646. # define PNG_TIME_RFC1123_SUPPORTED
  159647. #endif
  159648. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159649. # define PNG_EASY_ACCESS_SUPPORTED
  159650. #endif
  159651. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159652. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159653. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159654. # endif
  159655. #endif
  159656. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159657. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159658. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159659. # endif
  159660. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159661. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159662. # define PNG_NO_MMX_CODE
  159663. # endif
  159664. # endif
  159665. # if defined(__APPLE__)
  159666. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159667. # define PNG_NO_MMX_CODE
  159668. # endif
  159669. # endif
  159670. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159671. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159672. # define PNG_NO_MMX_CODE
  159673. # endif
  159674. # endif
  159675. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159676. # define PNG_MMX_CODE_SUPPORTED
  159677. # endif
  159678. #endif
  159679. #if !defined(PNG_1_0_X)
  159680. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159681. # define PNG_USER_MEM_SUPPORTED
  159682. #endif
  159683. #endif /* PNG_1_0_X */
  159684. #if !defined(PNG_1_0_X)
  159685. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159686. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159687. # define PNG_SET_USER_LIMITS_SUPPORTED
  159688. #endif
  159689. #endif
  159690. #endif /* PNG_1_0_X */
  159691. #ifndef PNG_USER_WIDTH_MAX
  159692. # define PNG_USER_WIDTH_MAX 1000000L
  159693. #endif
  159694. #ifndef PNG_USER_HEIGHT_MAX
  159695. # define PNG_USER_HEIGHT_MAX 1000000L
  159696. #endif
  159697. #if defined(PNG_READ_SUPPORTED) && \
  159698. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159699. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159700. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159701. #endif
  159702. #if defined(PNG_WRITE_SUPPORTED) && \
  159703. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159704. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159705. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159706. #endif
  159707. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159708. #ifdef PNG_NO_READ_TEXT
  159709. # define PNG_NO_READ_iTXt
  159710. # define PNG_NO_READ_tEXt
  159711. # define PNG_NO_READ_zTXt
  159712. #endif
  159713. #ifndef PNG_NO_READ_bKGD
  159714. # define PNG_READ_bKGD_SUPPORTED
  159715. # define PNG_bKGD_SUPPORTED
  159716. #endif
  159717. #ifndef PNG_NO_READ_cHRM
  159718. # define PNG_READ_cHRM_SUPPORTED
  159719. # define PNG_cHRM_SUPPORTED
  159720. #endif
  159721. #ifndef PNG_NO_READ_gAMA
  159722. # define PNG_READ_gAMA_SUPPORTED
  159723. # define PNG_gAMA_SUPPORTED
  159724. #endif
  159725. #ifndef PNG_NO_READ_hIST
  159726. # define PNG_READ_hIST_SUPPORTED
  159727. # define PNG_hIST_SUPPORTED
  159728. #endif
  159729. #ifndef PNG_NO_READ_iCCP
  159730. # define PNG_READ_iCCP_SUPPORTED
  159731. # define PNG_iCCP_SUPPORTED
  159732. #endif
  159733. #ifndef PNG_NO_READ_iTXt
  159734. # ifndef PNG_READ_iTXt_SUPPORTED
  159735. # define PNG_READ_iTXt_SUPPORTED
  159736. # endif
  159737. # ifndef PNG_iTXt_SUPPORTED
  159738. # define PNG_iTXt_SUPPORTED
  159739. # endif
  159740. #endif
  159741. #ifndef PNG_NO_READ_oFFs
  159742. # define PNG_READ_oFFs_SUPPORTED
  159743. # define PNG_oFFs_SUPPORTED
  159744. #endif
  159745. #ifndef PNG_NO_READ_pCAL
  159746. # define PNG_READ_pCAL_SUPPORTED
  159747. # define PNG_pCAL_SUPPORTED
  159748. #endif
  159749. #ifndef PNG_NO_READ_sCAL
  159750. # define PNG_READ_sCAL_SUPPORTED
  159751. # define PNG_sCAL_SUPPORTED
  159752. #endif
  159753. #ifndef PNG_NO_READ_pHYs
  159754. # define PNG_READ_pHYs_SUPPORTED
  159755. # define PNG_pHYs_SUPPORTED
  159756. #endif
  159757. #ifndef PNG_NO_READ_sBIT
  159758. # define PNG_READ_sBIT_SUPPORTED
  159759. # define PNG_sBIT_SUPPORTED
  159760. #endif
  159761. #ifndef PNG_NO_READ_sPLT
  159762. # define PNG_READ_sPLT_SUPPORTED
  159763. # define PNG_sPLT_SUPPORTED
  159764. #endif
  159765. #ifndef PNG_NO_READ_sRGB
  159766. # define PNG_READ_sRGB_SUPPORTED
  159767. # define PNG_sRGB_SUPPORTED
  159768. #endif
  159769. #ifndef PNG_NO_READ_tEXt
  159770. # define PNG_READ_tEXt_SUPPORTED
  159771. # define PNG_tEXt_SUPPORTED
  159772. #endif
  159773. #ifndef PNG_NO_READ_tIME
  159774. # define PNG_READ_tIME_SUPPORTED
  159775. # define PNG_tIME_SUPPORTED
  159776. #endif
  159777. #ifndef PNG_NO_READ_tRNS
  159778. # define PNG_READ_tRNS_SUPPORTED
  159779. # define PNG_tRNS_SUPPORTED
  159780. #endif
  159781. #ifndef PNG_NO_READ_zTXt
  159782. # define PNG_READ_zTXt_SUPPORTED
  159783. # define PNG_zTXt_SUPPORTED
  159784. #endif
  159785. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159786. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159787. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159788. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159789. # endif
  159790. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159791. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159792. # endif
  159793. #endif
  159794. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159795. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159796. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159797. # define PNG_USER_CHUNKS_SUPPORTED
  159798. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159799. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159800. # endif
  159801. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159802. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159803. # endif
  159804. #endif
  159805. #ifndef PNG_NO_READ_OPT_PLTE
  159806. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159807. #endif /* optional PLTE chunk in RGB and RGBA images */
  159808. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159809. defined(PNG_READ_zTXt_SUPPORTED)
  159810. # define PNG_READ_TEXT_SUPPORTED
  159811. # define PNG_TEXT_SUPPORTED
  159812. #endif
  159813. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159814. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159815. #ifdef PNG_NO_WRITE_TEXT
  159816. # define PNG_NO_WRITE_iTXt
  159817. # define PNG_NO_WRITE_tEXt
  159818. # define PNG_NO_WRITE_zTXt
  159819. #endif
  159820. #ifndef PNG_NO_WRITE_bKGD
  159821. # define PNG_WRITE_bKGD_SUPPORTED
  159822. # ifndef PNG_bKGD_SUPPORTED
  159823. # define PNG_bKGD_SUPPORTED
  159824. # endif
  159825. #endif
  159826. #ifndef PNG_NO_WRITE_cHRM
  159827. # define PNG_WRITE_cHRM_SUPPORTED
  159828. # ifndef PNG_cHRM_SUPPORTED
  159829. # define PNG_cHRM_SUPPORTED
  159830. # endif
  159831. #endif
  159832. #ifndef PNG_NO_WRITE_gAMA
  159833. # define PNG_WRITE_gAMA_SUPPORTED
  159834. # ifndef PNG_gAMA_SUPPORTED
  159835. # define PNG_gAMA_SUPPORTED
  159836. # endif
  159837. #endif
  159838. #ifndef PNG_NO_WRITE_hIST
  159839. # define PNG_WRITE_hIST_SUPPORTED
  159840. # ifndef PNG_hIST_SUPPORTED
  159841. # define PNG_hIST_SUPPORTED
  159842. # endif
  159843. #endif
  159844. #ifndef PNG_NO_WRITE_iCCP
  159845. # define PNG_WRITE_iCCP_SUPPORTED
  159846. # ifndef PNG_iCCP_SUPPORTED
  159847. # define PNG_iCCP_SUPPORTED
  159848. # endif
  159849. #endif
  159850. #ifndef PNG_NO_WRITE_iTXt
  159851. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159852. # define PNG_WRITE_iTXt_SUPPORTED
  159853. # endif
  159854. # ifndef PNG_iTXt_SUPPORTED
  159855. # define PNG_iTXt_SUPPORTED
  159856. # endif
  159857. #endif
  159858. #ifndef PNG_NO_WRITE_oFFs
  159859. # define PNG_WRITE_oFFs_SUPPORTED
  159860. # ifndef PNG_oFFs_SUPPORTED
  159861. # define PNG_oFFs_SUPPORTED
  159862. # endif
  159863. #endif
  159864. #ifndef PNG_NO_WRITE_pCAL
  159865. # define PNG_WRITE_pCAL_SUPPORTED
  159866. # ifndef PNG_pCAL_SUPPORTED
  159867. # define PNG_pCAL_SUPPORTED
  159868. # endif
  159869. #endif
  159870. #ifndef PNG_NO_WRITE_sCAL
  159871. # define PNG_WRITE_sCAL_SUPPORTED
  159872. # ifndef PNG_sCAL_SUPPORTED
  159873. # define PNG_sCAL_SUPPORTED
  159874. # endif
  159875. #endif
  159876. #ifndef PNG_NO_WRITE_pHYs
  159877. # define PNG_WRITE_pHYs_SUPPORTED
  159878. # ifndef PNG_pHYs_SUPPORTED
  159879. # define PNG_pHYs_SUPPORTED
  159880. # endif
  159881. #endif
  159882. #ifndef PNG_NO_WRITE_sBIT
  159883. # define PNG_WRITE_sBIT_SUPPORTED
  159884. # ifndef PNG_sBIT_SUPPORTED
  159885. # define PNG_sBIT_SUPPORTED
  159886. # endif
  159887. #endif
  159888. #ifndef PNG_NO_WRITE_sPLT
  159889. # define PNG_WRITE_sPLT_SUPPORTED
  159890. # ifndef PNG_sPLT_SUPPORTED
  159891. # define PNG_sPLT_SUPPORTED
  159892. # endif
  159893. #endif
  159894. #ifndef PNG_NO_WRITE_sRGB
  159895. # define PNG_WRITE_sRGB_SUPPORTED
  159896. # ifndef PNG_sRGB_SUPPORTED
  159897. # define PNG_sRGB_SUPPORTED
  159898. # endif
  159899. #endif
  159900. #ifndef PNG_NO_WRITE_tEXt
  159901. # define PNG_WRITE_tEXt_SUPPORTED
  159902. # ifndef PNG_tEXt_SUPPORTED
  159903. # define PNG_tEXt_SUPPORTED
  159904. # endif
  159905. #endif
  159906. #ifndef PNG_NO_WRITE_tIME
  159907. # define PNG_WRITE_tIME_SUPPORTED
  159908. # ifndef PNG_tIME_SUPPORTED
  159909. # define PNG_tIME_SUPPORTED
  159910. # endif
  159911. #endif
  159912. #ifndef PNG_NO_WRITE_tRNS
  159913. # define PNG_WRITE_tRNS_SUPPORTED
  159914. # ifndef PNG_tRNS_SUPPORTED
  159915. # define PNG_tRNS_SUPPORTED
  159916. # endif
  159917. #endif
  159918. #ifndef PNG_NO_WRITE_zTXt
  159919. # define PNG_WRITE_zTXt_SUPPORTED
  159920. # ifndef PNG_zTXt_SUPPORTED
  159921. # define PNG_zTXt_SUPPORTED
  159922. # endif
  159923. #endif
  159924. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159925. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159926. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159927. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159928. # endif
  159929. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159930. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159931. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159932. # endif
  159933. # endif
  159934. #endif
  159935. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159936. defined(PNG_WRITE_zTXt_SUPPORTED)
  159937. # define PNG_WRITE_TEXT_SUPPORTED
  159938. # ifndef PNG_TEXT_SUPPORTED
  159939. # define PNG_TEXT_SUPPORTED
  159940. # endif
  159941. #endif
  159942. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159943. #ifndef PNG_NO_INFO_IMAGE
  159944. # define PNG_INFO_IMAGE_SUPPORTED
  159945. #endif
  159946. #if defined(PNG_tIME_SUPPORTED)
  159947. # if !defined(_WIN32_WCE)
  159948. # include <time.h>
  159949. # endif
  159950. #endif
  159951. typedef unsigned long png_uint_32;
  159952. typedef long png_int_32;
  159953. typedef unsigned short png_uint_16;
  159954. typedef short png_int_16;
  159955. typedef unsigned char png_byte;
  159956. #ifdef PNG_SIZE_T
  159957. typedef PNG_SIZE_T png_size_t;
  159958. # define png_sizeof(x) png_convert_size(sizeof (x))
  159959. #else
  159960. typedef size_t png_size_t;
  159961. # define png_sizeof(x) sizeof (x)
  159962. #endif
  159963. #ifdef __BORLANDC__
  159964. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  159965. # define LDATA 1
  159966. # else
  159967. # define LDATA 0
  159968. # endif
  159969. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  159970. # define PNG_MAX_MALLOC_64K
  159971. # if (LDATA != 1)
  159972. # ifndef FAR
  159973. # define FAR __far
  159974. # endif
  159975. # define USE_FAR_KEYWORD
  159976. # endif /* LDATA != 1 */
  159977. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  159978. #endif /* __BORLANDC__ */
  159979. #if defined(FAR)
  159980. # if defined(M_I86MM)
  159981. # define USE_FAR_KEYWORD
  159982. # define FARDATA FAR
  159983. # include <dos.h>
  159984. # endif
  159985. #endif
  159986. #ifndef FAR
  159987. # define FAR
  159988. #endif
  159989. #ifndef FARDATA
  159990. # define FARDATA
  159991. #endif
  159992. typedef png_int_32 png_fixed_point;
  159993. typedef void FAR * png_voidp;
  159994. typedef png_byte FAR * png_bytep;
  159995. typedef png_uint_32 FAR * png_uint_32p;
  159996. typedef png_int_32 FAR * png_int_32p;
  159997. typedef png_uint_16 FAR * png_uint_16p;
  159998. typedef png_int_16 FAR * png_int_16p;
  159999. typedef PNG_CONST char FAR * png_const_charp;
  160000. typedef char FAR * png_charp;
  160001. typedef png_fixed_point FAR * png_fixed_point_p;
  160002. #ifndef PNG_NO_STDIO
  160003. #if defined(_WIN32_WCE)
  160004. typedef HANDLE png_FILE_p;
  160005. #else
  160006. typedef FILE * png_FILE_p;
  160007. #endif
  160008. #endif
  160009. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160010. typedef double FAR * png_doublep;
  160011. #endif
  160012. typedef png_byte FAR * FAR * png_bytepp;
  160013. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  160014. typedef png_int_32 FAR * FAR * png_int_32pp;
  160015. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  160016. typedef png_int_16 FAR * FAR * png_int_16pp;
  160017. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  160018. typedef char FAR * FAR * png_charpp;
  160019. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  160020. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160021. typedef double FAR * FAR * png_doublepp;
  160022. #endif
  160023. typedef char FAR * FAR * FAR * png_charppp;
  160024. #if 0
  160025. typedef charf * png_zcharp;
  160026. typedef charf * FAR * png_zcharpp;
  160027. typedef z_stream FAR * png_zstreamp;
  160028. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  160029. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  160030. # define PNG_DLL
  160031. #endif
  160032. #if defined(__CYGWIN__)
  160033. # if !defined(PNG_STATIC)
  160034. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160035. # undef PNG_USE_GLOBAL_ARRAYS
  160036. # endif
  160037. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160038. # define PNG_USE_LOCAL_ARRAYS
  160039. # endif
  160040. # else
  160041. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160042. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160043. # undef PNG_USE_GLOBAL_ARRAYS
  160044. # endif
  160045. # endif
  160046. # endif
  160047. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160048. # define PNG_USE_LOCAL_ARRAYS
  160049. # endif
  160050. #endif
  160051. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160052. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160053. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160054. # define PNG_USE_LOCAL_ARRAYS
  160055. # else
  160056. # define PNG_USE_GLOBAL_ARRAYS
  160057. # endif
  160058. #endif
  160059. #if defined(__CYGWIN__)
  160060. # undef PNGAPI
  160061. # define PNGAPI __cdecl
  160062. # undef PNG_IMPEXP
  160063. # define PNG_IMPEXP
  160064. #endif
  160065. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160066. # ifndef PNG_NO_MODULEDEF
  160067. # define PNG_NO_MODULEDEF
  160068. # endif
  160069. #endif
  160070. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160071. # define PNG_IMPEXP
  160072. #endif
  160073. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160074. (( defined(_Windows) || defined(_WINDOWS) || \
  160075. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160076. # ifndef PNGAPI
  160077. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160078. # define PNGAPI __cdecl
  160079. # else
  160080. # define PNGAPI _cdecl
  160081. # endif
  160082. # endif
  160083. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160084. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160085. # define PNG_IMPEXP
  160086. # endif
  160087. # if !defined(PNG_IMPEXP)
  160088. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160089. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160090. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160091. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160092. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160093. # else
  160094. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160095. # if defined(PNG_BUILD_DLL)
  160096. # define PNG_IMPEXP __export
  160097. # else
  160098. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160099. VC++ */
  160100. # endif /* Exists in Borland C++ for
  160101. C++ classes (== huge) */
  160102. # endif
  160103. # endif
  160104. # if !defined(PNG_IMPEXP)
  160105. # if defined(PNG_BUILD_DLL)
  160106. # define PNG_IMPEXP __declspec(dllexport)
  160107. # else
  160108. # define PNG_IMPEXP __declspec(dllimport)
  160109. # endif
  160110. # endif
  160111. # endif /* PNG_IMPEXP */
  160112. #else /* !(DLL || non-cygwin WINDOWS) */
  160113. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160114. # ifndef PNGAPI
  160115. # define PNGAPI _System
  160116. # endif
  160117. # else
  160118. # if 0 /* ... other platforms, with other meanings */
  160119. # endif
  160120. # endif
  160121. #endif
  160122. #ifndef PNGAPI
  160123. # define PNGAPI
  160124. #endif
  160125. #ifndef PNG_IMPEXP
  160126. # define PNG_IMPEXP
  160127. #endif
  160128. #ifdef PNG_BUILDSYMS
  160129. # ifndef PNG_EXPORT
  160130. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160131. # endif
  160132. # ifdef PNG_USE_GLOBAL_ARRAYS
  160133. # ifndef PNG_EXPORT_VAR
  160134. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160135. # endif
  160136. # endif
  160137. #endif
  160138. #ifndef PNG_EXPORT
  160139. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160140. #endif
  160141. #ifdef PNG_USE_GLOBAL_ARRAYS
  160142. # ifndef PNG_EXPORT_VAR
  160143. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160144. # endif
  160145. #endif
  160146. #ifndef PNG_ABORT
  160147. # define PNG_ABORT() abort()
  160148. #endif
  160149. #ifdef PNG_SETJMP_SUPPORTED
  160150. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160151. #else
  160152. # define png_jmpbuf(png_ptr) \
  160153. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160154. #endif
  160155. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160156. # define CHECK 1
  160157. # define NOCHECK 0
  160158. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160159. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160160. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160161. # define png_strcpy _fstrcpy
  160162. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160163. # define png_strlen _fstrlen
  160164. # define png_memcmp _fmemcmp /* SJT: added */
  160165. # define png_memcpy _fmemcpy
  160166. # define png_memset _fmemset
  160167. #else /* use the usual functions */
  160168. # define CVT_PTR(ptr) (ptr)
  160169. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160170. # ifndef PNG_NO_SNPRINTF
  160171. # ifdef _MSC_VER
  160172. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160173. # define png_snprintf2 _snprintf
  160174. # define png_snprintf6 _snprintf
  160175. # else
  160176. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160177. # define png_snprintf2 snprintf
  160178. # define png_snprintf6 snprintf
  160179. # endif
  160180. # else
  160181. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160182. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160183. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160184. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160185. # endif
  160186. # define png_strcpy strcpy
  160187. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160188. # define png_strlen strlen
  160189. # define png_memcmp memcmp /* SJT: added */
  160190. # define png_memcpy memcpy
  160191. # define png_memset memset
  160192. #endif
  160193. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160194. # undef PNG_ZBUF_SIZE
  160195. # define PNG_ZBUF_SIZE 65536L
  160196. #endif
  160197. #endif /* PNG_VERSION_INFO_ONLY */
  160198. #endif /* PNGCONF_H */
  160199. /*** End of inlined file: pngconf.h ***/
  160200. #ifdef _MSC_VER
  160201. #pragma warning (disable: 4996 4100)
  160202. #endif
  160203. #if defined(PNG_USER_PRIVATEBUILD)
  160204. # define PNG_LIBPNG_BUILD_TYPE \
  160205. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160206. #else
  160207. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160208. # define PNG_LIBPNG_BUILD_TYPE \
  160209. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160210. # else
  160211. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160212. # endif
  160213. #endif
  160214. #ifndef PNG_VERSION_INFO_ONLY
  160215. #ifdef __cplusplus
  160216. extern "C" {
  160217. #endif /* __cplusplus */
  160218. #ifndef PNG_NO_TYPECAST_NULL
  160219. #define int_p_NULL (int *)NULL
  160220. #define png_bytep_NULL (png_bytep)NULL
  160221. #define png_bytepp_NULL (png_bytepp)NULL
  160222. #define png_doublep_NULL (png_doublep)NULL
  160223. #define png_error_ptr_NULL (png_error_ptr)NULL
  160224. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160225. #define png_free_ptr_NULL (png_free_ptr)NULL
  160226. #define png_infopp_NULL (png_infopp)NULL
  160227. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160228. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160229. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160230. #define png_structp_NULL (png_structp)NULL
  160231. #define png_uint_16p_NULL (png_uint_16p)NULL
  160232. #define png_voidp_NULL (png_voidp)NULL
  160233. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160234. #else
  160235. #define int_p_NULL NULL
  160236. #define png_bytep_NULL NULL
  160237. #define png_bytepp_NULL NULL
  160238. #define png_doublep_NULL NULL
  160239. #define png_error_ptr_NULL NULL
  160240. #define png_flush_ptr_NULL NULL
  160241. #define png_free_ptr_NULL NULL
  160242. #define png_infopp_NULL NULL
  160243. #define png_malloc_ptr_NULL NULL
  160244. #define png_read_status_ptr_NULL NULL
  160245. #define png_rw_ptr_NULL NULL
  160246. #define png_structp_NULL NULL
  160247. #define png_uint_16p_NULL NULL
  160248. #define png_voidp_NULL NULL
  160249. #define png_write_status_ptr_NULL NULL
  160250. #endif
  160251. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160252. #ifdef PNG_USE_GLOBAL_ARRAYS
  160253. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160254. #else
  160255. #define png_libpng_ver png_get_header_ver(NULL)
  160256. #endif
  160257. #ifdef PNG_USE_GLOBAL_ARRAYS
  160258. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160259. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160260. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160261. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160262. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160263. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160264. #endif
  160265. #endif /* PNG_NO_EXTERN */
  160266. typedef struct png_color_struct
  160267. {
  160268. png_byte red;
  160269. png_byte green;
  160270. png_byte blue;
  160271. } png_color;
  160272. typedef png_color FAR * png_colorp;
  160273. typedef png_color FAR * FAR * png_colorpp;
  160274. typedef struct png_color_16_struct
  160275. {
  160276. png_byte index; /* used for palette files */
  160277. png_uint_16 red; /* for use in red green blue files */
  160278. png_uint_16 green;
  160279. png_uint_16 blue;
  160280. png_uint_16 gray; /* for use in grayscale files */
  160281. } png_color_16;
  160282. typedef png_color_16 FAR * png_color_16p;
  160283. typedef png_color_16 FAR * FAR * png_color_16pp;
  160284. typedef struct png_color_8_struct
  160285. {
  160286. png_byte red; /* for use in red green blue files */
  160287. png_byte green;
  160288. png_byte blue;
  160289. png_byte gray; /* for use in grayscale files */
  160290. png_byte alpha; /* for alpha channel files */
  160291. } png_color_8;
  160292. typedef png_color_8 FAR * png_color_8p;
  160293. typedef png_color_8 FAR * FAR * png_color_8pp;
  160294. typedef struct png_sPLT_entry_struct
  160295. {
  160296. png_uint_16 red;
  160297. png_uint_16 green;
  160298. png_uint_16 blue;
  160299. png_uint_16 alpha;
  160300. png_uint_16 frequency;
  160301. } png_sPLT_entry;
  160302. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160303. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160304. typedef struct png_sPLT_struct
  160305. {
  160306. png_charp name; /* palette name */
  160307. png_byte depth; /* depth of palette samples */
  160308. png_sPLT_entryp entries; /* palette entries */
  160309. png_int_32 nentries; /* number of palette entries */
  160310. } png_sPLT_t;
  160311. typedef png_sPLT_t FAR * png_sPLT_tp;
  160312. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160313. #ifdef PNG_TEXT_SUPPORTED
  160314. typedef struct png_text_struct
  160315. {
  160316. int compression; /* compression value:
  160317. -1: tEXt, none
  160318. 0: zTXt, deflate
  160319. 1: iTXt, none
  160320. 2: iTXt, deflate */
  160321. png_charp key; /* keyword, 1-79 character description of "text" */
  160322. png_charp text; /* comment, may be an empty string (ie "")
  160323. or a NULL pointer */
  160324. png_size_t text_length; /* length of the text string */
  160325. #ifdef PNG_iTXt_SUPPORTED
  160326. png_size_t itxt_length; /* length of the itxt string */
  160327. png_charp lang; /* language code, 0-79 characters
  160328. or a NULL pointer */
  160329. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160330. chars or a NULL pointer */
  160331. #endif
  160332. } png_text;
  160333. typedef png_text FAR * png_textp;
  160334. typedef png_text FAR * FAR * png_textpp;
  160335. #endif
  160336. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160337. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160338. #define PNG_TEXT_COMPRESSION_NONE -1
  160339. #define PNG_TEXT_COMPRESSION_zTXt 0
  160340. #define PNG_ITXT_COMPRESSION_NONE 1
  160341. #define PNG_ITXT_COMPRESSION_zTXt 2
  160342. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160343. typedef struct png_time_struct
  160344. {
  160345. png_uint_16 year; /* full year, as in, 1995 */
  160346. png_byte month; /* month of year, 1 - 12 */
  160347. png_byte day; /* day of month, 1 - 31 */
  160348. png_byte hour; /* hour of day, 0 - 23 */
  160349. png_byte minute; /* minute of hour, 0 - 59 */
  160350. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160351. } png_time;
  160352. typedef png_time FAR * png_timep;
  160353. typedef png_time FAR * FAR * png_timepp;
  160354. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160355. typedef struct png_unknown_chunk_t
  160356. {
  160357. png_byte name[5];
  160358. png_byte *data;
  160359. png_size_t size;
  160360. png_byte location; /* mode of operation at read time */
  160361. }
  160362. png_unknown_chunk;
  160363. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160364. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160365. #endif
  160366. typedef struct png_info_struct
  160367. {
  160368. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160369. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160370. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160371. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160372. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160373. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160374. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160375. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160376. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160377. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160378. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160379. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160380. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160381. png_byte pixel_depth; /* number of bits per pixel */
  160382. png_byte spare_byte; /* to align the data, and for future use */
  160383. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160384. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160385. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160386. #endif
  160387. #if defined(PNG_sRGB_SUPPORTED)
  160388. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160389. #endif
  160390. #if defined(PNG_TEXT_SUPPORTED)
  160391. int num_text; /* number of comments read/to write */
  160392. int max_text; /* current size of text array */
  160393. png_textp text; /* array of comments read/to write */
  160394. #endif /* PNG_TEXT_SUPPORTED */
  160395. #if defined(PNG_tIME_SUPPORTED)
  160396. png_time mod_time;
  160397. #endif
  160398. #if defined(PNG_sBIT_SUPPORTED)
  160399. png_color_8 sig_bit; /* significant bits in color channels */
  160400. #endif
  160401. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160402. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160403. png_bytep trans; /* transparent values for paletted image */
  160404. png_color_16 trans_values; /* transparent color for non-palette image */
  160405. #endif
  160406. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160407. png_color_16 background;
  160408. #endif
  160409. #if defined(PNG_oFFs_SUPPORTED)
  160410. png_int_32 x_offset; /* x offset on page */
  160411. png_int_32 y_offset; /* y offset on page */
  160412. png_byte offset_unit_type; /* offset units type */
  160413. #endif
  160414. #if defined(PNG_pHYs_SUPPORTED)
  160415. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160416. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160417. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160418. #endif
  160419. #if defined(PNG_hIST_SUPPORTED)
  160420. png_uint_16p hist;
  160421. #endif
  160422. #ifdef PNG_cHRM_SUPPORTED
  160423. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160424. float x_white;
  160425. float y_white;
  160426. float x_red;
  160427. float y_red;
  160428. float x_green;
  160429. float y_green;
  160430. float x_blue;
  160431. float y_blue;
  160432. #endif
  160433. #endif
  160434. #if defined(PNG_pCAL_SUPPORTED)
  160435. png_charp pcal_purpose; /* pCAL chunk description string */
  160436. png_int_32 pcal_X0; /* minimum value */
  160437. png_int_32 pcal_X1; /* maximum value */
  160438. png_charp pcal_units; /* Latin-1 string giving physical units */
  160439. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160440. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160441. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160442. #endif
  160443. #ifdef PNG_FREE_ME_SUPPORTED
  160444. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160445. #endif
  160446. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160447. png_unknown_chunkp unknown_chunks;
  160448. png_size_t unknown_chunks_num;
  160449. #endif
  160450. #if defined(PNG_iCCP_SUPPORTED)
  160451. png_charp iccp_name; /* profile name */
  160452. png_charp iccp_profile; /* International Color Consortium profile data */
  160453. png_uint_32 iccp_proflen; /* ICC profile data length */
  160454. png_byte iccp_compression; /* Always zero */
  160455. #endif
  160456. #if defined(PNG_sPLT_SUPPORTED)
  160457. png_sPLT_tp splt_palettes;
  160458. png_uint_32 splt_palettes_num;
  160459. #endif
  160460. #if defined(PNG_sCAL_SUPPORTED)
  160461. png_byte scal_unit; /* unit of physical scale */
  160462. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160463. double scal_pixel_width; /* width of one pixel */
  160464. double scal_pixel_height; /* height of one pixel */
  160465. #endif
  160466. #ifdef PNG_FIXED_POINT_SUPPORTED
  160467. png_charp scal_s_width; /* string containing height */
  160468. png_charp scal_s_height; /* string containing width */
  160469. #endif
  160470. #endif
  160471. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160472. png_bytepp row_pointers; /* the image bits */
  160473. #endif
  160474. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160475. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160476. #endif
  160477. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160478. png_fixed_point int_x_white;
  160479. png_fixed_point int_y_white;
  160480. png_fixed_point int_x_red;
  160481. png_fixed_point int_y_red;
  160482. png_fixed_point int_x_green;
  160483. png_fixed_point int_y_green;
  160484. png_fixed_point int_x_blue;
  160485. png_fixed_point int_y_blue;
  160486. #endif
  160487. } png_info;
  160488. typedef png_info FAR * png_infop;
  160489. typedef png_info FAR * FAR * png_infopp;
  160490. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160491. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160492. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160493. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160494. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160495. #endif
  160496. #define PNG_COLOR_MASK_PALETTE 1
  160497. #define PNG_COLOR_MASK_COLOR 2
  160498. #define PNG_COLOR_MASK_ALPHA 4
  160499. #define PNG_COLOR_TYPE_GRAY 0
  160500. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160501. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160502. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160503. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160504. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160505. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160506. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160507. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160508. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160509. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160510. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160511. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160512. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160513. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160514. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160515. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160516. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160517. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160518. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160519. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160520. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160521. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160522. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160523. #define PNG_SCALE_METER 1 /* meters per pixel */
  160524. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160525. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160526. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160527. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160528. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160529. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160530. #define PNG_sRGB_INTENT_RELATIVE 1
  160531. #define PNG_sRGB_INTENT_SATURATION 2
  160532. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160533. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160534. #define PNG_KEYWORD_MAX_LENGTH 79
  160535. #define PNG_MAX_PALETTE_LENGTH 256
  160536. #define PNG_INFO_gAMA 0x0001
  160537. #define PNG_INFO_sBIT 0x0002
  160538. #define PNG_INFO_cHRM 0x0004
  160539. #define PNG_INFO_PLTE 0x0008
  160540. #define PNG_INFO_tRNS 0x0010
  160541. #define PNG_INFO_bKGD 0x0020
  160542. #define PNG_INFO_hIST 0x0040
  160543. #define PNG_INFO_pHYs 0x0080
  160544. #define PNG_INFO_oFFs 0x0100
  160545. #define PNG_INFO_tIME 0x0200
  160546. #define PNG_INFO_pCAL 0x0400
  160547. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160548. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160549. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160550. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160551. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160552. typedef struct png_row_info_struct
  160553. {
  160554. png_uint_32 width; /* width of row */
  160555. png_uint_32 rowbytes; /* number of bytes in row */
  160556. png_byte color_type; /* color type of row */
  160557. png_byte bit_depth; /* bit depth of row */
  160558. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160559. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160560. } png_row_info;
  160561. typedef png_row_info FAR * png_row_infop;
  160562. typedef png_row_info FAR * FAR * png_row_infopp;
  160563. typedef struct png_struct_def png_struct;
  160564. typedef png_struct FAR * png_structp;
  160565. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160566. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160567. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160568. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160569. int));
  160570. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160571. int));
  160572. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160573. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160574. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160575. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160576. png_uint_32, int));
  160577. #endif
  160578. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160579. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160580. defined(PNG_LEGACY_SUPPORTED)
  160581. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160582. png_row_infop, png_bytep));
  160583. #endif
  160584. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160585. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160586. #endif
  160587. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160588. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160589. #endif
  160590. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160591. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160592. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160593. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160594. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160595. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160596. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160597. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160598. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160599. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160600. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160601. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160602. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160603. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160604. #define PNG_FLAG_MNG_FILTER_64 0x04
  160605. #define PNG_ALL_MNG_FEATURES 0x05
  160606. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160607. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160608. struct png_struct_def
  160609. {
  160610. #ifdef PNG_SETJMP_SUPPORTED
  160611. jmp_buf jmpbuf; /* used in png_error */
  160612. #endif
  160613. png_error_ptr error_fn; /* function for printing errors and aborting */
  160614. png_error_ptr warning_fn; /* function for printing warnings */
  160615. png_voidp error_ptr; /* user supplied struct for error functions */
  160616. png_rw_ptr write_data_fn; /* function for writing output data */
  160617. png_rw_ptr read_data_fn; /* function for reading input data */
  160618. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160619. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160620. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160621. #endif
  160622. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160623. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160624. #endif
  160625. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160626. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160627. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160628. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160629. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160630. png_byte user_transform_channels; /* channels in user transformed pixels */
  160631. #endif
  160632. #endif
  160633. png_uint_32 mode; /* tells us where we are in the PNG file */
  160634. png_uint_32 flags; /* flags indicating various things to libpng */
  160635. png_uint_32 transformations; /* which transformations to perform */
  160636. z_stream zstream; /* pointer to decompression structure (below) */
  160637. png_bytep zbuf; /* buffer for zlib */
  160638. png_size_t zbuf_size; /* size of zbuf */
  160639. int zlib_level; /* holds zlib compression level */
  160640. int zlib_method; /* holds zlib compression method */
  160641. int zlib_window_bits; /* holds zlib compression window bits */
  160642. int zlib_mem_level; /* holds zlib compression memory level */
  160643. int zlib_strategy; /* holds zlib compression strategy */
  160644. png_uint_32 width; /* width of image in pixels */
  160645. png_uint_32 height; /* height of image in pixels */
  160646. png_uint_32 num_rows; /* number of rows in current pass */
  160647. png_uint_32 usr_width; /* width of row at start of write */
  160648. png_uint_32 rowbytes; /* size of row in bytes */
  160649. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160650. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160651. png_uint_32 row_number; /* current row in interlace pass */
  160652. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160653. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160654. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160655. png_bytep up_row; /* buffer to save "up" row when filtering */
  160656. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160657. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160658. png_row_info row_info; /* used for transformation routines */
  160659. png_uint_32 idat_size; /* current IDAT size for read */
  160660. png_uint_32 crc; /* current chunk CRC value */
  160661. png_colorp palette; /* palette from the input file */
  160662. png_uint_16 num_palette; /* number of color entries in palette */
  160663. png_uint_16 num_trans; /* number of transparency values */
  160664. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160665. png_byte compression; /* file compression type (always 0) */
  160666. png_byte filter; /* file filter type (always 0) */
  160667. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160668. png_byte pass; /* current interlace pass (0 - 6) */
  160669. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160670. png_byte color_type; /* color type of file */
  160671. png_byte bit_depth; /* bit depth of file */
  160672. png_byte usr_bit_depth; /* bit depth of users row */
  160673. png_byte pixel_depth; /* number of bits per pixel */
  160674. png_byte channels; /* number of channels in file */
  160675. png_byte usr_channels; /* channels at start of write */
  160676. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160677. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160678. #ifdef PNG_LEGACY_SUPPORTED
  160679. png_byte filler; /* filler byte for pixel expansion */
  160680. #else
  160681. png_uint_16 filler; /* filler bytes for pixel expansion */
  160682. #endif
  160683. #endif
  160684. #if defined(PNG_bKGD_SUPPORTED)
  160685. png_byte background_gamma_type;
  160686. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160687. float background_gamma;
  160688. # endif
  160689. png_color_16 background; /* background color in screen gamma space */
  160690. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160691. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160692. #endif
  160693. #endif /* PNG_bKGD_SUPPORTED */
  160694. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160695. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160696. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160697. png_uint_32 flush_rows; /* number of rows written since last flush */
  160698. #endif
  160699. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160700. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160701. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160702. float gamma; /* file gamma value */
  160703. float screen_gamma; /* screen gamma value (display_exponent) */
  160704. #endif
  160705. #endif
  160706. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160707. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160708. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160709. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160710. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160711. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160712. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160713. #endif
  160714. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160715. png_color_8 sig_bit; /* significant bits in each available channel */
  160716. #endif
  160717. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160718. png_color_8 shift; /* shift for significant bit tranformation */
  160719. #endif
  160720. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160721. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160722. png_bytep trans; /* transparency values for paletted files */
  160723. png_color_16 trans_values; /* transparency values for non-paletted files */
  160724. #endif
  160725. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160726. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160727. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160728. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160729. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160730. png_progressive_end_ptr end_fn; /* called after image is complete */
  160731. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160732. png_bytep save_buffer; /* buffer for previously read data */
  160733. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160734. png_bytep current_buffer; /* buffer for recently used data */
  160735. png_uint_32 push_length; /* size of current input chunk */
  160736. png_uint_32 skip_length; /* bytes to skip in input data */
  160737. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160738. png_size_t save_buffer_max; /* total size of save_buffer */
  160739. png_size_t buffer_size; /* total amount of available input data */
  160740. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160741. int process_mode; /* what push library is currently doing */
  160742. int cur_palette; /* current push library palette index */
  160743. # if defined(PNG_TEXT_SUPPORTED)
  160744. png_size_t current_text_size; /* current size of text input data */
  160745. png_size_t current_text_left; /* how much text left to read in input */
  160746. png_charp current_text; /* current text chunk buffer */
  160747. png_charp current_text_ptr; /* current location in current_text */
  160748. # endif /* PNG_TEXT_SUPPORTED */
  160749. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160750. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160751. png_bytepp offset_table_ptr;
  160752. png_bytep offset_table;
  160753. png_uint_16 offset_table_number;
  160754. png_uint_16 offset_table_count;
  160755. png_uint_16 offset_table_count_free;
  160756. #endif
  160757. #if defined(PNG_READ_DITHER_SUPPORTED)
  160758. png_bytep palette_lookup; /* lookup table for dithering */
  160759. png_bytep dither_index; /* index translation for palette files */
  160760. #endif
  160761. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160762. png_uint_16p hist; /* histogram */
  160763. #endif
  160764. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160765. png_byte heuristic_method; /* heuristic for row filter selection */
  160766. png_byte num_prev_filters; /* number of weights for previous rows */
  160767. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160768. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160769. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160770. png_uint_16p filter_costs; /* relative filter calculation cost */
  160771. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160772. #endif
  160773. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160774. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160775. #endif
  160776. #ifdef PNG_FREE_ME_SUPPORTED
  160777. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160778. #endif
  160779. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160780. png_voidp user_chunk_ptr;
  160781. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160782. #endif
  160783. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160784. int num_chunk_list;
  160785. png_bytep chunk_list;
  160786. #endif
  160787. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160788. png_byte rgb_to_gray_status;
  160789. png_uint_16 rgb_to_gray_red_coeff;
  160790. png_uint_16 rgb_to_gray_green_coeff;
  160791. png_uint_16 rgb_to_gray_blue_coeff;
  160792. #endif
  160793. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160794. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160795. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160796. #ifdef PNG_1_0_X
  160797. png_byte mng_features_permitted;
  160798. #else
  160799. png_uint_32 mng_features_permitted;
  160800. #endif /* PNG_1_0_X */
  160801. #endif
  160802. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160803. png_fixed_point int_gamma;
  160804. #endif
  160805. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160806. png_byte filter_type;
  160807. #endif
  160808. #if defined(PNG_1_0_X)
  160809. png_uint_32 row_buf_size;
  160810. #endif
  160811. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160812. # if !defined(PNG_1_0_X)
  160813. # if defined(PNG_MMX_CODE_SUPPORTED)
  160814. png_byte mmx_bitdepth_threshold;
  160815. png_uint_32 mmx_rowbytes_threshold;
  160816. # endif
  160817. png_uint_32 asm_flags;
  160818. # endif
  160819. #endif
  160820. #ifdef PNG_USER_MEM_SUPPORTED
  160821. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160822. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160823. png_free_ptr free_fn; /* function for freeing memory */
  160824. #endif
  160825. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160826. #if defined(PNG_READ_DITHER_SUPPORTED)
  160827. png_bytep dither_sort; /* working sort array */
  160828. png_bytep index_to_palette; /* where the original index currently is */
  160829. png_bytep palette_to_index; /* which original index points to this */
  160830. #endif
  160831. png_byte compression_type;
  160832. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160833. png_uint_32 user_width_max;
  160834. png_uint_32 user_height_max;
  160835. #endif
  160836. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160837. png_unknown_chunk unknown_chunk;
  160838. #endif
  160839. };
  160840. typedef png_structp version_1_2_21;
  160841. typedef png_struct FAR * FAR * png_structpp;
  160842. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160843. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160844. int num_bytes));
  160845. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160846. png_size_t num_to_check));
  160847. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160848. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160849. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160850. png_error_ptr error_fn, png_error_ptr warn_fn));
  160851. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160852. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160853. png_error_ptr error_fn, png_error_ptr warn_fn));
  160854. #ifdef PNG_WRITE_SUPPORTED
  160855. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160856. PNGARG((png_structp png_ptr));
  160857. #endif
  160858. #ifdef PNG_WRITE_SUPPORTED
  160859. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160860. PNGARG((png_structp png_ptr, png_uint_32 size));
  160861. #endif
  160862. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160863. #ifdef PNG_USER_MEM_SUPPORTED
  160864. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160865. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160866. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160867. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160868. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160869. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160870. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160871. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160872. #endif
  160873. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160874. png_bytep chunk_name, png_bytep data, png_size_t length));
  160875. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160876. png_bytep chunk_name, png_uint_32 length));
  160877. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160878. png_bytep data, png_size_t length));
  160879. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160880. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160881. PNGARG((png_structp png_ptr));
  160882. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160883. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160884. #undef png_info_init
  160885. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160886. png_sizeof(png_info));
  160887. #endif
  160888. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160889. png_size_t png_info_struct_size));
  160890. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160891. png_infop info_ptr));
  160892. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160893. png_infop info_ptr));
  160894. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160895. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160896. png_infop info_ptr));
  160897. #endif
  160898. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160899. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160900. PNGARG((png_structp png_ptr, png_timep ptime));
  160901. #endif
  160902. #if !defined(_WIN32_WCE)
  160903. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160904. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160905. struct tm FAR * ttime));
  160906. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160907. time_t ttime));
  160908. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160909. #endif /* _WIN32_WCE */
  160910. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160911. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160912. #if !defined(PNG_1_0_X)
  160913. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160914. png_ptr));
  160915. #endif
  160916. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160917. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160918. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160919. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160920. #endif
  160921. #endif
  160922. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160923. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160924. #endif
  160925. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160926. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160927. #endif
  160928. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160929. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160930. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160931. int error_action, double red, double green ));
  160932. #endif
  160933. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160934. int error_action, png_fixed_point red, png_fixed_point green ));
  160935. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160936. png_ptr));
  160937. #endif
  160938. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160939. png_colorp palette));
  160940. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160941. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160942. #endif
  160943. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160944. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  160945. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  160946. #endif
  160947. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  160948. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  160949. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  160950. #endif
  160951. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160952. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  160953. png_uint_32 filler, int flags));
  160954. #define PNG_FILLER_BEFORE 0
  160955. #define PNG_FILLER_AFTER 1
  160956. #if !defined(PNG_1_0_X)
  160957. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  160958. png_uint_32 filler, int flags));
  160959. #endif
  160960. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  160961. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  160962. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  160963. #endif
  160964. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  160965. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  160966. #endif
  160967. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  160968. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  160969. #endif
  160970. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160971. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  160972. png_color_8p true_bits));
  160973. #endif
  160974. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  160975. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160976. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  160977. #endif
  160978. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  160979. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  160980. #endif
  160981. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  160982. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160983. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  160984. png_color_16p background_color, int background_gamma_code,
  160985. int need_expand, double background_gamma));
  160986. #endif
  160987. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  160988. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  160989. #define PNG_BACKGROUND_GAMMA_FILE 2
  160990. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  160991. #endif
  160992. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  160993. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  160994. #endif
  160995. #if defined(PNG_READ_DITHER_SUPPORTED)
  160996. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  160997. png_colorp palette, int num_palette, int maximum_colors,
  160998. png_uint_16p histogram, int full_dither));
  160999. #endif
  161000. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161001. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161002. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  161003. double screen_gamma, double default_file_gamma));
  161004. #endif
  161005. #endif
  161006. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161007. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161008. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161009. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  161010. int empty_plte_permitted));
  161011. #endif
  161012. #endif
  161013. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161014. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  161015. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  161016. #endif
  161017. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  161018. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  161019. png_infop info_ptr));
  161020. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161021. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  161022. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  161023. #endif
  161024. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161025. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  161026. png_bytep row,
  161027. png_bytep display_row));
  161028. #endif
  161029. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161030. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  161031. png_bytepp image));
  161032. #endif
  161033. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161034. png_bytep row));
  161035. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161036. png_bytepp row, png_uint_32 num_rows));
  161037. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161038. png_bytepp image));
  161039. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161040. png_infop info_ptr));
  161041. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161042. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161043. png_infop info_ptr));
  161044. #endif
  161045. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161046. png_infopp info_ptr_ptr));
  161047. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161048. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161049. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161050. png_infop end_info_ptr));
  161051. extern PNG_EXPORT(void,png_destroy_write_struct)
  161052. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161053. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161054. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161055. int crit_action, int ancil_action));
  161056. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161057. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161058. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161059. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161060. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161061. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161062. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161063. int filters));
  161064. #define PNG_NO_FILTERS 0x00
  161065. #define PNG_FILTER_NONE 0x08
  161066. #define PNG_FILTER_SUB 0x10
  161067. #define PNG_FILTER_UP 0x20
  161068. #define PNG_FILTER_AVG 0x40
  161069. #define PNG_FILTER_PAETH 0x80
  161070. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161071. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161072. #define PNG_FILTER_VALUE_NONE 0
  161073. #define PNG_FILTER_VALUE_SUB 1
  161074. #define PNG_FILTER_VALUE_UP 2
  161075. #define PNG_FILTER_VALUE_AVG 3
  161076. #define PNG_FILTER_VALUE_PAETH 4
  161077. #define PNG_FILTER_VALUE_LAST 5
  161078. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161079. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161080. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161081. int heuristic_method, int num_weights, png_doublep filter_weights,
  161082. png_doublep filter_costs));
  161083. #endif
  161084. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161085. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161086. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161087. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161088. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161089. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161090. int level));
  161091. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161092. PNGARG((png_structp png_ptr, int mem_level));
  161093. extern PNG_EXPORT(void,png_set_compression_strategy)
  161094. PNGARG((png_structp png_ptr, int strategy));
  161095. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161096. PNGARG((png_structp png_ptr, int window_bits));
  161097. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161098. int method));
  161099. #if !defined(PNG_NO_STDIO)
  161100. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161101. #endif
  161102. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161103. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161104. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161105. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161106. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161107. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161108. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161109. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161110. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161111. png_read_status_ptr read_row_fn));
  161112. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161113. png_write_status_ptr write_row_fn));
  161114. #ifdef PNG_USER_MEM_SUPPORTED
  161115. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161116. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161117. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161118. #endif
  161119. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161120. defined(PNG_LEGACY_SUPPORTED)
  161121. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161122. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161123. #endif
  161124. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161125. defined(PNG_LEGACY_SUPPORTED)
  161126. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161127. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161128. #endif
  161129. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161130. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161131. defined(PNG_LEGACY_SUPPORTED)
  161132. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161133. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161134. int user_transform_channels));
  161135. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161136. PNGARG((png_structp png_ptr));
  161137. #endif
  161138. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161139. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161140. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161141. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161142. png_ptr));
  161143. #endif
  161144. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161145. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161146. png_voidp progressive_ptr,
  161147. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161148. png_progressive_end_ptr end_fn));
  161149. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161150. PNGARG((png_structp png_ptr));
  161151. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161152. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161153. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161154. png_bytep old_row, png_bytep new_row));
  161155. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161156. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161157. png_uint_32 size));
  161158. #if defined(PNG_1_0_X)
  161159. # define png_malloc_warn png_malloc
  161160. #else
  161161. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161162. png_uint_32 size));
  161163. #endif
  161164. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161165. #if defined(PNG_1_0_X)
  161166. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161167. uInt size));
  161168. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161169. #endif
  161170. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161171. png_infop info_ptr, png_uint_32 free_me, int num));
  161172. #ifdef PNG_FREE_ME_SUPPORTED
  161173. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161174. png_infop info_ptr, int freer, png_uint_32 mask));
  161175. #endif
  161176. #define PNG_DESTROY_WILL_FREE_DATA 1
  161177. #define PNG_SET_WILL_FREE_DATA 1
  161178. #define PNG_USER_WILL_FREE_DATA 2
  161179. #define PNG_FREE_HIST 0x0008
  161180. #define PNG_FREE_ICCP 0x0010
  161181. #define PNG_FREE_SPLT 0x0020
  161182. #define PNG_FREE_ROWS 0x0040
  161183. #define PNG_FREE_PCAL 0x0080
  161184. #define PNG_FREE_SCAL 0x0100
  161185. #define PNG_FREE_UNKN 0x0200
  161186. #define PNG_FREE_LIST 0x0400
  161187. #define PNG_FREE_PLTE 0x1000
  161188. #define PNG_FREE_TRNS 0x2000
  161189. #define PNG_FREE_TEXT 0x4000
  161190. #define PNG_FREE_ALL 0x7fff
  161191. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161192. #ifdef PNG_USER_MEM_SUPPORTED
  161193. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161194. png_uint_32 size));
  161195. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161196. png_voidp ptr));
  161197. #endif
  161198. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161199. png_voidp s1, png_voidp s2, png_uint_32 size));
  161200. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161201. png_voidp s1, int value, png_uint_32 size));
  161202. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161203. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161204. int check));
  161205. #endif /* USE_FAR_KEYWORD */
  161206. #ifndef PNG_NO_ERROR_TEXT
  161207. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161208. png_const_charp error_message));
  161209. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161210. png_const_charp error_message));
  161211. #else
  161212. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161213. #endif
  161214. #ifndef PNG_NO_WARNINGS
  161215. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161216. png_const_charp warning_message));
  161217. #ifdef PNG_READ_SUPPORTED
  161218. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161219. png_const_charp warning_message));
  161220. #endif /* PNG_READ_SUPPORTED */
  161221. #endif /* PNG_NO_WARNINGS */
  161222. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161223. png_infop info_ptr, png_uint_32 flag));
  161224. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161225. png_infop info_ptr));
  161226. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161227. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161228. png_infop info_ptr));
  161229. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161230. png_infop info_ptr, png_bytepp row_pointers));
  161231. #endif
  161232. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161233. png_infop info_ptr));
  161234. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161235. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161236. png_ptr, png_infop info_ptr));
  161237. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161238. png_ptr, png_infop info_ptr));
  161239. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161240. png_ptr, png_infop info_ptr));
  161241. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161242. png_ptr, png_infop info_ptr));
  161243. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161244. png_ptr, png_infop info_ptr));
  161245. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161246. png_ptr, png_infop info_ptr));
  161247. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161248. png_ptr, png_infop info_ptr));
  161249. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161250. png_ptr, png_infop info_ptr));
  161251. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161252. png_ptr, png_infop info_ptr));
  161253. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161254. png_ptr, png_infop info_ptr));
  161255. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161256. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161257. png_ptr, png_infop info_ptr));
  161258. #endif
  161259. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161260. png_ptr, png_infop info_ptr));
  161261. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161262. png_ptr, png_infop info_ptr));
  161263. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161264. png_ptr, png_infop info_ptr));
  161265. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161266. png_ptr, png_infop info_ptr));
  161267. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161268. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161269. png_infop info_ptr));
  161270. #if defined(PNG_bKGD_SUPPORTED)
  161271. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161272. png_infop info_ptr, png_color_16p *background));
  161273. #endif
  161274. #if defined(PNG_bKGD_SUPPORTED)
  161275. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161276. png_infop info_ptr, png_color_16p background));
  161277. #endif
  161278. #if defined(PNG_cHRM_SUPPORTED)
  161279. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161280. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161281. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161282. double *red_y, double *green_x, double *green_y, double *blue_x,
  161283. double *blue_y));
  161284. #endif
  161285. #ifdef PNG_FIXED_POINT_SUPPORTED
  161286. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161287. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161288. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161289. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161290. *int_blue_x, png_fixed_point *int_blue_y));
  161291. #endif
  161292. #endif
  161293. #if defined(PNG_cHRM_SUPPORTED)
  161294. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161295. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161296. png_infop info_ptr, double white_x, double white_y, double red_x,
  161297. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161298. #endif
  161299. #ifdef PNG_FIXED_POINT_SUPPORTED
  161300. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161301. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161302. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161303. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161304. png_fixed_point int_blue_y));
  161305. #endif
  161306. #endif
  161307. #if defined(PNG_gAMA_SUPPORTED)
  161308. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161309. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161310. png_infop info_ptr, double *file_gamma));
  161311. #endif
  161312. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161313. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161314. #endif
  161315. #if defined(PNG_gAMA_SUPPORTED)
  161316. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161317. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161318. png_infop info_ptr, double file_gamma));
  161319. #endif
  161320. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161321. png_infop info_ptr, png_fixed_point int_file_gamma));
  161322. #endif
  161323. #if defined(PNG_hIST_SUPPORTED)
  161324. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161325. png_infop info_ptr, png_uint_16p *hist));
  161326. #endif
  161327. #if defined(PNG_hIST_SUPPORTED)
  161328. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161329. png_infop info_ptr, png_uint_16p hist));
  161330. #endif
  161331. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161332. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161333. int *bit_depth, int *color_type, int *interlace_method,
  161334. int *compression_method, int *filter_method));
  161335. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161336. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161337. int color_type, int interlace_method, int compression_method,
  161338. int filter_method));
  161339. #if defined(PNG_oFFs_SUPPORTED)
  161340. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161341. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161342. int *unit_type));
  161343. #endif
  161344. #if defined(PNG_oFFs_SUPPORTED)
  161345. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161346. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161347. int unit_type));
  161348. #endif
  161349. #if defined(PNG_pCAL_SUPPORTED)
  161350. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161351. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161352. int *type, int *nparams, png_charp *units, png_charpp *params));
  161353. #endif
  161354. #if defined(PNG_pCAL_SUPPORTED)
  161355. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161356. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161357. int type, int nparams, png_charp units, png_charpp params));
  161358. #endif
  161359. #if defined(PNG_pHYs_SUPPORTED)
  161360. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161361. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161362. #endif
  161363. #if defined(PNG_pHYs_SUPPORTED)
  161364. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161365. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161366. #endif
  161367. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161368. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161369. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161370. png_infop info_ptr, png_colorp palette, int num_palette));
  161371. #if defined(PNG_sBIT_SUPPORTED)
  161372. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161373. png_infop info_ptr, png_color_8p *sig_bit));
  161374. #endif
  161375. #if defined(PNG_sBIT_SUPPORTED)
  161376. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161377. png_infop info_ptr, png_color_8p sig_bit));
  161378. #endif
  161379. #if defined(PNG_sRGB_SUPPORTED)
  161380. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161381. png_infop info_ptr, int *intent));
  161382. #endif
  161383. #if defined(PNG_sRGB_SUPPORTED)
  161384. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161385. png_infop info_ptr, int intent));
  161386. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161387. png_infop info_ptr, int intent));
  161388. #endif
  161389. #if defined(PNG_iCCP_SUPPORTED)
  161390. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161391. png_infop info_ptr, png_charpp name, int *compression_type,
  161392. png_charpp profile, png_uint_32 *proflen));
  161393. #endif
  161394. #if defined(PNG_iCCP_SUPPORTED)
  161395. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161396. png_infop info_ptr, png_charp name, int compression_type,
  161397. png_charp profile, png_uint_32 proflen));
  161398. #endif
  161399. #if defined(PNG_sPLT_SUPPORTED)
  161400. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161401. png_infop info_ptr, png_sPLT_tpp entries));
  161402. #endif
  161403. #if defined(PNG_sPLT_SUPPORTED)
  161404. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161405. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161406. #endif
  161407. #if defined(PNG_TEXT_SUPPORTED)
  161408. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161409. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161410. #endif
  161411. #if defined(PNG_TEXT_SUPPORTED)
  161412. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161413. png_infop info_ptr, png_textp text_ptr, int num_text));
  161414. #endif
  161415. #if defined(PNG_tIME_SUPPORTED)
  161416. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161417. png_infop info_ptr, png_timep *mod_time));
  161418. #endif
  161419. #if defined(PNG_tIME_SUPPORTED)
  161420. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161421. png_infop info_ptr, png_timep mod_time));
  161422. #endif
  161423. #if defined(PNG_tRNS_SUPPORTED)
  161424. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161425. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161426. png_color_16p *trans_values));
  161427. #endif
  161428. #if defined(PNG_tRNS_SUPPORTED)
  161429. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161430. png_infop info_ptr, png_bytep trans, int num_trans,
  161431. png_color_16p trans_values));
  161432. #endif
  161433. #if defined(PNG_tRNS_SUPPORTED)
  161434. #endif
  161435. #if defined(PNG_sCAL_SUPPORTED)
  161436. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161437. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161438. png_infop info_ptr, int *unit, double *width, double *height));
  161439. #else
  161440. #ifdef PNG_FIXED_POINT_SUPPORTED
  161441. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161442. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161443. #endif
  161444. #endif
  161445. #endif /* PNG_sCAL_SUPPORTED */
  161446. #if defined(PNG_sCAL_SUPPORTED)
  161447. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161448. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161449. png_infop info_ptr, int unit, double width, double height));
  161450. #else
  161451. #ifdef PNG_FIXED_POINT_SUPPORTED
  161452. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161453. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161454. #endif
  161455. #endif
  161456. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161457. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161458. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161459. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161460. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161461. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161462. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161463. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161464. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161465. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161466. #endif
  161467. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161468. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161469. chunk_name));
  161470. #endif
  161471. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161472. png_infop info_ptr, int mask));
  161473. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161474. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161475. png_infop info_ptr,
  161476. int transforms,
  161477. png_voidp params));
  161478. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161479. png_infop info_ptr,
  161480. int transforms,
  161481. png_voidp params));
  161482. #endif
  161483. #ifdef PNG_DEBUG
  161484. #if (PNG_DEBUG > 0)
  161485. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161486. #include <crtdbg.h>
  161487. #if (PNG_DEBUG > 1)
  161488. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161489. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161490. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161491. #endif
  161492. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161493. #ifndef PNG_DEBUG_FILE
  161494. #define PNG_DEBUG_FILE stderr
  161495. #endif /* PNG_DEBUG_FILE */
  161496. #if (PNG_DEBUG > 1)
  161497. #define png_debug(l,m) \
  161498. { \
  161499. int num_tabs=l; \
  161500. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161501. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161502. }
  161503. #define png_debug1(l,m,p1) \
  161504. { \
  161505. int num_tabs=l; \
  161506. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161507. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161508. }
  161509. #define png_debug2(l,m,p1,p2) \
  161510. { \
  161511. int num_tabs=l; \
  161512. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161513. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161514. }
  161515. #endif /* (PNG_DEBUG > 1) */
  161516. #endif /* _MSC_VER */
  161517. #endif /* (PNG_DEBUG > 0) */
  161518. #endif /* PNG_DEBUG */
  161519. #ifndef png_debug
  161520. #define png_debug(l, m)
  161521. #endif
  161522. #ifndef png_debug1
  161523. #define png_debug1(l, m, p1)
  161524. #endif
  161525. #ifndef png_debug2
  161526. #define png_debug2(l, m, p1, p2)
  161527. #endif
  161528. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161529. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161530. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161531. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161532. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161533. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161534. png_ptr, png_uint_32 mng_features_permitted));
  161535. #endif
  161536. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161537. #define PNG_HANDLE_CHUNK_NEVER 1
  161538. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161539. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161540. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161541. #if defined(PNG_MMX_CODE_SUPPORTED)
  161542. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161543. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161544. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161545. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161546. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161547. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161548. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161549. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161550. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161551. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161552. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161553. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161554. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161555. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161556. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161557. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161558. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161559. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161560. | PNG_MMX_READ_FLAGS \
  161561. | PNG_MMX_WRITE_FLAGS )
  161562. #define PNG_SELECT_READ 1
  161563. #define PNG_SELECT_WRITE 2
  161564. #endif /* PNG_MMX_CODE_SUPPORTED */
  161565. #if !defined(PNG_1_0_X)
  161566. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161567. PNGARG((int flag_select, int *compilerID));
  161568. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161569. PNGARG((int flag_select));
  161570. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161571. PNGARG((png_structp png_ptr));
  161572. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161573. PNGARG((png_structp png_ptr));
  161574. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161575. PNGARG((png_structp png_ptr));
  161576. extern PNG_EXPORT(void,png_set_asm_flags)
  161577. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161578. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161579. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161580. png_uint_32 mmx_rowbytes_threshold));
  161581. #endif /* PNG_1_0_X */
  161582. #if !defined(PNG_1_0_X)
  161583. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161584. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161585. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161586. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161587. png_ptr, png_uint_32 strip_mode));
  161588. #endif
  161589. #endif /* PNG_1_0_X */
  161590. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161591. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161592. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161593. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161594. png_ptr));
  161595. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161596. png_ptr));
  161597. #endif
  161598. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161599. # define png_composite(composite, fg, alpha, bg) \
  161600. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161601. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161602. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161603. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161604. # define png_composite_16(composite, fg, alpha, bg) \
  161605. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161606. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161607. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161608. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161609. #else /* standard method using integer division */
  161610. # define png_composite(composite, fg, alpha, bg) \
  161611. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161612. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161613. (png_uint_16)127) / 255)
  161614. # define png_composite_16(composite, fg, alpha, bg) \
  161615. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161616. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161617. (png_uint_32)32767) / (png_uint_32)65535L)
  161618. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161619. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161620. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161621. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161622. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161623. #else
  161624. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161625. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161626. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161627. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161628. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161629. PNGARG((png_structp png_ptr, png_bytep buf));
  161630. extern PNG_EXPORT(void,png_save_uint_32)
  161631. PNGARG((png_bytep buf, png_uint_32 i));
  161632. extern PNG_EXPORT(void,png_save_int_32)
  161633. PNGARG((png_bytep buf, png_int_32 i));
  161634. extern PNG_EXPORT(void,png_save_uint_16)
  161635. PNGARG((png_bytep buf, unsigned int i));
  161636. #define PNG_HAVE_IHDR 0x01
  161637. #define PNG_HAVE_PLTE 0x02
  161638. #define PNG_HAVE_IDAT 0x04
  161639. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161640. #define PNG_HAVE_IEND 0x10
  161641. #if defined(PNG_INTERNAL)
  161642. #define PNG_HAVE_gAMA 0x20
  161643. #define PNG_HAVE_cHRM 0x40
  161644. #define PNG_HAVE_sRGB 0x80
  161645. #define PNG_HAVE_CHUNK_HEADER 0x100
  161646. #define PNG_WROTE_tIME 0x200
  161647. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161648. #define PNG_BACKGROUND_IS_GRAY 0x800
  161649. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161650. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161651. #define PNG_BGR 0x0001
  161652. #define PNG_INTERLACE 0x0002
  161653. #define PNG_PACK 0x0004
  161654. #define PNG_SHIFT 0x0008
  161655. #define PNG_SWAP_BYTES 0x0010
  161656. #define PNG_INVERT_MONO 0x0020
  161657. #define PNG_DITHER 0x0040
  161658. #define PNG_BACKGROUND 0x0080
  161659. #define PNG_BACKGROUND_EXPAND 0x0100
  161660. #define PNG_16_TO_8 0x0400
  161661. #define PNG_RGBA 0x0800
  161662. #define PNG_EXPAND 0x1000
  161663. #define PNG_GAMMA 0x2000
  161664. #define PNG_GRAY_TO_RGB 0x4000
  161665. #define PNG_FILLER 0x8000L
  161666. #define PNG_PACKSWAP 0x10000L
  161667. #define PNG_SWAP_ALPHA 0x20000L
  161668. #define PNG_STRIP_ALPHA 0x40000L
  161669. #define PNG_INVERT_ALPHA 0x80000L
  161670. #define PNG_USER_TRANSFORM 0x100000L
  161671. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161672. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161673. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161674. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161675. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161676. #define PNG_STRUCT_PNG 0x0001
  161677. #define PNG_STRUCT_INFO 0x0002
  161678. #define PNG_WEIGHT_SHIFT 8
  161679. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161680. #define PNG_COST_SHIFT 3
  161681. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161682. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161683. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161684. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161685. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161686. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161687. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161688. #define PNG_FLAG_ROW_INIT 0x0040
  161689. #define PNG_FLAG_FILLER_AFTER 0x0080
  161690. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161691. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161692. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161693. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161694. #define PNG_FLAG_FREE_PLTE 0x1000
  161695. #define PNG_FLAG_FREE_TRNS 0x2000
  161696. #define PNG_FLAG_FREE_HIST 0x4000
  161697. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161698. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161699. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161700. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161701. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161702. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161703. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161704. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161705. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161706. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161707. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161708. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161709. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161710. PNG_FLAG_CRC_CRITICAL_MASK)
  161711. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161712. abs((int)((c1).green) - (int)((c2).green)) + \
  161713. abs((int)((c1).blue) - (int)((c2).blue)))
  161714. #define PNG_ROWBYTES(pixel_bits, width) \
  161715. ((pixel_bits) >= 8 ? \
  161716. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161717. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161718. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161719. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161720. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161721. #ifdef PNG_USE_GLOBAL_ARRAYS
  161722. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161723. #else
  161724. #endif
  161725. #endif /* PNG_NO_EXTERN */
  161726. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161727. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161728. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161729. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161730. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161731. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161732. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161733. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161734. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161735. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161736. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161737. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161738. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161739. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161740. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161741. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161742. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161743. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161744. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161745. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161746. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161747. #ifdef PNG_USE_GLOBAL_ARRAYS
  161748. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161749. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161750. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161751. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161752. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161753. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161754. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161755. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161756. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161757. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161758. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161759. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161760. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161761. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161762. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161763. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161764. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161765. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161766. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161767. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161768. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161769. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161770. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161771. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161772. #undef png_read_init
  161773. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161774. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161775. #endif
  161776. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161777. png_const_charp user_png_ver, png_size_t png_struct_size));
  161778. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161779. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161780. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161781. png_info_size));
  161782. #endif
  161783. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161784. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161785. #undef png_write_init
  161786. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161787. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161788. #endif
  161789. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161790. png_const_charp user_png_ver, png_size_t png_struct_size));
  161791. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  161792. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161793. png_info_size));
  161794. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161795. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161796. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161797. malloc_fn, png_voidp mem_ptr));
  161798. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161799. png_free_ptr free_fn, png_voidp mem_ptr));
  161800. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161801. png_infop info_ptr));
  161802. #ifndef PNG_1_0_X
  161803. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161804. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161805. #ifdef PNG_SIZE_T
  161806. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161807. #endif
  161808. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161809. png_bytep data, png_size_t length));
  161810. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161811. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161812. png_bytep buffer, png_size_t length));
  161813. #endif
  161814. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161815. png_bytep data, png_size_t length));
  161816. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161817. #if !defined(PNG_NO_STDIO)
  161818. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161819. #endif
  161820. #endif
  161821. #else /* PNG_1_0_X */
  161822. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161823. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161824. png_bytep buffer, png_size_t length));
  161825. #endif
  161826. #endif /* PNG_1_0_X */
  161827. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161828. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161829. png_size_t length));
  161830. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161831. png_size_t length));
  161832. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161833. png_size_t length));
  161834. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161835. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161836. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161837. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161838. png_size_t prefix_length, png_size_t *data_length));
  161839. #endif
  161840. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161841. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161842. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161843. png_size_t length));
  161844. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161845. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161846. #endif
  161847. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161848. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161849. png_uint_32 height,
  161850. int bit_depth, int color_type, int compression_method, int filter_method,
  161851. int interlace_method));
  161852. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161853. png_uint_32 num_pal));
  161854. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161855. png_size_t length));
  161856. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161857. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161858. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161859. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161860. #endif
  161861. #ifdef PNG_FIXED_POINT_SUPPORTED
  161862. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161863. file_gamma));
  161864. #endif
  161865. #endif
  161866. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161867. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161868. int color_type));
  161869. #endif
  161870. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161871. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161872. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161873. double white_x, double white_y,
  161874. double red_x, double red_y, double green_x, double green_y,
  161875. double blue_x, double blue_y));
  161876. #endif
  161877. #ifdef PNG_FIXED_POINT_SUPPORTED
  161878. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161879. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161880. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161881. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161882. png_fixed_point int_blue_y));
  161883. #endif
  161884. #endif
  161885. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161886. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161887. int intent));
  161888. #endif
  161889. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161890. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161891. png_charp name, int compression_type,
  161892. png_charp profile, int proflen));
  161893. #endif
  161894. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161895. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161896. png_sPLT_tp palette));
  161897. #endif
  161898. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161899. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161900. png_color_16p values, int number, int color_type));
  161901. #endif
  161902. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161903. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161904. png_color_16p values, int color_type));
  161905. #endif
  161906. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161907. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161908. int num_hist));
  161909. #endif
  161910. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161911. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161912. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161913. png_charp key, png_charpp new_key));
  161914. #endif
  161915. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161916. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161917. png_charp text, png_size_t text_len));
  161918. #endif
  161919. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161920. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161921. png_charp text, png_size_t text_len, int compression));
  161922. #endif
  161923. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161924. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161925. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161926. png_charp text));
  161927. #endif
  161928. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161929. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161930. png_infop info_ptr, png_textp text_ptr, int num_text));
  161931. #endif
  161932. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161933. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161934. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161935. #endif
  161936. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161937. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161938. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161939. png_charp units, png_charpp params));
  161940. #endif
  161941. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161942. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161943. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161944. int unit_type));
  161945. #endif
  161946. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161947. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  161948. png_timep mod_time));
  161949. #endif
  161950. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  161951. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  161952. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  161953. int unit, double width, double height));
  161954. #else
  161955. #ifdef PNG_FIXED_POINT_SUPPORTED
  161956. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  161957. int unit, png_charp width, png_charp height));
  161958. #endif
  161959. #endif
  161960. #endif
  161961. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  161962. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  161963. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161964. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  161965. #endif
  161966. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  161967. int mask));
  161968. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  161969. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  161970. #endif
  161971. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161972. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  161973. png_bytep row, int pass));
  161974. #endif
  161975. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  161976. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  161977. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  161978. png_row_infop row_info));
  161979. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  161980. png_bytep filtered_row));
  161981. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  161982. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  161983. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  161984. png_infop info_ptr));
  161985. #if defined(PNG_READ_FILLER_SUPPORTED)
  161986. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  161987. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  161988. #endif
  161989. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  161990. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  161991. png_bytep row));
  161992. #endif
  161993. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161994. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  161995. png_bytep row));
  161996. #endif
  161997. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  161998. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  161999. png_bytep row));
  162000. #endif
  162001. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  162002. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  162003. png_bytep row));
  162004. #endif
  162005. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  162006. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  162007. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  162008. png_bytep row, png_uint_32 flags));
  162009. #endif
  162010. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162011. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  162012. #endif
  162013. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162014. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  162015. #endif
  162016. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  162017. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  162018. row_info, png_bytep row));
  162019. #endif
  162020. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  162021. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  162022. png_bytep row));
  162023. #endif
  162024. #if defined(PNG_READ_PACK_SUPPORTED)
  162025. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  162026. #endif
  162027. #if defined(PNG_READ_SHIFT_SUPPORTED)
  162028. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  162029. png_color_8p sig_bits));
  162030. #endif
  162031. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  162032. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162033. #endif
  162034. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162035. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162036. #endif
  162037. #if defined(PNG_READ_DITHER_SUPPORTED)
  162038. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162039. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162040. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162041. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162042. png_colorp palette, int num_palette));
  162043. # endif
  162044. #endif
  162045. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162046. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162047. #endif
  162048. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162049. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162050. png_bytep row, png_uint_32 bit_depth));
  162051. #endif
  162052. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162053. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162054. png_color_8p bit_depth));
  162055. #endif
  162056. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162057. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162058. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162059. png_color_16p trans_values, png_color_16p background,
  162060. png_color_16p background_1,
  162061. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162062. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162063. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162064. #else
  162065. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162066. png_color_16p trans_values, png_color_16p background));
  162067. #endif
  162068. #endif
  162069. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162070. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162071. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162072. int gamma_shift));
  162073. #endif
  162074. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162075. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162076. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162077. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162078. png_bytep row, png_color_16p trans_value));
  162079. #endif
  162080. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162081. png_uint_32 length));
  162082. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162083. png_uint_32 length));
  162084. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162085. png_uint_32 length));
  162086. #if defined(PNG_READ_bKGD_SUPPORTED)
  162087. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162088. png_uint_32 length));
  162089. #endif
  162090. #if defined(PNG_READ_cHRM_SUPPORTED)
  162091. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162092. png_uint_32 length));
  162093. #endif
  162094. #if defined(PNG_READ_gAMA_SUPPORTED)
  162095. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162096. png_uint_32 length));
  162097. #endif
  162098. #if defined(PNG_READ_hIST_SUPPORTED)
  162099. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162100. png_uint_32 length));
  162101. #endif
  162102. #if defined(PNG_READ_iCCP_SUPPORTED)
  162103. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162104. png_uint_32 length));
  162105. #endif /* PNG_READ_iCCP_SUPPORTED */
  162106. #if defined(PNG_READ_iTXt_SUPPORTED)
  162107. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162108. png_uint_32 length));
  162109. #endif
  162110. #if defined(PNG_READ_oFFs_SUPPORTED)
  162111. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162112. png_uint_32 length));
  162113. #endif
  162114. #if defined(PNG_READ_pCAL_SUPPORTED)
  162115. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162116. png_uint_32 length));
  162117. #endif
  162118. #if defined(PNG_READ_pHYs_SUPPORTED)
  162119. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162120. png_uint_32 length));
  162121. #endif
  162122. #if defined(PNG_READ_sBIT_SUPPORTED)
  162123. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162124. png_uint_32 length));
  162125. #endif
  162126. #if defined(PNG_READ_sCAL_SUPPORTED)
  162127. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162128. png_uint_32 length));
  162129. #endif
  162130. #if defined(PNG_READ_sPLT_SUPPORTED)
  162131. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162132. png_uint_32 length));
  162133. #endif /* PNG_READ_sPLT_SUPPORTED */
  162134. #if defined(PNG_READ_sRGB_SUPPORTED)
  162135. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162136. png_uint_32 length));
  162137. #endif
  162138. #if defined(PNG_READ_tEXt_SUPPORTED)
  162139. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162140. png_uint_32 length));
  162141. #endif
  162142. #if defined(PNG_READ_tIME_SUPPORTED)
  162143. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162144. png_uint_32 length));
  162145. #endif
  162146. #if defined(PNG_READ_tRNS_SUPPORTED)
  162147. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162148. png_uint_32 length));
  162149. #endif
  162150. #if defined(PNG_READ_zTXt_SUPPORTED)
  162151. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162152. png_uint_32 length));
  162153. #endif
  162154. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162155. png_infop info_ptr, png_uint_32 length));
  162156. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162157. png_bytep chunk_name));
  162158. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162159. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162160. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162161. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162162. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162163. png_infop info_ptr));
  162164. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162165. png_infop info_ptr));
  162166. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162167. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162168. png_uint_32 length));
  162169. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162170. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162171. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162172. png_bytep buffer, png_size_t buffer_length));
  162173. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162174. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162175. png_bytep buffer, png_size_t buffer_length));
  162176. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162177. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162178. png_infop info_ptr, png_uint_32 length));
  162179. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162180. png_infop info_ptr));
  162181. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162182. png_infop info_ptr));
  162183. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162184. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162185. png_infop info_ptr));
  162186. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162187. png_infop info_ptr));
  162188. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162189. #if defined(PNG_READ_tEXt_SUPPORTED)
  162190. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162191. png_infop info_ptr, png_uint_32 length));
  162192. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162193. png_infop info_ptr));
  162194. #endif
  162195. #if defined(PNG_READ_zTXt_SUPPORTED)
  162196. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162197. png_infop info_ptr, png_uint_32 length));
  162198. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162199. png_infop info_ptr));
  162200. #endif
  162201. #if defined(PNG_READ_iTXt_SUPPORTED)
  162202. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162203. png_infop info_ptr, png_uint_32 length));
  162204. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162205. png_infop info_ptr));
  162206. #endif
  162207. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162208. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162209. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162210. png_bytep row));
  162211. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162212. png_bytep row));
  162213. #endif
  162214. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162215. #if defined(PNG_MMX_CODE_SUPPORTED)
  162216. /* PRIVATE */
  162217. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162218. #endif
  162219. #endif
  162220. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162221. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162222. png_infop info_ptr));
  162223. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162224. png_infop info_ptr));
  162225. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162226. png_infop info_ptr));
  162227. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162228. png_infop info_ptr));
  162229. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162230. png_infop info_ptr));
  162231. #if defined(PNG_pHYs_SUPPORTED)
  162232. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162233. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162234. #endif /* PNG_pHYs_SUPPORTED */
  162235. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162236. #endif /* PNG_INTERNAL */
  162237. #ifdef __cplusplus
  162238. }
  162239. #endif
  162240. #endif /* PNG_VERSION_INFO_ONLY */
  162241. #endif /* PNG_H */
  162242. /*** End of inlined file: png.h ***/
  162243. #define PNG_NO_EXTERN
  162244. /*** Start of inlined file: png.c ***/
  162245. #define PNG_INTERNAL
  162246. #define PNG_NO_EXTERN
  162247. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162248. #ifdef PNG_USE_GLOBAL_ARRAYS
  162249. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162250. #ifdef PNG_READ_SUPPORTED
  162251. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162252. #endif /* PNG_READ_SUPPORTED */
  162253. PNG_IHDR;
  162254. PNG_IDAT;
  162255. PNG_IEND;
  162256. PNG_PLTE;
  162257. PNG_bKGD;
  162258. PNG_cHRM;
  162259. PNG_gAMA;
  162260. PNG_hIST;
  162261. PNG_iCCP;
  162262. PNG_iTXt;
  162263. PNG_oFFs;
  162264. PNG_pCAL;
  162265. PNG_sCAL;
  162266. PNG_pHYs;
  162267. PNG_sBIT;
  162268. PNG_sPLT;
  162269. PNG_sRGB;
  162270. PNG_tEXt;
  162271. PNG_tIME;
  162272. PNG_tRNS;
  162273. PNG_zTXt;
  162274. #ifdef PNG_READ_SUPPORTED
  162275. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162276. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162277. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162278. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162279. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162280. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162281. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162282. #endif /* PNG_READ_SUPPORTED */
  162283. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162284. #ifdef PNG_READ_SUPPORTED
  162285. void PNGAPI
  162286. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162287. {
  162288. if(png_ptr == NULL) return;
  162289. png_debug(1, "in png_set_sig_bytes\n");
  162290. if (num_bytes > 8)
  162291. png_error(png_ptr, "Too many bytes for PNG signature.");
  162292. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162293. }
  162294. int PNGAPI
  162295. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162296. {
  162297. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162298. if (num_to_check > 8)
  162299. num_to_check = 8;
  162300. else if (num_to_check < 1)
  162301. return (-1);
  162302. if (start > 7)
  162303. return (-1);
  162304. if (start + num_to_check > 8)
  162305. num_to_check = 8 - start;
  162306. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162307. }
  162308. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162309. int PNGAPI
  162310. png_check_sig(png_bytep sig, int num)
  162311. {
  162312. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162313. }
  162314. #endif
  162315. #endif /* PNG_READ_SUPPORTED */
  162316. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162317. #ifdef PNG_1_0_X
  162318. voidpf PNGAPI
  162319. #else
  162320. voidpf /* private */
  162321. #endif
  162322. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162323. {
  162324. png_voidp ptr;
  162325. png_structp p=(png_structp)png_ptr;
  162326. png_uint_32 save_flags=p->flags;
  162327. png_uint_32 num_bytes;
  162328. if(png_ptr == NULL) return (NULL);
  162329. if (items > PNG_UINT_32_MAX/size)
  162330. {
  162331. png_warning (p, "Potential overflow in png_zalloc()");
  162332. return (NULL);
  162333. }
  162334. num_bytes = (png_uint_32)items * size;
  162335. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162336. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162337. p->flags=save_flags;
  162338. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162339. if (ptr == NULL)
  162340. return ((voidpf)ptr);
  162341. if (num_bytes > (png_uint_32)0x8000L)
  162342. {
  162343. png_memset(ptr, 0, (png_size_t)0x8000L);
  162344. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162345. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162346. }
  162347. else
  162348. {
  162349. png_memset(ptr, 0, (png_size_t)num_bytes);
  162350. }
  162351. #endif
  162352. return ((voidpf)ptr);
  162353. }
  162354. #ifdef PNG_1_0_X
  162355. void PNGAPI
  162356. #else
  162357. void /* private */
  162358. #endif
  162359. png_zfree(voidpf png_ptr, voidpf ptr)
  162360. {
  162361. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162362. }
  162363. void /* PRIVATE */
  162364. png_reset_crc(png_structp png_ptr)
  162365. {
  162366. png_ptr->crc = crc32(0, Z_NULL, 0);
  162367. }
  162368. void /* PRIVATE */
  162369. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162370. {
  162371. int need_crc = 1;
  162372. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162373. {
  162374. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162375. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162376. need_crc = 0;
  162377. }
  162378. else /* critical */
  162379. {
  162380. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162381. need_crc = 0;
  162382. }
  162383. if (need_crc)
  162384. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162385. }
  162386. png_infop PNGAPI
  162387. png_create_info_struct(png_structp png_ptr)
  162388. {
  162389. png_infop info_ptr;
  162390. png_debug(1, "in png_create_info_struct\n");
  162391. if(png_ptr == NULL) return (NULL);
  162392. #ifdef PNG_USER_MEM_SUPPORTED
  162393. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162394. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162395. #else
  162396. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162397. #endif
  162398. if (info_ptr != NULL)
  162399. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162400. return (info_ptr);
  162401. }
  162402. void PNGAPI
  162403. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162404. {
  162405. png_infop info_ptr = NULL;
  162406. if(png_ptr == NULL) return;
  162407. png_debug(1, "in png_destroy_info_struct\n");
  162408. if (info_ptr_ptr != NULL)
  162409. info_ptr = *info_ptr_ptr;
  162410. if (info_ptr != NULL)
  162411. {
  162412. png_info_destroy(png_ptr, info_ptr);
  162413. #ifdef PNG_USER_MEM_SUPPORTED
  162414. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162415. png_ptr->mem_ptr);
  162416. #else
  162417. png_destroy_struct((png_voidp)info_ptr);
  162418. #endif
  162419. *info_ptr_ptr = NULL;
  162420. }
  162421. }
  162422. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162423. #undef png_info_init
  162424. void PNGAPI
  162425. png_info_init(png_infop info_ptr)
  162426. {
  162427. png_info_init_3(&info_ptr, 0);
  162428. }
  162429. #endif
  162430. void PNGAPI
  162431. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162432. {
  162433. png_infop info_ptr = *ptr_ptr;
  162434. if(info_ptr == NULL) return;
  162435. png_debug(1, "in png_info_init_3\n");
  162436. if(png_sizeof(png_info) > png_info_struct_size)
  162437. {
  162438. png_destroy_struct(info_ptr);
  162439. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162440. *ptr_ptr = info_ptr;
  162441. }
  162442. png_memset(info_ptr, 0, png_sizeof (png_info));
  162443. }
  162444. #ifdef PNG_FREE_ME_SUPPORTED
  162445. void PNGAPI
  162446. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162447. int freer, png_uint_32 mask)
  162448. {
  162449. png_debug(1, "in png_data_freer\n");
  162450. if (png_ptr == NULL || info_ptr == NULL)
  162451. return;
  162452. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162453. info_ptr->free_me |= mask;
  162454. else if(freer == PNG_USER_WILL_FREE_DATA)
  162455. info_ptr->free_me &= ~mask;
  162456. else
  162457. png_warning(png_ptr,
  162458. "Unknown freer parameter in png_data_freer.");
  162459. }
  162460. #endif
  162461. void PNGAPI
  162462. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162463. int num)
  162464. {
  162465. png_debug(1, "in png_free_data\n");
  162466. if (png_ptr == NULL || info_ptr == NULL)
  162467. return;
  162468. #if defined(PNG_TEXT_SUPPORTED)
  162469. #ifdef PNG_FREE_ME_SUPPORTED
  162470. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162471. #else
  162472. if (mask & PNG_FREE_TEXT)
  162473. #endif
  162474. {
  162475. if (num != -1)
  162476. {
  162477. if (info_ptr->text && info_ptr->text[num].key)
  162478. {
  162479. png_free(png_ptr, info_ptr->text[num].key);
  162480. info_ptr->text[num].key = NULL;
  162481. }
  162482. }
  162483. else
  162484. {
  162485. int i;
  162486. for (i = 0; i < info_ptr->num_text; i++)
  162487. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162488. png_free(png_ptr, info_ptr->text);
  162489. info_ptr->text = NULL;
  162490. info_ptr->num_text=0;
  162491. }
  162492. }
  162493. #endif
  162494. #if defined(PNG_tRNS_SUPPORTED)
  162495. #ifdef PNG_FREE_ME_SUPPORTED
  162496. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162497. #else
  162498. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162499. #endif
  162500. {
  162501. png_free(png_ptr, info_ptr->trans);
  162502. info_ptr->valid &= ~PNG_INFO_tRNS;
  162503. #ifndef PNG_FREE_ME_SUPPORTED
  162504. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162505. #endif
  162506. info_ptr->trans = NULL;
  162507. }
  162508. #endif
  162509. #if defined(PNG_sCAL_SUPPORTED)
  162510. #ifdef PNG_FREE_ME_SUPPORTED
  162511. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162512. #else
  162513. if (mask & PNG_FREE_SCAL)
  162514. #endif
  162515. {
  162516. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162517. png_free(png_ptr, info_ptr->scal_s_width);
  162518. png_free(png_ptr, info_ptr->scal_s_height);
  162519. info_ptr->scal_s_width = NULL;
  162520. info_ptr->scal_s_height = NULL;
  162521. #endif
  162522. info_ptr->valid &= ~PNG_INFO_sCAL;
  162523. }
  162524. #endif
  162525. #if defined(PNG_pCAL_SUPPORTED)
  162526. #ifdef PNG_FREE_ME_SUPPORTED
  162527. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162528. #else
  162529. if (mask & PNG_FREE_PCAL)
  162530. #endif
  162531. {
  162532. png_free(png_ptr, info_ptr->pcal_purpose);
  162533. png_free(png_ptr, info_ptr->pcal_units);
  162534. info_ptr->pcal_purpose = NULL;
  162535. info_ptr->pcal_units = NULL;
  162536. if (info_ptr->pcal_params != NULL)
  162537. {
  162538. int i;
  162539. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162540. {
  162541. png_free(png_ptr, info_ptr->pcal_params[i]);
  162542. info_ptr->pcal_params[i]=NULL;
  162543. }
  162544. png_free(png_ptr, info_ptr->pcal_params);
  162545. info_ptr->pcal_params = NULL;
  162546. }
  162547. info_ptr->valid &= ~PNG_INFO_pCAL;
  162548. }
  162549. #endif
  162550. #if defined(PNG_iCCP_SUPPORTED)
  162551. #ifdef PNG_FREE_ME_SUPPORTED
  162552. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162553. #else
  162554. if (mask & PNG_FREE_ICCP)
  162555. #endif
  162556. {
  162557. png_free(png_ptr, info_ptr->iccp_name);
  162558. png_free(png_ptr, info_ptr->iccp_profile);
  162559. info_ptr->iccp_name = NULL;
  162560. info_ptr->iccp_profile = NULL;
  162561. info_ptr->valid &= ~PNG_INFO_iCCP;
  162562. }
  162563. #endif
  162564. #if defined(PNG_sPLT_SUPPORTED)
  162565. #ifdef PNG_FREE_ME_SUPPORTED
  162566. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162567. #else
  162568. if (mask & PNG_FREE_SPLT)
  162569. #endif
  162570. {
  162571. if (num != -1)
  162572. {
  162573. if(info_ptr->splt_palettes)
  162574. {
  162575. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162576. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162577. info_ptr->splt_palettes[num].name = NULL;
  162578. info_ptr->splt_palettes[num].entries = NULL;
  162579. }
  162580. }
  162581. else
  162582. {
  162583. if(info_ptr->splt_palettes_num)
  162584. {
  162585. int i;
  162586. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162587. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162588. png_free(png_ptr, info_ptr->splt_palettes);
  162589. info_ptr->splt_palettes = NULL;
  162590. info_ptr->splt_palettes_num = 0;
  162591. }
  162592. info_ptr->valid &= ~PNG_INFO_sPLT;
  162593. }
  162594. }
  162595. #endif
  162596. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162597. if(png_ptr->unknown_chunk.data)
  162598. {
  162599. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162600. png_ptr->unknown_chunk.data = NULL;
  162601. }
  162602. #ifdef PNG_FREE_ME_SUPPORTED
  162603. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162604. #else
  162605. if (mask & PNG_FREE_UNKN)
  162606. #endif
  162607. {
  162608. if (num != -1)
  162609. {
  162610. if(info_ptr->unknown_chunks)
  162611. {
  162612. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162613. info_ptr->unknown_chunks[num].data = NULL;
  162614. }
  162615. }
  162616. else
  162617. {
  162618. int i;
  162619. if(info_ptr->unknown_chunks_num)
  162620. {
  162621. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162622. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162623. png_free(png_ptr, info_ptr->unknown_chunks);
  162624. info_ptr->unknown_chunks = NULL;
  162625. info_ptr->unknown_chunks_num = 0;
  162626. }
  162627. }
  162628. }
  162629. #endif
  162630. #if defined(PNG_hIST_SUPPORTED)
  162631. #ifdef PNG_FREE_ME_SUPPORTED
  162632. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162633. #else
  162634. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162635. #endif
  162636. {
  162637. png_free(png_ptr, info_ptr->hist);
  162638. info_ptr->hist = NULL;
  162639. info_ptr->valid &= ~PNG_INFO_hIST;
  162640. #ifndef PNG_FREE_ME_SUPPORTED
  162641. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162642. #endif
  162643. }
  162644. #endif
  162645. #ifdef PNG_FREE_ME_SUPPORTED
  162646. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162647. #else
  162648. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162649. #endif
  162650. {
  162651. png_zfree(png_ptr, info_ptr->palette);
  162652. info_ptr->palette = NULL;
  162653. info_ptr->valid &= ~PNG_INFO_PLTE;
  162654. #ifndef PNG_FREE_ME_SUPPORTED
  162655. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162656. #endif
  162657. info_ptr->num_palette = 0;
  162658. }
  162659. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162660. #ifdef PNG_FREE_ME_SUPPORTED
  162661. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162662. #else
  162663. if (mask & PNG_FREE_ROWS)
  162664. #endif
  162665. {
  162666. if(info_ptr->row_pointers)
  162667. {
  162668. int row;
  162669. for (row = 0; row < (int)info_ptr->height; row++)
  162670. {
  162671. png_free(png_ptr, info_ptr->row_pointers[row]);
  162672. info_ptr->row_pointers[row]=NULL;
  162673. }
  162674. png_free(png_ptr, info_ptr->row_pointers);
  162675. info_ptr->row_pointers=NULL;
  162676. }
  162677. info_ptr->valid &= ~PNG_INFO_IDAT;
  162678. }
  162679. #endif
  162680. #ifdef PNG_FREE_ME_SUPPORTED
  162681. if(num == -1)
  162682. info_ptr->free_me &= ~mask;
  162683. else
  162684. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162685. #endif
  162686. }
  162687. void /* PRIVATE */
  162688. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162689. {
  162690. png_debug(1, "in png_info_destroy\n");
  162691. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162692. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162693. if (png_ptr->num_chunk_list)
  162694. {
  162695. png_free(png_ptr, png_ptr->chunk_list);
  162696. png_ptr->chunk_list=NULL;
  162697. png_ptr->num_chunk_list=0;
  162698. }
  162699. #endif
  162700. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162701. }
  162702. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162703. png_voidp PNGAPI
  162704. png_get_io_ptr(png_structp png_ptr)
  162705. {
  162706. if(png_ptr == NULL) return (NULL);
  162707. return (png_ptr->io_ptr);
  162708. }
  162709. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162710. #if !defined(PNG_NO_STDIO)
  162711. void PNGAPI
  162712. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162713. {
  162714. png_debug(1, "in png_init_io\n");
  162715. if(png_ptr == NULL) return;
  162716. png_ptr->io_ptr = (png_voidp)fp;
  162717. }
  162718. #endif
  162719. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162720. png_charp PNGAPI
  162721. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162722. {
  162723. static PNG_CONST char short_months[12][4] =
  162724. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162725. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162726. if(png_ptr == NULL) return (NULL);
  162727. if (png_ptr->time_buffer == NULL)
  162728. {
  162729. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162730. png_sizeof(char)));
  162731. }
  162732. #if defined(_WIN32_WCE)
  162733. {
  162734. wchar_t time_buf[29];
  162735. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162736. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162737. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162738. ptime->second % 61);
  162739. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162740. NULL, NULL);
  162741. }
  162742. #else
  162743. #ifdef USE_FAR_KEYWORD
  162744. {
  162745. char near_time_buf[29];
  162746. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162747. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162748. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162749. ptime->second % 61);
  162750. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162751. 29*png_sizeof(char));
  162752. }
  162753. #else
  162754. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162755. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162756. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162757. ptime->second % 61);
  162758. #endif
  162759. #endif /* _WIN32_WCE */
  162760. return ((png_charp)png_ptr->time_buffer);
  162761. }
  162762. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162763. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162764. png_charp PNGAPI
  162765. png_get_copyright(png_structp png_ptr)
  162766. {
  162767. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162768. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162769. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162770. Copyright (c) 1996-1997 Andreas Dilger\n\
  162771. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162772. }
  162773. png_charp PNGAPI
  162774. png_get_libpng_ver(png_structp png_ptr)
  162775. {
  162776. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162777. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162778. }
  162779. png_charp PNGAPI
  162780. png_get_header_ver(png_structp png_ptr)
  162781. {
  162782. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162783. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162784. }
  162785. png_charp PNGAPI
  162786. png_get_header_version(png_structp png_ptr)
  162787. {
  162788. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162789. return ((png_charp) PNG_HEADER_VERSION_STRING
  162790. #ifndef PNG_READ_SUPPORTED
  162791. " (NO READ SUPPORT)"
  162792. #endif
  162793. "\n");
  162794. }
  162795. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162796. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162797. int PNGAPI
  162798. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162799. {
  162800. int i;
  162801. png_bytep p;
  162802. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162803. return 0;
  162804. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162805. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162806. if (!png_memcmp(chunk_name, p, 4))
  162807. return ((int)*(p+4));
  162808. return 0;
  162809. }
  162810. #endif
  162811. int PNGAPI
  162812. png_reset_zstream(png_structp png_ptr)
  162813. {
  162814. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162815. return (inflateReset(&png_ptr->zstream));
  162816. }
  162817. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162818. png_uint_32 PNGAPI
  162819. png_access_version_number(void)
  162820. {
  162821. return((png_uint_32) PNG_LIBPNG_VER);
  162822. }
  162823. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162824. #if !defined(PNG_1_0_X)
  162825. int PNGAPI
  162826. png_mmx_support(void)
  162827. {
  162828. return -1;
  162829. }
  162830. #endif /* PNG_1_0_X */
  162831. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162832. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162833. #ifdef PNG_SIZE_T
  162834. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162835. png_size_t PNGAPI
  162836. png_convert_size(size_t size)
  162837. {
  162838. if (size > (png_size_t)-1)
  162839. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162840. return ((png_size_t)size);
  162841. }
  162842. #endif /* PNG_SIZE_T */
  162843. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162844. /*** End of inlined file: png.c ***/
  162845. /*** Start of inlined file: pngerror.c ***/
  162846. #define PNG_INTERNAL
  162847. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162848. static void /* PRIVATE */
  162849. png_default_error PNGARG((png_structp png_ptr,
  162850. png_const_charp error_message));
  162851. #ifndef PNG_NO_WARNINGS
  162852. static void /* PRIVATE */
  162853. png_default_warning PNGARG((png_structp png_ptr,
  162854. png_const_charp warning_message));
  162855. #endif /* PNG_NO_WARNINGS */
  162856. #ifndef PNG_NO_ERROR_TEXT
  162857. void PNGAPI
  162858. png_error(png_structp png_ptr, png_const_charp error_message)
  162859. {
  162860. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162861. char msg[16];
  162862. if (png_ptr != NULL)
  162863. {
  162864. if (png_ptr->flags&
  162865. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162866. {
  162867. if (*error_message == '#')
  162868. {
  162869. int offset;
  162870. for (offset=1; offset<15; offset++)
  162871. if (*(error_message+offset) == ' ')
  162872. break;
  162873. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162874. {
  162875. int i;
  162876. for (i=0; i<offset-1; i++)
  162877. msg[i]=error_message[i+1];
  162878. msg[i]='\0';
  162879. error_message=msg;
  162880. }
  162881. else
  162882. error_message+=offset;
  162883. }
  162884. else
  162885. {
  162886. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162887. {
  162888. msg[0]='0';
  162889. msg[1]='\0';
  162890. error_message=msg;
  162891. }
  162892. }
  162893. }
  162894. }
  162895. #endif
  162896. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162897. (*(png_ptr->error_fn))(png_ptr, error_message);
  162898. png_default_error(png_ptr, error_message);
  162899. }
  162900. #else
  162901. void PNGAPI
  162902. png_err(png_structp png_ptr)
  162903. {
  162904. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162905. (*(png_ptr->error_fn))(png_ptr, '\0');
  162906. png_default_error(png_ptr, '\0');
  162907. }
  162908. #endif /* PNG_NO_ERROR_TEXT */
  162909. #ifndef PNG_NO_WARNINGS
  162910. void PNGAPI
  162911. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162912. {
  162913. int offset = 0;
  162914. if (png_ptr != NULL)
  162915. {
  162916. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162917. if (png_ptr->flags&
  162918. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162919. #endif
  162920. {
  162921. if (*warning_message == '#')
  162922. {
  162923. for (offset=1; offset<15; offset++)
  162924. if (*(warning_message+offset) == ' ')
  162925. break;
  162926. }
  162927. }
  162928. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162929. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162930. }
  162931. else
  162932. png_default_warning(png_ptr, warning_message+offset);
  162933. }
  162934. #endif /* PNG_NO_WARNINGS */
  162935. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162936. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162937. static void /* PRIVATE */
  162938. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162939. error_message)
  162940. {
  162941. int iout = 0, iin = 0;
  162942. while (iin < 4)
  162943. {
  162944. int c = png_ptr->chunk_name[iin++];
  162945. if (isnonalpha(c))
  162946. {
  162947. buffer[iout++] = '[';
  162948. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  162949. buffer[iout++] = png_digit[c & 0x0f];
  162950. buffer[iout++] = ']';
  162951. }
  162952. else
  162953. {
  162954. buffer[iout++] = (png_byte)c;
  162955. }
  162956. }
  162957. if (error_message == NULL)
  162958. buffer[iout] = 0;
  162959. else
  162960. {
  162961. buffer[iout++] = ':';
  162962. buffer[iout++] = ' ';
  162963. png_strncpy(buffer+iout, error_message, 63);
  162964. buffer[iout+63] = 0;
  162965. }
  162966. }
  162967. #ifdef PNG_READ_SUPPORTED
  162968. void PNGAPI
  162969. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  162970. {
  162971. char msg[18+64];
  162972. if (png_ptr == NULL)
  162973. png_error(png_ptr, error_message);
  162974. else
  162975. {
  162976. png_format_buffer(png_ptr, msg, error_message);
  162977. png_error(png_ptr, msg);
  162978. }
  162979. }
  162980. #endif /* PNG_READ_SUPPORTED */
  162981. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  162982. #ifndef PNG_NO_WARNINGS
  162983. void PNGAPI
  162984. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  162985. {
  162986. char msg[18+64];
  162987. if (png_ptr == NULL)
  162988. png_warning(png_ptr, warning_message);
  162989. else
  162990. {
  162991. png_format_buffer(png_ptr, msg, warning_message);
  162992. png_warning(png_ptr, msg);
  162993. }
  162994. }
  162995. #endif /* PNG_NO_WARNINGS */
  162996. static void /* PRIVATE */
  162997. png_default_error(png_structp png_ptr, png_const_charp error_message)
  162998. {
  162999. #ifndef PNG_NO_CONSOLE_IO
  163000. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163001. if (*error_message == '#')
  163002. {
  163003. int offset;
  163004. char error_number[16];
  163005. for (offset=0; offset<15; offset++)
  163006. {
  163007. error_number[offset] = *(error_message+offset+1);
  163008. if (*(error_message+offset) == ' ')
  163009. break;
  163010. }
  163011. if((offset > 1) && (offset < 15))
  163012. {
  163013. error_number[offset-1]='\0';
  163014. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  163015. error_message+offset);
  163016. }
  163017. else
  163018. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  163019. }
  163020. else
  163021. #endif
  163022. fprintf(stderr, "libpng error: %s\n", error_message);
  163023. #endif
  163024. #ifdef PNG_SETJMP_SUPPORTED
  163025. if (png_ptr)
  163026. {
  163027. # ifdef USE_FAR_KEYWORD
  163028. {
  163029. jmp_buf jmpbuf;
  163030. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  163031. longjmp(jmpbuf, 1);
  163032. }
  163033. # else
  163034. longjmp(png_ptr->jmpbuf, 1);
  163035. # endif
  163036. }
  163037. #else
  163038. PNG_ABORT();
  163039. #endif
  163040. #ifdef PNG_NO_CONSOLE_IO
  163041. error_message = error_message; /* make compiler happy */
  163042. #endif
  163043. }
  163044. #ifndef PNG_NO_WARNINGS
  163045. static void /* PRIVATE */
  163046. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163047. {
  163048. #ifndef PNG_NO_CONSOLE_IO
  163049. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163050. if (*warning_message == '#')
  163051. {
  163052. int offset;
  163053. char warning_number[16];
  163054. for (offset=0; offset<15; offset++)
  163055. {
  163056. warning_number[offset]=*(warning_message+offset+1);
  163057. if (*(warning_message+offset) == ' ')
  163058. break;
  163059. }
  163060. if((offset > 1) && (offset < 15))
  163061. {
  163062. warning_number[offset-1]='\0';
  163063. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163064. warning_message+offset);
  163065. }
  163066. else
  163067. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163068. }
  163069. else
  163070. # endif
  163071. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163072. #else
  163073. warning_message = warning_message; /* make compiler happy */
  163074. #endif
  163075. png_ptr = png_ptr; /* make compiler happy */
  163076. }
  163077. #endif /* PNG_NO_WARNINGS */
  163078. void PNGAPI
  163079. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163080. png_error_ptr error_fn, png_error_ptr warning_fn)
  163081. {
  163082. if (png_ptr == NULL)
  163083. return;
  163084. png_ptr->error_ptr = error_ptr;
  163085. png_ptr->error_fn = error_fn;
  163086. png_ptr->warning_fn = warning_fn;
  163087. }
  163088. png_voidp PNGAPI
  163089. png_get_error_ptr(png_structp png_ptr)
  163090. {
  163091. if (png_ptr == NULL)
  163092. return NULL;
  163093. return ((png_voidp)png_ptr->error_ptr);
  163094. }
  163095. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163096. void PNGAPI
  163097. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163098. {
  163099. if(png_ptr != NULL)
  163100. {
  163101. png_ptr->flags &=
  163102. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163103. }
  163104. }
  163105. #endif
  163106. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163107. /*** End of inlined file: pngerror.c ***/
  163108. /*** Start of inlined file: pngget.c ***/
  163109. #define PNG_INTERNAL
  163110. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163111. png_uint_32 PNGAPI
  163112. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163113. {
  163114. if (png_ptr != NULL && info_ptr != NULL)
  163115. return(info_ptr->valid & flag);
  163116. else
  163117. return(0);
  163118. }
  163119. png_uint_32 PNGAPI
  163120. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163121. {
  163122. if (png_ptr != NULL && info_ptr != NULL)
  163123. return(info_ptr->rowbytes);
  163124. else
  163125. return(0);
  163126. }
  163127. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163128. png_bytepp PNGAPI
  163129. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163130. {
  163131. if (png_ptr != NULL && info_ptr != NULL)
  163132. return(info_ptr->row_pointers);
  163133. else
  163134. return(0);
  163135. }
  163136. #endif
  163137. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163138. png_uint_32 PNGAPI
  163139. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163140. {
  163141. if (png_ptr != NULL && info_ptr != NULL)
  163142. {
  163143. return info_ptr->width;
  163144. }
  163145. return (0);
  163146. }
  163147. png_uint_32 PNGAPI
  163148. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163149. {
  163150. if (png_ptr != NULL && info_ptr != NULL)
  163151. {
  163152. return info_ptr->height;
  163153. }
  163154. return (0);
  163155. }
  163156. png_byte PNGAPI
  163157. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163158. {
  163159. if (png_ptr != NULL && info_ptr != NULL)
  163160. {
  163161. return info_ptr->bit_depth;
  163162. }
  163163. return (0);
  163164. }
  163165. png_byte PNGAPI
  163166. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163167. {
  163168. if (png_ptr != NULL && info_ptr != NULL)
  163169. {
  163170. return info_ptr->color_type;
  163171. }
  163172. return (0);
  163173. }
  163174. png_byte PNGAPI
  163175. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163176. {
  163177. if (png_ptr != NULL && info_ptr != NULL)
  163178. {
  163179. return info_ptr->filter_type;
  163180. }
  163181. return (0);
  163182. }
  163183. png_byte PNGAPI
  163184. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163185. {
  163186. if (png_ptr != NULL && info_ptr != NULL)
  163187. {
  163188. return info_ptr->interlace_type;
  163189. }
  163190. return (0);
  163191. }
  163192. png_byte PNGAPI
  163193. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163194. {
  163195. if (png_ptr != NULL && info_ptr != NULL)
  163196. {
  163197. return info_ptr->compression_type;
  163198. }
  163199. return (0);
  163200. }
  163201. png_uint_32 PNGAPI
  163202. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163203. {
  163204. if (png_ptr != NULL && info_ptr != NULL)
  163205. #if defined(PNG_pHYs_SUPPORTED)
  163206. if (info_ptr->valid & PNG_INFO_pHYs)
  163207. {
  163208. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163209. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163210. return (0);
  163211. else return (info_ptr->x_pixels_per_unit);
  163212. }
  163213. #else
  163214. return (0);
  163215. #endif
  163216. return (0);
  163217. }
  163218. png_uint_32 PNGAPI
  163219. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163220. {
  163221. if (png_ptr != NULL && info_ptr != NULL)
  163222. #if defined(PNG_pHYs_SUPPORTED)
  163223. if (info_ptr->valid & PNG_INFO_pHYs)
  163224. {
  163225. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163226. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163227. return (0);
  163228. else return (info_ptr->y_pixels_per_unit);
  163229. }
  163230. #else
  163231. return (0);
  163232. #endif
  163233. return (0);
  163234. }
  163235. png_uint_32 PNGAPI
  163236. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163237. {
  163238. if (png_ptr != NULL && info_ptr != NULL)
  163239. #if defined(PNG_pHYs_SUPPORTED)
  163240. if (info_ptr->valid & PNG_INFO_pHYs)
  163241. {
  163242. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163243. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163244. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163245. return (0);
  163246. else return (info_ptr->x_pixels_per_unit);
  163247. }
  163248. #else
  163249. return (0);
  163250. #endif
  163251. return (0);
  163252. }
  163253. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163254. float PNGAPI
  163255. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163256. {
  163257. if (png_ptr != NULL && info_ptr != NULL)
  163258. #if defined(PNG_pHYs_SUPPORTED)
  163259. if (info_ptr->valid & PNG_INFO_pHYs)
  163260. {
  163261. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163262. if (info_ptr->x_pixels_per_unit == 0)
  163263. return ((float)0.0);
  163264. else
  163265. return ((float)((float)info_ptr->y_pixels_per_unit
  163266. /(float)info_ptr->x_pixels_per_unit));
  163267. }
  163268. #else
  163269. return (0.0);
  163270. #endif
  163271. return ((float)0.0);
  163272. }
  163273. #endif
  163274. png_int_32 PNGAPI
  163275. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163276. {
  163277. if (png_ptr != NULL && info_ptr != NULL)
  163278. #if defined(PNG_oFFs_SUPPORTED)
  163279. if (info_ptr->valid & PNG_INFO_oFFs)
  163280. {
  163281. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163282. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163283. return (0);
  163284. else return (info_ptr->x_offset);
  163285. }
  163286. #else
  163287. return (0);
  163288. #endif
  163289. return (0);
  163290. }
  163291. png_int_32 PNGAPI
  163292. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163293. {
  163294. if (png_ptr != NULL && info_ptr != NULL)
  163295. #if defined(PNG_oFFs_SUPPORTED)
  163296. if (info_ptr->valid & PNG_INFO_oFFs)
  163297. {
  163298. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163299. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163300. return (0);
  163301. else return (info_ptr->y_offset);
  163302. }
  163303. #else
  163304. return (0);
  163305. #endif
  163306. return (0);
  163307. }
  163308. png_int_32 PNGAPI
  163309. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163310. {
  163311. if (png_ptr != NULL && info_ptr != NULL)
  163312. #if defined(PNG_oFFs_SUPPORTED)
  163313. if (info_ptr->valid & PNG_INFO_oFFs)
  163314. {
  163315. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163316. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163317. return (0);
  163318. else return (info_ptr->x_offset);
  163319. }
  163320. #else
  163321. return (0);
  163322. #endif
  163323. return (0);
  163324. }
  163325. png_int_32 PNGAPI
  163326. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163327. {
  163328. if (png_ptr != NULL && info_ptr != NULL)
  163329. #if defined(PNG_oFFs_SUPPORTED)
  163330. if (info_ptr->valid & PNG_INFO_oFFs)
  163331. {
  163332. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163333. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163334. return (0);
  163335. else return (info_ptr->y_offset);
  163336. }
  163337. #else
  163338. return (0);
  163339. #endif
  163340. return (0);
  163341. }
  163342. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163343. png_uint_32 PNGAPI
  163344. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163345. {
  163346. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163347. *.0254 +.5));
  163348. }
  163349. png_uint_32 PNGAPI
  163350. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163351. {
  163352. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163353. *.0254 +.5));
  163354. }
  163355. png_uint_32 PNGAPI
  163356. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163357. {
  163358. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163359. *.0254 +.5));
  163360. }
  163361. float PNGAPI
  163362. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163363. {
  163364. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163365. *.00003937);
  163366. }
  163367. float PNGAPI
  163368. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163369. {
  163370. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163371. *.00003937);
  163372. }
  163373. #if defined(PNG_pHYs_SUPPORTED)
  163374. png_uint_32 PNGAPI
  163375. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163376. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163377. {
  163378. png_uint_32 retval = 0;
  163379. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163380. {
  163381. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163382. if (res_x != NULL)
  163383. {
  163384. *res_x = info_ptr->x_pixels_per_unit;
  163385. retval |= PNG_INFO_pHYs;
  163386. }
  163387. if (res_y != NULL)
  163388. {
  163389. *res_y = info_ptr->y_pixels_per_unit;
  163390. retval |= PNG_INFO_pHYs;
  163391. }
  163392. if (unit_type != NULL)
  163393. {
  163394. *unit_type = (int)info_ptr->phys_unit_type;
  163395. retval |= PNG_INFO_pHYs;
  163396. if(*unit_type == 1)
  163397. {
  163398. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163399. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163400. }
  163401. }
  163402. }
  163403. return (retval);
  163404. }
  163405. #endif /* PNG_pHYs_SUPPORTED */
  163406. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163407. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163408. png_byte PNGAPI
  163409. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163410. {
  163411. if (png_ptr != NULL && info_ptr != NULL)
  163412. return(info_ptr->channels);
  163413. else
  163414. return (0);
  163415. }
  163416. png_bytep PNGAPI
  163417. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163418. {
  163419. if (png_ptr != NULL && info_ptr != NULL)
  163420. return(info_ptr->signature);
  163421. else
  163422. return (NULL);
  163423. }
  163424. #if defined(PNG_bKGD_SUPPORTED)
  163425. png_uint_32 PNGAPI
  163426. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163427. png_color_16p *background)
  163428. {
  163429. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163430. && background != NULL)
  163431. {
  163432. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163433. *background = &(info_ptr->background);
  163434. return (PNG_INFO_bKGD);
  163435. }
  163436. return (0);
  163437. }
  163438. #endif
  163439. #if defined(PNG_cHRM_SUPPORTED)
  163440. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163441. png_uint_32 PNGAPI
  163442. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163443. double *white_x, double *white_y, double *red_x, double *red_y,
  163444. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163445. {
  163446. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163447. {
  163448. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163449. if (white_x != NULL)
  163450. *white_x = (double)info_ptr->x_white;
  163451. if (white_y != NULL)
  163452. *white_y = (double)info_ptr->y_white;
  163453. if (red_x != NULL)
  163454. *red_x = (double)info_ptr->x_red;
  163455. if (red_y != NULL)
  163456. *red_y = (double)info_ptr->y_red;
  163457. if (green_x != NULL)
  163458. *green_x = (double)info_ptr->x_green;
  163459. if (green_y != NULL)
  163460. *green_y = (double)info_ptr->y_green;
  163461. if (blue_x != NULL)
  163462. *blue_x = (double)info_ptr->x_blue;
  163463. if (blue_y != NULL)
  163464. *blue_y = (double)info_ptr->y_blue;
  163465. return (PNG_INFO_cHRM);
  163466. }
  163467. return (0);
  163468. }
  163469. #endif
  163470. #ifdef PNG_FIXED_POINT_SUPPORTED
  163471. png_uint_32 PNGAPI
  163472. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163473. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163474. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163475. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163476. {
  163477. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163478. {
  163479. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163480. if (white_x != NULL)
  163481. *white_x = info_ptr->int_x_white;
  163482. if (white_y != NULL)
  163483. *white_y = info_ptr->int_y_white;
  163484. if (red_x != NULL)
  163485. *red_x = info_ptr->int_x_red;
  163486. if (red_y != NULL)
  163487. *red_y = info_ptr->int_y_red;
  163488. if (green_x != NULL)
  163489. *green_x = info_ptr->int_x_green;
  163490. if (green_y != NULL)
  163491. *green_y = info_ptr->int_y_green;
  163492. if (blue_x != NULL)
  163493. *blue_x = info_ptr->int_x_blue;
  163494. if (blue_y != NULL)
  163495. *blue_y = info_ptr->int_y_blue;
  163496. return (PNG_INFO_cHRM);
  163497. }
  163498. return (0);
  163499. }
  163500. #endif
  163501. #endif
  163502. #if defined(PNG_gAMA_SUPPORTED)
  163503. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163504. png_uint_32 PNGAPI
  163505. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163506. {
  163507. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163508. && file_gamma != NULL)
  163509. {
  163510. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163511. *file_gamma = (double)info_ptr->gamma;
  163512. return (PNG_INFO_gAMA);
  163513. }
  163514. return (0);
  163515. }
  163516. #endif
  163517. #ifdef PNG_FIXED_POINT_SUPPORTED
  163518. png_uint_32 PNGAPI
  163519. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163520. png_fixed_point *int_file_gamma)
  163521. {
  163522. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163523. && int_file_gamma != NULL)
  163524. {
  163525. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163526. *int_file_gamma = info_ptr->int_gamma;
  163527. return (PNG_INFO_gAMA);
  163528. }
  163529. return (0);
  163530. }
  163531. #endif
  163532. #endif
  163533. #if defined(PNG_sRGB_SUPPORTED)
  163534. png_uint_32 PNGAPI
  163535. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163536. {
  163537. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163538. && file_srgb_intent != NULL)
  163539. {
  163540. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163541. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163542. return (PNG_INFO_sRGB);
  163543. }
  163544. return (0);
  163545. }
  163546. #endif
  163547. #if defined(PNG_iCCP_SUPPORTED)
  163548. png_uint_32 PNGAPI
  163549. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163550. png_charpp name, int *compression_type,
  163551. png_charpp profile, png_uint_32 *proflen)
  163552. {
  163553. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163554. && name != NULL && profile != NULL && proflen != NULL)
  163555. {
  163556. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163557. *name = info_ptr->iccp_name;
  163558. *profile = info_ptr->iccp_profile;
  163559. *proflen = (int)info_ptr->iccp_proflen;
  163560. *compression_type = (int)info_ptr->iccp_compression;
  163561. return (PNG_INFO_iCCP);
  163562. }
  163563. return (0);
  163564. }
  163565. #endif
  163566. #if defined(PNG_sPLT_SUPPORTED)
  163567. png_uint_32 PNGAPI
  163568. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163569. png_sPLT_tpp spalettes)
  163570. {
  163571. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163572. {
  163573. *spalettes = info_ptr->splt_palettes;
  163574. return ((png_uint_32)info_ptr->splt_palettes_num);
  163575. }
  163576. return (0);
  163577. }
  163578. #endif
  163579. #if defined(PNG_hIST_SUPPORTED)
  163580. png_uint_32 PNGAPI
  163581. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163582. {
  163583. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163584. && hist != NULL)
  163585. {
  163586. png_debug1(1, "in %s retrieval function\n", "hIST");
  163587. *hist = info_ptr->hist;
  163588. return (PNG_INFO_hIST);
  163589. }
  163590. return (0);
  163591. }
  163592. #endif
  163593. png_uint_32 PNGAPI
  163594. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163595. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163596. int *color_type, int *interlace_type, int *compression_type,
  163597. int *filter_type)
  163598. {
  163599. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163600. bit_depth != NULL && color_type != NULL)
  163601. {
  163602. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163603. *width = info_ptr->width;
  163604. *height = info_ptr->height;
  163605. *bit_depth = info_ptr->bit_depth;
  163606. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163607. png_error(png_ptr, "Invalid bit depth");
  163608. *color_type = info_ptr->color_type;
  163609. if (info_ptr->color_type > 6)
  163610. png_error(png_ptr, "Invalid color type");
  163611. if (compression_type != NULL)
  163612. *compression_type = info_ptr->compression_type;
  163613. if (filter_type != NULL)
  163614. *filter_type = info_ptr->filter_type;
  163615. if (interlace_type != NULL)
  163616. *interlace_type = info_ptr->interlace_type;
  163617. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163618. png_error(png_ptr, "Invalid image width");
  163619. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163620. png_error(png_ptr, "Invalid image height");
  163621. if (info_ptr->width > (PNG_UINT_32_MAX
  163622. >> 3) /* 8-byte RGBA pixels */
  163623. - 64 /* bigrowbuf hack */
  163624. - 1 /* filter byte */
  163625. - 7*8 /* rounding of width to multiple of 8 pixels */
  163626. - 8) /* extra max_pixel_depth pad */
  163627. {
  163628. png_warning(png_ptr,
  163629. "Width too large for libpng to process image data.");
  163630. }
  163631. return (1);
  163632. }
  163633. return (0);
  163634. }
  163635. #if defined(PNG_oFFs_SUPPORTED)
  163636. png_uint_32 PNGAPI
  163637. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163638. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163639. {
  163640. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163641. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163642. {
  163643. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163644. *offset_x = info_ptr->x_offset;
  163645. *offset_y = info_ptr->y_offset;
  163646. *unit_type = (int)info_ptr->offset_unit_type;
  163647. return (PNG_INFO_oFFs);
  163648. }
  163649. return (0);
  163650. }
  163651. #endif
  163652. #if defined(PNG_pCAL_SUPPORTED)
  163653. png_uint_32 PNGAPI
  163654. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163655. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163656. png_charp *units, png_charpp *params)
  163657. {
  163658. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163659. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163660. nparams != NULL && units != NULL && params != NULL)
  163661. {
  163662. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163663. *purpose = info_ptr->pcal_purpose;
  163664. *X0 = info_ptr->pcal_X0;
  163665. *X1 = info_ptr->pcal_X1;
  163666. *type = (int)info_ptr->pcal_type;
  163667. *nparams = (int)info_ptr->pcal_nparams;
  163668. *units = info_ptr->pcal_units;
  163669. *params = info_ptr->pcal_params;
  163670. return (PNG_INFO_pCAL);
  163671. }
  163672. return (0);
  163673. }
  163674. #endif
  163675. #if defined(PNG_sCAL_SUPPORTED)
  163676. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163677. png_uint_32 PNGAPI
  163678. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163679. int *unit, double *width, double *height)
  163680. {
  163681. if (png_ptr != NULL && info_ptr != NULL &&
  163682. (info_ptr->valid & PNG_INFO_sCAL))
  163683. {
  163684. *unit = info_ptr->scal_unit;
  163685. *width = info_ptr->scal_pixel_width;
  163686. *height = info_ptr->scal_pixel_height;
  163687. return (PNG_INFO_sCAL);
  163688. }
  163689. return(0);
  163690. }
  163691. #else
  163692. #ifdef PNG_FIXED_POINT_SUPPORTED
  163693. png_uint_32 PNGAPI
  163694. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163695. int *unit, png_charpp width, png_charpp height)
  163696. {
  163697. if (png_ptr != NULL && info_ptr != NULL &&
  163698. (info_ptr->valid & PNG_INFO_sCAL))
  163699. {
  163700. *unit = info_ptr->scal_unit;
  163701. *width = info_ptr->scal_s_width;
  163702. *height = info_ptr->scal_s_height;
  163703. return (PNG_INFO_sCAL);
  163704. }
  163705. return(0);
  163706. }
  163707. #endif
  163708. #endif
  163709. #endif
  163710. #if defined(PNG_pHYs_SUPPORTED)
  163711. png_uint_32 PNGAPI
  163712. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163713. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163714. {
  163715. png_uint_32 retval = 0;
  163716. if (png_ptr != NULL && info_ptr != NULL &&
  163717. (info_ptr->valid & PNG_INFO_pHYs))
  163718. {
  163719. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163720. if (res_x != NULL)
  163721. {
  163722. *res_x = info_ptr->x_pixels_per_unit;
  163723. retval |= PNG_INFO_pHYs;
  163724. }
  163725. if (res_y != NULL)
  163726. {
  163727. *res_y = info_ptr->y_pixels_per_unit;
  163728. retval |= PNG_INFO_pHYs;
  163729. }
  163730. if (unit_type != NULL)
  163731. {
  163732. *unit_type = (int)info_ptr->phys_unit_type;
  163733. retval |= PNG_INFO_pHYs;
  163734. }
  163735. }
  163736. return (retval);
  163737. }
  163738. #endif
  163739. png_uint_32 PNGAPI
  163740. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163741. int *num_palette)
  163742. {
  163743. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163744. && palette != NULL)
  163745. {
  163746. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163747. *palette = info_ptr->palette;
  163748. *num_palette = info_ptr->num_palette;
  163749. png_debug1(3, "num_palette = %d\n", *num_palette);
  163750. return (PNG_INFO_PLTE);
  163751. }
  163752. return (0);
  163753. }
  163754. #if defined(PNG_sBIT_SUPPORTED)
  163755. png_uint_32 PNGAPI
  163756. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163757. {
  163758. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163759. && sig_bit != NULL)
  163760. {
  163761. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163762. *sig_bit = &(info_ptr->sig_bit);
  163763. return (PNG_INFO_sBIT);
  163764. }
  163765. return (0);
  163766. }
  163767. #endif
  163768. #if defined(PNG_TEXT_SUPPORTED)
  163769. png_uint_32 PNGAPI
  163770. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163771. int *num_text)
  163772. {
  163773. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163774. {
  163775. png_debug1(1, "in %s retrieval function\n",
  163776. (png_ptr->chunk_name[0] == '\0' ? "text"
  163777. : (png_const_charp)png_ptr->chunk_name));
  163778. if (text_ptr != NULL)
  163779. *text_ptr = info_ptr->text;
  163780. if (num_text != NULL)
  163781. *num_text = info_ptr->num_text;
  163782. return ((png_uint_32)info_ptr->num_text);
  163783. }
  163784. if (num_text != NULL)
  163785. *num_text = 0;
  163786. return(0);
  163787. }
  163788. #endif
  163789. #if defined(PNG_tIME_SUPPORTED)
  163790. png_uint_32 PNGAPI
  163791. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163792. {
  163793. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163794. && mod_time != NULL)
  163795. {
  163796. png_debug1(1, "in %s retrieval function\n", "tIME");
  163797. *mod_time = &(info_ptr->mod_time);
  163798. return (PNG_INFO_tIME);
  163799. }
  163800. return (0);
  163801. }
  163802. #endif
  163803. #if defined(PNG_tRNS_SUPPORTED)
  163804. png_uint_32 PNGAPI
  163805. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163806. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163807. {
  163808. png_uint_32 retval = 0;
  163809. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163810. {
  163811. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163812. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163813. {
  163814. if (trans != NULL)
  163815. {
  163816. *trans = info_ptr->trans;
  163817. retval |= PNG_INFO_tRNS;
  163818. }
  163819. if (trans_values != NULL)
  163820. *trans_values = &(info_ptr->trans_values);
  163821. }
  163822. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163823. {
  163824. if (trans_values != NULL)
  163825. {
  163826. *trans_values = &(info_ptr->trans_values);
  163827. retval |= PNG_INFO_tRNS;
  163828. }
  163829. if(trans != NULL)
  163830. *trans = NULL;
  163831. }
  163832. if(num_trans != NULL)
  163833. {
  163834. *num_trans = info_ptr->num_trans;
  163835. retval |= PNG_INFO_tRNS;
  163836. }
  163837. }
  163838. return (retval);
  163839. }
  163840. #endif
  163841. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163842. png_uint_32 PNGAPI
  163843. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163844. png_unknown_chunkpp unknowns)
  163845. {
  163846. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163847. {
  163848. *unknowns = info_ptr->unknown_chunks;
  163849. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163850. }
  163851. return (0);
  163852. }
  163853. #endif
  163854. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163855. png_byte PNGAPI
  163856. png_get_rgb_to_gray_status (png_structp png_ptr)
  163857. {
  163858. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163859. }
  163860. #endif
  163861. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163862. png_voidp PNGAPI
  163863. png_get_user_chunk_ptr(png_structp png_ptr)
  163864. {
  163865. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163866. }
  163867. #endif
  163868. #ifdef PNG_WRITE_SUPPORTED
  163869. png_uint_32 PNGAPI
  163870. png_get_compression_buffer_size(png_structp png_ptr)
  163871. {
  163872. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163873. }
  163874. #endif
  163875. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163876. #ifndef PNG_1_0_X
  163877. png_uint_32 PNGAPI
  163878. png_get_asm_flags (png_structp png_ptr)
  163879. {
  163880. return (png_ptr? 0L: 0L);
  163881. }
  163882. png_uint_32 PNGAPI
  163883. png_get_asm_flagmask (int flag_select)
  163884. {
  163885. flag_select=flag_select;
  163886. return 0L;
  163887. }
  163888. png_uint_32 PNGAPI
  163889. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163890. {
  163891. flag_select=flag_select;
  163892. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163893. return 0L;
  163894. }
  163895. png_byte PNGAPI
  163896. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163897. {
  163898. return (png_ptr? 0: 0);
  163899. }
  163900. png_uint_32 PNGAPI
  163901. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163902. {
  163903. return (png_ptr? 0L: 0L);
  163904. }
  163905. #endif /* ?PNG_1_0_X */
  163906. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163907. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163908. png_uint_32 PNGAPI
  163909. png_get_user_width_max (png_structp png_ptr)
  163910. {
  163911. return (png_ptr? png_ptr->user_width_max : 0);
  163912. }
  163913. png_uint_32 PNGAPI
  163914. png_get_user_height_max (png_structp png_ptr)
  163915. {
  163916. return (png_ptr? png_ptr->user_height_max : 0);
  163917. }
  163918. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163919. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163920. /*** End of inlined file: pngget.c ***/
  163921. /*** Start of inlined file: pngmem.c ***/
  163922. #define PNG_INTERNAL
  163923. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163924. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163925. png_voidp /* PRIVATE */
  163926. png_create_struct(int type)
  163927. {
  163928. #ifdef PNG_USER_MEM_SUPPORTED
  163929. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163930. }
  163931. png_voidp /* PRIVATE */
  163932. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163933. {
  163934. #endif /* PNG_USER_MEM_SUPPORTED */
  163935. png_size_t size;
  163936. png_voidp struct_ptr;
  163937. if (type == PNG_STRUCT_INFO)
  163938. size = png_sizeof(png_info);
  163939. else if (type == PNG_STRUCT_PNG)
  163940. size = png_sizeof(png_struct);
  163941. else
  163942. return (png_get_copyright(NULL));
  163943. #ifdef PNG_USER_MEM_SUPPORTED
  163944. if(malloc_fn != NULL)
  163945. {
  163946. png_struct dummy_struct;
  163947. png_structp png_ptr = &dummy_struct;
  163948. png_ptr->mem_ptr=mem_ptr;
  163949. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  163950. }
  163951. else
  163952. #endif /* PNG_USER_MEM_SUPPORTED */
  163953. struct_ptr = (png_voidp)farmalloc(size);
  163954. if (struct_ptr != NULL)
  163955. png_memset(struct_ptr, 0, size);
  163956. return (struct_ptr);
  163957. }
  163958. void /* PRIVATE */
  163959. png_destroy_struct(png_voidp struct_ptr)
  163960. {
  163961. #ifdef PNG_USER_MEM_SUPPORTED
  163962. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163963. }
  163964. void /* PRIVATE */
  163965. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163966. png_voidp mem_ptr)
  163967. {
  163968. #endif
  163969. if (struct_ptr != NULL)
  163970. {
  163971. #ifdef PNG_USER_MEM_SUPPORTED
  163972. if(free_fn != NULL)
  163973. {
  163974. png_struct dummy_struct;
  163975. png_structp png_ptr = &dummy_struct;
  163976. png_ptr->mem_ptr=mem_ptr;
  163977. (*(free_fn))(png_ptr, struct_ptr);
  163978. return;
  163979. }
  163980. #endif /* PNG_USER_MEM_SUPPORTED */
  163981. farfree (struct_ptr);
  163982. }
  163983. }
  163984. png_voidp PNGAPI
  163985. png_malloc(png_structp png_ptr, png_uint_32 size)
  163986. {
  163987. png_voidp ret;
  163988. if (png_ptr == NULL || size == 0)
  163989. return (NULL);
  163990. #ifdef PNG_USER_MEM_SUPPORTED
  163991. if(png_ptr->malloc_fn != NULL)
  163992. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163993. else
  163994. ret = (png_malloc_default(png_ptr, size));
  163995. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163996. png_error(png_ptr, "Out of memory!");
  163997. return (ret);
  163998. }
  163999. png_voidp PNGAPI
  164000. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164001. {
  164002. png_voidp ret;
  164003. #endif /* PNG_USER_MEM_SUPPORTED */
  164004. if (png_ptr == NULL || size == 0)
  164005. return (NULL);
  164006. #ifdef PNG_MAX_MALLOC_64K
  164007. if (size > (png_uint_32)65536L)
  164008. {
  164009. png_warning(png_ptr, "Cannot Allocate > 64K");
  164010. ret = NULL;
  164011. }
  164012. else
  164013. #endif
  164014. if (size != (size_t)size)
  164015. ret = NULL;
  164016. else if (size == (png_uint_32)65536L)
  164017. {
  164018. if (png_ptr->offset_table == NULL)
  164019. {
  164020. ret = farmalloc(size);
  164021. if (ret == NULL || ((png_size_t)ret & 0xffff))
  164022. {
  164023. int num_blocks;
  164024. png_uint_32 total_size;
  164025. png_bytep table;
  164026. int i;
  164027. png_byte huge * hptr;
  164028. if (ret != NULL)
  164029. {
  164030. farfree(ret);
  164031. ret = NULL;
  164032. }
  164033. if(png_ptr->zlib_window_bits > 14)
  164034. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164035. else
  164036. num_blocks = 1;
  164037. if (png_ptr->zlib_mem_level >= 7)
  164038. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164039. else
  164040. num_blocks++;
  164041. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164042. table = farmalloc(total_size);
  164043. if (table == NULL)
  164044. {
  164045. #ifndef PNG_USER_MEM_SUPPORTED
  164046. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164047. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164048. else
  164049. png_warning(png_ptr, "Out Of Memory.");
  164050. #endif
  164051. return (NULL);
  164052. }
  164053. if ((png_size_t)table & 0xfff0)
  164054. {
  164055. #ifndef PNG_USER_MEM_SUPPORTED
  164056. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164057. png_error(png_ptr,
  164058. "Farmalloc didn't return normalized pointer");
  164059. else
  164060. png_warning(png_ptr,
  164061. "Farmalloc didn't return normalized pointer");
  164062. #endif
  164063. return (NULL);
  164064. }
  164065. png_ptr->offset_table = table;
  164066. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164067. png_sizeof (png_bytep));
  164068. if (png_ptr->offset_table_ptr == NULL)
  164069. {
  164070. #ifndef PNG_USER_MEM_SUPPORTED
  164071. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164072. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164073. else
  164074. png_warning(png_ptr, "Out Of memory.");
  164075. #endif
  164076. return (NULL);
  164077. }
  164078. hptr = (png_byte huge *)table;
  164079. if ((png_size_t)hptr & 0xf)
  164080. {
  164081. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164082. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164083. }
  164084. for (i = 0; i < num_blocks; i++)
  164085. {
  164086. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164087. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164088. }
  164089. png_ptr->offset_table_number = num_blocks;
  164090. png_ptr->offset_table_count = 0;
  164091. png_ptr->offset_table_count_free = 0;
  164092. }
  164093. }
  164094. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164095. {
  164096. #ifndef PNG_USER_MEM_SUPPORTED
  164097. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164098. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164099. else
  164100. png_warning(png_ptr, "Out of Memory.");
  164101. #endif
  164102. return (NULL);
  164103. }
  164104. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164105. }
  164106. else
  164107. ret = farmalloc(size);
  164108. #ifndef PNG_USER_MEM_SUPPORTED
  164109. if (ret == NULL)
  164110. {
  164111. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164112. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164113. else
  164114. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164115. }
  164116. #endif
  164117. return (ret);
  164118. }
  164119. void PNGAPI
  164120. png_free(png_structp png_ptr, png_voidp ptr)
  164121. {
  164122. if (png_ptr == NULL || ptr == NULL)
  164123. return;
  164124. #ifdef PNG_USER_MEM_SUPPORTED
  164125. if (png_ptr->free_fn != NULL)
  164126. {
  164127. (*(png_ptr->free_fn))(png_ptr, ptr);
  164128. return;
  164129. }
  164130. else png_free_default(png_ptr, ptr);
  164131. }
  164132. void PNGAPI
  164133. png_free_default(png_structp png_ptr, png_voidp ptr)
  164134. {
  164135. #endif /* PNG_USER_MEM_SUPPORTED */
  164136. if(png_ptr == NULL) return;
  164137. if (png_ptr->offset_table != NULL)
  164138. {
  164139. int i;
  164140. for (i = 0; i < png_ptr->offset_table_count; i++)
  164141. {
  164142. if (ptr == png_ptr->offset_table_ptr[i])
  164143. {
  164144. ptr = NULL;
  164145. png_ptr->offset_table_count_free++;
  164146. break;
  164147. }
  164148. }
  164149. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164150. {
  164151. farfree(png_ptr->offset_table);
  164152. farfree(png_ptr->offset_table_ptr);
  164153. png_ptr->offset_table = NULL;
  164154. png_ptr->offset_table_ptr = NULL;
  164155. }
  164156. }
  164157. if (ptr != NULL)
  164158. {
  164159. farfree(ptr);
  164160. }
  164161. }
  164162. #else /* Not the Borland DOS special memory handler */
  164163. png_voidp /* PRIVATE */
  164164. png_create_struct(int type)
  164165. {
  164166. #ifdef PNG_USER_MEM_SUPPORTED
  164167. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164168. }
  164169. png_voidp /* PRIVATE */
  164170. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164171. {
  164172. #endif /* PNG_USER_MEM_SUPPORTED */
  164173. png_size_t size;
  164174. png_voidp struct_ptr;
  164175. if (type == PNG_STRUCT_INFO)
  164176. size = png_sizeof(png_info);
  164177. else if (type == PNG_STRUCT_PNG)
  164178. size = png_sizeof(png_struct);
  164179. else
  164180. return (NULL);
  164181. #ifdef PNG_USER_MEM_SUPPORTED
  164182. if(malloc_fn != NULL)
  164183. {
  164184. png_struct dummy_struct;
  164185. png_structp png_ptr = &dummy_struct;
  164186. png_ptr->mem_ptr=mem_ptr;
  164187. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164188. if (struct_ptr != NULL)
  164189. png_memset(struct_ptr, 0, size);
  164190. return (struct_ptr);
  164191. }
  164192. #endif /* PNG_USER_MEM_SUPPORTED */
  164193. #if defined(__TURBOC__) && !defined(__FLAT__)
  164194. struct_ptr = (png_voidp)farmalloc(size);
  164195. #else
  164196. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164197. struct_ptr = (png_voidp)halloc(size,1);
  164198. # else
  164199. struct_ptr = (png_voidp)malloc(size);
  164200. # endif
  164201. #endif
  164202. if (struct_ptr != NULL)
  164203. png_memset(struct_ptr, 0, size);
  164204. return (struct_ptr);
  164205. }
  164206. void /* PRIVATE */
  164207. png_destroy_struct(png_voidp struct_ptr)
  164208. {
  164209. #ifdef PNG_USER_MEM_SUPPORTED
  164210. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164211. }
  164212. void /* PRIVATE */
  164213. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164214. png_voidp mem_ptr)
  164215. {
  164216. #endif /* PNG_USER_MEM_SUPPORTED */
  164217. if (struct_ptr != NULL)
  164218. {
  164219. #ifdef PNG_USER_MEM_SUPPORTED
  164220. if(free_fn != NULL)
  164221. {
  164222. png_struct dummy_struct;
  164223. png_structp png_ptr = &dummy_struct;
  164224. png_ptr->mem_ptr=mem_ptr;
  164225. (*(free_fn))(png_ptr, struct_ptr);
  164226. return;
  164227. }
  164228. #endif /* PNG_USER_MEM_SUPPORTED */
  164229. #if defined(__TURBOC__) && !defined(__FLAT__)
  164230. farfree(struct_ptr);
  164231. #else
  164232. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164233. hfree(struct_ptr);
  164234. # else
  164235. free(struct_ptr);
  164236. # endif
  164237. #endif
  164238. }
  164239. }
  164240. png_voidp PNGAPI
  164241. png_malloc(png_structp png_ptr, png_uint_32 size)
  164242. {
  164243. png_voidp ret;
  164244. #ifdef PNG_USER_MEM_SUPPORTED
  164245. if (png_ptr == NULL || size == 0)
  164246. return (NULL);
  164247. if(png_ptr->malloc_fn != NULL)
  164248. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164249. else
  164250. ret = (png_malloc_default(png_ptr, size));
  164251. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164252. png_error(png_ptr, "Out of Memory!");
  164253. return (ret);
  164254. }
  164255. png_voidp PNGAPI
  164256. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164257. {
  164258. png_voidp ret;
  164259. #endif /* PNG_USER_MEM_SUPPORTED */
  164260. if (png_ptr == NULL || size == 0)
  164261. return (NULL);
  164262. #ifdef PNG_MAX_MALLOC_64K
  164263. if (size > (png_uint_32)65536L)
  164264. {
  164265. #ifndef PNG_USER_MEM_SUPPORTED
  164266. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164267. png_error(png_ptr, "Cannot Allocate > 64K");
  164268. else
  164269. #endif
  164270. return NULL;
  164271. }
  164272. #endif
  164273. #if defined(__TURBOC__) && !defined(__FLAT__)
  164274. if (size != (unsigned long)size)
  164275. ret = NULL;
  164276. else
  164277. ret = farmalloc(size);
  164278. #else
  164279. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164280. if (size != (unsigned long)size)
  164281. ret = NULL;
  164282. else
  164283. ret = halloc(size, 1);
  164284. # else
  164285. if (size != (size_t)size)
  164286. ret = NULL;
  164287. else
  164288. ret = malloc((size_t)size);
  164289. # endif
  164290. #endif
  164291. #ifndef PNG_USER_MEM_SUPPORTED
  164292. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164293. png_error(png_ptr, "Out of Memory");
  164294. #endif
  164295. return (ret);
  164296. }
  164297. void PNGAPI
  164298. png_free(png_structp png_ptr, png_voidp ptr)
  164299. {
  164300. if (png_ptr == NULL || ptr == NULL)
  164301. return;
  164302. #ifdef PNG_USER_MEM_SUPPORTED
  164303. if (png_ptr->free_fn != NULL)
  164304. {
  164305. (*(png_ptr->free_fn))(png_ptr, ptr);
  164306. return;
  164307. }
  164308. else png_free_default(png_ptr, ptr);
  164309. }
  164310. void PNGAPI
  164311. png_free_default(png_structp png_ptr, png_voidp ptr)
  164312. {
  164313. if (png_ptr == NULL || ptr == NULL)
  164314. return;
  164315. #endif /* PNG_USER_MEM_SUPPORTED */
  164316. #if defined(__TURBOC__) && !defined(__FLAT__)
  164317. farfree(ptr);
  164318. #else
  164319. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164320. hfree(ptr);
  164321. # else
  164322. free(ptr);
  164323. # endif
  164324. #endif
  164325. }
  164326. #endif /* Not Borland DOS special memory handler */
  164327. #if defined(PNG_1_0_X)
  164328. # define png_malloc_warn png_malloc
  164329. #else
  164330. png_voidp PNGAPI
  164331. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164332. {
  164333. png_voidp ptr;
  164334. png_uint_32 save_flags;
  164335. if(png_ptr == NULL) return (NULL);
  164336. save_flags=png_ptr->flags;
  164337. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164338. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164339. png_ptr->flags=save_flags;
  164340. return(ptr);
  164341. }
  164342. #endif
  164343. png_voidp PNGAPI
  164344. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164345. png_uint_32 length)
  164346. {
  164347. png_size_t size;
  164348. size = (png_size_t)length;
  164349. if ((png_uint_32)size != length)
  164350. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164351. return(png_memcpy (s1, s2, size));
  164352. }
  164353. png_voidp PNGAPI
  164354. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164355. png_uint_32 length)
  164356. {
  164357. png_size_t size;
  164358. size = (png_size_t)length;
  164359. if ((png_uint_32)size != length)
  164360. png_error(png_ptr,"Overflow in png_memset_check.");
  164361. return (png_memset (s1, value, size));
  164362. }
  164363. #ifdef PNG_USER_MEM_SUPPORTED
  164364. void PNGAPI
  164365. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164366. malloc_fn, png_free_ptr free_fn)
  164367. {
  164368. if(png_ptr != NULL) {
  164369. png_ptr->mem_ptr = mem_ptr;
  164370. png_ptr->malloc_fn = malloc_fn;
  164371. png_ptr->free_fn = free_fn;
  164372. }
  164373. }
  164374. png_voidp PNGAPI
  164375. png_get_mem_ptr(png_structp png_ptr)
  164376. {
  164377. if(png_ptr == NULL) return (NULL);
  164378. return ((png_voidp)png_ptr->mem_ptr);
  164379. }
  164380. #endif /* PNG_USER_MEM_SUPPORTED */
  164381. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164382. /*** End of inlined file: pngmem.c ***/
  164383. /*** Start of inlined file: pngread.c ***/
  164384. #define PNG_INTERNAL
  164385. #if defined(PNG_READ_SUPPORTED)
  164386. png_structp PNGAPI
  164387. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164388. png_error_ptr error_fn, png_error_ptr warn_fn)
  164389. {
  164390. #ifdef PNG_USER_MEM_SUPPORTED
  164391. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164392. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164393. }
  164394. png_structp PNGAPI
  164395. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164396. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164397. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164398. {
  164399. #endif /* PNG_USER_MEM_SUPPORTED */
  164400. png_structp png_ptr;
  164401. #ifdef PNG_SETJMP_SUPPORTED
  164402. #ifdef USE_FAR_KEYWORD
  164403. jmp_buf jmpbuf;
  164404. #endif
  164405. #endif
  164406. int i;
  164407. png_debug(1, "in png_create_read_struct\n");
  164408. #ifdef PNG_USER_MEM_SUPPORTED
  164409. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164410. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164411. #else
  164412. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164413. #endif
  164414. if (png_ptr == NULL)
  164415. return (NULL);
  164416. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164417. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164418. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164419. #endif
  164420. #ifdef PNG_SETJMP_SUPPORTED
  164421. #ifdef USE_FAR_KEYWORD
  164422. if (setjmp(jmpbuf))
  164423. #else
  164424. if (setjmp(png_ptr->jmpbuf))
  164425. #endif
  164426. {
  164427. png_free(png_ptr, png_ptr->zbuf);
  164428. png_ptr->zbuf=NULL;
  164429. #ifdef PNG_USER_MEM_SUPPORTED
  164430. png_destroy_struct_2((png_voidp)png_ptr,
  164431. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164432. #else
  164433. png_destroy_struct((png_voidp)png_ptr);
  164434. #endif
  164435. return (NULL);
  164436. }
  164437. #ifdef USE_FAR_KEYWORD
  164438. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164439. #endif
  164440. #endif
  164441. #ifdef PNG_USER_MEM_SUPPORTED
  164442. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164443. #endif
  164444. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164445. i=0;
  164446. do
  164447. {
  164448. if(user_png_ver[i] != png_libpng_ver[i])
  164449. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164450. } while (png_libpng_ver[i++]);
  164451. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164452. {
  164453. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164454. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164455. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164456. {
  164457. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164458. char msg[80];
  164459. if (user_png_ver)
  164460. {
  164461. png_snprintf(msg, 80,
  164462. "Application was compiled with png.h from libpng-%.20s",
  164463. user_png_ver);
  164464. png_warning(png_ptr, msg);
  164465. }
  164466. png_snprintf(msg, 80,
  164467. "Application is running with png.c from libpng-%.20s",
  164468. png_libpng_ver);
  164469. png_warning(png_ptr, msg);
  164470. #endif
  164471. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164472. png_ptr->flags=0;
  164473. #endif
  164474. png_error(png_ptr,
  164475. "Incompatible libpng version in application and library");
  164476. }
  164477. }
  164478. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164479. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164480. (png_uint_32)png_ptr->zbuf_size);
  164481. png_ptr->zstream.zalloc = png_zalloc;
  164482. png_ptr->zstream.zfree = png_zfree;
  164483. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164484. switch (inflateInit(&png_ptr->zstream))
  164485. {
  164486. case Z_OK: /* Do nothing */ break;
  164487. case Z_MEM_ERROR:
  164488. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164489. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164490. default: png_error(png_ptr, "Unknown zlib error");
  164491. }
  164492. png_ptr->zstream.next_out = png_ptr->zbuf;
  164493. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164494. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164495. #ifdef PNG_SETJMP_SUPPORTED
  164496. #ifdef USE_FAR_KEYWORD
  164497. if (setjmp(jmpbuf))
  164498. PNG_ABORT();
  164499. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164500. #else
  164501. if (setjmp(png_ptr->jmpbuf))
  164502. PNG_ABORT();
  164503. #endif
  164504. #endif
  164505. return (png_ptr);
  164506. }
  164507. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164508. #undef png_read_init
  164509. void PNGAPI
  164510. png_read_init(png_structp png_ptr)
  164511. {
  164512. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164513. }
  164514. void PNGAPI
  164515. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164516. png_size_t png_struct_size, png_size_t png_info_size)
  164517. {
  164518. if(png_ptr == NULL) return;
  164519. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164520. if(png_sizeof(png_struct) > png_struct_size ||
  164521. png_sizeof(png_info) > png_info_size)
  164522. {
  164523. char msg[80];
  164524. png_ptr->warning_fn=NULL;
  164525. if (user_png_ver)
  164526. {
  164527. png_snprintf(msg, 80,
  164528. "Application was compiled with png.h from libpng-%.20s",
  164529. user_png_ver);
  164530. png_warning(png_ptr, msg);
  164531. }
  164532. png_snprintf(msg, 80,
  164533. "Application is running with png.c from libpng-%.20s",
  164534. png_libpng_ver);
  164535. png_warning(png_ptr, msg);
  164536. }
  164537. #endif
  164538. if(png_sizeof(png_struct) > png_struct_size)
  164539. {
  164540. png_ptr->error_fn=NULL;
  164541. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164542. png_ptr->flags=0;
  164543. #endif
  164544. png_error(png_ptr,
  164545. "The png struct allocated by the application for reading is too small.");
  164546. }
  164547. if(png_sizeof(png_info) > png_info_size)
  164548. {
  164549. png_ptr->error_fn=NULL;
  164550. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164551. png_ptr->flags=0;
  164552. #endif
  164553. png_error(png_ptr,
  164554. "The info struct allocated by application for reading is too small.");
  164555. }
  164556. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164557. }
  164558. #endif /* PNG_1_0_X || PNG_1_2_X */
  164559. void PNGAPI
  164560. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164561. png_size_t png_struct_size)
  164562. {
  164563. #ifdef PNG_SETJMP_SUPPORTED
  164564. jmp_buf tmp_jmp; /* to save current jump buffer */
  164565. #endif
  164566. int i=0;
  164567. png_structp png_ptr=*ptr_ptr;
  164568. if(png_ptr == NULL) return;
  164569. do
  164570. {
  164571. if(user_png_ver[i] != png_libpng_ver[i])
  164572. {
  164573. #ifdef PNG_LEGACY_SUPPORTED
  164574. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164575. #else
  164576. png_ptr->warning_fn=NULL;
  164577. png_warning(png_ptr,
  164578. "Application uses deprecated png_read_init() and should be recompiled.");
  164579. break;
  164580. #endif
  164581. }
  164582. } while (png_libpng_ver[i++]);
  164583. png_debug(1, "in png_read_init_3\n");
  164584. #ifdef PNG_SETJMP_SUPPORTED
  164585. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164586. #endif
  164587. if(png_sizeof(png_struct) > png_struct_size)
  164588. {
  164589. png_destroy_struct(png_ptr);
  164590. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164591. png_ptr = *ptr_ptr;
  164592. }
  164593. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164594. #ifdef PNG_SETJMP_SUPPORTED
  164595. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164596. #endif
  164597. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164598. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164599. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164600. #endif
  164601. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164602. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164603. (png_uint_32)png_ptr->zbuf_size);
  164604. png_ptr->zstream.zalloc = png_zalloc;
  164605. png_ptr->zstream.zfree = png_zfree;
  164606. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164607. switch (inflateInit(&png_ptr->zstream))
  164608. {
  164609. case Z_OK: /* Do nothing */ break;
  164610. case Z_MEM_ERROR:
  164611. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164612. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164613. default: png_error(png_ptr, "Unknown zlib error");
  164614. }
  164615. png_ptr->zstream.next_out = png_ptr->zbuf;
  164616. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164617. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164618. }
  164619. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164620. void PNGAPI
  164621. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164622. {
  164623. if(png_ptr == NULL) return;
  164624. png_debug(1, "in png_read_info\n");
  164625. if (png_ptr->sig_bytes < 8)
  164626. {
  164627. png_size_t num_checked = png_ptr->sig_bytes,
  164628. num_to_check = 8 - num_checked;
  164629. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164630. png_ptr->sig_bytes = 8;
  164631. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164632. {
  164633. if (num_checked < 4 &&
  164634. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164635. png_error(png_ptr, "Not a PNG file");
  164636. else
  164637. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164638. }
  164639. if (num_checked < 3)
  164640. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164641. }
  164642. for(;;)
  164643. {
  164644. #ifdef PNG_USE_LOCAL_ARRAYS
  164645. PNG_CONST PNG_IHDR;
  164646. PNG_CONST PNG_IDAT;
  164647. PNG_CONST PNG_IEND;
  164648. PNG_CONST PNG_PLTE;
  164649. #if defined(PNG_READ_bKGD_SUPPORTED)
  164650. PNG_CONST PNG_bKGD;
  164651. #endif
  164652. #if defined(PNG_READ_cHRM_SUPPORTED)
  164653. PNG_CONST PNG_cHRM;
  164654. #endif
  164655. #if defined(PNG_READ_gAMA_SUPPORTED)
  164656. PNG_CONST PNG_gAMA;
  164657. #endif
  164658. #if defined(PNG_READ_hIST_SUPPORTED)
  164659. PNG_CONST PNG_hIST;
  164660. #endif
  164661. #if defined(PNG_READ_iCCP_SUPPORTED)
  164662. PNG_CONST PNG_iCCP;
  164663. #endif
  164664. #if defined(PNG_READ_iTXt_SUPPORTED)
  164665. PNG_CONST PNG_iTXt;
  164666. #endif
  164667. #if defined(PNG_READ_oFFs_SUPPORTED)
  164668. PNG_CONST PNG_oFFs;
  164669. #endif
  164670. #if defined(PNG_READ_pCAL_SUPPORTED)
  164671. PNG_CONST PNG_pCAL;
  164672. #endif
  164673. #if defined(PNG_READ_pHYs_SUPPORTED)
  164674. PNG_CONST PNG_pHYs;
  164675. #endif
  164676. #if defined(PNG_READ_sBIT_SUPPORTED)
  164677. PNG_CONST PNG_sBIT;
  164678. #endif
  164679. #if defined(PNG_READ_sCAL_SUPPORTED)
  164680. PNG_CONST PNG_sCAL;
  164681. #endif
  164682. #if defined(PNG_READ_sPLT_SUPPORTED)
  164683. PNG_CONST PNG_sPLT;
  164684. #endif
  164685. #if defined(PNG_READ_sRGB_SUPPORTED)
  164686. PNG_CONST PNG_sRGB;
  164687. #endif
  164688. #if defined(PNG_READ_tEXt_SUPPORTED)
  164689. PNG_CONST PNG_tEXt;
  164690. #endif
  164691. #if defined(PNG_READ_tIME_SUPPORTED)
  164692. PNG_CONST PNG_tIME;
  164693. #endif
  164694. #if defined(PNG_READ_tRNS_SUPPORTED)
  164695. PNG_CONST PNG_tRNS;
  164696. #endif
  164697. #if defined(PNG_READ_zTXt_SUPPORTED)
  164698. PNG_CONST PNG_zTXt;
  164699. #endif
  164700. #endif /* PNG_USE_LOCAL_ARRAYS */
  164701. png_byte chunk_length[4];
  164702. png_uint_32 length;
  164703. png_read_data(png_ptr, chunk_length, 4);
  164704. length = png_get_uint_31(png_ptr,chunk_length);
  164705. png_reset_crc(png_ptr);
  164706. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164707. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164708. length);
  164709. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164710. if(png_ptr->mode & PNG_AFTER_IDAT)
  164711. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164712. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164713. png_handle_IHDR(png_ptr, info_ptr, length);
  164714. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164715. png_handle_IEND(png_ptr, info_ptr, length);
  164716. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164717. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164718. {
  164719. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164720. png_ptr->mode |= PNG_HAVE_IDAT;
  164721. png_handle_unknown(png_ptr, info_ptr, length);
  164722. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164723. png_ptr->mode |= PNG_HAVE_PLTE;
  164724. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164725. {
  164726. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164727. png_error(png_ptr, "Missing IHDR before IDAT");
  164728. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164729. !(png_ptr->mode & PNG_HAVE_PLTE))
  164730. png_error(png_ptr, "Missing PLTE before IDAT");
  164731. break;
  164732. }
  164733. }
  164734. #endif
  164735. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164736. png_handle_PLTE(png_ptr, info_ptr, length);
  164737. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164738. {
  164739. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164740. png_error(png_ptr, "Missing IHDR before IDAT");
  164741. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164742. !(png_ptr->mode & PNG_HAVE_PLTE))
  164743. png_error(png_ptr, "Missing PLTE before IDAT");
  164744. png_ptr->idat_size = length;
  164745. png_ptr->mode |= PNG_HAVE_IDAT;
  164746. break;
  164747. }
  164748. #if defined(PNG_READ_bKGD_SUPPORTED)
  164749. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164750. png_handle_bKGD(png_ptr, info_ptr, length);
  164751. #endif
  164752. #if defined(PNG_READ_cHRM_SUPPORTED)
  164753. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164754. png_handle_cHRM(png_ptr, info_ptr, length);
  164755. #endif
  164756. #if defined(PNG_READ_gAMA_SUPPORTED)
  164757. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164758. png_handle_gAMA(png_ptr, info_ptr, length);
  164759. #endif
  164760. #if defined(PNG_READ_hIST_SUPPORTED)
  164761. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164762. png_handle_hIST(png_ptr, info_ptr, length);
  164763. #endif
  164764. #if defined(PNG_READ_oFFs_SUPPORTED)
  164765. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164766. png_handle_oFFs(png_ptr, info_ptr, length);
  164767. #endif
  164768. #if defined(PNG_READ_pCAL_SUPPORTED)
  164769. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164770. png_handle_pCAL(png_ptr, info_ptr, length);
  164771. #endif
  164772. #if defined(PNG_READ_sCAL_SUPPORTED)
  164773. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164774. png_handle_sCAL(png_ptr, info_ptr, length);
  164775. #endif
  164776. #if defined(PNG_READ_pHYs_SUPPORTED)
  164777. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164778. png_handle_pHYs(png_ptr, info_ptr, length);
  164779. #endif
  164780. #if defined(PNG_READ_sBIT_SUPPORTED)
  164781. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164782. png_handle_sBIT(png_ptr, info_ptr, length);
  164783. #endif
  164784. #if defined(PNG_READ_sRGB_SUPPORTED)
  164785. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164786. png_handle_sRGB(png_ptr, info_ptr, length);
  164787. #endif
  164788. #if defined(PNG_READ_iCCP_SUPPORTED)
  164789. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164790. png_handle_iCCP(png_ptr, info_ptr, length);
  164791. #endif
  164792. #if defined(PNG_READ_sPLT_SUPPORTED)
  164793. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164794. png_handle_sPLT(png_ptr, info_ptr, length);
  164795. #endif
  164796. #if defined(PNG_READ_tEXt_SUPPORTED)
  164797. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164798. png_handle_tEXt(png_ptr, info_ptr, length);
  164799. #endif
  164800. #if defined(PNG_READ_tIME_SUPPORTED)
  164801. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164802. png_handle_tIME(png_ptr, info_ptr, length);
  164803. #endif
  164804. #if defined(PNG_READ_tRNS_SUPPORTED)
  164805. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164806. png_handle_tRNS(png_ptr, info_ptr, length);
  164807. #endif
  164808. #if defined(PNG_READ_zTXt_SUPPORTED)
  164809. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164810. png_handle_zTXt(png_ptr, info_ptr, length);
  164811. #endif
  164812. #if defined(PNG_READ_iTXt_SUPPORTED)
  164813. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164814. png_handle_iTXt(png_ptr, info_ptr, length);
  164815. #endif
  164816. else
  164817. png_handle_unknown(png_ptr, info_ptr, length);
  164818. }
  164819. }
  164820. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164821. void PNGAPI
  164822. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164823. {
  164824. png_debug(1, "in png_read_update_info\n");
  164825. if(png_ptr == NULL) return;
  164826. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164827. png_read_start_row(png_ptr);
  164828. else
  164829. png_warning(png_ptr,
  164830. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164831. png_read_transform_info(png_ptr, info_ptr);
  164832. }
  164833. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164834. void PNGAPI
  164835. png_start_read_image(png_structp png_ptr)
  164836. {
  164837. png_debug(1, "in png_start_read_image\n");
  164838. if(png_ptr == NULL) return;
  164839. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164840. png_read_start_row(png_ptr);
  164841. }
  164842. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164843. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164844. void PNGAPI
  164845. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164846. {
  164847. #ifdef PNG_USE_LOCAL_ARRAYS
  164848. PNG_CONST PNG_IDAT;
  164849. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164850. 0xff};
  164851. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164852. #endif
  164853. int ret;
  164854. if(png_ptr == NULL) return;
  164855. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164856. png_ptr->row_number, png_ptr->pass);
  164857. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164858. png_read_start_row(png_ptr);
  164859. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164860. {
  164861. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164862. if (png_ptr->transformations & PNG_INVERT_MONO)
  164863. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164864. #endif
  164865. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164866. if (png_ptr->transformations & PNG_FILLER)
  164867. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164868. #endif
  164869. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164870. if (png_ptr->transformations & PNG_PACKSWAP)
  164871. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164872. #endif
  164873. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164874. if (png_ptr->transformations & PNG_PACK)
  164875. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164876. #endif
  164877. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164878. if (png_ptr->transformations & PNG_SHIFT)
  164879. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164880. #endif
  164881. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164882. if (png_ptr->transformations & PNG_BGR)
  164883. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164884. #endif
  164885. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164886. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164887. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164888. #endif
  164889. }
  164890. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164891. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164892. {
  164893. switch (png_ptr->pass)
  164894. {
  164895. case 0:
  164896. if (png_ptr->row_number & 0x07)
  164897. {
  164898. if (dsp_row != NULL)
  164899. png_combine_row(png_ptr, dsp_row,
  164900. png_pass_dsp_mask[png_ptr->pass]);
  164901. png_read_finish_row(png_ptr);
  164902. return;
  164903. }
  164904. break;
  164905. case 1:
  164906. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164907. {
  164908. if (dsp_row != NULL)
  164909. png_combine_row(png_ptr, dsp_row,
  164910. png_pass_dsp_mask[png_ptr->pass]);
  164911. png_read_finish_row(png_ptr);
  164912. return;
  164913. }
  164914. break;
  164915. case 2:
  164916. if ((png_ptr->row_number & 0x07) != 4)
  164917. {
  164918. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164919. png_combine_row(png_ptr, dsp_row,
  164920. png_pass_dsp_mask[png_ptr->pass]);
  164921. png_read_finish_row(png_ptr);
  164922. return;
  164923. }
  164924. break;
  164925. case 3:
  164926. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164927. {
  164928. if (dsp_row != NULL)
  164929. png_combine_row(png_ptr, dsp_row,
  164930. png_pass_dsp_mask[png_ptr->pass]);
  164931. png_read_finish_row(png_ptr);
  164932. return;
  164933. }
  164934. break;
  164935. case 4:
  164936. if ((png_ptr->row_number & 3) != 2)
  164937. {
  164938. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164939. png_combine_row(png_ptr, dsp_row,
  164940. png_pass_dsp_mask[png_ptr->pass]);
  164941. png_read_finish_row(png_ptr);
  164942. return;
  164943. }
  164944. break;
  164945. case 5:
  164946. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  164947. {
  164948. if (dsp_row != NULL)
  164949. png_combine_row(png_ptr, dsp_row,
  164950. png_pass_dsp_mask[png_ptr->pass]);
  164951. png_read_finish_row(png_ptr);
  164952. return;
  164953. }
  164954. break;
  164955. case 6:
  164956. if (!(png_ptr->row_number & 1))
  164957. {
  164958. png_read_finish_row(png_ptr);
  164959. return;
  164960. }
  164961. break;
  164962. }
  164963. }
  164964. #endif
  164965. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  164966. png_error(png_ptr, "Invalid attempt to read row data");
  164967. png_ptr->zstream.next_out = png_ptr->row_buf;
  164968. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  164969. do
  164970. {
  164971. if (!(png_ptr->zstream.avail_in))
  164972. {
  164973. while (!png_ptr->idat_size)
  164974. {
  164975. png_byte chunk_length[4];
  164976. png_crc_finish(png_ptr, 0);
  164977. png_read_data(png_ptr, chunk_length, 4);
  164978. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  164979. png_reset_crc(png_ptr);
  164980. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164981. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164982. png_error(png_ptr, "Not enough image data");
  164983. }
  164984. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  164985. png_ptr->zstream.next_in = png_ptr->zbuf;
  164986. if (png_ptr->zbuf_size > png_ptr->idat_size)
  164987. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  164988. png_crc_read(png_ptr, png_ptr->zbuf,
  164989. (png_size_t)png_ptr->zstream.avail_in);
  164990. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  164991. }
  164992. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  164993. if (ret == Z_STREAM_END)
  164994. {
  164995. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  164996. png_ptr->idat_size)
  164997. png_error(png_ptr, "Extra compressed data");
  164998. png_ptr->mode |= PNG_AFTER_IDAT;
  164999. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165000. break;
  165001. }
  165002. if (ret != Z_OK)
  165003. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  165004. "Decompression error");
  165005. } while (png_ptr->zstream.avail_out);
  165006. png_ptr->row_info.color_type = png_ptr->color_type;
  165007. png_ptr->row_info.width = png_ptr->iwidth;
  165008. png_ptr->row_info.channels = png_ptr->channels;
  165009. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165010. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165011. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165012. png_ptr->row_info.width);
  165013. if(png_ptr->row_buf[0])
  165014. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165015. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165016. (int)(png_ptr->row_buf[0]));
  165017. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165018. png_ptr->rowbytes + 1);
  165019. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  165020. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  165021. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  165022. {
  165023. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  165024. }
  165025. #endif
  165026. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165027. png_do_read_transformations(png_ptr);
  165028. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165029. if (png_ptr->interlaced &&
  165030. (png_ptr->transformations & PNG_INTERLACE))
  165031. {
  165032. if (png_ptr->pass < 6)
  165033. png_do_read_interlace(png_ptr);
  165034. if (dsp_row != NULL)
  165035. png_combine_row(png_ptr, dsp_row,
  165036. png_pass_dsp_mask[png_ptr->pass]);
  165037. if (row != NULL)
  165038. png_combine_row(png_ptr, row,
  165039. png_pass_mask[png_ptr->pass]);
  165040. }
  165041. else
  165042. #endif
  165043. {
  165044. if (row != NULL)
  165045. png_combine_row(png_ptr, row, 0xff);
  165046. if (dsp_row != NULL)
  165047. png_combine_row(png_ptr, dsp_row, 0xff);
  165048. }
  165049. png_read_finish_row(png_ptr);
  165050. if (png_ptr->read_row_fn != NULL)
  165051. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165052. }
  165053. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165054. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165055. void PNGAPI
  165056. png_read_rows(png_structp png_ptr, png_bytepp row,
  165057. png_bytepp display_row, png_uint_32 num_rows)
  165058. {
  165059. png_uint_32 i;
  165060. png_bytepp rp;
  165061. png_bytepp dp;
  165062. png_debug(1, "in png_read_rows\n");
  165063. if(png_ptr == NULL) return;
  165064. rp = row;
  165065. dp = display_row;
  165066. if (rp != NULL && dp != NULL)
  165067. for (i = 0; i < num_rows; i++)
  165068. {
  165069. png_bytep rptr = *rp++;
  165070. png_bytep dptr = *dp++;
  165071. png_read_row(png_ptr, rptr, dptr);
  165072. }
  165073. else if(rp != NULL)
  165074. for (i = 0; i < num_rows; i++)
  165075. {
  165076. png_bytep rptr = *rp;
  165077. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165078. rp++;
  165079. }
  165080. else if(dp != NULL)
  165081. for (i = 0; i < num_rows; i++)
  165082. {
  165083. png_bytep dptr = *dp;
  165084. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165085. dp++;
  165086. }
  165087. }
  165088. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165089. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165090. void PNGAPI
  165091. png_read_image(png_structp png_ptr, png_bytepp image)
  165092. {
  165093. png_uint_32 i,image_height;
  165094. int pass, j;
  165095. png_bytepp rp;
  165096. png_debug(1, "in png_read_image\n");
  165097. if(png_ptr == NULL) return;
  165098. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165099. pass = png_set_interlace_handling(png_ptr);
  165100. #else
  165101. if (png_ptr->interlaced)
  165102. png_error(png_ptr,
  165103. "Cannot read interlaced image -- interlace handler disabled.");
  165104. pass = 1;
  165105. #endif
  165106. image_height=png_ptr->height;
  165107. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165108. for (j = 0; j < pass; j++)
  165109. {
  165110. rp = image;
  165111. for (i = 0; i < image_height; i++)
  165112. {
  165113. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165114. rp++;
  165115. }
  165116. }
  165117. }
  165118. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165119. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165120. void PNGAPI
  165121. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165122. {
  165123. png_byte chunk_length[4];
  165124. png_uint_32 length;
  165125. png_debug(1, "in png_read_end\n");
  165126. if(png_ptr == NULL) return;
  165127. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165128. do
  165129. {
  165130. #ifdef PNG_USE_LOCAL_ARRAYS
  165131. PNG_CONST PNG_IHDR;
  165132. PNG_CONST PNG_IDAT;
  165133. PNG_CONST PNG_IEND;
  165134. PNG_CONST PNG_PLTE;
  165135. #if defined(PNG_READ_bKGD_SUPPORTED)
  165136. PNG_CONST PNG_bKGD;
  165137. #endif
  165138. #if defined(PNG_READ_cHRM_SUPPORTED)
  165139. PNG_CONST PNG_cHRM;
  165140. #endif
  165141. #if defined(PNG_READ_gAMA_SUPPORTED)
  165142. PNG_CONST PNG_gAMA;
  165143. #endif
  165144. #if defined(PNG_READ_hIST_SUPPORTED)
  165145. PNG_CONST PNG_hIST;
  165146. #endif
  165147. #if defined(PNG_READ_iCCP_SUPPORTED)
  165148. PNG_CONST PNG_iCCP;
  165149. #endif
  165150. #if defined(PNG_READ_iTXt_SUPPORTED)
  165151. PNG_CONST PNG_iTXt;
  165152. #endif
  165153. #if defined(PNG_READ_oFFs_SUPPORTED)
  165154. PNG_CONST PNG_oFFs;
  165155. #endif
  165156. #if defined(PNG_READ_pCAL_SUPPORTED)
  165157. PNG_CONST PNG_pCAL;
  165158. #endif
  165159. #if defined(PNG_READ_pHYs_SUPPORTED)
  165160. PNG_CONST PNG_pHYs;
  165161. #endif
  165162. #if defined(PNG_READ_sBIT_SUPPORTED)
  165163. PNG_CONST PNG_sBIT;
  165164. #endif
  165165. #if defined(PNG_READ_sCAL_SUPPORTED)
  165166. PNG_CONST PNG_sCAL;
  165167. #endif
  165168. #if defined(PNG_READ_sPLT_SUPPORTED)
  165169. PNG_CONST PNG_sPLT;
  165170. #endif
  165171. #if defined(PNG_READ_sRGB_SUPPORTED)
  165172. PNG_CONST PNG_sRGB;
  165173. #endif
  165174. #if defined(PNG_READ_tEXt_SUPPORTED)
  165175. PNG_CONST PNG_tEXt;
  165176. #endif
  165177. #if defined(PNG_READ_tIME_SUPPORTED)
  165178. PNG_CONST PNG_tIME;
  165179. #endif
  165180. #if defined(PNG_READ_tRNS_SUPPORTED)
  165181. PNG_CONST PNG_tRNS;
  165182. #endif
  165183. #if defined(PNG_READ_zTXt_SUPPORTED)
  165184. PNG_CONST PNG_zTXt;
  165185. #endif
  165186. #endif /* PNG_USE_LOCAL_ARRAYS */
  165187. png_read_data(png_ptr, chunk_length, 4);
  165188. length = png_get_uint_31(png_ptr,chunk_length);
  165189. png_reset_crc(png_ptr);
  165190. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165191. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165192. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165193. png_handle_IHDR(png_ptr, info_ptr, length);
  165194. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165195. png_handle_IEND(png_ptr, info_ptr, length);
  165196. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165197. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165198. {
  165199. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165200. {
  165201. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165202. png_error(png_ptr, "Too many IDAT's found");
  165203. }
  165204. png_handle_unknown(png_ptr, info_ptr, length);
  165205. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165206. png_ptr->mode |= PNG_HAVE_PLTE;
  165207. }
  165208. #endif
  165209. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165210. {
  165211. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165212. png_error(png_ptr, "Too many IDAT's found");
  165213. png_crc_finish(png_ptr, length);
  165214. }
  165215. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165216. png_handle_PLTE(png_ptr, info_ptr, length);
  165217. #if defined(PNG_READ_bKGD_SUPPORTED)
  165218. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165219. png_handle_bKGD(png_ptr, info_ptr, length);
  165220. #endif
  165221. #if defined(PNG_READ_cHRM_SUPPORTED)
  165222. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165223. png_handle_cHRM(png_ptr, info_ptr, length);
  165224. #endif
  165225. #if defined(PNG_READ_gAMA_SUPPORTED)
  165226. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165227. png_handle_gAMA(png_ptr, info_ptr, length);
  165228. #endif
  165229. #if defined(PNG_READ_hIST_SUPPORTED)
  165230. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165231. png_handle_hIST(png_ptr, info_ptr, length);
  165232. #endif
  165233. #if defined(PNG_READ_oFFs_SUPPORTED)
  165234. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165235. png_handle_oFFs(png_ptr, info_ptr, length);
  165236. #endif
  165237. #if defined(PNG_READ_pCAL_SUPPORTED)
  165238. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165239. png_handle_pCAL(png_ptr, info_ptr, length);
  165240. #endif
  165241. #if defined(PNG_READ_sCAL_SUPPORTED)
  165242. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165243. png_handle_sCAL(png_ptr, info_ptr, length);
  165244. #endif
  165245. #if defined(PNG_READ_pHYs_SUPPORTED)
  165246. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165247. png_handle_pHYs(png_ptr, info_ptr, length);
  165248. #endif
  165249. #if defined(PNG_READ_sBIT_SUPPORTED)
  165250. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165251. png_handle_sBIT(png_ptr, info_ptr, length);
  165252. #endif
  165253. #if defined(PNG_READ_sRGB_SUPPORTED)
  165254. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165255. png_handle_sRGB(png_ptr, info_ptr, length);
  165256. #endif
  165257. #if defined(PNG_READ_iCCP_SUPPORTED)
  165258. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165259. png_handle_iCCP(png_ptr, info_ptr, length);
  165260. #endif
  165261. #if defined(PNG_READ_sPLT_SUPPORTED)
  165262. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165263. png_handle_sPLT(png_ptr, info_ptr, length);
  165264. #endif
  165265. #if defined(PNG_READ_tEXt_SUPPORTED)
  165266. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165267. png_handle_tEXt(png_ptr, info_ptr, length);
  165268. #endif
  165269. #if defined(PNG_READ_tIME_SUPPORTED)
  165270. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165271. png_handle_tIME(png_ptr, info_ptr, length);
  165272. #endif
  165273. #if defined(PNG_READ_tRNS_SUPPORTED)
  165274. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165275. png_handle_tRNS(png_ptr, info_ptr, length);
  165276. #endif
  165277. #if defined(PNG_READ_zTXt_SUPPORTED)
  165278. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165279. png_handle_zTXt(png_ptr, info_ptr, length);
  165280. #endif
  165281. #if defined(PNG_READ_iTXt_SUPPORTED)
  165282. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165283. png_handle_iTXt(png_ptr, info_ptr, length);
  165284. #endif
  165285. else
  165286. png_handle_unknown(png_ptr, info_ptr, length);
  165287. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165288. }
  165289. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165290. void PNGAPI
  165291. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165292. png_infopp end_info_ptr_ptr)
  165293. {
  165294. png_structp png_ptr = NULL;
  165295. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165296. #ifdef PNG_USER_MEM_SUPPORTED
  165297. png_free_ptr free_fn;
  165298. png_voidp mem_ptr;
  165299. #endif
  165300. png_debug(1, "in png_destroy_read_struct\n");
  165301. if (png_ptr_ptr != NULL)
  165302. png_ptr = *png_ptr_ptr;
  165303. if (info_ptr_ptr != NULL)
  165304. info_ptr = *info_ptr_ptr;
  165305. if (end_info_ptr_ptr != NULL)
  165306. end_info_ptr = *end_info_ptr_ptr;
  165307. #ifdef PNG_USER_MEM_SUPPORTED
  165308. free_fn = png_ptr->free_fn;
  165309. mem_ptr = png_ptr->mem_ptr;
  165310. #endif
  165311. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165312. if (info_ptr != NULL)
  165313. {
  165314. #if defined(PNG_TEXT_SUPPORTED)
  165315. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165316. #endif
  165317. #ifdef PNG_USER_MEM_SUPPORTED
  165318. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165319. (png_voidp)mem_ptr);
  165320. #else
  165321. png_destroy_struct((png_voidp)info_ptr);
  165322. #endif
  165323. *info_ptr_ptr = NULL;
  165324. }
  165325. if (end_info_ptr != NULL)
  165326. {
  165327. #if defined(PNG_READ_TEXT_SUPPORTED)
  165328. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165329. #endif
  165330. #ifdef PNG_USER_MEM_SUPPORTED
  165331. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165332. (png_voidp)mem_ptr);
  165333. #else
  165334. png_destroy_struct((png_voidp)end_info_ptr);
  165335. #endif
  165336. *end_info_ptr_ptr = NULL;
  165337. }
  165338. if (png_ptr != NULL)
  165339. {
  165340. #ifdef PNG_USER_MEM_SUPPORTED
  165341. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165342. (png_voidp)mem_ptr);
  165343. #else
  165344. png_destroy_struct((png_voidp)png_ptr);
  165345. #endif
  165346. *png_ptr_ptr = NULL;
  165347. }
  165348. }
  165349. void /* PRIVATE */
  165350. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165351. {
  165352. #ifdef PNG_SETJMP_SUPPORTED
  165353. jmp_buf tmp_jmp;
  165354. #endif
  165355. png_error_ptr error_fn;
  165356. png_error_ptr warning_fn;
  165357. png_voidp error_ptr;
  165358. #ifdef PNG_USER_MEM_SUPPORTED
  165359. png_free_ptr free_fn;
  165360. #endif
  165361. png_debug(1, "in png_read_destroy\n");
  165362. if (info_ptr != NULL)
  165363. png_info_destroy(png_ptr, info_ptr);
  165364. if (end_info_ptr != NULL)
  165365. png_info_destroy(png_ptr, end_info_ptr);
  165366. png_free(png_ptr, png_ptr->zbuf);
  165367. png_free(png_ptr, png_ptr->big_row_buf);
  165368. png_free(png_ptr, png_ptr->prev_row);
  165369. #if defined(PNG_READ_DITHER_SUPPORTED)
  165370. png_free(png_ptr, png_ptr->palette_lookup);
  165371. png_free(png_ptr, png_ptr->dither_index);
  165372. #endif
  165373. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165374. png_free(png_ptr, png_ptr->gamma_table);
  165375. #endif
  165376. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165377. png_free(png_ptr, png_ptr->gamma_from_1);
  165378. png_free(png_ptr, png_ptr->gamma_to_1);
  165379. #endif
  165380. #ifdef PNG_FREE_ME_SUPPORTED
  165381. if (png_ptr->free_me & PNG_FREE_PLTE)
  165382. png_zfree(png_ptr, png_ptr->palette);
  165383. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165384. #else
  165385. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165386. png_zfree(png_ptr, png_ptr->palette);
  165387. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165388. #endif
  165389. #if defined(PNG_tRNS_SUPPORTED) || \
  165390. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165391. #ifdef PNG_FREE_ME_SUPPORTED
  165392. if (png_ptr->free_me & PNG_FREE_TRNS)
  165393. png_free(png_ptr, png_ptr->trans);
  165394. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165395. #else
  165396. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165397. png_free(png_ptr, png_ptr->trans);
  165398. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165399. #endif
  165400. #endif
  165401. #if defined(PNG_READ_hIST_SUPPORTED)
  165402. #ifdef PNG_FREE_ME_SUPPORTED
  165403. if (png_ptr->free_me & PNG_FREE_HIST)
  165404. png_free(png_ptr, png_ptr->hist);
  165405. png_ptr->free_me &= ~PNG_FREE_HIST;
  165406. #else
  165407. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165408. png_free(png_ptr, png_ptr->hist);
  165409. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165410. #endif
  165411. #endif
  165412. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165413. if (png_ptr->gamma_16_table != NULL)
  165414. {
  165415. int i;
  165416. int istop = (1 << (8 - png_ptr->gamma_shift));
  165417. for (i = 0; i < istop; i++)
  165418. {
  165419. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165420. }
  165421. png_free(png_ptr, png_ptr->gamma_16_table);
  165422. }
  165423. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165424. if (png_ptr->gamma_16_from_1 != NULL)
  165425. {
  165426. int i;
  165427. int istop = (1 << (8 - png_ptr->gamma_shift));
  165428. for (i = 0; i < istop; i++)
  165429. {
  165430. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165431. }
  165432. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165433. }
  165434. if (png_ptr->gamma_16_to_1 != NULL)
  165435. {
  165436. int i;
  165437. int istop = (1 << (8 - png_ptr->gamma_shift));
  165438. for (i = 0; i < istop; i++)
  165439. {
  165440. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165441. }
  165442. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165443. }
  165444. #endif
  165445. #endif
  165446. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165447. png_free(png_ptr, png_ptr->time_buffer);
  165448. #endif
  165449. inflateEnd(&png_ptr->zstream);
  165450. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165451. png_free(png_ptr, png_ptr->save_buffer);
  165452. #endif
  165453. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165454. #ifdef PNG_TEXT_SUPPORTED
  165455. png_free(png_ptr, png_ptr->current_text);
  165456. #endif /* PNG_TEXT_SUPPORTED */
  165457. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165458. #ifdef PNG_SETJMP_SUPPORTED
  165459. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165460. #endif
  165461. error_fn = png_ptr->error_fn;
  165462. warning_fn = png_ptr->warning_fn;
  165463. error_ptr = png_ptr->error_ptr;
  165464. #ifdef PNG_USER_MEM_SUPPORTED
  165465. free_fn = png_ptr->free_fn;
  165466. #endif
  165467. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165468. png_ptr->error_fn = error_fn;
  165469. png_ptr->warning_fn = warning_fn;
  165470. png_ptr->error_ptr = error_ptr;
  165471. #ifdef PNG_USER_MEM_SUPPORTED
  165472. png_ptr->free_fn = free_fn;
  165473. #endif
  165474. #ifdef PNG_SETJMP_SUPPORTED
  165475. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165476. #endif
  165477. }
  165478. void PNGAPI
  165479. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165480. {
  165481. if(png_ptr == NULL) return;
  165482. png_ptr->read_row_fn = read_row_fn;
  165483. }
  165484. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165485. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165486. void PNGAPI
  165487. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165488. int transforms,
  165489. voidp params)
  165490. {
  165491. int row;
  165492. if(png_ptr == NULL) return;
  165493. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165494. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165495. png_set_invert_alpha(png_ptr);
  165496. #endif
  165497. png_read_info(png_ptr, info_ptr);
  165498. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165499. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165500. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165501. if (transforms & PNG_TRANSFORM_STRIP_16)
  165502. png_set_strip_16(png_ptr);
  165503. #endif
  165504. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165505. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165506. png_set_strip_alpha(png_ptr);
  165507. #endif
  165508. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165509. if (transforms & PNG_TRANSFORM_PACKING)
  165510. png_set_packing(png_ptr);
  165511. #endif
  165512. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165513. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165514. png_set_packswap(png_ptr);
  165515. #endif
  165516. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165517. if (transforms & PNG_TRANSFORM_EXPAND)
  165518. if ((png_ptr->bit_depth < 8) ||
  165519. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165520. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165521. png_set_expand(png_ptr);
  165522. #endif
  165523. #if defined(PNG_READ_INVERT_SUPPORTED)
  165524. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165525. png_set_invert_mono(png_ptr);
  165526. #endif
  165527. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165528. if ((transforms & PNG_TRANSFORM_SHIFT)
  165529. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165530. {
  165531. png_color_8p sig_bit;
  165532. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165533. png_set_shift(png_ptr, sig_bit);
  165534. }
  165535. #endif
  165536. #if defined(PNG_READ_BGR_SUPPORTED)
  165537. if (transforms & PNG_TRANSFORM_BGR)
  165538. png_set_bgr(png_ptr);
  165539. #endif
  165540. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165541. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165542. png_set_swap_alpha(png_ptr);
  165543. #endif
  165544. #if defined(PNG_READ_SWAP_SUPPORTED)
  165545. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165546. png_set_swap(png_ptr);
  165547. #endif
  165548. png_read_update_info(png_ptr, info_ptr);
  165549. #ifdef PNG_FREE_ME_SUPPORTED
  165550. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165551. #endif
  165552. if(info_ptr->row_pointers == NULL)
  165553. {
  165554. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165555. info_ptr->height * png_sizeof(png_bytep));
  165556. #ifdef PNG_FREE_ME_SUPPORTED
  165557. info_ptr->free_me |= PNG_FREE_ROWS;
  165558. #endif
  165559. for (row = 0; row < (int)info_ptr->height; row++)
  165560. {
  165561. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165562. png_get_rowbytes(png_ptr, info_ptr));
  165563. }
  165564. }
  165565. png_read_image(png_ptr, info_ptr->row_pointers);
  165566. info_ptr->valid |= PNG_INFO_IDAT;
  165567. png_read_end(png_ptr, info_ptr);
  165568. transforms = transforms; /* quiet compiler warnings */
  165569. params = params;
  165570. }
  165571. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165572. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165573. #endif /* PNG_READ_SUPPORTED */
  165574. /*** End of inlined file: pngread.c ***/
  165575. /*** Start of inlined file: pngpread.c ***/
  165576. #define PNG_INTERNAL
  165577. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165578. #define PNG_READ_SIG_MODE 0
  165579. #define PNG_READ_CHUNK_MODE 1
  165580. #define PNG_READ_IDAT_MODE 2
  165581. #define PNG_SKIP_MODE 3
  165582. #define PNG_READ_tEXt_MODE 4
  165583. #define PNG_READ_zTXt_MODE 5
  165584. #define PNG_READ_DONE_MODE 6
  165585. #define PNG_READ_iTXt_MODE 7
  165586. #define PNG_ERROR_MODE 8
  165587. void PNGAPI
  165588. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165589. png_bytep buffer, png_size_t buffer_size)
  165590. {
  165591. if(png_ptr == NULL) return;
  165592. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165593. while (png_ptr->buffer_size)
  165594. {
  165595. png_process_some_data(png_ptr, info_ptr);
  165596. }
  165597. }
  165598. void /* PRIVATE */
  165599. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165600. {
  165601. if(png_ptr == NULL) return;
  165602. switch (png_ptr->process_mode)
  165603. {
  165604. case PNG_READ_SIG_MODE:
  165605. {
  165606. png_push_read_sig(png_ptr, info_ptr);
  165607. break;
  165608. }
  165609. case PNG_READ_CHUNK_MODE:
  165610. {
  165611. png_push_read_chunk(png_ptr, info_ptr);
  165612. break;
  165613. }
  165614. case PNG_READ_IDAT_MODE:
  165615. {
  165616. png_push_read_IDAT(png_ptr);
  165617. break;
  165618. }
  165619. #if defined(PNG_READ_tEXt_SUPPORTED)
  165620. case PNG_READ_tEXt_MODE:
  165621. {
  165622. png_push_read_tEXt(png_ptr, info_ptr);
  165623. break;
  165624. }
  165625. #endif
  165626. #if defined(PNG_READ_zTXt_SUPPORTED)
  165627. case PNG_READ_zTXt_MODE:
  165628. {
  165629. png_push_read_zTXt(png_ptr, info_ptr);
  165630. break;
  165631. }
  165632. #endif
  165633. #if defined(PNG_READ_iTXt_SUPPORTED)
  165634. case PNG_READ_iTXt_MODE:
  165635. {
  165636. png_push_read_iTXt(png_ptr, info_ptr);
  165637. break;
  165638. }
  165639. #endif
  165640. case PNG_SKIP_MODE:
  165641. {
  165642. png_push_crc_finish(png_ptr);
  165643. break;
  165644. }
  165645. default:
  165646. {
  165647. png_ptr->buffer_size = 0;
  165648. break;
  165649. }
  165650. }
  165651. }
  165652. void /* PRIVATE */
  165653. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165654. {
  165655. png_size_t num_checked = png_ptr->sig_bytes,
  165656. num_to_check = 8 - num_checked;
  165657. if (png_ptr->buffer_size < num_to_check)
  165658. {
  165659. num_to_check = png_ptr->buffer_size;
  165660. }
  165661. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165662. num_to_check);
  165663. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165664. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165665. {
  165666. if (num_checked < 4 &&
  165667. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165668. png_error(png_ptr, "Not a PNG file");
  165669. else
  165670. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165671. }
  165672. else
  165673. {
  165674. if (png_ptr->sig_bytes >= 8)
  165675. {
  165676. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165677. }
  165678. }
  165679. }
  165680. void /* PRIVATE */
  165681. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165682. {
  165683. #ifdef PNG_USE_LOCAL_ARRAYS
  165684. PNG_CONST PNG_IHDR;
  165685. PNG_CONST PNG_IDAT;
  165686. PNG_CONST PNG_IEND;
  165687. PNG_CONST PNG_PLTE;
  165688. #if defined(PNG_READ_bKGD_SUPPORTED)
  165689. PNG_CONST PNG_bKGD;
  165690. #endif
  165691. #if defined(PNG_READ_cHRM_SUPPORTED)
  165692. PNG_CONST PNG_cHRM;
  165693. #endif
  165694. #if defined(PNG_READ_gAMA_SUPPORTED)
  165695. PNG_CONST PNG_gAMA;
  165696. #endif
  165697. #if defined(PNG_READ_hIST_SUPPORTED)
  165698. PNG_CONST PNG_hIST;
  165699. #endif
  165700. #if defined(PNG_READ_iCCP_SUPPORTED)
  165701. PNG_CONST PNG_iCCP;
  165702. #endif
  165703. #if defined(PNG_READ_iTXt_SUPPORTED)
  165704. PNG_CONST PNG_iTXt;
  165705. #endif
  165706. #if defined(PNG_READ_oFFs_SUPPORTED)
  165707. PNG_CONST PNG_oFFs;
  165708. #endif
  165709. #if defined(PNG_READ_pCAL_SUPPORTED)
  165710. PNG_CONST PNG_pCAL;
  165711. #endif
  165712. #if defined(PNG_READ_pHYs_SUPPORTED)
  165713. PNG_CONST PNG_pHYs;
  165714. #endif
  165715. #if defined(PNG_READ_sBIT_SUPPORTED)
  165716. PNG_CONST PNG_sBIT;
  165717. #endif
  165718. #if defined(PNG_READ_sCAL_SUPPORTED)
  165719. PNG_CONST PNG_sCAL;
  165720. #endif
  165721. #if defined(PNG_READ_sRGB_SUPPORTED)
  165722. PNG_CONST PNG_sRGB;
  165723. #endif
  165724. #if defined(PNG_READ_sPLT_SUPPORTED)
  165725. PNG_CONST PNG_sPLT;
  165726. #endif
  165727. #if defined(PNG_READ_tEXt_SUPPORTED)
  165728. PNG_CONST PNG_tEXt;
  165729. #endif
  165730. #if defined(PNG_READ_tIME_SUPPORTED)
  165731. PNG_CONST PNG_tIME;
  165732. #endif
  165733. #if defined(PNG_READ_tRNS_SUPPORTED)
  165734. PNG_CONST PNG_tRNS;
  165735. #endif
  165736. #if defined(PNG_READ_zTXt_SUPPORTED)
  165737. PNG_CONST PNG_zTXt;
  165738. #endif
  165739. #endif /* PNG_USE_LOCAL_ARRAYS */
  165740. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165741. {
  165742. png_byte chunk_length[4];
  165743. if (png_ptr->buffer_size < 8)
  165744. {
  165745. png_push_save_buffer(png_ptr);
  165746. return;
  165747. }
  165748. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165749. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165750. png_reset_crc(png_ptr);
  165751. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165752. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165753. }
  165754. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165755. if(png_ptr->mode & PNG_AFTER_IDAT)
  165756. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165757. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165758. {
  165759. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165760. {
  165761. png_push_save_buffer(png_ptr);
  165762. return;
  165763. }
  165764. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165765. }
  165766. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165767. {
  165768. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165769. {
  165770. png_push_save_buffer(png_ptr);
  165771. return;
  165772. }
  165773. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165774. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165775. png_push_have_end(png_ptr, info_ptr);
  165776. }
  165777. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165778. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165779. {
  165780. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165781. {
  165782. png_push_save_buffer(png_ptr);
  165783. return;
  165784. }
  165785. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165786. png_ptr->mode |= PNG_HAVE_IDAT;
  165787. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165788. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165789. png_ptr->mode |= PNG_HAVE_PLTE;
  165790. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165791. {
  165792. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165793. png_error(png_ptr, "Missing IHDR before IDAT");
  165794. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165795. !(png_ptr->mode & PNG_HAVE_PLTE))
  165796. png_error(png_ptr, "Missing PLTE before IDAT");
  165797. }
  165798. }
  165799. #endif
  165800. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165801. {
  165802. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165803. {
  165804. png_push_save_buffer(png_ptr);
  165805. return;
  165806. }
  165807. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165808. }
  165809. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165810. {
  165811. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165812. png_error(png_ptr, "Missing IHDR before IDAT");
  165813. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165814. !(png_ptr->mode & PNG_HAVE_PLTE))
  165815. png_error(png_ptr, "Missing PLTE before IDAT");
  165816. if (png_ptr->mode & PNG_HAVE_IDAT)
  165817. {
  165818. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165819. if (png_ptr->push_length == 0)
  165820. return;
  165821. if (png_ptr->mode & PNG_AFTER_IDAT)
  165822. png_error(png_ptr, "Too many IDAT's found");
  165823. }
  165824. png_ptr->idat_size = png_ptr->push_length;
  165825. png_ptr->mode |= PNG_HAVE_IDAT;
  165826. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165827. png_push_have_info(png_ptr, info_ptr);
  165828. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165829. png_ptr->zstream.next_out = png_ptr->row_buf;
  165830. return;
  165831. }
  165832. #if defined(PNG_READ_gAMA_SUPPORTED)
  165833. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165834. {
  165835. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165836. {
  165837. png_push_save_buffer(png_ptr);
  165838. return;
  165839. }
  165840. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165841. }
  165842. #endif
  165843. #if defined(PNG_READ_sBIT_SUPPORTED)
  165844. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165845. {
  165846. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165847. {
  165848. png_push_save_buffer(png_ptr);
  165849. return;
  165850. }
  165851. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165852. }
  165853. #endif
  165854. #if defined(PNG_READ_cHRM_SUPPORTED)
  165855. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 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_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165863. }
  165864. #endif
  165865. #if defined(PNG_READ_sRGB_SUPPORTED)
  165866. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165867. {
  165868. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165869. {
  165870. png_push_save_buffer(png_ptr);
  165871. return;
  165872. }
  165873. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165874. }
  165875. #endif
  165876. #if defined(PNG_READ_iCCP_SUPPORTED)
  165877. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165878. {
  165879. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165880. {
  165881. png_push_save_buffer(png_ptr);
  165882. return;
  165883. }
  165884. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165885. }
  165886. #endif
  165887. #if defined(PNG_READ_sPLT_SUPPORTED)
  165888. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 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_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165896. }
  165897. #endif
  165898. #if defined(PNG_READ_tRNS_SUPPORTED)
  165899. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 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_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165907. }
  165908. #endif
  165909. #if defined(PNG_READ_bKGD_SUPPORTED)
  165910. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 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_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165918. }
  165919. #endif
  165920. #if defined(PNG_READ_hIST_SUPPORTED)
  165921. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 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_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165929. }
  165930. #endif
  165931. #if defined(PNG_READ_pHYs_SUPPORTED)
  165932. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 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_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165940. }
  165941. #endif
  165942. #if defined(PNG_READ_oFFs_SUPPORTED)
  165943. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 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_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  165951. }
  165952. #endif
  165953. #if defined(PNG_READ_pCAL_SUPPORTED)
  165954. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 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_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  165962. }
  165963. #endif
  165964. #if defined(PNG_READ_sCAL_SUPPORTED)
  165965. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 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_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  165973. }
  165974. #endif
  165975. #if defined(PNG_READ_tIME_SUPPORTED)
  165976. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 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_tIME(png_ptr, info_ptr, png_ptr->push_length);
  165984. }
  165985. #endif
  165986. #if defined(PNG_READ_tEXt_SUPPORTED)
  165987. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 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_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  165995. }
  165996. #endif
  165997. #if defined(PNG_READ_zTXt_SUPPORTED)
  165998. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 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_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  166006. }
  166007. #endif
  166008. #if defined(PNG_READ_iTXt_SUPPORTED)
  166009. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 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_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  166017. }
  166018. #endif
  166019. else
  166020. {
  166021. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166022. {
  166023. png_push_save_buffer(png_ptr);
  166024. return;
  166025. }
  166026. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166027. }
  166028. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166029. }
  166030. void /* PRIVATE */
  166031. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  166032. {
  166033. png_ptr->process_mode = PNG_SKIP_MODE;
  166034. png_ptr->skip_length = skip;
  166035. }
  166036. void /* PRIVATE */
  166037. png_push_crc_finish(png_structp png_ptr)
  166038. {
  166039. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166040. {
  166041. png_size_t save_size;
  166042. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166043. save_size = (png_size_t)png_ptr->skip_length;
  166044. else
  166045. save_size = png_ptr->save_buffer_size;
  166046. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166047. png_ptr->skip_length -= save_size;
  166048. png_ptr->buffer_size -= save_size;
  166049. png_ptr->save_buffer_size -= save_size;
  166050. png_ptr->save_buffer_ptr += save_size;
  166051. }
  166052. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166053. {
  166054. png_size_t save_size;
  166055. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166056. save_size = (png_size_t)png_ptr->skip_length;
  166057. else
  166058. save_size = png_ptr->current_buffer_size;
  166059. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166060. png_ptr->skip_length -= save_size;
  166061. png_ptr->buffer_size -= save_size;
  166062. png_ptr->current_buffer_size -= save_size;
  166063. png_ptr->current_buffer_ptr += save_size;
  166064. }
  166065. if (!png_ptr->skip_length)
  166066. {
  166067. if (png_ptr->buffer_size < 4)
  166068. {
  166069. png_push_save_buffer(png_ptr);
  166070. return;
  166071. }
  166072. png_crc_finish(png_ptr, 0);
  166073. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166074. }
  166075. }
  166076. void PNGAPI
  166077. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166078. {
  166079. png_bytep ptr;
  166080. if(png_ptr == NULL) return;
  166081. ptr = buffer;
  166082. if (png_ptr->save_buffer_size)
  166083. {
  166084. png_size_t save_size;
  166085. if (length < png_ptr->save_buffer_size)
  166086. save_size = length;
  166087. else
  166088. save_size = png_ptr->save_buffer_size;
  166089. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166090. length -= save_size;
  166091. ptr += save_size;
  166092. png_ptr->buffer_size -= save_size;
  166093. png_ptr->save_buffer_size -= save_size;
  166094. png_ptr->save_buffer_ptr += save_size;
  166095. }
  166096. if (length && png_ptr->current_buffer_size)
  166097. {
  166098. png_size_t save_size;
  166099. if (length < png_ptr->current_buffer_size)
  166100. save_size = length;
  166101. else
  166102. save_size = png_ptr->current_buffer_size;
  166103. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166104. png_ptr->buffer_size -= save_size;
  166105. png_ptr->current_buffer_size -= save_size;
  166106. png_ptr->current_buffer_ptr += save_size;
  166107. }
  166108. }
  166109. void /* PRIVATE */
  166110. png_push_save_buffer(png_structp png_ptr)
  166111. {
  166112. if (png_ptr->save_buffer_size)
  166113. {
  166114. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166115. {
  166116. png_size_t i,istop;
  166117. png_bytep sp;
  166118. png_bytep dp;
  166119. istop = png_ptr->save_buffer_size;
  166120. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166121. i < istop; i++, sp++, dp++)
  166122. {
  166123. *dp = *sp;
  166124. }
  166125. }
  166126. }
  166127. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166128. png_ptr->save_buffer_max)
  166129. {
  166130. png_size_t new_max;
  166131. png_bytep old_buffer;
  166132. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166133. (png_ptr->current_buffer_size + 256))
  166134. {
  166135. png_error(png_ptr, "Potential overflow of save_buffer");
  166136. }
  166137. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166138. old_buffer = png_ptr->save_buffer;
  166139. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166140. (png_uint_32)new_max);
  166141. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166142. png_free(png_ptr, old_buffer);
  166143. png_ptr->save_buffer_max = new_max;
  166144. }
  166145. if (png_ptr->current_buffer_size)
  166146. {
  166147. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166148. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166149. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166150. png_ptr->current_buffer_size = 0;
  166151. }
  166152. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166153. png_ptr->buffer_size = 0;
  166154. }
  166155. void /* PRIVATE */
  166156. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166157. png_size_t buffer_length)
  166158. {
  166159. png_ptr->current_buffer = buffer;
  166160. png_ptr->current_buffer_size = buffer_length;
  166161. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166162. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166163. }
  166164. void /* PRIVATE */
  166165. png_push_read_IDAT(png_structp png_ptr)
  166166. {
  166167. #ifdef PNG_USE_LOCAL_ARRAYS
  166168. PNG_CONST PNG_IDAT;
  166169. #endif
  166170. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166171. {
  166172. png_byte chunk_length[4];
  166173. if (png_ptr->buffer_size < 8)
  166174. {
  166175. png_push_save_buffer(png_ptr);
  166176. return;
  166177. }
  166178. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166179. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166180. png_reset_crc(png_ptr);
  166181. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166182. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166183. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166184. {
  166185. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166186. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166187. png_error(png_ptr, "Not enough compressed data");
  166188. return;
  166189. }
  166190. png_ptr->idat_size = png_ptr->push_length;
  166191. }
  166192. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166193. {
  166194. png_size_t save_size;
  166195. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166196. {
  166197. save_size = (png_size_t)png_ptr->idat_size;
  166198. if((png_uint_32)save_size != png_ptr->idat_size)
  166199. png_error(png_ptr, "save_size overflowed in pngpread");
  166200. }
  166201. else
  166202. save_size = png_ptr->save_buffer_size;
  166203. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166204. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166205. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166206. png_ptr->idat_size -= save_size;
  166207. png_ptr->buffer_size -= save_size;
  166208. png_ptr->save_buffer_size -= save_size;
  166209. png_ptr->save_buffer_ptr += save_size;
  166210. }
  166211. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166212. {
  166213. png_size_t save_size;
  166214. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166215. {
  166216. save_size = (png_size_t)png_ptr->idat_size;
  166217. if((png_uint_32)save_size != png_ptr->idat_size)
  166218. png_error(png_ptr, "save_size overflowed in pngpread");
  166219. }
  166220. else
  166221. save_size = png_ptr->current_buffer_size;
  166222. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166223. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166224. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166225. png_ptr->idat_size -= save_size;
  166226. png_ptr->buffer_size -= save_size;
  166227. png_ptr->current_buffer_size -= save_size;
  166228. png_ptr->current_buffer_ptr += save_size;
  166229. }
  166230. if (!png_ptr->idat_size)
  166231. {
  166232. if (png_ptr->buffer_size < 4)
  166233. {
  166234. png_push_save_buffer(png_ptr);
  166235. return;
  166236. }
  166237. png_crc_finish(png_ptr, 0);
  166238. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166239. png_ptr->mode |= PNG_AFTER_IDAT;
  166240. }
  166241. }
  166242. void /* PRIVATE */
  166243. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166244. png_size_t buffer_length)
  166245. {
  166246. int ret;
  166247. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166248. png_error(png_ptr, "Extra compression data");
  166249. png_ptr->zstream.next_in = buffer;
  166250. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166251. for(;;)
  166252. {
  166253. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166254. if (ret != Z_OK)
  166255. {
  166256. if (ret == Z_STREAM_END)
  166257. {
  166258. if (png_ptr->zstream.avail_in)
  166259. png_error(png_ptr, "Extra compressed data");
  166260. if (!(png_ptr->zstream.avail_out))
  166261. {
  166262. png_push_process_row(png_ptr);
  166263. }
  166264. png_ptr->mode |= PNG_AFTER_IDAT;
  166265. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166266. break;
  166267. }
  166268. else if (ret == Z_BUF_ERROR)
  166269. break;
  166270. else
  166271. png_error(png_ptr, "Decompression Error");
  166272. }
  166273. if (!(png_ptr->zstream.avail_out))
  166274. {
  166275. if ((
  166276. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166277. png_ptr->interlaced && png_ptr->pass > 6) ||
  166278. (!png_ptr->interlaced &&
  166279. #endif
  166280. png_ptr->row_number == png_ptr->num_rows))
  166281. {
  166282. if (png_ptr->zstream.avail_in)
  166283. {
  166284. png_warning(png_ptr, "Too much data in IDAT chunks");
  166285. }
  166286. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166287. break;
  166288. }
  166289. png_push_process_row(png_ptr);
  166290. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166291. png_ptr->zstream.next_out = png_ptr->row_buf;
  166292. }
  166293. else
  166294. break;
  166295. }
  166296. }
  166297. void /* PRIVATE */
  166298. png_push_process_row(png_structp png_ptr)
  166299. {
  166300. png_ptr->row_info.color_type = png_ptr->color_type;
  166301. png_ptr->row_info.width = png_ptr->iwidth;
  166302. png_ptr->row_info.channels = png_ptr->channels;
  166303. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166304. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166305. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166306. png_ptr->row_info.width);
  166307. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166308. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166309. (int)(png_ptr->row_buf[0]));
  166310. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166311. png_ptr->rowbytes + 1);
  166312. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166313. png_do_read_transformations(png_ptr);
  166314. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166315. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166316. {
  166317. if (png_ptr->pass < 6)
  166318. png_do_read_interlace(png_ptr);
  166319. switch (png_ptr->pass)
  166320. {
  166321. case 0:
  166322. {
  166323. int i;
  166324. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166325. {
  166326. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166327. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166328. }
  166329. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166330. {
  166331. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166332. {
  166333. png_push_have_row(png_ptr, png_bytep_NULL);
  166334. png_read_push_finish_row(png_ptr);
  166335. }
  166336. }
  166337. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166338. {
  166339. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166340. {
  166341. png_push_have_row(png_ptr, png_bytep_NULL);
  166342. png_read_push_finish_row(png_ptr);
  166343. }
  166344. }
  166345. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166346. {
  166347. png_push_have_row(png_ptr, png_bytep_NULL);
  166348. png_read_push_finish_row(png_ptr);
  166349. }
  166350. break;
  166351. }
  166352. case 1:
  166353. {
  166354. int i;
  166355. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166356. {
  166357. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166358. png_read_push_finish_row(png_ptr);
  166359. }
  166360. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166361. {
  166362. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166363. {
  166364. png_push_have_row(png_ptr, png_bytep_NULL);
  166365. png_read_push_finish_row(png_ptr);
  166366. }
  166367. }
  166368. break;
  166369. }
  166370. case 2:
  166371. {
  166372. int i;
  166373. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166374. {
  166375. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166376. png_read_push_finish_row(png_ptr);
  166377. }
  166378. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166379. {
  166380. png_push_have_row(png_ptr, png_bytep_NULL);
  166381. png_read_push_finish_row(png_ptr);
  166382. }
  166383. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166384. {
  166385. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166386. {
  166387. png_push_have_row(png_ptr, png_bytep_NULL);
  166388. png_read_push_finish_row(png_ptr);
  166389. }
  166390. }
  166391. break;
  166392. }
  166393. case 3:
  166394. {
  166395. int i;
  166396. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166397. {
  166398. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166399. png_read_push_finish_row(png_ptr);
  166400. }
  166401. if (png_ptr->pass == 4) /* skip top two generated rows */
  166402. {
  166403. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166404. {
  166405. png_push_have_row(png_ptr, png_bytep_NULL);
  166406. png_read_push_finish_row(png_ptr);
  166407. }
  166408. }
  166409. break;
  166410. }
  166411. case 4:
  166412. {
  166413. int i;
  166414. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166415. {
  166416. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166417. png_read_push_finish_row(png_ptr);
  166418. }
  166419. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166420. {
  166421. png_push_have_row(png_ptr, png_bytep_NULL);
  166422. png_read_push_finish_row(png_ptr);
  166423. }
  166424. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166425. {
  166426. png_push_have_row(png_ptr, png_bytep_NULL);
  166427. png_read_push_finish_row(png_ptr);
  166428. }
  166429. break;
  166430. }
  166431. case 5:
  166432. {
  166433. int i;
  166434. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166435. {
  166436. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166437. png_read_push_finish_row(png_ptr);
  166438. }
  166439. if (png_ptr->pass == 6) /* skip top generated row */
  166440. {
  166441. png_push_have_row(png_ptr, png_bytep_NULL);
  166442. png_read_push_finish_row(png_ptr);
  166443. }
  166444. break;
  166445. }
  166446. case 6:
  166447. {
  166448. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166449. png_read_push_finish_row(png_ptr);
  166450. if (png_ptr->pass != 6)
  166451. break;
  166452. png_push_have_row(png_ptr, png_bytep_NULL);
  166453. png_read_push_finish_row(png_ptr);
  166454. }
  166455. }
  166456. }
  166457. else
  166458. #endif
  166459. {
  166460. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166461. png_read_push_finish_row(png_ptr);
  166462. }
  166463. }
  166464. void /* PRIVATE */
  166465. png_read_push_finish_row(png_structp png_ptr)
  166466. {
  166467. #ifdef PNG_USE_LOCAL_ARRAYS
  166468. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166469. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166470. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166471. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166472. #endif
  166473. png_ptr->row_number++;
  166474. if (png_ptr->row_number < png_ptr->num_rows)
  166475. return;
  166476. if (png_ptr->interlaced)
  166477. {
  166478. png_ptr->row_number = 0;
  166479. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166480. png_ptr->rowbytes + 1);
  166481. do
  166482. {
  166483. png_ptr->pass++;
  166484. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166485. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166486. (png_ptr->pass == 5 && png_ptr->width < 2))
  166487. png_ptr->pass++;
  166488. if (png_ptr->pass > 7)
  166489. png_ptr->pass--;
  166490. if (png_ptr->pass >= 7)
  166491. break;
  166492. png_ptr->iwidth = (png_ptr->width +
  166493. png_pass_inc[png_ptr->pass] - 1 -
  166494. png_pass_start[png_ptr->pass]) /
  166495. png_pass_inc[png_ptr->pass];
  166496. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166497. png_ptr->iwidth) + 1;
  166498. if (png_ptr->transformations & PNG_INTERLACE)
  166499. break;
  166500. png_ptr->num_rows = (png_ptr->height +
  166501. png_pass_yinc[png_ptr->pass] - 1 -
  166502. png_pass_ystart[png_ptr->pass]) /
  166503. png_pass_yinc[png_ptr->pass];
  166504. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166505. }
  166506. }
  166507. #if defined(PNG_READ_tEXt_SUPPORTED)
  166508. void /* PRIVATE */
  166509. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166510. length)
  166511. {
  166512. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166513. {
  166514. png_error(png_ptr, "Out of place tEXt");
  166515. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166516. }
  166517. #ifdef PNG_MAX_MALLOC_64K
  166518. png_ptr->skip_length = 0; /* This may not be necessary */
  166519. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166520. {
  166521. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166522. png_ptr->skip_length = length - (png_uint_32)65535L;
  166523. length = (png_uint_32)65535L;
  166524. }
  166525. #endif
  166526. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166527. (png_uint_32)(length+1));
  166528. png_ptr->current_text[length] = '\0';
  166529. png_ptr->current_text_ptr = png_ptr->current_text;
  166530. png_ptr->current_text_size = (png_size_t)length;
  166531. png_ptr->current_text_left = (png_size_t)length;
  166532. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166533. }
  166534. void /* PRIVATE */
  166535. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166536. {
  166537. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166538. {
  166539. png_size_t text_size;
  166540. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166541. text_size = png_ptr->buffer_size;
  166542. else
  166543. text_size = png_ptr->current_text_left;
  166544. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166545. png_ptr->current_text_left -= text_size;
  166546. png_ptr->current_text_ptr += text_size;
  166547. }
  166548. if (!(png_ptr->current_text_left))
  166549. {
  166550. png_textp text_ptr;
  166551. png_charp text;
  166552. png_charp key;
  166553. int ret;
  166554. if (png_ptr->buffer_size < 4)
  166555. {
  166556. png_push_save_buffer(png_ptr);
  166557. return;
  166558. }
  166559. png_push_crc_finish(png_ptr);
  166560. #if defined(PNG_MAX_MALLOC_64K)
  166561. if (png_ptr->skip_length)
  166562. return;
  166563. #endif
  166564. key = png_ptr->current_text;
  166565. for (text = key; *text; text++)
  166566. ;
  166567. if (text < key + png_ptr->current_text_size)
  166568. text++;
  166569. text_ptr = (png_textp)png_malloc(png_ptr,
  166570. (png_uint_32)png_sizeof(png_text));
  166571. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166572. text_ptr->key = key;
  166573. #ifdef PNG_iTXt_SUPPORTED
  166574. text_ptr->lang = NULL;
  166575. text_ptr->lang_key = NULL;
  166576. #endif
  166577. text_ptr->text = text;
  166578. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166579. png_free(png_ptr, key);
  166580. png_free(png_ptr, text_ptr);
  166581. png_ptr->current_text = NULL;
  166582. if (ret)
  166583. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166584. }
  166585. }
  166586. #endif
  166587. #if defined(PNG_READ_zTXt_SUPPORTED)
  166588. void /* PRIVATE */
  166589. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166590. length)
  166591. {
  166592. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166593. {
  166594. png_error(png_ptr, "Out of place zTXt");
  166595. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166596. }
  166597. #ifdef PNG_MAX_MALLOC_64K
  166598. if (length > (png_uint_32)65535L)
  166599. {
  166600. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166601. png_push_crc_skip(png_ptr, length);
  166602. return;
  166603. }
  166604. #endif
  166605. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166606. (png_uint_32)(length+1));
  166607. png_ptr->current_text[length] = '\0';
  166608. png_ptr->current_text_ptr = png_ptr->current_text;
  166609. png_ptr->current_text_size = (png_size_t)length;
  166610. png_ptr->current_text_left = (png_size_t)length;
  166611. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166612. }
  166613. void /* PRIVATE */
  166614. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166615. {
  166616. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166617. {
  166618. png_size_t text_size;
  166619. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166620. text_size = png_ptr->buffer_size;
  166621. else
  166622. text_size = png_ptr->current_text_left;
  166623. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166624. png_ptr->current_text_left -= text_size;
  166625. png_ptr->current_text_ptr += text_size;
  166626. }
  166627. if (!(png_ptr->current_text_left))
  166628. {
  166629. png_textp text_ptr;
  166630. png_charp text;
  166631. png_charp key;
  166632. int ret;
  166633. png_size_t text_size, key_size;
  166634. if (png_ptr->buffer_size < 4)
  166635. {
  166636. png_push_save_buffer(png_ptr);
  166637. return;
  166638. }
  166639. png_push_crc_finish(png_ptr);
  166640. key = png_ptr->current_text;
  166641. for (text = key; *text; text++)
  166642. ;
  166643. if (text >= key + png_ptr->current_text_size)
  166644. {
  166645. png_ptr->current_text = NULL;
  166646. png_free(png_ptr, key);
  166647. return;
  166648. }
  166649. text++;
  166650. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166651. {
  166652. png_ptr->current_text = NULL;
  166653. png_free(png_ptr, key);
  166654. return;
  166655. }
  166656. text++;
  166657. png_ptr->zstream.next_in = (png_bytep )text;
  166658. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166659. (text - key));
  166660. png_ptr->zstream.next_out = png_ptr->zbuf;
  166661. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166662. key_size = text - key;
  166663. text_size = 0;
  166664. text = NULL;
  166665. ret = Z_STREAM_END;
  166666. while (png_ptr->zstream.avail_in)
  166667. {
  166668. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166669. if (ret != Z_OK && ret != Z_STREAM_END)
  166670. {
  166671. inflateReset(&png_ptr->zstream);
  166672. png_ptr->zstream.avail_in = 0;
  166673. png_ptr->current_text = NULL;
  166674. png_free(png_ptr, key);
  166675. png_free(png_ptr, text);
  166676. return;
  166677. }
  166678. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166679. {
  166680. if (text == NULL)
  166681. {
  166682. text = (png_charp)png_malloc(png_ptr,
  166683. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166684. + key_size + 1));
  166685. png_memcpy(text + key_size, png_ptr->zbuf,
  166686. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166687. png_memcpy(text, key, key_size);
  166688. text_size = key_size + png_ptr->zbuf_size -
  166689. png_ptr->zstream.avail_out;
  166690. *(text + text_size) = '\0';
  166691. }
  166692. else
  166693. {
  166694. png_charp tmp;
  166695. tmp = text;
  166696. text = (png_charp)png_malloc(png_ptr, text_size +
  166697. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166698. + 1));
  166699. png_memcpy(text, tmp, text_size);
  166700. png_free(png_ptr, tmp);
  166701. png_memcpy(text + text_size, png_ptr->zbuf,
  166702. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166703. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166704. *(text + text_size) = '\0';
  166705. }
  166706. if (ret != Z_STREAM_END)
  166707. {
  166708. png_ptr->zstream.next_out = png_ptr->zbuf;
  166709. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166710. }
  166711. }
  166712. else
  166713. {
  166714. break;
  166715. }
  166716. if (ret == Z_STREAM_END)
  166717. break;
  166718. }
  166719. inflateReset(&png_ptr->zstream);
  166720. png_ptr->zstream.avail_in = 0;
  166721. if (ret != Z_STREAM_END)
  166722. {
  166723. png_ptr->current_text = NULL;
  166724. png_free(png_ptr, key);
  166725. png_free(png_ptr, text);
  166726. return;
  166727. }
  166728. png_ptr->current_text = NULL;
  166729. png_free(png_ptr, key);
  166730. key = text;
  166731. text += key_size;
  166732. text_ptr = (png_textp)png_malloc(png_ptr,
  166733. (png_uint_32)png_sizeof(png_text));
  166734. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166735. text_ptr->key = key;
  166736. #ifdef PNG_iTXt_SUPPORTED
  166737. text_ptr->lang = NULL;
  166738. text_ptr->lang_key = NULL;
  166739. #endif
  166740. text_ptr->text = text;
  166741. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166742. png_free(png_ptr, key);
  166743. png_free(png_ptr, text_ptr);
  166744. if (ret)
  166745. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166746. }
  166747. }
  166748. #endif
  166749. #if defined(PNG_READ_iTXt_SUPPORTED)
  166750. void /* PRIVATE */
  166751. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166752. length)
  166753. {
  166754. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166755. {
  166756. png_error(png_ptr, "Out of place iTXt");
  166757. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166758. }
  166759. #ifdef PNG_MAX_MALLOC_64K
  166760. png_ptr->skip_length = 0; /* This may not be necessary */
  166761. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166762. {
  166763. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166764. png_ptr->skip_length = length - (png_uint_32)65535L;
  166765. length = (png_uint_32)65535L;
  166766. }
  166767. #endif
  166768. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166769. (png_uint_32)(length+1));
  166770. png_ptr->current_text[length] = '\0';
  166771. png_ptr->current_text_ptr = png_ptr->current_text;
  166772. png_ptr->current_text_size = (png_size_t)length;
  166773. png_ptr->current_text_left = (png_size_t)length;
  166774. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166775. }
  166776. void /* PRIVATE */
  166777. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166778. {
  166779. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166780. {
  166781. png_size_t text_size;
  166782. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166783. text_size = png_ptr->buffer_size;
  166784. else
  166785. text_size = png_ptr->current_text_left;
  166786. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166787. png_ptr->current_text_left -= text_size;
  166788. png_ptr->current_text_ptr += text_size;
  166789. }
  166790. if (!(png_ptr->current_text_left))
  166791. {
  166792. png_textp text_ptr;
  166793. png_charp key;
  166794. int comp_flag;
  166795. png_charp lang;
  166796. png_charp lang_key;
  166797. png_charp text;
  166798. int ret;
  166799. if (png_ptr->buffer_size < 4)
  166800. {
  166801. png_push_save_buffer(png_ptr);
  166802. return;
  166803. }
  166804. png_push_crc_finish(png_ptr);
  166805. #if defined(PNG_MAX_MALLOC_64K)
  166806. if (png_ptr->skip_length)
  166807. return;
  166808. #endif
  166809. key = png_ptr->current_text;
  166810. for (lang = key; *lang; lang++)
  166811. ;
  166812. if (lang < key + png_ptr->current_text_size - 3)
  166813. lang++;
  166814. comp_flag = *lang++;
  166815. lang++; /* skip comp_type, always zero */
  166816. for (lang_key = lang; *lang_key; lang_key++)
  166817. ;
  166818. lang_key++; /* skip NUL separator */
  166819. text=lang_key;
  166820. if (lang_key < key + png_ptr->current_text_size - 1)
  166821. {
  166822. for (; *text; text++)
  166823. ;
  166824. }
  166825. if (text < key + png_ptr->current_text_size)
  166826. text++;
  166827. text_ptr = (png_textp)png_malloc(png_ptr,
  166828. (png_uint_32)png_sizeof(png_text));
  166829. text_ptr->compression = comp_flag + 2;
  166830. text_ptr->key = key;
  166831. text_ptr->lang = lang;
  166832. text_ptr->lang_key = lang_key;
  166833. text_ptr->text = text;
  166834. text_ptr->text_length = 0;
  166835. text_ptr->itxt_length = png_strlen(text);
  166836. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166837. png_ptr->current_text = NULL;
  166838. png_free(png_ptr, text_ptr);
  166839. if (ret)
  166840. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166841. }
  166842. }
  166843. #endif
  166844. void /* PRIVATE */
  166845. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166846. length)
  166847. {
  166848. png_uint_32 skip=0;
  166849. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166850. if (!(png_ptr->chunk_name[0] & 0x20))
  166851. {
  166852. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166853. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166854. PNG_HANDLE_CHUNK_ALWAYS
  166855. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166856. && png_ptr->read_user_chunk_fn == NULL
  166857. #endif
  166858. )
  166859. #endif
  166860. png_chunk_error(png_ptr, "unknown critical chunk");
  166861. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166862. }
  166863. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166864. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166865. {
  166866. #ifdef PNG_MAX_MALLOC_64K
  166867. if (length > (png_uint_32)65535L)
  166868. {
  166869. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166870. skip = length - (png_uint_32)65535L;
  166871. length = (png_uint_32)65535L;
  166872. }
  166873. #endif
  166874. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166875. (png_charp)png_ptr->chunk_name, 5);
  166876. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166877. png_ptr->unknown_chunk.size = (png_size_t)length;
  166878. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166879. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166880. if(png_ptr->read_user_chunk_fn != NULL)
  166881. {
  166882. int ret;
  166883. ret = (*(png_ptr->read_user_chunk_fn))
  166884. (png_ptr, &png_ptr->unknown_chunk);
  166885. if (ret < 0)
  166886. png_chunk_error(png_ptr, "error in user chunk");
  166887. if (ret == 0)
  166888. {
  166889. if (!(png_ptr->chunk_name[0] & 0x20))
  166890. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166891. PNG_HANDLE_CHUNK_ALWAYS)
  166892. png_chunk_error(png_ptr, "unknown critical chunk");
  166893. png_set_unknown_chunks(png_ptr, info_ptr,
  166894. &png_ptr->unknown_chunk, 1);
  166895. }
  166896. }
  166897. #else
  166898. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166899. #endif
  166900. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166901. png_ptr->unknown_chunk.data = NULL;
  166902. }
  166903. else
  166904. #endif
  166905. skip=length;
  166906. png_push_crc_skip(png_ptr, skip);
  166907. }
  166908. void /* PRIVATE */
  166909. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166910. {
  166911. if (png_ptr->info_fn != NULL)
  166912. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166913. }
  166914. void /* PRIVATE */
  166915. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166916. {
  166917. if (png_ptr->end_fn != NULL)
  166918. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166919. }
  166920. void /* PRIVATE */
  166921. png_push_have_row(png_structp png_ptr, png_bytep row)
  166922. {
  166923. if (png_ptr->row_fn != NULL)
  166924. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166925. (int)png_ptr->pass);
  166926. }
  166927. void PNGAPI
  166928. png_progressive_combine_row (png_structp png_ptr,
  166929. png_bytep old_row, png_bytep new_row)
  166930. {
  166931. #ifdef PNG_USE_LOCAL_ARRAYS
  166932. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166933. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166934. #endif
  166935. if(png_ptr == NULL) return;
  166936. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166937. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166938. }
  166939. void PNGAPI
  166940. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166941. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166942. png_progressive_end_ptr end_fn)
  166943. {
  166944. if(png_ptr == NULL) return;
  166945. png_ptr->info_fn = info_fn;
  166946. png_ptr->row_fn = row_fn;
  166947. png_ptr->end_fn = end_fn;
  166948. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  166949. }
  166950. png_voidp PNGAPI
  166951. png_get_progressive_ptr(png_structp png_ptr)
  166952. {
  166953. if(png_ptr == NULL) return (NULL);
  166954. return png_ptr->io_ptr;
  166955. }
  166956. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166957. /*** End of inlined file: pngpread.c ***/
  166958. /*** Start of inlined file: pngrio.c ***/
  166959. #define PNG_INTERNAL
  166960. #if defined(PNG_READ_SUPPORTED)
  166961. void /* PRIVATE */
  166962. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166963. {
  166964. png_debug1(4,"reading %d bytes\n", (int)length);
  166965. if (png_ptr->read_data_fn != NULL)
  166966. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  166967. else
  166968. png_error(png_ptr, "Call to NULL read function");
  166969. }
  166970. #if !defined(PNG_NO_STDIO)
  166971. #ifndef USE_FAR_KEYWORD
  166972. void PNGAPI
  166973. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166974. {
  166975. png_size_t check;
  166976. if(png_ptr == NULL) return;
  166977. #if defined(_WIN32_WCE)
  166978. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166979. check = 0;
  166980. #else
  166981. check = (png_size_t)fread(data, (png_size_t)1, length,
  166982. (png_FILE_p)png_ptr->io_ptr);
  166983. #endif
  166984. if (check != length)
  166985. png_error(png_ptr, "Read Error");
  166986. }
  166987. #else
  166988. #define NEAR_BUF_SIZE 1024
  166989. #define MIN(a,b) (a <= b ? a : b)
  166990. static void PNGAPI
  166991. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166992. {
  166993. int check;
  166994. png_byte *n_data;
  166995. png_FILE_p io_ptr;
  166996. if(png_ptr == NULL) return;
  166997. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  166998. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  166999. if ((png_bytep)n_data == data)
  167000. {
  167001. #if defined(_WIN32_WCE)
  167002. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167003. check = 0;
  167004. #else
  167005. check = fread(n_data, 1, length, io_ptr);
  167006. #endif
  167007. }
  167008. else
  167009. {
  167010. png_byte buf[NEAR_BUF_SIZE];
  167011. png_size_t read, remaining, err;
  167012. check = 0;
  167013. remaining = length;
  167014. do
  167015. {
  167016. read = MIN(NEAR_BUF_SIZE, remaining);
  167017. #if defined(_WIN32_WCE)
  167018. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  167019. err = 0;
  167020. #else
  167021. err = fread(buf, (png_size_t)1, read, io_ptr);
  167022. #endif
  167023. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  167024. if(err != read)
  167025. break;
  167026. else
  167027. check += err;
  167028. data += read;
  167029. remaining -= read;
  167030. }
  167031. while (remaining != 0);
  167032. }
  167033. if ((png_uint_32)check != (png_uint_32)length)
  167034. png_error(png_ptr, "read Error");
  167035. }
  167036. #endif
  167037. #endif
  167038. void PNGAPI
  167039. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167040. png_rw_ptr read_data_fn)
  167041. {
  167042. if(png_ptr == NULL) return;
  167043. png_ptr->io_ptr = io_ptr;
  167044. #if !defined(PNG_NO_STDIO)
  167045. if (read_data_fn != NULL)
  167046. png_ptr->read_data_fn = read_data_fn;
  167047. else
  167048. png_ptr->read_data_fn = png_default_read_data;
  167049. #else
  167050. png_ptr->read_data_fn = read_data_fn;
  167051. #endif
  167052. if (png_ptr->write_data_fn != NULL)
  167053. {
  167054. png_ptr->write_data_fn = NULL;
  167055. png_warning(png_ptr,
  167056. "It's an error to set both read_data_fn and write_data_fn in the ");
  167057. png_warning(png_ptr,
  167058. "same structure. Resetting write_data_fn to NULL.");
  167059. }
  167060. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167061. png_ptr->output_flush_fn = NULL;
  167062. #endif
  167063. }
  167064. #endif /* PNG_READ_SUPPORTED */
  167065. /*** End of inlined file: pngrio.c ***/
  167066. /*** Start of inlined file: pngrtran.c ***/
  167067. #define PNG_INTERNAL
  167068. #if defined(PNG_READ_SUPPORTED)
  167069. void PNGAPI
  167070. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167071. {
  167072. png_debug(1, "in png_set_crc_action\n");
  167073. if(png_ptr == NULL) return;
  167074. switch (crit_action)
  167075. {
  167076. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167077. break;
  167078. case PNG_CRC_WARN_USE: /* warn/use data */
  167079. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167080. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167081. break;
  167082. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167083. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167084. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167085. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167086. break;
  167087. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167088. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167089. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167090. case PNG_CRC_DEFAULT:
  167091. default:
  167092. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167093. break;
  167094. }
  167095. switch (ancil_action)
  167096. {
  167097. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167098. break;
  167099. case PNG_CRC_WARN_USE: /* warn/use data */
  167100. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167101. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167102. break;
  167103. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167104. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167105. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167106. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167107. break;
  167108. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167109. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167110. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167111. break;
  167112. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167113. case PNG_CRC_DEFAULT:
  167114. default:
  167115. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167116. break;
  167117. }
  167118. }
  167119. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167120. defined(PNG_FLOATING_POINT_SUPPORTED)
  167121. void PNGAPI
  167122. png_set_background(png_structp png_ptr,
  167123. png_color_16p background_color, int background_gamma_code,
  167124. int need_expand, double background_gamma)
  167125. {
  167126. png_debug(1, "in png_set_background\n");
  167127. if(png_ptr == NULL) return;
  167128. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167129. {
  167130. png_warning(png_ptr, "Application must supply a known background gamma");
  167131. return;
  167132. }
  167133. png_ptr->transformations |= PNG_BACKGROUND;
  167134. png_memcpy(&(png_ptr->background), background_color,
  167135. png_sizeof(png_color_16));
  167136. png_ptr->background_gamma = (float)background_gamma;
  167137. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167138. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167139. }
  167140. #endif
  167141. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167142. void PNGAPI
  167143. png_set_strip_16(png_structp png_ptr)
  167144. {
  167145. png_debug(1, "in png_set_strip_16\n");
  167146. if(png_ptr == NULL) return;
  167147. png_ptr->transformations |= PNG_16_TO_8;
  167148. }
  167149. #endif
  167150. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167151. void PNGAPI
  167152. png_set_strip_alpha(png_structp png_ptr)
  167153. {
  167154. png_debug(1, "in png_set_strip_alpha\n");
  167155. if(png_ptr == NULL) return;
  167156. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167157. }
  167158. #endif
  167159. #if defined(PNG_READ_DITHER_SUPPORTED)
  167160. typedef struct png_dsort_struct
  167161. {
  167162. struct png_dsort_struct FAR * next;
  167163. png_byte left;
  167164. png_byte right;
  167165. } png_dsort;
  167166. typedef png_dsort FAR * png_dsortp;
  167167. typedef png_dsort FAR * FAR * png_dsortpp;
  167168. void PNGAPI
  167169. png_set_dither(png_structp png_ptr, png_colorp palette,
  167170. int num_palette, int maximum_colors, png_uint_16p histogram,
  167171. int full_dither)
  167172. {
  167173. png_debug(1, "in png_set_dither\n");
  167174. if(png_ptr == NULL) return;
  167175. png_ptr->transformations |= PNG_DITHER;
  167176. if (!full_dither)
  167177. {
  167178. int i;
  167179. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167180. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167181. for (i = 0; i < num_palette; i++)
  167182. png_ptr->dither_index[i] = (png_byte)i;
  167183. }
  167184. if (num_palette > maximum_colors)
  167185. {
  167186. if (histogram != NULL)
  167187. {
  167188. int i;
  167189. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167190. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167191. for (i = 0; i < num_palette; i++)
  167192. png_ptr->dither_sort[i] = (png_byte)i;
  167193. for (i = num_palette - 1; i >= maximum_colors; i--)
  167194. {
  167195. int done; /* to stop early if the list is pre-sorted */
  167196. int j;
  167197. done = 1;
  167198. for (j = 0; j < i; j++)
  167199. {
  167200. if (histogram[png_ptr->dither_sort[j]]
  167201. < histogram[png_ptr->dither_sort[j + 1]])
  167202. {
  167203. png_byte t;
  167204. t = png_ptr->dither_sort[j];
  167205. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167206. png_ptr->dither_sort[j + 1] = t;
  167207. done = 0;
  167208. }
  167209. }
  167210. if (done)
  167211. break;
  167212. }
  167213. if (full_dither)
  167214. {
  167215. int j = num_palette;
  167216. for (i = 0; i < maximum_colors; i++)
  167217. {
  167218. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167219. {
  167220. do
  167221. j--;
  167222. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167223. palette[i] = palette[j];
  167224. }
  167225. }
  167226. }
  167227. else
  167228. {
  167229. int j = num_palette;
  167230. for (i = 0; i < maximum_colors; i++)
  167231. {
  167232. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167233. {
  167234. png_color tmp_color;
  167235. do
  167236. j--;
  167237. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167238. tmp_color = palette[j];
  167239. palette[j] = palette[i];
  167240. palette[i] = tmp_color;
  167241. png_ptr->dither_index[j] = (png_byte)i;
  167242. png_ptr->dither_index[i] = (png_byte)j;
  167243. }
  167244. }
  167245. for (i = 0; i < num_palette; i++)
  167246. {
  167247. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167248. {
  167249. int min_d, k, min_k, d_index;
  167250. d_index = png_ptr->dither_index[i];
  167251. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167252. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167253. {
  167254. int d;
  167255. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167256. if (d < min_d)
  167257. {
  167258. min_d = d;
  167259. min_k = k;
  167260. }
  167261. }
  167262. png_ptr->dither_index[i] = (png_byte)min_k;
  167263. }
  167264. }
  167265. }
  167266. png_free(png_ptr, png_ptr->dither_sort);
  167267. png_ptr->dither_sort=NULL;
  167268. }
  167269. else
  167270. {
  167271. int i;
  167272. int max_d;
  167273. int num_new_palette;
  167274. png_dsortp t;
  167275. png_dsortpp hash;
  167276. t=NULL;
  167277. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167278. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167279. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167280. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167281. for (i = 0; i < num_palette; i++)
  167282. {
  167283. png_ptr->index_to_palette[i] = (png_byte)i;
  167284. png_ptr->palette_to_index[i] = (png_byte)i;
  167285. }
  167286. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167287. png_sizeof (png_dsortp)));
  167288. for (i = 0; i < 769; i++)
  167289. hash[i] = NULL;
  167290. num_new_palette = num_palette;
  167291. max_d = 96;
  167292. while (num_new_palette > maximum_colors)
  167293. {
  167294. for (i = 0; i < num_new_palette - 1; i++)
  167295. {
  167296. int j;
  167297. for (j = i + 1; j < num_new_palette; j++)
  167298. {
  167299. int d;
  167300. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167301. if (d <= max_d)
  167302. {
  167303. t = (png_dsortp)png_malloc_warn(png_ptr,
  167304. (png_uint_32)(png_sizeof(png_dsort)));
  167305. if (t == NULL)
  167306. break;
  167307. t->next = hash[d];
  167308. t->left = (png_byte)i;
  167309. t->right = (png_byte)j;
  167310. hash[d] = t;
  167311. }
  167312. }
  167313. if (t == NULL)
  167314. break;
  167315. }
  167316. if (t != NULL)
  167317. for (i = 0; i <= max_d; i++)
  167318. {
  167319. if (hash[i] != NULL)
  167320. {
  167321. png_dsortp p;
  167322. for (p = hash[i]; p; p = p->next)
  167323. {
  167324. if ((int)png_ptr->index_to_palette[p->left]
  167325. < num_new_palette &&
  167326. (int)png_ptr->index_to_palette[p->right]
  167327. < num_new_palette)
  167328. {
  167329. int j, next_j;
  167330. if (num_new_palette & 0x01)
  167331. {
  167332. j = p->left;
  167333. next_j = p->right;
  167334. }
  167335. else
  167336. {
  167337. j = p->right;
  167338. next_j = p->left;
  167339. }
  167340. num_new_palette--;
  167341. palette[png_ptr->index_to_palette[j]]
  167342. = palette[num_new_palette];
  167343. if (!full_dither)
  167344. {
  167345. int k;
  167346. for (k = 0; k < num_palette; k++)
  167347. {
  167348. if (png_ptr->dither_index[k] ==
  167349. png_ptr->index_to_palette[j])
  167350. png_ptr->dither_index[k] =
  167351. png_ptr->index_to_palette[next_j];
  167352. if ((int)png_ptr->dither_index[k] ==
  167353. num_new_palette)
  167354. png_ptr->dither_index[k] =
  167355. png_ptr->index_to_palette[j];
  167356. }
  167357. }
  167358. png_ptr->index_to_palette[png_ptr->palette_to_index
  167359. [num_new_palette]] = png_ptr->index_to_palette[j];
  167360. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167361. = png_ptr->palette_to_index[num_new_palette];
  167362. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167363. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167364. }
  167365. if (num_new_palette <= maximum_colors)
  167366. break;
  167367. }
  167368. if (num_new_palette <= maximum_colors)
  167369. break;
  167370. }
  167371. }
  167372. for (i = 0; i < 769; i++)
  167373. {
  167374. if (hash[i] != NULL)
  167375. {
  167376. png_dsortp p = hash[i];
  167377. while (p)
  167378. {
  167379. t = p->next;
  167380. png_free(png_ptr, p);
  167381. p = t;
  167382. }
  167383. }
  167384. hash[i] = 0;
  167385. }
  167386. max_d += 96;
  167387. }
  167388. png_free(png_ptr, hash);
  167389. png_free(png_ptr, png_ptr->palette_to_index);
  167390. png_free(png_ptr, png_ptr->index_to_palette);
  167391. png_ptr->palette_to_index=NULL;
  167392. png_ptr->index_to_palette=NULL;
  167393. }
  167394. num_palette = maximum_colors;
  167395. }
  167396. if (png_ptr->palette == NULL)
  167397. {
  167398. png_ptr->palette = palette;
  167399. }
  167400. png_ptr->num_palette = (png_uint_16)num_palette;
  167401. if (full_dither)
  167402. {
  167403. int i;
  167404. png_bytep distance;
  167405. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167406. PNG_DITHER_BLUE_BITS;
  167407. int num_red = (1 << PNG_DITHER_RED_BITS);
  167408. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167409. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167410. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167411. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167412. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167413. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167414. png_sizeof (png_byte));
  167415. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167416. png_sizeof(png_byte)));
  167417. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167418. for (i = 0; i < num_palette; i++)
  167419. {
  167420. int ir, ig, ib;
  167421. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167422. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167423. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167424. for (ir = 0; ir < num_red; ir++)
  167425. {
  167426. int dr = ((ir > r) ? ir - r : r - ir);
  167427. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167428. for (ig = 0; ig < num_green; ig++)
  167429. {
  167430. int dg = ((ig > g) ? ig - g : g - ig);
  167431. int dt = dr + dg;
  167432. int dm = ((dr > dg) ? dr : dg);
  167433. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167434. for (ib = 0; ib < num_blue; ib++)
  167435. {
  167436. int d_index = index_g | ib;
  167437. int db = ((ib > b) ? ib - b : b - ib);
  167438. int dmax = ((dm > db) ? dm : db);
  167439. int d = dmax + dt + db;
  167440. if (d < (int)distance[d_index])
  167441. {
  167442. distance[d_index] = (png_byte)d;
  167443. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167444. }
  167445. }
  167446. }
  167447. }
  167448. }
  167449. png_free(png_ptr, distance);
  167450. }
  167451. }
  167452. #endif
  167453. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167454. void PNGAPI
  167455. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167456. {
  167457. png_debug(1, "in png_set_gamma\n");
  167458. if(png_ptr == NULL) return;
  167459. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167460. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167461. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167462. png_ptr->transformations |= PNG_GAMMA;
  167463. png_ptr->gamma = (float)file_gamma;
  167464. png_ptr->screen_gamma = (float)scrn_gamma;
  167465. }
  167466. #endif
  167467. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167468. void PNGAPI
  167469. png_set_expand(png_structp png_ptr)
  167470. {
  167471. png_debug(1, "in png_set_expand\n");
  167472. if(png_ptr == NULL) return;
  167473. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167474. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167475. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167476. #endif
  167477. }
  167478. void PNGAPI
  167479. png_set_palette_to_rgb(png_structp png_ptr)
  167480. {
  167481. png_debug(1, "in png_set_palette_to_rgb\n");
  167482. if(png_ptr == NULL) return;
  167483. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167484. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167485. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167486. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167487. #endif
  167488. }
  167489. #if !defined(PNG_1_0_X)
  167490. void PNGAPI
  167491. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167492. {
  167493. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167494. if(png_ptr == NULL) return;
  167495. png_ptr->transformations |= PNG_EXPAND;
  167496. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167497. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167498. #endif
  167499. }
  167500. #endif
  167501. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167502. void PNGAPI
  167503. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167504. {
  167505. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167506. if(png_ptr == NULL) return;
  167507. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167508. }
  167509. #endif
  167510. void PNGAPI
  167511. png_set_tRNS_to_alpha(png_structp png_ptr)
  167512. {
  167513. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167514. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167515. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167516. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167517. #endif
  167518. }
  167519. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167520. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167521. void PNGAPI
  167522. png_set_gray_to_rgb(png_structp png_ptr)
  167523. {
  167524. png_debug(1, "in png_set_gray_to_rgb\n");
  167525. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167526. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167527. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167528. #endif
  167529. }
  167530. #endif
  167531. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167532. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167533. void PNGAPI
  167534. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167535. double green)
  167536. {
  167537. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167538. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167539. if(png_ptr == NULL) return;
  167540. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167541. }
  167542. #endif
  167543. void PNGAPI
  167544. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167545. png_fixed_point red, png_fixed_point green)
  167546. {
  167547. png_debug(1, "in png_set_rgb_to_gray\n");
  167548. if(png_ptr == NULL) return;
  167549. switch(error_action)
  167550. {
  167551. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167552. break;
  167553. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167554. break;
  167555. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167556. }
  167557. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167558. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167559. png_ptr->transformations |= PNG_EXPAND;
  167560. #else
  167561. {
  167562. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167563. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167564. }
  167565. #endif
  167566. {
  167567. png_uint_16 red_int, green_int;
  167568. if(red < 0 || green < 0)
  167569. {
  167570. red_int = 6968; /* .212671 * 32768 + .5 */
  167571. green_int = 23434; /* .715160 * 32768 + .5 */
  167572. }
  167573. else if(red + green < 100000L)
  167574. {
  167575. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167576. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167577. }
  167578. else
  167579. {
  167580. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167581. red_int = 6968;
  167582. green_int = 23434;
  167583. }
  167584. png_ptr->rgb_to_gray_red_coeff = red_int;
  167585. png_ptr->rgb_to_gray_green_coeff = green_int;
  167586. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167587. }
  167588. }
  167589. #endif
  167590. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167591. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167592. defined(PNG_LEGACY_SUPPORTED)
  167593. void PNGAPI
  167594. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167595. read_user_transform_fn)
  167596. {
  167597. png_debug(1, "in png_set_read_user_transform_fn\n");
  167598. if(png_ptr == NULL) return;
  167599. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167600. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167601. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167602. #endif
  167603. #ifdef PNG_LEGACY_SUPPORTED
  167604. if(read_user_transform_fn)
  167605. png_warning(png_ptr,
  167606. "This version of libpng does not support user transforms");
  167607. #endif
  167608. }
  167609. #endif
  167610. void /* PRIVATE */
  167611. png_init_read_transformations(png_structp png_ptr)
  167612. {
  167613. png_debug(1, "in png_init_read_transformations\n");
  167614. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167615. if(png_ptr != NULL)
  167616. #endif
  167617. {
  167618. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167619. || defined(PNG_READ_GAMMA_SUPPORTED)
  167620. int color_type = png_ptr->color_type;
  167621. #endif
  167622. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167623. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167624. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167625. !(color_type & PNG_COLOR_MASK_COLOR))
  167626. {
  167627. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167628. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167629. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167630. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167631. png_ptr->background.red == png_ptr->background.green &&
  167632. png_ptr->background.red == png_ptr->background.blue)
  167633. {
  167634. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167635. png_ptr->background.gray = png_ptr->background.red;
  167636. }
  167637. #endif
  167638. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167639. (png_ptr->transformations & PNG_EXPAND))
  167640. {
  167641. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167642. {
  167643. switch (png_ptr->bit_depth)
  167644. {
  167645. case 1:
  167646. png_ptr->background.gray *= (png_uint_16)0xff;
  167647. png_ptr->background.red = png_ptr->background.green
  167648. = png_ptr->background.blue = png_ptr->background.gray;
  167649. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167650. {
  167651. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167652. png_ptr->trans_values.red = png_ptr->trans_values.green
  167653. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167654. }
  167655. break;
  167656. case 2:
  167657. png_ptr->background.gray *= (png_uint_16)0x55;
  167658. png_ptr->background.red = png_ptr->background.green
  167659. = png_ptr->background.blue = png_ptr->background.gray;
  167660. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167661. {
  167662. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167663. png_ptr->trans_values.red = png_ptr->trans_values.green
  167664. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167665. }
  167666. break;
  167667. case 4:
  167668. png_ptr->background.gray *= (png_uint_16)0x11;
  167669. png_ptr->background.red = png_ptr->background.green
  167670. = png_ptr->background.blue = png_ptr->background.gray;
  167671. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167672. {
  167673. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167674. png_ptr->trans_values.red = png_ptr->trans_values.green
  167675. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167676. }
  167677. break;
  167678. case 8:
  167679. case 16:
  167680. png_ptr->background.red = png_ptr->background.green
  167681. = png_ptr->background.blue = png_ptr->background.gray;
  167682. break;
  167683. }
  167684. }
  167685. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167686. {
  167687. png_ptr->background.red =
  167688. png_ptr->palette[png_ptr->background.index].red;
  167689. png_ptr->background.green =
  167690. png_ptr->palette[png_ptr->background.index].green;
  167691. png_ptr->background.blue =
  167692. png_ptr->palette[png_ptr->background.index].blue;
  167693. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167694. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167695. {
  167696. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167697. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167698. #endif
  167699. {
  167700. int i,istop;
  167701. istop=(int)png_ptr->num_trans;
  167702. for (i=0; i<istop; i++)
  167703. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167704. }
  167705. }
  167706. #endif
  167707. }
  167708. }
  167709. #endif
  167710. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167711. png_ptr->background_1 = png_ptr->background;
  167712. #endif
  167713. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167714. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167715. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167716. < PNG_GAMMA_THRESHOLD))
  167717. {
  167718. int i,k;
  167719. k=0;
  167720. for (i=0; i<png_ptr->num_trans; i++)
  167721. {
  167722. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167723. k=1; /* partial transparency is present */
  167724. }
  167725. if (k == 0)
  167726. png_ptr->transformations &= (~PNG_GAMMA);
  167727. }
  167728. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167729. png_ptr->gamma != 0.0)
  167730. {
  167731. png_build_gamma_table(png_ptr);
  167732. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167733. if (png_ptr->transformations & PNG_BACKGROUND)
  167734. {
  167735. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167736. {
  167737. png_color back, back_1;
  167738. png_colorp palette = png_ptr->palette;
  167739. int num_palette = png_ptr->num_palette;
  167740. int i;
  167741. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167742. {
  167743. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167744. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167745. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167746. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167747. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167748. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167749. }
  167750. else
  167751. {
  167752. double g, gs;
  167753. switch (png_ptr->background_gamma_type)
  167754. {
  167755. case PNG_BACKGROUND_GAMMA_SCREEN:
  167756. g = (png_ptr->screen_gamma);
  167757. gs = 1.0;
  167758. break;
  167759. case PNG_BACKGROUND_GAMMA_FILE:
  167760. g = 1.0 / (png_ptr->gamma);
  167761. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167762. break;
  167763. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167764. g = 1.0 / (png_ptr->background_gamma);
  167765. gs = 1.0 / (png_ptr->background_gamma *
  167766. png_ptr->screen_gamma);
  167767. break;
  167768. default:
  167769. g = 1.0; /* back_1 */
  167770. gs = 1.0; /* back */
  167771. }
  167772. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167773. {
  167774. back.red = (png_byte)png_ptr->background.red;
  167775. back.green = (png_byte)png_ptr->background.green;
  167776. back.blue = (png_byte)png_ptr->background.blue;
  167777. }
  167778. else
  167779. {
  167780. back.red = (png_byte)(pow(
  167781. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167782. back.green = (png_byte)(pow(
  167783. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167784. back.blue = (png_byte)(pow(
  167785. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167786. }
  167787. back_1.red = (png_byte)(pow(
  167788. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167789. back_1.green = (png_byte)(pow(
  167790. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167791. back_1.blue = (png_byte)(pow(
  167792. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167793. }
  167794. for (i = 0; i < num_palette; i++)
  167795. {
  167796. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167797. {
  167798. if (png_ptr->trans[i] == 0)
  167799. {
  167800. palette[i] = back;
  167801. }
  167802. else /* if (png_ptr->trans[i] != 0xff) */
  167803. {
  167804. png_byte v, w;
  167805. v = png_ptr->gamma_to_1[palette[i].red];
  167806. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167807. palette[i].red = png_ptr->gamma_from_1[w];
  167808. v = png_ptr->gamma_to_1[palette[i].green];
  167809. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167810. palette[i].green = png_ptr->gamma_from_1[w];
  167811. v = png_ptr->gamma_to_1[palette[i].blue];
  167812. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167813. palette[i].blue = png_ptr->gamma_from_1[w];
  167814. }
  167815. }
  167816. else
  167817. {
  167818. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167819. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167820. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167821. }
  167822. }
  167823. }
  167824. else
  167825. {
  167826. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167827. double g = 1.0;
  167828. double gs = 1.0;
  167829. switch (png_ptr->background_gamma_type)
  167830. {
  167831. case PNG_BACKGROUND_GAMMA_SCREEN:
  167832. g = (png_ptr->screen_gamma);
  167833. gs = 1.0;
  167834. break;
  167835. case PNG_BACKGROUND_GAMMA_FILE:
  167836. g = 1.0 / (png_ptr->gamma);
  167837. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167838. break;
  167839. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167840. g = 1.0 / (png_ptr->background_gamma);
  167841. gs = 1.0 / (png_ptr->background_gamma *
  167842. png_ptr->screen_gamma);
  167843. break;
  167844. }
  167845. png_ptr->background_1.gray = (png_uint_16)(pow(
  167846. (double)png_ptr->background.gray / m, g) * m + .5);
  167847. png_ptr->background.gray = (png_uint_16)(pow(
  167848. (double)png_ptr->background.gray / m, gs) * m + .5);
  167849. if ((png_ptr->background.red != png_ptr->background.green) ||
  167850. (png_ptr->background.red != png_ptr->background.blue) ||
  167851. (png_ptr->background.red != png_ptr->background.gray))
  167852. {
  167853. png_ptr->background_1.red = (png_uint_16)(pow(
  167854. (double)png_ptr->background.red / m, g) * m + .5);
  167855. png_ptr->background_1.green = (png_uint_16)(pow(
  167856. (double)png_ptr->background.green / m, g) * m + .5);
  167857. png_ptr->background_1.blue = (png_uint_16)(pow(
  167858. (double)png_ptr->background.blue / m, g) * m + .5);
  167859. png_ptr->background.red = (png_uint_16)(pow(
  167860. (double)png_ptr->background.red / m, gs) * m + .5);
  167861. png_ptr->background.green = (png_uint_16)(pow(
  167862. (double)png_ptr->background.green / m, gs) * m + .5);
  167863. png_ptr->background.blue = (png_uint_16)(pow(
  167864. (double)png_ptr->background.blue / m, gs) * m + .5);
  167865. }
  167866. else
  167867. {
  167868. png_ptr->background_1.red = png_ptr->background_1.green
  167869. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167870. png_ptr->background.red = png_ptr->background.green
  167871. = png_ptr->background.blue = png_ptr->background.gray;
  167872. }
  167873. }
  167874. }
  167875. else
  167876. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167877. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167878. {
  167879. png_colorp palette = png_ptr->palette;
  167880. int num_palette = png_ptr->num_palette;
  167881. int i;
  167882. for (i = 0; i < num_palette; i++)
  167883. {
  167884. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167885. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167886. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167887. }
  167888. }
  167889. }
  167890. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167891. else
  167892. #endif
  167893. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167894. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167895. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167896. (color_type == PNG_COLOR_TYPE_PALETTE))
  167897. {
  167898. int i;
  167899. int istop = (int)png_ptr->num_trans;
  167900. png_color back;
  167901. png_colorp palette = png_ptr->palette;
  167902. back.red = (png_byte)png_ptr->background.red;
  167903. back.green = (png_byte)png_ptr->background.green;
  167904. back.blue = (png_byte)png_ptr->background.blue;
  167905. for (i = 0; i < istop; i++)
  167906. {
  167907. if (png_ptr->trans[i] == 0)
  167908. {
  167909. palette[i] = back;
  167910. }
  167911. else if (png_ptr->trans[i] != 0xff)
  167912. {
  167913. png_composite(palette[i].red, palette[i].red,
  167914. png_ptr->trans[i], back.red);
  167915. png_composite(palette[i].green, palette[i].green,
  167916. png_ptr->trans[i], back.green);
  167917. png_composite(palette[i].blue, palette[i].blue,
  167918. png_ptr->trans[i], back.blue);
  167919. }
  167920. }
  167921. }
  167922. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167923. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167924. if ((png_ptr->transformations & PNG_SHIFT) &&
  167925. (color_type == PNG_COLOR_TYPE_PALETTE))
  167926. {
  167927. png_uint_16 i;
  167928. png_uint_16 istop = png_ptr->num_palette;
  167929. int sr = 8 - png_ptr->sig_bit.red;
  167930. int sg = 8 - png_ptr->sig_bit.green;
  167931. int sb = 8 - png_ptr->sig_bit.blue;
  167932. if (sr < 0 || sr > 8)
  167933. sr = 0;
  167934. if (sg < 0 || sg > 8)
  167935. sg = 0;
  167936. if (sb < 0 || sb > 8)
  167937. sb = 0;
  167938. for (i = 0; i < istop; i++)
  167939. {
  167940. png_ptr->palette[i].red >>= sr;
  167941. png_ptr->palette[i].green >>= sg;
  167942. png_ptr->palette[i].blue >>= sb;
  167943. }
  167944. }
  167945. #endif /* PNG_READ_SHIFT_SUPPORTED */
  167946. }
  167947. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  167948. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  167949. if(png_ptr)
  167950. return;
  167951. #endif
  167952. }
  167953. void /* PRIVATE */
  167954. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  167955. {
  167956. png_debug(1, "in png_read_transform_info\n");
  167957. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167958. if (png_ptr->transformations & PNG_EXPAND)
  167959. {
  167960. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167961. {
  167962. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  167963. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  167964. else
  167965. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  167966. info_ptr->bit_depth = 8;
  167967. info_ptr->num_trans = 0;
  167968. }
  167969. else
  167970. {
  167971. if (png_ptr->num_trans)
  167972. {
  167973. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  167974. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167975. else
  167976. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167977. }
  167978. if (info_ptr->bit_depth < 8)
  167979. info_ptr->bit_depth = 8;
  167980. info_ptr->num_trans = 0;
  167981. }
  167982. }
  167983. #endif
  167984. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167985. if (png_ptr->transformations & PNG_BACKGROUND)
  167986. {
  167987. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167988. info_ptr->num_trans = 0;
  167989. info_ptr->background = png_ptr->background;
  167990. }
  167991. #endif
  167992. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167993. if (png_ptr->transformations & PNG_GAMMA)
  167994. {
  167995. #ifdef PNG_FLOATING_POINT_SUPPORTED
  167996. info_ptr->gamma = png_ptr->gamma;
  167997. #endif
  167998. #ifdef PNG_FIXED_POINT_SUPPORTED
  167999. info_ptr->int_gamma = png_ptr->int_gamma;
  168000. #endif
  168001. }
  168002. #endif
  168003. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168004. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  168005. info_ptr->bit_depth = 8;
  168006. #endif
  168007. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168008. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  168009. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168010. #endif
  168011. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168012. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168013. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  168014. #endif
  168015. #if defined(PNG_READ_DITHER_SUPPORTED)
  168016. if (png_ptr->transformations & PNG_DITHER)
  168017. {
  168018. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168019. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  168020. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  168021. {
  168022. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  168023. }
  168024. }
  168025. #endif
  168026. #if defined(PNG_READ_PACK_SUPPORTED)
  168027. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  168028. info_ptr->bit_depth = 8;
  168029. #endif
  168030. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168031. info_ptr->channels = 1;
  168032. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168033. info_ptr->channels = 3;
  168034. else
  168035. info_ptr->channels = 1;
  168036. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168037. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168038. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168039. #endif
  168040. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168041. info_ptr->channels++;
  168042. #if defined(PNG_READ_FILLER_SUPPORTED)
  168043. if ((png_ptr->transformations & PNG_FILLER) &&
  168044. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168045. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168046. {
  168047. info_ptr->channels++;
  168048. #if !defined(PNG_1_0_X)
  168049. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168050. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168051. #endif
  168052. }
  168053. #endif
  168054. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168055. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168056. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168057. {
  168058. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168059. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168060. if(info_ptr->channels < png_ptr->user_transform_channels)
  168061. info_ptr->channels = png_ptr->user_transform_channels;
  168062. }
  168063. #endif
  168064. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168065. info_ptr->bit_depth);
  168066. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168067. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168068. if(png_ptr)
  168069. return;
  168070. #endif
  168071. }
  168072. void /* PRIVATE */
  168073. png_do_read_transformations(png_structp png_ptr)
  168074. {
  168075. png_debug(1, "in png_do_read_transformations\n");
  168076. if (png_ptr->row_buf == NULL)
  168077. {
  168078. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168079. char msg[50];
  168080. png_snprintf2(msg, 50,
  168081. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168082. png_ptr->pass);
  168083. png_error(png_ptr, msg);
  168084. #else
  168085. png_error(png_ptr, "NULL row buffer");
  168086. #endif
  168087. }
  168088. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168089. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168090. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168091. png_error(png_ptr, "Uninitialized row");
  168092. #else
  168093. png_warning(png_ptr, "Uninitialized row");
  168094. #endif
  168095. #endif
  168096. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168097. if (png_ptr->transformations & PNG_EXPAND)
  168098. {
  168099. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168100. {
  168101. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168102. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168103. }
  168104. else
  168105. {
  168106. if (png_ptr->num_trans &&
  168107. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168108. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168109. &(png_ptr->trans_values));
  168110. else
  168111. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168112. NULL);
  168113. }
  168114. }
  168115. #endif
  168116. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168117. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168118. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168119. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168120. #endif
  168121. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168122. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168123. {
  168124. int rgb_error =
  168125. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168126. if(rgb_error)
  168127. {
  168128. png_ptr->rgb_to_gray_status=1;
  168129. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168130. PNG_RGB_TO_GRAY_WARN)
  168131. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168132. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168133. PNG_RGB_TO_GRAY_ERR)
  168134. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168135. }
  168136. }
  168137. #endif
  168138. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168139. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168140. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168141. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168142. #endif
  168143. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168144. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168145. ((png_ptr->num_trans != 0 ) ||
  168146. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168147. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168148. &(png_ptr->trans_values), &(png_ptr->background)
  168149. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168150. , &(png_ptr->background_1),
  168151. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168152. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168153. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168154. png_ptr->gamma_shift
  168155. #endif
  168156. );
  168157. #endif
  168158. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168159. if ((png_ptr->transformations & PNG_GAMMA) &&
  168160. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168161. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168162. ((png_ptr->num_trans != 0) ||
  168163. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168164. #endif
  168165. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168166. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168167. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168168. png_ptr->gamma_shift);
  168169. #endif
  168170. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168171. if (png_ptr->transformations & PNG_16_TO_8)
  168172. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168173. #endif
  168174. #if defined(PNG_READ_DITHER_SUPPORTED)
  168175. if (png_ptr->transformations & PNG_DITHER)
  168176. {
  168177. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168178. png_ptr->palette_lookup, png_ptr->dither_index);
  168179. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168180. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168181. }
  168182. #endif
  168183. #if defined(PNG_READ_INVERT_SUPPORTED)
  168184. if (png_ptr->transformations & PNG_INVERT_MONO)
  168185. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168186. #endif
  168187. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168188. if (png_ptr->transformations & PNG_SHIFT)
  168189. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168190. &(png_ptr->shift));
  168191. #endif
  168192. #if defined(PNG_READ_PACK_SUPPORTED)
  168193. if (png_ptr->transformations & PNG_PACK)
  168194. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168195. #endif
  168196. #if defined(PNG_READ_BGR_SUPPORTED)
  168197. if (png_ptr->transformations & PNG_BGR)
  168198. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168199. #endif
  168200. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168201. if (png_ptr->transformations & PNG_PACKSWAP)
  168202. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168203. #endif
  168204. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168205. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168206. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168207. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168208. #endif
  168209. #if defined(PNG_READ_FILLER_SUPPORTED)
  168210. if (png_ptr->transformations & PNG_FILLER)
  168211. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168212. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168213. #endif
  168214. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168215. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168216. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168217. #endif
  168218. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168219. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168220. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168221. #endif
  168222. #if defined(PNG_READ_SWAP_SUPPORTED)
  168223. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168224. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168225. #endif
  168226. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168227. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168228. {
  168229. if(png_ptr->read_user_transform_fn != NULL)
  168230. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168231. (png_ptr, /* png_ptr */
  168232. &(png_ptr->row_info), /* row_info: */
  168233. png_ptr->row_buf + 1); /* start of pixel data for row */
  168234. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168235. if(png_ptr->user_transform_depth)
  168236. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168237. if(png_ptr->user_transform_channels)
  168238. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168239. #endif
  168240. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168241. png_ptr->row_info.channels);
  168242. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168243. png_ptr->row_info.width);
  168244. }
  168245. #endif
  168246. }
  168247. #if defined(PNG_READ_PACK_SUPPORTED)
  168248. void /* PRIVATE */
  168249. png_do_unpack(png_row_infop row_info, png_bytep row)
  168250. {
  168251. png_debug(1, "in png_do_unpack\n");
  168252. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168253. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168254. #else
  168255. if (row_info->bit_depth < 8)
  168256. #endif
  168257. {
  168258. png_uint_32 i;
  168259. png_uint_32 row_width=row_info->width;
  168260. switch (row_info->bit_depth)
  168261. {
  168262. case 1:
  168263. {
  168264. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168265. png_bytep dp = row + (png_size_t)row_width - 1;
  168266. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168267. for (i = 0; i < row_width; i++)
  168268. {
  168269. *dp = (png_byte)((*sp >> shift) & 0x01);
  168270. if (shift == 7)
  168271. {
  168272. shift = 0;
  168273. sp--;
  168274. }
  168275. else
  168276. shift++;
  168277. dp--;
  168278. }
  168279. break;
  168280. }
  168281. case 2:
  168282. {
  168283. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168284. png_bytep dp = row + (png_size_t)row_width - 1;
  168285. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168286. for (i = 0; i < row_width; i++)
  168287. {
  168288. *dp = (png_byte)((*sp >> shift) & 0x03);
  168289. if (shift == 6)
  168290. {
  168291. shift = 0;
  168292. sp--;
  168293. }
  168294. else
  168295. shift += 2;
  168296. dp--;
  168297. }
  168298. break;
  168299. }
  168300. case 4:
  168301. {
  168302. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168303. png_bytep dp = row + (png_size_t)row_width - 1;
  168304. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168305. for (i = 0; i < row_width; i++)
  168306. {
  168307. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168308. if (shift == 4)
  168309. {
  168310. shift = 0;
  168311. sp--;
  168312. }
  168313. else
  168314. shift = 4;
  168315. dp--;
  168316. }
  168317. break;
  168318. }
  168319. }
  168320. row_info->bit_depth = 8;
  168321. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168322. row_info->rowbytes = row_width * row_info->channels;
  168323. }
  168324. }
  168325. #endif
  168326. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168327. void /* PRIVATE */
  168328. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168329. {
  168330. png_debug(1, "in png_do_unshift\n");
  168331. if (
  168332. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168333. row != NULL && row_info != NULL && sig_bits != NULL &&
  168334. #endif
  168335. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168336. {
  168337. int shift[4];
  168338. int channels = 0;
  168339. int c;
  168340. png_uint_16 value = 0;
  168341. png_uint_32 row_width = row_info->width;
  168342. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168343. {
  168344. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168345. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168346. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168347. }
  168348. else
  168349. {
  168350. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168351. }
  168352. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168353. {
  168354. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168355. }
  168356. for (c = 0; c < channels; c++)
  168357. {
  168358. if (shift[c] <= 0)
  168359. shift[c] = 0;
  168360. else
  168361. value = 1;
  168362. }
  168363. if (!value)
  168364. return;
  168365. switch (row_info->bit_depth)
  168366. {
  168367. case 2:
  168368. {
  168369. png_bytep bp;
  168370. png_uint_32 i;
  168371. png_uint_32 istop = row_info->rowbytes;
  168372. for (bp = row, i = 0; i < istop; i++)
  168373. {
  168374. *bp >>= 1;
  168375. *bp++ &= 0x55;
  168376. }
  168377. break;
  168378. }
  168379. case 4:
  168380. {
  168381. png_bytep bp = row;
  168382. png_uint_32 i;
  168383. png_uint_32 istop = row_info->rowbytes;
  168384. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168385. (png_byte)((int)0xf >> shift[0]));
  168386. for (i = 0; i < istop; i++)
  168387. {
  168388. *bp >>= shift[0];
  168389. *bp++ &= mask;
  168390. }
  168391. break;
  168392. }
  168393. case 8:
  168394. {
  168395. png_bytep bp = row;
  168396. png_uint_32 i;
  168397. png_uint_32 istop = row_width * channels;
  168398. for (i = 0; i < istop; i++)
  168399. {
  168400. *bp++ >>= shift[i%channels];
  168401. }
  168402. break;
  168403. }
  168404. case 16:
  168405. {
  168406. png_bytep bp = row;
  168407. png_uint_32 i;
  168408. png_uint_32 istop = channels * row_width;
  168409. for (i = 0; i < istop; i++)
  168410. {
  168411. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168412. value >>= shift[i%channels];
  168413. *bp++ = (png_byte)(value >> 8);
  168414. *bp++ = (png_byte)(value & 0xff);
  168415. }
  168416. break;
  168417. }
  168418. }
  168419. }
  168420. }
  168421. #endif
  168422. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168423. void /* PRIVATE */
  168424. png_do_chop(png_row_infop row_info, png_bytep row)
  168425. {
  168426. png_debug(1, "in png_do_chop\n");
  168427. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168428. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168429. #else
  168430. if (row_info->bit_depth == 16)
  168431. #endif
  168432. {
  168433. png_bytep sp = row;
  168434. png_bytep dp = row;
  168435. png_uint_32 i;
  168436. png_uint_32 istop = row_info->width * row_info->channels;
  168437. for (i = 0; i<istop; i++, sp += 2, dp++)
  168438. {
  168439. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168440. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168441. #else
  168442. *dp = *sp;
  168443. #endif
  168444. }
  168445. row_info->bit_depth = 8;
  168446. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168447. row_info->rowbytes = row_info->width * row_info->channels;
  168448. }
  168449. }
  168450. #endif
  168451. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168452. void /* PRIVATE */
  168453. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168454. {
  168455. png_debug(1, "in png_do_read_swap_alpha\n");
  168456. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168457. if (row != NULL && row_info != NULL)
  168458. #endif
  168459. {
  168460. png_uint_32 row_width = row_info->width;
  168461. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168462. {
  168463. if (row_info->bit_depth == 8)
  168464. {
  168465. png_bytep sp = row + row_info->rowbytes;
  168466. png_bytep dp = sp;
  168467. png_byte save;
  168468. png_uint_32 i;
  168469. for (i = 0; i < row_width; i++)
  168470. {
  168471. save = *(--sp);
  168472. *(--dp) = *(--sp);
  168473. *(--dp) = *(--sp);
  168474. *(--dp) = *(--sp);
  168475. *(--dp) = save;
  168476. }
  168477. }
  168478. else
  168479. {
  168480. png_bytep sp = row + row_info->rowbytes;
  168481. png_bytep dp = sp;
  168482. png_byte save[2];
  168483. png_uint_32 i;
  168484. for (i = 0; i < row_width; i++)
  168485. {
  168486. save[0] = *(--sp);
  168487. save[1] = *(--sp);
  168488. *(--dp) = *(--sp);
  168489. *(--dp) = *(--sp);
  168490. *(--dp) = *(--sp);
  168491. *(--dp) = *(--sp);
  168492. *(--dp) = *(--sp);
  168493. *(--dp) = *(--sp);
  168494. *(--dp) = save[0];
  168495. *(--dp) = save[1];
  168496. }
  168497. }
  168498. }
  168499. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168500. {
  168501. if (row_info->bit_depth == 8)
  168502. {
  168503. png_bytep sp = row + row_info->rowbytes;
  168504. png_bytep dp = sp;
  168505. png_byte save;
  168506. png_uint_32 i;
  168507. for (i = 0; i < row_width; i++)
  168508. {
  168509. save = *(--sp);
  168510. *(--dp) = *(--sp);
  168511. *(--dp) = save;
  168512. }
  168513. }
  168514. else
  168515. {
  168516. png_bytep sp = row + row_info->rowbytes;
  168517. png_bytep dp = sp;
  168518. png_byte save[2];
  168519. png_uint_32 i;
  168520. for (i = 0; i < row_width; i++)
  168521. {
  168522. save[0] = *(--sp);
  168523. save[1] = *(--sp);
  168524. *(--dp) = *(--sp);
  168525. *(--dp) = *(--sp);
  168526. *(--dp) = save[0];
  168527. *(--dp) = save[1];
  168528. }
  168529. }
  168530. }
  168531. }
  168532. }
  168533. #endif
  168534. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168535. void /* PRIVATE */
  168536. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168537. {
  168538. png_debug(1, "in png_do_read_invert_alpha\n");
  168539. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168540. if (row != NULL && row_info != NULL)
  168541. #endif
  168542. {
  168543. png_uint_32 row_width = row_info->width;
  168544. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168545. {
  168546. if (row_info->bit_depth == 8)
  168547. {
  168548. png_bytep sp = row + row_info->rowbytes;
  168549. png_bytep dp = sp;
  168550. png_uint_32 i;
  168551. for (i = 0; i < row_width; i++)
  168552. {
  168553. *(--dp) = (png_byte)(255 - *(--sp));
  168554. sp-=3;
  168555. dp=sp;
  168556. }
  168557. }
  168558. else
  168559. {
  168560. png_bytep sp = row + row_info->rowbytes;
  168561. png_bytep dp = sp;
  168562. png_uint_32 i;
  168563. for (i = 0; i < row_width; i++)
  168564. {
  168565. *(--dp) = (png_byte)(255 - *(--sp));
  168566. *(--dp) = (png_byte)(255 - *(--sp));
  168567. sp-=6;
  168568. dp=sp;
  168569. }
  168570. }
  168571. }
  168572. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168573. {
  168574. if (row_info->bit_depth == 8)
  168575. {
  168576. png_bytep sp = row + row_info->rowbytes;
  168577. png_bytep dp = sp;
  168578. png_uint_32 i;
  168579. for (i = 0; i < row_width; i++)
  168580. {
  168581. *(--dp) = (png_byte)(255 - *(--sp));
  168582. *(--dp) = *(--sp);
  168583. }
  168584. }
  168585. else
  168586. {
  168587. png_bytep sp = row + row_info->rowbytes;
  168588. png_bytep dp = sp;
  168589. png_uint_32 i;
  168590. for (i = 0; i < row_width; i++)
  168591. {
  168592. *(--dp) = (png_byte)(255 - *(--sp));
  168593. *(--dp) = (png_byte)(255 - *(--sp));
  168594. sp-=2;
  168595. dp=sp;
  168596. }
  168597. }
  168598. }
  168599. }
  168600. }
  168601. #endif
  168602. #if defined(PNG_READ_FILLER_SUPPORTED)
  168603. void /* PRIVATE */
  168604. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168605. png_uint_32 filler, png_uint_32 flags)
  168606. {
  168607. png_uint_32 i;
  168608. png_uint_32 row_width = row_info->width;
  168609. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168610. png_byte lo_filler = (png_byte)(filler & 0xff);
  168611. png_debug(1, "in png_do_read_filler\n");
  168612. if (
  168613. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168614. row != NULL && row_info != NULL &&
  168615. #endif
  168616. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168617. {
  168618. if(row_info->bit_depth == 8)
  168619. {
  168620. if (flags & PNG_FLAG_FILLER_AFTER)
  168621. {
  168622. png_bytep sp = row + (png_size_t)row_width;
  168623. png_bytep dp = sp + (png_size_t)row_width;
  168624. for (i = 1; i < row_width; i++)
  168625. {
  168626. *(--dp) = lo_filler;
  168627. *(--dp) = *(--sp);
  168628. }
  168629. *(--dp) = lo_filler;
  168630. row_info->channels = 2;
  168631. row_info->pixel_depth = 16;
  168632. row_info->rowbytes = row_width * 2;
  168633. }
  168634. else
  168635. {
  168636. png_bytep sp = row + (png_size_t)row_width;
  168637. png_bytep dp = sp + (png_size_t)row_width;
  168638. for (i = 0; i < row_width; i++)
  168639. {
  168640. *(--dp) = *(--sp);
  168641. *(--dp) = lo_filler;
  168642. }
  168643. row_info->channels = 2;
  168644. row_info->pixel_depth = 16;
  168645. row_info->rowbytes = row_width * 2;
  168646. }
  168647. }
  168648. else if(row_info->bit_depth == 16)
  168649. {
  168650. if (flags & PNG_FLAG_FILLER_AFTER)
  168651. {
  168652. png_bytep sp = row + (png_size_t)row_width * 2;
  168653. png_bytep dp = sp + (png_size_t)row_width * 2;
  168654. for (i = 1; i < row_width; i++)
  168655. {
  168656. *(--dp) = hi_filler;
  168657. *(--dp) = lo_filler;
  168658. *(--dp) = *(--sp);
  168659. *(--dp) = *(--sp);
  168660. }
  168661. *(--dp) = hi_filler;
  168662. *(--dp) = lo_filler;
  168663. row_info->channels = 2;
  168664. row_info->pixel_depth = 32;
  168665. row_info->rowbytes = row_width * 4;
  168666. }
  168667. else
  168668. {
  168669. png_bytep sp = row + (png_size_t)row_width * 2;
  168670. png_bytep dp = sp + (png_size_t)row_width * 2;
  168671. for (i = 0; i < row_width; i++)
  168672. {
  168673. *(--dp) = *(--sp);
  168674. *(--dp) = *(--sp);
  168675. *(--dp) = hi_filler;
  168676. *(--dp) = lo_filler;
  168677. }
  168678. row_info->channels = 2;
  168679. row_info->pixel_depth = 32;
  168680. row_info->rowbytes = row_width * 4;
  168681. }
  168682. }
  168683. } /* COLOR_TYPE == GRAY */
  168684. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168685. {
  168686. if(row_info->bit_depth == 8)
  168687. {
  168688. if (flags & PNG_FLAG_FILLER_AFTER)
  168689. {
  168690. png_bytep sp = row + (png_size_t)row_width * 3;
  168691. png_bytep dp = sp + (png_size_t)row_width;
  168692. for (i = 1; i < row_width; i++)
  168693. {
  168694. *(--dp) = lo_filler;
  168695. *(--dp) = *(--sp);
  168696. *(--dp) = *(--sp);
  168697. *(--dp) = *(--sp);
  168698. }
  168699. *(--dp) = lo_filler;
  168700. row_info->channels = 4;
  168701. row_info->pixel_depth = 32;
  168702. row_info->rowbytes = row_width * 4;
  168703. }
  168704. else
  168705. {
  168706. png_bytep sp = row + (png_size_t)row_width * 3;
  168707. png_bytep dp = sp + (png_size_t)row_width;
  168708. for (i = 0; i < row_width; i++)
  168709. {
  168710. *(--dp) = *(--sp);
  168711. *(--dp) = *(--sp);
  168712. *(--dp) = *(--sp);
  168713. *(--dp) = lo_filler;
  168714. }
  168715. row_info->channels = 4;
  168716. row_info->pixel_depth = 32;
  168717. row_info->rowbytes = row_width * 4;
  168718. }
  168719. }
  168720. else if(row_info->bit_depth == 16)
  168721. {
  168722. if (flags & PNG_FLAG_FILLER_AFTER)
  168723. {
  168724. png_bytep sp = row + (png_size_t)row_width * 6;
  168725. png_bytep dp = sp + (png_size_t)row_width * 2;
  168726. for (i = 1; i < row_width; i++)
  168727. {
  168728. *(--dp) = hi_filler;
  168729. *(--dp) = lo_filler;
  168730. *(--dp) = *(--sp);
  168731. *(--dp) = *(--sp);
  168732. *(--dp) = *(--sp);
  168733. *(--dp) = *(--sp);
  168734. *(--dp) = *(--sp);
  168735. *(--dp) = *(--sp);
  168736. }
  168737. *(--dp) = hi_filler;
  168738. *(--dp) = lo_filler;
  168739. row_info->channels = 4;
  168740. row_info->pixel_depth = 64;
  168741. row_info->rowbytes = row_width * 8;
  168742. }
  168743. else
  168744. {
  168745. png_bytep sp = row + (png_size_t)row_width * 6;
  168746. png_bytep dp = sp + (png_size_t)row_width * 2;
  168747. for (i = 0; i < row_width; i++)
  168748. {
  168749. *(--dp) = *(--sp);
  168750. *(--dp) = *(--sp);
  168751. *(--dp) = *(--sp);
  168752. *(--dp) = *(--sp);
  168753. *(--dp) = *(--sp);
  168754. *(--dp) = *(--sp);
  168755. *(--dp) = hi_filler;
  168756. *(--dp) = lo_filler;
  168757. }
  168758. row_info->channels = 4;
  168759. row_info->pixel_depth = 64;
  168760. row_info->rowbytes = row_width * 8;
  168761. }
  168762. }
  168763. } /* COLOR_TYPE == RGB */
  168764. }
  168765. #endif
  168766. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168767. void /* PRIVATE */
  168768. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168769. {
  168770. png_uint_32 i;
  168771. png_uint_32 row_width = row_info->width;
  168772. png_debug(1, "in png_do_gray_to_rgb\n");
  168773. if (row_info->bit_depth >= 8 &&
  168774. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168775. row != NULL && row_info != NULL &&
  168776. #endif
  168777. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168778. {
  168779. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168780. {
  168781. if (row_info->bit_depth == 8)
  168782. {
  168783. png_bytep sp = row + (png_size_t)row_width - 1;
  168784. png_bytep dp = sp + (png_size_t)row_width * 2;
  168785. for (i = 0; i < row_width; i++)
  168786. {
  168787. *(dp--) = *sp;
  168788. *(dp--) = *sp;
  168789. *(dp--) = *(sp--);
  168790. }
  168791. }
  168792. else
  168793. {
  168794. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168795. png_bytep dp = sp + (png_size_t)row_width * 4;
  168796. for (i = 0; i < row_width; i++)
  168797. {
  168798. *(dp--) = *sp;
  168799. *(dp--) = *(sp - 1);
  168800. *(dp--) = *sp;
  168801. *(dp--) = *(sp - 1);
  168802. *(dp--) = *(sp--);
  168803. *(dp--) = *(sp--);
  168804. }
  168805. }
  168806. }
  168807. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168808. {
  168809. if (row_info->bit_depth == 8)
  168810. {
  168811. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168812. png_bytep dp = sp + (png_size_t)row_width * 2;
  168813. for (i = 0; i < row_width; i++)
  168814. {
  168815. *(dp--) = *(sp--);
  168816. *(dp--) = *sp;
  168817. *(dp--) = *sp;
  168818. *(dp--) = *(sp--);
  168819. }
  168820. }
  168821. else
  168822. {
  168823. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168824. png_bytep dp = sp + (png_size_t)row_width * 4;
  168825. for (i = 0; i < row_width; i++)
  168826. {
  168827. *(dp--) = *(sp--);
  168828. *(dp--) = *(sp--);
  168829. *(dp--) = *sp;
  168830. *(dp--) = *(sp - 1);
  168831. *(dp--) = *sp;
  168832. *(dp--) = *(sp - 1);
  168833. *(dp--) = *(sp--);
  168834. *(dp--) = *(sp--);
  168835. }
  168836. }
  168837. }
  168838. row_info->channels += (png_byte)2;
  168839. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168840. row_info->pixel_depth = (png_byte)(row_info->channels *
  168841. row_info->bit_depth);
  168842. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168843. }
  168844. }
  168845. #endif
  168846. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168847. int /* PRIVATE */
  168848. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168849. {
  168850. png_uint_32 i;
  168851. png_uint_32 row_width = row_info->width;
  168852. int rgb_error = 0;
  168853. png_debug(1, "in png_do_rgb_to_gray\n");
  168854. if (
  168855. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168856. row != NULL && row_info != NULL &&
  168857. #endif
  168858. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168859. {
  168860. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168861. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168862. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168863. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168864. {
  168865. if (row_info->bit_depth == 8)
  168866. {
  168867. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168868. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168869. {
  168870. png_bytep sp = row;
  168871. png_bytep dp = row;
  168872. for (i = 0; i < row_width; i++)
  168873. {
  168874. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168875. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168876. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168877. if(red != green || red != blue)
  168878. {
  168879. rgb_error |= 1;
  168880. *(dp++) = png_ptr->gamma_from_1[
  168881. (rc*red+gc*green+bc*blue)>>15];
  168882. }
  168883. else
  168884. *(dp++) = *(sp-1);
  168885. }
  168886. }
  168887. else
  168888. #endif
  168889. {
  168890. png_bytep sp = row;
  168891. png_bytep dp = row;
  168892. for (i = 0; i < row_width; i++)
  168893. {
  168894. png_byte red = *(sp++);
  168895. png_byte green = *(sp++);
  168896. png_byte blue = *(sp++);
  168897. if(red != green || red != blue)
  168898. {
  168899. rgb_error |= 1;
  168900. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168901. }
  168902. else
  168903. *(dp++) = *(sp-1);
  168904. }
  168905. }
  168906. }
  168907. else /* RGB bit_depth == 16 */
  168908. {
  168909. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168910. if (png_ptr->gamma_16_to_1 != NULL &&
  168911. png_ptr->gamma_16_from_1 != NULL)
  168912. {
  168913. png_bytep sp = row;
  168914. png_bytep dp = row;
  168915. for (i = 0; i < row_width; i++)
  168916. {
  168917. png_uint_16 red, green, blue, w;
  168918. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168919. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168920. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168921. if(red == green && red == blue)
  168922. w = red;
  168923. else
  168924. {
  168925. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168926. png_ptr->gamma_shift][red>>8];
  168927. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168928. png_ptr->gamma_shift][green>>8];
  168929. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168930. png_ptr->gamma_shift][blue>>8];
  168931. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168932. + bc*blue_1)>>15);
  168933. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168934. png_ptr->gamma_shift][gray16 >> 8];
  168935. rgb_error |= 1;
  168936. }
  168937. *(dp++) = (png_byte)((w>>8) & 0xff);
  168938. *(dp++) = (png_byte)(w & 0xff);
  168939. }
  168940. }
  168941. else
  168942. #endif
  168943. {
  168944. png_bytep sp = row;
  168945. png_bytep dp = row;
  168946. for (i = 0; i < row_width; i++)
  168947. {
  168948. png_uint_16 red, green, blue, gray16;
  168949. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168950. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168951. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168952. if(red != green || red != blue)
  168953. rgb_error |= 1;
  168954. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168955. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168956. *(dp++) = (png_byte)(gray16 & 0xff);
  168957. }
  168958. }
  168959. }
  168960. }
  168961. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168962. {
  168963. if (row_info->bit_depth == 8)
  168964. {
  168965. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168966. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168967. {
  168968. png_bytep sp = row;
  168969. png_bytep dp = row;
  168970. for (i = 0; i < row_width; i++)
  168971. {
  168972. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168973. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168974. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168975. if(red != green || red != blue)
  168976. rgb_error |= 1;
  168977. *(dp++) = png_ptr->gamma_from_1
  168978. [(rc*red + gc*green + bc*blue)>>15];
  168979. *(dp++) = *(sp++); /* alpha */
  168980. }
  168981. }
  168982. else
  168983. #endif
  168984. {
  168985. png_bytep sp = row;
  168986. png_bytep dp = row;
  168987. for (i = 0; i < row_width; i++)
  168988. {
  168989. png_byte red = *(sp++);
  168990. png_byte green = *(sp++);
  168991. png_byte blue = *(sp++);
  168992. if(red != green || red != blue)
  168993. rgb_error |= 1;
  168994. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  168995. *(dp++) = *(sp++); /* alpha */
  168996. }
  168997. }
  168998. }
  168999. else /* RGBA bit_depth == 16 */
  169000. {
  169001. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169002. if (png_ptr->gamma_16_to_1 != NULL &&
  169003. png_ptr->gamma_16_from_1 != NULL)
  169004. {
  169005. png_bytep sp = row;
  169006. png_bytep dp = row;
  169007. for (i = 0; i < row_width; i++)
  169008. {
  169009. png_uint_16 red, green, blue, w;
  169010. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169011. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169012. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169013. if(red == green && red == blue)
  169014. w = red;
  169015. else
  169016. {
  169017. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169018. png_ptr->gamma_shift][red>>8];
  169019. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169020. png_ptr->gamma_shift][green>>8];
  169021. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169022. png_ptr->gamma_shift][blue>>8];
  169023. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  169024. + gc * green_1 + bc * blue_1)>>15);
  169025. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169026. png_ptr->gamma_shift][gray16 >> 8];
  169027. rgb_error |= 1;
  169028. }
  169029. *(dp++) = (png_byte)((w>>8) & 0xff);
  169030. *(dp++) = (png_byte)(w & 0xff);
  169031. *(dp++) = *(sp++); /* alpha */
  169032. *(dp++) = *(sp++);
  169033. }
  169034. }
  169035. else
  169036. #endif
  169037. {
  169038. png_bytep sp = row;
  169039. png_bytep dp = row;
  169040. for (i = 0; i < row_width; i++)
  169041. {
  169042. png_uint_16 red, green, blue, gray16;
  169043. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169044. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169045. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169046. if(red != green || red != blue)
  169047. rgb_error |= 1;
  169048. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169049. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169050. *(dp++) = (png_byte)(gray16 & 0xff);
  169051. *(dp++) = *(sp++); /* alpha */
  169052. *(dp++) = *(sp++);
  169053. }
  169054. }
  169055. }
  169056. }
  169057. row_info->channels -= (png_byte)2;
  169058. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169059. row_info->pixel_depth = (png_byte)(row_info->channels *
  169060. row_info->bit_depth);
  169061. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169062. }
  169063. return rgb_error;
  169064. }
  169065. #endif
  169066. void PNGAPI
  169067. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169068. {
  169069. int num_palette;
  169070. int color_inc;
  169071. int i;
  169072. int v;
  169073. png_debug(1, "in png_do_build_grayscale_palette\n");
  169074. if (palette == NULL)
  169075. return;
  169076. switch (bit_depth)
  169077. {
  169078. case 1:
  169079. num_palette = 2;
  169080. color_inc = 0xff;
  169081. break;
  169082. case 2:
  169083. num_palette = 4;
  169084. color_inc = 0x55;
  169085. break;
  169086. case 4:
  169087. num_palette = 16;
  169088. color_inc = 0x11;
  169089. break;
  169090. case 8:
  169091. num_palette = 256;
  169092. color_inc = 1;
  169093. break;
  169094. default:
  169095. num_palette = 0;
  169096. color_inc = 0;
  169097. break;
  169098. }
  169099. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169100. {
  169101. palette[i].red = (png_byte)v;
  169102. palette[i].green = (png_byte)v;
  169103. palette[i].blue = (png_byte)v;
  169104. }
  169105. }
  169106. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169107. void /* PRIVATE */
  169108. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169109. int num_palette)
  169110. {
  169111. png_debug(1, "in png_correct_palette\n");
  169112. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169113. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169114. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169115. {
  169116. png_color back, back_1;
  169117. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169118. {
  169119. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169120. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169121. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169122. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169123. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169124. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169125. }
  169126. else
  169127. {
  169128. double g;
  169129. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169130. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169131. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169132. {
  169133. back.red = png_ptr->background.red;
  169134. back.green = png_ptr->background.green;
  169135. back.blue = png_ptr->background.blue;
  169136. }
  169137. else
  169138. {
  169139. back.red =
  169140. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169141. 255.0 + 0.5);
  169142. back.green =
  169143. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169144. 255.0 + 0.5);
  169145. back.blue =
  169146. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169147. 255.0 + 0.5);
  169148. }
  169149. g = 1.0 / png_ptr->background_gamma;
  169150. back_1.red =
  169151. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169152. 255.0 + 0.5);
  169153. back_1.green =
  169154. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169155. 255.0 + 0.5);
  169156. back_1.blue =
  169157. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169158. 255.0 + 0.5);
  169159. }
  169160. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169161. {
  169162. png_uint_32 i;
  169163. for (i = 0; i < (png_uint_32)num_palette; i++)
  169164. {
  169165. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169166. {
  169167. palette[i] = back;
  169168. }
  169169. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169170. {
  169171. png_byte v, w;
  169172. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169173. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169174. palette[i].red = png_ptr->gamma_from_1[w];
  169175. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169176. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169177. palette[i].green = png_ptr->gamma_from_1[w];
  169178. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169179. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169180. palette[i].blue = png_ptr->gamma_from_1[w];
  169181. }
  169182. else
  169183. {
  169184. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169185. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169186. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169187. }
  169188. }
  169189. }
  169190. else
  169191. {
  169192. int i;
  169193. for (i = 0; i < num_palette; i++)
  169194. {
  169195. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169196. {
  169197. palette[i] = back;
  169198. }
  169199. else
  169200. {
  169201. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169202. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169203. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169204. }
  169205. }
  169206. }
  169207. }
  169208. else
  169209. #endif
  169210. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169211. if (png_ptr->transformations & PNG_GAMMA)
  169212. {
  169213. int i;
  169214. for (i = 0; i < num_palette; i++)
  169215. {
  169216. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169217. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169218. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169219. }
  169220. }
  169221. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169222. else
  169223. #endif
  169224. #endif
  169225. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169226. if (png_ptr->transformations & PNG_BACKGROUND)
  169227. {
  169228. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169229. {
  169230. png_color back;
  169231. back.red = (png_byte)png_ptr->background.red;
  169232. back.green = (png_byte)png_ptr->background.green;
  169233. back.blue = (png_byte)png_ptr->background.blue;
  169234. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169235. {
  169236. if (png_ptr->trans[i] == 0)
  169237. {
  169238. palette[i].red = back.red;
  169239. palette[i].green = back.green;
  169240. palette[i].blue = back.blue;
  169241. }
  169242. else if (png_ptr->trans[i] != 0xff)
  169243. {
  169244. png_composite(palette[i].red, png_ptr->palette[i].red,
  169245. png_ptr->trans[i], back.red);
  169246. png_composite(palette[i].green, png_ptr->palette[i].green,
  169247. png_ptr->trans[i], back.green);
  169248. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169249. png_ptr->trans[i], back.blue);
  169250. }
  169251. }
  169252. }
  169253. else /* assume grayscale palette (what else could it be?) */
  169254. {
  169255. int i;
  169256. for (i = 0; i < num_palette; i++)
  169257. {
  169258. if (i == (png_byte)png_ptr->trans_values.gray)
  169259. {
  169260. palette[i].red = (png_byte)png_ptr->background.red;
  169261. palette[i].green = (png_byte)png_ptr->background.green;
  169262. palette[i].blue = (png_byte)png_ptr->background.blue;
  169263. }
  169264. }
  169265. }
  169266. }
  169267. #endif
  169268. }
  169269. #endif
  169270. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169271. void /* PRIVATE */
  169272. png_do_background(png_row_infop row_info, png_bytep row,
  169273. png_color_16p trans_values, png_color_16p background
  169274. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169275. , png_color_16p background_1,
  169276. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169277. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169278. png_uint_16pp gamma_16_to_1, int gamma_shift
  169279. #endif
  169280. )
  169281. {
  169282. png_bytep sp, dp;
  169283. png_uint_32 i;
  169284. png_uint_32 row_width=row_info->width;
  169285. int shift;
  169286. png_debug(1, "in png_do_background\n");
  169287. if (background != NULL &&
  169288. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169289. row != NULL && row_info != NULL &&
  169290. #endif
  169291. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169292. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169293. {
  169294. switch (row_info->color_type)
  169295. {
  169296. case PNG_COLOR_TYPE_GRAY:
  169297. {
  169298. switch (row_info->bit_depth)
  169299. {
  169300. case 1:
  169301. {
  169302. sp = row;
  169303. shift = 7;
  169304. for (i = 0; i < row_width; i++)
  169305. {
  169306. if ((png_uint_16)((*sp >> shift) & 0x01)
  169307. == trans_values->gray)
  169308. {
  169309. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169310. *sp |= (png_byte)(background->gray << shift);
  169311. }
  169312. if (!shift)
  169313. {
  169314. shift = 7;
  169315. sp++;
  169316. }
  169317. else
  169318. shift--;
  169319. }
  169320. break;
  169321. }
  169322. case 2:
  169323. {
  169324. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169325. if (gamma_table != NULL)
  169326. {
  169327. sp = row;
  169328. shift = 6;
  169329. for (i = 0; i < row_width; i++)
  169330. {
  169331. if ((png_uint_16)((*sp >> shift) & 0x03)
  169332. == trans_values->gray)
  169333. {
  169334. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169335. *sp |= (png_byte)(background->gray << shift);
  169336. }
  169337. else
  169338. {
  169339. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169340. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169341. (p << 4) | (p << 6)] >> 6) & 0x03);
  169342. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169343. *sp |= (png_byte)(g << shift);
  169344. }
  169345. if (!shift)
  169346. {
  169347. shift = 6;
  169348. sp++;
  169349. }
  169350. else
  169351. shift -= 2;
  169352. }
  169353. }
  169354. else
  169355. #endif
  169356. {
  169357. sp = row;
  169358. shift = 6;
  169359. for (i = 0; i < row_width; i++)
  169360. {
  169361. if ((png_uint_16)((*sp >> shift) & 0x03)
  169362. == trans_values->gray)
  169363. {
  169364. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169365. *sp |= (png_byte)(background->gray << shift);
  169366. }
  169367. if (!shift)
  169368. {
  169369. shift = 6;
  169370. sp++;
  169371. }
  169372. else
  169373. shift -= 2;
  169374. }
  169375. }
  169376. break;
  169377. }
  169378. case 4:
  169379. {
  169380. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169381. if (gamma_table != NULL)
  169382. {
  169383. sp = row;
  169384. shift = 4;
  169385. for (i = 0; i < row_width; i++)
  169386. {
  169387. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169388. == trans_values->gray)
  169389. {
  169390. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169391. *sp |= (png_byte)(background->gray << shift);
  169392. }
  169393. else
  169394. {
  169395. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169396. png_byte g = (png_byte)((gamma_table[p |
  169397. (p << 4)] >> 4) & 0x0f);
  169398. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169399. *sp |= (png_byte)(g << shift);
  169400. }
  169401. if (!shift)
  169402. {
  169403. shift = 4;
  169404. sp++;
  169405. }
  169406. else
  169407. shift -= 4;
  169408. }
  169409. }
  169410. else
  169411. #endif
  169412. {
  169413. sp = row;
  169414. shift = 4;
  169415. for (i = 0; i < row_width; i++)
  169416. {
  169417. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169418. == trans_values->gray)
  169419. {
  169420. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169421. *sp |= (png_byte)(background->gray << shift);
  169422. }
  169423. if (!shift)
  169424. {
  169425. shift = 4;
  169426. sp++;
  169427. }
  169428. else
  169429. shift -= 4;
  169430. }
  169431. }
  169432. break;
  169433. }
  169434. case 8:
  169435. {
  169436. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169437. if (gamma_table != NULL)
  169438. {
  169439. sp = row;
  169440. for (i = 0; i < row_width; i++, sp++)
  169441. {
  169442. if (*sp == trans_values->gray)
  169443. {
  169444. *sp = (png_byte)background->gray;
  169445. }
  169446. else
  169447. {
  169448. *sp = gamma_table[*sp];
  169449. }
  169450. }
  169451. }
  169452. else
  169453. #endif
  169454. {
  169455. sp = row;
  169456. for (i = 0; i < row_width; i++, sp++)
  169457. {
  169458. if (*sp == trans_values->gray)
  169459. {
  169460. *sp = (png_byte)background->gray;
  169461. }
  169462. }
  169463. }
  169464. break;
  169465. }
  169466. case 16:
  169467. {
  169468. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169469. if (gamma_16 != NULL)
  169470. {
  169471. sp = row;
  169472. for (i = 0; i < row_width; i++, sp += 2)
  169473. {
  169474. png_uint_16 v;
  169475. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169476. if (v == trans_values->gray)
  169477. {
  169478. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169479. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169480. }
  169481. else
  169482. {
  169483. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169484. *sp = (png_byte)((v >> 8) & 0xff);
  169485. *(sp + 1) = (png_byte)(v & 0xff);
  169486. }
  169487. }
  169488. }
  169489. else
  169490. #endif
  169491. {
  169492. sp = row;
  169493. for (i = 0; i < row_width; i++, sp += 2)
  169494. {
  169495. png_uint_16 v;
  169496. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169497. if (v == trans_values->gray)
  169498. {
  169499. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169500. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169501. }
  169502. }
  169503. }
  169504. break;
  169505. }
  169506. }
  169507. break;
  169508. }
  169509. case PNG_COLOR_TYPE_RGB:
  169510. {
  169511. if (row_info->bit_depth == 8)
  169512. {
  169513. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169514. if (gamma_table != NULL)
  169515. {
  169516. sp = row;
  169517. for (i = 0; i < row_width; i++, sp += 3)
  169518. {
  169519. if (*sp == trans_values->red &&
  169520. *(sp + 1) == trans_values->green &&
  169521. *(sp + 2) == trans_values->blue)
  169522. {
  169523. *sp = (png_byte)background->red;
  169524. *(sp + 1) = (png_byte)background->green;
  169525. *(sp + 2) = (png_byte)background->blue;
  169526. }
  169527. else
  169528. {
  169529. *sp = gamma_table[*sp];
  169530. *(sp + 1) = gamma_table[*(sp + 1)];
  169531. *(sp + 2) = gamma_table[*(sp + 2)];
  169532. }
  169533. }
  169534. }
  169535. else
  169536. #endif
  169537. {
  169538. sp = row;
  169539. for (i = 0; i < row_width; i++, sp += 3)
  169540. {
  169541. if (*sp == trans_values->red &&
  169542. *(sp + 1) == trans_values->green &&
  169543. *(sp + 2) == trans_values->blue)
  169544. {
  169545. *sp = (png_byte)background->red;
  169546. *(sp + 1) = (png_byte)background->green;
  169547. *(sp + 2) = (png_byte)background->blue;
  169548. }
  169549. }
  169550. }
  169551. }
  169552. else /* if (row_info->bit_depth == 16) */
  169553. {
  169554. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169555. if (gamma_16 != NULL)
  169556. {
  169557. sp = row;
  169558. for (i = 0; i < row_width; i++, sp += 6)
  169559. {
  169560. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169561. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169562. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169563. if (r == trans_values->red && g == trans_values->green &&
  169564. b == trans_values->blue)
  169565. {
  169566. *sp = (png_byte)((background->red >> 8) & 0xff);
  169567. *(sp + 1) = (png_byte)(background->red & 0xff);
  169568. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169569. *(sp + 3) = (png_byte)(background->green & 0xff);
  169570. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169571. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169572. }
  169573. else
  169574. {
  169575. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169576. *sp = (png_byte)((v >> 8) & 0xff);
  169577. *(sp + 1) = (png_byte)(v & 0xff);
  169578. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169579. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169580. *(sp + 3) = (png_byte)(v & 0xff);
  169581. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169582. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169583. *(sp + 5) = (png_byte)(v & 0xff);
  169584. }
  169585. }
  169586. }
  169587. else
  169588. #endif
  169589. {
  169590. sp = row;
  169591. for (i = 0; i < row_width; i++, sp += 6)
  169592. {
  169593. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169594. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169595. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169596. if (r == trans_values->red && g == trans_values->green &&
  169597. b == trans_values->blue)
  169598. {
  169599. *sp = (png_byte)((background->red >> 8) & 0xff);
  169600. *(sp + 1) = (png_byte)(background->red & 0xff);
  169601. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169602. *(sp + 3) = (png_byte)(background->green & 0xff);
  169603. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169604. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169605. }
  169606. }
  169607. }
  169608. }
  169609. break;
  169610. }
  169611. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169612. {
  169613. if (row_info->bit_depth == 8)
  169614. {
  169615. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169616. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169617. gamma_table != NULL)
  169618. {
  169619. sp = row;
  169620. dp = row;
  169621. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169622. {
  169623. png_uint_16 a = *(sp + 1);
  169624. if (a == 0xff)
  169625. {
  169626. *dp = gamma_table[*sp];
  169627. }
  169628. else if (a == 0)
  169629. {
  169630. *dp = (png_byte)background->gray;
  169631. }
  169632. else
  169633. {
  169634. png_byte v, w;
  169635. v = gamma_to_1[*sp];
  169636. png_composite(w, v, a, background_1->gray);
  169637. *dp = gamma_from_1[w];
  169638. }
  169639. }
  169640. }
  169641. else
  169642. #endif
  169643. {
  169644. sp = row;
  169645. dp = row;
  169646. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169647. {
  169648. png_byte a = *(sp + 1);
  169649. if (a == 0xff)
  169650. {
  169651. *dp = *sp;
  169652. }
  169653. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169654. else if (a == 0)
  169655. {
  169656. *dp = (png_byte)background->gray;
  169657. }
  169658. else
  169659. {
  169660. png_composite(*dp, *sp, a, background_1->gray);
  169661. }
  169662. #else
  169663. *dp = (png_byte)background->gray;
  169664. #endif
  169665. }
  169666. }
  169667. }
  169668. else /* if (png_ptr->bit_depth == 16) */
  169669. {
  169670. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169671. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169672. gamma_16_to_1 != NULL)
  169673. {
  169674. sp = row;
  169675. dp = row;
  169676. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169677. {
  169678. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169679. if (a == (png_uint_16)0xffff)
  169680. {
  169681. png_uint_16 v;
  169682. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169683. *dp = (png_byte)((v >> 8) & 0xff);
  169684. *(dp + 1) = (png_byte)(v & 0xff);
  169685. }
  169686. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169687. else if (a == 0)
  169688. #else
  169689. else
  169690. #endif
  169691. {
  169692. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169693. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169694. }
  169695. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169696. else
  169697. {
  169698. png_uint_16 g, v, w;
  169699. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169700. png_composite_16(v, g, a, background_1->gray);
  169701. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169702. *dp = (png_byte)((w >> 8) & 0xff);
  169703. *(dp + 1) = (png_byte)(w & 0xff);
  169704. }
  169705. #endif
  169706. }
  169707. }
  169708. else
  169709. #endif
  169710. {
  169711. sp = row;
  169712. dp = row;
  169713. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169714. {
  169715. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169716. if (a == (png_uint_16)0xffff)
  169717. {
  169718. png_memcpy(dp, sp, 2);
  169719. }
  169720. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169721. else if (a == 0)
  169722. #else
  169723. else
  169724. #endif
  169725. {
  169726. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169727. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169728. }
  169729. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169730. else
  169731. {
  169732. png_uint_16 g, v;
  169733. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169734. png_composite_16(v, g, a, background_1->gray);
  169735. *dp = (png_byte)((v >> 8) & 0xff);
  169736. *(dp + 1) = (png_byte)(v & 0xff);
  169737. }
  169738. #endif
  169739. }
  169740. }
  169741. }
  169742. break;
  169743. }
  169744. case PNG_COLOR_TYPE_RGB_ALPHA:
  169745. {
  169746. if (row_info->bit_depth == 8)
  169747. {
  169748. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169749. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169750. gamma_table != NULL)
  169751. {
  169752. sp = row;
  169753. dp = row;
  169754. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169755. {
  169756. png_byte a = *(sp + 3);
  169757. if (a == 0xff)
  169758. {
  169759. *dp = gamma_table[*sp];
  169760. *(dp + 1) = gamma_table[*(sp + 1)];
  169761. *(dp + 2) = gamma_table[*(sp + 2)];
  169762. }
  169763. else if (a == 0)
  169764. {
  169765. *dp = (png_byte)background->red;
  169766. *(dp + 1) = (png_byte)background->green;
  169767. *(dp + 2) = (png_byte)background->blue;
  169768. }
  169769. else
  169770. {
  169771. png_byte v, w;
  169772. v = gamma_to_1[*sp];
  169773. png_composite(w, v, a, background_1->red);
  169774. *dp = gamma_from_1[w];
  169775. v = gamma_to_1[*(sp + 1)];
  169776. png_composite(w, v, a, background_1->green);
  169777. *(dp + 1) = gamma_from_1[w];
  169778. v = gamma_to_1[*(sp + 2)];
  169779. png_composite(w, v, a, background_1->blue);
  169780. *(dp + 2) = gamma_from_1[w];
  169781. }
  169782. }
  169783. }
  169784. else
  169785. #endif
  169786. {
  169787. sp = row;
  169788. dp = row;
  169789. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169790. {
  169791. png_byte a = *(sp + 3);
  169792. if (a == 0xff)
  169793. {
  169794. *dp = *sp;
  169795. *(dp + 1) = *(sp + 1);
  169796. *(dp + 2) = *(sp + 2);
  169797. }
  169798. else if (a == 0)
  169799. {
  169800. *dp = (png_byte)background->red;
  169801. *(dp + 1) = (png_byte)background->green;
  169802. *(dp + 2) = (png_byte)background->blue;
  169803. }
  169804. else
  169805. {
  169806. png_composite(*dp, *sp, a, background->red);
  169807. png_composite(*(dp + 1), *(sp + 1), a,
  169808. background->green);
  169809. png_composite(*(dp + 2), *(sp + 2), a,
  169810. background->blue);
  169811. }
  169812. }
  169813. }
  169814. }
  169815. else /* if (row_info->bit_depth == 16) */
  169816. {
  169817. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169818. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169819. gamma_16_to_1 != NULL)
  169820. {
  169821. sp = row;
  169822. dp = row;
  169823. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169824. {
  169825. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169826. << 8) + (png_uint_16)(*(sp + 7)));
  169827. if (a == (png_uint_16)0xffff)
  169828. {
  169829. png_uint_16 v;
  169830. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169831. *dp = (png_byte)((v >> 8) & 0xff);
  169832. *(dp + 1) = (png_byte)(v & 0xff);
  169833. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169834. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169835. *(dp + 3) = (png_byte)(v & 0xff);
  169836. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169837. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169838. *(dp + 5) = (png_byte)(v & 0xff);
  169839. }
  169840. else if (a == 0)
  169841. {
  169842. *dp = (png_byte)((background->red >> 8) & 0xff);
  169843. *(dp + 1) = (png_byte)(background->red & 0xff);
  169844. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169845. *(dp + 3) = (png_byte)(background->green & 0xff);
  169846. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169847. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169848. }
  169849. else
  169850. {
  169851. png_uint_16 v, w, x;
  169852. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169853. png_composite_16(w, v, a, background_1->red);
  169854. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169855. *dp = (png_byte)((x >> 8) & 0xff);
  169856. *(dp + 1) = (png_byte)(x & 0xff);
  169857. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169858. png_composite_16(w, v, a, background_1->green);
  169859. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169860. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169861. *(dp + 3) = (png_byte)(x & 0xff);
  169862. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169863. png_composite_16(w, v, a, background_1->blue);
  169864. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169865. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169866. *(dp + 5) = (png_byte)(x & 0xff);
  169867. }
  169868. }
  169869. }
  169870. else
  169871. #endif
  169872. {
  169873. sp = row;
  169874. dp = row;
  169875. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169876. {
  169877. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169878. << 8) + (png_uint_16)(*(sp + 7)));
  169879. if (a == (png_uint_16)0xffff)
  169880. {
  169881. png_memcpy(dp, sp, 6);
  169882. }
  169883. else if (a == 0)
  169884. {
  169885. *dp = (png_byte)((background->red >> 8) & 0xff);
  169886. *(dp + 1) = (png_byte)(background->red & 0xff);
  169887. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169888. *(dp + 3) = (png_byte)(background->green & 0xff);
  169889. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169890. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169891. }
  169892. else
  169893. {
  169894. png_uint_16 v;
  169895. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169896. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169897. + *(sp + 3));
  169898. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169899. + *(sp + 5));
  169900. png_composite_16(v, r, a, background->red);
  169901. *dp = (png_byte)((v >> 8) & 0xff);
  169902. *(dp + 1) = (png_byte)(v & 0xff);
  169903. png_composite_16(v, g, a, background->green);
  169904. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169905. *(dp + 3) = (png_byte)(v & 0xff);
  169906. png_composite_16(v, b, a, background->blue);
  169907. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169908. *(dp + 5) = (png_byte)(v & 0xff);
  169909. }
  169910. }
  169911. }
  169912. }
  169913. break;
  169914. }
  169915. }
  169916. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169917. {
  169918. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169919. row_info->channels--;
  169920. row_info->pixel_depth = (png_byte)(row_info->channels *
  169921. row_info->bit_depth);
  169922. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169923. }
  169924. }
  169925. }
  169926. #endif
  169927. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169928. void /* PRIVATE */
  169929. png_do_gamma(png_row_infop row_info, png_bytep row,
  169930. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169931. int gamma_shift)
  169932. {
  169933. png_bytep sp;
  169934. png_uint_32 i;
  169935. png_uint_32 row_width=row_info->width;
  169936. png_debug(1, "in png_do_gamma\n");
  169937. if (
  169938. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169939. row != NULL && row_info != NULL &&
  169940. #endif
  169941. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169942. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169943. {
  169944. switch (row_info->color_type)
  169945. {
  169946. case PNG_COLOR_TYPE_RGB:
  169947. {
  169948. if (row_info->bit_depth == 8)
  169949. {
  169950. sp = row;
  169951. for (i = 0; i < row_width; i++)
  169952. {
  169953. *sp = gamma_table[*sp];
  169954. sp++;
  169955. *sp = gamma_table[*sp];
  169956. sp++;
  169957. *sp = gamma_table[*sp];
  169958. sp++;
  169959. }
  169960. }
  169961. else /* if (row_info->bit_depth == 16) */
  169962. {
  169963. sp = row;
  169964. for (i = 0; i < row_width; i++)
  169965. {
  169966. png_uint_16 v;
  169967. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169968. *sp = (png_byte)((v >> 8) & 0xff);
  169969. *(sp + 1) = (png_byte)(v & 0xff);
  169970. sp += 2;
  169971. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169972. *sp = (png_byte)((v >> 8) & 0xff);
  169973. *(sp + 1) = (png_byte)(v & 0xff);
  169974. sp += 2;
  169975. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169976. *sp = (png_byte)((v >> 8) & 0xff);
  169977. *(sp + 1) = (png_byte)(v & 0xff);
  169978. sp += 2;
  169979. }
  169980. }
  169981. break;
  169982. }
  169983. case PNG_COLOR_TYPE_RGB_ALPHA:
  169984. {
  169985. if (row_info->bit_depth == 8)
  169986. {
  169987. sp = row;
  169988. for (i = 0; i < row_width; i++)
  169989. {
  169990. *sp = gamma_table[*sp];
  169991. sp++;
  169992. *sp = gamma_table[*sp];
  169993. sp++;
  169994. *sp = gamma_table[*sp];
  169995. sp++;
  169996. sp++;
  169997. }
  169998. }
  169999. else /* if (row_info->bit_depth == 16) */
  170000. {
  170001. sp = row;
  170002. for (i = 0; i < row_width; i++)
  170003. {
  170004. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170005. *sp = (png_byte)((v >> 8) & 0xff);
  170006. *(sp + 1) = (png_byte)(v & 0xff);
  170007. sp += 2;
  170008. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170009. *sp = (png_byte)((v >> 8) & 0xff);
  170010. *(sp + 1) = (png_byte)(v & 0xff);
  170011. sp += 2;
  170012. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170013. *sp = (png_byte)((v >> 8) & 0xff);
  170014. *(sp + 1) = (png_byte)(v & 0xff);
  170015. sp += 4;
  170016. }
  170017. }
  170018. break;
  170019. }
  170020. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170021. {
  170022. if (row_info->bit_depth == 8)
  170023. {
  170024. sp = row;
  170025. for (i = 0; i < row_width; i++)
  170026. {
  170027. *sp = gamma_table[*sp];
  170028. sp += 2;
  170029. }
  170030. }
  170031. else /* if (row_info->bit_depth == 16) */
  170032. {
  170033. sp = row;
  170034. for (i = 0; i < row_width; i++)
  170035. {
  170036. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170037. *sp = (png_byte)((v >> 8) & 0xff);
  170038. *(sp + 1) = (png_byte)(v & 0xff);
  170039. sp += 4;
  170040. }
  170041. }
  170042. break;
  170043. }
  170044. case PNG_COLOR_TYPE_GRAY:
  170045. {
  170046. if (row_info->bit_depth == 2)
  170047. {
  170048. sp = row;
  170049. for (i = 0; i < row_width; i += 4)
  170050. {
  170051. int a = *sp & 0xc0;
  170052. int b = *sp & 0x30;
  170053. int c = *sp & 0x0c;
  170054. int d = *sp & 0x03;
  170055. *sp = (png_byte)(
  170056. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170057. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170058. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170059. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170060. sp++;
  170061. }
  170062. }
  170063. if (row_info->bit_depth == 4)
  170064. {
  170065. sp = row;
  170066. for (i = 0; i < row_width; i += 2)
  170067. {
  170068. int msb = *sp & 0xf0;
  170069. int lsb = *sp & 0x0f;
  170070. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170071. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170072. sp++;
  170073. }
  170074. }
  170075. else if (row_info->bit_depth == 8)
  170076. {
  170077. sp = row;
  170078. for (i = 0; i < row_width; i++)
  170079. {
  170080. *sp = gamma_table[*sp];
  170081. sp++;
  170082. }
  170083. }
  170084. else if (row_info->bit_depth == 16)
  170085. {
  170086. sp = row;
  170087. for (i = 0; i < row_width; i++)
  170088. {
  170089. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170090. *sp = (png_byte)((v >> 8) & 0xff);
  170091. *(sp + 1) = (png_byte)(v & 0xff);
  170092. sp += 2;
  170093. }
  170094. }
  170095. break;
  170096. }
  170097. }
  170098. }
  170099. }
  170100. #endif
  170101. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170102. void /* PRIVATE */
  170103. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170104. png_colorp palette, png_bytep trans, int num_trans)
  170105. {
  170106. int shift, value;
  170107. png_bytep sp, dp;
  170108. png_uint_32 i;
  170109. png_uint_32 row_width=row_info->width;
  170110. png_debug(1, "in png_do_expand_palette\n");
  170111. if (
  170112. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170113. row != NULL && row_info != NULL &&
  170114. #endif
  170115. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170116. {
  170117. if (row_info->bit_depth < 8)
  170118. {
  170119. switch (row_info->bit_depth)
  170120. {
  170121. case 1:
  170122. {
  170123. sp = row + (png_size_t)((row_width - 1) >> 3);
  170124. dp = row + (png_size_t)row_width - 1;
  170125. shift = 7 - (int)((row_width + 7) & 0x07);
  170126. for (i = 0; i < row_width; i++)
  170127. {
  170128. if ((*sp >> shift) & 0x01)
  170129. *dp = 1;
  170130. else
  170131. *dp = 0;
  170132. if (shift == 7)
  170133. {
  170134. shift = 0;
  170135. sp--;
  170136. }
  170137. else
  170138. shift++;
  170139. dp--;
  170140. }
  170141. break;
  170142. }
  170143. case 2:
  170144. {
  170145. sp = row + (png_size_t)((row_width - 1) >> 2);
  170146. dp = row + (png_size_t)row_width - 1;
  170147. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170148. for (i = 0; i < row_width; i++)
  170149. {
  170150. value = (*sp >> shift) & 0x03;
  170151. *dp = (png_byte)value;
  170152. if (shift == 6)
  170153. {
  170154. shift = 0;
  170155. sp--;
  170156. }
  170157. else
  170158. shift += 2;
  170159. dp--;
  170160. }
  170161. break;
  170162. }
  170163. case 4:
  170164. {
  170165. sp = row + (png_size_t)((row_width - 1) >> 1);
  170166. dp = row + (png_size_t)row_width - 1;
  170167. shift = (int)((row_width & 0x01) << 2);
  170168. for (i = 0; i < row_width; i++)
  170169. {
  170170. value = (*sp >> shift) & 0x0f;
  170171. *dp = (png_byte)value;
  170172. if (shift == 4)
  170173. {
  170174. shift = 0;
  170175. sp--;
  170176. }
  170177. else
  170178. shift += 4;
  170179. dp--;
  170180. }
  170181. break;
  170182. }
  170183. }
  170184. row_info->bit_depth = 8;
  170185. row_info->pixel_depth = 8;
  170186. row_info->rowbytes = row_width;
  170187. }
  170188. switch (row_info->bit_depth)
  170189. {
  170190. case 8:
  170191. {
  170192. if (trans != NULL)
  170193. {
  170194. sp = row + (png_size_t)row_width - 1;
  170195. dp = row + (png_size_t)(row_width << 2) - 1;
  170196. for (i = 0; i < row_width; i++)
  170197. {
  170198. if ((int)(*sp) >= num_trans)
  170199. *dp-- = 0xff;
  170200. else
  170201. *dp-- = trans[*sp];
  170202. *dp-- = palette[*sp].blue;
  170203. *dp-- = palette[*sp].green;
  170204. *dp-- = palette[*sp].red;
  170205. sp--;
  170206. }
  170207. row_info->bit_depth = 8;
  170208. row_info->pixel_depth = 32;
  170209. row_info->rowbytes = row_width * 4;
  170210. row_info->color_type = 6;
  170211. row_info->channels = 4;
  170212. }
  170213. else
  170214. {
  170215. sp = row + (png_size_t)row_width - 1;
  170216. dp = row + (png_size_t)(row_width * 3) - 1;
  170217. for (i = 0; i < row_width; i++)
  170218. {
  170219. *dp-- = palette[*sp].blue;
  170220. *dp-- = palette[*sp].green;
  170221. *dp-- = palette[*sp].red;
  170222. sp--;
  170223. }
  170224. row_info->bit_depth = 8;
  170225. row_info->pixel_depth = 24;
  170226. row_info->rowbytes = row_width * 3;
  170227. row_info->color_type = 2;
  170228. row_info->channels = 3;
  170229. }
  170230. break;
  170231. }
  170232. }
  170233. }
  170234. }
  170235. void /* PRIVATE */
  170236. png_do_expand(png_row_infop row_info, png_bytep row,
  170237. png_color_16p trans_value)
  170238. {
  170239. int shift, value;
  170240. png_bytep sp, dp;
  170241. png_uint_32 i;
  170242. png_uint_32 row_width=row_info->width;
  170243. png_debug(1, "in png_do_expand\n");
  170244. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170245. if (row != NULL && row_info != NULL)
  170246. #endif
  170247. {
  170248. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170249. {
  170250. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170251. if (row_info->bit_depth < 8)
  170252. {
  170253. switch (row_info->bit_depth)
  170254. {
  170255. case 1:
  170256. {
  170257. gray = (png_uint_16)((gray&0x01)*0xff);
  170258. sp = row + (png_size_t)((row_width - 1) >> 3);
  170259. dp = row + (png_size_t)row_width - 1;
  170260. shift = 7 - (int)((row_width + 7) & 0x07);
  170261. for (i = 0; i < row_width; i++)
  170262. {
  170263. if ((*sp >> shift) & 0x01)
  170264. *dp = 0xff;
  170265. else
  170266. *dp = 0;
  170267. if (shift == 7)
  170268. {
  170269. shift = 0;
  170270. sp--;
  170271. }
  170272. else
  170273. shift++;
  170274. dp--;
  170275. }
  170276. break;
  170277. }
  170278. case 2:
  170279. {
  170280. gray = (png_uint_16)((gray&0x03)*0x55);
  170281. sp = row + (png_size_t)((row_width - 1) >> 2);
  170282. dp = row + (png_size_t)row_width - 1;
  170283. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170284. for (i = 0; i < row_width; i++)
  170285. {
  170286. value = (*sp >> shift) & 0x03;
  170287. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170288. (value << 6));
  170289. if (shift == 6)
  170290. {
  170291. shift = 0;
  170292. sp--;
  170293. }
  170294. else
  170295. shift += 2;
  170296. dp--;
  170297. }
  170298. break;
  170299. }
  170300. case 4:
  170301. {
  170302. gray = (png_uint_16)((gray&0x0f)*0x11);
  170303. sp = row + (png_size_t)((row_width - 1) >> 1);
  170304. dp = row + (png_size_t)row_width - 1;
  170305. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170306. for (i = 0; i < row_width; i++)
  170307. {
  170308. value = (*sp >> shift) & 0x0f;
  170309. *dp = (png_byte)(value | (value << 4));
  170310. if (shift == 4)
  170311. {
  170312. shift = 0;
  170313. sp--;
  170314. }
  170315. else
  170316. shift = 4;
  170317. dp--;
  170318. }
  170319. break;
  170320. }
  170321. }
  170322. row_info->bit_depth = 8;
  170323. row_info->pixel_depth = 8;
  170324. row_info->rowbytes = row_width;
  170325. }
  170326. if (trans_value != NULL)
  170327. {
  170328. if (row_info->bit_depth == 8)
  170329. {
  170330. gray = gray & 0xff;
  170331. sp = row + (png_size_t)row_width - 1;
  170332. dp = row + (png_size_t)(row_width << 1) - 1;
  170333. for (i = 0; i < row_width; i++)
  170334. {
  170335. if (*sp == gray)
  170336. *dp-- = 0;
  170337. else
  170338. *dp-- = 0xff;
  170339. *dp-- = *sp--;
  170340. }
  170341. }
  170342. else if (row_info->bit_depth == 16)
  170343. {
  170344. png_byte gray_high = (gray >> 8) & 0xff;
  170345. png_byte gray_low = gray & 0xff;
  170346. sp = row + row_info->rowbytes - 1;
  170347. dp = row + (row_info->rowbytes << 1) - 1;
  170348. for (i = 0; i < row_width; i++)
  170349. {
  170350. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170351. {
  170352. *dp-- = 0;
  170353. *dp-- = 0;
  170354. }
  170355. else
  170356. {
  170357. *dp-- = 0xff;
  170358. *dp-- = 0xff;
  170359. }
  170360. *dp-- = *sp--;
  170361. *dp-- = *sp--;
  170362. }
  170363. }
  170364. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170365. row_info->channels = 2;
  170366. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170367. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170368. row_width);
  170369. }
  170370. }
  170371. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170372. {
  170373. if (row_info->bit_depth == 8)
  170374. {
  170375. png_byte red = trans_value->red & 0xff;
  170376. png_byte green = trans_value->green & 0xff;
  170377. png_byte blue = trans_value->blue & 0xff;
  170378. sp = row + (png_size_t)row_info->rowbytes - 1;
  170379. dp = row + (png_size_t)(row_width << 2) - 1;
  170380. for (i = 0; i < row_width; i++)
  170381. {
  170382. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170383. *dp-- = 0;
  170384. else
  170385. *dp-- = 0xff;
  170386. *dp-- = *sp--;
  170387. *dp-- = *sp--;
  170388. *dp-- = *sp--;
  170389. }
  170390. }
  170391. else if (row_info->bit_depth == 16)
  170392. {
  170393. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170394. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170395. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170396. png_byte red_low = trans_value->red & 0xff;
  170397. png_byte green_low = trans_value->green & 0xff;
  170398. png_byte blue_low = trans_value->blue & 0xff;
  170399. sp = row + row_info->rowbytes - 1;
  170400. dp = row + (png_size_t)(row_width << 3) - 1;
  170401. for (i = 0; i < row_width; i++)
  170402. {
  170403. if (*(sp - 5) == red_high &&
  170404. *(sp - 4) == red_low &&
  170405. *(sp - 3) == green_high &&
  170406. *(sp - 2) == green_low &&
  170407. *(sp - 1) == blue_high &&
  170408. *(sp ) == blue_low)
  170409. {
  170410. *dp-- = 0;
  170411. *dp-- = 0;
  170412. }
  170413. else
  170414. {
  170415. *dp-- = 0xff;
  170416. *dp-- = 0xff;
  170417. }
  170418. *dp-- = *sp--;
  170419. *dp-- = *sp--;
  170420. *dp-- = *sp--;
  170421. *dp-- = *sp--;
  170422. *dp-- = *sp--;
  170423. *dp-- = *sp--;
  170424. }
  170425. }
  170426. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170427. row_info->channels = 4;
  170428. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170429. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170430. }
  170431. }
  170432. }
  170433. #endif
  170434. #if defined(PNG_READ_DITHER_SUPPORTED)
  170435. void /* PRIVATE */
  170436. png_do_dither(png_row_infop row_info, png_bytep row,
  170437. png_bytep palette_lookup, png_bytep dither_lookup)
  170438. {
  170439. png_bytep sp, dp;
  170440. png_uint_32 i;
  170441. png_uint_32 row_width=row_info->width;
  170442. png_debug(1, "in png_do_dither\n");
  170443. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170444. if (row != NULL && row_info != NULL)
  170445. #endif
  170446. {
  170447. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170448. palette_lookup && row_info->bit_depth == 8)
  170449. {
  170450. int r, g, b, p;
  170451. sp = row;
  170452. dp = row;
  170453. for (i = 0; i < row_width; i++)
  170454. {
  170455. r = *sp++;
  170456. g = *sp++;
  170457. b = *sp++;
  170458. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170459. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170460. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170461. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170462. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170463. (PNG_DITHER_BLUE_BITS)) |
  170464. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170465. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170466. *dp++ = palette_lookup[p];
  170467. }
  170468. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170469. row_info->channels = 1;
  170470. row_info->pixel_depth = row_info->bit_depth;
  170471. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170472. }
  170473. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170474. palette_lookup != NULL && row_info->bit_depth == 8)
  170475. {
  170476. int r, g, b, p;
  170477. sp = row;
  170478. dp = row;
  170479. for (i = 0; i < row_width; i++)
  170480. {
  170481. r = *sp++;
  170482. g = *sp++;
  170483. b = *sp++;
  170484. sp++;
  170485. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170486. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170487. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170488. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170489. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170490. (PNG_DITHER_BLUE_BITS)) |
  170491. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170492. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170493. *dp++ = palette_lookup[p];
  170494. }
  170495. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170496. row_info->channels = 1;
  170497. row_info->pixel_depth = row_info->bit_depth;
  170498. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170499. }
  170500. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170501. dither_lookup && row_info->bit_depth == 8)
  170502. {
  170503. sp = row;
  170504. for (i = 0; i < row_width; i++, sp++)
  170505. {
  170506. *sp = dither_lookup[*sp];
  170507. }
  170508. }
  170509. }
  170510. }
  170511. #endif
  170512. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170513. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170514. static PNG_CONST int png_gamma_shift[] =
  170515. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170516. void /* PRIVATE */
  170517. png_build_gamma_table(png_structp png_ptr)
  170518. {
  170519. png_debug(1, "in png_build_gamma_table\n");
  170520. if (png_ptr->bit_depth <= 8)
  170521. {
  170522. int i;
  170523. double g;
  170524. if (png_ptr->screen_gamma > .000001)
  170525. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170526. else
  170527. g = 1.0;
  170528. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170529. (png_uint_32)256);
  170530. for (i = 0; i < 256; i++)
  170531. {
  170532. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170533. g) * 255.0 + .5);
  170534. }
  170535. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170536. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170537. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170538. {
  170539. g = 1.0 / (png_ptr->gamma);
  170540. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170541. (png_uint_32)256);
  170542. for (i = 0; i < 256; i++)
  170543. {
  170544. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170545. g) * 255.0 + .5);
  170546. }
  170547. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170548. (png_uint_32)256);
  170549. if(png_ptr->screen_gamma > 0.000001)
  170550. g = 1.0 / png_ptr->screen_gamma;
  170551. else
  170552. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170553. for (i = 0; i < 256; i++)
  170554. {
  170555. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170556. g) * 255.0 + .5);
  170557. }
  170558. }
  170559. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170560. }
  170561. else
  170562. {
  170563. double g;
  170564. int i, j, shift, num;
  170565. int sig_bit;
  170566. png_uint_32 ig;
  170567. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170568. {
  170569. sig_bit = (int)png_ptr->sig_bit.red;
  170570. if ((int)png_ptr->sig_bit.green > sig_bit)
  170571. sig_bit = png_ptr->sig_bit.green;
  170572. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170573. sig_bit = png_ptr->sig_bit.blue;
  170574. }
  170575. else
  170576. {
  170577. sig_bit = (int)png_ptr->sig_bit.gray;
  170578. }
  170579. if (sig_bit > 0)
  170580. shift = 16 - sig_bit;
  170581. else
  170582. shift = 0;
  170583. if (png_ptr->transformations & PNG_16_TO_8)
  170584. {
  170585. if (shift < (16 - PNG_MAX_GAMMA_8))
  170586. shift = (16 - PNG_MAX_GAMMA_8);
  170587. }
  170588. if (shift > 8)
  170589. shift = 8;
  170590. if (shift < 0)
  170591. shift = 0;
  170592. png_ptr->gamma_shift = (png_byte)shift;
  170593. num = (1 << (8 - shift));
  170594. if (png_ptr->screen_gamma > .000001)
  170595. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170596. else
  170597. g = 1.0;
  170598. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170599. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170600. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170601. {
  170602. double fin, fout;
  170603. png_uint_32 last, max;
  170604. for (i = 0; i < num; i++)
  170605. {
  170606. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170607. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170608. }
  170609. g = 1.0 / g;
  170610. last = 0;
  170611. for (i = 0; i < 256; i++)
  170612. {
  170613. fout = ((double)i + 0.5) / 256.0;
  170614. fin = pow(fout, g);
  170615. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170616. while (last <= max)
  170617. {
  170618. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170619. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170620. (png_uint_16)i | ((png_uint_16)i << 8));
  170621. last++;
  170622. }
  170623. }
  170624. while (last < ((png_uint_32)num << 8))
  170625. {
  170626. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170627. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170628. last++;
  170629. }
  170630. }
  170631. else
  170632. {
  170633. for (i = 0; i < num; i++)
  170634. {
  170635. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170636. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170637. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170638. for (j = 0; j < 256; j++)
  170639. {
  170640. png_ptr->gamma_16_table[i][j] =
  170641. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170642. 65535.0, g) * 65535.0 + .5);
  170643. }
  170644. }
  170645. }
  170646. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170647. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170648. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170649. {
  170650. g = 1.0 / (png_ptr->gamma);
  170651. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170652. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170653. for (i = 0; i < num; i++)
  170654. {
  170655. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170656. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170657. ig = (((png_uint_32)i *
  170658. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170659. for (j = 0; j < 256; j++)
  170660. {
  170661. png_ptr->gamma_16_to_1[i][j] =
  170662. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170663. 65535.0, g) * 65535.0 + .5);
  170664. }
  170665. }
  170666. if(png_ptr->screen_gamma > 0.000001)
  170667. g = 1.0 / png_ptr->screen_gamma;
  170668. else
  170669. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170670. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170671. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170672. for (i = 0; i < num; i++)
  170673. {
  170674. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170675. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170676. ig = (((png_uint_32)i *
  170677. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170678. for (j = 0; j < 256; j++)
  170679. {
  170680. png_ptr->gamma_16_from_1[i][j] =
  170681. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170682. 65535.0, g) * 65535.0 + .5);
  170683. }
  170684. }
  170685. }
  170686. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170687. }
  170688. }
  170689. #endif
  170690. #endif
  170691. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170692. void /* PRIVATE */
  170693. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170694. {
  170695. png_debug(1, "in png_do_read_intrapixel\n");
  170696. if (
  170697. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170698. row != NULL && row_info != NULL &&
  170699. #endif
  170700. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170701. {
  170702. int bytes_per_pixel;
  170703. png_uint_32 row_width = row_info->width;
  170704. if (row_info->bit_depth == 8)
  170705. {
  170706. png_bytep rp;
  170707. png_uint_32 i;
  170708. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170709. bytes_per_pixel = 3;
  170710. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170711. bytes_per_pixel = 4;
  170712. else
  170713. return;
  170714. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170715. {
  170716. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170717. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170718. }
  170719. }
  170720. else if (row_info->bit_depth == 16)
  170721. {
  170722. png_bytep rp;
  170723. png_uint_32 i;
  170724. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170725. bytes_per_pixel = 6;
  170726. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170727. bytes_per_pixel = 8;
  170728. else
  170729. return;
  170730. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170731. {
  170732. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170733. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170734. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170735. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170736. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170737. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170738. *(rp+1) = (png_byte)(red & 0xff);
  170739. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170740. *(rp+5) = (png_byte)(blue & 0xff);
  170741. }
  170742. }
  170743. }
  170744. }
  170745. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170746. #endif /* PNG_READ_SUPPORTED */
  170747. /*** End of inlined file: pngrtran.c ***/
  170748. /*** Start of inlined file: pngrutil.c ***/
  170749. #define PNG_INTERNAL
  170750. #if defined(PNG_READ_SUPPORTED)
  170751. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170752. # define WIN32_WCE_OLD
  170753. #endif
  170754. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170755. # if defined(WIN32_WCE_OLD)
  170756. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170757. {
  170758. double result = 0;
  170759. int len;
  170760. wchar_t *str, *end;
  170761. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170762. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170763. if ( NULL != str )
  170764. {
  170765. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170766. result = wcstod(str, &end);
  170767. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170768. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170769. png_free(png_ptr, str);
  170770. }
  170771. return result;
  170772. }
  170773. # else
  170774. # define png_strtod(p,a,b) strtod(a,b)
  170775. # endif
  170776. #endif
  170777. png_uint_32 PNGAPI
  170778. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170779. {
  170780. png_uint_32 i = png_get_uint_32(buf);
  170781. if (i > PNG_UINT_31_MAX)
  170782. png_error(png_ptr, "PNG unsigned integer out of range.");
  170783. return (i);
  170784. }
  170785. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170786. png_uint_32 PNGAPI
  170787. png_get_uint_32(png_bytep buf)
  170788. {
  170789. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170790. ((png_uint_32)(*(buf + 1)) << 16) +
  170791. ((png_uint_32)(*(buf + 2)) << 8) +
  170792. (png_uint_32)(*(buf + 3));
  170793. return (i);
  170794. }
  170795. png_int_32 PNGAPI
  170796. png_get_int_32(png_bytep buf)
  170797. {
  170798. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170799. ((png_int_32)(*(buf + 1)) << 16) +
  170800. ((png_int_32)(*(buf + 2)) << 8) +
  170801. (png_int_32)(*(buf + 3));
  170802. return (i);
  170803. }
  170804. png_uint_16 PNGAPI
  170805. png_get_uint_16(png_bytep buf)
  170806. {
  170807. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170808. (png_uint_16)(*(buf + 1)));
  170809. return (i);
  170810. }
  170811. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170812. void /* PRIVATE */
  170813. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170814. {
  170815. if(png_ptr == NULL) return;
  170816. png_read_data(png_ptr, buf, length);
  170817. png_calculate_crc(png_ptr, buf, length);
  170818. }
  170819. int /* PRIVATE */
  170820. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170821. {
  170822. png_size_t i;
  170823. png_size_t istop = png_ptr->zbuf_size;
  170824. for (i = (png_size_t)skip; i > istop; i -= istop)
  170825. {
  170826. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170827. }
  170828. if (i)
  170829. {
  170830. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170831. }
  170832. if (png_crc_error(png_ptr))
  170833. {
  170834. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170835. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170836. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170837. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170838. {
  170839. png_chunk_warning(png_ptr, "CRC error");
  170840. }
  170841. else
  170842. {
  170843. png_chunk_error(png_ptr, "CRC error");
  170844. }
  170845. return (1);
  170846. }
  170847. return (0);
  170848. }
  170849. int /* PRIVATE */
  170850. png_crc_error(png_structp png_ptr)
  170851. {
  170852. png_byte crc_bytes[4];
  170853. png_uint_32 crc;
  170854. int need_crc = 1;
  170855. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170856. {
  170857. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170858. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170859. need_crc = 0;
  170860. }
  170861. else /* critical */
  170862. {
  170863. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170864. need_crc = 0;
  170865. }
  170866. png_read_data(png_ptr, crc_bytes, 4);
  170867. if (need_crc)
  170868. {
  170869. crc = png_get_uint_32(crc_bytes);
  170870. return ((int)(crc != png_ptr->crc));
  170871. }
  170872. else
  170873. return (0);
  170874. }
  170875. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170876. defined(PNG_READ_iCCP_SUPPORTED)
  170877. png_charp /* PRIVATE */
  170878. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170879. png_charp chunkdata, png_size_t chunklength,
  170880. png_size_t prefix_size, png_size_t *newlength)
  170881. {
  170882. static PNG_CONST char msg[] = "Error decoding compressed text";
  170883. png_charp text;
  170884. png_size_t text_size;
  170885. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170886. {
  170887. int ret = Z_OK;
  170888. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170889. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170890. png_ptr->zstream.next_out = png_ptr->zbuf;
  170891. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170892. text_size = 0;
  170893. text = NULL;
  170894. while (png_ptr->zstream.avail_in)
  170895. {
  170896. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170897. if (ret != Z_OK && ret != Z_STREAM_END)
  170898. {
  170899. if (png_ptr->zstream.msg != NULL)
  170900. png_warning(png_ptr, png_ptr->zstream.msg);
  170901. else
  170902. png_warning(png_ptr, msg);
  170903. inflateReset(&png_ptr->zstream);
  170904. png_ptr->zstream.avail_in = 0;
  170905. if (text == NULL)
  170906. {
  170907. text_size = prefix_size + png_sizeof(msg) + 1;
  170908. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170909. if (text == NULL)
  170910. {
  170911. png_free(png_ptr,chunkdata);
  170912. png_error(png_ptr,"Not enough memory to decompress chunk");
  170913. }
  170914. png_memcpy(text, chunkdata, prefix_size);
  170915. }
  170916. text[text_size - 1] = 0x00;
  170917. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170918. text_size = png_sizeof(msg) > text_size ? text_size :
  170919. png_sizeof(msg);
  170920. png_memcpy(text + prefix_size, msg, text_size + 1);
  170921. break;
  170922. }
  170923. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170924. {
  170925. if (text == NULL)
  170926. {
  170927. text_size = prefix_size +
  170928. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170929. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170930. if (text == NULL)
  170931. {
  170932. png_free(png_ptr,chunkdata);
  170933. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170934. }
  170935. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170936. text_size - prefix_size);
  170937. png_memcpy(text, chunkdata, prefix_size);
  170938. *(text + text_size) = 0x00;
  170939. }
  170940. else
  170941. {
  170942. png_charp tmp;
  170943. tmp = text;
  170944. text = (png_charp)png_malloc_warn(png_ptr,
  170945. (png_uint_32)(text_size +
  170946. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  170947. if (text == NULL)
  170948. {
  170949. png_free(png_ptr, tmp);
  170950. png_free(png_ptr, chunkdata);
  170951. png_error(png_ptr,"Not enough memory to decompress chunk..");
  170952. }
  170953. png_memcpy(text, tmp, text_size);
  170954. png_free(png_ptr, tmp);
  170955. png_memcpy(text + text_size, png_ptr->zbuf,
  170956. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  170957. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170958. *(text + text_size) = 0x00;
  170959. }
  170960. if (ret == Z_STREAM_END)
  170961. break;
  170962. else
  170963. {
  170964. png_ptr->zstream.next_out = png_ptr->zbuf;
  170965. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170966. }
  170967. }
  170968. }
  170969. if (ret != Z_STREAM_END)
  170970. {
  170971. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170972. char umsg[52];
  170973. if (ret == Z_BUF_ERROR)
  170974. png_snprintf(umsg, 52,
  170975. "Buffer error in compressed datastream in %s chunk",
  170976. png_ptr->chunk_name);
  170977. else if (ret == Z_DATA_ERROR)
  170978. png_snprintf(umsg, 52,
  170979. "Data error in compressed datastream in %s chunk",
  170980. png_ptr->chunk_name);
  170981. else
  170982. png_snprintf(umsg, 52,
  170983. "Incomplete compressed datastream in %s chunk",
  170984. png_ptr->chunk_name);
  170985. png_warning(png_ptr, umsg);
  170986. #else
  170987. png_warning(png_ptr,
  170988. "Incomplete compressed datastream in chunk other than IDAT");
  170989. #endif
  170990. text_size=prefix_size;
  170991. if (text == NULL)
  170992. {
  170993. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  170994. if (text == NULL)
  170995. {
  170996. png_free(png_ptr, chunkdata);
  170997. png_error(png_ptr,"Not enough memory for text.");
  170998. }
  170999. png_memcpy(text, chunkdata, prefix_size);
  171000. }
  171001. *(text + text_size) = 0x00;
  171002. }
  171003. inflateReset(&png_ptr->zstream);
  171004. png_ptr->zstream.avail_in = 0;
  171005. png_free(png_ptr, chunkdata);
  171006. chunkdata = text;
  171007. *newlength=text_size;
  171008. }
  171009. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  171010. {
  171011. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171012. char umsg[50];
  171013. png_snprintf(umsg, 50,
  171014. "Unknown zTXt compression type %d", comp_type);
  171015. png_warning(png_ptr, umsg);
  171016. #else
  171017. png_warning(png_ptr, "Unknown zTXt compression type");
  171018. #endif
  171019. *(chunkdata + prefix_size) = 0x00;
  171020. *newlength=prefix_size;
  171021. }
  171022. return chunkdata;
  171023. }
  171024. #endif
  171025. void /* PRIVATE */
  171026. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171027. {
  171028. png_byte buf[13];
  171029. png_uint_32 width, height;
  171030. int bit_depth, color_type, compression_type, filter_type;
  171031. int interlace_type;
  171032. png_debug(1, "in png_handle_IHDR\n");
  171033. if (png_ptr->mode & PNG_HAVE_IHDR)
  171034. png_error(png_ptr, "Out of place IHDR");
  171035. if (length != 13)
  171036. png_error(png_ptr, "Invalid IHDR chunk");
  171037. png_ptr->mode |= PNG_HAVE_IHDR;
  171038. png_crc_read(png_ptr, buf, 13);
  171039. png_crc_finish(png_ptr, 0);
  171040. width = png_get_uint_31(png_ptr, buf);
  171041. height = png_get_uint_31(png_ptr, buf + 4);
  171042. bit_depth = buf[8];
  171043. color_type = buf[9];
  171044. compression_type = buf[10];
  171045. filter_type = buf[11];
  171046. interlace_type = buf[12];
  171047. png_ptr->width = width;
  171048. png_ptr->height = height;
  171049. png_ptr->bit_depth = (png_byte)bit_depth;
  171050. png_ptr->interlaced = (png_byte)interlace_type;
  171051. png_ptr->color_type = (png_byte)color_type;
  171052. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171053. png_ptr->filter_type = (png_byte)filter_type;
  171054. #endif
  171055. png_ptr->compression_type = (png_byte)compression_type;
  171056. switch (png_ptr->color_type)
  171057. {
  171058. case PNG_COLOR_TYPE_GRAY:
  171059. case PNG_COLOR_TYPE_PALETTE:
  171060. png_ptr->channels = 1;
  171061. break;
  171062. case PNG_COLOR_TYPE_RGB:
  171063. png_ptr->channels = 3;
  171064. break;
  171065. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171066. png_ptr->channels = 2;
  171067. break;
  171068. case PNG_COLOR_TYPE_RGB_ALPHA:
  171069. png_ptr->channels = 4;
  171070. break;
  171071. }
  171072. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171073. png_ptr->channels);
  171074. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171075. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171076. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171077. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171078. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171079. color_type, interlace_type, compression_type, filter_type);
  171080. }
  171081. void /* PRIVATE */
  171082. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171083. {
  171084. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171085. int num, i;
  171086. #ifndef PNG_NO_POINTER_INDEXING
  171087. png_colorp pal_ptr;
  171088. #endif
  171089. png_debug(1, "in png_handle_PLTE\n");
  171090. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171091. png_error(png_ptr, "Missing IHDR before PLTE");
  171092. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171093. {
  171094. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171095. png_crc_finish(png_ptr, length);
  171096. return;
  171097. }
  171098. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171099. png_error(png_ptr, "Duplicate PLTE chunk");
  171100. png_ptr->mode |= PNG_HAVE_PLTE;
  171101. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171102. {
  171103. png_warning(png_ptr,
  171104. "Ignoring PLTE chunk in grayscale PNG");
  171105. png_crc_finish(png_ptr, length);
  171106. return;
  171107. }
  171108. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171109. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171110. {
  171111. png_crc_finish(png_ptr, length);
  171112. return;
  171113. }
  171114. #endif
  171115. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171116. {
  171117. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171118. {
  171119. png_warning(png_ptr, "Invalid palette chunk");
  171120. png_crc_finish(png_ptr, length);
  171121. return;
  171122. }
  171123. else
  171124. {
  171125. png_error(png_ptr, "Invalid palette chunk");
  171126. }
  171127. }
  171128. num = (int)length / 3;
  171129. #ifndef PNG_NO_POINTER_INDEXING
  171130. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171131. {
  171132. png_byte buf[3];
  171133. png_crc_read(png_ptr, buf, 3);
  171134. pal_ptr->red = buf[0];
  171135. pal_ptr->green = buf[1];
  171136. pal_ptr->blue = buf[2];
  171137. }
  171138. #else
  171139. for (i = 0; i < num; i++)
  171140. {
  171141. png_byte buf[3];
  171142. png_crc_read(png_ptr, buf, 3);
  171143. palette[i].red = buf[0];
  171144. palette[i].green = buf[1];
  171145. palette[i].blue = buf[2];
  171146. }
  171147. #endif
  171148. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171149. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171150. #endif
  171151. {
  171152. png_crc_finish(png_ptr, 0);
  171153. }
  171154. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171155. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171156. {
  171157. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171158. {
  171159. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171160. {
  171161. png_chunk_error(png_ptr, "CRC error");
  171162. }
  171163. else
  171164. {
  171165. png_chunk_warning(png_ptr, "CRC error");
  171166. return;
  171167. }
  171168. }
  171169. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171170. {
  171171. png_chunk_warning(png_ptr, "CRC error");
  171172. }
  171173. }
  171174. #endif
  171175. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171176. #if defined(PNG_READ_tRNS_SUPPORTED)
  171177. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171178. {
  171179. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171180. {
  171181. if (png_ptr->num_trans > (png_uint_16)num)
  171182. {
  171183. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171184. png_ptr->num_trans = (png_uint_16)num;
  171185. }
  171186. if (info_ptr->num_trans > (png_uint_16)num)
  171187. {
  171188. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171189. info_ptr->num_trans = (png_uint_16)num;
  171190. }
  171191. }
  171192. }
  171193. #endif
  171194. }
  171195. void /* PRIVATE */
  171196. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171197. {
  171198. png_debug(1, "in png_handle_IEND\n");
  171199. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171200. {
  171201. png_error(png_ptr, "No image in file");
  171202. }
  171203. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171204. if (length != 0)
  171205. {
  171206. png_warning(png_ptr, "Incorrect IEND chunk length");
  171207. }
  171208. png_crc_finish(png_ptr, length);
  171209. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171210. }
  171211. #if defined(PNG_READ_gAMA_SUPPORTED)
  171212. void /* PRIVATE */
  171213. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171214. {
  171215. png_fixed_point igamma;
  171216. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171217. float file_gamma;
  171218. #endif
  171219. png_byte buf[4];
  171220. png_debug(1, "in png_handle_gAMA\n");
  171221. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171222. png_error(png_ptr, "Missing IHDR before gAMA");
  171223. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171224. {
  171225. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171226. png_crc_finish(png_ptr, length);
  171227. return;
  171228. }
  171229. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171230. png_warning(png_ptr, "Out of place gAMA chunk");
  171231. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171232. #if defined(PNG_READ_sRGB_SUPPORTED)
  171233. && !(info_ptr->valid & PNG_INFO_sRGB)
  171234. #endif
  171235. )
  171236. {
  171237. png_warning(png_ptr, "Duplicate gAMA chunk");
  171238. png_crc_finish(png_ptr, length);
  171239. return;
  171240. }
  171241. if (length != 4)
  171242. {
  171243. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171244. png_crc_finish(png_ptr, length);
  171245. return;
  171246. }
  171247. png_crc_read(png_ptr, buf, 4);
  171248. if (png_crc_finish(png_ptr, 0))
  171249. return;
  171250. igamma = (png_fixed_point)png_get_uint_32(buf);
  171251. if (igamma == 0)
  171252. {
  171253. png_warning(png_ptr,
  171254. "Ignoring gAMA chunk with gamma=0");
  171255. return;
  171256. }
  171257. #if defined(PNG_READ_sRGB_SUPPORTED)
  171258. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171259. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171260. {
  171261. png_warning(png_ptr,
  171262. "Ignoring incorrect gAMA value when sRGB is also present");
  171263. #ifndef PNG_NO_CONSOLE_IO
  171264. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171265. #endif
  171266. return;
  171267. }
  171268. #endif /* PNG_READ_sRGB_SUPPORTED */
  171269. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171270. file_gamma = (float)igamma / (float)100000.0;
  171271. # ifdef PNG_READ_GAMMA_SUPPORTED
  171272. png_ptr->gamma = file_gamma;
  171273. # endif
  171274. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171275. #endif
  171276. #ifdef PNG_FIXED_POINT_SUPPORTED
  171277. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171278. #endif
  171279. }
  171280. #endif
  171281. #if defined(PNG_READ_sBIT_SUPPORTED)
  171282. void /* PRIVATE */
  171283. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171284. {
  171285. png_size_t truelen;
  171286. png_byte buf[4];
  171287. png_debug(1, "in png_handle_sBIT\n");
  171288. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171289. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171290. png_error(png_ptr, "Missing IHDR before sBIT");
  171291. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171292. {
  171293. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171294. png_crc_finish(png_ptr, length);
  171295. return;
  171296. }
  171297. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171298. {
  171299. png_warning(png_ptr, "Out of place sBIT chunk");
  171300. }
  171301. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171302. {
  171303. png_warning(png_ptr, "Duplicate sBIT chunk");
  171304. png_crc_finish(png_ptr, length);
  171305. return;
  171306. }
  171307. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171308. truelen = 3;
  171309. else
  171310. truelen = (png_size_t)png_ptr->channels;
  171311. if (length != truelen || length > 4)
  171312. {
  171313. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171314. png_crc_finish(png_ptr, length);
  171315. return;
  171316. }
  171317. png_crc_read(png_ptr, buf, truelen);
  171318. if (png_crc_finish(png_ptr, 0))
  171319. return;
  171320. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171321. {
  171322. png_ptr->sig_bit.red = buf[0];
  171323. png_ptr->sig_bit.green = buf[1];
  171324. png_ptr->sig_bit.blue = buf[2];
  171325. png_ptr->sig_bit.alpha = buf[3];
  171326. }
  171327. else
  171328. {
  171329. png_ptr->sig_bit.gray = buf[0];
  171330. png_ptr->sig_bit.red = buf[0];
  171331. png_ptr->sig_bit.green = buf[0];
  171332. png_ptr->sig_bit.blue = buf[0];
  171333. png_ptr->sig_bit.alpha = buf[1];
  171334. }
  171335. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171336. }
  171337. #endif
  171338. #if defined(PNG_READ_cHRM_SUPPORTED)
  171339. void /* PRIVATE */
  171340. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171341. {
  171342. png_byte buf[4];
  171343. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171344. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171345. #endif
  171346. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171347. int_y_green, int_x_blue, int_y_blue;
  171348. png_uint_32 uint_x, uint_y;
  171349. png_debug(1, "in png_handle_cHRM\n");
  171350. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171351. png_error(png_ptr, "Missing IHDR before cHRM");
  171352. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171353. {
  171354. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171355. png_crc_finish(png_ptr, length);
  171356. return;
  171357. }
  171358. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171359. png_warning(png_ptr, "Missing PLTE before cHRM");
  171360. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171361. #if defined(PNG_READ_sRGB_SUPPORTED)
  171362. && !(info_ptr->valid & PNG_INFO_sRGB)
  171363. #endif
  171364. )
  171365. {
  171366. png_warning(png_ptr, "Duplicate cHRM chunk");
  171367. png_crc_finish(png_ptr, length);
  171368. return;
  171369. }
  171370. if (length != 32)
  171371. {
  171372. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171373. png_crc_finish(png_ptr, length);
  171374. return;
  171375. }
  171376. png_crc_read(png_ptr, buf, 4);
  171377. uint_x = png_get_uint_32(buf);
  171378. png_crc_read(png_ptr, buf, 4);
  171379. uint_y = png_get_uint_32(buf);
  171380. if (uint_x > 80000L || uint_y > 80000L ||
  171381. uint_x + uint_y > 100000L)
  171382. {
  171383. png_warning(png_ptr, "Invalid cHRM white point");
  171384. png_crc_finish(png_ptr, 24);
  171385. return;
  171386. }
  171387. int_x_white = (png_fixed_point)uint_x;
  171388. int_y_white = (png_fixed_point)uint_y;
  171389. png_crc_read(png_ptr, buf, 4);
  171390. uint_x = png_get_uint_32(buf);
  171391. png_crc_read(png_ptr, buf, 4);
  171392. uint_y = png_get_uint_32(buf);
  171393. if (uint_x + uint_y > 100000L)
  171394. {
  171395. png_warning(png_ptr, "Invalid cHRM red point");
  171396. png_crc_finish(png_ptr, 16);
  171397. return;
  171398. }
  171399. int_x_red = (png_fixed_point)uint_x;
  171400. int_y_red = (png_fixed_point)uint_y;
  171401. png_crc_read(png_ptr, buf, 4);
  171402. uint_x = png_get_uint_32(buf);
  171403. png_crc_read(png_ptr, buf, 4);
  171404. uint_y = png_get_uint_32(buf);
  171405. if (uint_x + uint_y > 100000L)
  171406. {
  171407. png_warning(png_ptr, "Invalid cHRM green point");
  171408. png_crc_finish(png_ptr, 8);
  171409. return;
  171410. }
  171411. int_x_green = (png_fixed_point)uint_x;
  171412. int_y_green = (png_fixed_point)uint_y;
  171413. png_crc_read(png_ptr, buf, 4);
  171414. uint_x = png_get_uint_32(buf);
  171415. png_crc_read(png_ptr, buf, 4);
  171416. uint_y = png_get_uint_32(buf);
  171417. if (uint_x + uint_y > 100000L)
  171418. {
  171419. png_warning(png_ptr, "Invalid cHRM blue point");
  171420. png_crc_finish(png_ptr, 0);
  171421. return;
  171422. }
  171423. int_x_blue = (png_fixed_point)uint_x;
  171424. int_y_blue = (png_fixed_point)uint_y;
  171425. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171426. white_x = (float)int_x_white / (float)100000.0;
  171427. white_y = (float)int_y_white / (float)100000.0;
  171428. red_x = (float)int_x_red / (float)100000.0;
  171429. red_y = (float)int_y_red / (float)100000.0;
  171430. green_x = (float)int_x_green / (float)100000.0;
  171431. green_y = (float)int_y_green / (float)100000.0;
  171432. blue_x = (float)int_x_blue / (float)100000.0;
  171433. blue_y = (float)int_y_blue / (float)100000.0;
  171434. #endif
  171435. #if defined(PNG_READ_sRGB_SUPPORTED)
  171436. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171437. {
  171438. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171439. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171440. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171441. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171442. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171443. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171444. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171445. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171446. {
  171447. png_warning(png_ptr,
  171448. "Ignoring incorrect cHRM value when sRGB is also present");
  171449. #ifndef PNG_NO_CONSOLE_IO
  171450. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171451. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171452. white_x, white_y, red_x, red_y);
  171453. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171454. green_x, green_y, blue_x, blue_y);
  171455. #else
  171456. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171457. int_x_white, int_y_white, int_x_red, int_y_red);
  171458. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171459. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171460. #endif
  171461. #endif /* PNG_NO_CONSOLE_IO */
  171462. }
  171463. png_crc_finish(png_ptr, 0);
  171464. return;
  171465. }
  171466. #endif /* PNG_READ_sRGB_SUPPORTED */
  171467. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171468. png_set_cHRM(png_ptr, info_ptr,
  171469. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171470. #endif
  171471. #ifdef PNG_FIXED_POINT_SUPPORTED
  171472. png_set_cHRM_fixed(png_ptr, info_ptr,
  171473. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171474. int_y_green, int_x_blue, int_y_blue);
  171475. #endif
  171476. if (png_crc_finish(png_ptr, 0))
  171477. return;
  171478. }
  171479. #endif
  171480. #if defined(PNG_READ_sRGB_SUPPORTED)
  171481. void /* PRIVATE */
  171482. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171483. {
  171484. int intent;
  171485. png_byte buf[1];
  171486. png_debug(1, "in png_handle_sRGB\n");
  171487. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171488. png_error(png_ptr, "Missing IHDR before sRGB");
  171489. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171490. {
  171491. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171492. png_crc_finish(png_ptr, length);
  171493. return;
  171494. }
  171495. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171496. png_warning(png_ptr, "Out of place sRGB chunk");
  171497. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171498. {
  171499. png_warning(png_ptr, "Duplicate sRGB chunk");
  171500. png_crc_finish(png_ptr, length);
  171501. return;
  171502. }
  171503. if (length != 1)
  171504. {
  171505. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171506. png_crc_finish(png_ptr, length);
  171507. return;
  171508. }
  171509. png_crc_read(png_ptr, buf, 1);
  171510. if (png_crc_finish(png_ptr, 0))
  171511. return;
  171512. intent = buf[0];
  171513. if (intent >= PNG_sRGB_INTENT_LAST)
  171514. {
  171515. png_warning(png_ptr, "Unknown sRGB intent");
  171516. return;
  171517. }
  171518. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171519. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171520. {
  171521. png_fixed_point igamma;
  171522. #ifdef PNG_FIXED_POINT_SUPPORTED
  171523. igamma=info_ptr->int_gamma;
  171524. #else
  171525. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171526. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171527. # endif
  171528. #endif
  171529. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171530. {
  171531. png_warning(png_ptr,
  171532. "Ignoring incorrect gAMA value when sRGB is also present");
  171533. #ifndef PNG_NO_CONSOLE_IO
  171534. # ifdef PNG_FIXED_POINT_SUPPORTED
  171535. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171536. # else
  171537. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171538. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171539. # endif
  171540. # endif
  171541. #endif
  171542. }
  171543. }
  171544. #endif /* PNG_READ_gAMA_SUPPORTED */
  171545. #ifdef PNG_READ_cHRM_SUPPORTED
  171546. #ifdef PNG_FIXED_POINT_SUPPORTED
  171547. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171548. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171549. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171550. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171551. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171552. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171553. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171554. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171555. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171556. {
  171557. png_warning(png_ptr,
  171558. "Ignoring incorrect cHRM value when sRGB is also present");
  171559. }
  171560. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171561. #endif /* PNG_READ_cHRM_SUPPORTED */
  171562. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171563. }
  171564. #endif /* PNG_READ_sRGB_SUPPORTED */
  171565. #if defined(PNG_READ_iCCP_SUPPORTED)
  171566. void /* PRIVATE */
  171567. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171568. {
  171569. png_charp chunkdata;
  171570. png_byte compression_type;
  171571. png_bytep pC;
  171572. png_charp profile;
  171573. png_uint_32 skip = 0;
  171574. png_uint_32 profile_size, profile_length;
  171575. png_size_t slength, prefix_length, data_length;
  171576. png_debug(1, "in png_handle_iCCP\n");
  171577. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171578. png_error(png_ptr, "Missing IHDR before iCCP");
  171579. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171580. {
  171581. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171582. png_crc_finish(png_ptr, length);
  171583. return;
  171584. }
  171585. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171586. png_warning(png_ptr, "Out of place iCCP chunk");
  171587. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171588. {
  171589. png_warning(png_ptr, "Duplicate iCCP chunk");
  171590. png_crc_finish(png_ptr, length);
  171591. return;
  171592. }
  171593. #ifdef PNG_MAX_MALLOC_64K
  171594. if (length > (png_uint_32)65535L)
  171595. {
  171596. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171597. skip = length - (png_uint_32)65535L;
  171598. length = (png_uint_32)65535L;
  171599. }
  171600. #endif
  171601. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171602. slength = (png_size_t)length;
  171603. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171604. if (png_crc_finish(png_ptr, skip))
  171605. {
  171606. png_free(png_ptr, chunkdata);
  171607. return;
  171608. }
  171609. chunkdata[slength] = 0x00;
  171610. for (profile = chunkdata; *profile; profile++)
  171611. ;
  171612. ++profile;
  171613. if ( profile >= chunkdata + slength - 1)
  171614. {
  171615. png_free(png_ptr, chunkdata);
  171616. png_warning(png_ptr, "Malformed iCCP chunk");
  171617. return;
  171618. }
  171619. compression_type = *profile++;
  171620. if (compression_type)
  171621. {
  171622. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171623. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171624. wrote nonzero) */
  171625. }
  171626. prefix_length = profile - chunkdata;
  171627. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171628. slength, prefix_length, &data_length);
  171629. profile_length = data_length - prefix_length;
  171630. if ( prefix_length > data_length || profile_length < 4)
  171631. {
  171632. png_free(png_ptr, chunkdata);
  171633. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171634. return;
  171635. }
  171636. pC = (png_bytep)(chunkdata+prefix_length);
  171637. profile_size = ((*(pC ))<<24) |
  171638. ((*(pC+1))<<16) |
  171639. ((*(pC+2))<< 8) |
  171640. ((*(pC+3)) );
  171641. if(profile_size < profile_length)
  171642. profile_length = profile_size;
  171643. if(profile_size > profile_length)
  171644. {
  171645. png_free(png_ptr, chunkdata);
  171646. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171647. return;
  171648. }
  171649. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171650. chunkdata + prefix_length, profile_length);
  171651. png_free(png_ptr, chunkdata);
  171652. }
  171653. #endif /* PNG_READ_iCCP_SUPPORTED */
  171654. #if defined(PNG_READ_sPLT_SUPPORTED)
  171655. void /* PRIVATE */
  171656. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171657. {
  171658. png_bytep chunkdata;
  171659. png_bytep entry_start;
  171660. png_sPLT_t new_palette;
  171661. #ifdef PNG_NO_POINTER_INDEXING
  171662. png_sPLT_entryp pp;
  171663. #endif
  171664. int data_length, entry_size, i;
  171665. png_uint_32 skip = 0;
  171666. png_size_t slength;
  171667. png_debug(1, "in png_handle_sPLT\n");
  171668. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171669. png_error(png_ptr, "Missing IHDR before sPLT");
  171670. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171671. {
  171672. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171673. png_crc_finish(png_ptr, length);
  171674. return;
  171675. }
  171676. #ifdef PNG_MAX_MALLOC_64K
  171677. if (length > (png_uint_32)65535L)
  171678. {
  171679. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171680. skip = length - (png_uint_32)65535L;
  171681. length = (png_uint_32)65535L;
  171682. }
  171683. #endif
  171684. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171685. slength = (png_size_t)length;
  171686. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171687. if (png_crc_finish(png_ptr, skip))
  171688. {
  171689. png_free(png_ptr, chunkdata);
  171690. return;
  171691. }
  171692. chunkdata[slength] = 0x00;
  171693. for (entry_start = chunkdata; *entry_start; entry_start++)
  171694. ;
  171695. ++entry_start;
  171696. if (entry_start > chunkdata + slength - 2)
  171697. {
  171698. png_free(png_ptr, chunkdata);
  171699. png_warning(png_ptr, "malformed sPLT chunk");
  171700. return;
  171701. }
  171702. new_palette.depth = *entry_start++;
  171703. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171704. data_length = (slength - (entry_start - chunkdata));
  171705. if (data_length % entry_size)
  171706. {
  171707. png_free(png_ptr, chunkdata);
  171708. png_warning(png_ptr, "sPLT chunk has bad length");
  171709. return;
  171710. }
  171711. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171712. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171713. png_sizeof(png_sPLT_entry)))
  171714. {
  171715. png_warning(png_ptr, "sPLT chunk too long");
  171716. return;
  171717. }
  171718. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171719. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171720. if (new_palette.entries == NULL)
  171721. {
  171722. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171723. return;
  171724. }
  171725. #ifndef PNG_NO_POINTER_INDEXING
  171726. for (i = 0; i < new_palette.nentries; i++)
  171727. {
  171728. png_sPLT_entryp pp = new_palette.entries + i;
  171729. if (new_palette.depth == 8)
  171730. {
  171731. pp->red = *entry_start++;
  171732. pp->green = *entry_start++;
  171733. pp->blue = *entry_start++;
  171734. pp->alpha = *entry_start++;
  171735. }
  171736. else
  171737. {
  171738. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171739. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171740. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171741. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171742. }
  171743. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171744. }
  171745. #else
  171746. pp = new_palette.entries;
  171747. for (i = 0; i < new_palette.nentries; i++)
  171748. {
  171749. if (new_palette.depth == 8)
  171750. {
  171751. pp[i].red = *entry_start++;
  171752. pp[i].green = *entry_start++;
  171753. pp[i].blue = *entry_start++;
  171754. pp[i].alpha = *entry_start++;
  171755. }
  171756. else
  171757. {
  171758. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171759. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171760. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171761. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171762. }
  171763. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171764. }
  171765. #endif
  171766. new_palette.name = (png_charp)chunkdata;
  171767. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171768. png_free(png_ptr, chunkdata);
  171769. png_free(png_ptr, new_palette.entries);
  171770. }
  171771. #endif /* PNG_READ_sPLT_SUPPORTED */
  171772. #if defined(PNG_READ_tRNS_SUPPORTED)
  171773. void /* PRIVATE */
  171774. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171775. {
  171776. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171777. int bit_mask;
  171778. png_debug(1, "in png_handle_tRNS\n");
  171779. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171780. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171781. png_error(png_ptr, "Missing IHDR before tRNS");
  171782. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171783. {
  171784. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171785. png_crc_finish(png_ptr, length);
  171786. return;
  171787. }
  171788. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171789. {
  171790. png_warning(png_ptr, "Duplicate tRNS chunk");
  171791. png_crc_finish(png_ptr, length);
  171792. return;
  171793. }
  171794. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171795. {
  171796. png_byte buf[2];
  171797. if (length != 2)
  171798. {
  171799. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171800. png_crc_finish(png_ptr, length);
  171801. return;
  171802. }
  171803. png_crc_read(png_ptr, buf, 2);
  171804. png_ptr->num_trans = 1;
  171805. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171806. }
  171807. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171808. {
  171809. png_byte buf[6];
  171810. if (length != 6)
  171811. {
  171812. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171813. png_crc_finish(png_ptr, length);
  171814. return;
  171815. }
  171816. png_crc_read(png_ptr, buf, (png_size_t)length);
  171817. png_ptr->num_trans = 1;
  171818. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171819. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171820. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171821. }
  171822. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171823. {
  171824. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171825. {
  171826. png_warning(png_ptr, "Missing PLTE before tRNS");
  171827. }
  171828. if (length > (png_uint_32)png_ptr->num_palette ||
  171829. length > PNG_MAX_PALETTE_LENGTH)
  171830. {
  171831. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171832. png_crc_finish(png_ptr, length);
  171833. return;
  171834. }
  171835. if (length == 0)
  171836. {
  171837. png_warning(png_ptr, "Zero length tRNS chunk");
  171838. png_crc_finish(png_ptr, length);
  171839. return;
  171840. }
  171841. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171842. png_ptr->num_trans = (png_uint_16)length;
  171843. }
  171844. else
  171845. {
  171846. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171847. png_crc_finish(png_ptr, length);
  171848. return;
  171849. }
  171850. if (png_crc_finish(png_ptr, 0))
  171851. {
  171852. png_ptr->num_trans = 0;
  171853. return;
  171854. }
  171855. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171856. &(png_ptr->trans_values));
  171857. }
  171858. #endif
  171859. #if defined(PNG_READ_bKGD_SUPPORTED)
  171860. void /* PRIVATE */
  171861. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171862. {
  171863. png_size_t truelen;
  171864. png_byte buf[6];
  171865. png_debug(1, "in png_handle_bKGD\n");
  171866. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171867. png_error(png_ptr, "Missing IHDR before bKGD");
  171868. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171869. {
  171870. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171871. png_crc_finish(png_ptr, length);
  171872. return;
  171873. }
  171874. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171875. !(png_ptr->mode & PNG_HAVE_PLTE))
  171876. {
  171877. png_warning(png_ptr, "Missing PLTE before bKGD");
  171878. png_crc_finish(png_ptr, length);
  171879. return;
  171880. }
  171881. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171882. {
  171883. png_warning(png_ptr, "Duplicate bKGD chunk");
  171884. png_crc_finish(png_ptr, length);
  171885. return;
  171886. }
  171887. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171888. truelen = 1;
  171889. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171890. truelen = 6;
  171891. else
  171892. truelen = 2;
  171893. if (length != truelen)
  171894. {
  171895. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171896. png_crc_finish(png_ptr, length);
  171897. return;
  171898. }
  171899. png_crc_read(png_ptr, buf, truelen);
  171900. if (png_crc_finish(png_ptr, 0))
  171901. return;
  171902. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171903. {
  171904. png_ptr->background.index = buf[0];
  171905. if(info_ptr->num_palette)
  171906. {
  171907. if(buf[0] > info_ptr->num_palette)
  171908. {
  171909. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171910. return;
  171911. }
  171912. png_ptr->background.red =
  171913. (png_uint_16)png_ptr->palette[buf[0]].red;
  171914. png_ptr->background.green =
  171915. (png_uint_16)png_ptr->palette[buf[0]].green;
  171916. png_ptr->background.blue =
  171917. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171918. }
  171919. }
  171920. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171921. {
  171922. png_ptr->background.red =
  171923. png_ptr->background.green =
  171924. png_ptr->background.blue =
  171925. png_ptr->background.gray = png_get_uint_16(buf);
  171926. }
  171927. else
  171928. {
  171929. png_ptr->background.red = png_get_uint_16(buf);
  171930. png_ptr->background.green = png_get_uint_16(buf + 2);
  171931. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171932. }
  171933. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171934. }
  171935. #endif
  171936. #if defined(PNG_READ_hIST_SUPPORTED)
  171937. void /* PRIVATE */
  171938. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171939. {
  171940. unsigned int num, i;
  171941. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171942. png_debug(1, "in png_handle_hIST\n");
  171943. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171944. png_error(png_ptr, "Missing IHDR before hIST");
  171945. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171946. {
  171947. png_warning(png_ptr, "Invalid hIST after IDAT");
  171948. png_crc_finish(png_ptr, length);
  171949. return;
  171950. }
  171951. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171952. {
  171953. png_warning(png_ptr, "Missing PLTE before hIST");
  171954. png_crc_finish(png_ptr, length);
  171955. return;
  171956. }
  171957. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  171958. {
  171959. png_warning(png_ptr, "Duplicate hIST chunk");
  171960. png_crc_finish(png_ptr, length);
  171961. return;
  171962. }
  171963. num = length / 2 ;
  171964. if (num != (unsigned int) png_ptr->num_palette || num >
  171965. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  171966. {
  171967. png_warning(png_ptr, "Incorrect hIST chunk length");
  171968. png_crc_finish(png_ptr, length);
  171969. return;
  171970. }
  171971. for (i = 0; i < num; i++)
  171972. {
  171973. png_byte buf[2];
  171974. png_crc_read(png_ptr, buf, 2);
  171975. readbuf[i] = png_get_uint_16(buf);
  171976. }
  171977. if (png_crc_finish(png_ptr, 0))
  171978. return;
  171979. png_set_hIST(png_ptr, info_ptr, readbuf);
  171980. }
  171981. #endif
  171982. #if defined(PNG_READ_pHYs_SUPPORTED)
  171983. void /* PRIVATE */
  171984. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171985. {
  171986. png_byte buf[9];
  171987. png_uint_32 res_x, res_y;
  171988. int unit_type;
  171989. png_debug(1, "in png_handle_pHYs\n");
  171990. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171991. png_error(png_ptr, "Missing IHDR before pHYs");
  171992. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171993. {
  171994. png_warning(png_ptr, "Invalid pHYs after IDAT");
  171995. png_crc_finish(png_ptr, length);
  171996. return;
  171997. }
  171998. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171999. {
  172000. png_warning(png_ptr, "Duplicate pHYs chunk");
  172001. png_crc_finish(png_ptr, length);
  172002. return;
  172003. }
  172004. if (length != 9)
  172005. {
  172006. png_warning(png_ptr, "Incorrect pHYs chunk length");
  172007. png_crc_finish(png_ptr, length);
  172008. return;
  172009. }
  172010. png_crc_read(png_ptr, buf, 9);
  172011. if (png_crc_finish(png_ptr, 0))
  172012. return;
  172013. res_x = png_get_uint_32(buf);
  172014. res_y = png_get_uint_32(buf + 4);
  172015. unit_type = buf[8];
  172016. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  172017. }
  172018. #endif
  172019. #if defined(PNG_READ_oFFs_SUPPORTED)
  172020. void /* PRIVATE */
  172021. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172022. {
  172023. png_byte buf[9];
  172024. png_int_32 offset_x, offset_y;
  172025. int unit_type;
  172026. png_debug(1, "in png_handle_oFFs\n");
  172027. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172028. png_error(png_ptr, "Missing IHDR before oFFs");
  172029. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172030. {
  172031. png_warning(png_ptr, "Invalid oFFs after IDAT");
  172032. png_crc_finish(png_ptr, length);
  172033. return;
  172034. }
  172035. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172036. {
  172037. png_warning(png_ptr, "Duplicate oFFs chunk");
  172038. png_crc_finish(png_ptr, length);
  172039. return;
  172040. }
  172041. if (length != 9)
  172042. {
  172043. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172044. png_crc_finish(png_ptr, length);
  172045. return;
  172046. }
  172047. png_crc_read(png_ptr, buf, 9);
  172048. if (png_crc_finish(png_ptr, 0))
  172049. return;
  172050. offset_x = png_get_int_32(buf);
  172051. offset_y = png_get_int_32(buf + 4);
  172052. unit_type = buf[8];
  172053. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172054. }
  172055. #endif
  172056. #if defined(PNG_READ_pCAL_SUPPORTED)
  172057. void /* PRIVATE */
  172058. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172059. {
  172060. png_charp purpose;
  172061. png_int_32 X0, X1;
  172062. png_byte type, nparams;
  172063. png_charp buf, units, endptr;
  172064. png_charpp params;
  172065. png_size_t slength;
  172066. int i;
  172067. png_debug(1, "in png_handle_pCAL\n");
  172068. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172069. png_error(png_ptr, "Missing IHDR before pCAL");
  172070. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172071. {
  172072. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172073. png_crc_finish(png_ptr, length);
  172074. return;
  172075. }
  172076. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172077. {
  172078. png_warning(png_ptr, "Duplicate pCAL chunk");
  172079. png_crc_finish(png_ptr, length);
  172080. return;
  172081. }
  172082. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172083. length + 1);
  172084. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172085. if (purpose == NULL)
  172086. {
  172087. png_warning(png_ptr, "No memory for pCAL purpose.");
  172088. return;
  172089. }
  172090. slength = (png_size_t)length;
  172091. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172092. if (png_crc_finish(png_ptr, 0))
  172093. {
  172094. png_free(png_ptr, purpose);
  172095. return;
  172096. }
  172097. purpose[slength] = 0x00; /* null terminate the last string */
  172098. png_debug(3, "Finding end of pCAL purpose string\n");
  172099. for (buf = purpose; *buf; buf++)
  172100. ;
  172101. endptr = purpose + slength;
  172102. if (endptr <= buf + 12)
  172103. {
  172104. png_warning(png_ptr, "Invalid pCAL data");
  172105. png_free(png_ptr, purpose);
  172106. return;
  172107. }
  172108. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172109. X0 = png_get_int_32((png_bytep)buf+1);
  172110. X1 = png_get_int_32((png_bytep)buf+5);
  172111. type = buf[9];
  172112. nparams = buf[10];
  172113. units = buf + 11;
  172114. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172115. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172116. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172117. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172118. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172119. {
  172120. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172121. png_free(png_ptr, purpose);
  172122. return;
  172123. }
  172124. else if (type >= PNG_EQUATION_LAST)
  172125. {
  172126. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172127. }
  172128. for (buf = units; *buf; buf++)
  172129. ;
  172130. png_debug(3, "Allocating pCAL parameters array\n");
  172131. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172132. *png_sizeof(png_charp))) ;
  172133. if (params == NULL)
  172134. {
  172135. png_free(png_ptr, purpose);
  172136. png_warning(png_ptr, "No memory for pCAL params.");
  172137. return;
  172138. }
  172139. for (i = 0; i < (int)nparams; i++)
  172140. {
  172141. buf++; /* Skip the null string terminator from previous parameter. */
  172142. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172143. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172144. ;
  172145. if (buf > endptr)
  172146. {
  172147. png_warning(png_ptr, "Invalid pCAL data");
  172148. png_free(png_ptr, purpose);
  172149. png_free(png_ptr, params);
  172150. return;
  172151. }
  172152. }
  172153. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172154. units, params);
  172155. png_free(png_ptr, purpose);
  172156. png_free(png_ptr, params);
  172157. }
  172158. #endif
  172159. #if defined(PNG_READ_sCAL_SUPPORTED)
  172160. void /* PRIVATE */
  172161. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172162. {
  172163. png_charp buffer, ep;
  172164. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172165. double width, height;
  172166. png_charp vp;
  172167. #else
  172168. #ifdef PNG_FIXED_POINT_SUPPORTED
  172169. png_charp swidth, sheight;
  172170. #endif
  172171. #endif
  172172. png_size_t slength;
  172173. png_debug(1, "in png_handle_sCAL\n");
  172174. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172175. png_error(png_ptr, "Missing IHDR before sCAL");
  172176. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172177. {
  172178. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172179. png_crc_finish(png_ptr, length);
  172180. return;
  172181. }
  172182. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172183. {
  172184. png_warning(png_ptr, "Duplicate sCAL chunk");
  172185. png_crc_finish(png_ptr, length);
  172186. return;
  172187. }
  172188. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172189. length + 1);
  172190. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172191. if (buffer == NULL)
  172192. {
  172193. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172194. return;
  172195. }
  172196. slength = (png_size_t)length;
  172197. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172198. if (png_crc_finish(png_ptr, 0))
  172199. {
  172200. png_free(png_ptr, buffer);
  172201. return;
  172202. }
  172203. buffer[slength] = 0x00; /* null terminate the last string */
  172204. ep = buffer + 1; /* skip unit byte */
  172205. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172206. width = png_strtod(png_ptr, ep, &vp);
  172207. if (*vp)
  172208. {
  172209. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172210. return;
  172211. }
  172212. #else
  172213. #ifdef PNG_FIXED_POINT_SUPPORTED
  172214. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172215. if (swidth == NULL)
  172216. {
  172217. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172218. return;
  172219. }
  172220. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172221. #endif
  172222. #endif
  172223. for (ep = buffer; *ep; ep++)
  172224. ;
  172225. ep++;
  172226. if (buffer + slength < ep)
  172227. {
  172228. png_warning(png_ptr, "Truncated sCAL chunk");
  172229. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172230. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172231. png_free(png_ptr, swidth);
  172232. #endif
  172233. png_free(png_ptr, buffer);
  172234. return;
  172235. }
  172236. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172237. height = png_strtod(png_ptr, ep, &vp);
  172238. if (*vp)
  172239. {
  172240. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172241. return;
  172242. }
  172243. #else
  172244. #ifdef PNG_FIXED_POINT_SUPPORTED
  172245. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172246. if (swidth == NULL)
  172247. {
  172248. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172249. return;
  172250. }
  172251. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172252. #endif
  172253. #endif
  172254. if (buffer + slength < ep
  172255. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172256. || width <= 0. || height <= 0.
  172257. #endif
  172258. )
  172259. {
  172260. png_warning(png_ptr, "Invalid sCAL data");
  172261. png_free(png_ptr, buffer);
  172262. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172263. png_free(png_ptr, swidth);
  172264. png_free(png_ptr, sheight);
  172265. #endif
  172266. return;
  172267. }
  172268. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172269. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172270. #else
  172271. #ifdef PNG_FIXED_POINT_SUPPORTED
  172272. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172273. #endif
  172274. #endif
  172275. png_free(png_ptr, buffer);
  172276. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172277. png_free(png_ptr, swidth);
  172278. png_free(png_ptr, sheight);
  172279. #endif
  172280. }
  172281. #endif
  172282. #if defined(PNG_READ_tIME_SUPPORTED)
  172283. void /* PRIVATE */
  172284. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172285. {
  172286. png_byte buf[7];
  172287. png_time mod_time;
  172288. png_debug(1, "in png_handle_tIME\n");
  172289. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172290. png_error(png_ptr, "Out of place tIME chunk");
  172291. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172292. {
  172293. png_warning(png_ptr, "Duplicate tIME chunk");
  172294. png_crc_finish(png_ptr, length);
  172295. return;
  172296. }
  172297. if (png_ptr->mode & PNG_HAVE_IDAT)
  172298. png_ptr->mode |= PNG_AFTER_IDAT;
  172299. if (length != 7)
  172300. {
  172301. png_warning(png_ptr, "Incorrect tIME chunk length");
  172302. png_crc_finish(png_ptr, length);
  172303. return;
  172304. }
  172305. png_crc_read(png_ptr, buf, 7);
  172306. if (png_crc_finish(png_ptr, 0))
  172307. return;
  172308. mod_time.second = buf[6];
  172309. mod_time.minute = buf[5];
  172310. mod_time.hour = buf[4];
  172311. mod_time.day = buf[3];
  172312. mod_time.month = buf[2];
  172313. mod_time.year = png_get_uint_16(buf);
  172314. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172315. }
  172316. #endif
  172317. #if defined(PNG_READ_tEXt_SUPPORTED)
  172318. void /* PRIVATE */
  172319. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172320. {
  172321. png_textp text_ptr;
  172322. png_charp key;
  172323. png_charp text;
  172324. png_uint_32 skip = 0;
  172325. png_size_t slength;
  172326. int ret;
  172327. png_debug(1, "in png_handle_tEXt\n");
  172328. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172329. png_error(png_ptr, "Missing IHDR before tEXt");
  172330. if (png_ptr->mode & PNG_HAVE_IDAT)
  172331. png_ptr->mode |= PNG_AFTER_IDAT;
  172332. #ifdef PNG_MAX_MALLOC_64K
  172333. if (length > (png_uint_32)65535L)
  172334. {
  172335. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172336. skip = length - (png_uint_32)65535L;
  172337. length = (png_uint_32)65535L;
  172338. }
  172339. #endif
  172340. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172341. if (key == NULL)
  172342. {
  172343. png_warning(png_ptr, "No memory to process text chunk.");
  172344. return;
  172345. }
  172346. slength = (png_size_t)length;
  172347. png_crc_read(png_ptr, (png_bytep)key, slength);
  172348. if (png_crc_finish(png_ptr, skip))
  172349. {
  172350. png_free(png_ptr, key);
  172351. return;
  172352. }
  172353. key[slength] = 0x00;
  172354. for (text = key; *text; text++)
  172355. ;
  172356. if (text != key + slength)
  172357. text++;
  172358. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172359. (png_uint_32)png_sizeof(png_text));
  172360. if (text_ptr == NULL)
  172361. {
  172362. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172363. png_free(png_ptr, key);
  172364. return;
  172365. }
  172366. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172367. text_ptr->key = key;
  172368. #ifdef PNG_iTXt_SUPPORTED
  172369. text_ptr->lang = NULL;
  172370. text_ptr->lang_key = NULL;
  172371. text_ptr->itxt_length = 0;
  172372. #endif
  172373. text_ptr->text = text;
  172374. text_ptr->text_length = png_strlen(text);
  172375. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172376. png_free(png_ptr, key);
  172377. png_free(png_ptr, text_ptr);
  172378. if (ret)
  172379. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172380. }
  172381. #endif
  172382. #if defined(PNG_READ_zTXt_SUPPORTED)
  172383. void /* PRIVATE */
  172384. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172385. {
  172386. png_textp text_ptr;
  172387. png_charp chunkdata;
  172388. png_charp text;
  172389. int comp_type;
  172390. int ret;
  172391. png_size_t slength, prefix_len, data_len;
  172392. png_debug(1, "in png_handle_zTXt\n");
  172393. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172394. png_error(png_ptr, "Missing IHDR before zTXt");
  172395. if (png_ptr->mode & PNG_HAVE_IDAT)
  172396. png_ptr->mode |= PNG_AFTER_IDAT;
  172397. #ifdef PNG_MAX_MALLOC_64K
  172398. if (length > (png_uint_32)65535L)
  172399. {
  172400. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172401. png_crc_finish(png_ptr, length);
  172402. return;
  172403. }
  172404. #endif
  172405. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172406. if (chunkdata == NULL)
  172407. {
  172408. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172409. return;
  172410. }
  172411. slength = (png_size_t)length;
  172412. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172413. if (png_crc_finish(png_ptr, 0))
  172414. {
  172415. png_free(png_ptr, chunkdata);
  172416. return;
  172417. }
  172418. chunkdata[slength] = 0x00;
  172419. for (text = chunkdata; *text; text++)
  172420. ;
  172421. if (text >= chunkdata + slength - 2)
  172422. {
  172423. png_warning(png_ptr, "Truncated zTXt chunk");
  172424. png_free(png_ptr, chunkdata);
  172425. return;
  172426. }
  172427. else
  172428. {
  172429. comp_type = *(++text);
  172430. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172431. {
  172432. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172433. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172434. }
  172435. text++; /* skip the compression_method byte */
  172436. }
  172437. prefix_len = text - chunkdata;
  172438. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172439. (png_size_t)length, prefix_len, &data_len);
  172440. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172441. (png_uint_32)png_sizeof(png_text));
  172442. if (text_ptr == NULL)
  172443. {
  172444. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172445. png_free(png_ptr, chunkdata);
  172446. return;
  172447. }
  172448. text_ptr->compression = comp_type;
  172449. text_ptr->key = chunkdata;
  172450. #ifdef PNG_iTXt_SUPPORTED
  172451. text_ptr->lang = NULL;
  172452. text_ptr->lang_key = NULL;
  172453. text_ptr->itxt_length = 0;
  172454. #endif
  172455. text_ptr->text = chunkdata + prefix_len;
  172456. text_ptr->text_length = data_len;
  172457. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172458. png_free(png_ptr, text_ptr);
  172459. png_free(png_ptr, chunkdata);
  172460. if (ret)
  172461. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172462. }
  172463. #endif
  172464. #if defined(PNG_READ_iTXt_SUPPORTED)
  172465. void /* PRIVATE */
  172466. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172467. {
  172468. png_textp text_ptr;
  172469. png_charp chunkdata;
  172470. png_charp key, lang, text, lang_key;
  172471. int comp_flag;
  172472. int comp_type = 0;
  172473. int ret;
  172474. png_size_t slength, prefix_len, data_len;
  172475. png_debug(1, "in png_handle_iTXt\n");
  172476. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172477. png_error(png_ptr, "Missing IHDR before iTXt");
  172478. if (png_ptr->mode & PNG_HAVE_IDAT)
  172479. png_ptr->mode |= PNG_AFTER_IDAT;
  172480. #ifdef PNG_MAX_MALLOC_64K
  172481. if (length > (png_uint_32)65535L)
  172482. {
  172483. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172484. png_crc_finish(png_ptr, length);
  172485. return;
  172486. }
  172487. #endif
  172488. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172489. if (chunkdata == NULL)
  172490. {
  172491. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172492. return;
  172493. }
  172494. slength = (png_size_t)length;
  172495. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172496. if (png_crc_finish(png_ptr, 0))
  172497. {
  172498. png_free(png_ptr, chunkdata);
  172499. return;
  172500. }
  172501. chunkdata[slength] = 0x00;
  172502. for (lang = chunkdata; *lang; lang++)
  172503. ;
  172504. lang++; /* skip NUL separator */
  172505. if (lang >= chunkdata + slength - 3)
  172506. {
  172507. png_warning(png_ptr, "Truncated iTXt chunk");
  172508. png_free(png_ptr, chunkdata);
  172509. return;
  172510. }
  172511. else
  172512. {
  172513. comp_flag = *lang++;
  172514. comp_type = *lang++;
  172515. }
  172516. for (lang_key = lang; *lang_key; lang_key++)
  172517. ;
  172518. lang_key++; /* skip NUL separator */
  172519. if (lang_key >= chunkdata + slength)
  172520. {
  172521. png_warning(png_ptr, "Truncated iTXt chunk");
  172522. png_free(png_ptr, chunkdata);
  172523. return;
  172524. }
  172525. for (text = lang_key; *text; text++)
  172526. ;
  172527. text++; /* skip NUL separator */
  172528. if (text >= chunkdata + slength)
  172529. {
  172530. png_warning(png_ptr, "Malformed iTXt chunk");
  172531. png_free(png_ptr, chunkdata);
  172532. return;
  172533. }
  172534. prefix_len = text - chunkdata;
  172535. key=chunkdata;
  172536. if (comp_flag)
  172537. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172538. (size_t)length, prefix_len, &data_len);
  172539. else
  172540. data_len=png_strlen(chunkdata + prefix_len);
  172541. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172542. (png_uint_32)png_sizeof(png_text));
  172543. if (text_ptr == NULL)
  172544. {
  172545. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172546. png_free(png_ptr, chunkdata);
  172547. return;
  172548. }
  172549. text_ptr->compression = (int)comp_flag + 1;
  172550. text_ptr->lang_key = chunkdata+(lang_key-key);
  172551. text_ptr->lang = chunkdata+(lang-key);
  172552. text_ptr->itxt_length = data_len;
  172553. text_ptr->text_length = 0;
  172554. text_ptr->key = chunkdata;
  172555. text_ptr->text = chunkdata + prefix_len;
  172556. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172557. png_free(png_ptr, text_ptr);
  172558. png_free(png_ptr, chunkdata);
  172559. if (ret)
  172560. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172561. }
  172562. #endif
  172563. void /* PRIVATE */
  172564. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172565. {
  172566. png_uint_32 skip = 0;
  172567. png_debug(1, "in png_handle_unknown\n");
  172568. if (png_ptr->mode & PNG_HAVE_IDAT)
  172569. {
  172570. #ifdef PNG_USE_LOCAL_ARRAYS
  172571. PNG_CONST PNG_IDAT;
  172572. #endif
  172573. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172574. png_ptr->mode |= PNG_AFTER_IDAT;
  172575. }
  172576. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172577. if (!(png_ptr->chunk_name[0] & 0x20))
  172578. {
  172579. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172580. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172581. PNG_HANDLE_CHUNK_ALWAYS
  172582. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172583. && png_ptr->read_user_chunk_fn == NULL
  172584. #endif
  172585. )
  172586. #endif
  172587. png_chunk_error(png_ptr, "unknown critical chunk");
  172588. }
  172589. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172590. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172591. (png_ptr->read_user_chunk_fn != NULL))
  172592. {
  172593. #ifdef PNG_MAX_MALLOC_64K
  172594. if (length > (png_uint_32)65535L)
  172595. {
  172596. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172597. skip = length - (png_uint_32)65535L;
  172598. length = (png_uint_32)65535L;
  172599. }
  172600. #endif
  172601. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172602. (png_charp)png_ptr->chunk_name, 5);
  172603. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172604. png_ptr->unknown_chunk.size = (png_size_t)length;
  172605. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172606. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172607. if(png_ptr->read_user_chunk_fn != NULL)
  172608. {
  172609. int ret;
  172610. ret = (*(png_ptr->read_user_chunk_fn))
  172611. (png_ptr, &png_ptr->unknown_chunk);
  172612. if (ret < 0)
  172613. png_chunk_error(png_ptr, "error in user chunk");
  172614. if (ret == 0)
  172615. {
  172616. if (!(png_ptr->chunk_name[0] & 0x20))
  172617. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172618. PNG_HANDLE_CHUNK_ALWAYS)
  172619. png_chunk_error(png_ptr, "unknown critical chunk");
  172620. png_set_unknown_chunks(png_ptr, info_ptr,
  172621. &png_ptr->unknown_chunk, 1);
  172622. }
  172623. }
  172624. #else
  172625. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172626. #endif
  172627. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172628. png_ptr->unknown_chunk.data = NULL;
  172629. }
  172630. else
  172631. #endif
  172632. skip = length;
  172633. png_crc_finish(png_ptr, skip);
  172634. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172635. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172636. #endif
  172637. }
  172638. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172639. void /* PRIVATE */
  172640. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172641. {
  172642. png_debug(1, "in png_check_chunk_name\n");
  172643. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172644. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172645. {
  172646. png_chunk_error(png_ptr, "invalid chunk type");
  172647. }
  172648. }
  172649. void /* PRIVATE */
  172650. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172651. {
  172652. png_debug(1,"in png_combine_row\n");
  172653. if (mask == 0xff)
  172654. {
  172655. png_memcpy(row, png_ptr->row_buf + 1,
  172656. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172657. }
  172658. else
  172659. {
  172660. switch (png_ptr->row_info.pixel_depth)
  172661. {
  172662. case 1:
  172663. {
  172664. png_bytep sp = png_ptr->row_buf + 1;
  172665. png_bytep dp = row;
  172666. int s_inc, s_start, s_end;
  172667. int m = 0x80;
  172668. int shift;
  172669. png_uint_32 i;
  172670. png_uint_32 row_width = png_ptr->width;
  172671. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172672. if (png_ptr->transformations & PNG_PACKSWAP)
  172673. {
  172674. s_start = 0;
  172675. s_end = 7;
  172676. s_inc = 1;
  172677. }
  172678. else
  172679. #endif
  172680. {
  172681. s_start = 7;
  172682. s_end = 0;
  172683. s_inc = -1;
  172684. }
  172685. shift = s_start;
  172686. for (i = 0; i < row_width; i++)
  172687. {
  172688. if (m & mask)
  172689. {
  172690. int value;
  172691. value = (*sp >> shift) & 0x01;
  172692. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172693. *dp |= (png_byte)(value << shift);
  172694. }
  172695. if (shift == s_end)
  172696. {
  172697. shift = s_start;
  172698. sp++;
  172699. dp++;
  172700. }
  172701. else
  172702. shift += s_inc;
  172703. if (m == 1)
  172704. m = 0x80;
  172705. else
  172706. m >>= 1;
  172707. }
  172708. break;
  172709. }
  172710. case 2:
  172711. {
  172712. png_bytep sp = png_ptr->row_buf + 1;
  172713. png_bytep dp = row;
  172714. int s_start, s_end, s_inc;
  172715. int m = 0x80;
  172716. int shift;
  172717. png_uint_32 i;
  172718. png_uint_32 row_width = png_ptr->width;
  172719. int value;
  172720. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172721. if (png_ptr->transformations & PNG_PACKSWAP)
  172722. {
  172723. s_start = 0;
  172724. s_end = 6;
  172725. s_inc = 2;
  172726. }
  172727. else
  172728. #endif
  172729. {
  172730. s_start = 6;
  172731. s_end = 0;
  172732. s_inc = -2;
  172733. }
  172734. shift = s_start;
  172735. for (i = 0; i < row_width; i++)
  172736. {
  172737. if (m & mask)
  172738. {
  172739. value = (*sp >> shift) & 0x03;
  172740. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172741. *dp |= (png_byte)(value << shift);
  172742. }
  172743. if (shift == s_end)
  172744. {
  172745. shift = s_start;
  172746. sp++;
  172747. dp++;
  172748. }
  172749. else
  172750. shift += s_inc;
  172751. if (m == 1)
  172752. m = 0x80;
  172753. else
  172754. m >>= 1;
  172755. }
  172756. break;
  172757. }
  172758. case 4:
  172759. {
  172760. png_bytep sp = png_ptr->row_buf + 1;
  172761. png_bytep dp = row;
  172762. int s_start, s_end, s_inc;
  172763. int m = 0x80;
  172764. int shift;
  172765. png_uint_32 i;
  172766. png_uint_32 row_width = png_ptr->width;
  172767. int value;
  172768. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172769. if (png_ptr->transformations & PNG_PACKSWAP)
  172770. {
  172771. s_start = 0;
  172772. s_end = 4;
  172773. s_inc = 4;
  172774. }
  172775. else
  172776. #endif
  172777. {
  172778. s_start = 4;
  172779. s_end = 0;
  172780. s_inc = -4;
  172781. }
  172782. shift = s_start;
  172783. for (i = 0; i < row_width; i++)
  172784. {
  172785. if (m & mask)
  172786. {
  172787. value = (*sp >> shift) & 0xf;
  172788. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172789. *dp |= (png_byte)(value << shift);
  172790. }
  172791. if (shift == s_end)
  172792. {
  172793. shift = s_start;
  172794. sp++;
  172795. dp++;
  172796. }
  172797. else
  172798. shift += s_inc;
  172799. if (m == 1)
  172800. m = 0x80;
  172801. else
  172802. m >>= 1;
  172803. }
  172804. break;
  172805. }
  172806. default:
  172807. {
  172808. png_bytep sp = png_ptr->row_buf + 1;
  172809. png_bytep dp = row;
  172810. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172811. png_uint_32 i;
  172812. png_uint_32 row_width = png_ptr->width;
  172813. png_byte m = 0x80;
  172814. for (i = 0; i < row_width; i++)
  172815. {
  172816. if (m & mask)
  172817. {
  172818. png_memcpy(dp, sp, pixel_bytes);
  172819. }
  172820. sp += pixel_bytes;
  172821. dp += pixel_bytes;
  172822. if (m == 1)
  172823. m = 0x80;
  172824. else
  172825. m >>= 1;
  172826. }
  172827. break;
  172828. }
  172829. }
  172830. }
  172831. }
  172832. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172833. void /* PRIVATE */
  172834. png_do_read_interlace(png_structp png_ptr)
  172835. {
  172836. png_row_infop row_info = &(png_ptr->row_info);
  172837. png_bytep row = png_ptr->row_buf + 1;
  172838. int pass = png_ptr->pass;
  172839. png_uint_32 transformations = png_ptr->transformations;
  172840. #ifdef PNG_USE_LOCAL_ARRAYS
  172841. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172842. #endif
  172843. png_debug(1,"in png_do_read_interlace\n");
  172844. if (row != NULL && row_info != NULL)
  172845. {
  172846. png_uint_32 final_width;
  172847. final_width = row_info->width * png_pass_inc[pass];
  172848. switch (row_info->pixel_depth)
  172849. {
  172850. case 1:
  172851. {
  172852. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172853. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172854. int sshift, dshift;
  172855. int s_start, s_end, s_inc;
  172856. int jstop = png_pass_inc[pass];
  172857. png_byte v;
  172858. png_uint_32 i;
  172859. int j;
  172860. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172861. if (transformations & PNG_PACKSWAP)
  172862. {
  172863. sshift = (int)((row_info->width + 7) & 0x07);
  172864. dshift = (int)((final_width + 7) & 0x07);
  172865. s_start = 7;
  172866. s_end = 0;
  172867. s_inc = -1;
  172868. }
  172869. else
  172870. #endif
  172871. {
  172872. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172873. dshift = 7 - (int)((final_width + 7) & 0x07);
  172874. s_start = 0;
  172875. s_end = 7;
  172876. s_inc = 1;
  172877. }
  172878. for (i = 0; i < row_info->width; i++)
  172879. {
  172880. v = (png_byte)((*sp >> sshift) & 0x01);
  172881. for (j = 0; j < jstop; j++)
  172882. {
  172883. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172884. *dp |= (png_byte)(v << dshift);
  172885. if (dshift == s_end)
  172886. {
  172887. dshift = s_start;
  172888. dp--;
  172889. }
  172890. else
  172891. dshift += s_inc;
  172892. }
  172893. if (sshift == s_end)
  172894. {
  172895. sshift = s_start;
  172896. sp--;
  172897. }
  172898. else
  172899. sshift += s_inc;
  172900. }
  172901. break;
  172902. }
  172903. case 2:
  172904. {
  172905. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172906. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172907. int sshift, dshift;
  172908. int s_start, s_end, s_inc;
  172909. int jstop = png_pass_inc[pass];
  172910. png_uint_32 i;
  172911. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172912. if (transformations & PNG_PACKSWAP)
  172913. {
  172914. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172915. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172916. s_start = 6;
  172917. s_end = 0;
  172918. s_inc = -2;
  172919. }
  172920. else
  172921. #endif
  172922. {
  172923. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172924. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172925. s_start = 0;
  172926. s_end = 6;
  172927. s_inc = 2;
  172928. }
  172929. for (i = 0; i < row_info->width; i++)
  172930. {
  172931. png_byte v;
  172932. int j;
  172933. v = (png_byte)((*sp >> sshift) & 0x03);
  172934. for (j = 0; j < jstop; j++)
  172935. {
  172936. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172937. *dp |= (png_byte)(v << dshift);
  172938. if (dshift == s_end)
  172939. {
  172940. dshift = s_start;
  172941. dp--;
  172942. }
  172943. else
  172944. dshift += s_inc;
  172945. }
  172946. if (sshift == s_end)
  172947. {
  172948. sshift = s_start;
  172949. sp--;
  172950. }
  172951. else
  172952. sshift += s_inc;
  172953. }
  172954. break;
  172955. }
  172956. case 4:
  172957. {
  172958. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  172959. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  172960. int sshift, dshift;
  172961. int s_start, s_end, s_inc;
  172962. png_uint_32 i;
  172963. int jstop = png_pass_inc[pass];
  172964. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172965. if (transformations & PNG_PACKSWAP)
  172966. {
  172967. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  172968. dshift = (int)(((final_width + 1) & 0x01) << 2);
  172969. s_start = 4;
  172970. s_end = 0;
  172971. s_inc = -4;
  172972. }
  172973. else
  172974. #endif
  172975. {
  172976. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  172977. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  172978. s_start = 0;
  172979. s_end = 4;
  172980. s_inc = 4;
  172981. }
  172982. for (i = 0; i < row_info->width; i++)
  172983. {
  172984. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  172985. int j;
  172986. for (j = 0; j < jstop; j++)
  172987. {
  172988. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  172989. *dp |= (png_byte)(v << dshift);
  172990. if (dshift == s_end)
  172991. {
  172992. dshift = s_start;
  172993. dp--;
  172994. }
  172995. else
  172996. dshift += s_inc;
  172997. }
  172998. if (sshift == s_end)
  172999. {
  173000. sshift = s_start;
  173001. sp--;
  173002. }
  173003. else
  173004. sshift += s_inc;
  173005. }
  173006. break;
  173007. }
  173008. default:
  173009. {
  173010. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  173011. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  173012. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  173013. int jstop = png_pass_inc[pass];
  173014. png_uint_32 i;
  173015. for (i = 0; i < row_info->width; i++)
  173016. {
  173017. png_byte v[8];
  173018. int j;
  173019. png_memcpy(v, sp, pixel_bytes);
  173020. for (j = 0; j < jstop; j++)
  173021. {
  173022. png_memcpy(dp, v, pixel_bytes);
  173023. dp -= pixel_bytes;
  173024. }
  173025. sp -= pixel_bytes;
  173026. }
  173027. break;
  173028. }
  173029. }
  173030. row_info->width = final_width;
  173031. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  173032. }
  173033. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173034. transformations = transformations; /* silence compiler warning */
  173035. #endif
  173036. }
  173037. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173038. void /* PRIVATE */
  173039. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173040. png_bytep prev_row, int filter)
  173041. {
  173042. png_debug(1, "in png_read_filter_row\n");
  173043. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173044. switch (filter)
  173045. {
  173046. case PNG_FILTER_VALUE_NONE:
  173047. break;
  173048. case PNG_FILTER_VALUE_SUB:
  173049. {
  173050. png_uint_32 i;
  173051. png_uint_32 istop = row_info->rowbytes;
  173052. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173053. png_bytep rp = row + bpp;
  173054. png_bytep lp = row;
  173055. for (i = bpp; i < istop; i++)
  173056. {
  173057. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173058. rp++;
  173059. }
  173060. break;
  173061. }
  173062. case PNG_FILTER_VALUE_UP:
  173063. {
  173064. png_uint_32 i;
  173065. png_uint_32 istop = row_info->rowbytes;
  173066. png_bytep rp = row;
  173067. png_bytep pp = prev_row;
  173068. for (i = 0; i < istop; i++)
  173069. {
  173070. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173071. rp++;
  173072. }
  173073. break;
  173074. }
  173075. case PNG_FILTER_VALUE_AVG:
  173076. {
  173077. png_uint_32 i;
  173078. png_bytep rp = row;
  173079. png_bytep pp = prev_row;
  173080. png_bytep lp = row;
  173081. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173082. png_uint_32 istop = row_info->rowbytes - bpp;
  173083. for (i = 0; i < bpp; i++)
  173084. {
  173085. *rp = (png_byte)(((int)(*rp) +
  173086. ((int)(*pp++) / 2 )) & 0xff);
  173087. rp++;
  173088. }
  173089. for (i = 0; i < istop; i++)
  173090. {
  173091. *rp = (png_byte)(((int)(*rp) +
  173092. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173093. rp++;
  173094. }
  173095. break;
  173096. }
  173097. case PNG_FILTER_VALUE_PAETH:
  173098. {
  173099. png_uint_32 i;
  173100. png_bytep rp = row;
  173101. png_bytep pp = prev_row;
  173102. png_bytep lp = row;
  173103. png_bytep cp = prev_row;
  173104. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173105. png_uint_32 istop=row_info->rowbytes - bpp;
  173106. for (i = 0; i < bpp; i++)
  173107. {
  173108. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173109. rp++;
  173110. }
  173111. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173112. {
  173113. int a, b, c, pa, pb, pc, p;
  173114. a = *lp++;
  173115. b = *pp++;
  173116. c = *cp++;
  173117. p = b - c;
  173118. pc = a - c;
  173119. #ifdef PNG_USE_ABS
  173120. pa = abs(p);
  173121. pb = abs(pc);
  173122. pc = abs(p + pc);
  173123. #else
  173124. pa = p < 0 ? -p : p;
  173125. pb = pc < 0 ? -pc : pc;
  173126. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173127. #endif
  173128. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173129. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173130. rp++;
  173131. }
  173132. break;
  173133. }
  173134. default:
  173135. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173136. *row=0;
  173137. break;
  173138. }
  173139. }
  173140. void /* PRIVATE */
  173141. png_read_finish_row(png_structp png_ptr)
  173142. {
  173143. #ifdef PNG_USE_LOCAL_ARRAYS
  173144. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173145. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173146. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173147. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173148. #endif
  173149. png_debug(1, "in png_read_finish_row\n");
  173150. png_ptr->row_number++;
  173151. if (png_ptr->row_number < png_ptr->num_rows)
  173152. return;
  173153. if (png_ptr->interlaced)
  173154. {
  173155. png_ptr->row_number = 0;
  173156. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173157. png_ptr->rowbytes + 1);
  173158. do
  173159. {
  173160. png_ptr->pass++;
  173161. if (png_ptr->pass >= 7)
  173162. break;
  173163. png_ptr->iwidth = (png_ptr->width +
  173164. png_pass_inc[png_ptr->pass] - 1 -
  173165. png_pass_start[png_ptr->pass]) /
  173166. png_pass_inc[png_ptr->pass];
  173167. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173168. png_ptr->iwidth) + 1;
  173169. if (!(png_ptr->transformations & PNG_INTERLACE))
  173170. {
  173171. png_ptr->num_rows = (png_ptr->height +
  173172. png_pass_yinc[png_ptr->pass] - 1 -
  173173. png_pass_ystart[png_ptr->pass]) /
  173174. png_pass_yinc[png_ptr->pass];
  173175. if (!(png_ptr->num_rows))
  173176. continue;
  173177. }
  173178. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173179. break;
  173180. } while (png_ptr->iwidth == 0);
  173181. if (png_ptr->pass < 7)
  173182. return;
  173183. }
  173184. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173185. {
  173186. #ifdef PNG_USE_LOCAL_ARRAYS
  173187. PNG_CONST PNG_IDAT;
  173188. #endif
  173189. char extra;
  173190. int ret;
  173191. png_ptr->zstream.next_out = (Bytef *)&extra;
  173192. png_ptr->zstream.avail_out = (uInt)1;
  173193. for(;;)
  173194. {
  173195. if (!(png_ptr->zstream.avail_in))
  173196. {
  173197. while (!png_ptr->idat_size)
  173198. {
  173199. png_byte chunk_length[4];
  173200. png_crc_finish(png_ptr, 0);
  173201. png_read_data(png_ptr, chunk_length, 4);
  173202. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173203. png_reset_crc(png_ptr);
  173204. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173205. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173206. png_error(png_ptr, "Not enough image data");
  173207. }
  173208. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173209. png_ptr->zstream.next_in = png_ptr->zbuf;
  173210. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173211. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173212. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173213. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173214. }
  173215. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173216. if (ret == Z_STREAM_END)
  173217. {
  173218. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173219. png_ptr->idat_size)
  173220. png_warning(png_ptr, "Extra compressed data");
  173221. png_ptr->mode |= PNG_AFTER_IDAT;
  173222. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173223. break;
  173224. }
  173225. if (ret != Z_OK)
  173226. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173227. "Decompression Error");
  173228. if (!(png_ptr->zstream.avail_out))
  173229. {
  173230. png_warning(png_ptr, "Extra compressed data.");
  173231. png_ptr->mode |= PNG_AFTER_IDAT;
  173232. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173233. break;
  173234. }
  173235. }
  173236. png_ptr->zstream.avail_out = 0;
  173237. }
  173238. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173239. png_warning(png_ptr, "Extra compression data");
  173240. inflateReset(&png_ptr->zstream);
  173241. png_ptr->mode |= PNG_AFTER_IDAT;
  173242. }
  173243. void /* PRIVATE */
  173244. png_read_start_row(png_structp png_ptr)
  173245. {
  173246. #ifdef PNG_USE_LOCAL_ARRAYS
  173247. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173248. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173249. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173250. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173251. #endif
  173252. int max_pixel_depth;
  173253. png_uint_32 row_bytes;
  173254. png_debug(1, "in png_read_start_row\n");
  173255. png_ptr->zstream.avail_in = 0;
  173256. png_init_read_transformations(png_ptr);
  173257. if (png_ptr->interlaced)
  173258. {
  173259. if (!(png_ptr->transformations & PNG_INTERLACE))
  173260. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173261. png_pass_ystart[0]) / png_pass_yinc[0];
  173262. else
  173263. png_ptr->num_rows = png_ptr->height;
  173264. png_ptr->iwidth = (png_ptr->width +
  173265. png_pass_inc[png_ptr->pass] - 1 -
  173266. png_pass_start[png_ptr->pass]) /
  173267. png_pass_inc[png_ptr->pass];
  173268. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173269. png_ptr->irowbytes = (png_size_t)row_bytes;
  173270. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173271. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173272. }
  173273. else
  173274. {
  173275. png_ptr->num_rows = png_ptr->height;
  173276. png_ptr->iwidth = png_ptr->width;
  173277. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173278. }
  173279. max_pixel_depth = png_ptr->pixel_depth;
  173280. #if defined(PNG_READ_PACK_SUPPORTED)
  173281. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173282. max_pixel_depth = 8;
  173283. #endif
  173284. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173285. if (png_ptr->transformations & PNG_EXPAND)
  173286. {
  173287. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173288. {
  173289. if (png_ptr->num_trans)
  173290. max_pixel_depth = 32;
  173291. else
  173292. max_pixel_depth = 24;
  173293. }
  173294. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173295. {
  173296. if (max_pixel_depth < 8)
  173297. max_pixel_depth = 8;
  173298. if (png_ptr->num_trans)
  173299. max_pixel_depth *= 2;
  173300. }
  173301. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173302. {
  173303. if (png_ptr->num_trans)
  173304. {
  173305. max_pixel_depth *= 4;
  173306. max_pixel_depth /= 3;
  173307. }
  173308. }
  173309. }
  173310. #endif
  173311. #if defined(PNG_READ_FILLER_SUPPORTED)
  173312. if (png_ptr->transformations & (PNG_FILLER))
  173313. {
  173314. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173315. max_pixel_depth = 32;
  173316. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173317. {
  173318. if (max_pixel_depth <= 8)
  173319. max_pixel_depth = 16;
  173320. else
  173321. max_pixel_depth = 32;
  173322. }
  173323. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173324. {
  173325. if (max_pixel_depth <= 32)
  173326. max_pixel_depth = 32;
  173327. else
  173328. max_pixel_depth = 64;
  173329. }
  173330. }
  173331. #endif
  173332. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173333. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173334. {
  173335. if (
  173336. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173337. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173338. #endif
  173339. #if defined(PNG_READ_FILLER_SUPPORTED)
  173340. (png_ptr->transformations & (PNG_FILLER)) ||
  173341. #endif
  173342. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173343. {
  173344. if (max_pixel_depth <= 16)
  173345. max_pixel_depth = 32;
  173346. else
  173347. max_pixel_depth = 64;
  173348. }
  173349. else
  173350. {
  173351. if (max_pixel_depth <= 8)
  173352. {
  173353. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173354. max_pixel_depth = 32;
  173355. else
  173356. max_pixel_depth = 24;
  173357. }
  173358. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173359. max_pixel_depth = 64;
  173360. else
  173361. max_pixel_depth = 48;
  173362. }
  173363. }
  173364. #endif
  173365. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173366. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173367. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173368. {
  173369. int user_pixel_depth=png_ptr->user_transform_depth*
  173370. png_ptr->user_transform_channels;
  173371. if(user_pixel_depth > max_pixel_depth)
  173372. max_pixel_depth=user_pixel_depth;
  173373. }
  173374. #endif
  173375. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173376. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173377. 1 + ((max_pixel_depth + 7) >> 3);
  173378. #ifdef PNG_MAX_MALLOC_64K
  173379. if (row_bytes > (png_uint_32)65536L)
  173380. png_error(png_ptr, "This image requires a row greater than 64KB");
  173381. #endif
  173382. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173383. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173384. #ifdef PNG_MAX_MALLOC_64K
  173385. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173386. png_error(png_ptr, "This image requires a row greater than 64KB");
  173387. #endif
  173388. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173389. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173390. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173391. png_ptr->rowbytes + 1));
  173392. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173393. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173394. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173395. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173396. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173397. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173398. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173399. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173400. }
  173401. #endif /* PNG_READ_SUPPORTED */
  173402. /*** End of inlined file: pngrutil.c ***/
  173403. /*** Start of inlined file: pngset.c ***/
  173404. #define PNG_INTERNAL
  173405. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173406. #if defined(PNG_bKGD_SUPPORTED)
  173407. void PNGAPI
  173408. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173409. {
  173410. png_debug1(1, "in %s storage function\n", "bKGD");
  173411. if (png_ptr == NULL || info_ptr == NULL)
  173412. return;
  173413. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173414. info_ptr->valid |= PNG_INFO_bKGD;
  173415. }
  173416. #endif
  173417. #if defined(PNG_cHRM_SUPPORTED)
  173418. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173419. void PNGAPI
  173420. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173421. double white_x, double white_y, double red_x, double red_y,
  173422. double green_x, double green_y, double blue_x, double blue_y)
  173423. {
  173424. png_debug1(1, "in %s storage function\n", "cHRM");
  173425. if (png_ptr == NULL || info_ptr == NULL)
  173426. return;
  173427. if (white_x < 0.0 || white_y < 0.0 ||
  173428. red_x < 0.0 || red_y < 0.0 ||
  173429. green_x < 0.0 || green_y < 0.0 ||
  173430. blue_x < 0.0 || blue_y < 0.0)
  173431. {
  173432. png_warning(png_ptr,
  173433. "Ignoring attempt to set negative chromaticity value");
  173434. return;
  173435. }
  173436. if (white_x > 21474.83 || white_y > 21474.83 ||
  173437. red_x > 21474.83 || red_y > 21474.83 ||
  173438. green_x > 21474.83 || green_y > 21474.83 ||
  173439. blue_x > 21474.83 || blue_y > 21474.83)
  173440. {
  173441. png_warning(png_ptr,
  173442. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173443. return;
  173444. }
  173445. info_ptr->x_white = (float)white_x;
  173446. info_ptr->y_white = (float)white_y;
  173447. info_ptr->x_red = (float)red_x;
  173448. info_ptr->y_red = (float)red_y;
  173449. info_ptr->x_green = (float)green_x;
  173450. info_ptr->y_green = (float)green_y;
  173451. info_ptr->x_blue = (float)blue_x;
  173452. info_ptr->y_blue = (float)blue_y;
  173453. #ifdef PNG_FIXED_POINT_SUPPORTED
  173454. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173455. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173456. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173457. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173458. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173459. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173460. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173461. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173462. #endif
  173463. info_ptr->valid |= PNG_INFO_cHRM;
  173464. }
  173465. #endif
  173466. #ifdef PNG_FIXED_POINT_SUPPORTED
  173467. void PNGAPI
  173468. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173469. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173470. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173471. png_fixed_point blue_x, png_fixed_point blue_y)
  173472. {
  173473. png_debug1(1, "in %s storage function\n", "cHRM");
  173474. if (png_ptr == NULL || info_ptr == NULL)
  173475. return;
  173476. if (white_x < 0 || white_y < 0 ||
  173477. red_x < 0 || red_y < 0 ||
  173478. green_x < 0 || green_y < 0 ||
  173479. blue_x < 0 || blue_y < 0)
  173480. {
  173481. png_warning(png_ptr,
  173482. "Ignoring attempt to set negative chromaticity value");
  173483. return;
  173484. }
  173485. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173486. if (white_x > (double) PNG_UINT_31_MAX ||
  173487. white_y > (double) PNG_UINT_31_MAX ||
  173488. red_x > (double) PNG_UINT_31_MAX ||
  173489. red_y > (double) PNG_UINT_31_MAX ||
  173490. green_x > (double) PNG_UINT_31_MAX ||
  173491. green_y > (double) PNG_UINT_31_MAX ||
  173492. blue_x > (double) PNG_UINT_31_MAX ||
  173493. blue_y > (double) PNG_UINT_31_MAX)
  173494. #else
  173495. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173496. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173497. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173498. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173499. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173500. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173501. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173502. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173503. #endif
  173504. {
  173505. png_warning(png_ptr,
  173506. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173507. return;
  173508. }
  173509. info_ptr->int_x_white = white_x;
  173510. info_ptr->int_y_white = white_y;
  173511. info_ptr->int_x_red = red_x;
  173512. info_ptr->int_y_red = red_y;
  173513. info_ptr->int_x_green = green_x;
  173514. info_ptr->int_y_green = green_y;
  173515. info_ptr->int_x_blue = blue_x;
  173516. info_ptr->int_y_blue = blue_y;
  173517. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173518. info_ptr->x_white = (float)(white_x/100000.);
  173519. info_ptr->y_white = (float)(white_y/100000.);
  173520. info_ptr->x_red = (float)( red_x/100000.);
  173521. info_ptr->y_red = (float)( red_y/100000.);
  173522. info_ptr->x_green = (float)(green_x/100000.);
  173523. info_ptr->y_green = (float)(green_y/100000.);
  173524. info_ptr->x_blue = (float)( blue_x/100000.);
  173525. info_ptr->y_blue = (float)( blue_y/100000.);
  173526. #endif
  173527. info_ptr->valid |= PNG_INFO_cHRM;
  173528. }
  173529. #endif
  173530. #endif
  173531. #if defined(PNG_gAMA_SUPPORTED)
  173532. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173533. void PNGAPI
  173534. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173535. {
  173536. double gamma;
  173537. png_debug1(1, "in %s storage function\n", "gAMA");
  173538. if (png_ptr == NULL || info_ptr == NULL)
  173539. return;
  173540. if (file_gamma > 21474.83)
  173541. {
  173542. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173543. gamma=21474.83;
  173544. }
  173545. else
  173546. gamma=file_gamma;
  173547. info_ptr->gamma = (float)gamma;
  173548. #ifdef PNG_FIXED_POINT_SUPPORTED
  173549. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173550. #endif
  173551. info_ptr->valid |= PNG_INFO_gAMA;
  173552. if(gamma == 0.0)
  173553. png_warning(png_ptr, "Setting gamma=0");
  173554. }
  173555. #endif
  173556. void PNGAPI
  173557. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173558. int_gamma)
  173559. {
  173560. png_fixed_point gamma;
  173561. png_debug1(1, "in %s storage function\n", "gAMA");
  173562. if (png_ptr == NULL || info_ptr == NULL)
  173563. return;
  173564. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173565. {
  173566. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173567. gamma=PNG_UINT_31_MAX;
  173568. }
  173569. else
  173570. {
  173571. if (int_gamma < 0)
  173572. {
  173573. png_warning(png_ptr, "Setting negative gamma to zero");
  173574. gamma=0;
  173575. }
  173576. else
  173577. gamma=int_gamma;
  173578. }
  173579. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173580. info_ptr->gamma = (float)(gamma/100000.);
  173581. #endif
  173582. #ifdef PNG_FIXED_POINT_SUPPORTED
  173583. info_ptr->int_gamma = gamma;
  173584. #endif
  173585. info_ptr->valid |= PNG_INFO_gAMA;
  173586. if(gamma == 0)
  173587. png_warning(png_ptr, "Setting gamma=0");
  173588. }
  173589. #endif
  173590. #if defined(PNG_hIST_SUPPORTED)
  173591. void PNGAPI
  173592. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173593. {
  173594. int i;
  173595. png_debug1(1, "in %s storage function\n", "hIST");
  173596. if (png_ptr == NULL || info_ptr == NULL)
  173597. return;
  173598. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173599. > PNG_MAX_PALETTE_LENGTH)
  173600. {
  173601. png_warning(png_ptr,
  173602. "Invalid palette size, hIST allocation skipped.");
  173603. return;
  173604. }
  173605. #ifdef PNG_FREE_ME_SUPPORTED
  173606. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173607. #endif
  173608. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173609. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173610. if (png_ptr->hist == NULL)
  173611. {
  173612. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173613. return;
  173614. }
  173615. for (i = 0; i < info_ptr->num_palette; i++)
  173616. png_ptr->hist[i] = hist[i];
  173617. info_ptr->hist = png_ptr->hist;
  173618. info_ptr->valid |= PNG_INFO_hIST;
  173619. #ifdef PNG_FREE_ME_SUPPORTED
  173620. info_ptr->free_me |= PNG_FREE_HIST;
  173621. #else
  173622. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173623. #endif
  173624. }
  173625. #endif
  173626. void PNGAPI
  173627. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173628. png_uint_32 width, png_uint_32 height, int bit_depth,
  173629. int color_type, int interlace_type, int compression_type,
  173630. int filter_type)
  173631. {
  173632. png_debug1(1, "in %s storage function\n", "IHDR");
  173633. if (png_ptr == NULL || info_ptr == NULL)
  173634. return;
  173635. if (width == 0 || height == 0)
  173636. png_error(png_ptr, "Image width or height is zero in IHDR");
  173637. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173638. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173639. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173640. #else
  173641. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173642. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173643. #endif
  173644. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173645. png_error(png_ptr, "Invalid image size in IHDR");
  173646. if ( width > (PNG_UINT_32_MAX
  173647. >> 3) /* 8-byte RGBA pixels */
  173648. - 64 /* bigrowbuf hack */
  173649. - 1 /* filter byte */
  173650. - 7*8 /* rounding of width to multiple of 8 pixels */
  173651. - 8) /* extra max_pixel_depth pad */
  173652. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173653. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173654. bit_depth != 8 && bit_depth != 16)
  173655. png_error(png_ptr, "Invalid bit depth in IHDR");
  173656. if (color_type < 0 || color_type == 1 ||
  173657. color_type == 5 || color_type > 6)
  173658. png_error(png_ptr, "Invalid color type in IHDR");
  173659. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173660. ((color_type == PNG_COLOR_TYPE_RGB ||
  173661. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173662. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173663. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173664. if (interlace_type >= PNG_INTERLACE_LAST)
  173665. png_error(png_ptr, "Unknown interlace method in IHDR");
  173666. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173667. png_error(png_ptr, "Unknown compression method in IHDR");
  173668. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173669. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173670. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173671. if(filter_type != PNG_FILTER_TYPE_BASE)
  173672. {
  173673. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173674. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173675. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173676. (color_type == PNG_COLOR_TYPE_RGB ||
  173677. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173678. png_error(png_ptr, "Unknown filter method in IHDR");
  173679. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173680. png_warning(png_ptr, "Invalid filter method in IHDR");
  173681. }
  173682. #else
  173683. if(filter_type != PNG_FILTER_TYPE_BASE)
  173684. png_error(png_ptr, "Unknown filter method in IHDR");
  173685. #endif
  173686. info_ptr->width = width;
  173687. info_ptr->height = height;
  173688. info_ptr->bit_depth = (png_byte)bit_depth;
  173689. info_ptr->color_type =(png_byte) color_type;
  173690. info_ptr->compression_type = (png_byte)compression_type;
  173691. info_ptr->filter_type = (png_byte)filter_type;
  173692. info_ptr->interlace_type = (png_byte)interlace_type;
  173693. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173694. info_ptr->channels = 1;
  173695. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173696. info_ptr->channels = 3;
  173697. else
  173698. info_ptr->channels = 1;
  173699. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173700. info_ptr->channels++;
  173701. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173702. if (width > (PNG_UINT_32_MAX
  173703. >> 3) /* 8-byte RGBA pixels */
  173704. - 64 /* bigrowbuf hack */
  173705. - 1 /* filter byte */
  173706. - 7*8 /* rounding of width to multiple of 8 pixels */
  173707. - 8) /* extra max_pixel_depth pad */
  173708. info_ptr->rowbytes = (png_size_t)0;
  173709. else
  173710. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173711. }
  173712. #if defined(PNG_oFFs_SUPPORTED)
  173713. void PNGAPI
  173714. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173715. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173716. {
  173717. png_debug1(1, "in %s storage function\n", "oFFs");
  173718. if (png_ptr == NULL || info_ptr == NULL)
  173719. return;
  173720. info_ptr->x_offset = offset_x;
  173721. info_ptr->y_offset = offset_y;
  173722. info_ptr->offset_unit_type = (png_byte)unit_type;
  173723. info_ptr->valid |= PNG_INFO_oFFs;
  173724. }
  173725. #endif
  173726. #if defined(PNG_pCAL_SUPPORTED)
  173727. void PNGAPI
  173728. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173729. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173730. png_charp units, png_charpp params)
  173731. {
  173732. png_uint_32 length;
  173733. int i;
  173734. png_debug1(1, "in %s storage function\n", "pCAL");
  173735. if (png_ptr == NULL || info_ptr == NULL)
  173736. return;
  173737. length = png_strlen(purpose) + 1;
  173738. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173739. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173740. if (info_ptr->pcal_purpose == NULL)
  173741. {
  173742. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173743. return;
  173744. }
  173745. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173746. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173747. info_ptr->pcal_X0 = X0;
  173748. info_ptr->pcal_X1 = X1;
  173749. info_ptr->pcal_type = (png_byte)type;
  173750. info_ptr->pcal_nparams = (png_byte)nparams;
  173751. length = png_strlen(units) + 1;
  173752. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173753. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173754. if (info_ptr->pcal_units == NULL)
  173755. {
  173756. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173757. return;
  173758. }
  173759. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173760. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173761. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173762. if (info_ptr->pcal_params == NULL)
  173763. {
  173764. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173765. return;
  173766. }
  173767. info_ptr->pcal_params[nparams] = NULL;
  173768. for (i = 0; i < nparams; i++)
  173769. {
  173770. length = png_strlen(params[i]) + 1;
  173771. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173772. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173773. if (info_ptr->pcal_params[i] == NULL)
  173774. {
  173775. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173776. return;
  173777. }
  173778. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173779. }
  173780. info_ptr->valid |= PNG_INFO_pCAL;
  173781. #ifdef PNG_FREE_ME_SUPPORTED
  173782. info_ptr->free_me |= PNG_FREE_PCAL;
  173783. #endif
  173784. }
  173785. #endif
  173786. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173787. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173788. void PNGAPI
  173789. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173790. int unit, double width, double height)
  173791. {
  173792. png_debug1(1, "in %s storage function\n", "sCAL");
  173793. if (png_ptr == NULL || info_ptr == NULL)
  173794. return;
  173795. info_ptr->scal_unit = (png_byte)unit;
  173796. info_ptr->scal_pixel_width = width;
  173797. info_ptr->scal_pixel_height = height;
  173798. info_ptr->valid |= PNG_INFO_sCAL;
  173799. }
  173800. #else
  173801. #ifdef PNG_FIXED_POINT_SUPPORTED
  173802. void PNGAPI
  173803. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173804. int unit, png_charp swidth, png_charp sheight)
  173805. {
  173806. png_uint_32 length;
  173807. png_debug1(1, "in %s storage function\n", "sCAL");
  173808. if (png_ptr == NULL || info_ptr == NULL)
  173809. return;
  173810. info_ptr->scal_unit = (png_byte)unit;
  173811. length = png_strlen(swidth) + 1;
  173812. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173813. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173814. if (info_ptr->scal_s_width == NULL)
  173815. {
  173816. png_warning(png_ptr,
  173817. "Memory allocation failed while processing sCAL.");
  173818. }
  173819. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173820. length = png_strlen(sheight) + 1;
  173821. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173822. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173823. if (info_ptr->scal_s_height == NULL)
  173824. {
  173825. png_free (png_ptr, info_ptr->scal_s_width);
  173826. png_warning(png_ptr,
  173827. "Memory allocation failed while processing sCAL.");
  173828. }
  173829. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173830. info_ptr->valid |= PNG_INFO_sCAL;
  173831. #ifdef PNG_FREE_ME_SUPPORTED
  173832. info_ptr->free_me |= PNG_FREE_SCAL;
  173833. #endif
  173834. }
  173835. #endif
  173836. #endif
  173837. #endif
  173838. #if defined(PNG_pHYs_SUPPORTED)
  173839. void PNGAPI
  173840. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173841. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173842. {
  173843. png_debug1(1, "in %s storage function\n", "pHYs");
  173844. if (png_ptr == NULL || info_ptr == NULL)
  173845. return;
  173846. info_ptr->x_pixels_per_unit = res_x;
  173847. info_ptr->y_pixels_per_unit = res_y;
  173848. info_ptr->phys_unit_type = (png_byte)unit_type;
  173849. info_ptr->valid |= PNG_INFO_pHYs;
  173850. }
  173851. #endif
  173852. void PNGAPI
  173853. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173854. png_colorp palette, int num_palette)
  173855. {
  173856. png_debug1(1, "in %s storage function\n", "PLTE");
  173857. if (png_ptr == NULL || info_ptr == NULL)
  173858. return;
  173859. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173860. {
  173861. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173862. png_error(png_ptr, "Invalid palette length");
  173863. else
  173864. {
  173865. png_warning(png_ptr, "Invalid palette length");
  173866. return;
  173867. }
  173868. }
  173869. #ifdef PNG_FREE_ME_SUPPORTED
  173870. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173871. #endif
  173872. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173873. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173874. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173875. png_sizeof(png_color));
  173876. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173877. info_ptr->palette = png_ptr->palette;
  173878. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173879. #ifdef PNG_FREE_ME_SUPPORTED
  173880. info_ptr->free_me |= PNG_FREE_PLTE;
  173881. #else
  173882. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173883. #endif
  173884. info_ptr->valid |= PNG_INFO_PLTE;
  173885. }
  173886. #if defined(PNG_sBIT_SUPPORTED)
  173887. void PNGAPI
  173888. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173889. png_color_8p sig_bit)
  173890. {
  173891. png_debug1(1, "in %s storage function\n", "sBIT");
  173892. if (png_ptr == NULL || info_ptr == NULL)
  173893. return;
  173894. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173895. info_ptr->valid |= PNG_INFO_sBIT;
  173896. }
  173897. #endif
  173898. #if defined(PNG_sRGB_SUPPORTED)
  173899. void PNGAPI
  173900. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173901. {
  173902. png_debug1(1, "in %s storage function\n", "sRGB");
  173903. if (png_ptr == NULL || info_ptr == NULL)
  173904. return;
  173905. info_ptr->srgb_intent = (png_byte)intent;
  173906. info_ptr->valid |= PNG_INFO_sRGB;
  173907. }
  173908. void PNGAPI
  173909. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173910. int intent)
  173911. {
  173912. #if defined(PNG_gAMA_SUPPORTED)
  173913. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173914. float file_gamma;
  173915. #endif
  173916. #ifdef PNG_FIXED_POINT_SUPPORTED
  173917. png_fixed_point int_file_gamma;
  173918. #endif
  173919. #endif
  173920. #if defined(PNG_cHRM_SUPPORTED)
  173921. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173922. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173923. #endif
  173924. #ifdef PNG_FIXED_POINT_SUPPORTED
  173925. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173926. int_green_y, int_blue_x, int_blue_y;
  173927. #endif
  173928. #endif
  173929. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173930. if (png_ptr == NULL || info_ptr == NULL)
  173931. return;
  173932. png_set_sRGB(png_ptr, info_ptr, intent);
  173933. #if defined(PNG_gAMA_SUPPORTED)
  173934. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173935. file_gamma = (float).45455;
  173936. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173937. #endif
  173938. #ifdef PNG_FIXED_POINT_SUPPORTED
  173939. int_file_gamma = 45455L;
  173940. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173941. #endif
  173942. #endif
  173943. #if defined(PNG_cHRM_SUPPORTED)
  173944. #ifdef PNG_FIXED_POINT_SUPPORTED
  173945. int_white_x = 31270L;
  173946. int_white_y = 32900L;
  173947. int_red_x = 64000L;
  173948. int_red_y = 33000L;
  173949. int_green_x = 30000L;
  173950. int_green_y = 60000L;
  173951. int_blue_x = 15000L;
  173952. int_blue_y = 6000L;
  173953. png_set_cHRM_fixed(png_ptr, info_ptr,
  173954. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  173955. int_blue_x, int_blue_y);
  173956. #endif
  173957. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173958. white_x = (float).3127;
  173959. white_y = (float).3290;
  173960. red_x = (float).64;
  173961. red_y = (float).33;
  173962. green_x = (float).30;
  173963. green_y = (float).60;
  173964. blue_x = (float).15;
  173965. blue_y = (float).06;
  173966. png_set_cHRM(png_ptr, info_ptr,
  173967. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  173968. #endif
  173969. #endif
  173970. }
  173971. #endif
  173972. #if defined(PNG_iCCP_SUPPORTED)
  173973. void PNGAPI
  173974. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  173975. png_charp name, int compression_type,
  173976. png_charp profile, png_uint_32 proflen)
  173977. {
  173978. png_charp new_iccp_name;
  173979. png_charp new_iccp_profile;
  173980. png_debug1(1, "in %s storage function\n", "iCCP");
  173981. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  173982. return;
  173983. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  173984. if (new_iccp_name == NULL)
  173985. {
  173986. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  173987. return;
  173988. }
  173989. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  173990. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  173991. if (new_iccp_profile == NULL)
  173992. {
  173993. png_free (png_ptr, new_iccp_name);
  173994. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  173995. return;
  173996. }
  173997. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  173998. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  173999. info_ptr->iccp_proflen = proflen;
  174000. info_ptr->iccp_name = new_iccp_name;
  174001. info_ptr->iccp_profile = new_iccp_profile;
  174002. info_ptr->iccp_compression = (png_byte)compression_type;
  174003. #ifdef PNG_FREE_ME_SUPPORTED
  174004. info_ptr->free_me |= PNG_FREE_ICCP;
  174005. #endif
  174006. info_ptr->valid |= PNG_INFO_iCCP;
  174007. }
  174008. #endif
  174009. #if defined(PNG_TEXT_SUPPORTED)
  174010. void PNGAPI
  174011. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174012. int num_text)
  174013. {
  174014. int ret;
  174015. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  174016. if (ret)
  174017. png_error(png_ptr, "Insufficient memory to store text");
  174018. }
  174019. int /* PRIVATE */
  174020. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174021. int num_text)
  174022. {
  174023. int i;
  174024. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  174025. "text" : (png_const_charp)png_ptr->chunk_name));
  174026. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  174027. return(0);
  174028. if (info_ptr->num_text + num_text > info_ptr->max_text)
  174029. {
  174030. if (info_ptr->text != NULL)
  174031. {
  174032. png_textp old_text;
  174033. int old_max;
  174034. old_max = info_ptr->max_text;
  174035. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174036. old_text = info_ptr->text;
  174037. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174038. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174039. if (info_ptr->text == NULL)
  174040. {
  174041. png_free(png_ptr, old_text);
  174042. return(1);
  174043. }
  174044. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174045. png_sizeof(png_text)));
  174046. png_free(png_ptr, old_text);
  174047. }
  174048. else
  174049. {
  174050. info_ptr->max_text = num_text + 8;
  174051. info_ptr->num_text = 0;
  174052. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174053. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174054. if (info_ptr->text == NULL)
  174055. return(1);
  174056. #ifdef PNG_FREE_ME_SUPPORTED
  174057. info_ptr->free_me |= PNG_FREE_TEXT;
  174058. #endif
  174059. }
  174060. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174061. info_ptr->max_text);
  174062. }
  174063. for (i = 0; i < num_text; i++)
  174064. {
  174065. png_size_t text_length,key_len;
  174066. png_size_t lang_len,lang_key_len;
  174067. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174068. if (text_ptr[i].key == NULL)
  174069. continue;
  174070. key_len = png_strlen(text_ptr[i].key);
  174071. if(text_ptr[i].compression <= 0)
  174072. {
  174073. lang_len = 0;
  174074. lang_key_len = 0;
  174075. }
  174076. else
  174077. #ifdef PNG_iTXt_SUPPORTED
  174078. {
  174079. if (text_ptr[i].lang != NULL)
  174080. lang_len = png_strlen(text_ptr[i].lang);
  174081. else
  174082. lang_len = 0;
  174083. if (text_ptr[i].lang_key != NULL)
  174084. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174085. else
  174086. lang_key_len = 0;
  174087. }
  174088. #else
  174089. {
  174090. png_warning(png_ptr, "iTXt chunk not supported.");
  174091. continue;
  174092. }
  174093. #endif
  174094. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174095. {
  174096. text_length = 0;
  174097. #ifdef PNG_iTXt_SUPPORTED
  174098. if(text_ptr[i].compression > 0)
  174099. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174100. else
  174101. #endif
  174102. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174103. }
  174104. else
  174105. {
  174106. text_length = png_strlen(text_ptr[i].text);
  174107. textp->compression = text_ptr[i].compression;
  174108. }
  174109. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174110. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174111. if (textp->key == NULL)
  174112. return(1);
  174113. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174114. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174115. (int)textp->key);
  174116. png_memcpy(textp->key, text_ptr[i].key,
  174117. (png_size_t)(key_len));
  174118. *(textp->key+key_len) = '\0';
  174119. #ifdef PNG_iTXt_SUPPORTED
  174120. if (text_ptr[i].compression > 0)
  174121. {
  174122. textp->lang=textp->key + key_len + 1;
  174123. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174124. *(textp->lang+lang_len) = '\0';
  174125. textp->lang_key=textp->lang + lang_len + 1;
  174126. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174127. *(textp->lang_key+lang_key_len) = '\0';
  174128. textp->text=textp->lang_key + lang_key_len + 1;
  174129. }
  174130. else
  174131. #endif
  174132. {
  174133. #ifdef PNG_iTXt_SUPPORTED
  174134. textp->lang=NULL;
  174135. textp->lang_key=NULL;
  174136. #endif
  174137. textp->text=textp->key + key_len + 1;
  174138. }
  174139. if(text_length)
  174140. png_memcpy(textp->text, text_ptr[i].text,
  174141. (png_size_t)(text_length));
  174142. *(textp->text+text_length) = '\0';
  174143. #ifdef PNG_iTXt_SUPPORTED
  174144. if(textp->compression > 0)
  174145. {
  174146. textp->text_length = 0;
  174147. textp->itxt_length = text_length;
  174148. }
  174149. else
  174150. #endif
  174151. {
  174152. textp->text_length = text_length;
  174153. #ifdef PNG_iTXt_SUPPORTED
  174154. textp->itxt_length = 0;
  174155. #endif
  174156. }
  174157. info_ptr->num_text++;
  174158. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174159. }
  174160. return(0);
  174161. }
  174162. #endif
  174163. #if defined(PNG_tIME_SUPPORTED)
  174164. void PNGAPI
  174165. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174166. {
  174167. png_debug1(1, "in %s storage function\n", "tIME");
  174168. if (png_ptr == NULL || info_ptr == NULL ||
  174169. (png_ptr->mode & PNG_WROTE_tIME))
  174170. return;
  174171. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174172. info_ptr->valid |= PNG_INFO_tIME;
  174173. }
  174174. #endif
  174175. #if defined(PNG_tRNS_SUPPORTED)
  174176. void PNGAPI
  174177. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174178. png_bytep trans, int num_trans, png_color_16p trans_values)
  174179. {
  174180. png_debug1(1, "in %s storage function\n", "tRNS");
  174181. if (png_ptr == NULL || info_ptr == NULL)
  174182. return;
  174183. if (trans != NULL)
  174184. {
  174185. #ifdef PNG_FREE_ME_SUPPORTED
  174186. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174187. #endif
  174188. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174189. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174190. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174191. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174192. #ifdef PNG_FREE_ME_SUPPORTED
  174193. info_ptr->free_me |= PNG_FREE_TRNS;
  174194. #else
  174195. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174196. #endif
  174197. }
  174198. if (trans_values != NULL)
  174199. {
  174200. png_memcpy(&(info_ptr->trans_values), trans_values,
  174201. png_sizeof(png_color_16));
  174202. if (num_trans == 0)
  174203. num_trans = 1;
  174204. }
  174205. info_ptr->num_trans = (png_uint_16)num_trans;
  174206. info_ptr->valid |= PNG_INFO_tRNS;
  174207. }
  174208. #endif
  174209. #if defined(PNG_sPLT_SUPPORTED)
  174210. void PNGAPI
  174211. png_set_sPLT(png_structp png_ptr,
  174212. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174213. {
  174214. png_sPLT_tp np;
  174215. int i;
  174216. if (png_ptr == NULL || info_ptr == NULL)
  174217. return;
  174218. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174219. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174220. if (np == NULL)
  174221. {
  174222. png_warning(png_ptr, "No memory for sPLT palettes.");
  174223. return;
  174224. }
  174225. png_memcpy(np, info_ptr->splt_palettes,
  174226. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174227. png_free(png_ptr, info_ptr->splt_palettes);
  174228. info_ptr->splt_palettes=NULL;
  174229. for (i = 0; i < nentries; i++)
  174230. {
  174231. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174232. png_sPLT_tp from = entries + i;
  174233. to->name = (png_charp)png_malloc_warn(png_ptr,
  174234. png_strlen(from->name) + 1);
  174235. if (to->name == NULL)
  174236. {
  174237. png_warning(png_ptr,
  174238. "Out of memory while processing sPLT chunk");
  174239. }
  174240. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174241. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174242. from->nentries * png_sizeof(png_sPLT_entry));
  174243. png_memcpy(to->entries, from->entries,
  174244. from->nentries * png_sizeof(png_sPLT_entry));
  174245. if (to->entries == NULL)
  174246. {
  174247. png_warning(png_ptr,
  174248. "Out of memory while processing sPLT chunk");
  174249. png_free(png_ptr,to->name);
  174250. to->name = NULL;
  174251. }
  174252. to->nentries = from->nentries;
  174253. to->depth = from->depth;
  174254. }
  174255. info_ptr->splt_palettes = np;
  174256. info_ptr->splt_palettes_num += nentries;
  174257. info_ptr->valid |= PNG_INFO_sPLT;
  174258. #ifdef PNG_FREE_ME_SUPPORTED
  174259. info_ptr->free_me |= PNG_FREE_SPLT;
  174260. #endif
  174261. }
  174262. #endif /* PNG_sPLT_SUPPORTED */
  174263. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174264. void PNGAPI
  174265. png_set_unknown_chunks(png_structp png_ptr,
  174266. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174267. {
  174268. png_unknown_chunkp np;
  174269. int i;
  174270. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174271. return;
  174272. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174273. (info_ptr->unknown_chunks_num + num_unknowns) *
  174274. png_sizeof(png_unknown_chunk));
  174275. if (np == NULL)
  174276. {
  174277. png_warning(png_ptr,
  174278. "Out of memory while processing unknown chunk.");
  174279. return;
  174280. }
  174281. png_memcpy(np, info_ptr->unknown_chunks,
  174282. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174283. png_free(png_ptr, info_ptr->unknown_chunks);
  174284. info_ptr->unknown_chunks=NULL;
  174285. for (i = 0; i < num_unknowns; i++)
  174286. {
  174287. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174288. png_unknown_chunkp from = unknowns + i;
  174289. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174290. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174291. if (to->data == NULL)
  174292. {
  174293. png_warning(png_ptr,
  174294. "Out of memory while processing unknown chunk.");
  174295. }
  174296. else
  174297. {
  174298. png_memcpy(to->data, from->data, from->size);
  174299. to->size = from->size;
  174300. to->location = (png_byte)(png_ptr->mode & 0xff);
  174301. }
  174302. }
  174303. info_ptr->unknown_chunks = np;
  174304. info_ptr->unknown_chunks_num += num_unknowns;
  174305. #ifdef PNG_FREE_ME_SUPPORTED
  174306. info_ptr->free_me |= PNG_FREE_UNKN;
  174307. #endif
  174308. }
  174309. void PNGAPI
  174310. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174311. int chunk, int location)
  174312. {
  174313. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174314. (int)info_ptr->unknown_chunks_num)
  174315. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174316. }
  174317. #endif
  174318. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174319. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174320. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174321. void PNGAPI
  174322. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174323. {
  174324. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174325. if (png_ptr == NULL)
  174326. return;
  174327. png_ptr->mng_features_permitted = (png_byte)
  174328. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174329. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174330. }
  174331. #endif
  174332. #endif
  174333. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174334. png_uint_32 PNGAPI
  174335. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174336. {
  174337. png_debug(1, "in png_permit_mng_features\n");
  174338. if (png_ptr == NULL)
  174339. return (png_uint_32)0;
  174340. png_ptr->mng_features_permitted =
  174341. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174342. return (png_uint_32)png_ptr->mng_features_permitted;
  174343. }
  174344. #endif
  174345. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174346. void PNGAPI
  174347. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174348. chunk_list, int num_chunks)
  174349. {
  174350. png_bytep new_list, p;
  174351. int i, old_num_chunks;
  174352. if (png_ptr == NULL)
  174353. return;
  174354. if (num_chunks == 0)
  174355. {
  174356. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174357. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174358. else
  174359. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174360. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174361. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174362. else
  174363. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174364. return;
  174365. }
  174366. if (chunk_list == NULL)
  174367. return;
  174368. old_num_chunks=png_ptr->num_chunk_list;
  174369. new_list=(png_bytep)png_malloc(png_ptr,
  174370. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174371. if(png_ptr->chunk_list != NULL)
  174372. {
  174373. png_memcpy(new_list, png_ptr->chunk_list,
  174374. (png_size_t)(5*old_num_chunks));
  174375. png_free(png_ptr, png_ptr->chunk_list);
  174376. png_ptr->chunk_list=NULL;
  174377. }
  174378. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174379. (png_size_t)(5*num_chunks));
  174380. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174381. *p=(png_byte)keep;
  174382. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174383. png_ptr->chunk_list=new_list;
  174384. #ifdef PNG_FREE_ME_SUPPORTED
  174385. png_ptr->free_me |= PNG_FREE_LIST;
  174386. #endif
  174387. }
  174388. #endif
  174389. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174390. void PNGAPI
  174391. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174392. png_user_chunk_ptr read_user_chunk_fn)
  174393. {
  174394. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174395. if (png_ptr == NULL)
  174396. return;
  174397. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174398. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174399. }
  174400. #endif
  174401. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174402. void PNGAPI
  174403. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174404. {
  174405. png_debug1(1, "in %s storage function\n", "rows");
  174406. if (png_ptr == NULL || info_ptr == NULL)
  174407. return;
  174408. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174409. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174410. info_ptr->row_pointers = row_pointers;
  174411. if(row_pointers)
  174412. info_ptr->valid |= PNG_INFO_IDAT;
  174413. }
  174414. #endif
  174415. #ifdef PNG_WRITE_SUPPORTED
  174416. void PNGAPI
  174417. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174418. {
  174419. if (png_ptr == NULL)
  174420. return;
  174421. if(png_ptr->zbuf)
  174422. png_free(png_ptr, png_ptr->zbuf);
  174423. png_ptr->zbuf_size = (png_size_t)size;
  174424. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174425. png_ptr->zstream.next_out = png_ptr->zbuf;
  174426. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174427. }
  174428. #endif
  174429. void PNGAPI
  174430. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174431. {
  174432. if (png_ptr && info_ptr)
  174433. info_ptr->valid &= ~(mask);
  174434. }
  174435. #ifndef PNG_1_0_X
  174436. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174437. void PNGAPI
  174438. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174439. {
  174440. if (png_ptr != NULL)
  174441. png_ptr->asm_flags = 0;
  174442. }
  174443. void PNGAPI
  174444. png_set_mmx_thresholds (png_structp png_ptr,
  174445. png_byte mmx_bitdepth_threshold,
  174446. png_uint_32 mmx_rowbytes_threshold)
  174447. {
  174448. if (png_ptr == NULL)
  174449. return;
  174450. }
  174451. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174452. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174453. void PNGAPI
  174454. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174455. png_uint_32 user_height_max)
  174456. {
  174457. if(png_ptr == NULL) return;
  174458. png_ptr->user_width_max = user_width_max;
  174459. png_ptr->user_height_max = user_height_max;
  174460. }
  174461. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174462. #endif /* ?PNG_1_0_X */
  174463. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174464. /*** End of inlined file: pngset.c ***/
  174465. /*** Start of inlined file: pngtrans.c ***/
  174466. #define PNG_INTERNAL
  174467. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174468. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174469. void PNGAPI
  174470. png_set_bgr(png_structp png_ptr)
  174471. {
  174472. png_debug(1, "in png_set_bgr\n");
  174473. if(png_ptr == NULL) return;
  174474. png_ptr->transformations |= PNG_BGR;
  174475. }
  174476. #endif
  174477. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174478. void PNGAPI
  174479. png_set_swap(png_structp png_ptr)
  174480. {
  174481. png_debug(1, "in png_set_swap\n");
  174482. if(png_ptr == NULL) return;
  174483. if (png_ptr->bit_depth == 16)
  174484. png_ptr->transformations |= PNG_SWAP_BYTES;
  174485. }
  174486. #endif
  174487. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174488. void PNGAPI
  174489. png_set_packing(png_structp png_ptr)
  174490. {
  174491. png_debug(1, "in png_set_packing\n");
  174492. if(png_ptr == NULL) return;
  174493. if (png_ptr->bit_depth < 8)
  174494. {
  174495. png_ptr->transformations |= PNG_PACK;
  174496. png_ptr->usr_bit_depth = 8;
  174497. }
  174498. }
  174499. #endif
  174500. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174501. void PNGAPI
  174502. png_set_packswap(png_structp png_ptr)
  174503. {
  174504. png_debug(1, "in png_set_packswap\n");
  174505. if(png_ptr == NULL) return;
  174506. if (png_ptr->bit_depth < 8)
  174507. png_ptr->transformations |= PNG_PACKSWAP;
  174508. }
  174509. #endif
  174510. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174511. void PNGAPI
  174512. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174513. {
  174514. png_debug(1, "in png_set_shift\n");
  174515. if(png_ptr == NULL) return;
  174516. png_ptr->transformations |= PNG_SHIFT;
  174517. png_ptr->shift = *true_bits;
  174518. }
  174519. #endif
  174520. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174521. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174522. int PNGAPI
  174523. png_set_interlace_handling(png_structp png_ptr)
  174524. {
  174525. png_debug(1, "in png_set_interlace handling\n");
  174526. if (png_ptr && png_ptr->interlaced)
  174527. {
  174528. png_ptr->transformations |= PNG_INTERLACE;
  174529. return (7);
  174530. }
  174531. return (1);
  174532. }
  174533. #endif
  174534. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174535. void PNGAPI
  174536. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174537. {
  174538. png_debug(1, "in png_set_filler\n");
  174539. if(png_ptr == NULL) return;
  174540. png_ptr->transformations |= PNG_FILLER;
  174541. png_ptr->filler = (png_byte)filler;
  174542. if (filler_loc == PNG_FILLER_AFTER)
  174543. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174544. else
  174545. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174546. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174547. {
  174548. png_ptr->usr_channels = 4;
  174549. }
  174550. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174551. {
  174552. png_ptr->usr_channels = 2;
  174553. }
  174554. }
  174555. #if !defined(PNG_1_0_X)
  174556. void PNGAPI
  174557. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174558. {
  174559. png_debug(1, "in png_set_add_alpha\n");
  174560. if(png_ptr == NULL) return;
  174561. png_set_filler(png_ptr, filler, filler_loc);
  174562. png_ptr->transformations |= PNG_ADD_ALPHA;
  174563. }
  174564. #endif
  174565. #endif
  174566. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174567. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174568. void PNGAPI
  174569. png_set_swap_alpha(png_structp png_ptr)
  174570. {
  174571. png_debug(1, "in png_set_swap_alpha\n");
  174572. if(png_ptr == NULL) return;
  174573. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174574. }
  174575. #endif
  174576. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174577. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174578. void PNGAPI
  174579. png_set_invert_alpha(png_structp png_ptr)
  174580. {
  174581. png_debug(1, "in png_set_invert_alpha\n");
  174582. if(png_ptr == NULL) return;
  174583. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174584. }
  174585. #endif
  174586. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174587. void PNGAPI
  174588. png_set_invert_mono(png_structp png_ptr)
  174589. {
  174590. png_debug(1, "in png_set_invert_mono\n");
  174591. if(png_ptr == NULL) return;
  174592. png_ptr->transformations |= PNG_INVERT_MONO;
  174593. }
  174594. void /* PRIVATE */
  174595. png_do_invert(png_row_infop row_info, png_bytep row)
  174596. {
  174597. png_debug(1, "in png_do_invert\n");
  174598. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174599. if (row == NULL || row_info == NULL)
  174600. return;
  174601. #endif
  174602. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174603. {
  174604. png_bytep rp = row;
  174605. png_uint_32 i;
  174606. png_uint_32 istop = row_info->rowbytes;
  174607. for (i = 0; i < istop; i++)
  174608. {
  174609. *rp = (png_byte)(~(*rp));
  174610. rp++;
  174611. }
  174612. }
  174613. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174614. row_info->bit_depth == 8)
  174615. {
  174616. png_bytep rp = row;
  174617. png_uint_32 i;
  174618. png_uint_32 istop = row_info->rowbytes;
  174619. for (i = 0; i < istop; i+=2)
  174620. {
  174621. *rp = (png_byte)(~(*rp));
  174622. rp+=2;
  174623. }
  174624. }
  174625. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174626. row_info->bit_depth == 16)
  174627. {
  174628. png_bytep rp = row;
  174629. png_uint_32 i;
  174630. png_uint_32 istop = row_info->rowbytes;
  174631. for (i = 0; i < istop; i+=4)
  174632. {
  174633. *rp = (png_byte)(~(*rp));
  174634. *(rp+1) = (png_byte)(~(*(rp+1)));
  174635. rp+=4;
  174636. }
  174637. }
  174638. }
  174639. #endif
  174640. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174641. void /* PRIVATE */
  174642. png_do_swap(png_row_infop row_info, png_bytep row)
  174643. {
  174644. png_debug(1, "in png_do_swap\n");
  174645. if (
  174646. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174647. row != NULL && row_info != NULL &&
  174648. #endif
  174649. row_info->bit_depth == 16)
  174650. {
  174651. png_bytep rp = row;
  174652. png_uint_32 i;
  174653. png_uint_32 istop= row_info->width * row_info->channels;
  174654. for (i = 0; i < istop; i++, rp += 2)
  174655. {
  174656. png_byte t = *rp;
  174657. *rp = *(rp + 1);
  174658. *(rp + 1) = t;
  174659. }
  174660. }
  174661. }
  174662. #endif
  174663. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174664. static PNG_CONST png_byte onebppswaptable[256] = {
  174665. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174666. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174667. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174668. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174669. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174670. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174671. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174672. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174673. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174674. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174675. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174676. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174677. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174678. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174679. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174680. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174681. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174682. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174683. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174684. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174685. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174686. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174687. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174688. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174689. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174690. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174691. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174692. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174693. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174694. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174695. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174696. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174697. };
  174698. static PNG_CONST png_byte twobppswaptable[256] = {
  174699. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174700. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174701. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174702. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174703. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174704. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174705. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174706. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174707. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174708. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174709. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174710. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174711. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174712. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174713. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174714. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174715. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174716. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174717. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174718. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174719. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174720. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174721. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174722. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174723. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174724. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174725. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174726. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174727. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174728. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174729. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174730. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174731. };
  174732. static PNG_CONST png_byte fourbppswaptable[256] = {
  174733. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174734. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174735. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174736. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174737. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174738. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174739. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174740. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174741. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174742. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174743. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174744. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174745. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174746. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174747. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174748. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174749. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174750. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174751. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174752. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174753. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174754. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174755. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174756. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174757. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174758. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174759. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174760. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174761. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174762. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174763. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174764. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174765. };
  174766. void /* PRIVATE */
  174767. png_do_packswap(png_row_infop row_info, png_bytep row)
  174768. {
  174769. png_debug(1, "in png_do_packswap\n");
  174770. if (
  174771. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174772. row != NULL && row_info != NULL &&
  174773. #endif
  174774. row_info->bit_depth < 8)
  174775. {
  174776. png_bytep rp, end, table;
  174777. end = row + row_info->rowbytes;
  174778. if (row_info->bit_depth == 1)
  174779. table = (png_bytep)onebppswaptable;
  174780. else if (row_info->bit_depth == 2)
  174781. table = (png_bytep)twobppswaptable;
  174782. else if (row_info->bit_depth == 4)
  174783. table = (png_bytep)fourbppswaptable;
  174784. else
  174785. return;
  174786. for (rp = row; rp < end; rp++)
  174787. *rp = table[*rp];
  174788. }
  174789. }
  174790. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174791. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174792. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174793. void /* PRIVATE */
  174794. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174795. {
  174796. png_debug(1, "in png_do_strip_filler\n");
  174797. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174798. if (row != NULL && row_info != NULL)
  174799. #endif
  174800. {
  174801. png_bytep sp=row;
  174802. png_bytep dp=row;
  174803. png_uint_32 row_width=row_info->width;
  174804. png_uint_32 i;
  174805. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174806. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174807. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174808. row_info->channels == 4)
  174809. {
  174810. if (row_info->bit_depth == 8)
  174811. {
  174812. if (flags & PNG_FLAG_FILLER_AFTER)
  174813. {
  174814. dp+=3; sp+=4;
  174815. for (i = 1; i < row_width; i++)
  174816. {
  174817. *dp++ = *sp++;
  174818. *dp++ = *sp++;
  174819. *dp++ = *sp++;
  174820. sp++;
  174821. }
  174822. }
  174823. else
  174824. {
  174825. for (i = 0; i < row_width; i++)
  174826. {
  174827. sp++;
  174828. *dp++ = *sp++;
  174829. *dp++ = *sp++;
  174830. *dp++ = *sp++;
  174831. }
  174832. }
  174833. row_info->pixel_depth = 24;
  174834. row_info->rowbytes = row_width * 3;
  174835. }
  174836. else /* if (row_info->bit_depth == 16) */
  174837. {
  174838. if (flags & PNG_FLAG_FILLER_AFTER)
  174839. {
  174840. sp += 8; dp += 6;
  174841. for (i = 1; i < row_width; i++)
  174842. {
  174843. *dp++ = *sp++;
  174844. *dp++ = *sp++;
  174845. *dp++ = *sp++;
  174846. *dp++ = *sp++;
  174847. *dp++ = *sp++;
  174848. *dp++ = *sp++;
  174849. sp += 2;
  174850. }
  174851. }
  174852. else
  174853. {
  174854. for (i = 0; i < row_width; i++)
  174855. {
  174856. sp+=2;
  174857. *dp++ = *sp++;
  174858. *dp++ = *sp++;
  174859. *dp++ = *sp++;
  174860. *dp++ = *sp++;
  174861. *dp++ = *sp++;
  174862. *dp++ = *sp++;
  174863. }
  174864. }
  174865. row_info->pixel_depth = 48;
  174866. row_info->rowbytes = row_width * 6;
  174867. }
  174868. row_info->channels = 3;
  174869. }
  174870. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174871. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174872. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174873. row_info->channels == 2)
  174874. {
  174875. if (row_info->bit_depth == 8)
  174876. {
  174877. if (flags & PNG_FLAG_FILLER_AFTER)
  174878. {
  174879. for (i = 0; i < row_width; i++)
  174880. {
  174881. *dp++ = *sp++;
  174882. sp++;
  174883. }
  174884. }
  174885. else
  174886. {
  174887. for (i = 0; i < row_width; i++)
  174888. {
  174889. sp++;
  174890. *dp++ = *sp++;
  174891. }
  174892. }
  174893. row_info->pixel_depth = 8;
  174894. row_info->rowbytes = row_width;
  174895. }
  174896. else /* if (row_info->bit_depth == 16) */
  174897. {
  174898. if (flags & PNG_FLAG_FILLER_AFTER)
  174899. {
  174900. sp += 4; dp += 2;
  174901. for (i = 1; i < row_width; i++)
  174902. {
  174903. *dp++ = *sp++;
  174904. *dp++ = *sp++;
  174905. sp += 2;
  174906. }
  174907. }
  174908. else
  174909. {
  174910. for (i = 0; i < row_width; i++)
  174911. {
  174912. sp += 2;
  174913. *dp++ = *sp++;
  174914. *dp++ = *sp++;
  174915. }
  174916. }
  174917. row_info->pixel_depth = 16;
  174918. row_info->rowbytes = row_width * 2;
  174919. }
  174920. row_info->channels = 1;
  174921. }
  174922. if (flags & PNG_FLAG_STRIP_ALPHA)
  174923. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174924. }
  174925. }
  174926. #endif
  174927. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174928. void /* PRIVATE */
  174929. png_do_bgr(png_row_infop row_info, png_bytep row)
  174930. {
  174931. png_debug(1, "in png_do_bgr\n");
  174932. if (
  174933. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174934. row != NULL && row_info != NULL &&
  174935. #endif
  174936. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174937. {
  174938. png_uint_32 row_width = row_info->width;
  174939. if (row_info->bit_depth == 8)
  174940. {
  174941. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174942. {
  174943. png_bytep rp;
  174944. png_uint_32 i;
  174945. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  174946. {
  174947. png_byte save = *rp;
  174948. *rp = *(rp + 2);
  174949. *(rp + 2) = save;
  174950. }
  174951. }
  174952. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174953. {
  174954. png_bytep rp;
  174955. png_uint_32 i;
  174956. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  174957. {
  174958. png_byte save = *rp;
  174959. *rp = *(rp + 2);
  174960. *(rp + 2) = save;
  174961. }
  174962. }
  174963. }
  174964. else if (row_info->bit_depth == 16)
  174965. {
  174966. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174967. {
  174968. png_bytep rp;
  174969. png_uint_32 i;
  174970. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  174971. {
  174972. png_byte save = *rp;
  174973. *rp = *(rp + 4);
  174974. *(rp + 4) = save;
  174975. save = *(rp + 1);
  174976. *(rp + 1) = *(rp + 5);
  174977. *(rp + 5) = save;
  174978. }
  174979. }
  174980. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174981. {
  174982. png_bytep rp;
  174983. png_uint_32 i;
  174984. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  174985. {
  174986. png_byte save = *rp;
  174987. *rp = *(rp + 4);
  174988. *(rp + 4) = save;
  174989. save = *(rp + 1);
  174990. *(rp + 1) = *(rp + 5);
  174991. *(rp + 5) = save;
  174992. }
  174993. }
  174994. }
  174995. }
  174996. }
  174997. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  174998. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  174999. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  175000. defined(PNG_LEGACY_SUPPORTED)
  175001. void PNGAPI
  175002. png_set_user_transform_info(png_structp png_ptr, png_voidp
  175003. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  175004. {
  175005. png_debug(1, "in png_set_user_transform_info\n");
  175006. if(png_ptr == NULL) return;
  175007. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175008. png_ptr->user_transform_ptr = user_transform_ptr;
  175009. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  175010. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  175011. #else
  175012. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  175013. png_warning(png_ptr,
  175014. "This version of libpng does not support user transform info");
  175015. #endif
  175016. }
  175017. #endif
  175018. png_voidp PNGAPI
  175019. png_get_user_transform_ptr(png_structp png_ptr)
  175020. {
  175021. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175022. if (png_ptr == NULL) return (NULL);
  175023. return ((png_voidp)png_ptr->user_transform_ptr);
  175024. #else
  175025. return (NULL);
  175026. #endif
  175027. }
  175028. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175029. /*** End of inlined file: pngtrans.c ***/
  175030. /*** Start of inlined file: pngwio.c ***/
  175031. #define PNG_INTERNAL
  175032. #ifdef PNG_WRITE_SUPPORTED
  175033. void /* PRIVATE */
  175034. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175035. {
  175036. if (png_ptr->write_data_fn != NULL )
  175037. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175038. else
  175039. png_error(png_ptr, "Call to NULL write function");
  175040. }
  175041. #if !defined(PNG_NO_STDIO)
  175042. #ifndef USE_FAR_KEYWORD
  175043. void PNGAPI
  175044. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175045. {
  175046. png_uint_32 check;
  175047. if(png_ptr == NULL) return;
  175048. #if defined(_WIN32_WCE)
  175049. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175050. check = 0;
  175051. #else
  175052. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175053. #endif
  175054. if (check != length)
  175055. png_error(png_ptr, "Write Error");
  175056. }
  175057. #else
  175058. #define NEAR_BUF_SIZE 1024
  175059. #define MIN(a,b) (a <= b ? a : b)
  175060. void PNGAPI
  175061. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175062. {
  175063. png_uint_32 check;
  175064. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175065. png_FILE_p io_ptr;
  175066. if(png_ptr == NULL) return;
  175067. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175068. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175069. if ((png_bytep)near_data == data)
  175070. {
  175071. #if defined(_WIN32_WCE)
  175072. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175073. check = 0;
  175074. #else
  175075. check = fwrite(near_data, 1, length, io_ptr);
  175076. #endif
  175077. }
  175078. else
  175079. {
  175080. png_byte buf[NEAR_BUF_SIZE];
  175081. png_size_t written, remaining, err;
  175082. check = 0;
  175083. remaining = length;
  175084. do
  175085. {
  175086. written = MIN(NEAR_BUF_SIZE, remaining);
  175087. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175088. #if defined(_WIN32_WCE)
  175089. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175090. err = 0;
  175091. #else
  175092. err = fwrite(buf, 1, written, io_ptr);
  175093. #endif
  175094. if (err != written)
  175095. break;
  175096. else
  175097. check += err;
  175098. data += written;
  175099. remaining -= written;
  175100. }
  175101. while (remaining != 0);
  175102. }
  175103. if (check != length)
  175104. png_error(png_ptr, "Write Error");
  175105. }
  175106. #endif
  175107. #endif
  175108. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175109. void /* PRIVATE */
  175110. png_flush(png_structp png_ptr)
  175111. {
  175112. if (png_ptr->output_flush_fn != NULL)
  175113. (*(png_ptr->output_flush_fn))(png_ptr);
  175114. }
  175115. #if !defined(PNG_NO_STDIO)
  175116. void PNGAPI
  175117. png_default_flush(png_structp png_ptr)
  175118. {
  175119. #if !defined(_WIN32_WCE)
  175120. png_FILE_p io_ptr;
  175121. #endif
  175122. if(png_ptr == NULL) return;
  175123. #if !defined(_WIN32_WCE)
  175124. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175125. if (io_ptr != NULL)
  175126. fflush(io_ptr);
  175127. #endif
  175128. }
  175129. #endif
  175130. #endif
  175131. void PNGAPI
  175132. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175133. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175134. {
  175135. if(png_ptr == NULL) return;
  175136. png_ptr->io_ptr = io_ptr;
  175137. #if !defined(PNG_NO_STDIO)
  175138. if (write_data_fn != NULL)
  175139. png_ptr->write_data_fn = write_data_fn;
  175140. else
  175141. png_ptr->write_data_fn = png_default_write_data;
  175142. #else
  175143. png_ptr->write_data_fn = write_data_fn;
  175144. #endif
  175145. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175146. #if !defined(PNG_NO_STDIO)
  175147. if (output_flush_fn != NULL)
  175148. png_ptr->output_flush_fn = output_flush_fn;
  175149. else
  175150. png_ptr->output_flush_fn = png_default_flush;
  175151. #else
  175152. png_ptr->output_flush_fn = output_flush_fn;
  175153. #endif
  175154. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175155. if (png_ptr->read_data_fn != NULL)
  175156. {
  175157. png_ptr->read_data_fn = NULL;
  175158. png_warning(png_ptr,
  175159. "Attempted to set both read_data_fn and write_data_fn in");
  175160. png_warning(png_ptr,
  175161. "the same structure. Resetting read_data_fn to NULL.");
  175162. }
  175163. }
  175164. #if defined(USE_FAR_KEYWORD)
  175165. #if defined(_MSC_VER)
  175166. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175167. {
  175168. void *near_ptr;
  175169. void FAR *far_ptr;
  175170. FP_OFF(near_ptr) = FP_OFF(ptr);
  175171. far_ptr = (void FAR *)near_ptr;
  175172. if(check != 0)
  175173. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175174. png_error(png_ptr,"segment lost in conversion");
  175175. return(near_ptr);
  175176. }
  175177. # else
  175178. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175179. {
  175180. void *near_ptr;
  175181. void FAR *far_ptr;
  175182. near_ptr = (void FAR *)ptr;
  175183. far_ptr = (void FAR *)near_ptr;
  175184. if(check != 0)
  175185. if(far_ptr != ptr)
  175186. png_error(png_ptr,"segment lost in conversion");
  175187. return(near_ptr);
  175188. }
  175189. # endif
  175190. # endif
  175191. #endif /* PNG_WRITE_SUPPORTED */
  175192. /*** End of inlined file: pngwio.c ***/
  175193. /*** Start of inlined file: pngwrite.c ***/
  175194. #define PNG_INTERNAL
  175195. #ifdef PNG_WRITE_SUPPORTED
  175196. void PNGAPI
  175197. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175198. {
  175199. png_debug(1, "in png_write_info_before_PLTE\n");
  175200. if (png_ptr == NULL || info_ptr == NULL)
  175201. return;
  175202. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175203. {
  175204. png_write_sig(png_ptr); /* write PNG signature */
  175205. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175206. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175207. {
  175208. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175209. png_ptr->mng_features_permitted=0;
  175210. }
  175211. #endif
  175212. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175213. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175214. info_ptr->filter_type,
  175215. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175216. info_ptr->interlace_type);
  175217. #else
  175218. 0);
  175219. #endif
  175220. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175221. if (info_ptr->valid & PNG_INFO_gAMA)
  175222. {
  175223. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175224. png_write_gAMA(png_ptr, info_ptr->gamma);
  175225. #else
  175226. #ifdef PNG_FIXED_POINT_SUPPORTED
  175227. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175228. # endif
  175229. #endif
  175230. }
  175231. #endif
  175232. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175233. if (info_ptr->valid & PNG_INFO_sRGB)
  175234. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175235. #endif
  175236. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175237. if (info_ptr->valid & PNG_INFO_iCCP)
  175238. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175239. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175240. #endif
  175241. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175242. if (info_ptr->valid & PNG_INFO_sBIT)
  175243. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175244. #endif
  175245. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175246. if (info_ptr->valid & PNG_INFO_cHRM)
  175247. {
  175248. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175249. png_write_cHRM(png_ptr,
  175250. info_ptr->x_white, info_ptr->y_white,
  175251. info_ptr->x_red, info_ptr->y_red,
  175252. info_ptr->x_green, info_ptr->y_green,
  175253. info_ptr->x_blue, info_ptr->y_blue);
  175254. #else
  175255. # ifdef PNG_FIXED_POINT_SUPPORTED
  175256. png_write_cHRM_fixed(png_ptr,
  175257. info_ptr->int_x_white, info_ptr->int_y_white,
  175258. info_ptr->int_x_red, info_ptr->int_y_red,
  175259. info_ptr->int_x_green, info_ptr->int_y_green,
  175260. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175261. # endif
  175262. #endif
  175263. }
  175264. #endif
  175265. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175266. if (info_ptr->unknown_chunks_num)
  175267. {
  175268. png_unknown_chunk *up;
  175269. png_debug(5, "writing extra chunks\n");
  175270. for (up = info_ptr->unknown_chunks;
  175271. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175272. up++)
  175273. {
  175274. int keep=png_handle_as_unknown(png_ptr, up->name);
  175275. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175276. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175277. !(up->location & PNG_HAVE_IDAT) &&
  175278. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175279. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175280. {
  175281. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175282. }
  175283. }
  175284. }
  175285. #endif
  175286. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175287. }
  175288. }
  175289. void PNGAPI
  175290. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175291. {
  175292. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175293. int i;
  175294. #endif
  175295. png_debug(1, "in png_write_info\n");
  175296. if (png_ptr == NULL || info_ptr == NULL)
  175297. return;
  175298. png_write_info_before_PLTE(png_ptr, info_ptr);
  175299. if (info_ptr->valid & PNG_INFO_PLTE)
  175300. png_write_PLTE(png_ptr, info_ptr->palette,
  175301. (png_uint_32)info_ptr->num_palette);
  175302. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175303. png_error(png_ptr, "Valid palette required for paletted images");
  175304. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175305. if (info_ptr->valid & PNG_INFO_tRNS)
  175306. {
  175307. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175308. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175309. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175310. {
  175311. int j;
  175312. for (j=0; j<(int)info_ptr->num_trans; j++)
  175313. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175314. }
  175315. #endif
  175316. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175317. info_ptr->num_trans, info_ptr->color_type);
  175318. }
  175319. #endif
  175320. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175321. if (info_ptr->valid & PNG_INFO_bKGD)
  175322. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175323. #endif
  175324. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175325. if (info_ptr->valid & PNG_INFO_hIST)
  175326. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175327. #endif
  175328. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175329. if (info_ptr->valid & PNG_INFO_oFFs)
  175330. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175331. info_ptr->offset_unit_type);
  175332. #endif
  175333. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175334. if (info_ptr->valid & PNG_INFO_pCAL)
  175335. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175336. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175337. info_ptr->pcal_units, info_ptr->pcal_params);
  175338. #endif
  175339. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175340. if (info_ptr->valid & PNG_INFO_sCAL)
  175341. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175342. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175343. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175344. #else
  175345. #ifdef PNG_FIXED_POINT_SUPPORTED
  175346. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175347. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175348. #else
  175349. png_warning(png_ptr,
  175350. "png_write_sCAL not supported; sCAL chunk not written.");
  175351. #endif
  175352. #endif
  175353. #endif
  175354. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175355. if (info_ptr->valid & PNG_INFO_pHYs)
  175356. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175357. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175358. #endif
  175359. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175360. if (info_ptr->valid & PNG_INFO_tIME)
  175361. {
  175362. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175363. png_ptr->mode |= PNG_WROTE_tIME;
  175364. }
  175365. #endif
  175366. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175367. if (info_ptr->valid & PNG_INFO_sPLT)
  175368. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175369. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175370. #endif
  175371. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175372. for (i = 0; i < info_ptr->num_text; i++)
  175373. {
  175374. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175375. info_ptr->text[i].compression);
  175376. if (info_ptr->text[i].compression > 0)
  175377. {
  175378. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175379. png_write_iTXt(png_ptr,
  175380. info_ptr->text[i].compression,
  175381. info_ptr->text[i].key,
  175382. info_ptr->text[i].lang,
  175383. info_ptr->text[i].lang_key,
  175384. info_ptr->text[i].text);
  175385. #else
  175386. png_warning(png_ptr, "Unable to write international text");
  175387. #endif
  175388. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175389. }
  175390. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175391. {
  175392. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175393. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175394. info_ptr->text[i].text, 0,
  175395. info_ptr->text[i].compression);
  175396. #else
  175397. png_warning(png_ptr, "Unable to write compressed text");
  175398. #endif
  175399. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175400. }
  175401. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175402. {
  175403. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175404. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175405. info_ptr->text[i].text,
  175406. 0);
  175407. #else
  175408. png_warning(png_ptr, "Unable to write uncompressed text");
  175409. #endif
  175410. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175411. }
  175412. }
  175413. #endif
  175414. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175415. if (info_ptr->unknown_chunks_num)
  175416. {
  175417. png_unknown_chunk *up;
  175418. png_debug(5, "writing extra chunks\n");
  175419. for (up = info_ptr->unknown_chunks;
  175420. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175421. up++)
  175422. {
  175423. int keep=png_handle_as_unknown(png_ptr, up->name);
  175424. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175425. up->location && (up->location & PNG_HAVE_PLTE) &&
  175426. !(up->location & PNG_HAVE_IDAT) &&
  175427. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175428. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175429. {
  175430. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175431. }
  175432. }
  175433. }
  175434. #endif
  175435. }
  175436. void PNGAPI
  175437. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175438. {
  175439. png_debug(1, "in png_write_end\n");
  175440. if (png_ptr == NULL)
  175441. return;
  175442. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175443. png_error(png_ptr, "No IDATs written into file");
  175444. if (info_ptr != NULL)
  175445. {
  175446. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175447. int i; /* local index variable */
  175448. #endif
  175449. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175450. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175451. !(png_ptr->mode & PNG_WROTE_tIME))
  175452. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175453. #endif
  175454. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175455. for (i = 0; i < info_ptr->num_text; i++)
  175456. {
  175457. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175458. info_ptr->text[i].compression);
  175459. if (info_ptr->text[i].compression > 0)
  175460. {
  175461. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175462. png_write_iTXt(png_ptr,
  175463. info_ptr->text[i].compression,
  175464. info_ptr->text[i].key,
  175465. info_ptr->text[i].lang,
  175466. info_ptr->text[i].lang_key,
  175467. info_ptr->text[i].text);
  175468. #else
  175469. png_warning(png_ptr, "Unable to write international text");
  175470. #endif
  175471. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175472. }
  175473. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175474. {
  175475. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175476. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175477. info_ptr->text[i].text, 0,
  175478. info_ptr->text[i].compression);
  175479. #else
  175480. png_warning(png_ptr, "Unable to write compressed text");
  175481. #endif
  175482. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175483. }
  175484. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175485. {
  175486. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175487. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175488. info_ptr->text[i].text, 0);
  175489. #else
  175490. png_warning(png_ptr, "Unable to write uncompressed text");
  175491. #endif
  175492. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175493. }
  175494. }
  175495. #endif
  175496. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175497. if (info_ptr->unknown_chunks_num)
  175498. {
  175499. png_unknown_chunk *up;
  175500. png_debug(5, "writing extra chunks\n");
  175501. for (up = info_ptr->unknown_chunks;
  175502. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175503. up++)
  175504. {
  175505. int keep=png_handle_as_unknown(png_ptr, up->name);
  175506. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175507. up->location && (up->location & PNG_AFTER_IDAT) &&
  175508. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175509. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175510. {
  175511. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175512. }
  175513. }
  175514. }
  175515. #endif
  175516. }
  175517. png_ptr->mode |= PNG_AFTER_IDAT;
  175518. png_write_IEND(png_ptr);
  175519. }
  175520. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175521. #if !defined(_WIN32_WCE)
  175522. void PNGAPI
  175523. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175524. {
  175525. png_debug(1, "in png_convert_from_struct_tm\n");
  175526. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175527. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175528. ptime->day = (png_byte)ttime->tm_mday;
  175529. ptime->hour = (png_byte)ttime->tm_hour;
  175530. ptime->minute = (png_byte)ttime->tm_min;
  175531. ptime->second = (png_byte)ttime->tm_sec;
  175532. }
  175533. void PNGAPI
  175534. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175535. {
  175536. struct tm *tbuf;
  175537. png_debug(1, "in png_convert_from_time_t\n");
  175538. tbuf = gmtime(&ttime);
  175539. png_convert_from_struct_tm(ptime, tbuf);
  175540. }
  175541. #endif
  175542. #endif
  175543. png_structp PNGAPI
  175544. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175545. png_error_ptr error_fn, png_error_ptr warn_fn)
  175546. {
  175547. #ifdef PNG_USER_MEM_SUPPORTED
  175548. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175549. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175550. }
  175551. png_structp PNGAPI
  175552. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175553. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175554. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175555. {
  175556. #endif /* PNG_USER_MEM_SUPPORTED */
  175557. png_structp png_ptr;
  175558. #ifdef PNG_SETJMP_SUPPORTED
  175559. #ifdef USE_FAR_KEYWORD
  175560. jmp_buf jmpbuf;
  175561. #endif
  175562. #endif
  175563. int i;
  175564. png_debug(1, "in png_create_write_struct\n");
  175565. #ifdef PNG_USER_MEM_SUPPORTED
  175566. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175567. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175568. #else
  175569. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175570. #endif /* PNG_USER_MEM_SUPPORTED */
  175571. if (png_ptr == NULL)
  175572. return (NULL);
  175573. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175574. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175575. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175576. #endif
  175577. #ifdef PNG_SETJMP_SUPPORTED
  175578. #ifdef USE_FAR_KEYWORD
  175579. if (setjmp(jmpbuf))
  175580. #else
  175581. if (setjmp(png_ptr->jmpbuf))
  175582. #endif
  175583. {
  175584. png_free(png_ptr, png_ptr->zbuf);
  175585. png_ptr->zbuf=NULL;
  175586. png_destroy_struct(png_ptr);
  175587. return (NULL);
  175588. }
  175589. #ifdef USE_FAR_KEYWORD
  175590. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175591. #endif
  175592. #endif
  175593. #ifdef PNG_USER_MEM_SUPPORTED
  175594. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175595. #endif /* PNG_USER_MEM_SUPPORTED */
  175596. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175597. i=0;
  175598. do
  175599. {
  175600. if(user_png_ver[i] != png_libpng_ver[i])
  175601. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175602. } while (png_libpng_ver[i++]);
  175603. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175604. {
  175605. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175606. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175607. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175608. {
  175609. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175610. char msg[80];
  175611. if (user_png_ver)
  175612. {
  175613. png_snprintf(msg, 80,
  175614. "Application was compiled with png.h from libpng-%.20s",
  175615. user_png_ver);
  175616. png_warning(png_ptr, msg);
  175617. }
  175618. png_snprintf(msg, 80,
  175619. "Application is running with png.c from libpng-%.20s",
  175620. png_libpng_ver);
  175621. png_warning(png_ptr, msg);
  175622. #endif
  175623. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175624. png_ptr->flags=0;
  175625. #endif
  175626. png_error(png_ptr,
  175627. "Incompatible libpng version in application and library");
  175628. }
  175629. }
  175630. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175631. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175632. (png_uint_32)png_ptr->zbuf_size);
  175633. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175634. png_flush_ptr_NULL);
  175635. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175636. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175637. 1, png_doublep_NULL, png_doublep_NULL);
  175638. #endif
  175639. #ifdef PNG_SETJMP_SUPPORTED
  175640. #ifdef USE_FAR_KEYWORD
  175641. if (setjmp(jmpbuf))
  175642. PNG_ABORT();
  175643. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175644. #else
  175645. if (setjmp(png_ptr->jmpbuf))
  175646. PNG_ABORT();
  175647. #endif
  175648. #endif
  175649. return (png_ptr);
  175650. }
  175651. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175652. #undef png_write_init
  175653. void PNGAPI
  175654. png_write_init(png_structp png_ptr)
  175655. {
  175656. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175657. }
  175658. void PNGAPI
  175659. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175660. png_size_t png_struct_size, png_size_t png_info_size)
  175661. {
  175662. if(png_ptr == NULL) return;
  175663. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175664. if(png_sizeof(png_struct) > png_struct_size ||
  175665. png_sizeof(png_info) > png_info_size)
  175666. {
  175667. char msg[80];
  175668. png_ptr->warning_fn=NULL;
  175669. if (user_png_ver)
  175670. {
  175671. png_snprintf(msg, 80,
  175672. "Application was compiled with png.h from libpng-%.20s",
  175673. user_png_ver);
  175674. png_warning(png_ptr, msg);
  175675. }
  175676. png_snprintf(msg, 80,
  175677. "Application is running with png.c from libpng-%.20s",
  175678. png_libpng_ver);
  175679. png_warning(png_ptr, msg);
  175680. }
  175681. #endif
  175682. if(png_sizeof(png_struct) > png_struct_size)
  175683. {
  175684. png_ptr->error_fn=NULL;
  175685. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175686. png_ptr->flags=0;
  175687. #endif
  175688. png_error(png_ptr,
  175689. "The png struct allocated by the application for writing is too small.");
  175690. }
  175691. if(png_sizeof(png_info) > png_info_size)
  175692. {
  175693. png_ptr->error_fn=NULL;
  175694. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175695. png_ptr->flags=0;
  175696. #endif
  175697. png_error(png_ptr,
  175698. "The info struct allocated by the application for writing is too small.");
  175699. }
  175700. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175701. }
  175702. #endif /* PNG_1_0_X || PNG_1_2_X */
  175703. void PNGAPI
  175704. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175705. png_size_t png_struct_size)
  175706. {
  175707. png_structp png_ptr=*ptr_ptr;
  175708. #ifdef PNG_SETJMP_SUPPORTED
  175709. jmp_buf tmp_jmp; /* to save current jump buffer */
  175710. #endif
  175711. int i = 0;
  175712. if (png_ptr == NULL)
  175713. return;
  175714. do
  175715. {
  175716. if (user_png_ver[i] != png_libpng_ver[i])
  175717. {
  175718. #ifdef PNG_LEGACY_SUPPORTED
  175719. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175720. #else
  175721. png_ptr->warning_fn=NULL;
  175722. png_warning(png_ptr,
  175723. "Application uses deprecated png_write_init() and should be recompiled.");
  175724. break;
  175725. #endif
  175726. }
  175727. } while (png_libpng_ver[i++]);
  175728. png_debug(1, "in png_write_init_3\n");
  175729. #ifdef PNG_SETJMP_SUPPORTED
  175730. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175731. #endif
  175732. if (png_sizeof(png_struct) > png_struct_size)
  175733. {
  175734. png_destroy_struct(png_ptr);
  175735. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175736. *ptr_ptr = png_ptr;
  175737. }
  175738. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175739. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175740. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175741. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175742. #endif
  175743. #ifdef PNG_SETJMP_SUPPORTED
  175744. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175745. #endif
  175746. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175747. png_flush_ptr_NULL);
  175748. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175749. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175750. (png_uint_32)png_ptr->zbuf_size);
  175751. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175752. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175753. 1, png_doublep_NULL, png_doublep_NULL);
  175754. #endif
  175755. }
  175756. void PNGAPI
  175757. png_write_rows(png_structp png_ptr, png_bytepp row,
  175758. png_uint_32 num_rows)
  175759. {
  175760. png_uint_32 i; /* row counter */
  175761. png_bytepp rp; /* row pointer */
  175762. png_debug(1, "in png_write_rows\n");
  175763. if (png_ptr == NULL)
  175764. return;
  175765. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175766. {
  175767. png_write_row(png_ptr, *rp);
  175768. }
  175769. }
  175770. void PNGAPI
  175771. png_write_image(png_structp png_ptr, png_bytepp image)
  175772. {
  175773. png_uint_32 i; /* row index */
  175774. int pass, num_pass; /* pass variables */
  175775. png_bytepp rp; /* points to current row */
  175776. if (png_ptr == NULL)
  175777. return;
  175778. png_debug(1, "in png_write_image\n");
  175779. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175780. num_pass = png_set_interlace_handling(png_ptr);
  175781. #else
  175782. num_pass = 1;
  175783. #endif
  175784. for (pass = 0; pass < num_pass; pass++)
  175785. {
  175786. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175787. {
  175788. png_write_row(png_ptr, *rp);
  175789. }
  175790. }
  175791. }
  175792. void PNGAPI
  175793. png_write_row(png_structp png_ptr, png_bytep row)
  175794. {
  175795. if (png_ptr == NULL)
  175796. return;
  175797. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175798. png_ptr->row_number, png_ptr->pass);
  175799. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175800. {
  175801. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175802. png_error(png_ptr,
  175803. "png_write_info was never called before png_write_row.");
  175804. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175805. if (png_ptr->transformations & PNG_INVERT_MONO)
  175806. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175807. #endif
  175808. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175809. if (png_ptr->transformations & PNG_FILLER)
  175810. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175811. #endif
  175812. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175813. if (png_ptr->transformations & PNG_PACKSWAP)
  175814. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175815. #endif
  175816. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175817. if (png_ptr->transformations & PNG_PACK)
  175818. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175819. #endif
  175820. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175821. if (png_ptr->transformations & PNG_SHIFT)
  175822. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175823. #endif
  175824. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175825. if (png_ptr->transformations & PNG_BGR)
  175826. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175827. #endif
  175828. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175829. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175830. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175831. #endif
  175832. png_write_start_row(png_ptr);
  175833. }
  175834. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175835. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175836. {
  175837. switch (png_ptr->pass)
  175838. {
  175839. case 0:
  175840. if (png_ptr->row_number & 0x07)
  175841. {
  175842. png_write_finish_row(png_ptr);
  175843. return;
  175844. }
  175845. break;
  175846. case 1:
  175847. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175848. {
  175849. png_write_finish_row(png_ptr);
  175850. return;
  175851. }
  175852. break;
  175853. case 2:
  175854. if ((png_ptr->row_number & 0x07) != 4)
  175855. {
  175856. png_write_finish_row(png_ptr);
  175857. return;
  175858. }
  175859. break;
  175860. case 3:
  175861. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175862. {
  175863. png_write_finish_row(png_ptr);
  175864. return;
  175865. }
  175866. break;
  175867. case 4:
  175868. if ((png_ptr->row_number & 0x03) != 2)
  175869. {
  175870. png_write_finish_row(png_ptr);
  175871. return;
  175872. }
  175873. break;
  175874. case 5:
  175875. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175876. {
  175877. png_write_finish_row(png_ptr);
  175878. return;
  175879. }
  175880. break;
  175881. case 6:
  175882. if (!(png_ptr->row_number & 0x01))
  175883. {
  175884. png_write_finish_row(png_ptr);
  175885. return;
  175886. }
  175887. break;
  175888. }
  175889. }
  175890. #endif
  175891. png_ptr->row_info.color_type = png_ptr->color_type;
  175892. png_ptr->row_info.width = png_ptr->usr_width;
  175893. png_ptr->row_info.channels = png_ptr->usr_channels;
  175894. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175895. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175896. png_ptr->row_info.channels);
  175897. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175898. png_ptr->row_info.width);
  175899. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175900. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175901. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175902. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175903. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175904. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175905. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175906. png_ptr->row_info.rowbytes);
  175907. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175908. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175909. (png_ptr->transformations & PNG_INTERLACE))
  175910. {
  175911. png_do_write_interlace(&(png_ptr->row_info),
  175912. png_ptr->row_buf + 1, png_ptr->pass);
  175913. if (!(png_ptr->row_info.width))
  175914. {
  175915. png_write_finish_row(png_ptr);
  175916. return;
  175917. }
  175918. }
  175919. #endif
  175920. if (png_ptr->transformations)
  175921. png_do_write_transformations(png_ptr);
  175922. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175923. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175924. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175925. {
  175926. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175927. }
  175928. #endif
  175929. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175930. if (png_ptr->write_row_fn != NULL)
  175931. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175932. }
  175933. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175934. void PNGAPI
  175935. png_set_flush(png_structp png_ptr, int nrows)
  175936. {
  175937. png_debug(1, "in png_set_flush\n");
  175938. if (png_ptr == NULL)
  175939. return;
  175940. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175941. }
  175942. void PNGAPI
  175943. png_write_flush(png_structp png_ptr)
  175944. {
  175945. int wrote_IDAT;
  175946. png_debug(1, "in png_write_flush\n");
  175947. if (png_ptr == NULL)
  175948. return;
  175949. if (png_ptr->row_number >= png_ptr->num_rows)
  175950. return;
  175951. do
  175952. {
  175953. int ret;
  175954. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  175955. wrote_IDAT = 0;
  175956. if (ret != Z_OK)
  175957. {
  175958. if (png_ptr->zstream.msg != NULL)
  175959. png_error(png_ptr, png_ptr->zstream.msg);
  175960. else
  175961. png_error(png_ptr, "zlib error");
  175962. }
  175963. if (!(png_ptr->zstream.avail_out))
  175964. {
  175965. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175966. png_ptr->zbuf_size);
  175967. png_ptr->zstream.next_out = png_ptr->zbuf;
  175968. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175969. wrote_IDAT = 1;
  175970. }
  175971. } while(wrote_IDAT == 1);
  175972. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  175973. {
  175974. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175975. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  175976. png_ptr->zstream.next_out = png_ptr->zbuf;
  175977. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175978. }
  175979. png_ptr->flush_rows = 0;
  175980. png_flush(png_ptr);
  175981. }
  175982. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175983. void PNGAPI
  175984. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  175985. {
  175986. png_structp png_ptr = NULL;
  175987. png_infop info_ptr = NULL;
  175988. #ifdef PNG_USER_MEM_SUPPORTED
  175989. png_free_ptr free_fn = NULL;
  175990. png_voidp mem_ptr = NULL;
  175991. #endif
  175992. png_debug(1, "in png_destroy_write_struct\n");
  175993. if (png_ptr_ptr != NULL)
  175994. {
  175995. png_ptr = *png_ptr_ptr;
  175996. #ifdef PNG_USER_MEM_SUPPORTED
  175997. free_fn = png_ptr->free_fn;
  175998. mem_ptr = png_ptr->mem_ptr;
  175999. #endif
  176000. }
  176001. if (info_ptr_ptr != NULL)
  176002. info_ptr = *info_ptr_ptr;
  176003. if (info_ptr != NULL)
  176004. {
  176005. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  176006. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  176007. if (png_ptr->num_chunk_list)
  176008. {
  176009. png_free(png_ptr, png_ptr->chunk_list);
  176010. png_ptr->chunk_list=NULL;
  176011. png_ptr->num_chunk_list=0;
  176012. }
  176013. #endif
  176014. #ifdef PNG_USER_MEM_SUPPORTED
  176015. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  176016. (png_voidp)mem_ptr);
  176017. #else
  176018. png_destroy_struct((png_voidp)info_ptr);
  176019. #endif
  176020. *info_ptr_ptr = NULL;
  176021. }
  176022. if (png_ptr != NULL)
  176023. {
  176024. png_write_destroy(png_ptr);
  176025. #ifdef PNG_USER_MEM_SUPPORTED
  176026. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  176027. (png_voidp)mem_ptr);
  176028. #else
  176029. png_destroy_struct((png_voidp)png_ptr);
  176030. #endif
  176031. *png_ptr_ptr = NULL;
  176032. }
  176033. }
  176034. void /* PRIVATE */
  176035. png_write_destroy(png_structp png_ptr)
  176036. {
  176037. #ifdef PNG_SETJMP_SUPPORTED
  176038. jmp_buf tmp_jmp; /* save jump buffer */
  176039. #endif
  176040. png_error_ptr error_fn;
  176041. png_error_ptr warning_fn;
  176042. png_voidp error_ptr;
  176043. #ifdef PNG_USER_MEM_SUPPORTED
  176044. png_free_ptr free_fn;
  176045. #endif
  176046. png_debug(1, "in png_write_destroy\n");
  176047. deflateEnd(&png_ptr->zstream);
  176048. png_free(png_ptr, png_ptr->zbuf);
  176049. png_free(png_ptr, png_ptr->row_buf);
  176050. png_free(png_ptr, png_ptr->prev_row);
  176051. png_free(png_ptr, png_ptr->sub_row);
  176052. png_free(png_ptr, png_ptr->up_row);
  176053. png_free(png_ptr, png_ptr->avg_row);
  176054. png_free(png_ptr, png_ptr->paeth_row);
  176055. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176056. png_free(png_ptr, png_ptr->time_buffer);
  176057. #endif
  176058. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176059. png_free(png_ptr, png_ptr->prev_filters);
  176060. png_free(png_ptr, png_ptr->filter_weights);
  176061. png_free(png_ptr, png_ptr->inv_filter_weights);
  176062. png_free(png_ptr, png_ptr->filter_costs);
  176063. png_free(png_ptr, png_ptr->inv_filter_costs);
  176064. #endif
  176065. #ifdef PNG_SETJMP_SUPPORTED
  176066. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176067. #endif
  176068. error_fn = png_ptr->error_fn;
  176069. warning_fn = png_ptr->warning_fn;
  176070. error_ptr = png_ptr->error_ptr;
  176071. #ifdef PNG_USER_MEM_SUPPORTED
  176072. free_fn = png_ptr->free_fn;
  176073. #endif
  176074. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176075. png_ptr->error_fn = error_fn;
  176076. png_ptr->warning_fn = warning_fn;
  176077. png_ptr->error_ptr = error_ptr;
  176078. #ifdef PNG_USER_MEM_SUPPORTED
  176079. png_ptr->free_fn = free_fn;
  176080. #endif
  176081. #ifdef PNG_SETJMP_SUPPORTED
  176082. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176083. #endif
  176084. }
  176085. void PNGAPI
  176086. png_set_filter(png_structp png_ptr, int method, int filters)
  176087. {
  176088. png_debug(1, "in png_set_filter\n");
  176089. if (png_ptr == NULL)
  176090. return;
  176091. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176092. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176093. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176094. method = PNG_FILTER_TYPE_BASE;
  176095. #endif
  176096. if (method == PNG_FILTER_TYPE_BASE)
  176097. {
  176098. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176099. {
  176100. #ifndef PNG_NO_WRITE_FILTER
  176101. case 5:
  176102. case 6:
  176103. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176104. #endif /* PNG_NO_WRITE_FILTER */
  176105. case PNG_FILTER_VALUE_NONE:
  176106. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176107. #ifndef PNG_NO_WRITE_FILTER
  176108. case PNG_FILTER_VALUE_SUB:
  176109. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176110. case PNG_FILTER_VALUE_UP:
  176111. png_ptr->do_filter=PNG_FILTER_UP; break;
  176112. case PNG_FILTER_VALUE_AVG:
  176113. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176114. case PNG_FILTER_VALUE_PAETH:
  176115. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176116. default: png_ptr->do_filter = (png_byte)filters; break;
  176117. #else
  176118. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176119. #endif /* PNG_NO_WRITE_FILTER */
  176120. }
  176121. if (png_ptr->row_buf != NULL)
  176122. {
  176123. #ifndef PNG_NO_WRITE_FILTER
  176124. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176125. {
  176126. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176127. (png_ptr->rowbytes + 1));
  176128. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176129. }
  176130. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176131. {
  176132. if (png_ptr->prev_row == NULL)
  176133. {
  176134. png_warning(png_ptr, "Can't add Up filter after starting");
  176135. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176136. }
  176137. else
  176138. {
  176139. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176140. (png_ptr->rowbytes + 1));
  176141. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176142. }
  176143. }
  176144. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176145. {
  176146. if (png_ptr->prev_row == NULL)
  176147. {
  176148. png_warning(png_ptr, "Can't add Average filter after starting");
  176149. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176150. }
  176151. else
  176152. {
  176153. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176154. (png_ptr->rowbytes + 1));
  176155. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176156. }
  176157. }
  176158. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176159. png_ptr->paeth_row == NULL)
  176160. {
  176161. if (png_ptr->prev_row == NULL)
  176162. {
  176163. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176164. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176165. }
  176166. else
  176167. {
  176168. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176169. (png_ptr->rowbytes + 1));
  176170. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176171. }
  176172. }
  176173. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176174. #endif /* PNG_NO_WRITE_FILTER */
  176175. png_ptr->do_filter = PNG_FILTER_NONE;
  176176. }
  176177. }
  176178. else
  176179. png_error(png_ptr, "Unknown custom filter method");
  176180. }
  176181. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176182. void PNGAPI
  176183. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176184. int num_weights, png_doublep filter_weights,
  176185. png_doublep filter_costs)
  176186. {
  176187. int i;
  176188. png_debug(1, "in png_set_filter_heuristics\n");
  176189. if (png_ptr == NULL)
  176190. return;
  176191. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176192. {
  176193. png_warning(png_ptr, "Unknown filter heuristic method");
  176194. return;
  176195. }
  176196. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176197. {
  176198. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176199. }
  176200. if (num_weights < 0 || filter_weights == NULL ||
  176201. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176202. {
  176203. num_weights = 0;
  176204. }
  176205. png_ptr->num_prev_filters = (png_byte)num_weights;
  176206. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176207. if (num_weights > 0)
  176208. {
  176209. if (png_ptr->prev_filters == NULL)
  176210. {
  176211. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176212. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176213. for (i = 0; i < num_weights; i++)
  176214. {
  176215. png_ptr->prev_filters[i] = 255;
  176216. }
  176217. }
  176218. if (png_ptr->filter_weights == NULL)
  176219. {
  176220. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176221. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176222. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176223. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176224. for (i = 0; i < num_weights; i++)
  176225. {
  176226. png_ptr->inv_filter_weights[i] =
  176227. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176228. }
  176229. }
  176230. for (i = 0; i < num_weights; i++)
  176231. {
  176232. if (filter_weights[i] < 0.0)
  176233. {
  176234. png_ptr->inv_filter_weights[i] =
  176235. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176236. }
  176237. else
  176238. {
  176239. png_ptr->inv_filter_weights[i] =
  176240. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176241. png_ptr->filter_weights[i] =
  176242. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176243. }
  176244. }
  176245. }
  176246. if (png_ptr->filter_costs == NULL)
  176247. {
  176248. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176249. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176250. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176251. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176252. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176253. {
  176254. png_ptr->inv_filter_costs[i] =
  176255. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176256. }
  176257. }
  176258. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176259. {
  176260. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176261. {
  176262. png_ptr->inv_filter_costs[i] =
  176263. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176264. }
  176265. else if (filter_costs[i] >= 1.0)
  176266. {
  176267. png_ptr->inv_filter_costs[i] =
  176268. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176269. png_ptr->filter_costs[i] =
  176270. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176271. }
  176272. }
  176273. }
  176274. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176275. void PNGAPI
  176276. png_set_compression_level(png_structp png_ptr, int level)
  176277. {
  176278. png_debug(1, "in png_set_compression_level\n");
  176279. if (png_ptr == NULL)
  176280. return;
  176281. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176282. png_ptr->zlib_level = level;
  176283. }
  176284. void PNGAPI
  176285. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176286. {
  176287. png_debug(1, "in png_set_compression_mem_level\n");
  176288. if (png_ptr == NULL)
  176289. return;
  176290. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176291. png_ptr->zlib_mem_level = mem_level;
  176292. }
  176293. void PNGAPI
  176294. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176295. {
  176296. png_debug(1, "in png_set_compression_strategy\n");
  176297. if (png_ptr == NULL)
  176298. return;
  176299. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176300. png_ptr->zlib_strategy = strategy;
  176301. }
  176302. void PNGAPI
  176303. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176304. {
  176305. if (png_ptr == NULL)
  176306. return;
  176307. if (window_bits > 15)
  176308. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176309. else if (window_bits < 8)
  176310. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176311. #ifndef WBITS_8_OK
  176312. if (window_bits == 8)
  176313. {
  176314. png_warning(png_ptr, "Compression window is being reset to 512");
  176315. window_bits=9;
  176316. }
  176317. #endif
  176318. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176319. png_ptr->zlib_window_bits = window_bits;
  176320. }
  176321. void PNGAPI
  176322. png_set_compression_method(png_structp png_ptr, int method)
  176323. {
  176324. png_debug(1, "in png_set_compression_method\n");
  176325. if (png_ptr == NULL)
  176326. return;
  176327. if (method != 8)
  176328. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176329. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176330. png_ptr->zlib_method = method;
  176331. }
  176332. void PNGAPI
  176333. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176334. {
  176335. if (png_ptr == NULL)
  176336. return;
  176337. png_ptr->write_row_fn = write_row_fn;
  176338. }
  176339. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176340. void PNGAPI
  176341. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176342. write_user_transform_fn)
  176343. {
  176344. png_debug(1, "in png_set_write_user_transform_fn\n");
  176345. if (png_ptr == NULL)
  176346. return;
  176347. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176348. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176349. }
  176350. #endif
  176351. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176352. void PNGAPI
  176353. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176354. int transforms, voidp params)
  176355. {
  176356. if (png_ptr == NULL || info_ptr == NULL)
  176357. return;
  176358. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176359. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176360. png_set_invert_alpha(png_ptr);
  176361. #endif
  176362. png_write_info(png_ptr, info_ptr);
  176363. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176364. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176365. png_set_invert_mono(png_ptr);
  176366. #endif
  176367. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176368. if ((transforms & PNG_TRANSFORM_SHIFT)
  176369. && (info_ptr->valid & PNG_INFO_sBIT))
  176370. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176371. #endif
  176372. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176373. if (transforms & PNG_TRANSFORM_PACKING)
  176374. png_set_packing(png_ptr);
  176375. #endif
  176376. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176377. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176378. png_set_swap_alpha(png_ptr);
  176379. #endif
  176380. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176381. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176382. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176383. #endif
  176384. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176385. if (transforms & PNG_TRANSFORM_BGR)
  176386. png_set_bgr(png_ptr);
  176387. #endif
  176388. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176389. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176390. png_set_swap(png_ptr);
  176391. #endif
  176392. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176393. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176394. png_set_packswap(png_ptr);
  176395. #endif
  176396. if (info_ptr->valid & PNG_INFO_IDAT)
  176397. png_write_image(png_ptr, info_ptr->row_pointers);
  176398. png_write_end(png_ptr, info_ptr);
  176399. transforms = transforms; /* quiet compiler warnings */
  176400. params = params;
  176401. }
  176402. #endif
  176403. #endif /* PNG_WRITE_SUPPORTED */
  176404. /*** End of inlined file: pngwrite.c ***/
  176405. /*** Start of inlined file: pngwtran.c ***/
  176406. #define PNG_INTERNAL
  176407. #ifdef PNG_WRITE_SUPPORTED
  176408. void /* PRIVATE */
  176409. png_do_write_transformations(png_structp png_ptr)
  176410. {
  176411. png_debug(1, "in png_do_write_transformations\n");
  176412. if (png_ptr == NULL)
  176413. return;
  176414. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176415. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176416. if(png_ptr->write_user_transform_fn != NULL)
  176417. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176418. (png_ptr, /* png_ptr */
  176419. &(png_ptr->row_info), /* row_info: */
  176420. png_ptr->row_buf + 1); /* start of pixel data for row */
  176421. #endif
  176422. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176423. if (png_ptr->transformations & PNG_FILLER)
  176424. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176425. png_ptr->flags);
  176426. #endif
  176427. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176428. if (png_ptr->transformations & PNG_PACKSWAP)
  176429. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176430. #endif
  176431. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176432. if (png_ptr->transformations & PNG_PACK)
  176433. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176434. (png_uint_32)png_ptr->bit_depth);
  176435. #endif
  176436. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176437. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176438. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176439. #endif
  176440. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176441. if (png_ptr->transformations & PNG_SHIFT)
  176442. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176443. &(png_ptr->shift));
  176444. #endif
  176445. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176446. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176447. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176448. #endif
  176449. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176450. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176451. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176452. #endif
  176453. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176454. if (png_ptr->transformations & PNG_BGR)
  176455. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176456. #endif
  176457. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176458. if (png_ptr->transformations & PNG_INVERT_MONO)
  176459. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176460. #endif
  176461. }
  176462. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176463. void /* PRIVATE */
  176464. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176465. {
  176466. png_debug(1, "in png_do_pack\n");
  176467. if (row_info->bit_depth == 8 &&
  176468. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176469. row != NULL && row_info != NULL &&
  176470. #endif
  176471. row_info->channels == 1)
  176472. {
  176473. switch ((int)bit_depth)
  176474. {
  176475. case 1:
  176476. {
  176477. png_bytep sp, dp;
  176478. int mask, v;
  176479. png_uint_32 i;
  176480. png_uint_32 row_width = row_info->width;
  176481. sp = row;
  176482. dp = row;
  176483. mask = 0x80;
  176484. v = 0;
  176485. for (i = 0; i < row_width; i++)
  176486. {
  176487. if (*sp != 0)
  176488. v |= mask;
  176489. sp++;
  176490. if (mask > 1)
  176491. mask >>= 1;
  176492. else
  176493. {
  176494. mask = 0x80;
  176495. *dp = (png_byte)v;
  176496. dp++;
  176497. v = 0;
  176498. }
  176499. }
  176500. if (mask != 0x80)
  176501. *dp = (png_byte)v;
  176502. break;
  176503. }
  176504. case 2:
  176505. {
  176506. png_bytep sp, dp;
  176507. int shift, v;
  176508. png_uint_32 i;
  176509. png_uint_32 row_width = row_info->width;
  176510. sp = row;
  176511. dp = row;
  176512. shift = 6;
  176513. v = 0;
  176514. for (i = 0; i < row_width; i++)
  176515. {
  176516. png_byte value;
  176517. value = (png_byte)(*sp & 0x03);
  176518. v |= (value << shift);
  176519. if (shift == 0)
  176520. {
  176521. shift = 6;
  176522. *dp = (png_byte)v;
  176523. dp++;
  176524. v = 0;
  176525. }
  176526. else
  176527. shift -= 2;
  176528. sp++;
  176529. }
  176530. if (shift != 6)
  176531. *dp = (png_byte)v;
  176532. break;
  176533. }
  176534. case 4:
  176535. {
  176536. png_bytep sp, dp;
  176537. int shift, v;
  176538. png_uint_32 i;
  176539. png_uint_32 row_width = row_info->width;
  176540. sp = row;
  176541. dp = row;
  176542. shift = 4;
  176543. v = 0;
  176544. for (i = 0; i < row_width; i++)
  176545. {
  176546. png_byte value;
  176547. value = (png_byte)(*sp & 0x0f);
  176548. v |= (value << shift);
  176549. if (shift == 0)
  176550. {
  176551. shift = 4;
  176552. *dp = (png_byte)v;
  176553. dp++;
  176554. v = 0;
  176555. }
  176556. else
  176557. shift -= 4;
  176558. sp++;
  176559. }
  176560. if (shift != 4)
  176561. *dp = (png_byte)v;
  176562. break;
  176563. }
  176564. }
  176565. row_info->bit_depth = (png_byte)bit_depth;
  176566. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176567. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176568. row_info->width);
  176569. }
  176570. }
  176571. #endif
  176572. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176573. void /* PRIVATE */
  176574. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176575. {
  176576. png_debug(1, "in png_do_shift\n");
  176577. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176578. if (row != NULL && row_info != NULL &&
  176579. #else
  176580. if (
  176581. #endif
  176582. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176583. {
  176584. int shift_start[4], shift_dec[4];
  176585. int channels = 0;
  176586. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176587. {
  176588. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176589. shift_dec[channels] = bit_depth->red;
  176590. channels++;
  176591. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176592. shift_dec[channels] = bit_depth->green;
  176593. channels++;
  176594. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176595. shift_dec[channels] = bit_depth->blue;
  176596. channels++;
  176597. }
  176598. else
  176599. {
  176600. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176601. shift_dec[channels] = bit_depth->gray;
  176602. channels++;
  176603. }
  176604. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176605. {
  176606. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176607. shift_dec[channels] = bit_depth->alpha;
  176608. channels++;
  176609. }
  176610. if (row_info->bit_depth < 8)
  176611. {
  176612. png_bytep bp = row;
  176613. png_uint_32 i;
  176614. png_byte mask;
  176615. png_uint_32 row_bytes = row_info->rowbytes;
  176616. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176617. mask = 0x55;
  176618. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176619. mask = 0x11;
  176620. else
  176621. mask = 0xff;
  176622. for (i = 0; i < row_bytes; i++, bp++)
  176623. {
  176624. png_uint_16 v;
  176625. int j;
  176626. v = *bp;
  176627. *bp = 0;
  176628. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176629. {
  176630. if (j > 0)
  176631. *bp |= (png_byte)((v << j) & 0xff);
  176632. else
  176633. *bp |= (png_byte)((v >> (-j)) & mask);
  176634. }
  176635. }
  176636. }
  176637. else if (row_info->bit_depth == 8)
  176638. {
  176639. png_bytep bp = row;
  176640. png_uint_32 i;
  176641. png_uint_32 istop = channels * row_info->width;
  176642. for (i = 0; i < istop; i++, bp++)
  176643. {
  176644. png_uint_16 v;
  176645. int j;
  176646. int c = (int)(i%channels);
  176647. v = *bp;
  176648. *bp = 0;
  176649. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176650. {
  176651. if (j > 0)
  176652. *bp |= (png_byte)((v << j) & 0xff);
  176653. else
  176654. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176655. }
  176656. }
  176657. }
  176658. else
  176659. {
  176660. png_bytep bp;
  176661. png_uint_32 i;
  176662. png_uint_32 istop = channels * row_info->width;
  176663. for (bp = row, i = 0; i < istop; i++)
  176664. {
  176665. int c = (int)(i%channels);
  176666. png_uint_16 value, v;
  176667. int j;
  176668. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176669. value = 0;
  176670. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176671. {
  176672. if (j > 0)
  176673. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176674. else
  176675. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176676. }
  176677. *bp++ = (png_byte)(value >> 8);
  176678. *bp++ = (png_byte)(value & 0xff);
  176679. }
  176680. }
  176681. }
  176682. }
  176683. #endif
  176684. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176685. void /* PRIVATE */
  176686. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176687. {
  176688. png_debug(1, "in png_do_write_swap_alpha\n");
  176689. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176690. if (row != NULL && row_info != NULL)
  176691. #endif
  176692. {
  176693. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176694. {
  176695. if (row_info->bit_depth == 8)
  176696. {
  176697. png_bytep sp, dp;
  176698. png_uint_32 i;
  176699. png_uint_32 row_width = row_info->width;
  176700. for (i = 0, sp = dp = row; i < row_width; i++)
  176701. {
  176702. png_byte save = *(sp++);
  176703. *(dp++) = *(sp++);
  176704. *(dp++) = *(sp++);
  176705. *(dp++) = *(sp++);
  176706. *(dp++) = save;
  176707. }
  176708. }
  176709. else
  176710. {
  176711. png_bytep sp, dp;
  176712. png_uint_32 i;
  176713. png_uint_32 row_width = row_info->width;
  176714. for (i = 0, sp = dp = row; i < row_width; i++)
  176715. {
  176716. png_byte save[2];
  176717. save[0] = *(sp++);
  176718. save[1] = *(sp++);
  176719. *(dp++) = *(sp++);
  176720. *(dp++) = *(sp++);
  176721. *(dp++) = *(sp++);
  176722. *(dp++) = *(sp++);
  176723. *(dp++) = *(sp++);
  176724. *(dp++) = *(sp++);
  176725. *(dp++) = save[0];
  176726. *(dp++) = save[1];
  176727. }
  176728. }
  176729. }
  176730. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176731. {
  176732. if (row_info->bit_depth == 8)
  176733. {
  176734. png_bytep sp, dp;
  176735. png_uint_32 i;
  176736. png_uint_32 row_width = row_info->width;
  176737. for (i = 0, sp = dp = row; i < row_width; i++)
  176738. {
  176739. png_byte save = *(sp++);
  176740. *(dp++) = *(sp++);
  176741. *(dp++) = save;
  176742. }
  176743. }
  176744. else
  176745. {
  176746. png_bytep sp, dp;
  176747. png_uint_32 i;
  176748. png_uint_32 row_width = row_info->width;
  176749. for (i = 0, sp = dp = row; i < row_width; i++)
  176750. {
  176751. png_byte save[2];
  176752. save[0] = *(sp++);
  176753. save[1] = *(sp++);
  176754. *(dp++) = *(sp++);
  176755. *(dp++) = *(sp++);
  176756. *(dp++) = save[0];
  176757. *(dp++) = save[1];
  176758. }
  176759. }
  176760. }
  176761. }
  176762. }
  176763. #endif
  176764. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176765. void /* PRIVATE */
  176766. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176767. {
  176768. png_debug(1, "in png_do_write_invert_alpha\n");
  176769. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176770. if (row != NULL && row_info != NULL)
  176771. #endif
  176772. {
  176773. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176774. {
  176775. if (row_info->bit_depth == 8)
  176776. {
  176777. png_bytep sp, dp;
  176778. png_uint_32 i;
  176779. png_uint_32 row_width = row_info->width;
  176780. for (i = 0, sp = dp = row; i < row_width; i++)
  176781. {
  176782. sp+=3; dp = sp;
  176783. *(dp++) = (png_byte)(255 - *(sp++));
  176784. }
  176785. }
  176786. else
  176787. {
  176788. png_bytep sp, dp;
  176789. png_uint_32 i;
  176790. png_uint_32 row_width = row_info->width;
  176791. for (i = 0, sp = dp = row; i < row_width; i++)
  176792. {
  176793. sp+=6; dp = sp;
  176794. *(dp++) = (png_byte)(255 - *(sp++));
  176795. *(dp++) = (png_byte)(255 - *(sp++));
  176796. }
  176797. }
  176798. }
  176799. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176800. {
  176801. if (row_info->bit_depth == 8)
  176802. {
  176803. png_bytep sp, dp;
  176804. png_uint_32 i;
  176805. png_uint_32 row_width = row_info->width;
  176806. for (i = 0, sp = dp = row; i < row_width; i++)
  176807. {
  176808. *(dp++) = *(sp++);
  176809. *(dp++) = (png_byte)(255 - *(sp++));
  176810. }
  176811. }
  176812. else
  176813. {
  176814. png_bytep sp, dp;
  176815. png_uint_32 i;
  176816. png_uint_32 row_width = row_info->width;
  176817. for (i = 0, sp = dp = row; i < row_width; i++)
  176818. {
  176819. sp+=2; dp = sp;
  176820. *(dp++) = (png_byte)(255 - *(sp++));
  176821. *(dp++) = (png_byte)(255 - *(sp++));
  176822. }
  176823. }
  176824. }
  176825. }
  176826. }
  176827. #endif
  176828. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176829. void /* PRIVATE */
  176830. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176831. {
  176832. png_debug(1, "in png_do_write_intrapixel\n");
  176833. if (
  176834. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176835. row != NULL && row_info != NULL &&
  176836. #endif
  176837. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176838. {
  176839. int bytes_per_pixel;
  176840. png_uint_32 row_width = row_info->width;
  176841. if (row_info->bit_depth == 8)
  176842. {
  176843. png_bytep rp;
  176844. png_uint_32 i;
  176845. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176846. bytes_per_pixel = 3;
  176847. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176848. bytes_per_pixel = 4;
  176849. else
  176850. return;
  176851. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176852. {
  176853. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176854. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176855. }
  176856. }
  176857. else if (row_info->bit_depth == 16)
  176858. {
  176859. png_bytep rp;
  176860. png_uint_32 i;
  176861. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176862. bytes_per_pixel = 6;
  176863. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176864. bytes_per_pixel = 8;
  176865. else
  176866. return;
  176867. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176868. {
  176869. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176870. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176871. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176872. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176873. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176874. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176875. *(rp+1) = (png_byte)(red & 0xff);
  176876. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176877. *(rp+5) = (png_byte)(blue & 0xff);
  176878. }
  176879. }
  176880. }
  176881. }
  176882. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176883. #endif /* PNG_WRITE_SUPPORTED */
  176884. /*** End of inlined file: pngwtran.c ***/
  176885. /*** Start of inlined file: pngwutil.c ***/
  176886. #define PNG_INTERNAL
  176887. #ifdef PNG_WRITE_SUPPORTED
  176888. void PNGAPI
  176889. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176890. {
  176891. buf[0] = (png_byte)((i >> 24) & 0xff);
  176892. buf[1] = (png_byte)((i >> 16) & 0xff);
  176893. buf[2] = (png_byte)((i >> 8) & 0xff);
  176894. buf[3] = (png_byte)(i & 0xff);
  176895. }
  176896. void PNGAPI
  176897. png_save_int_32(png_bytep buf, png_int_32 i)
  176898. {
  176899. buf[0] = (png_byte)((i >> 24) & 0xff);
  176900. buf[1] = (png_byte)((i >> 16) & 0xff);
  176901. buf[2] = (png_byte)((i >> 8) & 0xff);
  176902. buf[3] = (png_byte)(i & 0xff);
  176903. }
  176904. void PNGAPI
  176905. png_save_uint_16(png_bytep buf, unsigned int i)
  176906. {
  176907. buf[0] = (png_byte)((i >> 8) & 0xff);
  176908. buf[1] = (png_byte)(i & 0xff);
  176909. }
  176910. void PNGAPI
  176911. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176912. png_bytep data, png_size_t length)
  176913. {
  176914. if(png_ptr == NULL) return;
  176915. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176916. png_write_chunk_data(png_ptr, data, length);
  176917. png_write_chunk_end(png_ptr);
  176918. }
  176919. void PNGAPI
  176920. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176921. png_uint_32 length)
  176922. {
  176923. png_byte buf[4];
  176924. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176925. if(png_ptr == NULL) return;
  176926. png_save_uint_32(buf, length);
  176927. png_write_data(png_ptr, buf, (png_size_t)4);
  176928. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176929. png_reset_crc(png_ptr);
  176930. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176931. }
  176932. void PNGAPI
  176933. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176934. {
  176935. if(png_ptr == NULL) return;
  176936. if (data != NULL && length > 0)
  176937. {
  176938. png_calculate_crc(png_ptr, data, length);
  176939. png_write_data(png_ptr, data, length);
  176940. }
  176941. }
  176942. void PNGAPI
  176943. png_write_chunk_end(png_structp png_ptr)
  176944. {
  176945. png_byte buf[4];
  176946. if(png_ptr == NULL) return;
  176947. png_save_uint_32(buf, png_ptr->crc);
  176948. png_write_data(png_ptr, buf, (png_size_t)4);
  176949. }
  176950. void /* PRIVATE */
  176951. png_write_sig(png_structp png_ptr)
  176952. {
  176953. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  176954. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  176955. (png_size_t)8 - png_ptr->sig_bytes);
  176956. if(png_ptr->sig_bytes < 3)
  176957. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  176958. }
  176959. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  176960. typedef struct
  176961. {
  176962. char *input; /* the uncompressed input data */
  176963. int input_len; /* its length */
  176964. int num_output_ptr; /* number of output pointers used */
  176965. int max_output_ptr; /* size of output_ptr */
  176966. png_charpp output_ptr; /* array of pointers to output */
  176967. } compression_state;
  176968. static int /* PRIVATE */
  176969. png_text_compress(png_structp png_ptr,
  176970. png_charp text, png_size_t text_len, int compression,
  176971. compression_state *comp)
  176972. {
  176973. int ret;
  176974. comp->num_output_ptr = 0;
  176975. comp->max_output_ptr = 0;
  176976. comp->output_ptr = NULL;
  176977. comp->input = NULL;
  176978. comp->input_len = 0;
  176979. if (compression == PNG_TEXT_COMPRESSION_NONE)
  176980. {
  176981. comp->input = text;
  176982. comp->input_len = text_len;
  176983. return((int)text_len);
  176984. }
  176985. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  176986. {
  176987. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176988. char msg[50];
  176989. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  176990. png_warning(png_ptr, msg);
  176991. #else
  176992. png_warning(png_ptr, "Unknown compression type");
  176993. #endif
  176994. }
  176995. png_ptr->zstream.avail_in = (uInt)text_len;
  176996. png_ptr->zstream.next_in = (Bytef *)text;
  176997. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176998. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  176999. do
  177000. {
  177001. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  177002. if (ret != Z_OK)
  177003. {
  177004. if (png_ptr->zstream.msg != NULL)
  177005. png_error(png_ptr, png_ptr->zstream.msg);
  177006. else
  177007. png_error(png_ptr, "zlib error");
  177008. }
  177009. if (!(png_ptr->zstream.avail_out))
  177010. {
  177011. if (comp->num_output_ptr >= comp->max_output_ptr)
  177012. {
  177013. int old_max;
  177014. old_max = comp->max_output_ptr;
  177015. comp->max_output_ptr = comp->num_output_ptr + 4;
  177016. if (comp->output_ptr != NULL)
  177017. {
  177018. png_charpp old_ptr;
  177019. old_ptr = comp->output_ptr;
  177020. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177021. (png_uint_32)(comp->max_output_ptr *
  177022. png_sizeof (png_charpp)));
  177023. png_memcpy(comp->output_ptr, old_ptr, old_max
  177024. * png_sizeof (png_charp));
  177025. png_free(png_ptr, old_ptr);
  177026. }
  177027. else
  177028. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177029. (png_uint_32)(comp->max_output_ptr *
  177030. png_sizeof (png_charp)));
  177031. }
  177032. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177033. (png_uint_32)png_ptr->zbuf_size);
  177034. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177035. png_ptr->zbuf_size);
  177036. comp->num_output_ptr++;
  177037. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177038. png_ptr->zstream.next_out = png_ptr->zbuf;
  177039. }
  177040. } while (png_ptr->zstream.avail_in);
  177041. do
  177042. {
  177043. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177044. if (ret == Z_OK)
  177045. {
  177046. if (!(png_ptr->zstream.avail_out))
  177047. {
  177048. if (comp->num_output_ptr >= comp->max_output_ptr)
  177049. {
  177050. int old_max;
  177051. old_max = comp->max_output_ptr;
  177052. comp->max_output_ptr = comp->num_output_ptr + 4;
  177053. if (comp->output_ptr != NULL)
  177054. {
  177055. png_charpp old_ptr;
  177056. old_ptr = comp->output_ptr;
  177057. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177058. (png_uint_32)(comp->max_output_ptr *
  177059. png_sizeof (png_charpp)));
  177060. png_memcpy(comp->output_ptr, old_ptr,
  177061. old_max * png_sizeof (png_charp));
  177062. png_free(png_ptr, old_ptr);
  177063. }
  177064. else
  177065. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177066. (png_uint_32)(comp->max_output_ptr *
  177067. png_sizeof (png_charp)));
  177068. }
  177069. comp->output_ptr[comp->num_output_ptr] =
  177070. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177071. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177072. png_ptr->zbuf_size);
  177073. comp->num_output_ptr++;
  177074. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177075. png_ptr->zstream.next_out = png_ptr->zbuf;
  177076. }
  177077. }
  177078. else if (ret != Z_STREAM_END)
  177079. {
  177080. if (png_ptr->zstream.msg != NULL)
  177081. png_error(png_ptr, png_ptr->zstream.msg);
  177082. else
  177083. png_error(png_ptr, "zlib error");
  177084. }
  177085. } while (ret != Z_STREAM_END);
  177086. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177087. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177088. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177089. return((int)text_len);
  177090. }
  177091. static void /* PRIVATE */
  177092. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177093. {
  177094. int i;
  177095. if (comp->input)
  177096. {
  177097. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177098. (png_size_t)comp->input_len);
  177099. return;
  177100. }
  177101. for (i = 0; i < comp->num_output_ptr; i++)
  177102. {
  177103. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177104. png_ptr->zbuf_size);
  177105. png_free(png_ptr, comp->output_ptr[i]);
  177106. comp->output_ptr[i]=NULL;
  177107. }
  177108. if (comp->max_output_ptr != 0)
  177109. png_free(png_ptr, comp->output_ptr);
  177110. comp->output_ptr=NULL;
  177111. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177112. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177113. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177114. deflateReset(&png_ptr->zstream);
  177115. png_ptr->zstream.data_type = Z_BINARY;
  177116. }
  177117. #endif
  177118. void /* PRIVATE */
  177119. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177120. int bit_depth, int color_type, int compression_type, int filter_type,
  177121. int interlace_type)
  177122. {
  177123. #ifdef PNG_USE_LOCAL_ARRAYS
  177124. PNG_IHDR;
  177125. #endif
  177126. png_byte buf[13]; /* buffer to store the IHDR info */
  177127. png_debug(1, "in png_write_IHDR\n");
  177128. switch (color_type)
  177129. {
  177130. case PNG_COLOR_TYPE_GRAY:
  177131. switch (bit_depth)
  177132. {
  177133. case 1:
  177134. case 2:
  177135. case 4:
  177136. case 8:
  177137. case 16: png_ptr->channels = 1; break;
  177138. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177139. }
  177140. break;
  177141. case PNG_COLOR_TYPE_RGB:
  177142. if (bit_depth != 8 && bit_depth != 16)
  177143. png_error(png_ptr, "Invalid bit depth for RGB image");
  177144. png_ptr->channels = 3;
  177145. break;
  177146. case PNG_COLOR_TYPE_PALETTE:
  177147. switch (bit_depth)
  177148. {
  177149. case 1:
  177150. case 2:
  177151. case 4:
  177152. case 8: png_ptr->channels = 1; break;
  177153. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177154. }
  177155. break;
  177156. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177157. if (bit_depth != 8 && bit_depth != 16)
  177158. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177159. png_ptr->channels = 2;
  177160. break;
  177161. case PNG_COLOR_TYPE_RGB_ALPHA:
  177162. if (bit_depth != 8 && bit_depth != 16)
  177163. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177164. png_ptr->channels = 4;
  177165. break;
  177166. default:
  177167. png_error(png_ptr, "Invalid image color type specified");
  177168. }
  177169. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177170. {
  177171. png_warning(png_ptr, "Invalid compression type specified");
  177172. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177173. }
  177174. if (
  177175. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177176. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177177. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177178. (color_type == PNG_COLOR_TYPE_RGB ||
  177179. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177180. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177181. #endif
  177182. filter_type != PNG_FILTER_TYPE_BASE)
  177183. {
  177184. png_warning(png_ptr, "Invalid filter type specified");
  177185. filter_type = PNG_FILTER_TYPE_BASE;
  177186. }
  177187. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177188. if (interlace_type != PNG_INTERLACE_NONE &&
  177189. interlace_type != PNG_INTERLACE_ADAM7)
  177190. {
  177191. png_warning(png_ptr, "Invalid interlace type specified");
  177192. interlace_type = PNG_INTERLACE_ADAM7;
  177193. }
  177194. #else
  177195. interlace_type=PNG_INTERLACE_NONE;
  177196. #endif
  177197. png_ptr->bit_depth = (png_byte)bit_depth;
  177198. png_ptr->color_type = (png_byte)color_type;
  177199. png_ptr->interlaced = (png_byte)interlace_type;
  177200. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177201. png_ptr->filter_type = (png_byte)filter_type;
  177202. #endif
  177203. png_ptr->compression_type = (png_byte)compression_type;
  177204. png_ptr->width = width;
  177205. png_ptr->height = height;
  177206. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177207. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177208. png_ptr->usr_width = png_ptr->width;
  177209. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177210. png_ptr->usr_channels = png_ptr->channels;
  177211. png_save_uint_32(buf, width);
  177212. png_save_uint_32(buf + 4, height);
  177213. buf[8] = (png_byte)bit_depth;
  177214. buf[9] = (png_byte)color_type;
  177215. buf[10] = (png_byte)compression_type;
  177216. buf[11] = (png_byte)filter_type;
  177217. buf[12] = (png_byte)interlace_type;
  177218. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177219. png_ptr->zstream.zalloc = png_zalloc;
  177220. png_ptr->zstream.zfree = png_zfree;
  177221. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177222. if (!(png_ptr->do_filter))
  177223. {
  177224. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177225. png_ptr->bit_depth < 8)
  177226. png_ptr->do_filter = PNG_FILTER_NONE;
  177227. else
  177228. png_ptr->do_filter = PNG_ALL_FILTERS;
  177229. }
  177230. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177231. {
  177232. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177233. png_ptr->zlib_strategy = Z_FILTERED;
  177234. else
  177235. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177236. }
  177237. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177238. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177239. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177240. png_ptr->zlib_mem_level = 8;
  177241. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177242. png_ptr->zlib_window_bits = 15;
  177243. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177244. png_ptr->zlib_method = 8;
  177245. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177246. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177247. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177248. png_error(png_ptr, "zlib failed to initialize compressor");
  177249. png_ptr->zstream.next_out = png_ptr->zbuf;
  177250. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177251. png_ptr->zstream.data_type = Z_BINARY;
  177252. png_ptr->mode = PNG_HAVE_IHDR;
  177253. }
  177254. void /* PRIVATE */
  177255. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177256. {
  177257. #ifdef PNG_USE_LOCAL_ARRAYS
  177258. PNG_PLTE;
  177259. #endif
  177260. png_uint_32 i;
  177261. png_colorp pal_ptr;
  177262. png_byte buf[3];
  177263. png_debug(1, "in png_write_PLTE\n");
  177264. if ((
  177265. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177266. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177267. #endif
  177268. num_pal == 0) || num_pal > 256)
  177269. {
  177270. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177271. {
  177272. png_error(png_ptr, "Invalid number of colors in palette");
  177273. }
  177274. else
  177275. {
  177276. png_warning(png_ptr, "Invalid number of colors in palette");
  177277. return;
  177278. }
  177279. }
  177280. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177281. {
  177282. png_warning(png_ptr,
  177283. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177284. return;
  177285. }
  177286. png_ptr->num_palette = (png_uint_16)num_pal;
  177287. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177288. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177289. #ifndef PNG_NO_POINTER_INDEXING
  177290. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177291. {
  177292. buf[0] = pal_ptr->red;
  177293. buf[1] = pal_ptr->green;
  177294. buf[2] = pal_ptr->blue;
  177295. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177296. }
  177297. #else
  177298. pal_ptr=palette;
  177299. for (i = 0; i < num_pal; i++)
  177300. {
  177301. buf[0] = pal_ptr[i].red;
  177302. buf[1] = pal_ptr[i].green;
  177303. buf[2] = pal_ptr[i].blue;
  177304. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177305. }
  177306. #endif
  177307. png_write_chunk_end(png_ptr);
  177308. png_ptr->mode |= PNG_HAVE_PLTE;
  177309. }
  177310. void /* PRIVATE */
  177311. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177312. {
  177313. #ifdef PNG_USE_LOCAL_ARRAYS
  177314. PNG_IDAT;
  177315. #endif
  177316. png_debug(1, "in png_write_IDAT\n");
  177317. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177318. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177319. {
  177320. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177321. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177322. {
  177323. if (length >= 2 &&
  177324. png_ptr->height < 16384 && png_ptr->width < 16384)
  177325. {
  177326. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177327. ((png_ptr->width *
  177328. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177329. unsigned int z_cinfo = z_cmf >> 4;
  177330. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177331. while (uncompressed_idat_size <= half_z_window_size &&
  177332. half_z_window_size >= 256)
  177333. {
  177334. z_cinfo--;
  177335. half_z_window_size >>= 1;
  177336. }
  177337. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177338. if (data[0] != (png_byte)z_cmf)
  177339. {
  177340. data[0] = (png_byte)z_cmf;
  177341. data[1] &= 0xe0;
  177342. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177343. }
  177344. }
  177345. }
  177346. else
  177347. png_error(png_ptr,
  177348. "Invalid zlib compression method or flags in IDAT");
  177349. }
  177350. png_write_chunk(png_ptr, png_IDAT, data, length);
  177351. png_ptr->mode |= PNG_HAVE_IDAT;
  177352. }
  177353. void /* PRIVATE */
  177354. png_write_IEND(png_structp png_ptr)
  177355. {
  177356. #ifdef PNG_USE_LOCAL_ARRAYS
  177357. PNG_IEND;
  177358. #endif
  177359. png_debug(1, "in png_write_IEND\n");
  177360. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177361. (png_size_t)0);
  177362. png_ptr->mode |= PNG_HAVE_IEND;
  177363. }
  177364. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177365. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177366. void /* PRIVATE */
  177367. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177368. {
  177369. #ifdef PNG_USE_LOCAL_ARRAYS
  177370. PNG_gAMA;
  177371. #endif
  177372. png_uint_32 igamma;
  177373. png_byte buf[4];
  177374. png_debug(1, "in png_write_gAMA\n");
  177375. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177376. png_save_uint_32(buf, igamma);
  177377. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177378. }
  177379. #endif
  177380. #ifdef PNG_FIXED_POINT_SUPPORTED
  177381. void /* PRIVATE */
  177382. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177383. {
  177384. #ifdef PNG_USE_LOCAL_ARRAYS
  177385. PNG_gAMA;
  177386. #endif
  177387. png_byte buf[4];
  177388. png_debug(1, "in png_write_gAMA\n");
  177389. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177390. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177391. }
  177392. #endif
  177393. #endif
  177394. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177395. void /* PRIVATE */
  177396. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177397. {
  177398. #ifdef PNG_USE_LOCAL_ARRAYS
  177399. PNG_sRGB;
  177400. #endif
  177401. png_byte buf[1];
  177402. png_debug(1, "in png_write_sRGB\n");
  177403. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177404. png_warning(png_ptr,
  177405. "Invalid sRGB rendering intent specified");
  177406. buf[0]=(png_byte)srgb_intent;
  177407. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177408. }
  177409. #endif
  177410. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177411. void /* PRIVATE */
  177412. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177413. png_charp profile, int profile_len)
  177414. {
  177415. #ifdef PNG_USE_LOCAL_ARRAYS
  177416. PNG_iCCP;
  177417. #endif
  177418. png_size_t name_len;
  177419. png_charp new_name;
  177420. compression_state comp;
  177421. int embedded_profile_len = 0;
  177422. png_debug(1, "in png_write_iCCP\n");
  177423. comp.num_output_ptr = 0;
  177424. comp.max_output_ptr = 0;
  177425. comp.output_ptr = NULL;
  177426. comp.input = NULL;
  177427. comp.input_len = 0;
  177428. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177429. &new_name)) == 0)
  177430. {
  177431. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177432. return;
  177433. }
  177434. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177435. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177436. if (profile == NULL)
  177437. profile_len = 0;
  177438. if (profile_len > 3)
  177439. embedded_profile_len =
  177440. ((*( (png_bytep)profile ))<<24) |
  177441. ((*( (png_bytep)profile+1))<<16) |
  177442. ((*( (png_bytep)profile+2))<< 8) |
  177443. ((*( (png_bytep)profile+3)) );
  177444. if (profile_len < embedded_profile_len)
  177445. {
  177446. png_warning(png_ptr,
  177447. "Embedded profile length too large in iCCP chunk");
  177448. return;
  177449. }
  177450. if (profile_len > embedded_profile_len)
  177451. {
  177452. png_warning(png_ptr,
  177453. "Truncating profile to actual length in iCCP chunk");
  177454. profile_len = embedded_profile_len;
  177455. }
  177456. if (profile_len)
  177457. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177458. PNG_COMPRESSION_TYPE_BASE, &comp);
  177459. png_write_chunk_start(png_ptr, png_iCCP,
  177460. (png_uint_32)name_len+profile_len+2);
  177461. new_name[name_len+1]=0x00;
  177462. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177463. if (profile_len)
  177464. png_write_compressed_data_out(png_ptr, &comp);
  177465. png_write_chunk_end(png_ptr);
  177466. png_free(png_ptr, new_name);
  177467. }
  177468. #endif
  177469. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177470. void /* PRIVATE */
  177471. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177472. {
  177473. #ifdef PNG_USE_LOCAL_ARRAYS
  177474. PNG_sPLT;
  177475. #endif
  177476. png_size_t name_len;
  177477. png_charp new_name;
  177478. png_byte entrybuf[10];
  177479. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177480. int palette_size = entry_size * spalette->nentries;
  177481. png_sPLT_entryp ep;
  177482. #ifdef PNG_NO_POINTER_INDEXING
  177483. int i;
  177484. #endif
  177485. png_debug(1, "in png_write_sPLT\n");
  177486. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177487. spalette->name, &new_name))==0)
  177488. {
  177489. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177490. return;
  177491. }
  177492. png_write_chunk_start(png_ptr, png_sPLT,
  177493. (png_uint_32)(name_len + 2 + palette_size));
  177494. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177495. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177496. #ifndef PNG_NO_POINTER_INDEXING
  177497. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177498. {
  177499. if (spalette->depth == 8)
  177500. {
  177501. entrybuf[0] = (png_byte)ep->red;
  177502. entrybuf[1] = (png_byte)ep->green;
  177503. entrybuf[2] = (png_byte)ep->blue;
  177504. entrybuf[3] = (png_byte)ep->alpha;
  177505. png_save_uint_16(entrybuf + 4, ep->frequency);
  177506. }
  177507. else
  177508. {
  177509. png_save_uint_16(entrybuf + 0, ep->red);
  177510. png_save_uint_16(entrybuf + 2, ep->green);
  177511. png_save_uint_16(entrybuf + 4, ep->blue);
  177512. png_save_uint_16(entrybuf + 6, ep->alpha);
  177513. png_save_uint_16(entrybuf + 8, ep->frequency);
  177514. }
  177515. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177516. }
  177517. #else
  177518. ep=spalette->entries;
  177519. for (i=0; i>spalette->nentries; i++)
  177520. {
  177521. if (spalette->depth == 8)
  177522. {
  177523. entrybuf[0] = (png_byte)ep[i].red;
  177524. entrybuf[1] = (png_byte)ep[i].green;
  177525. entrybuf[2] = (png_byte)ep[i].blue;
  177526. entrybuf[3] = (png_byte)ep[i].alpha;
  177527. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177528. }
  177529. else
  177530. {
  177531. png_save_uint_16(entrybuf + 0, ep[i].red);
  177532. png_save_uint_16(entrybuf + 2, ep[i].green);
  177533. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177534. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177535. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177536. }
  177537. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177538. }
  177539. #endif
  177540. png_write_chunk_end(png_ptr);
  177541. png_free(png_ptr, new_name);
  177542. }
  177543. #endif
  177544. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177545. void /* PRIVATE */
  177546. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177547. {
  177548. #ifdef PNG_USE_LOCAL_ARRAYS
  177549. PNG_sBIT;
  177550. #endif
  177551. png_byte buf[4];
  177552. png_size_t size;
  177553. png_debug(1, "in png_write_sBIT\n");
  177554. if (color_type & PNG_COLOR_MASK_COLOR)
  177555. {
  177556. png_byte maxbits;
  177557. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177558. png_ptr->usr_bit_depth);
  177559. if (sbit->red == 0 || sbit->red > maxbits ||
  177560. sbit->green == 0 || sbit->green > maxbits ||
  177561. sbit->blue == 0 || sbit->blue > maxbits)
  177562. {
  177563. png_warning(png_ptr, "Invalid sBIT depth specified");
  177564. return;
  177565. }
  177566. buf[0] = sbit->red;
  177567. buf[1] = sbit->green;
  177568. buf[2] = sbit->blue;
  177569. size = 3;
  177570. }
  177571. else
  177572. {
  177573. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177574. {
  177575. png_warning(png_ptr, "Invalid sBIT depth specified");
  177576. return;
  177577. }
  177578. buf[0] = sbit->gray;
  177579. size = 1;
  177580. }
  177581. if (color_type & PNG_COLOR_MASK_ALPHA)
  177582. {
  177583. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177584. {
  177585. png_warning(png_ptr, "Invalid sBIT depth specified");
  177586. return;
  177587. }
  177588. buf[size++] = sbit->alpha;
  177589. }
  177590. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177591. }
  177592. #endif
  177593. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177594. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177595. void /* PRIVATE */
  177596. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177597. double red_x, double red_y, double green_x, double green_y,
  177598. double blue_x, double blue_y)
  177599. {
  177600. #ifdef PNG_USE_LOCAL_ARRAYS
  177601. PNG_cHRM;
  177602. #endif
  177603. png_byte buf[32];
  177604. png_uint_32 itemp;
  177605. png_debug(1, "in png_write_cHRM\n");
  177606. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177607. white_x + white_y > 1.0)
  177608. {
  177609. png_warning(png_ptr, "Invalid cHRM white point specified");
  177610. #if !defined(PNG_NO_CONSOLE_IO)
  177611. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177612. #endif
  177613. return;
  177614. }
  177615. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177616. png_save_uint_32(buf, itemp);
  177617. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177618. png_save_uint_32(buf + 4, itemp);
  177619. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177620. {
  177621. png_warning(png_ptr, "Invalid cHRM red point specified");
  177622. return;
  177623. }
  177624. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177625. png_save_uint_32(buf + 8, itemp);
  177626. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177627. png_save_uint_32(buf + 12, itemp);
  177628. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177629. {
  177630. png_warning(png_ptr, "Invalid cHRM green point specified");
  177631. return;
  177632. }
  177633. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177634. png_save_uint_32(buf + 16, itemp);
  177635. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177636. png_save_uint_32(buf + 20, itemp);
  177637. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177638. {
  177639. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177640. return;
  177641. }
  177642. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177643. png_save_uint_32(buf + 24, itemp);
  177644. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177645. png_save_uint_32(buf + 28, itemp);
  177646. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177647. }
  177648. #endif
  177649. #ifdef PNG_FIXED_POINT_SUPPORTED
  177650. void /* PRIVATE */
  177651. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177652. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177653. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177654. png_fixed_point blue_y)
  177655. {
  177656. #ifdef PNG_USE_LOCAL_ARRAYS
  177657. PNG_cHRM;
  177658. #endif
  177659. png_byte buf[32];
  177660. png_debug(1, "in png_write_cHRM\n");
  177661. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177662. {
  177663. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177664. #if !defined(PNG_NO_CONSOLE_IO)
  177665. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177666. #endif
  177667. return;
  177668. }
  177669. png_save_uint_32(buf, (png_uint_32)white_x);
  177670. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177671. if (red_x + red_y > 100000L)
  177672. {
  177673. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177674. return;
  177675. }
  177676. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177677. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177678. if (green_x + green_y > 100000L)
  177679. {
  177680. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177681. return;
  177682. }
  177683. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177684. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177685. if (blue_x + blue_y > 100000L)
  177686. {
  177687. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177688. return;
  177689. }
  177690. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177691. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177692. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177693. }
  177694. #endif
  177695. #endif
  177696. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177697. void /* PRIVATE */
  177698. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177699. int num_trans, int color_type)
  177700. {
  177701. #ifdef PNG_USE_LOCAL_ARRAYS
  177702. PNG_tRNS;
  177703. #endif
  177704. png_byte buf[6];
  177705. png_debug(1, "in png_write_tRNS\n");
  177706. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177707. {
  177708. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177709. {
  177710. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177711. return;
  177712. }
  177713. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177714. }
  177715. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177716. {
  177717. if(tran->gray >= (1 << png_ptr->bit_depth))
  177718. {
  177719. png_warning(png_ptr,
  177720. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177721. return;
  177722. }
  177723. png_save_uint_16(buf, tran->gray);
  177724. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177725. }
  177726. else if (color_type == PNG_COLOR_TYPE_RGB)
  177727. {
  177728. png_save_uint_16(buf, tran->red);
  177729. png_save_uint_16(buf + 2, tran->green);
  177730. png_save_uint_16(buf + 4, tran->blue);
  177731. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177732. {
  177733. png_warning(png_ptr,
  177734. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177735. return;
  177736. }
  177737. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177738. }
  177739. else
  177740. {
  177741. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177742. }
  177743. }
  177744. #endif
  177745. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177746. void /* PRIVATE */
  177747. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177748. {
  177749. #ifdef PNG_USE_LOCAL_ARRAYS
  177750. PNG_bKGD;
  177751. #endif
  177752. png_byte buf[6];
  177753. png_debug(1, "in png_write_bKGD\n");
  177754. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177755. {
  177756. if (
  177757. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177758. (png_ptr->num_palette ||
  177759. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177760. #endif
  177761. back->index > png_ptr->num_palette)
  177762. {
  177763. png_warning(png_ptr, "Invalid background palette index");
  177764. return;
  177765. }
  177766. buf[0] = back->index;
  177767. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177768. }
  177769. else if (color_type & PNG_COLOR_MASK_COLOR)
  177770. {
  177771. png_save_uint_16(buf, back->red);
  177772. png_save_uint_16(buf + 2, back->green);
  177773. png_save_uint_16(buf + 4, back->blue);
  177774. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177775. {
  177776. png_warning(png_ptr,
  177777. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177778. return;
  177779. }
  177780. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177781. }
  177782. else
  177783. {
  177784. if(back->gray >= (1 << png_ptr->bit_depth))
  177785. {
  177786. png_warning(png_ptr,
  177787. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177788. return;
  177789. }
  177790. png_save_uint_16(buf, back->gray);
  177791. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177792. }
  177793. }
  177794. #endif
  177795. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177796. void /* PRIVATE */
  177797. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177798. {
  177799. #ifdef PNG_USE_LOCAL_ARRAYS
  177800. PNG_hIST;
  177801. #endif
  177802. int i;
  177803. png_byte buf[3];
  177804. png_debug(1, "in png_write_hIST\n");
  177805. if (num_hist > (int)png_ptr->num_palette)
  177806. {
  177807. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177808. png_ptr->num_palette);
  177809. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177810. return;
  177811. }
  177812. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177813. for (i = 0; i < num_hist; i++)
  177814. {
  177815. png_save_uint_16(buf, hist[i]);
  177816. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177817. }
  177818. png_write_chunk_end(png_ptr);
  177819. }
  177820. #endif
  177821. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177822. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177823. png_size_t /* PRIVATE */
  177824. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177825. {
  177826. png_size_t key_len;
  177827. png_charp kp, dp;
  177828. int kflag;
  177829. int kwarn=0;
  177830. png_debug(1, "in png_check_keyword\n");
  177831. *new_key = NULL;
  177832. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177833. {
  177834. png_warning(png_ptr, "zero length keyword");
  177835. return ((png_size_t)0);
  177836. }
  177837. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177838. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177839. if (*new_key == NULL)
  177840. {
  177841. png_warning(png_ptr, "Out of memory while procesing keyword");
  177842. return ((png_size_t)0);
  177843. }
  177844. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177845. {
  177846. if ((png_byte)*kp < 0x20 ||
  177847. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177848. {
  177849. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177850. char msg[40];
  177851. png_snprintf(msg, 40,
  177852. "invalid keyword character 0x%02X", (png_byte)*kp);
  177853. png_warning(png_ptr, msg);
  177854. #else
  177855. png_warning(png_ptr, "invalid character in keyword");
  177856. #endif
  177857. *dp = ' ';
  177858. }
  177859. else
  177860. {
  177861. *dp = *kp;
  177862. }
  177863. }
  177864. *dp = '\0';
  177865. kp = *new_key + key_len - 1;
  177866. if (*kp == ' ')
  177867. {
  177868. png_warning(png_ptr, "trailing spaces removed from keyword");
  177869. while (*kp == ' ')
  177870. {
  177871. *(kp--) = '\0';
  177872. key_len--;
  177873. }
  177874. }
  177875. kp = *new_key;
  177876. if (*kp == ' ')
  177877. {
  177878. png_warning(png_ptr, "leading spaces removed from keyword");
  177879. while (*kp == ' ')
  177880. {
  177881. kp++;
  177882. key_len--;
  177883. }
  177884. }
  177885. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177886. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177887. {
  177888. if (*kp == ' ' && kflag == 0)
  177889. {
  177890. *(dp++) = *kp;
  177891. kflag = 1;
  177892. }
  177893. else if (*kp == ' ')
  177894. {
  177895. key_len--;
  177896. kwarn=1;
  177897. }
  177898. else
  177899. {
  177900. *(dp++) = *kp;
  177901. kflag = 0;
  177902. }
  177903. }
  177904. *dp = '\0';
  177905. if(kwarn)
  177906. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177907. if (key_len == 0)
  177908. {
  177909. png_free(png_ptr, *new_key);
  177910. *new_key=NULL;
  177911. png_warning(png_ptr, "Zero length keyword");
  177912. }
  177913. if (key_len > 79)
  177914. {
  177915. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177916. new_key[79] = '\0';
  177917. key_len = 79;
  177918. }
  177919. return (key_len);
  177920. }
  177921. #endif
  177922. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177923. void /* PRIVATE */
  177924. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177925. png_size_t text_len)
  177926. {
  177927. #ifdef PNG_USE_LOCAL_ARRAYS
  177928. PNG_tEXt;
  177929. #endif
  177930. png_size_t key_len;
  177931. png_charp new_key;
  177932. png_debug(1, "in png_write_tEXt\n");
  177933. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177934. {
  177935. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177936. return;
  177937. }
  177938. if (text == NULL || *text == '\0')
  177939. text_len = 0;
  177940. else
  177941. text_len = png_strlen(text);
  177942. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177943. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177944. if (text_len)
  177945. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  177946. png_write_chunk_end(png_ptr);
  177947. png_free(png_ptr, new_key);
  177948. }
  177949. #endif
  177950. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  177951. void /* PRIVATE */
  177952. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  177953. png_size_t text_len, int compression)
  177954. {
  177955. #ifdef PNG_USE_LOCAL_ARRAYS
  177956. PNG_zTXt;
  177957. #endif
  177958. png_size_t key_len;
  177959. char buf[1];
  177960. png_charp new_key;
  177961. compression_state comp;
  177962. png_debug(1, "in png_write_zTXt\n");
  177963. comp.num_output_ptr = 0;
  177964. comp.max_output_ptr = 0;
  177965. comp.output_ptr = NULL;
  177966. comp.input = NULL;
  177967. comp.input_len = 0;
  177968. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177969. {
  177970. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  177971. return;
  177972. }
  177973. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  177974. {
  177975. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  177976. png_free(png_ptr, new_key);
  177977. return;
  177978. }
  177979. text_len = png_strlen(text);
  177980. text_len = png_text_compress(png_ptr, text, text_len, compression,
  177981. &comp);
  177982. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  177983. (key_len+text_len+2));
  177984. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177985. png_free(png_ptr, new_key);
  177986. buf[0] = (png_byte)compression;
  177987. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  177988. png_write_compressed_data_out(png_ptr, &comp);
  177989. png_write_chunk_end(png_ptr);
  177990. }
  177991. #endif
  177992. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  177993. void /* PRIVATE */
  177994. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  177995. png_charp lang, png_charp lang_key, png_charp text)
  177996. {
  177997. #ifdef PNG_USE_LOCAL_ARRAYS
  177998. PNG_iTXt;
  177999. #endif
  178000. png_size_t lang_len, key_len, lang_key_len, text_len;
  178001. png_charp new_lang, new_key;
  178002. png_byte cbuf[2];
  178003. compression_state comp;
  178004. png_debug(1, "in png_write_iTXt\n");
  178005. comp.num_output_ptr = 0;
  178006. comp.max_output_ptr = 0;
  178007. comp.output_ptr = NULL;
  178008. comp.input = NULL;
  178009. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178010. {
  178011. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  178012. return;
  178013. }
  178014. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  178015. {
  178016. png_warning(png_ptr, "Empty language field in iTXt chunk");
  178017. new_lang = NULL;
  178018. lang_len = 0;
  178019. }
  178020. if (lang_key == NULL)
  178021. lang_key_len = 0;
  178022. else
  178023. lang_key_len = png_strlen(lang_key);
  178024. if (text == NULL)
  178025. text_len = 0;
  178026. else
  178027. text_len = png_strlen(text);
  178028. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  178029. &comp);
  178030. png_write_chunk_start(png_ptr, png_iTXt,
  178031. (png_uint_32)(
  178032. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178033. + key_len
  178034. + lang_len
  178035. + lang_key_len
  178036. + text_len));
  178037. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178038. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178039. compression == PNG_TEXT_COMPRESSION_NONE)
  178040. cbuf[0] = 0;
  178041. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178042. cbuf[0] = 1;
  178043. cbuf[1] = 0;
  178044. png_write_chunk_data(png_ptr, cbuf, 2);
  178045. cbuf[0] = 0;
  178046. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178047. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178048. png_write_compressed_data_out(png_ptr, &comp);
  178049. png_write_chunk_end(png_ptr);
  178050. png_free(png_ptr, new_key);
  178051. if (new_lang)
  178052. png_free(png_ptr, new_lang);
  178053. }
  178054. #endif
  178055. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178056. void /* PRIVATE */
  178057. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178058. int unit_type)
  178059. {
  178060. #ifdef PNG_USE_LOCAL_ARRAYS
  178061. PNG_oFFs;
  178062. #endif
  178063. png_byte buf[9];
  178064. png_debug(1, "in png_write_oFFs\n");
  178065. if (unit_type >= PNG_OFFSET_LAST)
  178066. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178067. png_save_int_32(buf, x_offset);
  178068. png_save_int_32(buf + 4, y_offset);
  178069. buf[8] = (png_byte)unit_type;
  178070. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178071. }
  178072. #endif
  178073. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178074. void /* PRIVATE */
  178075. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178076. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178077. {
  178078. #ifdef PNG_USE_LOCAL_ARRAYS
  178079. PNG_pCAL;
  178080. #endif
  178081. png_size_t purpose_len, units_len, total_len;
  178082. png_uint_32p params_len;
  178083. png_byte buf[10];
  178084. png_charp new_purpose;
  178085. int i;
  178086. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178087. if (type >= PNG_EQUATION_LAST)
  178088. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178089. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178090. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178091. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178092. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178093. total_len = purpose_len + units_len + 10;
  178094. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178095. *png_sizeof(png_uint_32)));
  178096. for (i = 0; i < nparams; i++)
  178097. {
  178098. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178099. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178100. total_len += (png_size_t)params_len[i];
  178101. }
  178102. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178103. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178104. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178105. png_save_int_32(buf, X0);
  178106. png_save_int_32(buf + 4, X1);
  178107. buf[8] = (png_byte)type;
  178108. buf[9] = (png_byte)nparams;
  178109. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178110. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178111. png_free(png_ptr, new_purpose);
  178112. for (i = 0; i < nparams; i++)
  178113. {
  178114. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178115. (png_size_t)params_len[i]);
  178116. }
  178117. png_free(png_ptr, params_len);
  178118. png_write_chunk_end(png_ptr);
  178119. }
  178120. #endif
  178121. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178122. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178123. void /* PRIVATE */
  178124. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178125. {
  178126. #ifdef PNG_USE_LOCAL_ARRAYS
  178127. PNG_sCAL;
  178128. #endif
  178129. char buf[64];
  178130. png_size_t total_len;
  178131. png_debug(1, "in png_write_sCAL\n");
  178132. buf[0] = (char)unit;
  178133. #if defined(_WIN32_WCE)
  178134. {
  178135. wchar_t wc_buf[32];
  178136. size_t wc_len;
  178137. swprintf(wc_buf, TEXT("%12.12e"), width);
  178138. wc_len = wcslen(wc_buf);
  178139. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178140. total_len = wc_len + 2;
  178141. swprintf(wc_buf, TEXT("%12.12e"), height);
  178142. wc_len = wcslen(wc_buf);
  178143. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178144. NULL, NULL);
  178145. total_len += wc_len;
  178146. }
  178147. #else
  178148. png_snprintf(buf + 1, 63, "%12.12e", width);
  178149. total_len = 1 + png_strlen(buf + 1) + 1;
  178150. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178151. total_len += png_strlen(buf + total_len);
  178152. #endif
  178153. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178154. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178155. }
  178156. #else
  178157. #ifdef PNG_FIXED_POINT_SUPPORTED
  178158. void /* PRIVATE */
  178159. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178160. png_charp height)
  178161. {
  178162. #ifdef PNG_USE_LOCAL_ARRAYS
  178163. PNG_sCAL;
  178164. #endif
  178165. png_byte buf[64];
  178166. png_size_t wlen, hlen, total_len;
  178167. png_debug(1, "in png_write_sCAL_s\n");
  178168. wlen = png_strlen(width);
  178169. hlen = png_strlen(height);
  178170. total_len = wlen + hlen + 2;
  178171. if (total_len > 64)
  178172. {
  178173. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178174. return;
  178175. }
  178176. buf[0] = (png_byte)unit;
  178177. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178178. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178179. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178180. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178181. }
  178182. #endif
  178183. #endif
  178184. #endif
  178185. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178186. void /* PRIVATE */
  178187. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178188. png_uint_32 y_pixels_per_unit,
  178189. int unit_type)
  178190. {
  178191. #ifdef PNG_USE_LOCAL_ARRAYS
  178192. PNG_pHYs;
  178193. #endif
  178194. png_byte buf[9];
  178195. png_debug(1, "in png_write_pHYs\n");
  178196. if (unit_type >= PNG_RESOLUTION_LAST)
  178197. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178198. png_save_uint_32(buf, x_pixels_per_unit);
  178199. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178200. buf[8] = (png_byte)unit_type;
  178201. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178202. }
  178203. #endif
  178204. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178205. void /* PRIVATE */
  178206. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178207. {
  178208. #ifdef PNG_USE_LOCAL_ARRAYS
  178209. PNG_tIME;
  178210. #endif
  178211. png_byte buf[7];
  178212. png_debug(1, "in png_write_tIME\n");
  178213. if (mod_time->month > 12 || mod_time->month < 1 ||
  178214. mod_time->day > 31 || mod_time->day < 1 ||
  178215. mod_time->hour > 23 || mod_time->second > 60)
  178216. {
  178217. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178218. return;
  178219. }
  178220. png_save_uint_16(buf, mod_time->year);
  178221. buf[2] = mod_time->month;
  178222. buf[3] = mod_time->day;
  178223. buf[4] = mod_time->hour;
  178224. buf[5] = mod_time->minute;
  178225. buf[6] = mod_time->second;
  178226. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178227. }
  178228. #endif
  178229. void /* PRIVATE */
  178230. png_write_start_row(png_structp png_ptr)
  178231. {
  178232. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178233. #ifdef PNG_USE_LOCAL_ARRAYS
  178234. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178235. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178236. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178237. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178238. #endif
  178239. #endif
  178240. png_size_t buf_size;
  178241. png_debug(1, "in png_write_start_row\n");
  178242. buf_size = (png_size_t)(PNG_ROWBYTES(
  178243. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178244. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178245. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178246. #ifndef PNG_NO_WRITE_FILTERING
  178247. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178248. {
  178249. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178250. (png_ptr->rowbytes + 1));
  178251. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178252. }
  178253. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178254. {
  178255. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178256. png_memset(png_ptr->prev_row, 0, buf_size);
  178257. if (png_ptr->do_filter & PNG_FILTER_UP)
  178258. {
  178259. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178260. (png_ptr->rowbytes + 1));
  178261. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178262. }
  178263. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178264. {
  178265. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178266. (png_ptr->rowbytes + 1));
  178267. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178268. }
  178269. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178270. {
  178271. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178272. (png_ptr->rowbytes + 1));
  178273. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178274. }
  178275. #endif /* PNG_NO_WRITE_FILTERING */
  178276. }
  178277. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178278. if (png_ptr->interlaced)
  178279. {
  178280. if (!(png_ptr->transformations & PNG_INTERLACE))
  178281. {
  178282. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178283. png_pass_ystart[0]) / png_pass_yinc[0];
  178284. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178285. png_pass_start[0]) / png_pass_inc[0];
  178286. }
  178287. else
  178288. {
  178289. png_ptr->num_rows = png_ptr->height;
  178290. png_ptr->usr_width = png_ptr->width;
  178291. }
  178292. }
  178293. else
  178294. #endif
  178295. {
  178296. png_ptr->num_rows = png_ptr->height;
  178297. png_ptr->usr_width = png_ptr->width;
  178298. }
  178299. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178300. png_ptr->zstream.next_out = png_ptr->zbuf;
  178301. }
  178302. void /* PRIVATE */
  178303. png_write_finish_row(png_structp png_ptr)
  178304. {
  178305. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178306. #ifdef PNG_USE_LOCAL_ARRAYS
  178307. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178308. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178309. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178310. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178311. #endif
  178312. #endif
  178313. int ret;
  178314. png_debug(1, "in png_write_finish_row\n");
  178315. png_ptr->row_number++;
  178316. if (png_ptr->row_number < png_ptr->num_rows)
  178317. return;
  178318. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178319. if (png_ptr->interlaced)
  178320. {
  178321. png_ptr->row_number = 0;
  178322. if (png_ptr->transformations & PNG_INTERLACE)
  178323. {
  178324. png_ptr->pass++;
  178325. }
  178326. else
  178327. {
  178328. do
  178329. {
  178330. png_ptr->pass++;
  178331. if (png_ptr->pass >= 7)
  178332. break;
  178333. png_ptr->usr_width = (png_ptr->width +
  178334. png_pass_inc[png_ptr->pass] - 1 -
  178335. png_pass_start[png_ptr->pass]) /
  178336. png_pass_inc[png_ptr->pass];
  178337. png_ptr->num_rows = (png_ptr->height +
  178338. png_pass_yinc[png_ptr->pass] - 1 -
  178339. png_pass_ystart[png_ptr->pass]) /
  178340. png_pass_yinc[png_ptr->pass];
  178341. if (png_ptr->transformations & PNG_INTERLACE)
  178342. break;
  178343. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178344. }
  178345. if (png_ptr->pass < 7)
  178346. {
  178347. if (png_ptr->prev_row != NULL)
  178348. png_memset(png_ptr->prev_row, 0,
  178349. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178350. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178351. return;
  178352. }
  178353. }
  178354. #endif
  178355. do
  178356. {
  178357. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178358. if (ret == Z_OK)
  178359. {
  178360. if (!(png_ptr->zstream.avail_out))
  178361. {
  178362. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178363. png_ptr->zstream.next_out = png_ptr->zbuf;
  178364. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178365. }
  178366. }
  178367. else if (ret != Z_STREAM_END)
  178368. {
  178369. if (png_ptr->zstream.msg != NULL)
  178370. png_error(png_ptr, png_ptr->zstream.msg);
  178371. else
  178372. png_error(png_ptr, "zlib error");
  178373. }
  178374. } while (ret != Z_STREAM_END);
  178375. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178376. {
  178377. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178378. png_ptr->zstream.avail_out);
  178379. }
  178380. deflateReset(&png_ptr->zstream);
  178381. png_ptr->zstream.data_type = Z_BINARY;
  178382. }
  178383. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178384. void /* PRIVATE */
  178385. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178386. {
  178387. #ifdef PNG_USE_LOCAL_ARRAYS
  178388. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178389. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178390. #endif
  178391. png_debug(1, "in png_do_write_interlace\n");
  178392. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178393. if (row != NULL && row_info != NULL && pass < 6)
  178394. #else
  178395. if (pass < 6)
  178396. #endif
  178397. {
  178398. switch (row_info->pixel_depth)
  178399. {
  178400. case 1:
  178401. {
  178402. png_bytep sp;
  178403. png_bytep dp;
  178404. int shift;
  178405. int d;
  178406. int value;
  178407. png_uint_32 i;
  178408. png_uint_32 row_width = row_info->width;
  178409. dp = row;
  178410. d = 0;
  178411. shift = 7;
  178412. for (i = png_pass_start[pass]; i < row_width;
  178413. i += png_pass_inc[pass])
  178414. {
  178415. sp = row + (png_size_t)(i >> 3);
  178416. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178417. d |= (value << shift);
  178418. if (shift == 0)
  178419. {
  178420. shift = 7;
  178421. *dp++ = (png_byte)d;
  178422. d = 0;
  178423. }
  178424. else
  178425. shift--;
  178426. }
  178427. if (shift != 7)
  178428. *dp = (png_byte)d;
  178429. break;
  178430. }
  178431. case 2:
  178432. {
  178433. png_bytep sp;
  178434. png_bytep dp;
  178435. int shift;
  178436. int d;
  178437. int value;
  178438. png_uint_32 i;
  178439. png_uint_32 row_width = row_info->width;
  178440. dp = row;
  178441. shift = 6;
  178442. d = 0;
  178443. for (i = png_pass_start[pass]; i < row_width;
  178444. i += png_pass_inc[pass])
  178445. {
  178446. sp = row + (png_size_t)(i >> 2);
  178447. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178448. d |= (value << shift);
  178449. if (shift == 0)
  178450. {
  178451. shift = 6;
  178452. *dp++ = (png_byte)d;
  178453. d = 0;
  178454. }
  178455. else
  178456. shift -= 2;
  178457. }
  178458. if (shift != 6)
  178459. *dp = (png_byte)d;
  178460. break;
  178461. }
  178462. case 4:
  178463. {
  178464. png_bytep sp;
  178465. png_bytep dp;
  178466. int shift;
  178467. int d;
  178468. int value;
  178469. png_uint_32 i;
  178470. png_uint_32 row_width = row_info->width;
  178471. dp = row;
  178472. shift = 4;
  178473. d = 0;
  178474. for (i = png_pass_start[pass]; i < row_width;
  178475. i += png_pass_inc[pass])
  178476. {
  178477. sp = row + (png_size_t)(i >> 1);
  178478. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178479. d |= (value << shift);
  178480. if (shift == 0)
  178481. {
  178482. shift = 4;
  178483. *dp++ = (png_byte)d;
  178484. d = 0;
  178485. }
  178486. else
  178487. shift -= 4;
  178488. }
  178489. if (shift != 4)
  178490. *dp = (png_byte)d;
  178491. break;
  178492. }
  178493. default:
  178494. {
  178495. png_bytep sp;
  178496. png_bytep dp;
  178497. png_uint_32 i;
  178498. png_uint_32 row_width = row_info->width;
  178499. png_size_t pixel_bytes;
  178500. dp = row;
  178501. pixel_bytes = (row_info->pixel_depth >> 3);
  178502. for (i = png_pass_start[pass]; i < row_width;
  178503. i += png_pass_inc[pass])
  178504. {
  178505. sp = row + (png_size_t)i * pixel_bytes;
  178506. if (dp != sp)
  178507. png_memcpy(dp, sp, pixel_bytes);
  178508. dp += pixel_bytes;
  178509. }
  178510. break;
  178511. }
  178512. }
  178513. row_info->width = (row_info->width +
  178514. png_pass_inc[pass] - 1 -
  178515. png_pass_start[pass]) /
  178516. png_pass_inc[pass];
  178517. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178518. row_info->width);
  178519. }
  178520. }
  178521. #endif
  178522. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178523. #define PNG_HISHIFT 10
  178524. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178525. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178526. void /* PRIVATE */
  178527. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178528. {
  178529. png_bytep best_row;
  178530. #ifndef PNG_NO_WRITE_FILTER
  178531. png_bytep prev_row, row_buf;
  178532. png_uint_32 mins, bpp;
  178533. png_byte filter_to_do = png_ptr->do_filter;
  178534. png_uint_32 row_bytes = row_info->rowbytes;
  178535. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178536. int num_p_filters = (int)png_ptr->num_prev_filters;
  178537. #endif
  178538. png_debug(1, "in png_write_find_filter\n");
  178539. bpp = (row_info->pixel_depth + 7) >> 3;
  178540. prev_row = png_ptr->prev_row;
  178541. #endif
  178542. best_row = png_ptr->row_buf;
  178543. #ifndef PNG_NO_WRITE_FILTER
  178544. row_buf = best_row;
  178545. mins = PNG_MAXSUM;
  178546. if ((filter_to_do & PNG_FILTER_NONE) &&
  178547. filter_to_do != PNG_FILTER_NONE)
  178548. {
  178549. png_bytep rp;
  178550. png_uint_32 sum = 0;
  178551. png_uint_32 i;
  178552. int v;
  178553. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178554. {
  178555. v = *rp;
  178556. sum += (v < 128) ? v : 256 - v;
  178557. }
  178558. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178559. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178560. {
  178561. png_uint_32 sumhi, sumlo;
  178562. int j;
  178563. sumlo = sum & PNG_LOMASK;
  178564. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178565. for (j = 0; j < num_p_filters; j++)
  178566. {
  178567. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178568. {
  178569. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178570. PNG_WEIGHT_SHIFT;
  178571. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178572. PNG_WEIGHT_SHIFT;
  178573. }
  178574. }
  178575. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178576. PNG_COST_SHIFT;
  178577. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178578. PNG_COST_SHIFT;
  178579. if (sumhi > PNG_HIMASK)
  178580. sum = PNG_MAXSUM;
  178581. else
  178582. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178583. }
  178584. #endif
  178585. mins = sum;
  178586. }
  178587. if (filter_to_do == PNG_FILTER_SUB)
  178588. {
  178589. png_bytep rp, lp, dp;
  178590. png_uint_32 i;
  178591. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178592. i++, rp++, dp++)
  178593. {
  178594. *dp = *rp;
  178595. }
  178596. for (lp = row_buf + 1; i < row_bytes;
  178597. i++, rp++, lp++, dp++)
  178598. {
  178599. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178600. }
  178601. best_row = png_ptr->sub_row;
  178602. }
  178603. else if (filter_to_do & PNG_FILTER_SUB)
  178604. {
  178605. png_bytep rp, dp, lp;
  178606. png_uint_32 sum = 0, lmins = mins;
  178607. png_uint_32 i;
  178608. int v;
  178609. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178610. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178611. {
  178612. int j;
  178613. png_uint_32 lmhi, lmlo;
  178614. lmlo = lmins & PNG_LOMASK;
  178615. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178616. for (j = 0; j < num_p_filters; j++)
  178617. {
  178618. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178619. {
  178620. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178621. PNG_WEIGHT_SHIFT;
  178622. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178623. PNG_WEIGHT_SHIFT;
  178624. }
  178625. }
  178626. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178627. PNG_COST_SHIFT;
  178628. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178629. PNG_COST_SHIFT;
  178630. if (lmhi > PNG_HIMASK)
  178631. lmins = PNG_MAXSUM;
  178632. else
  178633. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178634. }
  178635. #endif
  178636. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178637. i++, rp++, dp++)
  178638. {
  178639. v = *dp = *rp;
  178640. sum += (v < 128) ? v : 256 - v;
  178641. }
  178642. for (lp = row_buf + 1; i < row_bytes;
  178643. i++, rp++, lp++, dp++)
  178644. {
  178645. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178646. sum += (v < 128) ? v : 256 - v;
  178647. if (sum > lmins) /* We are already worse, don't continue. */
  178648. break;
  178649. }
  178650. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178651. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178652. {
  178653. int j;
  178654. png_uint_32 sumhi, sumlo;
  178655. sumlo = sum & PNG_LOMASK;
  178656. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178657. for (j = 0; j < num_p_filters; j++)
  178658. {
  178659. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178660. {
  178661. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178662. PNG_WEIGHT_SHIFT;
  178663. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178664. PNG_WEIGHT_SHIFT;
  178665. }
  178666. }
  178667. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178668. PNG_COST_SHIFT;
  178669. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178670. PNG_COST_SHIFT;
  178671. if (sumhi > PNG_HIMASK)
  178672. sum = PNG_MAXSUM;
  178673. else
  178674. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178675. }
  178676. #endif
  178677. if (sum < mins)
  178678. {
  178679. mins = sum;
  178680. best_row = png_ptr->sub_row;
  178681. }
  178682. }
  178683. if (filter_to_do == PNG_FILTER_UP)
  178684. {
  178685. png_bytep rp, dp, pp;
  178686. png_uint_32 i;
  178687. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178688. pp = prev_row + 1; i < row_bytes;
  178689. i++, rp++, pp++, dp++)
  178690. {
  178691. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178692. }
  178693. best_row = png_ptr->up_row;
  178694. }
  178695. else if (filter_to_do & PNG_FILTER_UP)
  178696. {
  178697. png_bytep rp, dp, pp;
  178698. png_uint_32 sum = 0, lmins = mins;
  178699. png_uint_32 i;
  178700. int v;
  178701. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178702. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178703. {
  178704. int j;
  178705. png_uint_32 lmhi, lmlo;
  178706. lmlo = lmins & PNG_LOMASK;
  178707. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178708. for (j = 0; j < num_p_filters; j++)
  178709. {
  178710. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178711. {
  178712. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178713. PNG_WEIGHT_SHIFT;
  178714. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178715. PNG_WEIGHT_SHIFT;
  178716. }
  178717. }
  178718. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178719. PNG_COST_SHIFT;
  178720. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178721. PNG_COST_SHIFT;
  178722. if (lmhi > PNG_HIMASK)
  178723. lmins = PNG_MAXSUM;
  178724. else
  178725. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178726. }
  178727. #endif
  178728. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178729. pp = prev_row + 1; i < row_bytes; i++)
  178730. {
  178731. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178732. sum += (v < 128) ? v : 256 - v;
  178733. if (sum > lmins) /* We are already worse, don't continue. */
  178734. break;
  178735. }
  178736. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178737. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178738. {
  178739. int j;
  178740. png_uint_32 sumhi, sumlo;
  178741. sumlo = sum & PNG_LOMASK;
  178742. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178743. for (j = 0; j < num_p_filters; j++)
  178744. {
  178745. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178746. {
  178747. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178748. PNG_WEIGHT_SHIFT;
  178749. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178750. PNG_WEIGHT_SHIFT;
  178751. }
  178752. }
  178753. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178754. PNG_COST_SHIFT;
  178755. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178756. PNG_COST_SHIFT;
  178757. if (sumhi > PNG_HIMASK)
  178758. sum = PNG_MAXSUM;
  178759. else
  178760. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178761. }
  178762. #endif
  178763. if (sum < mins)
  178764. {
  178765. mins = sum;
  178766. best_row = png_ptr->up_row;
  178767. }
  178768. }
  178769. if (filter_to_do == PNG_FILTER_AVG)
  178770. {
  178771. png_bytep rp, dp, pp, lp;
  178772. png_uint_32 i;
  178773. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178774. pp = prev_row + 1; i < bpp; i++)
  178775. {
  178776. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178777. }
  178778. for (lp = row_buf + 1; i < row_bytes; i++)
  178779. {
  178780. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178781. & 0xff);
  178782. }
  178783. best_row = png_ptr->avg_row;
  178784. }
  178785. else if (filter_to_do & PNG_FILTER_AVG)
  178786. {
  178787. png_bytep rp, dp, pp, lp;
  178788. png_uint_32 sum = 0, lmins = mins;
  178789. png_uint_32 i;
  178790. int v;
  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 lmhi, lmlo;
  178796. lmlo = lmins & PNG_LOMASK;
  178797. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178798. for (j = 0; j < num_p_filters; j++)
  178799. {
  178800. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178801. {
  178802. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178803. PNG_WEIGHT_SHIFT;
  178804. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178805. PNG_WEIGHT_SHIFT;
  178806. }
  178807. }
  178808. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178809. PNG_COST_SHIFT;
  178810. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178811. PNG_COST_SHIFT;
  178812. if (lmhi > PNG_HIMASK)
  178813. lmins = PNG_MAXSUM;
  178814. else
  178815. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178816. }
  178817. #endif
  178818. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178819. pp = prev_row + 1; i < bpp; i++)
  178820. {
  178821. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178822. sum += (v < 128) ? v : 256 - v;
  178823. }
  178824. for (lp = row_buf + 1; i < row_bytes; i++)
  178825. {
  178826. v = *dp++ =
  178827. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178828. sum += (v < 128) ? v : 256 - v;
  178829. if (sum > lmins) /* We are already worse, don't continue. */
  178830. break;
  178831. }
  178832. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178833. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178834. {
  178835. int j;
  178836. png_uint_32 sumhi, sumlo;
  178837. sumlo = sum & PNG_LOMASK;
  178838. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178839. for (j = 0; j < num_p_filters; j++)
  178840. {
  178841. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178842. {
  178843. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178844. PNG_WEIGHT_SHIFT;
  178845. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178846. PNG_WEIGHT_SHIFT;
  178847. }
  178848. }
  178849. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178850. PNG_COST_SHIFT;
  178851. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178852. PNG_COST_SHIFT;
  178853. if (sumhi > PNG_HIMASK)
  178854. sum = PNG_MAXSUM;
  178855. else
  178856. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178857. }
  178858. #endif
  178859. if (sum < mins)
  178860. {
  178861. mins = sum;
  178862. best_row = png_ptr->avg_row;
  178863. }
  178864. }
  178865. if (filter_to_do == PNG_FILTER_PAETH)
  178866. {
  178867. png_bytep rp, dp, pp, cp, lp;
  178868. png_uint_32 i;
  178869. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178870. pp = prev_row + 1; i < bpp; i++)
  178871. {
  178872. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178873. }
  178874. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178875. {
  178876. int a, b, c, pa, pb, pc, p;
  178877. b = *pp++;
  178878. c = *cp++;
  178879. a = *lp++;
  178880. p = b - c;
  178881. pc = a - c;
  178882. #ifdef PNG_USE_ABS
  178883. pa = abs(p);
  178884. pb = abs(pc);
  178885. pc = abs(p + pc);
  178886. #else
  178887. pa = p < 0 ? -p : p;
  178888. pb = pc < 0 ? -pc : pc;
  178889. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178890. #endif
  178891. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178892. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178893. }
  178894. best_row = png_ptr->paeth_row;
  178895. }
  178896. else if (filter_to_do & PNG_FILTER_PAETH)
  178897. {
  178898. png_bytep rp, dp, pp, cp, lp;
  178899. png_uint_32 sum = 0, lmins = mins;
  178900. png_uint_32 i;
  178901. int v;
  178902. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178903. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178904. {
  178905. int j;
  178906. png_uint_32 lmhi, lmlo;
  178907. lmlo = lmins & PNG_LOMASK;
  178908. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178909. for (j = 0; j < num_p_filters; j++)
  178910. {
  178911. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178912. {
  178913. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178914. PNG_WEIGHT_SHIFT;
  178915. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178916. PNG_WEIGHT_SHIFT;
  178917. }
  178918. }
  178919. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178920. PNG_COST_SHIFT;
  178921. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178922. PNG_COST_SHIFT;
  178923. if (lmhi > PNG_HIMASK)
  178924. lmins = PNG_MAXSUM;
  178925. else
  178926. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178927. }
  178928. #endif
  178929. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178930. pp = prev_row + 1; i < bpp; i++)
  178931. {
  178932. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178933. sum += (v < 128) ? v : 256 - v;
  178934. }
  178935. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178936. {
  178937. int a, b, c, pa, pb, pc, p;
  178938. b = *pp++;
  178939. c = *cp++;
  178940. a = *lp++;
  178941. #ifndef PNG_SLOW_PAETH
  178942. p = b - c;
  178943. pc = a - c;
  178944. #ifdef PNG_USE_ABS
  178945. pa = abs(p);
  178946. pb = abs(pc);
  178947. pc = abs(p + pc);
  178948. #else
  178949. pa = p < 0 ? -p : p;
  178950. pb = pc < 0 ? -pc : pc;
  178951. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178952. #endif
  178953. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178954. #else /* PNG_SLOW_PAETH */
  178955. p = a + b - c;
  178956. pa = abs(p - a);
  178957. pb = abs(p - b);
  178958. pc = abs(p - c);
  178959. if (pa <= pb && pa <= pc)
  178960. p = a;
  178961. else if (pb <= pc)
  178962. p = b;
  178963. else
  178964. p = c;
  178965. #endif /* PNG_SLOW_PAETH */
  178966. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178967. sum += (v < 128) ? v : 256 - v;
  178968. if (sum > lmins) /* We are already worse, don't continue. */
  178969. break;
  178970. }
  178971. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178972. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178973. {
  178974. int j;
  178975. png_uint_32 sumhi, sumlo;
  178976. sumlo = sum & PNG_LOMASK;
  178977. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178978. for (j = 0; j < num_p_filters; j++)
  178979. {
  178980. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178981. {
  178982. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178983. PNG_WEIGHT_SHIFT;
  178984. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178985. PNG_WEIGHT_SHIFT;
  178986. }
  178987. }
  178988. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178989. PNG_COST_SHIFT;
  178990. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178991. PNG_COST_SHIFT;
  178992. if (sumhi > PNG_HIMASK)
  178993. sum = PNG_MAXSUM;
  178994. else
  178995. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178996. }
  178997. #endif
  178998. if (sum < mins)
  178999. {
  179000. best_row = png_ptr->paeth_row;
  179001. }
  179002. }
  179003. #endif /* PNG_NO_WRITE_FILTER */
  179004. png_write_filtered_row(png_ptr, best_row);
  179005. #ifndef PNG_NO_WRITE_FILTER
  179006. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179007. if (png_ptr->num_prev_filters > 0)
  179008. {
  179009. int j;
  179010. for (j = 1; j < num_p_filters; j++)
  179011. {
  179012. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  179013. }
  179014. png_ptr->prev_filters[j] = best_row[0];
  179015. }
  179016. #endif
  179017. #endif /* PNG_NO_WRITE_FILTER */
  179018. }
  179019. void /* PRIVATE */
  179020. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  179021. {
  179022. png_debug(1, "in png_write_filtered_row\n");
  179023. png_debug1(2, "filter = %d\n", filtered_row[0]);
  179024. png_ptr->zstream.next_in = filtered_row;
  179025. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  179026. do
  179027. {
  179028. int ret; /* return of zlib */
  179029. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  179030. if (ret != Z_OK)
  179031. {
  179032. if (png_ptr->zstream.msg != NULL)
  179033. png_error(png_ptr, png_ptr->zstream.msg);
  179034. else
  179035. png_error(png_ptr, "zlib error");
  179036. }
  179037. if (!(png_ptr->zstream.avail_out))
  179038. {
  179039. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179040. png_ptr->zstream.next_out = png_ptr->zbuf;
  179041. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179042. }
  179043. } while (png_ptr->zstream.avail_in);
  179044. if (png_ptr->prev_row != NULL)
  179045. {
  179046. png_bytep tptr;
  179047. tptr = png_ptr->prev_row;
  179048. png_ptr->prev_row = png_ptr->row_buf;
  179049. png_ptr->row_buf = tptr;
  179050. }
  179051. png_write_finish_row(png_ptr);
  179052. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179053. png_ptr->flush_rows++;
  179054. if (png_ptr->flush_dist > 0 &&
  179055. png_ptr->flush_rows >= png_ptr->flush_dist)
  179056. {
  179057. png_write_flush(png_ptr);
  179058. }
  179059. #endif
  179060. }
  179061. #endif /* PNG_WRITE_SUPPORTED */
  179062. /*** End of inlined file: pngwutil.c ***/
  179063. }
  179064. #else
  179065. #define PNG_INTERNAL
  179066. #define PNG_SETJMP_NOT_SUPPORTED
  179067. #include <png.h>
  179068. #include <pngconf.h>
  179069. #endif
  179070. }
  179071. #ifdef _MSC_VER
  179072. #pragma warning (pop)
  179073. #endif
  179074. BEGIN_JUCE_NAMESPACE
  179075. using ::calloc;
  179076. using ::malloc;
  179077. using ::free;
  179078. namespace PNGHelpers
  179079. {
  179080. using namespace pnglibNamespace;
  179081. static void readCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179082. {
  179083. using namespace pnglibNamespace;
  179084. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179085. in->read (data, (int) length);
  179086. }
  179087. struct PNGErrorStruct {};
  179088. static void errorCallback (png_structp, png_const_charp)
  179089. {
  179090. throw PNGErrorStruct();
  179091. }
  179092. static void writeDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179093. {
  179094. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179095. const bool ok = out->write (data, (int) length);
  179096. (void) ok;
  179097. jassert (ok);
  179098. }
  179099. }
  179100. Image* juce_loadPNGImageFromStream (InputStream& in)
  179101. {
  179102. using namespace pnglibNamespace;
  179103. Image* image = 0;
  179104. png_structp pngReadStruct;
  179105. png_infop pngInfoStruct;
  179106. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179107. if (pngReadStruct != 0)
  179108. {
  179109. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179110. if (pngInfoStruct == 0)
  179111. {
  179112. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179113. return 0;
  179114. }
  179115. png_set_error_fn (pngReadStruct, 0, PNGHelpers::errorCallback, PNGHelpers::errorCallback );
  179116. // read the header..
  179117. png_set_read_fn (pngReadStruct, &in, PNGHelpers::readCallback);
  179118. png_uint_32 width, height;
  179119. int bitDepth, colorType, interlaceType;
  179120. png_read_info (pngReadStruct, pngInfoStruct);
  179121. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179122. &width, &height,
  179123. &bitDepth, &colorType,
  179124. &interlaceType, 0, 0);
  179125. if (bitDepth == 16)
  179126. png_set_strip_16 (pngReadStruct);
  179127. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179128. png_set_expand (pngReadStruct);
  179129. if (bitDepth < 8)
  179130. png_set_expand (pngReadStruct);
  179131. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179132. png_set_expand (pngReadStruct);
  179133. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179134. png_set_gray_to_rgb (pngReadStruct);
  179135. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179136. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179137. || pngInfoStruct->num_trans > 0;
  179138. // Load the image into a temp buffer in the pnglib format..
  179139. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179140. {
  179141. HeapBlock <png_bytep> rows (height);
  179142. for (int y = (int) height; --y >= 0;)
  179143. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179144. png_read_image (pngReadStruct, rows);
  179145. png_read_end (pngReadStruct, pngInfoStruct);
  179146. }
  179147. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179148. // now convert the data to a juce image format..
  179149. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179150. (int) width, (int) height, hasAlphaChan);
  179151. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179152. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179153. uint8* srcRow = tempBuffer;
  179154. uint8* destRow = destData.data;
  179155. for (int y = 0; y < (int) height; ++y)
  179156. {
  179157. const uint8* src = srcRow;
  179158. srcRow += (width << 2);
  179159. uint8* dest = destRow;
  179160. destRow += destData.lineStride;
  179161. if (hasAlphaChan)
  179162. {
  179163. for (int i = (int) width; --i >= 0;)
  179164. {
  179165. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179166. ((PixelARGB*) dest)->premultiply();
  179167. dest += destData.pixelStride;
  179168. src += 4;
  179169. }
  179170. }
  179171. else
  179172. {
  179173. for (int i = (int) width; --i >= 0;)
  179174. {
  179175. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179176. dest += destData.pixelStride;
  179177. src += 4;
  179178. }
  179179. }
  179180. }
  179181. }
  179182. return image;
  179183. }
  179184. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179185. {
  179186. using namespace pnglibNamespace;
  179187. const int width = image.getWidth();
  179188. const int height = image.getHeight();
  179189. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179190. if (pngWriteStruct == 0)
  179191. return false;
  179192. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179193. if (pngInfoStruct == 0)
  179194. {
  179195. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179196. return false;
  179197. }
  179198. png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);
  179199. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179200. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179201. : PNG_COLOR_TYPE_RGB,
  179202. PNG_INTERLACE_NONE,
  179203. PNG_COMPRESSION_TYPE_BASE,
  179204. PNG_FILTER_TYPE_BASE);
  179205. HeapBlock <png_byte> rowData (width * 4);
  179206. png_color_8 sig_bit;
  179207. sig_bit.red = 8;
  179208. sig_bit.green = 8;
  179209. sig_bit.blue = 8;
  179210. sig_bit.alpha = 8;
  179211. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179212. png_write_info (pngWriteStruct, pngInfoStruct);
  179213. png_set_shift (pngWriteStruct, &sig_bit);
  179214. png_set_packing (pngWriteStruct);
  179215. const Image::BitmapData srcData (image, 0, 0, width, height);
  179216. for (int y = 0; y < height; ++y)
  179217. {
  179218. uint8* dst = (uint8*) rowData;
  179219. const uint8* src = srcData.getLinePointer (y);
  179220. if (image.hasAlphaChannel())
  179221. {
  179222. for (int i = width; --i >= 0;)
  179223. {
  179224. PixelARGB p (*(const PixelARGB*) src);
  179225. p.unpremultiply();
  179226. *dst++ = p.getRed();
  179227. *dst++ = p.getGreen();
  179228. *dst++ = p.getBlue();
  179229. *dst++ = p.getAlpha();
  179230. src += srcData.pixelStride;
  179231. }
  179232. }
  179233. else
  179234. {
  179235. for (int i = width; --i >= 0;)
  179236. {
  179237. *dst++ = ((const PixelRGB*) src)->getRed();
  179238. *dst++ = ((const PixelRGB*) src)->getGreen();
  179239. *dst++ = ((const PixelRGB*) src)->getBlue();
  179240. src += srcData.pixelStride;
  179241. }
  179242. }
  179243. png_write_rows (pngWriteStruct, &rowData, 1);
  179244. }
  179245. png_write_end (pngWriteStruct, pngInfoStruct);
  179246. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179247. out.flush();
  179248. return true;
  179249. }
  179250. END_JUCE_NAMESPACE
  179251. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179252. #endif
  179253. //==============================================================================
  179254. #if JUCE_BUILD_NATIVE
  179255. #if JUCE_WINDOWS
  179256. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179257. #if JUCE_WINDOWS
  179258. BEGIN_JUCE_NAMESPACE
  179259. #define JUCE_INCLUDED_FILE 1
  179260. // Now include the actual code files..
  179261. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179262. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179263. // compiled on its own).
  179264. #if JUCE_INCLUDED_FILE
  179265. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179266. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179267. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179268. #ifndef DOXYGEN
  179269. // use with DynamicLibraryLoader to simplify importing functions
  179270. //
  179271. // functionName: function to import
  179272. // localFunctionName: name you want to use to actually call it (must be different)
  179273. // returnType: the return type
  179274. // object: the DynamicLibraryLoader to use
  179275. // params: list of params (bracketed)
  179276. //
  179277. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179278. typedef returnType (WINAPI *type##localFunctionName) params; \
  179279. type##localFunctionName localFunctionName \
  179280. = (type##localFunctionName)object.findProcAddress (#functionName);
  179281. // loads and unloads a DLL automatically
  179282. class JUCE_API DynamicLibraryLoader
  179283. {
  179284. public:
  179285. DynamicLibraryLoader (const String& name);
  179286. ~DynamicLibraryLoader();
  179287. void* findProcAddress (const String& functionName);
  179288. private:
  179289. void* libHandle;
  179290. };
  179291. #endif
  179292. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179293. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179294. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179295. {
  179296. libHandle = LoadLibrary (name);
  179297. }
  179298. DynamicLibraryLoader::~DynamicLibraryLoader()
  179299. {
  179300. FreeLibrary ((HMODULE) libHandle);
  179301. }
  179302. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179303. {
  179304. return (void*) GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179305. }
  179306. #endif
  179307. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179308. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179309. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179310. // compiled on its own).
  179311. #if JUCE_INCLUDED_FILE
  179312. extern void juce_initialiseThreadEvents();
  179313. void Logger::outputDebugString (const String& text) throw()
  179314. {
  179315. OutputDebugString (text + T("\n"));
  179316. }
  179317. static int64 hiResTicksPerSecond;
  179318. static double hiResTicksScaleFactor;
  179319. #if JUCE_USE_INTRINSICS
  179320. // CPU info functions using intrinsics...
  179321. #pragma intrinsic (__cpuid)
  179322. #pragma intrinsic (__rdtsc)
  179323. const String SystemStats::getCpuVendor() throw()
  179324. {
  179325. int info [4];
  179326. __cpuid (info, 0);
  179327. char v [12];
  179328. memcpy (v, info + 1, 4);
  179329. memcpy (v + 4, info + 3, 4);
  179330. memcpy (v + 8, info + 2, 4);
  179331. return String (v, 12);
  179332. }
  179333. #else
  179334. // CPU info functions using old fashioned inline asm...
  179335. static void juce_getCpuVendor (char* const v)
  179336. {
  179337. int vendor[4];
  179338. zeromem (vendor, 16);
  179339. #ifdef JUCE_64BIT
  179340. #else
  179341. #ifndef __MINGW32__
  179342. __try
  179343. #endif
  179344. {
  179345. #if JUCE_GCC
  179346. unsigned int dummy = 0;
  179347. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179348. #else
  179349. __asm
  179350. {
  179351. mov eax, 0
  179352. cpuid
  179353. mov [vendor], ebx
  179354. mov [vendor + 4], edx
  179355. mov [vendor + 8], ecx
  179356. }
  179357. #endif
  179358. }
  179359. #ifndef __MINGW32__
  179360. __except (EXCEPTION_EXECUTE_HANDLER)
  179361. {
  179362. *v = 0;
  179363. }
  179364. #endif
  179365. #endif
  179366. memcpy (v, vendor, 16);
  179367. }
  179368. const String SystemStats::getCpuVendor() throw()
  179369. {
  179370. char v [16];
  179371. juce_getCpuVendor (v);
  179372. return String (v, 16);
  179373. }
  179374. #endif
  179375. struct CPUFlags
  179376. {
  179377. bool hasMMX : 1;
  179378. bool hasSSE : 1;
  179379. bool hasSSE2 : 1;
  179380. bool has3DNow : 1;
  179381. };
  179382. static CPUFlags cpuFlags;
  179383. bool SystemStats::hasMMX() throw()
  179384. {
  179385. return cpuFlags.hasMMX;
  179386. }
  179387. bool SystemStats::hasSSE() throw()
  179388. {
  179389. return cpuFlags.hasSSE;
  179390. }
  179391. bool SystemStats::hasSSE2() throw()
  179392. {
  179393. return cpuFlags.hasSSE2;
  179394. }
  179395. bool SystemStats::has3DNow() throw()
  179396. {
  179397. return cpuFlags.has3DNow;
  179398. }
  179399. void SystemStats::initialiseStats() throw()
  179400. {
  179401. juce_initialiseThreadEvents();
  179402. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179403. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179404. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179405. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179406. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179407. #else
  179408. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179409. #endif
  179410. LARGE_INTEGER f;
  179411. QueryPerformanceFrequency (&f);
  179412. hiResTicksPerSecond = f.QuadPart;
  179413. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179414. String s (SystemStats::getJUCEVersion());
  179415. #ifdef JUCE_DEBUG
  179416. const MMRESULT res = timeBeginPeriod (1);
  179417. jassert (res == TIMERR_NOERROR);
  179418. #else
  179419. timeBeginPeriod (1);
  179420. #endif
  179421. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179422. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179423. #endif
  179424. }
  179425. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179426. {
  179427. OSVERSIONINFO info;
  179428. info.dwOSVersionInfoSize = sizeof (info);
  179429. GetVersionEx (&info);
  179430. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179431. {
  179432. switch (info.dwMajorVersion)
  179433. {
  179434. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179435. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179436. default: jassertfalse; break; // !! not a supported OS!
  179437. }
  179438. }
  179439. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179440. {
  179441. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179442. return Win98;
  179443. }
  179444. return UnknownOS;
  179445. }
  179446. const String SystemStats::getOperatingSystemName() throw()
  179447. {
  179448. const char* name = "Unknown OS";
  179449. switch (getOperatingSystemType())
  179450. {
  179451. case Windows7: name = "Windows 7"; break;
  179452. case WinVista: name = "Windows Vista"; break;
  179453. case WinXP: name = "Windows XP"; break;
  179454. case Win2000: name = "Windows 2000"; break;
  179455. case Win98: name = "Windows 98"; break;
  179456. default: jassertfalse; break; // !! new type of OS?
  179457. }
  179458. return name;
  179459. }
  179460. bool SystemStats::isOperatingSystem64Bit() throw()
  179461. {
  179462. #ifdef _WIN64
  179463. return true;
  179464. #else
  179465. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179466. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179467. BOOL isWow64 = FALSE;
  179468. return (fnIsWow64Process != 0)
  179469. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179470. && (isWow64 != FALSE);
  179471. #endif
  179472. }
  179473. int SystemStats::getMemorySizeInMegabytes() throw()
  179474. {
  179475. MEMORYSTATUSEX mem;
  179476. mem.dwLength = sizeof (mem);
  179477. GlobalMemoryStatusEx (&mem);
  179478. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179479. }
  179480. int SystemStats::getNumCpus() throw()
  179481. {
  179482. SYSTEM_INFO systemInfo;
  179483. GetSystemInfo (&systemInfo);
  179484. return systemInfo.dwNumberOfProcessors;
  179485. }
  179486. uint32 juce_millisecondsSinceStartup() throw()
  179487. {
  179488. return (uint32) GetTickCount();
  179489. }
  179490. int64 Time::getHighResolutionTicks() throw()
  179491. {
  179492. LARGE_INTEGER ticks;
  179493. QueryPerformanceCounter (&ticks);
  179494. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179495. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179496. // fix for a very obscure PCI hardware bug that can make the counter
  179497. // sometimes jump forwards by a few seconds..
  179498. static int64 hiResTicksOffset = 0;
  179499. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179500. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179501. hiResTicksOffset = newOffset;
  179502. return ticks.QuadPart + hiResTicksOffset;
  179503. }
  179504. double Time::getMillisecondCounterHiRes() throw()
  179505. {
  179506. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179507. }
  179508. int64 Time::getHighResolutionTicksPerSecond() throw()
  179509. {
  179510. return hiResTicksPerSecond;
  179511. }
  179512. int64 SystemStats::getClockCycleCounter() throw()
  179513. {
  179514. #if JUCE_USE_INTRINSICS
  179515. // MS intrinsics version...
  179516. return __rdtsc();
  179517. #elif JUCE_GCC
  179518. // GNU inline asm version...
  179519. unsigned int hi = 0, lo = 0;
  179520. __asm__ __volatile__ (
  179521. "xor %%eax, %%eax \n\
  179522. xor %%edx, %%edx \n\
  179523. rdtsc \n\
  179524. movl %%eax, %[lo] \n\
  179525. movl %%edx, %[hi]"
  179526. :
  179527. : [hi] "m" (hi),
  179528. [lo] "m" (lo)
  179529. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179530. return (int64) ((((uint64) hi) << 32) | lo);
  179531. #else
  179532. // MSVC inline asm version...
  179533. unsigned int hi = 0, lo = 0;
  179534. __asm
  179535. {
  179536. xor eax, eax
  179537. xor edx, edx
  179538. rdtsc
  179539. mov lo, eax
  179540. mov hi, edx
  179541. }
  179542. return (int64) ((((uint64) hi) << 32) | lo);
  179543. #endif
  179544. }
  179545. int SystemStats::getCpuSpeedInMegaherz() throw()
  179546. {
  179547. const int64 cycles = SystemStats::getClockCycleCounter();
  179548. const uint32 millis = Time::getMillisecondCounter();
  179549. int lastResult = 0;
  179550. for (;;)
  179551. {
  179552. int n = 1000000;
  179553. while (--n > 0) {}
  179554. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179555. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179556. if (millisElapsed > 80)
  179557. {
  179558. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179559. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179560. return newResult;
  179561. lastResult = newResult;
  179562. }
  179563. }
  179564. }
  179565. bool Time::setSystemTimeToThisTime() const throw()
  179566. {
  179567. SYSTEMTIME st;
  179568. st.wDayOfWeek = 0;
  179569. st.wYear = (WORD) getYear();
  179570. st.wMonth = (WORD) (getMonth() + 1);
  179571. st.wDay = (WORD) getDayOfMonth();
  179572. st.wHour = (WORD) getHours();
  179573. st.wMinute = (WORD) getMinutes();
  179574. st.wSecond = (WORD) getSeconds();
  179575. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179576. // do this twice because of daylight saving conversion problems - the
  179577. // first one sets it up, the second one kicks it in.
  179578. return SetLocalTime (&st) != 0
  179579. && SetLocalTime (&st) != 0;
  179580. }
  179581. int SystemStats::getPageSize() throw()
  179582. {
  179583. SYSTEM_INFO systemInfo;
  179584. GetSystemInfo (&systemInfo);
  179585. return systemInfo.dwPageSize;
  179586. }
  179587. const String SystemStats::getLogonName()
  179588. {
  179589. TCHAR text [256];
  179590. DWORD len = numElementsInArray (text) - 2;
  179591. zerostruct (text);
  179592. GetUserName (text, &len);
  179593. return String (text, len);
  179594. }
  179595. const String SystemStats::getFullUserName()
  179596. {
  179597. return getLogonName();
  179598. }
  179599. #endif
  179600. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179601. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179602. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179603. // compiled on its own).
  179604. #if JUCE_INCLUDED_FILE
  179605. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179606. extern HWND juce_messageWindowHandle;
  179607. #endif
  179608. #if ! JUCE_USE_INTRINSICS
  179609. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179610. // older ones we have to actually call the ops as win32 functions..
  179611. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179612. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179613. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179614. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179615. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179616. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179617. #endif
  179618. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179619. CriticalSection::CriticalSection() throw()
  179620. {
  179621. // (just to check the MS haven't changed this structure and broken things...)
  179622. #if _MSC_VER >= 1400
  179623. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179624. #else
  179625. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179626. #endif
  179627. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179628. }
  179629. CriticalSection::~CriticalSection() throw()
  179630. {
  179631. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179632. }
  179633. void CriticalSection::enter() const throw()
  179634. {
  179635. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179636. }
  179637. bool CriticalSection::tryEnter() const throw()
  179638. {
  179639. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179640. }
  179641. void CriticalSection::exit() const throw()
  179642. {
  179643. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179644. }
  179645. WaitableEvent::WaitableEvent() throw()
  179646. : internal (CreateEvent (0, FALSE, FALSE, 0))
  179647. {
  179648. }
  179649. WaitableEvent::~WaitableEvent() throw()
  179650. {
  179651. CloseHandle (internal);
  179652. }
  179653. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179654. {
  179655. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179656. }
  179657. void WaitableEvent::signal() const throw()
  179658. {
  179659. SetEvent (internal);
  179660. }
  179661. void WaitableEvent::reset() const throw()
  179662. {
  179663. ResetEvent (internal);
  179664. }
  179665. void JUCE_API juce_threadEntryPoint (void*);
  179666. static unsigned int __stdcall threadEntryProc (void* userData)
  179667. {
  179668. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179669. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179670. GetCurrentThreadId(), TRUE);
  179671. #endif
  179672. juce_threadEntryPoint (userData);
  179673. _endthreadex (0);
  179674. return 0;
  179675. }
  179676. void juce_CloseThreadHandle (void* handle)
  179677. {
  179678. CloseHandle ((HANDLE) handle);
  179679. }
  179680. void* juce_createThread (void* userData)
  179681. {
  179682. unsigned int threadId;
  179683. return (void*) _beginthreadex (0, 0,
  179684. &threadEntryProc,
  179685. userData,
  179686. 0, &threadId);
  179687. }
  179688. void juce_killThread (void* handle)
  179689. {
  179690. if (handle != 0)
  179691. {
  179692. #ifdef JUCE_DEBUG
  179693. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179694. #endif
  179695. TerminateThread (handle, 0);
  179696. }
  179697. }
  179698. void juce_setCurrentThreadName (const String& name)
  179699. {
  179700. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179701. struct
  179702. {
  179703. DWORD dwType;
  179704. LPCSTR szName;
  179705. DWORD dwThreadID;
  179706. DWORD dwFlags;
  179707. } info;
  179708. info.dwType = 0x1000;
  179709. info.szName = name.toCString();
  179710. info.dwThreadID = GetCurrentThreadId();
  179711. info.dwFlags = 0;
  179712. #define MS_VC_EXCEPTION 0x406d1388
  179713. __try
  179714. {
  179715. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179716. }
  179717. __except (EXCEPTION_CONTINUE_EXECUTION)
  179718. {}
  179719. #else
  179720. (void) name;
  179721. #endif
  179722. }
  179723. Thread::ThreadID Thread::getCurrentThreadId()
  179724. {
  179725. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179726. }
  179727. // priority 1 to 10 where 5=normal, 1=low
  179728. bool juce_setThreadPriority (void* threadHandle, int priority)
  179729. {
  179730. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179731. if (priority < 1)
  179732. pri = THREAD_PRIORITY_IDLE;
  179733. else if (priority < 2)
  179734. pri = THREAD_PRIORITY_LOWEST;
  179735. else if (priority < 5)
  179736. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179737. else if (priority < 7)
  179738. pri = THREAD_PRIORITY_NORMAL;
  179739. else if (priority < 9)
  179740. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179741. else if (priority < 10)
  179742. pri = THREAD_PRIORITY_HIGHEST;
  179743. if (threadHandle == 0)
  179744. threadHandle = GetCurrentThread();
  179745. return SetThreadPriority (threadHandle, pri) != FALSE;
  179746. }
  179747. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179748. {
  179749. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179750. }
  179751. static HANDLE sleepEvent = 0;
  179752. void juce_initialiseThreadEvents()
  179753. {
  179754. if (sleepEvent == 0)
  179755. #ifdef JUCE_DEBUG
  179756. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179757. #else
  179758. sleepEvent = CreateEvent (0, 0, 0, 0);
  179759. #endif
  179760. }
  179761. void Thread::yield()
  179762. {
  179763. Sleep (0);
  179764. }
  179765. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179766. {
  179767. if (millisecs >= 10)
  179768. {
  179769. Sleep (millisecs);
  179770. }
  179771. else
  179772. {
  179773. jassert (sleepEvent != 0);
  179774. // unlike Sleep() this is guaranteed to return to the current thread after
  179775. // the time expires, so we'll use this for short waits, which are more likely
  179776. // to need to be accurate
  179777. WaitForSingleObject (sleepEvent, millisecs);
  179778. }
  179779. }
  179780. static int lastProcessPriority = -1;
  179781. // called by WindowDriver because Windows does wierd things to process priority
  179782. // when you swap apps, and this forces an update when the app is brought to the front.
  179783. void juce_repeatLastProcessPriority()
  179784. {
  179785. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179786. {
  179787. DWORD p;
  179788. switch (lastProcessPriority)
  179789. {
  179790. case Process::LowPriority:
  179791. p = IDLE_PRIORITY_CLASS;
  179792. break;
  179793. case Process::NormalPriority:
  179794. p = NORMAL_PRIORITY_CLASS;
  179795. break;
  179796. case Process::HighPriority:
  179797. p = HIGH_PRIORITY_CLASS;
  179798. break;
  179799. case Process::RealtimePriority:
  179800. p = REALTIME_PRIORITY_CLASS;
  179801. break;
  179802. default:
  179803. jassertfalse // bad priority value
  179804. return;
  179805. }
  179806. SetPriorityClass (GetCurrentProcess(), p);
  179807. }
  179808. }
  179809. void Process::setPriority (ProcessPriority prior)
  179810. {
  179811. if (lastProcessPriority != (int) prior)
  179812. {
  179813. lastProcessPriority = (int) prior;
  179814. juce_repeatLastProcessPriority();
  179815. }
  179816. }
  179817. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179818. {
  179819. return IsDebuggerPresent() != FALSE;
  179820. }
  179821. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179822. {
  179823. return juce_isRunningUnderDebugger();
  179824. }
  179825. void Process::raisePrivilege()
  179826. {
  179827. jassertfalse // xxx not implemented
  179828. }
  179829. void Process::lowerPrivilege()
  179830. {
  179831. jassertfalse // xxx not implemented
  179832. }
  179833. void Process::terminate()
  179834. {
  179835. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179836. _CrtDumpMemoryLeaks();
  179837. #endif
  179838. // bullet in the head in case there's a problem shutting down..
  179839. ExitProcess (0);
  179840. }
  179841. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179842. {
  179843. void* result = 0;
  179844. JUCE_TRY
  179845. {
  179846. result = (void*) LoadLibrary (name);
  179847. }
  179848. JUCE_CATCH_ALL
  179849. return result;
  179850. }
  179851. void PlatformUtilities::freeDynamicLibrary (void* h)
  179852. {
  179853. JUCE_TRY
  179854. {
  179855. if (h != 0)
  179856. FreeLibrary ((HMODULE) h);
  179857. }
  179858. JUCE_CATCH_ALL
  179859. }
  179860. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179861. {
  179862. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179863. }
  179864. InterProcessLock::InterProcessLock (const String& name_)
  179865. : internal (0),
  179866. name (name_),
  179867. reentrancyLevel (0)
  179868. {
  179869. }
  179870. InterProcessLock::~InterProcessLock()
  179871. {
  179872. exit();
  179873. }
  179874. bool InterProcessLock::enter (const int timeOutMillisecs)
  179875. {
  179876. if (reentrancyLevel++ == 0)
  179877. {
  179878. internal = CreateMutex (0, TRUE, "Global\\" + name);
  179879. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179880. {
  179881. if (timeOutMillisecs == 0
  179882. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  179883. == WAIT_TIMEOUT)
  179884. {
  179885. ReleaseMutex (internal);
  179886. CloseHandle (internal);
  179887. internal = 0;
  179888. }
  179889. }
  179890. }
  179891. return (internal != 0);
  179892. }
  179893. void InterProcessLock::exit()
  179894. {
  179895. if (--reentrancyLevel == 0 && internal != 0)
  179896. {
  179897. ReleaseMutex (internal);
  179898. CloseHandle (internal);
  179899. internal = 0;
  179900. }
  179901. }
  179902. #endif
  179903. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179904. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179905. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179906. // compiled on its own).
  179907. #if JUCE_INCLUDED_FILE
  179908. #ifndef CSIDL_MYMUSIC
  179909. #define CSIDL_MYMUSIC 0x000d
  179910. #endif
  179911. #ifndef CSIDL_MYVIDEO
  179912. #define CSIDL_MYVIDEO 0x000e
  179913. #endif
  179914. const tchar File::separator = T('\\');
  179915. const tchar* File::separatorString = T("\\");
  179916. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  179917. {
  179918. if (fileName.isEmpty())
  179919. return false;
  179920. const DWORD attr = GetFileAttributes (fileName);
  179921. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  179922. : (attr != 0xffffffff);
  179923. }
  179924. bool juce_isDirectory (const String& fileName)
  179925. {
  179926. const DWORD attr = GetFileAttributes (fileName);
  179927. return (attr != 0xffffffff)
  179928. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  179929. }
  179930. bool juce_canWriteToFile (const String& fileName)
  179931. {
  179932. const DWORD attr = GetFileAttributes (fileName);
  179933. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  179934. }
  179935. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  179936. {
  179937. DWORD attr = GetFileAttributes (fileName);
  179938. if (attr == 0xffffffff)
  179939. return false;
  179940. if (isReadOnly != juce_canWriteToFile (fileName))
  179941. return true;
  179942. if (isReadOnly)
  179943. attr |= FILE_ATTRIBUTE_READONLY;
  179944. else
  179945. attr &= ~FILE_ATTRIBUTE_READONLY;
  179946. return SetFileAttributes (fileName, attr) != FALSE;
  179947. }
  179948. bool File::isHidden() const
  179949. {
  179950. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  179951. }
  179952. bool juce_deleteFile (const String& fileName)
  179953. {
  179954. if (juce_isDirectory (fileName))
  179955. return RemoveDirectory (fileName) != 0;
  179956. return DeleteFile (fileName) != 0;
  179957. }
  179958. bool File::moveToTrash() const
  179959. {
  179960. if (! exists())
  179961. return true;
  179962. SHFILEOPSTRUCT fos;
  179963. zerostruct (fos);
  179964. // The string we pass in must be double null terminated..
  179965. String doubleNullTermPath (getFullPathName() + " ");
  179966. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  179967. p [getFullPathName().length()] = 0;
  179968. fos.wFunc = FO_DELETE;
  179969. fos.hwnd = (HWND) 0;
  179970. fos.pFrom = p;
  179971. fos.pTo = NULL;
  179972. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  179973. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  179974. return SHFileOperation (&fos) == 0;
  179975. }
  179976. bool juce_moveFile (const String& source, const String& dest)
  179977. {
  179978. return MoveFile (source, dest) != 0;
  179979. }
  179980. bool juce_copyFile (const String& source, const String& dest)
  179981. {
  179982. return CopyFile (source, dest, false) != 0;
  179983. }
  179984. void juce_createDirectory (const String& fileName)
  179985. {
  179986. if (! juce_fileExists (fileName, true))
  179987. {
  179988. CreateDirectory (fileName, 0);
  179989. }
  179990. }
  179991. // return 0 if not possible
  179992. void* juce_fileOpen (const String& fileName, bool forWriting)
  179993. {
  179994. HANDLE h;
  179995. if (forWriting)
  179996. {
  179997. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  179998. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  179999. if (h != INVALID_HANDLE_VALUE)
  180000. SetFilePointer (h, 0, 0, FILE_END);
  180001. else
  180002. h = 0;
  180003. }
  180004. else
  180005. {
  180006. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  180007. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  180008. if (h == INVALID_HANDLE_VALUE)
  180009. h = 0;
  180010. }
  180011. return (void*) h;
  180012. }
  180013. void juce_fileClose (void* handle)
  180014. {
  180015. CloseHandle (handle);
  180016. }
  180017. int juce_fileRead (void* handle, void* buffer, int size)
  180018. {
  180019. DWORD num = 0;
  180020. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  180021. return num;
  180022. }
  180023. int juce_fileWrite (void* handle, const void* buffer, int size)
  180024. {
  180025. DWORD num;
  180026. WriteFile ((HANDLE) handle,
  180027. buffer, size,
  180028. &num, 0);
  180029. return num;
  180030. }
  180031. int64 juce_fileSetPosition (void* handle, int64 pos)
  180032. {
  180033. LARGE_INTEGER li;
  180034. li.QuadPart = pos;
  180035. li.LowPart = SetFilePointer ((HANDLE) handle,
  180036. li.LowPart,
  180037. &li.HighPart,
  180038. FILE_BEGIN); // (returns -1 if it fails)
  180039. return li.QuadPart;
  180040. }
  180041. int64 juce_fileGetPosition (void* handle)
  180042. {
  180043. LARGE_INTEGER li;
  180044. li.QuadPart = 0;
  180045. li.LowPart = SetFilePointer ((HANDLE) handle,
  180046. 0, &li.HighPart,
  180047. FILE_CURRENT); // (returns -1 if it fails)
  180048. return jmax ((int64) 0, li.QuadPart);
  180049. }
  180050. void juce_fileFlush (void* handle)
  180051. {
  180052. FlushFileBuffers ((HANDLE) handle);
  180053. }
  180054. int64 juce_getFileSize (const String& fileName)
  180055. {
  180056. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180057. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180058. {
  180059. return (((int64) attributes.nFileSizeHigh) << 32)
  180060. | attributes.nFileSizeLow;
  180061. }
  180062. return 0;
  180063. }
  180064. static int64 fileTimeToTime (const FILETIME* const ft)
  180065. {
  180066. // tell me if this fails!
  180067. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180068. #if JUCE_GCC
  180069. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180070. #else
  180071. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180072. #endif
  180073. }
  180074. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180075. {
  180076. #if JUCE_GCC
  180077. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180078. #else
  180079. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180080. #endif
  180081. }
  180082. void juce_getFileTimes (const String& fileName,
  180083. int64& modificationTime,
  180084. int64& accessTime,
  180085. int64& creationTime)
  180086. {
  180087. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180088. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180089. {
  180090. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180091. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180092. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180093. }
  180094. else
  180095. {
  180096. creationTime = accessTime = modificationTime = 0;
  180097. }
  180098. }
  180099. bool juce_setFileTimes (const String& fileName,
  180100. int64 modificationTime,
  180101. int64 accessTime,
  180102. int64 creationTime)
  180103. {
  180104. FILETIME m, a, c;
  180105. if (modificationTime > 0)
  180106. timeToFileTime (modificationTime, &m);
  180107. if (accessTime > 0)
  180108. timeToFileTime (accessTime, &a);
  180109. if (creationTime > 0)
  180110. timeToFileTime (creationTime, &c);
  180111. void* const h = juce_fileOpen (fileName, true);
  180112. bool ok = false;
  180113. if (h != 0)
  180114. {
  180115. ok = SetFileTime ((HANDLE) h,
  180116. (creationTime > 0) ? &c : 0,
  180117. (accessTime > 0) ? &a : 0,
  180118. (modificationTime > 0) ? &m : 0) != 0;
  180119. juce_fileClose (h);
  180120. }
  180121. return ok;
  180122. }
  180123. // return '\0' separated list of strings
  180124. const StringArray juce_getFileSystemRoots()
  180125. {
  180126. TCHAR buffer [2048];
  180127. buffer[0] = 0;
  180128. buffer[1] = 0;
  180129. GetLogicalDriveStrings (2048, buffer);
  180130. TCHAR* n = buffer;
  180131. StringArray roots;
  180132. while (*n != 0)
  180133. {
  180134. roots.add (String (n));
  180135. while (*n++ != 0)
  180136. {
  180137. }
  180138. }
  180139. roots.sort (true);
  180140. return roots;
  180141. }
  180142. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180143. int& volumeSerialNumber)
  180144. {
  180145. TCHAR n [4];
  180146. n[0] = *(const TCHAR*) filenameOnVolume;
  180147. n[1] = L':';
  180148. n[2] = L'\\';
  180149. n[3] = 0;
  180150. TCHAR dest [64];
  180151. DWORD serialNum;
  180152. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180153. {
  180154. dest[0] = 0;
  180155. serialNum = 0;
  180156. }
  180157. volumeSerialNumber = serialNum;
  180158. return String (dest);
  180159. }
  180160. static int64 getDiskSpaceInfo (String fn, const bool total)
  180161. {
  180162. if (fn[1] == T(':'))
  180163. fn = fn.substring (0, 2) + T("\\");
  180164. ULARGE_INTEGER spc, tot, totFree;
  180165. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180166. return (int64) (total ? tot.QuadPart
  180167. : spc.QuadPart);
  180168. return 0;
  180169. }
  180170. int64 File::getBytesFreeOnVolume() const
  180171. {
  180172. return getDiskSpaceInfo (getFullPathName(), false);
  180173. }
  180174. int64 File::getVolumeTotalSize() const
  180175. {
  180176. return getDiskSpaceInfo (getFullPathName(), true);
  180177. }
  180178. static unsigned int getWindowsDriveType (const String& fileName)
  180179. {
  180180. TCHAR n[4];
  180181. n[0] = *(const TCHAR*) fileName;
  180182. n[1] = L':';
  180183. n[2] = L'\\';
  180184. n[3] = 0;
  180185. return GetDriveType (n);
  180186. }
  180187. bool File::isOnCDRomDrive() const
  180188. {
  180189. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180190. }
  180191. bool File::isOnHardDisk() const
  180192. {
  180193. if (fullPath.isEmpty())
  180194. return false;
  180195. const unsigned int n = getWindowsDriveType (getFullPathName());
  180196. if (fullPath.toLowerCase()[0] <= 'b'
  180197. && fullPath[1] == T(':'))
  180198. {
  180199. return n != DRIVE_REMOVABLE;
  180200. }
  180201. else
  180202. {
  180203. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180204. }
  180205. }
  180206. bool File::isOnRemovableDrive() const
  180207. {
  180208. if (fullPath.isEmpty())
  180209. return false;
  180210. const unsigned int n = getWindowsDriveType (getFullPathName());
  180211. return n == DRIVE_CDROM
  180212. || n == DRIVE_REMOTE
  180213. || n == DRIVE_REMOVABLE
  180214. || n == DRIVE_RAMDISK;
  180215. }
  180216. static const File juce_getSpecialFolderPath (int type)
  180217. {
  180218. WCHAR path [MAX_PATH + 256];
  180219. if (SHGetSpecialFolderPath (0, path, type, 0))
  180220. return File (String (path));
  180221. return File::nonexistent;
  180222. }
  180223. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180224. {
  180225. int csidlType = 0;
  180226. switch (type)
  180227. {
  180228. case userHomeDirectory:
  180229. csidlType = CSIDL_PROFILE;
  180230. break;
  180231. case userDocumentsDirectory:
  180232. csidlType = CSIDL_PERSONAL;
  180233. break;
  180234. case userDesktopDirectory:
  180235. csidlType = CSIDL_DESKTOP;
  180236. break;
  180237. case userApplicationDataDirectory:
  180238. csidlType = CSIDL_APPDATA;
  180239. break;
  180240. case commonApplicationDataDirectory:
  180241. csidlType = CSIDL_COMMON_APPDATA;
  180242. break;
  180243. case globalApplicationsDirectory:
  180244. csidlType = CSIDL_PROGRAM_FILES;
  180245. break;
  180246. case userMusicDirectory:
  180247. csidlType = CSIDL_MYMUSIC;
  180248. break;
  180249. case userMoviesDirectory:
  180250. csidlType = CSIDL_MYVIDEO;
  180251. break;
  180252. case tempDirectory:
  180253. {
  180254. WCHAR dest [2048];
  180255. dest[0] = 0;
  180256. GetTempPath (2048, dest);
  180257. return File (String (dest));
  180258. }
  180259. case invokedExecutableFile:
  180260. case currentExecutableFile:
  180261. case currentApplicationFile:
  180262. {
  180263. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180264. WCHAR dest [MAX_PATH + 256];
  180265. dest[0] = 0;
  180266. GetModuleFileName (moduleHandle, dest, numElementsInArray (dest));
  180267. return File (String (dest));
  180268. }
  180269. break;
  180270. default:
  180271. jassertfalse // unknown type?
  180272. return File::nonexistent;
  180273. }
  180274. return juce_getSpecialFolderPath (csidlType);
  180275. }
  180276. const File File::getCurrentWorkingDirectory()
  180277. {
  180278. WCHAR dest [MAX_PATH + 256];
  180279. dest[0] = 0;
  180280. GetCurrentDirectory (numElementsInArray (dest), dest);
  180281. return File (String (dest));
  180282. }
  180283. bool File::setAsCurrentWorkingDirectory() const
  180284. {
  180285. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180286. }
  180287. const String File::getVersion() const
  180288. {
  180289. String result;
  180290. DWORD handle = 0;
  180291. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180292. HeapBlock <char> buffer;
  180293. buffer.calloc (bufferSize);
  180294. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180295. {
  180296. VS_FIXEDFILEINFO* vffi;
  180297. UINT len = 0;
  180298. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180299. {
  180300. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180301. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180302. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180303. << (int) LOWORD (vffi->dwFileVersionLS);
  180304. }
  180305. }
  180306. return result;
  180307. }
  180308. const File File::getLinkedTarget() const
  180309. {
  180310. File result (*this);
  180311. String p (getFullPathName());
  180312. if (! exists())
  180313. p += T(".lnk");
  180314. else if (getFileExtension() != T(".lnk"))
  180315. return result;
  180316. ComSmartPtr <IShellLink> shellLink;
  180317. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180318. {
  180319. ComSmartPtr <IPersistFile> persistFile;
  180320. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180321. {
  180322. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180323. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180324. {
  180325. WIN32_FIND_DATA winFindData;
  180326. WCHAR resolvedPath [MAX_PATH];
  180327. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180328. result = File (resolvedPath);
  180329. }
  180330. }
  180331. }
  180332. return result;
  180333. }
  180334. template <class FindDataType>
  180335. static void getFindFileInfo (FindDataType& findData,
  180336. String& filename, bool* const isDir, bool* const isHidden,
  180337. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180338. bool* const isReadOnly)
  180339. {
  180340. filename = findData.cFileName;
  180341. if (isDir != 0)
  180342. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180343. if (isHidden != 0)
  180344. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180345. if (fileSize != 0)
  180346. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180347. if (modTime != 0)
  180348. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180349. if (creationTime != 0)
  180350. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180351. if (isReadOnly != 0)
  180352. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180353. }
  180354. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180355. bool* isDir, bool* isHidden, int64* fileSize,
  180356. Time* modTime, Time* creationTime, bool* isReadOnly)
  180357. {
  180358. String wc (directory);
  180359. if (! wc.endsWithChar (File::separator))
  180360. wc += File::separator;
  180361. wc += wildCard;
  180362. WIN32_FIND_DATA findData;
  180363. HANDLE h = FindFirstFile (wc, &findData);
  180364. if (h != INVALID_HANDLE_VALUE)
  180365. {
  180366. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180367. modTime, creationTime, isReadOnly);
  180368. return h;
  180369. }
  180370. firstResult = String::empty;
  180371. return 0;
  180372. }
  180373. bool juce_findFileNext (void* handle, String& resultFile,
  180374. bool* isDir, bool* isHidden, int64* fileSize,
  180375. Time* modTime, Time* creationTime, bool* isReadOnly)
  180376. {
  180377. WIN32_FIND_DATA findData;
  180378. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180379. {
  180380. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180381. modTime, creationTime, isReadOnly);
  180382. return true;
  180383. }
  180384. resultFile = String::empty;
  180385. return false;
  180386. }
  180387. void juce_findFileClose (void* handle)
  180388. {
  180389. FindClose (handle);
  180390. }
  180391. bool juce_launchFile (const String& fileName,
  180392. const String& parameters)
  180393. {
  180394. HINSTANCE hInstance = 0;
  180395. JUCE_TRY
  180396. {
  180397. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180398. }
  180399. JUCE_CATCH_ALL
  180400. return hInstance > (HINSTANCE) 32;
  180401. }
  180402. void File::revealToUser() const
  180403. {
  180404. if (isDirectory())
  180405. startAsProcess();
  180406. else if (getParentDirectory().exists())
  180407. getParentDirectory().startAsProcess();
  180408. }
  180409. struct NamedPipeInternal
  180410. {
  180411. HANDLE pipeH;
  180412. HANDLE cancelEvent;
  180413. bool connected, createdPipe;
  180414. NamedPipeInternal()
  180415. : pipeH (0),
  180416. cancelEvent (0),
  180417. connected (false),
  180418. createdPipe (false)
  180419. {
  180420. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180421. }
  180422. ~NamedPipeInternal()
  180423. {
  180424. disconnect();
  180425. if (pipeH != 0)
  180426. CloseHandle (pipeH);
  180427. CloseHandle (cancelEvent);
  180428. }
  180429. bool connect (const int timeOutMs)
  180430. {
  180431. if (! createdPipe)
  180432. return true;
  180433. if (! connected)
  180434. {
  180435. OVERLAPPED over;
  180436. zerostruct (over);
  180437. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180438. if (ConnectNamedPipe (pipeH, &over))
  180439. {
  180440. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180441. }
  180442. else
  180443. {
  180444. const int err = GetLastError();
  180445. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180446. {
  180447. HANDLE handles[] = { over.hEvent, cancelEvent };
  180448. if (WaitForMultipleObjects (2, handles, FALSE,
  180449. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180450. connected = true;
  180451. }
  180452. else if (err == ERROR_PIPE_CONNECTED)
  180453. {
  180454. connected = true;
  180455. }
  180456. }
  180457. CloseHandle (over.hEvent);
  180458. }
  180459. return connected;
  180460. }
  180461. void disconnect()
  180462. {
  180463. if (connected)
  180464. {
  180465. DisconnectNamedPipe (pipeH);
  180466. connected = false;
  180467. }
  180468. }
  180469. };
  180470. void NamedPipe::close()
  180471. {
  180472. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180473. delete intern;
  180474. internal = 0;
  180475. }
  180476. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180477. {
  180478. close();
  180479. NamedPipeInternal* const intern = new NamedPipeInternal();
  180480. String file ("\\\\.\\pipe\\");
  180481. file += pipeName;
  180482. intern->createdPipe = createPipe;
  180483. if (createPipe)
  180484. {
  180485. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180486. PIPE_UNLIMITED_INSTANCES,
  180487. 4096, 4096, 0, NULL);
  180488. }
  180489. else
  180490. {
  180491. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  180492. FILE_FLAG_OVERLAPPED, 0);
  180493. }
  180494. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180495. {
  180496. internal = intern;
  180497. return true;
  180498. }
  180499. delete intern;
  180500. return false;
  180501. }
  180502. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180503. {
  180504. int bytesRead = -1;
  180505. bool waitAgain = true;
  180506. while (waitAgain && internal != 0)
  180507. {
  180508. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180509. waitAgain = false;
  180510. if (! intern->connect (timeOutMilliseconds))
  180511. break;
  180512. if (maxBytesToRead <= 0)
  180513. return 0;
  180514. OVERLAPPED over;
  180515. zerostruct (over);
  180516. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180517. unsigned long numRead;
  180518. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180519. {
  180520. bytesRead = (int) numRead;
  180521. }
  180522. else if (GetLastError() == ERROR_IO_PENDING)
  180523. {
  180524. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180525. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180526. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180527. : INFINITE);
  180528. if (waitResult != WAIT_OBJECT_0)
  180529. {
  180530. // if the operation timed out, let's cancel it...
  180531. CancelIo (intern->pipeH);
  180532. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180533. }
  180534. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180535. {
  180536. bytesRead = (int) numRead;
  180537. }
  180538. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180539. {
  180540. intern->disconnect();
  180541. waitAgain = true;
  180542. }
  180543. }
  180544. else
  180545. {
  180546. waitAgain = internal != 0;
  180547. Sleep (5);
  180548. }
  180549. CloseHandle (over.hEvent);
  180550. }
  180551. return bytesRead;
  180552. }
  180553. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180554. {
  180555. int bytesWritten = -1;
  180556. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180557. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180558. {
  180559. if (numBytesToWrite <= 0)
  180560. return 0;
  180561. OVERLAPPED over;
  180562. zerostruct (over);
  180563. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180564. unsigned long numWritten;
  180565. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180566. {
  180567. bytesWritten = (int) numWritten;
  180568. }
  180569. else if (GetLastError() == ERROR_IO_PENDING)
  180570. {
  180571. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180572. DWORD waitResult;
  180573. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180574. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180575. : INFINITE);
  180576. if (waitResult != WAIT_OBJECT_0)
  180577. {
  180578. CancelIo (intern->pipeH);
  180579. WaitForSingleObject (over.hEvent, INFINITE);
  180580. }
  180581. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180582. {
  180583. bytesWritten = (int) numWritten;
  180584. }
  180585. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180586. {
  180587. intern->disconnect();
  180588. }
  180589. }
  180590. CloseHandle (over.hEvent);
  180591. }
  180592. return bytesWritten;
  180593. }
  180594. void NamedPipe::cancelPendingReads()
  180595. {
  180596. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180597. if (intern != 0)
  180598. SetEvent (intern->cancelEvent);
  180599. }
  180600. #endif
  180601. /*** End of inlined file: juce_win32_Files.cpp ***/
  180602. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180603. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180604. // compiled on its own).
  180605. #if JUCE_INCLUDED_FILE
  180606. #ifndef INTERNET_FLAG_NEED_FILE
  180607. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180608. #endif
  180609. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180610. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180611. #endif
  180612. bool juce_isOnLine()
  180613. {
  180614. DWORD connectionType;
  180615. return InternetGetConnectedState (&connectionType, 0) != 0
  180616. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180617. }
  180618. struct ConnectionAndRequestStruct
  180619. {
  180620. HINTERNET connection, request;
  180621. };
  180622. static HINTERNET sessionHandle = 0;
  180623. #ifndef WORKAROUND_TIMEOUT_BUG
  180624. //#define WORKAROUND_TIMEOUT_BUG 1
  180625. #endif
  180626. #if WORKAROUND_TIMEOUT_BUG
  180627. // Required because of a Microsoft bug in setting a timeout
  180628. class InternetConnectThread : public Thread
  180629. {
  180630. public:
  180631. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180632. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180633. {
  180634. startThread();
  180635. }
  180636. ~InternetConnectThread()
  180637. {
  180638. stopThread (60000);
  180639. }
  180640. void run()
  180641. {
  180642. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180643. uc.nPort, _T(""), _T(""),
  180644. isFtp ? INTERNET_SERVICE_FTP
  180645. : INTERNET_SERVICE_HTTP,
  180646. 0, 0);
  180647. notify();
  180648. }
  180649. juce_UseDebuggingNewOperator
  180650. private:
  180651. URL_COMPONENTS& uc;
  180652. HINTERNET& connection;
  180653. const bool isFtp;
  180654. InternetConnectThread (const InternetConnectThread&);
  180655. InternetConnectThread& operator= (const InternetConnectThread&);
  180656. };
  180657. #endif
  180658. void* juce_openInternetFile (const String& url,
  180659. const String& headers,
  180660. const MemoryBlock& postData,
  180661. const bool isPost,
  180662. URL::OpenStreamProgressCallback* callback,
  180663. void* callbackContext,
  180664. int timeOutMs)
  180665. {
  180666. if (sessionHandle == 0)
  180667. sessionHandle = InternetOpen (_T("juce"),
  180668. INTERNET_OPEN_TYPE_PRECONFIG,
  180669. 0, 0, 0);
  180670. if (sessionHandle != 0)
  180671. {
  180672. // break up the url..
  180673. TCHAR file[1024], server[1024];
  180674. URL_COMPONENTS uc;
  180675. zerostruct (uc);
  180676. uc.dwStructSize = sizeof (uc);
  180677. uc.dwUrlPathLength = sizeof (file);
  180678. uc.dwHostNameLength = sizeof (server);
  180679. uc.lpszUrlPath = file;
  180680. uc.lpszHostName = server;
  180681. if (InternetCrackUrl (url, 0, 0, &uc))
  180682. {
  180683. int disable = 1;
  180684. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180685. if (timeOutMs == 0)
  180686. timeOutMs = 30000;
  180687. else if (timeOutMs < 0)
  180688. timeOutMs = -1;
  180689. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180690. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  180691. #if WORKAROUND_TIMEOUT_BUG
  180692. HINTERNET connection = 0;
  180693. {
  180694. InternetConnectThread connectThread (uc, connection, isFtp);
  180695. connectThread.wait (timeOutMs);
  180696. if (connection == 0)
  180697. {
  180698. InternetCloseHandle (sessionHandle);
  180699. sessionHandle = 0;
  180700. }
  180701. }
  180702. #else
  180703. HINTERNET connection = InternetConnect (sessionHandle,
  180704. uc.lpszHostName,
  180705. uc.nPort,
  180706. _T(""), _T(""),
  180707. isFtp ? INTERNET_SERVICE_FTP
  180708. : INTERNET_SERVICE_HTTP,
  180709. 0, 0);
  180710. #endif
  180711. if (connection != 0)
  180712. {
  180713. if (isFtp)
  180714. {
  180715. HINTERNET request = FtpOpenFile (connection,
  180716. uc.lpszUrlPath,
  180717. GENERIC_READ,
  180718. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180719. 0);
  180720. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180721. result->connection = connection;
  180722. result->request = request;
  180723. return result;
  180724. }
  180725. else
  180726. {
  180727. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180728. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180729. if (url.startsWithIgnoreCase (T("https:")))
  180730. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180731. // IE7 seems to automatically work out when it's https)
  180732. HINTERNET request = HttpOpenRequest (connection,
  180733. isPost ? _T("POST")
  180734. : _T("GET"),
  180735. uc.lpszUrlPath,
  180736. 0, 0, mimeTypes, flags, 0);
  180737. if (request != 0)
  180738. {
  180739. INTERNET_BUFFERS buffers;
  180740. zerostruct (buffers);
  180741. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180742. buffers.lpcszHeader = (LPCTSTR) headers;
  180743. buffers.dwHeadersLength = headers.length();
  180744. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180745. ConnectionAndRequestStruct* result = 0;
  180746. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180747. {
  180748. int bytesSent = 0;
  180749. for (;;)
  180750. {
  180751. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180752. DWORD bytesDone = 0;
  180753. if (bytesToDo > 0
  180754. && ! InternetWriteFile (request,
  180755. ((const char*) postData.getData()) + bytesSent,
  180756. bytesToDo, &bytesDone))
  180757. {
  180758. break;
  180759. }
  180760. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180761. {
  180762. result = new ConnectionAndRequestStruct();
  180763. result->connection = connection;
  180764. result->request = request;
  180765. HttpEndRequest (request, 0, 0, 0);
  180766. return result;
  180767. }
  180768. bytesSent += bytesDone;
  180769. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180770. break;
  180771. }
  180772. }
  180773. InternetCloseHandle (request);
  180774. }
  180775. InternetCloseHandle (connection);
  180776. }
  180777. }
  180778. }
  180779. }
  180780. return 0;
  180781. }
  180782. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180783. {
  180784. DWORD bytesRead = 0;
  180785. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180786. if (crs != 0)
  180787. InternetReadFile (crs->request,
  180788. buffer, bytesToRead,
  180789. &bytesRead);
  180790. return bytesRead;
  180791. }
  180792. int juce_seekInInternetFile (void* handle, int newPosition)
  180793. {
  180794. if (handle != 0)
  180795. {
  180796. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180797. return InternetSetFilePointer (crs->request,
  180798. newPosition, 0,
  180799. FILE_BEGIN, 0);
  180800. }
  180801. else
  180802. {
  180803. return -1;
  180804. }
  180805. }
  180806. int64 juce_getInternetFileContentLength (void* handle)
  180807. {
  180808. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180809. if (crs != 0)
  180810. {
  180811. DWORD index = 0;
  180812. DWORD result = 0;
  180813. DWORD size = sizeof (result);
  180814. if (HttpQueryInfo (crs->request,
  180815. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180816. &result,
  180817. &size,
  180818. &index))
  180819. {
  180820. return (int64) result;
  180821. }
  180822. }
  180823. return -1;
  180824. }
  180825. void juce_closeInternetFile (void* handle)
  180826. {
  180827. if (handle != 0)
  180828. {
  180829. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  180830. InternetCloseHandle (crs->request);
  180831. InternetCloseHandle (crs->connection);
  180832. delete crs;
  180833. }
  180834. }
  180835. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180836. {
  180837. int numFound = 0;
  180838. DynamicLibraryLoader dll ("iphlpapi.dll");
  180839. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180840. if (getAdaptersInfo != 0)
  180841. {
  180842. ULONG len = sizeof (IP_ADAPTER_INFO);
  180843. MemoryBlock mb;
  180844. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180845. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180846. {
  180847. mb.setSize (len);
  180848. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180849. }
  180850. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180851. {
  180852. PIP_ADAPTER_INFO adapter = adapterInfo;
  180853. while (adapter != 0)
  180854. {
  180855. int64 mac = 0;
  180856. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180857. mac = (mac << 8) | adapter->Address[i];
  180858. if (littleEndian)
  180859. mac = (int64) ByteOrder::swap ((uint64) mac);
  180860. if (numFound < maxNum && mac != 0)
  180861. addresses [numFound++] = mac;
  180862. adapter = adapter->Next;
  180863. }
  180864. }
  180865. }
  180866. return numFound;
  180867. }
  180868. struct ASTAT
  180869. {
  180870. ADAPTER_STATUS adapt;
  180871. NAME_BUFFER NameBuff [30];
  180872. };
  180873. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180874. {
  180875. int numFound = 0;
  180876. DynamicLibraryLoader dll ("netapi32.dll");
  180877. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180878. if (NetbiosCall != 0)
  180879. {
  180880. NCB ncb;
  180881. zerostruct (ncb);
  180882. ASTAT astat;
  180883. zerostruct (astat);
  180884. LANA_ENUM enums;
  180885. zerostruct (enums);
  180886. ncb.ncb_command = NCBENUM;
  180887. ncb.ncb_buffer = (unsigned char*) &enums;
  180888. ncb.ncb_length = sizeof (LANA_ENUM);
  180889. NetbiosCall (&ncb);
  180890. for (int i = 0; i < enums.length; ++i)
  180891. {
  180892. zerostruct (ncb);
  180893. ncb.ncb_command = NCBRESET;
  180894. ncb.ncb_lana_num = enums.lana[i];
  180895. if (NetbiosCall (&ncb) == 0)
  180896. {
  180897. zerostruct (ncb);
  180898. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180899. ncb.ncb_command = NCBASTAT;
  180900. ncb.ncb_lana_num = enums.lana[i];
  180901. ncb.ncb_buffer = (unsigned char*) &astat;
  180902. ncb.ncb_length = sizeof (ASTAT);
  180903. if (NetbiosCall (&ncb) == 0)
  180904. {
  180905. if (astat.adapt.adapter_type == 0xfe)
  180906. {
  180907. uint64 mac = 0;
  180908. for (int i = 6; --i >= 0;)
  180909. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180910. if (numFound < maxNum && mac != 0)
  180911. addresses [numFound++] = mac;
  180912. }
  180913. }
  180914. }
  180915. }
  180916. }
  180917. return numFound;
  180918. }
  180919. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  180920. {
  180921. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180922. if (numFound == 0)
  180923. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180924. return numFound;
  180925. }
  180926. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180927. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180928. const String& emailSubject,
  180929. const String& bodyText,
  180930. const StringArray& filesToAttach)
  180931. {
  180932. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180933. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180934. bool ok = false;
  180935. if (mapiSendMail != 0)
  180936. {
  180937. MapiMessage message;
  180938. zerostruct (message);
  180939. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180940. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180941. MapiRecipDesc recip;
  180942. zerostruct (recip);
  180943. recip.ulRecipClass = MAPI_TO;
  180944. String targetEmailAddress_ (targetEmailAddress);
  180945. if (targetEmailAddress_.isEmpty())
  180946. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  180947. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  180948. message.nRecipCount = 1;
  180949. message.lpRecips = &recip;
  180950. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  180951. mb.fillWith (0);
  180952. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  180953. message.nFileCount = filesToAttach.size();
  180954. message.lpFiles = files;
  180955. for (int i = 0; i < filesToAttach.size(); ++i)
  180956. {
  180957. files[i].nPosition = (ULONG) -1;
  180958. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  180959. }
  180960. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  180961. }
  180962. FreeLibrary (h);
  180963. return ok;
  180964. }
  180965. #endif
  180966. /*** End of inlined file: juce_win32_Network.cpp ***/
  180967. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  180968. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180969. // compiled on its own).
  180970. #if JUCE_INCLUDED_FILE
  180971. static HKEY findKeyForPath (String name,
  180972. const bool createForWriting,
  180973. String& valueName)
  180974. {
  180975. HKEY rootKey = 0;
  180976. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  180977. rootKey = HKEY_CURRENT_USER;
  180978. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  180979. rootKey = HKEY_LOCAL_MACHINE;
  180980. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  180981. rootKey = HKEY_CLASSES_ROOT;
  180982. if (rootKey != 0)
  180983. {
  180984. name = name.substring (name.indexOfChar (T('\\')) + 1);
  180985. const int lastSlash = name.lastIndexOfChar (T('\\'));
  180986. valueName = name.substring (lastSlash + 1);
  180987. name = name.substring (0, lastSlash);
  180988. HKEY key;
  180989. DWORD result;
  180990. if (createForWriting)
  180991. {
  180992. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  180993. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  180994. return key;
  180995. }
  180996. else
  180997. {
  180998. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  180999. return key;
  181000. }
  181001. }
  181002. return 0;
  181003. }
  181004. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  181005. const String& defaultValue)
  181006. {
  181007. String valueName, result (defaultValue);
  181008. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181009. if (k != 0)
  181010. {
  181011. WCHAR buffer [2048];
  181012. unsigned long bufferSize = sizeof (buffer);
  181013. DWORD type = REG_SZ;
  181014. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  181015. {
  181016. if (type == REG_SZ)
  181017. result = buffer;
  181018. else if (type == REG_DWORD)
  181019. result = String ((int) *(DWORD*) buffer);
  181020. }
  181021. RegCloseKey (k);
  181022. }
  181023. return result;
  181024. }
  181025. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  181026. const String& value)
  181027. {
  181028. String valueName;
  181029. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181030. if (k != 0)
  181031. {
  181032. RegSetValueEx (k, valueName, 0, REG_SZ,
  181033. (const BYTE*) (const WCHAR*) value,
  181034. sizeof (WCHAR) * (value.length() + 1));
  181035. RegCloseKey (k);
  181036. }
  181037. }
  181038. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181039. {
  181040. bool exists = false;
  181041. String valueName;
  181042. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181043. if (k != 0)
  181044. {
  181045. unsigned char buffer [2048];
  181046. unsigned long bufferSize = sizeof (buffer);
  181047. DWORD type = 0;
  181048. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181049. exists = true;
  181050. RegCloseKey (k);
  181051. }
  181052. return exists;
  181053. }
  181054. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181055. {
  181056. String valueName;
  181057. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181058. if (k != 0)
  181059. {
  181060. RegDeleteValue (k, valueName);
  181061. RegCloseKey (k);
  181062. }
  181063. }
  181064. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181065. {
  181066. String valueName;
  181067. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181068. if (k != 0)
  181069. {
  181070. RegDeleteKey (k, valueName);
  181071. RegCloseKey (k);
  181072. }
  181073. }
  181074. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181075. const String& symbolicDescription,
  181076. const String& fullDescription,
  181077. const File& targetExecutable,
  181078. int iconResourceNumber)
  181079. {
  181080. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181081. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181082. if (iconResourceNumber != 0)
  181083. setRegistryValue (key + "\\DefaultIcon\\",
  181084. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181085. setRegistryValue (key + "\\", fullDescription);
  181086. setRegistryValue (key + "\\shell\\open\\command\\",
  181087. targetExecutable.getFullPathName() + " %1");
  181088. }
  181089. bool juce_IsRunningInWine()
  181090. {
  181091. HKEY key;
  181092. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181093. {
  181094. RegCloseKey (key);
  181095. return true;
  181096. }
  181097. return false;
  181098. }
  181099. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181100. {
  181101. String s (::GetCommandLineW());
  181102. StringArray tokens;
  181103. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181104. return tokens.joinIntoString (T(" "), 1);
  181105. }
  181106. static void* currentModuleHandle = 0;
  181107. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181108. {
  181109. if (currentModuleHandle == 0)
  181110. currentModuleHandle = GetModuleHandle (0);
  181111. return currentModuleHandle;
  181112. }
  181113. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181114. {
  181115. currentModuleHandle = newHandle;
  181116. }
  181117. void PlatformUtilities::fpuReset()
  181118. {
  181119. #if JUCE_MSVC
  181120. _clearfp();
  181121. #endif
  181122. }
  181123. void PlatformUtilities::beep()
  181124. {
  181125. MessageBeep (MB_OK);
  181126. }
  181127. #endif
  181128. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181129. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181130. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181131. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181132. // compiled on its own).
  181133. #if JUCE_INCLUDED_FILE
  181134. static const unsigned int specialId = WM_APP + 0x4400;
  181135. static const unsigned int broadcastId = WM_APP + 0x4403;
  181136. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181137. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181138. HWND juce_messageWindowHandle = 0;
  181139. extern long improbableWindowNumber; // defined in windowing.cpp
  181140. #ifndef WM_APPCOMMAND
  181141. #define WM_APPCOMMAND 0x0319
  181142. #endif
  181143. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181144. const UINT message,
  181145. const WPARAM wParam,
  181146. const LPARAM lParam) throw()
  181147. {
  181148. JUCE_TRY
  181149. {
  181150. if (h == juce_messageWindowHandle)
  181151. {
  181152. if (message == specialCallbackId)
  181153. {
  181154. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181155. return (LRESULT) (*func) ((void*) lParam);
  181156. }
  181157. else if (message == specialId)
  181158. {
  181159. // these are trapped early in the dispatch call, but must also be checked
  181160. // here in case there are windows modal dialog boxes doing their own
  181161. // dispatch loop and not calling our version
  181162. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181163. return 0;
  181164. }
  181165. else if (message == broadcastId)
  181166. {
  181167. const ScopedPointer <String> messageString ((String*) lParam);
  181168. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181169. return 0;
  181170. }
  181171. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181172. {
  181173. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181174. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181175. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181176. return 0;
  181177. }
  181178. }
  181179. }
  181180. JUCE_CATCH_EXCEPTION
  181181. return DefWindowProc (h, message, wParam, lParam);
  181182. }
  181183. static bool isEventBlockedByModalComps (MSG& m)
  181184. {
  181185. if (Component::getNumCurrentlyModalComponents() == 0
  181186. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181187. return false;
  181188. switch (m.message)
  181189. {
  181190. case WM_MOUSEMOVE:
  181191. case WM_NCMOUSEMOVE:
  181192. case 0x020A: /* WM_MOUSEWHEEL */
  181193. case 0x020E: /* WM_MOUSEHWHEEL */
  181194. case WM_KEYUP:
  181195. case WM_SYSKEYUP:
  181196. case WM_CHAR:
  181197. case WM_APPCOMMAND:
  181198. case WM_LBUTTONUP:
  181199. case WM_MBUTTONUP:
  181200. case WM_RBUTTONUP:
  181201. case WM_MOUSEACTIVATE:
  181202. case WM_NCMOUSEHOVER:
  181203. case WM_MOUSEHOVER:
  181204. return true;
  181205. case WM_NCLBUTTONDOWN:
  181206. case WM_NCLBUTTONDBLCLK:
  181207. case WM_NCRBUTTONDOWN:
  181208. case WM_NCRBUTTONDBLCLK:
  181209. case WM_NCMBUTTONDOWN:
  181210. case WM_NCMBUTTONDBLCLK:
  181211. case WM_LBUTTONDOWN:
  181212. case WM_LBUTTONDBLCLK:
  181213. case WM_MBUTTONDOWN:
  181214. case WM_MBUTTONDBLCLK:
  181215. case WM_RBUTTONDOWN:
  181216. case WM_RBUTTONDBLCLK:
  181217. case WM_KEYDOWN:
  181218. case WM_SYSKEYDOWN:
  181219. {
  181220. Component* const modal = Component::getCurrentlyModalComponent (0);
  181221. if (modal != 0)
  181222. modal->inputAttemptWhenModal();
  181223. return true;
  181224. }
  181225. default:
  181226. break;
  181227. }
  181228. return false;
  181229. }
  181230. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181231. {
  181232. MSG m;
  181233. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181234. return false;
  181235. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181236. {
  181237. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181238. {
  181239. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181240. }
  181241. else if (m.message == WM_QUIT)
  181242. {
  181243. if (JUCEApplication::getInstance())
  181244. JUCEApplication::getInstance()->systemRequestedQuit();
  181245. }
  181246. else if (! isEventBlockedByModalComps (m))
  181247. {
  181248. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181249. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181250. {
  181251. // if it's someone else's window being clicked on, and the focus is
  181252. // currently on a juce window, pass the kb focus over..
  181253. HWND currentFocus = GetFocus();
  181254. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181255. SetFocus (m.hwnd);
  181256. }
  181257. TranslateMessage (&m);
  181258. DispatchMessage (&m);
  181259. }
  181260. }
  181261. return true;
  181262. }
  181263. bool juce_postMessageToSystemQueue (void* message)
  181264. {
  181265. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181266. }
  181267. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181268. void* userData)
  181269. {
  181270. if (MessageManager::getInstance()->isThisTheMessageThread())
  181271. {
  181272. return (*callback) (userData);
  181273. }
  181274. else
  181275. {
  181276. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181277. // deadlock because the message manager is blocked from running, and can't
  181278. // call your function..
  181279. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181280. return (void*) SendMessage (juce_messageWindowHandle,
  181281. specialCallbackId,
  181282. (WPARAM) callback,
  181283. (LPARAM) userData);
  181284. }
  181285. }
  181286. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181287. {
  181288. if (hwnd != juce_messageWindowHandle)
  181289. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181290. return TRUE;
  181291. }
  181292. void MessageManager::broadcastMessage (const String& value) throw()
  181293. {
  181294. VoidArray windows;
  181295. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181296. const String localCopy (value);
  181297. COPYDATASTRUCT data;
  181298. data.dwData = broadcastId;
  181299. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181300. data.lpData = (void*) (const juce_wchar*) localCopy;
  181301. for (int i = windows.size(); --i >= 0;)
  181302. {
  181303. HWND hwnd = (HWND) windows.getUnchecked(i);
  181304. TCHAR windowName [64]; // no need to read longer strings than this
  181305. GetWindowText (hwnd, windowName, 64);
  181306. windowName [63] = 0;
  181307. if (String (windowName) == String (messageWindowName))
  181308. {
  181309. DWORD_PTR result;
  181310. SendMessageTimeout (hwnd, WM_COPYDATA,
  181311. (WPARAM) juce_messageWindowHandle,
  181312. (LPARAM) &data,
  181313. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181314. 8000,
  181315. &result);
  181316. }
  181317. }
  181318. }
  181319. static const String getMessageWindowClassName()
  181320. {
  181321. // this name has to be different for each app/dll instance because otherwise
  181322. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181323. // window class).
  181324. static int number = 0;
  181325. if (number == 0)
  181326. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181327. return T("JUCEcs_") + String (number);
  181328. }
  181329. void MessageManager::doPlatformSpecificInitialisation()
  181330. {
  181331. OleInitialize (0);
  181332. const String className (getMessageWindowClassName());
  181333. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181334. WNDCLASSEX wc;
  181335. zerostruct (wc);
  181336. wc.cbSize = sizeof (wc);
  181337. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181338. wc.cbWndExtra = 4;
  181339. wc.hInstance = hmod;
  181340. wc.lpszClassName = className;
  181341. RegisterClassEx (&wc);
  181342. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181343. messageWindowName,
  181344. 0, 0, 0, 0, 0, 0, 0,
  181345. hmod, 0);
  181346. }
  181347. void MessageManager::doPlatformSpecificShutdown()
  181348. {
  181349. DestroyWindow (juce_messageWindowHandle);
  181350. UnregisterClass (getMessageWindowClassName(), 0);
  181351. OleUninitialize();
  181352. }
  181353. #endif
  181354. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181355. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181356. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181357. // compiled on its own).
  181358. #if JUCE_INCLUDED_FILE
  181359. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181360. // these are in the windows SDK, but need to be repeated here for GCC..
  181361. #ifndef GET_APPCOMMAND_LPARAM
  181362. #define FAPPCOMMAND_MASK 0xF000
  181363. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181364. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181365. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181366. #define APPCOMMAND_MEDIA_STOP 13
  181367. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181368. #define WM_APPCOMMAND 0x0319
  181369. #endif
  181370. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181371. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181372. extern bool juce_IsRunningInWine();
  181373. #ifndef ULW_ALPHA
  181374. #define ULW_ALPHA 0x00000002
  181375. #endif
  181376. #ifndef AC_SRC_ALPHA
  181377. #define AC_SRC_ALPHA 0x01
  181378. #endif
  181379. static HPALETTE palette = 0;
  181380. static bool createPaletteIfNeeded = true;
  181381. static bool shouldDeactivateTitleBar = true;
  181382. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181383. #define WM_TRAYNOTIFY WM_USER + 100
  181384. using ::abs;
  181385. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181386. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181387. bool Desktop::canUseSemiTransparentWindows() throw()
  181388. {
  181389. if (updateLayeredWindow == 0)
  181390. {
  181391. if (! juce_IsRunningInWine())
  181392. {
  181393. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181394. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181395. }
  181396. }
  181397. return updateLayeredWindow != 0;
  181398. }
  181399. const int extendedKeyModifier = 0x10000;
  181400. const int KeyPress::spaceKey = VK_SPACE;
  181401. const int KeyPress::returnKey = VK_RETURN;
  181402. const int KeyPress::escapeKey = VK_ESCAPE;
  181403. const int KeyPress::backspaceKey = VK_BACK;
  181404. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181405. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181406. const int KeyPress::tabKey = VK_TAB;
  181407. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181408. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181409. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181410. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181411. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181412. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181413. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181414. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181415. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181416. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181417. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181418. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181419. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181420. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181421. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181422. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181423. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181424. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181425. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181426. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181427. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181428. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181429. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181430. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181431. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181432. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181433. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181434. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181435. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181436. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181437. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181438. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181439. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181440. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181441. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181442. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181443. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181444. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181445. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181446. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181447. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181448. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181449. const int KeyPress::playKey = 0x30000;
  181450. const int KeyPress::stopKey = 0x30001;
  181451. const int KeyPress::fastForwardKey = 0x30002;
  181452. const int KeyPress::rewindKey = 0x30003;
  181453. class WindowsBitmapImage : public Image
  181454. {
  181455. public:
  181456. HBITMAP hBitmap;
  181457. BITMAPV4HEADER bitmapInfo;
  181458. HDC hdc;
  181459. unsigned char* bitmapData;
  181460. WindowsBitmapImage (const PixelFormat format_,
  181461. const int w, const int h, const bool clearImage)
  181462. : Image (format_, w, h)
  181463. {
  181464. jassert (format_ == RGB || format_ == ARGB);
  181465. pixelStride = (format_ == RGB) ? 3 : 4;
  181466. zerostruct (bitmapInfo);
  181467. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181468. bitmapInfo.bV4Width = w;
  181469. bitmapInfo.bV4Height = h;
  181470. bitmapInfo.bV4Planes = 1;
  181471. bitmapInfo.bV4CSType = 1;
  181472. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181473. if (format_ == ARGB)
  181474. {
  181475. bitmapInfo.bV4AlphaMask = 0xff000000;
  181476. bitmapInfo.bV4RedMask = 0xff0000;
  181477. bitmapInfo.bV4GreenMask = 0xff00;
  181478. bitmapInfo.bV4BlueMask = 0xff;
  181479. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181480. }
  181481. else
  181482. {
  181483. bitmapInfo.bV4V4Compression = BI_RGB;
  181484. }
  181485. lineStride = -((w * pixelStride + 3) & ~3);
  181486. HDC dc = GetDC (0);
  181487. hdc = CreateCompatibleDC (dc);
  181488. ReleaseDC (0, dc);
  181489. SetMapMode (hdc, MM_TEXT);
  181490. hBitmap = CreateDIBSection (hdc,
  181491. (BITMAPINFO*) &(bitmapInfo),
  181492. DIB_RGB_COLORS,
  181493. (void**) &bitmapData,
  181494. 0, 0);
  181495. SelectObject (hdc, hBitmap);
  181496. if (format_ == ARGB && clearImage)
  181497. zeromem (bitmapData, abs (h * lineStride));
  181498. imageData = bitmapData - (lineStride * (h - 1));
  181499. }
  181500. ~WindowsBitmapImage()
  181501. {
  181502. DeleteDC (hdc);
  181503. DeleteObject (hBitmap);
  181504. }
  181505. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181506. const int x, const int y,
  181507. const RectangleList& maskedRegion) throw()
  181508. {
  181509. static HDRAWDIB hdd = 0;
  181510. static bool needToCreateDrawDib = true;
  181511. if (needToCreateDrawDib)
  181512. {
  181513. needToCreateDrawDib = false;
  181514. HDC dc = GetDC (0);
  181515. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181516. ReleaseDC (0, dc);
  181517. // only open if we're not palettised
  181518. if (n > 8)
  181519. hdd = DrawDibOpen();
  181520. }
  181521. if (createPaletteIfNeeded)
  181522. {
  181523. HDC dc = GetDC (0);
  181524. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181525. ReleaseDC (0, dc);
  181526. if (n <= 8)
  181527. palette = CreateHalftonePalette (dc);
  181528. createPaletteIfNeeded = false;
  181529. }
  181530. if (palette != 0)
  181531. {
  181532. SelectPalette (dc, palette, FALSE);
  181533. RealizePalette (dc);
  181534. SetStretchBltMode (dc, HALFTONE);
  181535. }
  181536. SetMapMode (dc, MM_TEXT);
  181537. if (transparent)
  181538. {
  181539. POINT p, pos;
  181540. SIZE size;
  181541. RECT windowBounds;
  181542. GetWindowRect (hwnd, &windowBounds);
  181543. p.x = -x;
  181544. p.y = -y;
  181545. pos.x = windowBounds.left;
  181546. pos.y = windowBounds.top;
  181547. size.cx = windowBounds.right - windowBounds.left;
  181548. size.cy = windowBounds.bottom - windowBounds.top;
  181549. BLENDFUNCTION bf;
  181550. bf.AlphaFormat = AC_SRC_ALPHA;
  181551. bf.BlendFlags = 0;
  181552. bf.BlendOp = AC_SRC_OVER;
  181553. bf.SourceConstantAlpha = 0xff;
  181554. if (! maskedRegion.isEmpty())
  181555. {
  181556. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181557. {
  181558. const Rectangle<int>& r = *i.getRectangle();
  181559. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181560. }
  181561. }
  181562. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181563. }
  181564. else
  181565. {
  181566. int savedDC = 0;
  181567. if (! maskedRegion.isEmpty())
  181568. {
  181569. savedDC = SaveDC (dc);
  181570. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181571. {
  181572. const Rectangle<int>& r = *i.getRectangle();
  181573. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181574. }
  181575. }
  181576. const int w = getWidth();
  181577. const int h = getHeight();
  181578. if (hdd == 0)
  181579. {
  181580. StretchDIBits (dc,
  181581. x, y, w, h,
  181582. 0, 0, w, h,
  181583. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181584. DIB_RGB_COLORS, SRCCOPY);
  181585. }
  181586. else
  181587. {
  181588. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181589. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181590. 0, 0, w, h, 0);
  181591. }
  181592. if (! maskedRegion.isEmpty())
  181593. RestoreDC (dc, savedDC);
  181594. }
  181595. }
  181596. juce_UseDebuggingNewOperator
  181597. private:
  181598. WindowsBitmapImage (const WindowsBitmapImage&);
  181599. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181600. };
  181601. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181602. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  181603. {
  181604. SHORT k = (SHORT) keyCode;
  181605. if ((keyCode & extendedKeyModifier) == 0
  181606. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  181607. k += (SHORT) T('A') - (SHORT) T('a');
  181608. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181609. (SHORT) '+', VK_OEM_PLUS,
  181610. (SHORT) '-', VK_OEM_MINUS,
  181611. (SHORT) '.', VK_OEM_PERIOD,
  181612. (SHORT) ';', VK_OEM_1,
  181613. (SHORT) ':', VK_OEM_1,
  181614. (SHORT) '/', VK_OEM_2,
  181615. (SHORT) '?', VK_OEM_2,
  181616. (SHORT) '[', VK_OEM_4,
  181617. (SHORT) ']', VK_OEM_6 };
  181618. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181619. if (k == translatedValues [i])
  181620. k = translatedValues [i + 1];
  181621. return (GetKeyState (k) & 0x8000) != 0;
  181622. }
  181623. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181624. {
  181625. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181626. return callback (userData);
  181627. else
  181628. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181629. }
  181630. class Win32ComponentPeer : public ComponentPeer
  181631. {
  181632. public:
  181633. Win32ComponentPeer (Component* const component,
  181634. const int windowStyleFlags)
  181635. : ComponentPeer (component, windowStyleFlags),
  181636. dontRepaint (false),
  181637. fullScreen (false),
  181638. isDragging (false),
  181639. isMouseOver (false),
  181640. hasCreatedCaret (false),
  181641. currentWindowIcon (0),
  181642. taskBarIcon (0),
  181643. dropTarget (0)
  181644. {
  181645. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  181646. setTitle (component->getName());
  181647. if ((windowStyleFlags & windowHasDropShadow) != 0
  181648. && Desktop::canUseSemiTransparentWindows())
  181649. {
  181650. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181651. if (shadower != 0)
  181652. shadower->setOwner (component);
  181653. }
  181654. else
  181655. {
  181656. shadower = 0;
  181657. }
  181658. }
  181659. ~Win32ComponentPeer()
  181660. {
  181661. setTaskBarIcon (0);
  181662. deleteAndZero (shadower);
  181663. // do this before the next bit to avoid messages arriving for this window
  181664. // before it's destroyed
  181665. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181666. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181667. if (currentWindowIcon != 0)
  181668. DestroyIcon (currentWindowIcon);
  181669. if (dropTarget != 0)
  181670. {
  181671. dropTarget->Release();
  181672. dropTarget = 0;
  181673. }
  181674. }
  181675. void* getNativeHandle() const
  181676. {
  181677. return (void*) hwnd;
  181678. }
  181679. void setVisible (bool shouldBeVisible)
  181680. {
  181681. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181682. if (shouldBeVisible)
  181683. InvalidateRect (hwnd, 0, 0);
  181684. else
  181685. lastPaintTime = 0;
  181686. }
  181687. void setTitle (const String& title)
  181688. {
  181689. SetWindowText (hwnd, title);
  181690. }
  181691. void setPosition (int x, int y)
  181692. {
  181693. offsetWithinParent (x, y);
  181694. SetWindowPos (hwnd, 0,
  181695. x - windowBorder.getLeft(),
  181696. y - windowBorder.getTop(),
  181697. 0, 0,
  181698. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181699. }
  181700. void repaintNowIfTransparent()
  181701. {
  181702. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181703. handlePaintMessage();
  181704. }
  181705. void updateBorderSize()
  181706. {
  181707. WINDOWINFO info;
  181708. info.cbSize = sizeof (info);
  181709. if (GetWindowInfo (hwnd, &info))
  181710. {
  181711. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181712. info.rcClient.left - info.rcWindow.left,
  181713. info.rcWindow.bottom - info.rcClient.bottom,
  181714. info.rcWindow.right - info.rcClient.right);
  181715. }
  181716. }
  181717. void setSize (int w, int h)
  181718. {
  181719. SetWindowPos (hwnd, 0, 0, 0,
  181720. w + windowBorder.getLeftAndRight(),
  181721. h + windowBorder.getTopAndBottom(),
  181722. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181723. updateBorderSize();
  181724. repaintNowIfTransparent();
  181725. }
  181726. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  181727. {
  181728. fullScreen = isNowFullScreen;
  181729. offsetWithinParent (x, y);
  181730. SetWindowPos (hwnd, 0,
  181731. x - windowBorder.getLeft(),
  181732. y - windowBorder.getTop(),
  181733. w + windowBorder.getLeftAndRight(),
  181734. h + windowBorder.getTopAndBottom(),
  181735. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181736. updateBorderSize();
  181737. repaintNowIfTransparent();
  181738. }
  181739. const Rectangle<int> getBounds() const
  181740. {
  181741. RECT r;
  181742. GetWindowRect (hwnd, &r);
  181743. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181744. HWND parentH = GetParent (hwnd);
  181745. if (parentH != 0)
  181746. {
  181747. GetWindowRect (parentH, &r);
  181748. bounds.translate (-r.left, -r.top);
  181749. }
  181750. return windowBorder.subtractedFrom (bounds);
  181751. }
  181752. const Point<int> getScreenPosition() const
  181753. {
  181754. RECT r;
  181755. GetWindowRect (hwnd, &r);
  181756. return Point<int> (r.left + windowBorder.getLeft(),
  181757. r.top + windowBorder.getTop());
  181758. }
  181759. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181760. {
  181761. return relativePosition + getScreenPosition();
  181762. }
  181763. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181764. {
  181765. return screenPosition - getScreenPosition();
  181766. }
  181767. void setMinimised (bool shouldBeMinimised)
  181768. {
  181769. if (shouldBeMinimised != isMinimised())
  181770. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181771. }
  181772. bool isMinimised() const
  181773. {
  181774. WINDOWPLACEMENT wp;
  181775. wp.length = sizeof (WINDOWPLACEMENT);
  181776. GetWindowPlacement (hwnd, &wp);
  181777. return wp.showCmd == SW_SHOWMINIMIZED;
  181778. }
  181779. void setFullScreen (bool shouldBeFullScreen)
  181780. {
  181781. setMinimised (false);
  181782. if (fullScreen != shouldBeFullScreen)
  181783. {
  181784. fullScreen = shouldBeFullScreen;
  181785. const Component::SafePointer<Component> deletionChecker (component);
  181786. if (! fullScreen)
  181787. {
  181788. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181789. if (hasTitleBar())
  181790. ShowWindow (hwnd, SW_SHOWNORMAL);
  181791. if (! boundsCopy.isEmpty())
  181792. {
  181793. setBounds (boundsCopy.getX(),
  181794. boundsCopy.getY(),
  181795. boundsCopy.getWidth(),
  181796. boundsCopy.getHeight(),
  181797. false);
  181798. }
  181799. }
  181800. else
  181801. {
  181802. if (hasTitleBar())
  181803. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181804. else
  181805. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181806. }
  181807. if (deletionChecker != 0)
  181808. handleMovedOrResized();
  181809. }
  181810. }
  181811. bool isFullScreen() const
  181812. {
  181813. if (! hasTitleBar())
  181814. return fullScreen;
  181815. WINDOWPLACEMENT wp;
  181816. wp.length = sizeof (wp);
  181817. GetWindowPlacement (hwnd, &wp);
  181818. return wp.showCmd == SW_SHOWMAXIMIZED;
  181819. }
  181820. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181821. {
  181822. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181823. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181824. return false;
  181825. RECT r;
  181826. GetWindowRect (hwnd, &r);
  181827. POINT p;
  181828. p.x = position.getX() + r.left + windowBorder.getLeft();
  181829. p.y = position.getY() + r.top + windowBorder.getTop();
  181830. HWND w = WindowFromPoint (p);
  181831. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181832. }
  181833. const BorderSize getFrameSize() const
  181834. {
  181835. return windowBorder;
  181836. }
  181837. bool setAlwaysOnTop (bool alwaysOnTop)
  181838. {
  181839. const bool oldDeactivate = shouldDeactivateTitleBar;
  181840. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181841. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181842. 0, 0, 0, 0,
  181843. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181844. shouldDeactivateTitleBar = oldDeactivate;
  181845. if (shadower != 0)
  181846. shadower->componentBroughtToFront (*component);
  181847. return true;
  181848. }
  181849. void toFront (bool makeActive)
  181850. {
  181851. setMinimised (false);
  181852. const bool oldDeactivate = shouldDeactivateTitleBar;
  181853. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181854. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  181855. : &toFrontCallback2,
  181856. (void*) hwnd);
  181857. shouldDeactivateTitleBar = oldDeactivate;
  181858. if (! makeActive)
  181859. {
  181860. // in this case a broughttofront call won't have occured, so do it now..
  181861. handleBroughtToFront();
  181862. }
  181863. }
  181864. void toBehind (ComponentPeer* other)
  181865. {
  181866. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181867. jassert (otherPeer != 0); // wrong type of window?
  181868. if (otherPeer != 0)
  181869. {
  181870. setMinimised (false);
  181871. // must be careful not to try to put a topmost window behind a normal one, or win32
  181872. // promotes the normal one to be topmost!
  181873. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181874. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181875. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181876. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181877. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181878. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181879. }
  181880. }
  181881. bool isFocused() const
  181882. {
  181883. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181884. }
  181885. void grabFocus()
  181886. {
  181887. const bool oldDeactivate = shouldDeactivateTitleBar;
  181888. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181889. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  181890. shouldDeactivateTitleBar = oldDeactivate;
  181891. }
  181892. void textInputRequired (const Point<int>&)
  181893. {
  181894. if (! hasCreatedCaret)
  181895. {
  181896. hasCreatedCaret = true;
  181897. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181898. }
  181899. ShowCaret (hwnd);
  181900. SetCaretPos (0, 0);
  181901. }
  181902. void repaint (int x, int y, int w, int h)
  181903. {
  181904. const RECT r = { x, y, x + w, y + h };
  181905. InvalidateRect (hwnd, &r, FALSE);
  181906. }
  181907. void performAnyPendingRepaintsNow()
  181908. {
  181909. MSG m;
  181910. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181911. DispatchMessage (&m);
  181912. }
  181913. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181914. {
  181915. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181916. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181917. return 0;
  181918. }
  181919. void setTaskBarIcon (const Image* const image)
  181920. {
  181921. if (image != 0)
  181922. {
  181923. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181924. if (taskBarIcon == 0)
  181925. {
  181926. taskBarIcon = new NOTIFYICONDATA();
  181927. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181928. taskBarIcon->hWnd = (HWND) hwnd;
  181929. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181930. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181931. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181932. taskBarIcon->hIcon = hicon;
  181933. taskBarIcon->szTip[0] = 0;
  181934. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181935. }
  181936. else
  181937. {
  181938. HICON oldIcon = taskBarIcon->hIcon;
  181939. taskBarIcon->hIcon = hicon;
  181940. taskBarIcon->uFlags = NIF_ICON;
  181941. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181942. DestroyIcon (oldIcon);
  181943. }
  181944. DestroyIcon (hicon);
  181945. }
  181946. else if (taskBarIcon != 0)
  181947. {
  181948. taskBarIcon->uFlags = 0;
  181949. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  181950. DestroyIcon (taskBarIcon->hIcon);
  181951. deleteAndZero (taskBarIcon);
  181952. }
  181953. }
  181954. void setTaskBarIconToolTip (const String& toolTip) const
  181955. {
  181956. if (taskBarIcon != 0)
  181957. {
  181958. taskBarIcon->uFlags = NIF_TIP;
  181959. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  181960. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181961. }
  181962. }
  181963. bool isInside (HWND h) const
  181964. {
  181965. return GetAncestor (hwnd, GA_ROOT) == h;
  181966. }
  181967. static void updateKeyModifiers() throw()
  181968. {
  181969. int keyMods = 0;
  181970. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  181971. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  181972. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  181973. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181974. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  181975. }
  181976. static void updateModifiersFromWParam (const WPARAM wParam)
  181977. {
  181978. int mouseMods = 0;
  181979. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  181980. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  181981. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  181982. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  181983. updateKeyModifiers();
  181984. }
  181985. static int64 getMouseEventTime()
  181986. {
  181987. static int64 eventTimeOffset = 0;
  181988. static DWORD lastMessageTime = 0;
  181989. const DWORD thisMessageTime = GetMessageTime();
  181990. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181991. {
  181992. lastMessageTime = thisMessageTime;
  181993. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181994. }
  181995. return eventTimeOffset + thisMessageTime;
  181996. }
  181997. juce_UseDebuggingNewOperator
  181998. bool dontRepaint;
  181999. static ModifierKeys currentModifiers;
  182000. static ModifierKeys modifiersAtLastCallback;
  182001. private:
  182002. HWND hwnd;
  182003. DropShadower* shadower;
  182004. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  182005. BorderSize windowBorder;
  182006. HICON currentWindowIcon;
  182007. NOTIFYICONDATA* taskBarIcon;
  182008. IDropTarget* dropTarget;
  182009. class TemporaryImage : public Timer
  182010. {
  182011. public:
  182012. TemporaryImage()
  182013. : image (0)
  182014. {
  182015. }
  182016. ~TemporaryImage()
  182017. {
  182018. delete image;
  182019. }
  182020. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  182021. {
  182022. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  182023. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  182024. {
  182025. delete image;
  182026. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  182027. }
  182028. startTimer (3000);
  182029. return image;
  182030. }
  182031. void timerCallback()
  182032. {
  182033. stopTimer();
  182034. deleteAndZero (image);
  182035. }
  182036. private:
  182037. WindowsBitmapImage* image;
  182038. TemporaryImage (const TemporaryImage&);
  182039. TemporaryImage& operator= (const TemporaryImage&);
  182040. };
  182041. TemporaryImage offscreenImageGenerator;
  182042. class WindowClassHolder : public DeletedAtShutdown
  182043. {
  182044. public:
  182045. WindowClassHolder()
  182046. : windowClassName ("JUCE_")
  182047. {
  182048. // this name has to be different for each app/dll instance because otherwise
  182049. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182050. // window class).
  182051. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182052. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182053. TCHAR moduleFile [1024];
  182054. moduleFile[0] = 0;
  182055. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182056. WORD iconNum = 0;
  182057. WNDCLASSEX wcex;
  182058. wcex.cbSize = sizeof (wcex);
  182059. wcex.style = CS_OWNDC;
  182060. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182061. wcex.lpszClassName = windowClassName;
  182062. wcex.cbClsExtra = 0;
  182063. wcex.cbWndExtra = 32;
  182064. wcex.hInstance = moduleHandle;
  182065. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182066. iconNum = 1;
  182067. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182068. wcex.hCursor = 0;
  182069. wcex.hbrBackground = 0;
  182070. wcex.lpszMenuName = 0;
  182071. RegisterClassEx (&wcex);
  182072. }
  182073. ~WindowClassHolder()
  182074. {
  182075. if (ComponentPeer::getNumPeers() == 0)
  182076. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182077. clearSingletonInstance();
  182078. }
  182079. String windowClassName;
  182080. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182081. };
  182082. static void* createWindowCallback (void* userData)
  182083. {
  182084. ((Win32ComponentPeer*) userData)->createWindow();
  182085. return 0;
  182086. }
  182087. void createWindow()
  182088. {
  182089. DWORD exstyle = WS_EX_ACCEPTFILES;
  182090. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182091. if (hasTitleBar())
  182092. {
  182093. type |= WS_OVERLAPPED;
  182094. exstyle |= WS_EX_APPWINDOW;
  182095. if ((styleFlags & windowHasCloseButton) != 0)
  182096. {
  182097. type |= WS_SYSMENU;
  182098. }
  182099. else
  182100. {
  182101. // annoyingly, windows won't let you have a min/max button without a close button
  182102. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182103. }
  182104. if ((styleFlags & windowIsResizable) != 0)
  182105. type |= WS_THICKFRAME;
  182106. }
  182107. else
  182108. {
  182109. type |= WS_POPUP | WS_SYSMENU;
  182110. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182111. exstyle |= WS_EX_TOOLWINDOW;
  182112. else
  182113. exstyle |= WS_EX_APPWINDOW;
  182114. }
  182115. if ((styleFlags & windowHasMinimiseButton) != 0)
  182116. type |= WS_MINIMIZEBOX;
  182117. if ((styleFlags & windowHasMaximiseButton) != 0)
  182118. type |= WS_MAXIMIZEBOX;
  182119. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182120. exstyle |= WS_EX_TRANSPARENT;
  182121. if ((styleFlags & windowIsSemiTransparent) != 0
  182122. && Desktop::canUseSemiTransparentWindows())
  182123. exstyle |= WS_EX_LAYERED;
  182124. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182125. if (hwnd != 0)
  182126. {
  182127. SetWindowLongPtr (hwnd, 0, 0);
  182128. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182129. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182130. if (dropTarget == 0)
  182131. dropTarget = new JuceDropTarget (this);
  182132. RegisterDragDrop (hwnd, dropTarget);
  182133. updateBorderSize();
  182134. // Calling this function here is (for some reason) necessary to make Windows
  182135. // correctly enable the menu items that we specify in the wm_initmenu message.
  182136. GetSystemMenu (hwnd, false);
  182137. }
  182138. else
  182139. {
  182140. jassertfalse
  182141. }
  182142. }
  182143. static void* destroyWindowCallback (void* handle)
  182144. {
  182145. RevokeDragDrop ((HWND) handle);
  182146. DestroyWindow ((HWND) handle);
  182147. return 0;
  182148. }
  182149. static void* toFrontCallback1 (void* h)
  182150. {
  182151. SetForegroundWindow ((HWND) h);
  182152. return 0;
  182153. }
  182154. static void* toFrontCallback2 (void* h)
  182155. {
  182156. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182157. return 0;
  182158. }
  182159. static void* setFocusCallback (void* h)
  182160. {
  182161. SetFocus ((HWND) h);
  182162. return 0;
  182163. }
  182164. static void* getFocusCallback (void*)
  182165. {
  182166. return (void*) GetFocus();
  182167. }
  182168. void offsetWithinParent (int& x, int& y) const
  182169. {
  182170. if (isTransparent())
  182171. {
  182172. HWND parentHwnd = GetParent (hwnd);
  182173. if (parentHwnd != 0)
  182174. {
  182175. RECT parentRect;
  182176. GetWindowRect (parentHwnd, &parentRect);
  182177. x += parentRect.left;
  182178. y += parentRect.top;
  182179. }
  182180. }
  182181. }
  182182. bool isTransparent() const
  182183. {
  182184. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182185. }
  182186. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182187. void setIcon (const Image& newIcon)
  182188. {
  182189. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182190. if (hicon != 0)
  182191. {
  182192. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182193. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182194. if (currentWindowIcon != 0)
  182195. DestroyIcon (currentWindowIcon);
  182196. currentWindowIcon = hicon;
  182197. }
  182198. }
  182199. void handlePaintMessage()
  182200. {
  182201. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182202. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182203. PAINTSTRUCT paintStruct;
  182204. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182205. // message and become re-entrant, but that's OK
  182206. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182207. // corrupt the image it's using to paint into, so do a check here.
  182208. static bool reentrant = false;
  182209. if (reentrant)
  182210. {
  182211. DeleteObject (rgn);
  182212. EndPaint (hwnd, &paintStruct);
  182213. return;
  182214. }
  182215. reentrant = true;
  182216. // this is the rectangle to update..
  182217. int x = paintStruct.rcPaint.left;
  182218. int y = paintStruct.rcPaint.top;
  182219. int w = paintStruct.rcPaint.right - x;
  182220. int h = paintStruct.rcPaint.bottom - y;
  182221. const bool transparent = isTransparent();
  182222. if (transparent)
  182223. {
  182224. // it's not possible to have a transparent window with a title bar at the moment!
  182225. jassert (! hasTitleBar());
  182226. RECT r;
  182227. GetWindowRect (hwnd, &r);
  182228. x = y = 0;
  182229. w = r.right - r.left;
  182230. h = r.bottom - r.top;
  182231. }
  182232. if (w > 0 && h > 0)
  182233. {
  182234. clearMaskedRegion();
  182235. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182236. RectangleList contextClip;
  182237. bool needToPaintAll = true;
  182238. if (regionType == COMPLEXREGION && ! transparent)
  182239. {
  182240. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182241. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182242. DeleteObject (clipRgn);
  182243. char rgnData [8192];
  182244. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182245. if (res > 0 && res <= sizeof (rgnData))
  182246. {
  182247. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182248. if (hdr->iType == RDH_RECTANGLES
  182249. && hdr->rcBound.right - hdr->rcBound.left >= w
  182250. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182251. {
  182252. needToPaintAll = false;
  182253. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182254. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182255. while (--num >= 0)
  182256. {
  182257. // (need to move this one pixel to the left because of a win32 bug)
  182258. const int cx = jmax (x, (int) rects->left - 1);
  182259. const int cy = rects->top;
  182260. const int cw = rects->right - cx;
  182261. const int ch = rects->bottom - rects->top;
  182262. if (cx + cw - x <= w && cy + ch - y <= h)
  182263. {
  182264. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182265. }
  182266. else
  182267. {
  182268. needToPaintAll = true;
  182269. break;
  182270. }
  182271. ++rects;
  182272. }
  182273. }
  182274. }
  182275. }
  182276. if (needToPaintAll)
  182277. {
  182278. contextClip.clear();
  182279. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182280. }
  182281. if (transparent)
  182282. {
  182283. RectangleList::Iterator i (contextClip);
  182284. while (i.next())
  182285. {
  182286. const Rectangle<int>& r = *i.getRectangle();
  182287. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182288. }
  182289. }
  182290. // if the component's not opaque, this won't draw properly unless the platform can support this
  182291. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182292. updateCurrentModifiers();
  182293. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182294. context.clipToRectangleList (contextClip);
  182295. context.setOrigin (-x, -y);
  182296. handlePaint (context);
  182297. if (! dontRepaint)
  182298. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182299. }
  182300. DeleteObject (rgn);
  182301. EndPaint (hwnd, &paintStruct);
  182302. reentrant = false;
  182303. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182304. _fpreset(); // because some graphics cards can unmask FP exceptions
  182305. #endif
  182306. lastPaintTime = Time::getMillisecondCounter();
  182307. }
  182308. void doMouseEvent (const Point<int>& position)
  182309. {
  182310. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  182311. }
  182312. void doMouseMove (const Point<int>& position)
  182313. {
  182314. if (! isMouseOver)
  182315. {
  182316. isMouseOver = true;
  182317. updateKeyModifiers();
  182318. TRACKMOUSEEVENT tme;
  182319. tme.cbSize = sizeof (tme);
  182320. tme.dwFlags = TME_LEAVE;
  182321. tme.hwndTrack = hwnd;
  182322. tme.dwHoverTime = 0;
  182323. if (! TrackMouseEvent (&tme))
  182324. jassertfalse;
  182325. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  182326. }
  182327. else if (! isDragging)
  182328. {
  182329. if (! contains (position, false))
  182330. return;
  182331. }
  182332. // (Throttling the incoming queue of mouse-events seems to still be required in XP..)
  182333. static uint32 lastMouseTime = 0;
  182334. const uint32 now = Time::getMillisecondCounter();
  182335. const int maxMouseMovesPerSecond = 60;
  182336. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182337. {
  182338. lastMouseTime = now;
  182339. doMouseEvent (position);
  182340. }
  182341. }
  182342. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182343. {
  182344. if (GetCapture() != hwnd)
  182345. SetCapture (hwnd);
  182346. doMouseMove (position);
  182347. updateModifiersFromWParam (wParam);
  182348. isDragging = true;
  182349. doMouseEvent (position);
  182350. }
  182351. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182352. {
  182353. updateModifiersFromWParam (wParam);
  182354. isDragging = false;
  182355. // release the mouse capture if the user has released all buttons
  182356. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182357. ReleaseCapture();
  182358. doMouseEvent (position);
  182359. }
  182360. void doCaptureChanged()
  182361. {
  182362. if (isDragging)
  182363. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182364. }
  182365. void doMouseExit()
  182366. {
  182367. isMouseOver = false;
  182368. doMouseEvent (getCurrentMousePos());
  182369. }
  182370. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182371. {
  182372. updateKeyModifiers();
  182373. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  182374. handleMouseWheel (0, position, getMouseEventTime(),
  182375. isVertical ? 0.0f : amount,
  182376. isVertical ? amount : 0.0f);
  182377. }
  182378. void sendModifierKeyChangeIfNeeded()
  182379. {
  182380. if (modifiersAtLastCallback != currentModifiers)
  182381. {
  182382. modifiersAtLastCallback = currentModifiers;
  182383. handleModifierKeysChange();
  182384. }
  182385. }
  182386. bool doKeyUp (const WPARAM key)
  182387. {
  182388. updateKeyModifiers();
  182389. switch (key)
  182390. {
  182391. case VK_SHIFT:
  182392. case VK_CONTROL:
  182393. case VK_MENU:
  182394. case VK_CAPITAL:
  182395. case VK_LWIN:
  182396. case VK_RWIN:
  182397. case VK_APPS:
  182398. case VK_NUMLOCK:
  182399. case VK_SCROLL:
  182400. case VK_LSHIFT:
  182401. case VK_RSHIFT:
  182402. case VK_LCONTROL:
  182403. case VK_LMENU:
  182404. case VK_RCONTROL:
  182405. case VK_RMENU:
  182406. sendModifierKeyChangeIfNeeded();
  182407. }
  182408. return handleKeyUpOrDown (false)
  182409. || Component::getCurrentlyModalComponent() != 0;
  182410. }
  182411. bool doKeyDown (const WPARAM key)
  182412. {
  182413. updateKeyModifiers();
  182414. bool used = false;
  182415. switch (key)
  182416. {
  182417. case VK_SHIFT:
  182418. case VK_LSHIFT:
  182419. case VK_RSHIFT:
  182420. case VK_CONTROL:
  182421. case VK_LCONTROL:
  182422. case VK_RCONTROL:
  182423. case VK_MENU:
  182424. case VK_LMENU:
  182425. case VK_RMENU:
  182426. case VK_LWIN:
  182427. case VK_RWIN:
  182428. case VK_CAPITAL:
  182429. case VK_NUMLOCK:
  182430. case VK_SCROLL:
  182431. case VK_APPS:
  182432. sendModifierKeyChangeIfNeeded();
  182433. break;
  182434. case VK_LEFT:
  182435. case VK_RIGHT:
  182436. case VK_UP:
  182437. case VK_DOWN:
  182438. case VK_PRIOR:
  182439. case VK_NEXT:
  182440. case VK_HOME:
  182441. case VK_END:
  182442. case VK_DELETE:
  182443. case VK_INSERT:
  182444. case VK_F1:
  182445. case VK_F2:
  182446. case VK_F3:
  182447. case VK_F4:
  182448. case VK_F5:
  182449. case VK_F6:
  182450. case VK_F7:
  182451. case VK_F8:
  182452. case VK_F9:
  182453. case VK_F10:
  182454. case VK_F11:
  182455. case VK_F12:
  182456. case VK_F13:
  182457. case VK_F14:
  182458. case VK_F15:
  182459. case VK_F16:
  182460. used = handleKeyUpOrDown (true);
  182461. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182462. break;
  182463. case VK_ADD:
  182464. case VK_SUBTRACT:
  182465. case VK_MULTIPLY:
  182466. case VK_DIVIDE:
  182467. case VK_SEPARATOR:
  182468. case VK_DECIMAL:
  182469. used = handleKeyUpOrDown (true);
  182470. break;
  182471. default:
  182472. used = handleKeyUpOrDown (true);
  182473. {
  182474. MSG msg;
  182475. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182476. {
  182477. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182478. // manually generate the key-press event that matches this key-down.
  182479. const UINT keyChar = MapVirtualKey (key, 2);
  182480. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182481. }
  182482. }
  182483. break;
  182484. }
  182485. if (Component::getCurrentlyModalComponent() != 0)
  182486. used = true;
  182487. return used;
  182488. }
  182489. bool doKeyChar (int key, const LPARAM flags)
  182490. {
  182491. updateKeyModifiers();
  182492. juce_wchar textChar = (juce_wchar) key;
  182493. const int virtualScanCode = (flags >> 16) & 0xff;
  182494. if (key >= '0' && key <= '9')
  182495. {
  182496. switch (virtualScanCode) // check for a numeric keypad scan-code
  182497. {
  182498. case 0x52:
  182499. case 0x4f:
  182500. case 0x50:
  182501. case 0x51:
  182502. case 0x4b:
  182503. case 0x4c:
  182504. case 0x4d:
  182505. case 0x47:
  182506. case 0x48:
  182507. case 0x49:
  182508. key = (key - '0') + KeyPress::numberPad0;
  182509. break;
  182510. default:
  182511. break;
  182512. }
  182513. }
  182514. else
  182515. {
  182516. // convert the scan code to an unmodified character code..
  182517. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182518. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182519. keyChar = LOWORD (keyChar);
  182520. if (keyChar != 0)
  182521. key = (int) keyChar;
  182522. // avoid sending junk text characters for some control-key combinations
  182523. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182524. textChar = 0;
  182525. }
  182526. return handleKeyPress (key, textChar);
  182527. }
  182528. bool doAppCommand (const LPARAM lParam)
  182529. {
  182530. int key = 0;
  182531. switch (GET_APPCOMMAND_LPARAM (lParam))
  182532. {
  182533. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182534. key = KeyPress::playKey;
  182535. break;
  182536. case APPCOMMAND_MEDIA_STOP:
  182537. key = KeyPress::stopKey;
  182538. break;
  182539. case APPCOMMAND_MEDIA_NEXTTRACK:
  182540. key = KeyPress::fastForwardKey;
  182541. break;
  182542. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182543. key = KeyPress::rewindKey;
  182544. break;
  182545. }
  182546. if (key != 0)
  182547. {
  182548. updateKeyModifiers();
  182549. if (hwnd == GetActiveWindow())
  182550. {
  182551. handleKeyPress (key, 0);
  182552. return true;
  182553. }
  182554. }
  182555. return false;
  182556. }
  182557. class JuceDropTarget : public IDropTarget
  182558. {
  182559. public:
  182560. JuceDropTarget (Win32ComponentPeer* const owner_)
  182561. : owner (owner_),
  182562. refCount (1)
  182563. {
  182564. }
  182565. virtual ~JuceDropTarget()
  182566. {
  182567. jassert (refCount == 0);
  182568. }
  182569. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182570. {
  182571. if (id == IID_IUnknown || id == IID_IDropTarget)
  182572. {
  182573. AddRef();
  182574. *result = this;
  182575. return S_OK;
  182576. }
  182577. *result = 0;
  182578. return E_NOINTERFACE;
  182579. }
  182580. ULONG __stdcall AddRef() { return ++refCount; }
  182581. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182582. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182583. {
  182584. updateFileList (pDataObject);
  182585. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182586. *pdwEffect = DROPEFFECT_COPY;
  182587. return S_OK;
  182588. }
  182589. HRESULT __stdcall DragLeave()
  182590. {
  182591. owner->handleFileDragExit (files);
  182592. return S_OK;
  182593. }
  182594. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182595. {
  182596. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182597. *pdwEffect = DROPEFFECT_COPY;
  182598. return S_OK;
  182599. }
  182600. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182601. {
  182602. updateFileList (pDataObject);
  182603. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182604. *pdwEffect = DROPEFFECT_COPY;
  182605. return S_OK;
  182606. }
  182607. private:
  182608. Win32ComponentPeer* const owner;
  182609. int refCount;
  182610. StringArray files;
  182611. void updateFileList (IDataObject* const pDataObject)
  182612. {
  182613. files.clear();
  182614. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182615. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182616. if (pDataObject->GetData (&format, &medium) == S_OK)
  182617. {
  182618. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182619. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182620. unsigned int i = 0;
  182621. if (pDropFiles->fWide)
  182622. {
  182623. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182624. for (;;)
  182625. {
  182626. unsigned int len = 0;
  182627. while (i + len < totalLen && fname [i + len] != 0)
  182628. ++len;
  182629. if (len == 0)
  182630. break;
  182631. files.add (String (fname + i, len));
  182632. i += len + 1;
  182633. }
  182634. }
  182635. else
  182636. {
  182637. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182638. for (;;)
  182639. {
  182640. unsigned int len = 0;
  182641. while (i + len < totalLen && fname [i + len] != 0)
  182642. ++len;
  182643. if (len == 0)
  182644. break;
  182645. files.add (String (fname + i, len));
  182646. i += len + 1;
  182647. }
  182648. }
  182649. GlobalUnlock (medium.hGlobal);
  182650. }
  182651. }
  182652. JuceDropTarget (const JuceDropTarget&);
  182653. JuceDropTarget& operator= (const JuceDropTarget&);
  182654. };
  182655. void doSettingChange()
  182656. {
  182657. Desktop::getInstance().refreshMonitorSizes();
  182658. if (fullScreen && ! isMinimised())
  182659. {
  182660. const Rectangle<int> r (component->getParentMonitorArea());
  182661. SetWindowPos (hwnd, 0,
  182662. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182663. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182664. }
  182665. }
  182666. public:
  182667. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182668. {
  182669. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182670. if (peer != 0)
  182671. return peer->peerWindowProc (h, message, wParam, lParam);
  182672. return DefWindowProcW (h, message, wParam, lParam);
  182673. }
  182674. private:
  182675. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182676. {
  182677. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182678. }
  182679. const Point<int> getCurrentMousePos() throw()
  182680. {
  182681. RECT wr;
  182682. GetWindowRect (hwnd, &wr);
  182683. const DWORD mp = GetMessagePos();
  182684. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182685. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182686. }
  182687. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182688. {
  182689. if (isValidPeer (this))
  182690. {
  182691. switch (message)
  182692. {
  182693. case WM_NCHITTEST:
  182694. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182695. return HTTRANSPARENT;
  182696. if (hasTitleBar())
  182697. break;
  182698. return HTCLIENT;
  182699. case WM_PAINT:
  182700. handlePaintMessage();
  182701. return 0;
  182702. case WM_NCPAINT:
  182703. if (wParam != 1)
  182704. handlePaintMessage();
  182705. if (hasTitleBar())
  182706. break;
  182707. return 0;
  182708. case WM_ERASEBKGND:
  182709. case WM_NCCALCSIZE:
  182710. if (hasTitleBar())
  182711. break;
  182712. return 1;
  182713. case WM_MOUSEMOVE:
  182714. doMouseMove (getPointFromLParam (lParam));
  182715. return 0;
  182716. case WM_MOUSELEAVE:
  182717. doMouseExit();
  182718. return 0;
  182719. case WM_LBUTTONDOWN:
  182720. case WM_MBUTTONDOWN:
  182721. case WM_RBUTTONDOWN:
  182722. doMouseDown (getPointFromLParam (lParam), wParam);
  182723. return 0;
  182724. case WM_LBUTTONUP:
  182725. case WM_MBUTTONUP:
  182726. case WM_RBUTTONUP:
  182727. doMouseUp (getPointFromLParam (lParam), wParam);
  182728. return 0;
  182729. case WM_CAPTURECHANGED:
  182730. doCaptureChanged();
  182731. return 0;
  182732. case WM_NCMOUSEMOVE:
  182733. if (hasTitleBar())
  182734. break;
  182735. return 0;
  182736. case 0x020A: /* WM_MOUSEWHEEL */
  182737. doMouseWheel (getCurrentMousePos(), wParam, true);
  182738. return 0;
  182739. case 0x020E: /* WM_MOUSEHWHEEL */
  182740. doMouseWheel (getCurrentMousePos(), wParam, false);
  182741. return 0;
  182742. case WM_WINDOWPOSCHANGING:
  182743. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182744. {
  182745. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182746. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182747. {
  182748. if (constrainer != 0)
  182749. {
  182750. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182751. component->getY() - windowBorder.getTop(),
  182752. component->getWidth() + windowBorder.getLeftAndRight(),
  182753. component->getHeight() + windowBorder.getTopAndBottom());
  182754. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182755. constrainer->checkBounds (pos, current,
  182756. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182757. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182758. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182759. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182760. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182761. wp->x = pos.getX();
  182762. wp->y = pos.getY();
  182763. wp->cx = pos.getWidth();
  182764. wp->cy = pos.getHeight();
  182765. }
  182766. }
  182767. }
  182768. return 0;
  182769. case WM_WINDOWPOSCHANGED:
  182770. handleMovedOrResized();
  182771. if (dontRepaint)
  182772. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182773. return 0;
  182774. case WM_KEYDOWN:
  182775. case WM_SYSKEYDOWN:
  182776. if (doKeyDown (wParam))
  182777. return 0;
  182778. break;
  182779. case WM_KEYUP:
  182780. case WM_SYSKEYUP:
  182781. if (doKeyUp (wParam))
  182782. return 0;
  182783. break;
  182784. case WM_CHAR:
  182785. if (doKeyChar ((int) wParam, lParam))
  182786. return 0;
  182787. break;
  182788. case WM_APPCOMMAND:
  182789. if (doAppCommand (lParam))
  182790. return TRUE;
  182791. break;
  182792. case WM_SETFOCUS:
  182793. updateKeyModifiers();
  182794. handleFocusGain();
  182795. break;
  182796. case WM_KILLFOCUS:
  182797. if (hasCreatedCaret)
  182798. {
  182799. hasCreatedCaret = false;
  182800. DestroyCaret();
  182801. }
  182802. handleFocusLoss();
  182803. break;
  182804. case WM_ACTIVATEAPP:
  182805. // Windows does weird things to process priority when you swap apps,
  182806. // so this forces an update when the app is brought to the front
  182807. if (wParam != FALSE)
  182808. juce_repeatLastProcessPriority();
  182809. else
  182810. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182811. juce_CheckCurrentlyFocusedTopLevelWindow();
  182812. modifiersAtLastCallback = -1;
  182813. return 0;
  182814. case WM_ACTIVATE:
  182815. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182816. {
  182817. modifiersAtLastCallback = -1;
  182818. updateKeyModifiers();
  182819. if (isMinimised())
  182820. {
  182821. component->repaint();
  182822. handleMovedOrResized();
  182823. if (! ComponentPeer::isValidPeer (this))
  182824. return 0;
  182825. }
  182826. if (LOWORD (wParam) == WA_CLICKACTIVE
  182827. && component->isCurrentlyBlockedByAnotherModalComponent())
  182828. {
  182829. const Point<int> mousePos (component->getMouseXYRelative());
  182830. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182831. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182832. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182833. return 0;
  182834. }
  182835. handleBroughtToFront();
  182836. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182837. Component::getCurrentlyModalComponent()->toFront (true);
  182838. return 0;
  182839. }
  182840. break;
  182841. case WM_NCACTIVATE:
  182842. // while a temporary window is being shown, prevent Windows from deactivating the
  182843. // title bars of our main windows.
  182844. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182845. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182846. break;
  182847. case WM_MOUSEACTIVATE:
  182848. if (! component->getMouseClickGrabsKeyboardFocus())
  182849. return MA_NOACTIVATE;
  182850. break;
  182851. case WM_SHOWWINDOW:
  182852. if (wParam != 0)
  182853. handleBroughtToFront();
  182854. break;
  182855. case WM_CLOSE:
  182856. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182857. handleUserClosingWindow();
  182858. return 0;
  182859. case WM_QUERYENDSESSION:
  182860. if (JUCEApplication::getInstance() != 0)
  182861. {
  182862. JUCEApplication::getInstance()->systemRequestedQuit();
  182863. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182864. }
  182865. return TRUE;
  182866. case WM_TRAYNOTIFY:
  182867. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182868. {
  182869. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182870. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182871. {
  182872. Component* const current = Component::getCurrentlyModalComponent();
  182873. if (current != 0)
  182874. current->inputAttemptWhenModal();
  182875. }
  182876. }
  182877. else
  182878. {
  182879. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182880. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182881. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182882. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182883. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182884. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182885. eventMods = eventMods.withoutMouseButtons();
  182886. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182887. Point<int>(), eventMods, component, getMouseEventTime(),
  182888. Point<int>(), getMouseEventTime(), 1, false);
  182889. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182890. {
  182891. SetFocus (hwnd);
  182892. SetForegroundWindow (hwnd);
  182893. component->mouseDown (e);
  182894. }
  182895. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182896. {
  182897. component->mouseUp (e);
  182898. }
  182899. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182900. {
  182901. component->mouseDoubleClick (e);
  182902. }
  182903. else if (lParam == WM_MOUSEMOVE)
  182904. {
  182905. component->mouseMove (e);
  182906. }
  182907. }
  182908. break;
  182909. case WM_SYNCPAINT:
  182910. return 0;
  182911. case WM_PALETTECHANGED:
  182912. InvalidateRect (h, 0, 0);
  182913. break;
  182914. case WM_DISPLAYCHANGE:
  182915. InvalidateRect (h, 0, 0);
  182916. createPaletteIfNeeded = true;
  182917. // intentional fall-through...
  182918. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182919. doSettingChange();
  182920. break;
  182921. case WM_INITMENU:
  182922. if (! hasTitleBar())
  182923. {
  182924. if (isFullScreen())
  182925. {
  182926. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182927. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182928. }
  182929. else if (! isMinimised())
  182930. {
  182931. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182932. }
  182933. }
  182934. break;
  182935. case WM_SYSCOMMAND:
  182936. switch (wParam & 0xfff0)
  182937. {
  182938. case SC_CLOSE:
  182939. if (sendInputAttemptWhenModalMessage())
  182940. return 0;
  182941. if (hasTitleBar())
  182942. {
  182943. PostMessage (h, WM_CLOSE, 0, 0);
  182944. return 0;
  182945. }
  182946. break;
  182947. case SC_KEYMENU:
  182948. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  182949. // obscure situations that can arise if a modal loop is started from an alt-key
  182950. // keypress).
  182951. if (hasTitleBar() && h == GetCapture())
  182952. ReleaseCapture();
  182953. break;
  182954. case SC_MAXIMIZE:
  182955. if (sendInputAttemptWhenModalMessage())
  182956. return 0;
  182957. setFullScreen (true);
  182958. return 0;
  182959. case SC_MINIMIZE:
  182960. if (sendInputAttemptWhenModalMessage())
  182961. return 0;
  182962. if (! hasTitleBar())
  182963. {
  182964. setMinimised (true);
  182965. return 0;
  182966. }
  182967. break;
  182968. case SC_RESTORE:
  182969. if (sendInputAttemptWhenModalMessage())
  182970. return 0;
  182971. if (hasTitleBar())
  182972. {
  182973. if (isFullScreen())
  182974. {
  182975. setFullScreen (false);
  182976. return 0;
  182977. }
  182978. }
  182979. else
  182980. {
  182981. if (isMinimised())
  182982. setMinimised (false);
  182983. else if (isFullScreen())
  182984. setFullScreen (false);
  182985. return 0;
  182986. }
  182987. break;
  182988. }
  182989. break;
  182990. case WM_NCLBUTTONDOWN:
  182991. case WM_NCRBUTTONDOWN:
  182992. case WM_NCMBUTTONDOWN:
  182993. sendInputAttemptWhenModalMessage();
  182994. break;
  182995. //case WM_IME_STARTCOMPOSITION;
  182996. // return 0;
  182997. case WM_GETDLGCODE:
  182998. return DLGC_WANTALLKEYS;
  182999. default:
  183000. break;
  183001. }
  183002. }
  183003. return DefWindowProcW (h, message, wParam, lParam);
  183004. }
  183005. bool sendInputAttemptWhenModalMessage()
  183006. {
  183007. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183008. {
  183009. Component* const current = Component::getCurrentlyModalComponent();
  183010. if (current != 0)
  183011. current->inputAttemptWhenModal();
  183012. return true;
  183013. }
  183014. return false;
  183015. }
  183016. Win32ComponentPeer (const Win32ComponentPeer&);
  183017. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  183018. };
  183019. ModifierKeys Win32ComponentPeer::currentModifiers;
  183020. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  183021. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  183022. {
  183023. return new Win32ComponentPeer (this, styleFlags);
  183024. }
  183025. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  183026. void ModifierKeys::updateCurrentModifiers() throw()
  183027. {
  183028. currentModifiers = Win32ComponentPeer::currentModifiers;
  183029. }
  183030. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  183031. {
  183032. Win32ComponentPeer::updateKeyModifiers();
  183033. int keyMods = 0;
  183034. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  183035. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  183036. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  183037. Win32ComponentPeer::currentModifiers
  183038. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  183039. return Win32ComponentPeer::currentModifiers;
  183040. }
  183041. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183042. {
  183043. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183044. if (wp != 0)
  183045. wp->setTaskBarIcon (&newImage);
  183046. }
  183047. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183048. {
  183049. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183050. if (wp != 0)
  183051. wp->setTaskBarIconToolTip (tooltip);
  183052. }
  183053. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183054. {
  183055. DWORD val = GetWindowLong (h, styleType);
  183056. if (bitIsSet)
  183057. val |= feature;
  183058. else
  183059. val &= ~feature;
  183060. SetWindowLongPtr (h, styleType, val);
  183061. SetWindowPos (h, 0, 0, 0, 0, 0,
  183062. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183063. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183064. }
  183065. bool Process::isForegroundProcess()
  183066. {
  183067. HWND fg = GetForegroundWindow();
  183068. if (fg == 0)
  183069. return true;
  183070. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183071. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183072. // have to see if any of our windows are children of the foreground window
  183073. fg = GetAncestor (fg, GA_ROOT);
  183074. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183075. {
  183076. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183077. if (wp != 0 && wp->isInside (fg))
  183078. return true;
  183079. }
  183080. return false;
  183081. }
  183082. bool AlertWindow::showNativeDialogBox (const String& title,
  183083. const String& bodyText,
  183084. bool isOkCancel)
  183085. {
  183086. return MessageBox (0, bodyText, title,
  183087. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183088. : MB_OK)) == IDOK;
  183089. }
  183090. void Desktop::createMouseInputSources()
  183091. {
  183092. mouseSources.add (new MouseInputSource (0, true));
  183093. }
  183094. const Point<int> Desktop::getMousePosition()
  183095. {
  183096. POINT mousePos;
  183097. GetCursorPos (&mousePos);
  183098. return Point<int> (mousePos.x, mousePos.y);
  183099. }
  183100. void Desktop::setMousePosition (const Point<int>& newPosition)
  183101. {
  183102. SetCursorPos (newPosition.getX(), newPosition.getY());
  183103. }
  183104. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183105. {
  183106. return new Image (format, imageWidth, imageHeight, clearImage);
  183107. }
  183108. class ScreenSaverDefeater : public Timer,
  183109. public DeletedAtShutdown
  183110. {
  183111. public:
  183112. ScreenSaverDefeater() throw()
  183113. {
  183114. startTimer (10000);
  183115. timerCallback();
  183116. }
  183117. ~ScreenSaverDefeater() {}
  183118. void timerCallback()
  183119. {
  183120. if (Process::isForegroundProcess())
  183121. {
  183122. // simulate a shift key getting pressed..
  183123. INPUT input[2];
  183124. input[0].type = INPUT_KEYBOARD;
  183125. input[0].ki.wVk = VK_SHIFT;
  183126. input[0].ki.dwFlags = 0;
  183127. input[0].ki.dwExtraInfo = 0;
  183128. input[1].type = INPUT_KEYBOARD;
  183129. input[1].ki.wVk = VK_SHIFT;
  183130. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183131. input[1].ki.dwExtraInfo = 0;
  183132. SendInput (2, input, sizeof (INPUT));
  183133. }
  183134. }
  183135. };
  183136. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183137. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183138. {
  183139. if (isEnabled)
  183140. {
  183141. deleteAndZero (screenSaverDefeater);
  183142. }
  183143. else if (screenSaverDefeater == 0)
  183144. {
  183145. screenSaverDefeater = new ScreenSaverDefeater();
  183146. }
  183147. }
  183148. bool Desktop::isScreenSaverEnabled() throw()
  183149. {
  183150. return screenSaverDefeater == 0;
  183151. }
  183152. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183153. {
  183154. if (enableOrDisable)
  183155. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183156. }
  183157. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183158. {
  183159. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183160. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183161. return TRUE;
  183162. }
  183163. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183164. {
  183165. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183166. // make sure the first in the list is the main monitor
  183167. for (int i = 1; i < monitorCoords.size(); ++i)
  183168. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183169. monitorCoords.swap (i, 0);
  183170. if (monitorCoords.size() == 0)
  183171. {
  183172. RECT r;
  183173. GetWindowRect (GetDesktopWindow(), &r);
  183174. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183175. }
  183176. if (clipToWorkArea)
  183177. {
  183178. // clip the main monitor to the active non-taskbar area
  183179. RECT r;
  183180. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183181. Rectangle<int>& screen = monitorCoords.getReference (0);
  183182. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183183. jmax (screen.getY(), (int) r.top));
  183184. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183185. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183186. }
  183187. }
  183188. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183189. {
  183190. Image* im = 0;
  183191. if (bitmap != 0)
  183192. {
  183193. BITMAP bm;
  183194. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183195. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183196. {
  183197. HDC tempDC = GetDC (0);
  183198. HDC dc = CreateCompatibleDC (tempDC);
  183199. ReleaseDC (0, tempDC);
  183200. SelectObject (dc, bitmap);
  183201. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183202. for (int y = bm.bmHeight; --y >= 0;)
  183203. {
  183204. for (int x = bm.bmWidth; --x >= 0;)
  183205. {
  183206. COLORREF col = GetPixel (dc, x, y);
  183207. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183208. (uint8) GetGValue (col),
  183209. (uint8) GetBValue (col)));
  183210. }
  183211. }
  183212. DeleteDC (dc);
  183213. }
  183214. }
  183215. return im;
  183216. }
  183217. static Image* createImageFromHICON (HICON icon) throw()
  183218. {
  183219. ICONINFO info;
  183220. if (GetIconInfo (icon, &info))
  183221. {
  183222. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183223. if (mask == 0)
  183224. return 0;
  183225. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183226. if (image == 0)
  183227. return mask;
  183228. for (int y = image->getHeight(); --y >= 0;)
  183229. {
  183230. for (int x = image->getWidth(); --x >= 0;)
  183231. {
  183232. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183233. if (brightness > 0.0f)
  183234. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183235. }
  183236. }
  183237. delete mask;
  183238. return image;
  183239. }
  183240. return 0;
  183241. }
  183242. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183243. {
  183244. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183245. ICONINFO info;
  183246. info.fIcon = isIcon;
  183247. info.xHotspot = hotspotX;
  183248. info.yHotspot = hotspotY;
  183249. info.hbmMask = mask;
  183250. HICON hi = 0;
  183251. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183252. {
  183253. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183254. Graphics g (bitmap);
  183255. g.drawImageAt (&image, 0, 0);
  183256. info.hbmColor = bitmap.hBitmap;
  183257. hi = CreateIconIndirect (&info);
  183258. }
  183259. else
  183260. {
  183261. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183262. HDC colDC = CreateCompatibleDC (GetDC (0));
  183263. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183264. SelectObject (colDC, colour);
  183265. SelectObject (alphaDC, mask);
  183266. for (int y = image.getHeight(); --y >= 0;)
  183267. {
  183268. for (int x = image.getWidth(); --x >= 0;)
  183269. {
  183270. const Colour c (image.getPixelAt (x, y));
  183271. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183272. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183273. }
  183274. }
  183275. DeleteDC (colDC);
  183276. DeleteDC (alphaDC);
  183277. info.hbmColor = colour;
  183278. hi = CreateIconIndirect (&info);
  183279. DeleteObject (colour);
  183280. }
  183281. DeleteObject (mask);
  183282. return hi;
  183283. }
  183284. Image* juce_createIconForFile (const File& file)
  183285. {
  183286. Image* image = 0;
  183287. WCHAR filename [1024];
  183288. file.getFullPathName().copyToUnicode (filename, 1023);
  183289. WORD iconNum = 0;
  183290. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183291. filename, &iconNum);
  183292. if (icon != 0)
  183293. {
  183294. image = createImageFromHICON (icon);
  183295. DestroyIcon (icon);
  183296. }
  183297. return image;
  183298. }
  183299. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183300. {
  183301. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183302. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183303. const Image* im = &image;
  183304. Image* newIm = 0;
  183305. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183306. {
  183307. im = newIm = image.createCopy (maxW, maxH);
  183308. hotspotX = (hotspotX * maxW) / image.getWidth();
  183309. hotspotY = (hotspotY * maxH) / image.getHeight();
  183310. }
  183311. void* cursorH = 0;
  183312. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183313. if (os == SystemStats::WinXP)
  183314. {
  183315. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183316. }
  183317. else
  183318. {
  183319. const int stride = (maxW + 7) >> 3;
  183320. HeapBlock <uint8> andPlane, xorPlane;
  183321. andPlane.calloc (stride * maxH);
  183322. xorPlane.calloc (stride * maxH);
  183323. int index = 0;
  183324. for (int y = 0; y < maxH; ++y)
  183325. {
  183326. for (int x = 0; x < maxW; ++x)
  183327. {
  183328. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183329. const Colour pixelColour (im->getPixelAt (x, y));
  183330. if (pixelColour.getAlpha() < 127)
  183331. andPlane [index + (x >> 3)] |= bit;
  183332. else if (pixelColour.getBrightness() >= 0.5f)
  183333. xorPlane [index + (x >> 3)] |= bit;
  183334. }
  183335. index += stride;
  183336. }
  183337. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183338. }
  183339. delete newIm;
  183340. return cursorH;
  183341. }
  183342. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183343. {
  183344. if (cursorHandle != 0 && ! isStandard)
  183345. DestroyCursor ((HCURSOR) cursorHandle);
  183346. }
  183347. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183348. {
  183349. LPCTSTR cursorName = IDC_ARROW;
  183350. switch (type)
  183351. {
  183352. case MouseCursor::NormalCursor:
  183353. cursorName = IDC_ARROW;
  183354. break;
  183355. case MouseCursor::NoCursor:
  183356. return 0;
  183357. case MouseCursor::DraggingHandCursor:
  183358. {
  183359. static void* dragHandCursor = 0;
  183360. if (dragHandCursor == 0)
  183361. {
  183362. static const unsigned char dragHandData[] =
  183363. { 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,
  183364. 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,
  183365. 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 };
  183366. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183367. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183368. }
  183369. return dragHandCursor;
  183370. }
  183371. case MouseCursor::WaitCursor:
  183372. cursorName = IDC_WAIT;
  183373. break;
  183374. case MouseCursor::IBeamCursor:
  183375. cursorName = IDC_IBEAM;
  183376. break;
  183377. case MouseCursor::PointingHandCursor:
  183378. cursorName = MAKEINTRESOURCE(32649);
  183379. break;
  183380. case MouseCursor::LeftRightResizeCursor:
  183381. case MouseCursor::LeftEdgeResizeCursor:
  183382. case MouseCursor::RightEdgeResizeCursor:
  183383. cursorName = IDC_SIZEWE;
  183384. break;
  183385. case MouseCursor::UpDownResizeCursor:
  183386. case MouseCursor::TopEdgeResizeCursor:
  183387. case MouseCursor::BottomEdgeResizeCursor:
  183388. cursorName = IDC_SIZENS;
  183389. break;
  183390. case MouseCursor::TopLeftCornerResizeCursor:
  183391. case MouseCursor::BottomRightCornerResizeCursor:
  183392. cursorName = IDC_SIZENWSE;
  183393. break;
  183394. case MouseCursor::TopRightCornerResizeCursor:
  183395. case MouseCursor::BottomLeftCornerResizeCursor:
  183396. cursorName = IDC_SIZENESW;
  183397. break;
  183398. case MouseCursor::UpDownLeftRightResizeCursor:
  183399. cursorName = IDC_SIZEALL;
  183400. break;
  183401. case MouseCursor::CrosshairCursor:
  183402. cursorName = IDC_CROSS;
  183403. break;
  183404. case MouseCursor::CopyingCursor:
  183405. // can't seem to find one of these in the win32 list..
  183406. break;
  183407. }
  183408. HCURSOR cursorH = LoadCursor (0, cursorName);
  183409. if (cursorH == 0)
  183410. cursorH = LoadCursor (0, IDC_ARROW);
  183411. return (void*) cursorH;
  183412. }
  183413. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183414. {
  183415. SetCursor ((HCURSOR) getHandle());
  183416. }
  183417. void MouseCursor::showInAllWindows() const throw()
  183418. {
  183419. showInWindow (0);
  183420. }
  183421. class JuceDropSource : public IDropSource
  183422. {
  183423. int refCount;
  183424. public:
  183425. JuceDropSource()
  183426. : refCount (1)
  183427. {
  183428. }
  183429. virtual ~JuceDropSource()
  183430. {
  183431. jassert (refCount == 0);
  183432. }
  183433. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183434. {
  183435. if (id == IID_IUnknown || id == IID_IDropSource)
  183436. {
  183437. AddRef();
  183438. *result = this;
  183439. return S_OK;
  183440. }
  183441. *result = 0;
  183442. return E_NOINTERFACE;
  183443. }
  183444. ULONG __stdcall AddRef() { return ++refCount; }
  183445. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183446. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183447. {
  183448. if (escapePressed)
  183449. return DRAGDROP_S_CANCEL;
  183450. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183451. return DRAGDROP_S_DROP;
  183452. return S_OK;
  183453. }
  183454. HRESULT __stdcall GiveFeedback (DWORD)
  183455. {
  183456. return DRAGDROP_S_USEDEFAULTCURSORS;
  183457. }
  183458. };
  183459. class JuceEnumFormatEtc : public IEnumFORMATETC
  183460. {
  183461. public:
  183462. JuceEnumFormatEtc (const FORMATETC* const format_)
  183463. : refCount (1),
  183464. format (format_),
  183465. index (0)
  183466. {
  183467. }
  183468. virtual ~JuceEnumFormatEtc()
  183469. {
  183470. jassert (refCount == 0);
  183471. }
  183472. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183473. {
  183474. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183475. {
  183476. AddRef();
  183477. *result = this;
  183478. return S_OK;
  183479. }
  183480. *result = 0;
  183481. return E_NOINTERFACE;
  183482. }
  183483. ULONG __stdcall AddRef() { return ++refCount; }
  183484. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183485. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183486. {
  183487. if (result == 0)
  183488. return E_POINTER;
  183489. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183490. newOne->index = index;
  183491. *result = newOne;
  183492. return S_OK;
  183493. }
  183494. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183495. {
  183496. if (pceltFetched != 0)
  183497. *pceltFetched = 0;
  183498. else if (celt != 1)
  183499. return S_FALSE;
  183500. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183501. {
  183502. copyFormatEtc (lpFormatEtc [0], *format);
  183503. ++index;
  183504. if (pceltFetched != 0)
  183505. *pceltFetched = 1;
  183506. return S_OK;
  183507. }
  183508. return S_FALSE;
  183509. }
  183510. HRESULT __stdcall Skip (ULONG celt)
  183511. {
  183512. if (index + (int) celt >= 1)
  183513. return S_FALSE;
  183514. index += celt;
  183515. return S_OK;
  183516. }
  183517. HRESULT __stdcall Reset()
  183518. {
  183519. index = 0;
  183520. return S_OK;
  183521. }
  183522. private:
  183523. int refCount;
  183524. const FORMATETC* const format;
  183525. int index;
  183526. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183527. {
  183528. dest = source;
  183529. if (source.ptd != 0)
  183530. {
  183531. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183532. *(dest.ptd) = *(source.ptd);
  183533. }
  183534. }
  183535. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183536. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183537. };
  183538. class JuceDataObject : public IDataObject
  183539. {
  183540. JuceDropSource* const dropSource;
  183541. const FORMATETC* const format;
  183542. const STGMEDIUM* const medium;
  183543. int refCount;
  183544. JuceDataObject (const JuceDataObject&);
  183545. JuceDataObject& operator= (const JuceDataObject&);
  183546. public:
  183547. JuceDataObject (JuceDropSource* const dropSource_,
  183548. const FORMATETC* const format_,
  183549. const STGMEDIUM* const medium_)
  183550. : dropSource (dropSource_),
  183551. format (format_),
  183552. medium (medium_),
  183553. refCount (1)
  183554. {
  183555. }
  183556. virtual ~JuceDataObject()
  183557. {
  183558. jassert (refCount == 0);
  183559. }
  183560. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183561. {
  183562. if (id == IID_IUnknown || id == IID_IDataObject)
  183563. {
  183564. AddRef();
  183565. *result = this;
  183566. return S_OK;
  183567. }
  183568. *result = 0;
  183569. return E_NOINTERFACE;
  183570. }
  183571. ULONG __stdcall AddRef() { return ++refCount; }
  183572. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183573. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183574. {
  183575. if ((pFormatEtc->tymed & format->tymed) != 0
  183576. && pFormatEtc->cfFormat == format->cfFormat
  183577. && pFormatEtc->dwAspect == format->dwAspect)
  183578. {
  183579. pMedium->tymed = format->tymed;
  183580. pMedium->pUnkForRelease = 0;
  183581. if (format->tymed == TYMED_HGLOBAL)
  183582. {
  183583. const SIZE_T len = GlobalSize (medium->hGlobal);
  183584. void* const src = GlobalLock (medium->hGlobal);
  183585. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183586. memcpy (dst, src, len);
  183587. GlobalUnlock (medium->hGlobal);
  183588. pMedium->hGlobal = dst;
  183589. return S_OK;
  183590. }
  183591. }
  183592. return DV_E_FORMATETC;
  183593. }
  183594. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183595. {
  183596. if (f == 0)
  183597. return E_INVALIDARG;
  183598. if (f->tymed == format->tymed
  183599. && f->cfFormat == format->cfFormat
  183600. && f->dwAspect == format->dwAspect)
  183601. return S_OK;
  183602. return DV_E_FORMATETC;
  183603. }
  183604. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183605. {
  183606. pFormatEtcOut->ptd = 0;
  183607. return E_NOTIMPL;
  183608. }
  183609. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183610. {
  183611. if (result == 0)
  183612. return E_POINTER;
  183613. if (direction == DATADIR_GET)
  183614. {
  183615. *result = new JuceEnumFormatEtc (format);
  183616. return S_OK;
  183617. }
  183618. *result = 0;
  183619. return E_NOTIMPL;
  183620. }
  183621. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183622. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183623. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183624. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183625. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183626. };
  183627. static HDROP createHDrop (const StringArray& fileNames) throw()
  183628. {
  183629. int totalChars = 0;
  183630. for (int i = fileNames.size(); --i >= 0;)
  183631. totalChars += fileNames[i].length() + 1;
  183632. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183633. sizeof (DROPFILES)
  183634. + sizeof (WCHAR) * (totalChars + 2));
  183635. if (hDrop != 0)
  183636. {
  183637. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183638. pDropFiles->pFiles = sizeof (DROPFILES);
  183639. pDropFiles->fWide = true;
  183640. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183641. for (int i = 0; i < fileNames.size(); ++i)
  183642. {
  183643. fileNames[i].copyToUnicode (fname, 2048);
  183644. fname += fileNames[i].length() + 1;
  183645. }
  183646. *fname = 0;
  183647. GlobalUnlock (hDrop);
  183648. }
  183649. return hDrop;
  183650. }
  183651. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183652. {
  183653. JuceDropSource* const source = new JuceDropSource();
  183654. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183655. DWORD effect;
  183656. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183657. data->Release();
  183658. source->Release();
  183659. return res == DRAGDROP_S_DROP;
  183660. }
  183661. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183662. {
  183663. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183664. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183665. medium.hGlobal = createHDrop (files);
  183666. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183667. : DROPEFFECT_COPY);
  183668. }
  183669. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183670. {
  183671. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183672. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183673. const int numChars = text.length();
  183674. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183675. char* d = (char*) GlobalLock (medium.hGlobal);
  183676. text.copyToUnicode ((WCHAR*) d, numChars + 1);
  183677. format.cfFormat = CF_UNICODETEXT;
  183678. GlobalUnlock (medium.hGlobal);
  183679. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183680. }
  183681. #endif
  183682. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183683. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183684. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183685. // compiled on its own).
  183686. #if JUCE_INCLUDED_FILE
  183687. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183688. NEWTEXTMETRICEXW*,
  183689. int type,
  183690. LPARAM lParam)
  183691. {
  183692. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183693. {
  183694. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183695. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  183696. }
  183697. return 1;
  183698. }
  183699. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183700. NEWTEXTMETRICEXW*,
  183701. int type,
  183702. LPARAM lParam)
  183703. {
  183704. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183705. {
  183706. LOGFONTW lf;
  183707. zerostruct (lf);
  183708. lf.lfWeight = FW_DONTCARE;
  183709. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183710. lf.lfQuality = DEFAULT_QUALITY;
  183711. lf.lfCharSet = DEFAULT_CHARSET;
  183712. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183713. lf.lfPitchAndFamily = FF_DONTCARE;
  183714. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183715. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183716. HDC dc = CreateCompatibleDC (0);
  183717. EnumFontFamiliesEx (dc, &lf,
  183718. (FONTENUMPROCW) &wfontEnum2,
  183719. lParam, 0);
  183720. DeleteDC (dc);
  183721. }
  183722. return 1;
  183723. }
  183724. const StringArray Font::findAllTypefaceNames() throw()
  183725. {
  183726. StringArray results;
  183727. HDC dc = CreateCompatibleDC (0);
  183728. {
  183729. LOGFONTW lf;
  183730. zerostruct (lf);
  183731. lf.lfWeight = FW_DONTCARE;
  183732. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183733. lf.lfQuality = DEFAULT_QUALITY;
  183734. lf.lfCharSet = DEFAULT_CHARSET;
  183735. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183736. lf.lfPitchAndFamily = FF_DONTCARE;
  183737. lf.lfFaceName[0] = 0;
  183738. EnumFontFamiliesEx (dc, &lf,
  183739. (FONTENUMPROCW) &wfontEnum1,
  183740. (LPARAM) &results, 0);
  183741. }
  183742. DeleteDC (dc);
  183743. results.sort (true);
  183744. return results;
  183745. }
  183746. extern bool juce_IsRunningInWine();
  183747. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  183748. {
  183749. if (juce_IsRunningInWine())
  183750. {
  183751. // If we're running in Wine, then use fonts that might be available on Linux..
  183752. defaultSans = "Bitstream Vera Sans";
  183753. defaultSerif = "Bitstream Vera Serif";
  183754. defaultFixed = "Bitstream Vera Sans Mono";
  183755. }
  183756. else
  183757. {
  183758. defaultSans = "Verdana";
  183759. defaultSerif = "Times";
  183760. defaultFixed = "Lucida Console";
  183761. }
  183762. }
  183763. class FontDCHolder : private DeletedAtShutdown
  183764. {
  183765. public:
  183766. FontDCHolder() throw()
  183767. : dc (0), numKPs (0), size (0),
  183768. bold (false), italic (false)
  183769. {
  183770. }
  183771. ~FontDCHolder() throw()
  183772. {
  183773. if (dc != 0)
  183774. {
  183775. DeleteDC (dc);
  183776. DeleteObject (fontH);
  183777. }
  183778. clearSingletonInstance();
  183779. }
  183780. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183781. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183782. {
  183783. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183784. {
  183785. fontName = fontName_;
  183786. bold = bold_;
  183787. italic = italic_;
  183788. size = size_;
  183789. if (dc != 0)
  183790. {
  183791. DeleteDC (dc);
  183792. DeleteObject (fontH);
  183793. kps.free();
  183794. }
  183795. fontH = 0;
  183796. dc = CreateCompatibleDC (0);
  183797. SetMapperFlags (dc, 0);
  183798. SetMapMode (dc, MM_TEXT);
  183799. LOGFONTW lfw;
  183800. zerostruct (lfw);
  183801. lfw.lfCharSet = DEFAULT_CHARSET;
  183802. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183803. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183804. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183805. lfw.lfQuality = PROOF_QUALITY;
  183806. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183807. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183808. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183809. lfw.lfHeight = size > 0 ? size : -256;
  183810. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183811. if (standardSizedFont != 0)
  183812. {
  183813. if (SelectObject (dc, standardSizedFont) != 0)
  183814. {
  183815. fontH = standardSizedFont;
  183816. if (size == 0)
  183817. {
  183818. OUTLINETEXTMETRIC otm;
  183819. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183820. {
  183821. lfw.lfHeight = -(int) otm.otmEMSquare;
  183822. fontH = CreateFontIndirect (&lfw);
  183823. SelectObject (dc, fontH);
  183824. DeleteObject (standardSizedFont);
  183825. }
  183826. }
  183827. }
  183828. else
  183829. {
  183830. jassertfalse
  183831. }
  183832. }
  183833. else
  183834. {
  183835. jassertfalse
  183836. }
  183837. }
  183838. return dc;
  183839. }
  183840. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183841. {
  183842. if (kps == 0)
  183843. {
  183844. numKPs = GetKerningPairs (dc, 0, 0);
  183845. kps.calloc (numKPs);
  183846. GetKerningPairs (dc, numKPs, kps);
  183847. }
  183848. numKPs_ = numKPs;
  183849. return kps;
  183850. }
  183851. private:
  183852. HFONT fontH;
  183853. HDC dc;
  183854. String fontName;
  183855. HeapBlock <KERNINGPAIR> kps;
  183856. int numKPs, size;
  183857. bool bold, italic;
  183858. FontDCHolder (const FontDCHolder&);
  183859. FontDCHolder& operator= (const FontDCHolder&);
  183860. };
  183861. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183862. class WindowsTypeface : public CustomTypeface
  183863. {
  183864. public:
  183865. WindowsTypeface (const Font& font)
  183866. {
  183867. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183868. font.isBold(), font.isItalic(), 0);
  183869. TEXTMETRIC tm;
  183870. tm.tmAscent = tm.tmHeight = 1;
  183871. tm.tmDefaultChar = 0;
  183872. GetTextMetrics (dc, &tm);
  183873. setCharacteristics (font.getTypefaceName(),
  183874. tm.tmAscent / (float) tm.tmHeight,
  183875. font.isBold(), font.isItalic(),
  183876. tm.tmDefaultChar);
  183877. }
  183878. bool loadGlyphIfPossible (const juce_wchar character)
  183879. {
  183880. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183881. GLYPHMETRICS gm;
  183882. {
  183883. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183884. WORD index = 0;
  183885. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183886. && index == 0xffff)
  183887. {
  183888. return false;
  183889. }
  183890. }
  183891. Path glyphPath;
  183892. TEXTMETRIC tm;
  183893. if (! GetTextMetrics (dc, &tm))
  183894. {
  183895. addGlyph (character, glyphPath, 0);
  183896. return true;
  183897. }
  183898. const float height = (float) tm.tmHeight;
  183899. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183900. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183901. &gm, 0, 0, &identityMatrix);
  183902. if (bufSize > 0)
  183903. {
  183904. HeapBlock<char> data (bufSize);
  183905. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183906. bufSize, data, &identityMatrix);
  183907. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183908. const float scaleX = 1.0f / height;
  183909. const float scaleY = -1.0f / height;
  183910. while ((char*) pheader < data + bufSize)
  183911. {
  183912. float x = scaleX * pheader->pfxStart.x.value;
  183913. float y = scaleY * pheader->pfxStart.y.value;
  183914. glyphPath.startNewSubPath (x, y);
  183915. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183916. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183917. while ((const char*) curve < curveEnd)
  183918. {
  183919. if (curve->wType == TT_PRIM_LINE)
  183920. {
  183921. for (int i = 0; i < curve->cpfx; ++i)
  183922. {
  183923. x = scaleX * curve->apfx[i].x.value;
  183924. y = scaleY * curve->apfx[i].y.value;
  183925. glyphPath.lineTo (x, y);
  183926. }
  183927. }
  183928. else if (curve->wType == TT_PRIM_QSPLINE)
  183929. {
  183930. for (int i = 0; i < curve->cpfx - 1; ++i)
  183931. {
  183932. const float x2 = scaleX * curve->apfx[i].x.value;
  183933. const float y2 = scaleY * curve->apfx[i].y.value;
  183934. float x3, y3;
  183935. if (i < curve->cpfx - 2)
  183936. {
  183937. x3 = 0.5f * (x2 + scaleX * curve->apfx[i + 1].x.value);
  183938. y3 = 0.5f * (y2 + scaleY * curve->apfx[i + 1].y.value);
  183939. }
  183940. else
  183941. {
  183942. x3 = scaleX * curve->apfx[i + 1].x.value;
  183943. y3 = scaleY * curve->apfx[i + 1].y.value;
  183944. }
  183945. glyphPath.quadraticTo (x2, y2, x3, y3);
  183946. x = x3;
  183947. y = y3;
  183948. }
  183949. }
  183950. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  183951. }
  183952. pheader = (const TTPOLYGONHEADER*) curve;
  183953. glyphPath.closeSubPath();
  183954. }
  183955. }
  183956. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  183957. int numKPs;
  183958. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  183959. for (int i = 0; i < numKPs; ++i)
  183960. {
  183961. if (kps[i].wFirst == character)
  183962. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  183963. kps[i].iKernAmount / height);
  183964. }
  183965. return true;
  183966. }
  183967. };
  183968. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  183969. {
  183970. return new WindowsTypeface (font);
  183971. }
  183972. #endif
  183973. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  183974. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  183975. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183976. // compiled on its own).
  183977. #if JUCE_INCLUDED_FILE
  183978. static const void* defaultDirPath = 0;
  183979. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  183980. static Component* currentExtraFileWin = 0;
  183981. static bool areThereAnyAlwaysOnTopWindows()
  183982. {
  183983. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  183984. {
  183985. Component* c = Desktop::getInstance().getComponent (i);
  183986. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  183987. return true;
  183988. }
  183989. return false;
  183990. }
  183991. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  183992. {
  183993. if (msg == BFFM_INITIALIZED)
  183994. {
  183995. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  183996. }
  183997. else if (msg == BFFM_VALIDATEFAILEDW)
  183998. {
  183999. returnedString = (LPCWSTR) lParam;
  184000. }
  184001. else if (msg == BFFM_VALIDATEFAILEDA)
  184002. {
  184003. returnedString = (const char*) lParam;
  184004. }
  184005. return 0;
  184006. }
  184007. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  184008. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  184009. {
  184010. if (currentExtraFileWin != 0)
  184011. {
  184012. if (uiMsg == WM_INITDIALOG)
  184013. {
  184014. HWND dialogH = GetParent (hdlg);
  184015. jassert (dialogH != 0);
  184016. if (dialogH == 0)
  184017. dialogH = hdlg;
  184018. RECT r, cr;
  184019. GetWindowRect (dialogH, &r);
  184020. GetClientRect (dialogH, &cr);
  184021. SetWindowPos (dialogH, 0,
  184022. r.left, r.top,
  184023. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  184024. jmax (150, (int) (r.bottom - r.top)),
  184025. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  184026. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  184027. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  184028. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  184029. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  184030. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  184031. }
  184032. else if (uiMsg == WM_NOTIFY)
  184033. {
  184034. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  184035. if (ofn->hdr.code == CDN_SELCHANGE)
  184036. {
  184037. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  184038. if (comp != 0)
  184039. {
  184040. TCHAR path [MAX_PATH * 2];
  184041. path[0] = 0;
  184042. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184043. const String fn ((const WCHAR*) path);
  184044. comp->selectedFileChanged (File (fn));
  184045. }
  184046. }
  184047. }
  184048. }
  184049. return 0;
  184050. }
  184051. class FPComponentHolder : public Component
  184052. {
  184053. public:
  184054. FPComponentHolder()
  184055. {
  184056. setVisible (true);
  184057. setOpaque (true);
  184058. }
  184059. ~FPComponentHolder()
  184060. {
  184061. }
  184062. void paint (Graphics& g)
  184063. {
  184064. g.fillAll (Colours::lightgrey);
  184065. }
  184066. private:
  184067. FPComponentHolder (const FPComponentHolder&);
  184068. FPComponentHolder& operator= (const FPComponentHolder&);
  184069. };
  184070. void FileChooser::showPlatformDialog (Array<File>& results,
  184071. const String& title,
  184072. const File& currentFileOrDirectory,
  184073. const String& filter,
  184074. bool selectsDirectory,
  184075. bool /*selectsFiles*/,
  184076. bool isSaveDialogue,
  184077. bool warnAboutOverwritingExistingFiles,
  184078. bool selectMultipleFiles,
  184079. FilePreviewComponent* extraInfoComponent)
  184080. {
  184081. const int numCharsAvailable = 32768;
  184082. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184083. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184084. int fnameIdx = 0;
  184085. JUCE_TRY
  184086. {
  184087. // use a modal window as the parent for this dialog box
  184088. // to block input from other app windows
  184089. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  184090. Component w (String::empty);
  184091. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184092. mainMon.getY() + mainMon.getHeight() / 4,
  184093. 0, 0);
  184094. w.setOpaque (true);
  184095. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184096. w.addToDesktop (0);
  184097. if (extraInfoComponent == 0)
  184098. w.enterModalState();
  184099. String initialDir;
  184100. if (currentFileOrDirectory.isDirectory())
  184101. {
  184102. initialDir = currentFileOrDirectory.getFullPathName();
  184103. }
  184104. else
  184105. {
  184106. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  184107. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184108. }
  184109. if (currentExtraFileWin->isValidComponent())
  184110. {
  184111. jassertfalse
  184112. return;
  184113. }
  184114. if (selectsDirectory)
  184115. {
  184116. LPITEMIDLIST list = 0;
  184117. filenameSpace.fillWith (0);
  184118. {
  184119. BROWSEINFO bi;
  184120. zerostruct (bi);
  184121. bi.hwndOwner = (HWND) w.getWindowHandle();
  184122. bi.pszDisplayName = fname;
  184123. bi.lpszTitle = title;
  184124. bi.lpfn = browseCallbackProc;
  184125. #ifdef BIF_USENEWUI
  184126. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184127. #else
  184128. bi.ulFlags = 0x50;
  184129. #endif
  184130. defaultDirPath = (const WCHAR*) initialDir;
  184131. list = SHBrowseForFolder (&bi);
  184132. if (! SHGetPathFromIDListW (list, fname))
  184133. {
  184134. fname[0] = 0;
  184135. returnedString = String::empty;
  184136. }
  184137. }
  184138. LPMALLOC al;
  184139. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184140. al->Free (list);
  184141. defaultDirPath = 0;
  184142. if (returnedString.isNotEmpty())
  184143. {
  184144. const String stringFName (fname);
  184145. results.add (File (stringFName).getSiblingFile (returnedString));
  184146. returnedString = String::empty;
  184147. return;
  184148. }
  184149. }
  184150. else
  184151. {
  184152. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184153. if (warnAboutOverwritingExistingFiles)
  184154. flags |= OFN_OVERWRITEPROMPT;
  184155. if (selectMultipleFiles)
  184156. flags |= OFN_ALLOWMULTISELECT;
  184157. if (extraInfoComponent != 0)
  184158. {
  184159. flags |= OFN_ENABLEHOOK;
  184160. currentExtraFileWin = new FPComponentHolder();
  184161. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184162. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184163. extraInfoComponent->getHeight());
  184164. currentExtraFileWin->addToDesktop (0);
  184165. currentExtraFileWin->enterModalState();
  184166. }
  184167. {
  184168. WCHAR filters [1024];
  184169. zeromem (filters, sizeof (filters));
  184170. filter.copyToUnicode (filters, 1024);
  184171. filter.copyToUnicode (filters + filter.length() + 1,
  184172. 1022 - filter.length());
  184173. OPENFILENAMEW of;
  184174. zerostruct (of);
  184175. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184176. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184177. #else
  184178. of.lStructSize = sizeof (of);
  184179. #endif
  184180. of.hwndOwner = (HWND) w.getWindowHandle();
  184181. of.lpstrFilter = filters;
  184182. of.nFilterIndex = 1;
  184183. of.lpstrFile = fname;
  184184. of.nMaxFile = numCharsAvailable;
  184185. of.lpstrInitialDir = initialDir;
  184186. of.lpstrTitle = title;
  184187. of.Flags = flags;
  184188. if (extraInfoComponent != 0)
  184189. of.lpfnHook = &openCallback;
  184190. if (isSaveDialogue)
  184191. {
  184192. if (! GetSaveFileName (&of))
  184193. fname[0] = 0;
  184194. else
  184195. fnameIdx = of.nFileOffset;
  184196. }
  184197. else
  184198. {
  184199. if (! GetOpenFileName (&of))
  184200. fname[0] = 0;
  184201. else
  184202. fnameIdx = of.nFileOffset;
  184203. }
  184204. }
  184205. }
  184206. }
  184207. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184208. catch (...)
  184209. {
  184210. fname[0] = 0;
  184211. }
  184212. #endif
  184213. deleteAndZero (currentExtraFileWin);
  184214. const WCHAR* const files = fname;
  184215. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184216. {
  184217. const WCHAR* filename = files + fnameIdx;
  184218. while (*filename != 0)
  184219. {
  184220. const String filepath (String (files) + T("\\") + String (filename));
  184221. results.add (File (filepath));
  184222. filename += CharacterFunctions::length (filename) + 1;
  184223. }
  184224. }
  184225. else if (files[0] != 0)
  184226. {
  184227. results.add (File (files));
  184228. }
  184229. }
  184230. #endif
  184231. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184232. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184233. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184234. // compiled on its own).
  184235. #if JUCE_INCLUDED_FILE
  184236. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184237. {
  184238. if (OpenClipboard (0) != 0)
  184239. {
  184240. if (EmptyClipboard() != 0)
  184241. {
  184242. const int len = text.length();
  184243. if (len > 0)
  184244. {
  184245. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184246. (len + 1) * sizeof (wchar_t));
  184247. if (bufH != 0)
  184248. {
  184249. WCHAR* const data = (WCHAR*) GlobalLock (bufH);
  184250. text.copyToUnicode (data, len);
  184251. GlobalUnlock (bufH);
  184252. SetClipboardData (CF_UNICODETEXT, bufH);
  184253. }
  184254. }
  184255. }
  184256. CloseClipboard();
  184257. }
  184258. }
  184259. const String SystemClipboard::getTextFromClipboard() throw()
  184260. {
  184261. String result;
  184262. if (OpenClipboard (0) != 0)
  184263. {
  184264. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184265. if (bufH != 0)
  184266. {
  184267. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184268. if (data != 0)
  184269. {
  184270. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184271. GlobalUnlock (bufH);
  184272. }
  184273. }
  184274. CloseClipboard();
  184275. }
  184276. return result;
  184277. }
  184278. #endif
  184279. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184280. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184281. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184282. // compiled on its own).
  184283. #if JUCE_INCLUDED_FILE
  184284. namespace ActiveXHelpers
  184285. {
  184286. class JuceIStorage : public IStorage
  184287. {
  184288. int refCount;
  184289. public:
  184290. JuceIStorage() : refCount (1) {}
  184291. virtual ~JuceIStorage()
  184292. {
  184293. jassert (refCount == 0);
  184294. }
  184295. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184296. {
  184297. if (id == IID_IUnknown || id == IID_IStorage)
  184298. {
  184299. AddRef();
  184300. *result = this;
  184301. return S_OK;
  184302. }
  184303. *result = 0;
  184304. return E_NOINTERFACE;
  184305. }
  184306. ULONG __stdcall AddRef() { return ++refCount; }
  184307. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184308. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184309. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184310. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184311. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184312. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184313. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184314. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184315. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184316. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184317. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184318. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184319. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184320. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184321. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184322. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184323. juce_UseDebuggingNewOperator
  184324. };
  184325. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184326. {
  184327. int refCount;
  184328. HWND window;
  184329. public:
  184330. JuceOleInPlaceFrame (HWND window_)
  184331. : refCount (1),
  184332. window (window_)
  184333. {
  184334. }
  184335. virtual ~JuceOleInPlaceFrame()
  184336. {
  184337. jassert (refCount == 0);
  184338. }
  184339. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184340. {
  184341. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184342. {
  184343. AddRef();
  184344. *result = this;
  184345. return S_OK;
  184346. }
  184347. *result = 0;
  184348. return E_NOINTERFACE;
  184349. }
  184350. ULONG __stdcall AddRef() { return ++refCount; }
  184351. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184352. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184353. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184354. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184355. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184356. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184357. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184358. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184359. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184360. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184361. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184362. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184363. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184364. juce_UseDebuggingNewOperator
  184365. };
  184366. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184367. {
  184368. int refCount;
  184369. HWND window;
  184370. JuceOleInPlaceFrame* frame;
  184371. public:
  184372. JuceIOleInPlaceSite (HWND window_)
  184373. : refCount (1),
  184374. window (window_)
  184375. {
  184376. frame = new JuceOleInPlaceFrame (window);
  184377. }
  184378. virtual ~JuceIOleInPlaceSite()
  184379. {
  184380. jassert (refCount == 0);
  184381. frame->Release();
  184382. }
  184383. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184384. {
  184385. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184386. {
  184387. AddRef();
  184388. *result = this;
  184389. return S_OK;
  184390. }
  184391. *result = 0;
  184392. return E_NOINTERFACE;
  184393. }
  184394. ULONG __stdcall AddRef() { return ++refCount; }
  184395. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184396. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184397. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184398. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184399. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184400. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184401. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184402. {
  184403. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184404. *lplpFrame = frame;
  184405. *lplpDoc = 0;
  184406. lpFrameInfo->fMDIApp = FALSE;
  184407. lpFrameInfo->hwndFrame = window;
  184408. lpFrameInfo->haccel = 0;
  184409. lpFrameInfo->cAccelEntries = 0;
  184410. return S_OK;
  184411. }
  184412. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184413. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184414. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184415. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184416. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184417. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184418. juce_UseDebuggingNewOperator
  184419. };
  184420. class JuceIOleClientSite : public IOleClientSite
  184421. {
  184422. int refCount;
  184423. JuceIOleInPlaceSite* inplaceSite;
  184424. public:
  184425. JuceIOleClientSite (HWND window)
  184426. : refCount (1)
  184427. {
  184428. inplaceSite = new JuceIOleInPlaceSite (window);
  184429. }
  184430. virtual ~JuceIOleClientSite()
  184431. {
  184432. jassert (refCount == 0);
  184433. inplaceSite->Release();
  184434. }
  184435. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184436. {
  184437. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184438. {
  184439. AddRef();
  184440. *result = this;
  184441. return S_OK;
  184442. }
  184443. else if (id == IID_IOleInPlaceSite)
  184444. {
  184445. inplaceSite->AddRef();
  184446. *result = inplaceSite;
  184447. return S_OK;
  184448. }
  184449. *result = 0;
  184450. return E_NOINTERFACE;
  184451. }
  184452. ULONG __stdcall AddRef() { return ++refCount; }
  184453. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184454. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184455. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184456. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184457. HRESULT __stdcall ShowObject() { return S_OK; }
  184458. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184459. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184460. juce_UseDebuggingNewOperator
  184461. };
  184462. static VoidArray activeXComps;
  184463. static HWND getHWND (const ActiveXControlComponent* const component)
  184464. {
  184465. HWND hwnd = 0;
  184466. const IID iid = IID_IOleWindow;
  184467. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184468. if (window != 0)
  184469. {
  184470. window->GetWindow (&hwnd);
  184471. window->Release();
  184472. }
  184473. return hwnd;
  184474. }
  184475. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184476. {
  184477. RECT activeXRect, peerRect;
  184478. GetWindowRect (hwnd, &activeXRect);
  184479. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184480. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184481. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184482. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184483. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184484. switch (message)
  184485. {
  184486. case WM_MOUSEMOVE:
  184487. case WM_LBUTTONDOWN:
  184488. case WM_MBUTTONDOWN:
  184489. case WM_RBUTTONDOWN:
  184490. case WM_LBUTTONUP:
  184491. case WM_MBUTTONUP:
  184492. case WM_RBUTTONUP:
  184493. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184494. break;
  184495. default:
  184496. break;
  184497. }
  184498. }
  184499. }
  184500. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184501. {
  184502. ActiveXControlComponent* const owner;
  184503. bool wasShowing;
  184504. public:
  184505. HWND controlHWND;
  184506. IStorage* storage;
  184507. IOleClientSite* clientSite;
  184508. IOleObject* control;
  184509. ActiveXControlData (HWND hwnd,
  184510. ActiveXControlComponent* const owner_)
  184511. : ComponentMovementWatcher (owner_),
  184512. owner (owner_),
  184513. wasShowing (owner_ != 0 && owner_->isShowing()),
  184514. controlHWND (0),
  184515. storage (new ActiveXHelpers::JuceIStorage()),
  184516. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184517. control (0)
  184518. {
  184519. }
  184520. ~ActiveXControlData()
  184521. {
  184522. if (control != 0)
  184523. {
  184524. control->Close (OLECLOSE_NOSAVE);
  184525. control->Release();
  184526. }
  184527. clientSite->Release();
  184528. storage->Release();
  184529. }
  184530. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184531. {
  184532. Component* const topComp = owner->getTopLevelComponent();
  184533. if (topComp->getPeer() != 0)
  184534. {
  184535. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184536. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184537. }
  184538. }
  184539. void componentPeerChanged()
  184540. {
  184541. const bool isShowingNow = owner->isShowing();
  184542. if (wasShowing != isShowingNow)
  184543. {
  184544. wasShowing = isShowingNow;
  184545. owner->setControlVisible (isShowingNow);
  184546. }
  184547. componentMovedOrResized (true, true);
  184548. }
  184549. void componentVisibilityChanged (Component&)
  184550. {
  184551. componentPeerChanged();
  184552. }
  184553. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184554. {
  184555. return ((ActiveXControlData*) ax->control) != 0
  184556. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184557. }
  184558. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184559. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184560. {
  184561. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184562. {
  184563. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184564. if (doesWindowMatch (ax, hwnd))
  184565. {
  184566. switch (message)
  184567. {
  184568. case WM_MOUSEMOVE:
  184569. case WM_LBUTTONDOWN:
  184570. case WM_MBUTTONDOWN:
  184571. case WM_RBUTTONDOWN:
  184572. case WM_LBUTTONUP:
  184573. case WM_MBUTTONUP:
  184574. case WM_RBUTTONUP:
  184575. case WM_LBUTTONDBLCLK:
  184576. case WM_MBUTTONDBLCLK:
  184577. case WM_RBUTTONDBLCLK:
  184578. if (ax->isShowing())
  184579. {
  184580. ComponentPeer* const peer = ax->getPeer();
  184581. if (peer != 0)
  184582. {
  184583. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184584. if (! ax->areMouseEventsAllowed())
  184585. return 0;
  184586. }
  184587. }
  184588. break;
  184589. default:
  184590. break;
  184591. }
  184592. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184593. }
  184594. }
  184595. return DefWindowProc (hwnd, message, wParam, lParam);
  184596. }
  184597. };
  184598. ActiveXControlComponent::ActiveXControlComponent()
  184599. : originalWndProc (0),
  184600. control (0),
  184601. mouseEventsAllowed (true)
  184602. {
  184603. ActiveXHelpers::activeXComps.add (this);
  184604. }
  184605. ActiveXControlComponent::~ActiveXControlComponent()
  184606. {
  184607. deleteControl();
  184608. ActiveXHelpers::activeXComps.removeValue (this);
  184609. }
  184610. void ActiveXControlComponent::paint (Graphics& g)
  184611. {
  184612. if (control == 0)
  184613. g.fillAll (Colours::lightgrey);
  184614. }
  184615. bool ActiveXControlComponent::createControl (const void* controlIID)
  184616. {
  184617. deleteControl();
  184618. ComponentPeer* const peer = getPeer();
  184619. // the component must have already been added to a real window when you call this!
  184620. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184621. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184622. {
  184623. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184624. HWND hwnd = (HWND) peer->getNativeHandle();
  184625. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184626. HRESULT hr;
  184627. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184628. info->clientSite, info->storage,
  184629. (void**) &(info->control))) == S_OK)
  184630. {
  184631. info->control->SetHostNames (L"Juce", 0);
  184632. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184633. {
  184634. RECT rect;
  184635. rect.left = pos.getX();
  184636. rect.top = pos.getY();
  184637. rect.right = pos.getX() + getWidth();
  184638. rect.bottom = pos.getY() + getHeight();
  184639. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184640. {
  184641. control = info.release();
  184642. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184643. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184644. if (((ActiveXControlData*) control)->controlHWND != 0)
  184645. {
  184646. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184647. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184648. }
  184649. return true;
  184650. }
  184651. }
  184652. }
  184653. }
  184654. return false;
  184655. }
  184656. void ActiveXControlComponent::deleteControl()
  184657. {
  184658. ActiveXControlData* const info = (ActiveXControlData*) control;
  184659. if (info != 0)
  184660. {
  184661. delete info;
  184662. control = 0;
  184663. originalWndProc = 0;
  184664. }
  184665. }
  184666. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184667. {
  184668. ActiveXControlData* const info = (ActiveXControlData*) control;
  184669. void* result = 0;
  184670. if (info != 0 && info->control != 0
  184671. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184672. return result;
  184673. return 0;
  184674. }
  184675. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184676. {
  184677. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184678. if (hwnd != 0)
  184679. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184680. }
  184681. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184682. {
  184683. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184684. if (hwnd != 0)
  184685. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184686. }
  184687. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184688. {
  184689. mouseEventsAllowed = eventsCanReachControl;
  184690. }
  184691. #endif
  184692. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184693. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184694. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184695. // compiled on its own).
  184696. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184697. using namespace QTOLibrary;
  184698. using namespace QTOControlLib;
  184699. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184700. static bool isQTAvailable = false;
  184701. class QuickTimeMovieComponent::Pimpl
  184702. {
  184703. public:
  184704. Pimpl() : dataHandle (0)
  184705. {
  184706. }
  184707. ~Pimpl()
  184708. {
  184709. clearHandle();
  184710. }
  184711. void clearHandle()
  184712. {
  184713. if (dataHandle != 0)
  184714. {
  184715. DisposeHandle (dataHandle);
  184716. dataHandle = 0;
  184717. }
  184718. }
  184719. IQTControlPtr qtControl;
  184720. IQTMoviePtr qtMovie;
  184721. Handle dataHandle;
  184722. };
  184723. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184724. : movieLoaded (false),
  184725. controllerVisible (true)
  184726. {
  184727. pimpl = new Pimpl();
  184728. setMouseEventsAllowed (false);
  184729. }
  184730. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184731. {
  184732. closeMovie();
  184733. pimpl->qtControl = 0;
  184734. deleteControl();
  184735. pimpl = 0;
  184736. }
  184737. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184738. {
  184739. if (! isQTAvailable)
  184740. isQTAvailable = (InitializeQTML (0) == noErr) && (EnterMovies() == noErr);
  184741. return isQTAvailable;
  184742. }
  184743. void QuickTimeMovieComponent::createControlIfNeeded()
  184744. {
  184745. if (isShowing() && ! isControlCreated())
  184746. {
  184747. const IID qtIID = __uuidof (QTControl);
  184748. if (createControl (&qtIID))
  184749. {
  184750. const IID qtInterfaceIID = __uuidof (IQTControl);
  184751. pimpl->qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184752. if (pimpl->qtControl != 0)
  184753. {
  184754. pimpl->qtControl->Release(); // it has one ref too many at this point
  184755. pimpl->qtControl->QuickTimeInitialize();
  184756. pimpl->qtControl->PutSizing (qtMovieFitsControl);
  184757. if (movieFile != File::nonexistent)
  184758. loadMovie (movieFile, controllerVisible);
  184759. }
  184760. }
  184761. }
  184762. }
  184763. bool QuickTimeMovieComponent::isControlCreated() const
  184764. {
  184765. return isControlOpen();
  184766. }
  184767. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184768. const bool isControllerVisible)
  184769. {
  184770. const ScopedPointer<InputStream> movieStreamDeleter (movieStream);
  184771. movieFile = File::nonexistent;
  184772. movieLoaded = false;
  184773. pimpl->qtMovie = 0;
  184774. controllerVisible = isControllerVisible;
  184775. createControlIfNeeded();
  184776. if (isControlCreated())
  184777. {
  184778. if (pimpl->qtControl != 0)
  184779. {
  184780. pimpl->qtControl->Put_MovieHandle (0);
  184781. pimpl->clearHandle();
  184782. Movie movie;
  184783. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, pimpl->dataHandle))
  184784. {
  184785. pimpl->qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184786. pimpl->qtMovie = pimpl->qtControl->GetMovie();
  184787. if (pimpl->qtMovie != 0)
  184788. pimpl->qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184789. : qtMovieControllerTypeNone);
  184790. }
  184791. if (movie == 0)
  184792. pimpl->clearHandle();
  184793. }
  184794. movieLoaded = (pimpl->qtMovie != 0);
  184795. }
  184796. else
  184797. {
  184798. // You're trying to open a movie when the control hasn't yet been created, probably because
  184799. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184800. jassertfalse
  184801. }
  184802. return movieLoaded;
  184803. }
  184804. void QuickTimeMovieComponent::closeMovie()
  184805. {
  184806. stop();
  184807. movieFile = File::nonexistent;
  184808. movieLoaded = false;
  184809. pimpl->qtMovie = 0;
  184810. if (pimpl->qtControl != 0)
  184811. pimpl->qtControl->Put_MovieHandle (0);
  184812. pimpl->clearHandle();
  184813. }
  184814. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184815. {
  184816. return movieFile;
  184817. }
  184818. bool QuickTimeMovieComponent::isMovieOpen() const
  184819. {
  184820. return movieLoaded;
  184821. }
  184822. double QuickTimeMovieComponent::getMovieDuration() const
  184823. {
  184824. if (pimpl->qtMovie != 0)
  184825. return pimpl->qtMovie->GetDuration() / (double) pimpl->qtMovie->GetTimeScale();
  184826. return 0.0;
  184827. }
  184828. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184829. {
  184830. if (pimpl->qtMovie != 0)
  184831. {
  184832. struct QTRECT r = pimpl->qtMovie->GetNaturalRect();
  184833. width = r.right - r.left;
  184834. height = r.bottom - r.top;
  184835. }
  184836. else
  184837. {
  184838. width = height = 0;
  184839. }
  184840. }
  184841. void QuickTimeMovieComponent::play()
  184842. {
  184843. if (pimpl->qtMovie != 0)
  184844. pimpl->qtMovie->Play();
  184845. }
  184846. void QuickTimeMovieComponent::stop()
  184847. {
  184848. if (pimpl->qtMovie != 0)
  184849. pimpl->qtMovie->Stop();
  184850. }
  184851. bool QuickTimeMovieComponent::isPlaying() const
  184852. {
  184853. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetRate() != 0.0f;
  184854. }
  184855. void QuickTimeMovieComponent::setPosition (const double seconds)
  184856. {
  184857. if (pimpl->qtMovie != 0)
  184858. pimpl->qtMovie->PutTime ((long) (seconds * pimpl->qtMovie->GetTimeScale()));
  184859. }
  184860. double QuickTimeMovieComponent::getPosition() const
  184861. {
  184862. if (pimpl->qtMovie != 0)
  184863. return pimpl->qtMovie->GetTime() / (double) pimpl->qtMovie->GetTimeScale();
  184864. return 0.0;
  184865. }
  184866. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184867. {
  184868. if (pimpl->qtMovie != 0)
  184869. pimpl->qtMovie->PutRate (newSpeed);
  184870. }
  184871. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184872. {
  184873. if (pimpl->qtMovie != 0)
  184874. {
  184875. pimpl->qtMovie->PutAudioVolume (newVolume);
  184876. pimpl->qtMovie->PutAudioMute (newVolume <= 0);
  184877. }
  184878. }
  184879. float QuickTimeMovieComponent::getMovieVolume() const
  184880. {
  184881. if (pimpl->qtMovie != 0)
  184882. return pimpl->qtMovie->GetAudioVolume();
  184883. return 0.0f;
  184884. }
  184885. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184886. {
  184887. if (pimpl->qtMovie != 0)
  184888. pimpl->qtMovie->PutLoop (shouldLoop);
  184889. }
  184890. bool QuickTimeMovieComponent::isLooping() const
  184891. {
  184892. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetLoop();
  184893. }
  184894. bool QuickTimeMovieComponent::isControllerVisible() const
  184895. {
  184896. return controllerVisible;
  184897. }
  184898. void QuickTimeMovieComponent::parentHierarchyChanged()
  184899. {
  184900. createControlIfNeeded();
  184901. QTCompBaseClass::parentHierarchyChanged();
  184902. }
  184903. void QuickTimeMovieComponent::visibilityChanged()
  184904. {
  184905. createControlIfNeeded();
  184906. QTCompBaseClass::visibilityChanged();
  184907. }
  184908. void QuickTimeMovieComponent::paint (Graphics& g)
  184909. {
  184910. if (! isControlCreated())
  184911. g.fillAll (Colours::black);
  184912. }
  184913. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184914. {
  184915. Handle dataRef = 0;
  184916. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184917. if (err == noErr)
  184918. {
  184919. Str255 suffix;
  184920. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184921. StringPtr name = suffix;
  184922. err = PtrAndHand (name, dataRef, name[0] + 1);
  184923. if (err == noErr)
  184924. {
  184925. long atoms[3];
  184926. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184927. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184928. atoms[2] = EndianU32_NtoB (MovieFileType);
  184929. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184930. if (err == noErr)
  184931. return dataRef;
  184932. }
  184933. DisposeHandle (dataRef);
  184934. }
  184935. return 0;
  184936. }
  184937. static CFStringRef juceStringToCFString (const String& s)
  184938. {
  184939. const int len = s.length();
  184940. const juce_wchar* const t = (const juce_wchar*) s;
  184941. HeapBlock <UniChar> temp (len + 2);
  184942. for (int i = 0; i <= len; ++i)
  184943. temp[i] = t[i];
  184944. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  184945. }
  184946. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  184947. {
  184948. Boolean trueBool = true;
  184949. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184950. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  184951. props[prop].propValueSize = sizeof (trueBool);
  184952. props[prop].propValueAddress = &trueBool;
  184953. ++prop;
  184954. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184955. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  184956. props[prop].propValueSize = sizeof (trueBool);
  184957. props[prop].propValueAddress = &trueBool;
  184958. ++prop;
  184959. Boolean isActive = true;
  184960. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  184961. props[prop].propID = kQTNewMoviePropertyID_Active;
  184962. props[prop].propValueSize = sizeof (isActive);
  184963. props[prop].propValueAddress = &isActive;
  184964. ++prop;
  184965. MacSetPort (0);
  184966. jassert (prop <= 5);
  184967. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  184968. return err == noErr;
  184969. }
  184970. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  184971. {
  184972. if (input == 0)
  184973. return false;
  184974. dataHandle = 0;
  184975. bool ok = false;
  184976. QTNewMoviePropertyElement props[5];
  184977. zeromem (props, sizeof (props));
  184978. int prop = 0;
  184979. DataReferenceRecord dr;
  184980. props[prop].propClass = kQTPropertyClass_DataLocation;
  184981. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  184982. props[prop].propValueSize = sizeof (dr);
  184983. props[prop].propValueAddress = (void*) &dr;
  184984. ++prop;
  184985. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  184986. if (fin != 0)
  184987. {
  184988. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  184989. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  184990. &dr.dataRef, &dr.dataRefType);
  184991. ok = openMovie (props, prop, movie);
  184992. DisposeHandle (dr.dataRef);
  184993. CFRelease (filePath);
  184994. }
  184995. else
  184996. {
  184997. // sanity-check because this currently needs to load the whole stream into memory..
  184998. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  184999. dataHandle = NewHandle ((Size) input->getTotalLength());
  185000. HLock (dataHandle);
  185001. // read the entire stream into memory - this is a pain, but can't get it to work
  185002. // properly using a custom callback to supply the data.
  185003. input->read (*dataHandle, (int) input->getTotalLength());
  185004. HUnlock (dataHandle);
  185005. // different types to get QT to try. (We should really be a bit smarter here by
  185006. // working out in advance which one the stream contains, rather than just trying
  185007. // each one)
  185008. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  185009. "\04.avi", "\04.m4a" };
  185010. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  185011. {
  185012. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  185013. dr.dataRefType = HandleDataHandlerSubType;
  185014. ok = openMovie (props, prop, movie);
  185015. DisposeHandle (dr.dataRef);
  185016. }
  185017. }
  185018. return ok;
  185019. }
  185020. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  185021. const bool isControllerVisible)
  185022. {
  185023. const bool ok = loadMovie (static_cast <InputStream*> (movieFile_.createInputStream()), isControllerVisible);
  185024. movieFile = movieFile_;
  185025. return ok;
  185026. }
  185027. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  185028. const bool isControllerVisible)
  185029. {
  185030. return loadMovie (static_cast <InputStream*> (movieURL.createInputStream (false)), isControllerVisible);
  185031. }
  185032. void QuickTimeMovieComponent::goToStart()
  185033. {
  185034. setPosition (0.0);
  185035. }
  185036. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  185037. const RectanglePlacement& placement)
  185038. {
  185039. int normalWidth, normalHeight;
  185040. getMovieNormalSize (normalWidth, normalHeight);
  185041. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185042. {
  185043. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185044. placement.applyTo (x, y, w, h,
  185045. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185046. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185047. if (w > 0 && h > 0)
  185048. {
  185049. setBounds (roundToInt (x), roundToInt (y),
  185050. roundToInt (w), roundToInt (h));
  185051. }
  185052. }
  185053. else
  185054. {
  185055. setBounds (spaceToFitWithin);
  185056. }
  185057. }
  185058. #endif
  185059. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185060. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185061. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185062. // compiled on its own).
  185063. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185064. class WebBrowserComponentInternal : public ActiveXControlComponent
  185065. {
  185066. public:
  185067. WebBrowserComponentInternal()
  185068. : browser (0),
  185069. connectionPoint (0),
  185070. adviseCookie (0)
  185071. {
  185072. }
  185073. ~WebBrowserComponentInternal()
  185074. {
  185075. if (connectionPoint != 0)
  185076. connectionPoint->Unadvise (adviseCookie);
  185077. if (browser != 0)
  185078. browser->Release();
  185079. }
  185080. void createBrowser()
  185081. {
  185082. createControl (&CLSID_WebBrowser);
  185083. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185084. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185085. if (connectionPointContainer != 0)
  185086. {
  185087. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185088. &connectionPoint);
  185089. if (connectionPoint != 0)
  185090. {
  185091. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185092. jassert (owner != 0);
  185093. EventHandler* handler = new EventHandler (owner);
  185094. connectionPoint->Advise (handler, &adviseCookie);
  185095. }
  185096. }
  185097. }
  185098. void goToURL (const String& url,
  185099. const StringArray* headers,
  185100. const MemoryBlock* postData)
  185101. {
  185102. if (browser != 0)
  185103. {
  185104. LPSAFEARRAY sa = 0;
  185105. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185106. VariantInit (&flags);
  185107. VariantInit (&frame);
  185108. VariantInit (&postDataVar);
  185109. VariantInit (&headersVar);
  185110. if (headers != 0)
  185111. {
  185112. V_VT (&headersVar) = VT_BSTR;
  185113. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185114. }
  185115. if (postData != 0 && postData->getSize() > 0)
  185116. {
  185117. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185118. if (sa != 0)
  185119. {
  185120. void* data = 0;
  185121. SafeArrayAccessData (sa, &data);
  185122. jassert (data != 0);
  185123. if (data != 0)
  185124. {
  185125. postData->copyTo (data, 0, postData->getSize());
  185126. SafeArrayUnaccessData (sa);
  185127. VARIANT postDataVar2;
  185128. VariantInit (&postDataVar2);
  185129. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185130. V_ARRAY (&postDataVar2) = sa;
  185131. postDataVar = postDataVar2;
  185132. }
  185133. }
  185134. }
  185135. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185136. &flags, &frame,
  185137. &postDataVar, &headersVar);
  185138. if (sa != 0)
  185139. SafeArrayDestroy (sa);
  185140. VariantClear (&flags);
  185141. VariantClear (&frame);
  185142. VariantClear (&postDataVar);
  185143. VariantClear (&headersVar);
  185144. }
  185145. }
  185146. IWebBrowser2* browser;
  185147. juce_UseDebuggingNewOperator
  185148. private:
  185149. IConnectionPoint* connectionPoint;
  185150. DWORD adviseCookie;
  185151. class EventHandler : public IDispatch,
  185152. public ComponentMovementWatcher
  185153. {
  185154. public:
  185155. EventHandler (WebBrowserComponent* owner_)
  185156. : ComponentMovementWatcher (owner_),
  185157. owner (owner_),
  185158. refCount (0)
  185159. {
  185160. }
  185161. ~EventHandler()
  185162. {
  185163. }
  185164. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185165. {
  185166. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185167. {
  185168. AddRef();
  185169. *result = this;
  185170. return S_OK;
  185171. }
  185172. *result = 0;
  185173. return E_NOINTERFACE;
  185174. }
  185175. ULONG __stdcall AddRef() { return ++refCount; }
  185176. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185177. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185178. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185179. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185180. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185181. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185182. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185183. UINT __RPC_FAR* /*puArgErr*/)
  185184. {
  185185. switch (dispIdMember)
  185186. {
  185187. case DISPID_BEFORENAVIGATE2:
  185188. {
  185189. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185190. String url;
  185191. if ((vurl->vt & VT_BYREF) != 0)
  185192. url = *vurl->pbstrVal;
  185193. else
  185194. url = vurl->bstrVal;
  185195. *pDispParams->rgvarg->pboolVal
  185196. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185197. : VARIANT_TRUE;
  185198. return S_OK;
  185199. }
  185200. default:
  185201. break;
  185202. }
  185203. return E_NOTIMPL;
  185204. }
  185205. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185206. void componentPeerChanged() {}
  185207. void componentVisibilityChanged (Component&)
  185208. {
  185209. owner->visibilityChanged();
  185210. }
  185211. juce_UseDebuggingNewOperator
  185212. private:
  185213. WebBrowserComponent* const owner;
  185214. int refCount;
  185215. EventHandler (const EventHandler&);
  185216. EventHandler& operator= (const EventHandler&);
  185217. };
  185218. };
  185219. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185220. : browser (0),
  185221. blankPageShown (false),
  185222. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185223. {
  185224. setOpaque (true);
  185225. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185226. }
  185227. WebBrowserComponent::~WebBrowserComponent()
  185228. {
  185229. delete browser;
  185230. }
  185231. void WebBrowserComponent::goToURL (const String& url,
  185232. const StringArray* headers,
  185233. const MemoryBlock* postData)
  185234. {
  185235. lastURL = url;
  185236. lastHeaders.clear();
  185237. if (headers != 0)
  185238. lastHeaders = *headers;
  185239. lastPostData.setSize (0);
  185240. if (postData != 0)
  185241. lastPostData = *postData;
  185242. blankPageShown = false;
  185243. browser->goToURL (url, headers, postData);
  185244. }
  185245. void WebBrowserComponent::stop()
  185246. {
  185247. if (browser->browser != 0)
  185248. browser->browser->Stop();
  185249. }
  185250. void WebBrowserComponent::goBack()
  185251. {
  185252. lastURL = String::empty;
  185253. blankPageShown = false;
  185254. if (browser->browser != 0)
  185255. browser->browser->GoBack();
  185256. }
  185257. void WebBrowserComponent::goForward()
  185258. {
  185259. lastURL = String::empty;
  185260. if (browser->browser != 0)
  185261. browser->browser->GoForward();
  185262. }
  185263. void WebBrowserComponent::refresh()
  185264. {
  185265. if (browser->browser != 0)
  185266. browser->browser->Refresh();
  185267. }
  185268. void WebBrowserComponent::paint (Graphics& g)
  185269. {
  185270. if (browser->browser == 0)
  185271. g.fillAll (Colours::white);
  185272. }
  185273. void WebBrowserComponent::checkWindowAssociation()
  185274. {
  185275. if (isShowing())
  185276. {
  185277. if (browser->browser == 0 && getPeer() != 0)
  185278. {
  185279. browser->createBrowser();
  185280. reloadLastURL();
  185281. }
  185282. else
  185283. {
  185284. if (blankPageShown)
  185285. goBack();
  185286. }
  185287. }
  185288. else
  185289. {
  185290. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185291. {
  185292. // when the component becomes invisible, some stuff like flash
  185293. // carries on playing audio, so we need to force it onto a blank
  185294. // page to avoid this..
  185295. blankPageShown = true;
  185296. browser->goToURL ("about:blank", 0, 0);
  185297. }
  185298. }
  185299. }
  185300. void WebBrowserComponent::reloadLastURL()
  185301. {
  185302. if (lastURL.isNotEmpty())
  185303. {
  185304. goToURL (lastURL, &lastHeaders, &lastPostData);
  185305. lastURL = String::empty;
  185306. }
  185307. }
  185308. void WebBrowserComponent::parentHierarchyChanged()
  185309. {
  185310. checkWindowAssociation();
  185311. }
  185312. void WebBrowserComponent::resized()
  185313. {
  185314. browser->setSize (getWidth(), getHeight());
  185315. }
  185316. void WebBrowserComponent::visibilityChanged()
  185317. {
  185318. checkWindowAssociation();
  185319. }
  185320. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185321. {
  185322. return true;
  185323. }
  185324. #endif
  185325. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185326. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185327. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185328. // compiled on its own).
  185329. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185330. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185331. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185332. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185333. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185334. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185335. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185336. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185337. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185338. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185339. #define WGL_ACCELERATION_ARB 0x2003
  185340. #define WGL_SWAP_METHOD_ARB 0x2007
  185341. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185342. #define WGL_PIXEL_TYPE_ARB 0x2013
  185343. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185344. #define WGL_COLOR_BITS_ARB 0x2014
  185345. #define WGL_RED_BITS_ARB 0x2015
  185346. #define WGL_GREEN_BITS_ARB 0x2017
  185347. #define WGL_BLUE_BITS_ARB 0x2019
  185348. #define WGL_ALPHA_BITS_ARB 0x201B
  185349. #define WGL_DEPTH_BITS_ARB 0x2022
  185350. #define WGL_STENCIL_BITS_ARB 0x2023
  185351. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185352. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185353. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185354. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185355. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185356. #define WGL_STEREO_ARB 0x2012
  185357. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185358. #define WGL_SAMPLES_ARB 0x2042
  185359. #define WGL_TYPE_RGBA_ARB 0x202B
  185360. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185361. {
  185362. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185363. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185364. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185365. else
  185366. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185367. }
  185368. class WindowedGLContext : public OpenGLContext
  185369. {
  185370. public:
  185371. WindowedGLContext (Component* const component_,
  185372. HGLRC contextToShareWith,
  185373. const OpenGLPixelFormat& pixelFormat)
  185374. : renderContext (0),
  185375. nativeWindow (0),
  185376. dc (0),
  185377. component (component_)
  185378. {
  185379. jassert (component != 0);
  185380. createNativeWindow();
  185381. // Use a default pixel format that should be supported everywhere
  185382. PIXELFORMATDESCRIPTOR pfd;
  185383. zerostruct (pfd);
  185384. pfd.nSize = sizeof (pfd);
  185385. pfd.nVersion = 1;
  185386. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185387. pfd.iPixelType = PFD_TYPE_RGBA;
  185388. pfd.cColorBits = 24;
  185389. pfd.cDepthBits = 16;
  185390. const int format = ChoosePixelFormat (dc, &pfd);
  185391. if (format != 0)
  185392. SetPixelFormat (dc, format, &pfd);
  185393. renderContext = wglCreateContext (dc);
  185394. makeActive();
  185395. setPixelFormat (pixelFormat);
  185396. if (contextToShareWith != 0 && renderContext != 0)
  185397. wglShareLists (contextToShareWith, renderContext);
  185398. }
  185399. ~WindowedGLContext()
  185400. {
  185401. makeInactive();
  185402. wglDeleteContext (renderContext);
  185403. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185404. delete nativeWindow;
  185405. }
  185406. bool makeActive() const throw()
  185407. {
  185408. jassert (renderContext != 0);
  185409. return wglMakeCurrent (dc, renderContext) != 0;
  185410. }
  185411. bool makeInactive() const throw()
  185412. {
  185413. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185414. }
  185415. bool isActive() const throw()
  185416. {
  185417. return wglGetCurrentContext() == renderContext;
  185418. }
  185419. const OpenGLPixelFormat getPixelFormat() const
  185420. {
  185421. OpenGLPixelFormat pf;
  185422. makeActive();
  185423. StringArray availableExtensions;
  185424. getWglExtensions (dc, availableExtensions);
  185425. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185426. return pf;
  185427. }
  185428. void* getRawContext() const throw()
  185429. {
  185430. return renderContext;
  185431. }
  185432. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185433. {
  185434. makeActive();
  185435. PIXELFORMATDESCRIPTOR pfd;
  185436. zerostruct (pfd);
  185437. pfd.nSize = sizeof (pfd);
  185438. pfd.nVersion = 1;
  185439. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185440. pfd.iPixelType = PFD_TYPE_RGBA;
  185441. pfd.iLayerType = PFD_MAIN_PLANE;
  185442. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185443. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185444. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185445. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185446. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185447. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185448. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185449. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185450. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185451. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185452. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185453. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185454. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185455. int format = 0;
  185456. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185457. StringArray availableExtensions;
  185458. getWglExtensions (dc, availableExtensions);
  185459. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185460. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185461. {
  185462. int attributes[64];
  185463. int n = 0;
  185464. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185465. attributes[n++] = GL_TRUE;
  185466. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185467. attributes[n++] = GL_TRUE;
  185468. attributes[n++] = WGL_ACCELERATION_ARB;
  185469. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185470. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185471. attributes[n++] = GL_TRUE;
  185472. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185473. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185474. attributes[n++] = WGL_COLOR_BITS_ARB;
  185475. attributes[n++] = pfd.cColorBits;
  185476. attributes[n++] = WGL_RED_BITS_ARB;
  185477. attributes[n++] = pixelFormat.redBits;
  185478. attributes[n++] = WGL_GREEN_BITS_ARB;
  185479. attributes[n++] = pixelFormat.greenBits;
  185480. attributes[n++] = WGL_BLUE_BITS_ARB;
  185481. attributes[n++] = pixelFormat.blueBits;
  185482. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185483. attributes[n++] = pixelFormat.alphaBits;
  185484. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185485. attributes[n++] = pixelFormat.depthBufferBits;
  185486. if (pixelFormat.stencilBufferBits > 0)
  185487. {
  185488. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185489. attributes[n++] = pixelFormat.stencilBufferBits;
  185490. }
  185491. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185492. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185493. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185494. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185495. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185496. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185497. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185498. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185499. if (availableExtensions.contains ("WGL_ARB_multisample")
  185500. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185501. {
  185502. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185503. attributes[n++] = 1;
  185504. attributes[n++] = WGL_SAMPLES_ARB;
  185505. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185506. }
  185507. attributes[n++] = 0;
  185508. UINT formatsCount;
  185509. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185510. (void) ok;
  185511. jassert (ok);
  185512. }
  185513. else
  185514. {
  185515. format = ChoosePixelFormat (dc, &pfd);
  185516. }
  185517. if (format != 0)
  185518. {
  185519. makeInactive();
  185520. // win32 can't change the pixel format of a window, so need to delete the
  185521. // old one and create a new one..
  185522. jassert (nativeWindow != 0);
  185523. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185524. delete nativeWindow;
  185525. createNativeWindow();
  185526. if (SetPixelFormat (dc, format, &pfd))
  185527. {
  185528. wglDeleteContext (renderContext);
  185529. renderContext = wglCreateContext (dc);
  185530. jassert (renderContext != 0);
  185531. return renderContext != 0;
  185532. }
  185533. }
  185534. return false;
  185535. }
  185536. void updateWindowPosition (int x, int y, int w, int h, int)
  185537. {
  185538. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185539. x, y, w, h,
  185540. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185541. }
  185542. void repaint()
  185543. {
  185544. const Rectangle<int> bounds (nativeWindow->getBounds());
  185545. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185546. }
  185547. void swapBuffers()
  185548. {
  185549. SwapBuffers (dc);
  185550. }
  185551. bool setSwapInterval (const int numFramesPerSwap)
  185552. {
  185553. makeActive();
  185554. StringArray availableExtensions;
  185555. getWglExtensions (dc, availableExtensions);
  185556. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185557. return availableExtensions.contains ("WGL_EXT_swap_control")
  185558. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185559. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185560. }
  185561. int getSwapInterval() const
  185562. {
  185563. makeActive();
  185564. StringArray availableExtensions;
  185565. getWglExtensions (dc, availableExtensions);
  185566. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185567. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185568. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185569. return wglGetSwapIntervalEXT();
  185570. return 0;
  185571. }
  185572. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185573. {
  185574. jassert (isActive());
  185575. StringArray availableExtensions;
  185576. getWglExtensions (dc, availableExtensions);
  185577. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185578. int numTypes = 0;
  185579. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185580. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185581. {
  185582. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185583. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185584. jassertfalse
  185585. }
  185586. else
  185587. {
  185588. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185589. }
  185590. OpenGLPixelFormat pf;
  185591. for (int i = 0; i < numTypes; ++i)
  185592. {
  185593. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185594. {
  185595. bool alreadyListed = false;
  185596. for (int j = results.size(); --j >= 0;)
  185597. if (pf == *results.getUnchecked(j))
  185598. alreadyListed = true;
  185599. if (! alreadyListed)
  185600. results.add (new OpenGLPixelFormat (pf));
  185601. }
  185602. }
  185603. }
  185604. void* getNativeWindowHandle() const
  185605. {
  185606. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185607. }
  185608. juce_UseDebuggingNewOperator
  185609. HGLRC renderContext;
  185610. private:
  185611. Win32ComponentPeer* nativeWindow;
  185612. Component* const component;
  185613. HDC dc;
  185614. void createNativeWindow()
  185615. {
  185616. nativeWindow = new Win32ComponentPeer (component, 0);
  185617. nativeWindow->dontRepaint = true;
  185618. nativeWindow->setVisible (true);
  185619. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185620. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185621. if (peer != 0)
  185622. {
  185623. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185624. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185625. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185626. }
  185627. dc = GetDC (hwnd);
  185628. }
  185629. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185630. OpenGLPixelFormat& result,
  185631. const StringArray& availableExtensions) const throw()
  185632. {
  185633. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185634. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185635. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185636. {
  185637. int attributes[32];
  185638. int numAttributes = 0;
  185639. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185640. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185641. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185642. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185643. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185644. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185645. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185646. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185647. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185648. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185649. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185650. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185651. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185652. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185653. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185654. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185655. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185656. int values[32];
  185657. zeromem (values, sizeof (values));
  185658. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185659. {
  185660. int n = 0;
  185661. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185662. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185663. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185664. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185665. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185666. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185667. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185668. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185669. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185670. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185671. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185672. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185673. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185674. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185675. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185676. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185677. return isValidFormat;
  185678. }
  185679. else
  185680. {
  185681. jassertfalse
  185682. }
  185683. }
  185684. else
  185685. {
  185686. PIXELFORMATDESCRIPTOR pfd;
  185687. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185688. {
  185689. result.redBits = pfd.cRedBits;
  185690. result.greenBits = pfd.cGreenBits;
  185691. result.blueBits = pfd.cBlueBits;
  185692. result.alphaBits = pfd.cAlphaBits;
  185693. result.depthBufferBits = pfd.cDepthBits;
  185694. result.stencilBufferBits = pfd.cStencilBits;
  185695. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185696. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185697. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185698. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185699. result.fullSceneAntiAliasingNumSamples = 0;
  185700. return true;
  185701. }
  185702. else
  185703. {
  185704. jassertfalse
  185705. }
  185706. }
  185707. return false;
  185708. }
  185709. WindowedGLContext (const WindowedGLContext&);
  185710. WindowedGLContext& operator= (const WindowedGLContext&);
  185711. };
  185712. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  185713. const OpenGLPixelFormat& pixelFormat,
  185714. const OpenGLContext* const contextToShareWith)
  185715. {
  185716. WindowedGLContext* c = new WindowedGLContext (component,
  185717. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  185718. pixelFormat);
  185719. if (c->renderContext == 0)
  185720. deleteAndZero (c);
  185721. return c;
  185722. }
  185723. void* OpenGLComponent::getNativeWindowHandle() const
  185724. {
  185725. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  185726. }
  185727. void juce_glViewport (const int w, const int h)
  185728. {
  185729. glViewport (0, 0, w, h);
  185730. }
  185731. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185732. OwnedArray <OpenGLPixelFormat>& results)
  185733. {
  185734. Component tempComp;
  185735. {
  185736. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185737. wc.makeActive();
  185738. wc.findAlternativeOpenGLPixelFormats (results);
  185739. }
  185740. }
  185741. #endif
  185742. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185743. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185744. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185745. // compiled on its own).
  185746. #if JUCE_INCLUDED_FILE
  185747. #if JUCE_USE_CDREADER
  185748. namespace CDReaderHelpers
  185749. {
  185750. //***************************************************************************
  185751. // %%% TARGET STATUS VALUES %%%
  185752. //***************************************************************************
  185753. #define STATUS_GOOD 0x00 // Status Good
  185754. #define STATUS_CHKCOND 0x02 // Check Condition
  185755. #define STATUS_CONDMET 0x04 // Condition Met
  185756. #define STATUS_BUSY 0x08 // Busy
  185757. #define STATUS_INTERM 0x10 // Intermediate
  185758. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185759. #define STATUS_RESCONF 0x18 // Reservation conflict
  185760. #define STATUS_COMTERM 0x22 // Command Terminated
  185761. #define STATUS_QFULL 0x28 // Queue full
  185762. //***************************************************************************
  185763. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185764. //***************************************************************************
  185765. #define MAXLUN 7 // Maximum Logical Unit Id
  185766. #define MAXTARG 7 // Maximum Target Id
  185767. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185768. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185769. //***************************************************************************
  185770. // %%% Commands for all Device Types %%%
  185771. //***************************************************************************
  185772. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185773. #define SCSI_COMPARE 0x39 // Compare (O)
  185774. #define SCSI_COPY 0x18 // Copy (O)
  185775. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185776. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185777. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185778. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185779. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185780. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185781. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185782. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185783. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185784. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185785. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185786. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185787. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185788. //***************************************************************************
  185789. // %%% Commands Unique to Direct Access Devices %%%
  185790. //***************************************************************************
  185791. #define SCSI_COMPARE 0x39 // Compare (O)
  185792. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185793. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185794. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185795. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185796. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185797. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185798. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185799. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185800. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185801. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185802. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185803. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185804. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185805. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185806. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185807. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185808. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185809. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185810. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185811. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185812. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185813. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185814. #define SCSI_VERIFY 0x2F // Verify (O)
  185815. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185816. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185817. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185818. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185819. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185820. //***************************************************************************
  185821. // %%% Commands Unique to Sequential Access Devices %%%
  185822. //***************************************************************************
  185823. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185824. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185825. #define SCSI_LOCATE 0x2B // Locate (O)
  185826. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185827. #define SCSI_READ_POS 0x34 // Read Position (O)
  185828. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185829. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185830. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185831. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185832. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185833. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185834. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185835. //***************************************************************************
  185836. // %%% Commands Unique to Printer Devices %%%
  185837. //***************************************************************************
  185838. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185839. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185840. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185841. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185842. //***************************************************************************
  185843. // %%% Commands Unique to Processor Devices %%%
  185844. //***************************************************************************
  185845. #define SCSI_RECEIVE 0x08 // Receive (O)
  185846. #define SCSI_SEND 0x0A // Send (O)
  185847. //***************************************************************************
  185848. // %%% Commands Unique to Write-Once Devices %%%
  185849. //***************************************************************************
  185850. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185851. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185852. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185853. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185854. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185855. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185856. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185857. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185858. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185859. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185860. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185861. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185862. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185863. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185864. //***************************************************************************
  185865. // %%% Commands Unique to CD-ROM Devices %%%
  185866. //***************************************************************************
  185867. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185868. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185869. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185870. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185871. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185872. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185873. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185874. #define SCSI_READHEADER 0x44 // Read Header (O)
  185875. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185876. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185877. //***************************************************************************
  185878. // %%% Commands Unique to Scanner Devices %%%
  185879. //***************************************************************************
  185880. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185881. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185882. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185883. #define SCSI_SCAN 0x1B // Scan (O)
  185884. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185885. //***************************************************************************
  185886. // %%% Commands Unique to Optical Memory Devices %%%
  185887. //***************************************************************************
  185888. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185889. //***************************************************************************
  185890. // %%% Commands Unique to Medium Changer Devices %%%
  185891. //***************************************************************************
  185892. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185893. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185894. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185895. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185896. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185897. //***************************************************************************
  185898. // %%% Commands Unique to Communication Devices %%%
  185899. //***************************************************************************
  185900. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185901. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185902. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185903. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185904. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185905. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185906. //***************************************************************************
  185907. // %%% Request Sense Data Format %%%
  185908. //***************************************************************************
  185909. typedef struct {
  185910. BYTE ErrorCode; // Error Code (70H or 71H)
  185911. BYTE SegmentNum; // Number of current segment descriptor
  185912. BYTE SenseKey; // Sense Key(See bit definitions too)
  185913. BYTE InfoByte0; // Information MSB
  185914. BYTE InfoByte1; // Information MID
  185915. BYTE InfoByte2; // Information MID
  185916. BYTE InfoByte3; // Information LSB
  185917. BYTE AddSenLen; // Additional Sense Length
  185918. BYTE ComSpecInf0; // Command Specific Information MSB
  185919. BYTE ComSpecInf1; // Command Specific Information MID
  185920. BYTE ComSpecInf2; // Command Specific Information MID
  185921. BYTE ComSpecInf3; // Command Specific Information LSB
  185922. BYTE AddSenseCode; // Additional Sense Code
  185923. BYTE AddSenQual; // Additional Sense Code Qualifier
  185924. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185925. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185926. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185927. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185928. BYTE AddSenseBytes; // Additional Sense Bytes
  185929. } SENSE_DATA_FMT;
  185930. //***************************************************************************
  185931. // %%% REQUEST SENSE ERROR CODE %%%
  185932. //***************************************************************************
  185933. #define SERROR_CURRENT 0x70 // Current Errors
  185934. #define SERROR_DEFERED 0x71 // Deferred Errors
  185935. //***************************************************************************
  185936. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  185937. //***************************************************************************
  185938. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  185939. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  185940. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  185941. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  185942. //***************************************************************************
  185943. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  185944. //***************************************************************************
  185945. #define KEY_NOSENSE 0x00 // No Sense
  185946. #define KEY_RECERROR 0x01 // Recovered Error
  185947. #define KEY_NOTREADY 0x02 // Not Ready
  185948. #define KEY_MEDIUMERR 0x03 // Medium Error
  185949. #define KEY_HARDERROR 0x04 // Hardware Error
  185950. #define KEY_ILLGLREQ 0x05 // Illegal Request
  185951. #define KEY_UNITATT 0x06 // Unit Attention
  185952. #define KEY_DATAPROT 0x07 // Data Protect
  185953. #define KEY_BLANKCHK 0x08 // Blank Check
  185954. #define KEY_VENDSPEC 0x09 // Vendor Specific
  185955. #define KEY_COPYABORT 0x0A // Copy Abort
  185956. #define KEY_EQUAL 0x0C // Equal (Search)
  185957. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  185958. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  185959. #define KEY_RESERVED 0x0F // Reserved
  185960. //***************************************************************************
  185961. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  185962. //***************************************************************************
  185963. #define DTYPE_DASD 0x00 // Disk Device
  185964. #define DTYPE_SEQD 0x01 // Tape Device
  185965. #define DTYPE_PRNT 0x02 // Printer
  185966. #define DTYPE_PROC 0x03 // Processor
  185967. #define DTYPE_WORM 0x04 // Write-once read-multiple
  185968. #define DTYPE_CROM 0x05 // CD-ROM device
  185969. #define DTYPE_SCAN 0x06 // Scanner device
  185970. #define DTYPE_OPTI 0x07 // Optical memory device
  185971. #define DTYPE_JUKE 0x08 // Medium Changer device
  185972. #define DTYPE_COMM 0x09 // Communications device
  185973. #define DTYPE_RESL 0x0A // Reserved (low)
  185974. #define DTYPE_RESH 0x1E // Reserved (high)
  185975. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  185976. //***************************************************************************
  185977. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  185978. //***************************************************************************
  185979. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  185980. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  185981. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  185982. #define ANSI_RESLO 0x3 // Reserved (low)
  185983. #define ANSI_RESHI 0x7 // Reserved (high)
  185984. typedef struct
  185985. {
  185986. USHORT Length;
  185987. UCHAR ScsiStatus;
  185988. UCHAR PathId;
  185989. UCHAR TargetId;
  185990. UCHAR Lun;
  185991. UCHAR CdbLength;
  185992. UCHAR SenseInfoLength;
  185993. UCHAR DataIn;
  185994. ULONG DataTransferLength;
  185995. ULONG TimeOutValue;
  185996. ULONG DataBufferOffset;
  185997. ULONG SenseInfoOffset;
  185998. UCHAR Cdb[16];
  185999. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  186000. typedef struct
  186001. {
  186002. USHORT Length;
  186003. UCHAR ScsiStatus;
  186004. UCHAR PathId;
  186005. UCHAR TargetId;
  186006. UCHAR Lun;
  186007. UCHAR CdbLength;
  186008. UCHAR SenseInfoLength;
  186009. UCHAR DataIn;
  186010. ULONG DataTransferLength;
  186011. ULONG TimeOutValue;
  186012. PVOID DataBuffer;
  186013. ULONG SenseInfoOffset;
  186014. UCHAR Cdb[16];
  186015. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  186016. typedef struct
  186017. {
  186018. SCSI_PASS_THROUGH_DIRECT spt;
  186019. ULONG Filler;
  186020. UCHAR ucSenseBuf[32];
  186021. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  186022. typedef struct
  186023. {
  186024. ULONG Length;
  186025. UCHAR PortNumber;
  186026. UCHAR PathId;
  186027. UCHAR TargetId;
  186028. UCHAR Lun;
  186029. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  186030. #define METHOD_BUFFERED 0
  186031. #define METHOD_IN_DIRECT 1
  186032. #define METHOD_OUT_DIRECT 2
  186033. #define METHOD_NEITHER 3
  186034. #define FILE_ANY_ACCESS 0
  186035. #ifndef FILE_READ_ACCESS
  186036. #define FILE_READ_ACCESS (0x0001)
  186037. #endif
  186038. #ifndef FILE_WRITE_ACCESS
  186039. #define FILE_WRITE_ACCESS (0x0002)
  186040. #endif
  186041. #define IOCTL_SCSI_BASE 0x00000004
  186042. #define SCSI_IOCTL_DATA_OUT 0
  186043. #define SCSI_IOCTL_DATA_IN 1
  186044. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186045. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186046. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186047. )
  186048. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186049. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186050. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186051. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186052. #define SENSE_LEN 14
  186053. #define SRB_DIR_SCSI 0x00
  186054. #define SRB_POSTING 0x01
  186055. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186056. #define SRB_DIR_IN 0x08
  186057. #define SRB_DIR_OUT 0x10
  186058. #define SRB_EVENT_NOTIFY 0x40
  186059. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186060. #define MAX_SRB_TIMEOUT 1080001u
  186061. #define DEFAULT_SRB_TIMEOUT 1080001u
  186062. #define SC_HA_INQUIRY 0x00
  186063. #define SC_GET_DEV_TYPE 0x01
  186064. #define SC_EXEC_SCSI_CMD 0x02
  186065. #define SC_ABORT_SRB 0x03
  186066. #define SC_RESET_DEV 0x04
  186067. #define SC_SET_HA_PARMS 0x05
  186068. #define SC_GET_DISK_INFO 0x06
  186069. #define SC_RESCAN_SCSI_BUS 0x07
  186070. #define SC_GETSET_TIMEOUTS 0x08
  186071. #define SS_PENDING 0x00
  186072. #define SS_COMP 0x01
  186073. #define SS_ABORTED 0x02
  186074. #define SS_ABORT_FAIL 0x03
  186075. #define SS_ERR 0x04
  186076. #define SS_INVALID_CMD 0x80
  186077. #define SS_INVALID_HA 0x81
  186078. #define SS_NO_DEVICE 0x82
  186079. #define SS_INVALID_SRB 0xE0
  186080. #define SS_OLD_MANAGER 0xE1
  186081. #define SS_BUFFER_ALIGN 0xE1
  186082. #define SS_ILLEGAL_MODE 0xE2
  186083. #define SS_NO_ASPI 0xE3
  186084. #define SS_FAILED_INIT 0xE4
  186085. #define SS_ASPI_IS_BUSY 0xE5
  186086. #define SS_BUFFER_TO_BIG 0xE6
  186087. #define SS_BUFFER_TOO_BIG 0xE6
  186088. #define SS_MISMATCHED_COMPONENTS 0xE7
  186089. #define SS_NO_ADAPTERS 0xE8
  186090. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186091. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186092. #define SS_BAD_INSTALL 0xEB
  186093. #define HASTAT_OK 0x00
  186094. #define HASTAT_SEL_TO 0x11
  186095. #define HASTAT_DO_DU 0x12
  186096. #define HASTAT_BUS_FREE 0x13
  186097. #define HASTAT_PHASE_ERR 0x14
  186098. #define HASTAT_TIMEOUT 0x09
  186099. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186100. #define HASTAT_MESSAGE_REJECT 0x0D
  186101. #define HASTAT_BUS_RESET 0x0E
  186102. #define HASTAT_PARITY_ERROR 0x0F
  186103. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186104. #define PACKED
  186105. #pragma pack(1)
  186106. typedef struct
  186107. {
  186108. BYTE SRB_Cmd;
  186109. BYTE SRB_Status;
  186110. BYTE SRB_HaID;
  186111. BYTE SRB_Flags;
  186112. DWORD SRB_Hdr_Rsvd;
  186113. BYTE HA_Count;
  186114. BYTE HA_SCSI_ID;
  186115. BYTE HA_ManagerId[16];
  186116. BYTE HA_Identifier[16];
  186117. BYTE HA_Unique[16];
  186118. WORD HA_Rsvd1;
  186119. BYTE pad[20];
  186120. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186121. typedef struct
  186122. {
  186123. BYTE SRB_Cmd;
  186124. BYTE SRB_Status;
  186125. BYTE SRB_HaID;
  186126. BYTE SRB_Flags;
  186127. DWORD SRB_Hdr_Rsvd;
  186128. BYTE SRB_Target;
  186129. BYTE SRB_Lun;
  186130. BYTE SRB_DeviceType;
  186131. BYTE SRB_Rsvd1;
  186132. BYTE pad[68];
  186133. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186134. typedef struct
  186135. {
  186136. BYTE SRB_Cmd;
  186137. BYTE SRB_Status;
  186138. BYTE SRB_HaID;
  186139. BYTE SRB_Flags;
  186140. DWORD SRB_Hdr_Rsvd;
  186141. BYTE SRB_Target;
  186142. BYTE SRB_Lun;
  186143. WORD SRB_Rsvd1;
  186144. DWORD SRB_BufLen;
  186145. BYTE FAR *SRB_BufPointer;
  186146. BYTE SRB_SenseLen;
  186147. BYTE SRB_CDBLen;
  186148. BYTE SRB_HaStat;
  186149. BYTE SRB_TargStat;
  186150. VOID FAR *SRB_PostProc;
  186151. BYTE SRB_Rsvd2[20];
  186152. BYTE CDBByte[16];
  186153. BYTE SenseArea[SENSE_LEN+2];
  186154. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186155. typedef struct
  186156. {
  186157. BYTE SRB_Cmd;
  186158. BYTE SRB_Status;
  186159. BYTE SRB_HaId;
  186160. BYTE SRB_Flags;
  186161. DWORD SRB_Hdr_Rsvd;
  186162. } PACKED SRB, *PSRB, FAR *LPSRB;
  186163. #pragma pack()
  186164. struct CDDeviceInfo
  186165. {
  186166. char vendor[9];
  186167. char productId[17];
  186168. char rev[5];
  186169. char vendorSpec[21];
  186170. BYTE ha;
  186171. BYTE tgt;
  186172. BYTE lun;
  186173. char scsiDriveLetter; // will be 0 if not using scsi
  186174. };
  186175. class CDReadBuffer
  186176. {
  186177. public:
  186178. int startFrame;
  186179. int numFrames;
  186180. int dataStartOffset;
  186181. int dataLength;
  186182. BYTE* buffer;
  186183. int bufferSize;
  186184. int index;
  186185. bool wantsIndex;
  186186. CDReadBuffer (const int numberOfFrames)
  186187. : startFrame (0),
  186188. numFrames (0),
  186189. dataStartOffset (0),
  186190. dataLength (0),
  186191. index (0),
  186192. wantsIndex (false)
  186193. {
  186194. bufferSize = 2352 * numberOfFrames;
  186195. buffer = (BYTE*) juce_malloc (bufferSize);
  186196. }
  186197. ~CDReadBuffer()
  186198. {
  186199. juce_free (buffer);
  186200. }
  186201. bool isZero() const
  186202. {
  186203. BYTE* p = buffer + dataStartOffset;
  186204. for (int i = dataLength; --i >= 0;)
  186205. if (*p++ != 0)
  186206. return false;
  186207. return true;
  186208. }
  186209. };
  186210. class CDDeviceHandle;
  186211. class CDController
  186212. {
  186213. public:
  186214. CDController();
  186215. virtual ~CDController();
  186216. virtual bool read (CDReadBuffer* t) = 0;
  186217. virtual void shutDown();
  186218. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186219. int getLastIndex();
  186220. public:
  186221. bool initialised;
  186222. CDDeviceHandle* deviceInfo;
  186223. int framesToCheck, framesOverlap;
  186224. void prepare (SRB_ExecSCSICmd& s);
  186225. void perform (SRB_ExecSCSICmd& s);
  186226. void setPaused (bool paused);
  186227. };
  186228. #pragma pack(1)
  186229. struct TOCTRACK
  186230. {
  186231. BYTE rsvd;
  186232. BYTE ADR;
  186233. BYTE trackNumber;
  186234. BYTE rsvd2;
  186235. BYTE addr[4];
  186236. };
  186237. struct TOC
  186238. {
  186239. WORD tocLen;
  186240. BYTE firstTrack;
  186241. BYTE lastTrack;
  186242. TOCTRACK tracks[100];
  186243. };
  186244. #pragma pack()
  186245. enum
  186246. {
  186247. READTYPE_ANY = 0,
  186248. READTYPE_ATAPI1 = 1,
  186249. READTYPE_ATAPI2 = 2,
  186250. READTYPE_READ6 = 3,
  186251. READTYPE_READ10 = 4,
  186252. READTYPE_READ_D8 = 5,
  186253. READTYPE_READ_D4 = 6,
  186254. READTYPE_READ_D4_1 = 7,
  186255. READTYPE_READ10_2 = 8
  186256. };
  186257. class CDDeviceHandle
  186258. {
  186259. public:
  186260. CDDeviceHandle (const CDDeviceInfo* const device)
  186261. : scsiHandle (0),
  186262. readType (READTYPE_ANY),
  186263. controller (0)
  186264. {
  186265. memcpy (&info, device, sizeof (info));
  186266. }
  186267. ~CDDeviceHandle()
  186268. {
  186269. if (controller != 0)
  186270. {
  186271. controller->shutDown();
  186272. controller = 0;
  186273. }
  186274. if (scsiHandle != 0)
  186275. CloseHandle (scsiHandle);
  186276. }
  186277. bool readTOC (TOC* lpToc, bool useMSF);
  186278. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186279. void openDrawer (bool shouldBeOpen);
  186280. CDDeviceInfo info;
  186281. HANDLE scsiHandle;
  186282. BYTE readType;
  186283. private:
  186284. ScopedPointer<CDController> controller;
  186285. bool testController (const int readType,
  186286. CDController* const newController,
  186287. CDReadBuffer* const bufferToUse);
  186288. };
  186289. DWORD (*fGetASPI32SupportInfo)(void);
  186290. DWORD (*fSendASPI32Command)(LPSRB);
  186291. static HINSTANCE winAspiLib = 0;
  186292. static bool usingScsi = false;
  186293. static bool initialised = false;
  186294. static bool InitialiseCDRipper()
  186295. {
  186296. if (! initialised)
  186297. {
  186298. initialised = true;
  186299. OSVERSIONINFO info;
  186300. info.dwOSVersionInfoSize = sizeof (info);
  186301. GetVersionEx (&info);
  186302. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186303. if (! usingScsi)
  186304. {
  186305. fGetASPI32SupportInfo = 0;
  186306. fSendASPI32Command = 0;
  186307. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186308. if (winAspiLib != 0)
  186309. {
  186310. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186311. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186312. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186313. return false;
  186314. }
  186315. else
  186316. {
  186317. usingScsi = true;
  186318. }
  186319. }
  186320. }
  186321. return true;
  186322. }
  186323. static void DeinitialiseCDRipper()
  186324. {
  186325. if (winAspiLib != 0)
  186326. {
  186327. fGetASPI32SupportInfo = 0;
  186328. fSendASPI32Command = 0;
  186329. FreeLibrary (winAspiLib);
  186330. winAspiLib = 0;
  186331. }
  186332. initialised = false;
  186333. }
  186334. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186335. {
  186336. TCHAR devicePath[] = { '\\', '\\', '.', '\\', driveLetter, ':', 0, 0 };
  186337. OSVERSIONINFO info;
  186338. info.dwOSVersionInfoSize = sizeof (info);
  186339. GetVersionEx (&info);
  186340. DWORD flags = GENERIC_READ;
  186341. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186342. flags = GENERIC_READ | GENERIC_WRITE;
  186343. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186344. if (h == INVALID_HANDLE_VALUE)
  186345. {
  186346. flags ^= GENERIC_WRITE;
  186347. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186348. }
  186349. return h;
  186350. }
  186351. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186352. const char driveLetter,
  186353. HANDLE& deviceHandle,
  186354. const bool retryOnFailure = true)
  186355. {
  186356. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186357. zerostruct (s);
  186358. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186359. s.spt.CdbLength = srb->SRB_CDBLen;
  186360. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186361. ? SCSI_IOCTL_DATA_IN
  186362. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186363. ? SCSI_IOCTL_DATA_OUT
  186364. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186365. s.spt.DataTransferLength = srb->SRB_BufLen;
  186366. s.spt.TimeOutValue = 5;
  186367. s.spt.DataBuffer = srb->SRB_BufPointer;
  186368. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186369. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186370. srb->SRB_Status = SS_ERR;
  186371. srb->SRB_TargStat = 0x0004;
  186372. DWORD bytesReturned = 0;
  186373. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186374. &s, sizeof (s),
  186375. &s, sizeof (s),
  186376. &bytesReturned, 0) != 0)
  186377. {
  186378. srb->SRB_Status = SS_COMP;
  186379. }
  186380. else if (retryOnFailure)
  186381. {
  186382. const DWORD error = GetLastError();
  186383. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186384. {
  186385. if (error != ERROR_INVALID_HANDLE)
  186386. CloseHandle (deviceHandle);
  186387. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186388. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186389. }
  186390. }
  186391. return srb->SRB_Status;
  186392. }
  186393. // Controller types..
  186394. class ControllerType1 : public CDController
  186395. {
  186396. public:
  186397. ControllerType1() {}
  186398. ~ControllerType1() {}
  186399. bool read (CDReadBuffer* rb)
  186400. {
  186401. if (rb->numFrames * 2352 > rb->bufferSize)
  186402. return false;
  186403. SRB_ExecSCSICmd s;
  186404. prepare (s);
  186405. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186406. s.SRB_BufLen = rb->bufferSize;
  186407. s.SRB_BufPointer = rb->buffer;
  186408. s.SRB_CDBLen = 12;
  186409. s.CDBByte[0] = 0xBE;
  186410. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186411. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186412. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186413. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186414. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186415. perform (s);
  186416. if (s.SRB_Status != SS_COMP)
  186417. return false;
  186418. rb->dataLength = rb->numFrames * 2352;
  186419. rb->dataStartOffset = 0;
  186420. return true;
  186421. }
  186422. };
  186423. class ControllerType2 : public CDController
  186424. {
  186425. public:
  186426. ControllerType2() {}
  186427. ~ControllerType2() {}
  186428. void shutDown()
  186429. {
  186430. if (initialised)
  186431. {
  186432. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186433. SRB_ExecSCSICmd s;
  186434. prepare (s);
  186435. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186436. s.SRB_BufLen = 0x0C;
  186437. s.SRB_BufPointer = bufPointer;
  186438. s.SRB_CDBLen = 6;
  186439. s.CDBByte[0] = 0x15;
  186440. s.CDBByte[4] = 0x0C;
  186441. perform (s);
  186442. }
  186443. }
  186444. bool init()
  186445. {
  186446. SRB_ExecSCSICmd s;
  186447. s.SRB_Status = SS_ERR;
  186448. if (deviceInfo->readType == READTYPE_READ10_2)
  186449. {
  186450. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186451. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186452. for (int i = 0; i < 2; ++i)
  186453. {
  186454. prepare (s);
  186455. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186456. s.SRB_BufLen = 0x14;
  186457. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186458. s.SRB_CDBLen = 6;
  186459. s.CDBByte[0] = 0x15;
  186460. s.CDBByte[1] = 0x10;
  186461. s.CDBByte[4] = 0x14;
  186462. perform (s);
  186463. if (s.SRB_Status != SS_COMP)
  186464. return false;
  186465. }
  186466. }
  186467. else
  186468. {
  186469. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186470. prepare (s);
  186471. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186472. s.SRB_BufLen = 0x0C;
  186473. s.SRB_BufPointer = bufPointer;
  186474. s.SRB_CDBLen = 6;
  186475. s.CDBByte[0] = 0x15;
  186476. s.CDBByte[4] = 0x0C;
  186477. perform (s);
  186478. }
  186479. return s.SRB_Status == SS_COMP;
  186480. }
  186481. bool read (CDReadBuffer* rb)
  186482. {
  186483. if (rb->numFrames * 2352 > rb->bufferSize)
  186484. return false;
  186485. if (!initialised)
  186486. {
  186487. initialised = init();
  186488. if (!initialised)
  186489. return false;
  186490. }
  186491. SRB_ExecSCSICmd s;
  186492. prepare (s);
  186493. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186494. s.SRB_BufLen = rb->bufferSize;
  186495. s.SRB_BufPointer = rb->buffer;
  186496. s.SRB_CDBLen = 10;
  186497. s.CDBByte[0] = 0x28;
  186498. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186499. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186500. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186501. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186502. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186503. perform (s);
  186504. if (s.SRB_Status != SS_COMP)
  186505. return false;
  186506. rb->dataLength = rb->numFrames * 2352;
  186507. rb->dataStartOffset = 0;
  186508. return true;
  186509. }
  186510. };
  186511. class ControllerType3 : public CDController
  186512. {
  186513. public:
  186514. ControllerType3() {}
  186515. ~ControllerType3() {}
  186516. bool read (CDReadBuffer* rb)
  186517. {
  186518. if (rb->numFrames * 2352 > rb->bufferSize)
  186519. return false;
  186520. if (!initialised)
  186521. {
  186522. setPaused (false);
  186523. initialised = true;
  186524. }
  186525. SRB_ExecSCSICmd s;
  186526. prepare (s);
  186527. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186528. s.SRB_BufLen = rb->numFrames * 2352;
  186529. s.SRB_BufPointer = rb->buffer;
  186530. s.SRB_CDBLen = 12;
  186531. s.CDBByte[0] = 0xD8;
  186532. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186533. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186534. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186535. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186536. perform (s);
  186537. if (s.SRB_Status != SS_COMP)
  186538. return false;
  186539. rb->dataLength = rb->numFrames * 2352;
  186540. rb->dataStartOffset = 0;
  186541. return true;
  186542. }
  186543. };
  186544. class ControllerType4 : public CDController
  186545. {
  186546. public:
  186547. ControllerType4() {}
  186548. ~ControllerType4() {}
  186549. bool selectD4Mode()
  186550. {
  186551. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186552. SRB_ExecSCSICmd s;
  186553. prepare (s);
  186554. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186555. s.SRB_CDBLen = 6;
  186556. s.SRB_BufLen = 12;
  186557. s.SRB_BufPointer = bufPointer;
  186558. s.CDBByte[0] = 0x15;
  186559. s.CDBByte[1] = 0x10;
  186560. s.CDBByte[4] = 0x08;
  186561. perform (s);
  186562. return s.SRB_Status == SS_COMP;
  186563. }
  186564. bool read (CDReadBuffer* rb)
  186565. {
  186566. if (rb->numFrames * 2352 > rb->bufferSize)
  186567. return false;
  186568. if (!initialised)
  186569. {
  186570. setPaused (true);
  186571. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186572. selectD4Mode();
  186573. initialised = true;
  186574. }
  186575. SRB_ExecSCSICmd s;
  186576. prepare (s);
  186577. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186578. s.SRB_BufLen = rb->bufferSize;
  186579. s.SRB_BufPointer = rb->buffer;
  186580. s.SRB_CDBLen = 10;
  186581. s.CDBByte[0] = 0xD4;
  186582. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186583. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186584. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186585. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186586. perform (s);
  186587. if (s.SRB_Status != SS_COMP)
  186588. return false;
  186589. rb->dataLength = rb->numFrames * 2352;
  186590. rb->dataStartOffset = 0;
  186591. return true;
  186592. }
  186593. };
  186594. CDController::CDController() : initialised (false)
  186595. {
  186596. }
  186597. CDController::~CDController()
  186598. {
  186599. }
  186600. void CDController::prepare (SRB_ExecSCSICmd& s)
  186601. {
  186602. zerostruct (s);
  186603. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186604. s.SRB_HaID = deviceInfo->info.ha;
  186605. s.SRB_Target = deviceInfo->info.tgt;
  186606. s.SRB_Lun = deviceInfo->info.lun;
  186607. s.SRB_SenseLen = SENSE_LEN;
  186608. }
  186609. void CDController::perform (SRB_ExecSCSICmd& s)
  186610. {
  186611. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186612. s.SRB_PostProc = (void*)event;
  186613. ResetEvent (event);
  186614. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186615. deviceInfo->info.scsiDriveLetter,
  186616. deviceInfo->scsiHandle)
  186617. : fSendASPI32Command ((LPSRB)&s);
  186618. if (status == SS_PENDING)
  186619. WaitForSingleObject (event, 4000);
  186620. CloseHandle (event);
  186621. }
  186622. void CDController::setPaused (bool paused)
  186623. {
  186624. SRB_ExecSCSICmd s;
  186625. prepare (s);
  186626. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186627. s.SRB_CDBLen = 10;
  186628. s.CDBByte[0] = 0x4B;
  186629. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186630. perform (s);
  186631. }
  186632. void CDController::shutDown()
  186633. {
  186634. }
  186635. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186636. {
  186637. if (overlapBuffer != 0)
  186638. {
  186639. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186640. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186641. if (doJitter
  186642. && overlapBuffer->startFrame > 0
  186643. && overlapBuffer->numFrames > 0
  186644. && overlapBuffer->dataLength > 0)
  186645. {
  186646. const int numFrames = rb->numFrames;
  186647. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186648. {
  186649. rb->startFrame -= framesOverlap;
  186650. if (framesToCheck < framesOverlap
  186651. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186652. rb->numFrames += framesOverlap;
  186653. }
  186654. else
  186655. {
  186656. overlapBuffer->dataLength = 0;
  186657. overlapBuffer->startFrame = 0;
  186658. overlapBuffer->numFrames = 0;
  186659. }
  186660. }
  186661. if (! read (rb))
  186662. return false;
  186663. if (doJitter)
  186664. {
  186665. const int checkLen = framesToCheck * 2352;
  186666. const int maxToCheck = rb->dataLength - checkLen;
  186667. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186668. return true;
  186669. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186670. bool found = false;
  186671. for (int i = 0; i < maxToCheck; ++i)
  186672. {
  186673. if (!memcmp (p, rb->buffer + i, checkLen))
  186674. {
  186675. i += checkLen;
  186676. rb->dataStartOffset = i;
  186677. rb->dataLength -= i;
  186678. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186679. found = true;
  186680. break;
  186681. }
  186682. }
  186683. rb->numFrames = rb->dataLength / 2352;
  186684. rb->dataLength = 2352 * rb->numFrames;
  186685. if (!found)
  186686. return false;
  186687. }
  186688. if (canDoJitter)
  186689. {
  186690. memcpy (overlapBuffer->buffer,
  186691. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186692. 2352 * framesToCheck);
  186693. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186694. overlapBuffer->numFrames = framesToCheck;
  186695. overlapBuffer->dataLength = 2352 * framesToCheck;
  186696. overlapBuffer->dataStartOffset = 0;
  186697. }
  186698. else
  186699. {
  186700. overlapBuffer->startFrame = 0;
  186701. overlapBuffer->numFrames = 0;
  186702. overlapBuffer->dataLength = 0;
  186703. }
  186704. return true;
  186705. }
  186706. else
  186707. {
  186708. return read (rb);
  186709. }
  186710. }
  186711. int CDController::getLastIndex()
  186712. {
  186713. char qdata[100];
  186714. SRB_ExecSCSICmd s;
  186715. prepare (s);
  186716. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186717. s.SRB_BufLen = sizeof (qdata);
  186718. s.SRB_BufPointer = (BYTE*)qdata;
  186719. s.SRB_CDBLen = 12;
  186720. s.CDBByte[0] = 0x42;
  186721. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186722. s.CDBByte[2] = 64;
  186723. s.CDBByte[3] = 1; // get current position
  186724. s.CDBByte[7] = 0;
  186725. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186726. perform (s);
  186727. if (s.SRB_Status == SS_COMP)
  186728. return qdata[7];
  186729. return 0;
  186730. }
  186731. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186732. {
  186733. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186734. SRB_ExecSCSICmd s;
  186735. zerostruct (s);
  186736. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186737. s.SRB_HaID = info.ha;
  186738. s.SRB_Target = info.tgt;
  186739. s.SRB_Lun = info.lun;
  186740. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186741. s.SRB_BufLen = 0x324;
  186742. s.SRB_BufPointer = (BYTE*)lpToc;
  186743. s.SRB_SenseLen = 0x0E;
  186744. s.SRB_CDBLen = 0x0A;
  186745. s.SRB_PostProc = (void*)event;
  186746. s.CDBByte[0] = 0x43;
  186747. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186748. s.CDBByte[7] = 0x03;
  186749. s.CDBByte[8] = 0x24;
  186750. ResetEvent (event);
  186751. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186752. : fSendASPI32Command ((LPSRB)&s);
  186753. if (status == SS_PENDING)
  186754. WaitForSingleObject (event, 4000);
  186755. CloseHandle (event);
  186756. return (s.SRB_Status == SS_COMP);
  186757. }
  186758. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186759. CDReadBuffer* const overlapBuffer)
  186760. {
  186761. if (controller == 0)
  186762. {
  186763. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186764. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186765. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186766. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186767. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186768. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186769. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186770. }
  186771. buffer->index = 0;
  186772. if ((controller != 0)
  186773. && controller->readAudio (buffer, overlapBuffer))
  186774. {
  186775. if (buffer->wantsIndex)
  186776. buffer->index = controller->getLastIndex();
  186777. return true;
  186778. }
  186779. return false;
  186780. }
  186781. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186782. {
  186783. if (shouldBeOpen)
  186784. {
  186785. if (controller != 0)
  186786. {
  186787. controller->shutDown();
  186788. controller = 0;
  186789. }
  186790. if (scsiHandle != 0)
  186791. {
  186792. CloseHandle (scsiHandle);
  186793. scsiHandle = 0;
  186794. }
  186795. }
  186796. SRB_ExecSCSICmd s;
  186797. zerostruct (s);
  186798. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186799. s.SRB_HaID = info.ha;
  186800. s.SRB_Target = info.tgt;
  186801. s.SRB_Lun = info.lun;
  186802. s.SRB_SenseLen = SENSE_LEN;
  186803. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186804. s.SRB_BufLen = 0;
  186805. s.SRB_BufPointer = 0;
  186806. s.SRB_CDBLen = 12;
  186807. s.CDBByte[0] = 0x1b;
  186808. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186809. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186810. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186811. s.SRB_PostProc = (void*)event;
  186812. ResetEvent (event);
  186813. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186814. : fSendASPI32Command ((LPSRB)&s);
  186815. if (status == SS_PENDING)
  186816. WaitForSingleObject (event, 4000);
  186817. CloseHandle (event);
  186818. }
  186819. bool CDDeviceHandle::testController (const int type,
  186820. CDController* const newController,
  186821. CDReadBuffer* const rb)
  186822. {
  186823. controller = newController;
  186824. readType = (BYTE)type;
  186825. controller->deviceInfo = this;
  186826. controller->framesToCheck = 1;
  186827. controller->framesOverlap = 3;
  186828. bool passed = false;
  186829. memset (rb->buffer, 0xcd, rb->bufferSize);
  186830. if (controller->read (rb))
  186831. {
  186832. passed = true;
  186833. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186834. int wrong = 0;
  186835. for (int i = rb->dataLength / 4; --i >= 0;)
  186836. {
  186837. if (*p++ == (int) 0xcdcdcdcd)
  186838. {
  186839. if (++wrong == 4)
  186840. {
  186841. passed = false;
  186842. break;
  186843. }
  186844. }
  186845. else
  186846. {
  186847. wrong = 0;
  186848. }
  186849. }
  186850. }
  186851. if (! passed)
  186852. {
  186853. controller->shutDown();
  186854. controller = 0;
  186855. }
  186856. return passed;
  186857. }
  186858. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186859. {
  186860. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186861. const int bufSize = 128;
  186862. BYTE buffer[bufSize];
  186863. zeromem (buffer, bufSize);
  186864. SRB_ExecSCSICmd s;
  186865. zerostruct (s);
  186866. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186867. s.SRB_HaID = ha;
  186868. s.SRB_Target = tgt;
  186869. s.SRB_Lun = lun;
  186870. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186871. s.SRB_BufLen = bufSize;
  186872. s.SRB_BufPointer = buffer;
  186873. s.SRB_SenseLen = SENSE_LEN;
  186874. s.SRB_CDBLen = 6;
  186875. s.SRB_PostProc = (void*)event;
  186876. s.CDBByte[0] = SCSI_INQUIRY;
  186877. s.CDBByte[4] = 100;
  186878. ResetEvent (event);
  186879. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186880. WaitForSingleObject (event, 4000);
  186881. CloseHandle (event);
  186882. if (s.SRB_Status == SS_COMP)
  186883. {
  186884. memcpy (dev->vendor, &buffer[8], 8);
  186885. memcpy (dev->productId, &buffer[16], 16);
  186886. memcpy (dev->rev, &buffer[32], 4);
  186887. memcpy (dev->vendorSpec, &buffer[36], 20);
  186888. }
  186889. }
  186890. static int FindCDDevices (CDDeviceInfo* const list,
  186891. int maxItems)
  186892. {
  186893. int count = 0;
  186894. if (usingScsi)
  186895. {
  186896. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186897. {
  186898. TCHAR drivePath[8];
  186899. drivePath[0] = driveLetter;
  186900. drivePath[1] = ':';
  186901. drivePath[2] = '\\';
  186902. drivePath[3] = 0;
  186903. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186904. {
  186905. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186906. if (h != INVALID_HANDLE_VALUE)
  186907. {
  186908. BYTE buffer[100], passThroughStruct[1024];
  186909. zeromem (buffer, sizeof (buffer));
  186910. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186911. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186912. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186913. p->spt.CdbLength = 6;
  186914. p->spt.SenseInfoLength = 24;
  186915. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186916. p->spt.DataTransferLength = 100;
  186917. p->spt.TimeOutValue = 2;
  186918. p->spt.DataBuffer = buffer;
  186919. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186920. p->spt.Cdb[0] = 0x12;
  186921. p->spt.Cdb[4] = 100;
  186922. DWORD bytesReturned = 0;
  186923. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186924. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186925. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186926. &bytesReturned, 0) != 0)
  186927. {
  186928. zeromem (&list[count], sizeof (CDDeviceInfo));
  186929. list[count].scsiDriveLetter = driveLetter;
  186930. memcpy (list[count].vendor, &buffer[8], 8);
  186931. memcpy (list[count].productId, &buffer[16], 16);
  186932. memcpy (list[count].rev, &buffer[32], 4);
  186933. memcpy (list[count].vendorSpec, &buffer[36], 20);
  186934. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186935. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  186936. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  186937. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  186938. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  186939. &bytesReturned, 0) != 0)
  186940. {
  186941. list[count].ha = scsiAddr->PortNumber;
  186942. list[count].tgt = scsiAddr->TargetId;
  186943. list[count].lun = scsiAddr->Lun;
  186944. ++count;
  186945. }
  186946. }
  186947. CloseHandle (h);
  186948. }
  186949. }
  186950. }
  186951. }
  186952. else
  186953. {
  186954. const DWORD d = fGetASPI32SupportInfo();
  186955. BYTE status = HIBYTE (LOWORD (d));
  186956. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  186957. return 0;
  186958. const int numAdapters = LOBYTE (LOWORD (d));
  186959. for (BYTE ha = 0; ha < numAdapters; ++ha)
  186960. {
  186961. SRB_HAInquiry s;
  186962. zerostruct (s);
  186963. s.SRB_Cmd = SC_HA_INQUIRY;
  186964. s.SRB_HaID = ha;
  186965. fSendASPI32Command ((LPSRB)&s);
  186966. if (s.SRB_Status == SS_COMP)
  186967. {
  186968. maxItems = (int)s.HA_Unique[3];
  186969. if (maxItems == 0)
  186970. maxItems = 8;
  186971. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  186972. {
  186973. for (BYTE lun = 0; lun < 8; ++lun)
  186974. {
  186975. SRB_GDEVBlock sb;
  186976. zerostruct (sb);
  186977. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  186978. sb.SRB_HaID = ha;
  186979. sb.SRB_Target = tgt;
  186980. sb.SRB_Lun = lun;
  186981. fSendASPI32Command ((LPSRB) &sb);
  186982. if (sb.SRB_Status == SS_COMP
  186983. && sb.SRB_DeviceType == DTYPE_CROM)
  186984. {
  186985. zeromem (&list[count], sizeof (CDDeviceInfo));
  186986. list[count].ha = ha;
  186987. list[count].tgt = tgt;
  186988. list[count].lun = lun;
  186989. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  186990. ++count;
  186991. }
  186992. }
  186993. }
  186994. }
  186995. }
  186996. }
  186997. return count;
  186998. }
  186999. static int ripperUsers = 0;
  187000. static bool initialisedOk = false;
  187001. class DeinitialiseTimer : private Timer,
  187002. private DeletedAtShutdown
  187003. {
  187004. DeinitialiseTimer (const DeinitialiseTimer&);
  187005. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  187006. public:
  187007. DeinitialiseTimer()
  187008. {
  187009. startTimer (4000);
  187010. }
  187011. ~DeinitialiseTimer()
  187012. {
  187013. if (--ripperUsers == 0)
  187014. DeinitialiseCDRipper();
  187015. }
  187016. void timerCallback()
  187017. {
  187018. delete this;
  187019. }
  187020. juce_UseDebuggingNewOperator
  187021. };
  187022. static void incUserCount()
  187023. {
  187024. if (ripperUsers++ == 0)
  187025. initialisedOk = InitialiseCDRipper();
  187026. }
  187027. static void decUserCount()
  187028. {
  187029. new DeinitialiseTimer();
  187030. }
  187031. struct CDDeviceWrapper
  187032. {
  187033. ScopedPointer<CDDeviceHandle> cdH;
  187034. ScopedPointer<CDReadBuffer> overlapBuffer;
  187035. bool jitter;
  187036. };
  187037. static int getAddressOf (const TOCTRACK* const t)
  187038. {
  187039. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187040. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187041. }
  187042. static int getMSFAddressOf (const TOCTRACK* const t)
  187043. {
  187044. return 60 * t->addr[1] + t->addr[2];
  187045. }
  187046. static const int samplesPerFrame = 44100 / 75;
  187047. static const int bytesPerFrame = samplesPerFrame * 4;
  187048. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187049. {
  187050. SRB_GDEVBlock s;
  187051. zerostruct (s);
  187052. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187053. s.SRB_HaID = device->ha;
  187054. s.SRB_Target = device->tgt;
  187055. s.SRB_Lun = device->lun;
  187056. if (usingScsi)
  187057. {
  187058. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187059. if (h != INVALID_HANDLE_VALUE)
  187060. {
  187061. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187062. cdh->scsiHandle = h;
  187063. return cdh;
  187064. }
  187065. }
  187066. else
  187067. {
  187068. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187069. && s.SRB_DeviceType == DTYPE_CROM)
  187070. {
  187071. return new CDDeviceHandle (device);
  187072. }
  187073. }
  187074. return 0;
  187075. }
  187076. }
  187077. const StringArray AudioCDReader::getAvailableCDNames()
  187078. {
  187079. using namespace CDReaderHelpers;
  187080. StringArray results;
  187081. incUserCount();
  187082. if (initialisedOk)
  187083. {
  187084. CDDeviceInfo list[8];
  187085. const int num = FindCDDevices (list, 8);
  187086. decUserCount();
  187087. for (int i = 0; i < num; ++i)
  187088. {
  187089. String s;
  187090. if (list[i].scsiDriveLetter > 0)
  187091. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187092. s << String (list[i].vendor).trim()
  187093. << T(" ") << String (list[i].productId).trim()
  187094. << T(" ") << String (list[i].rev).trim();
  187095. results.add (s);
  187096. }
  187097. }
  187098. return results;
  187099. }
  187100. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187101. {
  187102. using namespace CDReaderHelpers;
  187103. incUserCount();
  187104. if (initialisedOk)
  187105. {
  187106. CDDeviceInfo list[8];
  187107. const int num = FindCDDevices (list, 8);
  187108. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187109. {
  187110. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187111. if (handle != 0)
  187112. {
  187113. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187114. d->cdH = handle;
  187115. d->overlapBuffer = new CDReadBuffer(3);
  187116. return new AudioCDReader (d);
  187117. }
  187118. }
  187119. }
  187120. decUserCount();
  187121. return 0;
  187122. }
  187123. AudioCDReader::AudioCDReader (void* handle_)
  187124. : AudioFormatReader (0, T("CD Audio")),
  187125. handle (handle_),
  187126. indexingEnabled (false),
  187127. lastIndex (0),
  187128. firstFrameInBuffer (0),
  187129. samplesInBuffer (0)
  187130. {
  187131. using namespace CDReaderHelpers;
  187132. jassert (handle_ != 0);
  187133. refreshTrackLengths();
  187134. sampleRate = 44100.0;
  187135. bitsPerSample = 16;
  187136. lengthInSamples = getPositionOfTrackStart (numTracks);
  187137. numChannels = 2;
  187138. usesFloatingPointData = false;
  187139. buffer.setSize (4 * bytesPerFrame, true);
  187140. }
  187141. AudioCDReader::~AudioCDReader()
  187142. {
  187143. using namespace CDReaderHelpers;
  187144. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187145. delete device;
  187146. decUserCount();
  187147. }
  187148. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187149. int64 startSampleInFile, int numSamples)
  187150. {
  187151. using namespace CDReaderHelpers;
  187152. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187153. bool ok = true;
  187154. while (numSamples > 0)
  187155. {
  187156. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187157. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187158. if (startSampleInFile >= bufferStartSample
  187159. && startSampleInFile < bufferEndSample)
  187160. {
  187161. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187162. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187163. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187164. const short* src = (const short*) buffer.getData();
  187165. src += 2 * (startSampleInFile - bufferStartSample);
  187166. for (int i = 0; i < toDo; ++i)
  187167. {
  187168. l[i] = src [i << 1] << 16;
  187169. if (r != 0)
  187170. r[i] = src [(i << 1) + 1] << 16;
  187171. }
  187172. startOffsetInDestBuffer += toDo;
  187173. startSampleInFile += toDo;
  187174. numSamples -= toDo;
  187175. }
  187176. else
  187177. {
  187178. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187179. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187180. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187181. {
  187182. device->overlapBuffer->dataLength = 0;
  187183. device->overlapBuffer->startFrame = 0;
  187184. device->overlapBuffer->numFrames = 0;
  187185. device->jitter = false;
  187186. }
  187187. firstFrameInBuffer = frameNeeded;
  187188. lastIndex = 0;
  187189. CDReadBuffer readBuffer (framesInBuffer + 4);
  187190. readBuffer.wantsIndex = indexingEnabled;
  187191. int i;
  187192. for (i = 5; --i >= 0;)
  187193. {
  187194. readBuffer.startFrame = frameNeeded;
  187195. readBuffer.numFrames = framesInBuffer;
  187196. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187197. break;
  187198. else
  187199. device->overlapBuffer->dataLength = 0;
  187200. }
  187201. if (i >= 0)
  187202. {
  187203. memcpy ((char*) buffer.getData(),
  187204. readBuffer.buffer + readBuffer.dataStartOffset,
  187205. readBuffer.dataLength);
  187206. samplesInBuffer = readBuffer.dataLength >> 2;
  187207. lastIndex = readBuffer.index;
  187208. }
  187209. else
  187210. {
  187211. int* l = destSamples[0] + startOffsetInDestBuffer;
  187212. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187213. while (--numSamples >= 0)
  187214. {
  187215. *l++ = 0;
  187216. if (r != 0)
  187217. *r++ = 0;
  187218. }
  187219. // sometimes the read fails for just the very last couple of blocks, so
  187220. // we'll ignore and errors in the last half-second of the disk..
  187221. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187222. break;
  187223. }
  187224. }
  187225. }
  187226. return ok;
  187227. }
  187228. bool AudioCDReader::isCDStillPresent() const
  187229. {
  187230. using namespace CDReaderHelpers;
  187231. TOC toc;
  187232. zerostruct (toc);
  187233. return ((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, false);
  187234. }
  187235. int AudioCDReader::getNumTracks() const
  187236. {
  187237. return numTracks;
  187238. }
  187239. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187240. {
  187241. using namespace CDReaderHelpers;
  187242. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187243. : 0;
  187244. }
  187245. void AudioCDReader::refreshTrackLengths()
  187246. {
  187247. using namespace CDReaderHelpers;
  187248. zeromem (trackStarts, sizeof (trackStarts));
  187249. zeromem (audioTracks, sizeof (audioTracks));
  187250. TOC toc;
  187251. zerostruct (toc);
  187252. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187253. {
  187254. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187255. for (int i = 0; i <= numTracks; ++i)
  187256. {
  187257. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187258. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187259. }
  187260. }
  187261. else
  187262. {
  187263. numTracks = 0;
  187264. }
  187265. }
  187266. bool AudioCDReader::isTrackAudio (int trackNum) const
  187267. {
  187268. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187269. : false;
  187270. }
  187271. void AudioCDReader::enableIndexScanning (bool b)
  187272. {
  187273. indexingEnabled = b;
  187274. }
  187275. int AudioCDReader::getLastIndex() const
  187276. {
  187277. return lastIndex;
  187278. }
  187279. const int framesPerIndexRead = 4;
  187280. int AudioCDReader::getIndexAt (int samplePos)
  187281. {
  187282. using namespace CDReaderHelpers;
  187283. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187284. const int frameNeeded = samplePos / samplesPerFrame;
  187285. device->overlapBuffer->dataLength = 0;
  187286. device->overlapBuffer->startFrame = 0;
  187287. device->overlapBuffer->numFrames = 0;
  187288. device->jitter = false;
  187289. firstFrameInBuffer = 0;
  187290. lastIndex = 0;
  187291. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187292. readBuffer.wantsIndex = true;
  187293. int i;
  187294. for (i = 5; --i >= 0;)
  187295. {
  187296. readBuffer.startFrame = frameNeeded;
  187297. readBuffer.numFrames = framesPerIndexRead;
  187298. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187299. break;
  187300. }
  187301. if (i >= 0)
  187302. return readBuffer.index;
  187303. return -1;
  187304. }
  187305. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187306. {
  187307. using namespace CDReaderHelpers;
  187308. Array <int> indexes;
  187309. const int trackStart = getPositionOfTrackStart (trackNumber);
  187310. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187311. bool needToScan = true;
  187312. if (trackEnd - trackStart > 20 * 44100)
  187313. {
  187314. // check the end of the track for indexes before scanning the whole thing
  187315. needToScan = false;
  187316. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187317. bool seenAnIndex = false;
  187318. while (pos <= trackEnd - samplesPerFrame)
  187319. {
  187320. const int index = getIndexAt (pos);
  187321. if (index == 0)
  187322. {
  187323. // lead-out, so skip back a bit if we've not found any indexes yet..
  187324. if (seenAnIndex)
  187325. break;
  187326. pos -= 44100 * 5;
  187327. if (pos < trackStart)
  187328. break;
  187329. }
  187330. else
  187331. {
  187332. if (index > 0)
  187333. seenAnIndex = true;
  187334. if (index > 1)
  187335. {
  187336. needToScan = true;
  187337. break;
  187338. }
  187339. pos += samplesPerFrame * framesPerIndexRead;
  187340. }
  187341. }
  187342. }
  187343. if (needToScan)
  187344. {
  187345. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187346. int pos = trackStart;
  187347. int last = -1;
  187348. while (pos < trackEnd - samplesPerFrame * 10)
  187349. {
  187350. const int frameNeeded = pos / samplesPerFrame;
  187351. device->overlapBuffer->dataLength = 0;
  187352. device->overlapBuffer->startFrame = 0;
  187353. device->overlapBuffer->numFrames = 0;
  187354. device->jitter = false;
  187355. firstFrameInBuffer = 0;
  187356. CDReadBuffer readBuffer (4);
  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. break;
  187368. if (readBuffer.index > last && readBuffer.index > 1)
  187369. {
  187370. last = readBuffer.index;
  187371. indexes.add (pos);
  187372. }
  187373. pos += samplesPerFrame * framesPerIndexRead;
  187374. }
  187375. indexes.removeValue (trackStart);
  187376. }
  187377. return indexes;
  187378. }
  187379. int AudioCDReader::getCDDBId()
  187380. {
  187381. using namespace CDReaderHelpers;
  187382. refreshTrackLengths();
  187383. if (numTracks > 0)
  187384. {
  187385. TOC toc;
  187386. zerostruct (toc);
  187387. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187388. {
  187389. int n = 0;
  187390. for (int i = numTracks; --i >= 0;)
  187391. {
  187392. int j = getMSFAddressOf (&toc.tracks[i]);
  187393. while (j > 0)
  187394. {
  187395. n += (j % 10);
  187396. j /= 10;
  187397. }
  187398. }
  187399. if (n != 0)
  187400. {
  187401. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187402. - getMSFAddressOf (&toc.tracks[0]);
  187403. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187404. }
  187405. }
  187406. }
  187407. return 0;
  187408. }
  187409. void AudioCDReader::ejectDisk()
  187410. {
  187411. using namespace CDReaderHelpers;
  187412. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187413. }
  187414. #endif
  187415. #if JUCE_USE_CDBURNER
  187416. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187417. {
  187418. CoInitialize (0);
  187419. IDiscMaster* dm;
  187420. IDiscRecorder* result = 0;
  187421. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187422. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187423. IID_IDiscMaster,
  187424. (void**) &dm)))
  187425. {
  187426. if (SUCCEEDED (dm->Open()))
  187427. {
  187428. IEnumDiscRecorders* drEnum = 0;
  187429. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187430. {
  187431. IDiscRecorder* dr = 0;
  187432. DWORD dummy;
  187433. int index = 0;
  187434. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187435. {
  187436. if (indexToOpen == index)
  187437. {
  187438. result = dr;
  187439. break;
  187440. }
  187441. else if (list != 0)
  187442. {
  187443. BSTR path;
  187444. if (SUCCEEDED (dr->GetPath (&path)))
  187445. list->add ((const WCHAR*) path);
  187446. }
  187447. ++index;
  187448. dr->Release();
  187449. }
  187450. drEnum->Release();
  187451. }
  187452. if (master == 0)
  187453. dm->Close();
  187454. }
  187455. if (master != 0)
  187456. *master = dm;
  187457. else
  187458. dm->Release();
  187459. }
  187460. return result;
  187461. }
  187462. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187463. public Timer
  187464. {
  187465. public:
  187466. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187467. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187468. listener (0), progress (0), shouldCancel (false), refCount (1)
  187469. {
  187470. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187471. jassert (SUCCEEDED (hr));
  187472. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187473. //jassert (SUCCEEDED (hr));
  187474. lastState = getDiskState();
  187475. startTimer (2000);
  187476. }
  187477. ~Pimpl() {}
  187478. void releaseObjects()
  187479. {
  187480. discRecorder->Close();
  187481. if (redbook != 0)
  187482. redbook->Release();
  187483. discRecorder->Release();
  187484. discMaster->Release();
  187485. Release();
  187486. }
  187487. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187488. {
  187489. if (result == 0)
  187490. return E_POINTER;
  187491. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187492. {
  187493. AddRef();
  187494. *result = this;
  187495. return S_OK;
  187496. }
  187497. *result = 0;
  187498. return E_NOINTERFACE;
  187499. }
  187500. ULONG __stdcall AddRef() { return ++refCount; }
  187501. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187502. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187503. {
  187504. if (listener != 0 && ! shouldCancel)
  187505. shouldCancel = listener->audioCDBurnProgress (progress);
  187506. *pbCancel = shouldCancel;
  187507. return S_OK;
  187508. }
  187509. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187510. {
  187511. progress = nCompleted / (float) nTotal;
  187512. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187513. return E_NOTIMPL;
  187514. }
  187515. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187516. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187517. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187518. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187519. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187520. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187521. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187522. class ScopedDiscOpener
  187523. {
  187524. public:
  187525. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187526. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187527. private:
  187528. Pimpl& pimpl;
  187529. ScopedDiscOpener (const ScopedDiscOpener&);
  187530. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187531. };
  187532. DiskState getDiskState()
  187533. {
  187534. const ScopedDiscOpener opener (*this);
  187535. long type, flags;
  187536. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187537. if (FAILED (hr))
  187538. return unknown;
  187539. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187540. return writableDiskPresent;
  187541. if (type == 0)
  187542. return noDisc;
  187543. else
  187544. return readOnlyDiskPresent;
  187545. }
  187546. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187547. {
  187548. ComSmartPtr<IPropertyStorage> prop;
  187549. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187550. return defaultReturn;
  187551. PROPSPEC iPropSpec;
  187552. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187553. iPropSpec.lpwstr = name;
  187554. PROPVARIANT iPropVariant;
  187555. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187556. ? defaultReturn : (int) iPropVariant.lVal;
  187557. }
  187558. bool setIntProperty (const LPOLESTR name, const int value) const
  187559. {
  187560. ComSmartPtr<IPropertyStorage> prop;
  187561. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187562. return false;
  187563. PROPSPEC iPropSpec;
  187564. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187565. iPropSpec.lpwstr = name;
  187566. PROPVARIANT iPropVariant;
  187567. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187568. return false;
  187569. iPropVariant.lVal = (long) value;
  187570. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187571. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187572. }
  187573. void timerCallback()
  187574. {
  187575. const DiskState state = getDiskState();
  187576. if (state != lastState)
  187577. {
  187578. lastState = state;
  187579. owner.sendChangeMessage (&owner);
  187580. }
  187581. }
  187582. AudioCDBurner& owner;
  187583. DiskState lastState;
  187584. IDiscMaster* discMaster;
  187585. IDiscRecorder* discRecorder;
  187586. IRedbookDiscMaster* redbook;
  187587. AudioCDBurner::BurnProgressListener* listener;
  187588. float progress;
  187589. bool shouldCancel;
  187590. private:
  187591. int refCount;
  187592. };
  187593. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187594. {
  187595. IDiscMaster* discMaster = 0;
  187596. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187597. if (discRecorder != 0)
  187598. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187599. }
  187600. AudioCDBurner::~AudioCDBurner()
  187601. {
  187602. if (pimpl != 0)
  187603. pimpl.release()->releaseObjects();
  187604. }
  187605. const StringArray AudioCDBurner::findAvailableDevices()
  187606. {
  187607. StringArray devs;
  187608. enumCDBurners (&devs, -1, 0);
  187609. return devs;
  187610. }
  187611. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187612. {
  187613. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187614. if (b->pimpl == 0)
  187615. b = 0;
  187616. return b.release();
  187617. }
  187618. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187619. {
  187620. return pimpl->getDiskState();
  187621. }
  187622. bool AudioCDBurner::isDiskPresent() const
  187623. {
  187624. return getDiskState() == writableDiskPresent;
  187625. }
  187626. bool AudioCDBurner::openTray()
  187627. {
  187628. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187629. return SUCCEEDED (pimpl->discRecorder->Eject());
  187630. }
  187631. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187632. {
  187633. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187634. DiskState oldState = getDiskState();
  187635. DiskState newState = oldState;
  187636. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187637. {
  187638. newState = getDiskState();
  187639. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187640. }
  187641. return newState;
  187642. }
  187643. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187644. {
  187645. Array<int> results;
  187646. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187647. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187648. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187649. if (speeds[i] <= maxSpeed)
  187650. results.add (speeds[i]);
  187651. results.addIfNotAlreadyThere (maxSpeed);
  187652. return results;
  187653. }
  187654. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187655. {
  187656. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187657. return false;
  187658. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187659. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187660. }
  187661. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187662. {
  187663. long blocksFree = 0;
  187664. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187665. return blocksFree;
  187666. }
  187667. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187668. bool performFakeBurnForTesting, int writeSpeed)
  187669. {
  187670. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187671. pimpl->listener = listener;
  187672. pimpl->progress = 0;
  187673. pimpl->shouldCancel = false;
  187674. UINT_PTR cookie;
  187675. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187676. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187677. ejectDiscAfterwards);
  187678. String error;
  187679. if (hr != S_OK)
  187680. {
  187681. const char* e = "Couldn't open or write to the CD device";
  187682. if (hr == IMAPI_E_USERABORT)
  187683. e = "User cancelled the write operation";
  187684. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187685. e = "No Disk present";
  187686. error = e;
  187687. }
  187688. pimpl->discMaster->ProgressUnadvise (cookie);
  187689. pimpl->listener = 0;
  187690. return error;
  187691. }
  187692. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187693. {
  187694. if (audioSource == 0)
  187695. return false;
  187696. ScopedPointer<AudioSource> source (audioSource);
  187697. long bytesPerBlock;
  187698. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187699. const int samplesPerBlock = bytesPerBlock / 4;
  187700. bool ok = true;
  187701. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187702. HeapBlock <byte> buffer (bytesPerBlock);
  187703. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187704. int samplesDone = 0;
  187705. source->prepareToPlay (samplesPerBlock, 44100.0);
  187706. while (ok)
  187707. {
  187708. {
  187709. AudioSourceChannelInfo info;
  187710. info.buffer = &sourceBuffer;
  187711. info.numSamples = samplesPerBlock;
  187712. info.startSample = 0;
  187713. sourceBuffer.clear();
  187714. source->getNextAudioBlock (info);
  187715. }
  187716. zeromem (buffer, bytesPerBlock);
  187717. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187718. buffer, samplesPerBlock, 4);
  187719. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187720. buffer + 2, samplesPerBlock, 4);
  187721. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187722. if (FAILED (hr))
  187723. ok = false;
  187724. samplesDone += samplesPerBlock;
  187725. if (samplesDone >= numSamples)
  187726. break;
  187727. }
  187728. hr = pimpl->redbook->CloseAudioTrack();
  187729. return ok && hr == S_OK;
  187730. }
  187731. #endif
  187732. #endif
  187733. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187734. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187735. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187736. // compiled on its own).
  187737. #if JUCE_INCLUDED_FILE
  187738. using ::free;
  187739. namespace MidiConstants
  187740. {
  187741. static const int midiBufferSize = 1024 * 10;
  187742. static const int numInHeaders = 32;
  187743. static const int inBufferSize = 256;
  187744. }
  187745. class MidiInThread : public Thread
  187746. {
  187747. public:
  187748. MidiInThread (MidiInput* const input_,
  187749. MidiInputCallback* const callback_)
  187750. : Thread ("Juce Midi"),
  187751. hIn (0),
  187752. input (input_),
  187753. callback (callback_),
  187754. isStarted (false),
  187755. startTime (0),
  187756. pendingLength(0)
  187757. {
  187758. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187759. {
  187760. zeromem (&hdr[i], sizeof (MIDIHDR));
  187761. hdr[i].lpData = inData[i];
  187762. hdr[i].dwBufferLength = MidiConstants::inBufferSize;
  187763. }
  187764. };
  187765. ~MidiInThread()
  187766. {
  187767. stop();
  187768. if (hIn != 0)
  187769. {
  187770. int count = 5;
  187771. while (--count >= 0)
  187772. {
  187773. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187774. break;
  187775. Sleep (20);
  187776. }
  187777. }
  187778. }
  187779. void handle (const uint32 message, const uint32 timeStamp) throw()
  187780. {
  187781. const int byte = message & 0xff;
  187782. if (byte < 0x80)
  187783. return;
  187784. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187785. const double time = timeStampToTime (timeStamp);
  187786. {
  187787. const ScopedLock sl (lock);
  187788. if (pendingLength < MidiConstants::midiBufferSize - 12)
  187789. {
  187790. char* const p = pending + pendingLength;
  187791. *(double*) p = time;
  187792. *(uint32*) (p + 8) = numBytes;
  187793. *(uint32*) (p + 12) = message;
  187794. pendingLength += 12 + numBytes;
  187795. }
  187796. else
  187797. {
  187798. jassertfalse // midi buffer overflow! You might need to increase the size..
  187799. }
  187800. }
  187801. notify();
  187802. }
  187803. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187804. {
  187805. const int num = hdr->dwBytesRecorded;
  187806. if (num > 0)
  187807. {
  187808. const double time = timeStampToTime (timeStamp);
  187809. {
  187810. const ScopedLock sl (lock);
  187811. if (pendingLength < MidiConstants::midiBufferSize - (8 + num))
  187812. {
  187813. char* const p = pending + pendingLength;
  187814. *(double*) p = time;
  187815. *(uint32*) (p + 8) = num;
  187816. memcpy (p + 12, hdr->lpData, num);
  187817. pendingLength += 12 + num;
  187818. }
  187819. else
  187820. {
  187821. jassertfalse // midi buffer overflow! You might need to increase the size..
  187822. }
  187823. }
  187824. notify();
  187825. }
  187826. }
  187827. void writeBlock (const int i) throw()
  187828. {
  187829. hdr[i].dwBytesRecorded = 0;
  187830. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187831. jassert (res == MMSYSERR_NOERROR);
  187832. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187833. jassert (res == MMSYSERR_NOERROR);
  187834. }
  187835. void run()
  187836. {
  187837. MemoryBlock pendingCopy (64);
  187838. while (! threadShouldExit())
  187839. {
  187840. for (int i = 0; i < MidiConstants::numInHeaders; ++i)
  187841. {
  187842. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187843. {
  187844. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187845. (void) res;
  187846. jassert (res == MMSYSERR_NOERROR);
  187847. writeBlock (i);
  187848. }
  187849. }
  187850. int len;
  187851. {
  187852. const ScopedLock sl (lock);
  187853. len = pendingLength;
  187854. if (len > 0)
  187855. {
  187856. pendingCopy.ensureSize (len);
  187857. pendingCopy.copyFrom (pending, 0, len);
  187858. pendingLength = 0;
  187859. }
  187860. }
  187861. //xxx needs to figure out if blocks are broken up or not
  187862. if (len == 0)
  187863. {
  187864. wait (500);
  187865. }
  187866. else
  187867. {
  187868. const char* p = (const char*) pendingCopy.getData();
  187869. while (len > 0)
  187870. {
  187871. const double time = *(const double*) p;
  187872. const int messageLen = *(const int*) (p + 8);
  187873. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187874. callback->handleIncomingMidiMessage (input, message);
  187875. p += 12 + messageLen;
  187876. len -= 12 + messageLen;
  187877. }
  187878. }
  187879. }
  187880. }
  187881. void start() throw()
  187882. {
  187883. jassert (hIn != 0);
  187884. if (hIn != 0 && ! isStarted)
  187885. {
  187886. stop();
  187887. activeMidiThreads.addIfNotAlreadyThere (this);
  187888. int i;
  187889. for (i = 0; i < MidiConstants::numInHeaders; ++i)
  187890. writeBlock (i);
  187891. startTime = Time::getMillisecondCounter();
  187892. MMRESULT res = midiInStart (hIn);
  187893. jassert (res == MMSYSERR_NOERROR);
  187894. if (res == MMSYSERR_NOERROR)
  187895. {
  187896. isStarted = true;
  187897. pendingLength = 0;
  187898. startThread (6);
  187899. }
  187900. }
  187901. }
  187902. void stop() throw()
  187903. {
  187904. if (isStarted)
  187905. {
  187906. stopThread (5000);
  187907. midiInReset (hIn);
  187908. midiInStop (hIn);
  187909. activeMidiThreads.removeValue (this);
  187910. { const ScopedLock sl (lock); }
  187911. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187912. {
  187913. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187914. {
  187915. int c = 10;
  187916. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187917. Sleep (20);
  187918. jassert (c >= 0);
  187919. }
  187920. }
  187921. isStarted = false;
  187922. pendingLength = 0;
  187923. }
  187924. }
  187925. static void CALLBACK midiInCallback (HMIDIIN, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR midiMessage, DWORD_PTR timeStamp)
  187926. {
  187927. MidiInThread* const thread = reinterpret_cast <MidiInThread*> (dwInstance);
  187928. if (thread != 0 && activeMidiThreads.contains (thread))
  187929. {
  187930. if (uMsg == MIM_DATA)
  187931. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  187932. else if (uMsg == MIM_LONGDATA)
  187933. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  187934. }
  187935. }
  187936. juce_UseDebuggingNewOperator
  187937. HMIDIIN hIn;
  187938. private:
  187939. static Array <void*, CriticalSection> activeMidiThreads;
  187940. MidiInput* input;
  187941. MidiInputCallback* callback;
  187942. bool isStarted;
  187943. uint32 startTime;
  187944. CriticalSection lock;
  187945. MIDIHDR hdr [MidiConstants::numInHeaders];
  187946. char inData [MidiConstants::numInHeaders] [MidiConstants::inBufferSize];
  187947. int pendingLength;
  187948. char pending [MidiConstants::midiBufferSize];
  187949. double timeStampToTime (uint32 timeStamp) throw()
  187950. {
  187951. timeStamp += startTime;
  187952. const uint32 now = Time::getMillisecondCounter();
  187953. if (timeStamp > now)
  187954. {
  187955. if (timeStamp > now + 2)
  187956. --startTime;
  187957. timeStamp = now;
  187958. }
  187959. return 0.001 * timeStamp;
  187960. }
  187961. MidiInThread (const MidiInThread&);
  187962. MidiInThread& operator= (const MidiInThread&);
  187963. };
  187964. Array <void*, CriticalSection> MidiInThread::activeMidiThreads;
  187965. const StringArray MidiInput::getDevices()
  187966. {
  187967. StringArray s;
  187968. const int num = midiInGetNumDevs();
  187969. for (int i = 0; i < num; ++i)
  187970. {
  187971. MIDIINCAPS mc;
  187972. zerostruct (mc);
  187973. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187974. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187975. }
  187976. return s;
  187977. }
  187978. int MidiInput::getDefaultDeviceIndex()
  187979. {
  187980. return 0;
  187981. }
  187982. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  187983. {
  187984. if (callback == 0)
  187985. return 0;
  187986. UINT deviceId = MIDI_MAPPER;
  187987. int n = 0;
  187988. String name;
  187989. const int num = midiInGetNumDevs();
  187990. for (int i = 0; i < num; ++i)
  187991. {
  187992. MIDIINCAPS mc;
  187993. zerostruct (mc);
  187994. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187995. {
  187996. if (index == n)
  187997. {
  187998. deviceId = i;
  187999. name = String (mc.szPname, sizeof (mc.szPname));
  188000. break;
  188001. }
  188002. ++n;
  188003. }
  188004. }
  188005. ScopedPointer <MidiInput> in (new MidiInput (name));
  188006. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  188007. HMIDIIN h;
  188008. HRESULT err = midiInOpen (&h, deviceId,
  188009. (DWORD_PTR) &MidiInThread::midiInCallback,
  188010. (DWORD_PTR) (MidiInThread*) thread,
  188011. CALLBACK_FUNCTION);
  188012. if (err == MMSYSERR_NOERROR)
  188013. {
  188014. thread->hIn = h;
  188015. in->internal = (void*) thread.release();
  188016. return in.release();
  188017. }
  188018. return 0;
  188019. }
  188020. MidiInput::MidiInput (const String& name_)
  188021. : name (name_),
  188022. internal (0)
  188023. {
  188024. }
  188025. MidiInput::~MidiInput()
  188026. {
  188027. delete static_cast <MidiInThread*> (internal);
  188028. }
  188029. void MidiInput::start()
  188030. {
  188031. static_cast <MidiInThread*> (internal)->start();
  188032. }
  188033. void MidiInput::stop()
  188034. {
  188035. static_cast <MidiInThread*> (internal)->stop();
  188036. }
  188037. struct MidiOutHandle
  188038. {
  188039. int refCount;
  188040. UINT deviceId;
  188041. HMIDIOUT handle;
  188042. static Array<MidiOutHandle*> activeHandles;
  188043. juce_UseDebuggingNewOperator
  188044. };
  188045. Array<MidiOutHandle*> MidiOutHandle::activeHandles;
  188046. const StringArray MidiOutput::getDevices()
  188047. {
  188048. StringArray s;
  188049. const int num = midiOutGetNumDevs();
  188050. for (int i = 0; i < num; ++i)
  188051. {
  188052. MIDIOUTCAPS mc;
  188053. zerostruct (mc);
  188054. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188055. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188056. }
  188057. return s;
  188058. }
  188059. int MidiOutput::getDefaultDeviceIndex()
  188060. {
  188061. const int num = midiOutGetNumDevs();
  188062. int n = 0;
  188063. for (int i = 0; i < num; ++i)
  188064. {
  188065. MIDIOUTCAPS mc;
  188066. zerostruct (mc);
  188067. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188068. {
  188069. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188070. return n;
  188071. ++n;
  188072. }
  188073. }
  188074. return 0;
  188075. }
  188076. MidiOutput* MidiOutput::openDevice (int index)
  188077. {
  188078. UINT deviceId = MIDI_MAPPER;
  188079. const int num = midiOutGetNumDevs();
  188080. int i, n = 0;
  188081. for (i = 0; i < num; ++i)
  188082. {
  188083. MIDIOUTCAPS mc;
  188084. zerostruct (mc);
  188085. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188086. {
  188087. // use the microsoft sw synth as a default - best not to allow deviceId
  188088. // to be MIDI_MAPPER, or else device sharing breaks
  188089. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188090. deviceId = i;
  188091. if (index == n)
  188092. {
  188093. deviceId = i;
  188094. break;
  188095. }
  188096. ++n;
  188097. }
  188098. }
  188099. for (i = MidiOutHandle::activeHandles.size(); --i >= 0;)
  188100. {
  188101. MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);
  188102. if (han != 0 && han->deviceId == deviceId)
  188103. {
  188104. han->refCount++;
  188105. MidiOutput* const out = new MidiOutput();
  188106. out->internal = (void*) han;
  188107. return out;
  188108. }
  188109. }
  188110. for (i = 4; --i >= 0;)
  188111. {
  188112. HMIDIOUT h = 0;
  188113. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188114. if (res == MMSYSERR_NOERROR)
  188115. {
  188116. MidiOutHandle* const han = new MidiOutHandle();
  188117. han->deviceId = deviceId;
  188118. han->refCount = 1;
  188119. han->handle = h;
  188120. MidiOutHandle::activeHandles.add (han);
  188121. MidiOutput* const out = new MidiOutput();
  188122. out->internal = (void*) han;
  188123. return out;
  188124. }
  188125. else if (res == MMSYSERR_ALLOCATED)
  188126. {
  188127. Sleep (100);
  188128. }
  188129. else
  188130. {
  188131. break;
  188132. }
  188133. }
  188134. return 0;
  188135. }
  188136. MidiOutput::~MidiOutput()
  188137. {
  188138. MidiOutHandle* const h = static_cast <MidiOutHandle*> (internal);
  188139. if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
  188140. {
  188141. midiOutClose (h->handle);
  188142. MidiOutHandle::activeHandles.removeValue (h);
  188143. delete h;
  188144. }
  188145. }
  188146. void MidiOutput::reset()
  188147. {
  188148. const MidiOutHandle* const h = static_cast <const MidiOutHandle*> (internal);
  188149. midiOutReset (h->handle);
  188150. }
  188151. bool MidiOutput::getVolume (float& leftVol,
  188152. float& rightVol)
  188153. {
  188154. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  188155. DWORD n;
  188156. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188157. {
  188158. const unsigned short* const nn = (const unsigned short*) &n;
  188159. rightVol = nn[0] / (float) 0xffff;
  188160. leftVol = nn[1] / (float) 0xffff;
  188161. return true;
  188162. }
  188163. else
  188164. {
  188165. rightVol = leftVol = 1.0f;
  188166. return false;
  188167. }
  188168. }
  188169. void MidiOutput::setVolume (float leftVol,
  188170. float rightVol)
  188171. {
  188172. const MidiOutHandle* const handle = static_cast <MidiOutHandle*> (internal);
  188173. DWORD n;
  188174. unsigned short* const nn = (unsigned short*) &n;
  188175. nn[0] = (unsigned short) jlimit (0, 0xffff, (int) (rightVol * 0xffff));
  188176. nn[1] = (unsigned short) jlimit (0, 0xffff, (int) (leftVol * 0xffff));
  188177. midiOutSetVolume (handle->handle, n);
  188178. }
  188179. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188180. {
  188181. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  188182. if (message.getRawDataSize() > 3
  188183. || message.isSysEx())
  188184. {
  188185. MIDIHDR h;
  188186. zerostruct (h);
  188187. h.lpData = (char*) message.getRawData();
  188188. h.dwBufferLength = message.getRawDataSize();
  188189. h.dwBytesRecorded = message.getRawDataSize();
  188190. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188191. {
  188192. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188193. if (res == MMSYSERR_NOERROR)
  188194. {
  188195. while ((h.dwFlags & MHDR_DONE) == 0)
  188196. Sleep (1);
  188197. int count = 500; // 1 sec timeout
  188198. while (--count >= 0)
  188199. {
  188200. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188201. if (res == MIDIERR_STILLPLAYING)
  188202. Sleep (2);
  188203. else
  188204. break;
  188205. }
  188206. }
  188207. }
  188208. }
  188209. else
  188210. {
  188211. midiOutShortMsg (handle->handle,
  188212. *(unsigned int*) message.getRawData());
  188213. }
  188214. }
  188215. #endif
  188216. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188217. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188218. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188219. // compiled on its own).
  188220. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188221. #undef WINDOWS
  188222. // #define ASIO_DEBUGGING
  188223. #ifdef ASIO_DEBUGGING
  188224. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188225. #else
  188226. #define log(a) {}
  188227. #endif
  188228. #ifdef ASIO_DEBUGGING
  188229. static void logError (const String& context, long error)
  188230. {
  188231. String err ("unknown error");
  188232. if (error == ASE_NotPresent)
  188233. err = "Not Present";
  188234. else if (error == ASE_HWMalfunction)
  188235. err = "Hardware Malfunction";
  188236. else if (error == ASE_InvalidParameter)
  188237. err = "Invalid Parameter";
  188238. else if (error == ASE_InvalidMode)
  188239. err = "Invalid Mode";
  188240. else if (error == ASE_SPNotAdvancing)
  188241. err = "Sample position not advancing";
  188242. else if (error == ASE_NoClock)
  188243. err = "No Clock";
  188244. else if (error == ASE_NoMemory)
  188245. err = "Out of memory";
  188246. log (T("!!error: ") + context + T(" - ") + err);
  188247. }
  188248. #else
  188249. #define logError(a, b) {}
  188250. #endif
  188251. class ASIOAudioIODevice;
  188252. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188253. static const int maxASIOChannels = 160;
  188254. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188255. private Timer
  188256. {
  188257. public:
  188258. Component ourWindow;
  188259. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188260. const String& optionalDllForDirectLoading_)
  188261. : AudioIODevice (name_, T("ASIO")),
  188262. asioObject (0),
  188263. classId (classId_),
  188264. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188265. currentBitDepth (16),
  188266. currentSampleRate (0),
  188267. isOpen_ (false),
  188268. isStarted (false),
  188269. postOutput (true),
  188270. insideControlPanelModalLoop (false),
  188271. shouldUsePreferredSize (false)
  188272. {
  188273. name = name_;
  188274. ourWindow.addToDesktop (0);
  188275. windowHandle = ourWindow.getWindowHandle();
  188276. jassert (currentASIODev [slotNumber] == 0);
  188277. currentASIODev [slotNumber] = this;
  188278. openDevice();
  188279. }
  188280. ~ASIOAudioIODevice()
  188281. {
  188282. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188283. if (currentASIODev[i] == this)
  188284. currentASIODev[i] = 0;
  188285. close();
  188286. log ("ASIO - exiting");
  188287. removeCurrentDriver();
  188288. }
  188289. void updateSampleRates()
  188290. {
  188291. // find a list of sample rates..
  188292. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188293. sampleRates.clear();
  188294. if (asioObject != 0)
  188295. {
  188296. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188297. {
  188298. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188299. if (err == 0)
  188300. {
  188301. sampleRates.add ((int) possibleSampleRates[index]);
  188302. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188303. }
  188304. else if (err != ASE_NoClock)
  188305. {
  188306. logError (T("CanSampleRate"), err);
  188307. }
  188308. }
  188309. if (sampleRates.size() == 0)
  188310. {
  188311. double cr = 0;
  188312. const long err = asioObject->getSampleRate (&cr);
  188313. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188314. if (err == 0)
  188315. sampleRates.add ((int) cr);
  188316. }
  188317. }
  188318. }
  188319. const StringArray getOutputChannelNames()
  188320. {
  188321. return outputChannelNames;
  188322. }
  188323. const StringArray getInputChannelNames()
  188324. {
  188325. return inputChannelNames;
  188326. }
  188327. int getNumSampleRates()
  188328. {
  188329. return sampleRates.size();
  188330. }
  188331. double getSampleRate (int index)
  188332. {
  188333. return sampleRates [index];
  188334. }
  188335. int getNumBufferSizesAvailable()
  188336. {
  188337. return bufferSizes.size();
  188338. }
  188339. int getBufferSizeSamples (int index)
  188340. {
  188341. return bufferSizes [index];
  188342. }
  188343. int getDefaultBufferSize()
  188344. {
  188345. return preferredSize;
  188346. }
  188347. const String open (const BitArray& inputChannels,
  188348. const BitArray& outputChannels,
  188349. double sr,
  188350. int bufferSizeSamples)
  188351. {
  188352. close();
  188353. currentCallback = 0;
  188354. if (bufferSizeSamples <= 0)
  188355. shouldUsePreferredSize = true;
  188356. if (asioObject == 0 || ! isASIOOpen)
  188357. {
  188358. log ("Warning: device not open");
  188359. const String err (openDevice());
  188360. if (asioObject == 0 || ! isASIOOpen)
  188361. return err;
  188362. }
  188363. isStarted = false;
  188364. bufferIndex = -1;
  188365. long err = 0;
  188366. long newPreferredSize = 0;
  188367. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188368. minSize = 0;
  188369. maxSize = 0;
  188370. newPreferredSize = 0;
  188371. granularity = 0;
  188372. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188373. {
  188374. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188375. shouldUsePreferredSize = true;
  188376. preferredSize = newPreferredSize;
  188377. }
  188378. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188379. // dynamic changes to the buffer size...
  188380. shouldUsePreferredSize = shouldUsePreferredSize
  188381. || getName().containsIgnoreCase (T("Digidesign"));
  188382. if (shouldUsePreferredSize)
  188383. {
  188384. log ("Using preferred size for buffer..");
  188385. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188386. {
  188387. bufferSizeSamples = preferredSize;
  188388. }
  188389. else
  188390. {
  188391. bufferSizeSamples = 1024;
  188392. logError ("GetBufferSize1", err);
  188393. }
  188394. shouldUsePreferredSize = false;
  188395. }
  188396. int sampleRate = roundDoubleToInt (sr);
  188397. currentSampleRate = sampleRate;
  188398. currentBlockSizeSamples = bufferSizeSamples;
  188399. currentChansOut.clear();
  188400. currentChansIn.clear();
  188401. zeromem (inBuffers, sizeof (inBuffers));
  188402. zeromem (outBuffers, sizeof (outBuffers));
  188403. updateSampleRates();
  188404. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188405. sampleRate = sampleRates[0];
  188406. jassert (sampleRate != 0);
  188407. if (sampleRate == 0)
  188408. sampleRate = 44100;
  188409. long numSources = 32;
  188410. ASIOClockSource clocks[32];
  188411. zeromem (clocks, sizeof (clocks));
  188412. asioObject->getClockSources (clocks, &numSources);
  188413. bool isSourceSet = false;
  188414. // careful not to remove this loop because it does more than just logging!
  188415. int i;
  188416. for (i = 0; i < numSources; ++i)
  188417. {
  188418. String s ("clock: ");
  188419. s += clocks[i].name;
  188420. if (clocks[i].isCurrentSource)
  188421. {
  188422. isSourceSet = true;
  188423. s << " (cur)";
  188424. }
  188425. log (s);
  188426. }
  188427. if (numSources > 1 && ! isSourceSet)
  188428. {
  188429. log ("setting clock source");
  188430. asioObject->setClockSource (clocks[0].index);
  188431. Thread::sleep (20);
  188432. }
  188433. else
  188434. {
  188435. if (numSources == 0)
  188436. {
  188437. log ("ASIO - no clock sources!");
  188438. }
  188439. }
  188440. double cr = 0;
  188441. err = asioObject->getSampleRate (&cr);
  188442. if (err == 0)
  188443. {
  188444. currentSampleRate = cr;
  188445. }
  188446. else
  188447. {
  188448. logError ("GetSampleRate", err);
  188449. currentSampleRate = 0;
  188450. }
  188451. error = String::empty;
  188452. needToReset = false;
  188453. isReSync = false;
  188454. err = 0;
  188455. bool buffersCreated = false;
  188456. if (currentSampleRate != sampleRate)
  188457. {
  188458. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188459. err = asioObject->setSampleRate (sampleRate);
  188460. if (err == ASE_NoClock && numSources > 0)
  188461. {
  188462. log ("trying to set a clock source..");
  188463. Thread::sleep (10);
  188464. err = asioObject->setClockSource (clocks[0].index);
  188465. if (err != 0)
  188466. {
  188467. logError ("SetClock", err);
  188468. }
  188469. Thread::sleep (10);
  188470. err = asioObject->setSampleRate (sampleRate);
  188471. }
  188472. }
  188473. if (err == 0)
  188474. {
  188475. currentSampleRate = sampleRate;
  188476. if (needToReset)
  188477. {
  188478. if (isReSync)
  188479. {
  188480. log ("Resync request");
  188481. }
  188482. log ("! Resetting ASIO after sample rate change");
  188483. removeCurrentDriver();
  188484. loadDriver();
  188485. const String error (initDriver());
  188486. if (error.isNotEmpty())
  188487. {
  188488. log (T("ASIOInit: ") + error);
  188489. }
  188490. needToReset = false;
  188491. isReSync = false;
  188492. }
  188493. numActiveInputChans = 0;
  188494. numActiveOutputChans = 0;
  188495. ASIOBufferInfo* info = bufferInfos;
  188496. int i;
  188497. for (i = 0; i < totalNumInputChans; ++i)
  188498. {
  188499. if (inputChannels[i])
  188500. {
  188501. currentChansIn.setBit (i);
  188502. info->isInput = 1;
  188503. info->channelNum = i;
  188504. info->buffers[0] = info->buffers[1] = 0;
  188505. ++info;
  188506. ++numActiveInputChans;
  188507. }
  188508. }
  188509. for (i = 0; i < totalNumOutputChans; ++i)
  188510. {
  188511. if (outputChannels[i])
  188512. {
  188513. currentChansOut.setBit (i);
  188514. info->isInput = 0;
  188515. info->channelNum = i;
  188516. info->buffers[0] = info->buffers[1] = 0;
  188517. ++info;
  188518. ++numActiveOutputChans;
  188519. }
  188520. }
  188521. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188522. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188523. if (currentASIODev[0] == this)
  188524. {
  188525. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188526. callbacks.asioMessage = &asioMessagesCallback0;
  188527. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188528. }
  188529. else if (currentASIODev[1] == this)
  188530. {
  188531. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188532. callbacks.asioMessage = &asioMessagesCallback1;
  188533. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188534. }
  188535. else if (currentASIODev[2] == this)
  188536. {
  188537. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188538. callbacks.asioMessage = &asioMessagesCallback2;
  188539. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188540. }
  188541. else
  188542. {
  188543. jassertfalse
  188544. }
  188545. log ("disposing buffers");
  188546. err = asioObject->disposeBuffers();
  188547. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188548. err = asioObject->createBuffers (bufferInfos,
  188549. totalBuffers,
  188550. currentBlockSizeSamples,
  188551. &callbacks);
  188552. if (err != 0)
  188553. {
  188554. currentBlockSizeSamples = preferredSize;
  188555. logError ("create buffers 2", err);
  188556. asioObject->disposeBuffers();
  188557. err = asioObject->createBuffers (bufferInfos,
  188558. totalBuffers,
  188559. currentBlockSizeSamples,
  188560. &callbacks);
  188561. }
  188562. if (err == 0)
  188563. {
  188564. buffersCreated = true;
  188565. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188566. int n = 0;
  188567. Array <int> types;
  188568. currentBitDepth = 16;
  188569. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188570. {
  188571. if (inputChannels[i])
  188572. {
  188573. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188574. ASIOChannelInfo channelInfo;
  188575. zerostruct (channelInfo);
  188576. channelInfo.channel = i;
  188577. channelInfo.isInput = 1;
  188578. asioObject->getChannelInfo (&channelInfo);
  188579. types.addIfNotAlreadyThere (channelInfo.type);
  188580. typeToFormatParameters (channelInfo.type,
  188581. inputChannelBitDepths[n],
  188582. inputChannelBytesPerSample[n],
  188583. inputChannelIsFloat[n],
  188584. inputChannelLittleEndian[n]);
  188585. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188586. ++n;
  188587. }
  188588. }
  188589. jassert (numActiveInputChans == n);
  188590. n = 0;
  188591. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188592. {
  188593. if (outputChannels[i])
  188594. {
  188595. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188596. ASIOChannelInfo channelInfo;
  188597. zerostruct (channelInfo);
  188598. channelInfo.channel = i;
  188599. channelInfo.isInput = 0;
  188600. asioObject->getChannelInfo (&channelInfo);
  188601. types.addIfNotAlreadyThere (channelInfo.type);
  188602. typeToFormatParameters (channelInfo.type,
  188603. outputChannelBitDepths[n],
  188604. outputChannelBytesPerSample[n],
  188605. outputChannelIsFloat[n],
  188606. outputChannelLittleEndian[n]);
  188607. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188608. ++n;
  188609. }
  188610. }
  188611. jassert (numActiveOutputChans == n);
  188612. for (i = types.size(); --i >= 0;)
  188613. {
  188614. log (T("channel format: ") + String (types[i]));
  188615. }
  188616. jassert (n <= totalBuffers);
  188617. for (i = 0; i < numActiveOutputChans; ++i)
  188618. {
  188619. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188620. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188621. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188622. {
  188623. log ("!! Null buffers");
  188624. }
  188625. else
  188626. {
  188627. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188628. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188629. }
  188630. }
  188631. inputLatency = outputLatency = 0;
  188632. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188633. {
  188634. log ("ASIO - no latencies");
  188635. }
  188636. else
  188637. {
  188638. log (T("ASIO latencies: ")
  188639. + String ((int) outputLatency)
  188640. + T(", ")
  188641. + String ((int) inputLatency));
  188642. }
  188643. isOpen_ = true;
  188644. log ("starting ASIO");
  188645. calledback = false;
  188646. err = asioObject->start();
  188647. if (err != 0)
  188648. {
  188649. isOpen_ = false;
  188650. log ("ASIO - stop on failure");
  188651. Thread::sleep (10);
  188652. asioObject->stop();
  188653. error = "Can't start device";
  188654. Thread::sleep (10);
  188655. }
  188656. else
  188657. {
  188658. int count = 300;
  188659. while (--count > 0 && ! calledback)
  188660. Thread::sleep (10);
  188661. isStarted = true;
  188662. if (! calledback)
  188663. {
  188664. error = "Device didn't start correctly";
  188665. log ("ASIO didn't callback - stopping..");
  188666. asioObject->stop();
  188667. }
  188668. }
  188669. }
  188670. else
  188671. {
  188672. error = "Can't create i/o buffers";
  188673. }
  188674. }
  188675. else
  188676. {
  188677. error = "Can't set sample rate: ";
  188678. error << sampleRate;
  188679. }
  188680. if (error.isNotEmpty())
  188681. {
  188682. logError (error, err);
  188683. if (asioObject != 0 && buffersCreated)
  188684. asioObject->disposeBuffers();
  188685. Thread::sleep (20);
  188686. isStarted = false;
  188687. isOpen_ = false;
  188688. close();
  188689. }
  188690. needToReset = false;
  188691. isReSync = false;
  188692. return error;
  188693. }
  188694. void close()
  188695. {
  188696. error = String::empty;
  188697. stopTimer();
  188698. stop();
  188699. if (isASIOOpen && isOpen_)
  188700. {
  188701. const ScopedLock sl (callbackLock);
  188702. isOpen_ = false;
  188703. isStarted = false;
  188704. needToReset = false;
  188705. isReSync = false;
  188706. log ("ASIO - stopping");
  188707. if (asioObject != 0)
  188708. {
  188709. Thread::sleep (20);
  188710. asioObject->stop();
  188711. Thread::sleep (10);
  188712. asioObject->disposeBuffers();
  188713. }
  188714. Thread::sleep (10);
  188715. }
  188716. }
  188717. bool isOpen()
  188718. {
  188719. return isOpen_ || insideControlPanelModalLoop;
  188720. }
  188721. int getCurrentBufferSizeSamples()
  188722. {
  188723. return currentBlockSizeSamples;
  188724. }
  188725. double getCurrentSampleRate()
  188726. {
  188727. return currentSampleRate;
  188728. }
  188729. const BitArray getActiveOutputChannels() const
  188730. {
  188731. return currentChansOut;
  188732. }
  188733. const BitArray getActiveInputChannels() const
  188734. {
  188735. return currentChansIn;
  188736. }
  188737. int getCurrentBitDepth()
  188738. {
  188739. return currentBitDepth;
  188740. }
  188741. int getOutputLatencyInSamples()
  188742. {
  188743. return outputLatency + currentBlockSizeSamples / 4;
  188744. }
  188745. int getInputLatencyInSamples()
  188746. {
  188747. return inputLatency + currentBlockSizeSamples / 4;
  188748. }
  188749. void start (AudioIODeviceCallback* callback)
  188750. {
  188751. if (callback != 0)
  188752. {
  188753. callback->audioDeviceAboutToStart (this);
  188754. const ScopedLock sl (callbackLock);
  188755. currentCallback = callback;
  188756. }
  188757. }
  188758. void stop()
  188759. {
  188760. AudioIODeviceCallback* const lastCallback = currentCallback;
  188761. {
  188762. const ScopedLock sl (callbackLock);
  188763. currentCallback = 0;
  188764. }
  188765. if (lastCallback != 0)
  188766. lastCallback->audioDeviceStopped();
  188767. }
  188768. bool isPlaying()
  188769. {
  188770. return isASIOOpen && (currentCallback != 0);
  188771. }
  188772. const String getLastError()
  188773. {
  188774. return error;
  188775. }
  188776. bool hasControlPanel() const
  188777. {
  188778. return true;
  188779. }
  188780. bool showControlPanel()
  188781. {
  188782. log ("ASIO - showing control panel");
  188783. Component modalWindow (String::empty);
  188784. modalWindow.setOpaque (true);
  188785. modalWindow.addToDesktop (0);
  188786. modalWindow.enterModalState();
  188787. bool done = false;
  188788. JUCE_TRY
  188789. {
  188790. // are there are devices that need to be closed before showing their control panel?
  188791. // close();
  188792. insideControlPanelModalLoop = true;
  188793. const uint32 started = Time::getMillisecondCounter();
  188794. if (asioObject != 0)
  188795. {
  188796. asioObject->controlPanel();
  188797. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188798. log (T("spent: ") + String (spent));
  188799. if (spent > 300)
  188800. {
  188801. shouldUsePreferredSize = true;
  188802. done = true;
  188803. }
  188804. }
  188805. }
  188806. JUCE_CATCH_ALL
  188807. insideControlPanelModalLoop = false;
  188808. return done;
  188809. }
  188810. void resetRequest() throw()
  188811. {
  188812. needToReset = true;
  188813. }
  188814. void resyncRequest() throw()
  188815. {
  188816. needToReset = true;
  188817. isReSync = true;
  188818. }
  188819. void timerCallback()
  188820. {
  188821. if (! insideControlPanelModalLoop)
  188822. {
  188823. stopTimer();
  188824. // used to cause a reset
  188825. log ("! ASIO restart request!");
  188826. if (isOpen_)
  188827. {
  188828. AudioIODeviceCallback* const oldCallback = currentCallback;
  188829. close();
  188830. open (BitArray (currentChansIn), BitArray (currentChansOut),
  188831. currentSampleRate, currentBlockSizeSamples);
  188832. if (oldCallback != 0)
  188833. start (oldCallback);
  188834. }
  188835. }
  188836. else
  188837. {
  188838. startTimer (100);
  188839. }
  188840. }
  188841. juce_UseDebuggingNewOperator
  188842. private:
  188843. IASIO* volatile asioObject;
  188844. ASIOCallbacks callbacks;
  188845. void* windowHandle;
  188846. CLSID classId;
  188847. const String optionalDllForDirectLoading;
  188848. String error;
  188849. long totalNumInputChans, totalNumOutputChans;
  188850. StringArray inputChannelNames, outputChannelNames;
  188851. Array<int> sampleRates, bufferSizes;
  188852. long inputLatency, outputLatency;
  188853. long minSize, maxSize, preferredSize, granularity;
  188854. int volatile currentBlockSizeSamples;
  188855. int volatile currentBitDepth;
  188856. double volatile currentSampleRate;
  188857. BitArray currentChansOut, currentChansIn;
  188858. AudioIODeviceCallback* volatile currentCallback;
  188859. CriticalSection callbackLock;
  188860. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188861. float* inBuffers [maxASIOChannels];
  188862. float* outBuffers [maxASIOChannels];
  188863. int inputChannelBitDepths [maxASIOChannels];
  188864. int outputChannelBitDepths [maxASIOChannels];
  188865. int inputChannelBytesPerSample [maxASIOChannels];
  188866. int outputChannelBytesPerSample [maxASIOChannels];
  188867. bool inputChannelIsFloat [maxASIOChannels];
  188868. bool outputChannelIsFloat [maxASIOChannels];
  188869. bool inputChannelLittleEndian [maxASIOChannels];
  188870. bool outputChannelLittleEndian [maxASIOChannels];
  188871. WaitableEvent event1;
  188872. HeapBlock <float> tempBuffer;
  188873. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188874. bool isOpen_, isStarted;
  188875. bool volatile isASIOOpen;
  188876. bool volatile calledback;
  188877. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188878. bool volatile insideControlPanelModalLoop;
  188879. bool volatile shouldUsePreferredSize;
  188880. void removeCurrentDriver()
  188881. {
  188882. if (asioObject != 0)
  188883. {
  188884. asioObject->Release();
  188885. asioObject = 0;
  188886. }
  188887. }
  188888. bool loadDriver()
  188889. {
  188890. removeCurrentDriver();
  188891. JUCE_TRY
  188892. {
  188893. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188894. classId, (void**) &asioObject) == S_OK)
  188895. {
  188896. return true;
  188897. }
  188898. // If a class isn't registered but we have a path for it, we can fallback to
  188899. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188900. if (optionalDllForDirectLoading.isNotEmpty())
  188901. {
  188902. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188903. if (h != 0)
  188904. {
  188905. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188906. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188907. if (dllGetClassObject != 0)
  188908. {
  188909. IClassFactory* classFactory = 0;
  188910. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188911. if (classFactory != 0)
  188912. {
  188913. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188914. classFactory->Release();
  188915. }
  188916. return asioObject != 0;
  188917. }
  188918. }
  188919. }
  188920. }
  188921. JUCE_CATCH_ALL
  188922. asioObject = 0;
  188923. return false;
  188924. }
  188925. const String initDriver()
  188926. {
  188927. if (asioObject != 0)
  188928. {
  188929. char buffer [256];
  188930. zeromem (buffer, sizeof (buffer));
  188931. if (! asioObject->init (windowHandle))
  188932. {
  188933. asioObject->getErrorMessage (buffer);
  188934. return String (buffer, sizeof (buffer) - 1);
  188935. }
  188936. // just in case any daft drivers expect this to be called..
  188937. asioObject->getDriverName (buffer);
  188938. return String::empty;
  188939. }
  188940. return "No Driver";
  188941. }
  188942. const String openDevice()
  188943. {
  188944. // use this in case the driver starts opening dialog boxes..
  188945. Component modalWindow (String::empty);
  188946. modalWindow.setOpaque (true);
  188947. modalWindow.addToDesktop (0);
  188948. modalWindow.enterModalState();
  188949. // open the device and get its info..
  188950. log (T("opening ASIO device: ") + getName());
  188951. needToReset = false;
  188952. isReSync = false;
  188953. outputChannelNames.clear();
  188954. inputChannelNames.clear();
  188955. bufferSizes.clear();
  188956. sampleRates.clear();
  188957. isASIOOpen = false;
  188958. isOpen_ = false;
  188959. totalNumInputChans = 0;
  188960. totalNumOutputChans = 0;
  188961. numActiveInputChans = 0;
  188962. numActiveOutputChans = 0;
  188963. currentCallback = 0;
  188964. error = String::empty;
  188965. if (getName().isEmpty())
  188966. return error;
  188967. long err = 0;
  188968. if (loadDriver())
  188969. {
  188970. if ((error = initDriver()).isEmpty())
  188971. {
  188972. numActiveInputChans = 0;
  188973. numActiveOutputChans = 0;
  188974. totalNumInputChans = 0;
  188975. totalNumOutputChans = 0;
  188976. if (asioObject != 0
  188977. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  188978. {
  188979. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  188980. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188981. {
  188982. // find a list of buffer sizes..
  188983. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  188984. if (granularity >= 0)
  188985. {
  188986. granularity = jmax (1, (int) granularity);
  188987. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  188988. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  188989. }
  188990. else if (granularity < 0)
  188991. {
  188992. for (int i = 0; i < 18; ++i)
  188993. {
  188994. const int s = (1 << i);
  188995. if (s >= minSize && s <= maxSize)
  188996. bufferSizes.add (s);
  188997. }
  188998. }
  188999. if (! bufferSizes.contains (preferredSize))
  189000. bufferSizes.insert (0, preferredSize);
  189001. double currentRate = 0;
  189002. asioObject->getSampleRate (&currentRate);
  189003. if (currentRate <= 0.0 || currentRate > 192001.0)
  189004. {
  189005. log ("setting sample rate");
  189006. err = asioObject->setSampleRate (44100.0);
  189007. if (err != 0)
  189008. {
  189009. logError ("setting sample rate", err);
  189010. }
  189011. asioObject->getSampleRate (&currentRate);
  189012. }
  189013. currentSampleRate = currentRate;
  189014. postOutput = (asioObject->outputReady() == 0);
  189015. if (postOutput)
  189016. {
  189017. log ("ASIO outputReady = ok");
  189018. }
  189019. updateSampleRates();
  189020. // ..because cubase does it at this point
  189021. inputLatency = outputLatency = 0;
  189022. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189023. {
  189024. log ("ASIO - no latencies");
  189025. }
  189026. log (String ("latencies: ")
  189027. + String ((int) inputLatency)
  189028. + T(", ") + String ((int) outputLatency));
  189029. // create some dummy buffers now.. because cubase does..
  189030. numActiveInputChans = 0;
  189031. numActiveOutputChans = 0;
  189032. ASIOBufferInfo* info = bufferInfos;
  189033. int i, numChans = 0;
  189034. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  189035. {
  189036. info->isInput = 1;
  189037. info->channelNum = i;
  189038. info->buffers[0] = info->buffers[1] = 0;
  189039. ++info;
  189040. ++numChans;
  189041. }
  189042. const int outputBufferIndex = numChans;
  189043. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189044. {
  189045. info->isInput = 0;
  189046. info->channelNum = i;
  189047. info->buffers[0] = info->buffers[1] = 0;
  189048. ++info;
  189049. ++numChans;
  189050. }
  189051. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189052. if (currentASIODev[0] == this)
  189053. {
  189054. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189055. callbacks.asioMessage = &asioMessagesCallback0;
  189056. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189057. }
  189058. else if (currentASIODev[1] == this)
  189059. {
  189060. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189061. callbacks.asioMessage = &asioMessagesCallback1;
  189062. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189063. }
  189064. else if (currentASIODev[2] == this)
  189065. {
  189066. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189067. callbacks.asioMessage = &asioMessagesCallback2;
  189068. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189069. }
  189070. else
  189071. {
  189072. jassertfalse
  189073. }
  189074. log (T("creating buffers (dummy): ") + String (numChans)
  189075. + T(", ") + String ((int) preferredSize));
  189076. if (preferredSize > 0)
  189077. {
  189078. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189079. if (err != 0)
  189080. {
  189081. logError ("dummy buffers", err);
  189082. }
  189083. }
  189084. long newInps = 0, newOuts = 0;
  189085. asioObject->getChannels (&newInps, &newOuts);
  189086. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189087. {
  189088. totalNumInputChans = newInps;
  189089. totalNumOutputChans = newOuts;
  189090. log (String ((int) totalNumInputChans) + T(" in; ")
  189091. + String ((int) totalNumOutputChans) + T(" out"));
  189092. }
  189093. updateSampleRates();
  189094. ASIOChannelInfo channelInfo;
  189095. channelInfo.type = 0;
  189096. for (i = 0; i < totalNumInputChans; ++i)
  189097. {
  189098. zerostruct (channelInfo);
  189099. channelInfo.channel = i;
  189100. channelInfo.isInput = 1;
  189101. asioObject->getChannelInfo (&channelInfo);
  189102. inputChannelNames.add (String (channelInfo.name));
  189103. }
  189104. for (i = 0; i < totalNumOutputChans; ++i)
  189105. {
  189106. zerostruct (channelInfo);
  189107. channelInfo.channel = i;
  189108. channelInfo.isInput = 0;
  189109. asioObject->getChannelInfo (&channelInfo);
  189110. outputChannelNames.add (String (channelInfo.name));
  189111. typeToFormatParameters (channelInfo.type,
  189112. outputChannelBitDepths[i],
  189113. outputChannelBytesPerSample[i],
  189114. outputChannelIsFloat[i],
  189115. outputChannelLittleEndian[i]);
  189116. if (i < 2)
  189117. {
  189118. // clear the channels that are used with the dummy stuff
  189119. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189120. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189121. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189122. }
  189123. }
  189124. outputChannelNames.trim();
  189125. inputChannelNames.trim();
  189126. outputChannelNames.appendNumbersToDuplicates (false, true);
  189127. inputChannelNames.appendNumbersToDuplicates (false, true);
  189128. // start and stop because cubase does it..
  189129. asioObject->getLatencies (&inputLatency, &outputLatency);
  189130. if ((err = asioObject->start()) != 0)
  189131. {
  189132. // ignore an error here, as it might start later after setting other stuff up
  189133. logError ("ASIO start", err);
  189134. }
  189135. Thread::sleep (100);
  189136. asioObject->stop();
  189137. }
  189138. else
  189139. {
  189140. error = "Can't detect buffer sizes";
  189141. }
  189142. }
  189143. else
  189144. {
  189145. error = "Can't detect asio channels";
  189146. }
  189147. }
  189148. }
  189149. else
  189150. {
  189151. error = "No such device";
  189152. }
  189153. if (error.isNotEmpty())
  189154. {
  189155. logError (error, err);
  189156. if (asioObject != 0)
  189157. asioObject->disposeBuffers();
  189158. removeCurrentDriver();
  189159. isASIOOpen = false;
  189160. }
  189161. else
  189162. {
  189163. isASIOOpen = true;
  189164. log ("ASIO device open");
  189165. }
  189166. isOpen_ = false;
  189167. needToReset = false;
  189168. isReSync = false;
  189169. return error;
  189170. }
  189171. void callback (const long index) throw()
  189172. {
  189173. if (isStarted)
  189174. {
  189175. bufferIndex = index;
  189176. processBuffer();
  189177. }
  189178. else
  189179. {
  189180. if (postOutput && (asioObject != 0))
  189181. asioObject->outputReady();
  189182. }
  189183. calledback = true;
  189184. }
  189185. void processBuffer() throw()
  189186. {
  189187. const ASIOBufferInfo* const infos = bufferInfos;
  189188. const int bi = bufferIndex;
  189189. const ScopedLock sl (callbackLock);
  189190. if (needToReset)
  189191. {
  189192. needToReset = false;
  189193. if (isReSync)
  189194. {
  189195. log ("! ASIO resync");
  189196. isReSync = false;
  189197. }
  189198. else
  189199. {
  189200. startTimer (20);
  189201. }
  189202. }
  189203. if (bi >= 0)
  189204. {
  189205. const int samps = currentBlockSizeSamples;
  189206. if (currentCallback != 0)
  189207. {
  189208. int i;
  189209. for (i = 0; i < numActiveInputChans; ++i)
  189210. {
  189211. float* const dst = inBuffers[i];
  189212. jassert (dst != 0);
  189213. const char* const src = (const char*) (infos[i].buffers[bi]);
  189214. if (inputChannelIsFloat[i])
  189215. {
  189216. memcpy (dst, src, samps * sizeof (float));
  189217. }
  189218. else
  189219. {
  189220. jassert (dst == tempBuffer + (samps * i));
  189221. switch (inputChannelBitDepths[i])
  189222. {
  189223. case 16:
  189224. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189225. samps, inputChannelLittleEndian[i]);
  189226. break;
  189227. case 24:
  189228. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189229. samps, inputChannelLittleEndian[i]);
  189230. break;
  189231. case 32:
  189232. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189233. samps, inputChannelLittleEndian[i]);
  189234. break;
  189235. case 64:
  189236. jassertfalse
  189237. break;
  189238. }
  189239. }
  189240. }
  189241. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189242. numActiveInputChans,
  189243. outBuffers,
  189244. numActiveOutputChans,
  189245. samps);
  189246. for (i = 0; i < numActiveOutputChans; ++i)
  189247. {
  189248. float* const src = outBuffers[i];
  189249. jassert (src != 0);
  189250. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189251. if (outputChannelIsFloat[i])
  189252. {
  189253. memcpy (dst, src, samps * sizeof (float));
  189254. }
  189255. else
  189256. {
  189257. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189258. switch (outputChannelBitDepths[i])
  189259. {
  189260. case 16:
  189261. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189262. samps, outputChannelLittleEndian[i]);
  189263. break;
  189264. case 24:
  189265. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189266. samps, outputChannelLittleEndian[i]);
  189267. break;
  189268. case 32:
  189269. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189270. samps, outputChannelLittleEndian[i]);
  189271. break;
  189272. case 64:
  189273. jassertfalse
  189274. break;
  189275. }
  189276. }
  189277. }
  189278. }
  189279. else
  189280. {
  189281. for (int i = 0; i < numActiveOutputChans; ++i)
  189282. {
  189283. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189284. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189285. }
  189286. }
  189287. }
  189288. if (postOutput)
  189289. asioObject->outputReady();
  189290. }
  189291. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189292. {
  189293. if (currentASIODev[0] != 0)
  189294. currentASIODev[0]->callback (index);
  189295. return 0;
  189296. }
  189297. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189298. {
  189299. if (currentASIODev[1] != 0)
  189300. currentASIODev[1]->callback (index);
  189301. return 0;
  189302. }
  189303. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189304. {
  189305. if (currentASIODev[2] != 0)
  189306. currentASIODev[2]->callback (index);
  189307. return 0;
  189308. }
  189309. static void bufferSwitchCallback0 (long index, long) throw()
  189310. {
  189311. if (currentASIODev[0] != 0)
  189312. currentASIODev[0]->callback (index);
  189313. }
  189314. static void bufferSwitchCallback1 (long index, long) throw()
  189315. {
  189316. if (currentASIODev[1] != 0)
  189317. currentASIODev[1]->callback (index);
  189318. }
  189319. static void bufferSwitchCallback2 (long index, long) throw()
  189320. {
  189321. if (currentASIODev[2] != 0)
  189322. currentASIODev[2]->callback (index);
  189323. }
  189324. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189325. {
  189326. return asioMessagesCallback (selector, value, 0);
  189327. }
  189328. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189329. {
  189330. return asioMessagesCallback (selector, value, 1);
  189331. }
  189332. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189333. {
  189334. return asioMessagesCallback (selector, value, 2);
  189335. }
  189336. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189337. {
  189338. switch (selector)
  189339. {
  189340. case kAsioSelectorSupported:
  189341. if (value == kAsioResetRequest
  189342. || value == kAsioEngineVersion
  189343. || value == kAsioResyncRequest
  189344. || value == kAsioLatenciesChanged
  189345. || value == kAsioSupportsInputMonitor)
  189346. return 1;
  189347. break;
  189348. case kAsioBufferSizeChange:
  189349. break;
  189350. case kAsioResetRequest:
  189351. if (currentASIODev[deviceIndex] != 0)
  189352. currentASIODev[deviceIndex]->resetRequest();
  189353. return 1;
  189354. case kAsioResyncRequest:
  189355. if (currentASIODev[deviceIndex] != 0)
  189356. currentASIODev[deviceIndex]->resyncRequest();
  189357. return 1;
  189358. case kAsioLatenciesChanged:
  189359. return 1;
  189360. case kAsioEngineVersion:
  189361. return 2;
  189362. case kAsioSupportsTimeInfo:
  189363. case kAsioSupportsTimeCode:
  189364. return 0;
  189365. }
  189366. return 0;
  189367. }
  189368. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189369. {
  189370. }
  189371. static void convertInt16ToFloat (const char* src,
  189372. float* dest,
  189373. const int srcStrideBytes,
  189374. int numSamples,
  189375. const bool littleEndian) throw()
  189376. {
  189377. const double g = 1.0 / 32768.0;
  189378. if (littleEndian)
  189379. {
  189380. while (--numSamples >= 0)
  189381. {
  189382. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189383. src += srcStrideBytes;
  189384. }
  189385. }
  189386. else
  189387. {
  189388. while (--numSamples >= 0)
  189389. {
  189390. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189391. src += srcStrideBytes;
  189392. }
  189393. }
  189394. }
  189395. static void convertFloatToInt16 (const float* src,
  189396. char* dest,
  189397. const int dstStrideBytes,
  189398. int numSamples,
  189399. const bool littleEndian) throw()
  189400. {
  189401. const double maxVal = (double) 0x7fff;
  189402. if (littleEndian)
  189403. {
  189404. while (--numSamples >= 0)
  189405. {
  189406. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189407. dest += dstStrideBytes;
  189408. }
  189409. }
  189410. else
  189411. {
  189412. while (--numSamples >= 0)
  189413. {
  189414. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189415. dest += dstStrideBytes;
  189416. }
  189417. }
  189418. }
  189419. static void convertInt24ToFloat (const char* src,
  189420. float* dest,
  189421. const int srcStrideBytes,
  189422. int numSamples,
  189423. const bool littleEndian) throw()
  189424. {
  189425. const double g = 1.0 / 0x7fffff;
  189426. if (littleEndian)
  189427. {
  189428. while (--numSamples >= 0)
  189429. {
  189430. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189431. src += srcStrideBytes;
  189432. }
  189433. }
  189434. else
  189435. {
  189436. while (--numSamples >= 0)
  189437. {
  189438. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189439. src += srcStrideBytes;
  189440. }
  189441. }
  189442. }
  189443. static void convertFloatToInt24 (const float* src,
  189444. char* dest,
  189445. const int dstStrideBytes,
  189446. int numSamples,
  189447. const bool littleEndian) throw()
  189448. {
  189449. const double maxVal = (double) 0x7fffff;
  189450. if (littleEndian)
  189451. {
  189452. while (--numSamples >= 0)
  189453. {
  189454. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189455. dest += dstStrideBytes;
  189456. }
  189457. }
  189458. else
  189459. {
  189460. while (--numSamples >= 0)
  189461. {
  189462. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189463. dest += dstStrideBytes;
  189464. }
  189465. }
  189466. }
  189467. static void convertInt32ToFloat (const char* src,
  189468. float* dest,
  189469. const int srcStrideBytes,
  189470. int numSamples,
  189471. const bool littleEndian) throw()
  189472. {
  189473. const double g = 1.0 / 0x7fffffff;
  189474. if (littleEndian)
  189475. {
  189476. while (--numSamples >= 0)
  189477. {
  189478. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189479. src += srcStrideBytes;
  189480. }
  189481. }
  189482. else
  189483. {
  189484. while (--numSamples >= 0)
  189485. {
  189486. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189487. src += srcStrideBytes;
  189488. }
  189489. }
  189490. }
  189491. static void convertFloatToInt32 (const float* src,
  189492. char* dest,
  189493. const int dstStrideBytes,
  189494. int numSamples,
  189495. const bool littleEndian) throw()
  189496. {
  189497. const double maxVal = (double) 0x7fffffff;
  189498. if (littleEndian)
  189499. {
  189500. while (--numSamples >= 0)
  189501. {
  189502. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189503. dest += dstStrideBytes;
  189504. }
  189505. }
  189506. else
  189507. {
  189508. while (--numSamples >= 0)
  189509. {
  189510. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189511. dest += dstStrideBytes;
  189512. }
  189513. }
  189514. }
  189515. static void typeToFormatParameters (const long type,
  189516. int& bitDepth,
  189517. int& byteStride,
  189518. bool& formatIsFloat,
  189519. bool& littleEndian) throw()
  189520. {
  189521. bitDepth = 0;
  189522. littleEndian = false;
  189523. formatIsFloat = false;
  189524. switch (type)
  189525. {
  189526. case ASIOSTInt16MSB:
  189527. case ASIOSTInt16LSB:
  189528. case ASIOSTInt32MSB16:
  189529. case ASIOSTInt32LSB16:
  189530. bitDepth = 16; break;
  189531. case ASIOSTFloat32MSB:
  189532. case ASIOSTFloat32LSB:
  189533. formatIsFloat = true;
  189534. bitDepth = 32; break;
  189535. case ASIOSTInt32MSB:
  189536. case ASIOSTInt32LSB:
  189537. bitDepth = 32; break;
  189538. case ASIOSTInt24MSB:
  189539. case ASIOSTInt24LSB:
  189540. case ASIOSTInt32MSB24:
  189541. case ASIOSTInt32LSB24:
  189542. case ASIOSTInt32MSB18:
  189543. case ASIOSTInt32MSB20:
  189544. case ASIOSTInt32LSB18:
  189545. case ASIOSTInt32LSB20:
  189546. bitDepth = 24; break;
  189547. case ASIOSTFloat64MSB:
  189548. case ASIOSTFloat64LSB:
  189549. default:
  189550. bitDepth = 64;
  189551. break;
  189552. }
  189553. switch (type)
  189554. {
  189555. case ASIOSTInt16MSB:
  189556. case ASIOSTInt32MSB16:
  189557. case ASIOSTFloat32MSB:
  189558. case ASIOSTFloat64MSB:
  189559. case ASIOSTInt32MSB:
  189560. case ASIOSTInt32MSB18:
  189561. case ASIOSTInt32MSB20:
  189562. case ASIOSTInt32MSB24:
  189563. case ASIOSTInt24MSB:
  189564. littleEndian = false; break;
  189565. case ASIOSTInt16LSB:
  189566. case ASIOSTInt32LSB16:
  189567. case ASIOSTFloat32LSB:
  189568. case ASIOSTFloat64LSB:
  189569. case ASIOSTInt32LSB:
  189570. case ASIOSTInt32LSB18:
  189571. case ASIOSTInt32LSB20:
  189572. case ASIOSTInt32LSB24:
  189573. case ASIOSTInt24LSB:
  189574. littleEndian = true; break;
  189575. default:
  189576. break;
  189577. }
  189578. switch (type)
  189579. {
  189580. case ASIOSTInt16LSB:
  189581. case ASIOSTInt16MSB:
  189582. byteStride = 2; break;
  189583. case ASIOSTInt24LSB:
  189584. case ASIOSTInt24MSB:
  189585. byteStride = 3; break;
  189586. case ASIOSTInt32MSB16:
  189587. case ASIOSTInt32LSB16:
  189588. case ASIOSTInt32MSB:
  189589. case ASIOSTInt32MSB18:
  189590. case ASIOSTInt32MSB20:
  189591. case ASIOSTInt32MSB24:
  189592. case ASIOSTInt32LSB:
  189593. case ASIOSTInt32LSB18:
  189594. case ASIOSTInt32LSB20:
  189595. case ASIOSTInt32LSB24:
  189596. case ASIOSTFloat32LSB:
  189597. case ASIOSTFloat32MSB:
  189598. byteStride = 4; break;
  189599. case ASIOSTFloat64MSB:
  189600. case ASIOSTFloat64LSB:
  189601. byteStride = 8; break;
  189602. default:
  189603. break;
  189604. }
  189605. }
  189606. };
  189607. class ASIOAudioIODeviceType : public AudioIODeviceType
  189608. {
  189609. public:
  189610. ASIOAudioIODeviceType()
  189611. : AudioIODeviceType (T("ASIO")),
  189612. hasScanned (false)
  189613. {
  189614. CoInitialize (0);
  189615. }
  189616. ~ASIOAudioIODeviceType()
  189617. {
  189618. }
  189619. void scanForDevices()
  189620. {
  189621. hasScanned = true;
  189622. deviceNames.clear();
  189623. classIds.clear();
  189624. HKEY hk = 0;
  189625. int index = 0;
  189626. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189627. {
  189628. for (;;)
  189629. {
  189630. char name [256];
  189631. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189632. {
  189633. addDriverInfo (name, hk);
  189634. }
  189635. else
  189636. {
  189637. break;
  189638. }
  189639. }
  189640. RegCloseKey (hk);
  189641. }
  189642. }
  189643. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  189644. {
  189645. jassert (hasScanned); // need to call scanForDevices() before doing this
  189646. return deviceNames;
  189647. }
  189648. int getDefaultDeviceIndex (const bool) const
  189649. {
  189650. jassert (hasScanned); // need to call scanForDevices() before doing this
  189651. for (int i = deviceNames.size(); --i >= 0;)
  189652. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  189653. return i; // asio4all is a safe choice for a default..
  189654. #if JUCE_DEBUG
  189655. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  189656. return 1; // (the digi m-box driver crashes the app when you run
  189657. // it in the debugger, which can be a bit annoying)
  189658. #endif
  189659. return 0;
  189660. }
  189661. static int findFreeSlot()
  189662. {
  189663. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189664. if (currentASIODev[i] == 0)
  189665. return i;
  189666. jassertfalse; // unfortunately you can only have a finite number
  189667. // of ASIO devices open at the same time..
  189668. return -1;
  189669. }
  189670. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  189671. {
  189672. jassert (hasScanned); // need to call scanForDevices() before doing this
  189673. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189674. }
  189675. bool hasSeparateInputsAndOutputs() const { return false; }
  189676. AudioIODevice* createDevice (const String& outputDeviceName,
  189677. const String& inputDeviceName)
  189678. {
  189679. // ASIO can't open two different devices for input and output - they must be the same one.
  189680. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189681. jassert (hasScanned); // need to call scanForDevices() before doing this
  189682. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189683. : inputDeviceName);
  189684. if (index >= 0)
  189685. {
  189686. const int freeSlot = findFreeSlot();
  189687. if (freeSlot >= 0)
  189688. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189689. }
  189690. return 0;
  189691. }
  189692. juce_UseDebuggingNewOperator
  189693. private:
  189694. StringArray deviceNames;
  189695. OwnedArray <CLSID> classIds;
  189696. bool hasScanned;
  189697. static bool checkClassIsOk (const String& classId)
  189698. {
  189699. HKEY hk = 0;
  189700. bool ok = false;
  189701. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189702. {
  189703. int index = 0;
  189704. for (;;)
  189705. {
  189706. WCHAR buf [512];
  189707. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189708. {
  189709. if (classId.equalsIgnoreCase (buf))
  189710. {
  189711. HKEY subKey, pathKey;
  189712. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189713. {
  189714. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189715. {
  189716. WCHAR pathName [1024];
  189717. DWORD dtype = REG_SZ;
  189718. DWORD dsize = sizeof (pathName);
  189719. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189720. ok = File (pathName).exists();
  189721. RegCloseKey (pathKey);
  189722. }
  189723. RegCloseKey (subKey);
  189724. }
  189725. break;
  189726. }
  189727. }
  189728. else
  189729. {
  189730. break;
  189731. }
  189732. }
  189733. RegCloseKey (hk);
  189734. }
  189735. return ok;
  189736. }
  189737. void addDriverInfo (const String& keyName, HKEY hk)
  189738. {
  189739. HKEY subKey;
  189740. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189741. {
  189742. WCHAR buf [256];
  189743. zerostruct (buf);
  189744. DWORD dtype = REG_SZ;
  189745. DWORD dsize = sizeof (buf);
  189746. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189747. {
  189748. if (dsize > 0 && checkClassIsOk (buf))
  189749. {
  189750. CLSID classId;
  189751. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189752. {
  189753. dtype = REG_SZ;
  189754. dsize = sizeof (buf);
  189755. String deviceName;
  189756. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189757. deviceName = buf;
  189758. else
  189759. deviceName = keyName;
  189760. log (T("found ") + deviceName);
  189761. deviceNames.add (deviceName);
  189762. classIds.add (new CLSID (classId));
  189763. }
  189764. }
  189765. RegCloseKey (subKey);
  189766. }
  189767. }
  189768. }
  189769. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189770. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189771. };
  189772. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189773. {
  189774. return new ASIOAudioIODeviceType();
  189775. }
  189776. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189777. void* guid,
  189778. const String& optionalDllForDirectLoading)
  189779. {
  189780. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189781. if (freeSlot < 0)
  189782. return 0;
  189783. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189784. }
  189785. #undef log
  189786. #endif
  189787. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189788. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189789. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189790. // compiled on its own).
  189791. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189792. END_JUCE_NAMESPACE
  189793. extern "C"
  189794. {
  189795. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189796. typedef struct typeDSBUFFERDESC
  189797. {
  189798. DWORD dwSize;
  189799. DWORD dwFlags;
  189800. DWORD dwBufferBytes;
  189801. DWORD dwReserved;
  189802. LPWAVEFORMATEX lpwfxFormat;
  189803. GUID guid3DAlgorithm;
  189804. } DSBUFFERDESC;
  189805. struct IDirectSoundBuffer;
  189806. #undef INTERFACE
  189807. #define INTERFACE IDirectSound
  189808. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189809. {
  189810. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189811. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189812. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189813. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189814. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189815. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189816. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189817. STDMETHOD(Compact) (THIS) PURE;
  189818. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189819. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189820. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189821. };
  189822. #undef INTERFACE
  189823. #define INTERFACE IDirectSoundBuffer
  189824. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189825. {
  189826. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189827. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189828. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189829. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189830. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189831. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189832. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189833. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189834. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189835. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189836. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189837. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189838. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189839. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189840. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189841. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189842. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189843. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189844. STDMETHOD(Stop) (THIS) PURE;
  189845. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189846. STDMETHOD(Restore) (THIS) PURE;
  189847. };
  189848. typedef struct typeDSCBUFFERDESC
  189849. {
  189850. DWORD dwSize;
  189851. DWORD dwFlags;
  189852. DWORD dwBufferBytes;
  189853. DWORD dwReserved;
  189854. LPWAVEFORMATEX lpwfxFormat;
  189855. } DSCBUFFERDESC;
  189856. struct IDirectSoundCaptureBuffer;
  189857. #undef INTERFACE
  189858. #define INTERFACE IDirectSoundCapture
  189859. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189860. {
  189861. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189862. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189863. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189864. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189865. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189866. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189867. };
  189868. #undef INTERFACE
  189869. #define INTERFACE IDirectSoundCaptureBuffer
  189870. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189871. {
  189872. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189873. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189874. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189875. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189876. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189877. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189878. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189879. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189880. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189881. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189882. STDMETHOD(Stop) (THIS) PURE;
  189883. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189884. };
  189885. };
  189886. BEGIN_JUCE_NAMESPACE
  189887. static const String getDSErrorMessage (HRESULT hr)
  189888. {
  189889. const char* result = 0;
  189890. switch (hr)
  189891. {
  189892. case MAKE_HRESULT(1, 0x878, 10):
  189893. result = "Device already allocated";
  189894. break;
  189895. case MAKE_HRESULT(1, 0x878, 30):
  189896. result = "Control unavailable";
  189897. break;
  189898. case E_INVALIDARG:
  189899. result = "Invalid parameter";
  189900. break;
  189901. case MAKE_HRESULT(1, 0x878, 50):
  189902. result = "Invalid call";
  189903. break;
  189904. case E_FAIL:
  189905. result = "Generic error";
  189906. break;
  189907. case MAKE_HRESULT(1, 0x878, 70):
  189908. result = "Priority level error";
  189909. break;
  189910. case E_OUTOFMEMORY:
  189911. result = "Out of memory";
  189912. break;
  189913. case MAKE_HRESULT(1, 0x878, 100):
  189914. result = "Bad format";
  189915. break;
  189916. case E_NOTIMPL:
  189917. result = "Unsupported function";
  189918. break;
  189919. case MAKE_HRESULT(1, 0x878, 120):
  189920. result = "No driver";
  189921. break;
  189922. case MAKE_HRESULT(1, 0x878, 130):
  189923. result = "Already initialised";
  189924. break;
  189925. case CLASS_E_NOAGGREGATION:
  189926. result = "No aggregation";
  189927. break;
  189928. case MAKE_HRESULT(1, 0x878, 150):
  189929. result = "Buffer lost";
  189930. break;
  189931. case MAKE_HRESULT(1, 0x878, 160):
  189932. result = "Another app has priority";
  189933. break;
  189934. case MAKE_HRESULT(1, 0x878, 170):
  189935. result = "Uninitialised";
  189936. break;
  189937. case E_NOINTERFACE:
  189938. result = "No interface";
  189939. break;
  189940. case S_OK:
  189941. result = "No error";
  189942. break;
  189943. default:
  189944. return "Unknown error: " + String ((int) hr);
  189945. }
  189946. return result;
  189947. }
  189948. #define DS_DEBUGGING 1
  189949. #ifdef DS_DEBUGGING
  189950. #define CATCH JUCE_CATCH_EXCEPTION
  189951. #undef log
  189952. #define log(a) Logger::writeToLog(a);
  189953. #undef logError
  189954. #define logError(a) logDSError(a, __LINE__);
  189955. static void logDSError (HRESULT hr, int lineNum)
  189956. {
  189957. if (hr != S_OK)
  189958. {
  189959. String error ("DS error at line ");
  189960. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  189961. log (error);
  189962. }
  189963. }
  189964. #else
  189965. #define CATCH JUCE_CATCH_ALL
  189966. #define log(a)
  189967. #define logError(a)
  189968. #endif
  189969. #define DSOUND_FUNCTION(functionName, params) \
  189970. typedef HRESULT (WINAPI *type##functionName) params; \
  189971. static type##functionName ds##functionName = 0;
  189972. #define DSOUND_FUNCTION_LOAD(functionName) \
  189973. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  189974. jassert (ds##functionName != 0);
  189975. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  189976. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  189977. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  189978. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  189979. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189980. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189981. static void initialiseDSoundFunctions()
  189982. {
  189983. if (dsDirectSoundCreate == 0)
  189984. {
  189985. HMODULE h = LoadLibraryA ("dsound.dll");
  189986. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  189987. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  189988. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  189989. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  189990. }
  189991. }
  189992. class DSoundInternalOutChannel
  189993. {
  189994. String name;
  189995. LPGUID guid;
  189996. int sampleRate, bufferSizeSamples;
  189997. float* leftBuffer;
  189998. float* rightBuffer;
  189999. IDirectSound* pDirectSound;
  190000. IDirectSoundBuffer* pOutputBuffer;
  190001. DWORD writeOffset;
  190002. int totalBytesPerBuffer;
  190003. int bytesPerBuffer;
  190004. unsigned int lastPlayCursor;
  190005. public:
  190006. int bitDepth;
  190007. bool doneFlag;
  190008. DSoundInternalOutChannel (const String& name_,
  190009. LPGUID guid_,
  190010. int rate,
  190011. int bufferSize,
  190012. float* left,
  190013. float* right)
  190014. : name (name_),
  190015. guid (guid_),
  190016. sampleRate (rate),
  190017. bufferSizeSamples (bufferSize),
  190018. leftBuffer (left),
  190019. rightBuffer (right),
  190020. pDirectSound (0),
  190021. pOutputBuffer (0),
  190022. bitDepth (16)
  190023. {
  190024. }
  190025. ~DSoundInternalOutChannel()
  190026. {
  190027. close();
  190028. }
  190029. void close()
  190030. {
  190031. HRESULT hr;
  190032. if (pOutputBuffer != 0)
  190033. {
  190034. JUCE_TRY
  190035. {
  190036. log (T("closing dsound out: ") + name);
  190037. hr = pOutputBuffer->Stop();
  190038. logError (hr);
  190039. }
  190040. CATCH
  190041. JUCE_TRY
  190042. {
  190043. hr = pOutputBuffer->Release();
  190044. logError (hr);
  190045. }
  190046. CATCH
  190047. pOutputBuffer = 0;
  190048. }
  190049. if (pDirectSound != 0)
  190050. {
  190051. JUCE_TRY
  190052. {
  190053. hr = pDirectSound->Release();
  190054. logError (hr);
  190055. }
  190056. CATCH
  190057. pDirectSound = 0;
  190058. }
  190059. }
  190060. const String open()
  190061. {
  190062. log (T("opening dsound out device: ") + name
  190063. + T(" rate=") + String (sampleRate)
  190064. + T(" bits=") + String (bitDepth)
  190065. + T(" buf=") + String (bufferSizeSamples));
  190066. pDirectSound = 0;
  190067. pOutputBuffer = 0;
  190068. writeOffset = 0;
  190069. String error;
  190070. HRESULT hr = E_NOINTERFACE;
  190071. if (dsDirectSoundCreate != 0)
  190072. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190073. if (hr == S_OK)
  190074. {
  190075. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190076. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190077. const int numChannels = 2;
  190078. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190079. logError (hr);
  190080. if (hr == S_OK)
  190081. {
  190082. IDirectSoundBuffer* pPrimaryBuffer;
  190083. DSBUFFERDESC primaryDesc;
  190084. zerostruct (primaryDesc);
  190085. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190086. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190087. primaryDesc.dwBufferBytes = 0;
  190088. primaryDesc.lpwfxFormat = 0;
  190089. log ("opening dsound out step 2");
  190090. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190091. logError (hr);
  190092. if (hr == S_OK)
  190093. {
  190094. WAVEFORMATEX wfFormat;
  190095. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190096. wfFormat.nChannels = (unsigned short) numChannels;
  190097. wfFormat.nSamplesPerSec = sampleRate;
  190098. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190099. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190100. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190101. wfFormat.cbSize = 0;
  190102. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190103. logError (hr);
  190104. if (hr == S_OK)
  190105. {
  190106. DSBUFFERDESC secondaryDesc;
  190107. zerostruct (secondaryDesc);
  190108. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190109. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190110. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190111. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190112. secondaryDesc.lpwfxFormat = &wfFormat;
  190113. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190114. logError (hr);
  190115. if (hr == S_OK)
  190116. {
  190117. log ("opening dsound out step 3");
  190118. DWORD dwDataLen;
  190119. unsigned char* pDSBuffData;
  190120. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190121. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190122. logError (hr);
  190123. if (hr == S_OK)
  190124. {
  190125. zeromem (pDSBuffData, dwDataLen);
  190126. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190127. if (hr == S_OK)
  190128. {
  190129. hr = pOutputBuffer->SetCurrentPosition (0);
  190130. if (hr == S_OK)
  190131. {
  190132. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190133. if (hr == S_OK)
  190134. return String::empty;
  190135. }
  190136. }
  190137. }
  190138. }
  190139. }
  190140. }
  190141. }
  190142. }
  190143. error = getDSErrorMessage (hr);
  190144. close();
  190145. return error;
  190146. }
  190147. void synchronisePosition()
  190148. {
  190149. if (pOutputBuffer != 0)
  190150. {
  190151. DWORD playCursor;
  190152. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190153. }
  190154. }
  190155. bool service()
  190156. {
  190157. if (pOutputBuffer == 0)
  190158. return true;
  190159. DWORD playCursor, writeCursor;
  190160. for (;;)
  190161. {
  190162. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190163. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190164. {
  190165. pOutputBuffer->Restore();
  190166. continue;
  190167. }
  190168. if (hr == S_OK)
  190169. break;
  190170. logError (hr);
  190171. jassertfalse
  190172. return true;
  190173. }
  190174. int playWriteGap = writeCursor - playCursor;
  190175. if (playWriteGap < 0)
  190176. playWriteGap += totalBytesPerBuffer;
  190177. int bytesEmpty = playCursor - writeOffset;
  190178. if (bytesEmpty < 0)
  190179. bytesEmpty += totalBytesPerBuffer;
  190180. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190181. {
  190182. writeOffset = writeCursor;
  190183. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190184. }
  190185. if (bytesEmpty >= bytesPerBuffer)
  190186. {
  190187. LPBYTE lpbuf1 = 0;
  190188. LPBYTE lpbuf2 = 0;
  190189. DWORD dwSize1 = 0;
  190190. DWORD dwSize2 = 0;
  190191. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190192. bytesPerBuffer,
  190193. (void**) &lpbuf1, &dwSize1,
  190194. (void**) &lpbuf2, &dwSize2, 0);
  190195. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190196. {
  190197. pOutputBuffer->Restore();
  190198. hr = pOutputBuffer->Lock (writeOffset,
  190199. bytesPerBuffer,
  190200. (void**) &lpbuf1, &dwSize1,
  190201. (void**) &lpbuf2, &dwSize2, 0);
  190202. }
  190203. if (hr == S_OK)
  190204. {
  190205. if (bitDepth == 16)
  190206. {
  190207. const float gainL = 32767.0f;
  190208. const float gainR = 32767.0f;
  190209. int* dest = (int*)lpbuf1;
  190210. const float* left = leftBuffer;
  190211. const float* right = rightBuffer;
  190212. int samples1 = dwSize1 >> 2;
  190213. int samples2 = dwSize2 >> 2;
  190214. if (left == 0)
  190215. {
  190216. while (--samples1 >= 0)
  190217. {
  190218. int r = roundToInt (gainR * *right++);
  190219. if (r < -32768)
  190220. r = -32768;
  190221. else if (r > 32767)
  190222. r = 32767;
  190223. *dest++ = (r << 16);
  190224. }
  190225. dest = (int*)lpbuf2;
  190226. while (--samples2 >= 0)
  190227. {
  190228. int r = roundToInt (gainR * *right++);
  190229. if (r < -32768)
  190230. r = -32768;
  190231. else if (r > 32767)
  190232. r = 32767;
  190233. *dest++ = (r << 16);
  190234. }
  190235. }
  190236. else if (right == 0)
  190237. {
  190238. while (--samples1 >= 0)
  190239. {
  190240. int l = roundToInt (gainL * *left++);
  190241. if (l < -32768)
  190242. l = -32768;
  190243. else if (l > 32767)
  190244. l = 32767;
  190245. l &= 0xffff;
  190246. *dest++ = l;
  190247. }
  190248. dest = (int*)lpbuf2;
  190249. while (--samples2 >= 0)
  190250. {
  190251. int l = roundToInt (gainL * *left++);
  190252. if (l < -32768)
  190253. l = -32768;
  190254. else if (l > 32767)
  190255. l = 32767;
  190256. l &= 0xffff;
  190257. *dest++ = l;
  190258. }
  190259. }
  190260. else
  190261. {
  190262. while (--samples1 >= 0)
  190263. {
  190264. int l = roundToInt (gainL * *left++);
  190265. if (l < -32768)
  190266. l = -32768;
  190267. else if (l > 32767)
  190268. l = 32767;
  190269. l &= 0xffff;
  190270. int r = roundToInt (gainR * *right++);
  190271. if (r < -32768)
  190272. r = -32768;
  190273. else if (r > 32767)
  190274. r = 32767;
  190275. *dest++ = (r << 16) | l;
  190276. }
  190277. dest = (int*)lpbuf2;
  190278. while (--samples2 >= 0)
  190279. {
  190280. int l = roundToInt (gainL * *left++);
  190281. if (l < -32768)
  190282. l = -32768;
  190283. else if (l > 32767)
  190284. l = 32767;
  190285. l &= 0xffff;
  190286. int r = roundToInt (gainR * *right++);
  190287. if (r < -32768)
  190288. r = -32768;
  190289. else if (r > 32767)
  190290. r = 32767;
  190291. *dest++ = (r << 16) | l;
  190292. }
  190293. }
  190294. }
  190295. else
  190296. {
  190297. jassertfalse
  190298. }
  190299. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190300. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190301. }
  190302. else
  190303. {
  190304. jassertfalse
  190305. logError (hr);
  190306. }
  190307. bytesEmpty -= bytesPerBuffer;
  190308. return true;
  190309. }
  190310. else
  190311. {
  190312. return false;
  190313. }
  190314. }
  190315. };
  190316. struct DSoundInternalInChannel
  190317. {
  190318. String name;
  190319. LPGUID guid;
  190320. int sampleRate, bufferSizeSamples;
  190321. float* leftBuffer;
  190322. float* rightBuffer;
  190323. IDirectSound* pDirectSound;
  190324. IDirectSoundCapture* pDirectSoundCapture;
  190325. IDirectSoundCaptureBuffer* pInputBuffer;
  190326. public:
  190327. unsigned int readOffset;
  190328. int bytesPerBuffer, totalBytesPerBuffer;
  190329. int bitDepth;
  190330. bool doneFlag;
  190331. DSoundInternalInChannel (const String& name_,
  190332. LPGUID guid_,
  190333. int rate,
  190334. int bufferSize,
  190335. float* left,
  190336. float* right)
  190337. : name (name_),
  190338. guid (guid_),
  190339. sampleRate (rate),
  190340. bufferSizeSamples (bufferSize),
  190341. leftBuffer (left),
  190342. rightBuffer (right),
  190343. pDirectSound (0),
  190344. pDirectSoundCapture (0),
  190345. pInputBuffer (0),
  190346. bitDepth (16)
  190347. {
  190348. }
  190349. ~DSoundInternalInChannel()
  190350. {
  190351. close();
  190352. }
  190353. void close()
  190354. {
  190355. HRESULT hr;
  190356. if (pInputBuffer != 0)
  190357. {
  190358. JUCE_TRY
  190359. {
  190360. log (T("closing dsound in: ") + name);
  190361. hr = pInputBuffer->Stop();
  190362. logError (hr);
  190363. }
  190364. CATCH
  190365. JUCE_TRY
  190366. {
  190367. hr = pInputBuffer->Release();
  190368. logError (hr);
  190369. }
  190370. CATCH
  190371. pInputBuffer = 0;
  190372. }
  190373. if (pDirectSoundCapture != 0)
  190374. {
  190375. JUCE_TRY
  190376. {
  190377. hr = pDirectSoundCapture->Release();
  190378. logError (hr);
  190379. }
  190380. CATCH
  190381. pDirectSoundCapture = 0;
  190382. }
  190383. if (pDirectSound != 0)
  190384. {
  190385. JUCE_TRY
  190386. {
  190387. hr = pDirectSound->Release();
  190388. logError (hr);
  190389. }
  190390. CATCH
  190391. pDirectSound = 0;
  190392. }
  190393. }
  190394. const String open()
  190395. {
  190396. log (T("opening dsound in device: ") + name
  190397. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190398. pDirectSound = 0;
  190399. pDirectSoundCapture = 0;
  190400. pInputBuffer = 0;
  190401. readOffset = 0;
  190402. totalBytesPerBuffer = 0;
  190403. String error;
  190404. HRESULT hr = E_NOINTERFACE;
  190405. if (dsDirectSoundCaptureCreate != 0)
  190406. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190407. logError (hr);
  190408. if (hr == S_OK)
  190409. {
  190410. const int numChannels = 2;
  190411. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190412. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190413. WAVEFORMATEX wfFormat;
  190414. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190415. wfFormat.nChannels = (unsigned short)numChannels;
  190416. wfFormat.nSamplesPerSec = sampleRate;
  190417. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190418. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190419. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190420. wfFormat.cbSize = 0;
  190421. DSCBUFFERDESC captureDesc;
  190422. zerostruct (captureDesc);
  190423. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190424. captureDesc.dwFlags = 0;
  190425. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190426. captureDesc.lpwfxFormat = &wfFormat;
  190427. log (T("opening dsound in step 2"));
  190428. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190429. logError (hr);
  190430. if (hr == S_OK)
  190431. {
  190432. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190433. logError (hr);
  190434. if (hr == S_OK)
  190435. return String::empty;
  190436. }
  190437. }
  190438. error = getDSErrorMessage (hr);
  190439. close();
  190440. return error;
  190441. }
  190442. void synchronisePosition()
  190443. {
  190444. if (pInputBuffer != 0)
  190445. {
  190446. DWORD capturePos;
  190447. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190448. }
  190449. }
  190450. bool service()
  190451. {
  190452. if (pInputBuffer == 0)
  190453. return true;
  190454. DWORD capturePos, readPos;
  190455. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190456. logError (hr);
  190457. if (hr != S_OK)
  190458. return true;
  190459. int bytesFilled = readPos - readOffset;
  190460. if (bytesFilled < 0)
  190461. bytesFilled += totalBytesPerBuffer;
  190462. if (bytesFilled >= bytesPerBuffer)
  190463. {
  190464. LPBYTE lpbuf1 = 0;
  190465. LPBYTE lpbuf2 = 0;
  190466. DWORD dwsize1 = 0;
  190467. DWORD dwsize2 = 0;
  190468. HRESULT hr = pInputBuffer->Lock (readOffset,
  190469. bytesPerBuffer,
  190470. (void**) &lpbuf1, &dwsize1,
  190471. (void**) &lpbuf2, &dwsize2, 0);
  190472. if (hr == S_OK)
  190473. {
  190474. if (bitDepth == 16)
  190475. {
  190476. const float g = 1.0f / 32768.0f;
  190477. float* destL = leftBuffer;
  190478. float* destR = rightBuffer;
  190479. int samples1 = dwsize1 >> 2;
  190480. int samples2 = dwsize2 >> 2;
  190481. const short* src = (const short*)lpbuf1;
  190482. if (destL == 0)
  190483. {
  190484. while (--samples1 >= 0)
  190485. {
  190486. ++src;
  190487. *destR++ = *src++ * g;
  190488. }
  190489. src = (const short*)lpbuf2;
  190490. while (--samples2 >= 0)
  190491. {
  190492. ++src;
  190493. *destR++ = *src++ * g;
  190494. }
  190495. }
  190496. else if (destR == 0)
  190497. {
  190498. while (--samples1 >= 0)
  190499. {
  190500. *destL++ = *src++ * g;
  190501. ++src;
  190502. }
  190503. src = (const short*)lpbuf2;
  190504. while (--samples2 >= 0)
  190505. {
  190506. *destL++ = *src++ * g;
  190507. ++src;
  190508. }
  190509. }
  190510. else
  190511. {
  190512. while (--samples1 >= 0)
  190513. {
  190514. *destL++ = *src++ * g;
  190515. *destR++ = *src++ * g;
  190516. }
  190517. src = (const short*)lpbuf2;
  190518. while (--samples2 >= 0)
  190519. {
  190520. *destL++ = *src++ * g;
  190521. *destR++ = *src++ * g;
  190522. }
  190523. }
  190524. }
  190525. else
  190526. {
  190527. jassertfalse
  190528. }
  190529. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190530. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190531. }
  190532. else
  190533. {
  190534. logError (hr);
  190535. jassertfalse
  190536. }
  190537. bytesFilled -= bytesPerBuffer;
  190538. return true;
  190539. }
  190540. else
  190541. {
  190542. return false;
  190543. }
  190544. }
  190545. };
  190546. class DSoundAudioIODevice : public AudioIODevice,
  190547. public Thread
  190548. {
  190549. public:
  190550. DSoundAudioIODevice (const String& deviceName,
  190551. const int outputDeviceIndex_,
  190552. const int inputDeviceIndex_)
  190553. : AudioIODevice (deviceName, "DirectSound"),
  190554. Thread ("Juce DSound"),
  190555. isOpen_ (false),
  190556. isStarted (false),
  190557. outputDeviceIndex (outputDeviceIndex_),
  190558. inputDeviceIndex (inputDeviceIndex_),
  190559. numInputBuffers (0),
  190560. numOutputBuffers (0),
  190561. totalSamplesOut (0),
  190562. sampleRate (0.0),
  190563. inputBuffers (0),
  190564. outputBuffers (0),
  190565. callback (0),
  190566. bufferSizeSamples (0)
  190567. {
  190568. if (outputDeviceIndex_ >= 0)
  190569. {
  190570. outChannels.add (TRANS("Left"));
  190571. outChannels.add (TRANS("Right"));
  190572. }
  190573. if (inputDeviceIndex_ >= 0)
  190574. {
  190575. inChannels.add (TRANS("Left"));
  190576. inChannels.add (TRANS("Right"));
  190577. }
  190578. }
  190579. ~DSoundAudioIODevice()
  190580. {
  190581. close();
  190582. }
  190583. const StringArray getOutputChannelNames()
  190584. {
  190585. return outChannels;
  190586. }
  190587. const StringArray getInputChannelNames()
  190588. {
  190589. return inChannels;
  190590. }
  190591. int getNumSampleRates()
  190592. {
  190593. return 4;
  190594. }
  190595. double getSampleRate (int index)
  190596. {
  190597. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190598. return samps [jlimit (0, 3, index)];
  190599. }
  190600. int getNumBufferSizesAvailable()
  190601. {
  190602. return 50;
  190603. }
  190604. int getBufferSizeSamples (int index)
  190605. {
  190606. int n = 64;
  190607. for (int i = 0; i < index; ++i)
  190608. n += (n < 512) ? 32
  190609. : ((n < 1024) ? 64
  190610. : ((n < 2048) ? 128 : 256));
  190611. return n;
  190612. }
  190613. int getDefaultBufferSize()
  190614. {
  190615. return 2560;
  190616. }
  190617. const String open (const BitArray& inputChannels,
  190618. const BitArray& outputChannels,
  190619. double sampleRate,
  190620. int bufferSizeSamples)
  190621. {
  190622. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190623. isOpen_ = lastError.isEmpty();
  190624. return lastError;
  190625. }
  190626. void close()
  190627. {
  190628. stop();
  190629. if (isOpen_)
  190630. {
  190631. closeDevice();
  190632. isOpen_ = false;
  190633. }
  190634. }
  190635. bool isOpen()
  190636. {
  190637. return isOpen_ && isThreadRunning();
  190638. }
  190639. int getCurrentBufferSizeSamples()
  190640. {
  190641. return bufferSizeSamples;
  190642. }
  190643. double getCurrentSampleRate()
  190644. {
  190645. return sampleRate;
  190646. }
  190647. int getCurrentBitDepth()
  190648. {
  190649. int i, bits = 256;
  190650. for (i = inChans.size(); --i >= 0;)
  190651. bits = jmin (bits, inChans[i]->bitDepth);
  190652. for (i = outChans.size(); --i >= 0;)
  190653. bits = jmin (bits, outChans[i]->bitDepth);
  190654. if (bits > 32)
  190655. bits = 16;
  190656. return bits;
  190657. }
  190658. const BitArray getActiveOutputChannels() const
  190659. {
  190660. return enabledOutputs;
  190661. }
  190662. const BitArray getActiveInputChannels() const
  190663. {
  190664. return enabledInputs;
  190665. }
  190666. int getOutputLatencyInSamples()
  190667. {
  190668. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190669. }
  190670. int getInputLatencyInSamples()
  190671. {
  190672. return getOutputLatencyInSamples();
  190673. }
  190674. void start (AudioIODeviceCallback* call)
  190675. {
  190676. if (isOpen_ && call != 0 && ! isStarted)
  190677. {
  190678. if (! isThreadRunning())
  190679. {
  190680. // something gone wrong and the thread's stopped..
  190681. isOpen_ = false;
  190682. return;
  190683. }
  190684. call->audioDeviceAboutToStart (this);
  190685. const ScopedLock sl (startStopLock);
  190686. callback = call;
  190687. isStarted = true;
  190688. }
  190689. }
  190690. void stop()
  190691. {
  190692. if (isStarted)
  190693. {
  190694. AudioIODeviceCallback* const callbackLocal = callback;
  190695. {
  190696. const ScopedLock sl (startStopLock);
  190697. isStarted = false;
  190698. }
  190699. if (callbackLocal != 0)
  190700. callbackLocal->audioDeviceStopped();
  190701. }
  190702. }
  190703. bool isPlaying()
  190704. {
  190705. return isStarted && isOpen_ && isThreadRunning();
  190706. }
  190707. const String getLastError()
  190708. {
  190709. return lastError;
  190710. }
  190711. juce_UseDebuggingNewOperator
  190712. StringArray inChannels, outChannels;
  190713. int outputDeviceIndex, inputDeviceIndex;
  190714. private:
  190715. bool isOpen_;
  190716. bool isStarted;
  190717. String lastError;
  190718. OwnedArray <DSoundInternalInChannel> inChans;
  190719. OwnedArray <DSoundInternalOutChannel> outChans;
  190720. WaitableEvent startEvent;
  190721. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190722. int volatile totalSamplesOut;
  190723. int64 volatile lastBlockTime;
  190724. double sampleRate;
  190725. BitArray enabledInputs, enabledOutputs;
  190726. HeapBlock <float*> inputBuffers, outputBuffers;
  190727. AudioIODeviceCallback* callback;
  190728. CriticalSection startStopLock;
  190729. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190730. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190731. const String openDevice (const BitArray& inputChannels,
  190732. const BitArray& outputChannels,
  190733. double sampleRate_,
  190734. int bufferSizeSamples_);
  190735. void closeDevice()
  190736. {
  190737. isStarted = false;
  190738. stopThread (5000);
  190739. inChans.clear();
  190740. outChans.clear();
  190741. int i;
  190742. for (i = 0; i < numInputBuffers; ++i)
  190743. juce_free (inputBuffers[i]);
  190744. inputBuffers.free();
  190745. numInputBuffers = 0;
  190746. for (i = 0; i < numOutputBuffers; ++i)
  190747. juce_free (outputBuffers[i]);
  190748. outputBuffers.free();
  190749. numOutputBuffers = 0;
  190750. }
  190751. void resync()
  190752. {
  190753. if (! threadShouldExit())
  190754. {
  190755. sleep (5);
  190756. int i;
  190757. for (i = 0; i < outChans.size(); ++i)
  190758. outChans.getUnchecked(i)->synchronisePosition();
  190759. for (i = 0; i < inChans.size(); ++i)
  190760. inChans.getUnchecked(i)->synchronisePosition();
  190761. }
  190762. }
  190763. public:
  190764. void run()
  190765. {
  190766. while (! threadShouldExit())
  190767. {
  190768. if (wait (100))
  190769. break;
  190770. }
  190771. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190772. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190773. while (! threadShouldExit())
  190774. {
  190775. int numToDo = 0;
  190776. uint32 startTime = Time::getMillisecondCounter();
  190777. int i;
  190778. for (i = inChans.size(); --i >= 0;)
  190779. {
  190780. inChans.getUnchecked(i)->doneFlag = false;
  190781. ++numToDo;
  190782. }
  190783. for (i = outChans.size(); --i >= 0;)
  190784. {
  190785. outChans.getUnchecked(i)->doneFlag = false;
  190786. ++numToDo;
  190787. }
  190788. if (numToDo > 0)
  190789. {
  190790. const int maxCount = 3;
  190791. int count = maxCount;
  190792. for (;;)
  190793. {
  190794. for (i = inChans.size(); --i >= 0;)
  190795. {
  190796. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190797. if ((! in->doneFlag) && in->service())
  190798. {
  190799. in->doneFlag = true;
  190800. --numToDo;
  190801. }
  190802. }
  190803. for (i = outChans.size(); --i >= 0;)
  190804. {
  190805. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190806. if ((! out->doneFlag) && out->service())
  190807. {
  190808. out->doneFlag = true;
  190809. --numToDo;
  190810. }
  190811. }
  190812. if (numToDo <= 0)
  190813. break;
  190814. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190815. {
  190816. resync();
  190817. break;
  190818. }
  190819. if (--count <= 0)
  190820. {
  190821. Sleep (1);
  190822. count = maxCount;
  190823. }
  190824. if (threadShouldExit())
  190825. return;
  190826. }
  190827. }
  190828. else
  190829. {
  190830. sleep (1);
  190831. }
  190832. const ScopedLock sl (startStopLock);
  190833. if (isStarted)
  190834. {
  190835. JUCE_TRY
  190836. {
  190837. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190838. numInputBuffers,
  190839. outputBuffers,
  190840. numOutputBuffers,
  190841. bufferSizeSamples);
  190842. }
  190843. JUCE_CATCH_EXCEPTION
  190844. totalSamplesOut += bufferSizeSamples;
  190845. }
  190846. else
  190847. {
  190848. for (i = 0; i < numOutputBuffers; ++i)
  190849. if (outputBuffers[i] != 0)
  190850. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190851. totalSamplesOut = 0;
  190852. sleep (1);
  190853. }
  190854. }
  190855. }
  190856. };
  190857. class DSoundAudioIODeviceType : public AudioIODeviceType
  190858. {
  190859. public:
  190860. DSoundAudioIODeviceType()
  190861. : AudioIODeviceType (T("DirectSound")),
  190862. hasScanned (false)
  190863. {
  190864. initialiseDSoundFunctions();
  190865. }
  190866. ~DSoundAudioIODeviceType()
  190867. {
  190868. }
  190869. void scanForDevices()
  190870. {
  190871. hasScanned = true;
  190872. outputDeviceNames.clear();
  190873. outputGuids.clear();
  190874. inputDeviceNames.clear();
  190875. inputGuids.clear();
  190876. if (dsDirectSoundEnumerateW != 0)
  190877. {
  190878. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190879. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190880. }
  190881. }
  190882. const StringArray getDeviceNames (const bool wantInputNames) const
  190883. {
  190884. jassert (hasScanned); // need to call scanForDevices() before doing this
  190885. return wantInputNames ? inputDeviceNames
  190886. : outputDeviceNames;
  190887. }
  190888. int getDefaultDeviceIndex (const bool /*forInput*/) const
  190889. {
  190890. jassert (hasScanned); // need to call scanForDevices() before doing this
  190891. return 0;
  190892. }
  190893. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  190894. {
  190895. jassert (hasScanned); // need to call scanForDevices() before doing this
  190896. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190897. if (d == 0)
  190898. return -1;
  190899. return asInput ? d->inputDeviceIndex
  190900. : d->outputDeviceIndex;
  190901. }
  190902. bool hasSeparateInputsAndOutputs() const { return true; }
  190903. AudioIODevice* createDevice (const String& outputDeviceName,
  190904. const String& inputDeviceName)
  190905. {
  190906. jassert (hasScanned); // need to call scanForDevices() before doing this
  190907. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190908. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190909. if (outputIndex >= 0 || inputIndex >= 0)
  190910. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190911. : inputDeviceName,
  190912. outputIndex, inputIndex);
  190913. return 0;
  190914. }
  190915. juce_UseDebuggingNewOperator
  190916. StringArray outputDeviceNames;
  190917. OwnedArray <GUID> outputGuids;
  190918. StringArray inputDeviceNames;
  190919. OwnedArray <GUID> inputGuids;
  190920. private:
  190921. bool hasScanned;
  190922. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190923. {
  190924. desc = desc.trim();
  190925. if (desc.isNotEmpty())
  190926. {
  190927. const String origDesc (desc);
  190928. int n = 2;
  190929. while (outputDeviceNames.contains (desc))
  190930. desc = origDesc + T(" (") + String (n++) + T(")");
  190931. outputDeviceNames.add (desc);
  190932. if (lpGUID != 0)
  190933. outputGuids.add (new GUID (*lpGUID));
  190934. else
  190935. outputGuids.add (0);
  190936. }
  190937. return TRUE;
  190938. }
  190939. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190940. {
  190941. return ((DSoundAudioIODeviceType*) object)
  190942. ->outputEnumProc (lpGUID, String (description));
  190943. }
  190944. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190945. {
  190946. return ((DSoundAudioIODeviceType*) object)
  190947. ->outputEnumProc (lpGUID, String (description));
  190948. }
  190949. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  190950. {
  190951. desc = desc.trim();
  190952. if (desc.isNotEmpty())
  190953. {
  190954. const String origDesc (desc);
  190955. int n = 2;
  190956. while (inputDeviceNames.contains (desc))
  190957. desc = origDesc + T(" (") + String (n++) + T(")");
  190958. inputDeviceNames.add (desc);
  190959. if (lpGUID != 0)
  190960. inputGuids.add (new GUID (*lpGUID));
  190961. else
  190962. inputGuids.add (0);
  190963. }
  190964. return TRUE;
  190965. }
  190966. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190967. {
  190968. return ((DSoundAudioIODeviceType*) object)
  190969. ->inputEnumProc (lpGUID, String (description));
  190970. }
  190971. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190972. {
  190973. return ((DSoundAudioIODeviceType*) object)
  190974. ->inputEnumProc (lpGUID, String (description));
  190975. }
  190976. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  190977. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  190978. };
  190979. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  190980. const BitArray& outputChannels,
  190981. double sampleRate_,
  190982. int bufferSizeSamples_)
  190983. {
  190984. closeDevice();
  190985. totalSamplesOut = 0;
  190986. sampleRate = sampleRate_;
  190987. if (bufferSizeSamples_ <= 0)
  190988. bufferSizeSamples_ = 960; // use as a default size if none is set.
  190989. bufferSizeSamples = bufferSizeSamples_ & ~7;
  190990. DSoundAudioIODeviceType dlh;
  190991. dlh.scanForDevices();
  190992. enabledInputs = inputChannels;
  190993. enabledInputs.setRange (inChannels.size(),
  190994. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  190995. false);
  190996. numInputBuffers = enabledInputs.countNumberOfSetBits();
  190997. inputBuffers.calloc (numInputBuffers + 2);
  190998. int i, numIns = 0;
  190999. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  191000. {
  191001. float* left = 0;
  191002. float* right = 0;
  191003. if (enabledInputs[i])
  191004. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191005. if (enabledInputs[i + 1])
  191006. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191007. if (left != 0 || right != 0)
  191008. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  191009. dlh.inputGuids [inputDeviceIndex],
  191010. (int) sampleRate, bufferSizeSamples,
  191011. left, right));
  191012. }
  191013. enabledOutputs = outputChannels;
  191014. enabledOutputs.setRange (outChannels.size(),
  191015. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  191016. false);
  191017. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  191018. outputBuffers.calloc (numOutputBuffers + 2);
  191019. int numOuts = 0;
  191020. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  191021. {
  191022. float* left = 0;
  191023. float* right = 0;
  191024. if (enabledOutputs[i])
  191025. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191026. if (enabledOutputs[i + 1])
  191027. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191028. if (left != 0 || right != 0)
  191029. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  191030. dlh.outputGuids [outputDeviceIndex],
  191031. (int) sampleRate, bufferSizeSamples,
  191032. left, right));
  191033. }
  191034. String error;
  191035. // boost our priority while opening the devices to try to get better sync between them
  191036. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  191037. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  191038. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191039. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191040. for (i = 0; i < outChans.size(); ++i)
  191041. {
  191042. error = outChans[i]->open();
  191043. if (error.isNotEmpty())
  191044. {
  191045. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191046. + T(": \"") + error + T("\"");
  191047. break;
  191048. }
  191049. }
  191050. if (error.isEmpty())
  191051. {
  191052. for (i = 0; i < inChans.size(); ++i)
  191053. {
  191054. error = inChans[i]->open();
  191055. if (error.isNotEmpty())
  191056. {
  191057. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191058. + T(": \"") + error + T("\"");
  191059. break;
  191060. }
  191061. }
  191062. }
  191063. if (error.isEmpty())
  191064. {
  191065. totalSamplesOut = 0;
  191066. for (i = 0; i < outChans.size(); ++i)
  191067. outChans.getUnchecked(i)->synchronisePosition();
  191068. for (i = 0; i < inChans.size(); ++i)
  191069. inChans.getUnchecked(i)->synchronisePosition();
  191070. startThread (9);
  191071. sleep (10);
  191072. notify();
  191073. }
  191074. else
  191075. {
  191076. log (error);
  191077. }
  191078. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191079. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191080. return error;
  191081. }
  191082. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191083. {
  191084. return new DSoundAudioIODeviceType();
  191085. }
  191086. #undef log
  191087. #endif
  191088. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  191089. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  191090. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191091. // compiled on its own).
  191092. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191093. #if 1
  191094. const String getAudioErrorDesc (HRESULT hr)
  191095. {
  191096. const char* e = 0;
  191097. switch (hr)
  191098. {
  191099. case E_POINTER: e = "E_POINTER"; break;
  191100. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191101. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191102. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191103. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191104. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191105. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191106. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191107. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191108. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191109. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191110. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191111. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191112. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191113. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191114. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191115. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191116. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191117. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191118. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191119. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191120. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191121. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191122. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191123. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191124. default: return String::toHexString ((int) hr);
  191125. }
  191126. return e;
  191127. }
  191128. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191129. #define OK(a) wasapi_checkResult(a)
  191130. static bool wasapi_checkResult (HRESULT hr)
  191131. {
  191132. logFailure (hr);
  191133. return SUCCEEDED (hr);
  191134. }
  191135. #else
  191136. #define logFailure(hr) {}
  191137. #define OK(a) SUCCEEDED(a)
  191138. #endif
  191139. static const String wasapi_getDeviceID (IMMDevice* const device)
  191140. {
  191141. String s;
  191142. WCHAR* deviceId = 0;
  191143. if (OK (device->GetId (&deviceId)))
  191144. {
  191145. s = String (deviceId);
  191146. CoTaskMemFree (deviceId);
  191147. }
  191148. return s;
  191149. }
  191150. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191151. {
  191152. EDataFlow flow = eRender;
  191153. ComSmartPtr <IMMEndpoint> endPoint;
  191154. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191155. (void) OK (endPoint->GetDataFlow (&flow));
  191156. return flow;
  191157. }
  191158. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191159. {
  191160. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191161. }
  191162. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191163. {
  191164. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191165. : sizeof (WAVEFORMATEX));
  191166. }
  191167. class WASAPIDeviceBase
  191168. {
  191169. public:
  191170. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191171. : device (device_),
  191172. sampleRate (0),
  191173. numChannels (0),
  191174. actualNumChannels (0),
  191175. defaultSampleRate (0),
  191176. minBufferSize (0),
  191177. defaultBufferSize (0),
  191178. latencySamples (0),
  191179. useExclusiveMode (useExclusiveMode_)
  191180. {
  191181. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191182. ComSmartPtr <IAudioClient> tempClient (createClient());
  191183. if (tempClient == 0)
  191184. return;
  191185. REFERENCE_TIME defaultPeriod, minPeriod;
  191186. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191187. return;
  191188. WAVEFORMATEX* mixFormat = 0;
  191189. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191190. return;
  191191. WAVEFORMATEXTENSIBLE format;
  191192. wasapi_copyWavFormat (format, mixFormat);
  191193. CoTaskMemFree (mixFormat);
  191194. actualNumChannels = numChannels = format.Format.nChannels;
  191195. defaultSampleRate = format.Format.nSamplesPerSec;
  191196. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191197. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191198. FloatElementComparator<double> comparator;
  191199. rates.addSorted (comparator, defaultSampleRate);
  191200. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191201. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191202. {
  191203. if (ratesToTest[i] == defaultSampleRate)
  191204. continue;
  191205. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191206. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191207. (WAVEFORMATEX*) &format, 0)))
  191208. if (! rates.contains (ratesToTest[i]))
  191209. rates.addSorted (comparator, ratesToTest[i]);
  191210. }
  191211. }
  191212. ~WASAPIDeviceBase()
  191213. {
  191214. device = 0;
  191215. CloseHandle (clientEvent);
  191216. }
  191217. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191218. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191219. {
  191220. sampleRate = newSampleRate;
  191221. channels = newChannels;
  191222. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191223. numChannels = channels.getHighestBit() + 1;
  191224. if (numChannels == 0)
  191225. return true;
  191226. client = createClient();
  191227. if (client != 0
  191228. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191229. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191230. {
  191231. channelMaps.clear();
  191232. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191233. if (channels[i])
  191234. channelMaps.add (i);
  191235. REFERENCE_TIME latency;
  191236. if (OK (client->GetStreamLatency (&latency)))
  191237. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191238. (void) OK (client->GetBufferSize (&actualBufferSize));
  191239. return OK (client->SetEventHandle (clientEvent));
  191240. }
  191241. return false;
  191242. }
  191243. void closeClient()
  191244. {
  191245. if (client != 0)
  191246. client->Stop();
  191247. client = 0;
  191248. ResetEvent (clientEvent);
  191249. }
  191250. ComSmartPtr <IMMDevice> device;
  191251. ComSmartPtr <IAudioClient> client;
  191252. double sampleRate, defaultSampleRate;
  191253. int numChannels, actualNumChannels;
  191254. int minBufferSize, defaultBufferSize, latencySamples;
  191255. const bool useExclusiveMode;
  191256. Array <double> rates;
  191257. HANDLE clientEvent;
  191258. BitArray channels;
  191259. AudioDataConverters::DataFormat dataFormat;
  191260. Array <int> channelMaps;
  191261. UINT32 actualBufferSize;
  191262. int bytesPerSample;
  191263. private:
  191264. const ComSmartPtr <IAudioClient> createClient()
  191265. {
  191266. ComSmartPtr <IAudioClient> client;
  191267. if (device != 0)
  191268. {
  191269. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191270. logFailure (hr);
  191271. }
  191272. return client;
  191273. }
  191274. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191275. {
  191276. WAVEFORMATEXTENSIBLE format;
  191277. zerostruct (format);
  191278. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191279. {
  191280. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191281. }
  191282. else
  191283. {
  191284. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191285. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191286. }
  191287. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191288. format.Format.nChannels = (WORD) numChannels;
  191289. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191290. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191291. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191292. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191293. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191294. switch (numChannels)
  191295. {
  191296. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191297. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191298. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191299. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191300. 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;
  191301. default: break;
  191302. }
  191303. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191304. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191305. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191306. logFailure (hr);
  191307. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191308. {
  191309. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191310. hr = S_OK;
  191311. }
  191312. CoTaskMemFree (nearestFormat);
  191313. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191314. if (useExclusiveMode)
  191315. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191316. GUID session;
  191317. if (hr == S_OK
  191318. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191319. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191320. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191321. {
  191322. actualNumChannels = format.Format.nChannels;
  191323. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191324. bytesPerSample = format.Format.wBitsPerSample / 8;
  191325. dataFormat = isFloat ? AudioDataConverters::float32LE
  191326. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191327. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191328. : AudioDataConverters::int16LE)));
  191329. return true;
  191330. }
  191331. return false;
  191332. }
  191333. };
  191334. class WASAPIInputDevice : public WASAPIDeviceBase
  191335. {
  191336. public:
  191337. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191338. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191339. reservoir (1, 1)
  191340. {
  191341. }
  191342. ~WASAPIInputDevice()
  191343. {
  191344. close();
  191345. }
  191346. bool open (const double newSampleRate, const BitArray& newChannels)
  191347. {
  191348. reservoirSize = 0;
  191349. reservoirCapacity = 16384;
  191350. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191351. return openClient (newSampleRate, newChannels)
  191352. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191353. }
  191354. void close()
  191355. {
  191356. closeClient();
  191357. captureClient = 0;
  191358. reservoir.setSize (0);
  191359. }
  191360. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191361. {
  191362. if (numChannels <= 0)
  191363. return;
  191364. int offset = 0;
  191365. while (bufferSize > 0)
  191366. {
  191367. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191368. {
  191369. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191370. for (int i = 0; i < numDestBuffers; ++i)
  191371. {
  191372. float* const dest = destBuffers[i] + offset;
  191373. const int srcChan = channelMaps.getUnchecked(i);
  191374. switch (dataFormat)
  191375. {
  191376. case AudioDataConverters::float32LE:
  191377. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191378. break;
  191379. case AudioDataConverters::int32LE:
  191380. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191381. break;
  191382. case AudioDataConverters::int24LE:
  191383. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191384. break;
  191385. case AudioDataConverters::int16LE:
  191386. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191387. break;
  191388. default: jassertfalse; break;
  191389. }
  191390. }
  191391. bufferSize -= samplesToDo;
  191392. offset += samplesToDo;
  191393. reservoirSize -= samplesToDo;
  191394. }
  191395. else
  191396. {
  191397. UINT32 packetLength = 0;
  191398. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191399. break;
  191400. if (packetLength == 0)
  191401. {
  191402. if (thread.threadShouldExit())
  191403. break;
  191404. Thread::sleep (1);
  191405. continue;
  191406. }
  191407. uint8* inputData = 0;
  191408. UINT32 numSamplesAvailable;
  191409. DWORD flags;
  191410. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191411. {
  191412. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191413. for (int i = 0; i < numDestBuffers; ++i)
  191414. {
  191415. float* const dest = destBuffers[i] + offset;
  191416. const int srcChan = channelMaps.getUnchecked(i);
  191417. switch (dataFormat)
  191418. {
  191419. case AudioDataConverters::float32LE:
  191420. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191421. break;
  191422. case AudioDataConverters::int32LE:
  191423. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191424. break;
  191425. case AudioDataConverters::int24LE:
  191426. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191427. break;
  191428. case AudioDataConverters::int16LE:
  191429. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191430. break;
  191431. default: jassertfalse; break;
  191432. }
  191433. }
  191434. bufferSize -= samplesToDo;
  191435. offset += samplesToDo;
  191436. if (samplesToDo < (int) numSamplesAvailable)
  191437. {
  191438. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191439. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191440. bytesPerSample * actualNumChannels * reservoirSize);
  191441. }
  191442. captureClient->ReleaseBuffer (numSamplesAvailable);
  191443. }
  191444. }
  191445. }
  191446. }
  191447. ComSmartPtr <IAudioCaptureClient> captureClient;
  191448. MemoryBlock reservoir;
  191449. int reservoirSize, reservoirCapacity;
  191450. };
  191451. class WASAPIOutputDevice : public WASAPIDeviceBase
  191452. {
  191453. public:
  191454. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191455. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191456. {
  191457. }
  191458. ~WASAPIOutputDevice()
  191459. {
  191460. close();
  191461. }
  191462. bool open (const double newSampleRate, const BitArray& newChannels)
  191463. {
  191464. return openClient (newSampleRate, newChannels)
  191465. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191466. }
  191467. void close()
  191468. {
  191469. closeClient();
  191470. renderClient = 0;
  191471. }
  191472. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191473. {
  191474. if (numChannels <= 0)
  191475. return;
  191476. int offset = 0;
  191477. while (bufferSize > 0)
  191478. {
  191479. UINT32 padding = 0;
  191480. if (! OK (client->GetCurrentPadding (&padding)))
  191481. return;
  191482. int samplesToDo = useExclusiveMode ? bufferSize
  191483. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191484. if (samplesToDo <= 0)
  191485. {
  191486. if (thread.threadShouldExit())
  191487. break;
  191488. Thread::sleep (0);
  191489. continue;
  191490. }
  191491. uint8* outputData = 0;
  191492. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191493. {
  191494. for (int i = 0; i < numSrcBuffers; ++i)
  191495. {
  191496. const float* const source = srcBuffers[i] + offset;
  191497. const int destChan = channelMaps.getUnchecked(i);
  191498. switch (dataFormat)
  191499. {
  191500. case AudioDataConverters::float32LE:
  191501. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191502. break;
  191503. case AudioDataConverters::int32LE:
  191504. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191505. break;
  191506. case AudioDataConverters::int24LE:
  191507. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191508. break;
  191509. case AudioDataConverters::int16LE:
  191510. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191511. break;
  191512. default: jassertfalse; break;
  191513. }
  191514. }
  191515. renderClient->ReleaseBuffer (samplesToDo, 0);
  191516. offset += samplesToDo;
  191517. bufferSize -= samplesToDo;
  191518. }
  191519. }
  191520. }
  191521. ComSmartPtr <IAudioRenderClient> renderClient;
  191522. };
  191523. class WASAPIAudioIODevice : public AudioIODevice,
  191524. public Thread
  191525. {
  191526. public:
  191527. WASAPIAudioIODevice (const String& deviceName,
  191528. const String& outputDeviceId_,
  191529. const String& inputDeviceId_,
  191530. const bool useExclusiveMode_)
  191531. : AudioIODevice (deviceName, "Windows Audio"),
  191532. Thread ("Juce WASAPI"),
  191533. isOpen_ (false),
  191534. isStarted (false),
  191535. outputDevice (0),
  191536. outputDeviceId (outputDeviceId_),
  191537. inputDevice (0),
  191538. inputDeviceId (inputDeviceId_),
  191539. useExclusiveMode (useExclusiveMode_),
  191540. currentBufferSizeSamples (0),
  191541. currentSampleRate (0),
  191542. callback (0)
  191543. {
  191544. }
  191545. ~WASAPIAudioIODevice()
  191546. {
  191547. close();
  191548. deleteAndZero (inputDevice);
  191549. deleteAndZero (outputDevice);
  191550. }
  191551. bool initialise()
  191552. {
  191553. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191554. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191555. latencyIn = latencyOut = 0;
  191556. Array <double> ratesIn, ratesOut;
  191557. if (createDevices())
  191558. {
  191559. jassert (inputDevice != 0 || outputDevice != 0);
  191560. if (inputDevice != 0 && outputDevice != 0)
  191561. {
  191562. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191563. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191564. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191565. sampleRates = inputDevice->rates;
  191566. sampleRates.removeValuesNotIn (outputDevice->rates);
  191567. }
  191568. else
  191569. {
  191570. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191571. defaultSampleRate = d->defaultSampleRate;
  191572. minBufferSize = d->minBufferSize;
  191573. defaultBufferSize = d->defaultBufferSize;
  191574. sampleRates = d->rates;
  191575. }
  191576. IntegerElementComparator<int> comparator;
  191577. bufferSizes.addSorted (comparator, defaultBufferSize);
  191578. if (minBufferSize != defaultBufferSize)
  191579. bufferSizes.addSorted (comparator, minBufferSize);
  191580. int n = 64;
  191581. for (int i = 0; i < 40; ++i)
  191582. {
  191583. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191584. bufferSizes.addSorted (comparator, n);
  191585. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191586. }
  191587. return true;
  191588. }
  191589. return false;
  191590. }
  191591. const StringArray getOutputChannelNames()
  191592. {
  191593. StringArray outChannels;
  191594. if (outputDevice != 0)
  191595. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191596. outChannels.add ("Output channel " + String (i));
  191597. return outChannels;
  191598. }
  191599. const StringArray getInputChannelNames()
  191600. {
  191601. StringArray inChannels;
  191602. if (inputDevice != 0)
  191603. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191604. inChannels.add ("Input channel " + String (i));
  191605. return inChannels;
  191606. }
  191607. int getNumSampleRates() { return sampleRates.size(); }
  191608. double getSampleRate (int index) { return sampleRates [index]; }
  191609. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191610. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191611. int getDefaultBufferSize() { return defaultBufferSize; }
  191612. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191613. double getCurrentSampleRate() { return currentSampleRate; }
  191614. int getCurrentBitDepth() { return 32; }
  191615. int getOutputLatencyInSamples() { return latencyOut; }
  191616. int getInputLatencyInSamples() { return latencyIn; }
  191617. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  191618. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  191619. const String getLastError() { return lastError; }
  191620. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  191621. double sampleRate, int bufferSizeSamples)
  191622. {
  191623. close();
  191624. lastError = String::empty;
  191625. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191626. {
  191627. lastError = "The input and output devices don't share a common sample rate!";
  191628. return lastError;
  191629. }
  191630. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191631. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191632. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191633. {
  191634. lastError = "Couldn't open the input device!";
  191635. return lastError;
  191636. }
  191637. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191638. {
  191639. close();
  191640. lastError = "Couldn't open the output device!";
  191641. return lastError;
  191642. }
  191643. if (inputDevice != 0)
  191644. ResetEvent (inputDevice->clientEvent);
  191645. if (outputDevice != 0)
  191646. ResetEvent (outputDevice->clientEvent);
  191647. startThread (8);
  191648. Thread::sleep (5);
  191649. if (inputDevice != 0 && inputDevice->client != 0)
  191650. {
  191651. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191652. HRESULT hr = inputDevice->client->Start();
  191653. logFailure (hr); //xxx handle this
  191654. }
  191655. if (outputDevice != 0 && outputDevice->client != 0)
  191656. {
  191657. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191658. HRESULT hr = outputDevice->client->Start();
  191659. logFailure (hr); //xxx handle this
  191660. }
  191661. isOpen_ = true;
  191662. return lastError;
  191663. }
  191664. void close()
  191665. {
  191666. stop();
  191667. if (inputDevice != 0)
  191668. SetEvent (inputDevice->clientEvent);
  191669. if (outputDevice != 0)
  191670. SetEvent (outputDevice->clientEvent);
  191671. stopThread (5000);
  191672. if (inputDevice != 0)
  191673. inputDevice->close();
  191674. if (outputDevice != 0)
  191675. outputDevice->close();
  191676. isOpen_ = false;
  191677. }
  191678. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191679. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191680. void start (AudioIODeviceCallback* call)
  191681. {
  191682. if (isOpen_ && call != 0 && ! isStarted)
  191683. {
  191684. if (! isThreadRunning())
  191685. {
  191686. // something's gone wrong and the thread's stopped..
  191687. isOpen_ = false;
  191688. return;
  191689. }
  191690. call->audioDeviceAboutToStart (this);
  191691. const ScopedLock sl (startStopLock);
  191692. callback = call;
  191693. isStarted = true;
  191694. }
  191695. }
  191696. void stop()
  191697. {
  191698. if (isStarted)
  191699. {
  191700. AudioIODeviceCallback* const callbackLocal = callback;
  191701. {
  191702. const ScopedLock sl (startStopLock);
  191703. isStarted = false;
  191704. }
  191705. if (callbackLocal != 0)
  191706. callbackLocal->audioDeviceStopped();
  191707. }
  191708. }
  191709. void setMMThreadPriority()
  191710. {
  191711. DynamicLibraryLoader dll ("avrt.dll");
  191712. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191713. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191714. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191715. {
  191716. DWORD dummy = 0;
  191717. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191718. if (h != 0)
  191719. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191720. }
  191721. }
  191722. void run()
  191723. {
  191724. setMMThreadPriority();
  191725. const int bufferSize = currentBufferSizeSamples;
  191726. HANDLE events[2];
  191727. int numEvents = 0;
  191728. if (inputDevice != 0)
  191729. events [numEvents++] = inputDevice->clientEvent;
  191730. if (outputDevice != 0)
  191731. events [numEvents++] = outputDevice->clientEvent;
  191732. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191733. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191734. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191735. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191736. float** const inputBuffers = ins.getArrayOfChannels();
  191737. float** const outputBuffers = outs.getArrayOfChannels();
  191738. ins.clear();
  191739. while (! threadShouldExit())
  191740. {
  191741. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191742. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191743. if (result == WAIT_TIMEOUT)
  191744. continue;
  191745. if (threadShouldExit())
  191746. break;
  191747. if (inputDevice != 0)
  191748. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191749. // Make the callback..
  191750. {
  191751. const ScopedLock sl (startStopLock);
  191752. if (isStarted)
  191753. {
  191754. JUCE_TRY
  191755. {
  191756. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191757. numInputBuffers,
  191758. outputBuffers,
  191759. numOutputBuffers,
  191760. bufferSize);
  191761. }
  191762. JUCE_CATCH_EXCEPTION
  191763. }
  191764. else
  191765. {
  191766. outs.clear();
  191767. }
  191768. }
  191769. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191770. continue;
  191771. if (outputDevice != 0)
  191772. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191773. }
  191774. }
  191775. juce_UseDebuggingNewOperator
  191776. String outputDeviceId, inputDeviceId;
  191777. String lastError;
  191778. private:
  191779. // Device stats...
  191780. WASAPIInputDevice* inputDevice;
  191781. WASAPIOutputDevice* outputDevice;
  191782. const bool useExclusiveMode;
  191783. double defaultSampleRate;
  191784. int minBufferSize, defaultBufferSize;
  191785. int latencyIn, latencyOut;
  191786. Array <double> sampleRates;
  191787. Array <int> bufferSizes;
  191788. // Active state...
  191789. bool isOpen_, isStarted;
  191790. int currentBufferSizeSamples;
  191791. double currentSampleRate;
  191792. AudioIODeviceCallback* callback;
  191793. CriticalSection startStopLock;
  191794. bool createDevices()
  191795. {
  191796. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191797. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191798. return false;
  191799. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191800. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191801. return false;
  191802. UINT32 numDevices = 0;
  191803. if (! OK (deviceCollection->GetCount (&numDevices)))
  191804. return false;
  191805. for (UINT32 i = 0; i < numDevices; ++i)
  191806. {
  191807. ComSmartPtr <IMMDevice> device;
  191808. if (! OK (deviceCollection->Item (i, &device)))
  191809. continue;
  191810. const String deviceId (wasapi_getDeviceID (device));
  191811. if (deviceId.isEmpty())
  191812. continue;
  191813. const EDataFlow flow = wasapi_getDataFlow (device);
  191814. if (deviceId == inputDeviceId && flow == eCapture)
  191815. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191816. else if (deviceId == outputDeviceId && flow == eRender)
  191817. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191818. }
  191819. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191820. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191821. }
  191822. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191823. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191824. };
  191825. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191826. {
  191827. public:
  191828. WASAPIAudioIODeviceType()
  191829. : AudioIODeviceType (T("Windows Audio")),
  191830. hasScanned (false)
  191831. {
  191832. }
  191833. ~WASAPIAudioIODeviceType()
  191834. {
  191835. }
  191836. void scanForDevices()
  191837. {
  191838. hasScanned = true;
  191839. outputDeviceNames.clear();
  191840. inputDeviceNames.clear();
  191841. outputDeviceIds.clear();
  191842. inputDeviceIds.clear();
  191843. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191844. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191845. return;
  191846. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191847. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191848. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191849. UINT32 numDevices = 0;
  191850. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191851. && OK (deviceCollection->GetCount (&numDevices))))
  191852. return;
  191853. for (UINT32 i = 0; i < numDevices; ++i)
  191854. {
  191855. ComSmartPtr <IMMDevice> device;
  191856. if (! OK (deviceCollection->Item (i, &device)))
  191857. continue;
  191858. const String deviceId (wasapi_getDeviceID (device));
  191859. DWORD state = 0;
  191860. if (! OK (device->GetState (&state)))
  191861. continue;
  191862. if (state != DEVICE_STATE_ACTIVE)
  191863. continue;
  191864. String name;
  191865. {
  191866. ComSmartPtr <IPropertyStore> properties;
  191867. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191868. continue;
  191869. PROPVARIANT value;
  191870. PropVariantInit (&value);
  191871. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191872. name = value.pwszVal;
  191873. PropVariantClear (&value);
  191874. }
  191875. const EDataFlow flow = wasapi_getDataFlow (device);
  191876. if (flow == eRender)
  191877. {
  191878. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191879. outputDeviceIds.insert (index, deviceId);
  191880. outputDeviceNames.insert (index, name);
  191881. }
  191882. else if (flow == eCapture)
  191883. {
  191884. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191885. inputDeviceIds.insert (index, deviceId);
  191886. inputDeviceNames.insert (index, name);
  191887. }
  191888. }
  191889. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191890. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191891. }
  191892. const StringArray getDeviceNames (const bool wantInputNames) const
  191893. {
  191894. jassert (hasScanned); // need to call scanForDevices() before doing this
  191895. return wantInputNames ? inputDeviceNames
  191896. : outputDeviceNames;
  191897. }
  191898. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191899. {
  191900. jassert (hasScanned); // need to call scanForDevices() before doing this
  191901. return 0;
  191902. }
  191903. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191904. {
  191905. jassert (hasScanned); // need to call scanForDevices() before doing this
  191906. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191907. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191908. : outputDeviceIds.indexOf (d->outputDeviceId));
  191909. }
  191910. bool hasSeparateInputsAndOutputs() const { return true; }
  191911. AudioIODevice* createDevice (const String& outputDeviceName,
  191912. const String& inputDeviceName)
  191913. {
  191914. jassert (hasScanned); // need to call scanForDevices() before doing this
  191915. const bool useExclusiveMode = false;
  191916. WASAPIAudioIODevice* d = 0;
  191917. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191918. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191919. if (outputIndex >= 0 || inputIndex >= 0)
  191920. {
  191921. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191922. : inputDeviceName,
  191923. outputDeviceIds [outputIndex],
  191924. inputDeviceIds [inputIndex],
  191925. useExclusiveMode);
  191926. if (! d->initialise())
  191927. deleteAndZero (d);
  191928. }
  191929. return d;
  191930. }
  191931. juce_UseDebuggingNewOperator
  191932. StringArray outputDeviceNames, outputDeviceIds;
  191933. StringArray inputDeviceNames, inputDeviceIds;
  191934. private:
  191935. bool hasScanned;
  191936. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  191937. {
  191938. String s;
  191939. IMMDevice* dev = 0;
  191940. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  191941. eMultimedia, &dev)))
  191942. {
  191943. WCHAR* deviceId = 0;
  191944. if (OK (dev->GetId (&deviceId)))
  191945. {
  191946. s = String (deviceId);
  191947. CoTaskMemFree (deviceId);
  191948. }
  191949. dev->Release();
  191950. }
  191951. return s;
  191952. }
  191953. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  191954. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  191955. };
  191956. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  191957. {
  191958. return new WASAPIAudioIODeviceType();
  191959. }
  191960. #undef logFailure
  191961. #undef OK
  191962. #endif
  191963. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  191964. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  191965. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191966. // compiled on its own).
  191967. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  191968. class DShowCameraDeviceInteral : public ChangeBroadcaster
  191969. {
  191970. public:
  191971. DShowCameraDeviceInteral (CameraDevice* const owner_,
  191972. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  191973. const ComSmartPtr <IBaseFilter>& filter_,
  191974. int minWidth, int minHeight,
  191975. int maxWidth, int maxHeight)
  191976. : owner (owner_),
  191977. captureGraphBuilder (captureGraphBuilder_),
  191978. filter (filter_),
  191979. ok (false),
  191980. imageNeedsFlipping (false),
  191981. width (0),
  191982. height (0),
  191983. activeUsers (0),
  191984. recordNextFrameTime (false),
  191985. activeImage (0),
  191986. loadingImage (0)
  191987. {
  191988. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  191989. if (FAILED (hr))
  191990. return;
  191991. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  191992. if (FAILED (hr))
  191993. return;
  191994. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  191995. if (FAILED (hr))
  191996. return;
  191997. {
  191998. ComSmartPtr <IAMStreamConfig> streamConfig;
  191999. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  192000. IID_IAMStreamConfig, (void**) &streamConfig);
  192001. if (streamConfig != 0)
  192002. {
  192003. getVideoSizes (streamConfig);
  192004. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  192005. return;
  192006. }
  192007. }
  192008. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  192009. if (FAILED (hr))
  192010. return;
  192011. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  192012. if (FAILED (hr))
  192013. return;
  192014. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  192015. if (FAILED (hr))
  192016. return;
  192017. if (! connectFilters (filter, smartTee))
  192018. return;
  192019. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  192020. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  192021. if (FAILED (hr))
  192022. return;
  192023. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  192024. if (FAILED (hr))
  192025. return;
  192026. AM_MEDIA_TYPE mt;
  192027. zerostruct (mt);
  192028. mt.majortype = MEDIATYPE_Video;
  192029. mt.subtype = MEDIASUBTYPE_RGB24;
  192030. mt.formattype = FORMAT_VideoInfo;
  192031. sampleGrabber->SetMediaType (&mt);
  192032. callback = new GrabberCallback (*this);
  192033. sampleGrabber->SetCallback (callback, 1);
  192034. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  192035. if (FAILED (hr))
  192036. return;
  192037. ComSmartPtr <IPin> grabberInputPin;
  192038. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192039. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192040. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192041. return;
  192042. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192043. if (FAILED (hr))
  192044. return;
  192045. zerostruct (mt);
  192046. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192047. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192048. width = pVih->bmiHeader.biWidth;
  192049. height = pVih->bmiHeader.biHeight;
  192050. ComSmartPtr <IBaseFilter> nullFilter;
  192051. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192052. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192053. if (connectFilters (sampleGrabberBase, nullFilter)
  192054. && addGraphToRot())
  192055. {
  192056. activeImage = new Image (Image::RGB, width, height, true);
  192057. loadingImage = new Image (Image::RGB, width, height, true);
  192058. ok = true;
  192059. }
  192060. }
  192061. ~DShowCameraDeviceInteral()
  192062. {
  192063. if (mediaControl != 0)
  192064. mediaControl->Stop();
  192065. removeGraphFromRot();
  192066. for (int i = viewerComps.size(); --i >= 0;)
  192067. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192068. callback = 0;
  192069. graphBuilder = 0;
  192070. sampleGrabber = 0;
  192071. mediaControl = 0;
  192072. filter = 0;
  192073. captureGraphBuilder = 0;
  192074. smartTee = 0;
  192075. smartTeePreviewOutputPin = 0;
  192076. smartTeeCaptureOutputPin = 0;
  192077. asfWriter = 0;
  192078. delete activeImage;
  192079. delete loadingImage;
  192080. }
  192081. void addUser()
  192082. {
  192083. if (ok && activeUsers++ == 0)
  192084. mediaControl->Run();
  192085. }
  192086. void removeUser()
  192087. {
  192088. if (ok && --activeUsers == 0)
  192089. mediaControl->Stop();
  192090. }
  192091. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192092. {
  192093. if (recordNextFrameTime)
  192094. {
  192095. const double defaultCameraLatency = 0.1;
  192096. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192097. recordNextFrameTime = false;
  192098. ComSmartPtr <IPin> pin;
  192099. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192100. {
  192101. ComSmartPtr <IAMPushSource> pushSource;
  192102. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192103. if (pushSource != 0)
  192104. {
  192105. REFERENCE_TIME latency = 0;
  192106. hr = pushSource->GetLatency (&latency);
  192107. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192108. }
  192109. }
  192110. }
  192111. {
  192112. const int lineStride = width * 3;
  192113. const ScopedLock sl (imageSwapLock);
  192114. {
  192115. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192116. for (int i = 0; i < height; ++i)
  192117. memcpy (destData.getLinePointer ((height - 1) - i),
  192118. buffer + lineStride * i,
  192119. lineStride);
  192120. }
  192121. imageNeedsFlipping = true;
  192122. }
  192123. if (listeners.size() > 0)
  192124. callListeners (*loadingImage);
  192125. sendChangeMessage (this);
  192126. }
  192127. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192128. {
  192129. if (imageNeedsFlipping)
  192130. {
  192131. const ScopedLock sl (imageSwapLock);
  192132. swapVariables (loadingImage, activeImage);
  192133. imageNeedsFlipping = false;
  192134. }
  192135. RectanglePlacement rp (RectanglePlacement::centred);
  192136. double dx = 0, dy = 0, dw = width, dh = height;
  192137. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192138. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192139. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192140. g.saveState();
  192141. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  192142. g.fillAll (Colours::black);
  192143. g.restoreState();
  192144. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192145. }
  192146. bool createFileCaptureFilter (const File& file)
  192147. {
  192148. removeFileCaptureFilter();
  192149. file.deleteFile();
  192150. mediaControl->Stop();
  192151. firstRecordedTime = Time();
  192152. recordNextFrameTime = true;
  192153. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  192154. if (SUCCEEDED (hr))
  192155. {
  192156. ComSmartPtr <IFileSinkFilter> fileSink;
  192157. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192158. if (SUCCEEDED (hr))
  192159. {
  192160. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  192161. if (SUCCEEDED (hr))
  192162. {
  192163. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  192164. if (SUCCEEDED (hr))
  192165. {
  192166. ComSmartPtr <IConfigAsfWriter> asfConfig;
  192167. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  192168. asfConfig->SetIndexMode (true);
  192169. ComSmartPtr <IWMProfileManager> profileManager;
  192170. hr = WMCreateProfileManager (&profileManager);
  192171. // This gibberish is the DirectShow profile for a video-only wmv file.
  192172. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  192173. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  192174. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  192175. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  192176. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  192177. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  192178. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  192179. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  192180. prof = prof.replace (T("$WIDTH"), String (width))
  192181. .replace (T("$HEIGHT"), String (height));
  192182. ComSmartPtr <IWMProfile> currentProfile;
  192183. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  192184. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  192185. if (SUCCEEDED (hr))
  192186. {
  192187. ComSmartPtr <IPin> asfWriterInputPin;
  192188. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  192189. {
  192190. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  192191. if (SUCCEEDED (hr)
  192192. && ok && activeUsers > 0
  192193. && SUCCEEDED (mediaControl->Run()))
  192194. {
  192195. return true;
  192196. }
  192197. }
  192198. }
  192199. }
  192200. }
  192201. }
  192202. }
  192203. removeFileCaptureFilter();
  192204. if (ok && activeUsers > 0)
  192205. mediaControl->Run();
  192206. return false;
  192207. }
  192208. void removeFileCaptureFilter()
  192209. {
  192210. mediaControl->Stop();
  192211. if (asfWriter != 0)
  192212. {
  192213. graphBuilder->RemoveFilter (asfWriter);
  192214. asfWriter = 0;
  192215. }
  192216. if (ok && activeUsers > 0)
  192217. mediaControl->Run();
  192218. }
  192219. void addListener (CameraImageListener* listenerToAdd)
  192220. {
  192221. const ScopedLock sl (listenerLock);
  192222. if (listeners.size() == 0)
  192223. addUser();
  192224. listeners.addIfNotAlreadyThere (listenerToAdd);
  192225. }
  192226. void removeListener (CameraImageListener* listenerToRemove)
  192227. {
  192228. const ScopedLock sl (listenerLock);
  192229. listeners.removeValue (listenerToRemove);
  192230. if (listeners.size() == 0)
  192231. removeUser();
  192232. }
  192233. void callListeners (Image& image)
  192234. {
  192235. const ScopedLock sl (listenerLock);
  192236. for (int i = listeners.size(); --i >= 0;)
  192237. {
  192238. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192239. if (l != 0)
  192240. l->imageReceived (image);
  192241. }
  192242. }
  192243. class DShowCaptureViewerComp : public Component,
  192244. public ChangeListener
  192245. {
  192246. public:
  192247. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192248. : owner (owner_)
  192249. {
  192250. setOpaque (true);
  192251. owner->addChangeListener (this);
  192252. owner->addUser();
  192253. owner->viewerComps.add (this);
  192254. setSize (owner_->width, owner_->height);
  192255. }
  192256. ~DShowCaptureViewerComp()
  192257. {
  192258. if (owner != 0)
  192259. {
  192260. owner->viewerComps.removeValue (this);
  192261. owner->removeUser();
  192262. owner->removeChangeListener (this);
  192263. }
  192264. }
  192265. void ownerDeleted()
  192266. {
  192267. owner = 0;
  192268. }
  192269. void paint (Graphics& g)
  192270. {
  192271. g.setColour (Colours::black);
  192272. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192273. if (owner != 0)
  192274. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192275. else
  192276. g.fillAll (Colours::black);
  192277. }
  192278. void changeListenerCallback (void*)
  192279. {
  192280. repaint();
  192281. }
  192282. private:
  192283. DShowCameraDeviceInteral* owner;
  192284. };
  192285. bool ok;
  192286. int width, height;
  192287. Time firstRecordedTime;
  192288. VoidArray viewerComps;
  192289. private:
  192290. CameraDevice* const owner;
  192291. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192292. ComSmartPtr <IBaseFilter> filter;
  192293. ComSmartPtr <IBaseFilter> smartTee;
  192294. ComSmartPtr <IGraphBuilder> graphBuilder;
  192295. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192296. ComSmartPtr <IMediaControl> mediaControl;
  192297. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192298. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192299. ComSmartPtr <IBaseFilter> asfWriter;
  192300. int activeUsers;
  192301. Array <int> widths, heights;
  192302. DWORD graphRegistrationID;
  192303. CriticalSection imageSwapLock;
  192304. bool imageNeedsFlipping;
  192305. Image* loadingImage;
  192306. Image* activeImage;
  192307. bool recordNextFrameTime;
  192308. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192309. {
  192310. widths.clear();
  192311. heights.clear();
  192312. int count = 0, size = 0;
  192313. streamConfig->GetNumberOfCapabilities (&count, &size);
  192314. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192315. {
  192316. for (int i = 0; i < count; ++i)
  192317. {
  192318. VIDEO_STREAM_CONFIG_CAPS scc;
  192319. AM_MEDIA_TYPE* config;
  192320. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192321. if (SUCCEEDED (hr))
  192322. {
  192323. const int w = scc.InputSize.cx;
  192324. const int h = scc.InputSize.cy;
  192325. bool duplicate = false;
  192326. for (int j = widths.size(); --j >= 0;)
  192327. {
  192328. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192329. {
  192330. duplicate = true;
  192331. break;
  192332. }
  192333. }
  192334. if (! duplicate)
  192335. {
  192336. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192337. widths.add (w);
  192338. heights.add (h);
  192339. }
  192340. deleteMediaType (config);
  192341. }
  192342. }
  192343. }
  192344. }
  192345. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192346. const int minWidth, const int minHeight,
  192347. const int maxWidth, const int maxHeight)
  192348. {
  192349. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192350. streamConfig->GetNumberOfCapabilities (&count, &size);
  192351. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192352. {
  192353. AM_MEDIA_TYPE* config;
  192354. VIDEO_STREAM_CONFIG_CAPS scc;
  192355. for (int i = 0; i < count; ++i)
  192356. {
  192357. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192358. if (SUCCEEDED (hr))
  192359. {
  192360. if (scc.InputSize.cx >= minWidth
  192361. && scc.InputSize.cy >= minHeight
  192362. && scc.InputSize.cx <= maxWidth
  192363. && scc.InputSize.cy <= maxHeight)
  192364. {
  192365. int area = scc.InputSize.cx * scc.InputSize.cy;
  192366. if (area > bestArea)
  192367. {
  192368. bestIndex = i;
  192369. bestArea = area;
  192370. }
  192371. }
  192372. deleteMediaType (config);
  192373. }
  192374. }
  192375. if (bestIndex >= 0)
  192376. {
  192377. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192378. hr = streamConfig->SetFormat (config);
  192379. deleteMediaType (config);
  192380. return SUCCEEDED (hr);
  192381. }
  192382. }
  192383. return false;
  192384. }
  192385. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192386. {
  192387. ComSmartPtr <IEnumPins> enumerator;
  192388. ComSmartPtr <IPin> pin;
  192389. filter->EnumPins (&enumerator);
  192390. while (enumerator->Next (1, &pin, 0) == S_OK)
  192391. {
  192392. PIN_DIRECTION dir;
  192393. pin->QueryDirection (&dir);
  192394. if (wantedDirection == dir)
  192395. {
  192396. PIN_INFO info;
  192397. zerostruct (info);
  192398. pin->QueryPinInfo (&info);
  192399. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192400. {
  192401. pin.p->AddRef();
  192402. *result = pin;
  192403. return true;
  192404. }
  192405. }
  192406. }
  192407. return false;
  192408. }
  192409. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192410. {
  192411. ComSmartPtr <IPin> in, out;
  192412. return getPin (first, PINDIR_OUTPUT, &out)
  192413. && getPin (second, PINDIR_INPUT, &in)
  192414. && SUCCEEDED (graphBuilder->Connect (out, in));
  192415. }
  192416. bool addGraphToRot()
  192417. {
  192418. ComSmartPtr <IRunningObjectTable> rot;
  192419. if (FAILED (GetRunningObjectTable (0, &rot)))
  192420. return false;
  192421. ComSmartPtr <IMoniker> moniker;
  192422. WCHAR buffer[128];
  192423. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192424. if (FAILED (hr))
  192425. return false;
  192426. graphRegistrationID = 0;
  192427. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192428. }
  192429. void removeGraphFromRot()
  192430. {
  192431. ComSmartPtr <IRunningObjectTable> rot;
  192432. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192433. rot->Revoke (graphRegistrationID);
  192434. }
  192435. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192436. {
  192437. if (pmt->cbFormat != 0)
  192438. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192439. if (pmt->pUnk != 0)
  192440. pmt->pUnk->Release();
  192441. CoTaskMemFree (pmt);
  192442. }
  192443. class GrabberCallback : public ISampleGrabberCB
  192444. {
  192445. public:
  192446. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192447. : owner (owner_)
  192448. {
  192449. }
  192450. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192451. {
  192452. if (id == IID_IUnknown)
  192453. *result = dynamic_cast <IUnknown*> (this);
  192454. else if (id == IID_ISampleGrabberCB)
  192455. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192456. else
  192457. {
  192458. *result = 0;
  192459. return E_NOINTERFACE;
  192460. }
  192461. AddRef();
  192462. return S_OK;
  192463. }
  192464. ULONG __stdcall AddRef() { return ++refCount; }
  192465. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192466. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192467. {
  192468. return E_FAIL;
  192469. }
  192470. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192471. {
  192472. owner.handleFrame (time, buffer, bufferSize);
  192473. return S_OK;
  192474. }
  192475. private:
  192476. int refCount;
  192477. DShowCameraDeviceInteral& owner;
  192478. GrabberCallback (const GrabberCallback&);
  192479. GrabberCallback& operator= (const GrabberCallback&);
  192480. };
  192481. ComSmartPtr <GrabberCallback> callback;
  192482. VoidArray listeners;
  192483. CriticalSection listenerLock;
  192484. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192485. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192486. };
  192487. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192488. : name (name_)
  192489. {
  192490. isRecording = false;
  192491. }
  192492. CameraDevice::~CameraDevice()
  192493. {
  192494. stopRecording();
  192495. delete (DShowCameraDeviceInteral*) internal;
  192496. internal = 0;
  192497. }
  192498. Component* CameraDevice::createViewerComponent()
  192499. {
  192500. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192501. }
  192502. const String CameraDevice::getFileExtension()
  192503. {
  192504. return ".wmv";
  192505. }
  192506. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192507. {
  192508. stopRecording();
  192509. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192510. d->addUser();
  192511. isRecording = d->createFileCaptureFilter (file);
  192512. }
  192513. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192514. {
  192515. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192516. return d->firstRecordedTime;
  192517. }
  192518. void CameraDevice::stopRecording()
  192519. {
  192520. if (isRecording)
  192521. {
  192522. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192523. d->removeFileCaptureFilter();
  192524. d->removeUser();
  192525. isRecording = false;
  192526. }
  192527. }
  192528. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192529. {
  192530. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192531. if (listenerToAdd != 0)
  192532. d->addListener (listenerToAdd);
  192533. }
  192534. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192535. {
  192536. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192537. if (listenerToRemove != 0)
  192538. d->removeListener (listenerToRemove);
  192539. }
  192540. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192541. const int deviceIndexToOpen,
  192542. String& name)
  192543. {
  192544. int index = 0;
  192545. ComSmartPtr <IBaseFilter> result;
  192546. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192547. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192548. if (SUCCEEDED (hr))
  192549. {
  192550. ComSmartPtr <IEnumMoniker> enumerator;
  192551. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192552. if (SUCCEEDED (hr) && enumerator != 0)
  192553. {
  192554. ComSmartPtr <IBaseFilter> captureFilter;
  192555. ComSmartPtr <IMoniker> moniker;
  192556. ULONG fetched;
  192557. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192558. {
  192559. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192560. if (SUCCEEDED (hr))
  192561. {
  192562. ComSmartPtr <IPropertyBag> propertyBag;
  192563. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192564. if (SUCCEEDED (hr))
  192565. {
  192566. VARIANT var;
  192567. var.vt = VT_BSTR;
  192568. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192569. propertyBag = 0;
  192570. if (SUCCEEDED (hr))
  192571. {
  192572. if (names != 0)
  192573. names->add (var.bstrVal);
  192574. if (index == deviceIndexToOpen)
  192575. {
  192576. name = var.bstrVal;
  192577. result = captureFilter;
  192578. captureFilter = 0;
  192579. break;
  192580. }
  192581. ++index;
  192582. }
  192583. moniker = 0;
  192584. }
  192585. captureFilter = 0;
  192586. }
  192587. }
  192588. }
  192589. }
  192590. return result;
  192591. }
  192592. const StringArray CameraDevice::getAvailableDevices()
  192593. {
  192594. StringArray devs;
  192595. String dummy;
  192596. enumerateCameras (&devs, -1, dummy);
  192597. return devs;
  192598. }
  192599. CameraDevice* CameraDevice::openDevice (int index,
  192600. int minWidth, int minHeight,
  192601. int maxWidth, int maxHeight)
  192602. {
  192603. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192604. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192605. if (SUCCEEDED (hr))
  192606. {
  192607. String name;
  192608. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192609. if (filter != 0)
  192610. {
  192611. CameraDevice* const cam = new CameraDevice (name, index);
  192612. DShowCameraDeviceInteral* const intern
  192613. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192614. minWidth, minHeight, maxWidth, maxHeight);
  192615. cam->internal = intern;
  192616. if (intern->ok)
  192617. return cam;
  192618. else
  192619. delete cam;
  192620. }
  192621. }
  192622. return 0;
  192623. }
  192624. #endif
  192625. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192626. #endif
  192627. // Auto-link the other win32 libs that are needed by library calls..
  192628. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192629. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192630. // Auto-links to various win32 libs that are needed by library calls..
  192631. #pragma comment(lib, "kernel32.lib")
  192632. #pragma comment(lib, "user32.lib")
  192633. #pragma comment(lib, "shell32.lib")
  192634. #pragma comment(lib, "gdi32.lib")
  192635. #pragma comment(lib, "vfw32.lib")
  192636. #pragma comment(lib, "comdlg32.lib")
  192637. #pragma comment(lib, "winmm.lib")
  192638. #pragma comment(lib, "wininet.lib")
  192639. #pragma comment(lib, "ole32.lib")
  192640. #pragma comment(lib, "oleaut32.lib")
  192641. #pragma comment(lib, "advapi32.lib")
  192642. #pragma comment(lib, "ws2_32.lib")
  192643. #pragma comment(lib, "comsupp.lib")
  192644. #pragma comment(lib, "version.lib")
  192645. #if JUCE_OPENGL
  192646. #pragma comment(lib, "OpenGL32.Lib")
  192647. #pragma comment(lib, "GlU32.Lib")
  192648. #endif
  192649. #if JUCE_QUICKTIME
  192650. #pragma comment (lib, "QTMLClient.lib")
  192651. #endif
  192652. #if JUCE_USE_CAMERA
  192653. #pragma comment (lib, "Strmiids.lib")
  192654. #pragma comment (lib, "wmvcore.lib")
  192655. #endif
  192656. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192657. #endif
  192658. END_JUCE_NAMESPACE
  192659. #endif
  192660. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192661. #endif
  192662. #if JUCE_LINUX
  192663. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192664. #if JUCE_LINUX
  192665. BEGIN_JUCE_NAMESPACE
  192666. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192667. #define SUPPORT_AFFINITIES 1
  192668. #endif
  192669. #define JUCE_INCLUDED_FILE 1
  192670. // Now include the actual code files..
  192671. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192672. CriticalSection::CriticalSection() throw()
  192673. {
  192674. pthread_mutexattr_t atts;
  192675. pthread_mutexattr_init (&atts);
  192676. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192677. pthread_mutex_init (&internal, &atts);
  192678. }
  192679. CriticalSection::~CriticalSection() throw()
  192680. {
  192681. pthread_mutex_destroy (&internal);
  192682. }
  192683. void CriticalSection::enter() const throw()
  192684. {
  192685. pthread_mutex_lock (&internal);
  192686. }
  192687. bool CriticalSection::tryEnter() const throw()
  192688. {
  192689. return pthread_mutex_trylock (&internal) == 0;
  192690. }
  192691. void CriticalSection::exit() const throw()
  192692. {
  192693. pthread_mutex_unlock (&internal);
  192694. }
  192695. struct EventStruct
  192696. {
  192697. pthread_cond_t condition;
  192698. pthread_mutex_t mutex;
  192699. bool triggered;
  192700. };
  192701. WaitableEvent::WaitableEvent() throw()
  192702. {
  192703. EventStruct* const es = new EventStruct();
  192704. es->triggered = false;
  192705. pthread_cond_init (&es->condition, 0);
  192706. pthread_mutex_init (&es->mutex, 0);
  192707. internal = es;
  192708. }
  192709. WaitableEvent::~WaitableEvent() throw()
  192710. {
  192711. EventStruct* const es = (EventStruct*) internal;
  192712. pthread_cond_destroy (&es->condition);
  192713. pthread_mutex_destroy (&es->mutex);
  192714. delete es;
  192715. }
  192716. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192717. {
  192718. EventStruct* const es = (EventStruct*) internal;
  192719. pthread_mutex_lock (&es->mutex);
  192720. if (timeOutMillisecs < 0)
  192721. {
  192722. while (! es->triggered)
  192723. pthread_cond_wait (&es->condition, &es->mutex);
  192724. }
  192725. else
  192726. {
  192727. while (! es->triggered)
  192728. {
  192729. struct timeval t;
  192730. gettimeofday (&t, 0);
  192731. struct timespec time;
  192732. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  192733. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192734. if (time.tv_nsec >= 1000000000)
  192735. {
  192736. time.tv_nsec -= 1000000000;
  192737. time.tv_sec++;
  192738. }
  192739. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  192740. {
  192741. pthread_mutex_unlock (&es->mutex);
  192742. return false;
  192743. }
  192744. }
  192745. }
  192746. es->triggered = false;
  192747. pthread_mutex_unlock (&es->mutex);
  192748. return true;
  192749. }
  192750. void WaitableEvent::signal() const throw()
  192751. {
  192752. EventStruct* const es = (EventStruct*) internal;
  192753. pthread_mutex_lock (&es->mutex);
  192754. es->triggered = true;
  192755. pthread_cond_broadcast (&es->condition);
  192756. pthread_mutex_unlock (&es->mutex);
  192757. }
  192758. void WaitableEvent::reset() const throw()
  192759. {
  192760. EventStruct* const es = (EventStruct*) internal;
  192761. pthread_mutex_lock (&es->mutex);
  192762. es->triggered = false;
  192763. pthread_mutex_unlock (&es->mutex);
  192764. }
  192765. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192766. {
  192767. struct timespec time;
  192768. time.tv_sec = millisecs / 1000;
  192769. time.tv_nsec = (millisecs % 1000) * 1000000;
  192770. nanosleep (&time, 0);
  192771. }
  192772. const tchar File::separator = T('/');
  192773. const tchar* File::separatorString = T("/");
  192774. const File File::getCurrentWorkingDirectory()
  192775. {
  192776. HeapBlock<char> heapBuffer;
  192777. char localBuffer [1024];
  192778. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192779. int bufferSize = 4096;
  192780. while (cwd == 0 && errno == ERANGE)
  192781. {
  192782. heapBuffer.malloc (bufferSize);
  192783. cwd = getcwd (heapBuffer, bufferSize - 1);
  192784. bufferSize += 1024;
  192785. }
  192786. return File (String::fromUTF8 (cwd));
  192787. }
  192788. bool File::setAsCurrentWorkingDirectory() const
  192789. {
  192790. return chdir (getFullPathName().toUTF8()) == 0;
  192791. }
  192792. bool juce_copyFile (const String& s, const String& d);
  192793. static bool juce_stat (const String& fileName, struct stat& info)
  192794. {
  192795. return fileName.isNotEmpty()
  192796. && (stat (fileName.toUTF8(), &info) == 0);
  192797. }
  192798. bool juce_isDirectory (const String& fileName)
  192799. {
  192800. struct stat info;
  192801. return fileName.isEmpty()
  192802. || (juce_stat (fileName, info)
  192803. && ((info.st_mode & S_IFDIR) != 0));
  192804. }
  192805. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  192806. {
  192807. if (fileName.isEmpty())
  192808. return false;
  192809. const char* const fileNameUTF8 = fileName.toUTF8();
  192810. bool exists = access (fileNameUTF8, F_OK) == 0;
  192811. if (exists && dontCountDirectories)
  192812. {
  192813. struct stat info;
  192814. const int res = stat (fileNameUTF8, &info);
  192815. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  192816. exists = false;
  192817. }
  192818. return exists;
  192819. }
  192820. int64 juce_getFileSize (const String& fileName)
  192821. {
  192822. struct stat info;
  192823. return juce_stat (fileName, info) ? info.st_size : 0;
  192824. }
  192825. bool juce_canWriteToFile (const String& fileName)
  192826. {
  192827. return access (fileName.toUTF8(), W_OK) == 0;
  192828. }
  192829. bool juce_deleteFile (const String& fileName)
  192830. {
  192831. if (juce_isDirectory (fileName))
  192832. return rmdir ((const char*) fileName.toUTF8()) == 0;
  192833. else
  192834. return remove ((const char*) fileName.toUTF8()) == 0;
  192835. }
  192836. bool juce_moveFile (const String& source, const String& dest)
  192837. {
  192838. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  192839. return true;
  192840. if (juce_canWriteToFile (source)
  192841. && juce_copyFile (source, dest))
  192842. {
  192843. if (juce_deleteFile (source))
  192844. return true;
  192845. juce_deleteFile (dest);
  192846. }
  192847. return false;
  192848. }
  192849. void juce_createDirectory (const String& fileName)
  192850. {
  192851. mkdir (fileName.toUTF8(), 0777);
  192852. }
  192853. void* juce_fileOpen (const String& fileName, bool forWriting)
  192854. {
  192855. int flags = O_RDONLY;
  192856. if (forWriting)
  192857. {
  192858. if (juce_fileExists (fileName, false))
  192859. {
  192860. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  192861. if (f != -1)
  192862. lseek (f, 0, SEEK_END);
  192863. return (void*) f;
  192864. }
  192865. else
  192866. {
  192867. flags = O_RDWR + O_CREAT;
  192868. }
  192869. }
  192870. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  192871. }
  192872. void juce_fileClose (void* handle)
  192873. {
  192874. if (handle != 0)
  192875. close ((int) (pointer_sized_int) handle);
  192876. }
  192877. int juce_fileRead (void* handle, void* buffer, int size)
  192878. {
  192879. if (handle != 0)
  192880. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  192881. return 0;
  192882. }
  192883. int juce_fileWrite (void* handle, const void* buffer, int size)
  192884. {
  192885. if (handle != 0)
  192886. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192887. return 0;
  192888. }
  192889. int64 juce_fileSetPosition (void* handle, int64 pos)
  192890. {
  192891. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192892. return pos;
  192893. return -1;
  192894. }
  192895. int64 juce_fileGetPosition (void* handle)
  192896. {
  192897. if (handle != 0)
  192898. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  192899. else
  192900. return -1;
  192901. }
  192902. void juce_fileFlush (void* handle)
  192903. {
  192904. if (handle != 0)
  192905. fsync ((int) (pointer_sized_int) handle);
  192906. }
  192907. const File juce_getExecutableFile()
  192908. {
  192909. Dl_info exeInfo;
  192910. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192911. return File (String::fromUTF8 (exeInfo.dli_fname));
  192912. }
  192913. // if this file doesn't exist, find a parent of it that does..
  192914. static bool doStatFS (const File* file, struct statfs& result)
  192915. {
  192916. File f (*file);
  192917. for (int i = 5; --i >= 0;)
  192918. {
  192919. if (f.exists())
  192920. break;
  192921. f = f.getParentDirectory();
  192922. }
  192923. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192924. }
  192925. int64 File::getBytesFreeOnVolume() const
  192926. {
  192927. struct statfs buf;
  192928. if (doStatFS (this, buf))
  192929. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192930. return 0;
  192931. }
  192932. int64 File::getVolumeTotalSize() const
  192933. {
  192934. struct statfs buf;
  192935. if (doStatFS (this, buf))
  192936. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  192937. return 0;
  192938. }
  192939. const String juce_getVolumeLabel (const String& filenameOnVolume,
  192940. int& volumeSerialNumber)
  192941. {
  192942. volumeSerialNumber = 0;
  192943. #if JUCE_MAC
  192944. struct VolAttrBuf
  192945. {
  192946. u_int32_t length;
  192947. attrreference_t mountPointRef;
  192948. char mountPointSpace [MAXPATHLEN];
  192949. } attrBuf;
  192950. struct attrlist attrList;
  192951. zerostruct (attrList);
  192952. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  192953. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  192954. File f (filenameOnVolume);
  192955. for (;;)
  192956. {
  192957. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  192958. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  192959. {
  192960. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  192961. (int) attrBuf.mountPointRef.attr_length);
  192962. }
  192963. const File parent (f.getParentDirectory());
  192964. if (f == parent)
  192965. break;
  192966. f = parent;
  192967. }
  192968. #endif
  192969. return String::empty;
  192970. }
  192971. void juce_runSystemCommand (const String& command)
  192972. {
  192973. int result = system ((const char*) command.toUTF8());
  192974. (void) result;
  192975. }
  192976. const String juce_getOutputFromCommand (const String& command)
  192977. {
  192978. // slight bodge here, as we just pipe the output into a temp file and read it...
  192979. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  192980. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  192981. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  192982. String result (tempFile.loadFileAsString());
  192983. tempFile.deleteFile();
  192984. return result;
  192985. }
  192986. InterProcessLock::InterProcessLock (const String& name_)
  192987. : internal (0),
  192988. name (name_),
  192989. reentrancyLevel (0)
  192990. {
  192991. #if JUCE_MAC
  192992. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  192993. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  192994. #else
  192995. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  192996. #endif
  192997. temp.create();
  192998. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  192999. }
  193000. InterProcessLock::~InterProcessLock()
  193001. {
  193002. while (reentrancyLevel > 0)
  193003. this->exit();
  193004. close (internal);
  193005. }
  193006. bool InterProcessLock::enter (const int timeOutMillisecs)
  193007. {
  193008. if (internal == 0)
  193009. return false;
  193010. if (reentrancyLevel != 0)
  193011. return true;
  193012. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  193013. struct flock fl;
  193014. zerostruct (fl);
  193015. fl.l_whence = SEEK_SET;
  193016. fl.l_type = F_WRLCK;
  193017. for (;;)
  193018. {
  193019. const int result = fcntl (internal, F_SETLK, &fl);
  193020. if (result >= 0)
  193021. {
  193022. ++reentrancyLevel;
  193023. return true;
  193024. }
  193025. if (errno != EINTR)
  193026. {
  193027. if (timeOutMillisecs == 0
  193028. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  193029. break;
  193030. Thread::sleep (10);
  193031. }
  193032. }
  193033. return false;
  193034. }
  193035. void InterProcessLock::exit()
  193036. {
  193037. if (reentrancyLevel > 0 && internal != 0)
  193038. {
  193039. --reentrancyLevel;
  193040. struct flock fl;
  193041. zerostruct (fl);
  193042. fl.l_whence = SEEK_SET;
  193043. fl.l_type = F_UNLCK;
  193044. for (;;)
  193045. {
  193046. const int result = fcntl (internal, F_SETLKW, &fl);
  193047. if (result >= 0 || errno != EINTR)
  193048. break;
  193049. }
  193050. }
  193051. }
  193052. /*** End of inlined file: juce_posix_SharedCode.h ***/
  193053. /*** Start of inlined file: juce_linux_Files.cpp ***/
  193054. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193055. // compiled on its own).
  193056. #if JUCE_INCLUDED_FILE
  193057. static const short U_ISOFS_SUPER_MAGIC = 0x9660; // linux/iso_fs.h
  193058. static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h
  193059. static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h
  193060. static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h
  193061. void juce_getFileTimes (const String& fileName,
  193062. int64& modificationTime,
  193063. int64& accessTime,
  193064. int64& creationTime)
  193065. {
  193066. modificationTime = 0;
  193067. accessTime = 0;
  193068. creationTime = 0;
  193069. struct stat info;
  193070. const int res = stat (fileName.toUTF8(), &info);
  193071. if (res == 0)
  193072. {
  193073. modificationTime = (int64) info.st_mtime * 1000;
  193074. accessTime = (int64) info.st_atime * 1000;
  193075. creationTime = (int64) info.st_ctime * 1000;
  193076. }
  193077. }
  193078. bool juce_setFileTimes (const String& fileName,
  193079. int64 modificationTime,
  193080. int64 accessTime,
  193081. int64 creationTime)
  193082. {
  193083. struct utimbuf times;
  193084. times.actime = (time_t) (accessTime / 1000);
  193085. times.modtime = (time_t) (modificationTime / 1000);
  193086. return utime (fileName.toUTF8(), &times) == 0;
  193087. }
  193088. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193089. {
  193090. struct stat info;
  193091. const int res = stat (fileName.toUTF8(), &info);
  193092. if (res != 0)
  193093. return false;
  193094. info.st_mode &= 0777; // Just permissions
  193095. if( isReadOnly )
  193096. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193097. else
  193098. // Give everybody write permission?
  193099. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193100. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193101. }
  193102. bool juce_copyFile (const String& s, const String& d)
  193103. {
  193104. const File source (s), dest (d);
  193105. FileInputStream* in = source.createInputStream();
  193106. bool ok = false;
  193107. if (in != 0)
  193108. {
  193109. if (dest.deleteFile())
  193110. {
  193111. FileOutputStream* const out = dest.createOutputStream();
  193112. if (out != 0)
  193113. {
  193114. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193115. delete out;
  193116. ok = (bytesCopied == source.getSize());
  193117. if (! ok)
  193118. dest.deleteFile();
  193119. }
  193120. }
  193121. delete in;
  193122. }
  193123. return ok;
  193124. }
  193125. const StringArray juce_getFileSystemRoots()
  193126. {
  193127. StringArray s;
  193128. s.add (T("/"));
  193129. return s;
  193130. }
  193131. bool File::isOnCDRomDrive() const
  193132. {
  193133. struct statfs buf;
  193134. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193135. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193136. // Assume not if this fails for some reason
  193137. return false;
  193138. }
  193139. bool File::isOnHardDisk() const
  193140. {
  193141. struct statfs buf;
  193142. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193143. {
  193144. switch (buf.f_type)
  193145. {
  193146. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193147. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193148. case U_NFS_SUPER_MAGIC: // Network NFS
  193149. case U_SMB_SUPER_MAGIC: // Network Samba
  193150. return false;
  193151. default:
  193152. // Assume anything else is a hard-disk (but note it could
  193153. // be a RAM disk. There isn't a good way of determining
  193154. // this for sure)
  193155. return true;
  193156. }
  193157. }
  193158. // Assume so if this fails for some reason
  193159. return true;
  193160. }
  193161. bool File::isOnRemovableDrive() const
  193162. {
  193163. jassertfalse // xxx not implemented for linux!
  193164. return false;
  193165. }
  193166. bool File::isHidden() const
  193167. {
  193168. return getFileName().startsWithChar (T('.'));
  193169. }
  193170. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193171. const File File::getSpecialLocation (const SpecialLocationType type)
  193172. {
  193173. switch (type)
  193174. {
  193175. case userHomeDirectory:
  193176. {
  193177. const char* homeDir = getenv ("HOME");
  193178. if (homeDir == 0)
  193179. {
  193180. struct passwd* const pw = getpwuid (getuid());
  193181. if (pw != 0)
  193182. homeDir = pw->pw_dir;
  193183. }
  193184. return File (String::fromUTF8 (homeDir));
  193185. }
  193186. case userDocumentsDirectory:
  193187. case userMusicDirectory:
  193188. case userMoviesDirectory:
  193189. case userApplicationDataDirectory:
  193190. return File ("~");
  193191. case userDesktopDirectory:
  193192. return File ("~/Desktop");
  193193. case commonApplicationDataDirectory:
  193194. return File ("/var");
  193195. case globalApplicationsDirectory:
  193196. return File ("/usr");
  193197. case tempDirectory:
  193198. {
  193199. File tmp ("/var/tmp");
  193200. if (! tmp.isDirectory())
  193201. {
  193202. tmp = T("/tmp");
  193203. if (! tmp.isDirectory())
  193204. tmp = File::getCurrentWorkingDirectory();
  193205. }
  193206. return tmp;
  193207. }
  193208. case invokedExecutableFile:
  193209. if (juce_Argv0 != 0)
  193210. return File (String::fromUTF8 (juce_Argv0));
  193211. // deliberate fall-through...
  193212. case currentExecutableFile:
  193213. case currentApplicationFile:
  193214. return juce_getExecutableFile();
  193215. default:
  193216. jassertfalse // unknown type?
  193217. break;
  193218. }
  193219. return File::nonexistent;
  193220. }
  193221. const String File::getVersion() const
  193222. {
  193223. return String::empty; // xxx not yet implemented
  193224. }
  193225. const File File::getLinkedTarget() const
  193226. {
  193227. char buffer [4096];
  193228. size_t numChars = readlink (getFullPathName().toUTF8(),
  193229. buffer, sizeof (buffer));
  193230. if (numChars > 0 && numChars <= sizeof (buffer))
  193231. return File (String::fromUTF8 (buffer, (int) numChars));
  193232. return *this;
  193233. }
  193234. bool File::moveToTrash() const
  193235. {
  193236. if (! exists())
  193237. return true;
  193238. File trashCan (T("~/.Trash"));
  193239. if (! trashCan.isDirectory())
  193240. trashCan = T("~/.local/share/Trash/files");
  193241. if (! trashCan.isDirectory())
  193242. return false;
  193243. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193244. getFileExtension()));
  193245. }
  193246. struct FindFileStruct
  193247. {
  193248. String parentDir, wildCard;
  193249. DIR* dir;
  193250. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193251. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193252. {
  193253. const char* const wildcardUTF8 = wildCard.toUTF8();
  193254. for (;;)
  193255. {
  193256. struct dirent* const de = readdir (dir);
  193257. if (de == 0)
  193258. break;
  193259. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193260. {
  193261. result = String::fromUTF8 (de->d_name);
  193262. const String path (parentDir + result);
  193263. if (isDir != 0 || fileSize != 0)
  193264. {
  193265. struct stat info;
  193266. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193267. if (isDir != 0)
  193268. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193269. if (isHidden != 0)
  193270. *isHidden = (de->d_name[0] == '.');
  193271. if (fileSize != 0)
  193272. *fileSize = statOk ? info.st_size : 0;
  193273. }
  193274. if (modTime != 0 || creationTime != 0)
  193275. {
  193276. int64 m, a, c;
  193277. juce_getFileTimes (path, m, a, c);
  193278. if (modTime != 0)
  193279. *modTime = m;
  193280. if (creationTime != 0)
  193281. *creationTime = c;
  193282. }
  193283. if (isReadOnly != 0)
  193284. *isReadOnly = ! juce_canWriteToFile (path);
  193285. return true;
  193286. }
  193287. }
  193288. return false;
  193289. }
  193290. };
  193291. // returns 0 on failure
  193292. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193293. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193294. Time* creationTime, bool* isReadOnly)
  193295. {
  193296. DIR* d = opendir (directory.toUTF8());
  193297. if (d != 0)
  193298. {
  193299. FindFileStruct* ff = new FindFileStruct();
  193300. ff->parentDir = directory;
  193301. if (!ff->parentDir.endsWithChar (File::separator))
  193302. ff->parentDir += File::separator;
  193303. ff->wildCard = wildCard;
  193304. if (wildCard == T("*.*"))
  193305. ff->wildCard = T("*");
  193306. ff->dir = d;
  193307. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193308. {
  193309. return ff;
  193310. }
  193311. else
  193312. {
  193313. firstResultFile = String::empty;
  193314. isDir = false;
  193315. isHidden = false;
  193316. closedir (d);
  193317. delete ff;
  193318. }
  193319. }
  193320. return 0;
  193321. }
  193322. bool juce_findFileNext (void* handle, String& resultFile,
  193323. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193324. {
  193325. FindFileStruct* const ff = (FindFileStruct*) handle;
  193326. if (ff != 0)
  193327. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193328. return false;
  193329. }
  193330. void juce_findFileClose (void* handle)
  193331. {
  193332. FindFileStruct* const ff = (FindFileStruct*) handle;
  193333. if (ff != 0)
  193334. {
  193335. closedir (ff->dir);
  193336. delete ff;
  193337. }
  193338. }
  193339. bool juce_launchFile (const String& fileName,
  193340. const String& parameters)
  193341. {
  193342. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193343. cmdString << " " << parameters;
  193344. if (URL::isProbablyAWebsiteURL (fileName)
  193345. || cmdString.startsWithIgnoreCase (T("file:"))
  193346. || URL::isProbablyAnEmailAddress (fileName))
  193347. {
  193348. // create a command that tries to launch a bunch of likely browsers
  193349. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193350. StringArray cmdLines;
  193351. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193352. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193353. cmdString = cmdLines.joinIntoString (T(" || "));
  193354. }
  193355. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193356. const int cpid = fork();
  193357. if (cpid == 0)
  193358. {
  193359. setsid();
  193360. // Child process
  193361. execve (argv[0], (char**) argv, environ);
  193362. exit (0);
  193363. }
  193364. return cpid >= 0;
  193365. }
  193366. void File::revealToUser() const
  193367. {
  193368. if (isDirectory())
  193369. startAsProcess();
  193370. else if (getParentDirectory().exists())
  193371. getParentDirectory().startAsProcess();
  193372. }
  193373. #endif
  193374. /*** End of inlined file: juce_linux_Files.cpp ***/
  193375. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193376. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193377. // compiled on its own).
  193378. #if JUCE_INCLUDED_FILE
  193379. struct NamedPipeInternal
  193380. {
  193381. String pipeInName, pipeOutName;
  193382. int pipeIn, pipeOut;
  193383. bool volatile createdPipe, blocked, stopReadOperation;
  193384. static void signalHandler (int) {}
  193385. };
  193386. void NamedPipe::cancelPendingReads()
  193387. {
  193388. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193389. {
  193390. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193391. intern->stopReadOperation = true;
  193392. char buffer [1] = { 0 };
  193393. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193394. (void) bytesWritten;
  193395. int timeout = 2000;
  193396. while (intern->blocked && --timeout >= 0)
  193397. Thread::sleep (2);
  193398. intern->stopReadOperation = false;
  193399. }
  193400. }
  193401. void NamedPipe::close()
  193402. {
  193403. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193404. if (intern != 0)
  193405. {
  193406. internal = 0;
  193407. if (intern->pipeIn != -1)
  193408. ::close (intern->pipeIn);
  193409. if (intern->pipeOut != -1)
  193410. ::close (intern->pipeOut);
  193411. if (intern->createdPipe)
  193412. {
  193413. unlink (intern->pipeInName.toUTF8());
  193414. unlink (intern->pipeOutName.toUTF8());
  193415. }
  193416. delete intern;
  193417. }
  193418. }
  193419. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193420. {
  193421. close();
  193422. NamedPipeInternal* const intern = new NamedPipeInternal();
  193423. internal = intern;
  193424. intern->createdPipe = createPipe;
  193425. intern->blocked = false;
  193426. intern->stopReadOperation = false;
  193427. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193428. siginterrupt (SIGPIPE, 1);
  193429. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193430. intern->pipeInName = pipePath + T("_in");
  193431. intern->pipeOutName = pipePath + T("_out");
  193432. intern->pipeIn = -1;
  193433. intern->pipeOut = -1;
  193434. if (createPipe)
  193435. {
  193436. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193437. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193438. {
  193439. delete intern;
  193440. internal = 0;
  193441. return false;
  193442. }
  193443. }
  193444. return true;
  193445. }
  193446. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193447. {
  193448. int bytesRead = -1;
  193449. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193450. if (intern != 0)
  193451. {
  193452. intern->blocked = true;
  193453. if (intern->pipeIn == -1)
  193454. {
  193455. if (intern->createdPipe)
  193456. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193457. else
  193458. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193459. if (intern->pipeIn == -1)
  193460. {
  193461. intern->blocked = false;
  193462. return -1;
  193463. }
  193464. }
  193465. bytesRead = 0;
  193466. char* p = (char*) destBuffer;
  193467. while (bytesRead < maxBytesToRead)
  193468. {
  193469. const int bytesThisTime = maxBytesToRead - bytesRead;
  193470. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193471. if (numRead <= 0 || intern->stopReadOperation)
  193472. {
  193473. bytesRead = -1;
  193474. break;
  193475. }
  193476. bytesRead += numRead;
  193477. p += bytesRead;
  193478. }
  193479. intern->blocked = false;
  193480. }
  193481. return bytesRead;
  193482. }
  193483. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193484. {
  193485. int bytesWritten = -1;
  193486. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193487. if (intern != 0)
  193488. {
  193489. if (intern->pipeOut == -1)
  193490. {
  193491. if (intern->createdPipe)
  193492. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193493. else
  193494. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193495. if (intern->pipeOut == -1)
  193496. {
  193497. return -1;
  193498. }
  193499. }
  193500. const char* p = (const char*) sourceBuffer;
  193501. bytesWritten = 0;
  193502. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193503. while (bytesWritten < numBytesToWrite
  193504. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193505. {
  193506. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193507. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193508. if (numWritten <= 0)
  193509. {
  193510. bytesWritten = -1;
  193511. break;
  193512. }
  193513. bytesWritten += numWritten;
  193514. p += bytesWritten;
  193515. }
  193516. }
  193517. return bytesWritten;
  193518. }
  193519. #endif
  193520. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193521. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193522. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193523. // compiled on its own).
  193524. #if JUCE_INCLUDED_FILE
  193525. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  193526. {
  193527. int numResults = 0;
  193528. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193529. if (s != -1)
  193530. {
  193531. char buf [1024];
  193532. struct ifconf ifc;
  193533. ifc.ifc_len = sizeof (buf);
  193534. ifc.ifc_buf = buf;
  193535. ioctl (s, SIOCGIFCONF, &ifc);
  193536. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193537. {
  193538. struct ifreq ifr;
  193539. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193540. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193541. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193542. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193543. && numResults < maxNum)
  193544. {
  193545. int64 a = 0;
  193546. for (int j = 6; --j >= 0;)
  193547. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193548. *addresses++ = a;
  193549. ++numResults;
  193550. }
  193551. }
  193552. close (s);
  193553. }
  193554. return numResults;
  193555. }
  193556. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193557. const String& emailSubject,
  193558. const String& bodyText,
  193559. const StringArray& filesToAttach)
  193560. {
  193561. jassertfalse // xxx todo
  193562. return false;
  193563. }
  193564. class JUCE_HTTPSocketStream
  193565. {
  193566. public:
  193567. JUCE_HTTPSocketStream()
  193568. : readPosition (0),
  193569. socketHandle (-1),
  193570. levelsOfRedirection (0),
  193571. timeoutSeconds (15)
  193572. {
  193573. }
  193574. ~JUCE_HTTPSocketStream()
  193575. {
  193576. closeSocket();
  193577. }
  193578. bool open (const String& url,
  193579. const String& headers,
  193580. const MemoryBlock& postData,
  193581. const bool isPost,
  193582. URL::OpenStreamProgressCallback* callback,
  193583. void* callbackContext,
  193584. int timeOutMs)
  193585. {
  193586. closeSocket();
  193587. uint32 timeOutTime = Time::getMillisecondCounter();
  193588. if (timeOutMs == 0)
  193589. timeOutTime += 60000;
  193590. else if (timeOutMs < 0)
  193591. timeOutTime = 0xffffffff;
  193592. else
  193593. timeOutTime += timeOutMs;
  193594. String hostName, hostPath;
  193595. int hostPort;
  193596. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193597. return false;
  193598. const struct hostent* host = 0;
  193599. int port = 0;
  193600. String proxyName, proxyPath;
  193601. int proxyPort = 0;
  193602. String proxyURL (getenv ("http_proxy"));
  193603. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193604. {
  193605. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193606. return false;
  193607. host = gethostbyname ((const char*) proxyName.toUTF8());
  193608. port = proxyPort;
  193609. }
  193610. else
  193611. {
  193612. host = gethostbyname ((const char*) hostName.toUTF8());
  193613. port = hostPort;
  193614. }
  193615. if (host == 0)
  193616. return false;
  193617. struct sockaddr_in address;
  193618. zerostruct (address);
  193619. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193620. address.sin_family = host->h_addrtype;
  193621. address.sin_port = htons (port);
  193622. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193623. if (socketHandle == -1)
  193624. return false;
  193625. int receiveBufferSize = 16384;
  193626. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193627. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193628. #if JUCE_MAC
  193629. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193630. #endif
  193631. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193632. {
  193633. closeSocket();
  193634. return false;
  193635. }
  193636. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193637. proxyName, proxyPort,
  193638. hostPath, url,
  193639. headers, postData,
  193640. isPost));
  193641. size_t totalHeaderSent = 0;
  193642. while (totalHeaderSent < requestHeader.getSize())
  193643. {
  193644. if (Time::getMillisecondCounter() > timeOutTime)
  193645. {
  193646. closeSocket();
  193647. return false;
  193648. }
  193649. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193650. if (send (socketHandle,
  193651. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193652. numToSend, 0)
  193653. != numToSend)
  193654. {
  193655. closeSocket();
  193656. return false;
  193657. }
  193658. totalHeaderSent += numToSend;
  193659. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193660. {
  193661. closeSocket();
  193662. return false;
  193663. }
  193664. }
  193665. const String responseHeader (readResponse (timeOutTime));
  193666. if (responseHeader.isNotEmpty())
  193667. {
  193668. //DBG (responseHeader);
  193669. StringArray lines;
  193670. lines.addLines (responseHeader);
  193671. // NB - using charToString() here instead of just T(" "), because that was
  193672. // causing a mysterious gcc internal compiler error...
  193673. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  193674. .substring (0, 3).getIntValue();
  193675. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  193676. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  193677. String location (findHeaderItem (lines, T("Location:")));
  193678. if (statusCode >= 300 && statusCode < 400
  193679. && location.isNotEmpty())
  193680. {
  193681. if (! location.startsWithIgnoreCase (T("http://")))
  193682. location = T("http://") + location;
  193683. if (levelsOfRedirection++ < 3)
  193684. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193685. }
  193686. else
  193687. {
  193688. levelsOfRedirection = 0;
  193689. return true;
  193690. }
  193691. }
  193692. closeSocket();
  193693. return false;
  193694. }
  193695. int read (void* buffer, int bytesToRead)
  193696. {
  193697. fd_set readbits;
  193698. FD_ZERO (&readbits);
  193699. FD_SET (socketHandle, &readbits);
  193700. struct timeval tv;
  193701. tv.tv_sec = timeoutSeconds;
  193702. tv.tv_usec = 0;
  193703. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193704. return 0; // (timeout)
  193705. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193706. readPosition += bytesRead;
  193707. return bytesRead;
  193708. }
  193709. int readPosition;
  193710. juce_UseDebuggingNewOperator
  193711. private:
  193712. int socketHandle, levelsOfRedirection;
  193713. const int timeoutSeconds;
  193714. void closeSocket()
  193715. {
  193716. if (socketHandle >= 0)
  193717. close (socketHandle);
  193718. socketHandle = -1;
  193719. }
  193720. const MemoryBlock createRequestHeader (const String& hostName,
  193721. const int hostPort,
  193722. const String& proxyName,
  193723. const int proxyPort,
  193724. const String& hostPath,
  193725. const String& originalURL,
  193726. const String& headers,
  193727. const MemoryBlock& postData,
  193728. const bool isPost)
  193729. {
  193730. String header (isPost ? "POST " : "GET ");
  193731. if (proxyName.isEmpty())
  193732. {
  193733. header << hostPath << " HTTP/1.0\r\nHost: "
  193734. << hostName << ':' << hostPort;
  193735. }
  193736. else
  193737. {
  193738. header << originalURL << " HTTP/1.0\r\nHost: "
  193739. << proxyName << ':' << proxyPort;
  193740. }
  193741. header << "\r\nUser-Agent: JUCE/"
  193742. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193743. << "\r\nConnection: Close\r\nContent-Length: "
  193744. << postData.getSize() << "\r\n"
  193745. << headers << "\r\n";
  193746. MemoryBlock mb;
  193747. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193748. mb.append (postData.getData(), postData.getSize());
  193749. return mb;
  193750. }
  193751. const String readResponse (const uint32 timeOutTime)
  193752. {
  193753. int bytesRead = 0, numConsecutiveLFs = 0;
  193754. MemoryBlock buffer (1024, true);
  193755. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193756. && Time::getMillisecondCounter() <= timeOutTime)
  193757. {
  193758. fd_set readbits;
  193759. FD_ZERO (&readbits);
  193760. FD_SET (socketHandle, &readbits);
  193761. struct timeval tv;
  193762. tv.tv_sec = timeoutSeconds;
  193763. tv.tv_usec = 0;
  193764. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193765. return String::empty; // (timeout)
  193766. buffer.ensureSize (bytesRead + 8, true);
  193767. char* const dest = (char*) buffer.getData() + bytesRead;
  193768. if (recv (socketHandle, dest, 1, 0) == -1)
  193769. return String::empty;
  193770. const char lastByte = *dest;
  193771. ++bytesRead;
  193772. if (lastByte == '\n')
  193773. ++numConsecutiveLFs;
  193774. else if (lastByte != '\r')
  193775. numConsecutiveLFs = 0;
  193776. }
  193777. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193778. if (header.startsWithIgnoreCase (T("HTTP/")))
  193779. return header.trimEnd();
  193780. return String::empty;
  193781. }
  193782. static bool decomposeURL (const String& url,
  193783. String& host, String& path, int& port)
  193784. {
  193785. if (! url.startsWithIgnoreCase (T("http://")))
  193786. return false;
  193787. const int nextSlash = url.indexOfChar (7, '/');
  193788. int nextColon = url.indexOfChar (7, ':');
  193789. if (nextColon > nextSlash && nextSlash > 0)
  193790. nextColon = -1;
  193791. if (nextColon >= 0)
  193792. {
  193793. host = url.substring (7, nextColon);
  193794. if (nextSlash >= 0)
  193795. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193796. else
  193797. port = url.substring (nextColon + 1).getIntValue();
  193798. }
  193799. else
  193800. {
  193801. port = 80;
  193802. if (nextSlash >= 0)
  193803. host = url.substring (7, nextSlash);
  193804. else
  193805. host = url.substring (7);
  193806. }
  193807. if (nextSlash >= 0)
  193808. path = url.substring (nextSlash);
  193809. else
  193810. path = T("/");
  193811. return true;
  193812. }
  193813. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193814. {
  193815. for (int i = 0; i < lines.size(); ++i)
  193816. if (lines[i].startsWithIgnoreCase (itemName))
  193817. return lines[i].substring (itemName.length()).trim();
  193818. return String::empty;
  193819. }
  193820. };
  193821. bool juce_isOnLine()
  193822. {
  193823. return true;
  193824. }
  193825. void* juce_openInternetFile (const String& url,
  193826. const String& headers,
  193827. const MemoryBlock& postData,
  193828. const bool isPost,
  193829. URL::OpenStreamProgressCallback* callback,
  193830. void* callbackContext,
  193831. int timeOutMs)
  193832. {
  193833. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193834. if (s->open (url, headers, postData, isPost,
  193835. callback, callbackContext, timeOutMs))
  193836. return s;
  193837. delete s;
  193838. return 0;
  193839. }
  193840. void juce_closeInternetFile (void* handle)
  193841. {
  193842. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193843. if (s != 0)
  193844. delete s;
  193845. }
  193846. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193847. {
  193848. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193849. if (s != 0)
  193850. return s->read (buffer, bytesToRead);
  193851. return 0;
  193852. }
  193853. int64 juce_getInternetFileContentLength (void* handle)
  193854. {
  193855. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193856. if (s != 0)
  193857. {
  193858. //xxx todo
  193859. jassertfalse
  193860. }
  193861. return -1;
  193862. }
  193863. int juce_seekInInternetFile (void* handle, int newPosition)
  193864. {
  193865. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193866. if (s != 0)
  193867. return s->readPosition;
  193868. return 0;
  193869. }
  193870. #endif
  193871. /*** End of inlined file: juce_linux_Network.cpp ***/
  193872. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193873. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193874. // compiled on its own).
  193875. #if JUCE_INCLUDED_FILE
  193876. void Logger::outputDebugString (const String& text) throw()
  193877. {
  193878. std::cerr << text << std::endl;
  193879. }
  193880. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193881. {
  193882. return Linux;
  193883. }
  193884. const String SystemStats::getOperatingSystemName() throw()
  193885. {
  193886. return T("Linux");
  193887. }
  193888. bool SystemStats::isOperatingSystem64Bit() throw()
  193889. {
  193890. #if JUCE_64BIT
  193891. return true;
  193892. #else
  193893. //xxx not sure how to find this out?..
  193894. return false;
  193895. #endif
  193896. }
  193897. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193898. {
  193899. String info;
  193900. char buf [256];
  193901. FILE* f = fopen ("/proc/cpuinfo", "r");
  193902. while (f != 0 && fgets (buf, sizeof(buf), f))
  193903. {
  193904. if (strncmp (buf, key, strlen (key)) == 0)
  193905. {
  193906. char* p = buf;
  193907. while (*p && *p != '\n')
  193908. ++p;
  193909. if (*p != 0)
  193910. *p = 0;
  193911. p = buf;
  193912. while (*p != 0 && *p != ':')
  193913. ++p;
  193914. if (*p != 0 && *(p + 1) != 0)
  193915. info = p + 2;
  193916. if (! lastOne)
  193917. break;
  193918. }
  193919. }
  193920. fclose (f);
  193921. return info;
  193922. }
  193923. bool SystemStats::hasMMX() throw()
  193924. {
  193925. return getCpuInfo ("flags").contains (T("mmx"));
  193926. }
  193927. bool SystemStats::hasSSE() throw()
  193928. {
  193929. return getCpuInfo ("flags").contains (T("sse"));
  193930. }
  193931. bool SystemStats::hasSSE2() throw()
  193932. {
  193933. return getCpuInfo ("flags").contains (T("sse2"));
  193934. }
  193935. bool SystemStats::has3DNow() throw()
  193936. {
  193937. return getCpuInfo ("flags").contains (T("3dnow"));
  193938. }
  193939. const String SystemStats::getCpuVendor() throw()
  193940. {
  193941. return getCpuInfo ("vendor_id");
  193942. }
  193943. int SystemStats::getCpuSpeedInMegaherz() throw()
  193944. {
  193945. const String speed (getCpuInfo ("cpu MHz"));
  193946. return (int) (speed.getFloatValue() + 0.5f);
  193947. }
  193948. int SystemStats::getMemorySizeInMegabytes() throw()
  193949. {
  193950. struct sysinfo sysi;
  193951. if (sysinfo (&sysi) == 0)
  193952. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  193953. return 0;
  193954. }
  193955. uint32 juce_millisecondsSinceStartup() throw()
  193956. {
  193957. static unsigned int calibrate = 0;
  193958. static bool calibrated = false;
  193959. timeval t;
  193960. unsigned int ret = 0;
  193961. if (! gettimeofday (&t, 0))
  193962. {
  193963. if (! calibrated)
  193964. {
  193965. struct sysinfo sysi;
  193966. if (sysinfo (&sysi) == 0)
  193967. // Safe to assume system was not brought up earlier than 1970!
  193968. calibrate = t.tv_sec - sysi.uptime;
  193969. calibrated = true;
  193970. }
  193971. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  193972. }
  193973. return ret;
  193974. }
  193975. double Time::getMillisecondCounterHiRes() throw()
  193976. {
  193977. return getHighResolutionTicks() * 0.001;
  193978. }
  193979. int64 Time::getHighResolutionTicks() throw()
  193980. {
  193981. timeval t;
  193982. if (gettimeofday (&t, 0))
  193983. return 0;
  193984. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  193985. }
  193986. int64 Time::getHighResolutionTicksPerSecond() throw()
  193987. {
  193988. // Microseconds
  193989. return 1000000;
  193990. }
  193991. bool Time::setSystemTimeToThisTime() const throw()
  193992. {
  193993. timeval t;
  193994. t.tv_sec = millisSinceEpoch % 1000000;
  193995. t.tv_usec = millisSinceEpoch - t.tv_sec;
  193996. return settimeofday (&t, NULL) ? false : true;
  193997. }
  193998. int SystemStats::getPageSize() throw()
  193999. {
  194000. static int systemPageSize = 0;
  194001. if (systemPageSize == 0)
  194002. systemPageSize = sysconf (_SC_PAGESIZE);
  194003. return systemPageSize;
  194004. }
  194005. int SystemStats::getNumCpus() throw()
  194006. {
  194007. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  194008. return lastCpu + 1;
  194009. }
  194010. const String SystemStats::getLogonName()
  194011. {
  194012. const char* user = getenv ("USER");
  194013. if (user == 0)
  194014. {
  194015. struct passwd* const pw = getpwuid (getuid());
  194016. if (pw != 0)
  194017. user = pw->pw_name;
  194018. }
  194019. return String::fromUTF8 (user);
  194020. }
  194021. const String SystemStats::getFullUserName()
  194022. {
  194023. return getLogonName();
  194024. }
  194025. void SystemStats::initialiseStats() throw()
  194026. {
  194027. // Process starts off as root when running suid
  194028. Process::lowerPrivilege();
  194029. String s (SystemStats::getJUCEVersion());
  194030. }
  194031. void PlatformUtilities::fpuReset()
  194032. {
  194033. }
  194034. #endif
  194035. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  194036. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  194037. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194038. // compiled on its own).
  194039. #if JUCE_INCLUDED_FILE
  194040. void JUCE_API juce_threadEntryPoint (void*);
  194041. void* threadEntryProc (void* value)
  194042. {
  194043. // New threads start off as root when running suid
  194044. Process::lowerPrivilege();
  194045. juce_threadEntryPoint (value);
  194046. return 0;
  194047. }
  194048. void* juce_createThread (void* userData)
  194049. {
  194050. pthread_t handle = 0;
  194051. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194052. {
  194053. pthread_detach (handle);
  194054. return (void*)handle;
  194055. }
  194056. return 0;
  194057. }
  194058. void juce_killThread (void* handle)
  194059. {
  194060. if (handle != 0)
  194061. pthread_cancel ((pthread_t)handle);
  194062. }
  194063. void juce_setCurrentThreadName (const String& /*name*/)
  194064. {
  194065. }
  194066. Thread::ThreadID Thread::getCurrentThreadId()
  194067. {
  194068. return (ThreadID) pthread_self();
  194069. }
  194070. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194071. // priority of the current thread
  194072. bool juce_setThreadPriority (void* handle, int priority)
  194073. {
  194074. struct sched_param param;
  194075. int policy, maxp, minp, pri;
  194076. if (handle == 0)
  194077. handle = (void*) pthread_self();
  194078. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194079. && policy != SCHED_OTHER)
  194080. {
  194081. minp = sched_get_priority_min(policy);
  194082. maxp = sched_get_priority_max(policy);
  194083. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194084. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194085. // Realtime process priority
  194086. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194087. else
  194088. // High process priority
  194089. param.__sched_priority = minp + pri;
  194090. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194091. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194092. }
  194093. return false;
  194094. }
  194095. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194096. {
  194097. #if SUPPORT_AFFINITIES
  194098. cpu_set_t affinity;
  194099. CPU_ZERO (&affinity);
  194100. for (int i = 0; i < 32; ++i)
  194101. if ((affinityMask & (1 << i)) != 0)
  194102. CPU_SET (i, &affinity);
  194103. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194104. sched_yield();
  194105. #else
  194106. /* affinities aren't supported because either the appropriate header files weren't found,
  194107. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194108. */
  194109. jassertfalse
  194110. #endif
  194111. }
  194112. void Thread::yield()
  194113. {
  194114. sched_yield();
  194115. }
  194116. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194117. void Process::setPriority (ProcessPriority prior)
  194118. {
  194119. struct sched_param param;
  194120. int policy, maxp, minp;
  194121. const int p = (int) prior;
  194122. if (p <= 1)
  194123. policy = SCHED_OTHER;
  194124. else
  194125. policy = SCHED_RR;
  194126. minp = sched_get_priority_min (policy);
  194127. maxp = sched_get_priority_max (policy);
  194128. if (p < 2)
  194129. param.__sched_priority = 0;
  194130. else if (p == 2 )
  194131. // Set to middle of lower realtime priority range
  194132. param.__sched_priority = minp + (maxp - minp) / 4;
  194133. else
  194134. // Set to middle of higher realtime priority range
  194135. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194136. pthread_setschedparam (pthread_self(), policy, &param);
  194137. }
  194138. void Process::terminate()
  194139. {
  194140. exit (0);
  194141. }
  194142. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194143. {
  194144. static char testResult = 0;
  194145. if (testResult == 0)
  194146. {
  194147. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194148. if (testResult >= 0)
  194149. {
  194150. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194151. testResult = 1;
  194152. }
  194153. }
  194154. return testResult < 0;
  194155. }
  194156. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194157. {
  194158. return juce_isRunningUnderDebugger();
  194159. }
  194160. void Process::raisePrivilege()
  194161. {
  194162. // If running suid root, change effective user
  194163. // to root
  194164. if (geteuid() != 0 && getuid() == 0)
  194165. {
  194166. setreuid (geteuid(), getuid());
  194167. setregid (getegid(), getgid());
  194168. }
  194169. }
  194170. void Process::lowerPrivilege()
  194171. {
  194172. // If runing suid root, change effective user
  194173. // back to real user
  194174. if (geteuid() == 0 && getuid() != 0)
  194175. {
  194176. setreuid (geteuid(), getuid());
  194177. setregid (getegid(), getgid());
  194178. }
  194179. }
  194180. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194181. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194182. {
  194183. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194184. }
  194185. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194186. {
  194187. dlclose(handle);
  194188. }
  194189. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194190. {
  194191. return dlsym (libraryHandle, procedureName.toCString());
  194192. }
  194193. #endif
  194194. #endif
  194195. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194196. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194197. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194198. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194199. // compiled on its own).
  194200. #if JUCE_INCLUDED_FILE
  194201. #ifdef JUCE_DEBUG
  194202. #define JUCE_DEBUG_XERRORS 1
  194203. #endif
  194204. extern Display* display;
  194205. extern Window juce_messageWindowHandle;
  194206. static String localClipboardContent;
  194207. static Atom atom_UTF8_STRING;
  194208. static Atom atom_CLIPBOARD;
  194209. static Atom atom_TARGETS;
  194210. static void initSelectionAtoms()
  194211. {
  194212. static bool isInitialised = false;
  194213. if (! isInitialised)
  194214. {
  194215. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194216. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194217. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194218. }
  194219. }
  194220. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194221. // works only for strings shorter than 1000000 bytes
  194222. static String juce_readWindowProperty (Window window, Atom prop,
  194223. Atom fmt, // XA_STRING or UTF8_STRING
  194224. bool deleteAfterReading)
  194225. {
  194226. String returnData;
  194227. char* clipData;
  194228. Atom actualType;
  194229. int actualFormat;
  194230. unsigned long numItems, bytesLeft;
  194231. if (XGetWindowProperty (display, window, prop,
  194232. 0L /* offset */, 1000000 /* length (max) */, False,
  194233. AnyPropertyType /* format */,
  194234. &actualType, &actualFormat, &numItems, &bytesLeft,
  194235. (unsigned char**) &clipData) == Success)
  194236. {
  194237. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194238. {
  194239. returnData = String::fromUTF8 (clipData, numItems);
  194240. }
  194241. else if (actualType == XA_STRING && actualFormat == 8)
  194242. {
  194243. returnData = String (clipData, numItems);
  194244. }
  194245. if (clipData != 0)
  194246. XFree (clipData);
  194247. jassert (bytesLeft == 0 || numItems == 1000000);
  194248. }
  194249. if (deleteAfterReading)
  194250. XDeleteProperty (display, window, prop);
  194251. return returnData;
  194252. }
  194253. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194254. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194255. {
  194256. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194257. // The selection owner will be asked to set the JUCE_SEL property on the
  194258. // juce_messageWindowHandle with the selection content
  194259. XConvertSelection (display, selection, requested_format, property_name,
  194260. juce_messageWindowHandle, CurrentTime);
  194261. int timeoutMs = 200; // will wait at most for 200 ms
  194262. do
  194263. {
  194264. XEvent event;
  194265. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194266. {
  194267. if (event.xselection.property == property_name)
  194268. {
  194269. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194270. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194271. event.xselection.property,
  194272. requested_format, true);
  194273. return true;
  194274. }
  194275. else
  194276. {
  194277. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194278. }
  194279. }
  194280. // not very elegant.. we could do a select() or something like that...
  194281. // however clipboard content requesting is inherently slow on x11, it
  194282. // often takes 50ms or more so...
  194283. Thread::sleep (4);
  194284. timeoutMs -= 4;
  194285. }
  194286. while (timeoutMs > 0);
  194287. DBG("timeout for juce_requestSelectionContent");
  194288. return false;
  194289. }
  194290. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194291. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194292. {
  194293. initSelectionAtoms();
  194294. // the selection content is sent to the target window as a window property
  194295. XSelectionEvent reply;
  194296. reply.type = SelectionNotify;
  194297. reply.display = evt.display;
  194298. reply.requestor = evt.requestor;
  194299. reply.selection = evt.selection;
  194300. reply.target = evt.target;
  194301. reply.property = None; // == "fail"
  194302. reply.time = evt.time;
  194303. HeapBlock <char> data;
  194304. int propertyFormat = 0, numDataItems = 0;
  194305. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194306. {
  194307. if (evt.target == XA_STRING)
  194308. {
  194309. // format data according to system locale
  194310. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194311. data.calloc (numDataItems + 1);
  194312. localClipboardContent.copyToCString (data, numDataItems);
  194313. propertyFormat = 8; // bits/item
  194314. }
  194315. else if (evt.target == atom_UTF8_STRING)
  194316. {
  194317. // translate to utf8
  194318. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194319. data.calloc (numDataItems + 1);
  194320. localClipboardContent.copyToUTF8 (data, numDataItems);
  194321. propertyFormat = 8; // bits/item
  194322. }
  194323. else if (evt.target == atom_TARGETS)
  194324. {
  194325. // another application wants to know what we are able to send
  194326. numDataItems = 2;
  194327. propertyFormat = 32; // atoms are 32-bit
  194328. data.calloc (numDataItems * 4);
  194329. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  194330. atoms[0] = atom_UTF8_STRING;
  194331. atoms[1] = XA_STRING;
  194332. }
  194333. }
  194334. else
  194335. {
  194336. DBG ("requested unsupported clipboard");
  194337. }
  194338. if (data != 0)
  194339. {
  194340. const int maxReasonableSelectionSize = 1000000;
  194341. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194342. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194343. {
  194344. XChangeProperty (evt.display, evt.requestor,
  194345. evt.property, evt.target,
  194346. propertyFormat /* 8 or 32 */, PropModeReplace,
  194347. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  194348. reply.property = evt.property; // " == success"
  194349. }
  194350. }
  194351. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194352. }
  194353. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194354. {
  194355. initSelectionAtoms();
  194356. localClipboardContent = clipText;
  194357. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194358. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194359. }
  194360. const String SystemClipboard::getTextFromClipboard() throw()
  194361. {
  194362. initSelectionAtoms();
  194363. String content;
  194364. Atom selection = XA_PRIMARY;
  194365. Window selectionOwner = None;
  194366. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194367. {
  194368. selection = atom_CLIPBOARD;
  194369. selectionOwner = XGetSelectionOwner (display, selection);
  194370. }
  194371. if (selectionOwner != None)
  194372. {
  194373. if (selectionOwner == juce_messageWindowHandle)
  194374. {
  194375. content = localClipboardContent;
  194376. }
  194377. else
  194378. {
  194379. // first try: we want an utf8 string
  194380. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194381. if (! ok)
  194382. {
  194383. // second chance, ask for a good old locale-dependent string ..
  194384. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194385. }
  194386. }
  194387. }
  194388. return content;
  194389. }
  194390. #endif
  194391. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194392. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194393. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194394. // compiled on its own).
  194395. #if JUCE_INCLUDED_FILE
  194396. #ifdef JUCE_DEBUG
  194397. #define JUCE_DEBUG_XERRORS 1
  194398. #endif
  194399. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194400. Window juce_messageWindowHandle = None;
  194401. XContext improbableNumber; // This is referenced from Windowing.cpp
  194402. extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp
  194403. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt); // Defined in Clipboard.cpp
  194404. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194405. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194406. class InternalMessageQueue
  194407. {
  194408. public:
  194409. InternalMessageQueue()
  194410. : bytesInSocket (0)
  194411. {
  194412. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194413. (void) ret; jassert (ret == 0);
  194414. //setNonBlocking (fd[0]);
  194415. //setNonBlocking (fd[1]);
  194416. }
  194417. ~InternalMessageQueue()
  194418. {
  194419. close (fd[0]);
  194420. close (fd[1]);
  194421. }
  194422. void postMessage (Message* msg)
  194423. {
  194424. const int maxBytesInSocketQueue = 128;
  194425. ScopedLock sl (lock);
  194426. queue.add (msg);
  194427. if (bytesInSocket < maxBytesInSocketQueue)
  194428. {
  194429. ++bytesInSocket;
  194430. ScopedUnlock ul (lock);
  194431. const unsigned char x = 0xff;
  194432. size_t bytesWritten = write (fd[0], &x, 1);
  194433. (void) bytesWritten;
  194434. }
  194435. }
  194436. bool isEmpty() const
  194437. {
  194438. ScopedLock sl (lock);
  194439. return queue.size() == 0;
  194440. }
  194441. Message* popNextMessage()
  194442. {
  194443. ScopedLock sl (lock);
  194444. if (bytesInSocket > 0)
  194445. {
  194446. --bytesInSocket;
  194447. ScopedUnlock ul (lock);
  194448. unsigned char x;
  194449. size_t numBytes = read (fd[1], &x, 1);
  194450. (void) numBytes;
  194451. }
  194452. Message* m = queue[0];
  194453. queue.remove (0, false /* deleteObject */);
  194454. return m;
  194455. }
  194456. int getWaitHandle() const { return fd[1]; }
  194457. private:
  194458. CriticalSection lock;
  194459. OwnedArray <Message> queue;
  194460. int fd[2];
  194461. int bytesInSocket;
  194462. static bool setNonBlocking (int handle)
  194463. {
  194464. int socketFlags = fcntl (handle, F_GETFL, 0);
  194465. if (socketFlags == -1)
  194466. return false;
  194467. socketFlags |= O_NONBLOCK;
  194468. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194469. }
  194470. };
  194471. struct MessageThreadFuncCall
  194472. {
  194473. enum { uniqueID = 0x73774623 };
  194474. MessageCallbackFunction* func;
  194475. void* parameter;
  194476. void* result;
  194477. CriticalSection lock;
  194478. WaitableEvent event;
  194479. };
  194480. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194481. // error handling in X11
  194482. static bool errorOccurred = false;
  194483. static bool keyboardBreakOccurred = false;
  194484. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194485. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194486. // Usually happens when client-server connection is broken
  194487. static int ioErrorHandler (Display* display)
  194488. {
  194489. DBG (T("ERROR: connection to X server broken.. terminating."));
  194490. errorOccurred = true;
  194491. if (JUCEApplication::getInstance() != 0)
  194492. Process::terminate();
  194493. return 0;
  194494. }
  194495. // A protocol error has occurred
  194496. static int errorHandler (Display* display, XErrorEvent* event)
  194497. {
  194498. #ifdef JUCE_DEBUG_XERRORS
  194499. char errorStr[64] = { 0 };
  194500. char requestStr[64] = { 0 };
  194501. XGetErrorText (display, event->error_code, errorStr, 64);
  194502. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194503. "Unknown", requestStr, 64);
  194504. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194505. #endif
  194506. return 0;
  194507. }
  194508. // Breakin from keyboard
  194509. static void signalHandler (int sig)
  194510. {
  194511. if (sig == SIGINT)
  194512. {
  194513. keyboardBreakOccurred = true;
  194514. return;
  194515. }
  194516. static bool reentrant = false;
  194517. if (! reentrant)
  194518. {
  194519. reentrant = true;
  194520. // Illegal instruction
  194521. fflush (stdout);
  194522. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194523. errorOccurred = true;
  194524. if (JUCEApplication::getInstance() != 0)
  194525. Process::terminate();
  194526. }
  194527. else
  194528. {
  194529. if (JUCEApplication::getInstance() != 0)
  194530. exit(0);
  194531. }
  194532. }
  194533. void MessageManager::doPlatformSpecificInitialisation()
  194534. {
  194535. // Initialise xlib for multiple thread support
  194536. static bool initThreadCalled = false;
  194537. if (! initThreadCalled)
  194538. {
  194539. if (! XInitThreads())
  194540. {
  194541. // This is fatal! Print error and closedown
  194542. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194543. if (JUCEApplication::getInstance() != 0)
  194544. Process::terminate();
  194545. return;
  194546. }
  194547. initThreadCalled = true;
  194548. }
  194549. // This is called if the client/server connection is broken
  194550. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194551. // This is called if a protocol error occurs
  194552. oldErrorHandler = XSetErrorHandler (errorHandler);
  194553. // Install signal handler for break-in
  194554. struct sigaction saction;
  194555. sigset_t maskSet;
  194556. sigemptyset (&maskSet);
  194557. saction.sa_handler = signalHandler;
  194558. saction.sa_mask = maskSet;
  194559. saction.sa_flags = 0;
  194560. sigaction (SIGINT, &saction, NULL);
  194561. #ifndef _DEBUG
  194562. // Setup signal handlers for various fatal errors
  194563. sigaction (SIGILL, &saction, NULL);
  194564. sigaction (SIGBUS, &saction, NULL);
  194565. sigaction (SIGFPE, &saction, NULL);
  194566. sigaction (SIGSEGV, &saction, NULL);
  194567. sigaction (SIGSYS, &saction, NULL);
  194568. #endif
  194569. // Create the internal message queue
  194570. juce_internalMessageQueue = new InternalMessageQueue();
  194571. // Try to connect to a display
  194572. String displayName (getenv ("DISPLAY"));
  194573. if (displayName.isEmpty())
  194574. displayName = ":0.0";
  194575. display = XOpenDisplay (displayName.toCString());
  194576. if (display == 0)
  194577. {
  194578. // This is not fatal! we can run headless.
  194579. return;
  194580. }
  194581. // Get defaults for various properties
  194582. int screen = DefaultScreen (display);
  194583. Window root = RootWindow (display, screen);
  194584. Visual* visual = DefaultVisual (display, screen);
  194585. // Create a context to store user data associated with Windows we
  194586. // create in WindowDriver
  194587. improbableNumber = XUniqueContext();
  194588. // We're only interested in client messages for this window
  194589. // which are always sent
  194590. XSetWindowAttributes swa;
  194591. swa.event_mask = NoEventMask;
  194592. // Create our message window (this will never be mapped)
  194593. juce_messageWindowHandle = XCreateWindow (display, root,
  194594. 0, 0, 1, 1, 0, 0, InputOnly,
  194595. visual, CWEventMask, &swa);
  194596. }
  194597. void MessageManager::doPlatformSpecificShutdown()
  194598. {
  194599. deleteAndZero (juce_internalMessageQueue);
  194600. if (display != 0 && ! errorOccurred)
  194601. {
  194602. XDestroyWindow (display, juce_messageWindowHandle);
  194603. XCloseDisplay (display);
  194604. // reset pointers
  194605. juce_messageWindowHandle = 0;
  194606. display = 0;
  194607. // Restore original error handlers
  194608. XSetIOErrorHandler (oldIOErrorHandler);
  194609. oldIOErrorHandler = 0;
  194610. XSetErrorHandler (oldErrorHandler);
  194611. oldErrorHandler = 0;
  194612. }
  194613. }
  194614. bool juce_postMessageToSystemQueue (void* message)
  194615. {
  194616. if (errorOccurred)
  194617. return false;
  194618. juce_internalMessageQueue->postMessage ((Message*) message);
  194619. return true;
  194620. }
  194621. void MessageManager::broadcastMessage (const String& value) throw()
  194622. {
  194623. }
  194624. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194625. void* parameter)
  194626. {
  194627. if (errorOccurred)
  194628. return 0;
  194629. if (! isThisTheMessageThread())
  194630. {
  194631. MessageThreadFuncCall messageCallContext;
  194632. messageCallContext.func = func;
  194633. messageCallContext.parameter = parameter;
  194634. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194635. 0, 0, &messageCallContext));
  194636. // Wait for it to complete before continuing
  194637. messageCallContext.event.wait();
  194638. return messageCallContext.result;
  194639. }
  194640. else
  194641. {
  194642. // Just call the function directly
  194643. return func (parameter);
  194644. }
  194645. }
  194646. // Wait for an event (either XEvent, or an internal Message)
  194647. static bool juce_sleepUntilEvent (const int timeoutMs)
  194648. {
  194649. if (! juce_internalMessageQueue->isEmpty())
  194650. return true;
  194651. if (display != 0)
  194652. {
  194653. ScopedXLock xlock;
  194654. if (XPending (display))
  194655. return true;
  194656. }
  194657. struct timeval tv;
  194658. tv.tv_sec = 0;
  194659. tv.tv_usec = timeoutMs * 1000;
  194660. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194661. int fdmax = fd0;
  194662. fd_set readset;
  194663. FD_ZERO (&readset);
  194664. FD_SET (fd0, &readset);
  194665. if (display != 0)
  194666. {
  194667. ScopedXLock xlock;
  194668. int fd1 = XConnectionNumber (display);
  194669. FD_SET (fd1, &readset);
  194670. fdmax = jmax (fd0, fd1);
  194671. }
  194672. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194673. return (ret > 0); // ret <= 0 if error or timeout
  194674. }
  194675. // Handle next XEvent (if any)
  194676. static bool juce_dispatchNextXEvent()
  194677. {
  194678. if (display == 0)
  194679. return false;
  194680. XEvent evt;
  194681. {
  194682. ScopedXLock xlock;
  194683. if (! XPending (display))
  194684. return false;
  194685. XNextEvent (display, &evt);
  194686. }
  194687. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194688. {
  194689. juce_handleSelectionRequest (evt.xselectionrequest);
  194690. }
  194691. else if (evt.xany.window != juce_messageWindowHandle)
  194692. {
  194693. juce_windowMessageReceive (&evt);
  194694. }
  194695. return true;
  194696. }
  194697. // Handle next internal Message (if any)
  194698. static bool juce_dispatchNextInternalMessage()
  194699. {
  194700. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194701. if (msg == 0)
  194702. return false;
  194703. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194704. {
  194705. // Handle callback message
  194706. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194707. call->result = (*(call->func)) (call->parameter);
  194708. call->event.signal();
  194709. }
  194710. else
  194711. {
  194712. // Handle "normal" messages
  194713. MessageManager::getInstance()->deliverMessage (msg.release());
  194714. }
  194715. return true;
  194716. }
  194717. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194718. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194719. {
  194720. for (;;)
  194721. {
  194722. if (errorOccurred)
  194723. break;
  194724. if (keyboardBreakOccurred)
  194725. {
  194726. errorOccurred = true;
  194727. if (JUCEApplication::getInstance() != 0)
  194728. Process::terminate();
  194729. break;
  194730. }
  194731. static int totalEventCount = 0;
  194732. ++totalEventCount;
  194733. // The purpose here is to give either priority to XEvents or
  194734. // to internal messages This is necessary to keep a "good"
  194735. // behaviour when the cpu is overloaded
  194736. if (totalEventCount & 1)
  194737. {
  194738. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194739. return true;
  194740. }
  194741. else
  194742. {
  194743. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194744. return true;
  194745. }
  194746. if (returnIfNoPendingMessages) // early exit
  194747. break;
  194748. // the timeout is to be on the safe side, but it does not seem to be useful
  194749. juce_sleepUntilEvent (2000);
  194750. }
  194751. return false;
  194752. }
  194753. #endif
  194754. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194755. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194756. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194757. // compiled on its own).
  194758. #if JUCE_INCLUDED_FILE
  194759. class FreeTypeFontFace
  194760. {
  194761. public:
  194762. enum FontStyle
  194763. {
  194764. Plain = 0,
  194765. Bold = 1,
  194766. Italic = 2
  194767. };
  194768. struct FontNameIndex
  194769. {
  194770. String fileName;
  194771. int faceIndex;
  194772. };
  194773. FreeTypeFontFace (const String& familyName) throw()
  194774. : hasSerif (false),
  194775. monospaced (false)
  194776. {
  194777. family = familyName;
  194778. }
  194779. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  194780. {
  194781. if (names [(int) style].fileName.isEmpty())
  194782. {
  194783. names [(int) style].fileName = name;
  194784. names [(int) style].faceIndex = faceIndex;
  194785. }
  194786. }
  194787. const String& getFamilyName() const throw() { return family; }
  194788. const String& getFileName (const int style, int& faceIndex) const throw()
  194789. {
  194790. faceIndex = names[style].faceIndex;
  194791. return names[style].fileName;
  194792. }
  194793. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194794. bool getMonospaced() const throw() { return monospaced; }
  194795. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194796. bool getSerif() const throw() { return hasSerif; }
  194797. private:
  194798. String family;
  194799. FontNameIndex names[4];
  194800. bool hasSerif, monospaced;
  194801. };
  194802. class FreeTypeInterface : public DeletedAtShutdown
  194803. {
  194804. public:
  194805. FreeTypeInterface() throw()
  194806. : lastFace (0),
  194807. lastBold (false),
  194808. lastItalic (false)
  194809. {
  194810. if (FT_Init_FreeType (&ftLib) != 0)
  194811. {
  194812. ftLib = 0;
  194813. DBG (T("Failed to initialize FreeType"));
  194814. }
  194815. StringArray fontDirs;
  194816. fontDirs.addTokens (String::fromUTF8 (getenv ("JUCE_FONT_PATH")), ";,", String::empty);
  194817. fontDirs.removeEmptyStrings (true);
  194818. if (fontDirs.size() == 0)
  194819. {
  194820. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194821. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  194822. if (fontsInfo != 0)
  194823. {
  194824. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  194825. {
  194826. fontDirs.add (e->getAllSubText().trim());
  194827. }
  194828. delete fontsInfo;
  194829. }
  194830. }
  194831. if (fontDirs.size() == 0)
  194832. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194833. for (int i = 0; i < fontDirs.size(); ++i)
  194834. enumerateFaces (fontDirs[i]);
  194835. }
  194836. ~FreeTypeInterface() throw()
  194837. {
  194838. if (lastFace != 0)
  194839. FT_Done_Face (lastFace);
  194840. if (ftLib != 0)
  194841. FT_Done_FreeType (ftLib);
  194842. clearSingletonInstance();
  194843. }
  194844. FreeTypeFontFace* findOrCreate (const String& familyName,
  194845. const bool create = false) throw()
  194846. {
  194847. for (int i = 0; i < faces.size(); i++)
  194848. if (faces[i]->getFamilyName() == familyName)
  194849. return faces[i];
  194850. if (! create)
  194851. return NULL;
  194852. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194853. faces.add (newFace);
  194854. return newFace;
  194855. }
  194856. // Enumerate all font faces available in a given directory
  194857. void enumerateFaces (const String& path) throw()
  194858. {
  194859. File dirPath (path);
  194860. if (path.isEmpty() || ! dirPath.isDirectory())
  194861. return;
  194862. DirectoryIterator di (dirPath, true);
  194863. while (di.next())
  194864. {
  194865. File possible (di.getFile());
  194866. if (possible.hasFileExtension (T("ttf"))
  194867. || possible.hasFileExtension (T("pfb"))
  194868. || possible.hasFileExtension (T("pcf")))
  194869. {
  194870. FT_Face face;
  194871. int faceIndex = 0;
  194872. int numFaces = 0;
  194873. do
  194874. {
  194875. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194876. faceIndex, &face) == 0)
  194877. {
  194878. if (faceIndex == 0)
  194879. numFaces = face->num_faces;
  194880. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194881. {
  194882. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194883. int style = (int) FreeTypeFontFace::Plain;
  194884. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194885. style |= (int) FreeTypeFontFace::Bold;
  194886. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194887. style |= (int) FreeTypeFontFace::Italic;
  194888. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194889. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194890. // Surely there must be a better way to do this?
  194891. const String name (face->family_name);
  194892. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  194893. || name.containsIgnoreCase (T("Verdana"))
  194894. || name.containsIgnoreCase (T("Arial"))));
  194895. }
  194896. FT_Done_Face (face);
  194897. }
  194898. ++faceIndex;
  194899. }
  194900. while (faceIndex < numFaces);
  194901. }
  194902. }
  194903. }
  194904. // Create a FreeType face object for a given font
  194905. FT_Face createFT_Face (const String& fontName,
  194906. const bool bold,
  194907. const bool italic) throw()
  194908. {
  194909. FT_Face face = 0;
  194910. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194911. {
  194912. face = lastFace;
  194913. }
  194914. else
  194915. {
  194916. if (lastFace != 0)
  194917. {
  194918. FT_Done_Face (lastFace);
  194919. lastFace = 0;
  194920. }
  194921. lastFontName = fontName;
  194922. lastBold = bold;
  194923. lastItalic = italic;
  194924. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  194925. if (ftFace != 0)
  194926. {
  194927. int style = (int) FreeTypeFontFace::Plain;
  194928. if (bold)
  194929. style |= (int) FreeTypeFontFace::Bold;
  194930. if (italic)
  194931. style |= (int) FreeTypeFontFace::Italic;
  194932. int faceIndex;
  194933. String fileName (ftFace->getFileName (style, faceIndex));
  194934. if (fileName.isEmpty())
  194935. {
  194936. style ^= (int) FreeTypeFontFace::Bold;
  194937. fileName = ftFace->getFileName (style, faceIndex);
  194938. if (fileName.isEmpty())
  194939. {
  194940. style ^= (int) FreeTypeFontFace::Bold;
  194941. style ^= (int) FreeTypeFontFace::Italic;
  194942. fileName = ftFace->getFileName (style, faceIndex);
  194943. if (! fileName.length())
  194944. {
  194945. style ^= (int) FreeTypeFontFace::Bold;
  194946. fileName = ftFace->getFileName (style, faceIndex);
  194947. }
  194948. }
  194949. }
  194950. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  194951. {
  194952. face = lastFace;
  194953. // If there isn't a unicode charmap then select the first one.
  194954. if (FT_Select_Charmap (face, ft_encoding_unicode))
  194955. FT_Set_Charmap (face, face->charmaps[0]);
  194956. }
  194957. }
  194958. }
  194959. return face;
  194960. }
  194961. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  194962. {
  194963. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  194964. const float height = (float) (face->ascender - face->descender);
  194965. const float scaleX = 1.0f / height;
  194966. const float scaleY = -1.0f / height;
  194967. Path destShape;
  194968. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  194969. || face->glyph->format != ft_glyph_format_outline)
  194970. {
  194971. return false;
  194972. }
  194973. const FT_Outline* const outline = &face->glyph->outline;
  194974. const short* const contours = outline->contours;
  194975. const char* const tags = outline->tags;
  194976. FT_Vector* const points = outline->points;
  194977. for (int c = 0; c < outline->n_contours; c++)
  194978. {
  194979. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  194980. const int endPoint = contours[c];
  194981. for (int p = startPoint; p <= endPoint; p++)
  194982. {
  194983. const float x = scaleX * points[p].x;
  194984. const float y = scaleY * points[p].y;
  194985. if (p == startPoint)
  194986. {
  194987. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194988. {
  194989. float x2 = scaleX * points [endPoint].x;
  194990. float y2 = scaleY * points [endPoint].y;
  194991. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  194992. {
  194993. x2 = (x + x2) * 0.5f;
  194994. y2 = (y + y2) * 0.5f;
  194995. }
  194996. destShape.startNewSubPath (x2, y2);
  194997. }
  194998. else
  194999. {
  195000. destShape.startNewSubPath (x, y);
  195001. }
  195002. }
  195003. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  195004. {
  195005. if (p != startPoint)
  195006. destShape.lineTo (x, y);
  195007. }
  195008. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195009. {
  195010. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  195011. float x2 = scaleX * points [nextIndex].x;
  195012. float y2 = scaleY * points [nextIndex].y;
  195013. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  195014. {
  195015. x2 = (x + x2) * 0.5f;
  195016. y2 = (y + y2) * 0.5f;
  195017. }
  195018. else
  195019. {
  195020. ++p;
  195021. }
  195022. destShape.quadraticTo (x, y, x2, y2);
  195023. }
  195024. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  195025. {
  195026. if (p >= endPoint)
  195027. return false;
  195028. const int next1 = p + 1;
  195029. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  195030. const float x2 = scaleX * points [next1].x;
  195031. const float y2 = scaleY * points [next1].y;
  195032. const float x3 = scaleX * points [next2].x;
  195033. const float y3 = scaleY * points [next2].y;
  195034. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  195035. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  195036. return false;
  195037. destShape.cubicTo (x, y, x2, y2, x3, y3);
  195038. p += 2;
  195039. }
  195040. }
  195041. destShape.closeSubPath();
  195042. }
  195043. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195044. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195045. addKerning (face, dest, character, glyphIndex);
  195046. return true;
  195047. }
  195048. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195049. {
  195050. const float height = (float) (face->ascender - face->descender);
  195051. uint32 rightGlyphIndex;
  195052. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195053. while (rightGlyphIndex != 0)
  195054. {
  195055. FT_Vector kerning;
  195056. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195057. {
  195058. if (kerning.x != 0)
  195059. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195060. }
  195061. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195062. }
  195063. }
  195064. // Add a glyph to a font
  195065. bool addGlyphToFont (const uint32 character,
  195066. const tchar* fontName, bool bold, bool italic,
  195067. CustomTypeface& dest) throw()
  195068. {
  195069. FT_Face face = createFT_Face (fontName, bold, italic);
  195070. if (face != 0)
  195071. return addGlyph (face, dest, character);
  195072. return false;
  195073. }
  195074. void getFamilyNames (StringArray& familyNames) const throw()
  195075. {
  195076. for (int i = 0; i < faces.size(); i++)
  195077. familyNames.add (faces[i]->getFamilyName());
  195078. }
  195079. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195080. {
  195081. for (int i = 0; i < faces.size(); i++)
  195082. if (faces[i]->getMonospaced())
  195083. monoSpaced.add (faces[i]->getFamilyName());
  195084. }
  195085. void getSerifNames (StringArray& serif) const throw()
  195086. {
  195087. for (int i = 0; i < faces.size(); i++)
  195088. if (faces[i]->getSerif())
  195089. serif.add (faces[i]->getFamilyName());
  195090. }
  195091. void getSansSerifNames (StringArray& sansSerif) const throw()
  195092. {
  195093. for (int i = 0; i < faces.size(); i++)
  195094. if (! faces[i]->getSerif())
  195095. sansSerif.add (faces[i]->getFamilyName());
  195096. }
  195097. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195098. private:
  195099. FT_Library ftLib;
  195100. FT_Face lastFace;
  195101. String lastFontName;
  195102. bool lastBold, lastItalic;
  195103. OwnedArray<FreeTypeFontFace> faces;
  195104. };
  195105. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195106. class FreetypeTypeface : public CustomTypeface
  195107. {
  195108. public:
  195109. FreetypeTypeface (const Font& font)
  195110. {
  195111. FT_Face face = FreeTypeInterface::getInstance()
  195112. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195113. if (face == 0)
  195114. {
  195115. #ifdef JUCE_DEBUG
  195116. String msg (T("Failed to create typeface: "));
  195117. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195118. DBG (msg);
  195119. #endif
  195120. }
  195121. else
  195122. {
  195123. setCharacteristics (font.getTypefaceName(),
  195124. face->ascender / (float) (face->ascender - face->descender),
  195125. font.isBold(), font.isItalic(),
  195126. L' ');
  195127. }
  195128. }
  195129. bool loadGlyphIfPossible (const juce_wchar character)
  195130. {
  195131. return FreeTypeInterface::getInstance()
  195132. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195133. }
  195134. };
  195135. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195136. {
  195137. return new FreetypeTypeface (font);
  195138. }
  195139. const StringArray Font::findAllTypefaceNames() throw()
  195140. {
  195141. StringArray s;
  195142. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195143. s.sort (true);
  195144. return s;
  195145. }
  195146. static const String pickBestFont (const StringArray& names,
  195147. const char* const choicesString)
  195148. {
  195149. StringArray choices;
  195150. choices.addTokens (String (choicesString), ",", String::empty);
  195151. choices.trim();
  195152. choices.removeEmptyStrings();
  195153. int i, j;
  195154. for (j = 0; j < choices.size(); ++j)
  195155. if (names.contains (choices[j], true))
  195156. return choices[j];
  195157. for (j = 0; j < choices.size(); ++j)
  195158. for (i = 0; i < names.size(); i++)
  195159. if (names[i].startsWithIgnoreCase (choices[j]))
  195160. return names[i];
  195161. for (j = 0; j < choices.size(); ++j)
  195162. for (i = 0; i < names.size(); i++)
  195163. if (names[i].containsIgnoreCase (choices[j]))
  195164. return names[i];
  195165. return names[0];
  195166. }
  195167. static const String linux_getDefaultSansSerifFontName()
  195168. {
  195169. StringArray allFonts;
  195170. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195171. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195172. }
  195173. static const String linux_getDefaultSerifFontName()
  195174. {
  195175. StringArray allFonts;
  195176. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195177. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195178. }
  195179. static const String linux_getDefaultMonospacedFontName()
  195180. {
  195181. StringArray allFonts;
  195182. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195183. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195184. }
  195185. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195186. {
  195187. defaultSans = linux_getDefaultSansSerifFontName();
  195188. defaultSerif = linux_getDefaultSerifFontName();
  195189. defaultFixed = linux_getDefaultMonospacedFontName();
  195190. }
  195191. #endif
  195192. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195193. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195194. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195195. // compiled on its own).
  195196. #if JUCE_INCLUDED_FILE
  195197. namespace Atoms
  195198. {
  195199. enum ProtocolItems
  195200. {
  195201. TAKE_FOCUS = 0,
  195202. DELETE_WINDOW = 1
  195203. };
  195204. static Atom Protocols, ProtocolList[2], ChangeState, State,
  195205. ActiveWin, Pid, WindowType, WindowState,
  195206. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  195207. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  195208. XdndActionDescription, XdndActionCopy,
  195209. allowedActions[5],
  195210. allowedMimeTypes[2];
  195211. const unsigned long DndVersion = 3;
  195212. static void initialiseAtoms()
  195213. {
  195214. static bool atomsInitialised = false;
  195215. if (! atomsInitialised)
  195216. {
  195217. atomsInitialised = true;
  195218. Protocols = XInternAtom (display, "WM_PROTOCOLS", True);
  195219. ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", True);
  195220. ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", True);
  195221. ChangeState = XInternAtom (display, "WM_CHANGE_STATE", True);
  195222. State = XInternAtom (display, "WM_STATE", True);
  195223. ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  195224. Pid = XInternAtom (display, "_NET_WM_PID", False);
  195225. WindowType = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  195226. WindowState = XInternAtom (display, "_NET_WM_WINDOW_STATE", True);
  195227. XdndAware = XInternAtom (display, "XdndAware", False);
  195228. XdndEnter = XInternAtom (display, "XdndEnter", False);
  195229. XdndLeave = XInternAtom (display, "XdndLeave", False);
  195230. XdndPosition = XInternAtom (display, "XdndPosition", False);
  195231. XdndStatus = XInternAtom (display, "XdndStatus", False);
  195232. XdndDrop = XInternAtom (display, "XdndDrop", False);
  195233. XdndFinished = XInternAtom (display, "XdndFinished", False);
  195234. XdndSelection = XInternAtom (display, "XdndSelection", False);
  195235. XdndTypeList = XInternAtom (display, "XdndTypeList", False);
  195236. XdndActionList = XInternAtom (display, "XdndActionList", False);
  195237. XdndActionCopy = XInternAtom (display, "XdndActionCopy", False);
  195238. XdndActionDescription = XInternAtom (display, "XdndActionDescription", False);
  195239. allowedMimeTypes [0] = XInternAtom (display, "text/plain", False);
  195240. allowedMimeTypes [1] = XInternAtom (display, "text/uri-list", False);
  195241. allowedActions [0] = XInternAtom (display, "XdndActionMove", False);
  195242. allowedActions [1] = XdndActionCopy;
  195243. allowedActions [2] = XInternAtom (display, "XdndActionLink", False);
  195244. allowedActions [3] = XInternAtom (display, "XdndActionAsk", False);
  195245. allowedActions [4] = XInternAtom (display, "XdndActionPrivate", False);
  195246. }
  195247. }
  195248. }
  195249. enum SystemTrayValues
  195250. {
  195251. SYSTEM_TRAY_REQUEST_DOCK = 0,
  195252. SYSTEM_TRAY_BEGIN_MESSAGE = 1,
  195253. SYSTEM_TRAY_CANCEL_MESSAGE = 2
  195254. };
  195255. static XErrorHandler oldHandler = 0;
  195256. static int trappedErrorCode = 0;
  195257. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195258. {
  195259. trappedErrorCode = err->error_code;
  195260. return 0;
  195261. }
  195262. static void trapErrors()
  195263. {
  195264. trappedErrorCode = 0;
  195265. oldHandler = XSetErrorHandler (errorTrapHandler);
  195266. }
  195267. static bool untrapErrors()
  195268. {
  195269. XSetErrorHandler (oldHandler);
  195270. return (trappedErrorCode == 0);
  195271. }
  195272. static bool isActiveApplication = false;
  195273. bool Process::isForegroundProcess()
  195274. {
  195275. return isActiveApplication;
  195276. }
  195277. // These are defined in juce_linux_Messaging.cpp
  195278. extern Display* display;
  195279. extern XContext improbableNumber;
  195280. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195281. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195282. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195283. namespace Keys
  195284. {
  195285. enum MouseButtons
  195286. {
  195287. NoButton = 0,
  195288. LeftButton = 1,
  195289. MiddleButton = 2,
  195290. RightButton = 3,
  195291. WheelUp = 4,
  195292. WheelDown = 5
  195293. };
  195294. static int AltMask = 0;
  195295. static int NumLockMask = 0;
  195296. static bool numLock = false;
  195297. static bool capsLock = false;
  195298. static char keyStates [32];
  195299. static const int extendedKeyModifier = 0x10000000;
  195300. }
  195301. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195302. {
  195303. int keysym;
  195304. if (keyCode & Keys::extendedKeyModifier)
  195305. {
  195306. keysym = 0xff00 | (keyCode & 0xff);
  195307. }
  195308. else
  195309. {
  195310. keysym = keyCode;
  195311. if (keysym == (XK_Tab & 0xff)
  195312. || keysym == (XK_Return & 0xff)
  195313. || keysym == (XK_Escape & 0xff)
  195314. || keysym == (XK_BackSpace & 0xff))
  195315. {
  195316. keysym |= 0xff00;
  195317. }
  195318. }
  195319. ScopedXLock xlock;
  195320. const int keycode = XKeysymToKeycode (display, keysym);
  195321. const int keybyte = keycode >> 3;
  195322. const int keybit = (1 << (keycode & 7));
  195323. return (Keys::keyStates [keybyte] & keybit) != 0;
  195324. }
  195325. #if JUCE_USE_XSHM
  195326. static bool isShmAvailable() throw()
  195327. {
  195328. static bool isChecked = false;
  195329. static bool isAvailable = false;
  195330. if (! isChecked)
  195331. {
  195332. isChecked = true;
  195333. int major, minor;
  195334. Bool pixmaps;
  195335. ScopedXLock xlock;
  195336. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195337. {
  195338. trapErrors();
  195339. XShmSegmentInfo segmentInfo;
  195340. zerostruct (segmentInfo);
  195341. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195342. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195343. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195344. xImage->bytes_per_line * xImage->height,
  195345. IPC_CREAT | 0777)) >= 0)
  195346. {
  195347. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195348. if (segmentInfo.shmaddr != (void*) -1)
  195349. {
  195350. segmentInfo.readOnly = False;
  195351. xImage->data = segmentInfo.shmaddr;
  195352. XSync (display, False);
  195353. if (XShmAttach (display, &segmentInfo) != 0)
  195354. {
  195355. XSync (display, False);
  195356. XShmDetach (display, &segmentInfo);
  195357. isAvailable = true;
  195358. }
  195359. }
  195360. XFlush (display);
  195361. XDestroyImage (xImage);
  195362. shmdt (segmentInfo.shmaddr);
  195363. }
  195364. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195365. isAvailable &= untrapErrors();
  195366. }
  195367. }
  195368. return isAvailable;
  195369. }
  195370. #endif
  195371. #if JUCE_USE_XRENDER
  195372. namespace XRender
  195373. {
  195374. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  195375. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  195376. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  195377. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  195378. static tXRenderQueryVersion xRenderQueryVersion = 0;
  195379. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  195380. static tXRenderFindFormat xRenderFindFormat = 0;
  195381. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  195382. static bool isAvailable()
  195383. {
  195384. static bool isChecked = false;
  195385. static bool isAvailable = false;
  195386. if (! isChecked)
  195387. {
  195388. ScopedXLock xlock;
  195389. isChecked = true;
  195390. if (xRenderQueryVersion == 0)
  195391. {
  195392. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  195393. if (h != 0)
  195394. {
  195395. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  195396. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  195397. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  195398. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  195399. }
  195400. }
  195401. if (xRenderQueryVersion != 0
  195402. && xRenderFindStandardFormat != 0
  195403. && xRenderFindFormat != 0
  195404. && xRenderFindVisualFormat != 0)
  195405. {
  195406. int major, minor;
  195407. if (xRenderQueryVersion (display, &major, &minor))
  195408. isAvailable = true;
  195409. }
  195410. }
  195411. return isAvailable;
  195412. }
  195413. static XRenderPictFormat* findPictureFormat()
  195414. {
  195415. ScopedXLock xlock;
  195416. XRenderPictFormat* pictFormat = 0;
  195417. if (isAvailable())
  195418. {
  195419. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  195420. if (pictFormat == 0)
  195421. {
  195422. XRenderPictFormat desiredFormat;
  195423. desiredFormat.type = PictTypeDirect;
  195424. desiredFormat.depth = 32;
  195425. desiredFormat.direct.alphaMask = 0xff;
  195426. desiredFormat.direct.redMask = 0xff;
  195427. desiredFormat.direct.greenMask = 0xff;
  195428. desiredFormat.direct.blueMask = 0xff;
  195429. desiredFormat.direct.alpha = 24;
  195430. desiredFormat.direct.red = 16;
  195431. desiredFormat.direct.green = 8;
  195432. desiredFormat.direct.blue = 0;
  195433. pictFormat = xRenderFindFormat (display,
  195434. PictFormatType | PictFormatDepth
  195435. | PictFormatRedMask | PictFormatRed
  195436. | PictFormatGreenMask | PictFormatGreen
  195437. | PictFormatBlueMask | PictFormatBlue
  195438. | PictFormatAlphaMask | PictFormatAlpha,
  195439. &desiredFormat,
  195440. 0);
  195441. }
  195442. }
  195443. return pictFormat;
  195444. }
  195445. }
  195446. #endif
  195447. namespace Visuals
  195448. {
  195449. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  195450. {
  195451. ScopedXLock xlock;
  195452. Visual* visual = 0;
  195453. int numVisuals = 0;
  195454. long desiredMask = VisualNoMask;
  195455. XVisualInfo desiredVisual;
  195456. desiredVisual.screen = DefaultScreen (display);
  195457. desiredVisual.depth = desiredDepth;
  195458. desiredMask = VisualScreenMask | VisualDepthMask;
  195459. if (desiredDepth == 32)
  195460. {
  195461. desiredVisual.c_class = TrueColor;
  195462. desiredVisual.red_mask = 0x00FF0000;
  195463. desiredVisual.green_mask = 0x0000FF00;
  195464. desiredVisual.blue_mask = 0x000000FF;
  195465. desiredVisual.bits_per_rgb = 8;
  195466. desiredMask |= VisualClassMask;
  195467. desiredMask |= VisualRedMaskMask;
  195468. desiredMask |= VisualGreenMaskMask;
  195469. desiredMask |= VisualBlueMaskMask;
  195470. desiredMask |= VisualBitsPerRGBMask;
  195471. }
  195472. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195473. desiredMask,
  195474. &desiredVisual,
  195475. &numVisuals);
  195476. if (xvinfos != 0)
  195477. {
  195478. for (int i = 0; i < numVisuals; i++)
  195479. {
  195480. if (xvinfos[i].depth == desiredDepth)
  195481. {
  195482. visual = xvinfos[i].visual;
  195483. break;
  195484. }
  195485. }
  195486. XFree (xvinfos);
  195487. }
  195488. return visual;
  195489. }
  195490. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  195491. {
  195492. Visual* visual = 0;
  195493. if (desiredDepth == 32)
  195494. {
  195495. #if JUCE_USE_XSHM
  195496. if (isShmAvailable())
  195497. {
  195498. #if JUCE_USE_XRENDER
  195499. if (XRender::isAvailable())
  195500. {
  195501. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  195502. if (pictFormat != 0)
  195503. {
  195504. int numVisuals = 0;
  195505. XVisualInfo desiredVisual;
  195506. desiredVisual.screen = DefaultScreen (display);
  195507. desiredVisual.depth = 32;
  195508. desiredVisual.bits_per_rgb = 8;
  195509. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195510. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  195511. &desiredVisual, &numVisuals);
  195512. if (xvinfos != 0)
  195513. {
  195514. for (int i = 0; i < numVisuals; ++i)
  195515. {
  195516. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  195517. if (pictVisualFormat != 0
  195518. && pictVisualFormat->type == PictTypeDirect
  195519. && pictVisualFormat->direct.alphaMask)
  195520. {
  195521. visual = xvinfos[i].visual;
  195522. matchedDepth = 32;
  195523. break;
  195524. }
  195525. }
  195526. XFree (xvinfos);
  195527. }
  195528. }
  195529. }
  195530. #endif
  195531. if (visual == 0)
  195532. {
  195533. visual = findVisualWithDepth (32);
  195534. if (visual != 0)
  195535. matchedDepth = 32;
  195536. }
  195537. }
  195538. #endif
  195539. }
  195540. if (visual == 0 && desiredDepth >= 24)
  195541. {
  195542. visual = findVisualWithDepth (24);
  195543. if (visual != 0)
  195544. matchedDepth = 24;
  195545. }
  195546. if (visual == 0 && desiredDepth >= 16)
  195547. {
  195548. visual = findVisualWithDepth (16);
  195549. if (visual != 0)
  195550. matchedDepth = 16;
  195551. }
  195552. return visual;
  195553. }
  195554. }
  195555. class XBitmapImage : public Image
  195556. {
  195557. public:
  195558. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195559. const bool clearImage, const int imageDepth_, Visual* visual)
  195560. : Image (format_, w, h),
  195561. imageDepth (imageDepth_),
  195562. gc (None)
  195563. {
  195564. jassert (format_ == RGB || format_ == ARGB);
  195565. pixelStride = (format_ == RGB) ? 3 : 4;
  195566. lineStride = ((w * pixelStride + 3) & ~3);
  195567. ScopedXLock xlock;
  195568. #if JUCE_USE_XSHM
  195569. usingXShm = false;
  195570. if ((imageDepth > 16) && isShmAvailable())
  195571. {
  195572. zerostruct (segmentInfo);
  195573. segmentInfo.shmid = -1;
  195574. segmentInfo.shmaddr = (char *) -1;
  195575. segmentInfo.readOnly = False;
  195576. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  195577. if (xImage != 0)
  195578. {
  195579. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195580. xImage->bytes_per_line * xImage->height,
  195581. IPC_CREAT | 0777)) >= 0)
  195582. {
  195583. if (segmentInfo.shmid != -1)
  195584. {
  195585. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195586. if (segmentInfo.shmaddr != (void*) -1)
  195587. {
  195588. segmentInfo.readOnly = False;
  195589. xImage->data = segmentInfo.shmaddr;
  195590. imageData = (uint8*) segmentInfo.shmaddr;
  195591. if (XShmAttach (display, &segmentInfo) != 0)
  195592. {
  195593. usingXShm = true;
  195594. }
  195595. else
  195596. {
  195597. jassertfalse
  195598. }
  195599. }
  195600. else
  195601. {
  195602. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195603. }
  195604. }
  195605. }
  195606. }
  195607. }
  195608. if (! usingXShm)
  195609. #endif
  195610. {
  195611. imageDataAllocated.malloc (lineStride * h);
  195612. imageData = imageDataAllocated;
  195613. if (format_ == ARGB && clearImage)
  195614. zeromem (imageData, h * lineStride);
  195615. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195616. xImage->width = w;
  195617. xImage->height = h;
  195618. xImage->xoffset = 0;
  195619. xImage->format = ZPixmap;
  195620. xImage->data = (char*) imageData;
  195621. xImage->byte_order = ImageByteOrder (display);
  195622. xImage->bitmap_unit = BitmapUnit (display);
  195623. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195624. xImage->bitmap_pad = 32;
  195625. xImage->depth = pixelStride * 8;
  195626. xImage->bytes_per_line = lineStride;
  195627. xImage->bits_per_pixel = pixelStride * 8;
  195628. xImage->red_mask = 0x00FF0000;
  195629. xImage->green_mask = 0x0000FF00;
  195630. xImage->blue_mask = 0x000000FF;
  195631. if (imageDepth == 16)
  195632. {
  195633. const int pixelStride = 2;
  195634. const int lineStride = ((w * pixelStride + 3) & ~3);
  195635. imageData16Bit.malloc (lineStride * h);
  195636. xImage->data = imageData16Bit;
  195637. xImage->bitmap_pad = 16;
  195638. xImage->depth = pixelStride * 8;
  195639. xImage->bytes_per_line = lineStride;
  195640. xImage->bits_per_pixel = pixelStride * 8;
  195641. xImage->red_mask = visual->red_mask;
  195642. xImage->green_mask = visual->green_mask;
  195643. xImage->blue_mask = visual->blue_mask;
  195644. }
  195645. if (! XInitImage (xImage))
  195646. {
  195647. jassertfalse
  195648. }
  195649. }
  195650. }
  195651. ~XBitmapImage()
  195652. {
  195653. ScopedXLock xlock;
  195654. #if JUCE_USE_XSHM
  195655. if (usingXShm)
  195656. {
  195657. XShmDetach (display, &segmentInfo);
  195658. XFlush (display);
  195659. XDestroyImage (xImage);
  195660. shmdt (segmentInfo.shmaddr);
  195661. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195662. }
  195663. else
  195664. #endif
  195665. {
  195666. xImage->data = 0;
  195667. XDestroyImage (xImage);
  195668. }
  195669. }
  195670. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195671. {
  195672. ScopedXLock xlock;
  195673. if (gc == 0)
  195674. {
  195675. XGCValues gcvalues;
  195676. gcvalues.foreground = None;
  195677. gcvalues.background = None;
  195678. gcvalues.function = GXcopy;
  195679. gcvalues.plane_mask = AllPlanes;
  195680. gcvalues.clip_mask = None;
  195681. gcvalues.graphics_exposures = False;
  195682. gc = XCreateGC (display, window,
  195683. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195684. &gcvalues);
  195685. }
  195686. if (imageDepth == 16)
  195687. {
  195688. const uint32 rMask = xImage->red_mask;
  195689. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195690. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195691. const uint32 gMask = xImage->green_mask;
  195692. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195693. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195694. const uint32 bMask = xImage->blue_mask;
  195695. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195696. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195697. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195698. for (int y = sy; y < sy + dh; ++y)
  195699. {
  195700. const uint8* p = srcData.getPixelPointer (sx, y);
  195701. for (int x = sx; x < sx + dw; ++x)
  195702. {
  195703. const PixelRGB* const pixel = (const PixelRGB*) p;
  195704. p += srcData.pixelStride;
  195705. XPutPixel (xImage, x, y,
  195706. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195707. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195708. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195709. }
  195710. }
  195711. }
  195712. // blit results to screen.
  195713. #if JUCE_USE_XSHM
  195714. if (usingXShm)
  195715. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195716. else
  195717. #endif
  195718. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195719. }
  195720. juce_UseDebuggingNewOperator
  195721. private:
  195722. XImage* xImage;
  195723. const int imageDepth;
  195724. HeapBlock <char> imageData16Bit;
  195725. GC gc;
  195726. #if JUCE_USE_XSHM
  195727. XShmSegmentInfo segmentInfo;
  195728. bool usingXShm;
  195729. #endif
  195730. static int getShiftNeeded (const uint32 mask) throw()
  195731. {
  195732. for (int i = 32; --i >= 0;)
  195733. if (((mask >> i) & 1) != 0)
  195734. return i - 7;
  195735. jassertfalse
  195736. return 0;
  195737. }
  195738. };
  195739. class LinuxComponentPeer : public ComponentPeer
  195740. {
  195741. public:
  195742. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195743. : ComponentPeer (component, windowStyleFlags),
  195744. windowH (0),
  195745. parentWindow (0),
  195746. wx (0),
  195747. wy (0),
  195748. ww (0),
  195749. wh (0),
  195750. taskbarImage (0),
  195751. fullScreen (false),
  195752. mapped (false),
  195753. visual (0),
  195754. depth (0)
  195755. {
  195756. // it's dangerous to create a window on a thread other than the message thread..
  195757. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195758. repainter = new LinuxRepaintManager (this);
  195759. createWindow();
  195760. setTitle (component->getName());
  195761. }
  195762. ~LinuxComponentPeer()
  195763. {
  195764. // it's dangerous to delete a window on a thread other than the message thread..
  195765. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195766. deleteTaskBarIcon();
  195767. deleteIconPixmaps();
  195768. destroyWindow();
  195769. windowH = 0;
  195770. }
  195771. void* getNativeHandle() const
  195772. {
  195773. return (void*) windowH;
  195774. }
  195775. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195776. {
  195777. XPointer peer = 0;
  195778. ScopedXLock xlock;
  195779. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195780. {
  195781. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195782. peer = 0;
  195783. }
  195784. return (LinuxComponentPeer*) peer;
  195785. }
  195786. void setVisible (bool shouldBeVisible)
  195787. {
  195788. ScopedXLock xlock;
  195789. if (shouldBeVisible)
  195790. XMapWindow (display, windowH);
  195791. else
  195792. XUnmapWindow (display, windowH);
  195793. }
  195794. void setTitle (const String& title)
  195795. {
  195796. setWindowTitle (windowH, title);
  195797. }
  195798. void setPosition (int x, int y)
  195799. {
  195800. setBounds (x, y, ww, wh, false);
  195801. }
  195802. void setSize (int w, int h)
  195803. {
  195804. setBounds (wx, wy, w, h, false);
  195805. }
  195806. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  195807. {
  195808. fullScreen = isNowFullScreen;
  195809. if (windowH != 0)
  195810. {
  195811. Component::SafePointer<Component> deletionChecker (component);
  195812. wx = x;
  195813. wy = y;
  195814. ww = jmax (1, w);
  195815. wh = jmax (1, h);
  195816. ScopedXLock xlock;
  195817. // Make sure the Window manager does what we want
  195818. XSizeHints* hints = XAllocSizeHints();
  195819. hints->flags = USSize | USPosition;
  195820. hints->width = ww;
  195821. hints->height = wh;
  195822. hints->x = wx;
  195823. hints->y = wy;
  195824. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195825. {
  195826. hints->min_width = hints->max_width = hints->width;
  195827. hints->min_height = hints->max_height = hints->height;
  195828. hints->flags |= PMinSize | PMaxSize;
  195829. }
  195830. XSetWMNormalHints (display, windowH, hints);
  195831. XFree (hints);
  195832. XMoveResizeWindow (display, windowH,
  195833. wx - windowBorder.getLeft(),
  195834. wy - windowBorder.getTop(), ww, wh);
  195835. if (deletionChecker != 0)
  195836. {
  195837. updateBorderSize();
  195838. handleMovedOrResized();
  195839. }
  195840. }
  195841. }
  195842. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195843. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195844. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195845. {
  195846. return relativePosition + getScreenPosition();
  195847. }
  195848. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195849. {
  195850. return screenPosition - getScreenPosition();
  195851. }
  195852. void setMinimised (bool shouldBeMinimised)
  195853. {
  195854. if (shouldBeMinimised)
  195855. {
  195856. Window root = RootWindow (display, DefaultScreen (display));
  195857. XClientMessageEvent clientMsg;
  195858. clientMsg.display = display;
  195859. clientMsg.window = windowH;
  195860. clientMsg.type = ClientMessage;
  195861. clientMsg.format = 32;
  195862. clientMsg.message_type = Atoms::ChangeState;
  195863. clientMsg.data.l[0] = IconicState;
  195864. ScopedXLock xlock;
  195865. XSendEvent (display, root, false,
  195866. SubstructureRedirectMask | SubstructureNotifyMask,
  195867. (XEvent*) &clientMsg);
  195868. }
  195869. else
  195870. {
  195871. setVisible (true);
  195872. }
  195873. }
  195874. bool isMinimised() const
  195875. {
  195876. bool minimised = false;
  195877. unsigned char* stateProp;
  195878. unsigned long nitems, bytesLeft;
  195879. Atom actualType;
  195880. int actualFormat;
  195881. ScopedXLock xlock;
  195882. if (XGetWindowProperty (display, windowH, Atoms::State, 0, 64, False,
  195883. Atoms::State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195884. &stateProp) == Success
  195885. && actualType == Atoms::State
  195886. && actualFormat == 32
  195887. && nitems > 0)
  195888. {
  195889. if (((unsigned long*) stateProp)[0] == IconicState)
  195890. minimised = true;
  195891. XFree (stateProp);
  195892. }
  195893. return minimised;
  195894. }
  195895. void setFullScreen (const bool shouldBeFullScreen)
  195896. {
  195897. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195898. setMinimised (false);
  195899. if (fullScreen != shouldBeFullScreen)
  195900. {
  195901. if (shouldBeFullScreen)
  195902. r = Desktop::getInstance().getMainMonitorArea();
  195903. if (! r.isEmpty())
  195904. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195905. getComponent()->repaint();
  195906. }
  195907. }
  195908. bool isFullScreen() const
  195909. {
  195910. return fullScreen;
  195911. }
  195912. bool isChildWindowOf (Window possibleParent) const
  195913. {
  195914. Window* windowList = 0;
  195915. uint32 windowListSize = 0;
  195916. Window parent, root;
  195917. ScopedXLock xlock;
  195918. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195919. {
  195920. if (windowList != 0)
  195921. XFree (windowList);
  195922. return parent == possibleParent;
  195923. }
  195924. return false;
  195925. }
  195926. bool isFrontWindow() const
  195927. {
  195928. Window* windowList = 0;
  195929. uint32 windowListSize = 0;
  195930. bool result = false;
  195931. ScopedXLock xlock;
  195932. Window parent, root = RootWindow (display, DefaultScreen (display));
  195933. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  195934. {
  195935. for (int i = windowListSize; --i >= 0;)
  195936. {
  195937. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  195938. if (peer != 0)
  195939. {
  195940. result = (peer == this);
  195941. break;
  195942. }
  195943. }
  195944. }
  195945. if (windowList != 0)
  195946. XFree (windowList);
  195947. return result;
  195948. }
  195949. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  195950. {
  195951. int x = position.getX();
  195952. int y = position.getY();
  195953. if (((unsigned int) x) >= (unsigned int) ww
  195954. || ((unsigned int) y) >= (unsigned int) wh)
  195955. return false;
  195956. bool inFront = false;
  195957. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  195958. {
  195959. Component* const c = Desktop::getInstance().getComponent (i);
  195960. if (inFront)
  195961. {
  195962. if (c->contains (x + wx - c->getScreenX(),
  195963. y + wy - c->getScreenY()))
  195964. {
  195965. return false;
  195966. }
  195967. }
  195968. else if (c == getComponent())
  195969. {
  195970. inFront = true;
  195971. }
  195972. }
  195973. if (trueIfInAChildWindow)
  195974. return true;
  195975. ::Window root, child;
  195976. unsigned int bw, depth;
  195977. int wx, wy, w, h;
  195978. ScopedXLock xlock;
  195979. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  195980. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  195981. &bw, &depth))
  195982. {
  195983. return false;
  195984. }
  195985. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  195986. return false;
  195987. return child == None;
  195988. }
  195989. const BorderSize getFrameSize() const
  195990. {
  195991. return BorderSize();
  195992. }
  195993. bool setAlwaysOnTop (bool alwaysOnTop)
  195994. {
  195995. if (windowH != 0)
  195996. {
  195997. const bool wasVisible = component->isVisible();
  195998. if (wasVisible)
  195999. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  196000. {
  196001. ScopedXLock xlock;
  196002. XSetWindowAttributes swa;
  196003. swa.override_redirect = alwaysOnTop ? True : False;
  196004. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  196005. }
  196006. if (wasVisible)
  196007. setVisible (true);
  196008. }
  196009. return true;
  196010. }
  196011. void toFront (bool makeActive)
  196012. {
  196013. if (makeActive)
  196014. {
  196015. setVisible (true);
  196016. grabFocus();
  196017. }
  196018. XEvent ev;
  196019. ev.xclient.type = ClientMessage;
  196020. ev.xclient.serial = 0;
  196021. ev.xclient.send_event = True;
  196022. ev.xclient.message_type = Atoms::ActiveWin;
  196023. ev.xclient.window = windowH;
  196024. ev.xclient.format = 32;
  196025. ev.xclient.data.l[0] = 2;
  196026. ev.xclient.data.l[1] = CurrentTime;
  196027. ev.xclient.data.l[2] = 0;
  196028. ev.xclient.data.l[3] = 0;
  196029. ev.xclient.data.l[4] = 0;
  196030. {
  196031. ScopedXLock xlock;
  196032. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  196033. False,
  196034. SubstructureRedirectMask | SubstructureNotifyMask,
  196035. &ev);
  196036. XWindowAttributes attr;
  196037. XGetWindowAttributes (display, windowH, &attr);
  196038. if (attr.override_redirect)
  196039. XRaiseWindow (display, windowH);
  196040. XSync (display, False);
  196041. }
  196042. handleBroughtToFront();
  196043. }
  196044. void toBehind (ComponentPeer* other)
  196045. {
  196046. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196047. jassert (otherPeer != 0); // wrong type of window?
  196048. if (otherPeer != 0)
  196049. {
  196050. setMinimised (false);
  196051. Window newStack[] = { otherPeer->windowH, windowH };
  196052. ScopedXLock xlock;
  196053. XRestackWindows (display, newStack, 2);
  196054. }
  196055. }
  196056. bool isFocused() const
  196057. {
  196058. int revert;
  196059. Window focusedWindow = 0;
  196060. ScopedXLock xlock;
  196061. XGetInputFocus (display, &focusedWindow, &revert);
  196062. return focusedWindow == windowH;
  196063. }
  196064. void grabFocus()
  196065. {
  196066. XWindowAttributes atts;
  196067. ScopedXLock xlock;
  196068. if (windowH != 0
  196069. && XGetWindowAttributes (display, windowH, &atts)
  196070. && atts.map_state == IsViewable
  196071. && ! isFocused())
  196072. {
  196073. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196074. isActiveApplication = true;
  196075. }
  196076. }
  196077. void textInputRequired (const Point<int>&)
  196078. {
  196079. }
  196080. void repaint (int x, int y, int w, int h)
  196081. {
  196082. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  196083. 0, 0,
  196084. getComponent()->getWidth(),
  196085. getComponent()->getHeight()))
  196086. {
  196087. repainter->repaint (x, y, w, h);
  196088. }
  196089. }
  196090. void performAnyPendingRepaintsNow()
  196091. {
  196092. repainter->performAnyPendingRepaintsNow();
  196093. }
  196094. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  196095. {
  196096. ScopedXLock xlock;
  196097. const int width = image.getWidth();
  196098. const int height = image.getHeight();
  196099. HeapBlock <uint32> colour (width * height);
  196100. int index = 0;
  196101. for (int y = 0; y < height; ++y)
  196102. for (int x = 0; x < width; ++x)
  196103. colour[index++] = image.getPixelAt (x, y).getARGB();
  196104. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  196105. 0, reinterpret_cast<char*> (colour.getData()),
  196106. width, height, 32, 0);
  196107. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  196108. width, height, 24);
  196109. GC gc = XCreateGC (display, pixmap, 0, 0);
  196110. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  196111. XFreeGC (display, gc);
  196112. return pixmap;
  196113. }
  196114. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  196115. {
  196116. ScopedXLock xlock;
  196117. const int width = image.getWidth();
  196118. const int height = image.getHeight();
  196119. const int stride = (width + 7) >> 3;
  196120. HeapBlock <uint8> mask;
  196121. mask.calloc (stride * height);
  196122. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  196123. for (int y = 0; y < height; ++y)
  196124. {
  196125. for (int x = 0; x < width; ++x)
  196126. {
  196127. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  196128. const int offset = y * stride + (x >> 3);
  196129. if (image.getPixelAt (x, y).getAlpha() >= 128)
  196130. mask[offset] |= bit;
  196131. }
  196132. }
  196133. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  196134. reinterpret_cast<char*> (mask.getData()), width, height, 1, 0, 1);
  196135. }
  196136. void setIcon (const Image& newIcon)
  196137. {
  196138. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196139. HeapBlock <unsigned long> data (dataSize);
  196140. int index = 0;
  196141. data[index++] = newIcon.getWidth();
  196142. data[index++] = newIcon.getHeight();
  196143. for (int y = 0; y < newIcon.getHeight(); ++y)
  196144. for (int x = 0; x < newIcon.getWidth(); ++x)
  196145. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196146. ScopedXLock xlock;
  196147. XChangeProperty (display, windowH,
  196148. XInternAtom (display, "_NET_WM_ICON", False),
  196149. XA_CARDINAL, 32, PropModeReplace,
  196150. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  196151. deleteIconPixmaps();
  196152. XWMHints* wmHints = XGetWMHints (display, windowH);
  196153. if (wmHints == 0)
  196154. wmHints = XAllocWMHints();
  196155. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196156. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196157. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196158. XSetWMHints (display, windowH, wmHints);
  196159. XFree (wmHints);
  196160. XSync (display, False);
  196161. }
  196162. void deleteIconPixmaps()
  196163. {
  196164. ScopedXLock xlock;
  196165. XWMHints* wmHints = XGetWMHints (display, windowH);
  196166. if (wmHints != 0)
  196167. {
  196168. if ((wmHints->flags & IconPixmapHint) != 0)
  196169. {
  196170. wmHints->flags &= ~IconPixmapHint;
  196171. XFreePixmap (display, wmHints->icon_pixmap);
  196172. }
  196173. if ((wmHints->flags & IconMaskHint) != 0)
  196174. {
  196175. wmHints->flags &= ~IconMaskHint;
  196176. XFreePixmap (display, wmHints->icon_mask);
  196177. }
  196178. XSetWMHints (display, windowH, wmHints);
  196179. XFree (wmHints);
  196180. }
  196181. }
  196182. void handleWindowMessage (XEvent* event)
  196183. {
  196184. switch (event->xany.type)
  196185. {
  196186. case 2: // 'KeyPress'
  196187. {
  196188. ScopedXLock xlock;
  196189. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196190. updateKeyStates (keyEvent->keycode, true);
  196191. char utf8 [64];
  196192. zeromem (utf8, sizeof (utf8));
  196193. KeySym sym;
  196194. {
  196195. const char* oldLocale = ::setlocale (LC_ALL, 0);
  196196. ::setlocale (LC_ALL, "");
  196197. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196198. ::setlocale (LC_ALL, oldLocale);
  196199. }
  196200. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 (utf8, sizeof (utf8) - 1);
  196201. int keyCode = (int) unicodeChar;
  196202. if (keyCode < 0x20)
  196203. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  196204. const ModifierKeys oldMods (currentModifiers);
  196205. bool keyPressed = false;
  196206. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196207. if ((sym & 0xff00) == 0xff00)
  196208. {
  196209. // Translate keypad
  196210. if (sym == XK_KP_Divide)
  196211. keyCode = XK_slash;
  196212. else if (sym == XK_KP_Multiply)
  196213. keyCode = XK_asterisk;
  196214. else if (sym == XK_KP_Subtract)
  196215. keyCode = XK_hyphen;
  196216. else if (sym == XK_KP_Add)
  196217. keyCode = XK_plus;
  196218. else if (sym == XK_KP_Enter)
  196219. keyCode = XK_Return;
  196220. else if (sym == XK_KP_Decimal)
  196221. keyCode = Keys::numLock ? XK_period : XK_Delete;
  196222. else if (sym == XK_KP_0)
  196223. keyCode = Keys::numLock ? XK_0 : XK_Insert;
  196224. else if (sym == XK_KP_1)
  196225. keyCode = Keys::numLock ? XK_1 : XK_End;
  196226. else if (sym == XK_KP_2)
  196227. keyCode = Keys::numLock ? XK_2 : XK_Down;
  196228. else if (sym == XK_KP_3)
  196229. keyCode = Keys::numLock ? XK_3 : XK_Page_Down;
  196230. else if (sym == XK_KP_4)
  196231. keyCode = Keys::numLock ? XK_4 : XK_Left;
  196232. else if (sym == XK_KP_5)
  196233. keyCode = XK_5;
  196234. else if (sym == XK_KP_6)
  196235. keyCode = Keys::numLock ? XK_6 : XK_Right;
  196236. else if (sym == XK_KP_7)
  196237. keyCode = Keys::numLock ? XK_7 : XK_Home;
  196238. else if (sym == XK_KP_8)
  196239. keyCode = Keys::numLock ? XK_8 : XK_Up;
  196240. else if (sym == XK_KP_9)
  196241. keyCode = Keys::numLock ? XK_9 : XK_Page_Up;
  196242. switch (sym)
  196243. {
  196244. case XK_Left:
  196245. case XK_Right:
  196246. case XK_Up:
  196247. case XK_Down:
  196248. case XK_Page_Up:
  196249. case XK_Page_Down:
  196250. case XK_End:
  196251. case XK_Home:
  196252. case XK_Delete:
  196253. case XK_Insert:
  196254. keyPressed = true;
  196255. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196256. break;
  196257. case XK_Tab:
  196258. case XK_Return:
  196259. case XK_Escape:
  196260. case XK_BackSpace:
  196261. keyPressed = true;
  196262. keyCode &= 0xff;
  196263. break;
  196264. default:
  196265. {
  196266. if (sym >= XK_F1 && sym <= XK_F16)
  196267. {
  196268. keyPressed = true;
  196269. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196270. }
  196271. break;
  196272. }
  196273. }
  196274. }
  196275. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196276. keyPressed = true;
  196277. if (oldMods != currentModifiers)
  196278. handleModifierKeysChange();
  196279. if (keyDownChange)
  196280. handleKeyUpOrDown (true);
  196281. if (keyPressed)
  196282. handleKeyPress (keyCode, unicodeChar);
  196283. break;
  196284. }
  196285. case KeyRelease:
  196286. {
  196287. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196288. updateKeyStates (keyEvent->keycode, false);
  196289. ScopedXLock xlock;
  196290. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196291. const ModifierKeys oldMods (currentModifiers);
  196292. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196293. if (oldMods != currentModifiers)
  196294. handleModifierKeysChange();
  196295. if (keyDownChange)
  196296. handleKeyUpOrDown (false);
  196297. break;
  196298. }
  196299. case ButtonPress:
  196300. {
  196301. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196302. updateKeyModifiers (buttonPressEvent->state);
  196303. bool buttonMsg = false;
  196304. const int map = pointerMap [buttonPressEvent->button - Button1];
  196305. if (map == Keys::WheelUp || map == Keys::WheelDown)
  196306. {
  196307. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196308. getEventTime (buttonPressEvent->time), 0, map == Keys::WheelDown ? -84.0f : 84.0f);
  196309. }
  196310. if (map == Keys::LeftButton)
  196311. {
  196312. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196313. buttonMsg = true;
  196314. }
  196315. else if (map == Keys::RightButton)
  196316. {
  196317. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196318. buttonMsg = true;
  196319. }
  196320. else if (map == Keys::MiddleButton)
  196321. {
  196322. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196323. buttonMsg = true;
  196324. }
  196325. if (buttonMsg)
  196326. {
  196327. toFront (true);
  196328. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196329. getEventTime (buttonPressEvent->time));
  196330. }
  196331. clearLastMousePos();
  196332. break;
  196333. }
  196334. case ButtonRelease:
  196335. {
  196336. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196337. updateKeyModifiers (buttonRelEvent->state);
  196338. const int map = pointerMap [buttonRelEvent->button - Button1];
  196339. if (map == Keys::LeftButton)
  196340. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196341. else if (map == Keys::RightButton)
  196342. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196343. else if (map == Keys::MiddleButton)
  196344. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196345. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196346. getEventTime (buttonRelEvent->time));
  196347. clearLastMousePos();
  196348. break;
  196349. }
  196350. case MotionNotify:
  196351. {
  196352. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196353. updateKeyModifiers (movedEvent->state);
  196354. const Point<int> mousePos (Desktop::getMousePosition());
  196355. if (lastMousePos != mousePos)
  196356. {
  196357. lastMousePos = mousePos;
  196358. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196359. {
  196360. Window wRoot = 0, wParent = 0;
  196361. {
  196362. ScopedXLock xlock;
  196363. unsigned int numChildren;
  196364. Window* wChild = 0;
  196365. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196366. }
  196367. if (wParent != 0
  196368. && wParent != windowH
  196369. && wParent != wRoot)
  196370. {
  196371. parentWindow = wParent;
  196372. updateBounds();
  196373. }
  196374. else
  196375. {
  196376. parentWindow = 0;
  196377. }
  196378. }
  196379. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196380. }
  196381. break;
  196382. }
  196383. case EnterNotify:
  196384. {
  196385. clearLastMousePos();
  196386. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196387. if (! currentModifiers.isAnyMouseButtonDown())
  196388. {
  196389. updateKeyModifiers (enterEvent->state);
  196390. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196391. }
  196392. break;
  196393. }
  196394. case LeaveNotify:
  196395. {
  196396. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196397. // Suppress the normal leave if we've got a pointer grab, or if
  196398. // it's a bogus one caused by clicking a mouse button when running
  196399. // in a Window manager
  196400. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196401. || leaveEvent->mode == NotifyUngrab)
  196402. {
  196403. updateKeyModifiers (leaveEvent->state);
  196404. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196405. }
  196406. break;
  196407. }
  196408. case FocusIn:
  196409. {
  196410. isActiveApplication = true;
  196411. if (isFocused())
  196412. handleFocusGain();
  196413. break;
  196414. }
  196415. case FocusOut:
  196416. {
  196417. isActiveApplication = false;
  196418. if (! isFocused())
  196419. handleFocusLoss();
  196420. break;
  196421. }
  196422. case Expose:
  196423. {
  196424. // Batch together all pending expose events
  196425. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196426. XEvent nextEvent;
  196427. ScopedXLock xlock;
  196428. if (exposeEvent->window != windowH)
  196429. {
  196430. Window child;
  196431. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196432. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196433. &child);
  196434. }
  196435. repaint (exposeEvent->x, exposeEvent->y,
  196436. exposeEvent->width, exposeEvent->height);
  196437. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196438. {
  196439. XPeekEvent (display, (XEvent*) &nextEvent);
  196440. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196441. break;
  196442. XNextEvent (display, (XEvent*) &nextEvent);
  196443. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196444. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196445. nextExposeEvent->width, nextExposeEvent->height);
  196446. }
  196447. break;
  196448. }
  196449. case CirculateNotify:
  196450. case CreateNotify:
  196451. case DestroyNotify:
  196452. // Think we can ignore these
  196453. break;
  196454. case ConfigureNotify:
  196455. {
  196456. updateBounds();
  196457. updateBorderSize();
  196458. handleMovedOrResized();
  196459. // if the native title bar is dragged, need to tell any active menus, etc.
  196460. if ((styleFlags & windowHasTitleBar) != 0
  196461. && component->isCurrentlyBlockedByAnotherModalComponent())
  196462. {
  196463. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196464. if (currentModalComp != 0)
  196465. currentModalComp->inputAttemptWhenModal();
  196466. }
  196467. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196468. if (confEvent->window == windowH
  196469. && confEvent->above != 0
  196470. && isFrontWindow())
  196471. {
  196472. handleBroughtToFront();
  196473. }
  196474. break;
  196475. }
  196476. case ReparentNotify:
  196477. case GravityNotify:
  196478. {
  196479. parentWindow = 0;
  196480. Window wRoot = 0;
  196481. Window* wChild = 0;
  196482. unsigned int numChildren;
  196483. {
  196484. ScopedXLock xlock;
  196485. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196486. }
  196487. if (parentWindow == windowH || parentWindow == wRoot)
  196488. parentWindow = 0;
  196489. updateBounds();
  196490. updateBorderSize();
  196491. handleMovedOrResized();
  196492. break;
  196493. }
  196494. case MapNotify:
  196495. mapped = true;
  196496. handleBroughtToFront();
  196497. break;
  196498. case UnmapNotify:
  196499. mapped = false;
  196500. break;
  196501. case MappingNotify:
  196502. {
  196503. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196504. if (mappingEvent->request != MappingPointer)
  196505. {
  196506. // Deal with modifier/keyboard mapping
  196507. ScopedXLock xlock;
  196508. XRefreshKeyboardMapping (mappingEvent);
  196509. updateModifierMappings();
  196510. }
  196511. break;
  196512. }
  196513. case ClientMessage:
  196514. {
  196515. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196516. if (clientMsg->message_type == Atoms::Protocols && clientMsg->format == 32)
  196517. {
  196518. const Atom atom = (Atom) clientMsg->data.l[0];
  196519. if (atom == Atoms::ProtocolList [Atoms::TAKE_FOCUS])
  196520. {
  196521. XWindowAttributes atts;
  196522. ScopedXLock xlock;
  196523. if (clientMsg->window != 0
  196524. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196525. {
  196526. if (atts.map_state == IsViewable)
  196527. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196528. }
  196529. }
  196530. else if (atom == Atoms::ProtocolList [Atoms::DELETE_WINDOW])
  196531. {
  196532. handleUserClosingWindow();
  196533. }
  196534. }
  196535. else if (clientMsg->message_type == Atoms::XdndEnter)
  196536. {
  196537. handleDragAndDropEnter (clientMsg);
  196538. }
  196539. else if (clientMsg->message_type == Atoms::XdndLeave)
  196540. {
  196541. resetDragAndDrop();
  196542. }
  196543. else if (clientMsg->message_type == Atoms::XdndPosition)
  196544. {
  196545. handleDragAndDropPosition (clientMsg);
  196546. }
  196547. else if (clientMsg->message_type == Atoms::XdndDrop)
  196548. {
  196549. handleDragAndDropDrop (clientMsg);
  196550. }
  196551. else if (clientMsg->message_type == Atoms::XdndStatus)
  196552. {
  196553. handleDragAndDropStatus (clientMsg);
  196554. }
  196555. else if (clientMsg->message_type == Atoms::XdndFinished)
  196556. {
  196557. resetDragAndDrop();
  196558. }
  196559. break;
  196560. }
  196561. case SelectionNotify:
  196562. handleDragAndDropSelection (event);
  196563. break;
  196564. case SelectionClear:
  196565. case SelectionRequest:
  196566. break;
  196567. default:
  196568. #if JUCE_USE_XSHM
  196569. {
  196570. ScopedXLock xlock;
  196571. if (event->xany.type == XShmGetEventBase (display))
  196572. repainter->notifyPaintCompleted();
  196573. }
  196574. #endif
  196575. break;
  196576. }
  196577. }
  196578. void showMouseCursor (Cursor cursor) throw()
  196579. {
  196580. ScopedXLock xlock;
  196581. XDefineCursor (display, windowH, cursor);
  196582. }
  196583. void setTaskBarIcon (const Image& image)
  196584. {
  196585. ScopedXLock xlock;
  196586. deleteTaskBarIcon();
  196587. taskbarImage = image.createCopy();
  196588. Screen* const screen = XDefaultScreenOfDisplay (display);
  196589. const int screenNumber = XScreenNumberOfScreen (screen);
  196590. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196591. screenAtom << screenNumber;
  196592. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196593. XGrabServer (display);
  196594. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196595. if (managerWin != None)
  196596. XSelectInput (display, managerWin, StructureNotifyMask);
  196597. XUngrabServer (display);
  196598. XFlush (display);
  196599. if (managerWin != None)
  196600. {
  196601. XEvent ev;
  196602. zerostruct (ev);
  196603. ev.xclient.type = ClientMessage;
  196604. ev.xclient.window = managerWin;
  196605. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196606. ev.xclient.format = 32;
  196607. ev.xclient.data.l[0] = CurrentTime;
  196608. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196609. ev.xclient.data.l[2] = windowH;
  196610. ev.xclient.data.l[3] = 0;
  196611. ev.xclient.data.l[4] = 0;
  196612. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196613. XSync (display, False);
  196614. }
  196615. // For older KDE's ...
  196616. long atomData = 1;
  196617. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196618. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196619. // For more recent KDE's...
  196620. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196621. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196622. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196623. XSizeHints* hints = XAllocSizeHints();
  196624. hints->flags = PMinSize;
  196625. hints->min_width = 22;
  196626. hints->min_height = 22;
  196627. XSetWMNormalHints (display, windowH, hints);
  196628. XFree (hints);
  196629. }
  196630. void deleteTaskBarIcon()
  196631. {
  196632. deleteAndZero (taskbarImage);
  196633. }
  196634. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196635. juce_UseDebuggingNewOperator
  196636. bool dontRepaint;
  196637. static ModifierKeys currentModifiers;
  196638. private:
  196639. class LinuxRepaintManager : public Timer
  196640. {
  196641. public:
  196642. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196643. : peer (peer_),
  196644. lastTimeImageUsed (0)
  196645. {
  196646. #if JUCE_USE_XSHM
  196647. shmCompletedDrawing = true;
  196648. useARGBImagesForRendering = isShmAvailable();
  196649. if (useARGBImagesForRendering)
  196650. {
  196651. ScopedXLock xlock;
  196652. XShmSegmentInfo segmentinfo;
  196653. XImage* const testImage
  196654. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196655. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196656. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196657. XDestroyImage (testImage);
  196658. }
  196659. #endif
  196660. }
  196661. ~LinuxRepaintManager()
  196662. {
  196663. }
  196664. void timerCallback()
  196665. {
  196666. #if JUCE_USE_XSHM
  196667. if (! shmCompletedDrawing)
  196668. return;
  196669. #endif
  196670. if (! regionsNeedingRepaint.isEmpty())
  196671. {
  196672. stopTimer();
  196673. performAnyPendingRepaintsNow();
  196674. }
  196675. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196676. {
  196677. stopTimer();
  196678. image = 0;
  196679. }
  196680. }
  196681. void repaint (int x, int y, int w, int h)
  196682. {
  196683. if (! isTimerRunning())
  196684. startTimer (repaintTimerPeriod);
  196685. regionsNeedingRepaint.add (x, y, w, h);
  196686. }
  196687. void performAnyPendingRepaintsNow()
  196688. {
  196689. #if JUCE_USE_XSHM
  196690. if (! shmCompletedDrawing)
  196691. {
  196692. startTimer (repaintTimerPeriod);
  196693. return;
  196694. }
  196695. #endif
  196696. peer->clearMaskedRegion();
  196697. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196698. regionsNeedingRepaint.clear();
  196699. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196700. if (! totalArea.isEmpty())
  196701. {
  196702. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196703. || image->getHeight() < totalArea.getHeight())
  196704. {
  196705. #if JUCE_USE_XSHM
  196706. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196707. : Image::RGB,
  196708. #else
  196709. image = new XBitmapImage (Image::RGB,
  196710. #endif
  196711. (totalArea.getWidth() + 31) & ~31,
  196712. (totalArea.getHeight() + 31) & ~31,
  196713. false,
  196714. peer->depth,
  196715. peer->visual);
  196716. }
  196717. startTimer (repaintTimerPeriod);
  196718. LowLevelGraphicsSoftwareRenderer context (*image);
  196719. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196720. if (context.clipToRectangleList (originalRepaintRegion))
  196721. {
  196722. if (peer->depth == 32)
  196723. {
  196724. RectangleList::Iterator i (originalRepaintRegion);
  196725. while (i.next())
  196726. {
  196727. const Rectangle<int>& r = *i.getRectangle();
  196728. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196729. }
  196730. }
  196731. peer->handlePaint (context);
  196732. }
  196733. if (! peer->maskedRegion.isEmpty())
  196734. originalRepaintRegion.subtract (peer->maskedRegion);
  196735. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196736. {
  196737. #if JUCE_USE_XSHM
  196738. shmCompletedDrawing = false;
  196739. #endif
  196740. const Rectangle<int>& r = *i.getRectangle();
  196741. image->blitToWindow (peer->windowH,
  196742. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196743. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196744. }
  196745. }
  196746. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196747. startTimer (repaintTimerPeriod);
  196748. }
  196749. #if JUCE_USE_XSHM
  196750. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196751. #endif
  196752. private:
  196753. enum { repaintTimerPeriod = 1000 / 100 };
  196754. LinuxComponentPeer* const peer;
  196755. ScopedPointer <XBitmapImage> image;
  196756. uint32 lastTimeImageUsed;
  196757. RectangleList regionsNeedingRepaint;
  196758. #if JUCE_USE_XSHM
  196759. bool useARGBImagesForRendering, shmCompletedDrawing;
  196760. #endif
  196761. LinuxRepaintManager (const LinuxRepaintManager&);
  196762. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196763. };
  196764. ScopedPointer <LinuxRepaintManager> repainter;
  196765. friend class LinuxRepaintManager;
  196766. Window windowH, parentWindow;
  196767. int wx, wy, ww, wh;
  196768. Image* taskbarImage;
  196769. bool fullScreen, mapped;
  196770. Visual* visual;
  196771. int depth;
  196772. BorderSize windowBorder;
  196773. struct MotifWmHints
  196774. {
  196775. unsigned long flags;
  196776. unsigned long functions;
  196777. unsigned long decorations;
  196778. long input_mode;
  196779. unsigned long status;
  196780. };
  196781. static void updateKeyStates (const int keycode, const bool press) throw()
  196782. {
  196783. const int keybyte = keycode >> 3;
  196784. const int keybit = (1 << (keycode & 7));
  196785. if (press)
  196786. Keys::keyStates [keybyte] |= keybit;
  196787. else
  196788. Keys::keyStates [keybyte] &= ~keybit;
  196789. }
  196790. static void updateKeyModifiers (const int status) throw()
  196791. {
  196792. int keyMods = 0;
  196793. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196794. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196795. if (status & Keys::AltMask) keyMods |= ModifierKeys::altModifier;
  196796. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196797. Keys::numLock = ((status & Keys::NumLockMask) != 0);
  196798. Keys::capsLock = ((status & LockMask) != 0);
  196799. }
  196800. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196801. {
  196802. int modifier = 0;
  196803. bool isModifier = true;
  196804. switch (sym)
  196805. {
  196806. case XK_Shift_L:
  196807. case XK_Shift_R:
  196808. modifier = ModifierKeys::shiftModifier;
  196809. break;
  196810. case XK_Control_L:
  196811. case XK_Control_R:
  196812. modifier = ModifierKeys::ctrlModifier;
  196813. break;
  196814. case XK_Alt_L:
  196815. case XK_Alt_R:
  196816. modifier = ModifierKeys::altModifier;
  196817. break;
  196818. case XK_Num_Lock:
  196819. if (press)
  196820. Keys::numLock = ! Keys::numLock;
  196821. break;
  196822. case XK_Caps_Lock:
  196823. if (press)
  196824. Keys::capsLock = ! Keys::capsLock;
  196825. break;
  196826. case XK_Scroll_Lock:
  196827. break;
  196828. default:
  196829. isModifier = false;
  196830. break;
  196831. }
  196832. if (modifier != 0)
  196833. {
  196834. if (press)
  196835. currentModifiers = currentModifiers.withFlags (modifier);
  196836. else
  196837. currentModifiers = currentModifiers.withoutFlags (modifier);
  196838. }
  196839. return isModifier;
  196840. }
  196841. // Alt and Num lock are not defined by standard X
  196842. // modifier constants: check what they're mapped to
  196843. static void updateModifierMappings() throw()
  196844. {
  196845. ScopedXLock xlock;
  196846. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196847. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196848. Keys::AltMask = 0;
  196849. Keys::NumLockMask = 0;
  196850. XModifierKeymap* mapping = XGetModifierMapping (display);
  196851. if (mapping)
  196852. {
  196853. for (int i = 0; i < 8; i++)
  196854. {
  196855. if (mapping->modifiermap [i << 1] == altLeftCode)
  196856. Keys::AltMask = 1 << i;
  196857. else if (mapping->modifiermap [i << 1] == numLockCode)
  196858. Keys::NumLockMask = 1 << i;
  196859. }
  196860. XFreeModifiermap (mapping);
  196861. }
  196862. }
  196863. void removeWindowDecorations (Window wndH)
  196864. {
  196865. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196866. if (hints != None)
  196867. {
  196868. MotifWmHints motifHints;
  196869. zerostruct (motifHints);
  196870. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196871. motifHints.decorations = 0;
  196872. ScopedXLock xlock;
  196873. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196874. (unsigned char*) &motifHints, 4);
  196875. }
  196876. hints = XInternAtom (display, "_WIN_HINTS", True);
  196877. if (hints != None)
  196878. {
  196879. long gnomeHints = 0;
  196880. ScopedXLock xlock;
  196881. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196882. (unsigned char*) &gnomeHints, 1);
  196883. }
  196884. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196885. if (hints != None)
  196886. {
  196887. long kwmHints = 2; /*KDE_tinyDecoration*/
  196888. ScopedXLock xlock;
  196889. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196890. (unsigned char*) &kwmHints, 1);
  196891. }
  196892. }
  196893. void addWindowButtons (Window wndH)
  196894. {
  196895. ScopedXLock xlock;
  196896. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196897. if (hints != None)
  196898. {
  196899. MotifWmHints motifHints;
  196900. zerostruct (motifHints);
  196901. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196902. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196903. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196904. if ((styleFlags & windowHasCloseButton) != 0)
  196905. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196906. if ((styleFlags & windowHasMinimiseButton) != 0)
  196907. {
  196908. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196909. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196910. }
  196911. if ((styleFlags & windowHasMaximiseButton) != 0)
  196912. {
  196913. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196914. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196915. }
  196916. if ((styleFlags & windowIsResizable) != 0)
  196917. {
  196918. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196919. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  196920. }
  196921. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  196922. }
  196923. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  196924. if (hints != None)
  196925. {
  196926. int netHints [6];
  196927. int num = 0;
  196928. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  196929. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  196930. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  196931. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  196932. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196933. (unsigned char*) &netHints, num);
  196934. }
  196935. }
  196936. void setWindowType (Window wndH)
  196937. {
  196938. int netHints [2];
  196939. int numHints = 0;
  196940. if ((styleFlags & windowIsTemporary) != 0
  196941. || ((styleFlags & windowHasDropShadow) == 0 && Desktop::canUseSemiTransparentWindows()))
  196942. {
  196943. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_COMBO", True);
  196944. }
  196945. else
  196946. {
  196947. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196948. }
  196949. if (netHints [numHints] != 0)
  196950. ++numHints;
  196951. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196952. if (netHints [numHints] != 0)
  196953. ++numHints;
  196954. XChangeProperty (display, wndH, Atoms::WindowType, XA_ATOM, 32, PropModeReplace,
  196955. (unsigned char*) &netHints, numHints);
  196956. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  196957. {
  196958. }
  196959. }
  196960. void createWindow()
  196961. {
  196962. ScopedXLock xlock;
  196963. Atoms::initialiseAtoms();
  196964. resetDragAndDrop();
  196965. // Get defaults for various properties
  196966. const int screen = DefaultScreen (display);
  196967. Window root = RootWindow (display, screen);
  196968. // Try to obtain a 32-bit visual or fallback to 24 or 16
  196969. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  196970. if (visual == 0)
  196971. {
  196972. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  196973. Process::terminate();
  196974. }
  196975. // Create and install a colormap suitable fr our visual
  196976. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  196977. XInstallColormap (display, colormap);
  196978. // Set up the window attributes
  196979. XSetWindowAttributes swa;
  196980. swa.border_pixel = 0;
  196981. swa.background_pixmap = None;
  196982. swa.colormap = colormap;
  196983. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  196984. swa.event_mask = eventMask;
  196985. Window wndH = XCreateWindow (display, root,
  196986. 0, 0, 1, 1,
  196987. 0, depth, InputOutput, visual,
  196988. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  196989. &swa);
  196990. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  196991. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  196992. GrabModeAsync, GrabModeAsync, None, None);
  196993. // Set the window context to identify the window handle object
  196994. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  196995. {
  196996. // Failed
  196997. jassertfalse
  196998. Logger::outputDebugString ("Failed to create context information for window.\n");
  196999. XDestroyWindow (display, wndH);
  197000. wndH = 0;
  197001. }
  197002. // Set window manager hints
  197003. XWMHints* wmHints = XAllocWMHints();
  197004. wmHints->flags = InputHint | StateHint;
  197005. wmHints->input = True; // Locally active input model
  197006. wmHints->initial_state = NormalState;
  197007. XSetWMHints (display, wndH, wmHints);
  197008. XFree (wmHints);
  197009. // Set the window type
  197010. setWindowType (wndH);
  197011. // Define decoration
  197012. if ((styleFlags & windowHasTitleBar) == 0)
  197013. removeWindowDecorations (wndH);
  197014. else
  197015. addWindowButtons (wndH);
  197016. // Set window name
  197017. setWindowTitle (wndH, getComponent()->getName());
  197018. // Associate the PID, allowing to be shut down when something goes wrong
  197019. unsigned long pid = getpid();
  197020. XChangeProperty (display, wndH, Atoms::Pid, XA_CARDINAL, 32, PropModeReplace,
  197021. (unsigned char*) &pid, 1);
  197022. // Set window manager protocols
  197023. XChangeProperty (display, wndH, Atoms::Protocols, XA_ATOM, 32, PropModeReplace,
  197024. (unsigned char*) Atoms::ProtocolList, 2);
  197025. // Set drag and drop flags
  197026. XChangeProperty (display, wndH, Atoms::XdndTypeList, XA_ATOM, 32, PropModeReplace,
  197027. (const unsigned char*) Atoms::allowedMimeTypes, numElementsInArray (Atoms::allowedMimeTypes));
  197028. XChangeProperty (display, wndH, Atoms::XdndActionList, XA_ATOM, 32, PropModeReplace,
  197029. (const unsigned char*) Atoms::allowedActions, numElementsInArray (Atoms::allowedActions));
  197030. XChangeProperty (display, wndH, Atoms::XdndActionDescription, XA_STRING, 8, PropModeReplace,
  197031. (const unsigned char*) "", 0);
  197032. unsigned long dndVersion = Atoms::DndVersion;
  197033. XChangeProperty (display, wndH, Atoms::XdndAware, XA_ATOM, 32, PropModeReplace,
  197034. (const unsigned char*) &dndVersion, 1);
  197035. // Initialise the pointer and keyboard mapping
  197036. // This is not the same as the logical pointer mapping the X server uses:
  197037. // we don't mess with this.
  197038. static bool mappingInitialised = false;
  197039. if (! mappingInitialised)
  197040. {
  197041. mappingInitialised = true;
  197042. const int numButtons = XGetPointerMapping (display, 0, 0);
  197043. if (numButtons == 2)
  197044. {
  197045. pointerMap[0] = Keys::LeftButton;
  197046. pointerMap[1] = Keys::RightButton;
  197047. pointerMap[2] = pointerMap[3] = pointerMap[4] = Keys::NoButton;
  197048. }
  197049. else if (numButtons >= 3)
  197050. {
  197051. pointerMap[0] = Keys::LeftButton;
  197052. pointerMap[1] = Keys::MiddleButton;
  197053. pointerMap[2] = Keys::RightButton;
  197054. if (numButtons >= 5)
  197055. {
  197056. pointerMap[3] = Keys::WheelUp;
  197057. pointerMap[4] = Keys::WheelDown;
  197058. }
  197059. }
  197060. updateModifierMappings();
  197061. }
  197062. windowH = wndH;
  197063. }
  197064. void destroyWindow()
  197065. {
  197066. ScopedXLock xlock;
  197067. XPointer handlePointer;
  197068. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197069. XDeleteContext (display, (XID) windowH, improbableNumber);
  197070. XDestroyWindow (display, windowH);
  197071. // Wait for it to complete and then remove any events for this
  197072. // window from the event queue.
  197073. XSync (display, false);
  197074. XEvent event;
  197075. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197076. {}
  197077. }
  197078. static int64 getEventTime (::Time t)
  197079. {
  197080. static int64 eventTimeOffset = 0x12345678;
  197081. const int64 thisMessageTime = t;
  197082. if (eventTimeOffset == 0x12345678)
  197083. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197084. return eventTimeOffset + thisMessageTime;
  197085. }
  197086. static void setWindowTitle (Window xwin, const String& title)
  197087. {
  197088. XTextProperty nameProperty;
  197089. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  197090. ScopedXLock xlock;
  197091. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197092. {
  197093. XSetWMName (display, xwin, &nameProperty);
  197094. XSetWMIconName (display, xwin, &nameProperty);
  197095. XFree (nameProperty.value);
  197096. }
  197097. }
  197098. void updateBorderSize()
  197099. {
  197100. if ((styleFlags & windowHasTitleBar) == 0)
  197101. {
  197102. windowBorder = BorderSize (0);
  197103. }
  197104. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197105. {
  197106. ScopedXLock xlock;
  197107. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197108. if (hints != None)
  197109. {
  197110. unsigned char* data = 0;
  197111. unsigned long nitems, bytesLeft;
  197112. Atom actualType;
  197113. int actualFormat;
  197114. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197115. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197116. &data) == Success)
  197117. {
  197118. const unsigned long* const sizes = (const unsigned long*) data;
  197119. if (actualFormat == 32)
  197120. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197121. (int) sizes[3], (int) sizes[1]);
  197122. XFree (data);
  197123. }
  197124. }
  197125. }
  197126. }
  197127. void updateBounds()
  197128. {
  197129. jassert (windowH != 0);
  197130. if (windowH != 0)
  197131. {
  197132. Window root, child;
  197133. unsigned int bw, depth;
  197134. ScopedXLock xlock;
  197135. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197136. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197137. &bw, &depth))
  197138. {
  197139. wx = wy = ww = wh = 0;
  197140. }
  197141. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197142. {
  197143. wx = wy = 0;
  197144. }
  197145. }
  197146. }
  197147. void resetDragAndDrop()
  197148. {
  197149. dragAndDropFiles.clear();
  197150. lastDropPos = Point<int> (-1, -1);
  197151. dragAndDropCurrentMimeType = 0;
  197152. dragAndDropSourceWindow = 0;
  197153. srcMimeTypeAtomList.clear();
  197154. }
  197155. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197156. {
  197157. msg.type = ClientMessage;
  197158. msg.display = display;
  197159. msg.window = dragAndDropSourceWindow;
  197160. msg.format = 32;
  197161. msg.data.l[0] = windowH;
  197162. ScopedXLock xlock;
  197163. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197164. }
  197165. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197166. {
  197167. XClientMessageEvent msg;
  197168. zerostruct (msg);
  197169. msg.message_type = Atoms::XdndStatus;
  197170. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197171. msg.data.l[4] = dropAction;
  197172. sendDragAndDropMessage (msg);
  197173. }
  197174. void sendDragAndDropLeave()
  197175. {
  197176. XClientMessageEvent msg;
  197177. zerostruct (msg);
  197178. msg.message_type = Atoms::XdndLeave;
  197179. sendDragAndDropMessage (msg);
  197180. }
  197181. void sendDragAndDropFinish()
  197182. {
  197183. XClientMessageEvent msg;
  197184. zerostruct (msg);
  197185. msg.message_type = Atoms::XdndFinished;
  197186. sendDragAndDropMessage (msg);
  197187. }
  197188. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197189. {
  197190. if ((clientMsg->data.l[1] & 1) == 0)
  197191. {
  197192. sendDragAndDropLeave();
  197193. if (dragAndDropFiles.size() > 0)
  197194. handleFileDragExit (dragAndDropFiles);
  197195. dragAndDropFiles.clear();
  197196. }
  197197. }
  197198. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197199. {
  197200. if (dragAndDropSourceWindow == 0)
  197201. return;
  197202. dragAndDropSourceWindow = clientMsg->data.l[0];
  197203. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  197204. (int) clientMsg->data.l[2] & 0xffff);
  197205. dropPos -= getScreenPosition();
  197206. if (lastDropPos != dropPos)
  197207. {
  197208. lastDropPos = dropPos;
  197209. dragAndDropTimestamp = clientMsg->data.l[3];
  197210. Atom targetAction = Atoms::XdndActionCopy;
  197211. for (int i = numElementsInArray (Atoms::allowedActions); --i >= 0;)
  197212. {
  197213. if ((Atom) clientMsg->data.l[4] == Atoms::allowedActions[i])
  197214. {
  197215. targetAction = Atoms::allowedActions[i];
  197216. break;
  197217. }
  197218. }
  197219. sendDragAndDropStatus (true, targetAction);
  197220. if (dragAndDropFiles.size() == 0)
  197221. updateDraggedFileList (clientMsg);
  197222. if (dragAndDropFiles.size() > 0)
  197223. handleFileDragMove (dragAndDropFiles, dropPos);
  197224. }
  197225. }
  197226. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197227. {
  197228. if (dragAndDropFiles.size() == 0)
  197229. updateDraggedFileList (clientMsg);
  197230. const StringArray files (dragAndDropFiles);
  197231. const Point<int> lastPos (lastDropPos);
  197232. sendDragAndDropFinish();
  197233. resetDragAndDrop();
  197234. if (files.size() > 0)
  197235. handleFileDragDrop (files, lastPos);
  197236. }
  197237. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197238. {
  197239. dragAndDropFiles.clear();
  197240. srcMimeTypeAtomList.clear();
  197241. dragAndDropCurrentMimeType = 0;
  197242. const unsigned long dndCurrentVersion = static_cast <unsigned long> (clientMsg->data.l[1] & 0xff000000) >> 24;
  197243. if (dndCurrentVersion < 3 || dndCurrentVersion > Atoms::DndVersion)
  197244. {
  197245. dragAndDropSourceWindow = 0;
  197246. return;
  197247. }
  197248. dragAndDropSourceWindow = clientMsg->data.l[0];
  197249. if ((clientMsg->data.l[1] & 1) != 0)
  197250. {
  197251. Atom actual;
  197252. int format;
  197253. unsigned long count = 0, remaining = 0;
  197254. unsigned char* data = 0;
  197255. ScopedXLock xlock;
  197256. XGetWindowProperty (display, dragAndDropSourceWindow, Atoms::XdndTypeList,
  197257. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197258. &count, &remaining, &data);
  197259. if (data != 0)
  197260. {
  197261. if (actual == XA_ATOM && format == 32 && count != 0)
  197262. {
  197263. const unsigned long* const types = (const unsigned long*) data;
  197264. for (unsigned int i = 0; i < count; ++i)
  197265. if (types[i] != None)
  197266. srcMimeTypeAtomList.add (types[i]);
  197267. }
  197268. XFree (data);
  197269. }
  197270. }
  197271. if (srcMimeTypeAtomList.size() == 0)
  197272. {
  197273. for (int i = 2; i < 5; ++i)
  197274. if (clientMsg->data.l[i] != None)
  197275. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197276. if (srcMimeTypeAtomList.size() == 0)
  197277. {
  197278. dragAndDropSourceWindow = 0;
  197279. return;
  197280. }
  197281. }
  197282. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197283. for (int j = 0; j < numElementsInArray (Atoms::allowedMimeTypes); ++j)
  197284. if (srcMimeTypeAtomList[i] == Atoms::allowedMimeTypes[j])
  197285. dragAndDropCurrentMimeType = Atoms::allowedMimeTypes[j];
  197286. handleDragAndDropPosition (clientMsg);
  197287. }
  197288. void handleDragAndDropSelection (const XEvent* const evt)
  197289. {
  197290. dragAndDropFiles.clear();
  197291. if (evt->xselection.property != 0)
  197292. {
  197293. StringArray lines;
  197294. {
  197295. MemoryBlock dropData;
  197296. for (;;)
  197297. {
  197298. Atom actual;
  197299. uint8* data = 0;
  197300. unsigned long count = 0, remaining = 0;
  197301. int format = 0;
  197302. ScopedXLock xlock;
  197303. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197304. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197305. &format, &count, &remaining, &data) == Success)
  197306. {
  197307. dropData.append (data, count * format / 8);
  197308. XFree (data);
  197309. if (remaining == 0)
  197310. break;
  197311. }
  197312. else
  197313. {
  197314. XFree (data);
  197315. break;
  197316. }
  197317. }
  197318. lines.addLines (dropData.toString());
  197319. }
  197320. for (int i = 0; i < lines.size(); ++i)
  197321. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197322. dragAndDropFiles.trim();
  197323. dragAndDropFiles.removeEmptyStrings();
  197324. }
  197325. }
  197326. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197327. {
  197328. dragAndDropFiles.clear();
  197329. if (dragAndDropSourceWindow != None
  197330. && dragAndDropCurrentMimeType != 0)
  197331. {
  197332. dragAndDropTimestamp = clientMsg->data.l[2];
  197333. ScopedXLock xlock;
  197334. XConvertSelection (display,
  197335. Atoms::XdndSelection,
  197336. dragAndDropCurrentMimeType,
  197337. XInternAtom (display, "JXSelectionWindowProperty", 0),
  197338. windowH,
  197339. dragAndDropTimestamp);
  197340. }
  197341. }
  197342. StringArray dragAndDropFiles;
  197343. int dragAndDropTimestamp;
  197344. Point<int> lastDropPos;
  197345. Atom dragAndDropCurrentMimeType;
  197346. Window dragAndDropSourceWindow;
  197347. Array <Atom> srcMimeTypeAtomList;
  197348. static int pointerMap[5];
  197349. static Point<int> lastMousePos;
  197350. static void clearLastMousePos() throw()
  197351. {
  197352. lastMousePos = Point<int> (0x100000, 0x100000);
  197353. }
  197354. };
  197355. ModifierKeys LinuxComponentPeer::currentModifiers;
  197356. int LinuxComponentPeer::pointerMap[5];
  197357. Point<int> LinuxComponentPeer::lastMousePos;
  197358. void ModifierKeys::updateCurrentModifiers() throw()
  197359. {
  197360. currentModifiers = LinuxComponentPeer::currentModifiers;
  197361. }
  197362. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197363. {
  197364. Window root, child;
  197365. int x, y, winx, winy;
  197366. unsigned int mask;
  197367. int mouseMods = 0;
  197368. ScopedXLock xlock;
  197369. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197370. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197371. {
  197372. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197373. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197374. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197375. }
  197376. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197377. return LinuxComponentPeer::currentModifiers;
  197378. }
  197379. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197380. {
  197381. if (enableOrDisable)
  197382. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197383. }
  197384. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197385. {
  197386. return new LinuxComponentPeer (this, styleFlags);
  197387. }
  197388. // (this callback is hooked up in the messaging code)
  197389. void juce_windowMessageReceive (XEvent* event)
  197390. {
  197391. if (event->xany.window != None)
  197392. {
  197393. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197394. if (ComponentPeer::isValidPeer (peer))
  197395. peer->handleWindowMessage (event);
  197396. }
  197397. else
  197398. {
  197399. switch (event->xany.type)
  197400. {
  197401. case KeymapNotify:
  197402. {
  197403. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197404. memcpy (Keys::keyStates, keymapEvent->key_vector, 32);
  197405. break;
  197406. }
  197407. default:
  197408. break;
  197409. }
  197410. }
  197411. }
  197412. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197413. {
  197414. if (display == 0)
  197415. return;
  197416. #if JUCE_USE_XINERAMA
  197417. int major_opcode, first_event, first_error;
  197418. ScopedXLock xlock;
  197419. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197420. {
  197421. typedef Bool (*tXineramaIsActive) (Display*);
  197422. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197423. static tXineramaIsActive xXineramaIsActive = 0;
  197424. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197425. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197426. {
  197427. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197428. if (h != 0)
  197429. {
  197430. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197431. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197432. }
  197433. }
  197434. if (xXineramaIsActive != 0
  197435. && xXineramaQueryScreens != 0
  197436. && xXineramaIsActive (display))
  197437. {
  197438. int numMonitors = 0;
  197439. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197440. if (screens != 0)
  197441. {
  197442. for (int i = numMonitors; --i >= 0;)
  197443. {
  197444. int index = screens[i].screen_number;
  197445. if (index >= 0)
  197446. {
  197447. while (monitorCoords.size() < index)
  197448. monitorCoords.add (Rectangle<int>());
  197449. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197450. screens[i].y_org,
  197451. screens[i].width,
  197452. screens[i].height));
  197453. }
  197454. }
  197455. XFree (screens);
  197456. }
  197457. }
  197458. }
  197459. if (monitorCoords.size() == 0)
  197460. #endif
  197461. {
  197462. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197463. if (hints != None)
  197464. {
  197465. const int numMonitors = ScreenCount (display);
  197466. for (int i = 0; i < numMonitors; ++i)
  197467. {
  197468. Window root = RootWindow (display, i);
  197469. unsigned long nitems, bytesLeft;
  197470. Atom actualType;
  197471. int actualFormat;
  197472. unsigned char* data = 0;
  197473. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197474. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197475. &data) == Success)
  197476. {
  197477. const long* const position = (const long*) data;
  197478. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197479. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197480. position[2], position[3]));
  197481. XFree (data);
  197482. }
  197483. }
  197484. }
  197485. if (monitorCoords.size() == 0)
  197486. {
  197487. monitorCoords.add (Rectangle<int> (0, 0,
  197488. DisplayWidth (display, DefaultScreen (display)),
  197489. DisplayHeight (display, DefaultScreen (display))));
  197490. }
  197491. }
  197492. }
  197493. void Desktop::createMouseInputSources()
  197494. {
  197495. mouseSources.add (new MouseInputSource (0, true));
  197496. }
  197497. bool Desktop::canUseSemiTransparentWindows() throw()
  197498. {
  197499. int matchedDepth = 0;
  197500. const int desiredDepth = 32;
  197501. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  197502. && (matchedDepth == desiredDepth);
  197503. }
  197504. const Point<int> Desktop::getMousePosition()
  197505. {
  197506. Window root, child;
  197507. int x, y, winx, winy;
  197508. unsigned int mask;
  197509. ScopedXLock xlock;
  197510. if (XQueryPointer (display,
  197511. RootWindow (display, DefaultScreen (display)),
  197512. &root, &child,
  197513. &x, &y, &winx, &winy, &mask) == False)
  197514. {
  197515. // Pointer not on the default screen
  197516. x = y = -1;
  197517. }
  197518. return Point<int> (x, y);
  197519. }
  197520. void Desktop::setMousePosition (const Point<int>& newPosition)
  197521. {
  197522. ScopedXLock xlock;
  197523. Window root = RootWindow (display, DefaultScreen (display));
  197524. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197525. }
  197526. static bool screenSaverAllowed = true;
  197527. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197528. {
  197529. if (screenSaverAllowed != isEnabled)
  197530. {
  197531. screenSaverAllowed = isEnabled;
  197532. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197533. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197534. if (xScreenSaverSuspend == 0)
  197535. {
  197536. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197537. if (h != 0)
  197538. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197539. }
  197540. ScopedXLock xlock;
  197541. if (xScreenSaverSuspend != 0)
  197542. xScreenSaverSuspend (display, ! isEnabled);
  197543. }
  197544. }
  197545. bool Desktop::isScreenSaverEnabled() throw()
  197546. {
  197547. return screenSaverAllowed;
  197548. }
  197549. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197550. {
  197551. ScopedXLock xlock;
  197552. Window root = RootWindow (display, DefaultScreen (display));
  197553. const unsigned int imageW = image.getWidth();
  197554. const unsigned int imageH = image.getHeight();
  197555. unsigned int cursorW, cursorH;
  197556. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197557. return 0;
  197558. Image im (Image::ARGB, cursorW, cursorH, true);
  197559. Graphics g (im);
  197560. if (imageW > cursorW || imageH > cursorH)
  197561. {
  197562. hotspotX = (hotspotX * cursorW) / imageW;
  197563. hotspotY = (hotspotY * cursorH) / imageH;
  197564. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197565. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197566. false);
  197567. }
  197568. else
  197569. {
  197570. g.drawImageAt (&image, 0, 0);
  197571. }
  197572. const int stride = (cursorW + 7) >> 3;
  197573. HeapBlock <uint8> maskPlane, sourcePlane;
  197574. maskPlane.calloc (stride * cursorH);
  197575. sourcePlane.calloc (stride * cursorH);
  197576. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197577. for (int y = cursorH; --y >= 0;)
  197578. {
  197579. for (int x = cursorW; --x >= 0;)
  197580. {
  197581. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197582. const int offset = y * stride + (x >> 3);
  197583. const Colour c (im.getPixelAt (x, y));
  197584. if (c.getAlpha() >= 128)
  197585. maskPlane[offset] |= mask;
  197586. if (c.getBrightness() >= 0.5f)
  197587. sourcePlane[offset] |= mask;
  197588. }
  197589. }
  197590. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (sourcePlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197591. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (maskPlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197592. XColor white, black;
  197593. black.red = black.green = black.blue = 0;
  197594. white.red = white.green = white.blue = 0xffff;
  197595. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197596. XFreePixmap (display, sourcePixmap);
  197597. XFreePixmap (display, maskPixmap);
  197598. return result;
  197599. }
  197600. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197601. {
  197602. ScopedXLock xlock;
  197603. if (cursorHandle != None)
  197604. XFreeCursor (display, (Cursor) cursorHandle);
  197605. }
  197606. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197607. {
  197608. unsigned int shape;
  197609. switch (type)
  197610. {
  197611. case MouseCursor::NoCursor:
  197612. {
  197613. const Image im (Image::ARGB, 16, 16, true);
  197614. return juce_createMouseCursorFromImage (im, 0, 0);
  197615. }
  197616. case MouseCursor::NormalCursor:
  197617. return (void*) None; // Use parent cursor
  197618. case MouseCursor::DraggingHandCursor:
  197619. {
  197620. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197621. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197622. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197623. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197624. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197625. const int dragHandDataSize = 99;
  197626. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197627. return juce_createMouseCursorFromImage (*im, 8, 7);
  197628. }
  197629. case MouseCursor::CopyingCursor:
  197630. {
  197631. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197632. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197633. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197634. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197635. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197636. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197637. const int copyCursorSize = 119;
  197638. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197639. return juce_createMouseCursorFromImage (*im, 1, 3);
  197640. }
  197641. case MouseCursor::WaitCursor:
  197642. shape = XC_watch;
  197643. break;
  197644. case MouseCursor::IBeamCursor:
  197645. shape = XC_xterm;
  197646. break;
  197647. case MouseCursor::PointingHandCursor:
  197648. shape = XC_hand2;
  197649. break;
  197650. case MouseCursor::LeftRightResizeCursor:
  197651. shape = XC_sb_h_double_arrow;
  197652. break;
  197653. case MouseCursor::UpDownResizeCursor:
  197654. shape = XC_sb_v_double_arrow;
  197655. break;
  197656. case MouseCursor::UpDownLeftRightResizeCursor:
  197657. shape = XC_fleur;
  197658. break;
  197659. case MouseCursor::TopEdgeResizeCursor:
  197660. shape = XC_top_side;
  197661. break;
  197662. case MouseCursor::BottomEdgeResizeCursor:
  197663. shape = XC_bottom_side;
  197664. break;
  197665. case MouseCursor::LeftEdgeResizeCursor:
  197666. shape = XC_left_side;
  197667. break;
  197668. case MouseCursor::RightEdgeResizeCursor:
  197669. shape = XC_right_side;
  197670. break;
  197671. case MouseCursor::TopLeftCornerResizeCursor:
  197672. shape = XC_top_left_corner;
  197673. break;
  197674. case MouseCursor::TopRightCornerResizeCursor:
  197675. shape = XC_top_right_corner;
  197676. break;
  197677. case MouseCursor::BottomLeftCornerResizeCursor:
  197678. shape = XC_bottom_left_corner;
  197679. break;
  197680. case MouseCursor::BottomRightCornerResizeCursor:
  197681. shape = XC_bottom_right_corner;
  197682. break;
  197683. case MouseCursor::CrosshairCursor:
  197684. shape = XC_crosshair;
  197685. break;
  197686. default:
  197687. return (void*) None; // Use parent cursor
  197688. }
  197689. ScopedXLock xlock;
  197690. return (void*) XCreateFontCursor (display, shape);
  197691. }
  197692. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197693. {
  197694. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197695. if (lp != 0)
  197696. lp->showMouseCursor ((Cursor) getHandle());
  197697. }
  197698. void MouseCursor::showInAllWindows() const throw()
  197699. {
  197700. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197701. showInWindow (ComponentPeer::getPeer (i));
  197702. }
  197703. Image* juce_createIconForFile (const File& file)
  197704. {
  197705. return 0;
  197706. }
  197707. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197708. {
  197709. return new Image (format, imageWidth, imageHeight, clearImage);
  197710. }
  197711. #if JUCE_OPENGL
  197712. class WindowedGLContext : public OpenGLContext
  197713. {
  197714. public:
  197715. WindowedGLContext (Component* const component,
  197716. const OpenGLPixelFormat& pixelFormat_,
  197717. GLXContext sharedContext)
  197718. : renderContext (0),
  197719. embeddedWindow (0),
  197720. pixelFormat (pixelFormat_)
  197721. {
  197722. jassert (component != 0);
  197723. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197724. if (peer == 0)
  197725. return;
  197726. ScopedXLock xlock;
  197727. XSync (display, False);
  197728. GLint attribs [64];
  197729. int n = 0;
  197730. attribs[n++] = GLX_RGBA;
  197731. attribs[n++] = GLX_DOUBLEBUFFER;
  197732. attribs[n++] = GLX_RED_SIZE;
  197733. attribs[n++] = pixelFormat.redBits;
  197734. attribs[n++] = GLX_GREEN_SIZE;
  197735. attribs[n++] = pixelFormat.greenBits;
  197736. attribs[n++] = GLX_BLUE_SIZE;
  197737. attribs[n++] = pixelFormat.blueBits;
  197738. attribs[n++] = GLX_ALPHA_SIZE;
  197739. attribs[n++] = pixelFormat.alphaBits;
  197740. attribs[n++] = GLX_DEPTH_SIZE;
  197741. attribs[n++] = pixelFormat.depthBufferBits;
  197742. attribs[n++] = GLX_STENCIL_SIZE;
  197743. attribs[n++] = pixelFormat.stencilBufferBits;
  197744. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197745. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197746. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197747. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197748. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197749. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197750. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197751. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197752. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197753. attribs[n++] = None;
  197754. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197755. if (bestVisual == 0)
  197756. return;
  197757. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197758. Window windowH = (Window) peer->getNativeHandle();
  197759. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197760. XSetWindowAttributes swa;
  197761. swa.colormap = colourMap;
  197762. swa.border_pixel = 0;
  197763. swa.event_mask = ExposureMask | StructureNotifyMask;
  197764. embeddedWindow = XCreateWindow (display, windowH,
  197765. 0, 0, 1, 1, 0,
  197766. bestVisual->depth,
  197767. InputOutput,
  197768. bestVisual->visual,
  197769. CWBorderPixel | CWColormap | CWEventMask,
  197770. &swa);
  197771. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197772. XMapWindow (display, embeddedWindow);
  197773. XFreeColormap (display, colourMap);
  197774. XFree (bestVisual);
  197775. XSync (display, False);
  197776. }
  197777. ~WindowedGLContext()
  197778. {
  197779. makeInactive();
  197780. ScopedXLock xlock;
  197781. glXDestroyContext (display, renderContext);
  197782. XUnmapWindow (display, embeddedWindow);
  197783. XDestroyWindow (display, embeddedWindow);
  197784. }
  197785. bool makeActive() const throw()
  197786. {
  197787. jassert (renderContext != 0);
  197788. ScopedXLock xlock;
  197789. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197790. && XSync (display, False);
  197791. }
  197792. bool makeInactive() const throw()
  197793. {
  197794. ScopedXLock xlock;
  197795. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197796. }
  197797. bool isActive() const throw()
  197798. {
  197799. ScopedXLock xlock;
  197800. return glXGetCurrentContext() == renderContext;
  197801. }
  197802. const OpenGLPixelFormat getPixelFormat() const
  197803. {
  197804. return pixelFormat;
  197805. }
  197806. void* getRawContext() const throw()
  197807. {
  197808. return renderContext;
  197809. }
  197810. void updateWindowPosition (int x, int y, int w, int h, int)
  197811. {
  197812. ScopedXLock xlock;
  197813. XMoveResizeWindow (display, embeddedWindow,
  197814. x, y, jmax (1, w), jmax (1, h));
  197815. }
  197816. void swapBuffers()
  197817. {
  197818. ScopedXLock xlock;
  197819. glXSwapBuffers (display, embeddedWindow);
  197820. }
  197821. bool setSwapInterval (const int numFramesPerSwap)
  197822. {
  197823. // xxx needs doing..
  197824. return false;
  197825. }
  197826. int getSwapInterval() const
  197827. {
  197828. // xxx needs doing..
  197829. return 0;
  197830. }
  197831. void repaint()
  197832. {
  197833. }
  197834. juce_UseDebuggingNewOperator
  197835. GLXContext renderContext;
  197836. private:
  197837. Window embeddedWindow;
  197838. OpenGLPixelFormat pixelFormat;
  197839. WindowedGLContext (const WindowedGLContext&);
  197840. WindowedGLContext& operator= (const WindowedGLContext&);
  197841. };
  197842. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  197843. const OpenGLPixelFormat& pixelFormat,
  197844. const OpenGLContext* const contextToShareWith)
  197845. {
  197846. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  197847. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  197848. if (c->renderContext == 0)
  197849. deleteAndZero (c);
  197850. return c;
  197851. }
  197852. void juce_glViewport (const int w, const int h)
  197853. {
  197854. glViewport (0, 0, w, h);
  197855. }
  197856. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197857. OwnedArray <OpenGLPixelFormat>& results)
  197858. {
  197859. results.add (new OpenGLPixelFormat()); // xxx
  197860. }
  197861. #endif
  197862. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197863. {
  197864. jassertfalse // not implemented!
  197865. return false;
  197866. }
  197867. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197868. {
  197869. jassertfalse // not implemented!
  197870. return false;
  197871. }
  197872. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197873. {
  197874. if (! isOnDesktop ())
  197875. addToDesktop (0);
  197876. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197877. if (wp != 0)
  197878. {
  197879. wp->setTaskBarIcon (newImage);
  197880. setVisible (true);
  197881. toFront (false);
  197882. repaint();
  197883. }
  197884. }
  197885. void SystemTrayIconComponent::paint (Graphics& g)
  197886. {
  197887. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197888. if (wp != 0)
  197889. {
  197890. const Image* const image = wp->getTaskbarIcon();
  197891. if (image != 0)
  197892. {
  197893. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197894. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197895. false);
  197896. }
  197897. }
  197898. }
  197899. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197900. {
  197901. // xxx not yet implemented!
  197902. }
  197903. void PlatformUtilities::beep()
  197904. {
  197905. std::cout << "\a" << std::flush;
  197906. }
  197907. bool AlertWindow::showNativeDialogBox (const String& title,
  197908. const String& bodyText,
  197909. bool isOkCancel)
  197910. {
  197911. // use a non-native one for the time being..
  197912. if (isOkCancel)
  197913. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  197914. else
  197915. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  197916. return true;
  197917. }
  197918. const int KeyPress::spaceKey = XK_space & 0xff;
  197919. const int KeyPress::returnKey = XK_Return & 0xff;
  197920. const int KeyPress::escapeKey = XK_Escape & 0xff;
  197921. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  197922. const int KeyPress::leftKey = (XK_Left & 0xff) | Keys::extendedKeyModifier;
  197923. const int KeyPress::rightKey = (XK_Right & 0xff) | Keys::extendedKeyModifier;
  197924. const int KeyPress::upKey = (XK_Up & 0xff) | Keys::extendedKeyModifier;
  197925. const int KeyPress::downKey = (XK_Down & 0xff) | Keys::extendedKeyModifier;
  197926. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | Keys::extendedKeyModifier;
  197927. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | Keys::extendedKeyModifier;
  197928. const int KeyPress::endKey = (XK_End & 0xff) | Keys::extendedKeyModifier;
  197929. const int KeyPress::homeKey = (XK_Home & 0xff) | Keys::extendedKeyModifier;
  197930. const int KeyPress::insertKey = (XK_Insert & 0xff) | Keys::extendedKeyModifier;
  197931. const int KeyPress::deleteKey = (XK_Delete & 0xff) | Keys::extendedKeyModifier;
  197932. const int KeyPress::tabKey = XK_Tab & 0xff;
  197933. const int KeyPress::F1Key = (XK_F1 & 0xff) | Keys::extendedKeyModifier;
  197934. const int KeyPress::F2Key = (XK_F2 & 0xff) | Keys::extendedKeyModifier;
  197935. const int KeyPress::F3Key = (XK_F3 & 0xff) | Keys::extendedKeyModifier;
  197936. const int KeyPress::F4Key = (XK_F4 & 0xff) | Keys::extendedKeyModifier;
  197937. const int KeyPress::F5Key = (XK_F5 & 0xff) | Keys::extendedKeyModifier;
  197938. const int KeyPress::F6Key = (XK_F6 & 0xff) | Keys::extendedKeyModifier;
  197939. const int KeyPress::F7Key = (XK_F7 & 0xff) | Keys::extendedKeyModifier;
  197940. const int KeyPress::F8Key = (XK_F8 & 0xff) | Keys::extendedKeyModifier;
  197941. const int KeyPress::F9Key = (XK_F9 & 0xff) | Keys::extendedKeyModifier;
  197942. const int KeyPress::F10Key = (XK_F10 & 0xff) | Keys::extendedKeyModifier;
  197943. const int KeyPress::F11Key = (XK_F11 & 0xff) | Keys::extendedKeyModifier;
  197944. const int KeyPress::F12Key = (XK_F12 & 0xff) | Keys::extendedKeyModifier;
  197945. const int KeyPress::F13Key = (XK_F13 & 0xff) | Keys::extendedKeyModifier;
  197946. const int KeyPress::F14Key = (XK_F14 & 0xff) | Keys::extendedKeyModifier;
  197947. const int KeyPress::F15Key = (XK_F15 & 0xff) | Keys::extendedKeyModifier;
  197948. const int KeyPress::F16Key = (XK_F16 & 0xff) | Keys::extendedKeyModifier;
  197949. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | Keys::extendedKeyModifier;
  197950. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | Keys::extendedKeyModifier;
  197951. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | Keys::extendedKeyModifier;
  197952. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | Keys::extendedKeyModifier;
  197953. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | Keys::extendedKeyModifier;
  197954. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | Keys::extendedKeyModifier;
  197955. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | Keys::extendedKeyModifier;
  197956. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| Keys::extendedKeyModifier;
  197957. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| Keys::extendedKeyModifier;
  197958. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| Keys::extendedKeyModifier;
  197959. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| Keys::extendedKeyModifier;
  197960. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| Keys::extendedKeyModifier;
  197961. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| Keys::extendedKeyModifier;
  197962. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| Keys::extendedKeyModifier;
  197963. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::extendedKeyModifier;
  197964. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
  197965. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
  197966. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
  197967. const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
  197968. const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
  197969. const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
  197970. const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
  197971. #endif
  197972. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  197973. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  197974. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  197975. // compiled on its own).
  197976. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  197977. static const int maxNumChans = 64;
  197978. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  197979. {
  197980. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  197981. snd_pcm_hw_params_t* hwParams;
  197982. snd_pcm_hw_params_alloca (&hwParams);
  197983. for (int i = 0; ratesToTry[i] != 0; ++i)
  197984. {
  197985. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  197986. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  197987. {
  197988. rates.addIfNotAlreadyThere (ratesToTry[i]);
  197989. }
  197990. }
  197991. }
  197992. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  197993. {
  197994. snd_pcm_hw_params_t *params;
  197995. snd_pcm_hw_params_alloca (&params);
  197996. if (snd_pcm_hw_params_any (handle, params) >= 0)
  197997. {
  197998. snd_pcm_hw_params_get_channels_min (params, minChans);
  197999. snd_pcm_hw_params_get_channels_max (params, maxChans);
  198000. }
  198001. }
  198002. static void getDeviceProperties (const String& deviceID,
  198003. unsigned int& minChansOut,
  198004. unsigned int& maxChansOut,
  198005. unsigned int& minChansIn,
  198006. unsigned int& maxChansIn,
  198007. Array <int>& rates)
  198008. {
  198009. if (deviceID.isEmpty())
  198010. return;
  198011. snd_ctl_t* handle;
  198012. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (T(","), false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198013. {
  198014. snd_pcm_info_t* info;
  198015. snd_pcm_info_alloca (&info);
  198016. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  198017. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  198018. snd_pcm_info_set_subdevice (info, 0);
  198019. if (snd_ctl_pcm_info (handle, info) >= 0)
  198020. {
  198021. snd_pcm_t* pcmHandle;
  198022. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198023. {
  198024. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  198025. getDeviceSampleRates (pcmHandle, rates);
  198026. snd_pcm_close (pcmHandle);
  198027. }
  198028. }
  198029. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  198030. if (snd_ctl_pcm_info (handle, info) >= 0)
  198031. {
  198032. snd_pcm_t* pcmHandle;
  198033. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198034. {
  198035. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  198036. if (rates.size() == 0)
  198037. getDeviceSampleRates (pcmHandle, rates);
  198038. snd_pcm_close (pcmHandle);
  198039. }
  198040. }
  198041. snd_ctl_close (handle);
  198042. }
  198043. }
  198044. class ALSADevice
  198045. {
  198046. public:
  198047. ALSADevice (const String& deviceID,
  198048. const bool forInput)
  198049. : handle (0),
  198050. bitDepth (16),
  198051. numChannelsRunning (0),
  198052. isInput (forInput),
  198053. sampleFormat (AudioDataConverters::int16LE)
  198054. {
  198055. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  198056. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198057. SND_PCM_ASYNC));
  198058. }
  198059. ~ALSADevice()
  198060. {
  198061. if (handle != 0)
  198062. snd_pcm_close (handle);
  198063. }
  198064. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198065. {
  198066. if (handle == 0)
  198067. return false;
  198068. snd_pcm_hw_params_t* hwParams;
  198069. snd_pcm_hw_params_alloca (&hwParams);
  198070. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198071. return false;
  198072. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198073. isInterleaved = false;
  198074. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198075. isInterleaved = true;
  198076. else
  198077. {
  198078. jassertfalse
  198079. return false;
  198080. }
  198081. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198082. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198083. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198084. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198085. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198086. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198087. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198088. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198089. bitDepth = 0;
  198090. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198091. {
  198092. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198093. {
  198094. bitDepth = formatsToTry [i + 1];
  198095. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198096. break;
  198097. }
  198098. }
  198099. if (bitDepth == 0)
  198100. {
  198101. error = "device doesn't support a compatible PCM format";
  198102. DBG (T("ALSA error: ") + error + T("\n"));
  198103. return false;
  198104. }
  198105. int dir = 0;
  198106. unsigned int periods = 4;
  198107. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198108. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198109. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198110. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198111. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198112. || failed (snd_pcm_hw_params (handle, hwParams)))
  198113. {
  198114. return false;
  198115. }
  198116. snd_pcm_sw_params_t* swParams;
  198117. snd_pcm_sw_params_alloca (&swParams);
  198118. snd_pcm_uframes_t boundary;
  198119. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198120. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198121. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198122. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198123. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198124. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198125. || failed (snd_pcm_sw_params (handle, swParams)))
  198126. {
  198127. return false;
  198128. }
  198129. numChannelsRunning = numChannels;
  198130. return true;
  198131. }
  198132. bool write (float** const data, const int numSamples)
  198133. {
  198134. if (isInterleaved)
  198135. {
  198136. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198137. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  198138. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198139. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198140. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198141. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198142. return false;
  198143. }
  198144. else
  198145. {
  198146. for (int i = 0; i < numChannelsRunning; ++i)
  198147. if (data[i] != 0)
  198148. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198149. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198150. if (failed (num))
  198151. {
  198152. if (num == -EPIPE)
  198153. {
  198154. if (failed (snd_pcm_prepare (handle)))
  198155. return false;
  198156. }
  198157. else if (num != -ESTRPIPE)
  198158. return false;
  198159. }
  198160. }
  198161. return true;
  198162. }
  198163. bool read (float** const data, const int numSamples)
  198164. {
  198165. if (isInterleaved)
  198166. {
  198167. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198168. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  198169. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198170. if (failed (num))
  198171. {
  198172. if (num == -EPIPE)
  198173. {
  198174. if (failed (snd_pcm_prepare (handle)))
  198175. return false;
  198176. }
  198177. else if (num != -ESTRPIPE)
  198178. return false;
  198179. }
  198180. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198181. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198182. }
  198183. else
  198184. {
  198185. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198186. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198187. return false;
  198188. for (int i = 0; i < numChannelsRunning; ++i)
  198189. if (data[i] != 0)
  198190. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198191. }
  198192. return true;
  198193. }
  198194. juce_UseDebuggingNewOperator
  198195. snd_pcm_t* handle;
  198196. String error;
  198197. int bitDepth, numChannelsRunning;
  198198. private:
  198199. const bool isInput;
  198200. bool isInterleaved;
  198201. MemoryBlock scratch;
  198202. AudioDataConverters::DataFormat sampleFormat;
  198203. bool failed (const int errorNum)
  198204. {
  198205. if (errorNum >= 0)
  198206. return false;
  198207. error = snd_strerror (errorNum);
  198208. DBG (T("ALSA error: ") + error + T("\n"));
  198209. return true;
  198210. }
  198211. };
  198212. class ALSAThread : public Thread
  198213. {
  198214. public:
  198215. ALSAThread (const String& inputId_,
  198216. const String& outputId_)
  198217. : Thread ("Juce ALSA"),
  198218. sampleRate (0),
  198219. bufferSize (0),
  198220. callback (0),
  198221. inputId (inputId_),
  198222. outputId (outputId_),
  198223. outputDevice (0),
  198224. inputDevice (0),
  198225. numCallbacks (0),
  198226. totalNumInputChannels (0),
  198227. totalNumOutputChannels (0)
  198228. {
  198229. zeromem (outputChannelData, sizeof (outputChannelData));
  198230. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198231. zeromem (inputChannelData, sizeof (inputChannelData));
  198232. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198233. initialiseRatesAndChannels();
  198234. }
  198235. ~ALSAThread()
  198236. {
  198237. close();
  198238. }
  198239. void open (BitArray inputChannels,
  198240. BitArray outputChannels,
  198241. const double sampleRate_,
  198242. const int bufferSize_)
  198243. {
  198244. close();
  198245. error = String::empty;
  198246. sampleRate = sampleRate_;
  198247. bufferSize = bufferSize_;
  198248. currentInputChans.clear();
  198249. currentOutputChans.clear();
  198250. if (inputChannels.getHighestBit() >= 0)
  198251. {
  198252. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198253. {
  198254. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198255. if (inputChannels[i])
  198256. {
  198257. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198258. currentInputChans.setBit (i);
  198259. }
  198260. }
  198261. }
  198262. if (outputChannels.getHighestBit() >= 0)
  198263. {
  198264. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198265. {
  198266. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198267. if (outputChannels[i])
  198268. {
  198269. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198270. currentOutputChans.setBit (i);
  198271. }
  198272. }
  198273. }
  198274. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198275. {
  198276. outputDevice = new ALSADevice (outputId, false);
  198277. if (outputDevice->error.isNotEmpty())
  198278. {
  198279. error = outputDevice->error;
  198280. deleteAndZero (outputDevice);
  198281. return;
  198282. }
  198283. currentOutputChans.setRange (0, minChansOut, true);
  198284. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198285. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198286. bufferSize))
  198287. {
  198288. error = outputDevice->error;
  198289. deleteAndZero (outputDevice);
  198290. return;
  198291. }
  198292. }
  198293. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198294. {
  198295. inputDevice = new ALSADevice (inputId, true);
  198296. if (inputDevice->error.isNotEmpty())
  198297. {
  198298. error = inputDevice->error;
  198299. deleteAndZero (inputDevice);
  198300. return;
  198301. }
  198302. currentInputChans.setRange (0, minChansIn, true);
  198303. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198304. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198305. bufferSize))
  198306. {
  198307. error = inputDevice->error;
  198308. deleteAndZero (inputDevice);
  198309. return;
  198310. }
  198311. }
  198312. if (outputDevice == 0 && inputDevice == 0)
  198313. {
  198314. error = "no channels";
  198315. return;
  198316. }
  198317. if (outputDevice != 0 && inputDevice != 0)
  198318. {
  198319. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198320. }
  198321. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198322. return;
  198323. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198324. return;
  198325. startThread (9);
  198326. int count = 1000;
  198327. while (numCallbacks == 0)
  198328. {
  198329. sleep (5);
  198330. if (--count < 0 || ! isThreadRunning())
  198331. {
  198332. error = "device didn't start";
  198333. break;
  198334. }
  198335. }
  198336. }
  198337. void close()
  198338. {
  198339. stopThread (6000);
  198340. deleteAndZero (inputDevice);
  198341. deleteAndZero (outputDevice);
  198342. for (int i = 0; i < maxNumChans; ++i)
  198343. {
  198344. juce_free (inputChannelData [i]);
  198345. juce_free (outputChannelData [i]);
  198346. }
  198347. zeromem (outputChannelData, sizeof (outputChannelData));
  198348. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198349. zeromem (inputChannelData, sizeof (inputChannelData));
  198350. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198351. totalNumOutputChannels = 0;
  198352. totalNumInputChannels = 0;
  198353. numCallbacks = 0;
  198354. }
  198355. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198356. {
  198357. const ScopedLock sl (callbackLock);
  198358. callback = newCallback;
  198359. }
  198360. void run()
  198361. {
  198362. while (! threadShouldExit())
  198363. {
  198364. if (inputDevice != 0)
  198365. {
  198366. if (! inputDevice->read (inputChannelData, bufferSize))
  198367. {
  198368. DBG ("ALSA: read failure");
  198369. break;
  198370. }
  198371. }
  198372. if (threadShouldExit())
  198373. break;
  198374. {
  198375. const ScopedLock sl (callbackLock);
  198376. ++numCallbacks;
  198377. if (callback != 0)
  198378. {
  198379. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198380. totalNumInputChannels,
  198381. outputChannelDataForCallback,
  198382. totalNumOutputChannels,
  198383. bufferSize);
  198384. }
  198385. else
  198386. {
  198387. for (int i = 0; i < totalNumOutputChannels; ++i)
  198388. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198389. }
  198390. }
  198391. if (outputDevice != 0)
  198392. {
  198393. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198394. if (threadShouldExit())
  198395. break;
  198396. failed (snd_pcm_avail_update (outputDevice->handle));
  198397. if (! outputDevice->write (outputChannelData, bufferSize))
  198398. {
  198399. DBG ("ALSA: write failure");
  198400. break;
  198401. }
  198402. }
  198403. }
  198404. }
  198405. int getBitDepth() const throw()
  198406. {
  198407. if (outputDevice != 0)
  198408. return outputDevice->bitDepth;
  198409. if (inputDevice != 0)
  198410. return inputDevice->bitDepth;
  198411. return 16;
  198412. }
  198413. juce_UseDebuggingNewOperator
  198414. String error;
  198415. double sampleRate;
  198416. int bufferSize;
  198417. BitArray currentInputChans, currentOutputChans;
  198418. Array <int> sampleRates;
  198419. StringArray channelNamesOut, channelNamesIn;
  198420. AudioIODeviceCallback* callback;
  198421. private:
  198422. const String inputId, outputId;
  198423. ALSADevice* outputDevice;
  198424. ALSADevice* inputDevice;
  198425. int numCallbacks;
  198426. CriticalSection callbackLock;
  198427. float* outputChannelData [maxNumChans];
  198428. float* outputChannelDataForCallback [maxNumChans];
  198429. int totalNumInputChannels;
  198430. float* inputChannelData [maxNumChans];
  198431. float* inputChannelDataForCallback [maxNumChans];
  198432. int totalNumOutputChannels;
  198433. unsigned int minChansOut, maxChansOut;
  198434. unsigned int minChansIn, maxChansIn;
  198435. bool failed (const int errorNum) throw()
  198436. {
  198437. if (errorNum >= 0)
  198438. return false;
  198439. error = snd_strerror (errorNum);
  198440. DBG (T("ALSA error: ") + error + T("\n"));
  198441. return true;
  198442. }
  198443. void initialiseRatesAndChannels() throw()
  198444. {
  198445. sampleRates.clear();
  198446. channelNamesOut.clear();
  198447. channelNamesIn.clear();
  198448. minChansOut = 0;
  198449. maxChansOut = 0;
  198450. minChansIn = 0;
  198451. maxChansIn = 0;
  198452. unsigned int dummy = 0;
  198453. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198454. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198455. unsigned int i;
  198456. for (i = 0; i < maxChansOut; ++i)
  198457. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198458. for (i = 0; i < maxChansIn; ++i)
  198459. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198460. }
  198461. };
  198462. class ALSAAudioIODevice : public AudioIODevice
  198463. {
  198464. public:
  198465. ALSAAudioIODevice (const String& deviceName,
  198466. const String& inputId_,
  198467. const String& outputId_)
  198468. : AudioIODevice (deviceName, T("ALSA")),
  198469. inputId (inputId_),
  198470. outputId (outputId_),
  198471. isOpen_ (false),
  198472. isStarted (false),
  198473. internal (0)
  198474. {
  198475. internal = new ALSAThread (inputId, outputId);
  198476. }
  198477. ~ALSAAudioIODevice()
  198478. {
  198479. delete internal;
  198480. }
  198481. const StringArray getOutputChannelNames()
  198482. {
  198483. return internal->channelNamesOut;
  198484. }
  198485. const StringArray getInputChannelNames()
  198486. {
  198487. return internal->channelNamesIn;
  198488. }
  198489. int getNumSampleRates()
  198490. {
  198491. return internal->sampleRates.size();
  198492. }
  198493. double getSampleRate (int index)
  198494. {
  198495. return internal->sampleRates [index];
  198496. }
  198497. int getNumBufferSizesAvailable()
  198498. {
  198499. return 50;
  198500. }
  198501. int getBufferSizeSamples (int index)
  198502. {
  198503. int n = 16;
  198504. for (int i = 0; i < index; ++i)
  198505. n += n < 64 ? 16
  198506. : (n < 512 ? 32
  198507. : (n < 1024 ? 64
  198508. : (n < 2048 ? 128 : 256)));
  198509. return n;
  198510. }
  198511. int getDefaultBufferSize()
  198512. {
  198513. return 512;
  198514. }
  198515. const String open (const BitArray& inputChannels,
  198516. const BitArray& outputChannels,
  198517. double sampleRate,
  198518. int bufferSizeSamples)
  198519. {
  198520. close();
  198521. if (bufferSizeSamples <= 0)
  198522. bufferSizeSamples = getDefaultBufferSize();
  198523. if (sampleRate <= 0)
  198524. {
  198525. for (int i = 0; i < getNumSampleRates(); ++i)
  198526. {
  198527. if (getSampleRate (i) >= 44100)
  198528. {
  198529. sampleRate = getSampleRate (i);
  198530. break;
  198531. }
  198532. }
  198533. }
  198534. internal->open (inputChannels, outputChannels,
  198535. sampleRate, bufferSizeSamples);
  198536. isOpen_ = internal->error.isEmpty();
  198537. return internal->error;
  198538. }
  198539. void close()
  198540. {
  198541. stop();
  198542. internal->close();
  198543. isOpen_ = false;
  198544. }
  198545. bool isOpen()
  198546. {
  198547. return isOpen_;
  198548. }
  198549. int getCurrentBufferSizeSamples()
  198550. {
  198551. return internal->bufferSize;
  198552. }
  198553. double getCurrentSampleRate()
  198554. {
  198555. return internal->sampleRate;
  198556. }
  198557. int getCurrentBitDepth()
  198558. {
  198559. return internal->getBitDepth();
  198560. }
  198561. const BitArray getActiveOutputChannels() const
  198562. {
  198563. return internal->currentOutputChans;
  198564. }
  198565. const BitArray getActiveInputChannels() const
  198566. {
  198567. return internal->currentInputChans;
  198568. }
  198569. int getOutputLatencyInSamples()
  198570. {
  198571. return 0;
  198572. }
  198573. int getInputLatencyInSamples()
  198574. {
  198575. return 0;
  198576. }
  198577. void start (AudioIODeviceCallback* callback)
  198578. {
  198579. if (! isOpen_)
  198580. callback = 0;
  198581. internal->setCallback (callback);
  198582. if (callback != 0)
  198583. callback->audioDeviceAboutToStart (this);
  198584. isStarted = (callback != 0);
  198585. }
  198586. void stop()
  198587. {
  198588. AudioIODeviceCallback* const oldCallback = internal->callback;
  198589. start (0);
  198590. if (oldCallback != 0)
  198591. oldCallback->audioDeviceStopped();
  198592. }
  198593. bool isPlaying()
  198594. {
  198595. return isStarted && internal->error.isEmpty();
  198596. }
  198597. const String getLastError()
  198598. {
  198599. return internal->error;
  198600. }
  198601. String inputId, outputId;
  198602. private:
  198603. bool isOpen_, isStarted;
  198604. ALSAThread* internal;
  198605. };
  198606. class ALSAAudioIODeviceType : public AudioIODeviceType
  198607. {
  198608. public:
  198609. ALSAAudioIODeviceType()
  198610. : AudioIODeviceType (T("ALSA")),
  198611. hasScanned (false)
  198612. {
  198613. }
  198614. ~ALSAAudioIODeviceType()
  198615. {
  198616. }
  198617. void scanForDevices()
  198618. {
  198619. if (hasScanned)
  198620. return;
  198621. hasScanned = true;
  198622. inputNames.clear();
  198623. inputIds.clear();
  198624. outputNames.clear();
  198625. outputIds.clear();
  198626. snd_ctl_t* handle;
  198627. snd_ctl_card_info_t* info;
  198628. snd_ctl_card_info_alloca (&info);
  198629. int cardNum = -1;
  198630. while (outputIds.size() + inputIds.size() <= 32)
  198631. {
  198632. snd_card_next (&cardNum);
  198633. if (cardNum < 0)
  198634. break;
  198635. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198636. {
  198637. if (snd_ctl_card_info (handle, info) >= 0)
  198638. {
  198639. String cardId (snd_ctl_card_info_get_id (info));
  198640. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198641. cardId = String (cardNum);
  198642. int device = -1;
  198643. for (;;)
  198644. {
  198645. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198646. break;
  198647. String id, name;
  198648. id << "hw:" << cardId << ',' << device;
  198649. bool isInput, isOutput;
  198650. if (testDevice (id, isInput, isOutput))
  198651. {
  198652. name << snd_ctl_card_info_get_name (info);
  198653. if (name.isEmpty())
  198654. name = id;
  198655. if (isInput)
  198656. {
  198657. inputNames.add (name);
  198658. inputIds.add (id);
  198659. }
  198660. if (isOutput)
  198661. {
  198662. outputNames.add (name);
  198663. outputIds.add (id);
  198664. }
  198665. }
  198666. }
  198667. }
  198668. snd_ctl_close (handle);
  198669. }
  198670. }
  198671. inputNames.appendNumbersToDuplicates (false, true);
  198672. outputNames.appendNumbersToDuplicates (false, true);
  198673. }
  198674. const StringArray getDeviceNames (const bool wantInputNames) const
  198675. {
  198676. jassert (hasScanned); // need to call scanForDevices() before doing this
  198677. return wantInputNames ? inputNames : outputNames;
  198678. }
  198679. int getDefaultDeviceIndex (const bool forInput) const
  198680. {
  198681. jassert (hasScanned); // need to call scanForDevices() before doing this
  198682. return 0;
  198683. }
  198684. bool hasSeparateInputsAndOutputs() const { return true; }
  198685. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198686. {
  198687. jassert (hasScanned); // need to call scanForDevices() before doing this
  198688. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198689. if (d == 0)
  198690. return -1;
  198691. return asInput ? inputIds.indexOf (d->inputId)
  198692. : outputIds.indexOf (d->outputId);
  198693. }
  198694. AudioIODevice* createDevice (const String& outputDeviceName,
  198695. const String& inputDeviceName)
  198696. {
  198697. jassert (hasScanned); // need to call scanForDevices() before doing this
  198698. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198699. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198700. String deviceName (outputIndex >= 0 ? outputDeviceName
  198701. : inputDeviceName);
  198702. if (inputIndex >= 0 || outputIndex >= 0)
  198703. return new ALSAAudioIODevice (deviceName,
  198704. inputIds [inputIndex],
  198705. outputIds [outputIndex]);
  198706. return 0;
  198707. }
  198708. juce_UseDebuggingNewOperator
  198709. private:
  198710. StringArray inputNames, outputNames, inputIds, outputIds;
  198711. bool hasScanned;
  198712. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198713. {
  198714. unsigned int minChansOut = 0, maxChansOut = 0;
  198715. unsigned int minChansIn = 0, maxChansIn = 0;
  198716. Array <int> rates;
  198717. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198718. DBG (T("ALSA device: ") + id
  198719. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198720. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198721. + T(" rates=") + String (rates.size()));
  198722. isInput = maxChansIn > 0;
  198723. isOutput = maxChansOut > 0;
  198724. return (isInput || isOutput) && rates.size() > 0;
  198725. }
  198726. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198727. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198728. };
  198729. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198730. {
  198731. return new ALSAAudioIODeviceType();
  198732. }
  198733. #endif
  198734. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198735. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198736. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198737. // compiled on its own).
  198738. #ifdef JUCE_INCLUDED_FILE
  198739. #if JUCE_JACK
  198740. static void* juce_libjack_handle = 0;
  198741. void* juce_load_jack_function (const char* const name)
  198742. {
  198743. if (juce_libjack_handle == 0)
  198744. return 0;
  198745. return dlsym (juce_libjack_handle, name);
  198746. }
  198747. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198748. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198749. return_type fn_name argument_types { \
  198750. static fn_name##_ptr_t fn = 0; \
  198751. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198752. if (fn) return (*fn)arguments; \
  198753. else return 0; \
  198754. }
  198755. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198756. typedef void (*fn_name##_ptr_t)argument_types; \
  198757. void fn_name argument_types { \
  198758. static fn_name##_ptr_t fn = 0; \
  198759. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198760. if (fn) (*fn)arguments; \
  198761. }
  198762. 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));
  198763. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198764. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198765. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198766. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198767. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198768. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198769. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198770. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198771. 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));
  198772. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198773. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198774. 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));
  198775. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198776. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198777. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198778. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198779. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198780. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198781. #if JUCE_DEBUG
  198782. #define JACK_LOGGING_ENABLED 1
  198783. #endif
  198784. #if JACK_LOGGING_ENABLED
  198785. static void jack_Log (const String& s)
  198786. {
  198787. std::cerr << s << std::endl;
  198788. }
  198789. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198790. {
  198791. if (status & JackServerFailed || status & JackServerError)
  198792. jack_Log ("Unable to connect to JACK server");
  198793. if (status & JackVersionError)
  198794. jack_Log ("Client's protocol version does not match");
  198795. if (status & JackInvalidOption)
  198796. jack_Log ("The operation contained an invalid or unsupported option");
  198797. if (status & JackNameNotUnique)
  198798. jack_Log ("The desired client name was not unique");
  198799. if (status & JackNoSuchClient)
  198800. jack_Log ("Requested client does not exist");
  198801. if (status & JackInitFailure)
  198802. jack_Log ("Unable to initialize client");
  198803. }
  198804. #else
  198805. #define dumpJackErrorMessage(a) {}
  198806. #define jack_Log(...) {}
  198807. #endif
  198808. #ifndef JUCE_JACK_CLIENT_NAME
  198809. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198810. #endif
  198811. class JackAudioIODevice : public AudioIODevice
  198812. {
  198813. public:
  198814. JackAudioIODevice (const String& deviceName,
  198815. const String& inputId_,
  198816. const String& outputId_)
  198817. : AudioIODevice (deviceName, T("JACK")),
  198818. inputId (inputId_),
  198819. outputId (outputId_),
  198820. isOpen_ (false),
  198821. callback (0),
  198822. totalNumberOfInputChannels (0),
  198823. totalNumberOfOutputChannels (0)
  198824. {
  198825. jassert (deviceName.isNotEmpty());
  198826. jack_status_t status;
  198827. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198828. if (client == 0)
  198829. {
  198830. dumpJackErrorMessage (status);
  198831. }
  198832. else
  198833. {
  198834. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198835. // open input ports
  198836. const StringArray inputChannels (getInputChannelNames());
  198837. for (int i = 0; i < inputChannels.size(); i++)
  198838. {
  198839. String inputName;
  198840. inputName << "in_" << ++totalNumberOfInputChannels;
  198841. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198842. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198843. }
  198844. // open output ports
  198845. const StringArray outputChannels (getOutputChannelNames());
  198846. for (int i = 0; i < outputChannels.size (); i++)
  198847. {
  198848. String outputName;
  198849. outputName << "out_" << ++totalNumberOfOutputChannels;
  198850. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198851. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198852. }
  198853. inChans.calloc (totalNumberOfInputChannels + 2);
  198854. outChans.calloc (totalNumberOfOutputChannels + 2);
  198855. }
  198856. }
  198857. ~JackAudioIODevice()
  198858. {
  198859. close();
  198860. if (client != 0)
  198861. {
  198862. JUCE_NAMESPACE::jack_client_close (client);
  198863. client = 0;
  198864. }
  198865. }
  198866. const StringArray getChannelNames (bool forInput) const
  198867. {
  198868. StringArray names;
  198869. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198870. forInput ? JackPortIsInput : JackPortIsOutput);
  198871. if (ports != 0)
  198872. {
  198873. int j = 0;
  198874. while (ports[j] != 0)
  198875. {
  198876. const String portName (ports [j++]);
  198877. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198878. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  198879. }
  198880. free (ports);
  198881. }
  198882. return names;
  198883. }
  198884. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198885. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198886. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198887. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198888. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198889. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198890. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198891. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  198892. double sampleRate, int bufferSizeSamples)
  198893. {
  198894. if (client == 0)
  198895. {
  198896. lastError = T("No JACK client running");
  198897. return lastError;
  198898. }
  198899. lastError = String::empty;
  198900. close();
  198901. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198902. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198903. JUCE_NAMESPACE::jack_activate (client);
  198904. isOpen_ = true;
  198905. if (! inputChannels.isEmpty())
  198906. {
  198907. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198908. if (ports != 0)
  198909. {
  198910. const int numInputChannels = inputChannels.getHighestBit () + 1;
  198911. for (int i = 0; i < numInputChannels; ++i)
  198912. {
  198913. const String portName (ports[i]);
  198914. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198915. {
  198916. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  198917. if (error != 0)
  198918. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198919. }
  198920. }
  198921. free (ports);
  198922. }
  198923. }
  198924. if (! outputChannels.isEmpty())
  198925. {
  198926. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198927. if (ports != 0)
  198928. {
  198929. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  198930. for (int i = 0; i < numOutputChannels; ++i)
  198931. {
  198932. const String portName (ports[i]);
  198933. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198934. {
  198935. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  198936. if (error != 0)
  198937. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198938. }
  198939. }
  198940. free (ports);
  198941. }
  198942. }
  198943. return lastError;
  198944. }
  198945. void close()
  198946. {
  198947. stop();
  198948. if (client != 0)
  198949. {
  198950. JUCE_NAMESPACE::jack_deactivate (client);
  198951. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  198952. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  198953. }
  198954. isOpen_ = false;
  198955. }
  198956. void start (AudioIODeviceCallback* newCallback)
  198957. {
  198958. if (isOpen_ && newCallback != callback)
  198959. {
  198960. if (newCallback != 0)
  198961. newCallback->audioDeviceAboutToStart (this);
  198962. AudioIODeviceCallback* const oldCallback = callback;
  198963. {
  198964. const ScopedLock sl (callbackLock);
  198965. callback = newCallback;
  198966. }
  198967. if (oldCallback != 0)
  198968. oldCallback->audioDeviceStopped();
  198969. }
  198970. }
  198971. void stop()
  198972. {
  198973. start (0);
  198974. }
  198975. bool isOpen() { return isOpen_; }
  198976. bool isPlaying() { return callback != 0; }
  198977. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  198978. double getCurrentSampleRate() { return getSampleRate (0); }
  198979. int getCurrentBitDepth() { return 32; }
  198980. const String getLastError() { return lastError; }
  198981. const BitArray getActiveOutputChannels() const
  198982. {
  198983. BitArray outputBits;
  198984. for (int i = 0; i < outputPorts.size(); i++)
  198985. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  198986. outputBits.setBit (i);
  198987. return outputBits;
  198988. }
  198989. const BitArray getActiveInputChannels() const
  198990. {
  198991. BitArray inputBits;
  198992. for (int i = 0; i < inputPorts.size(); i++)
  198993. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  198994. inputBits.setBit (i);
  198995. return inputBits;
  198996. }
  198997. int getOutputLatencyInSamples()
  198998. {
  198999. int latency = 0;
  199000. for (int i = 0; i < outputPorts.size(); i++)
  199001. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  199002. return latency;
  199003. }
  199004. int getInputLatencyInSamples()
  199005. {
  199006. int latency = 0;
  199007. for (int i = 0; i < inputPorts.size(); i++)
  199008. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  199009. return latency;
  199010. }
  199011. String inputId, outputId;
  199012. private:
  199013. void process (const int numSamples)
  199014. {
  199015. int i, numActiveInChans = 0, numActiveOutChans = 0;
  199016. for (i = 0; i < totalNumberOfInputChannels; ++i)
  199017. {
  199018. jack_default_audio_sample_t* in
  199019. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  199020. if (in != 0)
  199021. inChans [numActiveInChans++] = (float*) in;
  199022. }
  199023. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  199024. {
  199025. jack_default_audio_sample_t* out
  199026. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  199027. if (out != 0)
  199028. outChans [numActiveOutChans++] = (float*) out;
  199029. }
  199030. const ScopedLock sl (callbackLock);
  199031. if (callback != 0)
  199032. {
  199033. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  199034. outChans, numActiveOutChans, numSamples);
  199035. }
  199036. else
  199037. {
  199038. for (i = 0; i < numActiveOutChans; ++i)
  199039. zeromem (outChans[i], sizeof (float) * numSamples);
  199040. }
  199041. }
  199042. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199043. {
  199044. if (callbackArgument != 0)
  199045. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199046. return 0;
  199047. }
  199048. static void threadInitCallback (void* callbackArgument)
  199049. {
  199050. jack_Log ("JackAudioIODevice::initialise");
  199051. }
  199052. static void shutdownCallback (void* callbackArgument)
  199053. {
  199054. jack_Log ("JackAudioIODevice::shutdown");
  199055. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199056. if (device != 0)
  199057. {
  199058. device->client = 0;
  199059. device->close();
  199060. }
  199061. }
  199062. static void errorCallback (const char* msg)
  199063. {
  199064. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199065. }
  199066. bool isOpen_;
  199067. jack_client_t* client;
  199068. String lastError;
  199069. AudioIODeviceCallback* callback;
  199070. CriticalSection callbackLock;
  199071. HeapBlock <float*> inChans, outChans;
  199072. int totalNumberOfInputChannels;
  199073. int totalNumberOfOutputChannels;
  199074. VoidArray inputPorts, outputPorts;
  199075. };
  199076. class JackAudioIODeviceType : public AudioIODeviceType
  199077. {
  199078. public:
  199079. JackAudioIODeviceType()
  199080. : AudioIODeviceType (T("JACK")),
  199081. hasScanned (false)
  199082. {
  199083. }
  199084. ~JackAudioIODeviceType()
  199085. {
  199086. }
  199087. void scanForDevices()
  199088. {
  199089. hasScanned = true;
  199090. inputNames.clear();
  199091. inputIds.clear();
  199092. outputNames.clear();
  199093. outputIds.clear();
  199094. if (juce_libjack_handle == 0)
  199095. {
  199096. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199097. if (juce_libjack_handle == 0)
  199098. return;
  199099. }
  199100. // open a dummy client
  199101. jack_status_t status;
  199102. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199103. if (client == 0)
  199104. {
  199105. dumpJackErrorMessage (status);
  199106. }
  199107. else
  199108. {
  199109. // scan for output devices
  199110. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199111. if (ports != 0)
  199112. {
  199113. int j = 0;
  199114. while (ports[j] != 0)
  199115. {
  199116. String clientName (ports[j]);
  199117. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199118. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199119. && ! inputNames.contains (clientName))
  199120. {
  199121. inputNames.add (clientName);
  199122. inputIds.add (ports [j]);
  199123. }
  199124. ++j;
  199125. }
  199126. free (ports);
  199127. }
  199128. // scan for input devices
  199129. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199130. if (ports != 0)
  199131. {
  199132. int j = 0;
  199133. while (ports[j] != 0)
  199134. {
  199135. String clientName (ports[j]);
  199136. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199137. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199138. && ! outputNames.contains (clientName))
  199139. {
  199140. outputNames.add (clientName);
  199141. outputIds.add (ports [j]);
  199142. }
  199143. ++j;
  199144. }
  199145. free (ports);
  199146. }
  199147. JUCE_NAMESPACE::jack_client_close (client);
  199148. }
  199149. }
  199150. const StringArray getDeviceNames (const bool wantInputNames) const
  199151. {
  199152. jassert (hasScanned); // need to call scanForDevices() before doing this
  199153. return wantInputNames ? inputNames : outputNames;
  199154. }
  199155. int getDefaultDeviceIndex (const bool forInput) const
  199156. {
  199157. jassert (hasScanned); // need to call scanForDevices() before doing this
  199158. return 0;
  199159. }
  199160. bool hasSeparateInputsAndOutputs() const { return true; }
  199161. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199162. {
  199163. jassert (hasScanned); // need to call scanForDevices() before doing this
  199164. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199165. if (d == 0)
  199166. return -1;
  199167. return asInput ? inputIds.indexOf (d->inputId)
  199168. : outputIds.indexOf (d->outputId);
  199169. }
  199170. AudioIODevice* createDevice (const String& outputDeviceName,
  199171. const String& inputDeviceName)
  199172. {
  199173. jassert (hasScanned); // need to call scanForDevices() before doing this
  199174. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199175. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199176. if (inputIndex >= 0 || outputIndex >= 0)
  199177. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199178. : inputDeviceName,
  199179. inputIds [inputIndex],
  199180. outputIds [outputIndex]);
  199181. return 0;
  199182. }
  199183. juce_UseDebuggingNewOperator
  199184. private:
  199185. StringArray inputNames, outputNames, inputIds, outputIds;
  199186. bool hasScanned;
  199187. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199188. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199189. };
  199190. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199191. {
  199192. return new JackAudioIODeviceType();
  199193. }
  199194. #else // if JACK is turned off..
  199195. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199196. #endif
  199197. #endif
  199198. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199199. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199200. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199201. // compiled on its own).
  199202. #if JUCE_INCLUDED_FILE
  199203. #if JUCE_ALSA
  199204. static snd_seq_t* iterateDevices (const bool forInput,
  199205. StringArray& deviceNamesFound,
  199206. const int deviceIndexToOpen)
  199207. {
  199208. snd_seq_t* returnedHandle = 0;
  199209. snd_seq_t* seqHandle;
  199210. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199211. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199212. {
  199213. snd_seq_system_info_t* systemInfo;
  199214. snd_seq_client_info_t* clientInfo;
  199215. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199216. {
  199217. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199218. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199219. {
  199220. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199221. while (--numClients >= 0 && returnedHandle == 0)
  199222. {
  199223. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199224. {
  199225. snd_seq_port_info_t* portInfo;
  199226. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199227. {
  199228. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199229. const int client = snd_seq_client_info_get_client (clientInfo);
  199230. snd_seq_port_info_set_client (portInfo, client);
  199231. snd_seq_port_info_set_port (portInfo, -1);
  199232. while (--numPorts >= 0)
  199233. {
  199234. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199235. && (snd_seq_port_info_get_capability (portInfo)
  199236. & (forInput ? SND_SEQ_PORT_CAP_READ
  199237. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199238. {
  199239. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199240. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199241. {
  199242. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199243. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199244. if (sourcePort != -1)
  199245. {
  199246. snd_seq_set_client_name (seqHandle,
  199247. forInput ? "Juce Midi Input"
  199248. : "Juce Midi Output");
  199249. const int portId
  199250. = snd_seq_create_simple_port (seqHandle,
  199251. forInput ? "Juce Midi In Port"
  199252. : "Juce Midi Out Port",
  199253. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199254. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199255. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199256. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199257. returnedHandle = seqHandle;
  199258. }
  199259. }
  199260. }
  199261. }
  199262. snd_seq_port_info_free (portInfo);
  199263. }
  199264. }
  199265. }
  199266. snd_seq_client_info_free (clientInfo);
  199267. }
  199268. snd_seq_system_info_free (systemInfo);
  199269. }
  199270. if (returnedHandle == 0)
  199271. snd_seq_close (seqHandle);
  199272. }
  199273. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199274. return returnedHandle;
  199275. }
  199276. static snd_seq_t* createDevice (const bool forInput,
  199277. const String& deviceNameToOpen)
  199278. {
  199279. snd_seq_t* seqHandle = 0;
  199280. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199281. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199282. {
  199283. snd_seq_set_client_name (seqHandle,
  199284. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199285. const int portId
  199286. = snd_seq_create_simple_port (seqHandle,
  199287. forInput ? "in"
  199288. : "out",
  199289. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199290. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199291. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199292. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199293. if (portId < 0)
  199294. {
  199295. snd_seq_close (seqHandle);
  199296. seqHandle = 0;
  199297. }
  199298. }
  199299. return seqHandle;
  199300. }
  199301. class MidiOutputDevice
  199302. {
  199303. public:
  199304. MidiOutputDevice (MidiOutput* const midiOutput_,
  199305. snd_seq_t* const seqHandle_)
  199306. :
  199307. midiOutput (midiOutput_),
  199308. seqHandle (seqHandle_),
  199309. maxEventSize (16 * 1024)
  199310. {
  199311. jassert (seqHandle != 0 && midiOutput != 0);
  199312. snd_midi_event_new (maxEventSize, &midiParser);
  199313. }
  199314. ~MidiOutputDevice()
  199315. {
  199316. snd_midi_event_free (midiParser);
  199317. snd_seq_close (seqHandle);
  199318. }
  199319. void sendMessageNow (const MidiMessage& message)
  199320. {
  199321. if (message.getRawDataSize() > maxEventSize)
  199322. {
  199323. maxEventSize = message.getRawDataSize();
  199324. snd_midi_event_free (midiParser);
  199325. snd_midi_event_new (maxEventSize, &midiParser);
  199326. }
  199327. snd_seq_event_t event;
  199328. snd_seq_ev_clear (&event);
  199329. snd_midi_event_encode (midiParser,
  199330. message.getRawData(),
  199331. message.getRawDataSize(),
  199332. &event);
  199333. snd_midi_event_reset_encode (midiParser);
  199334. snd_seq_ev_set_source (&event, 0);
  199335. snd_seq_ev_set_subs (&event);
  199336. snd_seq_ev_set_direct (&event);
  199337. snd_seq_event_output (seqHandle, &event);
  199338. snd_seq_drain_output (seqHandle);
  199339. }
  199340. juce_UseDebuggingNewOperator
  199341. private:
  199342. MidiOutput* const midiOutput;
  199343. snd_seq_t* const seqHandle;
  199344. snd_midi_event_t* midiParser;
  199345. int maxEventSize;
  199346. };
  199347. const StringArray MidiOutput::getDevices()
  199348. {
  199349. StringArray devices;
  199350. iterateDevices (false, devices, -1);
  199351. return devices;
  199352. }
  199353. int MidiOutput::getDefaultDeviceIndex()
  199354. {
  199355. return 0;
  199356. }
  199357. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199358. {
  199359. MidiOutput* newDevice = 0;
  199360. StringArray devices;
  199361. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199362. if (handle != 0)
  199363. {
  199364. newDevice = new MidiOutput();
  199365. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199366. }
  199367. return newDevice;
  199368. }
  199369. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199370. {
  199371. MidiOutput* newDevice = 0;
  199372. snd_seq_t* const handle = createDevice (false, deviceName);
  199373. if (handle != 0)
  199374. {
  199375. newDevice = new MidiOutput();
  199376. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199377. }
  199378. return newDevice;
  199379. }
  199380. MidiOutput::~MidiOutput()
  199381. {
  199382. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199383. delete device;
  199384. }
  199385. void MidiOutput::reset()
  199386. {
  199387. }
  199388. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199389. {
  199390. return false;
  199391. }
  199392. void MidiOutput::setVolume (float leftVol, float rightVol)
  199393. {
  199394. }
  199395. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199396. {
  199397. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199398. }
  199399. class MidiInputThread : public Thread
  199400. {
  199401. public:
  199402. MidiInputThread (MidiInput* const midiInput_,
  199403. snd_seq_t* const seqHandle_,
  199404. MidiInputCallback* const callback_)
  199405. : Thread (T("Juce MIDI Input")),
  199406. midiInput (midiInput_),
  199407. seqHandle (seqHandle_),
  199408. callback (callback_)
  199409. {
  199410. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199411. }
  199412. ~MidiInputThread()
  199413. {
  199414. snd_seq_close (seqHandle);
  199415. }
  199416. void run()
  199417. {
  199418. const int maxEventSize = 16 * 1024;
  199419. snd_midi_event_t* midiParser;
  199420. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199421. {
  199422. HeapBlock <uint8> buffer (maxEventSize);
  199423. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199424. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199425. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199426. while (! threadShouldExit())
  199427. {
  199428. if (poll (pfd, numPfds, 500) > 0)
  199429. {
  199430. snd_seq_event_t* inputEvent = 0;
  199431. snd_seq_nonblock (seqHandle, 1);
  199432. do
  199433. {
  199434. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199435. {
  199436. // xxx what about SYSEXes that are too big for the buffer?
  199437. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199438. snd_midi_event_reset_decode (midiParser);
  199439. if (numBytes > 0)
  199440. {
  199441. const MidiMessage message ((const uint8*) buffer,
  199442. numBytes,
  199443. Time::getMillisecondCounter() * 0.001);
  199444. callback->handleIncomingMidiMessage (midiInput, message);
  199445. }
  199446. snd_seq_free_event (inputEvent);
  199447. }
  199448. }
  199449. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199450. snd_seq_free_event (inputEvent);
  199451. }
  199452. }
  199453. snd_midi_event_free (midiParser);
  199454. }
  199455. };
  199456. juce_UseDebuggingNewOperator
  199457. private:
  199458. MidiInput* const midiInput;
  199459. snd_seq_t* const seqHandle;
  199460. MidiInputCallback* const callback;
  199461. };
  199462. MidiInput::MidiInput (const String& name_)
  199463. : name (name_),
  199464. internal (0)
  199465. {
  199466. }
  199467. MidiInput::~MidiInput()
  199468. {
  199469. stop();
  199470. MidiInputThread* const thread = (MidiInputThread*) internal;
  199471. delete thread;
  199472. }
  199473. void MidiInput::start()
  199474. {
  199475. ((MidiInputThread*) internal)->startThread();
  199476. }
  199477. void MidiInput::stop()
  199478. {
  199479. ((MidiInputThread*) internal)->stopThread (3000);
  199480. }
  199481. int MidiInput::getDefaultDeviceIndex()
  199482. {
  199483. return 0;
  199484. }
  199485. const StringArray MidiInput::getDevices()
  199486. {
  199487. StringArray devices;
  199488. iterateDevices (true, devices, -1);
  199489. return devices;
  199490. }
  199491. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199492. {
  199493. MidiInput* newDevice = 0;
  199494. StringArray devices;
  199495. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199496. if (handle != 0)
  199497. {
  199498. newDevice = new MidiInput (devices [deviceIndex]);
  199499. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199500. }
  199501. return newDevice;
  199502. }
  199503. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199504. {
  199505. MidiInput* newDevice = 0;
  199506. snd_seq_t* const handle = createDevice (true, deviceName);
  199507. if (handle != 0)
  199508. {
  199509. newDevice = new MidiInput (deviceName);
  199510. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199511. }
  199512. return newDevice;
  199513. }
  199514. #else
  199515. // (These are just stub functions if ALSA is unavailable...)
  199516. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199517. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199518. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199519. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199520. MidiOutput::~MidiOutput() {}
  199521. void MidiOutput::reset() {}
  199522. bool MidiOutput::getVolume (float&, float&) { return false; }
  199523. void MidiOutput::setVolume (float, float) {}
  199524. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199525. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199526. MidiInput::~MidiInput() {}
  199527. void MidiInput::start() {}
  199528. void MidiInput::stop() {}
  199529. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199530. const StringArray MidiInput::getDevices() { return StringArray(); }
  199531. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199532. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199533. #endif
  199534. #endif
  199535. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199536. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199537. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199538. // compiled on its own).
  199539. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199540. AudioCDReader::AudioCDReader()
  199541. : AudioFormatReader (0, T("CD Audio"))
  199542. {
  199543. }
  199544. const StringArray AudioCDReader::getAvailableCDNames()
  199545. {
  199546. StringArray names;
  199547. return names;
  199548. }
  199549. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199550. {
  199551. return 0;
  199552. }
  199553. AudioCDReader::~AudioCDReader()
  199554. {
  199555. }
  199556. void AudioCDReader::refreshTrackLengths()
  199557. {
  199558. }
  199559. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199560. int64 startSampleInFile, int numSamples)
  199561. {
  199562. return false;
  199563. }
  199564. bool AudioCDReader::isCDStillPresent() const
  199565. {
  199566. return false;
  199567. }
  199568. int AudioCDReader::getNumTracks() const
  199569. {
  199570. return 0;
  199571. }
  199572. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199573. {
  199574. return 0;
  199575. }
  199576. bool AudioCDReader::isTrackAudio (int trackNum) const
  199577. {
  199578. return false;
  199579. }
  199580. void AudioCDReader::enableIndexScanning (bool b)
  199581. {
  199582. }
  199583. int AudioCDReader::getLastIndex() const
  199584. {
  199585. return 0;
  199586. }
  199587. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199588. {
  199589. return Array<int>();
  199590. }
  199591. int AudioCDReader::getCDDBId()
  199592. {
  199593. return 0;
  199594. }
  199595. #endif
  199596. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199597. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199598. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199599. // compiled on its own).
  199600. #if JUCE_INCLUDED_FILE
  199601. void FileChooser::showPlatformDialog (Array<File>& results,
  199602. const String& title,
  199603. const File& file,
  199604. const String& filters,
  199605. bool isDirectory,
  199606. bool selectsFiles,
  199607. bool isSave,
  199608. bool warnAboutOverwritingExistingFiles,
  199609. bool selectMultipleFiles,
  199610. FilePreviewComponent* previewComponent)
  199611. {
  199612. const tchar* const separator = T(":");
  199613. String command ("zenity --file-selection");
  199614. if (title.isNotEmpty())
  199615. command << " --title=\"" << title << "\"";
  199616. if (file != File::nonexistent)
  199617. command << " --filename=\"" << file.getFullPathName () << "\"";
  199618. if (isDirectory)
  199619. command << " --directory";
  199620. if (isSave)
  199621. command << " --save";
  199622. if (selectMultipleFiles)
  199623. command << " --multiple --separator=\"" << separator << "\"";
  199624. command << " 2>&1";
  199625. MemoryOutputStream result;
  199626. int status = -1;
  199627. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  199628. if (stream != 0)
  199629. {
  199630. for (;;)
  199631. {
  199632. char buffer [1024];
  199633. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199634. if (bytesRead <= 0)
  199635. break;
  199636. result.write (buffer, bytesRead);
  199637. }
  199638. status = pclose (stream);
  199639. }
  199640. if (status == 0)
  199641. {
  199642. String resultString (String::fromUTF8 (result.getData(), result.getDataSize()));
  199643. StringArray tokens;
  199644. if (selectMultipleFiles)
  199645. tokens.addTokens (resultString, separator, String::empty);
  199646. else
  199647. tokens.add (resultString);
  199648. for (int i = 0; i < tokens.size(); i++)
  199649. results.add (File (tokens[i]));
  199650. return;
  199651. }
  199652. //xxx ain't got one!
  199653. jassertfalse
  199654. }
  199655. #endif
  199656. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199657. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199658. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199659. // compiled on its own).
  199660. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199661. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199662. : browser (0),
  199663. blankPageShown (false),
  199664. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199665. {
  199666. setOpaque (true);
  199667. }
  199668. WebBrowserComponent::~WebBrowserComponent()
  199669. {
  199670. }
  199671. void WebBrowserComponent::goToURL (const String& url,
  199672. const StringArray* headers,
  199673. const MemoryBlock* postData)
  199674. {
  199675. lastURL = url;
  199676. lastHeaders.clear();
  199677. if (headers != 0)
  199678. lastHeaders = *headers;
  199679. lastPostData.setSize (0);
  199680. if (postData != 0)
  199681. lastPostData = *postData;
  199682. blankPageShown = false;
  199683. }
  199684. void WebBrowserComponent::stop()
  199685. {
  199686. }
  199687. void WebBrowserComponent::goBack()
  199688. {
  199689. lastURL = String::empty;
  199690. blankPageShown = false;
  199691. }
  199692. void WebBrowserComponent::goForward()
  199693. {
  199694. lastURL = String::empty;
  199695. }
  199696. void WebBrowserComponent::refresh()
  199697. {
  199698. }
  199699. void WebBrowserComponent::paint (Graphics& g)
  199700. {
  199701. g.fillAll (Colours::white);
  199702. }
  199703. void WebBrowserComponent::checkWindowAssociation()
  199704. {
  199705. }
  199706. void WebBrowserComponent::reloadLastURL()
  199707. {
  199708. if (lastURL.isNotEmpty())
  199709. {
  199710. goToURL (lastURL, &lastHeaders, &lastPostData);
  199711. lastURL = String::empty;
  199712. }
  199713. }
  199714. void WebBrowserComponent::parentHierarchyChanged()
  199715. {
  199716. checkWindowAssociation();
  199717. }
  199718. void WebBrowserComponent::resized()
  199719. {
  199720. }
  199721. void WebBrowserComponent::visibilityChanged()
  199722. {
  199723. checkWindowAssociation();
  199724. }
  199725. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199726. {
  199727. return true;
  199728. }
  199729. #endif
  199730. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199731. #endif
  199732. END_JUCE_NAMESPACE
  199733. #endif
  199734. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199735. #endif
  199736. #if JUCE_MAC || JUCE_IPHONE
  199737. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199738. #if JUCE_MAC || JUCE_IPHONE
  199739. BEGIN_JUCE_NAMESPACE
  199740. #undef Point
  199741. #define JUCE_INCLUDED_FILE 1
  199742. // Now include the actual code files..
  199743. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199744. #ifndef JUCE_ObjCExtraSuffix
  199745. #define JUCE_ObjCExtraSuffix 3
  199746. #endif
  199747. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199748. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199749. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199750. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199751. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199752. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199753. // compiled on its own).
  199754. #if JUCE_INCLUDED_FILE
  199755. static const String nsStringToJuce (NSString* s)
  199756. {
  199757. return String::fromUTF8 ([s UTF8String]);
  199758. }
  199759. static NSString* juceStringToNS (const String& s)
  199760. {
  199761. return [NSString stringWithUTF8String: s.toUTF8()];
  199762. }
  199763. static const String convertUTF16ToString (const UniChar* utf16)
  199764. {
  199765. String s;
  199766. while (*utf16 != 0)
  199767. s += (juce_wchar) *utf16++;
  199768. return s;
  199769. }
  199770. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199771. {
  199772. String result;
  199773. if (cfString != 0)
  199774. {
  199775. CFRange range = { 0, CFStringGetLength (cfString) };
  199776. HeapBlock <UniChar> u (range.length + 1);
  199777. CFStringGetCharacters (cfString, range, u);
  199778. u[range.length] = 0;
  199779. result = convertUTF16ToString (u);
  199780. }
  199781. return result;
  199782. }
  199783. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199784. {
  199785. const int len = s.length();
  199786. const juce_wchar* t = (const juce_wchar*) s;
  199787. HeapBlock <UniChar> temp (len + 2);
  199788. for (int i = 0; i <= len; ++i)
  199789. temp[i] = t[i];
  199790. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199791. }
  199792. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199793. {
  199794. #if JUCE_IPHONE
  199795. const ScopedAutoReleasePool pool;
  199796. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199797. #else
  199798. UnicodeMapping map;
  199799. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199800. kUnicodeNoSubset,
  199801. kTextEncodingDefaultFormat);
  199802. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199803. kUnicodeCanonicalCompVariant,
  199804. kTextEncodingDefaultFormat);
  199805. map.mappingVersion = kUnicodeUseLatestMapping;
  199806. UnicodeToTextInfo conversionInfo = 0;
  199807. String result;
  199808. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199809. {
  199810. const int len = s.length();
  199811. HeapBlock <UniChar> tempIn, tempOut;
  199812. tempIn.calloc (len + 2);
  199813. tempOut.calloc (len + 2);
  199814. for (int i = 0; i <= len; ++i)
  199815. tempIn[i] = s[i];
  199816. ByteCount bytesRead = 0;
  199817. ByteCount outputBufferSize = 0;
  199818. if (ConvertFromUnicodeToText (conversionInfo,
  199819. len * sizeof (UniChar), tempIn,
  199820. kUnicodeDefaultDirectionMask,
  199821. 0, 0, 0, 0,
  199822. len * sizeof (UniChar), &bytesRead,
  199823. &outputBufferSize, tempOut) == noErr)
  199824. {
  199825. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199826. tchar* t = const_cast <tchar*> ((const tchar*) result);
  199827. unsigned int i;
  199828. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199829. t[i] = (tchar) tempOut[i];
  199830. t[i] = 0;
  199831. }
  199832. DisposeUnicodeToTextInfo (&conversionInfo);
  199833. }
  199834. return result;
  199835. #endif
  199836. }
  199837. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199838. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  199839. {
  199840. #if JUCE_IPHONE
  199841. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199842. forPasteboardType: @"public.text"];
  199843. #else
  199844. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199845. owner: nil];
  199846. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199847. forType: NSStringPboardType];
  199848. #endif
  199849. }
  199850. const String SystemClipboard::getTextFromClipboard() throw()
  199851. {
  199852. #if JUCE_IPHONE
  199853. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199854. #else
  199855. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199856. #endif
  199857. return text == 0 ? String::empty
  199858. : nsStringToJuce (text);
  199859. }
  199860. #endif
  199861. #endif
  199862. /*** End of inlined file: juce_mac_Strings.mm ***/
  199863. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199864. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199865. // compiled on its own).
  199866. #if JUCE_INCLUDED_FILE
  199867. namespace SystemStatsHelpers
  199868. {
  199869. static int64 highResTimerFrequency = 0;
  199870. static double highResTimerToMillisecRatio = 0;
  199871. #if JUCE_INTEL
  199872. static void juce_getCpuVendor (char* const v) throw()
  199873. {
  199874. int vendor[4];
  199875. zerostruct (vendor);
  199876. int dummy = 0;
  199877. asm ("mov %%ebx, %%esi \n\t"
  199878. "cpuid \n\t"
  199879. "xchg %%esi, %%ebx"
  199880. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199881. memcpy (v, vendor, 16);
  199882. }
  199883. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199884. {
  199885. unsigned int cpu = 0;
  199886. unsigned int ext = 0;
  199887. unsigned int family = 0;
  199888. unsigned int dummy = 0;
  199889. asm ("mov %%ebx, %%esi \n\t"
  199890. "cpuid \n\t"
  199891. "xchg %%esi, %%ebx"
  199892. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199893. familyModel = family;
  199894. extFeatures = ext;
  199895. return cpu;
  199896. }
  199897. struct CPUFlags
  199898. {
  199899. bool hasMMX : 1;
  199900. bool hasSSE : 1;
  199901. bool hasSSE2 : 1;
  199902. bool has3DNow : 1;
  199903. };
  199904. static CPUFlags cpuFlags;
  199905. #endif
  199906. }
  199907. void SystemStats::initialiseStats() throw()
  199908. {
  199909. using namespace SystemStatsHelpers;
  199910. static bool initialised = false;
  199911. if (! initialised)
  199912. {
  199913. initialised = true;
  199914. #if JUCE_MAC
  199915. // extremely annoying: adding this line stops the apple menu items from working. Of
  199916. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  199917. // any events.
  199918. //NSApplicationLoad();
  199919. [NSApplication sharedApplication];
  199920. #endif
  199921. #if JUCE_INTEL
  199922. {
  199923. unsigned int familyModel, extFeatures;
  199924. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  199925. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  199926. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  199927. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  199928. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  199929. }
  199930. #endif
  199931. mach_timebase_info_data_t timebase;
  199932. (void) mach_timebase_info (&timebase);
  199933. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  199934. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  199935. String s (SystemStats::getJUCEVersion());
  199936. rlimit lim;
  199937. getrlimit (RLIMIT_NOFILE, &lim);
  199938. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  199939. setrlimit (RLIMIT_NOFILE, &lim);
  199940. }
  199941. }
  199942. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  199943. {
  199944. return MacOSX;
  199945. }
  199946. const String SystemStats::getOperatingSystemName() throw()
  199947. {
  199948. return T("Mac OS X");
  199949. }
  199950. bool SystemStats::isOperatingSystem64Bit() throw()
  199951. {
  199952. #if JUCE_64BIT
  199953. return true;
  199954. #else
  199955. //xxx not sure how to find this out?..
  199956. return false;
  199957. #endif
  199958. }
  199959. int SystemStats::getMemorySizeInMegabytes() throw()
  199960. {
  199961. uint64 mem = 0;
  199962. size_t memSize = sizeof (mem);
  199963. int mib[] = { CTL_HW, HW_MEMSIZE };
  199964. sysctl (mib, 2, &mem, &memSize, 0, 0);
  199965. return (int) (mem / (1024 * 1024));
  199966. }
  199967. bool SystemStats::hasMMX() throw()
  199968. {
  199969. #if JUCE_INTEL
  199970. return SystemStatsHelpers::cpuFlags.hasMMX;
  199971. #else
  199972. return false;
  199973. #endif
  199974. }
  199975. bool SystemStats::hasSSE() throw()
  199976. {
  199977. #if JUCE_INTEL
  199978. return SystemStatsHelpers::cpuFlags.hasSSE;
  199979. #else
  199980. return false;
  199981. #endif
  199982. }
  199983. bool SystemStats::hasSSE2() throw()
  199984. {
  199985. #if JUCE_INTEL
  199986. return SystemStatsHelpers::cpuFlags.hasSSE2;
  199987. #else
  199988. return false;
  199989. #endif
  199990. }
  199991. bool SystemStats::has3DNow() throw()
  199992. {
  199993. #if JUCE_INTEL
  199994. return SystemStatsHelpers::cpuFlags.has3DNow;
  199995. #else
  199996. return false;
  199997. #endif
  199998. }
  199999. const String SystemStats::getCpuVendor() throw()
  200000. {
  200001. #if JUCE_INTEL
  200002. char v [16];
  200003. SystemStatsHelpers::juce_getCpuVendor (v);
  200004. return String (v, 16);
  200005. #else
  200006. return String::empty;
  200007. #endif
  200008. }
  200009. int SystemStats::getCpuSpeedInMegaherz() throw()
  200010. {
  200011. uint64 speedHz = 0;
  200012. size_t speedSize = sizeof (speedHz);
  200013. int mib[] = { CTL_HW, HW_CPU_FREQ };
  200014. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  200015. #if JUCE_BIG_ENDIAN
  200016. if (speedSize == 4)
  200017. speedHz >>= 32;
  200018. #endif
  200019. return (int) (speedHz / 1000000);
  200020. }
  200021. int SystemStats::getNumCpus() throw()
  200022. {
  200023. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  200024. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  200025. #else
  200026. return MPProcessors();
  200027. #endif
  200028. }
  200029. const String SystemStats::getLogonName()
  200030. {
  200031. return nsStringToJuce (NSUserName());
  200032. }
  200033. const String SystemStats::getFullUserName()
  200034. {
  200035. return nsStringToJuce (NSFullUserName());
  200036. }
  200037. uint32 juce_millisecondsSinceStartup() throw()
  200038. {
  200039. return (uint32) (mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio);
  200040. }
  200041. double Time::getMillisecondCounterHiRes() throw()
  200042. {
  200043. return mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio;
  200044. }
  200045. int64 Time::getHighResolutionTicks() throw()
  200046. {
  200047. return (int64) mach_absolute_time();
  200048. }
  200049. int64 Time::getHighResolutionTicksPerSecond() throw()
  200050. {
  200051. return SystemStatsHelpers::highResTimerFrequency;
  200052. }
  200053. int64 SystemStats::getClockCycleCounter() throw()
  200054. {
  200055. return (int64) mach_absolute_time();
  200056. }
  200057. bool Time::setSystemTimeToThisTime() const throw()
  200058. {
  200059. jassertfalse
  200060. return false;
  200061. }
  200062. int SystemStats::getPageSize() throw()
  200063. {
  200064. return (int) NSPageSize();
  200065. }
  200066. void PlatformUtilities::fpuReset()
  200067. {
  200068. }
  200069. #endif
  200070. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  200071. /*** Start of inlined file: juce_mac_Network.mm ***/
  200072. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200073. // compiled on its own).
  200074. #if JUCE_INCLUDED_FILE
  200075. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  200076. {
  200077. #ifndef IFT_ETHER
  200078. #define IFT_ETHER 6
  200079. #endif
  200080. ifaddrs* addrs = 0;
  200081. int numResults = 0;
  200082. if (getifaddrs (&addrs) == 0)
  200083. {
  200084. const ifaddrs* cursor = addrs;
  200085. while (cursor != 0 && numResults < maxNum)
  200086. {
  200087. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  200088. if (sto->ss_family == AF_LINK)
  200089. {
  200090. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200091. if (sadd->sdl_type == IFT_ETHER)
  200092. {
  200093. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200094. uint64 a = 0;
  200095. for (int i = 6; --i >= 0;)
  200096. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200097. *addresses++ = (int64) a;
  200098. ++numResults;
  200099. }
  200100. }
  200101. cursor = cursor->ifa_next;
  200102. }
  200103. freeifaddrs (addrs);
  200104. }
  200105. return numResults;
  200106. }
  200107. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200108. const String& emailSubject,
  200109. const String& bodyText,
  200110. const StringArray& filesToAttach)
  200111. {
  200112. #if JUCE_IPHONE
  200113. //xxx probably need to use MFMailComposeViewController
  200114. jassertfalse
  200115. return false;
  200116. #else
  200117. const ScopedAutoReleasePool pool;
  200118. String script;
  200119. script << "tell application \"Mail\"\r\n"
  200120. "set newMessage to make new outgoing message with properties {subject:\""
  200121. << emailSubject.replace (T("\""), T("\\\""))
  200122. << "\", content:\""
  200123. << bodyText.replace (T("\""), T("\\\""))
  200124. << "\" & return & return}\r\n"
  200125. "tell newMessage\r\n"
  200126. "set visible to true\r\n"
  200127. "set sender to \"sdfsdfsdfewf\"\r\n"
  200128. "make new to recipient at end of to recipients with properties {address:\""
  200129. << targetEmailAddress
  200130. << "\"}\r\n";
  200131. for (int i = 0; i < filesToAttach.size(); ++i)
  200132. {
  200133. script << "tell content\r\n"
  200134. "make new attachment with properties {file name:\""
  200135. << filesToAttach[i].replace (T("\""), T("\\\""))
  200136. << "\"} at after the last paragraph\r\n"
  200137. "end tell\r\n";
  200138. }
  200139. script << "end tell\r\n"
  200140. "end tell\r\n";
  200141. NSAppleScript* s = [[NSAppleScript alloc]
  200142. initWithSource: juceStringToNS (script)];
  200143. NSDictionary* error = 0;
  200144. const bool ok = [s executeAndReturnError: &error] != nil;
  200145. [s release];
  200146. return ok;
  200147. #endif
  200148. }
  200149. END_JUCE_NAMESPACE
  200150. using namespace JUCE_NAMESPACE;
  200151. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200152. @interface JuceURLConnection : NSObject
  200153. {
  200154. @public
  200155. NSURLRequest* request;
  200156. NSURLConnection* connection;
  200157. NSMutableData* data;
  200158. Thread* runLoopThread;
  200159. bool initialised, hasFailed, hasFinished;
  200160. int position;
  200161. int64 contentLength;
  200162. NSLock* dataLock;
  200163. }
  200164. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200165. - (void) dealloc;
  200166. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200167. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200168. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200169. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200170. - (BOOL) isOpen;
  200171. - (int) read: (char*) dest numBytes: (int) num;
  200172. - (int) readPosition;
  200173. - (void) stop;
  200174. - (void) createConnection;
  200175. @end
  200176. class JuceURLConnectionMessageThread : public Thread
  200177. {
  200178. JuceURLConnection* owner;
  200179. public:
  200180. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200181. : Thread (T("http connection")),
  200182. owner (owner_)
  200183. {
  200184. }
  200185. ~JuceURLConnectionMessageThread()
  200186. {
  200187. stopThread (10000);
  200188. }
  200189. void run()
  200190. {
  200191. [owner createConnection];
  200192. while (! threadShouldExit())
  200193. {
  200194. const ScopedAutoReleasePool pool;
  200195. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200196. }
  200197. }
  200198. };
  200199. @implementation JuceURLConnection
  200200. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200201. withCallback: (URL::OpenStreamProgressCallback*) callback
  200202. withContext: (void*) context;
  200203. {
  200204. [super init];
  200205. request = req;
  200206. [request retain];
  200207. data = [[NSMutableData data] retain];
  200208. dataLock = [[NSLock alloc] init];
  200209. connection = 0;
  200210. initialised = false;
  200211. hasFailed = false;
  200212. hasFinished = false;
  200213. contentLength = -1;
  200214. runLoopThread = new JuceURLConnectionMessageThread (self);
  200215. runLoopThread->startThread();
  200216. while (runLoopThread->isThreadRunning() && ! initialised)
  200217. {
  200218. if (callback != 0)
  200219. callback (context, -1, (int) [[request HTTPBody] length]);
  200220. Thread::sleep (1);
  200221. }
  200222. return self;
  200223. }
  200224. - (void) dealloc
  200225. {
  200226. [self stop];
  200227. delete runLoopThread;
  200228. [connection release];
  200229. [data release];
  200230. [dataLock release];
  200231. [request release];
  200232. [super dealloc];
  200233. }
  200234. - (void) createConnection
  200235. {
  200236. connection = [[NSURLConnection alloc] initWithRequest: request
  200237. delegate: [self retain]];
  200238. if (connection == nil)
  200239. runLoopThread->signalThreadShouldExit();
  200240. }
  200241. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200242. {
  200243. [dataLock lock];
  200244. [data setLength: 0];
  200245. [dataLock unlock];
  200246. initialised = true;
  200247. contentLength = [response expectedContentLength];
  200248. }
  200249. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200250. {
  200251. DBG (nsStringToJuce ([error description]));
  200252. hasFailed = true;
  200253. initialised = true;
  200254. runLoopThread->signalThreadShouldExit();
  200255. }
  200256. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200257. {
  200258. [dataLock lock];
  200259. [data appendData: newData];
  200260. [dataLock unlock];
  200261. initialised = true;
  200262. }
  200263. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200264. {
  200265. hasFinished = true;
  200266. initialised = true;
  200267. runLoopThread->signalThreadShouldExit();
  200268. }
  200269. - (BOOL) isOpen
  200270. {
  200271. return connection != 0 && ! hasFailed;
  200272. }
  200273. - (int) readPosition
  200274. {
  200275. return position;
  200276. }
  200277. - (int) read: (char*) dest numBytes: (int) numNeeded
  200278. {
  200279. int numDone = 0;
  200280. while (numNeeded > 0)
  200281. {
  200282. int available = jmin (numNeeded, (int) [data length]);
  200283. if (available > 0)
  200284. {
  200285. [dataLock lock];
  200286. [data getBytes: dest length: available];
  200287. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200288. [dataLock unlock];
  200289. numDone += available;
  200290. numNeeded -= available;
  200291. dest += available;
  200292. }
  200293. else
  200294. {
  200295. if (hasFailed || hasFinished)
  200296. break;
  200297. Thread::sleep (1);
  200298. }
  200299. }
  200300. position += numDone;
  200301. return numDone;
  200302. }
  200303. - (void) stop
  200304. {
  200305. [connection cancel];
  200306. runLoopThread->stopThread (10000);
  200307. }
  200308. @end
  200309. BEGIN_JUCE_NAMESPACE
  200310. bool juce_isOnLine()
  200311. {
  200312. return true;
  200313. }
  200314. void* juce_openInternetFile (const String& url,
  200315. const String& headers,
  200316. const MemoryBlock& postData,
  200317. const bool isPost,
  200318. URL::OpenStreamProgressCallback* callback,
  200319. void* callbackContext,
  200320. int timeOutMs)
  200321. {
  200322. const ScopedAutoReleasePool pool;
  200323. NSMutableURLRequest* req = [NSMutableURLRequest
  200324. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200325. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200326. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200327. if (req == nil)
  200328. return 0;
  200329. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200330. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200331. StringArray headerLines;
  200332. headerLines.addLines (headers);
  200333. headerLines.removeEmptyStrings (true);
  200334. for (int i = 0; i < headerLines.size(); ++i)
  200335. {
  200336. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200337. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200338. if (key.isNotEmpty() && value.isNotEmpty())
  200339. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200340. }
  200341. if (isPost && postData.getSize() > 0)
  200342. {
  200343. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200344. length: postData.getSize()]];
  200345. }
  200346. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200347. withCallback: callback
  200348. withContext: callbackContext];
  200349. if ([s isOpen])
  200350. return s;
  200351. [s release];
  200352. return 0;
  200353. }
  200354. void juce_closeInternetFile (void* handle)
  200355. {
  200356. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200357. if (s != 0)
  200358. {
  200359. const ScopedAutoReleasePool pool;
  200360. [s stop];
  200361. [s release];
  200362. }
  200363. }
  200364. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200365. {
  200366. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200367. if (s != 0)
  200368. {
  200369. const ScopedAutoReleasePool pool;
  200370. return [s read: (char*) buffer numBytes: bytesToRead];
  200371. }
  200372. return 0;
  200373. }
  200374. int64 juce_getInternetFileContentLength (void* handle)
  200375. {
  200376. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200377. if (s != 0)
  200378. return s->contentLength;
  200379. return -1;
  200380. }
  200381. int juce_seekInInternetFile (void* handle, int newPosition)
  200382. {
  200383. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200384. if (s != 0)
  200385. return [s readPosition];
  200386. return 0;
  200387. }
  200388. #endif
  200389. /*** End of inlined file: juce_mac_Network.mm ***/
  200390. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200391. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200392. // compiled on its own).
  200393. #if JUCE_INCLUDED_FILE
  200394. struct NamedPipeInternal
  200395. {
  200396. String pipeInName, pipeOutName;
  200397. int pipeIn, pipeOut;
  200398. bool volatile createdPipe, blocked, stopReadOperation;
  200399. static void signalHandler (int) {}
  200400. };
  200401. void NamedPipe::cancelPendingReads()
  200402. {
  200403. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200404. {
  200405. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200406. intern->stopReadOperation = true;
  200407. char buffer [1] = { 0 };
  200408. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200409. (void) bytesWritten;
  200410. int timeout = 2000;
  200411. while (intern->blocked && --timeout >= 0)
  200412. Thread::sleep (2);
  200413. intern->stopReadOperation = false;
  200414. }
  200415. }
  200416. void NamedPipe::close()
  200417. {
  200418. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200419. if (intern != 0)
  200420. {
  200421. internal = 0;
  200422. if (intern->pipeIn != -1)
  200423. ::close (intern->pipeIn);
  200424. if (intern->pipeOut != -1)
  200425. ::close (intern->pipeOut);
  200426. if (intern->createdPipe)
  200427. {
  200428. unlink (intern->pipeInName.toUTF8());
  200429. unlink (intern->pipeOutName.toUTF8());
  200430. }
  200431. delete intern;
  200432. }
  200433. }
  200434. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200435. {
  200436. close();
  200437. NamedPipeInternal* const intern = new NamedPipeInternal();
  200438. internal = intern;
  200439. intern->createdPipe = createPipe;
  200440. intern->blocked = false;
  200441. intern->stopReadOperation = false;
  200442. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200443. siginterrupt (SIGPIPE, 1);
  200444. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200445. intern->pipeInName = pipePath + T("_in");
  200446. intern->pipeOutName = pipePath + T("_out");
  200447. intern->pipeIn = -1;
  200448. intern->pipeOut = -1;
  200449. if (createPipe)
  200450. {
  200451. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200452. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200453. {
  200454. delete intern;
  200455. internal = 0;
  200456. return false;
  200457. }
  200458. }
  200459. return true;
  200460. }
  200461. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200462. {
  200463. int bytesRead = -1;
  200464. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200465. if (intern != 0)
  200466. {
  200467. intern->blocked = true;
  200468. if (intern->pipeIn == -1)
  200469. {
  200470. if (intern->createdPipe)
  200471. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200472. else
  200473. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200474. if (intern->pipeIn == -1)
  200475. {
  200476. intern->blocked = false;
  200477. return -1;
  200478. }
  200479. }
  200480. bytesRead = 0;
  200481. char* p = (char*) destBuffer;
  200482. while (bytesRead < maxBytesToRead)
  200483. {
  200484. const int bytesThisTime = maxBytesToRead - bytesRead;
  200485. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200486. if (numRead <= 0 || intern->stopReadOperation)
  200487. {
  200488. bytesRead = -1;
  200489. break;
  200490. }
  200491. bytesRead += numRead;
  200492. p += bytesRead;
  200493. }
  200494. intern->blocked = false;
  200495. }
  200496. return bytesRead;
  200497. }
  200498. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200499. {
  200500. int bytesWritten = -1;
  200501. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200502. if (intern != 0)
  200503. {
  200504. if (intern->pipeOut == -1)
  200505. {
  200506. if (intern->createdPipe)
  200507. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200508. else
  200509. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200510. if (intern->pipeOut == -1)
  200511. {
  200512. return -1;
  200513. }
  200514. }
  200515. const char* p = (const char*) sourceBuffer;
  200516. bytesWritten = 0;
  200517. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200518. while (bytesWritten < numBytesToWrite
  200519. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200520. {
  200521. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200522. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200523. if (numWritten <= 0)
  200524. {
  200525. bytesWritten = -1;
  200526. break;
  200527. }
  200528. bytesWritten += numWritten;
  200529. p += bytesWritten;
  200530. }
  200531. }
  200532. return bytesWritten;
  200533. }
  200534. #endif
  200535. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200536. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200537. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200538. // compiled on its own).
  200539. #if JUCE_INCLUDED_FILE
  200540. void JUCE_API juce_threadEntryPoint (void*);
  200541. void* threadEntryProc (void* userData)
  200542. {
  200543. const ScopedAutoReleasePool pool;
  200544. juce_threadEntryPoint (userData);
  200545. return 0;
  200546. }
  200547. void* juce_createThread (void* userData)
  200548. {
  200549. pthread_t handle = 0;
  200550. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200551. {
  200552. pthread_detach (handle);
  200553. return (void*) handle;
  200554. }
  200555. return 0;
  200556. }
  200557. void juce_killThread (void* handle)
  200558. {
  200559. if (handle != 0)
  200560. pthread_cancel ((pthread_t) handle);
  200561. }
  200562. void juce_setCurrentThreadName (const String& /*name*/)
  200563. {
  200564. }
  200565. bool juce_setThreadPriority (void* handle, int priority)
  200566. {
  200567. if (handle == 0)
  200568. handle = (void*) pthread_self();
  200569. struct sched_param param;
  200570. int policy;
  200571. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200572. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200573. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200574. }
  200575. Thread::ThreadID Thread::getCurrentThreadId()
  200576. {
  200577. return static_cast <ThreadID> (pthread_self());
  200578. }
  200579. void Thread::yield()
  200580. {
  200581. sched_yield();
  200582. }
  200583. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200584. {
  200585. // xxx
  200586. jassertfalse
  200587. }
  200588. bool Process::isForegroundProcess()
  200589. {
  200590. #if JUCE_MAC
  200591. return [NSApp isActive];
  200592. #else
  200593. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200594. #endif
  200595. }
  200596. void Process::raisePrivilege()
  200597. {
  200598. jassertfalse
  200599. }
  200600. void Process::lowerPrivilege()
  200601. {
  200602. jassertfalse
  200603. }
  200604. void Process::terminate()
  200605. {
  200606. exit (0);
  200607. }
  200608. void Process::setPriority (ProcessPriority p)
  200609. {
  200610. // xxx
  200611. }
  200612. #endif
  200613. /*** End of inlined file: juce_mac_Threads.mm ***/
  200614. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200615. CriticalSection::CriticalSection() throw()
  200616. {
  200617. pthread_mutexattr_t atts;
  200618. pthread_mutexattr_init (&atts);
  200619. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200620. pthread_mutex_init (&internal, &atts);
  200621. }
  200622. CriticalSection::~CriticalSection() throw()
  200623. {
  200624. pthread_mutex_destroy (&internal);
  200625. }
  200626. void CriticalSection::enter() const throw()
  200627. {
  200628. pthread_mutex_lock (&internal);
  200629. }
  200630. bool CriticalSection::tryEnter() const throw()
  200631. {
  200632. return pthread_mutex_trylock (&internal) == 0;
  200633. }
  200634. void CriticalSection::exit() const throw()
  200635. {
  200636. pthread_mutex_unlock (&internal);
  200637. }
  200638. struct EventStruct
  200639. {
  200640. pthread_cond_t condition;
  200641. pthread_mutex_t mutex;
  200642. bool triggered;
  200643. };
  200644. WaitableEvent::WaitableEvent() throw()
  200645. {
  200646. EventStruct* const es = new EventStruct();
  200647. es->triggered = false;
  200648. pthread_cond_init (&es->condition, 0);
  200649. pthread_mutex_init (&es->mutex, 0);
  200650. internal = es;
  200651. }
  200652. WaitableEvent::~WaitableEvent() throw()
  200653. {
  200654. EventStruct* const es = (EventStruct*) internal;
  200655. pthread_cond_destroy (&es->condition);
  200656. pthread_mutex_destroy (&es->mutex);
  200657. delete es;
  200658. }
  200659. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200660. {
  200661. EventStruct* const es = (EventStruct*) internal;
  200662. pthread_mutex_lock (&es->mutex);
  200663. if (timeOutMillisecs < 0)
  200664. {
  200665. while (! es->triggered)
  200666. pthread_cond_wait (&es->condition, &es->mutex);
  200667. }
  200668. else
  200669. {
  200670. while (! es->triggered)
  200671. {
  200672. struct timeval t;
  200673. gettimeofday (&t, 0);
  200674. struct timespec time;
  200675. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  200676. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200677. if (time.tv_nsec >= 1000000000)
  200678. {
  200679. time.tv_nsec -= 1000000000;
  200680. time.tv_sec++;
  200681. }
  200682. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  200683. {
  200684. pthread_mutex_unlock (&es->mutex);
  200685. return false;
  200686. }
  200687. }
  200688. }
  200689. es->triggered = false;
  200690. pthread_mutex_unlock (&es->mutex);
  200691. return true;
  200692. }
  200693. void WaitableEvent::signal() const throw()
  200694. {
  200695. EventStruct* const es = (EventStruct*) internal;
  200696. pthread_mutex_lock (&es->mutex);
  200697. es->triggered = true;
  200698. pthread_cond_broadcast (&es->condition);
  200699. pthread_mutex_unlock (&es->mutex);
  200700. }
  200701. void WaitableEvent::reset() const throw()
  200702. {
  200703. EventStruct* const es = (EventStruct*) internal;
  200704. pthread_mutex_lock (&es->mutex);
  200705. es->triggered = false;
  200706. pthread_mutex_unlock (&es->mutex);
  200707. }
  200708. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200709. {
  200710. struct timespec time;
  200711. time.tv_sec = millisecs / 1000;
  200712. time.tv_nsec = (millisecs % 1000) * 1000000;
  200713. nanosleep (&time, 0);
  200714. }
  200715. const tchar File::separator = T('/');
  200716. const tchar* File::separatorString = T("/");
  200717. const File File::getCurrentWorkingDirectory()
  200718. {
  200719. HeapBlock<char> heapBuffer;
  200720. char localBuffer [1024];
  200721. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200722. int bufferSize = 4096;
  200723. while (cwd == 0 && errno == ERANGE)
  200724. {
  200725. heapBuffer.malloc (bufferSize);
  200726. cwd = getcwd (heapBuffer, bufferSize - 1);
  200727. bufferSize += 1024;
  200728. }
  200729. return File (String::fromUTF8 (cwd));
  200730. }
  200731. bool File::setAsCurrentWorkingDirectory() const
  200732. {
  200733. return chdir (getFullPathName().toUTF8()) == 0;
  200734. }
  200735. bool juce_copyFile (const String& s, const String& d);
  200736. static bool juce_stat (const String& fileName, struct stat& info)
  200737. {
  200738. return fileName.isNotEmpty()
  200739. && (stat (fileName.toUTF8(), &info) == 0);
  200740. }
  200741. bool juce_isDirectory (const String& fileName)
  200742. {
  200743. struct stat info;
  200744. return fileName.isEmpty()
  200745. || (juce_stat (fileName, info)
  200746. && ((info.st_mode & S_IFDIR) != 0));
  200747. }
  200748. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200749. {
  200750. if (fileName.isEmpty())
  200751. return false;
  200752. const char* const fileNameUTF8 = fileName.toUTF8();
  200753. bool exists = access (fileNameUTF8, F_OK) == 0;
  200754. if (exists && dontCountDirectories)
  200755. {
  200756. struct stat info;
  200757. const int res = stat (fileNameUTF8, &info);
  200758. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200759. exists = false;
  200760. }
  200761. return exists;
  200762. }
  200763. int64 juce_getFileSize (const String& fileName)
  200764. {
  200765. struct stat info;
  200766. return juce_stat (fileName, info) ? info.st_size : 0;
  200767. }
  200768. bool juce_canWriteToFile (const String& fileName)
  200769. {
  200770. return access (fileName.toUTF8(), W_OK) == 0;
  200771. }
  200772. bool juce_deleteFile (const String& fileName)
  200773. {
  200774. if (juce_isDirectory (fileName))
  200775. return rmdir ((const char*) fileName.toUTF8()) == 0;
  200776. else
  200777. return remove ((const char*) fileName.toUTF8()) == 0;
  200778. }
  200779. bool juce_moveFile (const String& source, const String& dest)
  200780. {
  200781. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200782. return true;
  200783. if (juce_canWriteToFile (source)
  200784. && juce_copyFile (source, dest))
  200785. {
  200786. if (juce_deleteFile (source))
  200787. return true;
  200788. juce_deleteFile (dest);
  200789. }
  200790. return false;
  200791. }
  200792. void juce_createDirectory (const String& fileName)
  200793. {
  200794. mkdir (fileName.toUTF8(), 0777);
  200795. }
  200796. void* juce_fileOpen (const String& fileName, bool forWriting)
  200797. {
  200798. int flags = O_RDONLY;
  200799. if (forWriting)
  200800. {
  200801. if (juce_fileExists (fileName, false))
  200802. {
  200803. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  200804. if (f != -1)
  200805. lseek (f, 0, SEEK_END);
  200806. return (void*) f;
  200807. }
  200808. else
  200809. {
  200810. flags = O_RDWR + O_CREAT;
  200811. }
  200812. }
  200813. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  200814. }
  200815. void juce_fileClose (void* handle)
  200816. {
  200817. if (handle != 0)
  200818. close ((int) (pointer_sized_int) handle);
  200819. }
  200820. int juce_fileRead (void* handle, void* buffer, int size)
  200821. {
  200822. if (handle != 0)
  200823. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  200824. return 0;
  200825. }
  200826. int juce_fileWrite (void* handle, const void* buffer, int size)
  200827. {
  200828. if (handle != 0)
  200829. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200830. return 0;
  200831. }
  200832. int64 juce_fileSetPosition (void* handle, int64 pos)
  200833. {
  200834. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200835. return pos;
  200836. return -1;
  200837. }
  200838. int64 juce_fileGetPosition (void* handle)
  200839. {
  200840. if (handle != 0)
  200841. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200842. else
  200843. return -1;
  200844. }
  200845. void juce_fileFlush (void* handle)
  200846. {
  200847. if (handle != 0)
  200848. fsync ((int) (pointer_sized_int) handle);
  200849. }
  200850. const File juce_getExecutableFile()
  200851. {
  200852. Dl_info exeInfo;
  200853. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200854. return File (String::fromUTF8 (exeInfo.dli_fname));
  200855. }
  200856. // if this file doesn't exist, find a parent of it that does..
  200857. static bool doStatFS (const File* file, struct statfs& result)
  200858. {
  200859. File f (*file);
  200860. for (int i = 5; --i >= 0;)
  200861. {
  200862. if (f.exists())
  200863. break;
  200864. f = f.getParentDirectory();
  200865. }
  200866. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200867. }
  200868. int64 File::getBytesFreeOnVolume() const
  200869. {
  200870. struct statfs buf;
  200871. if (doStatFS (this, buf))
  200872. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200873. return 0;
  200874. }
  200875. int64 File::getVolumeTotalSize() const
  200876. {
  200877. struct statfs buf;
  200878. if (doStatFS (this, buf))
  200879. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200880. return 0;
  200881. }
  200882. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200883. int& volumeSerialNumber)
  200884. {
  200885. volumeSerialNumber = 0;
  200886. #if JUCE_MAC
  200887. struct VolAttrBuf
  200888. {
  200889. u_int32_t length;
  200890. attrreference_t mountPointRef;
  200891. char mountPointSpace [MAXPATHLEN];
  200892. } attrBuf;
  200893. struct attrlist attrList;
  200894. zerostruct (attrList);
  200895. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200896. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200897. File f (filenameOnVolume);
  200898. for (;;)
  200899. {
  200900. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  200901. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200902. {
  200903. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200904. (int) attrBuf.mountPointRef.attr_length);
  200905. }
  200906. const File parent (f.getParentDirectory());
  200907. if (f == parent)
  200908. break;
  200909. f = parent;
  200910. }
  200911. #endif
  200912. return String::empty;
  200913. }
  200914. void juce_runSystemCommand (const String& command)
  200915. {
  200916. int result = system ((const char*) command.toUTF8());
  200917. (void) result;
  200918. }
  200919. const String juce_getOutputFromCommand (const String& command)
  200920. {
  200921. // slight bodge here, as we just pipe the output into a temp file and read it...
  200922. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  200923. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  200924. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  200925. String result (tempFile.loadFileAsString());
  200926. tempFile.deleteFile();
  200927. return result;
  200928. }
  200929. InterProcessLock::InterProcessLock (const String& name_)
  200930. : internal (0),
  200931. name (name_),
  200932. reentrancyLevel (0)
  200933. {
  200934. #if JUCE_MAC
  200935. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  200936. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  200937. #else
  200938. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  200939. #endif
  200940. temp.create();
  200941. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  200942. }
  200943. InterProcessLock::~InterProcessLock()
  200944. {
  200945. while (reentrancyLevel > 0)
  200946. this->exit();
  200947. close (internal);
  200948. }
  200949. bool InterProcessLock::enter (const int timeOutMillisecs)
  200950. {
  200951. if (internal == 0)
  200952. return false;
  200953. if (reentrancyLevel != 0)
  200954. return true;
  200955. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  200956. struct flock fl;
  200957. zerostruct (fl);
  200958. fl.l_whence = SEEK_SET;
  200959. fl.l_type = F_WRLCK;
  200960. for (;;)
  200961. {
  200962. const int result = fcntl (internal, F_SETLK, &fl);
  200963. if (result >= 0)
  200964. {
  200965. ++reentrancyLevel;
  200966. return true;
  200967. }
  200968. if (errno != EINTR)
  200969. {
  200970. if (timeOutMillisecs == 0
  200971. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  200972. break;
  200973. Thread::sleep (10);
  200974. }
  200975. }
  200976. return false;
  200977. }
  200978. void InterProcessLock::exit()
  200979. {
  200980. if (reentrancyLevel > 0 && internal != 0)
  200981. {
  200982. --reentrancyLevel;
  200983. struct flock fl;
  200984. zerostruct (fl);
  200985. fl.l_whence = SEEK_SET;
  200986. fl.l_type = F_UNLCK;
  200987. for (;;)
  200988. {
  200989. const int result = fcntl (internal, F_SETLKW, &fl);
  200990. if (result >= 0 || errno != EINTR)
  200991. break;
  200992. }
  200993. }
  200994. }
  200995. /*** End of inlined file: juce_posix_SharedCode.h ***/
  200996. /*** Start of inlined file: juce_mac_Files.mm ***/
  200997. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200998. // compiled on its own).
  200999. #if JUCE_INCLUDED_FILE
  201000. void juce_getFileTimes (const String& fileName,
  201001. int64& modificationTime,
  201002. int64& accessTime,
  201003. int64& creationTime)
  201004. {
  201005. modificationTime = 0;
  201006. accessTime = 0;
  201007. creationTime = 0;
  201008. struct stat info;
  201009. const int res = stat (fileName.toUTF8(), &info);
  201010. if (res == 0)
  201011. {
  201012. modificationTime = (int64) info.st_mtime * 1000;
  201013. accessTime = (int64) info.st_atime * 1000;
  201014. creationTime = (int64) info.st_ctime * 1000;
  201015. }
  201016. }
  201017. bool juce_setFileTimes (const String& fileName,
  201018. int64 modificationTime,
  201019. int64 accessTime,
  201020. int64 creationTime)
  201021. {
  201022. struct utimbuf times;
  201023. times.actime = (time_t) (accessTime / 1000);
  201024. times.modtime = (time_t) (modificationTime / 1000);
  201025. return utime (fileName.toUTF8(), &times) == 0;
  201026. }
  201027. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  201028. {
  201029. struct stat info;
  201030. const int res = stat (fileName.toUTF8(), &info);
  201031. if (res != 0)
  201032. return false;
  201033. info.st_mode &= 0777; // Just permissions
  201034. if (isReadOnly)
  201035. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201036. else
  201037. // Give everybody write permission?
  201038. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201039. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201040. }
  201041. bool juce_copyFile (const String& src, const String& dst)
  201042. {
  201043. const ScopedAutoReleasePool pool;
  201044. NSFileManager* fm = [NSFileManager defaultManager];
  201045. return [fm fileExistsAtPath: juceStringToNS (src)]
  201046. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201047. && [fm copyItemAtPath: juceStringToNS (src)
  201048. toPath: juceStringToNS (dst)
  201049. error: nil];
  201050. #else
  201051. && [fm copyPath: juceStringToNS (src)
  201052. toPath: juceStringToNS (dst)
  201053. handler: nil];
  201054. #endif
  201055. }
  201056. const StringArray juce_getFileSystemRoots()
  201057. {
  201058. StringArray s;
  201059. s.add (T("/"));
  201060. return s;
  201061. }
  201062. static bool isFileOnDriveType (const File* const f, const char** types)
  201063. {
  201064. struct statfs buf;
  201065. if (doStatFS (f, buf))
  201066. {
  201067. const String type (buf.f_fstypename);
  201068. while (*types != 0)
  201069. if (type.equalsIgnoreCase (*types++))
  201070. return true;
  201071. }
  201072. return false;
  201073. }
  201074. bool File::isOnCDRomDrive() const
  201075. {
  201076. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201077. return isFileOnDriveType (this, (const char**) cdTypes);
  201078. }
  201079. bool File::isOnHardDisk() const
  201080. {
  201081. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201082. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201083. }
  201084. bool File::isOnRemovableDrive() const
  201085. {
  201086. #if JUCE_IPHONE
  201087. return false; // xxx is this possible?
  201088. #else
  201089. const ScopedAutoReleasePool pool;
  201090. BOOL removable = false;
  201091. [[NSWorkspace sharedWorkspace]
  201092. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201093. isRemovable: &removable
  201094. isWritable: nil
  201095. isUnmountable: nil
  201096. description: nil
  201097. type: nil];
  201098. return removable;
  201099. #endif
  201100. }
  201101. static bool juce_isHiddenFile (const String& path)
  201102. {
  201103. #if JUCE_IPHONE
  201104. return File (path).getFileName().startsWithChar (T('.'));
  201105. #else
  201106. FSRef ref;
  201107. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201108. return false;
  201109. FSCatalogInfo info;
  201110. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201111. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201112. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201113. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201114. #endif
  201115. }
  201116. bool File::isHidden() const
  201117. {
  201118. return juce_isHiddenFile (getFullPathName());
  201119. }
  201120. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201121. const File File::getSpecialLocation (const SpecialLocationType type)
  201122. {
  201123. const ScopedAutoReleasePool pool;
  201124. String resultPath;
  201125. switch (type)
  201126. {
  201127. case userHomeDirectory:
  201128. resultPath = nsStringToJuce (NSHomeDirectory());
  201129. break;
  201130. case userDocumentsDirectory:
  201131. resultPath = "~/Documents";
  201132. break;
  201133. case userDesktopDirectory:
  201134. resultPath = "~/Desktop";
  201135. break;
  201136. case userApplicationDataDirectory:
  201137. resultPath = "~/Library";
  201138. break;
  201139. case commonApplicationDataDirectory:
  201140. resultPath = "/Library";
  201141. break;
  201142. case globalApplicationsDirectory:
  201143. resultPath = "/Applications";
  201144. break;
  201145. case userMusicDirectory:
  201146. resultPath = "~/Music";
  201147. break;
  201148. case userMoviesDirectory:
  201149. resultPath = "~/Movies";
  201150. break;
  201151. case tempDirectory:
  201152. {
  201153. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201154. tmp.createDirectory();
  201155. return tmp.getFullPathName();
  201156. }
  201157. case invokedExecutableFile:
  201158. if (juce_Argv0 != 0)
  201159. return File (String::fromUTF8 (juce_Argv0));
  201160. // deliberate fall-through...
  201161. case currentExecutableFile:
  201162. return juce_getExecutableFile();
  201163. case currentApplicationFile:
  201164. {
  201165. const File exe (juce_getExecutableFile());
  201166. const File parent (exe.getParentDirectory());
  201167. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201168. ? parent.getParentDirectory().getParentDirectory()
  201169. : exe;
  201170. }
  201171. default:
  201172. jassertfalse // unknown type?
  201173. break;
  201174. }
  201175. if (resultPath.isNotEmpty())
  201176. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201177. return File::nonexistent;
  201178. }
  201179. const String File::getVersion() const
  201180. {
  201181. const ScopedAutoReleasePool pool;
  201182. String result;
  201183. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201184. if (bundle != 0)
  201185. {
  201186. NSDictionary* info = [bundle infoDictionary];
  201187. if (info != 0)
  201188. {
  201189. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201190. if (name != nil)
  201191. result = nsStringToJuce (name);
  201192. }
  201193. }
  201194. return result;
  201195. }
  201196. const File File::getLinkedTarget() const
  201197. {
  201198. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201199. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201200. #else
  201201. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201202. #endif
  201203. if (dest != nil)
  201204. return File (nsStringToJuce (dest));
  201205. return *this;
  201206. }
  201207. bool File::moveToTrash() const
  201208. {
  201209. if (! exists())
  201210. return true;
  201211. #if JUCE_IPHONE
  201212. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201213. #else
  201214. const ScopedAutoReleasePool pool;
  201215. NSString* p = juceStringToNS (getFullPathName());
  201216. return [[NSWorkspace sharedWorkspace]
  201217. performFileOperation: NSWorkspaceRecycleOperation
  201218. source: [p stringByDeletingLastPathComponent]
  201219. destination: @""
  201220. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201221. tag: nil ];
  201222. #endif
  201223. }
  201224. struct FindFileStruct
  201225. {
  201226. NSDirectoryEnumerator* enumerator;
  201227. String parentDir, wildCard;
  201228. };
  201229. bool juce_findFileNext (void* handle, String& resultFile,
  201230. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201231. {
  201232. ScopedAutoReleasePool pool;
  201233. FindFileStruct* ff = (FindFileStruct*) handle;
  201234. NSString* file;
  201235. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201236. for (;;)
  201237. {
  201238. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201239. return false;
  201240. [ff->enumerator skipDescendents];
  201241. resultFile = nsStringToJuce (file);
  201242. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201243. continue;
  201244. const String path (ff->parentDir + resultFile);
  201245. if (isDir != 0 || fileSize != 0)
  201246. {
  201247. struct stat info;
  201248. const bool statOk = juce_stat (path, info);
  201249. if (isDir != 0)
  201250. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201251. if (isHidden != 0)
  201252. *isHidden = juce_isHiddenFile (path);
  201253. if (fileSize != 0)
  201254. *fileSize = statOk ? info.st_size : 0;
  201255. }
  201256. if (modTime != 0 || creationTime != 0)
  201257. {
  201258. int64 m, a, c;
  201259. juce_getFileTimes (path, m, a, c);
  201260. if (modTime != 0)
  201261. *modTime = m;
  201262. if (creationTime != 0)
  201263. *creationTime = c;
  201264. }
  201265. if (isReadOnly != 0)
  201266. *isReadOnly = ! juce_canWriteToFile (path);
  201267. return true;
  201268. }
  201269. }
  201270. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201271. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201272. Time* creationTime, bool* isReadOnly)
  201273. {
  201274. ScopedAutoReleasePool pool;
  201275. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201276. if (e != 0)
  201277. {
  201278. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201279. ff->enumerator = [e retain];
  201280. ff->parentDir = directory;
  201281. ff->wildCard = wildCard;
  201282. if (! ff->parentDir.endsWithChar (File::separator))
  201283. ff->parentDir += File::separator;
  201284. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201285. return ff.release();
  201286. [e release];
  201287. }
  201288. return 0;
  201289. }
  201290. void juce_findFileClose (void* handle)
  201291. {
  201292. ScopedAutoReleasePool pool;
  201293. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201294. [ff->enumerator release];
  201295. }
  201296. bool juce_launchExecutable (const String& pathAndArguments)
  201297. {
  201298. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201299. const int cpid = fork();
  201300. if (cpid == 0)
  201301. {
  201302. // Child process
  201303. if (execve (argv[0], (char**) argv, 0) < 0)
  201304. exit (0);
  201305. }
  201306. else
  201307. {
  201308. if (cpid < 0)
  201309. return false;
  201310. }
  201311. return true;
  201312. }
  201313. bool juce_launchFile (const String& fileName, const String& parameters)
  201314. {
  201315. #if JUCE_IPHONE
  201316. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201317. #else
  201318. const ScopedAutoReleasePool pool;
  201319. if (parameters.isEmpty())
  201320. {
  201321. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201322. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201323. }
  201324. bool ok = false;
  201325. FSRef ref;
  201326. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201327. {
  201328. if (PlatformUtilities::isBundle (fileName))
  201329. {
  201330. NSMutableArray* urls = [NSMutableArray array];
  201331. StringArray docs;
  201332. docs.addTokens (parameters, true);
  201333. for (int i = 0; i < docs.size(); ++i)
  201334. [urls addObject: juceStringToNS (docs[i])];
  201335. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201336. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201337. options: 0
  201338. additionalEventParamDescriptor: nil
  201339. launchIdentifiers: nil];
  201340. }
  201341. else
  201342. {
  201343. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201344. }
  201345. }
  201346. return ok;
  201347. #endif
  201348. }
  201349. void File::revealToUser() const
  201350. {
  201351. #if ! JUCE_IPHONE
  201352. if (exists())
  201353. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201354. else if (getParentDirectory().exists())
  201355. getParentDirectory().revealToUser();
  201356. #endif
  201357. }
  201358. #if ! JUCE_IPHONE
  201359. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201360. {
  201361. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201362. }
  201363. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201364. {
  201365. char path [2048];
  201366. zerostruct (path);
  201367. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201368. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201369. return String::empty;
  201370. }
  201371. #endif
  201372. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201373. {
  201374. const ScopedAutoReleasePool pool;
  201375. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201376. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201377. #else
  201378. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201379. #endif
  201380. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201381. return [fileDict fileHFSTypeCode];
  201382. }
  201383. bool PlatformUtilities::isBundle (const String& filename)
  201384. {
  201385. #if JUCE_IPHONE
  201386. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201387. #else
  201388. const ScopedAutoReleasePool pool;
  201389. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201390. #endif
  201391. }
  201392. #endif
  201393. /*** End of inlined file: juce_mac_Files.mm ***/
  201394. #if JUCE_IPHONE
  201395. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201396. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201397. // compiled on its own).
  201398. #if JUCE_INCLUDED_FILE
  201399. static JUCEApplication* juce_intialisingApp;
  201400. END_JUCE_NAMESPACE
  201401. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201402. {
  201403. }
  201404. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201405. - (void) applicationWillResignActive: (UIApplication*) application;
  201406. @end
  201407. @implementation JuceAppStartupDelegate
  201408. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201409. {
  201410. String dummy;
  201411. if (! juce_intialisingApp->initialiseApp (dummy))
  201412. exit (0);
  201413. }
  201414. - (void) applicationWillResignActive: (UIApplication*) application
  201415. {
  201416. JUCEApplication::shutdownAppAndClearUp();
  201417. }
  201418. @end
  201419. BEGIN_JUCE_NAMESPACE
  201420. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201421. {
  201422. juce_intialisingApp = app;
  201423. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201424. }
  201425. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201426. {
  201427. pool = [[NSAutoreleasePool alloc] init];
  201428. }
  201429. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201430. {
  201431. [((NSAutoreleasePool*) pool) release];
  201432. }
  201433. void PlatformUtilities::beep()
  201434. {
  201435. //xxx
  201436. //AudioServicesPlaySystemSound ();
  201437. }
  201438. void PlatformUtilities::addItemToDock (const File& file)
  201439. {
  201440. }
  201441. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201442. END_JUCE_NAMESPACE
  201443. @interface JuceAlertBoxDelegate : NSObject
  201444. {
  201445. @public
  201446. bool clickedOk;
  201447. }
  201448. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201449. @end
  201450. @implementation JuceAlertBoxDelegate
  201451. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201452. {
  201453. clickedOk = (buttonIndex == 0);
  201454. alertView.hidden = true;
  201455. }
  201456. @end
  201457. BEGIN_JUCE_NAMESPACE
  201458. // (This function is used directly by other bits of code)
  201459. bool juce_iPhoneShowModalAlert (const String& title,
  201460. const String& bodyText,
  201461. NSString* okButtonText,
  201462. NSString* cancelButtonText)
  201463. {
  201464. const ScopedAutoReleasePool pool;
  201465. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201466. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201467. message: juceStringToNS (bodyText)
  201468. delegate: callback
  201469. cancelButtonTitle: okButtonText
  201470. otherButtonTitles: cancelButtonText, nil];
  201471. [alert retain];
  201472. [alert show];
  201473. while (! alert.hidden && alert.superview != nil)
  201474. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201475. const bool result = callback->clickedOk;
  201476. [alert release];
  201477. [callback release];
  201478. return result;
  201479. }
  201480. bool AlertWindow::showNativeDialogBox (const String& title,
  201481. const String& bodyText,
  201482. bool isOkCancel)
  201483. {
  201484. return juce_iPhoneShowModalAlert (title, bodyText,
  201485. @"OK",
  201486. isOkCancel ? @"Cancel" : nil);
  201487. }
  201488. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201489. {
  201490. jassertfalse // no such thing on the iphone!
  201491. return false;
  201492. }
  201493. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201494. {
  201495. jassertfalse // no such thing on the iphone!
  201496. return false;
  201497. }
  201498. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201499. {
  201500. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201501. }
  201502. bool Desktop::isScreenSaverEnabled() throw()
  201503. {
  201504. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201505. }
  201506. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201507. {
  201508. const ScopedAutoReleasePool pool;
  201509. monitorCoords.clear();
  201510. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201511. : [[UIScreen mainScreen] bounds];
  201512. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201513. (int) r.origin.y,
  201514. (int) r.size.width,
  201515. (int) r.size.height));
  201516. }
  201517. #endif
  201518. #endif
  201519. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201520. #else
  201521. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201522. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201523. // compiled on its own).
  201524. #if JUCE_INCLUDED_FILE
  201525. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201526. {
  201527. pool = [[NSAutoreleasePool alloc] init];
  201528. }
  201529. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201530. {
  201531. [((NSAutoreleasePool*) pool) release];
  201532. }
  201533. void PlatformUtilities::beep()
  201534. {
  201535. NSBeep();
  201536. }
  201537. void PlatformUtilities::addItemToDock (const File& file)
  201538. {
  201539. // check that it's not already there...
  201540. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201541. .containsIgnoreCase (file.getFullPathName()))
  201542. {
  201543. 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>"
  201544. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201545. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201546. }
  201547. }
  201548. int PlatformUtilities::getOSXMinorVersionNumber()
  201549. {
  201550. SInt32 versionMinor = 0;
  201551. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201552. (void) err;
  201553. jassert (err == noErr);
  201554. return (int) versionMinor;
  201555. }
  201556. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201557. bool AlertWindow::showNativeDialogBox (const String& title,
  201558. const String& bodyText,
  201559. bool isOkCancel)
  201560. {
  201561. const ScopedAutoReleasePool pool;
  201562. return NSRunAlertPanel (juceStringToNS (title),
  201563. juceStringToNS (bodyText),
  201564. @"Ok",
  201565. isOkCancel ? @"Cancel" : nil,
  201566. nil) == NSAlertDefaultReturn;
  201567. }
  201568. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201569. {
  201570. if (files.size() == 0)
  201571. return false;
  201572. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201573. if (draggingSource == 0)
  201574. {
  201575. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201576. return false;
  201577. }
  201578. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201579. if (sourceComp == 0)
  201580. {
  201581. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201582. return false;
  201583. }
  201584. const ScopedAutoReleasePool pool;
  201585. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201586. if (view == 0)
  201587. return false;
  201588. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201589. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201590. owner: nil];
  201591. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201592. for (int i = 0; i < files.size(); ++i)
  201593. [filesArray addObject: juceStringToNS (files[i])];
  201594. [pboard setPropertyList: filesArray
  201595. forType: NSFilenamesPboardType];
  201596. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201597. fromView: nil];
  201598. dragPosition.x -= 16;
  201599. dragPosition.y -= 16;
  201600. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201601. at: dragPosition
  201602. offset: NSMakeSize (0, 0)
  201603. event: [[view window] currentEvent]
  201604. pasteboard: pboard
  201605. source: view
  201606. slideBack: YES];
  201607. return true;
  201608. }
  201609. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201610. {
  201611. jassertfalse // not implemented!
  201612. return false;
  201613. }
  201614. bool Desktop::canUseSemiTransparentWindows() throw()
  201615. {
  201616. return true;
  201617. }
  201618. const Point<int> Desktop::getMousePosition()
  201619. {
  201620. const ScopedAutoReleasePool pool;
  201621. const NSPoint p ([NSEvent mouseLocation]);
  201622. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201623. }
  201624. void Desktop::setMousePosition (const Point<int>& newPosition)
  201625. {
  201626. // this rubbish needs to be done around the warp call, to avoid causing a
  201627. // bizarre glitch..
  201628. CGAssociateMouseAndMouseCursorPosition (false);
  201629. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201630. CGAssociateMouseAndMouseCursorPosition (true);
  201631. }
  201632. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201633. class ScreenSaverDefeater : public Timer,
  201634. public DeletedAtShutdown
  201635. {
  201636. public:
  201637. ScreenSaverDefeater() throw()
  201638. {
  201639. startTimer (10000);
  201640. timerCallback();
  201641. }
  201642. ~ScreenSaverDefeater() {}
  201643. void timerCallback()
  201644. {
  201645. if (Process::isForegroundProcess())
  201646. UpdateSystemActivity (UsrActivity);
  201647. }
  201648. };
  201649. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201650. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201651. {
  201652. if (isEnabled)
  201653. {
  201654. deleteAndZero (screenSaverDefeater);
  201655. }
  201656. else if (screenSaverDefeater == 0)
  201657. {
  201658. screenSaverDefeater = new ScreenSaverDefeater();
  201659. }
  201660. }
  201661. bool Desktop::isScreenSaverEnabled() throw()
  201662. {
  201663. return screenSaverDefeater == 0;
  201664. }
  201665. #else
  201666. static IOPMAssertionID screenSaverDisablerID = 0;
  201667. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201668. {
  201669. if (isEnabled)
  201670. {
  201671. if (screenSaverDisablerID != 0)
  201672. {
  201673. IOPMAssertionRelease (screenSaverDisablerID);
  201674. screenSaverDisablerID = 0;
  201675. }
  201676. }
  201677. else
  201678. {
  201679. if (screenSaverDisablerID == 0)
  201680. {
  201681. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201682. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201683. CFSTR ("Juce"), &screenSaverDisablerID);
  201684. #else
  201685. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201686. &screenSaverDisablerID);
  201687. #endif
  201688. }
  201689. }
  201690. }
  201691. bool Desktop::isScreenSaverEnabled() throw()
  201692. {
  201693. return screenSaverDisablerID == 0;
  201694. }
  201695. #endif
  201696. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201697. {
  201698. const ScopedAutoReleasePool pool;
  201699. monitorCoords.clear();
  201700. NSArray* screens = [NSScreen screens];
  201701. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201702. for (unsigned int i = 0; i < [screens count]; ++i)
  201703. {
  201704. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201705. NSRect r = clipToWorkArea ? [s visibleFrame]
  201706. : [s frame];
  201707. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201708. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201709. (int) r.size.width,
  201710. (int) r.size.height));
  201711. }
  201712. jassert (monitorCoords.size() > 0);
  201713. }
  201714. #endif
  201715. #endif
  201716. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201717. #endif
  201718. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201719. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201720. // compiled on its own).
  201721. #if JUCE_INCLUDED_FILE
  201722. void Logger::outputDebugString (const String& text) throw()
  201723. {
  201724. std::cerr << text << std::endl;
  201725. }
  201726. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201727. {
  201728. static char testResult = 0;
  201729. if (testResult == 0)
  201730. {
  201731. struct kinfo_proc info;
  201732. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201733. size_t sz = sizeof (info);
  201734. sysctl (m, 4, &info, &sz, 0, 0);
  201735. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201736. }
  201737. return testResult > 0;
  201738. }
  201739. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201740. {
  201741. return juce_isRunningUnderDebugger();
  201742. }
  201743. #endif
  201744. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201745. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201746. #if JUCE_IPHONE
  201747. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201748. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201749. // compiled on its own).
  201750. #if JUCE_INCLUDED_FILE
  201751. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201752. #define SUPPORT_10_4_FONTS 1
  201753. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201754. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201755. #define SUPPORT_ONLY_10_4_FONTS 1
  201756. #endif
  201757. END_JUCE_NAMESPACE
  201758. @interface NSFont (PrivateHack)
  201759. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201760. @end
  201761. BEGIN_JUCE_NAMESPACE
  201762. #endif
  201763. class MacTypeface : public Typeface
  201764. {
  201765. public:
  201766. MacTypeface (const Font& font)
  201767. : Typeface (font.getTypefaceName())
  201768. {
  201769. const ScopedAutoReleasePool pool;
  201770. renderingTransform = CGAffineTransformIdentity;
  201771. bool needsItalicTransform = false;
  201772. #if JUCE_IPHONE
  201773. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201774. if (font.isItalic() || font.isBold())
  201775. {
  201776. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201777. for (NSString* i in familyFonts)
  201778. {
  201779. const String fn (nsStringToJuce (i));
  201780. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  201781. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  201782. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  201783. || afterDash.containsIgnoreCase (T("italic"))
  201784. || fn.endsWithIgnoreCase (T("oblique"))
  201785. || fn.endsWithIgnoreCase (T("italic"));
  201786. if (probablyBold == font.isBold()
  201787. && probablyItalic == font.isItalic())
  201788. {
  201789. fontName = i;
  201790. needsItalicTransform = false;
  201791. break;
  201792. }
  201793. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201794. {
  201795. fontName = i;
  201796. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201797. }
  201798. }
  201799. if (needsItalicTransform)
  201800. renderingTransform.c = 0.15f;
  201801. }
  201802. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201803. const int ascender = abs (CGFontGetAscent (fontRef));
  201804. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201805. ascent = ascender / totalHeight;
  201806. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201807. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201808. #else
  201809. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201810. if (font.isItalic())
  201811. {
  201812. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201813. toHaveTrait: NSItalicFontMask];
  201814. if (newFont == nsFont)
  201815. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201816. nsFont = newFont;
  201817. }
  201818. if (font.isBold())
  201819. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201820. [nsFont retain];
  201821. ascent = fabsf ((float) [nsFont ascender]);
  201822. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201823. ascent /= totalSize;
  201824. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201825. if (needsItalicTransform)
  201826. {
  201827. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201828. renderingTransform.c = 0.15f;
  201829. }
  201830. #if SUPPORT_ONLY_10_4_FONTS
  201831. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201832. if (atsFont == 0)
  201833. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201834. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201835. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201836. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201837. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201838. #else
  201839. #if SUPPORT_10_4_FONTS
  201840. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201841. {
  201842. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201843. if (atsFont == 0)
  201844. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201845. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201846. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201847. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201848. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201849. }
  201850. else
  201851. #endif
  201852. {
  201853. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201854. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201855. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201856. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201857. }
  201858. #endif
  201859. #endif
  201860. }
  201861. ~MacTypeface()
  201862. {
  201863. #if ! JUCE_IPHONE
  201864. [nsFont release];
  201865. #endif
  201866. if (fontRef != 0)
  201867. CGFontRelease (fontRef);
  201868. }
  201869. float getAscent() const
  201870. {
  201871. return ascent;
  201872. }
  201873. float getDescent() const
  201874. {
  201875. return 1.0f - ascent;
  201876. }
  201877. float getStringWidth (const String& text)
  201878. {
  201879. if (fontRef == 0 || text.isEmpty())
  201880. return 0;
  201881. const int length = text.length();
  201882. HeapBlock <CGGlyph> glyphs;
  201883. createGlyphsForString (text, length, glyphs);
  201884. float x = 0;
  201885. #if SUPPORT_ONLY_10_4_FONTS
  201886. HeapBlock <NSSize> advances (length);
  201887. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201888. for (int i = 0; i < length; ++i)
  201889. x += advances[i].width;
  201890. #else
  201891. #if SUPPORT_10_4_FONTS
  201892. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201893. {
  201894. HeapBlock <NSSize> advances (length);
  201895. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201896. for (int i = 0; i < length; ++i)
  201897. x += advances[i].width;
  201898. }
  201899. else
  201900. #endif
  201901. {
  201902. HeapBlock <int> advances (length);
  201903. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201904. for (int i = 0; i < length; ++i)
  201905. x += advances[i];
  201906. }
  201907. #endif
  201908. return x * unitsToHeightScaleFactor;
  201909. }
  201910. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  201911. {
  201912. xOffsets.add (0);
  201913. if (fontRef == 0 || text.isEmpty())
  201914. return;
  201915. const int length = text.length();
  201916. HeapBlock <CGGlyph> glyphs;
  201917. createGlyphsForString (text, length, glyphs);
  201918. #if SUPPORT_ONLY_10_4_FONTS
  201919. HeapBlock <NSSize> advances (length);
  201920. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201921. int x = 0;
  201922. for (int i = 0; i < length; ++i)
  201923. {
  201924. x += advances[i].width;
  201925. xOffsets.add (x * unitsToHeightScaleFactor);
  201926. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  201927. }
  201928. #else
  201929. #if SUPPORT_10_4_FONTS
  201930. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201931. {
  201932. HeapBlock <NSSize> advances (length);
  201933. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201934. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  201935. float x = 0;
  201936. for (int i = 0; i < length; ++i)
  201937. {
  201938. x += advances[i].width;
  201939. xOffsets.add (x * unitsToHeightScaleFactor);
  201940. resultGlyphs.add (nsGlyphs[i]);
  201941. }
  201942. }
  201943. else
  201944. #endif
  201945. {
  201946. HeapBlock <int> advances (length);
  201947. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201948. {
  201949. int x = 0;
  201950. for (int i = 0; i < length; ++i)
  201951. {
  201952. x += advances [i];
  201953. xOffsets.add (x * unitsToHeightScaleFactor);
  201954. resultGlyphs.add (glyphs[i]);
  201955. }
  201956. }
  201957. }
  201958. #endif
  201959. }
  201960. bool getOutlineForGlyph (int glyphNumber, Path& path)
  201961. {
  201962. #if JUCE_IPHONE
  201963. return false;
  201964. #else
  201965. if (nsFont == 0)
  201966. return false;
  201967. // we might need to apply a transform to the path, so it mustn't have anything else in it
  201968. jassert (path.isEmpty());
  201969. const ScopedAutoReleasePool pool;
  201970. NSBezierPath* bez = [NSBezierPath bezierPath];
  201971. [bez moveToPoint: NSMakePoint (0, 0)];
  201972. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  201973. inFont: nsFont];
  201974. for (int i = 0; i < [bez elementCount]; ++i)
  201975. {
  201976. NSPoint p[3];
  201977. switch ([bez elementAtIndex: i associatedPoints: p])
  201978. {
  201979. case NSMoveToBezierPathElement:
  201980. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  201981. break;
  201982. case NSLineToBezierPathElement:
  201983. path.lineTo ((float) p[0].x, (float) -p[0].y);
  201984. break;
  201985. case NSCurveToBezierPathElement:
  201986. 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);
  201987. break;
  201988. case NSClosePathBezierPathElement:
  201989. path.closeSubPath();
  201990. break;
  201991. default:
  201992. jassertfalse
  201993. break;
  201994. }
  201995. }
  201996. path.applyTransform (pathTransform);
  201997. return true;
  201998. #endif
  201999. }
  202000. juce_UseDebuggingNewOperator
  202001. CGFontRef fontRef;
  202002. float fontHeightToCGSizeFactor;
  202003. CGAffineTransform renderingTransform;
  202004. private:
  202005. float ascent, unitsToHeightScaleFactor;
  202006. #if JUCE_IPHONE
  202007. #else
  202008. NSFont* nsFont;
  202009. AffineTransform pathTransform;
  202010. #endif
  202011. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  202012. {
  202013. #if SUPPORT_10_4_FONTS
  202014. #if ! SUPPORT_ONLY_10_4_FONTS
  202015. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202016. #endif
  202017. {
  202018. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  202019. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  202020. for (int i = 0; i < length; ++i)
  202021. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  202022. return;
  202023. }
  202024. #endif
  202025. #if ! SUPPORT_ONLY_10_4_FONTS
  202026. if (charToGlyphMapper == 0)
  202027. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  202028. glyphs.malloc (length);
  202029. for (int i = 0; i < length; ++i)
  202030. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202031. #endif
  202032. }
  202033. #if ! SUPPORT_ONLY_10_4_FONTS
  202034. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202035. class CharToGlyphMapper
  202036. {
  202037. public:
  202038. CharToGlyphMapper (CGFontRef fontRef)
  202039. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202040. idRangeOffset (0), glyphIndexes (0)
  202041. {
  202042. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202043. if (cmapTable != 0)
  202044. {
  202045. const int numSubtables = getValue16 (cmapTable, 2);
  202046. for (int i = 0; i < numSubtables; ++i)
  202047. {
  202048. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202049. {
  202050. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202051. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202052. {
  202053. const int length = getValue16 (cmapTable, offset + 2);
  202054. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202055. segCount = segCountX2 / 2;
  202056. const int endCodeOffset = offset + 14;
  202057. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202058. const int idDeltaOffset = startCodeOffset + segCountX2;
  202059. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202060. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202061. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202062. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202063. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202064. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202065. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202066. }
  202067. break;
  202068. }
  202069. }
  202070. CFRelease (cmapTable);
  202071. }
  202072. }
  202073. ~CharToGlyphMapper()
  202074. {
  202075. if (endCode != 0)
  202076. {
  202077. CFRelease (endCode);
  202078. CFRelease (startCode);
  202079. CFRelease (idDelta);
  202080. CFRelease (idRangeOffset);
  202081. CFRelease (glyphIndexes);
  202082. }
  202083. }
  202084. int getGlyphForCharacter (const juce_wchar c) const
  202085. {
  202086. for (int i = 0; i < segCount; ++i)
  202087. {
  202088. if (getValue16 (endCode, i * 2) >= c)
  202089. {
  202090. const int start = getValue16 (startCode, i * 2);
  202091. if (start > c)
  202092. break;
  202093. const int delta = getValue16 (idDelta, i * 2);
  202094. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202095. if (rangeOffset == 0)
  202096. return delta + c;
  202097. else
  202098. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202099. }
  202100. }
  202101. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202102. return jmax (-1, c - 29);
  202103. }
  202104. private:
  202105. int segCount;
  202106. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202107. static uint16 getValue16 (CFDataRef data, const int index)
  202108. {
  202109. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202110. }
  202111. static uint32 getValue32 (CFDataRef data, const int index)
  202112. {
  202113. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202114. }
  202115. };
  202116. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202117. #endif
  202118. MacTypeface (const MacTypeface&);
  202119. MacTypeface& operator= (const MacTypeface&);
  202120. };
  202121. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202122. {
  202123. return new MacTypeface (font);
  202124. }
  202125. const StringArray Font::findAllTypefaceNames() throw()
  202126. {
  202127. StringArray names;
  202128. const ScopedAutoReleasePool pool;
  202129. #if JUCE_IPHONE
  202130. NSArray* fonts = [UIFont familyNames];
  202131. #else
  202132. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202133. #endif
  202134. for (unsigned int i = 0; i < [fonts count]; ++i)
  202135. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202136. names.sort (true);
  202137. return names;
  202138. }
  202139. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202140. {
  202141. #if JUCE_IPHONE
  202142. defaultSans = "Helvetica";
  202143. defaultSerif = "Times New Roman";
  202144. defaultFixed = "Courier New";
  202145. #else
  202146. defaultSans = "Lucida Grande";
  202147. defaultSerif = "Times New Roman";
  202148. defaultFixed = "Monaco";
  202149. #endif
  202150. }
  202151. #endif
  202152. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202153. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202154. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202155. // compiled on its own).
  202156. #if JUCE_INCLUDED_FILE
  202157. class CoreGraphicsImage : public Image
  202158. {
  202159. public:
  202160. CoreGraphicsImage (const PixelFormat format_,
  202161. const int imageWidth_,
  202162. const int imageHeight_,
  202163. const bool clearImage)
  202164. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202165. {
  202166. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  202167. : CGColorSpaceCreateDeviceRGB();
  202168. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202169. colourSpace, getCGImageFlags (*this));
  202170. CGColorSpaceRelease (colourSpace);
  202171. }
  202172. ~CoreGraphicsImage()
  202173. {
  202174. CGContextRelease (context);
  202175. }
  202176. LowLevelGraphicsContext* createLowLevelContext();
  202177. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202178. {
  202179. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202180. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202181. {
  202182. return CGBitmapContextCreateImage (nativeImage->context);
  202183. }
  202184. else
  202185. {
  202186. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202187. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202188. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202189. 8, srcData.pixelStride * 8, srcData.lineStride,
  202190. colourSpace, getCGImageFlags (juceImage), provider,
  202191. 0, true, kCGRenderingIntentDefault);
  202192. CGDataProviderRelease (provider);
  202193. return imageRef;
  202194. }
  202195. }
  202196. #if JUCE_MAC
  202197. static NSImage* createNSImage (const Image& image)
  202198. {
  202199. const ScopedAutoReleasePool pool;
  202200. NSImage* im = [[NSImage alloc] init];
  202201. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202202. [im lockFocus];
  202203. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202204. CGImageRef imageRef = createImage (image, false, colourSpace);
  202205. CGColorSpaceRelease (colourSpace);
  202206. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202207. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202208. CGImageRelease (imageRef);
  202209. [im unlockFocus];
  202210. return im;
  202211. }
  202212. #endif
  202213. CGContextRef context;
  202214. private:
  202215. static CGBitmapInfo getCGImageFlags (const Image& image)
  202216. {
  202217. #if JUCE_BIG_ENDIAN
  202218. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202219. #else
  202220. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202221. #endif
  202222. }
  202223. };
  202224. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202225. {
  202226. #if USE_COREGRAPHICS_RENDERING
  202227. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202228. #else
  202229. return new Image (format, imageWidth, imageHeight, clearImage);
  202230. #endif
  202231. }
  202232. class CoreGraphicsContext : public LowLevelGraphicsContext
  202233. {
  202234. public:
  202235. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202236. : context (context_),
  202237. flipHeight (flipHeight_),
  202238. state (new SavedState()),
  202239. numGradientLookupEntries (0)
  202240. {
  202241. CGContextRetain (context);
  202242. CGContextSaveGState(context);
  202243. CGContextSetShouldSmoothFonts (context, true);
  202244. CGContextSetShouldAntialias (context, true);
  202245. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202246. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202247. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202248. gradientCallbacks.version = 0;
  202249. gradientCallbacks.evaluate = gradientCallback;
  202250. gradientCallbacks.releaseInfo = 0;
  202251. setFont (Font());
  202252. }
  202253. ~CoreGraphicsContext()
  202254. {
  202255. CGContextRestoreGState (context);
  202256. CGContextRelease (context);
  202257. CGColorSpaceRelease (rgbColourSpace);
  202258. CGColorSpaceRelease (greyColourSpace);
  202259. }
  202260. bool isVectorDevice() const { return false; }
  202261. void setOrigin (int x, int y)
  202262. {
  202263. CGContextTranslateCTM (context, x, -y);
  202264. }
  202265. bool clipToRectangle (const Rectangle<int>& r)
  202266. {
  202267. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202268. return ! isClipEmpty();
  202269. }
  202270. bool clipToRectangleList (const RectangleList& clipRegion)
  202271. {
  202272. if (clipRegion.isEmpty())
  202273. {
  202274. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202275. return false;
  202276. }
  202277. else
  202278. {
  202279. const int numRects = clipRegion.getNumRectangles();
  202280. HeapBlock <CGRect> rects (numRects);
  202281. for (int i = 0; i < numRects; ++i)
  202282. {
  202283. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202284. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202285. }
  202286. CGContextClipToRects (context, rects, numRects);
  202287. return ! isClipEmpty();
  202288. }
  202289. }
  202290. void excludeClipRectangle (const Rectangle<int>& r)
  202291. {
  202292. RectangleList remaining (getClipBounds());
  202293. remaining.subtract (r);
  202294. clipToRectangleList (remaining);
  202295. }
  202296. void clipToPath (const Path& path, const AffineTransform& transform)
  202297. {
  202298. createPath (path, transform);
  202299. CGContextClip (context);
  202300. }
  202301. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202302. {
  202303. if (! transform.isSingularity())
  202304. {
  202305. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202306. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202307. flip();
  202308. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202309. applyTransform (t);
  202310. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202311. CGContextClipToMask (context, r, image);
  202312. applyTransform (t.inverted());
  202313. flip();
  202314. CGImageRelease (image);
  202315. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202316. }
  202317. }
  202318. bool clipRegionIntersects (const Rectangle<int>& r)
  202319. {
  202320. return getClipBounds().intersects (r);
  202321. }
  202322. const Rectangle<int> getClipBounds() const
  202323. {
  202324. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202325. return Rectangle<int> (roundToInt (bounds.origin.x),
  202326. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202327. roundToInt (bounds.size.width),
  202328. roundToInt (bounds.size.height));
  202329. }
  202330. bool isClipEmpty() const
  202331. {
  202332. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202333. }
  202334. void saveState()
  202335. {
  202336. CGContextSaveGState (context);
  202337. stateStack.add (new SavedState (*state));
  202338. }
  202339. void restoreState()
  202340. {
  202341. CGContextRestoreGState (context);
  202342. SavedState* const top = stateStack.getLast();
  202343. if (top != 0)
  202344. {
  202345. state = top;
  202346. stateStack.removeLast (1, false);
  202347. }
  202348. else
  202349. {
  202350. jassertfalse // trying to pop with an empty stack!
  202351. }
  202352. }
  202353. void setFill (const FillType& fillType)
  202354. {
  202355. state->fillType = fillType;
  202356. if (fillType.isColour())
  202357. {
  202358. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202359. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202360. CGContextSetAlpha (context, 1.0f);
  202361. }
  202362. }
  202363. void setOpacity (float newOpacity)
  202364. {
  202365. state->fillType.setOpacity (newOpacity);
  202366. setFill (state->fillType);
  202367. }
  202368. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202369. {
  202370. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202371. ? kCGInterpolationLow
  202372. : kCGInterpolationHigh);
  202373. }
  202374. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202375. {
  202376. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202377. if (replaceExistingContents)
  202378. {
  202379. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202380. CGContextClearRect (context, cgRect);
  202381. #else
  202382. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202383. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202384. CGContextClearRect (context, cgRect);
  202385. else
  202386. #endif
  202387. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202388. #endif
  202389. fillRect (r, false);
  202390. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202391. }
  202392. else
  202393. {
  202394. if (state->fillType.isColour())
  202395. {
  202396. CGContextFillRect (context, cgRect);
  202397. }
  202398. else if (state->fillType.isGradient())
  202399. {
  202400. CGContextSaveGState (context);
  202401. CGContextClipToRect (context, cgRect);
  202402. drawGradient();
  202403. CGContextRestoreGState (context);
  202404. }
  202405. else
  202406. {
  202407. CGContextSaveGState (context);
  202408. CGContextClipToRect (context, cgRect);
  202409. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202410. CGContextRestoreGState (context);
  202411. }
  202412. }
  202413. }
  202414. void fillPath (const Path& path, const AffineTransform& transform)
  202415. {
  202416. CGContextSaveGState (context);
  202417. if (state->fillType.isColour())
  202418. {
  202419. flip();
  202420. applyTransform (transform);
  202421. createPath (path);
  202422. if (path.isUsingNonZeroWinding())
  202423. CGContextFillPath (context);
  202424. else
  202425. CGContextEOFillPath (context);
  202426. }
  202427. else
  202428. {
  202429. createPath (path, transform);
  202430. if (path.isUsingNonZeroWinding())
  202431. CGContextClip (context);
  202432. else
  202433. CGContextEOClip (context);
  202434. if (state->fillType.isGradient())
  202435. drawGradient();
  202436. else
  202437. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202438. }
  202439. CGContextRestoreGState (context);
  202440. }
  202441. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202442. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202443. {
  202444. jassert (sourceImage.getBounds().contains (srcClip));
  202445. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202446. CGImageRef image = fullImage;
  202447. if (srcClip != sourceImage.getBounds())
  202448. {
  202449. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202450. srcClip.getWidth(), srcClip.getHeight()));
  202451. CGImageRelease (fullImage);
  202452. }
  202453. CGContextSaveGState (context);
  202454. CGContextSetAlpha (context, state->fillType.getOpacity());
  202455. flip();
  202456. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202457. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202458. if (fillEntireClipAsTiles)
  202459. {
  202460. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202461. CGContextDrawTiledImage (context, imageRect, image);
  202462. #else
  202463. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202464. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202465. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202466. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202467. CGContextDrawTiledImage (context, imageRect, image);
  202468. else
  202469. #endif
  202470. {
  202471. // Fallback to manually doing a tiled fill on 10.4
  202472. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202473. const int iw = srcClip.getWidth();
  202474. const int ih = srcClip.getHeight();
  202475. int x = 0, y = 0;
  202476. while (x > clip.origin.x) x -= iw;
  202477. while (y > clip.origin.y) y -= ih;
  202478. const int right = (int) (clip.origin.x + clip.size.width);
  202479. const int bottom = (int) (clip.origin.y + clip.size.height);
  202480. while (y < bottom)
  202481. {
  202482. for (int x2 = x; x2 < right; x2 += iw)
  202483. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202484. y += ih;
  202485. }
  202486. }
  202487. #endif
  202488. }
  202489. else
  202490. {
  202491. CGContextDrawImage (context, imageRect, image);
  202492. }
  202493. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202494. CGContextRestoreGState (context);
  202495. }
  202496. void drawLine (double x1, double y1, double x2, double y2)
  202497. {
  202498. CGContextSetLineCap (context, kCGLineCapSquare);
  202499. CGContextSetLineWidth (context, 1.0f);
  202500. CGContextSetRGBStrokeColor (context,
  202501. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202502. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202503. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  202504. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  202505. CGContextStrokeLineSegments (context, line, 1);
  202506. }
  202507. void drawVerticalLine (const int x, double top, double bottom)
  202508. {
  202509. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202510. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202511. #else
  202512. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202513. // the x co-ord slightly to trick it..
  202514. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202515. #endif
  202516. }
  202517. void drawHorizontalLine (const int y, double left, double right)
  202518. {
  202519. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202520. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202521. #else
  202522. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202523. // the x co-ord slightly to trick it..
  202524. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202525. #endif
  202526. }
  202527. void setFont (const Font& newFont)
  202528. {
  202529. if (state->font != newFont)
  202530. {
  202531. state->fontRef = 0;
  202532. state->font = newFont;
  202533. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202534. if (mf != 0)
  202535. {
  202536. state->fontRef = mf->fontRef;
  202537. CGContextSetFont (context, state->fontRef);
  202538. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202539. state->fontTransform = mf->renderingTransform;
  202540. state->fontTransform.a *= state->font.getHorizontalScale();
  202541. CGContextSetTextMatrix (context, state->fontTransform);
  202542. }
  202543. }
  202544. }
  202545. const Font getFont()
  202546. {
  202547. return state->font;
  202548. }
  202549. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202550. {
  202551. if (state->fontRef != 0 && state->fillType.isColour())
  202552. {
  202553. if (transform.isOnlyTranslation())
  202554. {
  202555. CGGlyph g = glyphNumber;
  202556. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202557. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202558. }
  202559. else
  202560. {
  202561. CGContextSaveGState (context);
  202562. flip();
  202563. applyTransform (transform);
  202564. CGAffineTransform t = state->fontTransform;
  202565. t.d = -t.d;
  202566. CGContextSetTextMatrix (context, t);
  202567. CGGlyph g = glyphNumber;
  202568. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202569. CGContextSetTextMatrix (context, state->fontTransform);
  202570. CGContextRestoreGState (context);
  202571. }
  202572. }
  202573. else
  202574. {
  202575. Path p;
  202576. Font& f = state->font;
  202577. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202578. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202579. .followedBy (transform));
  202580. }
  202581. }
  202582. private:
  202583. CGContextRef context;
  202584. const CGFloat flipHeight;
  202585. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202586. CGFunctionCallbacks gradientCallbacks;
  202587. struct SavedState
  202588. {
  202589. SavedState()
  202590. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202591. {
  202592. }
  202593. SavedState (const SavedState& other)
  202594. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202595. fontTransform (other.fontTransform)
  202596. {
  202597. }
  202598. ~SavedState()
  202599. {
  202600. }
  202601. FillType fillType;
  202602. Font font;
  202603. CGFontRef fontRef;
  202604. CGAffineTransform fontTransform;
  202605. };
  202606. ScopedPointer <SavedState> state;
  202607. OwnedArray <SavedState> stateStack;
  202608. HeapBlock <PixelARGB> gradientLookupTable;
  202609. int numGradientLookupEntries;
  202610. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202611. {
  202612. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202613. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202614. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202615. colour.unpremultiply();
  202616. outData[0] = colour.getRed() / 255.0f;
  202617. outData[1] = colour.getGreen() / 255.0f;
  202618. outData[2] = colour.getBlue() / 255.0f;
  202619. outData[3] = colour.getAlpha() / 255.0f;
  202620. }
  202621. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202622. {
  202623. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202624. --numGradientLookupEntries;
  202625. CGShadingRef result = 0;
  202626. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202627. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202628. if (gradient.isRadial)
  202629. {
  202630. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202631. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202632. function, true, true);
  202633. }
  202634. else
  202635. {
  202636. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202637. CGPointMake (gradient.x2, gradient.y2),
  202638. function, true, true);
  202639. }
  202640. CGFunctionRelease (function);
  202641. return result;
  202642. }
  202643. void drawGradient()
  202644. {
  202645. flip();
  202646. applyTransform (state->fillType.transform);
  202647. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202648. // you draw a gradient with high quality interp enabled).
  202649. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202650. CGContextSetAlpha (context, state->fillType.getOpacity());
  202651. CGContextDrawShading (context, shading);
  202652. CGShadingRelease (shading);
  202653. }
  202654. void createPath (const Path& path) const
  202655. {
  202656. CGContextBeginPath (context);
  202657. Path::Iterator i (path);
  202658. while (i.next())
  202659. {
  202660. switch (i.elementType)
  202661. {
  202662. case Path::Iterator::startNewSubPath:
  202663. CGContextMoveToPoint (context, i.x1, i.y1);
  202664. break;
  202665. case Path::Iterator::lineTo:
  202666. CGContextAddLineToPoint (context, i.x1, i.y1);
  202667. break;
  202668. case Path::Iterator::quadraticTo:
  202669. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202670. break;
  202671. case Path::Iterator::cubicTo:
  202672. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202673. break;
  202674. case Path::Iterator::closePath:
  202675. CGContextClosePath (context); break;
  202676. default:
  202677. jassertfalse
  202678. break;
  202679. }
  202680. }
  202681. }
  202682. void createPath (const Path& path, const AffineTransform& transform) const
  202683. {
  202684. CGContextBeginPath (context);
  202685. Path::Iterator i (path);
  202686. while (i.next())
  202687. {
  202688. switch (i.elementType)
  202689. {
  202690. case Path::Iterator::startNewSubPath:
  202691. transform.transformPoint (i.x1, i.y1);
  202692. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202693. break;
  202694. case Path::Iterator::lineTo:
  202695. transform.transformPoint (i.x1, i.y1);
  202696. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202697. break;
  202698. case Path::Iterator::quadraticTo:
  202699. transform.transformPoint (i.x1, i.y1);
  202700. transform.transformPoint (i.x2, i.y2);
  202701. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202702. break;
  202703. case Path::Iterator::cubicTo:
  202704. transform.transformPoint (i.x1, i.y1);
  202705. transform.transformPoint (i.x2, i.y2);
  202706. transform.transformPoint (i.x3, i.y3);
  202707. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202708. break;
  202709. case Path::Iterator::closePath:
  202710. CGContextClosePath (context); break;
  202711. default:
  202712. jassertfalse
  202713. break;
  202714. }
  202715. }
  202716. }
  202717. static Image* createAlphaChannelImage (const Image& im)
  202718. {
  202719. if (im.getFormat() == Image::SingleChannel)
  202720. return const_cast <Image*> (&im);
  202721. return im.createCopyOfAlphaChannel();
  202722. }
  202723. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202724. {
  202725. if (im.getFormat() != Image::SingleChannel)
  202726. delete alphaIm;
  202727. }
  202728. void flip() const
  202729. {
  202730. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202731. }
  202732. void applyTransform (const AffineTransform& transform) const
  202733. {
  202734. CGAffineTransform t;
  202735. t.a = transform.mat00;
  202736. t.b = transform.mat10;
  202737. t.c = transform.mat01;
  202738. t.d = transform.mat11;
  202739. t.tx = transform.mat02;
  202740. t.ty = transform.mat12;
  202741. CGContextConcatCTM (context, t);
  202742. }
  202743. CoreGraphicsContext (const CoreGraphicsContext&);
  202744. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  202745. };
  202746. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202747. {
  202748. return new CoreGraphicsContext (context, imageHeight);
  202749. }
  202750. #endif
  202751. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202752. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202753. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202754. // compiled on its own).
  202755. #if JUCE_INCLUDED_FILE
  202756. class UIViewComponentPeer;
  202757. END_JUCE_NAMESPACE
  202758. #define JuceUIView MakeObjCClassName(JuceUIView)
  202759. @interface JuceUIView : UIView
  202760. {
  202761. @public
  202762. UIViewComponentPeer* owner;
  202763. }
  202764. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202765. - (void) dealloc;
  202766. - (void) drawRect: (CGRect) r;
  202767. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202768. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202769. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202770. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202771. - (BOOL) becomeFirstResponder;
  202772. - (BOOL) resignFirstResponder;
  202773. - (BOOL) canBecomeFirstResponder;
  202774. - (void) asyncRepaint: (id) rect;
  202775. @end
  202776. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202777. @interface JuceUIWindow : UIWindow
  202778. {
  202779. @private
  202780. UIViewComponentPeer* owner;
  202781. bool isZooming;
  202782. }
  202783. - (void) setOwner: (UIViewComponentPeer*) owner;
  202784. - (void) becomeKeyWindow;
  202785. @end
  202786. BEGIN_JUCE_NAMESPACE
  202787. class UIViewComponentPeer : public ComponentPeer
  202788. {
  202789. public:
  202790. UIViewComponentPeer (Component* const component,
  202791. const int windowStyleFlags,
  202792. UIView* viewToAttachTo);
  202793. ~UIViewComponentPeer();
  202794. void* getNativeHandle() const;
  202795. void setVisible (bool shouldBeVisible);
  202796. void setTitle (const String& title);
  202797. void setPosition (int x, int y);
  202798. void setSize (int w, int h);
  202799. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  202800. const Rectangle<int> getBounds() const;
  202801. const Rectangle<int> getBounds (const bool global) const;
  202802. const Point<int> getScreenPosition() const;
  202803. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202804. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202805. void setMinimised (bool shouldBeMinimised);
  202806. bool isMinimised() const;
  202807. void setFullScreen (bool shouldBeFullScreen);
  202808. bool isFullScreen() const;
  202809. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202810. const BorderSize getFrameSize() const;
  202811. bool setAlwaysOnTop (bool alwaysOnTop);
  202812. void toFront (bool makeActiveWindow);
  202813. void toBehind (ComponentPeer* other);
  202814. void setIcon (const Image& newIcon);
  202815. virtual void drawRect (CGRect r);
  202816. virtual bool canBecomeKeyWindow();
  202817. virtual bool windowShouldClose();
  202818. virtual void redirectMovedOrResized();
  202819. virtual CGRect constrainRect (CGRect r);
  202820. virtual void viewFocusGain();
  202821. virtual void viewFocusLoss();
  202822. bool isFocused() const;
  202823. void grabFocus();
  202824. void textInputRequired (const Point<int>& position);
  202825. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202826. void repaint (int x, int y, int w, int h);
  202827. void performAnyPendingRepaintsNow();
  202828. juce_UseDebuggingNewOperator
  202829. UIWindow* window;
  202830. JuceUIView* view;
  202831. bool isSharedWindow, fullScreen, insideDrawRect;
  202832. static ModifierKeys currentModifiers;
  202833. static int64 getMouseTime (UIEvent* e)
  202834. {
  202835. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202836. + (int64) ([e timestamp] * 1000.0);
  202837. }
  202838. Array <UITouch*> currentTouches;
  202839. };
  202840. END_JUCE_NAMESPACE
  202841. @implementation JuceUIView
  202842. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202843. withFrame: (CGRect) frame
  202844. {
  202845. [super initWithFrame: frame];
  202846. owner = owner_;
  202847. return self;
  202848. }
  202849. - (void) dealloc
  202850. {
  202851. [super dealloc];
  202852. }
  202853. - (void) drawRect: (CGRect) r
  202854. {
  202855. if (owner != 0)
  202856. owner->drawRect (r);
  202857. }
  202858. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  202859. {
  202860. return false;
  202861. }
  202862. ModifierKeys UIViewComponentPeer::currentModifiers;
  202863. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202864. {
  202865. return UIViewComponentPeer::currentModifiers;
  202866. }
  202867. void ModifierKeys::updateCurrentModifiers() throw()
  202868. {
  202869. currentModifiers = UIViewComponentPeer::currentModifiers;
  202870. }
  202871. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202872. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202873. {
  202874. if (owner != 0)
  202875. owner->handleTouches (event, true, false, false);
  202876. }
  202877. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202878. {
  202879. if (owner != 0)
  202880. owner->handleTouches (event, false, false, false);
  202881. }
  202882. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202883. {
  202884. if (owner != 0)
  202885. owner->handleTouches (event, false, true, false);
  202886. }
  202887. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202888. {
  202889. if (owner != 0)
  202890. owner->handleTouches (event, false, true, true);
  202891. [self touchesEnded: touches withEvent: event];
  202892. }
  202893. - (BOOL) becomeFirstResponder
  202894. {
  202895. if (owner != 0)
  202896. owner->viewFocusGain();
  202897. return true;
  202898. }
  202899. - (BOOL) resignFirstResponder
  202900. {
  202901. if (owner != 0)
  202902. owner->viewFocusLoss();
  202903. return true;
  202904. }
  202905. - (BOOL) canBecomeFirstResponder
  202906. {
  202907. return owner != 0 && owner->canBecomeKeyWindow();
  202908. }
  202909. - (void) asyncRepaint: (id) rect
  202910. {
  202911. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  202912. [self setNeedsDisplayInRect: *r];
  202913. }
  202914. @end
  202915. @implementation JuceUIWindow
  202916. - (void) setOwner: (UIViewComponentPeer*) owner_
  202917. {
  202918. owner = owner_;
  202919. isZooming = false;
  202920. }
  202921. - (void) becomeKeyWindow
  202922. {
  202923. [super becomeKeyWindow];
  202924. if (owner != 0)
  202925. owner->grabFocus();
  202926. }
  202927. @end
  202928. BEGIN_JUCE_NAMESPACE
  202929. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  202930. const int windowStyleFlags,
  202931. UIView* viewToAttachTo)
  202932. : ComponentPeer (component, windowStyleFlags),
  202933. window (0),
  202934. view (0),
  202935. isSharedWindow (viewToAttachTo != 0),
  202936. fullScreen (false),
  202937. insideDrawRect (false)
  202938. {
  202939. CGRect r;
  202940. r.origin.x = 0;
  202941. r.origin.y = 0;
  202942. r.size.width = (float) component->getWidth();
  202943. r.size.height = (float) component->getHeight();
  202944. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  202945. if (isSharedWindow)
  202946. {
  202947. window = [viewToAttachTo window];
  202948. [viewToAttachTo addSubview: view];
  202949. setVisible (component->isVisible());
  202950. }
  202951. else
  202952. {
  202953. r.origin.x = (float) component->getX();
  202954. r.origin.y = (float) component->getY();
  202955. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  202956. window = [[JuceUIWindow alloc] init];
  202957. window.frame = r;
  202958. window.opaque = component->isOpaque();
  202959. view.opaque = component->isOpaque();
  202960. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202961. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202962. [((JuceUIWindow*) window) setOwner: this];
  202963. if (component->isAlwaysOnTop())
  202964. window.windowLevel = UIWindowLevelAlert;
  202965. [window addSubview: view];
  202966. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202967. view.hidden = ! component->isVisible();
  202968. window.hidden = ! component->isVisible();
  202969. view.multipleTouchEnabled = YES;
  202970. }
  202971. setTitle (component->getName());
  202972. }
  202973. UIViewComponentPeer::~UIViewComponentPeer()
  202974. {
  202975. view->owner = 0;
  202976. [view removeFromSuperview];
  202977. [view release];
  202978. if (! isSharedWindow)
  202979. {
  202980. [((JuceUIWindow*) window) setOwner: 0];
  202981. [window release];
  202982. }
  202983. }
  202984. void* UIViewComponentPeer::getNativeHandle() const
  202985. {
  202986. return view;
  202987. }
  202988. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  202989. {
  202990. view.hidden = ! shouldBeVisible;
  202991. if (! isSharedWindow)
  202992. window.hidden = ! shouldBeVisible;
  202993. }
  202994. void UIViewComponentPeer::setTitle (const String& title)
  202995. {
  202996. // xxx is this possible?
  202997. }
  202998. void UIViewComponentPeer::setPosition (int x, int y)
  202999. {
  203000. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  203001. }
  203002. void UIViewComponentPeer::setSize (int w, int h)
  203003. {
  203004. setBounds (component->getX(), component->getY(), w, h, false);
  203005. }
  203006. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  203007. {
  203008. fullScreen = isNowFullScreen;
  203009. w = jmax (0, w);
  203010. h = jmax (0, h);
  203011. CGRect r;
  203012. r.origin.x = (float) x;
  203013. r.origin.y = (float) y;
  203014. r.size.width = (float) w;
  203015. r.size.height = (float) h;
  203016. if (isSharedWindow)
  203017. {
  203018. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203019. if ([view frame].size.width != r.size.width
  203020. || [view frame].size.height != r.size.height)
  203021. [view setNeedsDisplay];
  203022. view.frame = r;
  203023. }
  203024. else
  203025. {
  203026. window.frame = r;
  203027. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203028. }
  203029. }
  203030. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  203031. {
  203032. CGRect r = [view frame];
  203033. if (global && [view window] != 0)
  203034. {
  203035. r = [view convertRect: r toView: nil];
  203036. CGRect wr = [[view window] frame];
  203037. r.origin.x += wr.origin.x;
  203038. r.origin.y += wr.origin.y;
  203039. }
  203040. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  203041. (int) r.size.width, (int) r.size.height);
  203042. }
  203043. const Rectangle<int> UIViewComponentPeer::getBounds() const
  203044. {
  203045. return getBounds (! isSharedWindow);
  203046. }
  203047. const Point<int> UIViewComponentPeer::getScreenPosition() const
  203048. {
  203049. return getBounds (true).getPosition();
  203050. }
  203051. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  203052. {
  203053. return relativePosition + getScreenPosition();
  203054. }
  203055. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  203056. {
  203057. return screenPosition - getScreenPosition();
  203058. }
  203059. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203060. {
  203061. if (constrainer != 0)
  203062. {
  203063. CGRect current = [window frame];
  203064. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203065. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203066. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203067. (int) r.size.width, (int) r.size.height);
  203068. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203069. (int) current.size.width, (int) current.size.height);
  203070. constrainer->checkBounds (pos, original,
  203071. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203072. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203073. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203074. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203075. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203076. r.origin.x = pos.getX();
  203077. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203078. r.size.width = pos.getWidth();
  203079. r.size.height = pos.getHeight();
  203080. }
  203081. return r;
  203082. }
  203083. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203084. {
  203085. // xxx
  203086. }
  203087. bool UIViewComponentPeer::isMinimised() const
  203088. {
  203089. return false;
  203090. }
  203091. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203092. {
  203093. if (! isSharedWindow)
  203094. {
  203095. Rectangle<int> r (lastNonFullscreenBounds);
  203096. setMinimised (false);
  203097. if (fullScreen != shouldBeFullScreen)
  203098. {
  203099. if (shouldBeFullScreen)
  203100. r = Desktop::getInstance().getMainMonitorArea();
  203101. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203102. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203103. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203104. }
  203105. }
  203106. }
  203107. bool UIViewComponentPeer::isFullScreen() const
  203108. {
  203109. return fullScreen;
  203110. }
  203111. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  203112. {
  203113. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  203114. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  203115. return false;
  203116. CGPoint p;
  203117. p.x = (float) position.getX();
  203118. p.y = (float) position.getY();
  203119. UIView* v = [view hitTest: p withEvent: nil];
  203120. if (trueIfInAChildWindow)
  203121. return v != nil;
  203122. return v == view;
  203123. }
  203124. const BorderSize UIViewComponentPeer::getFrameSize() const
  203125. {
  203126. BorderSize b;
  203127. if (! isSharedWindow)
  203128. {
  203129. CGRect v = [view convertRect: [view frame] toView: nil];
  203130. CGRect w = [window frame];
  203131. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203132. b.setBottom ((int) v.origin.y);
  203133. b.setLeft ((int) v.origin.x);
  203134. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203135. }
  203136. return b;
  203137. }
  203138. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203139. {
  203140. if (! isSharedWindow)
  203141. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203142. return true;
  203143. }
  203144. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203145. {
  203146. if (isSharedWindow)
  203147. [[view superview] bringSubviewToFront: view];
  203148. if (window != 0 && component->isVisible())
  203149. [window makeKeyAndVisible];
  203150. }
  203151. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203152. {
  203153. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203154. if (isSharedWindow)
  203155. {
  203156. [[view superview] insertSubview: view belowSubview: o->view];
  203157. }
  203158. else
  203159. {
  203160. jassertfalse // don't know how to do this
  203161. }
  203162. }
  203163. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203164. {
  203165. // to do..
  203166. }
  203167. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  203168. {
  203169. NSArray* touches = [[event touchesForView: view] allObjects];
  203170. for (unsigned int i = 0; i < [touches count]; ++i)
  203171. {
  203172. UITouch* touch = [touches objectAtIndex: i];
  203173. CGPoint p = [touch locationInView: view];
  203174. const Point<int> pos ((int) p.x, (int) p.y);
  203175. juce_lastMousePos = pos + getScreenPosition();
  203176. const int64 time = getMouseTime (event);
  203177. int touchIndex = currentTouches.indexOf (touch);
  203178. if (touchIndex < 0)
  203179. {
  203180. touchIndex = currentTouches.size();
  203181. currentTouches.add (touch);
  203182. }
  203183. if (isDown)
  203184. {
  203185. currentModifiers = currentModifiers.withoutMouseButtons();
  203186. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203187. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  203188. }
  203189. else if (isUp)
  203190. {
  203191. currentModifiers = currentModifiers.withoutMouseButtons();
  203192. currentTouches.remove (touchIndex);
  203193. }
  203194. if (isCancel)
  203195. currentTouches.clear();
  203196. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203197. }
  203198. }
  203199. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203200. void UIViewComponentPeer::viewFocusGain()
  203201. {
  203202. if (currentlyFocusedPeer != this)
  203203. {
  203204. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203205. currentlyFocusedPeer->handleFocusLoss();
  203206. currentlyFocusedPeer = this;
  203207. handleFocusGain();
  203208. }
  203209. }
  203210. void UIViewComponentPeer::viewFocusLoss()
  203211. {
  203212. if (currentlyFocusedPeer == this)
  203213. {
  203214. currentlyFocusedPeer = 0;
  203215. handleFocusLoss();
  203216. }
  203217. }
  203218. void juce_HandleProcessFocusChange()
  203219. {
  203220. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203221. {
  203222. if (Process::isForegroundProcess())
  203223. {
  203224. currentlyFocusedPeer->handleFocusGain();
  203225. ComponentPeer::bringModalComponentToFront();
  203226. }
  203227. else
  203228. {
  203229. currentlyFocusedPeer->handleFocusLoss();
  203230. // turn kiosk mode off if we lose focus..
  203231. Desktop::getInstance().setKioskModeComponent (0);
  203232. }
  203233. }
  203234. }
  203235. bool UIViewComponentPeer::isFocused() const
  203236. {
  203237. return isSharedWindow ? this == currentlyFocusedPeer
  203238. : (window != 0 && [window isKeyWindow]);
  203239. }
  203240. void UIViewComponentPeer::grabFocus()
  203241. {
  203242. if (window != 0)
  203243. {
  203244. [window makeKeyWindow];
  203245. viewFocusGain();
  203246. }
  203247. }
  203248. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203249. {
  203250. }
  203251. void UIViewComponentPeer::drawRect (CGRect r)
  203252. {
  203253. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203254. return;
  203255. CGContextRef cg = UIGraphicsGetCurrentContext();
  203256. if (! component->isOpaque())
  203257. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203258. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203259. CoreGraphicsContext g (cg, view.bounds.size.height);
  203260. insideDrawRect = true;
  203261. handlePaint (g);
  203262. insideDrawRect = false;
  203263. }
  203264. bool UIViewComponentPeer::canBecomeKeyWindow()
  203265. {
  203266. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203267. }
  203268. bool UIViewComponentPeer::windowShouldClose()
  203269. {
  203270. if (! isValidPeer (this))
  203271. return YES;
  203272. handleUserClosingWindow();
  203273. return NO;
  203274. }
  203275. void UIViewComponentPeer::redirectMovedOrResized()
  203276. {
  203277. handleMovedOrResized();
  203278. }
  203279. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203280. {
  203281. }
  203282. class AsyncRepaintMessage : public CallbackMessage
  203283. {
  203284. public:
  203285. UIViewComponentPeer* const peer;
  203286. const Rectangle<int> rect;
  203287. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203288. : peer (peer_), rect (rect_)
  203289. {
  203290. }
  203291. void messageCallback()
  203292. {
  203293. if (ComponentPeer::isValidPeer (peer))
  203294. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203295. }
  203296. };
  203297. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203298. {
  203299. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203300. {
  203301. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203302. }
  203303. else
  203304. {
  203305. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203306. }
  203307. }
  203308. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203309. {
  203310. }
  203311. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203312. {
  203313. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203314. }
  203315. Image* juce_createIconForFile (const File& file)
  203316. {
  203317. return 0;
  203318. }
  203319. void Desktop::createMouseInputSources()
  203320. {
  203321. for (int i = 0; i < 10; ++i)
  203322. mouseSources.add (new MouseInputSource (i, false));
  203323. }
  203324. bool Desktop::canUseSemiTransparentWindows() throw()
  203325. {
  203326. return true;
  203327. }
  203328. const Point<int> Desktop::getMousePosition()
  203329. {
  203330. return juce_lastMousePos;
  203331. }
  203332. void Desktop::setMousePosition (const Point<int>&)
  203333. {
  203334. }
  203335. const int KeyPress::spaceKey = ' ';
  203336. const int KeyPress::returnKey = 0x0d;
  203337. const int KeyPress::escapeKey = 0x1b;
  203338. const int KeyPress::backspaceKey = 0x7f;
  203339. const int KeyPress::leftKey = 0x1000;
  203340. const int KeyPress::rightKey = 0x1001;
  203341. const int KeyPress::upKey = 0x1002;
  203342. const int KeyPress::downKey = 0x1003;
  203343. const int KeyPress::pageUpKey = 0x1004;
  203344. const int KeyPress::pageDownKey = 0x1005;
  203345. const int KeyPress::endKey = 0x1006;
  203346. const int KeyPress::homeKey = 0x1007;
  203347. const int KeyPress::deleteKey = 0x1008;
  203348. const int KeyPress::insertKey = -1;
  203349. const int KeyPress::tabKey = 9;
  203350. const int KeyPress::F1Key = 0x2001;
  203351. const int KeyPress::F2Key = 0x2002;
  203352. const int KeyPress::F3Key = 0x2003;
  203353. const int KeyPress::F4Key = 0x2004;
  203354. const int KeyPress::F5Key = 0x2005;
  203355. const int KeyPress::F6Key = 0x2006;
  203356. const int KeyPress::F7Key = 0x2007;
  203357. const int KeyPress::F8Key = 0x2008;
  203358. const int KeyPress::F9Key = 0x2009;
  203359. const int KeyPress::F10Key = 0x200a;
  203360. const int KeyPress::F11Key = 0x200b;
  203361. const int KeyPress::F12Key = 0x200c;
  203362. const int KeyPress::F13Key = 0x200d;
  203363. const int KeyPress::F14Key = 0x200e;
  203364. const int KeyPress::F15Key = 0x200f;
  203365. const int KeyPress::F16Key = 0x2010;
  203366. const int KeyPress::numberPad0 = 0x30020;
  203367. const int KeyPress::numberPad1 = 0x30021;
  203368. const int KeyPress::numberPad2 = 0x30022;
  203369. const int KeyPress::numberPad3 = 0x30023;
  203370. const int KeyPress::numberPad4 = 0x30024;
  203371. const int KeyPress::numberPad5 = 0x30025;
  203372. const int KeyPress::numberPad6 = 0x30026;
  203373. const int KeyPress::numberPad7 = 0x30027;
  203374. const int KeyPress::numberPad8 = 0x30028;
  203375. const int KeyPress::numberPad9 = 0x30029;
  203376. const int KeyPress::numberPadAdd = 0x3002a;
  203377. const int KeyPress::numberPadSubtract = 0x3002b;
  203378. const int KeyPress::numberPadMultiply = 0x3002c;
  203379. const int KeyPress::numberPadDivide = 0x3002d;
  203380. const int KeyPress::numberPadSeparator = 0x3002e;
  203381. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203382. const int KeyPress::numberPadEquals = 0x30030;
  203383. const int KeyPress::numberPadDelete = 0x30031;
  203384. const int KeyPress::playKey = 0x30000;
  203385. const int KeyPress::stopKey = 0x30001;
  203386. const int KeyPress::fastForwardKey = 0x30002;
  203387. const int KeyPress::rewindKey = 0x30003;
  203388. #endif
  203389. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203390. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203391. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203392. // compiled on its own).
  203393. #if JUCE_INCLUDED_FILE
  203394. struct CallbackMessagePayload
  203395. {
  203396. MessageCallbackFunction* function;
  203397. void* parameter;
  203398. void* volatile result;
  203399. bool volatile hasBeenExecuted;
  203400. };
  203401. END_JUCE_NAMESPACE
  203402. using namespace JUCE_NAMESPACE;
  203403. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203404. {
  203405. }
  203406. - (JuceAppDelegate*) init;
  203407. - (void) dealloc;
  203408. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203409. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203410. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203411. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203412. - (void) customEvent: (id) data;
  203413. - (void) performCallback: (id) info;
  203414. @end
  203415. @implementation JuceAppDelegate
  203416. - (JuceAppDelegate*) init
  203417. {
  203418. [super init];
  203419. [[UIApplication sharedApplication] setDelegate: self];
  203420. return self;
  203421. }
  203422. - (void) dealloc
  203423. {
  203424. [[UIApplication sharedApplication] setDelegate: nil];
  203425. [super dealloc];
  203426. }
  203427. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203428. {
  203429. if (JUCEApplication::getInstance() != 0)
  203430. {
  203431. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203432. return YES;
  203433. }
  203434. return NO;
  203435. }
  203436. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203437. {
  203438. juce_HandleProcessFocusChange();
  203439. }
  203440. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203441. {
  203442. juce_HandleProcessFocusChange();
  203443. }
  203444. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203445. {
  203446. juce_HandleProcessFocusChange();
  203447. }
  203448. - (void) customEvent: (id) n
  203449. {
  203450. NSData* data = (NSData*) n;
  203451. void* message = 0;
  203452. [data getBytes: &message length: sizeof (message)];
  203453. [data release];
  203454. if (message != 0)
  203455. MessageManager::getInstance()->deliverMessage (message);
  203456. }
  203457. - (void) performCallback: (id) info
  203458. {
  203459. if ([info isKindOfClass: [NSData class]])
  203460. {
  203461. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203462. if (pl != 0)
  203463. {
  203464. pl->result = (*pl->function) (pl->parameter);
  203465. pl->hasBeenExecuted = true;
  203466. }
  203467. }
  203468. else
  203469. {
  203470. jassertfalse // should never get here!
  203471. }
  203472. }
  203473. @end
  203474. BEGIN_JUCE_NAMESPACE
  203475. static JuceAppDelegate* juceAppDelegate = 0;
  203476. void MessageManager::runDispatchLoop()
  203477. {
  203478. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203479. runDispatchLoopUntil (-1);
  203480. }
  203481. void MessageManager::stopDispatchLoop()
  203482. {
  203483. exit (0); // iPhone apps get no mercy..
  203484. }
  203485. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203486. {
  203487. const ScopedAutoReleasePool pool;
  203488. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203489. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203490. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203491. while (! quitMessagePosted)
  203492. {
  203493. const ScopedAutoReleasePool pool;
  203494. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203495. beforeDate: endDate];
  203496. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203497. break;
  203498. }
  203499. return ! quitMessagePosted;
  203500. }
  203501. static CFRunLoopRef runLoop = 0;
  203502. static CFRunLoopSourceRef runLoopSource = 0;
  203503. static Array <void*, CriticalSection>* pendingMessages = 0;
  203504. static void runLoopSourceCallback (void*)
  203505. {
  203506. if (pendingMessages != 0)
  203507. {
  203508. int numDispatched = 0;
  203509. do
  203510. {
  203511. void* const nextMessage = pendingMessages->remove (0);
  203512. if (nextMessage == 0)
  203513. return;
  203514. const ScopedAutoReleasePool pool;
  203515. MessageManager::getInstance()->deliverMessage (nextMessage);
  203516. } while (++numDispatched <= 4);
  203517. CFRunLoopSourceSignal (runLoopSource);
  203518. CFRunLoopWakeUp (runLoop);
  203519. }
  203520. }
  203521. void MessageManager::doPlatformSpecificInitialisation()
  203522. {
  203523. pendingMessages = new Array <void*, CriticalSection>();
  203524. runLoop = CFRunLoopGetCurrent();
  203525. CFRunLoopSourceContext sourceContext;
  203526. zerostruct (sourceContext);
  203527. sourceContext.perform = runLoopSourceCallback;
  203528. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203529. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203530. if (juceAppDelegate == 0)
  203531. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203532. }
  203533. void MessageManager::doPlatformSpecificShutdown()
  203534. {
  203535. CFRunLoopSourceInvalidate (runLoopSource);
  203536. CFRelease (runLoopSource);
  203537. runLoopSource = 0;
  203538. if (pendingMessages != 0)
  203539. {
  203540. while (pendingMessages->size() > 0)
  203541. delete ((Message*) pendingMessages->remove(0));
  203542. deleteAndZero (pendingMessages);
  203543. }
  203544. if (juceAppDelegate != 0)
  203545. {
  203546. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203547. [juceAppDelegate release];
  203548. juceAppDelegate = 0;
  203549. }
  203550. }
  203551. bool juce_postMessageToSystemQueue (void* message)
  203552. {
  203553. if (pendingMessages != 0)
  203554. {
  203555. pendingMessages->add (message);
  203556. CFRunLoopSourceSignal (runLoopSource);
  203557. CFRunLoopWakeUp (runLoop);
  203558. }
  203559. return true;
  203560. }
  203561. void MessageManager::broadcastMessage (const String& value) throw()
  203562. {
  203563. }
  203564. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203565. void* data)
  203566. {
  203567. if (isThisTheMessageThread())
  203568. {
  203569. return (*callback) (data);
  203570. }
  203571. else
  203572. {
  203573. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203574. // deadlock because the message manager is blocked from running, so can never
  203575. // call your function..
  203576. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203577. const ScopedAutoReleasePool pool;
  203578. CallbackMessagePayload cmp;
  203579. cmp.function = callback;
  203580. cmp.parameter = data;
  203581. cmp.result = 0;
  203582. cmp.hasBeenExecuted = false;
  203583. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203584. withObject: [NSData dataWithBytesNoCopy: &cmp
  203585. length: sizeof (cmp)
  203586. freeWhenDone: NO]
  203587. waitUntilDone: YES];
  203588. return cmp.result;
  203589. }
  203590. }
  203591. #endif
  203592. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203593. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203594. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203595. // compiled on its own).
  203596. #if JUCE_INCLUDED_FILE
  203597. #if JUCE_MAC
  203598. END_JUCE_NAMESPACE
  203599. using namespace JUCE_NAMESPACE;
  203600. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203601. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203602. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203603. #else
  203604. @interface JuceFileChooserDelegate : NSObject
  203605. #endif
  203606. {
  203607. StringArray* filters;
  203608. }
  203609. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203610. - (void) dealloc;
  203611. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203612. @end
  203613. @implementation JuceFileChooserDelegate
  203614. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203615. {
  203616. [super init];
  203617. filters = filters_;
  203618. return self;
  203619. }
  203620. - (void) dealloc
  203621. {
  203622. delete filters;
  203623. [super dealloc];
  203624. }
  203625. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203626. {
  203627. const File f (nsStringToJuce (filename));
  203628. for (int i = filters->size(); --i >= 0;)
  203629. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203630. return true;
  203631. return f.isDirectory();
  203632. }
  203633. @end
  203634. BEGIN_JUCE_NAMESPACE
  203635. void FileChooser::showPlatformDialog (Array<File>& results,
  203636. const String& title,
  203637. const File& currentFileOrDirectory,
  203638. const String& filter,
  203639. bool selectsDirectory,
  203640. bool selectsFiles,
  203641. bool isSaveDialogue,
  203642. bool warnAboutOverwritingExistingFiles,
  203643. bool selectMultipleFiles,
  203644. FilePreviewComponent* extraInfoComponent)
  203645. {
  203646. const ScopedAutoReleasePool pool;
  203647. StringArray* filters = new StringArray();
  203648. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), String::empty);
  203649. filters->trim();
  203650. filters->removeEmptyStrings();
  203651. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203652. [delegate autorelease];
  203653. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203654. : [NSOpenPanel openPanel];
  203655. [panel setTitle: juceStringToNS (title)];
  203656. if (! isSaveDialogue)
  203657. {
  203658. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203659. [openPanel setCanChooseDirectories: selectsDirectory];
  203660. [openPanel setCanChooseFiles: selectsFiles];
  203661. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203662. }
  203663. [panel setDelegate: delegate];
  203664. if (isSaveDialogue || selectsDirectory)
  203665. [panel setCanCreateDirectories: YES];
  203666. String directory, filename;
  203667. if (currentFileOrDirectory.isDirectory())
  203668. {
  203669. directory = currentFileOrDirectory.getFullPathName();
  203670. }
  203671. else
  203672. {
  203673. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203674. filename = currentFileOrDirectory.getFileName();
  203675. }
  203676. if ([panel runModalForDirectory: juceStringToNS (directory)
  203677. file: juceStringToNS (filename)]
  203678. == NSOKButton)
  203679. {
  203680. if (isSaveDialogue)
  203681. {
  203682. results.add (File (nsStringToJuce ([panel filename])));
  203683. }
  203684. else
  203685. {
  203686. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203687. NSArray* urls = [openPanel filenames];
  203688. for (unsigned int i = 0; i < [urls count]; ++i)
  203689. {
  203690. NSString* f = [urls objectAtIndex: i];
  203691. results.add (File (nsStringToJuce (f)));
  203692. }
  203693. }
  203694. }
  203695. [panel setDelegate: nil];
  203696. }
  203697. #else
  203698. void FileChooser::showPlatformDialog (Array<File>& results,
  203699. const String& title,
  203700. const File& currentFileOrDirectory,
  203701. const String& filter,
  203702. bool selectsDirectory,
  203703. bool selectsFiles,
  203704. bool isSaveDialogue,
  203705. bool warnAboutOverwritingExistingFiles,
  203706. bool selectMultipleFiles,
  203707. FilePreviewComponent* extraInfoComponent)
  203708. {
  203709. const ScopedAutoReleasePool pool;
  203710. jassertfalse //xxx to do
  203711. }
  203712. #endif
  203713. #endif
  203714. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203715. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203716. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203717. // compiled on its own).
  203718. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203719. #if JUCE_MAC
  203720. END_JUCE_NAMESPACE
  203721. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203722. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203723. {
  203724. CriticalSection* contextLock;
  203725. bool needsUpdate;
  203726. }
  203727. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203728. - (bool) makeActive;
  203729. - (void) makeInactive;
  203730. - (void) reshape;
  203731. @end
  203732. @implementation ThreadSafeNSOpenGLView
  203733. - (id) initWithFrame: (NSRect) frameRect
  203734. pixelFormat: (NSOpenGLPixelFormat*) format
  203735. {
  203736. contextLock = new CriticalSection();
  203737. self = [super initWithFrame: frameRect pixelFormat: format];
  203738. if (self != nil)
  203739. [[NSNotificationCenter defaultCenter] addObserver: self
  203740. selector: @selector (_surfaceNeedsUpdate:)
  203741. name: NSViewGlobalFrameDidChangeNotification
  203742. object: self];
  203743. return self;
  203744. }
  203745. - (void) dealloc
  203746. {
  203747. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203748. delete contextLock;
  203749. [super dealloc];
  203750. }
  203751. - (bool) makeActive
  203752. {
  203753. const ScopedLock sl (*contextLock);
  203754. if ([self openGLContext] == 0)
  203755. return false;
  203756. [[self openGLContext] makeCurrentContext];
  203757. if (needsUpdate)
  203758. {
  203759. [super update];
  203760. needsUpdate = false;
  203761. }
  203762. return true;
  203763. }
  203764. - (void) makeInactive
  203765. {
  203766. const ScopedLock sl (*contextLock);
  203767. [NSOpenGLContext clearCurrentContext];
  203768. }
  203769. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203770. {
  203771. const ScopedLock sl (*contextLock);
  203772. needsUpdate = true;
  203773. }
  203774. - (void) update
  203775. {
  203776. const ScopedLock sl (*contextLock);
  203777. needsUpdate = true;
  203778. }
  203779. - (void) reshape
  203780. {
  203781. const ScopedLock sl (*contextLock);
  203782. needsUpdate = true;
  203783. }
  203784. @end
  203785. BEGIN_JUCE_NAMESPACE
  203786. class WindowedGLContext : public OpenGLContext
  203787. {
  203788. public:
  203789. WindowedGLContext (Component* const component,
  203790. const OpenGLPixelFormat& pixelFormat_,
  203791. NSOpenGLContext* sharedContext)
  203792. : renderContext (0),
  203793. pixelFormat (pixelFormat_)
  203794. {
  203795. jassert (component != 0);
  203796. NSOpenGLPixelFormatAttribute attribs [64];
  203797. int n = 0;
  203798. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203799. attribs[n++] = NSOpenGLPFAAccelerated;
  203800. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203801. attribs[n++] = NSOpenGLPFAColorSize;
  203802. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203803. pixelFormat.greenBits,
  203804. pixelFormat.blueBits);
  203805. attribs[n++] = NSOpenGLPFAAlphaSize;
  203806. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203807. attribs[n++] = NSOpenGLPFADepthSize;
  203808. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203809. attribs[n++] = NSOpenGLPFAStencilSize;
  203810. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203811. attribs[n++] = NSOpenGLPFAAccumSize;
  203812. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203813. pixelFormat.accumulationBufferGreenBits,
  203814. pixelFormat.accumulationBufferBlueBits,
  203815. pixelFormat.accumulationBufferAlphaBits);
  203816. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203817. attribs[n++] = NSOpenGLPFASampleBuffers;
  203818. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203819. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203820. attribs[n++] = NSOpenGLPFANoRecovery;
  203821. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203822. NSOpenGLPixelFormat* format
  203823. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203824. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203825. pixelFormat: format];
  203826. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203827. shareContext: sharedContext] autorelease];
  203828. const GLint swapInterval = 1;
  203829. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203830. [view setOpenGLContext: renderContext];
  203831. [renderContext setView: view];
  203832. [format release];
  203833. viewHolder = new NSViewComponentInternal (view, component);
  203834. }
  203835. ~WindowedGLContext()
  203836. {
  203837. makeInactive();
  203838. [renderContext clearDrawable];
  203839. viewHolder = 0;
  203840. }
  203841. bool makeActive() const throw()
  203842. {
  203843. jassert (renderContext != 0);
  203844. [view makeActive];
  203845. return isActive();
  203846. }
  203847. bool makeInactive() const throw()
  203848. {
  203849. [view makeInactive];
  203850. return true;
  203851. }
  203852. bool isActive() const throw()
  203853. {
  203854. return [NSOpenGLContext currentContext] == renderContext;
  203855. }
  203856. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203857. void* getRawContext() const throw() { return renderContext; }
  203858. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203859. {
  203860. }
  203861. void swapBuffers()
  203862. {
  203863. [renderContext flushBuffer];
  203864. }
  203865. bool setSwapInterval (const int numFramesPerSwap)
  203866. {
  203867. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203868. forParameter: NSOpenGLCPSwapInterval];
  203869. return true;
  203870. }
  203871. int getSwapInterval() const
  203872. {
  203873. GLint numFrames = 0;
  203874. [renderContext getValues: &numFrames
  203875. forParameter: NSOpenGLCPSwapInterval];
  203876. return numFrames;
  203877. }
  203878. void repaint()
  203879. {
  203880. // we need to invalidate the juce view that holds this gl view, to make it
  203881. // cause a repaint callback
  203882. NSView* v = (NSView*) viewHolder->view;
  203883. NSRect r = [v frame];
  203884. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203885. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203886. // repaint message, thus never causing our paint() callback, and never repainting
  203887. // the comp. So invalidating just a little bit around the edge helps..
  203888. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203889. }
  203890. void* getNativeWindowHandle() const { return viewHolder->view; }
  203891. juce_UseDebuggingNewOperator
  203892. NSOpenGLContext* renderContext;
  203893. ThreadSafeNSOpenGLView* view;
  203894. private:
  203895. OpenGLPixelFormat pixelFormat;
  203896. ScopedPointer <NSViewComponentInternal> viewHolder;
  203897. WindowedGLContext (const WindowedGLContext&);
  203898. WindowedGLContext& operator= (const WindowedGLContext&);
  203899. };
  203900. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  203901. const OpenGLPixelFormat& pixelFormat,
  203902. const OpenGLContext* const contextToShareWith)
  203903. {
  203904. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  203905. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  203906. return (c->renderContext != 0) ? c.release() : 0;
  203907. }
  203908. void* OpenGLComponent::getNativeWindowHandle() const
  203909. {
  203910. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  203911. : 0;
  203912. }
  203913. void juce_glViewport (const int w, const int h)
  203914. {
  203915. glViewport (0, 0, w, h);
  203916. }
  203917. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203918. OwnedArray <OpenGLPixelFormat>& results)
  203919. {
  203920. /* GLint attribs [64];
  203921. int n = 0;
  203922. attribs[n++] = AGL_RGBA;
  203923. attribs[n++] = AGL_DOUBLEBUFFER;
  203924. attribs[n++] = AGL_ACCELERATED;
  203925. attribs[n++] = AGL_NO_RECOVERY;
  203926. attribs[n++] = AGL_NONE;
  203927. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  203928. while (p != 0)
  203929. {
  203930. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  203931. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  203932. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  203933. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  203934. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  203935. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  203936. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  203937. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  203938. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  203939. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  203940. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  203941. results.add (pf);
  203942. p = aglNextPixelFormat (p);
  203943. }*/
  203944. //jassertfalse //xxx can't see how you do this in cocoa!
  203945. }
  203946. #else
  203947. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  203948. const OpenGLPixelFormat& pixelFormat,
  203949. const OpenGLContext* const contextToShareWith)
  203950. {
  203951. return 0;
  203952. }
  203953. void juce_glViewport (const int w, const int h)
  203954. {
  203955. //glViewport (0, 0, w, h);
  203956. }
  203957. #endif
  203958. #endif
  203959. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  203960. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  203961. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203962. // compiled on its own).
  203963. #if JUCE_INCLUDED_FILE
  203964. #if JUCE_MAC
  203965. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  203966. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  203967. {
  203968. NSImage* im = CoreGraphicsImage::createNSImage (image);
  203969. NSCursor* c = [[NSCursor alloc] initWithImage: im
  203970. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  203971. [im release];
  203972. return (void*) c;
  203973. }
  203974. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  203975. {
  203976. MemoryInputStream stream (data, size, false);
  203977. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  203978. jassert (im != 0);
  203979. if (im == 0)
  203980. return 0;
  203981. return juce_createMouseCursorFromImage (*im,
  203982. (int) (hx * im->getWidth()),
  203983. (int) (hy * im->getHeight()));
  203984. }
  203985. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  203986. {
  203987. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  203988. MemoryBlock mb;
  203989. if (f.getChildFile (filename).loadFileAsData (mb))
  203990. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  203991. return 0;
  203992. }
  203993. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  203994. {
  203995. const ScopedAutoReleasePool pool;
  203996. NSCursor* c = 0;
  203997. switch (type)
  203998. {
  203999. case MouseCursor::NormalCursor:
  204000. c = [NSCursor arrowCursor];
  204001. break;
  204002. case MouseCursor::NoCursor:
  204003. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  204004. case MouseCursor::DraggingHandCursor:
  204005. c = [NSCursor openHandCursor];
  204006. break;
  204007. case MouseCursor::CopyingCursor:
  204008. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204009. case MouseCursor::WaitCursor:
  204010. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204011. break;
  204012. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204013. case MouseCursor::IBeamCursor:
  204014. c = [NSCursor IBeamCursor];
  204015. break;
  204016. case MouseCursor::PointingHandCursor:
  204017. c = [NSCursor pointingHandCursor];
  204018. break;
  204019. case MouseCursor::LeftRightResizeCursor:
  204020. c = [NSCursor resizeLeftRightCursor];
  204021. break;
  204022. case MouseCursor::LeftEdgeResizeCursor:
  204023. c = [NSCursor resizeLeftCursor];
  204024. break;
  204025. case MouseCursor::RightEdgeResizeCursor:
  204026. c = [NSCursor resizeRightCursor];
  204027. break;
  204028. case MouseCursor::UpDownResizeCursor:
  204029. case MouseCursor::TopEdgeResizeCursor:
  204030. case MouseCursor::BottomEdgeResizeCursor:
  204031. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204032. case MouseCursor::TopLeftCornerResizeCursor:
  204033. case MouseCursor::BottomRightCornerResizeCursor:
  204034. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204035. case MouseCursor::TopRightCornerResizeCursor:
  204036. case MouseCursor::BottomLeftCornerResizeCursor:
  204037. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204038. case MouseCursor::UpDownLeftRightResizeCursor:
  204039. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204040. case MouseCursor::CrosshairCursor:
  204041. c = [NSCursor crosshairCursor];
  204042. break;
  204043. }
  204044. [c retain];
  204045. return (void*) c;
  204046. }
  204047. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204048. {
  204049. NSCursor* c = (NSCursor*) cursorHandle;
  204050. [c release];
  204051. }
  204052. void MouseCursor::showInAllWindows() const throw()
  204053. {
  204054. showInWindow (0);
  204055. }
  204056. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204057. {
  204058. NSCursor* const c = (NSCursor*) getHandle();
  204059. [c set];
  204060. }
  204061. #else
  204062. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204063. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204064. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204065. void MouseCursor::showInAllWindows() const throw() {}
  204066. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204067. #endif
  204068. #endif
  204069. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204070. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204071. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204072. // compiled on its own).
  204073. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204074. #if JUCE_MAC
  204075. END_JUCE_NAMESPACE
  204076. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204077. @interface DownloadClickDetector : NSObject
  204078. {
  204079. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204080. }
  204081. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204082. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204083. request: (NSURLRequest*) request
  204084. frame: (WebFrame*) frame
  204085. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204086. @end
  204087. @implementation DownloadClickDetector
  204088. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204089. {
  204090. [super init];
  204091. ownerComponent = ownerComponent_;
  204092. return self;
  204093. }
  204094. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204095. request: (NSURLRequest*) request
  204096. frame: (WebFrame*) frame
  204097. decisionListener: (id <WebPolicyDecisionListener>) listener
  204098. {
  204099. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204100. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204101. [listener use];
  204102. else
  204103. [listener ignore];
  204104. }
  204105. @end
  204106. BEGIN_JUCE_NAMESPACE
  204107. class WebBrowserComponentInternal : public NSViewComponent
  204108. {
  204109. public:
  204110. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204111. {
  204112. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204113. frameName: @""
  204114. groupName: @""];
  204115. setView (webView);
  204116. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204117. [webView setPolicyDelegate: clickListener];
  204118. }
  204119. ~WebBrowserComponentInternal()
  204120. {
  204121. [webView setPolicyDelegate: nil];
  204122. [clickListener release];
  204123. setView (0);
  204124. }
  204125. void goToURL (const String& url,
  204126. const StringArray* headers,
  204127. const MemoryBlock* postData)
  204128. {
  204129. NSMutableURLRequest* r
  204130. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204131. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204132. timeoutInterval: 30.0];
  204133. if (postData != 0 && postData->getSize() > 0)
  204134. {
  204135. [r setHTTPMethod: @"POST"];
  204136. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204137. length: postData->getSize()]];
  204138. }
  204139. if (headers != 0)
  204140. {
  204141. for (int i = 0; i < headers->size(); ++i)
  204142. {
  204143. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204144. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204145. [r setValue: juceStringToNS (headerValue)
  204146. forHTTPHeaderField: juceStringToNS (headerName)];
  204147. }
  204148. }
  204149. stop();
  204150. [[webView mainFrame] loadRequest: r];
  204151. }
  204152. void goBack()
  204153. {
  204154. [webView goBack];
  204155. }
  204156. void goForward()
  204157. {
  204158. [webView goForward];
  204159. }
  204160. void stop()
  204161. {
  204162. [webView stopLoading: nil];
  204163. }
  204164. void refresh()
  204165. {
  204166. [webView reload: nil];
  204167. }
  204168. private:
  204169. WebView* webView;
  204170. DownloadClickDetector* clickListener;
  204171. };
  204172. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204173. : browser (0),
  204174. blankPageShown (false),
  204175. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204176. {
  204177. setOpaque (true);
  204178. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204179. }
  204180. WebBrowserComponent::~WebBrowserComponent()
  204181. {
  204182. deleteAndZero (browser);
  204183. }
  204184. void WebBrowserComponent::goToURL (const String& url,
  204185. const StringArray* headers,
  204186. const MemoryBlock* postData)
  204187. {
  204188. lastURL = url;
  204189. lastHeaders.clear();
  204190. if (headers != 0)
  204191. lastHeaders = *headers;
  204192. lastPostData.setSize (0);
  204193. if (postData != 0)
  204194. lastPostData = *postData;
  204195. blankPageShown = false;
  204196. browser->goToURL (url, headers, postData);
  204197. }
  204198. void WebBrowserComponent::stop()
  204199. {
  204200. browser->stop();
  204201. }
  204202. void WebBrowserComponent::goBack()
  204203. {
  204204. lastURL = String::empty;
  204205. blankPageShown = false;
  204206. browser->goBack();
  204207. }
  204208. void WebBrowserComponent::goForward()
  204209. {
  204210. lastURL = String::empty;
  204211. browser->goForward();
  204212. }
  204213. void WebBrowserComponent::refresh()
  204214. {
  204215. browser->refresh();
  204216. }
  204217. void WebBrowserComponent::paint (Graphics& g)
  204218. {
  204219. }
  204220. void WebBrowserComponent::checkWindowAssociation()
  204221. {
  204222. if (isShowing())
  204223. {
  204224. if (blankPageShown)
  204225. goBack();
  204226. }
  204227. else
  204228. {
  204229. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204230. {
  204231. // when the component becomes invisible, some stuff like flash
  204232. // carries on playing audio, so we need to force it onto a blank
  204233. // page to avoid this, (and send it back when it's made visible again).
  204234. blankPageShown = true;
  204235. browser->goToURL ("about:blank", 0, 0);
  204236. }
  204237. }
  204238. }
  204239. void WebBrowserComponent::reloadLastURL()
  204240. {
  204241. if (lastURL.isNotEmpty())
  204242. {
  204243. goToURL (lastURL, &lastHeaders, &lastPostData);
  204244. lastURL = String::empty;
  204245. }
  204246. }
  204247. void WebBrowserComponent::parentHierarchyChanged()
  204248. {
  204249. checkWindowAssociation();
  204250. }
  204251. void WebBrowserComponent::resized()
  204252. {
  204253. browser->setSize (getWidth(), getHeight());
  204254. }
  204255. void WebBrowserComponent::visibilityChanged()
  204256. {
  204257. checkWindowAssociation();
  204258. }
  204259. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204260. {
  204261. return true;
  204262. }
  204263. #else
  204264. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204265. {
  204266. }
  204267. WebBrowserComponent::~WebBrowserComponent()
  204268. {
  204269. }
  204270. void WebBrowserComponent::goToURL (const String& url,
  204271. const StringArray* headers,
  204272. const MemoryBlock* postData)
  204273. {
  204274. }
  204275. void WebBrowserComponent::stop()
  204276. {
  204277. }
  204278. void WebBrowserComponent::goBack()
  204279. {
  204280. }
  204281. void WebBrowserComponent::goForward()
  204282. {
  204283. }
  204284. void WebBrowserComponent::refresh()
  204285. {
  204286. }
  204287. void WebBrowserComponent::paint (Graphics& g)
  204288. {
  204289. }
  204290. void WebBrowserComponent::checkWindowAssociation()
  204291. {
  204292. }
  204293. void WebBrowserComponent::reloadLastURL()
  204294. {
  204295. }
  204296. void WebBrowserComponent::parentHierarchyChanged()
  204297. {
  204298. }
  204299. void WebBrowserComponent::resized()
  204300. {
  204301. }
  204302. void WebBrowserComponent::visibilityChanged()
  204303. {
  204304. }
  204305. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204306. {
  204307. return true;
  204308. }
  204309. #endif
  204310. #endif
  204311. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204312. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204313. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204314. // compiled on its own).
  204315. #if JUCE_INCLUDED_FILE
  204316. class IPhoneAudioIODevice : public AudioIODevice
  204317. {
  204318. public:
  204319. IPhoneAudioIODevice (const String& deviceName)
  204320. : AudioIODevice (deviceName, T("Audio")),
  204321. audioUnit (0),
  204322. isRunning (false),
  204323. callback (0),
  204324. actualBufferSize (0),
  204325. floatData (1, 2)
  204326. {
  204327. numInputChannels = 2;
  204328. numOutputChannels = 2;
  204329. preferredBufferSize = 0;
  204330. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204331. updateDeviceInfo();
  204332. }
  204333. ~IPhoneAudioIODevice()
  204334. {
  204335. close();
  204336. }
  204337. const StringArray getOutputChannelNames()
  204338. {
  204339. StringArray s;
  204340. s.add ("Left");
  204341. s.add ("Right");
  204342. return s;
  204343. }
  204344. const StringArray getInputChannelNames()
  204345. {
  204346. StringArray s;
  204347. if (audioInputIsAvailable)
  204348. {
  204349. s.add ("Left");
  204350. s.add ("Right");
  204351. }
  204352. return s;
  204353. }
  204354. int getNumSampleRates()
  204355. {
  204356. return 1;
  204357. }
  204358. double getSampleRate (int index)
  204359. {
  204360. return sampleRate;
  204361. }
  204362. int getNumBufferSizesAvailable()
  204363. {
  204364. return 1;
  204365. }
  204366. int getBufferSizeSamples (int index)
  204367. {
  204368. return getDefaultBufferSize();
  204369. }
  204370. int getDefaultBufferSize()
  204371. {
  204372. return 1024;
  204373. }
  204374. const String open (const BitArray& inputChannels,
  204375. const BitArray& outputChannels,
  204376. double sampleRate,
  204377. int bufferSize)
  204378. {
  204379. close();
  204380. lastError = String::empty;
  204381. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204382. // xxx set up channel mapping
  204383. activeOutputChans = outputChannels;
  204384. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204385. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204386. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204387. activeInputChans = inputChannels;
  204388. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204389. numInputChannels = activeInputChans.countNumberOfSetBits();
  204390. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204391. AudioSessionSetActive (true);
  204392. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204393. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204394. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204395. fixAudioRouteIfSetToReceiver();
  204396. updateDeviceInfo();
  204397. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204398. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204399. actualBufferSize = preferredBufferSize;
  204400. prepareFloatBuffers();
  204401. isRunning = true;
  204402. propertyChanged (0, 0, 0); // creates and starts the AU
  204403. lastError = audioUnit != 0 ? String::empty
  204404. : T("Couldn't open the device");
  204405. return lastError;
  204406. }
  204407. void close()
  204408. {
  204409. if (isRunning)
  204410. {
  204411. isRunning = false;
  204412. AudioSessionSetActive (false);
  204413. if (audioUnit != 0)
  204414. {
  204415. AudioComponentInstanceDispose (audioUnit);
  204416. audioUnit = 0;
  204417. }
  204418. }
  204419. }
  204420. bool isOpen()
  204421. {
  204422. return isRunning;
  204423. }
  204424. int getCurrentBufferSizeSamples()
  204425. {
  204426. return actualBufferSize;
  204427. }
  204428. double getCurrentSampleRate()
  204429. {
  204430. return sampleRate;
  204431. }
  204432. int getCurrentBitDepth()
  204433. {
  204434. return 16;
  204435. }
  204436. const BitArray getActiveOutputChannels() const
  204437. {
  204438. return activeOutputChans;
  204439. }
  204440. const BitArray getActiveInputChannels() const
  204441. {
  204442. return activeInputChans;
  204443. }
  204444. int getOutputLatencyInSamples()
  204445. {
  204446. return 0; //xxx
  204447. }
  204448. int getInputLatencyInSamples()
  204449. {
  204450. return 0; //xxx
  204451. }
  204452. void start (AudioIODeviceCallback* callback_)
  204453. {
  204454. if (isRunning && callback != callback_)
  204455. {
  204456. if (callback_ != 0)
  204457. callback_->audioDeviceAboutToStart (this);
  204458. const ScopedLock sl (callbackLock);
  204459. callback = callback_;
  204460. }
  204461. }
  204462. void stop()
  204463. {
  204464. if (isRunning)
  204465. {
  204466. AudioIODeviceCallback* lastCallback;
  204467. {
  204468. const ScopedLock sl (callbackLock);
  204469. lastCallback = callback;
  204470. callback = 0;
  204471. }
  204472. if (lastCallback != 0)
  204473. lastCallback->audioDeviceStopped();
  204474. }
  204475. }
  204476. bool isPlaying()
  204477. {
  204478. return isRunning && callback != 0;
  204479. }
  204480. const String getLastError()
  204481. {
  204482. return lastError;
  204483. }
  204484. private:
  204485. CriticalSection callbackLock;
  204486. Float64 sampleRate;
  204487. int numInputChannels, numOutputChannels;
  204488. int preferredBufferSize;
  204489. int actualBufferSize;
  204490. bool isRunning;
  204491. String lastError;
  204492. AudioStreamBasicDescription format;
  204493. AudioUnit audioUnit;
  204494. UInt32 audioInputIsAvailable;
  204495. AudioIODeviceCallback* callback;
  204496. BitArray activeOutputChans, activeInputChans;
  204497. AudioSampleBuffer floatData;
  204498. float* inputChannels[3];
  204499. float* outputChannels[3];
  204500. bool monoInputChannelNumber, monoOutputChannelNumber;
  204501. void prepareFloatBuffers()
  204502. {
  204503. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204504. zerostruct (inputChannels);
  204505. zerostruct (outputChannels);
  204506. for (int i = 0; i < numInputChannels; ++i)
  204507. inputChannels[i] = floatData.getSampleData (i);
  204508. for (int i = 0; i < numOutputChannels; ++i)
  204509. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204510. }
  204511. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204512. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204513. {
  204514. OSStatus err = noErr;
  204515. if (audioInputIsAvailable)
  204516. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204517. const ScopedLock sl (callbackLock);
  204518. if (callback != 0)
  204519. {
  204520. if (audioInputIsAvailable && numInputChannels > 0)
  204521. {
  204522. short* shortData = (short*) ioData->mBuffers[0].mData;
  204523. if (numInputChannels >= 2)
  204524. {
  204525. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204526. {
  204527. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204528. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204529. }
  204530. }
  204531. else
  204532. {
  204533. if (monoInputChannelNumber > 0)
  204534. ++shortData;
  204535. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204536. {
  204537. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204538. ++shortData;
  204539. }
  204540. }
  204541. }
  204542. else
  204543. {
  204544. for (int i = numInputChannels; --i >= 0;)
  204545. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204546. }
  204547. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204548. outputChannels, numOutputChannels,
  204549. (int) inNumberFrames);
  204550. short* shortData = (short*) ioData->mBuffers[0].mData;
  204551. int n = 0;
  204552. if (numOutputChannels >= 2)
  204553. {
  204554. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204555. {
  204556. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204557. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204558. }
  204559. }
  204560. else if (numOutputChannels == 1)
  204561. {
  204562. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204563. {
  204564. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204565. shortData [n++] = s;
  204566. shortData [n++] = s;
  204567. }
  204568. }
  204569. else
  204570. {
  204571. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204572. }
  204573. }
  204574. else
  204575. {
  204576. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204577. }
  204578. return err;
  204579. }
  204580. void updateDeviceInfo()
  204581. {
  204582. UInt32 size = sizeof (sampleRate);
  204583. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204584. size = sizeof (audioInputIsAvailable);
  204585. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204586. }
  204587. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204588. {
  204589. if (! isRunning)
  204590. return;
  204591. if (inPropertyValue != 0)
  204592. {
  204593. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204594. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204595. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204596. SInt32 routeChangeReason;
  204597. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204598. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204599. fixAudioRouteIfSetToReceiver();
  204600. }
  204601. updateDeviceInfo();
  204602. createAudioUnit();
  204603. AudioSessionSetActive (true);
  204604. if (audioUnit != 0)
  204605. {
  204606. UInt32 formatSize = sizeof (format);
  204607. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204608. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204609. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204610. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204611. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204612. AudioOutputUnitStart (audioUnit);
  204613. }
  204614. }
  204615. void interruptionListener (UInt32 inInterruption)
  204616. {
  204617. if (inInterruption == kAudioSessionEndInterruption)
  204618. {
  204619. isRunning = true;
  204620. AudioSessionSetActive (true);
  204621. AudioOutputUnitStart (audioUnit);
  204622. }
  204623. }
  204624. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204625. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204626. {
  204627. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204628. }
  204629. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204630. {
  204631. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204632. }
  204633. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204634. {
  204635. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204636. }
  204637. void resetFormat (const int numChannels)
  204638. {
  204639. memset (&format, 0, sizeof (format));
  204640. format.mFormatID = kAudioFormatLinearPCM;
  204641. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204642. format.mBitsPerChannel = 8 * sizeof (short);
  204643. format.mChannelsPerFrame = 2;
  204644. format.mFramesPerPacket = 1;
  204645. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204646. }
  204647. bool createAudioUnit()
  204648. {
  204649. if (audioUnit != 0)
  204650. {
  204651. AudioComponentInstanceDispose (audioUnit);
  204652. audioUnit = 0;
  204653. }
  204654. resetFormat (2);
  204655. AudioComponentDescription desc;
  204656. desc.componentType = kAudioUnitType_Output;
  204657. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204658. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204659. desc.componentFlags = 0;
  204660. desc.componentFlagsMask = 0;
  204661. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204662. AudioComponentInstanceNew (comp, &audioUnit);
  204663. if (audioUnit == 0)
  204664. return false;
  204665. const UInt32 one = 1;
  204666. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204667. AudioChannelLayout layout;
  204668. layout.mChannelBitmap = 0;
  204669. layout.mNumberChannelDescriptions = 0;
  204670. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204671. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204672. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204673. AURenderCallbackStruct inputProc;
  204674. inputProc.inputProc = processStatic;
  204675. inputProc.inputProcRefCon = this;
  204676. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204677. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204678. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204679. AudioUnitInitialize (audioUnit);
  204680. return true;
  204681. }
  204682. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204683. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204684. static void fixAudioRouteIfSetToReceiver()
  204685. {
  204686. CFStringRef audioRoute = 0;
  204687. UInt32 propertySize = sizeof (audioRoute);
  204688. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204689. {
  204690. NSString* route = (NSString*) audioRoute;
  204691. //DBG ("audio route: " + nsStringToJuce (route));
  204692. if ([route hasPrefix: @"Receiver"])
  204693. {
  204694. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204695. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204696. }
  204697. CFRelease (audioRoute);
  204698. }
  204699. }
  204700. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204701. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204702. };
  204703. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204704. {
  204705. public:
  204706. IPhoneAudioIODeviceType()
  204707. : AudioIODeviceType (T("iPhone Audio"))
  204708. {
  204709. }
  204710. ~IPhoneAudioIODeviceType()
  204711. {
  204712. }
  204713. void scanForDevices()
  204714. {
  204715. }
  204716. const StringArray getDeviceNames (const bool wantInputNames) const
  204717. {
  204718. StringArray s;
  204719. s.add ("iPhone Audio");
  204720. return s;
  204721. }
  204722. int getDefaultDeviceIndex (const bool forInput) const
  204723. {
  204724. return 0;
  204725. }
  204726. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  204727. {
  204728. return device != 0 ? 0 : -1;
  204729. }
  204730. bool hasSeparateInputsAndOutputs() const { return false; }
  204731. AudioIODevice* createDevice (const String& outputDeviceName,
  204732. const String& inputDeviceName)
  204733. {
  204734. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204735. {
  204736. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204737. : inputDeviceName);
  204738. }
  204739. return 0;
  204740. }
  204741. juce_UseDebuggingNewOperator
  204742. private:
  204743. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204744. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204745. };
  204746. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204747. {
  204748. return new IPhoneAudioIODeviceType();
  204749. }
  204750. #endif
  204751. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204752. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204753. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204754. // compiled on its own).
  204755. #if JUCE_INCLUDED_FILE
  204756. #if JUCE_MAC
  204757. #undef log
  204758. #define log(a) Logger::writeToLog(a)
  204759. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204760. {
  204761. if (err == noErr)
  204762. return true;
  204763. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  204764. jassertfalse
  204765. return false;
  204766. }
  204767. #undef OK
  204768. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204769. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204770. {
  204771. String result;
  204772. CFStringRef str = 0;
  204773. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204774. if (str != 0)
  204775. {
  204776. result = PlatformUtilities::cfStringToJuceString (str);
  204777. CFRelease (str);
  204778. str = 0;
  204779. }
  204780. MIDIEntityRef entity = 0;
  204781. MIDIEndpointGetEntity (endpoint, &entity);
  204782. if (entity == 0)
  204783. return result; // probably virtual
  204784. if (result.isEmpty())
  204785. {
  204786. // endpoint name has zero length - try the entity
  204787. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204788. if (str != 0)
  204789. {
  204790. result += PlatformUtilities::cfStringToJuceString (str);
  204791. CFRelease (str);
  204792. str = 0;
  204793. }
  204794. }
  204795. // now consider the device's name
  204796. MIDIDeviceRef device = 0;
  204797. MIDIEntityGetDevice (entity, &device);
  204798. if (device == 0)
  204799. return result;
  204800. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204801. if (str != 0)
  204802. {
  204803. const String s (PlatformUtilities::cfStringToJuceString (str));
  204804. CFRelease (str);
  204805. // if an external device has only one entity, throw away
  204806. // the endpoint name and just use the device name
  204807. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204808. {
  204809. result = s;
  204810. }
  204811. else if (! result.startsWithIgnoreCase (s))
  204812. {
  204813. // prepend the device name to the entity name
  204814. result = (s + T(" ") + result).trimEnd();
  204815. }
  204816. }
  204817. return result;
  204818. }
  204819. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204820. {
  204821. String result;
  204822. // Does the endpoint have connections?
  204823. CFDataRef connections = 0;
  204824. int numConnections = 0;
  204825. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204826. if (connections != 0)
  204827. {
  204828. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204829. if (numConnections > 0)
  204830. {
  204831. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204832. for (int i = 0; i < numConnections; ++i, ++pid)
  204833. {
  204834. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204835. MIDIObjectRef connObject;
  204836. MIDIObjectType connObjectType;
  204837. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204838. if (err == noErr)
  204839. {
  204840. String s;
  204841. if (connObjectType == kMIDIObjectType_ExternalSource
  204842. || connObjectType == kMIDIObjectType_ExternalDestination)
  204843. {
  204844. // Connected to an external device's endpoint (10.3 and later).
  204845. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204846. }
  204847. else
  204848. {
  204849. // Connected to an external device (10.2) (or something else, catch-all)
  204850. CFStringRef str = 0;
  204851. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204852. if (str != 0)
  204853. {
  204854. s = PlatformUtilities::cfStringToJuceString (str);
  204855. CFRelease (str);
  204856. }
  204857. }
  204858. if (s.isNotEmpty())
  204859. {
  204860. if (result.isNotEmpty())
  204861. result += (", ");
  204862. result += s;
  204863. }
  204864. }
  204865. }
  204866. }
  204867. CFRelease (connections);
  204868. }
  204869. if (result.isNotEmpty())
  204870. return result;
  204871. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204872. return getEndpointName (endpoint, false);
  204873. }
  204874. const StringArray MidiOutput::getDevices()
  204875. {
  204876. StringArray s;
  204877. const ItemCount num = MIDIGetNumberOfDestinations();
  204878. for (ItemCount i = 0; i < num; ++i)
  204879. {
  204880. MIDIEndpointRef dest = MIDIGetDestination (i);
  204881. if (dest != 0)
  204882. {
  204883. String name (getConnectedEndpointName (dest));
  204884. if (name.isEmpty())
  204885. name = "<error>";
  204886. s.add (name);
  204887. }
  204888. else
  204889. {
  204890. s.add ("<error>");
  204891. }
  204892. }
  204893. return s;
  204894. }
  204895. int MidiOutput::getDefaultDeviceIndex()
  204896. {
  204897. return 0;
  204898. }
  204899. static MIDIClientRef globalMidiClient;
  204900. static bool hasGlobalClientBeenCreated = false;
  204901. static bool makeSureClientExists()
  204902. {
  204903. if (! hasGlobalClientBeenCreated)
  204904. {
  204905. String name (T("JUCE"));
  204906. if (JUCEApplication::getInstance() != 0)
  204907. name = JUCEApplication::getInstance()->getApplicationName();
  204908. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  204909. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  204910. CFRelease (appName);
  204911. }
  204912. return hasGlobalClientBeenCreated;
  204913. }
  204914. class MidiPortAndEndpoint
  204915. {
  204916. public:
  204917. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  204918. : port (port_), endPoint (endPoint_)
  204919. {
  204920. }
  204921. ~MidiPortAndEndpoint()
  204922. {
  204923. if (port != 0)
  204924. MIDIPortDispose (port);
  204925. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  204926. MIDIEndpointDispose (endPoint);
  204927. }
  204928. MIDIPortRef port;
  204929. MIDIEndpointRef endPoint;
  204930. };
  204931. MidiOutput* MidiOutput::openDevice (int index)
  204932. {
  204933. MidiOutput* mo = 0;
  204934. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  204935. {
  204936. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  204937. CFStringRef pname;
  204938. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  204939. {
  204940. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  204941. if (makeSureClientExists())
  204942. {
  204943. MIDIPortRef port;
  204944. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  204945. {
  204946. mo = new MidiOutput();
  204947. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  204948. }
  204949. }
  204950. CFRelease (pname);
  204951. }
  204952. }
  204953. return mo;
  204954. }
  204955. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  204956. {
  204957. MidiOutput* mo = 0;
  204958. if (makeSureClientExists())
  204959. {
  204960. MIDIEndpointRef endPoint;
  204961. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  204962. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  204963. {
  204964. mo = new MidiOutput();
  204965. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  204966. }
  204967. CFRelease (name);
  204968. }
  204969. return mo;
  204970. }
  204971. MidiOutput::~MidiOutput()
  204972. {
  204973. delete (MidiPortAndEndpoint*) internal;
  204974. }
  204975. void MidiOutput::reset()
  204976. {
  204977. }
  204978. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  204979. {
  204980. return false;
  204981. }
  204982. void MidiOutput::setVolume (float leftVol, float rightVol)
  204983. {
  204984. }
  204985. void MidiOutput::sendMessageNow (const MidiMessage& message)
  204986. {
  204987. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  204988. if (message.isSysEx())
  204989. {
  204990. const int maxPacketSize = 256;
  204991. int pos = 0, bytesLeft = message.getRawDataSize();
  204992. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  204993. HeapBlock <MIDIPacketList> packets;
  204994. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  204995. packets->numPackets = numPackets;
  204996. MIDIPacket* p = packets->packet;
  204997. for (int i = 0; i < numPackets; ++i)
  204998. {
  204999. p->timeStamp = 0;
  205000. p->length = jmin (maxPacketSize, bytesLeft);
  205001. memcpy (p->data, message.getRawData() + pos, p->length);
  205002. pos += p->length;
  205003. bytesLeft -= p->length;
  205004. p = MIDIPacketNext (p);
  205005. }
  205006. if (mpe->port != 0)
  205007. MIDISend (mpe->port, mpe->endPoint, packets);
  205008. else
  205009. MIDIReceived (mpe->endPoint, packets);
  205010. }
  205011. else
  205012. {
  205013. MIDIPacketList packets;
  205014. packets.numPackets = 1;
  205015. packets.packet[0].timeStamp = 0;
  205016. packets.packet[0].length = message.getRawDataSize();
  205017. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205018. if (mpe->port != 0)
  205019. MIDISend (mpe->port, mpe->endPoint, &packets);
  205020. else
  205021. MIDIReceived (mpe->endPoint, &packets);
  205022. }
  205023. }
  205024. const StringArray MidiInput::getDevices()
  205025. {
  205026. StringArray s;
  205027. const ItemCount num = MIDIGetNumberOfSources();
  205028. for (ItemCount i = 0; i < num; ++i)
  205029. {
  205030. MIDIEndpointRef source = MIDIGetSource (i);
  205031. if (source != 0)
  205032. {
  205033. String name (getConnectedEndpointName (source));
  205034. if (name.isEmpty())
  205035. name = "<error>";
  205036. s.add (name);
  205037. }
  205038. else
  205039. {
  205040. s.add ("<error>");
  205041. }
  205042. }
  205043. return s;
  205044. }
  205045. int MidiInput::getDefaultDeviceIndex()
  205046. {
  205047. return 0;
  205048. }
  205049. struct MidiPortAndCallback
  205050. {
  205051. MidiInput* input;
  205052. MidiPortAndEndpoint* portAndEndpoint;
  205053. MidiInputCallback* callback;
  205054. MemoryBlock pendingData;
  205055. int pendingBytes;
  205056. double pendingDataTime;
  205057. bool active;
  205058. void processSysex (const uint8*& d, int& size, const double time)
  205059. {
  205060. if (*d == 0xf0)
  205061. {
  205062. pendingBytes = 0;
  205063. pendingDataTime = time;
  205064. }
  205065. pendingData.ensureSize (pendingBytes + size, false);
  205066. uint8* totalMessage = (uint8*) pendingData.getData();
  205067. uint8* dest = totalMessage + pendingBytes;
  205068. while (size > 0)
  205069. {
  205070. if (pendingBytes > 0 && *d >= 0x80)
  205071. {
  205072. if (*d >= 0xfa || *d == 0xf8)
  205073. {
  205074. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205075. ++d;
  205076. --size;
  205077. }
  205078. else
  205079. {
  205080. if (*d == 0xf7)
  205081. {
  205082. *dest++ = *d++;
  205083. pendingBytes++;
  205084. --size;
  205085. }
  205086. break;
  205087. }
  205088. }
  205089. else
  205090. {
  205091. *dest++ = *d++;
  205092. pendingBytes++;
  205093. --size;
  205094. }
  205095. }
  205096. if (totalMessage [pendingBytes - 1] == 0xf7)
  205097. {
  205098. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205099. pendingBytes = 0;
  205100. }
  205101. else
  205102. {
  205103. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205104. }
  205105. }
  205106. };
  205107. namespace CoreMidiCallbacks
  205108. {
  205109. static CriticalSection callbackLock;
  205110. static VoidArray activeCallbacks;
  205111. }
  205112. static void midiInputProc (const MIDIPacketList* pktlist,
  205113. void* readProcRefCon,
  205114. void* srcConnRefCon)
  205115. {
  205116. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205117. const double originalTime = time;
  205118. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205119. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205120. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205121. {
  205122. const MIDIPacket* packet = &pktlist->packet[0];
  205123. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205124. {
  205125. const uint8* d = (const uint8*) (packet->data);
  205126. int size = packet->length;
  205127. while (size > 0)
  205128. {
  205129. time = originalTime;
  205130. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205131. {
  205132. mpc->processSysex (d, size, time);
  205133. }
  205134. else
  205135. {
  205136. int used = 0;
  205137. const MidiMessage m (d, size, used, 0, time);
  205138. if (used <= 0)
  205139. {
  205140. jassertfalse // malformed midi message
  205141. break;
  205142. }
  205143. else
  205144. {
  205145. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205146. }
  205147. size -= used;
  205148. d += used;
  205149. }
  205150. }
  205151. packet = MIDIPacketNext (packet);
  205152. }
  205153. }
  205154. }
  205155. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205156. {
  205157. MidiInput* mi = 0;
  205158. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205159. {
  205160. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205161. if (endPoint != 0)
  205162. {
  205163. CFStringRef pname;
  205164. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205165. {
  205166. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205167. if (makeSureClientExists())
  205168. {
  205169. MIDIPortRef port;
  205170. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205171. mpc->active = false;
  205172. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205173. {
  205174. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205175. {
  205176. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205177. mpc->callback = callback;
  205178. mpc->pendingBytes = 0;
  205179. mpc->pendingData.ensureSize (128);
  205180. mi = new MidiInput (getDevices() [index]);
  205181. mpc->input = mi;
  205182. mi->internal = (void*) mpc;
  205183. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205184. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205185. }
  205186. else
  205187. {
  205188. OK (MIDIPortDispose (port));
  205189. }
  205190. }
  205191. }
  205192. }
  205193. CFRelease (pname);
  205194. }
  205195. }
  205196. return mi;
  205197. }
  205198. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205199. {
  205200. MidiInput* mi = 0;
  205201. if (makeSureClientExists())
  205202. {
  205203. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205204. mpc->active = false;
  205205. MIDIEndpointRef endPoint;
  205206. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205207. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205208. {
  205209. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205210. mpc->callback = callback;
  205211. mpc->pendingBytes = 0;
  205212. mpc->pendingData.ensureSize (128);
  205213. mi = new MidiInput (deviceName);
  205214. mpc->input = mi;
  205215. mi->internal = (void*) mpc;
  205216. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205217. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205218. }
  205219. CFRelease (name);
  205220. }
  205221. return mi;
  205222. }
  205223. MidiInput::MidiInput (const String& name_)
  205224. : name (name_)
  205225. {
  205226. }
  205227. MidiInput::~MidiInput()
  205228. {
  205229. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205230. mpc->active = false;
  205231. {
  205232. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205233. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205234. }
  205235. if (mpc->portAndEndpoint->port != 0)
  205236. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205237. delete mpc->portAndEndpoint;
  205238. delete mpc;
  205239. }
  205240. void MidiInput::start()
  205241. {
  205242. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205243. ((MidiPortAndCallback*) internal)->active = true;
  205244. }
  205245. void MidiInput::stop()
  205246. {
  205247. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205248. ((MidiPortAndCallback*) internal)->active = false;
  205249. }
  205250. #undef log
  205251. #else
  205252. MidiOutput::~MidiOutput()
  205253. {
  205254. }
  205255. void MidiOutput::reset()
  205256. {
  205257. }
  205258. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205259. {
  205260. return false;
  205261. }
  205262. void MidiOutput::setVolume (float leftVol, float rightVol)
  205263. {
  205264. }
  205265. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205266. {
  205267. }
  205268. const StringArray MidiOutput::getDevices()
  205269. {
  205270. return StringArray();
  205271. }
  205272. MidiOutput* MidiOutput::openDevice (int index)
  205273. {
  205274. return 0;
  205275. }
  205276. const StringArray MidiInput::getDevices()
  205277. {
  205278. return StringArray();
  205279. }
  205280. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205281. {
  205282. return 0;
  205283. }
  205284. #endif
  205285. #endif
  205286. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205287. #else
  205288. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205289. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205290. // compiled on its own).
  205291. #if JUCE_INCLUDED_FILE
  205292. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205293. #define SUPPORT_10_4_FONTS 1
  205294. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205295. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205296. #define SUPPORT_ONLY_10_4_FONTS 1
  205297. #endif
  205298. END_JUCE_NAMESPACE
  205299. @interface NSFont (PrivateHack)
  205300. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205301. @end
  205302. BEGIN_JUCE_NAMESPACE
  205303. #endif
  205304. class MacTypeface : public Typeface
  205305. {
  205306. public:
  205307. MacTypeface (const Font& font)
  205308. : Typeface (font.getTypefaceName())
  205309. {
  205310. const ScopedAutoReleasePool pool;
  205311. renderingTransform = CGAffineTransformIdentity;
  205312. bool needsItalicTransform = false;
  205313. #if JUCE_IPHONE
  205314. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205315. if (font.isItalic() || font.isBold())
  205316. {
  205317. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205318. for (NSString* i in familyFonts)
  205319. {
  205320. const String fn (nsStringToJuce (i));
  205321. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205322. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205323. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205324. || afterDash.containsIgnoreCase (T("italic"))
  205325. || fn.endsWithIgnoreCase (T("oblique"))
  205326. || fn.endsWithIgnoreCase (T("italic"));
  205327. if (probablyBold == font.isBold()
  205328. && probablyItalic == font.isItalic())
  205329. {
  205330. fontName = i;
  205331. needsItalicTransform = false;
  205332. break;
  205333. }
  205334. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205335. {
  205336. fontName = i;
  205337. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205338. }
  205339. }
  205340. if (needsItalicTransform)
  205341. renderingTransform.c = 0.15f;
  205342. }
  205343. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205344. const int ascender = abs (CGFontGetAscent (fontRef));
  205345. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205346. ascent = ascender / totalHeight;
  205347. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205348. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205349. #else
  205350. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205351. if (font.isItalic())
  205352. {
  205353. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205354. toHaveTrait: NSItalicFontMask];
  205355. if (newFont == nsFont)
  205356. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205357. nsFont = newFont;
  205358. }
  205359. if (font.isBold())
  205360. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205361. [nsFont retain];
  205362. ascent = fabsf ((float) [nsFont ascender]);
  205363. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205364. ascent /= totalSize;
  205365. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205366. if (needsItalicTransform)
  205367. {
  205368. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205369. renderingTransform.c = 0.15f;
  205370. }
  205371. #if SUPPORT_ONLY_10_4_FONTS
  205372. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205373. if (atsFont == 0)
  205374. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205375. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205376. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205377. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205378. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205379. #else
  205380. #if SUPPORT_10_4_FONTS
  205381. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205382. {
  205383. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205384. if (atsFont == 0)
  205385. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205386. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205387. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205388. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205389. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205390. }
  205391. else
  205392. #endif
  205393. {
  205394. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205395. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205396. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205397. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205398. }
  205399. #endif
  205400. #endif
  205401. }
  205402. ~MacTypeface()
  205403. {
  205404. #if ! JUCE_IPHONE
  205405. [nsFont release];
  205406. #endif
  205407. if (fontRef != 0)
  205408. CGFontRelease (fontRef);
  205409. }
  205410. float getAscent() const
  205411. {
  205412. return ascent;
  205413. }
  205414. float getDescent() const
  205415. {
  205416. return 1.0f - ascent;
  205417. }
  205418. float getStringWidth (const String& text)
  205419. {
  205420. if (fontRef == 0 || text.isEmpty())
  205421. return 0;
  205422. const int length = text.length();
  205423. HeapBlock <CGGlyph> glyphs;
  205424. createGlyphsForString (text, length, glyphs);
  205425. float x = 0;
  205426. #if SUPPORT_ONLY_10_4_FONTS
  205427. HeapBlock <NSSize> advances (length);
  205428. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205429. for (int i = 0; i < length; ++i)
  205430. x += advances[i].width;
  205431. #else
  205432. #if SUPPORT_10_4_FONTS
  205433. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205434. {
  205435. HeapBlock <NSSize> advances (length);
  205436. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205437. for (int i = 0; i < length; ++i)
  205438. x += advances[i].width;
  205439. }
  205440. else
  205441. #endif
  205442. {
  205443. HeapBlock <int> advances (length);
  205444. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205445. for (int i = 0; i < length; ++i)
  205446. x += advances[i];
  205447. }
  205448. #endif
  205449. return x * unitsToHeightScaleFactor;
  205450. }
  205451. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205452. {
  205453. xOffsets.add (0);
  205454. if (fontRef == 0 || text.isEmpty())
  205455. return;
  205456. const int length = text.length();
  205457. HeapBlock <CGGlyph> glyphs;
  205458. createGlyphsForString (text, length, glyphs);
  205459. #if SUPPORT_ONLY_10_4_FONTS
  205460. HeapBlock <NSSize> advances (length);
  205461. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205462. int x = 0;
  205463. for (int i = 0; i < length; ++i)
  205464. {
  205465. x += advances[i].width;
  205466. xOffsets.add (x * unitsToHeightScaleFactor);
  205467. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  205468. }
  205469. #else
  205470. #if SUPPORT_10_4_FONTS
  205471. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205472. {
  205473. HeapBlock <NSSize> advances (length);
  205474. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205475. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205476. float x = 0;
  205477. for (int i = 0; i < length; ++i)
  205478. {
  205479. x += advances[i].width;
  205480. xOffsets.add (x * unitsToHeightScaleFactor);
  205481. resultGlyphs.add (nsGlyphs[i]);
  205482. }
  205483. }
  205484. else
  205485. #endif
  205486. {
  205487. HeapBlock <int> advances (length);
  205488. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205489. {
  205490. int x = 0;
  205491. for (int i = 0; i < length; ++i)
  205492. {
  205493. x += advances [i];
  205494. xOffsets.add (x * unitsToHeightScaleFactor);
  205495. resultGlyphs.add (glyphs[i]);
  205496. }
  205497. }
  205498. }
  205499. #endif
  205500. }
  205501. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205502. {
  205503. #if JUCE_IPHONE
  205504. return false;
  205505. #else
  205506. if (nsFont == 0)
  205507. return false;
  205508. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205509. jassert (path.isEmpty());
  205510. const ScopedAutoReleasePool pool;
  205511. NSBezierPath* bez = [NSBezierPath bezierPath];
  205512. [bez moveToPoint: NSMakePoint (0, 0)];
  205513. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205514. inFont: nsFont];
  205515. for (int i = 0; i < [bez elementCount]; ++i)
  205516. {
  205517. NSPoint p[3];
  205518. switch ([bez elementAtIndex: i associatedPoints: p])
  205519. {
  205520. case NSMoveToBezierPathElement:
  205521. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205522. break;
  205523. case NSLineToBezierPathElement:
  205524. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205525. break;
  205526. case NSCurveToBezierPathElement:
  205527. 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);
  205528. break;
  205529. case NSClosePathBezierPathElement:
  205530. path.closeSubPath();
  205531. break;
  205532. default:
  205533. jassertfalse
  205534. break;
  205535. }
  205536. }
  205537. path.applyTransform (pathTransform);
  205538. return true;
  205539. #endif
  205540. }
  205541. juce_UseDebuggingNewOperator
  205542. CGFontRef fontRef;
  205543. float fontHeightToCGSizeFactor;
  205544. CGAffineTransform renderingTransform;
  205545. private:
  205546. float ascent, unitsToHeightScaleFactor;
  205547. #if JUCE_IPHONE
  205548. #else
  205549. NSFont* nsFont;
  205550. AffineTransform pathTransform;
  205551. #endif
  205552. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205553. {
  205554. #if SUPPORT_10_4_FONTS
  205555. #if ! SUPPORT_ONLY_10_4_FONTS
  205556. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205557. #endif
  205558. {
  205559. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205560. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205561. for (int i = 0; i < length; ++i)
  205562. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205563. return;
  205564. }
  205565. #endif
  205566. #if ! SUPPORT_ONLY_10_4_FONTS
  205567. if (charToGlyphMapper == 0)
  205568. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205569. glyphs.malloc (length);
  205570. for (int i = 0; i < length; ++i)
  205571. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205572. #endif
  205573. }
  205574. #if ! SUPPORT_ONLY_10_4_FONTS
  205575. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205576. class CharToGlyphMapper
  205577. {
  205578. public:
  205579. CharToGlyphMapper (CGFontRef fontRef)
  205580. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205581. idRangeOffset (0), glyphIndexes (0)
  205582. {
  205583. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205584. if (cmapTable != 0)
  205585. {
  205586. const int numSubtables = getValue16 (cmapTable, 2);
  205587. for (int i = 0; i < numSubtables; ++i)
  205588. {
  205589. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205590. {
  205591. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205592. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205593. {
  205594. const int length = getValue16 (cmapTable, offset + 2);
  205595. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205596. segCount = segCountX2 / 2;
  205597. const int endCodeOffset = offset + 14;
  205598. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205599. const int idDeltaOffset = startCodeOffset + segCountX2;
  205600. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205601. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205602. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205603. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205604. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205605. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205606. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205607. }
  205608. break;
  205609. }
  205610. }
  205611. CFRelease (cmapTable);
  205612. }
  205613. }
  205614. ~CharToGlyphMapper()
  205615. {
  205616. if (endCode != 0)
  205617. {
  205618. CFRelease (endCode);
  205619. CFRelease (startCode);
  205620. CFRelease (idDelta);
  205621. CFRelease (idRangeOffset);
  205622. CFRelease (glyphIndexes);
  205623. }
  205624. }
  205625. int getGlyphForCharacter (const juce_wchar c) const
  205626. {
  205627. for (int i = 0; i < segCount; ++i)
  205628. {
  205629. if (getValue16 (endCode, i * 2) >= c)
  205630. {
  205631. const int start = getValue16 (startCode, i * 2);
  205632. if (start > c)
  205633. break;
  205634. const int delta = getValue16 (idDelta, i * 2);
  205635. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205636. if (rangeOffset == 0)
  205637. return delta + c;
  205638. else
  205639. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205640. }
  205641. }
  205642. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205643. return jmax (-1, c - 29);
  205644. }
  205645. private:
  205646. int segCount;
  205647. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205648. static uint16 getValue16 (CFDataRef data, const int index)
  205649. {
  205650. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205651. }
  205652. static uint32 getValue32 (CFDataRef data, const int index)
  205653. {
  205654. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205655. }
  205656. };
  205657. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205658. #endif
  205659. MacTypeface (const MacTypeface&);
  205660. MacTypeface& operator= (const MacTypeface&);
  205661. };
  205662. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205663. {
  205664. return new MacTypeface (font);
  205665. }
  205666. const StringArray Font::findAllTypefaceNames() throw()
  205667. {
  205668. StringArray names;
  205669. const ScopedAutoReleasePool pool;
  205670. #if JUCE_IPHONE
  205671. NSArray* fonts = [UIFont familyNames];
  205672. #else
  205673. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205674. #endif
  205675. for (unsigned int i = 0; i < [fonts count]; ++i)
  205676. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205677. names.sort (true);
  205678. return names;
  205679. }
  205680. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205681. {
  205682. #if JUCE_IPHONE
  205683. defaultSans = "Helvetica";
  205684. defaultSerif = "Times New Roman";
  205685. defaultFixed = "Courier New";
  205686. #else
  205687. defaultSans = "Lucida Grande";
  205688. defaultSerif = "Times New Roman";
  205689. defaultFixed = "Monaco";
  205690. #endif
  205691. }
  205692. #endif
  205693. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205694. // (must go before juce_mac_CoreGraphicsContext.mm)
  205695. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205696. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205697. // compiled on its own).
  205698. #if JUCE_INCLUDED_FILE
  205699. class CoreGraphicsImage : public Image
  205700. {
  205701. public:
  205702. CoreGraphicsImage (const PixelFormat format_,
  205703. const int imageWidth_,
  205704. const int imageHeight_,
  205705. const bool clearImage)
  205706. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205707. {
  205708. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  205709. : CGColorSpaceCreateDeviceRGB();
  205710. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205711. colourSpace, getCGImageFlags (*this));
  205712. CGColorSpaceRelease (colourSpace);
  205713. }
  205714. ~CoreGraphicsImage()
  205715. {
  205716. CGContextRelease (context);
  205717. }
  205718. LowLevelGraphicsContext* createLowLevelContext();
  205719. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205720. {
  205721. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205722. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205723. {
  205724. return CGBitmapContextCreateImage (nativeImage->context);
  205725. }
  205726. else
  205727. {
  205728. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205729. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205730. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205731. 8, srcData.pixelStride * 8, srcData.lineStride,
  205732. colourSpace, getCGImageFlags (juceImage), provider,
  205733. 0, true, kCGRenderingIntentDefault);
  205734. CGDataProviderRelease (provider);
  205735. return imageRef;
  205736. }
  205737. }
  205738. #if JUCE_MAC
  205739. static NSImage* createNSImage (const Image& image)
  205740. {
  205741. const ScopedAutoReleasePool pool;
  205742. NSImage* im = [[NSImage alloc] init];
  205743. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205744. [im lockFocus];
  205745. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205746. CGImageRef imageRef = createImage (image, false, colourSpace);
  205747. CGColorSpaceRelease (colourSpace);
  205748. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205749. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205750. CGImageRelease (imageRef);
  205751. [im unlockFocus];
  205752. return im;
  205753. }
  205754. #endif
  205755. CGContextRef context;
  205756. private:
  205757. static CGBitmapInfo getCGImageFlags (const Image& image)
  205758. {
  205759. #if JUCE_BIG_ENDIAN
  205760. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205761. #else
  205762. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205763. #endif
  205764. }
  205765. };
  205766. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205767. {
  205768. #if USE_COREGRAPHICS_RENDERING
  205769. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205770. #else
  205771. return new Image (format, imageWidth, imageHeight, clearImage);
  205772. #endif
  205773. }
  205774. class CoreGraphicsContext : public LowLevelGraphicsContext
  205775. {
  205776. public:
  205777. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205778. : context (context_),
  205779. flipHeight (flipHeight_),
  205780. state (new SavedState()),
  205781. numGradientLookupEntries (0)
  205782. {
  205783. CGContextRetain (context);
  205784. CGContextSaveGState(context);
  205785. CGContextSetShouldSmoothFonts (context, true);
  205786. CGContextSetShouldAntialias (context, true);
  205787. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205788. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205789. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205790. gradientCallbacks.version = 0;
  205791. gradientCallbacks.evaluate = gradientCallback;
  205792. gradientCallbacks.releaseInfo = 0;
  205793. setFont (Font());
  205794. }
  205795. ~CoreGraphicsContext()
  205796. {
  205797. CGContextRestoreGState (context);
  205798. CGContextRelease (context);
  205799. CGColorSpaceRelease (rgbColourSpace);
  205800. CGColorSpaceRelease (greyColourSpace);
  205801. }
  205802. bool isVectorDevice() const { return false; }
  205803. void setOrigin (int x, int y)
  205804. {
  205805. CGContextTranslateCTM (context, x, -y);
  205806. }
  205807. bool clipToRectangle (const Rectangle<int>& r)
  205808. {
  205809. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205810. return ! isClipEmpty();
  205811. }
  205812. bool clipToRectangleList (const RectangleList& clipRegion)
  205813. {
  205814. if (clipRegion.isEmpty())
  205815. {
  205816. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205817. return false;
  205818. }
  205819. else
  205820. {
  205821. const int numRects = clipRegion.getNumRectangles();
  205822. HeapBlock <CGRect> rects (numRects);
  205823. for (int i = 0; i < numRects; ++i)
  205824. {
  205825. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205826. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205827. }
  205828. CGContextClipToRects (context, rects, numRects);
  205829. return ! isClipEmpty();
  205830. }
  205831. }
  205832. void excludeClipRectangle (const Rectangle<int>& r)
  205833. {
  205834. RectangleList remaining (getClipBounds());
  205835. remaining.subtract (r);
  205836. clipToRectangleList (remaining);
  205837. }
  205838. void clipToPath (const Path& path, const AffineTransform& transform)
  205839. {
  205840. createPath (path, transform);
  205841. CGContextClip (context);
  205842. }
  205843. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205844. {
  205845. if (! transform.isSingularity())
  205846. {
  205847. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  205848. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205849. flip();
  205850. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205851. applyTransform (t);
  205852. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205853. CGContextClipToMask (context, r, image);
  205854. applyTransform (t.inverted());
  205855. flip();
  205856. CGImageRelease (image);
  205857. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  205858. }
  205859. }
  205860. bool clipRegionIntersects (const Rectangle<int>& r)
  205861. {
  205862. return getClipBounds().intersects (r);
  205863. }
  205864. const Rectangle<int> getClipBounds() const
  205865. {
  205866. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205867. return Rectangle<int> (roundToInt (bounds.origin.x),
  205868. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205869. roundToInt (bounds.size.width),
  205870. roundToInt (bounds.size.height));
  205871. }
  205872. bool isClipEmpty() const
  205873. {
  205874. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205875. }
  205876. void saveState()
  205877. {
  205878. CGContextSaveGState (context);
  205879. stateStack.add (new SavedState (*state));
  205880. }
  205881. void restoreState()
  205882. {
  205883. CGContextRestoreGState (context);
  205884. SavedState* const top = stateStack.getLast();
  205885. if (top != 0)
  205886. {
  205887. state = top;
  205888. stateStack.removeLast (1, false);
  205889. }
  205890. else
  205891. {
  205892. jassertfalse // trying to pop with an empty stack!
  205893. }
  205894. }
  205895. void setFill (const FillType& fillType)
  205896. {
  205897. state->fillType = fillType;
  205898. if (fillType.isColour())
  205899. {
  205900. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  205901. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  205902. CGContextSetAlpha (context, 1.0f);
  205903. }
  205904. }
  205905. void setOpacity (float newOpacity)
  205906. {
  205907. state->fillType.setOpacity (newOpacity);
  205908. setFill (state->fillType);
  205909. }
  205910. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  205911. {
  205912. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  205913. ? kCGInterpolationLow
  205914. : kCGInterpolationHigh);
  205915. }
  205916. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  205917. {
  205918. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205919. if (replaceExistingContents)
  205920. {
  205921. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205922. CGContextClearRect (context, cgRect);
  205923. #else
  205924. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205925. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  205926. CGContextClearRect (context, cgRect);
  205927. else
  205928. #endif
  205929. CGContextSetBlendMode (context, kCGBlendModeCopy);
  205930. #endif
  205931. fillRect (r, false);
  205932. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205933. }
  205934. else
  205935. {
  205936. if (state->fillType.isColour())
  205937. {
  205938. CGContextFillRect (context, cgRect);
  205939. }
  205940. else if (state->fillType.isGradient())
  205941. {
  205942. CGContextSaveGState (context);
  205943. CGContextClipToRect (context, cgRect);
  205944. drawGradient();
  205945. CGContextRestoreGState (context);
  205946. }
  205947. else
  205948. {
  205949. CGContextSaveGState (context);
  205950. CGContextClipToRect (context, cgRect);
  205951. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  205952. CGContextRestoreGState (context);
  205953. }
  205954. }
  205955. }
  205956. void fillPath (const Path& path, const AffineTransform& transform)
  205957. {
  205958. CGContextSaveGState (context);
  205959. if (state->fillType.isColour())
  205960. {
  205961. flip();
  205962. applyTransform (transform);
  205963. createPath (path);
  205964. if (path.isUsingNonZeroWinding())
  205965. CGContextFillPath (context);
  205966. else
  205967. CGContextEOFillPath (context);
  205968. }
  205969. else
  205970. {
  205971. createPath (path, transform);
  205972. if (path.isUsingNonZeroWinding())
  205973. CGContextClip (context);
  205974. else
  205975. CGContextEOClip (context);
  205976. if (state->fillType.isGradient())
  205977. drawGradient();
  205978. else
  205979. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  205980. }
  205981. CGContextRestoreGState (context);
  205982. }
  205983. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  205984. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  205985. {
  205986. jassert (sourceImage.getBounds().contains (srcClip));
  205987. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  205988. CGImageRef image = fullImage;
  205989. if (srcClip != sourceImage.getBounds())
  205990. {
  205991. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  205992. srcClip.getWidth(), srcClip.getHeight()));
  205993. CGImageRelease (fullImage);
  205994. }
  205995. CGContextSaveGState (context);
  205996. CGContextSetAlpha (context, state->fillType.getOpacity());
  205997. flip();
  205998. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  205999. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206000. if (fillEntireClipAsTiles)
  206001. {
  206002. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206003. CGContextDrawTiledImage (context, imageRect, image);
  206004. #else
  206005. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206006. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206007. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206008. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206009. CGContextDrawTiledImage (context, imageRect, image);
  206010. else
  206011. #endif
  206012. {
  206013. // Fallback to manually doing a tiled fill on 10.4
  206014. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206015. const int iw = srcClip.getWidth();
  206016. const int ih = srcClip.getHeight();
  206017. int x = 0, y = 0;
  206018. while (x > clip.origin.x) x -= iw;
  206019. while (y > clip.origin.y) y -= ih;
  206020. const int right = (int) (clip.origin.x + clip.size.width);
  206021. const int bottom = (int) (clip.origin.y + clip.size.height);
  206022. while (y < bottom)
  206023. {
  206024. for (int x2 = x; x2 < right; x2 += iw)
  206025. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206026. y += ih;
  206027. }
  206028. }
  206029. #endif
  206030. }
  206031. else
  206032. {
  206033. CGContextDrawImage (context, imageRect, image);
  206034. }
  206035. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206036. CGContextRestoreGState (context);
  206037. }
  206038. void drawLine (double x1, double y1, double x2, double y2)
  206039. {
  206040. CGContextSetLineCap (context, kCGLineCapSquare);
  206041. CGContextSetLineWidth (context, 1.0f);
  206042. CGContextSetRGBStrokeColor (context,
  206043. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206044. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206045. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  206046. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  206047. CGContextStrokeLineSegments (context, line, 1);
  206048. }
  206049. void drawVerticalLine (const int x, double top, double bottom)
  206050. {
  206051. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206052. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206053. #else
  206054. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206055. // the x co-ord slightly to trick it..
  206056. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206057. #endif
  206058. }
  206059. void drawHorizontalLine (const int y, double left, double right)
  206060. {
  206061. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206062. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206063. #else
  206064. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206065. // the x co-ord slightly to trick it..
  206066. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206067. #endif
  206068. }
  206069. void setFont (const Font& newFont)
  206070. {
  206071. if (state->font != newFont)
  206072. {
  206073. state->fontRef = 0;
  206074. state->font = newFont;
  206075. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206076. if (mf != 0)
  206077. {
  206078. state->fontRef = mf->fontRef;
  206079. CGContextSetFont (context, state->fontRef);
  206080. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206081. state->fontTransform = mf->renderingTransform;
  206082. state->fontTransform.a *= state->font.getHorizontalScale();
  206083. CGContextSetTextMatrix (context, state->fontTransform);
  206084. }
  206085. }
  206086. }
  206087. const Font getFont()
  206088. {
  206089. return state->font;
  206090. }
  206091. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206092. {
  206093. if (state->fontRef != 0 && state->fillType.isColour())
  206094. {
  206095. if (transform.isOnlyTranslation())
  206096. {
  206097. CGGlyph g = glyphNumber;
  206098. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206099. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206100. }
  206101. else
  206102. {
  206103. CGContextSaveGState (context);
  206104. flip();
  206105. applyTransform (transform);
  206106. CGAffineTransform t = state->fontTransform;
  206107. t.d = -t.d;
  206108. CGContextSetTextMatrix (context, t);
  206109. CGGlyph g = glyphNumber;
  206110. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206111. CGContextSetTextMatrix (context, state->fontTransform);
  206112. CGContextRestoreGState (context);
  206113. }
  206114. }
  206115. else
  206116. {
  206117. Path p;
  206118. Font& f = state->font;
  206119. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206120. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206121. .followedBy (transform));
  206122. }
  206123. }
  206124. private:
  206125. CGContextRef context;
  206126. const CGFloat flipHeight;
  206127. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206128. CGFunctionCallbacks gradientCallbacks;
  206129. struct SavedState
  206130. {
  206131. SavedState()
  206132. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206133. {
  206134. }
  206135. SavedState (const SavedState& other)
  206136. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206137. fontTransform (other.fontTransform)
  206138. {
  206139. }
  206140. ~SavedState()
  206141. {
  206142. }
  206143. FillType fillType;
  206144. Font font;
  206145. CGFontRef fontRef;
  206146. CGAffineTransform fontTransform;
  206147. };
  206148. ScopedPointer <SavedState> state;
  206149. OwnedArray <SavedState> stateStack;
  206150. HeapBlock <PixelARGB> gradientLookupTable;
  206151. int numGradientLookupEntries;
  206152. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206153. {
  206154. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206155. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206156. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206157. colour.unpremultiply();
  206158. outData[0] = colour.getRed() / 255.0f;
  206159. outData[1] = colour.getGreen() / 255.0f;
  206160. outData[2] = colour.getBlue() / 255.0f;
  206161. outData[3] = colour.getAlpha() / 255.0f;
  206162. }
  206163. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206164. {
  206165. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206166. --numGradientLookupEntries;
  206167. CGShadingRef result = 0;
  206168. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206169. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206170. if (gradient.isRadial)
  206171. {
  206172. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206173. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206174. function, true, true);
  206175. }
  206176. else
  206177. {
  206178. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206179. CGPointMake (gradient.x2, gradient.y2),
  206180. function, true, true);
  206181. }
  206182. CGFunctionRelease (function);
  206183. return result;
  206184. }
  206185. void drawGradient()
  206186. {
  206187. flip();
  206188. applyTransform (state->fillType.transform);
  206189. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206190. // you draw a gradient with high quality interp enabled).
  206191. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206192. CGContextSetAlpha (context, state->fillType.getOpacity());
  206193. CGContextDrawShading (context, shading);
  206194. CGShadingRelease (shading);
  206195. }
  206196. void createPath (const Path& path) const
  206197. {
  206198. CGContextBeginPath (context);
  206199. Path::Iterator i (path);
  206200. while (i.next())
  206201. {
  206202. switch (i.elementType)
  206203. {
  206204. case Path::Iterator::startNewSubPath:
  206205. CGContextMoveToPoint (context, i.x1, i.y1);
  206206. break;
  206207. case Path::Iterator::lineTo:
  206208. CGContextAddLineToPoint (context, i.x1, i.y1);
  206209. break;
  206210. case Path::Iterator::quadraticTo:
  206211. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206212. break;
  206213. case Path::Iterator::cubicTo:
  206214. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206215. break;
  206216. case Path::Iterator::closePath:
  206217. CGContextClosePath (context); break;
  206218. default:
  206219. jassertfalse
  206220. break;
  206221. }
  206222. }
  206223. }
  206224. void createPath (const Path& path, const AffineTransform& transform) const
  206225. {
  206226. CGContextBeginPath (context);
  206227. Path::Iterator i (path);
  206228. while (i.next())
  206229. {
  206230. switch (i.elementType)
  206231. {
  206232. case Path::Iterator::startNewSubPath:
  206233. transform.transformPoint (i.x1, i.y1);
  206234. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206235. break;
  206236. case Path::Iterator::lineTo:
  206237. transform.transformPoint (i.x1, i.y1);
  206238. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206239. break;
  206240. case Path::Iterator::quadraticTo:
  206241. transform.transformPoint (i.x1, i.y1);
  206242. transform.transformPoint (i.x2, i.y2);
  206243. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206244. break;
  206245. case Path::Iterator::cubicTo:
  206246. transform.transformPoint (i.x1, i.y1);
  206247. transform.transformPoint (i.x2, i.y2);
  206248. transform.transformPoint (i.x3, i.y3);
  206249. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206250. break;
  206251. case Path::Iterator::closePath:
  206252. CGContextClosePath (context); break;
  206253. default:
  206254. jassertfalse
  206255. break;
  206256. }
  206257. }
  206258. }
  206259. static Image* createAlphaChannelImage (const Image& im)
  206260. {
  206261. if (im.getFormat() == Image::SingleChannel)
  206262. return const_cast <Image*> (&im);
  206263. return im.createCopyOfAlphaChannel();
  206264. }
  206265. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206266. {
  206267. if (im.getFormat() != Image::SingleChannel)
  206268. delete alphaIm;
  206269. }
  206270. void flip() const
  206271. {
  206272. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206273. }
  206274. void applyTransform (const AffineTransform& transform) const
  206275. {
  206276. CGAffineTransform t;
  206277. t.a = transform.mat00;
  206278. t.b = transform.mat10;
  206279. t.c = transform.mat01;
  206280. t.d = transform.mat11;
  206281. t.tx = transform.mat02;
  206282. t.ty = transform.mat12;
  206283. CGContextConcatCTM (context, t);
  206284. }
  206285. CoreGraphicsContext (const CoreGraphicsContext&);
  206286. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  206287. };
  206288. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206289. {
  206290. return new CoreGraphicsContext (context, imageHeight);
  206291. }
  206292. #endif
  206293. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206294. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206295. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206296. // compiled on its own).
  206297. #if JUCE_INCLUDED_FILE
  206298. class NSViewComponentPeer;
  206299. END_JUCE_NAMESPACE
  206300. #define JuceNSView MakeObjCClassName(JuceNSView)
  206301. @interface JuceNSView : NSView<NSTextInput>
  206302. {
  206303. @public
  206304. NSViewComponentPeer* owner;
  206305. NSNotificationCenter* notificationCenter;
  206306. String* stringBeingComposed;
  206307. bool textWasInserted;
  206308. }
  206309. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206310. - (void) dealloc;
  206311. - (BOOL) isOpaque;
  206312. - (void) drawRect: (NSRect) r;
  206313. - (void) mouseDown: (NSEvent*) ev;
  206314. - (void) asyncMouseDown: (NSEvent*) ev;
  206315. - (void) mouseUp: (NSEvent*) ev;
  206316. - (void) asyncMouseUp: (NSEvent*) ev;
  206317. - (void) mouseDragged: (NSEvent*) ev;
  206318. - (void) mouseMoved: (NSEvent*) ev;
  206319. - (void) mouseEntered: (NSEvent*) ev;
  206320. - (void) mouseExited: (NSEvent*) ev;
  206321. - (void) rightMouseDown: (NSEvent*) ev;
  206322. - (void) rightMouseDragged: (NSEvent*) ev;
  206323. - (void) rightMouseUp: (NSEvent*) ev;
  206324. - (void) otherMouseDown: (NSEvent*) ev;
  206325. - (void) otherMouseDragged: (NSEvent*) ev;
  206326. - (void) otherMouseUp: (NSEvent*) ev;
  206327. - (void) scrollWheel: (NSEvent*) ev;
  206328. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206329. - (void) frameChanged: (NSNotification*) n;
  206330. - (void) viewDidMoveToWindow;
  206331. - (void) keyDown: (NSEvent*) ev;
  206332. - (void) keyUp: (NSEvent*) ev;
  206333. // NSTextInput Methods
  206334. - (void) insertText: (id) aString;
  206335. - (void) doCommandBySelector: (SEL) aSelector;
  206336. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206337. - (void) unmarkText;
  206338. - (BOOL) hasMarkedText;
  206339. - (long) conversationIdentifier;
  206340. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206341. - (NSRange) markedRange;
  206342. - (NSRange) selectedRange;
  206343. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206344. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206345. - (NSArray*) validAttributesForMarkedText;
  206346. - (void) flagsChanged: (NSEvent*) ev;
  206347. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206348. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206349. #endif
  206350. - (BOOL) becomeFirstResponder;
  206351. - (BOOL) resignFirstResponder;
  206352. - (BOOL) acceptsFirstResponder;
  206353. - (void) asyncRepaint: (id) rect;
  206354. - (NSArray*) getSupportedDragTypes;
  206355. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206356. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206357. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206358. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206359. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206360. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206361. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206362. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206363. @end
  206364. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206365. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206366. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206367. #else
  206368. @interface JuceNSWindow : NSWindow
  206369. #endif
  206370. {
  206371. @private
  206372. NSViewComponentPeer* owner;
  206373. bool isZooming;
  206374. }
  206375. - (void) setOwner: (NSViewComponentPeer*) owner;
  206376. - (BOOL) canBecomeKeyWindow;
  206377. - (void) becomeKeyWindow;
  206378. - (BOOL) windowShouldClose: (id) window;
  206379. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206380. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206381. - (void) zoom: (id) sender;
  206382. @end
  206383. BEGIN_JUCE_NAMESPACE
  206384. class NSViewComponentPeer : public ComponentPeer
  206385. {
  206386. public:
  206387. NSViewComponentPeer (Component* const component,
  206388. const int windowStyleFlags,
  206389. NSView* viewToAttachTo);
  206390. ~NSViewComponentPeer();
  206391. void* getNativeHandle() const;
  206392. void setVisible (bool shouldBeVisible);
  206393. void setTitle (const String& title);
  206394. void setPosition (int x, int y);
  206395. void setSize (int w, int h);
  206396. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206397. const Rectangle<int> getBounds (const bool global) const;
  206398. const Rectangle<int> getBounds() const;
  206399. const Point<int> getScreenPosition() const;
  206400. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206401. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206402. void setMinimised (bool shouldBeMinimised);
  206403. bool isMinimised() const;
  206404. void setFullScreen (bool shouldBeFullScreen);
  206405. bool isFullScreen() const;
  206406. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206407. const BorderSize getFrameSize() const;
  206408. bool setAlwaysOnTop (bool alwaysOnTop);
  206409. void toFront (bool makeActiveWindow);
  206410. void toBehind (ComponentPeer* other);
  206411. void setIcon (const Image& newIcon);
  206412. const StringArray getAvailableRenderingEngines() throw();
  206413. int getCurrentRenderingEngine() throw();
  206414. void setCurrentRenderingEngine (int index) throw();
  206415. virtual void redirectMouseDown (NSEvent* ev);
  206416. virtual void redirectMouseUp (NSEvent* ev);
  206417. virtual void redirectMouseDrag (NSEvent* ev);
  206418. virtual void redirectMouseMove (NSEvent* ev);
  206419. virtual void redirectMouseEnter (NSEvent* ev);
  206420. virtual void redirectMouseExit (NSEvent* ev);
  206421. virtual void redirectMouseWheel (NSEvent* ev);
  206422. void sendMouseEvent (NSEvent* ev);
  206423. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206424. virtual bool redirectKeyDown (NSEvent* ev);
  206425. virtual bool redirectKeyUp (NSEvent* ev);
  206426. virtual void redirectModKeyChange (NSEvent* ev);
  206427. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206428. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206429. #endif
  206430. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206431. virtual bool isOpaque();
  206432. virtual void drawRect (NSRect r);
  206433. virtual bool canBecomeKeyWindow();
  206434. virtual bool windowShouldClose();
  206435. virtual void redirectMovedOrResized();
  206436. virtual void viewMovedToWindow();
  206437. virtual NSRect constrainRect (NSRect r);
  206438. static void showArrowCursorIfNeeded();
  206439. static void updateModifiers (NSEvent* e);
  206440. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206441. static int getKeyCodeFromEvent (NSEvent* ev)
  206442. {
  206443. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206444. int keyCode = unmodified[0];
  206445. if (keyCode == 0x19) // (backwards-tab)
  206446. keyCode = '\t';
  206447. else if (keyCode == 0x03) // (enter)
  206448. keyCode = '\r';
  206449. return keyCode;
  206450. }
  206451. static int64 getMouseTime (NSEvent* e)
  206452. {
  206453. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206454. + (int64) ([e timestamp] * 1000.0);
  206455. }
  206456. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206457. {
  206458. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206459. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206460. }
  206461. static int getModifierForButtonNumber (const NSInteger num)
  206462. {
  206463. return num == 0 ? ModifierKeys::leftButtonModifier
  206464. : (num == 1 ? ModifierKeys::rightButtonModifier
  206465. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206466. }
  206467. virtual void viewFocusGain();
  206468. virtual void viewFocusLoss();
  206469. bool isFocused() const;
  206470. void grabFocus();
  206471. void textInputRequired (const Point<int>& position);
  206472. void repaint (int x, int y, int w, int h);
  206473. void performAnyPendingRepaintsNow();
  206474. juce_UseDebuggingNewOperator
  206475. NSWindow* window;
  206476. JuceNSView* view;
  206477. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206478. static ModifierKeys currentModifiers;
  206479. static ComponentPeer* currentlyFocusedPeer;
  206480. static VoidArray keysCurrentlyDown;
  206481. };
  206482. END_JUCE_NAMESPACE
  206483. @implementation JuceNSView
  206484. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206485. withFrame: (NSRect) frame
  206486. {
  206487. [super initWithFrame: frame];
  206488. owner = owner_;
  206489. stringBeingComposed = 0;
  206490. textWasInserted = false;
  206491. notificationCenter = [NSNotificationCenter defaultCenter];
  206492. [notificationCenter addObserver: self
  206493. selector: @selector (frameChanged:)
  206494. name: NSViewFrameDidChangeNotification
  206495. object: self];
  206496. if (! owner_->isSharedWindow)
  206497. {
  206498. [notificationCenter addObserver: self
  206499. selector: @selector (frameChanged:)
  206500. name: NSWindowDidMoveNotification
  206501. object: owner_->window];
  206502. }
  206503. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206504. return self;
  206505. }
  206506. - (void) dealloc
  206507. {
  206508. [notificationCenter removeObserver: self];
  206509. delete stringBeingComposed;
  206510. [super dealloc];
  206511. }
  206512. - (void) drawRect: (NSRect) r
  206513. {
  206514. if (owner != 0)
  206515. owner->drawRect (r);
  206516. }
  206517. - (BOOL) isOpaque
  206518. {
  206519. return owner == 0 || owner->isOpaque();
  206520. }
  206521. - (void) mouseDown: (NSEvent*) ev
  206522. {
  206523. // In some host situations, the host will stop modal loops from working
  206524. // correctly if they're called from a mouse event, so we'll trigger
  206525. // the event asynchronously..
  206526. if (JUCEApplication::getInstance() == 0)
  206527. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206528. withObject: ev
  206529. waitUntilDone: NO];
  206530. else
  206531. [self asyncMouseDown: ev];
  206532. }
  206533. - (void) asyncMouseDown: (NSEvent*) ev
  206534. {
  206535. if (owner != 0)
  206536. owner->redirectMouseDown (ev);
  206537. }
  206538. - (void) mouseUp: (NSEvent*) ev
  206539. {
  206540. // In some host situations, the host will stop modal loops from working
  206541. // correctly if they're called from a mouse event, so we'll trigger
  206542. // the event asynchronously..
  206543. if (JUCEApplication::getInstance() == 0)
  206544. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206545. withObject: ev
  206546. waitUntilDone: NO];
  206547. else
  206548. [self asyncMouseUp: ev];
  206549. }
  206550. - (void) asyncMouseUp: (NSEvent*) ev
  206551. {
  206552. if (owner != 0)
  206553. owner->redirectMouseUp (ev);
  206554. }
  206555. - (void) mouseDragged: (NSEvent*) ev
  206556. {
  206557. if (owner != 0)
  206558. owner->redirectMouseDrag (ev);
  206559. }
  206560. - (void) mouseMoved: (NSEvent*) ev
  206561. {
  206562. if (owner != 0)
  206563. owner->redirectMouseMove (ev);
  206564. }
  206565. - (void) mouseEntered: (NSEvent*) ev
  206566. {
  206567. if (owner != 0)
  206568. owner->redirectMouseEnter (ev);
  206569. }
  206570. - (void) mouseExited: (NSEvent*) ev
  206571. {
  206572. if (owner != 0)
  206573. owner->redirectMouseExit (ev);
  206574. }
  206575. - (void) rightMouseDown: (NSEvent*) ev
  206576. {
  206577. [self mouseDown: ev];
  206578. }
  206579. - (void) rightMouseDragged: (NSEvent*) ev
  206580. {
  206581. [self mouseDragged: ev];
  206582. }
  206583. - (void) rightMouseUp: (NSEvent*) ev
  206584. {
  206585. [self mouseUp: ev];
  206586. }
  206587. - (void) otherMouseDown: (NSEvent*) ev
  206588. {
  206589. [self mouseDown: ev];
  206590. }
  206591. - (void) otherMouseDragged: (NSEvent*) ev
  206592. {
  206593. [self mouseDragged: ev];
  206594. }
  206595. - (void) otherMouseUp: (NSEvent*) ev
  206596. {
  206597. [self mouseUp: ev];
  206598. }
  206599. - (void) scrollWheel: (NSEvent*) ev
  206600. {
  206601. if (owner != 0)
  206602. owner->redirectMouseWheel (ev);
  206603. }
  206604. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206605. {
  206606. return YES;
  206607. }
  206608. - (void) frameChanged: (NSNotification*) n
  206609. {
  206610. if (owner != 0)
  206611. owner->redirectMovedOrResized();
  206612. }
  206613. - (void) viewDidMoveToWindow
  206614. {
  206615. if (owner != 0)
  206616. owner->viewMovedToWindow();
  206617. }
  206618. - (void) asyncRepaint: (id) rect
  206619. {
  206620. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206621. [self setNeedsDisplayInRect: *r];
  206622. }
  206623. - (void) keyDown: (NSEvent*) ev
  206624. {
  206625. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206626. textWasInserted = false;
  206627. if (target != 0)
  206628. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206629. else
  206630. deleteAndZero (stringBeingComposed);
  206631. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206632. [super keyDown: ev];
  206633. }
  206634. - (void) keyUp: (NSEvent*) ev
  206635. {
  206636. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206637. [super keyUp: ev];
  206638. }
  206639. - (void) insertText: (id) aString
  206640. {
  206641. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206642. if ([aString length] > 0)
  206643. {
  206644. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206645. if (target != 0)
  206646. {
  206647. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206648. textWasInserted = true;
  206649. }
  206650. }
  206651. deleteAndZero (stringBeingComposed);
  206652. }
  206653. - (void) doCommandBySelector: (SEL) aSelector
  206654. {
  206655. }
  206656. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206657. {
  206658. if (stringBeingComposed == 0)
  206659. stringBeingComposed = new String();
  206660. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206661. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206662. if (target != 0)
  206663. {
  206664. const Range<int> currentHighlight (target->getHighlightedRegion());
  206665. target->insertTextAtCaret (*stringBeingComposed);
  206666. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206667. textWasInserted = true;
  206668. }
  206669. }
  206670. - (void) unmarkText
  206671. {
  206672. if (stringBeingComposed != 0)
  206673. {
  206674. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206675. if (target != 0)
  206676. {
  206677. target->insertTextAtCaret (*stringBeingComposed);
  206678. textWasInserted = true;
  206679. }
  206680. }
  206681. deleteAndZero (stringBeingComposed);
  206682. }
  206683. - (BOOL) hasMarkedText
  206684. {
  206685. return stringBeingComposed != 0;
  206686. }
  206687. - (long) conversationIdentifier
  206688. {
  206689. return (long) (pointer_sized_int) self;
  206690. }
  206691. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206692. {
  206693. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206694. if (target != 0)
  206695. {
  206696. const Range<int> r ((int) theRange.location,
  206697. (int) (theRange.location + theRange.length));
  206698. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206699. }
  206700. return nil;
  206701. }
  206702. - (NSRange) markedRange
  206703. {
  206704. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206705. : NSMakeRange (NSNotFound, 0);
  206706. }
  206707. - (NSRange) selectedRange
  206708. {
  206709. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206710. if (target != 0)
  206711. {
  206712. const Range<int> highlight (target->getHighlightedRegion());
  206713. if (! highlight.isEmpty())
  206714. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206715. }
  206716. return NSMakeRange (NSNotFound, 0);
  206717. }
  206718. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206719. {
  206720. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206721. if (comp == 0)
  206722. return NSMakeRect (0, 0, 0, 0);
  206723. const Rectangle<int> bounds (comp->getScreenBounds());
  206724. return NSMakeRect (bounds.getX(),
  206725. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206726. bounds.getWidth(),
  206727. bounds.getHeight());
  206728. }
  206729. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206730. {
  206731. return NSNotFound;
  206732. }
  206733. - (NSArray*) validAttributesForMarkedText
  206734. {
  206735. return [NSArray array];
  206736. }
  206737. - (void) flagsChanged: (NSEvent*) ev
  206738. {
  206739. if (owner != 0)
  206740. owner->redirectModKeyChange (ev);
  206741. }
  206742. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206743. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206744. {
  206745. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206746. return true;
  206747. return [super performKeyEquivalent: ev];
  206748. }
  206749. #endif
  206750. - (BOOL) becomeFirstResponder
  206751. {
  206752. if (owner != 0)
  206753. owner->viewFocusGain();
  206754. return true;
  206755. }
  206756. - (BOOL) resignFirstResponder
  206757. {
  206758. if (owner != 0)
  206759. owner->viewFocusLoss();
  206760. return true;
  206761. }
  206762. - (BOOL) acceptsFirstResponder
  206763. {
  206764. return owner != 0 && owner->canBecomeKeyWindow();
  206765. }
  206766. - (NSArray*) getSupportedDragTypes
  206767. {
  206768. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206769. }
  206770. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206771. {
  206772. return owner != 0 && owner->sendDragCallback (type, sender);
  206773. }
  206774. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206775. {
  206776. if ([self sendDragCallback: 0 sender: sender])
  206777. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206778. else
  206779. return NSDragOperationNone;
  206780. }
  206781. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206782. {
  206783. if ([self sendDragCallback: 0 sender: sender])
  206784. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206785. else
  206786. return NSDragOperationNone;
  206787. }
  206788. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206789. {
  206790. [self sendDragCallback: 1 sender: sender];
  206791. }
  206792. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206793. {
  206794. [self sendDragCallback: 1 sender: sender];
  206795. }
  206796. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206797. {
  206798. return YES;
  206799. }
  206800. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206801. {
  206802. return [self sendDragCallback: 2 sender: sender];
  206803. }
  206804. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206805. {
  206806. }
  206807. @end
  206808. @implementation JuceNSWindow
  206809. - (void) setOwner: (NSViewComponentPeer*) owner_
  206810. {
  206811. owner = owner_;
  206812. isZooming = false;
  206813. }
  206814. - (BOOL) canBecomeKeyWindow
  206815. {
  206816. return owner != 0 && owner->canBecomeKeyWindow();
  206817. }
  206818. - (void) becomeKeyWindow
  206819. {
  206820. [super becomeKeyWindow];
  206821. if (owner != 0)
  206822. owner->grabFocus();
  206823. }
  206824. - (BOOL) windowShouldClose: (id) window
  206825. {
  206826. return owner == 0 || owner->windowShouldClose();
  206827. }
  206828. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206829. {
  206830. if (owner != 0)
  206831. frameRect = owner->constrainRect (frameRect);
  206832. return frameRect;
  206833. }
  206834. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206835. {
  206836. if (isZooming)
  206837. return proposedFrameSize;
  206838. NSRect frameRect = [self frame];
  206839. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206840. frameRect.size = proposedFrameSize;
  206841. if (owner != 0)
  206842. frameRect = owner->constrainRect (frameRect);
  206843. return frameRect.size;
  206844. }
  206845. - (void) zoom: (id) sender
  206846. {
  206847. isZooming = true;
  206848. [super zoom: sender];
  206849. isZooming = false;
  206850. }
  206851. - (void) windowWillMove: (NSNotification*) notification
  206852. {
  206853. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206854. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206855. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206856. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206857. }
  206858. @end
  206859. BEGIN_JUCE_NAMESPACE
  206860. ModifierKeys NSViewComponentPeer::currentModifiers;
  206861. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  206862. VoidArray NSViewComponentPeer::keysCurrentlyDown;
  206863. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206864. {
  206865. if (NSViewComponentPeer::keysCurrentlyDown.contains ((void*) keyCode))
  206866. return true;
  206867. if (keyCode >= 'A' && keyCode <= 'Z'
  206868. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206869. return true;
  206870. if (keyCode >= 'a' && keyCode <= 'z'
  206871. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  206872. return true;
  206873. return false;
  206874. }
  206875. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  206876. {
  206877. int m = 0;
  206878. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  206879. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  206880. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  206881. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  206882. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  206883. }
  206884. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  206885. {
  206886. updateModifiers (ev);
  206887. int keyCode = getKeyCodeFromEvent (ev);
  206888. if (keyCode != 0)
  206889. {
  206890. if (isKeyDown)
  206891. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  206892. else
  206893. keysCurrentlyDown.removeValue ((void*) keyCode);
  206894. }
  206895. }
  206896. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  206897. {
  206898. return NSViewComponentPeer::currentModifiers;
  206899. }
  206900. void ModifierKeys::updateCurrentModifiers() throw()
  206901. {
  206902. currentModifiers = NSViewComponentPeer::currentModifiers;
  206903. }
  206904. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  206905. const int windowStyleFlags,
  206906. NSView* viewToAttachTo)
  206907. : ComponentPeer (component_, windowStyleFlags),
  206908. window (0),
  206909. view (0),
  206910. isSharedWindow (viewToAttachTo != 0),
  206911. fullScreen (false),
  206912. insideDrawRect (false),
  206913. #if USE_COREGRAPHICS_RENDERING
  206914. usingCoreGraphics (true),
  206915. #else
  206916. usingCoreGraphics (false),
  206917. #endif
  206918. recursiveToFrontCall (false)
  206919. {
  206920. NSRect r;
  206921. r.origin.x = 0;
  206922. r.origin.y = 0;
  206923. r.size.width = (float) component->getWidth();
  206924. r.size.height = (float) component->getHeight();
  206925. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  206926. [view setPostsFrameChangedNotifications: YES];
  206927. if (isSharedWindow)
  206928. {
  206929. window = [viewToAttachTo window];
  206930. [viewToAttachTo addSubview: view];
  206931. setVisible (component->isVisible());
  206932. }
  206933. else
  206934. {
  206935. r.origin.x = (float) component->getX();
  206936. r.origin.y = (float) component->getY();
  206937. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  206938. unsigned int style = 0;
  206939. if ((windowStyleFlags & windowHasTitleBar) == 0)
  206940. style = NSBorderlessWindowMask;
  206941. else
  206942. style = NSTitledWindowMask;
  206943. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  206944. style |= NSMiniaturizableWindowMask;
  206945. if ((windowStyleFlags & windowHasCloseButton) != 0)
  206946. style |= NSClosableWindowMask;
  206947. if ((windowStyleFlags & windowIsResizable) != 0)
  206948. style |= NSResizableWindowMask;
  206949. window = [[JuceNSWindow alloc] initWithContentRect: r
  206950. styleMask: style
  206951. backing: NSBackingStoreBuffered
  206952. defer: YES];
  206953. [((JuceNSWindow*) window) setOwner: this];
  206954. [window orderOut: nil];
  206955. [window setDelegate: (JuceNSWindow*) window];
  206956. [window setOpaque: component->isOpaque()];
  206957. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  206958. if (component->isAlwaysOnTop())
  206959. [window setLevel: NSFloatingWindowLevel];
  206960. [window setContentView: view];
  206961. [window setAutodisplay: YES];
  206962. [window setAcceptsMouseMovedEvents: YES];
  206963. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  206964. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  206965. [window setReleasedWhenClosed: YES];
  206966. [window retain];
  206967. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  206968. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  206969. }
  206970. setTitle (component->getName());
  206971. }
  206972. NSViewComponentPeer::~NSViewComponentPeer()
  206973. {
  206974. view->owner = 0;
  206975. [view removeFromSuperview];
  206976. [view release];
  206977. if (! isSharedWindow)
  206978. {
  206979. [((JuceNSWindow*) window) setOwner: 0];
  206980. [window close];
  206981. [window release];
  206982. }
  206983. }
  206984. void* NSViewComponentPeer::getNativeHandle() const
  206985. {
  206986. return view;
  206987. }
  206988. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  206989. {
  206990. if (isSharedWindow)
  206991. {
  206992. [view setHidden: ! shouldBeVisible];
  206993. }
  206994. else
  206995. {
  206996. if (shouldBeVisible)
  206997. {
  206998. [window orderFront: nil];
  206999. handleBroughtToFront();
  207000. }
  207001. else
  207002. {
  207003. [window orderOut: nil];
  207004. }
  207005. }
  207006. }
  207007. void NSViewComponentPeer::setTitle (const String& title)
  207008. {
  207009. const ScopedAutoReleasePool pool;
  207010. if (! isSharedWindow)
  207011. [window setTitle: juceStringToNS (title)];
  207012. }
  207013. void NSViewComponentPeer::setPosition (int x, int y)
  207014. {
  207015. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207016. }
  207017. void NSViewComponentPeer::setSize (int w, int h)
  207018. {
  207019. setBounds (component->getX(), component->getY(), w, h, false);
  207020. }
  207021. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207022. {
  207023. fullScreen = isNowFullScreen;
  207024. w = jmax (0, w);
  207025. h = jmax (0, h);
  207026. NSRect r;
  207027. r.origin.x = (float) x;
  207028. r.origin.y = (float) y;
  207029. r.size.width = (float) w;
  207030. r.size.height = (float) h;
  207031. if (isSharedWindow)
  207032. {
  207033. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207034. if ([view frame].size.width != r.size.width
  207035. || [view frame].size.height != r.size.height)
  207036. [view setNeedsDisplay: true];
  207037. [view setFrame: r];
  207038. }
  207039. else
  207040. {
  207041. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207042. [window setFrame: [window frameRectForContentRect: r]
  207043. display: true];
  207044. }
  207045. }
  207046. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207047. {
  207048. NSRect r = [view frame];
  207049. if (global && [view window] != 0)
  207050. {
  207051. r = [view convertRect: r toView: nil];
  207052. NSRect wr = [[view window] frame];
  207053. r.origin.x += wr.origin.x;
  207054. r.origin.y += wr.origin.y;
  207055. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207056. }
  207057. else
  207058. {
  207059. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207060. }
  207061. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207062. }
  207063. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207064. {
  207065. return getBounds (! isSharedWindow);
  207066. }
  207067. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207068. {
  207069. return getBounds (true).getPosition();
  207070. }
  207071. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207072. {
  207073. return relativePosition + getScreenPosition();
  207074. }
  207075. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207076. {
  207077. return screenPosition - getScreenPosition();
  207078. }
  207079. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207080. {
  207081. if (constrainer != 0)
  207082. {
  207083. NSRect current = [window frame];
  207084. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207085. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207086. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207087. (int) r.size.width, (int) r.size.height);
  207088. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207089. (int) current.size.width, (int) current.size.height);
  207090. constrainer->checkBounds (pos, original,
  207091. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207092. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207093. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207094. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207095. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207096. r.origin.x = pos.getX();
  207097. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207098. r.size.width = pos.getWidth();
  207099. r.size.height = pos.getHeight();
  207100. }
  207101. return r;
  207102. }
  207103. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207104. {
  207105. if (! isSharedWindow)
  207106. {
  207107. if (shouldBeMinimised)
  207108. [window miniaturize: nil];
  207109. else
  207110. [window deminiaturize: nil];
  207111. }
  207112. }
  207113. bool NSViewComponentPeer::isMinimised() const
  207114. {
  207115. return window != 0 && [window isMiniaturized];
  207116. }
  207117. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207118. {
  207119. if (! isSharedWindow)
  207120. {
  207121. Rectangle<int> r (lastNonFullscreenBounds);
  207122. setMinimised (false);
  207123. if (fullScreen != shouldBeFullScreen)
  207124. {
  207125. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207126. {
  207127. fullScreen = true;
  207128. [window performZoom: nil];
  207129. }
  207130. else
  207131. {
  207132. if (shouldBeFullScreen)
  207133. r = Desktop::getInstance().getMainMonitorArea();
  207134. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207135. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207136. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207137. }
  207138. }
  207139. }
  207140. }
  207141. bool NSViewComponentPeer::isFullScreen() const
  207142. {
  207143. return fullScreen;
  207144. }
  207145. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207146. {
  207147. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207148. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207149. return false;
  207150. NSPoint p;
  207151. p.x = (float) position.getX();
  207152. p.y = (float) position.getY();
  207153. NSView* v = [view hitTest: p];
  207154. if (trueIfInAChildWindow)
  207155. return v != nil;
  207156. return v == view;
  207157. }
  207158. const BorderSize NSViewComponentPeer::getFrameSize() const
  207159. {
  207160. BorderSize b;
  207161. if (! isSharedWindow)
  207162. {
  207163. NSRect v = [view convertRect: [view frame] toView: nil];
  207164. NSRect w = [window frame];
  207165. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207166. b.setBottom ((int) v.origin.y);
  207167. b.setLeft ((int) v.origin.x);
  207168. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207169. }
  207170. return b;
  207171. }
  207172. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207173. {
  207174. if (! isSharedWindow)
  207175. {
  207176. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207177. : NSNormalWindowLevel];
  207178. }
  207179. return true;
  207180. }
  207181. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207182. {
  207183. if (isSharedWindow)
  207184. {
  207185. [[view superview] addSubview: view
  207186. positioned: NSWindowAbove
  207187. relativeTo: nil];
  207188. }
  207189. if (window != 0 && component->isVisible())
  207190. {
  207191. if (makeActiveWindow)
  207192. [window makeKeyAndOrderFront: nil];
  207193. else
  207194. [window orderFront: nil];
  207195. if (! recursiveToFrontCall)
  207196. {
  207197. recursiveToFrontCall = true;
  207198. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207199. handleBroughtToFront();
  207200. recursiveToFrontCall = false;
  207201. }
  207202. }
  207203. }
  207204. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207205. {
  207206. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207207. if (isSharedWindow)
  207208. {
  207209. [[view superview] addSubview: view
  207210. positioned: NSWindowBelow
  207211. relativeTo: o->view];
  207212. }
  207213. else
  207214. {
  207215. [window orderWindow: NSWindowBelow
  207216. relativeTo: o->window != 0 ? [o->window windowNumber]
  207217. : nil ];
  207218. }
  207219. }
  207220. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207221. {
  207222. // to do..
  207223. }
  207224. void NSViewComponentPeer::viewFocusGain()
  207225. {
  207226. if (currentlyFocusedPeer != this)
  207227. {
  207228. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207229. currentlyFocusedPeer->handleFocusLoss();
  207230. currentlyFocusedPeer = this;
  207231. handleFocusGain();
  207232. }
  207233. }
  207234. void NSViewComponentPeer::viewFocusLoss()
  207235. {
  207236. if (currentlyFocusedPeer == this)
  207237. {
  207238. currentlyFocusedPeer = 0;
  207239. handleFocusLoss();
  207240. }
  207241. }
  207242. void juce_HandleProcessFocusChange()
  207243. {
  207244. NSViewComponentPeer::keysCurrentlyDown.clear();
  207245. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207246. {
  207247. if (Process::isForegroundProcess())
  207248. {
  207249. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207250. ComponentPeer::bringModalComponentToFront();
  207251. }
  207252. else
  207253. {
  207254. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207255. // turn kiosk mode off if we lose focus..
  207256. Desktop::getInstance().setKioskModeComponent (0);
  207257. }
  207258. }
  207259. }
  207260. bool NSViewComponentPeer::isFocused() const
  207261. {
  207262. return isSharedWindow ? this == currentlyFocusedPeer
  207263. : (window != 0 && [window isKeyWindow]);
  207264. }
  207265. void NSViewComponentPeer::grabFocus()
  207266. {
  207267. if (window != 0)
  207268. {
  207269. [window makeKeyWindow];
  207270. [window makeFirstResponder: view];
  207271. viewFocusGain();
  207272. }
  207273. }
  207274. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207275. {
  207276. }
  207277. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207278. {
  207279. String unicode (nsStringToJuce ([ev characters]));
  207280. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207281. int keyCode = getKeyCodeFromEvent (ev);
  207282. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207283. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207284. if (unicode.isNotEmpty() || keyCode != 0)
  207285. {
  207286. if (isKeyDown)
  207287. {
  207288. bool used = false;
  207289. while (unicode.length() > 0)
  207290. {
  207291. juce_wchar textCharacter = unicode[0];
  207292. unicode = unicode.substring (1);
  207293. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207294. textCharacter = 0;
  207295. used = handleKeyUpOrDown (true) || used;
  207296. used = handleKeyPress (keyCode, textCharacter) || used;
  207297. }
  207298. return used;
  207299. }
  207300. else
  207301. {
  207302. if (handleKeyUpOrDown (false))
  207303. return true;
  207304. }
  207305. }
  207306. return false;
  207307. }
  207308. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207309. {
  207310. updateKeysDown (ev, true);
  207311. bool used = handleKeyEvent (ev, true);
  207312. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207313. {
  207314. // for command keys, the key-up event is thrown away, so simulate one..
  207315. updateKeysDown (ev, false);
  207316. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207317. }
  207318. // (If we're running modally, don't allow unused keystrokes to be passed
  207319. // along to other blocked views..)
  207320. if (Component::getCurrentlyModalComponent() != 0)
  207321. used = true;
  207322. return used;
  207323. }
  207324. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207325. {
  207326. updateKeysDown (ev, false);
  207327. return handleKeyEvent (ev, false)
  207328. || Component::getCurrentlyModalComponent() != 0;
  207329. }
  207330. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207331. {
  207332. keysCurrentlyDown.clear();
  207333. handleKeyUpOrDown (true);
  207334. updateModifiers (ev);
  207335. handleModifierKeysChange();
  207336. }
  207337. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207338. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207339. {
  207340. if ([ev type] == NSKeyDown)
  207341. return redirectKeyDown (ev);
  207342. else if ([ev type] == NSKeyUp)
  207343. return redirectKeyUp (ev);
  207344. return false;
  207345. }
  207346. #endif
  207347. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207348. {
  207349. updateModifiers (ev);
  207350. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207351. }
  207352. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207353. {
  207354. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207355. sendMouseEvent (ev);
  207356. }
  207357. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207358. {
  207359. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207360. sendMouseEvent (ev);
  207361. showArrowCursorIfNeeded();
  207362. }
  207363. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207364. {
  207365. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207366. sendMouseEvent (ev);
  207367. }
  207368. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207369. {
  207370. currentModifiers = currentModifiers.withoutMouseButtons();
  207371. sendMouseEvent (ev);
  207372. showArrowCursorIfNeeded();
  207373. }
  207374. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207375. {
  207376. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207377. currentModifiers = currentModifiers.withoutMouseButtons();
  207378. sendMouseEvent (ev);
  207379. }
  207380. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207381. {
  207382. currentModifiers = currentModifiers.withoutMouseButtons();
  207383. sendMouseEvent (ev);
  207384. }
  207385. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207386. {
  207387. updateModifiers (ev);
  207388. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207389. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207390. }
  207391. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207392. {
  207393. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207394. if (mouse.getComponentUnderMouse() == 0
  207395. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207396. {
  207397. [[NSCursor arrowCursor] set];
  207398. }
  207399. }
  207400. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207401. {
  207402. NSString* bestType
  207403. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207404. if (bestType == nil)
  207405. return false;
  207406. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207407. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207408. StringArray files;
  207409. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207410. if (list == nil)
  207411. return false;
  207412. if ([list isKindOfClass: [NSArray class]])
  207413. {
  207414. NSArray* items = (NSArray*) list;
  207415. for (unsigned int i = 0; i < [items count]; ++i)
  207416. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207417. }
  207418. if (files.size() == 0)
  207419. return false;
  207420. if (type == 0)
  207421. handleFileDragMove (files, pos);
  207422. else if (type == 1)
  207423. handleFileDragExit (files);
  207424. else if (type == 2)
  207425. handleFileDragDrop (files, pos);
  207426. return true;
  207427. }
  207428. bool NSViewComponentPeer::isOpaque()
  207429. {
  207430. return component == 0 || component->isOpaque();
  207431. }
  207432. void NSViewComponentPeer::drawRect (NSRect r)
  207433. {
  207434. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207435. return;
  207436. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207437. if (! component->isOpaque())
  207438. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207439. #if USE_COREGRAPHICS_RENDERING
  207440. if (usingCoreGraphics)
  207441. {
  207442. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207443. insideDrawRect = true;
  207444. handlePaint (context);
  207445. insideDrawRect = false;
  207446. }
  207447. else
  207448. #endif
  207449. {
  207450. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207451. (int) (r.size.width + 0.5f),
  207452. (int) (r.size.height + 0.5f),
  207453. ! getComponent()->isOpaque());
  207454. LowLevelGraphicsSoftwareRenderer context (temp);
  207455. context.setOrigin (-roundToInt (r.origin.x),
  207456. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207457. const NSRect* rects = 0;
  207458. NSInteger numRects = 0;
  207459. [view getRectsBeingDrawn: &rects count: &numRects];
  207460. RectangleList clip;
  207461. for (int i = 0; i < numRects; ++i)
  207462. {
  207463. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207464. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207465. roundToInt (rects[i].size.width),
  207466. roundToInt (rects[i].size.height)));
  207467. }
  207468. if (context.clipToRectangleList (clip))
  207469. {
  207470. insideDrawRect = true;
  207471. handlePaint (context);
  207472. insideDrawRect = false;
  207473. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207474. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207475. CGColorSpaceRelease (colourSpace);
  207476. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207477. CGImageRelease (image);
  207478. }
  207479. }
  207480. }
  207481. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207482. {
  207483. StringArray s;
  207484. s.add ("Software Renderer");
  207485. #if USE_COREGRAPHICS_RENDERING
  207486. s.add ("CoreGraphics Renderer");
  207487. #endif
  207488. return s;
  207489. }
  207490. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207491. {
  207492. return usingCoreGraphics ? 1 : 0;
  207493. }
  207494. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207495. {
  207496. #if USE_COREGRAPHICS_RENDERING
  207497. if (usingCoreGraphics != (index > 0))
  207498. {
  207499. usingCoreGraphics = index > 0;
  207500. [view setNeedsDisplay: true];
  207501. }
  207502. #endif
  207503. }
  207504. bool NSViewComponentPeer::canBecomeKeyWindow()
  207505. {
  207506. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207507. }
  207508. bool NSViewComponentPeer::windowShouldClose()
  207509. {
  207510. if (! isValidPeer (this))
  207511. return YES;
  207512. handleUserClosingWindow();
  207513. return NO;
  207514. }
  207515. void NSViewComponentPeer::redirectMovedOrResized()
  207516. {
  207517. handleMovedOrResized();
  207518. }
  207519. void NSViewComponentPeer::viewMovedToWindow()
  207520. {
  207521. if (isSharedWindow)
  207522. window = [view window];
  207523. }
  207524. void Desktop::createMouseInputSources()
  207525. {
  207526. mouseSources.add (new MouseInputSource (0, true));
  207527. }
  207528. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207529. {
  207530. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207531. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207532. // is apparently still available in 64-bit apps..
  207533. if (enableOrDisable)
  207534. {
  207535. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207536. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207537. }
  207538. else
  207539. {
  207540. SetSystemUIMode (kUIModeNormal, 0);
  207541. }
  207542. }
  207543. class AsyncRepaintMessage : public CallbackMessage
  207544. {
  207545. public:
  207546. NSViewComponentPeer* const peer;
  207547. const Rectangle<int> rect;
  207548. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207549. : peer (peer_), rect (rect_)
  207550. {
  207551. }
  207552. void messageCallback()
  207553. {
  207554. if (ComponentPeer::isValidPeer (peer))
  207555. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207556. }
  207557. };
  207558. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207559. {
  207560. if (insideDrawRect)
  207561. {
  207562. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207563. }
  207564. else
  207565. {
  207566. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207567. (float) w, (float) h)];
  207568. }
  207569. }
  207570. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207571. {
  207572. [view displayIfNeeded];
  207573. }
  207574. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207575. {
  207576. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207577. }
  207578. Image* juce_createIconForFile (const File& file)
  207579. {
  207580. const ScopedAutoReleasePool pool;
  207581. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207582. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207583. [NSGraphicsContext saveGraphicsState];
  207584. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207585. [image drawAtPoint: NSMakePoint (0, 0)
  207586. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207587. operation: NSCompositeSourceOver fraction: 1.0f];
  207588. [[NSGraphicsContext currentContext] flushGraphics];
  207589. [NSGraphicsContext restoreGraphicsState];
  207590. return result;
  207591. }
  207592. const int KeyPress::spaceKey = ' ';
  207593. const int KeyPress::returnKey = 0x0d;
  207594. const int KeyPress::escapeKey = 0x1b;
  207595. const int KeyPress::backspaceKey = 0x7f;
  207596. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207597. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207598. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207599. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207600. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207601. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207602. const int KeyPress::endKey = NSEndFunctionKey;
  207603. const int KeyPress::homeKey = NSHomeFunctionKey;
  207604. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207605. const int KeyPress::insertKey = -1;
  207606. const int KeyPress::tabKey = 9;
  207607. const int KeyPress::F1Key = NSF1FunctionKey;
  207608. const int KeyPress::F2Key = NSF2FunctionKey;
  207609. const int KeyPress::F3Key = NSF3FunctionKey;
  207610. const int KeyPress::F4Key = NSF4FunctionKey;
  207611. const int KeyPress::F5Key = NSF5FunctionKey;
  207612. const int KeyPress::F6Key = NSF6FunctionKey;
  207613. const int KeyPress::F7Key = NSF7FunctionKey;
  207614. const int KeyPress::F8Key = NSF8FunctionKey;
  207615. const int KeyPress::F9Key = NSF9FunctionKey;
  207616. const int KeyPress::F10Key = NSF10FunctionKey;
  207617. const int KeyPress::F11Key = NSF1FunctionKey;
  207618. const int KeyPress::F12Key = NSF12FunctionKey;
  207619. const int KeyPress::F13Key = NSF13FunctionKey;
  207620. const int KeyPress::F14Key = NSF14FunctionKey;
  207621. const int KeyPress::F15Key = NSF15FunctionKey;
  207622. const int KeyPress::F16Key = NSF16FunctionKey;
  207623. const int KeyPress::numberPad0 = 0x30020;
  207624. const int KeyPress::numberPad1 = 0x30021;
  207625. const int KeyPress::numberPad2 = 0x30022;
  207626. const int KeyPress::numberPad3 = 0x30023;
  207627. const int KeyPress::numberPad4 = 0x30024;
  207628. const int KeyPress::numberPad5 = 0x30025;
  207629. const int KeyPress::numberPad6 = 0x30026;
  207630. const int KeyPress::numberPad7 = 0x30027;
  207631. const int KeyPress::numberPad8 = 0x30028;
  207632. const int KeyPress::numberPad9 = 0x30029;
  207633. const int KeyPress::numberPadAdd = 0x3002a;
  207634. const int KeyPress::numberPadSubtract = 0x3002b;
  207635. const int KeyPress::numberPadMultiply = 0x3002c;
  207636. const int KeyPress::numberPadDivide = 0x3002d;
  207637. const int KeyPress::numberPadSeparator = 0x3002e;
  207638. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207639. const int KeyPress::numberPadEquals = 0x30030;
  207640. const int KeyPress::numberPadDelete = 0x30031;
  207641. const int KeyPress::playKey = 0x30000;
  207642. const int KeyPress::stopKey = 0x30001;
  207643. const int KeyPress::fastForwardKey = 0x30002;
  207644. const int KeyPress::rewindKey = 0x30003;
  207645. #endif
  207646. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207647. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207648. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207649. // compiled on its own).
  207650. #if JUCE_INCLUDED_FILE
  207651. #if JUCE_MAC
  207652. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  207653. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207654. {
  207655. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207656. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207657. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207658. [im release];
  207659. return (void*) c;
  207660. }
  207661. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207662. {
  207663. MemoryInputStream stream (data, size, false);
  207664. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  207665. jassert (im != 0);
  207666. if (im == 0)
  207667. return 0;
  207668. return juce_createMouseCursorFromImage (*im,
  207669. (int) (hx * im->getWidth()),
  207670. (int) (hy * im->getHeight()));
  207671. }
  207672. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207673. {
  207674. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207675. MemoryBlock mb;
  207676. if (f.getChildFile (filename).loadFileAsData (mb))
  207677. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207678. return 0;
  207679. }
  207680. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207681. {
  207682. const ScopedAutoReleasePool pool;
  207683. NSCursor* c = 0;
  207684. switch (type)
  207685. {
  207686. case MouseCursor::NormalCursor:
  207687. c = [NSCursor arrowCursor];
  207688. break;
  207689. case MouseCursor::NoCursor:
  207690. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  207691. case MouseCursor::DraggingHandCursor:
  207692. c = [NSCursor openHandCursor];
  207693. break;
  207694. case MouseCursor::CopyingCursor:
  207695. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207696. case MouseCursor::WaitCursor:
  207697. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207698. break;
  207699. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207700. case MouseCursor::IBeamCursor:
  207701. c = [NSCursor IBeamCursor];
  207702. break;
  207703. case MouseCursor::PointingHandCursor:
  207704. c = [NSCursor pointingHandCursor];
  207705. break;
  207706. case MouseCursor::LeftRightResizeCursor:
  207707. c = [NSCursor resizeLeftRightCursor];
  207708. break;
  207709. case MouseCursor::LeftEdgeResizeCursor:
  207710. c = [NSCursor resizeLeftCursor];
  207711. break;
  207712. case MouseCursor::RightEdgeResizeCursor:
  207713. c = [NSCursor resizeRightCursor];
  207714. break;
  207715. case MouseCursor::UpDownResizeCursor:
  207716. case MouseCursor::TopEdgeResizeCursor:
  207717. case MouseCursor::BottomEdgeResizeCursor:
  207718. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207719. case MouseCursor::TopLeftCornerResizeCursor:
  207720. case MouseCursor::BottomRightCornerResizeCursor:
  207721. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207722. case MouseCursor::TopRightCornerResizeCursor:
  207723. case MouseCursor::BottomLeftCornerResizeCursor:
  207724. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207725. case MouseCursor::UpDownLeftRightResizeCursor:
  207726. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207727. case MouseCursor::CrosshairCursor:
  207728. c = [NSCursor crosshairCursor];
  207729. break;
  207730. }
  207731. [c retain];
  207732. return (void*) c;
  207733. }
  207734. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207735. {
  207736. NSCursor* c = (NSCursor*) cursorHandle;
  207737. [c release];
  207738. }
  207739. void MouseCursor::showInAllWindows() const throw()
  207740. {
  207741. showInWindow (0);
  207742. }
  207743. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207744. {
  207745. NSCursor* const c = (NSCursor*) getHandle();
  207746. [c set];
  207747. }
  207748. #else
  207749. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207750. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207751. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207752. void MouseCursor::showInAllWindows() const throw() {}
  207753. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207754. #endif
  207755. #endif
  207756. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207757. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207758. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207759. // compiled on its own).
  207760. #if JUCE_INCLUDED_FILE
  207761. class NSViewComponentInternal : public ComponentMovementWatcher
  207762. {
  207763. Component* const owner;
  207764. NSViewComponentPeer* currentPeer;
  207765. bool wasShowing;
  207766. public:
  207767. NSView* const view;
  207768. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207769. : ComponentMovementWatcher (owner_),
  207770. owner (owner_),
  207771. currentPeer (0),
  207772. wasShowing (false),
  207773. view (view_)
  207774. {
  207775. [view_ retain];
  207776. if (owner_->isShowing())
  207777. componentPeerChanged();
  207778. }
  207779. ~NSViewComponentInternal()
  207780. {
  207781. [view removeFromSuperview];
  207782. [view release];
  207783. }
  207784. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207785. {
  207786. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207787. // The ComponentMovementWatcher version of this method avoids calling
  207788. // us when the top-level comp is resized, but for an NSView we need to know this
  207789. // because with inverted co-ords, we need to update the position even if the
  207790. // top-left pos hasn't changed
  207791. if (comp.isOnDesktop() && wasResized)
  207792. componentMovedOrResized (wasMoved, wasResized);
  207793. }
  207794. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207795. {
  207796. Component* const topComp = owner->getTopLevelComponent();
  207797. if (topComp->getPeer() != 0)
  207798. {
  207799. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207800. NSRect r;
  207801. r.origin.x = (float) pos.getX();
  207802. r.origin.y = (float) pos.getY();
  207803. r.size.width = (float) owner->getWidth();
  207804. r.size.height = (float) owner->getHeight();
  207805. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207806. [view setFrame: r];
  207807. }
  207808. }
  207809. void componentPeerChanged()
  207810. {
  207811. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207812. if (currentPeer != peer)
  207813. {
  207814. [view removeFromSuperview];
  207815. currentPeer = peer;
  207816. if (peer != 0)
  207817. {
  207818. [peer->view addSubview: view];
  207819. componentMovedOrResized (false, false);
  207820. }
  207821. }
  207822. [view setHidden: ! owner->isShowing()];
  207823. }
  207824. void componentVisibilityChanged (Component&)
  207825. {
  207826. componentPeerChanged();
  207827. }
  207828. juce_UseDebuggingNewOperator
  207829. private:
  207830. NSViewComponentInternal (const NSViewComponentInternal&);
  207831. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207832. };
  207833. NSViewComponent::NSViewComponent()
  207834. {
  207835. }
  207836. NSViewComponent::~NSViewComponent()
  207837. {
  207838. }
  207839. void NSViewComponent::setView (void* view)
  207840. {
  207841. if (view != getView())
  207842. {
  207843. if (view != 0)
  207844. info = new NSViewComponentInternal ((NSView*) view, this);
  207845. else
  207846. info = 0;
  207847. }
  207848. }
  207849. void* NSViewComponent::getView() const
  207850. {
  207851. return info == 0 ? 0 : info->view;
  207852. }
  207853. void NSViewComponent::paint (Graphics& g)
  207854. {
  207855. }
  207856. #endif
  207857. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207858. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207859. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207860. // compiled on its own).
  207861. #if JUCE_INCLUDED_FILE
  207862. AppleRemoteDevice::AppleRemoteDevice()
  207863. : device (0),
  207864. queue (0),
  207865. remoteId (0)
  207866. {
  207867. }
  207868. AppleRemoteDevice::~AppleRemoteDevice()
  207869. {
  207870. stop();
  207871. }
  207872. static io_object_t getAppleRemoteDevice()
  207873. {
  207874. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207875. io_iterator_t iter = 0;
  207876. io_object_t iod = 0;
  207877. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207878. && iter != 0)
  207879. {
  207880. iod = IOIteratorNext (iter);
  207881. }
  207882. IOObjectRelease (iter);
  207883. return iod;
  207884. }
  207885. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  207886. {
  207887. jassert (*device == 0);
  207888. io_name_t classname;
  207889. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  207890. {
  207891. IOCFPlugInInterface** cfPlugInInterface = 0;
  207892. SInt32 score = 0;
  207893. if (IOCreatePlugInInterfaceForService (iod,
  207894. kIOHIDDeviceUserClientTypeID,
  207895. kIOCFPlugInInterfaceID,
  207896. &cfPlugInInterface,
  207897. &score) == kIOReturnSuccess)
  207898. {
  207899. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  207900. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  207901. device);
  207902. (void) hr;
  207903. (*cfPlugInInterface)->Release (cfPlugInInterface);
  207904. }
  207905. }
  207906. return *device != 0;
  207907. }
  207908. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  207909. {
  207910. if (queue != 0)
  207911. return true;
  207912. stop();
  207913. bool result = false;
  207914. io_object_t iod = getAppleRemoteDevice();
  207915. if (iod != 0)
  207916. {
  207917. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  207918. result = true;
  207919. else
  207920. stop();
  207921. IOObjectRelease (iod);
  207922. }
  207923. return result;
  207924. }
  207925. void AppleRemoteDevice::stop()
  207926. {
  207927. if (queue != 0)
  207928. {
  207929. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  207930. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  207931. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  207932. queue = 0;
  207933. }
  207934. if (device != 0)
  207935. {
  207936. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  207937. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  207938. device = 0;
  207939. }
  207940. }
  207941. bool AppleRemoteDevice::isActive() const
  207942. {
  207943. return queue != 0;
  207944. }
  207945. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  207946. {
  207947. if (result == kIOReturnSuccess)
  207948. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  207949. }
  207950. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  207951. {
  207952. Array <int> cookies;
  207953. CFArrayRef elements;
  207954. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  207955. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  207956. return false;
  207957. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  207958. {
  207959. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  207960. // get the cookie
  207961. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  207962. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  207963. continue;
  207964. long number;
  207965. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  207966. continue;
  207967. cookies.add ((int) number);
  207968. }
  207969. CFRelease (elements);
  207970. if ((*(IOHIDDeviceInterface**) device)
  207971. ->open ((IOHIDDeviceInterface**) device,
  207972. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  207973. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  207974. {
  207975. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  207976. if (queue != 0)
  207977. {
  207978. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  207979. for (int i = 0; i < cookies.size(); ++i)
  207980. {
  207981. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  207982. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  207983. }
  207984. CFRunLoopSourceRef eventSource;
  207985. if ((*(IOHIDQueueInterface**) queue)
  207986. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  207987. {
  207988. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  207989. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  207990. {
  207991. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  207992. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  207993. return true;
  207994. }
  207995. }
  207996. }
  207997. }
  207998. return false;
  207999. }
  208000. void AppleRemoteDevice::handleCallbackInternal()
  208001. {
  208002. int totalValues = 0;
  208003. AbsoluteTime nullTime = { 0, 0 };
  208004. char cookies [12];
  208005. int numCookies = 0;
  208006. while (numCookies < numElementsInArray (cookies))
  208007. {
  208008. IOHIDEventStruct e;
  208009. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208010. break;
  208011. if ((int) e.elementCookie == 19)
  208012. {
  208013. remoteId = e.value;
  208014. buttonPressed (switched, false);
  208015. }
  208016. else
  208017. {
  208018. totalValues += e.value;
  208019. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208020. }
  208021. }
  208022. cookies [numCookies++] = 0;
  208023. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208024. static const char buttonPatterns[] =
  208025. {
  208026. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208027. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208028. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208029. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208030. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208031. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208032. 0x1f, 0x12, 0x04, 0x02, 0,
  208033. 0x1f, 0x12, 0x03, 0x02, 0,
  208034. 0x1f, 0x12, 0x1f, 0x12, 0,
  208035. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208036. 19, 0
  208037. };
  208038. int buttonNum = (int) menuButton;
  208039. int i = 0;
  208040. while (i < numElementsInArray (buttonPatterns))
  208041. {
  208042. if (strcmp (cookies, buttonPatterns + i) == 0)
  208043. {
  208044. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208045. break;
  208046. }
  208047. i += (int) strlen (buttonPatterns + i) + 1;
  208048. ++buttonNum;
  208049. }
  208050. }
  208051. #endif
  208052. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208053. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208054. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208055. // compiled on its own).
  208056. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208057. #if JUCE_MAC
  208058. END_JUCE_NAMESPACE
  208059. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208060. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208061. {
  208062. CriticalSection* contextLock;
  208063. bool needsUpdate;
  208064. }
  208065. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208066. - (bool) makeActive;
  208067. - (void) makeInactive;
  208068. - (void) reshape;
  208069. @end
  208070. @implementation ThreadSafeNSOpenGLView
  208071. - (id) initWithFrame: (NSRect) frameRect
  208072. pixelFormat: (NSOpenGLPixelFormat*) format
  208073. {
  208074. contextLock = new CriticalSection();
  208075. self = [super initWithFrame: frameRect pixelFormat: format];
  208076. if (self != nil)
  208077. [[NSNotificationCenter defaultCenter] addObserver: self
  208078. selector: @selector (_surfaceNeedsUpdate:)
  208079. name: NSViewGlobalFrameDidChangeNotification
  208080. object: self];
  208081. return self;
  208082. }
  208083. - (void) dealloc
  208084. {
  208085. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208086. delete contextLock;
  208087. [super dealloc];
  208088. }
  208089. - (bool) makeActive
  208090. {
  208091. const ScopedLock sl (*contextLock);
  208092. if ([self openGLContext] == 0)
  208093. return false;
  208094. [[self openGLContext] makeCurrentContext];
  208095. if (needsUpdate)
  208096. {
  208097. [super update];
  208098. needsUpdate = false;
  208099. }
  208100. return true;
  208101. }
  208102. - (void) makeInactive
  208103. {
  208104. const ScopedLock sl (*contextLock);
  208105. [NSOpenGLContext clearCurrentContext];
  208106. }
  208107. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208108. {
  208109. const ScopedLock sl (*contextLock);
  208110. needsUpdate = true;
  208111. }
  208112. - (void) update
  208113. {
  208114. const ScopedLock sl (*contextLock);
  208115. needsUpdate = true;
  208116. }
  208117. - (void) reshape
  208118. {
  208119. const ScopedLock sl (*contextLock);
  208120. needsUpdate = true;
  208121. }
  208122. @end
  208123. BEGIN_JUCE_NAMESPACE
  208124. class WindowedGLContext : public OpenGLContext
  208125. {
  208126. public:
  208127. WindowedGLContext (Component* const component,
  208128. const OpenGLPixelFormat& pixelFormat_,
  208129. NSOpenGLContext* sharedContext)
  208130. : renderContext (0),
  208131. pixelFormat (pixelFormat_)
  208132. {
  208133. jassert (component != 0);
  208134. NSOpenGLPixelFormatAttribute attribs [64];
  208135. int n = 0;
  208136. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208137. attribs[n++] = NSOpenGLPFAAccelerated;
  208138. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208139. attribs[n++] = NSOpenGLPFAColorSize;
  208140. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208141. pixelFormat.greenBits,
  208142. pixelFormat.blueBits);
  208143. attribs[n++] = NSOpenGLPFAAlphaSize;
  208144. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208145. attribs[n++] = NSOpenGLPFADepthSize;
  208146. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208147. attribs[n++] = NSOpenGLPFAStencilSize;
  208148. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208149. attribs[n++] = NSOpenGLPFAAccumSize;
  208150. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208151. pixelFormat.accumulationBufferGreenBits,
  208152. pixelFormat.accumulationBufferBlueBits,
  208153. pixelFormat.accumulationBufferAlphaBits);
  208154. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208155. attribs[n++] = NSOpenGLPFASampleBuffers;
  208156. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208157. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208158. attribs[n++] = NSOpenGLPFANoRecovery;
  208159. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208160. NSOpenGLPixelFormat* format
  208161. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208162. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208163. pixelFormat: format];
  208164. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208165. shareContext: sharedContext] autorelease];
  208166. const GLint swapInterval = 1;
  208167. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208168. [view setOpenGLContext: renderContext];
  208169. [renderContext setView: view];
  208170. [format release];
  208171. viewHolder = new NSViewComponentInternal (view, component);
  208172. }
  208173. ~WindowedGLContext()
  208174. {
  208175. makeInactive();
  208176. [renderContext clearDrawable];
  208177. viewHolder = 0;
  208178. }
  208179. bool makeActive() const throw()
  208180. {
  208181. jassert (renderContext != 0);
  208182. [view makeActive];
  208183. return isActive();
  208184. }
  208185. bool makeInactive() const throw()
  208186. {
  208187. [view makeInactive];
  208188. return true;
  208189. }
  208190. bool isActive() const throw()
  208191. {
  208192. return [NSOpenGLContext currentContext] == renderContext;
  208193. }
  208194. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208195. void* getRawContext() const throw() { return renderContext; }
  208196. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208197. {
  208198. }
  208199. void swapBuffers()
  208200. {
  208201. [renderContext flushBuffer];
  208202. }
  208203. bool setSwapInterval (const int numFramesPerSwap)
  208204. {
  208205. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208206. forParameter: NSOpenGLCPSwapInterval];
  208207. return true;
  208208. }
  208209. int getSwapInterval() const
  208210. {
  208211. GLint numFrames = 0;
  208212. [renderContext getValues: &numFrames
  208213. forParameter: NSOpenGLCPSwapInterval];
  208214. return numFrames;
  208215. }
  208216. void repaint()
  208217. {
  208218. // we need to invalidate the juce view that holds this gl view, to make it
  208219. // cause a repaint callback
  208220. NSView* v = (NSView*) viewHolder->view;
  208221. NSRect r = [v frame];
  208222. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208223. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208224. // repaint message, thus never causing our paint() callback, and never repainting
  208225. // the comp. So invalidating just a little bit around the edge helps..
  208226. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208227. }
  208228. void* getNativeWindowHandle() const { return viewHolder->view; }
  208229. juce_UseDebuggingNewOperator
  208230. NSOpenGLContext* renderContext;
  208231. ThreadSafeNSOpenGLView* view;
  208232. private:
  208233. OpenGLPixelFormat pixelFormat;
  208234. ScopedPointer <NSViewComponentInternal> viewHolder;
  208235. WindowedGLContext (const WindowedGLContext&);
  208236. WindowedGLContext& operator= (const WindowedGLContext&);
  208237. };
  208238. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208239. const OpenGLPixelFormat& pixelFormat,
  208240. const OpenGLContext* const contextToShareWith)
  208241. {
  208242. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208243. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208244. return (c->renderContext != 0) ? c.release() : 0;
  208245. }
  208246. void* OpenGLComponent::getNativeWindowHandle() const
  208247. {
  208248. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208249. : 0;
  208250. }
  208251. void juce_glViewport (const int w, const int h)
  208252. {
  208253. glViewport (0, 0, w, h);
  208254. }
  208255. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208256. OwnedArray <OpenGLPixelFormat>& results)
  208257. {
  208258. /* GLint attribs [64];
  208259. int n = 0;
  208260. attribs[n++] = AGL_RGBA;
  208261. attribs[n++] = AGL_DOUBLEBUFFER;
  208262. attribs[n++] = AGL_ACCELERATED;
  208263. attribs[n++] = AGL_NO_RECOVERY;
  208264. attribs[n++] = AGL_NONE;
  208265. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208266. while (p != 0)
  208267. {
  208268. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208269. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208270. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208271. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208272. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208273. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208274. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208275. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208276. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208277. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208278. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208279. results.add (pf);
  208280. p = aglNextPixelFormat (p);
  208281. }*/
  208282. //jassertfalse //xxx can't see how you do this in cocoa!
  208283. }
  208284. #else
  208285. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208286. const OpenGLPixelFormat& pixelFormat,
  208287. const OpenGLContext* const contextToShareWith)
  208288. {
  208289. return 0;
  208290. }
  208291. void juce_glViewport (const int w, const int h)
  208292. {
  208293. //glViewport (0, 0, w, h);
  208294. }
  208295. #endif
  208296. #endif
  208297. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208298. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208299. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208300. // compiled on its own).
  208301. #if JUCE_INCLUDED_FILE
  208302. class JuceMainMenuHandler;
  208303. END_JUCE_NAMESPACE
  208304. using namespace JUCE_NAMESPACE;
  208305. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208306. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208307. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208308. #else
  208309. @interface JuceMenuCallback : NSObject
  208310. #endif
  208311. {
  208312. JuceMainMenuHandler* owner;
  208313. }
  208314. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208315. - (void) dealloc;
  208316. - (void) menuItemInvoked: (id) menu;
  208317. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208318. @end
  208319. BEGIN_JUCE_NAMESPACE
  208320. class JuceMainMenuHandler : private MenuBarModelListener,
  208321. private DeletedAtShutdown
  208322. {
  208323. public:
  208324. static JuceMainMenuHandler* instance;
  208325. JuceMainMenuHandler()
  208326. : currentModel (0),
  208327. lastUpdateTime (0)
  208328. {
  208329. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208330. }
  208331. ~JuceMainMenuHandler()
  208332. {
  208333. setMenu (0);
  208334. jassert (instance == this);
  208335. instance = 0;
  208336. [callback release];
  208337. }
  208338. void setMenu (MenuBarModel* const newMenuBarModel)
  208339. {
  208340. if (currentModel != newMenuBarModel)
  208341. {
  208342. if (currentModel != 0)
  208343. currentModel->removeListener (this);
  208344. currentModel = newMenuBarModel;
  208345. if (currentModel != 0)
  208346. currentModel->addListener (this);
  208347. menuBarItemsChanged (0);
  208348. }
  208349. }
  208350. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208351. const String& name, const int menuId, const int tag)
  208352. {
  208353. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208354. action: nil
  208355. keyEquivalent: @""];
  208356. [item setTag: tag];
  208357. NSMenu* sub = createMenu (child, name, menuId, tag);
  208358. [parent setSubmenu: sub forItem: item];
  208359. [sub setAutoenablesItems: false];
  208360. [sub release];
  208361. }
  208362. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208363. const String& name, const int menuId, const int tag)
  208364. {
  208365. [parentItem setTag: tag];
  208366. NSMenu* menu = [parentItem submenu];
  208367. [menu setTitle: juceStringToNS (name)];
  208368. while ([menu numberOfItems] > 0)
  208369. [menu removeItemAtIndex: 0];
  208370. PopupMenu::MenuItemIterator iter (menuToCopy);
  208371. while (iter.next())
  208372. addMenuItem (iter, menu, menuId, tag);
  208373. [menu setAutoenablesItems: false];
  208374. [menu update];
  208375. }
  208376. void menuBarItemsChanged (MenuBarModel*)
  208377. {
  208378. lastUpdateTime = Time::getMillisecondCounter();
  208379. StringArray menuNames;
  208380. if (currentModel != 0)
  208381. menuNames = currentModel->getMenuBarNames();
  208382. NSMenu* menuBar = [NSApp mainMenu];
  208383. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208384. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208385. int menuId = 1;
  208386. for (int i = 0; i < menuNames.size(); ++i)
  208387. {
  208388. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208389. if (i >= [menuBar numberOfItems] - 1)
  208390. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208391. else
  208392. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208393. }
  208394. }
  208395. static void flashMenuBar (NSMenu* menu)
  208396. {
  208397. if ([[menu title] isEqualToString: @"Apple"])
  208398. return;
  208399. [menu retain];
  208400. const unichar f35Key = NSF35FunctionKey;
  208401. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208402. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208403. action: nil
  208404. keyEquivalent: f35String];
  208405. [item setTarget: nil];
  208406. [menu insertItem: item atIndex: [menu numberOfItems]];
  208407. [item release];
  208408. if ([menu indexOfItem: item] >= 0)
  208409. {
  208410. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208411. location: NSZeroPoint
  208412. modifierFlags: NSCommandKeyMask
  208413. timestamp: 0
  208414. windowNumber: 0
  208415. context: [NSGraphicsContext currentContext]
  208416. characters: f35String
  208417. charactersIgnoringModifiers: f35String
  208418. isARepeat: NO
  208419. keyCode: 0];
  208420. [menu performKeyEquivalent: f35Event];
  208421. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208422. }
  208423. [menu release];
  208424. }
  208425. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208426. {
  208427. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208428. {
  208429. NSMenuItem* m = [menu itemAtIndex: i];
  208430. if ([m tag] == info.commandID)
  208431. return m;
  208432. if ([m submenu] != 0)
  208433. {
  208434. NSMenuItem* found = findMenuItem ([m submenu], info);
  208435. if (found != 0)
  208436. return found;
  208437. }
  208438. }
  208439. return 0;
  208440. }
  208441. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208442. {
  208443. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208444. if (item != 0)
  208445. flashMenuBar ([item menu]);
  208446. }
  208447. void updateMenus()
  208448. {
  208449. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208450. menuBarItemsChanged (0);
  208451. }
  208452. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208453. {
  208454. if (currentModel != 0)
  208455. {
  208456. if (commandManager != 0)
  208457. {
  208458. ApplicationCommandTarget::InvocationInfo info (commandId);
  208459. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208460. commandManager->invoke (info, true);
  208461. }
  208462. currentModel->menuItemSelected (commandId, topLevelIndex);
  208463. }
  208464. }
  208465. MenuBarModel* currentModel;
  208466. uint32 lastUpdateTime;
  208467. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208468. const int topLevelMenuId, const int topLevelIndex)
  208469. {
  208470. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208471. if (text == 0)
  208472. text = @"";
  208473. if (iter.isSeparator)
  208474. {
  208475. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208476. }
  208477. else if (iter.isSectionHeader)
  208478. {
  208479. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208480. action: nil
  208481. keyEquivalent: @""];
  208482. [item setEnabled: false];
  208483. }
  208484. else if (iter.subMenu != 0)
  208485. {
  208486. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208487. action: nil
  208488. keyEquivalent: @""];
  208489. [item setTag: iter.itemId];
  208490. [item setEnabled: iter.isEnabled];
  208491. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208492. [sub setDelegate: nil];
  208493. [menuToAddTo setSubmenu: sub forItem: item];
  208494. [sub release];
  208495. }
  208496. else
  208497. {
  208498. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208499. action: @selector (menuItemInvoked:)
  208500. keyEquivalent: @""];
  208501. [item setTag: iter.itemId];
  208502. [item setEnabled: iter.isEnabled];
  208503. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208504. [item setTarget: (id) callback];
  208505. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208506. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208507. [item setRepresentedObject: info];
  208508. if (iter.commandManager != 0)
  208509. {
  208510. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208511. ->getKeyPressesAssignedToCommand (iter.itemId));
  208512. if (keyPresses.size() > 0)
  208513. {
  208514. const KeyPress& kp = keyPresses.getReference(0);
  208515. juce_wchar key = kp.getTextCharacter();
  208516. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208517. key = NSBackspaceCharacter;
  208518. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208519. key = NSDeleteCharacter;
  208520. else if (key == 0)
  208521. key = (juce_wchar) kp.getKeyCode();
  208522. unsigned int mods = 0;
  208523. if (kp.getModifiers().isShiftDown())
  208524. mods |= NSShiftKeyMask;
  208525. if (kp.getModifiers().isCtrlDown())
  208526. mods |= NSControlKeyMask;
  208527. if (kp.getModifiers().isAltDown())
  208528. mods |= NSAlternateKeyMask;
  208529. if (kp.getModifiers().isCommandDown())
  208530. mods |= NSCommandKeyMask;
  208531. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208532. [item setKeyEquivalentModifierMask: mods];
  208533. }
  208534. }
  208535. }
  208536. }
  208537. JuceMenuCallback* callback;
  208538. private:
  208539. NSMenu* createMenu (const PopupMenu menu,
  208540. const String& menuName,
  208541. const int topLevelMenuId,
  208542. const int topLevelIndex)
  208543. {
  208544. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208545. [m setAutoenablesItems: false];
  208546. [m setDelegate: callback];
  208547. PopupMenu::MenuItemIterator iter (menu);
  208548. while (iter.next())
  208549. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208550. [m update];
  208551. return m;
  208552. }
  208553. };
  208554. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208555. END_JUCE_NAMESPACE
  208556. @implementation JuceMenuCallback
  208557. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208558. {
  208559. [super init];
  208560. owner = owner_;
  208561. return self;
  208562. }
  208563. - (void) dealloc
  208564. {
  208565. [super dealloc];
  208566. }
  208567. - (void) menuItemInvoked: (id) menu
  208568. {
  208569. NSMenuItem* item = (NSMenuItem*) menu;
  208570. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208571. {
  208572. // 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
  208573. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208574. // into the focused component and let it trigger the menu item indirectly.
  208575. NSEvent* e = [NSApp currentEvent];
  208576. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208577. {
  208578. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208579. {
  208580. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208581. if (peer != 0)
  208582. {
  208583. if ([e type] == NSKeyDown)
  208584. peer->redirectKeyDown (e);
  208585. else
  208586. peer->redirectKeyUp (e);
  208587. return;
  208588. }
  208589. }
  208590. }
  208591. NSArray* info = (NSArray*) [item representedObject];
  208592. owner->invoke ((int) [item tag],
  208593. (ApplicationCommandManager*) (pointer_sized_int)
  208594. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208595. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208596. }
  208597. }
  208598. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208599. {
  208600. if (JuceMainMenuHandler::instance != 0)
  208601. JuceMainMenuHandler::instance->updateMenus();
  208602. }
  208603. @end
  208604. BEGIN_JUCE_NAMESPACE
  208605. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208606. const PopupMenu* extraItems)
  208607. {
  208608. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208609. {
  208610. PopupMenu::MenuItemIterator iter (*extraItems);
  208611. while (iter.next())
  208612. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208613. [menu addItem: [NSMenuItem separatorItem]];
  208614. }
  208615. NSMenuItem* item;
  208616. // Services...
  208617. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208618. action: nil keyEquivalent: @""];
  208619. [menu addItem: item];
  208620. [item release];
  208621. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208622. [menu setSubmenu: servicesMenu forItem: item];
  208623. [NSApp setServicesMenu: servicesMenu];
  208624. [servicesMenu release];
  208625. [menu addItem: [NSMenuItem separatorItem]];
  208626. // Hide + Show stuff...
  208627. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208628. action: @selector (hide:) keyEquivalent: @"h"];
  208629. [item setTarget: NSApp];
  208630. [menu addItem: item];
  208631. [item release];
  208632. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208633. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208634. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208635. [item setTarget: NSApp];
  208636. [menu addItem: item];
  208637. [item release];
  208638. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208639. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208640. [item setTarget: NSApp];
  208641. [menu addItem: item];
  208642. [item release];
  208643. [menu addItem: [NSMenuItem separatorItem]];
  208644. // Quit item....
  208645. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208646. action: @selector (terminate:) keyEquivalent: @"q"];
  208647. [item setTarget: NSApp];
  208648. [menu addItem: item];
  208649. [item release];
  208650. return menu;
  208651. }
  208652. // Since our app has no NIB, this initialises a standard app menu...
  208653. static void rebuildMainMenu (const PopupMenu* extraItems)
  208654. {
  208655. // this can't be used in a plugin!
  208656. jassert (JUCEApplication::getInstance() != 0);
  208657. if (JUCEApplication::getInstance() != 0)
  208658. {
  208659. const ScopedAutoReleasePool pool;
  208660. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208661. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208662. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208663. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208664. [mainMenu setSubmenu: appMenu forItem: item];
  208665. [NSApp setMainMenu: mainMenu];
  208666. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208667. [appMenu release];
  208668. [mainMenu release];
  208669. }
  208670. }
  208671. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208672. const PopupMenu* extraAppleMenuItems)
  208673. {
  208674. if (getMacMainMenu() != newMenuBarModel)
  208675. {
  208676. const ScopedAutoReleasePool pool;
  208677. if (newMenuBarModel == 0)
  208678. {
  208679. delete JuceMainMenuHandler::instance;
  208680. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208681. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208682. extraAppleMenuItems = 0;
  208683. }
  208684. else
  208685. {
  208686. if (JuceMainMenuHandler::instance == 0)
  208687. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208688. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208689. }
  208690. }
  208691. rebuildMainMenu (extraAppleMenuItems);
  208692. if (newMenuBarModel != 0)
  208693. newMenuBarModel->menuItemsChanged();
  208694. }
  208695. MenuBarModel* MenuBarModel::getMacMainMenu()
  208696. {
  208697. return JuceMainMenuHandler::instance != 0
  208698. ? JuceMainMenuHandler::instance->currentModel : 0;
  208699. }
  208700. void initialiseMainMenu()
  208701. {
  208702. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208703. rebuildMainMenu (0);
  208704. }
  208705. #endif
  208706. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208707. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208708. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208709. // compiled on its own).
  208710. #if JUCE_INCLUDED_FILE
  208711. #if JUCE_MAC
  208712. END_JUCE_NAMESPACE
  208713. using namespace JUCE_NAMESPACE;
  208714. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208715. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208716. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208717. #else
  208718. @interface JuceFileChooserDelegate : NSObject
  208719. #endif
  208720. {
  208721. StringArray* filters;
  208722. }
  208723. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208724. - (void) dealloc;
  208725. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208726. @end
  208727. @implementation JuceFileChooserDelegate
  208728. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208729. {
  208730. [super init];
  208731. filters = filters_;
  208732. return self;
  208733. }
  208734. - (void) dealloc
  208735. {
  208736. delete filters;
  208737. [super dealloc];
  208738. }
  208739. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208740. {
  208741. const File f (nsStringToJuce (filename));
  208742. for (int i = filters->size(); --i >= 0;)
  208743. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208744. return true;
  208745. return f.isDirectory();
  208746. }
  208747. @end
  208748. BEGIN_JUCE_NAMESPACE
  208749. void FileChooser::showPlatformDialog (Array<File>& results,
  208750. const String& title,
  208751. const File& currentFileOrDirectory,
  208752. const String& filter,
  208753. bool selectsDirectory,
  208754. bool selectsFiles,
  208755. bool isSaveDialogue,
  208756. bool warnAboutOverwritingExistingFiles,
  208757. bool selectMultipleFiles,
  208758. FilePreviewComponent* extraInfoComponent)
  208759. {
  208760. const ScopedAutoReleasePool pool;
  208761. StringArray* filters = new StringArray();
  208762. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), String::empty);
  208763. filters->trim();
  208764. filters->removeEmptyStrings();
  208765. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208766. [delegate autorelease];
  208767. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208768. : [NSOpenPanel openPanel];
  208769. [panel setTitle: juceStringToNS (title)];
  208770. if (! isSaveDialogue)
  208771. {
  208772. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208773. [openPanel setCanChooseDirectories: selectsDirectory];
  208774. [openPanel setCanChooseFiles: selectsFiles];
  208775. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208776. }
  208777. [panel setDelegate: delegate];
  208778. if (isSaveDialogue || selectsDirectory)
  208779. [panel setCanCreateDirectories: YES];
  208780. String directory, filename;
  208781. if (currentFileOrDirectory.isDirectory())
  208782. {
  208783. directory = currentFileOrDirectory.getFullPathName();
  208784. }
  208785. else
  208786. {
  208787. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208788. filename = currentFileOrDirectory.getFileName();
  208789. }
  208790. if ([panel runModalForDirectory: juceStringToNS (directory)
  208791. file: juceStringToNS (filename)]
  208792. == NSOKButton)
  208793. {
  208794. if (isSaveDialogue)
  208795. {
  208796. results.add (File (nsStringToJuce ([panel filename])));
  208797. }
  208798. else
  208799. {
  208800. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208801. NSArray* urls = [openPanel filenames];
  208802. for (unsigned int i = 0; i < [urls count]; ++i)
  208803. {
  208804. NSString* f = [urls objectAtIndex: i];
  208805. results.add (File (nsStringToJuce (f)));
  208806. }
  208807. }
  208808. }
  208809. [panel setDelegate: nil];
  208810. }
  208811. #else
  208812. void FileChooser::showPlatformDialog (Array<File>& results,
  208813. const String& title,
  208814. const File& currentFileOrDirectory,
  208815. const String& filter,
  208816. bool selectsDirectory,
  208817. bool selectsFiles,
  208818. bool isSaveDialogue,
  208819. bool warnAboutOverwritingExistingFiles,
  208820. bool selectMultipleFiles,
  208821. FilePreviewComponent* extraInfoComponent)
  208822. {
  208823. const ScopedAutoReleasePool pool;
  208824. jassertfalse //xxx to do
  208825. }
  208826. #endif
  208827. #endif
  208828. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  208829. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  208830. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208831. // compiled on its own).
  208832. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  208833. END_JUCE_NAMESPACE
  208834. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  208835. @interface NonInterceptingQTMovieView : QTMovieView
  208836. {
  208837. }
  208838. - (id) initWithFrame: (NSRect) frame;
  208839. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  208840. - (NSView*) hitTest: (NSPoint) p;
  208841. @end
  208842. @implementation NonInterceptingQTMovieView
  208843. - (id) initWithFrame: (NSRect) frame
  208844. {
  208845. self = [super initWithFrame: frame];
  208846. [self setNextResponder: [self superview]];
  208847. return self;
  208848. }
  208849. - (void) dealloc
  208850. {
  208851. [super dealloc];
  208852. }
  208853. - (NSView*) hitTest: (NSPoint) point
  208854. {
  208855. return [self isControllerVisible] ? [super hitTest: point] : nil;
  208856. }
  208857. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  208858. {
  208859. return YES;
  208860. }
  208861. @end
  208862. BEGIN_JUCE_NAMESPACE
  208863. #define theMovie (static_cast <QTMovie*> (movie))
  208864. QuickTimeMovieComponent::QuickTimeMovieComponent()
  208865. : movie (0)
  208866. {
  208867. setOpaque (true);
  208868. setVisible (true);
  208869. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  208870. setView (view);
  208871. [view release];
  208872. }
  208873. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  208874. {
  208875. closeMovie();
  208876. setView (0);
  208877. }
  208878. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  208879. {
  208880. return true;
  208881. }
  208882. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  208883. {
  208884. // unfortunately, QTMovie objects can only be created on the main thread..
  208885. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  208886. QTMovie* movie = 0;
  208887. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  208888. if (fin != 0)
  208889. {
  208890. movieFile = fin->getFile();
  208891. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  208892. error: nil];
  208893. }
  208894. else
  208895. {
  208896. MemoryBlock temp;
  208897. movieStream->readIntoMemoryBlock (temp);
  208898. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  208899. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  208900. {
  208901. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  208902. length: temp.getSize()]
  208903. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  208904. MIMEType: @""]
  208905. error: nil];
  208906. if (movie != 0)
  208907. break;
  208908. }
  208909. }
  208910. return movie;
  208911. }
  208912. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  208913. const bool isControllerVisible_)
  208914. {
  208915. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  208916. }
  208917. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  208918. const bool controllerVisible_)
  208919. {
  208920. closeMovie();
  208921. if (getPeer() == 0)
  208922. {
  208923. // To open a movie, this component must be visible inside a functioning window, so that
  208924. // the QT control can be assigned to the window.
  208925. jassertfalse
  208926. return false;
  208927. }
  208928. movie = openMovieFromStream (movieStream, movieFile);
  208929. [theMovie retain];
  208930. QTMovieView* view = (QTMovieView*) getView();
  208931. [view setMovie: theMovie];
  208932. [view setControllerVisible: controllerVisible_];
  208933. setLooping (looping);
  208934. return movie != nil;
  208935. }
  208936. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  208937. const bool isControllerVisible_)
  208938. {
  208939. // unfortunately, QTMovie objects can only be created on the main thread..
  208940. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  208941. closeMovie();
  208942. if (getPeer() == 0)
  208943. {
  208944. // To open a movie, this component must be visible inside a functioning window, so that
  208945. // the QT control can be assigned to the window.
  208946. jassertfalse
  208947. return false;
  208948. }
  208949. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  208950. NSError* err;
  208951. if ([QTMovie canInitWithURL: url])
  208952. movie = [QTMovie movieWithURL: url error: &err];
  208953. [theMovie retain];
  208954. QTMovieView* view = (QTMovieView*) getView();
  208955. [view setMovie: theMovie];
  208956. [view setControllerVisible: controllerVisible];
  208957. setLooping (looping);
  208958. return movie != nil;
  208959. }
  208960. void QuickTimeMovieComponent::closeMovie()
  208961. {
  208962. stop();
  208963. QTMovieView* view = (QTMovieView*) getView();
  208964. [view setMovie: nil];
  208965. [theMovie release];
  208966. movie = 0;
  208967. movieFile = File::nonexistent;
  208968. }
  208969. bool QuickTimeMovieComponent::isMovieOpen() const
  208970. {
  208971. return movie != nil;
  208972. }
  208973. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  208974. {
  208975. return movieFile;
  208976. }
  208977. void QuickTimeMovieComponent::play()
  208978. {
  208979. [theMovie play];
  208980. }
  208981. void QuickTimeMovieComponent::stop()
  208982. {
  208983. [theMovie stop];
  208984. }
  208985. bool QuickTimeMovieComponent::isPlaying() const
  208986. {
  208987. return movie != 0 && [theMovie rate] != 0;
  208988. }
  208989. void QuickTimeMovieComponent::setPosition (const double seconds)
  208990. {
  208991. if (movie != 0)
  208992. {
  208993. QTTime t;
  208994. t.timeValue = (uint64) (100000.0 * seconds);
  208995. t.timeScale = 100000;
  208996. t.flags = 0;
  208997. [theMovie setCurrentTime: t];
  208998. }
  208999. }
  209000. double QuickTimeMovieComponent::getPosition() const
  209001. {
  209002. if (movie == 0)
  209003. return 0.0;
  209004. QTTime t = [theMovie currentTime];
  209005. return t.timeValue / (double) t.timeScale;
  209006. }
  209007. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209008. {
  209009. [theMovie setRate: newSpeed];
  209010. }
  209011. double QuickTimeMovieComponent::getMovieDuration() const
  209012. {
  209013. if (movie == 0)
  209014. return 0.0;
  209015. QTTime t = [theMovie duration];
  209016. return t.timeValue / (double) t.timeScale;
  209017. }
  209018. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209019. {
  209020. looping = shouldLoop;
  209021. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209022. forKey: QTMovieLoopsAttribute];
  209023. }
  209024. bool QuickTimeMovieComponent::isLooping() const
  209025. {
  209026. return looping;
  209027. }
  209028. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209029. {
  209030. [theMovie setVolume: newVolume];
  209031. }
  209032. float QuickTimeMovieComponent::getMovieVolume() const
  209033. {
  209034. return movie != 0 ? [theMovie volume] : 0.0f;
  209035. }
  209036. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209037. {
  209038. width = 0;
  209039. height = 0;
  209040. if (movie != 0)
  209041. {
  209042. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209043. width = (int) s.width;
  209044. height = (int) s.height;
  209045. }
  209046. }
  209047. void QuickTimeMovieComponent::paint (Graphics& g)
  209048. {
  209049. if (movie == 0)
  209050. g.fillAll (Colours::black);
  209051. }
  209052. bool QuickTimeMovieComponent::isControllerVisible() const
  209053. {
  209054. return controllerVisible;
  209055. }
  209056. void QuickTimeMovieComponent::goToStart()
  209057. {
  209058. setPosition (0.0);
  209059. }
  209060. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209061. const RectanglePlacement& placement)
  209062. {
  209063. int normalWidth, normalHeight;
  209064. getMovieNormalSize (normalWidth, normalHeight);
  209065. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209066. {
  209067. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209068. placement.applyTo (x, y, w, h,
  209069. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209070. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209071. if (w > 0 && h > 0)
  209072. {
  209073. setBounds (roundToInt (x), roundToInt (y),
  209074. roundToInt (w), roundToInt (h));
  209075. }
  209076. }
  209077. else
  209078. {
  209079. setBounds (spaceToFitWithin);
  209080. }
  209081. }
  209082. #if ! (JUCE_MAC && JUCE_64BIT)
  209083. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209084. {
  209085. if (movieStream == 0)
  209086. return false;
  209087. File file;
  209088. QTMovie* movie = openMovieFromStream (movieStream, file);
  209089. if (movie != nil)
  209090. result = [movie quickTimeMovie];
  209091. return movie != nil;
  209092. }
  209093. #endif
  209094. #endif
  209095. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209096. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209097. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209098. // compiled on its own).
  209099. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209100. const int kilobytesPerSecond1x = 176;
  209101. END_JUCE_NAMESPACE
  209102. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209103. @interface OpenDiskDevice : NSObject
  209104. {
  209105. @public
  209106. DRDevice* device;
  209107. NSMutableArray* tracks;
  209108. bool underrunProtection;
  209109. }
  209110. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209111. - (void) dealloc;
  209112. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209113. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209114. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209115. @end
  209116. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209117. @interface AudioTrackProducer : NSObject
  209118. {
  209119. JUCE_NAMESPACE::AudioSource* source;
  209120. int readPosition, lengthInFrames;
  209121. }
  209122. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209123. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209124. - (void) dealloc;
  209125. - (void) setupTrackProperties: (DRTrack*) track;
  209126. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209127. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209128. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209129. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209130. toMedia:(NSDictionary*)mediaInfo;
  209131. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209132. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209133. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209134. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209135. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209136. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209137. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209138. ioFlags:(uint32_t*)flags;
  209139. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209140. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209141. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209142. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209143. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209144. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209145. ioFlags:(uint32_t*)flags;
  209146. @end
  209147. @implementation OpenDiskDevice
  209148. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209149. {
  209150. [super init];
  209151. device = device_;
  209152. tracks = [[NSMutableArray alloc] init];
  209153. underrunProtection = true;
  209154. return self;
  209155. }
  209156. - (void) dealloc
  209157. {
  209158. [tracks release];
  209159. [super dealloc];
  209160. }
  209161. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209162. {
  209163. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209164. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209165. [p setupTrackProperties: t];
  209166. [tracks addObject: t];
  209167. [t release];
  209168. [p release];
  209169. }
  209170. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209171. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209172. {
  209173. DRBurn* burn = [DRBurn burnForDevice: device];
  209174. if (! [device acquireExclusiveAccess])
  209175. {
  209176. *error = "Couldn't open or write to the CD device";
  209177. return;
  209178. }
  209179. [device acquireMediaReservation];
  209180. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209181. [d autorelease];
  209182. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209183. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209184. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209185. if (burnSpeed > 0)
  209186. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209187. if (! underrunProtection)
  209188. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209189. [burn setProperties: d];
  209190. [burn writeLayout: tracks];
  209191. for (;;)
  209192. {
  209193. JUCE_NAMESPACE::Thread::sleep (300);
  209194. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209195. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209196. {
  209197. [burn abort];
  209198. *error = "User cancelled the write operation";
  209199. break;
  209200. }
  209201. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209202. {
  209203. *error = "Write operation failed";
  209204. break;
  209205. }
  209206. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209207. {
  209208. break;
  209209. }
  209210. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209211. objectForKey: DRErrorStatusErrorStringKey];
  209212. if ([err length] > 0)
  209213. {
  209214. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209215. break;
  209216. }
  209217. }
  209218. [device releaseMediaReservation];
  209219. [device releaseExclusiveAccess];
  209220. }
  209221. @end
  209222. @implementation AudioTrackProducer
  209223. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209224. {
  209225. lengthInFrames = lengthInFrames_;
  209226. readPosition = 0;
  209227. return self;
  209228. }
  209229. - (void) setupTrackProperties: (DRTrack*) track
  209230. {
  209231. NSMutableDictionary* p = [[track properties] mutableCopy];
  209232. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209233. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209234. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209235. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209236. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209237. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209238. [track setProperties: p];
  209239. [p release];
  209240. }
  209241. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209242. {
  209243. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209244. if (s != nil)
  209245. s->source = source_;
  209246. return s;
  209247. }
  209248. - (void) dealloc
  209249. {
  209250. if (source != 0)
  209251. {
  209252. source->releaseResources();
  209253. delete source;
  209254. }
  209255. [super dealloc];
  209256. }
  209257. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209258. {
  209259. }
  209260. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209261. {
  209262. return true;
  209263. }
  209264. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209265. {
  209266. return lengthInFrames;
  209267. }
  209268. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209269. toMedia: (NSDictionary*) mediaInfo
  209270. {
  209271. if (source != 0)
  209272. source->prepareToPlay (44100 / 75, 44100);
  209273. readPosition = 0;
  209274. return true;
  209275. }
  209276. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209277. {
  209278. if (source != 0)
  209279. source->prepareToPlay (44100 / 75, 44100);
  209280. return true;
  209281. }
  209282. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209283. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209284. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209285. {
  209286. if (source != 0)
  209287. {
  209288. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209289. if (numSamples > 0)
  209290. {
  209291. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209292. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209293. info.buffer = &tempBuffer;
  209294. info.startSample = 0;
  209295. info.numSamples = numSamples;
  209296. source->getNextAudioBlock (info);
  209297. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209298. buffer, numSamples, 4);
  209299. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209300. buffer + 2, numSamples, 4);
  209301. readPosition += numSamples;
  209302. }
  209303. return numSamples * 4;
  209304. }
  209305. return 0;
  209306. }
  209307. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209308. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209309. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209310. ioFlags: (uint32_t*) flags
  209311. {
  209312. zeromem (buffer, bufferLength);
  209313. return bufferLength;
  209314. }
  209315. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209316. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209317. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209318. {
  209319. return true;
  209320. }
  209321. @end
  209322. BEGIN_JUCE_NAMESPACE
  209323. class AudioCDBurner::Pimpl : public Timer
  209324. {
  209325. public:
  209326. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209327. : device (0), owner (owner_)
  209328. {
  209329. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209330. if (dev != 0)
  209331. {
  209332. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209333. lastState = getDiskState();
  209334. startTimer (1000);
  209335. }
  209336. }
  209337. ~Pimpl()
  209338. {
  209339. stopTimer();
  209340. [device release];
  209341. }
  209342. void timerCallback()
  209343. {
  209344. const DiskState state = getDiskState();
  209345. if (state != lastState)
  209346. {
  209347. lastState = state;
  209348. owner.sendChangeMessage (&owner);
  209349. }
  209350. }
  209351. DiskState getDiskState() const
  209352. {
  209353. if ([device->device isValid])
  209354. {
  209355. NSDictionary* status = [device->device status];
  209356. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209357. if ([state isEqualTo: DRDeviceMediaStateNone])
  209358. {
  209359. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209360. return trayOpen;
  209361. return noDisc;
  209362. }
  209363. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209364. {
  209365. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209366. return writableDiskPresent;
  209367. else
  209368. return readOnlyDiskPresent;
  209369. }
  209370. }
  209371. return unknown;
  209372. }
  209373. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209374. const Array<int> getAvailableWriteSpeeds() const
  209375. {
  209376. Array<int> results;
  209377. if ([device->device isValid])
  209378. {
  209379. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209380. for (unsigned int i = 0; i < [speeds count]; ++i)
  209381. {
  209382. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209383. results.add (kbPerSec / kilobytesPerSecond1x);
  209384. }
  209385. }
  209386. return results;
  209387. }
  209388. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209389. {
  209390. if ([device->device isValid])
  209391. {
  209392. device->underrunProtection = shouldBeEnabled;
  209393. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209394. }
  209395. return false;
  209396. }
  209397. int getNumAvailableAudioBlocks() const
  209398. {
  209399. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209400. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209401. }
  209402. OpenDiskDevice* device;
  209403. private:
  209404. DiskState lastState;
  209405. AudioCDBurner& owner;
  209406. };
  209407. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209408. {
  209409. pimpl = new Pimpl (*this, deviceIndex);
  209410. }
  209411. AudioCDBurner::~AudioCDBurner()
  209412. {
  209413. }
  209414. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209415. {
  209416. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209417. if (b->pimpl->device == 0)
  209418. b = 0;
  209419. return b.release();
  209420. }
  209421. static NSArray* findDiskBurnerDevices()
  209422. {
  209423. NSMutableArray* results = [NSMutableArray array];
  209424. NSArray* devs = [DRDevice devices];
  209425. if (devs != 0)
  209426. {
  209427. int num = [devs count];
  209428. int i;
  209429. for (i = 0; i < num; ++i)
  209430. {
  209431. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209432. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209433. if (name != nil)
  209434. [results addObject: name];
  209435. }
  209436. }
  209437. return results;
  209438. }
  209439. const StringArray AudioCDBurner::findAvailableDevices()
  209440. {
  209441. NSArray* names = findDiskBurnerDevices();
  209442. StringArray s;
  209443. for (unsigned int i = 0; i < [names count]; ++i)
  209444. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209445. return s;
  209446. }
  209447. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209448. {
  209449. return pimpl->getDiskState();
  209450. }
  209451. bool AudioCDBurner::isDiskPresent() const
  209452. {
  209453. return getDiskState() == writableDiskPresent;
  209454. }
  209455. bool AudioCDBurner::openTray()
  209456. {
  209457. return pimpl->openTray();
  209458. }
  209459. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209460. {
  209461. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209462. DiskState oldState = getDiskState();
  209463. DiskState newState = oldState;
  209464. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209465. {
  209466. newState = getDiskState();
  209467. Thread::sleep (100);
  209468. }
  209469. return newState;
  209470. }
  209471. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209472. {
  209473. return pimpl->getAvailableWriteSpeeds();
  209474. }
  209475. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209476. {
  209477. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209478. }
  209479. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209480. {
  209481. return pimpl->getNumAvailableAudioBlocks();
  209482. }
  209483. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209484. {
  209485. if ([pimpl->device->device isValid])
  209486. {
  209487. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209488. return true;
  209489. }
  209490. return false;
  209491. }
  209492. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209493. bool ejectDiscAfterwards,
  209494. bool performFakeBurnForTesting,
  209495. int writeSpeed)
  209496. {
  209497. String error ("Couldn't open or write to the CD device");
  209498. if ([pimpl->device->device isValid])
  209499. {
  209500. error = String::empty;
  209501. [pimpl->device burn: listener
  209502. errorString: &error
  209503. ejectAfterwards: ejectDiscAfterwards
  209504. isFake: performFakeBurnForTesting
  209505. speed: writeSpeed];
  209506. }
  209507. return error;
  209508. }
  209509. #endif
  209510. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209511. void AudioCDReader::ejectDisk()
  209512. {
  209513. const ScopedAutoReleasePool p;
  209514. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209515. }
  209516. #endif
  209517. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209518. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209519. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209520. // compiled on its own).
  209521. #if JUCE_INCLUDED_FILE
  209522. class AppDelegateRedirector
  209523. {
  209524. public:
  209525. AppDelegateRedirector()
  209526. {
  209527. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209528. runLoop = CFRunLoopGetMain();
  209529. #else
  209530. runLoop = CFRunLoopGetCurrent();
  209531. #endif
  209532. CFRunLoopSourceContext sourceContext;
  209533. zerostruct (sourceContext);
  209534. sourceContext.info = this;
  209535. sourceContext.perform = runLoopSourceCallback;
  209536. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209537. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209538. }
  209539. virtual ~AppDelegateRedirector()
  209540. {
  209541. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209542. CFRunLoopSourceInvalidate (runLoopSource);
  209543. CFRelease (runLoopSource);
  209544. while (messages.size() > 0)
  209545. delete ((Message*) messages.remove(0));
  209546. }
  209547. virtual NSApplicationTerminateReply shouldTerminate()
  209548. {
  209549. if (JUCEApplication::getInstance() != 0)
  209550. {
  209551. JUCEApplication::getInstance()->systemRequestedQuit();
  209552. return NSTerminateCancel;
  209553. }
  209554. return NSTerminateNow;
  209555. }
  209556. virtual BOOL openFile (const NSString* filename)
  209557. {
  209558. if (JUCEApplication::getInstance() != 0)
  209559. {
  209560. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209561. return YES;
  209562. }
  209563. return NO;
  209564. }
  209565. virtual void openFiles (NSArray* filenames)
  209566. {
  209567. StringArray files;
  209568. for (unsigned int i = 0; i < [filenames count]; ++i)
  209569. {
  209570. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209571. if (filename.containsChar (T(' ')))
  209572. filename = filename.quoted('"');
  209573. files.add (filename);
  209574. }
  209575. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209576. {
  209577. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209578. }
  209579. }
  209580. virtual void focusChanged()
  209581. {
  209582. juce_HandleProcessFocusChange();
  209583. }
  209584. struct CallbackMessagePayload
  209585. {
  209586. MessageCallbackFunction* function;
  209587. void* parameter;
  209588. void* volatile result;
  209589. bool volatile hasBeenExecuted;
  209590. };
  209591. virtual void performCallback (CallbackMessagePayload* pl)
  209592. {
  209593. pl->result = (*pl->function) (pl->parameter);
  209594. pl->hasBeenExecuted = true;
  209595. }
  209596. virtual void deleteSelf()
  209597. {
  209598. delete this;
  209599. }
  209600. void postMessage (void* m)
  209601. {
  209602. messages.add (m);
  209603. CFRunLoopSourceSignal (runLoopSource);
  209604. CFRunLoopWakeUp (runLoop);
  209605. }
  209606. private:
  209607. CFRunLoopRef runLoop;
  209608. CFRunLoopSourceRef runLoopSource;
  209609. Array <void*, CriticalSection> messages;
  209610. void runLoopCallback()
  209611. {
  209612. int numDispatched = 0;
  209613. do
  209614. {
  209615. void* const nextMessage = messages.remove (0);
  209616. if (nextMessage == 0)
  209617. return;
  209618. const ScopedAutoReleasePool pool;
  209619. MessageManager::getInstance()->deliverMessage (nextMessage);
  209620. } while (++numDispatched <= 4);
  209621. CFRunLoopSourceSignal (runLoopSource);
  209622. CFRunLoopWakeUp (runLoop);
  209623. }
  209624. static void runLoopSourceCallback (void* info)
  209625. {
  209626. ((AppDelegateRedirector*) info)->runLoopCallback();
  209627. }
  209628. };
  209629. END_JUCE_NAMESPACE
  209630. using namespace JUCE_NAMESPACE;
  209631. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209632. @interface JuceAppDelegate : NSObject
  209633. {
  209634. @private
  209635. id oldDelegate;
  209636. @public
  209637. AppDelegateRedirector* redirector;
  209638. }
  209639. - (JuceAppDelegate*) init;
  209640. - (void) dealloc;
  209641. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209642. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209643. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209644. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209645. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209646. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209647. - (void) performCallback: (id) info;
  209648. - (void) dummyMethod;
  209649. @end
  209650. @implementation JuceAppDelegate
  209651. - (JuceAppDelegate*) init
  209652. {
  209653. [super init];
  209654. redirector = new AppDelegateRedirector();
  209655. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209656. if (JUCEApplication::getInstance() != 0)
  209657. {
  209658. oldDelegate = [NSApp delegate];
  209659. [NSApp setDelegate: self];
  209660. }
  209661. else
  209662. {
  209663. oldDelegate = 0;
  209664. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209665. name: NSApplicationDidResignActiveNotification object: NSApp];
  209666. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209667. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209668. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209669. name: NSApplicationWillUnhideNotification object: NSApp];
  209670. }
  209671. return self;
  209672. }
  209673. - (void) dealloc
  209674. {
  209675. if (oldDelegate != 0)
  209676. [NSApp setDelegate: oldDelegate];
  209677. redirector->deleteSelf();
  209678. [super dealloc];
  209679. }
  209680. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209681. {
  209682. return redirector->shouldTerminate();
  209683. }
  209684. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209685. {
  209686. return redirector->openFile (filename);
  209687. }
  209688. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209689. {
  209690. return redirector->openFiles (filenames);
  209691. }
  209692. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209693. {
  209694. redirector->focusChanged();
  209695. }
  209696. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209697. {
  209698. redirector->focusChanged();
  209699. }
  209700. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209701. {
  209702. redirector->focusChanged();
  209703. }
  209704. - (void) performCallback: (id) info
  209705. {
  209706. if ([info isKindOfClass: [NSData class]])
  209707. {
  209708. AppDelegateRedirector::CallbackMessagePayload* pl
  209709. = (AppDelegateRedirector::CallbackMessagePayload*) [((NSData*) info) bytes];
  209710. if (pl != 0)
  209711. redirector->performCallback (pl);
  209712. }
  209713. else
  209714. {
  209715. jassertfalse // should never get here!
  209716. }
  209717. }
  209718. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209719. @end
  209720. BEGIN_JUCE_NAMESPACE
  209721. static JuceAppDelegate* juceAppDelegate = 0;
  209722. void MessageManager::runDispatchLoop()
  209723. {
  209724. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209725. {
  209726. const ScopedAutoReleasePool pool;
  209727. // must only be called by the message thread!
  209728. jassert (isThisTheMessageThread());
  209729. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209730. @try
  209731. {
  209732. [NSApp run];
  209733. }
  209734. @catch (NSException* e)
  209735. {
  209736. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209737. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209738. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209739. }
  209740. @finally
  209741. {
  209742. }
  209743. #else
  209744. [NSApp run];
  209745. #endif
  209746. }
  209747. }
  209748. void MessageManager::stopDispatchLoop()
  209749. {
  209750. quitMessagePosted = true;
  209751. [NSApp stop: nil];
  209752. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209753. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209754. }
  209755. static bool isEventBlockedByModalComps (NSEvent* e)
  209756. {
  209757. if (Component::getNumCurrentlyModalComponents() == 0)
  209758. return false;
  209759. NSWindow* const w = [e window];
  209760. if (w == 0 || [w worksWhenModal])
  209761. return false;
  209762. bool isKey = false, isInputAttempt = false;
  209763. switch ([e type])
  209764. {
  209765. case NSKeyDown:
  209766. case NSKeyUp:
  209767. isKey = isInputAttempt = true;
  209768. break;
  209769. case NSLeftMouseDown:
  209770. case NSRightMouseDown:
  209771. case NSOtherMouseDown:
  209772. isInputAttempt = true;
  209773. break;
  209774. case NSLeftMouseDragged:
  209775. case NSRightMouseDragged:
  209776. case NSLeftMouseUp:
  209777. case NSRightMouseUp:
  209778. case NSOtherMouseUp:
  209779. case NSOtherMouseDragged:
  209780. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  209781. return false;
  209782. break;
  209783. case NSMouseMoved:
  209784. case NSMouseEntered:
  209785. case NSMouseExited:
  209786. case NSCursorUpdate:
  209787. case NSScrollWheel:
  209788. case NSTabletPoint:
  209789. case NSTabletProximity:
  209790. break;
  209791. default:
  209792. return false;
  209793. }
  209794. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209795. {
  209796. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209797. NSView* const compView = (NSView*) peer->getNativeHandle();
  209798. if ([compView window] == w)
  209799. {
  209800. if (isKey)
  209801. {
  209802. if (compView == [w firstResponder])
  209803. return false;
  209804. }
  209805. else
  209806. {
  209807. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209808. [compView bounds]))
  209809. return false;
  209810. }
  209811. }
  209812. }
  209813. if (isInputAttempt)
  209814. {
  209815. if (! [NSApp isActive])
  209816. [NSApp activateIgnoringOtherApps: YES];
  209817. Component* const modal = Component::getCurrentlyModalComponent (0);
  209818. if (modal != 0)
  209819. modal->inputAttemptWhenModal();
  209820. }
  209821. return true;
  209822. }
  209823. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  209824. {
  209825. const ScopedAutoReleasePool pool;
  209826. jassert (isThisTheMessageThread()); // must only be called by the message thread
  209827. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  209828. while (! quitMessagePosted)
  209829. {
  209830. const ScopedAutoReleasePool pool2;
  209831. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  209832. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  209833. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  209834. inMode: NSDefaultRunLoopMode
  209835. dequeue: YES];
  209836. if (e != 0 && ! isEventBlockedByModalComps (e))
  209837. [NSApp sendEvent: e];
  209838. if (Time::getMillisecondCounter() >= endTime)
  209839. break;
  209840. }
  209841. return ! quitMessagePosted;
  209842. }
  209843. void MessageManager::doPlatformSpecificInitialisation()
  209844. {
  209845. if (juceAppDelegate == 0)
  209846. juceAppDelegate = [[JuceAppDelegate alloc] init];
  209847. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  209848. // correctly (needed prior to 10.5)
  209849. if (! [NSThread isMultiThreaded])
  209850. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  209851. toTarget: juceAppDelegate
  209852. withObject: nil];
  209853. initialiseMainMenu();
  209854. }
  209855. void MessageManager::doPlatformSpecificShutdown()
  209856. {
  209857. if (juceAppDelegate != 0)
  209858. {
  209859. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  209860. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  209861. [juceAppDelegate release];
  209862. juceAppDelegate = 0;
  209863. }
  209864. }
  209865. bool juce_postMessageToSystemQueue (void* message)
  209866. {
  209867. juceAppDelegate->redirector->postMessage (message);
  209868. return true;
  209869. }
  209870. void MessageManager::broadcastMessage (const String& value) throw()
  209871. {
  209872. }
  209873. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  209874. void* data)
  209875. {
  209876. if (isThisTheMessageThread())
  209877. {
  209878. return (*callback) (data);
  209879. }
  209880. else
  209881. {
  209882. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  209883. // deadlock because the message manager is blocked from running, so can never
  209884. // call your function..
  209885. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  209886. const ScopedAutoReleasePool pool;
  209887. AppDelegateRedirector::CallbackMessagePayload cmp;
  209888. cmp.function = callback;
  209889. cmp.parameter = data;
  209890. cmp.result = 0;
  209891. cmp.hasBeenExecuted = false;
  209892. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  209893. withObject: [NSData dataWithBytesNoCopy: &cmp
  209894. length: sizeof (cmp)
  209895. freeWhenDone: NO]
  209896. waitUntilDone: YES];
  209897. return cmp.result;
  209898. }
  209899. }
  209900. #endif
  209901. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  209902. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  209903. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209904. // compiled on its own).
  209905. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  209906. #if JUCE_MAC
  209907. END_JUCE_NAMESPACE
  209908. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  209909. @interface DownloadClickDetector : NSObject
  209910. {
  209911. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  209912. }
  209913. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  209914. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209915. request: (NSURLRequest*) request
  209916. frame: (WebFrame*) frame
  209917. decisionListener: (id<WebPolicyDecisionListener>) listener;
  209918. @end
  209919. @implementation DownloadClickDetector
  209920. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  209921. {
  209922. [super init];
  209923. ownerComponent = ownerComponent_;
  209924. return self;
  209925. }
  209926. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209927. request: (NSURLRequest*) request
  209928. frame: (WebFrame*) frame
  209929. decisionListener: (id <WebPolicyDecisionListener>) listener
  209930. {
  209931. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  209932. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  209933. [listener use];
  209934. else
  209935. [listener ignore];
  209936. }
  209937. @end
  209938. BEGIN_JUCE_NAMESPACE
  209939. class WebBrowserComponentInternal : public NSViewComponent
  209940. {
  209941. public:
  209942. WebBrowserComponentInternal (WebBrowserComponent* owner)
  209943. {
  209944. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  209945. frameName: @""
  209946. groupName: @""];
  209947. setView (webView);
  209948. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  209949. [webView setPolicyDelegate: clickListener];
  209950. }
  209951. ~WebBrowserComponentInternal()
  209952. {
  209953. [webView setPolicyDelegate: nil];
  209954. [clickListener release];
  209955. setView (0);
  209956. }
  209957. void goToURL (const String& url,
  209958. const StringArray* headers,
  209959. const MemoryBlock* postData)
  209960. {
  209961. NSMutableURLRequest* r
  209962. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  209963. cachePolicy: NSURLRequestUseProtocolCachePolicy
  209964. timeoutInterval: 30.0];
  209965. if (postData != 0 && postData->getSize() > 0)
  209966. {
  209967. [r setHTTPMethod: @"POST"];
  209968. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  209969. length: postData->getSize()]];
  209970. }
  209971. if (headers != 0)
  209972. {
  209973. for (int i = 0; i < headers->size(); ++i)
  209974. {
  209975. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  209976. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  209977. [r setValue: juceStringToNS (headerValue)
  209978. forHTTPHeaderField: juceStringToNS (headerName)];
  209979. }
  209980. }
  209981. stop();
  209982. [[webView mainFrame] loadRequest: r];
  209983. }
  209984. void goBack()
  209985. {
  209986. [webView goBack];
  209987. }
  209988. void goForward()
  209989. {
  209990. [webView goForward];
  209991. }
  209992. void stop()
  209993. {
  209994. [webView stopLoading: nil];
  209995. }
  209996. void refresh()
  209997. {
  209998. [webView reload: nil];
  209999. }
  210000. private:
  210001. WebView* webView;
  210002. DownloadClickDetector* clickListener;
  210003. };
  210004. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210005. : browser (0),
  210006. blankPageShown (false),
  210007. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210008. {
  210009. setOpaque (true);
  210010. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210011. }
  210012. WebBrowserComponent::~WebBrowserComponent()
  210013. {
  210014. deleteAndZero (browser);
  210015. }
  210016. void WebBrowserComponent::goToURL (const String& url,
  210017. const StringArray* headers,
  210018. const MemoryBlock* postData)
  210019. {
  210020. lastURL = url;
  210021. lastHeaders.clear();
  210022. if (headers != 0)
  210023. lastHeaders = *headers;
  210024. lastPostData.setSize (0);
  210025. if (postData != 0)
  210026. lastPostData = *postData;
  210027. blankPageShown = false;
  210028. browser->goToURL (url, headers, postData);
  210029. }
  210030. void WebBrowserComponent::stop()
  210031. {
  210032. browser->stop();
  210033. }
  210034. void WebBrowserComponent::goBack()
  210035. {
  210036. lastURL = String::empty;
  210037. blankPageShown = false;
  210038. browser->goBack();
  210039. }
  210040. void WebBrowserComponent::goForward()
  210041. {
  210042. lastURL = String::empty;
  210043. browser->goForward();
  210044. }
  210045. void WebBrowserComponent::refresh()
  210046. {
  210047. browser->refresh();
  210048. }
  210049. void WebBrowserComponent::paint (Graphics& g)
  210050. {
  210051. }
  210052. void WebBrowserComponent::checkWindowAssociation()
  210053. {
  210054. if (isShowing())
  210055. {
  210056. if (blankPageShown)
  210057. goBack();
  210058. }
  210059. else
  210060. {
  210061. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210062. {
  210063. // when the component becomes invisible, some stuff like flash
  210064. // carries on playing audio, so we need to force it onto a blank
  210065. // page to avoid this, (and send it back when it's made visible again).
  210066. blankPageShown = true;
  210067. browser->goToURL ("about:blank", 0, 0);
  210068. }
  210069. }
  210070. }
  210071. void WebBrowserComponent::reloadLastURL()
  210072. {
  210073. if (lastURL.isNotEmpty())
  210074. {
  210075. goToURL (lastURL, &lastHeaders, &lastPostData);
  210076. lastURL = String::empty;
  210077. }
  210078. }
  210079. void WebBrowserComponent::parentHierarchyChanged()
  210080. {
  210081. checkWindowAssociation();
  210082. }
  210083. void WebBrowserComponent::resized()
  210084. {
  210085. browser->setSize (getWidth(), getHeight());
  210086. }
  210087. void WebBrowserComponent::visibilityChanged()
  210088. {
  210089. checkWindowAssociation();
  210090. }
  210091. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210092. {
  210093. return true;
  210094. }
  210095. #else
  210096. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210097. {
  210098. }
  210099. WebBrowserComponent::~WebBrowserComponent()
  210100. {
  210101. }
  210102. void WebBrowserComponent::goToURL (const String& url,
  210103. const StringArray* headers,
  210104. const MemoryBlock* postData)
  210105. {
  210106. }
  210107. void WebBrowserComponent::stop()
  210108. {
  210109. }
  210110. void WebBrowserComponent::goBack()
  210111. {
  210112. }
  210113. void WebBrowserComponent::goForward()
  210114. {
  210115. }
  210116. void WebBrowserComponent::refresh()
  210117. {
  210118. }
  210119. void WebBrowserComponent::paint (Graphics& g)
  210120. {
  210121. }
  210122. void WebBrowserComponent::checkWindowAssociation()
  210123. {
  210124. }
  210125. void WebBrowserComponent::reloadLastURL()
  210126. {
  210127. }
  210128. void WebBrowserComponent::parentHierarchyChanged()
  210129. {
  210130. }
  210131. void WebBrowserComponent::resized()
  210132. {
  210133. }
  210134. void WebBrowserComponent::visibilityChanged()
  210135. {
  210136. }
  210137. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210138. {
  210139. return true;
  210140. }
  210141. #endif
  210142. #endif
  210143. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210144. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210145. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210146. // compiled on its own).
  210147. #if JUCE_INCLUDED_FILE
  210148. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210149. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210150. #endif
  210151. #undef log
  210152. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210153. #define log(a) Logger::writeToLog (a)
  210154. #else
  210155. #define log(a)
  210156. #endif
  210157. #undef OK
  210158. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210159. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210160. {
  210161. if (err == noErr)
  210162. return true;
  210163. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210164. jassertfalse
  210165. return false;
  210166. }
  210167. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210168. #else
  210169. #define OK(a) (a == noErr)
  210170. #endif
  210171. class CoreAudioInternal : public Timer
  210172. {
  210173. public:
  210174. CoreAudioInternal (AudioDeviceID id)
  210175. : inputLatency (0),
  210176. outputLatency (0),
  210177. callback (0),
  210178. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210179. audioProcID (0),
  210180. #endif
  210181. inputDevice (0),
  210182. isSlaveDevice (false),
  210183. deviceID (id),
  210184. started (false),
  210185. sampleRate (0),
  210186. bufferSize (512),
  210187. numInputChans (0),
  210188. numOutputChans (0),
  210189. callbacksAllowed (true),
  210190. numInputChannelInfos (0),
  210191. numOutputChannelInfos (0)
  210192. {
  210193. jassert (deviceID != 0);
  210194. updateDetailsFromDevice();
  210195. AudioObjectPropertyAddress pa;
  210196. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210197. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210198. pa.mElement = kAudioObjectPropertyElementWildcard;
  210199. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210200. }
  210201. ~CoreAudioInternal()
  210202. {
  210203. AudioObjectPropertyAddress pa;
  210204. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210205. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210206. pa.mElement = kAudioObjectPropertyElementWildcard;
  210207. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210208. stop (false);
  210209. delete inputDevice;
  210210. }
  210211. void allocateTempBuffers()
  210212. {
  210213. const int tempBufSize = bufferSize + 4;
  210214. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210215. tempInputBuffers.calloc (numInputChans + 2);
  210216. tempOutputBuffers.calloc (numOutputChans + 2);
  210217. int i, count = 0;
  210218. for (i = 0; i < numInputChans; ++i)
  210219. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210220. for (i = 0; i < numOutputChans; ++i)
  210221. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210222. }
  210223. // returns the number of actual available channels
  210224. void fillInChannelInfo (const bool input)
  210225. {
  210226. int chanNum = 0;
  210227. UInt32 size;
  210228. AudioObjectPropertyAddress pa;
  210229. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210230. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210231. pa.mElement = kAudioObjectPropertyElementMaster;
  210232. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210233. {
  210234. HeapBlock <AudioBufferList> bufList;
  210235. bufList.calloc (size, 1);
  210236. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210237. {
  210238. const int numStreams = bufList->mNumberBuffers;
  210239. for (int i = 0; i < numStreams; ++i)
  210240. {
  210241. const AudioBuffer& b = bufList->mBuffers[i];
  210242. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210243. {
  210244. String name;
  210245. {
  210246. char channelName [256];
  210247. zerostruct (channelName);
  210248. UInt32 nameSize = sizeof (channelName);
  210249. UInt32 channelNum = chanNum + 1;
  210250. pa.mSelector = kAudioDevicePropertyChannelName;
  210251. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210252. name = String::fromUTF8 (channelName, nameSize);
  210253. }
  210254. if (input)
  210255. {
  210256. if (activeInputChans[chanNum])
  210257. {
  210258. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210259. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210260. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210261. ++numInputChannelInfos;
  210262. }
  210263. if (name.isEmpty())
  210264. name << "Input " << (chanNum + 1);
  210265. inChanNames.add (name);
  210266. }
  210267. else
  210268. {
  210269. if (activeOutputChans[chanNum])
  210270. {
  210271. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210272. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210273. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210274. ++numOutputChannelInfos;
  210275. }
  210276. if (name.isEmpty())
  210277. name << "Output " << (chanNum + 1);
  210278. outChanNames.add (name);
  210279. }
  210280. ++chanNum;
  210281. }
  210282. }
  210283. }
  210284. }
  210285. }
  210286. void updateDetailsFromDevice()
  210287. {
  210288. stopTimer();
  210289. if (deviceID == 0)
  210290. return;
  210291. const ScopedLock sl (callbackLock);
  210292. Float64 sr;
  210293. UInt32 size = sizeof (Float64);
  210294. AudioObjectPropertyAddress pa;
  210295. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210296. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210297. pa.mElement = kAudioObjectPropertyElementMaster;
  210298. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210299. sampleRate = sr;
  210300. UInt32 framesPerBuf;
  210301. size = sizeof (framesPerBuf);
  210302. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210303. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210304. {
  210305. bufferSize = framesPerBuf;
  210306. allocateTempBuffers();
  210307. }
  210308. bufferSizes.clear();
  210309. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210310. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210311. {
  210312. HeapBlock <AudioValueRange> ranges;
  210313. ranges.calloc (size, 1);
  210314. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210315. {
  210316. bufferSizes.add ((int) ranges[0].mMinimum);
  210317. for (int i = 32; i < 2048; i += 32)
  210318. {
  210319. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210320. {
  210321. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210322. {
  210323. bufferSizes.addIfNotAlreadyThere (i);
  210324. break;
  210325. }
  210326. }
  210327. }
  210328. if (bufferSize > 0)
  210329. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210330. }
  210331. }
  210332. if (bufferSizes.size() == 0 && bufferSize > 0)
  210333. bufferSizes.add (bufferSize);
  210334. sampleRates.clear();
  210335. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210336. String rates;
  210337. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210338. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210339. {
  210340. HeapBlock <AudioValueRange> ranges;
  210341. ranges.calloc (size, 1);
  210342. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210343. {
  210344. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210345. {
  210346. bool ok = false;
  210347. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210348. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210349. ok = true;
  210350. if (ok)
  210351. {
  210352. sampleRates.add (possibleRates[i]);
  210353. rates << possibleRates[i] << T(" ");
  210354. }
  210355. }
  210356. }
  210357. }
  210358. if (sampleRates.size() == 0 && sampleRate > 0)
  210359. {
  210360. sampleRates.add (sampleRate);
  210361. rates << sampleRate;
  210362. }
  210363. log (T("sr: ") + rates);
  210364. inputLatency = 0;
  210365. outputLatency = 0;
  210366. UInt32 lat;
  210367. size = sizeof (lat);
  210368. pa.mSelector = kAudioDevicePropertyLatency;
  210369. pa.mScope = kAudioDevicePropertyScopeInput;
  210370. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210371. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210372. inputLatency = (int) lat;
  210373. pa.mScope = kAudioDevicePropertyScopeOutput;
  210374. size = sizeof (lat);
  210375. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210376. outputLatency = (int) lat;
  210377. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210378. inChanNames.clear();
  210379. outChanNames.clear();
  210380. inputChannelInfo.calloc (numInputChans + 2);
  210381. numInputChannelInfos = 0;
  210382. outputChannelInfo.calloc (numOutputChans + 2);
  210383. numOutputChannelInfos = 0;
  210384. fillInChannelInfo (true);
  210385. fillInChannelInfo (false);
  210386. }
  210387. const StringArray getSources (bool input)
  210388. {
  210389. StringArray s;
  210390. HeapBlock <OSType> types;
  210391. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210392. for (int i = 0; i < num; ++i)
  210393. {
  210394. AudioValueTranslation avt;
  210395. char buffer[256];
  210396. avt.mInputData = (void*) &(types[i]);
  210397. avt.mInputDataSize = sizeof (UInt32);
  210398. avt.mOutputData = buffer;
  210399. avt.mOutputDataSize = 256;
  210400. UInt32 transSize = sizeof (avt);
  210401. AudioObjectPropertyAddress pa;
  210402. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210403. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210404. pa.mElement = kAudioObjectPropertyElementMaster;
  210405. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210406. {
  210407. DBG (buffer);
  210408. s.add (buffer);
  210409. }
  210410. }
  210411. return s;
  210412. }
  210413. int getCurrentSourceIndex (bool input) const
  210414. {
  210415. OSType currentSourceID = 0;
  210416. UInt32 size = sizeof (currentSourceID);
  210417. int result = -1;
  210418. AudioObjectPropertyAddress pa;
  210419. pa.mSelector = kAudioDevicePropertyDataSource;
  210420. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210421. pa.mElement = kAudioObjectPropertyElementMaster;
  210422. if (deviceID != 0)
  210423. {
  210424. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210425. {
  210426. HeapBlock <OSType> types;
  210427. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210428. for (int i = 0; i < num; ++i)
  210429. {
  210430. if (types[num] == currentSourceID)
  210431. {
  210432. result = i;
  210433. break;
  210434. }
  210435. }
  210436. }
  210437. }
  210438. return result;
  210439. }
  210440. void setCurrentSourceIndex (int index, bool input)
  210441. {
  210442. if (deviceID != 0)
  210443. {
  210444. HeapBlock <OSType> types;
  210445. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210446. if (((unsigned int) index) < (unsigned int) num)
  210447. {
  210448. AudioObjectPropertyAddress pa;
  210449. pa.mSelector = kAudioDevicePropertyDataSource;
  210450. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210451. pa.mElement = kAudioObjectPropertyElementMaster;
  210452. OSType typeId = types[index];
  210453. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210454. }
  210455. }
  210456. }
  210457. const String reopen (const BitArray& inputChannels,
  210458. const BitArray& outputChannels,
  210459. double newSampleRate,
  210460. int bufferSizeSamples)
  210461. {
  210462. String error;
  210463. log ("CoreAudio reopen");
  210464. callbacksAllowed = false;
  210465. stopTimer();
  210466. stop (false);
  210467. activeInputChans = inputChannels;
  210468. activeInputChans.setRange (inChanNames.size(),
  210469. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210470. false);
  210471. activeOutputChans = outputChannels;
  210472. activeOutputChans.setRange (outChanNames.size(),
  210473. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210474. false);
  210475. numInputChans = activeInputChans.countNumberOfSetBits();
  210476. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210477. // set sample rate
  210478. AudioObjectPropertyAddress pa;
  210479. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210480. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210481. pa.mElement = kAudioObjectPropertyElementMaster;
  210482. Float64 sr = newSampleRate;
  210483. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210484. {
  210485. error = "Couldn't change sample rate";
  210486. }
  210487. else
  210488. {
  210489. // change buffer size
  210490. UInt32 framesPerBuf = bufferSizeSamples;
  210491. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210492. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210493. {
  210494. error = "Couldn't change buffer size";
  210495. }
  210496. else
  210497. {
  210498. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210499. // correctly report their new settings until some random time in the future, so
  210500. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210501. // to make sure we're using the correct numbers..
  210502. updateDetailsFromDevice();
  210503. sampleRate = newSampleRate;
  210504. bufferSize = bufferSizeSamples;
  210505. if (sampleRates.size() == 0)
  210506. error = "Device has no available sample-rates";
  210507. else if (bufferSizes.size() == 0)
  210508. error = "Device has no available buffer-sizes";
  210509. else if (inputDevice != 0)
  210510. error = inputDevice->reopen (inputChannels,
  210511. outputChannels,
  210512. newSampleRate,
  210513. bufferSizeSamples);
  210514. }
  210515. }
  210516. callbacksAllowed = true;
  210517. return error;
  210518. }
  210519. bool start (AudioIODeviceCallback* cb)
  210520. {
  210521. if (! started)
  210522. {
  210523. callback = 0;
  210524. if (deviceID != 0)
  210525. {
  210526. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210527. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210528. #else
  210529. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210530. #endif
  210531. {
  210532. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210533. {
  210534. started = true;
  210535. }
  210536. else
  210537. {
  210538. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210539. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210540. #else
  210541. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210542. audioProcID = 0;
  210543. #endif
  210544. }
  210545. }
  210546. }
  210547. }
  210548. if (started)
  210549. {
  210550. const ScopedLock sl (callbackLock);
  210551. callback = cb;
  210552. }
  210553. if (inputDevice != 0)
  210554. return started && inputDevice->start (cb);
  210555. else
  210556. return started;
  210557. }
  210558. void stop (bool leaveInterruptRunning)
  210559. {
  210560. {
  210561. const ScopedLock sl (callbackLock);
  210562. callback = 0;
  210563. }
  210564. if (started
  210565. && (deviceID != 0)
  210566. && ! leaveInterruptRunning)
  210567. {
  210568. OK (AudioDeviceStop (deviceID, audioIOProc));
  210569. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210570. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210571. #else
  210572. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210573. audioProcID = 0;
  210574. #endif
  210575. started = false;
  210576. { const ScopedLock sl (callbackLock); }
  210577. // wait until it's definately stopped calling back..
  210578. for (int i = 40; --i >= 0;)
  210579. {
  210580. Thread::sleep (50);
  210581. UInt32 running = 0;
  210582. UInt32 size = sizeof (running);
  210583. AudioObjectPropertyAddress pa;
  210584. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210585. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210586. pa.mElement = kAudioObjectPropertyElementMaster;
  210587. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210588. if (running == 0)
  210589. break;
  210590. }
  210591. const ScopedLock sl (callbackLock);
  210592. }
  210593. if (inputDevice != 0)
  210594. inputDevice->stop (leaveInterruptRunning);
  210595. }
  210596. double getSampleRate() const
  210597. {
  210598. return sampleRate;
  210599. }
  210600. int getBufferSize() const
  210601. {
  210602. return bufferSize;
  210603. }
  210604. void audioCallback (const AudioBufferList* inInputData,
  210605. AudioBufferList* outOutputData)
  210606. {
  210607. int i;
  210608. const ScopedLock sl (callbackLock);
  210609. if (callback != 0)
  210610. {
  210611. if (inputDevice == 0)
  210612. {
  210613. for (i = numInputChans; --i >= 0;)
  210614. {
  210615. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210616. float* dest = tempInputBuffers [i];
  210617. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210618. + info.dataOffsetSamples;
  210619. const int stride = info.dataStrideSamples;
  210620. if (stride != 0) // if this is zero, info is invalid
  210621. {
  210622. for (int j = bufferSize; --j >= 0;)
  210623. {
  210624. *dest++ = *src;
  210625. src += stride;
  210626. }
  210627. }
  210628. }
  210629. }
  210630. if (! isSlaveDevice)
  210631. {
  210632. if (inputDevice == 0)
  210633. {
  210634. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210635. numInputChans,
  210636. tempOutputBuffers,
  210637. numOutputChans,
  210638. bufferSize);
  210639. }
  210640. else
  210641. {
  210642. jassert (inputDevice->bufferSize == bufferSize);
  210643. // Sometimes the two linked devices seem to get their callbacks in
  210644. // parallel, so we need to lock both devices to stop the input data being
  210645. // changed while inside our callback..
  210646. const ScopedLock sl2 (inputDevice->callbackLock);
  210647. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210648. inputDevice->numInputChans,
  210649. tempOutputBuffers,
  210650. numOutputChans,
  210651. bufferSize);
  210652. }
  210653. for (i = numOutputChans; --i >= 0;)
  210654. {
  210655. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210656. const float* src = tempOutputBuffers [i];
  210657. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210658. + info.dataOffsetSamples;
  210659. const int stride = info.dataStrideSamples;
  210660. if (stride != 0) // if this is zero, info is invalid
  210661. {
  210662. for (int j = bufferSize; --j >= 0;)
  210663. {
  210664. *dest = *src++;
  210665. dest += stride;
  210666. }
  210667. }
  210668. }
  210669. }
  210670. }
  210671. else
  210672. {
  210673. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210674. {
  210675. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210676. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210677. + info.dataOffsetSamples;
  210678. const int stride = info.dataStrideSamples;
  210679. if (stride != 0) // if this is zero, info is invalid
  210680. {
  210681. for (int j = bufferSize; --j >= 0;)
  210682. {
  210683. *dest = 0.0f;
  210684. dest += stride;
  210685. }
  210686. }
  210687. }
  210688. }
  210689. }
  210690. // called by callbacks
  210691. void deviceDetailsChanged()
  210692. {
  210693. if (callbacksAllowed)
  210694. startTimer (100);
  210695. }
  210696. void timerCallback()
  210697. {
  210698. stopTimer();
  210699. log ("CoreAudio device changed callback");
  210700. const double oldSampleRate = sampleRate;
  210701. const int oldBufferSize = bufferSize;
  210702. updateDetailsFromDevice();
  210703. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210704. {
  210705. callbacksAllowed = false;
  210706. stop (false);
  210707. updateDetailsFromDevice();
  210708. callbacksAllowed = true;
  210709. }
  210710. }
  210711. CoreAudioInternal* getRelatedDevice() const
  210712. {
  210713. UInt32 size = 0;
  210714. ScopedPointer <CoreAudioInternal> result;
  210715. AudioObjectPropertyAddress pa;
  210716. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210717. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210718. pa.mElement = kAudioObjectPropertyElementMaster;
  210719. if (deviceID != 0
  210720. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210721. && size > 0)
  210722. {
  210723. HeapBlock <AudioDeviceID> devs;
  210724. devs.calloc (size, 1);
  210725. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210726. {
  210727. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210728. {
  210729. if (devs[i] != deviceID && devs[i] != 0)
  210730. {
  210731. result = new CoreAudioInternal (devs[i]);
  210732. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210733. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210734. if (thisIsInput != otherIsInput
  210735. || (inChanNames.size() + outChanNames.size() == 0)
  210736. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210737. break;
  210738. result = 0;
  210739. }
  210740. }
  210741. }
  210742. }
  210743. return result.release();
  210744. }
  210745. juce_UseDebuggingNewOperator
  210746. int inputLatency, outputLatency;
  210747. BitArray activeInputChans, activeOutputChans;
  210748. StringArray inChanNames, outChanNames;
  210749. Array <double> sampleRates;
  210750. Array <int> bufferSizes;
  210751. AudioIODeviceCallback* callback;
  210752. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210753. AudioDeviceIOProcID audioProcID;
  210754. #endif
  210755. CoreAudioInternal* inputDevice;
  210756. bool isSlaveDevice;
  210757. private:
  210758. CriticalSection callbackLock;
  210759. AudioDeviceID deviceID;
  210760. bool started;
  210761. double sampleRate;
  210762. int bufferSize;
  210763. HeapBlock <float> audioBuffer;
  210764. int numInputChans, numOutputChans;
  210765. bool callbacksAllowed;
  210766. struct CallbackDetailsForChannel
  210767. {
  210768. int streamNum;
  210769. int dataOffsetSamples;
  210770. int dataStrideSamples;
  210771. };
  210772. int numInputChannelInfos, numOutputChannelInfos;
  210773. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210774. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210775. CoreAudioInternal (const CoreAudioInternal&);
  210776. CoreAudioInternal& operator= (const CoreAudioInternal&);
  210777. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210778. const AudioTimeStamp* inNow,
  210779. const AudioBufferList* inInputData,
  210780. const AudioTimeStamp* inInputTime,
  210781. AudioBufferList* outOutputData,
  210782. const AudioTimeStamp* inOutputTime,
  210783. void* device)
  210784. {
  210785. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210786. return noErr;
  210787. }
  210788. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210789. {
  210790. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210791. switch (pa->mSelector)
  210792. {
  210793. case kAudioDevicePropertyBufferSize:
  210794. case kAudioDevicePropertyBufferFrameSize:
  210795. case kAudioDevicePropertyNominalSampleRate:
  210796. case kAudioDevicePropertyStreamFormat:
  210797. case kAudioDevicePropertyDeviceIsAlive:
  210798. intern->deviceDetailsChanged();
  210799. break;
  210800. case kAudioDevicePropertyBufferSizeRange:
  210801. case kAudioDevicePropertyVolumeScalar:
  210802. case kAudioDevicePropertyMute:
  210803. case kAudioDevicePropertyPlayThru:
  210804. case kAudioDevicePropertyDataSource:
  210805. case kAudioDevicePropertyDeviceIsRunning:
  210806. break;
  210807. }
  210808. return noErr;
  210809. }
  210810. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210811. {
  210812. AudioObjectPropertyAddress pa;
  210813. pa.mSelector = kAudioDevicePropertyDataSources;
  210814. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210815. pa.mElement = kAudioObjectPropertyElementMaster;
  210816. UInt32 size = 0;
  210817. if (deviceID != 0
  210818. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210819. {
  210820. types.calloc (size, 1);
  210821. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  210822. return size / (int) sizeof (OSType);
  210823. }
  210824. return 0;
  210825. }
  210826. };
  210827. class CoreAudioIODevice : public AudioIODevice
  210828. {
  210829. public:
  210830. CoreAudioIODevice (const String& deviceName,
  210831. AudioDeviceID inputDeviceId,
  210832. const int inputIndex_,
  210833. AudioDeviceID outputDeviceId,
  210834. const int outputIndex_)
  210835. : AudioIODevice (deviceName, "CoreAudio"),
  210836. inputIndex (inputIndex_),
  210837. outputIndex (outputIndex_),
  210838. isOpen_ (false),
  210839. isStarted (false)
  210840. {
  210841. internal = 0;
  210842. CoreAudioInternal* device = 0;
  210843. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  210844. {
  210845. jassert (inputDeviceId != 0);
  210846. device = new CoreAudioInternal (inputDeviceId);
  210847. }
  210848. else
  210849. {
  210850. device = new CoreAudioInternal (outputDeviceId);
  210851. if (inputDeviceId != 0)
  210852. {
  210853. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  210854. device->inputDevice = secondDevice;
  210855. secondDevice->isSlaveDevice = true;
  210856. }
  210857. }
  210858. internal = device;
  210859. AudioObjectPropertyAddress pa;
  210860. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210861. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210862. pa.mElement = kAudioObjectPropertyElementWildcard;
  210863. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210864. }
  210865. ~CoreAudioIODevice()
  210866. {
  210867. AudioObjectPropertyAddress pa;
  210868. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210869. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210870. pa.mElement = kAudioObjectPropertyElementWildcard;
  210871. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210872. delete internal;
  210873. }
  210874. const StringArray getOutputChannelNames()
  210875. {
  210876. return internal->outChanNames;
  210877. }
  210878. const StringArray getInputChannelNames()
  210879. {
  210880. if (internal->inputDevice != 0)
  210881. return internal->inputDevice->inChanNames;
  210882. else
  210883. return internal->inChanNames;
  210884. }
  210885. int getNumSampleRates()
  210886. {
  210887. return internal->sampleRates.size();
  210888. }
  210889. double getSampleRate (int index)
  210890. {
  210891. return internal->sampleRates [index];
  210892. }
  210893. int getNumBufferSizesAvailable()
  210894. {
  210895. return internal->bufferSizes.size();
  210896. }
  210897. int getBufferSizeSamples (int index)
  210898. {
  210899. return internal->bufferSizes [index];
  210900. }
  210901. int getDefaultBufferSize()
  210902. {
  210903. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  210904. if (getBufferSizeSamples(i) >= 512)
  210905. return getBufferSizeSamples(i);
  210906. return 512;
  210907. }
  210908. const String open (const BitArray& inputChannels,
  210909. const BitArray& outputChannels,
  210910. double sampleRate,
  210911. int bufferSizeSamples)
  210912. {
  210913. isOpen_ = true;
  210914. if (bufferSizeSamples <= 0)
  210915. bufferSizeSamples = getDefaultBufferSize();
  210916. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  210917. isOpen_ = lastError.isEmpty();
  210918. return lastError;
  210919. }
  210920. void close()
  210921. {
  210922. isOpen_ = false;
  210923. internal->stop (false);
  210924. }
  210925. bool isOpen()
  210926. {
  210927. return isOpen_;
  210928. }
  210929. int getCurrentBufferSizeSamples()
  210930. {
  210931. return internal != 0 ? internal->getBufferSize() : 512;
  210932. }
  210933. double getCurrentSampleRate()
  210934. {
  210935. return internal != 0 ? internal->getSampleRate() : 0;
  210936. }
  210937. int getCurrentBitDepth()
  210938. {
  210939. return 32; // no way to find out, so just assume it's high..
  210940. }
  210941. const BitArray getActiveOutputChannels() const
  210942. {
  210943. return internal != 0 ? internal->activeOutputChans : BitArray();
  210944. }
  210945. const BitArray getActiveInputChannels() const
  210946. {
  210947. BitArray chans;
  210948. if (internal != 0)
  210949. {
  210950. chans = internal->activeInputChans;
  210951. if (internal->inputDevice != 0)
  210952. chans.orWith (internal->inputDevice->activeInputChans);
  210953. }
  210954. return chans;
  210955. }
  210956. int getOutputLatencyInSamples()
  210957. {
  210958. if (internal == 0)
  210959. return 0;
  210960. // this seems like a good guess at getting the latency right - comparing
  210961. // this with a round-trip measurement, it gets it to within a few millisecs
  210962. // for the built-in mac soundcard
  210963. return internal->outputLatency + internal->getBufferSize() * 2;
  210964. }
  210965. int getInputLatencyInSamples()
  210966. {
  210967. if (internal == 0)
  210968. return 0;
  210969. return internal->inputLatency + internal->getBufferSize() * 2;
  210970. }
  210971. void start (AudioIODeviceCallback* callback)
  210972. {
  210973. if (internal != 0 && ! isStarted)
  210974. {
  210975. if (callback != 0)
  210976. callback->audioDeviceAboutToStart (this);
  210977. isStarted = true;
  210978. internal->start (callback);
  210979. }
  210980. }
  210981. void stop()
  210982. {
  210983. if (isStarted && internal != 0)
  210984. {
  210985. AudioIODeviceCallback* const lastCallback = internal->callback;
  210986. isStarted = false;
  210987. internal->stop (true);
  210988. if (lastCallback != 0)
  210989. lastCallback->audioDeviceStopped();
  210990. }
  210991. }
  210992. bool isPlaying()
  210993. {
  210994. if (internal->callback == 0)
  210995. isStarted = false;
  210996. return isStarted;
  210997. }
  210998. const String getLastError()
  210999. {
  211000. return lastError;
  211001. }
  211002. int inputIndex, outputIndex;
  211003. juce_UseDebuggingNewOperator
  211004. private:
  211005. CoreAudioInternal* internal;
  211006. bool isOpen_, isStarted;
  211007. String lastError;
  211008. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211009. {
  211010. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211011. switch (pa->mSelector)
  211012. {
  211013. case kAudioHardwarePropertyDevices:
  211014. intern->deviceDetailsChanged();
  211015. break;
  211016. case kAudioHardwarePropertyDefaultOutputDevice:
  211017. case kAudioHardwarePropertyDefaultInputDevice:
  211018. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211019. break;
  211020. }
  211021. return noErr;
  211022. }
  211023. CoreAudioIODevice (const CoreAudioIODevice&);
  211024. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211025. };
  211026. class CoreAudioIODeviceType : public AudioIODeviceType
  211027. {
  211028. public:
  211029. CoreAudioIODeviceType()
  211030. : AudioIODeviceType (T("CoreAudio")),
  211031. hasScanned (false)
  211032. {
  211033. }
  211034. ~CoreAudioIODeviceType()
  211035. {
  211036. }
  211037. void scanForDevices()
  211038. {
  211039. hasScanned = true;
  211040. inputDeviceNames.clear();
  211041. outputDeviceNames.clear();
  211042. inputIds.clear();
  211043. outputIds.clear();
  211044. UInt32 size;
  211045. AudioObjectPropertyAddress pa;
  211046. pa.mSelector = kAudioHardwarePropertyDevices;
  211047. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211048. pa.mElement = kAudioObjectPropertyElementMaster;
  211049. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211050. {
  211051. HeapBlock <AudioDeviceID> devs;
  211052. devs.calloc (size, 1);
  211053. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211054. {
  211055. static bool alreadyLogged = false;
  211056. const int num = size / (int) sizeof (AudioDeviceID);
  211057. for (int i = 0; i < num; ++i)
  211058. {
  211059. char name [1024];
  211060. size = sizeof (name);
  211061. pa.mSelector = kAudioDevicePropertyDeviceName;
  211062. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211063. {
  211064. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211065. if (! alreadyLogged)
  211066. log (T("CoreAudio device: ") + nameString);
  211067. const int numIns = getNumChannels (devs[i], true);
  211068. const int numOuts = getNumChannels (devs[i], false);
  211069. if (numIns > 0)
  211070. {
  211071. inputDeviceNames.add (nameString);
  211072. inputIds.add (devs[i]);
  211073. }
  211074. if (numOuts > 0)
  211075. {
  211076. outputDeviceNames.add (nameString);
  211077. outputIds.add (devs[i]);
  211078. }
  211079. }
  211080. }
  211081. alreadyLogged = true;
  211082. }
  211083. }
  211084. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211085. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211086. }
  211087. const StringArray getDeviceNames (const bool wantInputNames) const
  211088. {
  211089. jassert (hasScanned); // need to call scanForDevices() before doing this
  211090. if (wantInputNames)
  211091. return inputDeviceNames;
  211092. else
  211093. return outputDeviceNames;
  211094. }
  211095. int getDefaultDeviceIndex (const bool forInput) const
  211096. {
  211097. jassert (hasScanned); // need to call scanForDevices() before doing this
  211098. AudioDeviceID deviceID;
  211099. UInt32 size = sizeof (deviceID);
  211100. // if they're asking for any input channels at all, use the default input, so we
  211101. // get the built-in mic rather than the built-in output with no inputs..
  211102. AudioObjectPropertyAddress pa;
  211103. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211104. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211105. pa.mElement = kAudioObjectPropertyElementMaster;
  211106. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211107. {
  211108. if (forInput)
  211109. {
  211110. for (int i = inputIds.size(); --i >= 0;)
  211111. if (inputIds[i] == deviceID)
  211112. return i;
  211113. }
  211114. else
  211115. {
  211116. for (int i = outputIds.size(); --i >= 0;)
  211117. if (outputIds[i] == deviceID)
  211118. return i;
  211119. }
  211120. }
  211121. return 0;
  211122. }
  211123. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211124. {
  211125. jassert (hasScanned); // need to call scanForDevices() before doing this
  211126. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211127. if (d == 0)
  211128. return -1;
  211129. return asInput ? d->inputIndex
  211130. : d->outputIndex;
  211131. }
  211132. bool hasSeparateInputsAndOutputs() const { return true; }
  211133. AudioIODevice* createDevice (const String& outputDeviceName,
  211134. const String& inputDeviceName)
  211135. {
  211136. jassert (hasScanned); // need to call scanForDevices() before doing this
  211137. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211138. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211139. String deviceName (outputDeviceName);
  211140. if (deviceName.isEmpty())
  211141. deviceName = inputDeviceName;
  211142. if (index >= 0)
  211143. return new CoreAudioIODevice (deviceName,
  211144. inputIds [inputIndex],
  211145. inputIndex,
  211146. outputIds [outputIndex],
  211147. outputIndex);
  211148. return 0;
  211149. }
  211150. juce_UseDebuggingNewOperator
  211151. private:
  211152. StringArray inputDeviceNames, outputDeviceNames;
  211153. Array <AudioDeviceID> inputIds, outputIds;
  211154. bool hasScanned;
  211155. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211156. {
  211157. int total = 0;
  211158. UInt32 size;
  211159. AudioObjectPropertyAddress pa;
  211160. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211161. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211162. pa.mElement = kAudioObjectPropertyElementMaster;
  211163. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211164. {
  211165. HeapBlock <AudioBufferList> bufList;
  211166. bufList.calloc (size, 1);
  211167. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211168. {
  211169. const int numStreams = bufList->mNumberBuffers;
  211170. for (int i = 0; i < numStreams; ++i)
  211171. {
  211172. const AudioBuffer& b = bufList->mBuffers[i];
  211173. total += b.mNumberChannels;
  211174. }
  211175. }
  211176. }
  211177. return total;
  211178. }
  211179. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211180. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211181. };
  211182. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211183. {
  211184. return new CoreAudioIODeviceType();
  211185. }
  211186. #undef log
  211187. #endif
  211188. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211189. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211190. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211191. // compiled on its own).
  211192. #if JUCE_INCLUDED_FILE
  211193. #if JUCE_MAC
  211194. #undef log
  211195. #define log(a) Logger::writeToLog(a)
  211196. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211197. {
  211198. if (err == noErr)
  211199. return true;
  211200. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211201. jassertfalse
  211202. return false;
  211203. }
  211204. #undef OK
  211205. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211206. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211207. {
  211208. String result;
  211209. CFStringRef str = 0;
  211210. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211211. if (str != 0)
  211212. {
  211213. result = PlatformUtilities::cfStringToJuceString (str);
  211214. CFRelease (str);
  211215. str = 0;
  211216. }
  211217. MIDIEntityRef entity = 0;
  211218. MIDIEndpointGetEntity (endpoint, &entity);
  211219. if (entity == 0)
  211220. return result; // probably virtual
  211221. if (result.isEmpty())
  211222. {
  211223. // endpoint name has zero length - try the entity
  211224. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211225. if (str != 0)
  211226. {
  211227. result += PlatformUtilities::cfStringToJuceString (str);
  211228. CFRelease (str);
  211229. str = 0;
  211230. }
  211231. }
  211232. // now consider the device's name
  211233. MIDIDeviceRef device = 0;
  211234. MIDIEntityGetDevice (entity, &device);
  211235. if (device == 0)
  211236. return result;
  211237. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211238. if (str != 0)
  211239. {
  211240. const String s (PlatformUtilities::cfStringToJuceString (str));
  211241. CFRelease (str);
  211242. // if an external device has only one entity, throw away
  211243. // the endpoint name and just use the device name
  211244. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211245. {
  211246. result = s;
  211247. }
  211248. else if (! result.startsWithIgnoreCase (s))
  211249. {
  211250. // prepend the device name to the entity name
  211251. result = (s + T(" ") + result).trimEnd();
  211252. }
  211253. }
  211254. return result;
  211255. }
  211256. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211257. {
  211258. String result;
  211259. // Does the endpoint have connections?
  211260. CFDataRef connections = 0;
  211261. int numConnections = 0;
  211262. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211263. if (connections != 0)
  211264. {
  211265. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211266. if (numConnections > 0)
  211267. {
  211268. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211269. for (int i = 0; i < numConnections; ++i, ++pid)
  211270. {
  211271. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211272. MIDIObjectRef connObject;
  211273. MIDIObjectType connObjectType;
  211274. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211275. if (err == noErr)
  211276. {
  211277. String s;
  211278. if (connObjectType == kMIDIObjectType_ExternalSource
  211279. || connObjectType == kMIDIObjectType_ExternalDestination)
  211280. {
  211281. // Connected to an external device's endpoint (10.3 and later).
  211282. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211283. }
  211284. else
  211285. {
  211286. // Connected to an external device (10.2) (or something else, catch-all)
  211287. CFStringRef str = 0;
  211288. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211289. if (str != 0)
  211290. {
  211291. s = PlatformUtilities::cfStringToJuceString (str);
  211292. CFRelease (str);
  211293. }
  211294. }
  211295. if (s.isNotEmpty())
  211296. {
  211297. if (result.isNotEmpty())
  211298. result += (", ");
  211299. result += s;
  211300. }
  211301. }
  211302. }
  211303. }
  211304. CFRelease (connections);
  211305. }
  211306. if (result.isNotEmpty())
  211307. return result;
  211308. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211309. return getEndpointName (endpoint, false);
  211310. }
  211311. const StringArray MidiOutput::getDevices()
  211312. {
  211313. StringArray s;
  211314. const ItemCount num = MIDIGetNumberOfDestinations();
  211315. for (ItemCount i = 0; i < num; ++i)
  211316. {
  211317. MIDIEndpointRef dest = MIDIGetDestination (i);
  211318. if (dest != 0)
  211319. {
  211320. String name (getConnectedEndpointName (dest));
  211321. if (name.isEmpty())
  211322. name = "<error>";
  211323. s.add (name);
  211324. }
  211325. else
  211326. {
  211327. s.add ("<error>");
  211328. }
  211329. }
  211330. return s;
  211331. }
  211332. int MidiOutput::getDefaultDeviceIndex()
  211333. {
  211334. return 0;
  211335. }
  211336. static MIDIClientRef globalMidiClient;
  211337. static bool hasGlobalClientBeenCreated = false;
  211338. static bool makeSureClientExists()
  211339. {
  211340. if (! hasGlobalClientBeenCreated)
  211341. {
  211342. String name (T("JUCE"));
  211343. if (JUCEApplication::getInstance() != 0)
  211344. name = JUCEApplication::getInstance()->getApplicationName();
  211345. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211346. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211347. CFRelease (appName);
  211348. }
  211349. return hasGlobalClientBeenCreated;
  211350. }
  211351. class MidiPortAndEndpoint
  211352. {
  211353. public:
  211354. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211355. : port (port_), endPoint (endPoint_)
  211356. {
  211357. }
  211358. ~MidiPortAndEndpoint()
  211359. {
  211360. if (port != 0)
  211361. MIDIPortDispose (port);
  211362. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211363. MIDIEndpointDispose (endPoint);
  211364. }
  211365. MIDIPortRef port;
  211366. MIDIEndpointRef endPoint;
  211367. };
  211368. MidiOutput* MidiOutput::openDevice (int index)
  211369. {
  211370. MidiOutput* mo = 0;
  211371. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211372. {
  211373. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211374. CFStringRef pname;
  211375. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211376. {
  211377. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211378. if (makeSureClientExists())
  211379. {
  211380. MIDIPortRef port;
  211381. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211382. {
  211383. mo = new MidiOutput();
  211384. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211385. }
  211386. }
  211387. CFRelease (pname);
  211388. }
  211389. }
  211390. return mo;
  211391. }
  211392. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211393. {
  211394. MidiOutput* mo = 0;
  211395. if (makeSureClientExists())
  211396. {
  211397. MIDIEndpointRef endPoint;
  211398. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211399. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211400. {
  211401. mo = new MidiOutput();
  211402. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211403. }
  211404. CFRelease (name);
  211405. }
  211406. return mo;
  211407. }
  211408. MidiOutput::~MidiOutput()
  211409. {
  211410. delete (MidiPortAndEndpoint*) internal;
  211411. }
  211412. void MidiOutput::reset()
  211413. {
  211414. }
  211415. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211416. {
  211417. return false;
  211418. }
  211419. void MidiOutput::setVolume (float leftVol, float rightVol)
  211420. {
  211421. }
  211422. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211423. {
  211424. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211425. if (message.isSysEx())
  211426. {
  211427. const int maxPacketSize = 256;
  211428. int pos = 0, bytesLeft = message.getRawDataSize();
  211429. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211430. HeapBlock <MIDIPacketList> packets;
  211431. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211432. packets->numPackets = numPackets;
  211433. MIDIPacket* p = packets->packet;
  211434. for (int i = 0; i < numPackets; ++i)
  211435. {
  211436. p->timeStamp = 0;
  211437. p->length = jmin (maxPacketSize, bytesLeft);
  211438. memcpy (p->data, message.getRawData() + pos, p->length);
  211439. pos += p->length;
  211440. bytesLeft -= p->length;
  211441. p = MIDIPacketNext (p);
  211442. }
  211443. if (mpe->port != 0)
  211444. MIDISend (mpe->port, mpe->endPoint, packets);
  211445. else
  211446. MIDIReceived (mpe->endPoint, packets);
  211447. }
  211448. else
  211449. {
  211450. MIDIPacketList packets;
  211451. packets.numPackets = 1;
  211452. packets.packet[0].timeStamp = 0;
  211453. packets.packet[0].length = message.getRawDataSize();
  211454. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211455. if (mpe->port != 0)
  211456. MIDISend (mpe->port, mpe->endPoint, &packets);
  211457. else
  211458. MIDIReceived (mpe->endPoint, &packets);
  211459. }
  211460. }
  211461. const StringArray MidiInput::getDevices()
  211462. {
  211463. StringArray s;
  211464. const ItemCount num = MIDIGetNumberOfSources();
  211465. for (ItemCount i = 0; i < num; ++i)
  211466. {
  211467. MIDIEndpointRef source = MIDIGetSource (i);
  211468. if (source != 0)
  211469. {
  211470. String name (getConnectedEndpointName (source));
  211471. if (name.isEmpty())
  211472. name = "<error>";
  211473. s.add (name);
  211474. }
  211475. else
  211476. {
  211477. s.add ("<error>");
  211478. }
  211479. }
  211480. return s;
  211481. }
  211482. int MidiInput::getDefaultDeviceIndex()
  211483. {
  211484. return 0;
  211485. }
  211486. struct MidiPortAndCallback
  211487. {
  211488. MidiInput* input;
  211489. MidiPortAndEndpoint* portAndEndpoint;
  211490. MidiInputCallback* callback;
  211491. MemoryBlock pendingData;
  211492. int pendingBytes;
  211493. double pendingDataTime;
  211494. bool active;
  211495. void processSysex (const uint8*& d, int& size, const double time)
  211496. {
  211497. if (*d == 0xf0)
  211498. {
  211499. pendingBytes = 0;
  211500. pendingDataTime = time;
  211501. }
  211502. pendingData.ensureSize (pendingBytes + size, false);
  211503. uint8* totalMessage = (uint8*) pendingData.getData();
  211504. uint8* dest = totalMessage + pendingBytes;
  211505. while (size > 0)
  211506. {
  211507. if (pendingBytes > 0 && *d >= 0x80)
  211508. {
  211509. if (*d >= 0xfa || *d == 0xf8)
  211510. {
  211511. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211512. ++d;
  211513. --size;
  211514. }
  211515. else
  211516. {
  211517. if (*d == 0xf7)
  211518. {
  211519. *dest++ = *d++;
  211520. pendingBytes++;
  211521. --size;
  211522. }
  211523. break;
  211524. }
  211525. }
  211526. else
  211527. {
  211528. *dest++ = *d++;
  211529. pendingBytes++;
  211530. --size;
  211531. }
  211532. }
  211533. if (totalMessage [pendingBytes - 1] == 0xf7)
  211534. {
  211535. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211536. pendingBytes = 0;
  211537. }
  211538. else
  211539. {
  211540. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211541. }
  211542. }
  211543. };
  211544. namespace CoreMidiCallbacks
  211545. {
  211546. static CriticalSection callbackLock;
  211547. static VoidArray activeCallbacks;
  211548. }
  211549. static void midiInputProc (const MIDIPacketList* pktlist,
  211550. void* readProcRefCon,
  211551. void* srcConnRefCon)
  211552. {
  211553. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211554. const double originalTime = time;
  211555. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211556. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211557. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211558. {
  211559. const MIDIPacket* packet = &pktlist->packet[0];
  211560. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211561. {
  211562. const uint8* d = (const uint8*) (packet->data);
  211563. int size = packet->length;
  211564. while (size > 0)
  211565. {
  211566. time = originalTime;
  211567. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211568. {
  211569. mpc->processSysex (d, size, time);
  211570. }
  211571. else
  211572. {
  211573. int used = 0;
  211574. const MidiMessage m (d, size, used, 0, time);
  211575. if (used <= 0)
  211576. {
  211577. jassertfalse // malformed midi message
  211578. break;
  211579. }
  211580. else
  211581. {
  211582. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211583. }
  211584. size -= used;
  211585. d += used;
  211586. }
  211587. }
  211588. packet = MIDIPacketNext (packet);
  211589. }
  211590. }
  211591. }
  211592. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211593. {
  211594. MidiInput* mi = 0;
  211595. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211596. {
  211597. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211598. if (endPoint != 0)
  211599. {
  211600. CFStringRef pname;
  211601. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211602. {
  211603. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211604. if (makeSureClientExists())
  211605. {
  211606. MIDIPortRef port;
  211607. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211608. mpc->active = false;
  211609. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211610. {
  211611. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211612. {
  211613. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211614. mpc->callback = callback;
  211615. mpc->pendingBytes = 0;
  211616. mpc->pendingData.ensureSize (128);
  211617. mi = new MidiInput (getDevices() [index]);
  211618. mpc->input = mi;
  211619. mi->internal = (void*) mpc;
  211620. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211621. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211622. }
  211623. else
  211624. {
  211625. OK (MIDIPortDispose (port));
  211626. }
  211627. }
  211628. }
  211629. }
  211630. CFRelease (pname);
  211631. }
  211632. }
  211633. return mi;
  211634. }
  211635. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211636. {
  211637. MidiInput* mi = 0;
  211638. if (makeSureClientExists())
  211639. {
  211640. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211641. mpc->active = false;
  211642. MIDIEndpointRef endPoint;
  211643. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211644. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211645. {
  211646. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211647. mpc->callback = callback;
  211648. mpc->pendingBytes = 0;
  211649. mpc->pendingData.ensureSize (128);
  211650. mi = new MidiInput (deviceName);
  211651. mpc->input = mi;
  211652. mi->internal = (void*) mpc;
  211653. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211654. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211655. }
  211656. CFRelease (name);
  211657. }
  211658. return mi;
  211659. }
  211660. MidiInput::MidiInput (const String& name_)
  211661. : name (name_)
  211662. {
  211663. }
  211664. MidiInput::~MidiInput()
  211665. {
  211666. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211667. mpc->active = false;
  211668. {
  211669. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211670. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211671. }
  211672. if (mpc->portAndEndpoint->port != 0)
  211673. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211674. delete mpc->portAndEndpoint;
  211675. delete mpc;
  211676. }
  211677. void MidiInput::start()
  211678. {
  211679. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211680. ((MidiPortAndCallback*) internal)->active = true;
  211681. }
  211682. void MidiInput::stop()
  211683. {
  211684. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211685. ((MidiPortAndCallback*) internal)->active = false;
  211686. }
  211687. #undef log
  211688. #else
  211689. MidiOutput::~MidiOutput()
  211690. {
  211691. }
  211692. void MidiOutput::reset()
  211693. {
  211694. }
  211695. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211696. {
  211697. return false;
  211698. }
  211699. void MidiOutput::setVolume (float leftVol, float rightVol)
  211700. {
  211701. }
  211702. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211703. {
  211704. }
  211705. const StringArray MidiOutput::getDevices()
  211706. {
  211707. return StringArray();
  211708. }
  211709. MidiOutput* MidiOutput::openDevice (int index)
  211710. {
  211711. return 0;
  211712. }
  211713. const StringArray MidiInput::getDevices()
  211714. {
  211715. return StringArray();
  211716. }
  211717. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211718. {
  211719. return 0;
  211720. }
  211721. #endif
  211722. #endif
  211723. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211724. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211725. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211726. // compiled on its own).
  211727. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  211728. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211729. class QTCameraDeviceInteral;
  211730. END_JUCE_NAMESPACE
  211731. @interface QTCaptureCallbackDelegate : NSObject
  211732. {
  211733. @public
  211734. CameraDevice* owner;
  211735. QTCameraDeviceInteral* internal;
  211736. int64 firstPresentationTime;
  211737. int64 averageTimeOffset;
  211738. }
  211739. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211740. - (void) dealloc;
  211741. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211742. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211743. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211744. fromConnection: (QTCaptureConnection*) connection;
  211745. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211746. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211747. fromConnection: (QTCaptureConnection*) connection;
  211748. @end
  211749. BEGIN_JUCE_NAMESPACE
  211750. class QTCameraDeviceInteral
  211751. {
  211752. public:
  211753. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211754. {
  211755. const ScopedAutoReleasePool pool;
  211756. session = [[QTCaptureSession alloc] init];
  211757. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211758. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211759. input = 0;
  211760. audioInput = 0;
  211761. audioDevice = 0;
  211762. fileOutput = 0;
  211763. imageOutput = 0;
  211764. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211765. internalDev: this];
  211766. NSError* err = 0;
  211767. [device retain];
  211768. [device open: &err];
  211769. if (err == 0)
  211770. {
  211771. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211772. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211773. [session addInput: input error: &err];
  211774. if (err == 0)
  211775. {
  211776. resetFile();
  211777. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211778. [imageOutput setDelegate: callbackDelegate];
  211779. if (err == 0)
  211780. {
  211781. [session startRunning];
  211782. return;
  211783. }
  211784. }
  211785. }
  211786. openingError = nsStringToJuce ([err description]);
  211787. DBG (openingError);
  211788. }
  211789. ~QTCameraDeviceInteral()
  211790. {
  211791. [session stopRunning];
  211792. [session removeOutput: imageOutput];
  211793. [session release];
  211794. [input release];
  211795. [device release];
  211796. [audioDevice release];
  211797. [audioInput release];
  211798. [fileOutput release];
  211799. [imageOutput release];
  211800. [callbackDelegate release];
  211801. }
  211802. void resetFile()
  211803. {
  211804. [fileOutput recordToOutputFileURL: nil];
  211805. [session removeOutput: fileOutput];
  211806. [fileOutput release];
  211807. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211808. [session removeInput: audioInput];
  211809. [audioInput release];
  211810. audioInput = 0;
  211811. [audioDevice release];
  211812. audioDevice = 0;
  211813. [fileOutput setDelegate: callbackDelegate];
  211814. }
  211815. void addDefaultAudioInput()
  211816. {
  211817. NSError* err = nil;
  211818. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  211819. if ([audioDevice open: &err])
  211820. [audioDevice retain];
  211821. else
  211822. audioDevice = nil;
  211823. if (audioDevice != 0)
  211824. {
  211825. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  211826. [session addInput: audioInput error: &err];
  211827. }
  211828. }
  211829. void addListener (CameraImageListener* listenerToAdd)
  211830. {
  211831. const ScopedLock sl (listenerLock);
  211832. if (listeners.size() == 0)
  211833. [session addOutput: imageOutput error: nil];
  211834. listeners.addIfNotAlreadyThere (listenerToAdd);
  211835. }
  211836. void removeListener (CameraImageListener* listenerToRemove)
  211837. {
  211838. const ScopedLock sl (listenerLock);
  211839. listeners.removeValue (listenerToRemove);
  211840. if (listeners.size() == 0)
  211841. [session removeOutput: imageOutput];
  211842. }
  211843. void callListeners (CIImage* frame, int w, int h)
  211844. {
  211845. CoreGraphicsImage image (Image::ARGB, w, h, false);
  211846. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  211847. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  211848. CGContextFlush (image.context);
  211849. const ScopedLock sl (listenerLock);
  211850. for (int i = listeners.size(); --i >= 0;)
  211851. {
  211852. CameraImageListener* l = (CameraImageListener*) listeners[i];
  211853. if (l != 0)
  211854. l->imageReceived (image);
  211855. }
  211856. }
  211857. QTCaptureDevice* device;
  211858. QTCaptureDeviceInput* input;
  211859. QTCaptureDevice* audioDevice;
  211860. QTCaptureDeviceInput* audioInput;
  211861. QTCaptureSession* session;
  211862. QTCaptureMovieFileOutput* fileOutput;
  211863. QTCaptureDecompressedVideoOutput* imageOutput;
  211864. QTCaptureCallbackDelegate* callbackDelegate;
  211865. String openingError;
  211866. VoidArray listeners;
  211867. CriticalSection listenerLock;
  211868. };
  211869. END_JUCE_NAMESPACE
  211870. @implementation QTCaptureCallbackDelegate
  211871. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  211872. internalDev: (QTCameraDeviceInteral*) d
  211873. {
  211874. [super init];
  211875. owner = owner_;
  211876. internal = d;
  211877. firstPresentationTime = 0;
  211878. averageTimeOffset = 0;
  211879. return self;
  211880. }
  211881. - (void) dealloc
  211882. {
  211883. [super dealloc];
  211884. }
  211885. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211886. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211887. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211888. fromConnection: (QTCaptureConnection*) connection
  211889. {
  211890. if (internal->listeners.size() > 0)
  211891. {
  211892. const ScopedAutoReleasePool pool;
  211893. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  211894. CVPixelBufferGetWidth (videoFrame),
  211895. CVPixelBufferGetHeight (videoFrame));
  211896. }
  211897. }
  211898. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211899. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211900. fromConnection: (QTCaptureConnection*) connection
  211901. {
  211902. const Time now (Time::getCurrentTime());
  211903. int64 presentationTime = ([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale;
  211904. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  211905. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  211906. #else
  211907. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  211908. #endif
  211909. if (hosttime != nil)
  211910. presentationTime = (int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000;
  211911. const int64 timeDiff = now.toMilliseconds() - presentationTime - 50;
  211912. if (firstPresentationTime == 0)
  211913. {
  211914. firstPresentationTime = presentationTime;
  211915. averageTimeOffset = timeDiff;
  211916. }
  211917. else
  211918. {
  211919. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  211920. }
  211921. }
  211922. @end
  211923. BEGIN_JUCE_NAMESPACE
  211924. class QTCaptureViewerComp : public NSViewComponent
  211925. {
  211926. public:
  211927. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  211928. {
  211929. const ScopedAutoReleasePool pool;
  211930. captureView = [[QTCaptureView alloc] init];
  211931. [captureView setCaptureSession: internal->session];
  211932. setSize (640, 480); // xxx need to somehow get the movie size - how?
  211933. setView (captureView);
  211934. }
  211935. ~QTCaptureViewerComp()
  211936. {
  211937. setView (0);
  211938. [captureView setCaptureSession: nil];
  211939. [captureView release];
  211940. }
  211941. QTCaptureView* captureView;
  211942. };
  211943. CameraDevice::CameraDevice (const String& name_, int index)
  211944. : name (name_)
  211945. {
  211946. isRecording = false;
  211947. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  211948. internal = d;
  211949. }
  211950. CameraDevice::~CameraDevice()
  211951. {
  211952. stopRecording();
  211953. delete (QTCameraDeviceInteral*) internal;
  211954. internal = 0;
  211955. }
  211956. Component* CameraDevice::createViewerComponent()
  211957. {
  211958. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  211959. }
  211960. const String CameraDevice::getFileExtension()
  211961. {
  211962. return ".mov";
  211963. }
  211964. void CameraDevice::startRecordingToFile (const File& file, int quality)
  211965. {
  211966. stopRecording();
  211967. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211968. d->callbackDelegate->firstPresentationTime = 0;
  211969. file.deleteFile();
  211970. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  211971. // out wrong, so we'll put some audio in there too..,
  211972. d->addDefaultAudioInput();
  211973. [d->session addOutput: d->fileOutput error: nil];
  211974. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  211975. for (;;)
  211976. {
  211977. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  211978. if (connection == 0)
  211979. break;
  211980. QTCompressionOptions* options = 0;
  211981. NSString* mediaType = [connection mediaType];
  211982. if ([mediaType isEqualToString: QTMediaTypeVideo])
  211983. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  211984. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  211985. : @"QTCompressionOptions240SizeH264Video"];
  211986. else if ([mediaType isEqualToString: QTMediaTypeSound])
  211987. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  211988. [d->fileOutput setCompressionOptions: options forConnection: connection];
  211989. }
  211990. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  211991. isRecording = true;
  211992. }
  211993. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  211994. {
  211995. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211996. if (d->callbackDelegate->firstPresentationTime != 0)
  211997. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  211998. return Time();
  211999. }
  212000. void CameraDevice::stopRecording()
  212001. {
  212002. if (isRecording)
  212003. {
  212004. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212005. d->resetFile();
  212006. isRecording = false;
  212007. }
  212008. }
  212009. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212010. {
  212011. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212012. if (listenerToAdd != 0)
  212013. d->addListener (listenerToAdd);
  212014. }
  212015. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212016. {
  212017. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212018. if (listenerToRemove != 0)
  212019. d->removeListener (listenerToRemove);
  212020. }
  212021. const StringArray CameraDevice::getAvailableDevices()
  212022. {
  212023. const ScopedAutoReleasePool pool;
  212024. StringArray results;
  212025. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212026. for (int i = 0; i < (int) [devs count]; ++i)
  212027. {
  212028. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212029. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212030. }
  212031. return results;
  212032. }
  212033. CameraDevice* CameraDevice::openDevice (int index,
  212034. int minWidth, int minHeight,
  212035. int maxWidth, int maxHeight)
  212036. {
  212037. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212038. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  212039. return d.release();
  212040. return 0;
  212041. }
  212042. #endif
  212043. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212044. #endif
  212045. #endif
  212046. END_JUCE_NAMESPACE
  212047. #endif
  212048. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212049. #endif
  212050. #endif